1e3ec7017SPing-Ke Shih // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2e3ec7017SPing-Ke Shih /* Copyright(c) 2019-2020 Realtek Corporation 3e3ec7017SPing-Ke Shih */ 4e3ec7017SPing-Ke Shih 5e3ec7017SPing-Ke Shih #include "cam.h" 6967439c7SZong-Zhe Yang #include "chan.h" 7e3ec7017SPing-Ke Shih #include "debug.h" 8e3ec7017SPing-Ke Shih #include "fw.h" 9e3ec7017SPing-Ke Shih #include "mac.h" 10*f7333fc2SChia-Yuan Li #include "pci.h" 11e3ec7017SPing-Ke Shih #include "ps.h" 12e3ec7017SPing-Ke Shih #include "reg.h" 13e3ec7017SPing-Ke Shih #include "util.h" 14e3ec7017SPing-Ke Shih 15ec356ffbSChia-Yuan Li const u32 rtw89_mac_mem_base_addrs[RTW89_MAC_MEM_NUM] = { 16e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_AXIDMA] = AXIDMA_BASE_ADDR, 17e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_SHARED_BUF] = SHARED_BUF_BASE_ADDR, 18e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_DMAC_TBL] = DMAC_TBL_BASE_ADDR, 19e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_SHCUT_MACHDR] = SHCUT_MACHDR_BASE_ADDR, 20e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_STA_SCHED] = STA_SCHED_BASE_ADDR, 21e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_RXPLD_FLTR_CAM] = RXPLD_FLTR_CAM_BASE_ADDR, 22e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_SECURITY_CAM] = SECURITY_CAM_BASE_ADDR, 23e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_WOW_CAM] = WOW_CAM_BASE_ADDR, 24e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_CMAC_TBL] = CMAC_TBL_BASE_ADDR, 25e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_ADDR_CAM] = ADDR_CAM_BASE_ADDR, 26e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_BA_CAM] = BA_CAM_BASE_ADDR, 27e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_BCN_IE_CAM0] = BCN_IE_CAM0_BASE_ADDR, 28e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_BCN_IE_CAM1] = BCN_IE_CAM1_BASE_ADDR, 29e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_TXD_FIFO_0] = TXD_FIFO_0_BASE_ADDR, 30e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_TXD_FIFO_1] = TXD_FIFO_1_BASE_ADDR, 31e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_TXDATA_FIFO_0] = TXDATA_FIFO_0_BASE_ADDR, 32e1400b11SZong-Zhe Yang [RTW89_MAC_MEM_TXDATA_FIFO_1] = TXDATA_FIFO_1_BASE_ADDR, 33ec356ffbSChia-Yuan Li [RTW89_MAC_MEM_CPU_LOCAL] = CPU_LOCAL_BASE_ADDR, 34dadb2086SPing-Ke Shih [RTW89_MAC_MEM_BSSID_CAM] = BSSID_CAM_BASE_ADDR, 35732dd91dSPing-Ke Shih [RTW89_MAC_MEM_TXD_FIFO_0_V1] = TXD_FIFO_0_BASE_ADDR_V1, 36732dd91dSPing-Ke Shih [RTW89_MAC_MEM_TXD_FIFO_1_V1] = TXD_FIFO_1_BASE_ADDR_V1, 37e1400b11SZong-Zhe Yang }; 38e1400b11SZong-Zhe Yang 39ec356ffbSChia-Yuan Li static void rtw89_mac_mem_write(struct rtw89_dev *rtwdev, u32 offset, 40ec356ffbSChia-Yuan Li u32 val, enum rtw89_mac_mem_sel sel) 41ec356ffbSChia-Yuan Li { 42ec356ffbSChia-Yuan Li u32 addr = rtw89_mac_mem_base_addrs[sel] + offset; 43ec356ffbSChia-Yuan Li 44ec356ffbSChia-Yuan Li rtw89_write32(rtwdev, R_AX_FILTER_MODEL_ADDR, addr); 45ec356ffbSChia-Yuan Li rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY, val); 46ec356ffbSChia-Yuan Li } 47ec356ffbSChia-Yuan Li 48ec356ffbSChia-Yuan Li static u32 rtw89_mac_mem_read(struct rtw89_dev *rtwdev, u32 offset, 49ec356ffbSChia-Yuan Li enum rtw89_mac_mem_sel sel) 50ec356ffbSChia-Yuan Li { 51ec356ffbSChia-Yuan Li u32 addr = rtw89_mac_mem_base_addrs[sel] + offset; 52ec356ffbSChia-Yuan Li 53ec356ffbSChia-Yuan Li rtw89_write32(rtwdev, R_AX_FILTER_MODEL_ADDR, addr); 54ec356ffbSChia-Yuan Li return rtw89_read32(rtwdev, R_AX_INDIR_ACCESS_ENTRY); 55ec356ffbSChia-Yuan Li } 56ec356ffbSChia-Yuan Li 57e3ec7017SPing-Ke Shih int rtw89_mac_check_mac_en(struct rtw89_dev *rtwdev, u8 mac_idx, 58e3ec7017SPing-Ke Shih enum rtw89_mac_hwmod_sel sel) 59e3ec7017SPing-Ke Shih { 60e3ec7017SPing-Ke Shih u32 val, r_val; 61e3ec7017SPing-Ke Shih 62e3ec7017SPing-Ke Shih if (sel == RTW89_DMAC_SEL) { 63e3ec7017SPing-Ke Shih r_val = rtw89_read32(rtwdev, R_AX_DMAC_FUNC_EN); 64e3ec7017SPing-Ke Shih val = (B_AX_MAC_FUNC_EN | B_AX_DMAC_FUNC_EN); 65e3ec7017SPing-Ke Shih } else if (sel == RTW89_CMAC_SEL && mac_idx == 0) { 66e3ec7017SPing-Ke Shih r_val = rtw89_read32(rtwdev, R_AX_CMAC_FUNC_EN); 67e3ec7017SPing-Ke Shih val = B_AX_CMAC_EN; 68e3ec7017SPing-Ke Shih } else if (sel == RTW89_CMAC_SEL && mac_idx == 1) { 69e3ec7017SPing-Ke Shih r_val = rtw89_read32(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND); 70e3ec7017SPing-Ke Shih val = B_AX_CMAC1_FEN; 71e3ec7017SPing-Ke Shih } else { 72e3ec7017SPing-Ke Shih return -EINVAL; 73e3ec7017SPing-Ke Shih } 74e3ec7017SPing-Ke Shih if (r_val == RTW89_R32_EA || r_val == RTW89_R32_DEAD || 75e3ec7017SPing-Ke Shih (val & r_val) != val) 76e3ec7017SPing-Ke Shih return -EFAULT; 77e3ec7017SPing-Ke Shih 78e3ec7017SPing-Ke Shih return 0; 79e3ec7017SPing-Ke Shih } 80e3ec7017SPing-Ke Shih 81e3ec7017SPing-Ke Shih int rtw89_mac_write_lte(struct rtw89_dev *rtwdev, const u32 offset, u32 val) 82e3ec7017SPing-Ke Shih { 83e3ec7017SPing-Ke Shih u8 lte_ctrl; 84e3ec7017SPing-Ke Shih int ret; 85e3ec7017SPing-Ke Shih 86e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read8, lte_ctrl, (lte_ctrl & BIT(5)) != 0, 87e3ec7017SPing-Ke Shih 50, 50000, false, rtwdev, R_AX_LTE_CTRL + 3); 88e3ec7017SPing-Ke Shih if (ret) 89e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]lte not ready(W)\n"); 90e3ec7017SPing-Ke Shih 91e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_LTE_WDATA, val); 92e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_LTE_CTRL, 0xC00F0000 | offset); 93e3ec7017SPing-Ke Shih 94e3ec7017SPing-Ke Shih return ret; 95e3ec7017SPing-Ke Shih } 96e3ec7017SPing-Ke Shih 97e3ec7017SPing-Ke Shih int rtw89_mac_read_lte(struct rtw89_dev *rtwdev, const u32 offset, u32 *val) 98e3ec7017SPing-Ke Shih { 99e3ec7017SPing-Ke Shih u8 lte_ctrl; 100e3ec7017SPing-Ke Shih int ret; 101e3ec7017SPing-Ke Shih 102e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read8, lte_ctrl, (lte_ctrl & BIT(5)) != 0, 103e3ec7017SPing-Ke Shih 50, 50000, false, rtwdev, R_AX_LTE_CTRL + 3); 104e3ec7017SPing-Ke Shih if (ret) 105e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]lte not ready(W)\n"); 106e3ec7017SPing-Ke Shih 107e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_LTE_CTRL, 0x800F0000 | offset); 108e3ec7017SPing-Ke Shih *val = rtw89_read32(rtwdev, R_AX_LTE_RDATA); 109e3ec7017SPing-Ke Shih 110e3ec7017SPing-Ke Shih return ret; 111e3ec7017SPing-Ke Shih } 112e3ec7017SPing-Ke Shih 113e3ec7017SPing-Ke Shih static 114e3ec7017SPing-Ke Shih int dle_dfi_ctrl(struct rtw89_dev *rtwdev, struct rtw89_mac_dle_dfi_ctrl *ctrl) 115e3ec7017SPing-Ke Shih { 116e3ec7017SPing-Ke Shih u32 ctrl_reg, data_reg, ctrl_data; 117e3ec7017SPing-Ke Shih u32 val; 118e3ec7017SPing-Ke Shih int ret; 119e3ec7017SPing-Ke Shih 120e3ec7017SPing-Ke Shih switch (ctrl->type) { 121e3ec7017SPing-Ke Shih case DLE_CTRL_TYPE_WDE: 122e3ec7017SPing-Ke Shih ctrl_reg = R_AX_WDE_DBG_FUN_INTF_CTL; 123e3ec7017SPing-Ke Shih data_reg = R_AX_WDE_DBG_FUN_INTF_DATA; 124e3ec7017SPing-Ke Shih ctrl_data = FIELD_PREP(B_AX_WDE_DFI_TRGSEL_MASK, ctrl->target) | 125e3ec7017SPing-Ke Shih FIELD_PREP(B_AX_WDE_DFI_ADDR_MASK, ctrl->addr) | 126e3ec7017SPing-Ke Shih B_AX_WDE_DFI_ACTIVE; 127e3ec7017SPing-Ke Shih break; 128e3ec7017SPing-Ke Shih case DLE_CTRL_TYPE_PLE: 129e3ec7017SPing-Ke Shih ctrl_reg = R_AX_PLE_DBG_FUN_INTF_CTL; 130e3ec7017SPing-Ke Shih data_reg = R_AX_PLE_DBG_FUN_INTF_DATA; 131e3ec7017SPing-Ke Shih ctrl_data = FIELD_PREP(B_AX_PLE_DFI_TRGSEL_MASK, ctrl->target) | 132e3ec7017SPing-Ke Shih FIELD_PREP(B_AX_PLE_DFI_ADDR_MASK, ctrl->addr) | 133e3ec7017SPing-Ke Shih B_AX_PLE_DFI_ACTIVE; 134e3ec7017SPing-Ke Shih break; 135e3ec7017SPing-Ke Shih default: 136e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "[ERR] dfi ctrl type %d\n", ctrl->type); 137e3ec7017SPing-Ke Shih return -EINVAL; 138e3ec7017SPing-Ke Shih } 139e3ec7017SPing-Ke Shih 140e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, ctrl_reg, ctrl_data); 141e3ec7017SPing-Ke Shih 142e3ec7017SPing-Ke Shih ret = read_poll_timeout_atomic(rtw89_read32, val, !(val & B_AX_WDE_DFI_ACTIVE), 143e3ec7017SPing-Ke Shih 1, 1000, false, rtwdev, ctrl_reg); 144e3ec7017SPing-Ke Shih if (ret) { 145e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "[ERR] dle dfi ctrl 0x%X set 0x%X timeout\n", 146e3ec7017SPing-Ke Shih ctrl_reg, ctrl_data); 147e3ec7017SPing-Ke Shih return ret; 148e3ec7017SPing-Ke Shih } 149e3ec7017SPing-Ke Shih 150e3ec7017SPing-Ke Shih ctrl->out_data = rtw89_read32(rtwdev, data_reg); 151e3ec7017SPing-Ke Shih return 0; 152e3ec7017SPing-Ke Shih } 153e3ec7017SPing-Ke Shih 154e3ec7017SPing-Ke Shih static int dle_dfi_quota(struct rtw89_dev *rtwdev, 155e3ec7017SPing-Ke Shih struct rtw89_mac_dle_dfi_quota *quota) 156e3ec7017SPing-Ke Shih { 157e3ec7017SPing-Ke Shih struct rtw89_mac_dle_dfi_ctrl ctrl; 158e3ec7017SPing-Ke Shih int ret; 159e3ec7017SPing-Ke Shih 160e3ec7017SPing-Ke Shih ctrl.type = quota->dle_type; 161e3ec7017SPing-Ke Shih ctrl.target = DLE_DFI_TYPE_QUOTA; 162e3ec7017SPing-Ke Shih ctrl.addr = quota->qtaid; 163e3ec7017SPing-Ke Shih ret = dle_dfi_ctrl(rtwdev, &ctrl); 164e3ec7017SPing-Ke Shih if (ret) { 165e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "[ERR]dle_dfi_ctrl %d\n", ret); 166e3ec7017SPing-Ke Shih return ret; 167e3ec7017SPing-Ke Shih } 168e3ec7017SPing-Ke Shih 169e3ec7017SPing-Ke Shih quota->rsv_pgnum = FIELD_GET(B_AX_DLE_RSV_PGNUM, ctrl.out_data); 170e3ec7017SPing-Ke Shih quota->use_pgnum = FIELD_GET(B_AX_DLE_USE_PGNUM, ctrl.out_data); 171e3ec7017SPing-Ke Shih return 0; 172e3ec7017SPing-Ke Shih } 173e3ec7017SPing-Ke Shih 174e3ec7017SPing-Ke Shih static int dle_dfi_qempty(struct rtw89_dev *rtwdev, 175e3ec7017SPing-Ke Shih struct rtw89_mac_dle_dfi_qempty *qempty) 176e3ec7017SPing-Ke Shih { 177e3ec7017SPing-Ke Shih struct rtw89_mac_dle_dfi_ctrl ctrl; 178e3ec7017SPing-Ke Shih u32 ret; 179e3ec7017SPing-Ke Shih 180e3ec7017SPing-Ke Shih ctrl.type = qempty->dle_type; 181e3ec7017SPing-Ke Shih ctrl.target = DLE_DFI_TYPE_QEMPTY; 182e3ec7017SPing-Ke Shih ctrl.addr = qempty->grpsel; 183e3ec7017SPing-Ke Shih ret = dle_dfi_ctrl(rtwdev, &ctrl); 184e3ec7017SPing-Ke Shih if (ret) { 185e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "[ERR]dle_dfi_ctrl %d\n", ret); 186e3ec7017SPing-Ke Shih return ret; 187e3ec7017SPing-Ke Shih } 188e3ec7017SPing-Ke Shih 189e3ec7017SPing-Ke Shih qempty->qempty = FIELD_GET(B_AX_DLE_QEMPTY_GRP, ctrl.out_data); 190e3ec7017SPing-Ke Shih return 0; 191e3ec7017SPing-Ke Shih } 192e3ec7017SPing-Ke Shih 193e3ec7017SPing-Ke Shih static void dump_err_status_dispatcher(struct rtw89_dev *rtwdev) 194e3ec7017SPing-Ke Shih { 195e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_HOST_DISPATCHER_ALWAYS_IMR=0x%08x ", 196e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_HOST_DISPATCHER_ERR_IMR)); 197e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_HOST_DISPATCHER_ALWAYS_ISR=0x%08x\n", 198e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_HOST_DISPATCHER_ERR_ISR)); 199e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_CPU_DISPATCHER_ALWAYS_IMR=0x%08x ", 200e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_CPU_DISPATCHER_ERR_IMR)); 201e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_CPU_DISPATCHER_ALWAYS_ISR=0x%08x\n", 202e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_CPU_DISPATCHER_ERR_ISR)); 203e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_OTHER_DISPATCHER_ALWAYS_IMR=0x%08x ", 204e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_OTHER_DISPATCHER_ERR_IMR)); 205e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_OTHER_DISPATCHER_ALWAYS_ISR=0x%08x\n", 206e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_OTHER_DISPATCHER_ERR_ISR)); 207e3ec7017SPing-Ke Shih } 208e3ec7017SPing-Ke Shih 209e3ec7017SPing-Ke Shih static void rtw89_mac_dump_qta_lost(struct rtw89_dev *rtwdev) 210e3ec7017SPing-Ke Shih { 211e3ec7017SPing-Ke Shih struct rtw89_mac_dle_dfi_qempty qempty; 212e3ec7017SPing-Ke Shih struct rtw89_mac_dle_dfi_quota quota; 213e3ec7017SPing-Ke Shih struct rtw89_mac_dle_dfi_ctrl ctrl; 214e3ec7017SPing-Ke Shih u32 val, not_empty, i; 215e3ec7017SPing-Ke Shih int ret; 216e3ec7017SPing-Ke Shih 217e3ec7017SPing-Ke Shih qempty.dle_type = DLE_CTRL_TYPE_PLE; 218e3ec7017SPing-Ke Shih qempty.grpsel = 0; 21989e4a00fSÍñigo Huguet qempty.qempty = ~(u32)0; 220e3ec7017SPing-Ke Shih ret = dle_dfi_qempty(rtwdev, &qempty); 221e3ec7017SPing-Ke Shih if (ret) 222e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "%s: query DLE fail\n", __func__); 223e3ec7017SPing-Ke Shih else 224e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "DLE group0 empty: 0x%x\n", qempty.qempty); 225e3ec7017SPing-Ke Shih 226e3ec7017SPing-Ke Shih for (not_empty = ~qempty.qempty, i = 0; not_empty != 0; not_empty >>= 1, i++) { 227e3ec7017SPing-Ke Shih if (!(not_empty & BIT(0))) 228e3ec7017SPing-Ke Shih continue; 229e3ec7017SPing-Ke Shih ctrl.type = DLE_CTRL_TYPE_PLE; 230e3ec7017SPing-Ke Shih ctrl.target = DLE_DFI_TYPE_QLNKTBL; 231e3ec7017SPing-Ke Shih ctrl.addr = (QLNKTBL_ADDR_INFO_SEL_0 ? QLNKTBL_ADDR_INFO_SEL : 0) | 232e3ec7017SPing-Ke Shih FIELD_PREP(QLNKTBL_ADDR_TBL_IDX_MASK, i); 233e3ec7017SPing-Ke Shih ret = dle_dfi_ctrl(rtwdev, &ctrl); 234e3ec7017SPing-Ke Shih if (ret) 235e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "%s: query DLE fail\n", __func__); 236e3ec7017SPing-Ke Shih else 237e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "qidx%d pktcnt = %ld\n", i, 238e3ec7017SPing-Ke Shih FIELD_GET(QLNKTBL_DATA_SEL1_PKT_CNT_MASK, 239e3ec7017SPing-Ke Shih ctrl.out_data)); 240e3ec7017SPing-Ke Shih } 241e3ec7017SPing-Ke Shih 242e3ec7017SPing-Ke Shih quota.dle_type = DLE_CTRL_TYPE_PLE; 243e3ec7017SPing-Ke Shih quota.qtaid = 6; 244e3ec7017SPing-Ke Shih ret = dle_dfi_quota(rtwdev, "a); 245e3ec7017SPing-Ke Shih if (ret) 246e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "%s: query DLE fail\n", __func__); 247e3ec7017SPing-Ke Shih else 248e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "quota6 rsv/use: 0x%x/0x%x\n", 249e3ec7017SPing-Ke Shih quota.rsv_pgnum, quota.use_pgnum); 250e3ec7017SPing-Ke Shih 251e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, R_AX_PLE_QTA6_CFG); 252e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "[PLE][CMAC0_RX]min_pgnum=0x%lx\n", 253e3ec7017SPing-Ke Shih FIELD_GET(B_AX_PLE_Q6_MIN_SIZE_MASK, val)); 254e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "[PLE][CMAC0_RX]max_pgnum=0x%lx\n", 255e3ec7017SPing-Ke Shih FIELD_GET(B_AX_PLE_Q6_MAX_SIZE_MASK, val)); 256e3ec7017SPing-Ke Shih 257e3ec7017SPing-Ke Shih dump_err_status_dispatcher(rtwdev); 258e3ec7017SPing-Ke Shih } 259e3ec7017SPing-Ke Shih 260e3ec7017SPing-Ke Shih static void rtw89_mac_dump_l0_to_l1(struct rtw89_dev *rtwdev, 261e3ec7017SPing-Ke Shih enum mac_ax_err_info err) 262e3ec7017SPing-Ke Shih { 263e3ec7017SPing-Ke Shih u32 dbg, event; 264e3ec7017SPing-Ke Shih 265e3ec7017SPing-Ke Shih dbg = rtw89_read32(rtwdev, R_AX_SER_DBG_INFO); 266e3ec7017SPing-Ke Shih event = FIELD_GET(B_AX_L0_TO_L1_EVENT_MASK, dbg); 267e3ec7017SPing-Ke Shih 268e3ec7017SPing-Ke Shih switch (event) { 269e3ec7017SPing-Ke Shih case MAC_AX_L0_TO_L1_RX_QTA_LOST: 270e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "quota lost!\n"); 271e3ec7017SPing-Ke Shih rtw89_mac_dump_qta_lost(rtwdev); 272e3ec7017SPing-Ke Shih break; 273e3ec7017SPing-Ke Shih default: 274e3ec7017SPing-Ke Shih break; 275e3ec7017SPing-Ke Shih } 276e3ec7017SPing-Ke Shih } 277e3ec7017SPing-Ke Shih 278*f7333fc2SChia-Yuan Li static void rtw89_mac_dump_dmac_err_status(struct rtw89_dev *rtwdev) 279e3ec7017SPing-Ke Shih { 280*f7333fc2SChia-Yuan Li const struct rtw89_chip_info *chip = rtwdev->chip; 281*f7333fc2SChia-Yuan Li u32 dmac_err; 282*f7333fc2SChia-Yuan Li int i, ret; 283e3ec7017SPing-Ke Shih 284*f7333fc2SChia-Yuan Li ret = rtw89_mac_check_mac_en(rtwdev, 0, RTW89_DMAC_SEL); 285*f7333fc2SChia-Yuan Li if (ret) { 286*f7333fc2SChia-Yuan Li rtw89_warn(rtwdev, "[DMAC] : DMAC not enabled\n"); 287e3ec7017SPing-Ke Shih return; 288*f7333fc2SChia-Yuan Li } 289e3ec7017SPing-Ke Shih 290e3ec7017SPing-Ke Shih dmac_err = rtw89_read32(rtwdev, R_AX_DMAC_ERR_ISR); 291e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_DMAC_ERR_ISR=0x%08x\n", dmac_err); 292*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_DMAC_ERR_IMR=0x%08x\n", 293*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_DMAC_ERR_IMR)); 294e3ec7017SPing-Ke Shih 295e3ec7017SPing-Ke Shih if (dmac_err) { 296*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_WDE_ERR_FLAG_CFG=0x%08x\n", 297*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_WDE_ERR_FLAG_CFG_NUM1)); 298e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_PLE_ERR_FLAG_CFG=0x%08x\n", 299*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_PLE_ERR_FLAG_CFG_NUM1)); 300*f7333fc2SChia-Yuan Li if (chip->chip_id == RTL8852C) { 301*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PLE_ERRFLAG_MSG=0x%08x\n", 302*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_PLE_ERRFLAG_MSG)); 303*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_WDE_ERRFLAG_MSG=0x%08x\n", 304*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_WDE_ERRFLAG_MSG)); 305*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PLE_DBGERR_LOCKEN=0x%08x\n", 306*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_PLE_DBGERR_LOCKEN)); 307*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PLE_DBGERR_STS=0x%08x\n", 308*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_PLE_DBGERR_STS)); 309*f7333fc2SChia-Yuan Li } 310e3ec7017SPing-Ke Shih } 311e3ec7017SPing-Ke Shih 312e3ec7017SPing-Ke Shih if (dmac_err & B_AX_WDRLS_ERR_FLAG) { 313*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_WDRLS_ERR_IMR=0x%08x\n", 314e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WDRLS_ERR_IMR)); 315e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_WDRLS_ERR_ISR=0x%08x\n", 316e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WDRLS_ERR_ISR)); 317*f7333fc2SChia-Yuan Li if (chip->chip_id == RTL8852C) 318*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_RPQ_RXBD_IDX=0x%08x\n", 319*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_RPQ_RXBD_IDX_V1)); 320*f7333fc2SChia-Yuan Li else 321*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_RPQ_RXBD_IDX=0x%08x\n", 322*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_RPQ_RXBD_IDX)); 323e3ec7017SPing-Ke Shih } 324e3ec7017SPing-Ke Shih 325e3ec7017SPing-Ke Shih if (dmac_err & B_AX_WSEC_ERR_FLAG) { 326*f7333fc2SChia-Yuan Li if (chip->chip_id == RTL8852C) { 327*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_ERR_IMR=0x%08x\n", 328*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SEC_ERROR_FLAG_IMR)); 329*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_ERR_ISR=0x%08x\n", 330*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SEC_ERROR_FLAG)); 331*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_ENG_CTRL=0x%08x\n", 332*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SEC_ENG_CTRL)); 333*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_MPDU_PROC=0x%08x\n", 334*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SEC_MPDU_PROC)); 335*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_CAM_ACCESS=0x%08x\n", 336*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SEC_CAM_ACCESS)); 337*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_CAM_RDATA=0x%08x\n", 338*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SEC_CAM_RDATA)); 339*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_DEBUG1=0x%08x\n", 340*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SEC_DEBUG1)); 341*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_TX_DEBUG=0x%08x\n", 342*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SEC_TX_DEBUG)); 343*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_RX_DEBUG=0x%08x\n", 344*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SEC_RX_DEBUG)); 345*f7333fc2SChia-Yuan Li 346*f7333fc2SChia-Yuan Li rtw89_write32_mask(rtwdev, R_AX_DBG_CTRL, 347*f7333fc2SChia-Yuan Li B_AX_DBG_SEL0, 0x8B); 348*f7333fc2SChia-Yuan Li rtw89_write32_mask(rtwdev, R_AX_DBG_CTRL, 349*f7333fc2SChia-Yuan Li B_AX_DBG_SEL1, 0x8B); 350*f7333fc2SChia-Yuan Li rtw89_write32_mask(rtwdev, R_AX_SYS_STATUS1, 351*f7333fc2SChia-Yuan Li B_AX_SEL_0XC0_MASK, 1); 352*f7333fc2SChia-Yuan Li for (i = 0; i < 0x10; i++) { 353*f7333fc2SChia-Yuan Li rtw89_write32_mask(rtwdev, R_AX_SEC_ENG_CTRL, 354*f7333fc2SChia-Yuan Li B_AX_SEC_DBG_PORT_FIELD_MASK, i); 355*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "sel=%x,R_AX_SEC_DEBUG2=0x%08x\n", 356*f7333fc2SChia-Yuan Li i, rtw89_read32(rtwdev, R_AX_SEC_DEBUG2)); 357*f7333fc2SChia-Yuan Li } 358*f7333fc2SChia-Yuan Li } else { 359e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_SEC_ERR_IMR_ISR=0x%08x\n", 360e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_DEBUG)); 361*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_ENG_CTRL=0x%08x\n", 362e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_ENG_CTRL)); 363*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_MPDU_PROC=0x%08x\n", 364e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_MPDU_PROC)); 365*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_CAM_ACCESS=0x%08x\n", 366e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_CAM_ACCESS)); 367*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_CAM_RDATA=0x%08x\n", 368e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_CAM_RDATA)); 369*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_CAM_WDATA=0x%08x\n", 370e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_CAM_WDATA)); 371*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_TX_DEBUG=0x%08x\n", 372e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_TX_DEBUG)); 373*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_RX_DEBUG=0x%08x\n", 374e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_RX_DEBUG)); 375*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_TRX_PKT_CNT=0x%08x\n", 376e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_TRX_PKT_CNT)); 377*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SEC_TRX_BLK_CNT=0x%08x\n", 378e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_SEC_TRX_BLK_CNT)); 379e3ec7017SPing-Ke Shih } 380*f7333fc2SChia-Yuan Li } 381e3ec7017SPing-Ke Shih 382e3ec7017SPing-Ke Shih if (dmac_err & B_AX_MPDU_ERR_FLAG) { 383*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_MPDU_TX_ERR_IMR=0x%08x\n", 384e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_MPDU_TX_ERR_IMR)); 385e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_MPDU_TX_ERR_ISR=0x%08x\n", 386e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_MPDU_TX_ERR_ISR)); 387*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_MPDU_RX_ERR_IMR=0x%08x\n", 388e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_MPDU_RX_ERR_IMR)); 389e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_MPDU_RX_ERR_ISR=0x%08x\n", 390e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_MPDU_RX_ERR_ISR)); 391e3ec7017SPing-Ke Shih } 392e3ec7017SPing-Ke Shih 393e3ec7017SPing-Ke Shih if (dmac_err & B_AX_STA_SCHEDULER_ERR_FLAG) { 394*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_STA_SCHEDULER_ERR_IMR=0x%08x\n", 395e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_STA_SCHEDULER_ERR_IMR)); 396e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_STA_SCHEDULER_ERR_ISR=0x%08x\n", 397e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_STA_SCHEDULER_ERR_ISR)); 398e3ec7017SPing-Ke Shih } 399e3ec7017SPing-Ke Shih 400e3ec7017SPing-Ke Shih if (dmac_err & B_AX_WDE_DLE_ERR_FLAG) { 401*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_WDE_ERR_IMR=0x%08x\n", 402e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WDE_ERR_IMR)); 403e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_WDE_ERR_ISR=0x%08x\n", 404e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WDE_ERR_ISR)); 405*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PLE_ERR_IMR=0x%08x\n", 406e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PLE_ERR_IMR)); 407e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_PLE_ERR_FLAG_ISR=0x%08x\n", 408e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PLE_ERR_FLAG_ISR)); 409e3ec7017SPing-Ke Shih } 410e3ec7017SPing-Ke Shih 411e3ec7017SPing-Ke Shih if (dmac_err & B_AX_TXPKTCTRL_ERR_FLAG) { 412*f7333fc2SChia-Yuan Li if (chip->chip_id == RTL8852C) { 413*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_TXPKTCTL_B0_ERRFLAG_IMR=0x%08x\n", 414*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_TXPKTCTL_B0_ERRFLAG_IMR)); 415*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_TXPKTCTL_B0_ERRFLAG_ISR=0x%08x\n", 416*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_TXPKTCTL_B0_ERRFLAG_ISR)); 417*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_TXPKTCTL_B1_ERRFLAG_IMR=0x%08x\n", 418*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_TXPKTCTL_B1_ERRFLAG_IMR)); 419*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_TXPKTCTL_B1_ERRFLAG_ISR=0x%08x\n", 420*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_TXPKTCTL_B1_ERRFLAG_ISR)); 421*f7333fc2SChia-Yuan Li } else { 422e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_TXPKTCTL_ERR_IMR_ISR=0x%08x\n", 423e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_TXPKTCTL_ERR_IMR_ISR)); 424e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_TXPKTCTL_ERR_IMR_ISR_B1=0x%08x\n", 425e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_TXPKTCTL_ERR_IMR_ISR_B1)); 426e3ec7017SPing-Ke Shih } 427*f7333fc2SChia-Yuan Li } 428e3ec7017SPing-Ke Shih 429e3ec7017SPing-Ke Shih if (dmac_err & B_AX_PLE_DLE_ERR_FLAG) { 430*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_WDE_ERR_IMR=0x%08x\n", 431e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WDE_ERR_IMR)); 432e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_WDE_ERR_ISR=0x%08x\n", 433e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WDE_ERR_ISR)); 434*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PLE_ERR_IMR=0x%08x\n", 435e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PLE_ERR_IMR)); 436e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_PLE_ERR_FLAG_ISR=0x%08x\n", 437e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PLE_ERR_FLAG_ISR)); 438e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_WD_CPUQ_OP_0=0x%08x\n", 439e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WD_CPUQ_OP_0)); 440e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_WD_CPUQ_OP_1=0x%08x\n", 441e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WD_CPUQ_OP_1)); 442e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_WD_CPUQ_OP_2=0x%08x\n", 443e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WD_CPUQ_OP_2)); 444e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_WD_CPUQ_OP_STATUS=0x%08x\n", 445e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WD_CPUQ_OP_STATUS)); 446e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_PL_CPUQ_OP_0=0x%08x\n", 447e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PL_CPUQ_OP_0)); 448e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_PL_CPUQ_OP_1=0x%08x\n", 449e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PL_CPUQ_OP_1)); 450e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_PL_CPUQ_OP_2=0x%08x\n", 451e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PL_CPUQ_OP_2)); 452e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_PL_CPUQ_OP_STATUS=0x%08x\n", 453e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PL_CPUQ_OP_STATUS)); 454*f7333fc2SChia-Yuan Li if (chip->chip_id == RTL8852C) { 455*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_RX_CTRL0=0x%08x\n", 456*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_RX_CTRL0)); 457*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_RX_CTRL1=0x%08x\n", 458*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_RX_CTRL1)); 459*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_RX_CTRL2=0x%08x\n", 460*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_RX_CTRL2)); 461*f7333fc2SChia-Yuan Li } else { 462e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_RXDMA_PKT_INFO_0=0x%08x\n", 463e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_RXDMA_PKT_INFO_0)); 464e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_RXDMA_PKT_INFO_1=0x%08x\n", 465e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_RXDMA_PKT_INFO_1)); 466e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_RXDMA_PKT_INFO_2=0x%08x\n", 467e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_RXDMA_PKT_INFO_2)); 468*f7333fc2SChia-Yuan Li } 469e3ec7017SPing-Ke Shih } 470e3ec7017SPing-Ke Shih 471e3ec7017SPing-Ke Shih if (dmac_err & B_AX_PKTIN_ERR_FLAG) { 472*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PKTIN_ERR_IMR=0x%08x\n", 473e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PKTIN_ERR_IMR)); 474e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_PKTIN_ERR_ISR=0x%08x\n", 475e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PKTIN_ERR_ISR)); 476e3ec7017SPing-Ke Shih } 477e3ec7017SPing-Ke Shih 478*f7333fc2SChia-Yuan Li if (dmac_err & B_AX_DISPATCH_ERR_FLAG) { 479*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_HOST_DISPATCHER_ERR_IMR=0x%08x\n", 480*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_HOST_DISPATCHER_ERR_IMR)); 481*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_HOST_DISPATCHER_ERR_ISR=0x%08x\n", 482*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_HOST_DISPATCHER_ERR_ISR)); 483*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_CPU_DISPATCHER_ERR_IMR=0x%08x\n", 484*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_CPU_DISPATCHER_ERR_IMR)); 485*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_CPU_DISPATCHER_ERR_ISR=0x%08x\n", 486*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_CPU_DISPATCHER_ERR_ISR)); 487*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_OTHER_DISPATCHER_ERR_IMR=0x%08x\n", 488*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_OTHER_DISPATCHER_ERR_IMR)); 489*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_OTHER_DISPATCHER_ERR_ISR=0x%08x\n", 490*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_OTHER_DISPATCHER_ERR_ISR)); 491e3ec7017SPing-Ke Shih } 492e3ec7017SPing-Ke Shih 493*f7333fc2SChia-Yuan Li if (dmac_err & B_AX_BBRPT_ERR_FLAG) { 494*f7333fc2SChia-Yuan Li if (chip->chip_id == RTL8852C) { 495*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_COM_ERR_IMR=0x%08x\n", 496*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_COM_ERR_IMR)); 497*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_COM_ERR_ISR=0x%08x\n", 498*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_COM_ERR_ISR)); 499*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_CHINFO_ERR_ISR=0x%08x\n", 500*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_CHINFO_ERR_ISR)); 501*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_CHINFO_ERR_IMR=0x%08x\n", 502*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_CHINFO_ERR_IMR)); 503*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_DFS_ERR_IMR=0x%08x\n", 504*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_DFS_ERR_IMR)); 505*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_DFS_ERR_ISR=0x%08x\n", 506*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_DFS_ERR_ISR)); 507*f7333fc2SChia-Yuan Li } else { 508e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "R_AX_BBRPT_COM_ERR_IMR_ISR=0x%08x\n", 509e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_BBRPT_COM_ERR_IMR_ISR)); 510*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_CHINFO_ERR_ISR=0x%08x\n", 511*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_CHINFO_ERR_ISR)); 512*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_CHINFO_ERR_IMR=0x%08x\n", 513*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_CHINFO_ERR_IMR)); 514*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_DFS_ERR_IMR=0x%08x\n", 515*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_DFS_ERR_IMR)); 516*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_BBRPT_DFS_ERR_ISR=0x%08x\n", 517*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_BBRPT_DFS_ERR_ISR)); 518*f7333fc2SChia-Yuan Li } 519e3ec7017SPing-Ke Shih } 520e3ec7017SPing-Ke Shih 521*f7333fc2SChia-Yuan Li if (dmac_err & B_AX_HAXIDMA_ERR_FLAG && chip->chip_id == RTL8852C) { 522*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_HAXIDMA_ERR_IMR=0x%08x\n", 523*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_HAXI_IDCT_MSK)); 524*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_HAXIDMA_ERR_ISR=0x%08x\n", 525*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_HAXI_IDCT)); 526*f7333fc2SChia-Yuan Li } 527*f7333fc2SChia-Yuan Li } 528*f7333fc2SChia-Yuan Li 529*f7333fc2SChia-Yuan Li static void rtw89_mac_dump_cmac_err_status(struct rtw89_dev *rtwdev, 530*f7333fc2SChia-Yuan Li u8 band) 531*f7333fc2SChia-Yuan Li { 532*f7333fc2SChia-Yuan Li const struct rtw89_chip_info *chip = rtwdev->chip; 533*f7333fc2SChia-Yuan Li u32 offset = 0; 534*f7333fc2SChia-Yuan Li u32 cmac_err; 535*f7333fc2SChia-Yuan Li int ret; 536*f7333fc2SChia-Yuan Li 537*f7333fc2SChia-Yuan Li ret = rtw89_mac_check_mac_en(rtwdev, band, RTW89_CMAC_SEL); 538*f7333fc2SChia-Yuan Li if (ret) { 539*f7333fc2SChia-Yuan Li if (band) 540*f7333fc2SChia-Yuan Li rtw89_warn(rtwdev, "[CMAC] : CMAC1 not enabled\n"); 541*f7333fc2SChia-Yuan Li else 542*f7333fc2SChia-Yuan Li rtw89_warn(rtwdev, "[CMAC] : CMAC0 not enabled\n"); 543*f7333fc2SChia-Yuan Li return; 544*f7333fc2SChia-Yuan Li } 545*f7333fc2SChia-Yuan Li 546*f7333fc2SChia-Yuan Li if (band) 547*f7333fc2SChia-Yuan Li offset = RTW89_MAC_AX_BAND_REG_OFFSET; 548*f7333fc2SChia-Yuan Li 549*f7333fc2SChia-Yuan Li cmac_err = rtw89_read32(rtwdev, R_AX_CMAC_ERR_ISR + offset); 550*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_CMAC_ERR_ISR [%d]=0x%08x\n", band, 551*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_CMAC_ERR_ISR + offset)); 552*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_CMAC_FUNC_EN [%d]=0x%08x\n", band, 553*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_CMAC_FUNC_EN + offset)); 554*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_CK_EN [%d]=0x%08x\n", band, 555*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_CK_EN + offset)); 556*f7333fc2SChia-Yuan Li 557e3ec7017SPing-Ke Shih if (cmac_err & B_AX_SCHEDULE_TOP_ERR_IND) { 558*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SCHEDULE_ERR_IMR [%d]=0x%08x\n", band, 559*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SCHEDULE_ERR_IMR + offset)); 560*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SCHEDULE_ERR_ISR [%d]=0x%08x\n", band, 561*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SCHEDULE_ERR_ISR + offset)); 562e3ec7017SPing-Ke Shih } 563e3ec7017SPing-Ke Shih 564e3ec7017SPing-Ke Shih if (cmac_err & B_AX_PTCL_TOP_ERR_IND) { 565*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PTCL_IMR0 [%d]=0x%08x\n", band, 566*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_PTCL_IMR0 + offset)); 567*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PTCL_ISR0 [%d]=0x%08x\n", band, 568*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_PTCL_ISR0 + offset)); 569e3ec7017SPing-Ke Shih } 570e3ec7017SPing-Ke Shih 571e3ec7017SPing-Ke Shih if (cmac_err & B_AX_DMA_TOP_ERR_IND) { 572*f7333fc2SChia-Yuan Li if (chip->chip_id == RTL8852C) { 573*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_RX_ERR_FLAG [%d]=0x%08x\n", band, 574*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_RX_ERR_FLAG + offset)); 575*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_RX_ERR_FLAG_IMR [%d]=0x%08x\n", band, 576*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_RX_ERR_FLAG_IMR + offset)); 577*f7333fc2SChia-Yuan Li } else { 578*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_DLE_CTRL [%d]=0x%08x\n", band, 579*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_DLE_CTRL + offset)); 580*f7333fc2SChia-Yuan Li } 581e3ec7017SPing-Ke Shih } 582e3ec7017SPing-Ke Shih 583*f7333fc2SChia-Yuan Li if (cmac_err & B_AX_DMA_TOP_ERR_IND || cmac_err & B_AX_WMAC_RX_ERR_IND) { 584*f7333fc2SChia-Yuan Li if (chip->chip_id == RTL8852C) { 585*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PHYINFO_ERR_ISR [%d]=0x%08x\n", band, 586*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_PHYINFO_ERR_ISR + offset)); 587*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PHYINFO_ERR_IMR [%d]=0x%08x\n", band, 588*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_PHYINFO_ERR_IMR + offset)); 589*f7333fc2SChia-Yuan Li } else { 590*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_PHYINFO_ERR_IMR [%d]=0x%08x\n", band, 591*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_PHYINFO_ERR_IMR + offset)); 592*f7333fc2SChia-Yuan Li } 593e3ec7017SPing-Ke Shih } 594e3ec7017SPing-Ke Shih 595e3ec7017SPing-Ke Shih if (cmac_err & B_AX_TXPWR_CTRL_ERR_IND) { 596*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_TXPWR_IMR [%d]=0x%08x\n", band, 597*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_TXPWR_IMR + offset)); 598*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_TXPWR_ISR [%d]=0x%08x\n", band, 599*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_TXPWR_ISR + offset)); 600e3ec7017SPing-Ke Shih } 601e3ec7017SPing-Ke Shih 602e3ec7017SPing-Ke Shih if (cmac_err & B_AX_WMAC_TX_ERR_IND) { 603*f7333fc2SChia-Yuan Li if (chip->chip_id == RTL8852C) { 604*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_TRXPTCL_ERROR_INDICA [%d]=0x%08x\n", band, 605*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_TRXPTCL_ERROR_INDICA + offset)); 606*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_TRXPTCL_ERROR_INDICA_MASK [%d]=0x%08x\n", band, 607*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_TRXPTCL_ERROR_INDICA_MASK + offset)); 608*f7333fc2SChia-Yuan Li } else { 609*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_TMAC_ERR_IMR_ISR [%d]=0x%08x\n", band, 610*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_TMAC_ERR_IMR_ISR + offset)); 611e3ec7017SPing-Ke Shih } 612*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_DBGSEL_TRXPTCL [%d]=0x%08x\n", band, 613*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_DBGSEL_TRXPTCL + offset)); 614*f7333fc2SChia-Yuan Li } 615*f7333fc2SChia-Yuan Li 616*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_CMAC_ERR_IMR [%d]=0x%08x\n", band, 617*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_CMAC_ERR_IMR + offset)); 618*f7333fc2SChia-Yuan Li } 619*f7333fc2SChia-Yuan Li 620*f7333fc2SChia-Yuan Li static void rtw89_mac_dump_err_status(struct rtw89_dev *rtwdev, 621*f7333fc2SChia-Yuan Li enum mac_ax_err_info err) 622*f7333fc2SChia-Yuan Li { 623*f7333fc2SChia-Yuan Li if (err != MAC_AX_ERR_L1_ERR_DMAC && 624*f7333fc2SChia-Yuan Li err != MAC_AX_ERR_L0_PROMOTE_TO_L1 && 625*f7333fc2SChia-Yuan Li err != MAC_AX_ERR_L0_ERR_CMAC0 && 626*f7333fc2SChia-Yuan Li err != MAC_AX_ERR_L0_ERR_CMAC1) 627*f7333fc2SChia-Yuan Li return; 628*f7333fc2SChia-Yuan Li 629*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "--->\nerr=0x%x\n", err); 630*f7333fc2SChia-Yuan Li rtw89_info(rtwdev, "R_AX_SER_DBG_INFO =0x%08x\n", 631*f7333fc2SChia-Yuan Li rtw89_read32(rtwdev, R_AX_SER_DBG_INFO)); 632*f7333fc2SChia-Yuan Li 633*f7333fc2SChia-Yuan Li rtw89_mac_dump_dmac_err_status(rtwdev); 634*f7333fc2SChia-Yuan Li rtw89_mac_dump_cmac_err_status(rtwdev, RTW89_MAC_0); 635*f7333fc2SChia-Yuan Li if (rtwdev->dbcc_en) 636*f7333fc2SChia-Yuan Li rtw89_mac_dump_cmac_err_status(rtwdev, RTW89_MAC_1); 637e3ec7017SPing-Ke Shih 638e3ec7017SPing-Ke Shih rtwdev->hci.ops->dump_err_status(rtwdev); 639e3ec7017SPing-Ke Shih 640e3ec7017SPing-Ke Shih if (err == MAC_AX_ERR_L0_PROMOTE_TO_L1) 641e3ec7017SPing-Ke Shih rtw89_mac_dump_l0_to_l1(rtwdev, err); 642e3ec7017SPing-Ke Shih 643e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "<---\n"); 644e3ec7017SPing-Ke Shih } 645e3ec7017SPing-Ke Shih 646e3ec7017SPing-Ke Shih u32 rtw89_mac_get_err_status(struct rtw89_dev *rtwdev) 647e3ec7017SPing-Ke Shih { 648198b6cf7SZong-Zhe Yang u32 err, err_scnr; 649e3ec7017SPing-Ke Shih int ret; 650e3ec7017SPing-Ke Shih 651e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read32, err, (err != 0), 1000, 100000, 652e3ec7017SPing-Ke Shih false, rtwdev, R_AX_HALT_C2H_CTRL); 653e3ec7017SPing-Ke Shih if (ret) { 654e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "Polling FW err status fail\n"); 655e3ec7017SPing-Ke Shih return ret; 656e3ec7017SPing-Ke Shih } 657e3ec7017SPing-Ke Shih 658e3ec7017SPing-Ke Shih err = rtw89_read32(rtwdev, R_AX_HALT_C2H); 659e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_HALT_C2H_CTRL, 0); 660e3ec7017SPing-Ke Shih 661198b6cf7SZong-Zhe Yang err_scnr = RTW89_ERROR_SCENARIO(err); 662198b6cf7SZong-Zhe Yang if (err_scnr == RTW89_WCPU_CPU_EXCEPTION) 663198b6cf7SZong-Zhe Yang err = MAC_AX_ERR_CPU_EXCEPTION; 664198b6cf7SZong-Zhe Yang else if (err_scnr == RTW89_WCPU_ASSERTION) 665198b6cf7SZong-Zhe Yang err = MAC_AX_ERR_ASSERTION; 666198b6cf7SZong-Zhe Yang 667e3ec7017SPing-Ke Shih rtw89_fw_st_dbg_dump(rtwdev); 668e3ec7017SPing-Ke Shih rtw89_mac_dump_err_status(rtwdev, err); 669e3ec7017SPing-Ke Shih 670e3ec7017SPing-Ke Shih return err; 671e3ec7017SPing-Ke Shih } 672e3ec7017SPing-Ke Shih EXPORT_SYMBOL(rtw89_mac_get_err_status); 673e3ec7017SPing-Ke Shih 674e3ec7017SPing-Ke Shih int rtw89_mac_set_err_status(struct rtw89_dev *rtwdev, u32 err) 675e3ec7017SPing-Ke Shih { 676e3ec7017SPing-Ke Shih u32 halt; 677e3ec7017SPing-Ke Shih int ret = 0; 678e3ec7017SPing-Ke Shih 679e3ec7017SPing-Ke Shih if (err > MAC_AX_SET_ERR_MAX) { 680e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "Bad set-err-status value 0x%08x\n", err); 681e3ec7017SPing-Ke Shih return -EINVAL; 682e3ec7017SPing-Ke Shih } 683e3ec7017SPing-Ke Shih 684e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read32, halt, (halt == 0x0), 1000, 685e3ec7017SPing-Ke Shih 100000, false, rtwdev, R_AX_HALT_H2C_CTRL); 686e3ec7017SPing-Ke Shih if (ret) { 687e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "FW doesn't receive previous msg\n"); 688e3ec7017SPing-Ke Shih return -EFAULT; 689e3ec7017SPing-Ke Shih } 690e3ec7017SPing-Ke Shih 691e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_HALT_H2C, err); 692e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_HALT_H2C_CTRL, B_AX_HALT_H2C_TRIGGER); 693e3ec7017SPing-Ke Shih 694e3ec7017SPing-Ke Shih return 0; 695e3ec7017SPing-Ke Shih } 696e3ec7017SPing-Ke Shih EXPORT_SYMBOL(rtw89_mac_set_err_status); 697e3ec7017SPing-Ke Shih 698e3ec7017SPing-Ke Shih static int hfc_reset_param(struct rtw89_dev *rtwdev) 699e3ec7017SPing-Ke Shih { 700e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 701e3ec7017SPing-Ke Shih struct rtw89_hfc_param_ini param_ini = {NULL}; 702e3ec7017SPing-Ke Shih u8 qta_mode = rtwdev->mac.dle_info.qta_mode; 703e3ec7017SPing-Ke Shih 704e3ec7017SPing-Ke Shih switch (rtwdev->hci.type) { 705e3ec7017SPing-Ke Shih case RTW89_HCI_TYPE_PCIE: 706e3ec7017SPing-Ke Shih param_ini = rtwdev->chip->hfc_param_ini[qta_mode]; 707e3ec7017SPing-Ke Shih param->en = 0; 708e3ec7017SPing-Ke Shih break; 709e3ec7017SPing-Ke Shih default: 710e3ec7017SPing-Ke Shih return -EINVAL; 711e3ec7017SPing-Ke Shih } 712e3ec7017SPing-Ke Shih 713e3ec7017SPing-Ke Shih if (param_ini.pub_cfg) 714e3ec7017SPing-Ke Shih param->pub_cfg = *param_ini.pub_cfg; 715e3ec7017SPing-Ke Shih 716e3ec7017SPing-Ke Shih if (param_ini.prec_cfg) { 717e3ec7017SPing-Ke Shih param->prec_cfg = *param_ini.prec_cfg; 718e3ec7017SPing-Ke Shih rtwdev->hal.sw_amsdu_max_size = 719e3ec7017SPing-Ke Shih param->prec_cfg.wp_ch07_prec * HFC_PAGE_UNIT; 720e3ec7017SPing-Ke Shih } 721e3ec7017SPing-Ke Shih 722e3ec7017SPing-Ke Shih if (param_ini.ch_cfg) 723e3ec7017SPing-Ke Shih param->ch_cfg = param_ini.ch_cfg; 724e3ec7017SPing-Ke Shih 725e3ec7017SPing-Ke Shih memset(¶m->ch_info, 0, sizeof(param->ch_info)); 726e3ec7017SPing-Ke Shih memset(¶m->pub_info, 0, sizeof(param->pub_info)); 727e3ec7017SPing-Ke Shih param->mode = param_ini.mode; 728e3ec7017SPing-Ke Shih 729e3ec7017SPing-Ke Shih return 0; 730e3ec7017SPing-Ke Shih } 731e3ec7017SPing-Ke Shih 732e3ec7017SPing-Ke Shih static int hfc_ch_cfg_chk(struct rtw89_dev *rtwdev, u8 ch) 733e3ec7017SPing-Ke Shih { 734e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 735e3ec7017SPing-Ke Shih const struct rtw89_hfc_ch_cfg *ch_cfg = param->ch_cfg; 736e3ec7017SPing-Ke Shih const struct rtw89_hfc_pub_cfg *pub_cfg = ¶m->pub_cfg; 737e3ec7017SPing-Ke Shih const struct rtw89_hfc_prec_cfg *prec_cfg = ¶m->prec_cfg; 738e3ec7017SPing-Ke Shih 739e3ec7017SPing-Ke Shih if (ch >= RTW89_DMA_CH_NUM) 740e3ec7017SPing-Ke Shih return -EINVAL; 741e3ec7017SPing-Ke Shih 742e3ec7017SPing-Ke Shih if ((ch_cfg[ch].min && ch_cfg[ch].min < prec_cfg->ch011_prec) || 743e3ec7017SPing-Ke Shih ch_cfg[ch].max > pub_cfg->pub_max) 744e3ec7017SPing-Ke Shih return -EINVAL; 745e3ec7017SPing-Ke Shih if (ch_cfg[ch].grp >= grp_num) 746e3ec7017SPing-Ke Shih return -EINVAL; 747e3ec7017SPing-Ke Shih 748e3ec7017SPing-Ke Shih return 0; 749e3ec7017SPing-Ke Shih } 750e3ec7017SPing-Ke Shih 751e3ec7017SPing-Ke Shih static int hfc_pub_info_chk(struct rtw89_dev *rtwdev) 752e3ec7017SPing-Ke Shih { 753e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 754e3ec7017SPing-Ke Shih const struct rtw89_hfc_pub_cfg *cfg = ¶m->pub_cfg; 755e3ec7017SPing-Ke Shih struct rtw89_hfc_pub_info *info = ¶m->pub_info; 756e3ec7017SPing-Ke Shih 757e3ec7017SPing-Ke Shih if (info->g0_used + info->g1_used + info->pub_aval != cfg->pub_max) { 758e3ec7017SPing-Ke Shih if (rtwdev->chip->chip_id == RTL8852A) 759e3ec7017SPing-Ke Shih return 0; 760e3ec7017SPing-Ke Shih else 761e3ec7017SPing-Ke Shih return -EFAULT; 762e3ec7017SPing-Ke Shih } 763e3ec7017SPing-Ke Shih 764e3ec7017SPing-Ke Shih return 0; 765e3ec7017SPing-Ke Shih } 766e3ec7017SPing-Ke Shih 767e3ec7017SPing-Ke Shih static int hfc_pub_cfg_chk(struct rtw89_dev *rtwdev) 768e3ec7017SPing-Ke Shih { 769e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 770e3ec7017SPing-Ke Shih const struct rtw89_hfc_pub_cfg *pub_cfg = ¶m->pub_cfg; 771e3ec7017SPing-Ke Shih 772e3ec7017SPing-Ke Shih if (pub_cfg->grp0 + pub_cfg->grp1 != pub_cfg->pub_max) 773c6477cb2SKevin Lo return -EFAULT; 774e3ec7017SPing-Ke Shih 775e3ec7017SPing-Ke Shih return 0; 776e3ec7017SPing-Ke Shih } 777e3ec7017SPing-Ke Shih 778e3ec7017SPing-Ke Shih static int hfc_ch_ctrl(struct rtw89_dev *rtwdev, u8 ch) 779e3ec7017SPing-Ke Shih { 780ab8a5671SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 781ab8a5671SPing-Ke Shih const struct rtw89_page_regs *regs = chip->page_regs; 782e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 783e3ec7017SPing-Ke Shih const struct rtw89_hfc_ch_cfg *cfg = param->ch_cfg; 784e3ec7017SPing-Ke Shih int ret = 0; 785e3ec7017SPing-Ke Shih u32 val = 0; 786e3ec7017SPing-Ke Shih 787e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 788e3ec7017SPing-Ke Shih if (ret) 789e3ec7017SPing-Ke Shih return ret; 790e3ec7017SPing-Ke Shih 791e3ec7017SPing-Ke Shih ret = hfc_ch_cfg_chk(rtwdev, ch); 792e3ec7017SPing-Ke Shih if (ret) 793e3ec7017SPing-Ke Shih return ret; 794e3ec7017SPing-Ke Shih 795e3ec7017SPing-Ke Shih if (ch > RTW89_DMA_B1HI) 796e3ec7017SPing-Ke Shih return -EINVAL; 797e3ec7017SPing-Ke Shih 798e3ec7017SPing-Ke Shih val = u32_encode_bits(cfg[ch].min, B_AX_MIN_PG_MASK) | 799e3ec7017SPing-Ke Shih u32_encode_bits(cfg[ch].max, B_AX_MAX_PG_MASK) | 800e3ec7017SPing-Ke Shih (cfg[ch].grp ? B_AX_GRP : 0); 801ab8a5671SPing-Ke Shih rtw89_write32(rtwdev, regs->ach_page_ctrl + ch * 4, val); 802e3ec7017SPing-Ke Shih 803e3ec7017SPing-Ke Shih return 0; 804e3ec7017SPing-Ke Shih } 805e3ec7017SPing-Ke Shih 806e3ec7017SPing-Ke Shih static int hfc_upd_ch_info(struct rtw89_dev *rtwdev, u8 ch) 807e3ec7017SPing-Ke Shih { 808ab8a5671SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 809ab8a5671SPing-Ke Shih const struct rtw89_page_regs *regs = chip->page_regs; 810e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 811e3ec7017SPing-Ke Shih struct rtw89_hfc_ch_info *info = param->ch_info; 812e3ec7017SPing-Ke Shih const struct rtw89_hfc_ch_cfg *cfg = param->ch_cfg; 813e3ec7017SPing-Ke Shih u32 val; 814e3ec7017SPing-Ke Shih u32 ret; 815e3ec7017SPing-Ke Shih 816e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 817e3ec7017SPing-Ke Shih if (ret) 818e3ec7017SPing-Ke Shih return ret; 819e3ec7017SPing-Ke Shih 820e3ec7017SPing-Ke Shih if (ch > RTW89_DMA_H2C) 821e3ec7017SPing-Ke Shih return -EINVAL; 822e3ec7017SPing-Ke Shih 823ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->ach_page_info + ch * 4); 824e3ec7017SPing-Ke Shih info[ch].aval = u32_get_bits(val, B_AX_AVAL_PG_MASK); 825e3ec7017SPing-Ke Shih if (ch < RTW89_DMA_H2C) 826e3ec7017SPing-Ke Shih info[ch].used = u32_get_bits(val, B_AX_USE_PG_MASK); 827e3ec7017SPing-Ke Shih else 828e3ec7017SPing-Ke Shih info[ch].used = cfg[ch].min - info[ch].aval; 829e3ec7017SPing-Ke Shih 830e3ec7017SPing-Ke Shih return 0; 831e3ec7017SPing-Ke Shih } 832e3ec7017SPing-Ke Shih 833e3ec7017SPing-Ke Shih static int hfc_pub_ctrl(struct rtw89_dev *rtwdev) 834e3ec7017SPing-Ke Shih { 835ab8a5671SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 836ab8a5671SPing-Ke Shih const struct rtw89_page_regs *regs = chip->page_regs; 837e3ec7017SPing-Ke Shih const struct rtw89_hfc_pub_cfg *cfg = &rtwdev->mac.hfc_param.pub_cfg; 838e3ec7017SPing-Ke Shih u32 val; 839e3ec7017SPing-Ke Shih int ret; 840e3ec7017SPing-Ke Shih 841e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 842e3ec7017SPing-Ke Shih if (ret) 843e3ec7017SPing-Ke Shih return ret; 844e3ec7017SPing-Ke Shih 845e3ec7017SPing-Ke Shih ret = hfc_pub_cfg_chk(rtwdev); 846e3ec7017SPing-Ke Shih if (ret) 847e3ec7017SPing-Ke Shih return ret; 848e3ec7017SPing-Ke Shih 849e3ec7017SPing-Ke Shih val = u32_encode_bits(cfg->grp0, B_AX_PUBPG_G0_MASK) | 850e3ec7017SPing-Ke Shih u32_encode_bits(cfg->grp1, B_AX_PUBPG_G1_MASK); 851ab8a5671SPing-Ke Shih rtw89_write32(rtwdev, regs->pub_page_ctrl1, val); 852e3ec7017SPing-Ke Shih 853e3ec7017SPing-Ke Shih val = u32_encode_bits(cfg->wp_thrd, B_AX_WP_THRD_MASK); 854ab8a5671SPing-Ke Shih rtw89_write32(rtwdev, regs->wp_page_ctrl2, val); 855e3ec7017SPing-Ke Shih 856e3ec7017SPing-Ke Shih return 0; 857e3ec7017SPing-Ke Shih } 858e3ec7017SPing-Ke Shih 859e3ec7017SPing-Ke Shih static int hfc_upd_mix_info(struct rtw89_dev *rtwdev) 860e3ec7017SPing-Ke Shih { 861ab8a5671SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 862ab8a5671SPing-Ke Shih const struct rtw89_page_regs *regs = chip->page_regs; 863e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 864e3ec7017SPing-Ke Shih struct rtw89_hfc_pub_cfg *pub_cfg = ¶m->pub_cfg; 865e3ec7017SPing-Ke Shih struct rtw89_hfc_prec_cfg *prec_cfg = ¶m->prec_cfg; 866e3ec7017SPing-Ke Shih struct rtw89_hfc_pub_info *info = ¶m->pub_info; 867e3ec7017SPing-Ke Shih u32 val; 868e3ec7017SPing-Ke Shih int ret; 869e3ec7017SPing-Ke Shih 870e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 871e3ec7017SPing-Ke Shih if (ret) 872e3ec7017SPing-Ke Shih return ret; 873e3ec7017SPing-Ke Shih 874ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->pub_page_info1); 875e3ec7017SPing-Ke Shih info->g0_used = u32_get_bits(val, B_AX_G0_USE_PG_MASK); 876e3ec7017SPing-Ke Shih info->g1_used = u32_get_bits(val, B_AX_G1_USE_PG_MASK); 877ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->pub_page_info3); 878e3ec7017SPing-Ke Shih info->g0_aval = u32_get_bits(val, B_AX_G0_AVAL_PG_MASK); 879e3ec7017SPing-Ke Shih info->g1_aval = u32_get_bits(val, B_AX_G1_AVAL_PG_MASK); 880e3ec7017SPing-Ke Shih info->pub_aval = 881ab8a5671SPing-Ke Shih u32_get_bits(rtw89_read32(rtwdev, regs->pub_page_info2), 882e3ec7017SPing-Ke Shih B_AX_PUB_AVAL_PG_MASK); 883e3ec7017SPing-Ke Shih info->wp_aval = 884ab8a5671SPing-Ke Shih u32_get_bits(rtw89_read32(rtwdev, regs->wp_page_info1), 885e3ec7017SPing-Ke Shih B_AX_WP_AVAL_PG_MASK); 886e3ec7017SPing-Ke Shih 887ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->hci_fc_ctrl); 888e3ec7017SPing-Ke Shih param->en = val & B_AX_HCI_FC_EN ? 1 : 0; 889e3ec7017SPing-Ke Shih param->h2c_en = val & B_AX_HCI_FC_CH12_EN ? 1 : 0; 890e3ec7017SPing-Ke Shih param->mode = u32_get_bits(val, B_AX_HCI_FC_MODE_MASK); 891e3ec7017SPing-Ke Shih prec_cfg->ch011_full_cond = 892e3ec7017SPing-Ke Shih u32_get_bits(val, B_AX_HCI_FC_WD_FULL_COND_MASK); 893e3ec7017SPing-Ke Shih prec_cfg->h2c_full_cond = 894e3ec7017SPing-Ke Shih u32_get_bits(val, B_AX_HCI_FC_CH12_FULL_COND_MASK); 895e3ec7017SPing-Ke Shih prec_cfg->wp_ch07_full_cond = 896e3ec7017SPing-Ke Shih u32_get_bits(val, B_AX_HCI_FC_WP_CH07_FULL_COND_MASK); 897e3ec7017SPing-Ke Shih prec_cfg->wp_ch811_full_cond = 898e3ec7017SPing-Ke Shih u32_get_bits(val, B_AX_HCI_FC_WP_CH811_FULL_COND_MASK); 899e3ec7017SPing-Ke Shih 900ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->ch_page_ctrl); 901e3ec7017SPing-Ke Shih prec_cfg->ch011_prec = u32_get_bits(val, B_AX_PREC_PAGE_CH011_MASK); 902e3ec7017SPing-Ke Shih prec_cfg->h2c_prec = u32_get_bits(val, B_AX_PREC_PAGE_CH12_MASK); 903e3ec7017SPing-Ke Shih 904ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->pub_page_ctrl2); 905e3ec7017SPing-Ke Shih pub_cfg->pub_max = u32_get_bits(val, B_AX_PUBPG_ALL_MASK); 906e3ec7017SPing-Ke Shih 907ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->wp_page_ctrl1); 908e3ec7017SPing-Ke Shih prec_cfg->wp_ch07_prec = u32_get_bits(val, B_AX_PREC_PAGE_WP_CH07_MASK); 909e3ec7017SPing-Ke Shih prec_cfg->wp_ch811_prec = u32_get_bits(val, B_AX_PREC_PAGE_WP_CH811_MASK); 910e3ec7017SPing-Ke Shih 911ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->wp_page_ctrl2); 912e3ec7017SPing-Ke Shih pub_cfg->wp_thrd = u32_get_bits(val, B_AX_WP_THRD_MASK); 913e3ec7017SPing-Ke Shih 914ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->pub_page_ctrl1); 915e3ec7017SPing-Ke Shih pub_cfg->grp0 = u32_get_bits(val, B_AX_PUBPG_G0_MASK); 916e3ec7017SPing-Ke Shih pub_cfg->grp1 = u32_get_bits(val, B_AX_PUBPG_G1_MASK); 917e3ec7017SPing-Ke Shih 918e3ec7017SPing-Ke Shih ret = hfc_pub_info_chk(rtwdev); 919e3ec7017SPing-Ke Shih if (param->en && ret) 920e3ec7017SPing-Ke Shih return ret; 921e3ec7017SPing-Ke Shih 922e3ec7017SPing-Ke Shih return 0; 923e3ec7017SPing-Ke Shih } 924e3ec7017SPing-Ke Shih 925e3ec7017SPing-Ke Shih static void hfc_h2c_cfg(struct rtw89_dev *rtwdev) 926e3ec7017SPing-Ke Shih { 927ab8a5671SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 928ab8a5671SPing-Ke Shih const struct rtw89_page_regs *regs = chip->page_regs; 929e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 930e3ec7017SPing-Ke Shih const struct rtw89_hfc_prec_cfg *prec_cfg = ¶m->prec_cfg; 931e3ec7017SPing-Ke Shih u32 val; 932e3ec7017SPing-Ke Shih 933e3ec7017SPing-Ke Shih val = u32_encode_bits(prec_cfg->h2c_prec, B_AX_PREC_PAGE_CH12_MASK); 934ab8a5671SPing-Ke Shih rtw89_write32(rtwdev, regs->ch_page_ctrl, val); 935e3ec7017SPing-Ke Shih 936ab8a5671SPing-Ke Shih rtw89_write32_mask(rtwdev, regs->hci_fc_ctrl, 937e3ec7017SPing-Ke Shih B_AX_HCI_FC_CH12_FULL_COND_MASK, 938e3ec7017SPing-Ke Shih prec_cfg->h2c_full_cond); 939e3ec7017SPing-Ke Shih } 940e3ec7017SPing-Ke Shih 941e3ec7017SPing-Ke Shih static void hfc_mix_cfg(struct rtw89_dev *rtwdev) 942e3ec7017SPing-Ke Shih { 943ab8a5671SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 944ab8a5671SPing-Ke Shih const struct rtw89_page_regs *regs = chip->page_regs; 945e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 946e3ec7017SPing-Ke Shih const struct rtw89_hfc_pub_cfg *pub_cfg = ¶m->pub_cfg; 947e3ec7017SPing-Ke Shih const struct rtw89_hfc_prec_cfg *prec_cfg = ¶m->prec_cfg; 948e3ec7017SPing-Ke Shih u32 val; 949e3ec7017SPing-Ke Shih 950e3ec7017SPing-Ke Shih val = u32_encode_bits(prec_cfg->ch011_prec, B_AX_PREC_PAGE_CH011_MASK) | 951e3ec7017SPing-Ke Shih u32_encode_bits(prec_cfg->h2c_prec, B_AX_PREC_PAGE_CH12_MASK); 952ab8a5671SPing-Ke Shih rtw89_write32(rtwdev, regs->ch_page_ctrl, val); 953e3ec7017SPing-Ke Shih 954e3ec7017SPing-Ke Shih val = u32_encode_bits(pub_cfg->pub_max, B_AX_PUBPG_ALL_MASK); 955ab8a5671SPing-Ke Shih rtw89_write32(rtwdev, regs->pub_page_ctrl2, val); 956e3ec7017SPing-Ke Shih 957e3ec7017SPing-Ke Shih val = u32_encode_bits(prec_cfg->wp_ch07_prec, 958e3ec7017SPing-Ke Shih B_AX_PREC_PAGE_WP_CH07_MASK) | 959e3ec7017SPing-Ke Shih u32_encode_bits(prec_cfg->wp_ch811_prec, 960e3ec7017SPing-Ke Shih B_AX_PREC_PAGE_WP_CH811_MASK); 961ab8a5671SPing-Ke Shih rtw89_write32(rtwdev, regs->wp_page_ctrl1, val); 962e3ec7017SPing-Ke Shih 963ab8a5671SPing-Ke Shih val = u32_replace_bits(rtw89_read32(rtwdev, regs->hci_fc_ctrl), 964e3ec7017SPing-Ke Shih param->mode, B_AX_HCI_FC_MODE_MASK); 965e3ec7017SPing-Ke Shih val = u32_replace_bits(val, prec_cfg->ch011_full_cond, 966e3ec7017SPing-Ke Shih B_AX_HCI_FC_WD_FULL_COND_MASK); 967e3ec7017SPing-Ke Shih val = u32_replace_bits(val, prec_cfg->h2c_full_cond, 968e3ec7017SPing-Ke Shih B_AX_HCI_FC_CH12_FULL_COND_MASK); 969e3ec7017SPing-Ke Shih val = u32_replace_bits(val, prec_cfg->wp_ch07_full_cond, 970e3ec7017SPing-Ke Shih B_AX_HCI_FC_WP_CH07_FULL_COND_MASK); 971e3ec7017SPing-Ke Shih val = u32_replace_bits(val, prec_cfg->wp_ch811_full_cond, 972e3ec7017SPing-Ke Shih B_AX_HCI_FC_WP_CH811_FULL_COND_MASK); 973ab8a5671SPing-Ke Shih rtw89_write32(rtwdev, regs->hci_fc_ctrl, val); 974e3ec7017SPing-Ke Shih } 975e3ec7017SPing-Ke Shih 976e3ec7017SPing-Ke Shih static void hfc_func_en(struct rtw89_dev *rtwdev, bool en, bool h2c_en) 977e3ec7017SPing-Ke Shih { 978ab8a5671SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 979ab8a5671SPing-Ke Shih const struct rtw89_page_regs *regs = chip->page_regs; 980e3ec7017SPing-Ke Shih struct rtw89_hfc_param *param = &rtwdev->mac.hfc_param; 981e3ec7017SPing-Ke Shih u32 val; 982e3ec7017SPing-Ke Shih 983ab8a5671SPing-Ke Shih val = rtw89_read32(rtwdev, regs->hci_fc_ctrl); 984e3ec7017SPing-Ke Shih param->en = en; 985e3ec7017SPing-Ke Shih param->h2c_en = h2c_en; 986e3ec7017SPing-Ke Shih val = en ? (val | B_AX_HCI_FC_EN) : (val & ~B_AX_HCI_FC_EN); 987e3ec7017SPing-Ke Shih val = h2c_en ? (val | B_AX_HCI_FC_CH12_EN) : 988e3ec7017SPing-Ke Shih (val & ~B_AX_HCI_FC_CH12_EN); 989ab8a5671SPing-Ke Shih rtw89_write32(rtwdev, regs->hci_fc_ctrl, val); 990e3ec7017SPing-Ke Shih } 991e3ec7017SPing-Ke Shih 992e3ec7017SPing-Ke Shih static int hfc_init(struct rtw89_dev *rtwdev, bool reset, bool en, bool h2c_en) 993e3ec7017SPing-Ke Shih { 994a1b7163aSPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 995a1b7163aSPing-Ke Shih u32 dma_ch_mask = chip->dma_ch_mask; 996e3ec7017SPing-Ke Shih u8 ch; 997e3ec7017SPing-Ke Shih u32 ret = 0; 998e3ec7017SPing-Ke Shih 999e3ec7017SPing-Ke Shih if (reset) 1000e3ec7017SPing-Ke Shih ret = hfc_reset_param(rtwdev); 1001e3ec7017SPing-Ke Shih if (ret) 1002e3ec7017SPing-Ke Shih return ret; 1003e3ec7017SPing-Ke Shih 1004e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 1005e3ec7017SPing-Ke Shih if (ret) 1006e3ec7017SPing-Ke Shih return ret; 1007e3ec7017SPing-Ke Shih 1008e3ec7017SPing-Ke Shih hfc_func_en(rtwdev, false, false); 1009e3ec7017SPing-Ke Shih 1010e3ec7017SPing-Ke Shih if (!en && h2c_en) { 1011e3ec7017SPing-Ke Shih hfc_h2c_cfg(rtwdev); 1012e3ec7017SPing-Ke Shih hfc_func_en(rtwdev, en, h2c_en); 1013e3ec7017SPing-Ke Shih return ret; 1014e3ec7017SPing-Ke Shih } 1015e3ec7017SPing-Ke Shih 1016e3ec7017SPing-Ke Shih for (ch = RTW89_DMA_ACH0; ch < RTW89_DMA_H2C; ch++) { 1017a1b7163aSPing-Ke Shih if (dma_ch_mask & BIT(ch)) 1018a1b7163aSPing-Ke Shih continue; 1019e3ec7017SPing-Ke Shih ret = hfc_ch_ctrl(rtwdev, ch); 1020e3ec7017SPing-Ke Shih if (ret) 1021e3ec7017SPing-Ke Shih return ret; 1022e3ec7017SPing-Ke Shih } 1023e3ec7017SPing-Ke Shih 1024e3ec7017SPing-Ke Shih ret = hfc_pub_ctrl(rtwdev); 1025e3ec7017SPing-Ke Shih if (ret) 1026e3ec7017SPing-Ke Shih return ret; 1027e3ec7017SPing-Ke Shih 1028e3ec7017SPing-Ke Shih hfc_mix_cfg(rtwdev); 1029e3ec7017SPing-Ke Shih if (en || h2c_en) { 1030e3ec7017SPing-Ke Shih hfc_func_en(rtwdev, en, h2c_en); 1031e3ec7017SPing-Ke Shih udelay(10); 1032e3ec7017SPing-Ke Shih } 1033e3ec7017SPing-Ke Shih for (ch = RTW89_DMA_ACH0; ch < RTW89_DMA_H2C; ch++) { 1034a1b7163aSPing-Ke Shih if (dma_ch_mask & BIT(ch)) 1035a1b7163aSPing-Ke Shih continue; 1036e3ec7017SPing-Ke Shih ret = hfc_upd_ch_info(rtwdev, ch); 1037e3ec7017SPing-Ke Shih if (ret) 1038e3ec7017SPing-Ke Shih return ret; 1039e3ec7017SPing-Ke Shih } 1040e3ec7017SPing-Ke Shih ret = hfc_upd_mix_info(rtwdev); 1041e3ec7017SPing-Ke Shih 1042e3ec7017SPing-Ke Shih return ret; 1043e3ec7017SPing-Ke Shih } 1044e3ec7017SPing-Ke Shih 1045e3ec7017SPing-Ke Shih #define PWR_POLL_CNT 2000 1046e3ec7017SPing-Ke Shih static int pwr_cmd_poll(struct rtw89_dev *rtwdev, 1047e3ec7017SPing-Ke Shih const struct rtw89_pwr_cfg *cfg) 1048e3ec7017SPing-Ke Shih { 1049e3ec7017SPing-Ke Shih u8 val = 0; 1050e3ec7017SPing-Ke Shih int ret; 1051e3ec7017SPing-Ke Shih u32 addr = cfg->base == PWR_INTF_MSK_SDIO ? 1052e3ec7017SPing-Ke Shih cfg->addr | SDIO_LOCAL_BASE_ADDR : cfg->addr; 1053e3ec7017SPing-Ke Shih 1054e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read8, val, !((val ^ cfg->val) & cfg->msk), 1055e3ec7017SPing-Ke Shih 1000, 1000 * PWR_POLL_CNT, false, rtwdev, addr); 1056e3ec7017SPing-Ke Shih 1057e3ec7017SPing-Ke Shih if (!ret) 1058e3ec7017SPing-Ke Shih return 0; 1059e3ec7017SPing-Ke Shih 1060e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "[ERR] Polling timeout\n"); 1061e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "[ERR] addr: %X, %X\n", addr, cfg->addr); 1062e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "[ERR] val: %X, %X\n", val, cfg->val); 1063e3ec7017SPing-Ke Shih 1064e3ec7017SPing-Ke Shih return -EBUSY; 1065e3ec7017SPing-Ke Shih } 1066e3ec7017SPing-Ke Shih 1067e3ec7017SPing-Ke Shih static int rtw89_mac_sub_pwr_seq(struct rtw89_dev *rtwdev, u8 cv_msk, 1068e3ec7017SPing-Ke Shih u8 intf_msk, const struct rtw89_pwr_cfg *cfg) 1069e3ec7017SPing-Ke Shih { 1070e3ec7017SPing-Ke Shih const struct rtw89_pwr_cfg *cur_cfg; 1071e3ec7017SPing-Ke Shih u32 addr; 1072e3ec7017SPing-Ke Shih u8 val; 1073e3ec7017SPing-Ke Shih 1074e3ec7017SPing-Ke Shih for (cur_cfg = cfg; cur_cfg->cmd != PWR_CMD_END; cur_cfg++) { 1075e3ec7017SPing-Ke Shih if (!(cur_cfg->intf_msk & intf_msk) || 1076e3ec7017SPing-Ke Shih !(cur_cfg->cv_msk & cv_msk)) 1077e3ec7017SPing-Ke Shih continue; 1078e3ec7017SPing-Ke Shih 1079e3ec7017SPing-Ke Shih switch (cur_cfg->cmd) { 1080e3ec7017SPing-Ke Shih case PWR_CMD_WRITE: 1081e3ec7017SPing-Ke Shih addr = cur_cfg->addr; 1082e3ec7017SPing-Ke Shih 1083e3ec7017SPing-Ke Shih if (cur_cfg->base == PWR_BASE_SDIO) 1084e3ec7017SPing-Ke Shih addr |= SDIO_LOCAL_BASE_ADDR; 1085e3ec7017SPing-Ke Shih 1086e3ec7017SPing-Ke Shih val = rtw89_read8(rtwdev, addr); 1087e3ec7017SPing-Ke Shih val &= ~(cur_cfg->msk); 1088e3ec7017SPing-Ke Shih val |= (cur_cfg->val & cur_cfg->msk); 1089e3ec7017SPing-Ke Shih 1090e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, addr, val); 1091e3ec7017SPing-Ke Shih break; 1092e3ec7017SPing-Ke Shih case PWR_CMD_POLL: 1093e3ec7017SPing-Ke Shih if (pwr_cmd_poll(rtwdev, cur_cfg)) 1094e3ec7017SPing-Ke Shih return -EBUSY; 1095e3ec7017SPing-Ke Shih break; 1096e3ec7017SPing-Ke Shih case PWR_CMD_DELAY: 1097e3ec7017SPing-Ke Shih if (cur_cfg->val == PWR_DELAY_US) 1098e3ec7017SPing-Ke Shih udelay(cur_cfg->addr); 1099e3ec7017SPing-Ke Shih else 1100e3ec7017SPing-Ke Shih fsleep(cur_cfg->addr * 1000); 1101e3ec7017SPing-Ke Shih break; 1102e3ec7017SPing-Ke Shih default: 1103e3ec7017SPing-Ke Shih return -EINVAL; 1104e3ec7017SPing-Ke Shih } 1105e3ec7017SPing-Ke Shih } 1106e3ec7017SPing-Ke Shih 1107e3ec7017SPing-Ke Shih return 0; 1108e3ec7017SPing-Ke Shih } 1109e3ec7017SPing-Ke Shih 1110e3ec7017SPing-Ke Shih static int rtw89_mac_pwr_seq(struct rtw89_dev *rtwdev, 1111e3ec7017SPing-Ke Shih const struct rtw89_pwr_cfg * const *cfg_seq) 1112e3ec7017SPing-Ke Shih { 1113e3ec7017SPing-Ke Shih int ret; 1114e3ec7017SPing-Ke Shih 1115e3ec7017SPing-Ke Shih for (; *cfg_seq; cfg_seq++) { 1116e3ec7017SPing-Ke Shih ret = rtw89_mac_sub_pwr_seq(rtwdev, BIT(rtwdev->hal.cv), 1117e3ec7017SPing-Ke Shih PWR_INTF_MSK_PCIE, *cfg_seq); 1118e3ec7017SPing-Ke Shih if (ret) 1119e3ec7017SPing-Ke Shih return -EBUSY; 1120e3ec7017SPing-Ke Shih } 1121e3ec7017SPing-Ke Shih 1122e3ec7017SPing-Ke Shih return 0; 1123e3ec7017SPing-Ke Shih } 1124e3ec7017SPing-Ke Shih 1125e3ec7017SPing-Ke Shih static enum rtw89_rpwm_req_pwr_state 1126e3ec7017SPing-Ke Shih rtw89_mac_get_req_pwr_state(struct rtw89_dev *rtwdev) 1127e3ec7017SPing-Ke Shih { 1128e3ec7017SPing-Ke Shih enum rtw89_rpwm_req_pwr_state state; 1129e3ec7017SPing-Ke Shih 1130e3ec7017SPing-Ke Shih switch (rtwdev->ps_mode) { 1131e3ec7017SPing-Ke Shih case RTW89_PS_MODE_RFOFF: 1132e3ec7017SPing-Ke Shih state = RTW89_MAC_RPWM_REQ_PWR_STATE_BAND0_RFOFF; 1133e3ec7017SPing-Ke Shih break; 1134e3ec7017SPing-Ke Shih case RTW89_PS_MODE_CLK_GATED: 1135e3ec7017SPing-Ke Shih state = RTW89_MAC_RPWM_REQ_PWR_STATE_CLK_GATED; 1136e3ec7017SPing-Ke Shih break; 1137e3ec7017SPing-Ke Shih case RTW89_PS_MODE_PWR_GATED: 1138e3ec7017SPing-Ke Shih state = RTW89_MAC_RPWM_REQ_PWR_STATE_PWR_GATED; 1139e3ec7017SPing-Ke Shih break; 1140e3ec7017SPing-Ke Shih default: 1141e3ec7017SPing-Ke Shih state = RTW89_MAC_RPWM_REQ_PWR_STATE_ACTIVE; 1142e3ec7017SPing-Ke Shih break; 1143e3ec7017SPing-Ke Shih } 1144e3ec7017SPing-Ke Shih return state; 1145e3ec7017SPing-Ke Shih } 1146e3ec7017SPing-Ke Shih 1147e3ec7017SPing-Ke Shih static void rtw89_mac_send_rpwm(struct rtw89_dev *rtwdev, 11487bfd05ffSChin-Yen Lee enum rtw89_rpwm_req_pwr_state req_pwr_state, 11497bfd05ffSChin-Yen Lee bool notify_wake) 1150e3ec7017SPing-Ke Shih { 1151e3ec7017SPing-Ke Shih u16 request; 1152e3ec7017SPing-Ke Shih 11537bfd05ffSChin-Yen Lee spin_lock_bh(&rtwdev->rpwm_lock); 11547bfd05ffSChin-Yen Lee 1155e3ec7017SPing-Ke Shih request = rtw89_read16(rtwdev, R_AX_RPWM); 1156e3ec7017SPing-Ke Shih request ^= request | PS_RPWM_TOGGLE; 11577bfd05ffSChin-Yen Lee request |= req_pwr_state; 1158e3ec7017SPing-Ke Shih 11597bfd05ffSChin-Yen Lee if (notify_wake) { 11607bfd05ffSChin-Yen Lee request |= PS_RPWM_NOTIFY_WAKE; 11617bfd05ffSChin-Yen Lee } else { 1162e3ec7017SPing-Ke Shih rtwdev->mac.rpwm_seq_num = (rtwdev->mac.rpwm_seq_num + 1) & 1163e3ec7017SPing-Ke Shih RPWM_SEQ_NUM_MAX; 11647bfd05ffSChin-Yen Lee request |= FIELD_PREP(PS_RPWM_SEQ_NUM, 11657bfd05ffSChin-Yen Lee rtwdev->mac.rpwm_seq_num); 1166e3ec7017SPing-Ke Shih 1167e3ec7017SPing-Ke Shih if (req_pwr_state < RTW89_MAC_RPWM_REQ_PWR_STATE_CLK_GATED) 1168e3ec7017SPing-Ke Shih request |= PS_RPWM_ACK; 11697bfd05ffSChin-Yen Lee } 1170e3ec7017SPing-Ke Shih rtw89_write16(rtwdev, rtwdev->hci.rpwm_addr, request); 11717bfd05ffSChin-Yen Lee 11727bfd05ffSChin-Yen Lee spin_unlock_bh(&rtwdev->rpwm_lock); 1173e3ec7017SPing-Ke Shih } 1174e3ec7017SPing-Ke Shih 1175e3ec7017SPing-Ke Shih static int rtw89_mac_check_cpwm_state(struct rtw89_dev *rtwdev, 1176e3ec7017SPing-Ke Shih enum rtw89_rpwm_req_pwr_state req_pwr_state) 1177e3ec7017SPing-Ke Shih { 1178e3ec7017SPing-Ke Shih bool request_deep_mode; 1179e3ec7017SPing-Ke Shih bool in_deep_mode; 1180e3ec7017SPing-Ke Shih u8 rpwm_req_num; 1181e3ec7017SPing-Ke Shih u8 cpwm_rsp_seq; 1182e3ec7017SPing-Ke Shih u8 cpwm_seq; 1183e3ec7017SPing-Ke Shih u8 cpwm_status; 1184e3ec7017SPing-Ke Shih 1185e3ec7017SPing-Ke Shih if (req_pwr_state >= RTW89_MAC_RPWM_REQ_PWR_STATE_CLK_GATED) 1186e3ec7017SPing-Ke Shih request_deep_mode = true; 1187e3ec7017SPing-Ke Shih else 1188e3ec7017SPing-Ke Shih request_deep_mode = false; 1189e3ec7017SPing-Ke Shih 1190e3ec7017SPing-Ke Shih if (rtw89_read32_mask(rtwdev, R_AX_LDM, B_AX_EN_32K)) 1191e3ec7017SPing-Ke Shih in_deep_mode = true; 1192e3ec7017SPing-Ke Shih else 1193e3ec7017SPing-Ke Shih in_deep_mode = false; 1194e3ec7017SPing-Ke Shih 1195e3ec7017SPing-Ke Shih if (request_deep_mode != in_deep_mode) 1196e3ec7017SPing-Ke Shih return -EPERM; 1197e3ec7017SPing-Ke Shih 1198e3ec7017SPing-Ke Shih if (request_deep_mode) 1199e3ec7017SPing-Ke Shih return 0; 1200e3ec7017SPing-Ke Shih 1201e3ec7017SPing-Ke Shih rpwm_req_num = rtwdev->mac.rpwm_seq_num; 1202e1757e80SPing-Ke Shih cpwm_rsp_seq = rtw89_read16_mask(rtwdev, rtwdev->hci.cpwm_addr, 1203e3ec7017SPing-Ke Shih PS_CPWM_RSP_SEQ_NUM); 1204e3ec7017SPing-Ke Shih 1205e3ec7017SPing-Ke Shih if (rpwm_req_num != cpwm_rsp_seq) 1206e3ec7017SPing-Ke Shih return -EPERM; 1207e3ec7017SPing-Ke Shih 1208e3ec7017SPing-Ke Shih rtwdev->mac.cpwm_seq_num = (rtwdev->mac.cpwm_seq_num + 1) & 1209e3ec7017SPing-Ke Shih CPWM_SEQ_NUM_MAX; 1210e3ec7017SPing-Ke Shih 1211e1757e80SPing-Ke Shih cpwm_seq = rtw89_read16_mask(rtwdev, rtwdev->hci.cpwm_addr, PS_CPWM_SEQ_NUM); 1212e3ec7017SPing-Ke Shih if (cpwm_seq != rtwdev->mac.cpwm_seq_num) 1213e3ec7017SPing-Ke Shih return -EPERM; 1214e3ec7017SPing-Ke Shih 1215e1757e80SPing-Ke Shih cpwm_status = rtw89_read16_mask(rtwdev, rtwdev->hci.cpwm_addr, PS_CPWM_STATE); 1216e3ec7017SPing-Ke Shih if (cpwm_status != req_pwr_state) 1217e3ec7017SPing-Ke Shih return -EPERM; 1218e3ec7017SPing-Ke Shih 1219e3ec7017SPing-Ke Shih return 0; 1220e3ec7017SPing-Ke Shih } 1221e3ec7017SPing-Ke Shih 1222e3ec7017SPing-Ke Shih void rtw89_mac_power_mode_change(struct rtw89_dev *rtwdev, bool enter) 1223e3ec7017SPing-Ke Shih { 1224e3ec7017SPing-Ke Shih enum rtw89_rpwm_req_pwr_state state; 122539a76521SPing-Ke Shih unsigned long delay = enter ? 10 : 150; 1226e3ec7017SPing-Ke Shih int ret; 122748c0e347SChin-Yen Lee int i; 1228e3ec7017SPing-Ke Shih 1229e3ec7017SPing-Ke Shih if (enter) 1230e3ec7017SPing-Ke Shih state = rtw89_mac_get_req_pwr_state(rtwdev); 1231e3ec7017SPing-Ke Shih else 1232e3ec7017SPing-Ke Shih state = RTW89_MAC_RPWM_REQ_PWR_STATE_ACTIVE; 1233e3ec7017SPing-Ke Shih 123448c0e347SChin-Yen Lee for (i = 0; i < RPWM_TRY_CNT; i++) { 12357bfd05ffSChin-Yen Lee rtw89_mac_send_rpwm(rtwdev, state, false); 123648c0e347SChin-Yen Lee ret = read_poll_timeout_atomic(rtw89_mac_check_cpwm_state, ret, 123748c0e347SChin-Yen Lee !ret, delay, 15000, false, 123848c0e347SChin-Yen Lee rtwdev, state); 123948c0e347SChin-Yen Lee if (!ret) 124048c0e347SChin-Yen Lee break; 124148c0e347SChin-Yen Lee 124248c0e347SChin-Yen Lee if (i == RPWM_TRY_CNT - 1) 1243e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "firmware failed to ack for %s ps mode\n", 1244e3ec7017SPing-Ke Shih enter ? "entering" : "leaving"); 124548c0e347SChin-Yen Lee else 124648c0e347SChin-Yen Lee rtw89_debug(rtwdev, RTW89_DBG_UNEXP, 124748c0e347SChin-Yen Lee "%d time firmware failed to ack for %s ps mode\n", 124848c0e347SChin-Yen Lee i + 1, enter ? "entering" : "leaving"); 124948c0e347SChin-Yen Lee } 1250e3ec7017SPing-Ke Shih } 1251e3ec7017SPing-Ke Shih 12527bfd05ffSChin-Yen Lee void rtw89_mac_notify_wake(struct rtw89_dev *rtwdev) 12537bfd05ffSChin-Yen Lee { 12547bfd05ffSChin-Yen Lee enum rtw89_rpwm_req_pwr_state state; 12557bfd05ffSChin-Yen Lee 12567bfd05ffSChin-Yen Lee state = rtw89_mac_get_req_pwr_state(rtwdev); 12577bfd05ffSChin-Yen Lee rtw89_mac_send_rpwm(rtwdev, state, true); 12587bfd05ffSChin-Yen Lee } 12597bfd05ffSChin-Yen Lee 1260e3ec7017SPing-Ke Shih static int rtw89_mac_power_switch(struct rtw89_dev *rtwdev, bool on) 1261e3ec7017SPing-Ke Shih { 1262e3ec7017SPing-Ke Shih #define PWR_ACT 1 1263e3ec7017SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 1264e3ec7017SPing-Ke Shih const struct rtw89_pwr_cfg * const *cfg_seq; 12652a7e54dbSPing-Ke Shih int (*cfg_func)(struct rtw89_dev *rtwdev); 1266e3ec7017SPing-Ke Shih int ret; 1267e3ec7017SPing-Ke Shih u8 val; 1268e3ec7017SPing-Ke Shih 12692a7e54dbSPing-Ke Shih if (on) { 1270e3ec7017SPing-Ke Shih cfg_seq = chip->pwr_on_seq; 12712a7e54dbSPing-Ke Shih cfg_func = chip->ops->pwr_on_func; 12722a7e54dbSPing-Ke Shih } else { 1273e3ec7017SPing-Ke Shih cfg_seq = chip->pwr_off_seq; 12742a7e54dbSPing-Ke Shih cfg_func = chip->ops->pwr_off_func; 12752a7e54dbSPing-Ke Shih } 1276e3ec7017SPing-Ke Shih 1277e3ec7017SPing-Ke Shih if (test_bit(RTW89_FLAG_FW_RDY, rtwdev->flags)) 1278e3ec7017SPing-Ke Shih __rtw89_leave_ps_mode(rtwdev); 1279e3ec7017SPing-Ke Shih 1280e3ec7017SPing-Ke Shih val = rtw89_read32_mask(rtwdev, R_AX_IC_PWR_STATE, B_AX_WLMAC_PWR_STE_MASK); 1281e3ec7017SPing-Ke Shih if (on && val == PWR_ACT) { 1282e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "MAC has already powered on\n"); 1283e3ec7017SPing-Ke Shih return -EBUSY; 1284e3ec7017SPing-Ke Shih } 1285e3ec7017SPing-Ke Shih 12862a7e54dbSPing-Ke Shih ret = cfg_func ? cfg_func(rtwdev) : rtw89_mac_pwr_seq(rtwdev, cfg_seq); 1287e3ec7017SPing-Ke Shih if (ret) 1288e3ec7017SPing-Ke Shih return ret; 1289e3ec7017SPing-Ke Shih 1290e3ec7017SPing-Ke Shih if (on) { 1291e3ec7017SPing-Ke Shih set_bit(RTW89_FLAG_POWERON, rtwdev->flags); 1292e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_SCOREBOARD + 3, MAC_AX_NOTIFY_TP_MAJOR); 1293e3ec7017SPing-Ke Shih } else { 1294e3ec7017SPing-Ke Shih clear_bit(RTW89_FLAG_POWERON, rtwdev->flags); 1295e3ec7017SPing-Ke Shih clear_bit(RTW89_FLAG_FW_RDY, rtwdev->flags); 1296e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_SCOREBOARD + 3, MAC_AX_NOTIFY_PWR_MAJOR); 1297967439c7SZong-Zhe Yang rtw89_set_entity_state(rtwdev, false); 1298e3ec7017SPing-Ke Shih } 1299e3ec7017SPing-Ke Shih 1300e3ec7017SPing-Ke Shih return 0; 1301e3ec7017SPing-Ke Shih #undef PWR_ACT 1302e3ec7017SPing-Ke Shih } 1303e3ec7017SPing-Ke Shih 1304e3ec7017SPing-Ke Shih void rtw89_mac_pwr_off(struct rtw89_dev *rtwdev) 1305e3ec7017SPing-Ke Shih { 1306e3ec7017SPing-Ke Shih rtw89_mac_power_switch(rtwdev, false); 1307e3ec7017SPing-Ke Shih } 1308e3ec7017SPing-Ke Shih 1309e3ec7017SPing-Ke Shih static int cmac_func_en(struct rtw89_dev *rtwdev, u8 mac_idx, bool en) 1310e3ec7017SPing-Ke Shih { 1311e3ec7017SPing-Ke Shih u32 func_en = 0; 1312e3ec7017SPing-Ke Shih u32 ck_en = 0; 1313e3ec7017SPing-Ke Shih u32 c1pc_en = 0; 1314e3ec7017SPing-Ke Shih u32 addrl_func_en[] = {R_AX_CMAC_FUNC_EN, R_AX_CMAC_FUNC_EN_C1}; 1315e3ec7017SPing-Ke Shih u32 addrl_ck_en[] = {R_AX_CK_EN, R_AX_CK_EN_C1}; 1316e3ec7017SPing-Ke Shih 1317e3ec7017SPing-Ke Shih func_en = B_AX_CMAC_EN | B_AX_CMAC_TXEN | B_AX_CMAC_RXEN | 1318e3ec7017SPing-Ke Shih B_AX_PHYINTF_EN | B_AX_CMAC_DMA_EN | B_AX_PTCLTOP_EN | 13195cb5562dSPing-Ke Shih B_AX_SCHEDULER_EN | B_AX_TMAC_EN | B_AX_RMAC_EN | 13205cb5562dSPing-Ke Shih B_AX_CMAC_CRPRT; 1321e3ec7017SPing-Ke Shih ck_en = B_AX_CMAC_CKEN | B_AX_PHYINTF_CKEN | B_AX_CMAC_DMA_CKEN | 1322e3ec7017SPing-Ke Shih B_AX_PTCLTOP_CKEN | B_AX_SCHEDULER_CKEN | B_AX_TMAC_CKEN | 1323e3ec7017SPing-Ke Shih B_AX_RMAC_CKEN; 1324e3ec7017SPing-Ke Shih c1pc_en = B_AX_R_SYM_WLCMAC1_PC_EN | 1325e3ec7017SPing-Ke Shih B_AX_R_SYM_WLCMAC1_P1_PC_EN | 1326e3ec7017SPing-Ke Shih B_AX_R_SYM_WLCMAC1_P2_PC_EN | 1327e3ec7017SPing-Ke Shih B_AX_R_SYM_WLCMAC1_P3_PC_EN | 1328e3ec7017SPing-Ke Shih B_AX_R_SYM_WLCMAC1_P4_PC_EN; 1329e3ec7017SPing-Ke Shih 1330e3ec7017SPing-Ke Shih if (en) { 1331e3ec7017SPing-Ke Shih if (mac_idx == RTW89_MAC_1) { 1332e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_AFE_CTRL1, c1pc_en); 1333e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, 1334e3ec7017SPing-Ke Shih B_AX_R_SYM_ISO_CMAC12PP); 1335e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, 1336e3ec7017SPing-Ke Shih B_AX_CMAC1_FEN); 1337e3ec7017SPing-Ke Shih } 1338e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, addrl_ck_en[mac_idx], ck_en); 1339e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, addrl_func_en[mac_idx], func_en); 1340e3ec7017SPing-Ke Shih } else { 1341e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, addrl_func_en[mac_idx], func_en); 1342e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, addrl_ck_en[mac_idx], ck_en); 1343e3ec7017SPing-Ke Shih if (mac_idx == RTW89_MAC_1) { 1344e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, 1345e3ec7017SPing-Ke Shih B_AX_CMAC1_FEN); 1346e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, 1347e3ec7017SPing-Ke Shih B_AX_R_SYM_ISO_CMAC12PP); 1348e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_AFE_CTRL1, c1pc_en); 1349e3ec7017SPing-Ke Shih } 1350e3ec7017SPing-Ke Shih } 1351e3ec7017SPing-Ke Shih 1352e3ec7017SPing-Ke Shih return 0; 1353e3ec7017SPing-Ke Shih } 1354e3ec7017SPing-Ke Shih 1355e3ec7017SPing-Ke Shih static int dmac_func_en(struct rtw89_dev *rtwdev) 1356e3ec7017SPing-Ke Shih { 1357828a4396SChia-Yuan Li enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id; 1358e3ec7017SPing-Ke Shih u32 val32; 1359e3ec7017SPing-Ke Shih 1360828a4396SChia-Yuan Li if (chip_id == RTL8852C) 1361828a4396SChia-Yuan Li val32 = (B_AX_MAC_FUNC_EN | B_AX_DMAC_FUNC_EN | 1362828a4396SChia-Yuan Li B_AX_MAC_SEC_EN | B_AX_DISPATCHER_EN | 1363828a4396SChia-Yuan Li B_AX_DLE_CPUIO_EN | B_AX_PKT_IN_EN | 1364828a4396SChia-Yuan Li B_AX_DMAC_TBL_EN | B_AX_PKT_BUF_EN | 1365828a4396SChia-Yuan Li B_AX_STA_SCH_EN | B_AX_TXPKT_CTRL_EN | 1366828a4396SChia-Yuan Li B_AX_WD_RLS_EN | B_AX_MPDU_PROC_EN | 1367828a4396SChia-Yuan Li B_AX_DMAC_CRPRT | B_AX_H_AXIDMA_EN); 1368828a4396SChia-Yuan Li else 1369828a4396SChia-Yuan Li val32 = (B_AX_MAC_FUNC_EN | B_AX_DMAC_FUNC_EN | 1370828a4396SChia-Yuan Li B_AX_MAC_SEC_EN | B_AX_DISPATCHER_EN | 1371828a4396SChia-Yuan Li B_AX_DLE_CPUIO_EN | B_AX_PKT_IN_EN | 1372828a4396SChia-Yuan Li B_AX_DMAC_TBL_EN | B_AX_PKT_BUF_EN | 1373828a4396SChia-Yuan Li B_AX_STA_SCH_EN | B_AX_TXPKT_CTRL_EN | 1374828a4396SChia-Yuan Li B_AX_WD_RLS_EN | B_AX_MPDU_PROC_EN | 1375828a4396SChia-Yuan Li B_AX_DMAC_CRPRT); 1376e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_DMAC_FUNC_EN, val32); 1377e3ec7017SPing-Ke Shih 1378e3ec7017SPing-Ke Shih val32 = (B_AX_MAC_SEC_CLK_EN | B_AX_DISPATCHER_CLK_EN | 1379e3ec7017SPing-Ke Shih B_AX_DLE_CPUIO_CLK_EN | B_AX_PKT_IN_CLK_EN | 1380e3ec7017SPing-Ke Shih B_AX_STA_SCH_CLK_EN | B_AX_TXPKT_CTRL_CLK_EN | 1381828a4396SChia-Yuan Li B_AX_WD_RLS_CLK_EN | B_AX_BBRPT_CLK_EN); 1382e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_DMAC_CLK_EN, val32); 1383e3ec7017SPing-Ke Shih 138443863efeSChangcheng Deng return 0; 1385e3ec7017SPing-Ke Shih } 1386e3ec7017SPing-Ke Shih 1387e3ec7017SPing-Ke Shih static int chip_func_en(struct rtw89_dev *rtwdev) 1388e3ec7017SPing-Ke Shih { 1389828a4396SChia-Yuan Li enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id; 1390828a4396SChia-Yuan Li 139114b6e9f4SPing-Ke Shih if (chip_id == RTL8852A || chip_id == RTL8852B) 139214b6e9f4SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_SPS_DIG_ON_CTRL0, 1393828a4396SChia-Yuan Li B_AX_OCP_L1_MASK); 1394e3ec7017SPing-Ke Shih 1395e3ec7017SPing-Ke Shih return 0; 1396e3ec7017SPing-Ke Shih } 1397e3ec7017SPing-Ke Shih 1398e3ec7017SPing-Ke Shih static int rtw89_mac_sys_init(struct rtw89_dev *rtwdev) 1399e3ec7017SPing-Ke Shih { 1400e3ec7017SPing-Ke Shih int ret; 1401e3ec7017SPing-Ke Shih 1402e3ec7017SPing-Ke Shih ret = dmac_func_en(rtwdev); 1403e3ec7017SPing-Ke Shih if (ret) 1404e3ec7017SPing-Ke Shih return ret; 1405e3ec7017SPing-Ke Shih 1406e3ec7017SPing-Ke Shih ret = cmac_func_en(rtwdev, 0, true); 1407e3ec7017SPing-Ke Shih if (ret) 1408e3ec7017SPing-Ke Shih return ret; 1409e3ec7017SPing-Ke Shih 1410e3ec7017SPing-Ke Shih ret = chip_func_en(rtwdev); 1411e3ec7017SPing-Ke Shih if (ret) 1412e3ec7017SPing-Ke Shih return ret; 1413e3ec7017SPing-Ke Shih 1414e3ec7017SPing-Ke Shih return ret; 1415e3ec7017SPing-Ke Shih } 1416e3ec7017SPing-Ke Shih 141730645118SPing-Ke Shih const struct rtw89_mac_size_set rtw89_mac_size = { 141830645118SPing-Ke Shih .hfc_preccfg_pcie = {2, 40, 0, 0, 1, 0, 0, 0}, 1419e3ec7017SPing-Ke Shih /* PCIE 64 */ 142030645118SPing-Ke Shih .wde_size0 = {RTW89_WDE_PG_64, 4095, 1,}, 1421e3ec7017SPing-Ke Shih /* DLFW */ 142230645118SPing-Ke Shih .wde_size4 = {RTW89_WDE_PG_64, 0, 4096,}, 1423a1cb0971SPing-Ke Shih /* PCIE 64 */ 1424a1cb0971SPing-Ke Shih .wde_size6 = {RTW89_WDE_PG_64, 512, 0,}, 1425a1cb0971SPing-Ke Shih /* DLFW */ 1426a1cb0971SPing-Ke Shih .wde_size9 = {RTW89_WDE_PG_64, 0, 1024,}, 142779d099e0SPing-Ke Shih /* 8852C DLFW */ 142830645118SPing-Ke Shih .wde_size18 = {RTW89_WDE_PG_64, 0, 2048,}, 142979d099e0SPing-Ke Shih /* 8852C PCIE SCC */ 143030645118SPing-Ke Shih .wde_size19 = {RTW89_WDE_PG_64, 3328, 0,}, 1431e3ec7017SPing-Ke Shih /* PCIE */ 143230645118SPing-Ke Shih .ple_size0 = {RTW89_PLE_PG_128, 1520, 16,}, 1433e3ec7017SPing-Ke Shih /* DLFW */ 143430645118SPing-Ke Shih .ple_size4 = {RTW89_PLE_PG_128, 64, 1472,}, 1435a1cb0971SPing-Ke Shih /* PCIE 64 */ 1436a1cb0971SPing-Ke Shih .ple_size6 = {RTW89_PLE_PG_128, 496, 16,}, 1437a1cb0971SPing-Ke Shih /* DLFW */ 1438a1cb0971SPing-Ke Shih .ple_size8 = {RTW89_PLE_PG_128, 64, 960,}, 143979d099e0SPing-Ke Shih /* 8852C DLFW */ 144030645118SPing-Ke Shih .ple_size18 = {RTW89_PLE_PG_128, 2544, 16,}, 144179d099e0SPing-Ke Shih /* 8852C PCIE SCC */ 144230645118SPing-Ke Shih .ple_size19 = {RTW89_PLE_PG_128, 1904, 16,}, 1443e3ec7017SPing-Ke Shih /* PCIE 64 */ 144430645118SPing-Ke Shih .wde_qt0 = {3792, 196, 0, 107,}, 1445e3ec7017SPing-Ke Shih /* DLFW */ 144630645118SPing-Ke Shih .wde_qt4 = {0, 0, 0, 0,}, 1447a1cb0971SPing-Ke Shih /* PCIE 64 */ 1448a1cb0971SPing-Ke Shih .wde_qt6 = {448, 48, 0, 16,}, 144979d099e0SPing-Ke Shih /* 8852C DLFW */ 145030645118SPing-Ke Shih .wde_qt17 = {0, 0, 0, 0,}, 145179d099e0SPing-Ke Shih /* 8852C PCIE SCC */ 145230645118SPing-Ke Shih .wde_qt18 = {3228, 60, 0, 40,}, 1453e3ec7017SPing-Ke Shih /* PCIE SCC */ 145430645118SPing-Ke Shih .ple_qt4 = {264, 0, 16, 20, 26, 13, 356, 0, 32, 40, 8,}, 1455e3ec7017SPing-Ke Shih /* PCIE SCC */ 145630645118SPing-Ke Shih .ple_qt5 = {264, 0, 32, 20, 64, 13, 1101, 0, 64, 128, 120,}, 1457e3ec7017SPing-Ke Shih /* DLFW */ 145830645118SPing-Ke Shih .ple_qt13 = {0, 0, 16, 48, 0, 0, 0, 0, 0, 0, 0,}, 1459a1cb0971SPing-Ke Shih /* PCIE 64 */ 1460a1cb0971SPing-Ke Shih .ple_qt18 = {147, 0, 16, 20, 17, 13, 89, 0, 32, 14, 8, 0,}, 146179d099e0SPing-Ke Shih /* DLFW 52C */ 146230645118SPing-Ke Shih .ple_qt44 = {0, 0, 16, 256, 0, 0, 0, 0, 0, 0, 0, 0,}, 146379d099e0SPing-Ke Shih /* DLFW 52C */ 146430645118SPing-Ke Shih .ple_qt45 = {0, 0, 32, 256, 0, 0, 0, 0, 0, 0, 0, 0,}, 146579d099e0SPing-Ke Shih /* 8852C PCIE SCC */ 146630645118SPing-Ke Shih .ple_qt46 = {525, 0, 16, 20, 13, 13, 178, 0, 32, 62, 8, 16,}, 146779d099e0SPing-Ke Shih /* 8852C PCIE SCC */ 146830645118SPing-Ke Shih .ple_qt47 = {525, 0, 32, 20, 1034, 13, 1199, 0, 1053, 62, 160, 1037,}, 1469a1cb0971SPing-Ke Shih /* PCIE 64 */ 1470a1cb0971SPing-Ke Shih .ple_qt58 = {147, 0, 16, 20, 157, 13, 229, 0, 172, 14, 24, 0,}, 14717a68ec3dSChih-Kang Chang /* 8852A PCIE WOW */ 14727a68ec3dSChih-Kang Chang .ple_qt_52a_wow = {264, 0, 32, 20, 64, 13, 1005, 0, 64, 128, 120,}, 147379d099e0SPing-Ke Shih }; 147430645118SPing-Ke Shih EXPORT_SYMBOL(rtw89_mac_size); 147579d099e0SPing-Ke Shih 1476e3ec7017SPing-Ke Shih static const struct rtw89_dle_mem *get_dle_mem_cfg(struct rtw89_dev *rtwdev, 1477e3ec7017SPing-Ke Shih enum rtw89_qta_mode mode) 1478e3ec7017SPing-Ke Shih { 1479e3ec7017SPing-Ke Shih struct rtw89_mac_info *mac = &rtwdev->mac; 1480e3ec7017SPing-Ke Shih const struct rtw89_dle_mem *cfg; 1481e3ec7017SPing-Ke Shih 1482e3ec7017SPing-Ke Shih cfg = &rtwdev->chip->dle_mem[mode]; 1483e3ec7017SPing-Ke Shih if (!cfg) 1484e3ec7017SPing-Ke Shih return NULL; 1485e3ec7017SPing-Ke Shih 1486e3ec7017SPing-Ke Shih if (cfg->mode != mode) { 1487e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "qta mode unmatch!\n"); 1488e3ec7017SPing-Ke Shih return NULL; 1489e3ec7017SPing-Ke Shih } 1490e3ec7017SPing-Ke Shih 1491e3ec7017SPing-Ke Shih mac->dle_info.wde_pg_size = cfg->wde_size->pge_size; 1492e3ec7017SPing-Ke Shih mac->dle_info.ple_pg_size = cfg->ple_size->pge_size; 1493e3ec7017SPing-Ke Shih mac->dle_info.qta_mode = mode; 1494e3ec7017SPing-Ke Shih mac->dle_info.c0_rx_qta = cfg->ple_min_qt->cma0_dma; 1495e3ec7017SPing-Ke Shih mac->dle_info.c1_rx_qta = cfg->ple_min_qt->cma1_dma; 1496e3ec7017SPing-Ke Shih 1497e3ec7017SPing-Ke Shih return cfg; 1498e3ec7017SPing-Ke Shih } 1499e3ec7017SPing-Ke Shih 150041d56769SChih-Kang Chang static bool mac_is_txq_empty(struct rtw89_dev *rtwdev) 150141d56769SChih-Kang Chang { 150241d56769SChih-Kang Chang struct rtw89_mac_dle_dfi_qempty qempty; 150341d56769SChih-Kang Chang u32 qnum, qtmp, val32, msk32; 150441d56769SChih-Kang Chang int i, j, ret; 150541d56769SChih-Kang Chang 150641d56769SChih-Kang Chang qnum = rtwdev->chip->wde_qempty_acq_num; 150741d56769SChih-Kang Chang qempty.dle_type = DLE_CTRL_TYPE_WDE; 150841d56769SChih-Kang Chang 150941d56769SChih-Kang Chang for (i = 0; i < qnum; i++) { 151041d56769SChih-Kang Chang qempty.grpsel = i; 151141d56769SChih-Kang Chang ret = dle_dfi_qempty(rtwdev, &qempty); 151241d56769SChih-Kang Chang if (ret) { 151341d56769SChih-Kang Chang rtw89_warn(rtwdev, "dle dfi acq empty %d\n", ret); 151441d56769SChih-Kang Chang return false; 151541d56769SChih-Kang Chang } 151641d56769SChih-Kang Chang qtmp = qempty.qempty; 151741d56769SChih-Kang Chang for (j = 0 ; j < QEMP_ACQ_GRP_MACID_NUM; j++) { 151841d56769SChih-Kang Chang val32 = FIELD_GET(QEMP_ACQ_GRP_QSEL_MASK, qtmp); 151941d56769SChih-Kang Chang if (val32 != QEMP_ACQ_GRP_QSEL_MASK) 152041d56769SChih-Kang Chang return false; 152141d56769SChih-Kang Chang qtmp >>= QEMP_ACQ_GRP_QSEL_SH; 152241d56769SChih-Kang Chang } 152341d56769SChih-Kang Chang } 152441d56769SChih-Kang Chang 152541d56769SChih-Kang Chang qempty.grpsel = rtwdev->chip->wde_qempty_mgq_sel; 152641d56769SChih-Kang Chang ret = dle_dfi_qempty(rtwdev, &qempty); 152741d56769SChih-Kang Chang if (ret) { 152841d56769SChih-Kang Chang rtw89_warn(rtwdev, "dle dfi mgq empty %d\n", ret); 152941d56769SChih-Kang Chang return false; 153041d56769SChih-Kang Chang } 153141d56769SChih-Kang Chang msk32 = B_CMAC0_MGQ_NORMAL | B_CMAC0_MGQ_NO_PWRSAV | B_CMAC0_CPUMGQ; 153241d56769SChih-Kang Chang if ((qempty.qempty & msk32) != msk32) 153341d56769SChih-Kang Chang return false; 153441d56769SChih-Kang Chang 153541d56769SChih-Kang Chang if (rtwdev->dbcc_en) { 153641d56769SChih-Kang Chang msk32 |= B_CMAC1_MGQ_NORMAL | B_CMAC1_MGQ_NO_PWRSAV | B_CMAC1_CPUMGQ; 153741d56769SChih-Kang Chang if ((qempty.qempty & msk32) != msk32) 153841d56769SChih-Kang Chang return false; 153941d56769SChih-Kang Chang } 154041d56769SChih-Kang Chang 154141d56769SChih-Kang Chang msk32 = B_AX_WDE_EMPTY_QTA_DMAC_WLAN_CPU | B_AX_WDE_EMPTY_QTA_DMAC_DATA_CPU | 154241d56769SChih-Kang Chang B_AX_PLE_EMPTY_QTA_DMAC_WLAN_CPU | B_AX_PLE_EMPTY_QTA_DMAC_H2C | 154341d56769SChih-Kang Chang B_AX_WDE_EMPTY_QUE_OTHERS | B_AX_PLE_EMPTY_QUE_DMAC_MPDU_TX | 154441d56769SChih-Kang Chang B_AX_WDE_EMPTY_QTA_DMAC_CPUIO | B_AX_PLE_EMPTY_QTA_DMAC_CPUIO | 154541d56769SChih-Kang Chang B_AX_WDE_EMPTY_QUE_DMAC_PKTIN | B_AX_WDE_EMPTY_QTA_DMAC_HIF | 154641d56769SChih-Kang Chang B_AX_PLE_EMPTY_QUE_DMAC_SEC_TX | B_AX_WDE_EMPTY_QTA_DMAC_PKTIN | 154741d56769SChih-Kang Chang B_AX_PLE_EMPTY_QTA_DMAC_B0_TXPL | B_AX_PLE_EMPTY_QTA_DMAC_B1_TXPL | 154841d56769SChih-Kang Chang B_AX_PLE_EMPTY_QTA_DMAC_MPDU_TX; 154941d56769SChih-Kang Chang val32 = rtw89_read32(rtwdev, R_AX_DLE_EMPTY0); 155041d56769SChih-Kang Chang 155141d56769SChih-Kang Chang return (val32 & msk32) == msk32; 155241d56769SChih-Kang Chang } 155341d56769SChih-Kang Chang 1554e3ec7017SPing-Ke Shih static inline u32 dle_used_size(const struct rtw89_dle_size *wde, 1555e3ec7017SPing-Ke Shih const struct rtw89_dle_size *ple) 1556e3ec7017SPing-Ke Shih { 1557e3ec7017SPing-Ke Shih return wde->pge_size * (wde->lnk_pge_num + wde->unlnk_pge_num) + 1558e3ec7017SPing-Ke Shih ple->pge_size * (ple->lnk_pge_num + ple->unlnk_pge_num); 1559e3ec7017SPing-Ke Shih } 1560e3ec7017SPing-Ke Shih 15615f8c35b9SPing-Ke Shih static u32 dle_expected_used_size(struct rtw89_dev *rtwdev, 15625f8c35b9SPing-Ke Shih enum rtw89_qta_mode mode) 15635f8c35b9SPing-Ke Shih { 15645f8c35b9SPing-Ke Shih u32 size = rtwdev->chip->fifo_size; 15655f8c35b9SPing-Ke Shih 15665f8c35b9SPing-Ke Shih if (mode == RTW89_QTA_SCC) 15675f8c35b9SPing-Ke Shih size -= rtwdev->chip->dle_scc_rsvd_size; 15685f8c35b9SPing-Ke Shih 15695f8c35b9SPing-Ke Shih return size; 15705f8c35b9SPing-Ke Shih } 15715f8c35b9SPing-Ke Shih 1572e3ec7017SPing-Ke Shih static void dle_func_en(struct rtw89_dev *rtwdev, bool enable) 1573e3ec7017SPing-Ke Shih { 1574e3ec7017SPing-Ke Shih if (enable) 1575e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_DMAC_FUNC_EN, 1576e3ec7017SPing-Ke Shih B_AX_DLE_WDE_EN | B_AX_DLE_PLE_EN); 1577e3ec7017SPing-Ke Shih else 1578e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_DMAC_FUNC_EN, 1579e3ec7017SPing-Ke Shih B_AX_DLE_WDE_EN | B_AX_DLE_PLE_EN); 1580e3ec7017SPing-Ke Shih } 1581e3ec7017SPing-Ke Shih 1582e3ec7017SPing-Ke Shih static void dle_clk_en(struct rtw89_dev *rtwdev, bool enable) 1583e3ec7017SPing-Ke Shih { 1584e3ec7017SPing-Ke Shih if (enable) 1585e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_DMAC_CLK_EN, 1586e3ec7017SPing-Ke Shih B_AX_DLE_WDE_CLK_EN | B_AX_DLE_PLE_CLK_EN); 1587e3ec7017SPing-Ke Shih else 1588e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_DMAC_CLK_EN, 1589e3ec7017SPing-Ke Shih B_AX_DLE_WDE_CLK_EN | B_AX_DLE_PLE_CLK_EN); 1590e3ec7017SPing-Ke Shih } 1591e3ec7017SPing-Ke Shih 1592e3ec7017SPing-Ke Shih static int dle_mix_cfg(struct rtw89_dev *rtwdev, const struct rtw89_dle_mem *cfg) 1593e3ec7017SPing-Ke Shih { 1594e3ec7017SPing-Ke Shih const struct rtw89_dle_size *size_cfg; 1595e3ec7017SPing-Ke Shih u32 val; 1596e3ec7017SPing-Ke Shih u8 bound = 0; 1597e3ec7017SPing-Ke Shih 1598e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, R_AX_WDE_PKTBUF_CFG); 1599e3ec7017SPing-Ke Shih size_cfg = cfg->wde_size; 1600e3ec7017SPing-Ke Shih 1601e3ec7017SPing-Ke Shih switch (size_cfg->pge_size) { 1602e3ec7017SPing-Ke Shih default: 1603e3ec7017SPing-Ke Shih case RTW89_WDE_PG_64: 1604e3ec7017SPing-Ke Shih val = u32_replace_bits(val, S_AX_WDE_PAGE_SEL_64, 1605e3ec7017SPing-Ke Shih B_AX_WDE_PAGE_SEL_MASK); 1606e3ec7017SPing-Ke Shih break; 1607e3ec7017SPing-Ke Shih case RTW89_WDE_PG_128: 1608e3ec7017SPing-Ke Shih val = u32_replace_bits(val, S_AX_WDE_PAGE_SEL_128, 1609e3ec7017SPing-Ke Shih B_AX_WDE_PAGE_SEL_MASK); 1610e3ec7017SPing-Ke Shih break; 1611e3ec7017SPing-Ke Shih case RTW89_WDE_PG_256: 1612e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]WDE DLE doesn't support 256 byte!\n"); 1613e3ec7017SPing-Ke Shih return -EINVAL; 1614e3ec7017SPing-Ke Shih } 1615e3ec7017SPing-Ke Shih 1616e3ec7017SPing-Ke Shih val = u32_replace_bits(val, bound, B_AX_WDE_START_BOUND_MASK); 1617e3ec7017SPing-Ke Shih val = u32_replace_bits(val, size_cfg->lnk_pge_num, 1618e3ec7017SPing-Ke Shih B_AX_WDE_FREE_PAGE_NUM_MASK); 1619e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_WDE_PKTBUF_CFG, val); 1620e3ec7017SPing-Ke Shih 1621e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, R_AX_PLE_PKTBUF_CFG); 1622e3ec7017SPing-Ke Shih bound = (size_cfg->lnk_pge_num + size_cfg->unlnk_pge_num) 1623e3ec7017SPing-Ke Shih * size_cfg->pge_size / DLE_BOUND_UNIT; 1624e3ec7017SPing-Ke Shih size_cfg = cfg->ple_size; 1625e3ec7017SPing-Ke Shih 1626e3ec7017SPing-Ke Shih switch (size_cfg->pge_size) { 1627e3ec7017SPing-Ke Shih default: 1628e3ec7017SPing-Ke Shih case RTW89_PLE_PG_64: 1629e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]PLE DLE doesn't support 64 byte!\n"); 1630e3ec7017SPing-Ke Shih return -EINVAL; 1631e3ec7017SPing-Ke Shih case RTW89_PLE_PG_128: 1632e3ec7017SPing-Ke Shih val = u32_replace_bits(val, S_AX_PLE_PAGE_SEL_128, 1633e3ec7017SPing-Ke Shih B_AX_PLE_PAGE_SEL_MASK); 1634e3ec7017SPing-Ke Shih break; 1635e3ec7017SPing-Ke Shih case RTW89_PLE_PG_256: 1636e3ec7017SPing-Ke Shih val = u32_replace_bits(val, S_AX_PLE_PAGE_SEL_256, 1637e3ec7017SPing-Ke Shih B_AX_PLE_PAGE_SEL_MASK); 1638e3ec7017SPing-Ke Shih break; 1639e3ec7017SPing-Ke Shih } 1640e3ec7017SPing-Ke Shih 1641e3ec7017SPing-Ke Shih val = u32_replace_bits(val, bound, B_AX_PLE_START_BOUND_MASK); 1642e3ec7017SPing-Ke Shih val = u32_replace_bits(val, size_cfg->lnk_pge_num, 1643e3ec7017SPing-Ke Shih B_AX_PLE_FREE_PAGE_NUM_MASK); 1644e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_PLE_PKTBUF_CFG, val); 1645e3ec7017SPing-Ke Shih 1646e3ec7017SPing-Ke Shih return 0; 1647e3ec7017SPing-Ke Shih } 1648e3ec7017SPing-Ke Shih 1649e3ec7017SPing-Ke Shih #define INVALID_QT_WCPU U16_MAX 1650e3ec7017SPing-Ke Shih #define SET_QUOTA_VAL(_min_x, _max_x, _module, _idx) \ 1651e3ec7017SPing-Ke Shih do { \ 1652e3ec7017SPing-Ke Shih val = ((_min_x) & \ 1653e3ec7017SPing-Ke Shih B_AX_ ## _module ## _MIN_SIZE_MASK) | \ 1654e3ec7017SPing-Ke Shih (((_max_x) << 16) & \ 1655e3ec7017SPing-Ke Shih B_AX_ ## _module ## _MAX_SIZE_MASK); \ 1656e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, \ 1657e3ec7017SPing-Ke Shih R_AX_ ## _module ## _QTA ## _idx ## _CFG, \ 1658e3ec7017SPing-Ke Shih val); \ 1659e3ec7017SPing-Ke Shih } while (0) 1660e3ec7017SPing-Ke Shih #define SET_QUOTA(_x, _module, _idx) \ 1661e3ec7017SPing-Ke Shih SET_QUOTA_VAL(min_cfg->_x, max_cfg->_x, _module, _idx) 1662e3ec7017SPing-Ke Shih 1663e3ec7017SPing-Ke Shih static void wde_quota_cfg(struct rtw89_dev *rtwdev, 1664e3ec7017SPing-Ke Shih const struct rtw89_wde_quota *min_cfg, 1665e3ec7017SPing-Ke Shih const struct rtw89_wde_quota *max_cfg, 1666e3ec7017SPing-Ke Shih u16 ext_wde_min_qt_wcpu) 1667e3ec7017SPing-Ke Shih { 1668e3ec7017SPing-Ke Shih u16 min_qt_wcpu = ext_wde_min_qt_wcpu != INVALID_QT_WCPU ? 1669e3ec7017SPing-Ke Shih ext_wde_min_qt_wcpu : min_cfg->wcpu; 1670e3ec7017SPing-Ke Shih u32 val; 1671e3ec7017SPing-Ke Shih 1672e3ec7017SPing-Ke Shih SET_QUOTA(hif, WDE, 0); 1673e3ec7017SPing-Ke Shih SET_QUOTA_VAL(min_qt_wcpu, max_cfg->wcpu, WDE, 1); 1674e3ec7017SPing-Ke Shih SET_QUOTA(pkt_in, WDE, 3); 1675e3ec7017SPing-Ke Shih SET_QUOTA(cpu_io, WDE, 4); 1676e3ec7017SPing-Ke Shih } 1677e3ec7017SPing-Ke Shih 1678e3ec7017SPing-Ke Shih static void ple_quota_cfg(struct rtw89_dev *rtwdev, 1679e3ec7017SPing-Ke Shih const struct rtw89_ple_quota *min_cfg, 1680e3ec7017SPing-Ke Shih const struct rtw89_ple_quota *max_cfg) 1681e3ec7017SPing-Ke Shih { 1682e3ec7017SPing-Ke Shih u32 val; 1683e3ec7017SPing-Ke Shih 1684e3ec7017SPing-Ke Shih SET_QUOTA(cma0_tx, PLE, 0); 1685e3ec7017SPing-Ke Shih SET_QUOTA(cma1_tx, PLE, 1); 1686e3ec7017SPing-Ke Shih SET_QUOTA(c2h, PLE, 2); 1687e3ec7017SPing-Ke Shih SET_QUOTA(h2c, PLE, 3); 1688e3ec7017SPing-Ke Shih SET_QUOTA(wcpu, PLE, 4); 1689e3ec7017SPing-Ke Shih SET_QUOTA(mpdu_proc, PLE, 5); 1690e3ec7017SPing-Ke Shih SET_QUOTA(cma0_dma, PLE, 6); 1691e3ec7017SPing-Ke Shih SET_QUOTA(cma1_dma, PLE, 7); 1692e3ec7017SPing-Ke Shih SET_QUOTA(bb_rpt, PLE, 8); 1693e3ec7017SPing-Ke Shih SET_QUOTA(wd_rel, PLE, 9); 1694e3ec7017SPing-Ke Shih SET_QUOTA(cpu_io, PLE, 10); 169579d099e0SPing-Ke Shih if (rtwdev->chip->chip_id == RTL8852C) 169679d099e0SPing-Ke Shih SET_QUOTA(tx_rpt, PLE, 11); 1697e3ec7017SPing-Ke Shih } 1698e3ec7017SPing-Ke Shih 16997a68ec3dSChih-Kang Chang int rtw89_mac_resize_ple_rx_quota(struct rtw89_dev *rtwdev, bool wow) 17007a68ec3dSChih-Kang Chang { 17017a68ec3dSChih-Kang Chang const struct rtw89_ple_quota *min_cfg, *max_cfg; 17027a68ec3dSChih-Kang Chang const struct rtw89_dle_mem *cfg; 17037a68ec3dSChih-Kang Chang u32 val; 17047a68ec3dSChih-Kang Chang 17057a68ec3dSChih-Kang Chang if (rtwdev->chip->chip_id == RTL8852C) 17067a68ec3dSChih-Kang Chang return 0; 17077a68ec3dSChih-Kang Chang 17087a68ec3dSChih-Kang Chang if (rtwdev->mac.qta_mode != RTW89_QTA_SCC) { 17097a68ec3dSChih-Kang Chang rtw89_err(rtwdev, "[ERR]support SCC mode only\n"); 17107a68ec3dSChih-Kang Chang return -EINVAL; 17117a68ec3dSChih-Kang Chang } 17127a68ec3dSChih-Kang Chang 17137a68ec3dSChih-Kang Chang if (wow) 17147a68ec3dSChih-Kang Chang cfg = get_dle_mem_cfg(rtwdev, RTW89_QTA_WOW); 17157a68ec3dSChih-Kang Chang else 17167a68ec3dSChih-Kang Chang cfg = get_dle_mem_cfg(rtwdev, RTW89_QTA_SCC); 17177a68ec3dSChih-Kang Chang if (!cfg) { 17187a68ec3dSChih-Kang Chang rtw89_err(rtwdev, "[ERR]get_dle_mem_cfg\n"); 17197a68ec3dSChih-Kang Chang return -EINVAL; 17207a68ec3dSChih-Kang Chang } 17217a68ec3dSChih-Kang Chang 17227a68ec3dSChih-Kang Chang min_cfg = cfg->ple_min_qt; 17237a68ec3dSChih-Kang Chang max_cfg = cfg->ple_max_qt; 17247a68ec3dSChih-Kang Chang SET_QUOTA(cma0_dma, PLE, 6); 17257a68ec3dSChih-Kang Chang SET_QUOTA(cma1_dma, PLE, 7); 17267a68ec3dSChih-Kang Chang 17277a68ec3dSChih-Kang Chang return 0; 17287a68ec3dSChih-Kang Chang } 1729e3ec7017SPing-Ke Shih #undef SET_QUOTA 1730e3ec7017SPing-Ke Shih 173119e28c7fSChin-Yen Lee void rtw89_mac_hw_mgnt_sec(struct rtw89_dev *rtwdev, bool enable) 173219e28c7fSChin-Yen Lee { 173319e28c7fSChin-Yen Lee u32 msk32 = B_AX_UC_MGNT_DEC | B_AX_BMC_MGNT_DEC; 173419e28c7fSChin-Yen Lee 173519e28c7fSChin-Yen Lee if (enable) 173619e28c7fSChin-Yen Lee rtw89_write32_set(rtwdev, R_AX_SEC_ENG_CTRL, msk32); 173719e28c7fSChin-Yen Lee else 173819e28c7fSChin-Yen Lee rtw89_write32_clr(rtwdev, R_AX_SEC_ENG_CTRL, msk32); 173919e28c7fSChin-Yen Lee } 174019e28c7fSChin-Yen Lee 1741e3ec7017SPing-Ke Shih static void dle_quota_cfg(struct rtw89_dev *rtwdev, 1742e3ec7017SPing-Ke Shih const struct rtw89_dle_mem *cfg, 1743e3ec7017SPing-Ke Shih u16 ext_wde_min_qt_wcpu) 1744e3ec7017SPing-Ke Shih { 1745e3ec7017SPing-Ke Shih wde_quota_cfg(rtwdev, cfg->wde_min_qt, cfg->wde_max_qt, ext_wde_min_qt_wcpu); 1746e3ec7017SPing-Ke Shih ple_quota_cfg(rtwdev, cfg->ple_min_qt, cfg->ple_max_qt); 1747e3ec7017SPing-Ke Shih } 1748e3ec7017SPing-Ke Shih 1749e3ec7017SPing-Ke Shih static int dle_init(struct rtw89_dev *rtwdev, enum rtw89_qta_mode mode, 1750e3ec7017SPing-Ke Shih enum rtw89_qta_mode ext_mode) 1751e3ec7017SPing-Ke Shih { 1752e3ec7017SPing-Ke Shih const struct rtw89_dle_mem *cfg, *ext_cfg; 1753e3ec7017SPing-Ke Shih u16 ext_wde_min_qt_wcpu = INVALID_QT_WCPU; 1754e3ec7017SPing-Ke Shih int ret = 0; 1755e3ec7017SPing-Ke Shih u32 ini; 1756e3ec7017SPing-Ke Shih 1757e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 1758e3ec7017SPing-Ke Shih if (ret) 1759e3ec7017SPing-Ke Shih return ret; 1760e3ec7017SPing-Ke Shih 1761e3ec7017SPing-Ke Shih cfg = get_dle_mem_cfg(rtwdev, mode); 1762e3ec7017SPing-Ke Shih if (!cfg) { 1763e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]get_dle_mem_cfg\n"); 1764e3ec7017SPing-Ke Shih ret = -EINVAL; 1765e3ec7017SPing-Ke Shih goto error; 1766e3ec7017SPing-Ke Shih } 1767e3ec7017SPing-Ke Shih 1768e3ec7017SPing-Ke Shih if (mode == RTW89_QTA_DLFW) { 1769e3ec7017SPing-Ke Shih ext_cfg = get_dle_mem_cfg(rtwdev, ext_mode); 1770e3ec7017SPing-Ke Shih if (!ext_cfg) { 1771e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]get_dle_ext_mem_cfg %d\n", 1772e3ec7017SPing-Ke Shih ext_mode); 1773e3ec7017SPing-Ke Shih ret = -EINVAL; 1774e3ec7017SPing-Ke Shih goto error; 1775e3ec7017SPing-Ke Shih } 1776e3ec7017SPing-Ke Shih ext_wde_min_qt_wcpu = ext_cfg->wde_min_qt->wcpu; 1777e3ec7017SPing-Ke Shih } 1778e3ec7017SPing-Ke Shih 17795f8c35b9SPing-Ke Shih if (dle_used_size(cfg->wde_size, cfg->ple_size) != 17805f8c35b9SPing-Ke Shih dle_expected_used_size(rtwdev, mode)) { 1781e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]wd/dle mem cfg\n"); 1782e3ec7017SPing-Ke Shih ret = -EINVAL; 1783e3ec7017SPing-Ke Shih goto error; 1784e3ec7017SPing-Ke Shih } 1785e3ec7017SPing-Ke Shih 1786e3ec7017SPing-Ke Shih dle_func_en(rtwdev, false); 1787e3ec7017SPing-Ke Shih dle_clk_en(rtwdev, true); 1788e3ec7017SPing-Ke Shih 1789e3ec7017SPing-Ke Shih ret = dle_mix_cfg(rtwdev, cfg); 1790e3ec7017SPing-Ke Shih if (ret) { 1791e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR] dle mix cfg\n"); 1792e3ec7017SPing-Ke Shih goto error; 1793e3ec7017SPing-Ke Shih } 1794e3ec7017SPing-Ke Shih dle_quota_cfg(rtwdev, cfg, ext_wde_min_qt_wcpu); 1795e3ec7017SPing-Ke Shih 1796e3ec7017SPing-Ke Shih dle_func_en(rtwdev, true); 1797e3ec7017SPing-Ke Shih 1798e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read32, ini, 1799e3ec7017SPing-Ke Shih (ini & WDE_MGN_INI_RDY) == WDE_MGN_INI_RDY, 1, 1800e3ec7017SPing-Ke Shih 2000, false, rtwdev, R_AX_WDE_INI_STATUS); 1801e3ec7017SPing-Ke Shih if (ret) { 1802e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]WDE cfg ready\n"); 1803e3ec7017SPing-Ke Shih return ret; 1804e3ec7017SPing-Ke Shih } 1805e3ec7017SPing-Ke Shih 1806e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read32, ini, 1807e3ec7017SPing-Ke Shih (ini & WDE_MGN_INI_RDY) == WDE_MGN_INI_RDY, 1, 1808e3ec7017SPing-Ke Shih 2000, false, rtwdev, R_AX_PLE_INI_STATUS); 1809e3ec7017SPing-Ke Shih if (ret) { 1810e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]PLE cfg ready\n"); 1811e3ec7017SPing-Ke Shih return ret; 1812e3ec7017SPing-Ke Shih } 1813e3ec7017SPing-Ke Shih 1814e3ec7017SPing-Ke Shih return 0; 1815e3ec7017SPing-Ke Shih error: 1816e3ec7017SPing-Ke Shih dle_func_en(rtwdev, false); 1817e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]trxcfg wde 0x8900 = %x\n", 1818e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_WDE_INI_STATUS)); 1819e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]trxcfg ple 0x8D00 = %x\n", 1820e3ec7017SPing-Ke Shih rtw89_read32(rtwdev, R_AX_PLE_INI_STATUS)); 1821e3ec7017SPing-Ke Shih 1822e3ec7017SPing-Ke Shih return ret; 1823e3ec7017SPing-Ke Shih } 1824e3ec7017SPing-Ke Shih 1825e07a9968SPing-Ke Shih static int preload_init_set(struct rtw89_dev *rtwdev, enum rtw89_mac_idx mac_idx, 1826e07a9968SPing-Ke Shih enum rtw89_qta_mode mode) 1827e07a9968SPing-Ke Shih { 1828e07a9968SPing-Ke Shih u32 reg, max_preld_size, min_rsvd_size; 1829e07a9968SPing-Ke Shih 1830e07a9968SPing-Ke Shih max_preld_size = (mac_idx == RTW89_MAC_0 ? 1831e07a9968SPing-Ke Shih PRELD_B0_ENT_NUM : PRELD_B1_ENT_NUM) * PRELD_AMSDU_SIZE; 1832e07a9968SPing-Ke Shih reg = mac_idx == RTW89_MAC_0 ? 1833e07a9968SPing-Ke Shih R_AX_TXPKTCTL_B0_PRELD_CFG0 : R_AX_TXPKTCTL_B1_PRELD_CFG0; 1834e07a9968SPing-Ke Shih rtw89_write32_mask(rtwdev, reg, B_AX_B0_PRELD_USEMAXSZ_MASK, max_preld_size); 1835e07a9968SPing-Ke Shih rtw89_write32_set(rtwdev, reg, B_AX_B0_PRELD_FEN); 1836e07a9968SPing-Ke Shih 1837e07a9968SPing-Ke Shih min_rsvd_size = PRELD_AMSDU_SIZE; 1838e07a9968SPing-Ke Shih reg = mac_idx == RTW89_MAC_0 ? 1839e07a9968SPing-Ke Shih R_AX_TXPKTCTL_B0_PRELD_CFG1 : R_AX_TXPKTCTL_B1_PRELD_CFG1; 1840e07a9968SPing-Ke Shih rtw89_write32_mask(rtwdev, reg, B_AX_B0_PRELD_NXT_TXENDWIN_MASK, PRELD_NEXT_WND); 1841e07a9968SPing-Ke Shih rtw89_write32_mask(rtwdev, reg, B_AX_B0_PRELD_NXT_RSVMINSZ_MASK, min_rsvd_size); 1842e07a9968SPing-Ke Shih 1843e07a9968SPing-Ke Shih return 0; 1844e07a9968SPing-Ke Shih } 1845e07a9968SPing-Ke Shih 1846e07a9968SPing-Ke Shih static bool is_qta_poh(struct rtw89_dev *rtwdev) 1847e07a9968SPing-Ke Shih { 1848e07a9968SPing-Ke Shih return rtwdev->hci.type == RTW89_HCI_TYPE_PCIE; 1849e07a9968SPing-Ke Shih } 1850e07a9968SPing-Ke Shih 1851e07a9968SPing-Ke Shih static int preload_init(struct rtw89_dev *rtwdev, enum rtw89_mac_idx mac_idx, 1852e07a9968SPing-Ke Shih enum rtw89_qta_mode mode) 1853e07a9968SPing-Ke Shih { 1854e07a9968SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 1855e07a9968SPing-Ke Shih 1856e07a9968SPing-Ke Shih if (chip->chip_id == RTL8852A || chip->chip_id == RTL8852B || !is_qta_poh(rtwdev)) 1857e07a9968SPing-Ke Shih return 0; 1858e07a9968SPing-Ke Shih 1859e07a9968SPing-Ke Shih return preload_init_set(rtwdev, mac_idx, mode); 1860e07a9968SPing-Ke Shih } 1861e07a9968SPing-Ke Shih 1862e3ec7017SPing-Ke Shih static bool dle_is_txq_empty(struct rtw89_dev *rtwdev) 1863e3ec7017SPing-Ke Shih { 1864e3ec7017SPing-Ke Shih u32 msk32; 1865e3ec7017SPing-Ke Shih u32 val32; 1866e3ec7017SPing-Ke Shih 1867e3ec7017SPing-Ke Shih msk32 = B_AX_WDE_EMPTY_QUE_CMAC0_ALL_AC | B_AX_WDE_EMPTY_QUE_CMAC0_MBH | 1868e3ec7017SPing-Ke Shih B_AX_WDE_EMPTY_QUE_CMAC1_MBH | B_AX_WDE_EMPTY_QUE_CMAC0_WMM0 | 1869e3ec7017SPing-Ke Shih B_AX_WDE_EMPTY_QUE_CMAC0_WMM1 | B_AX_WDE_EMPTY_QUE_OTHERS | 1870e3ec7017SPing-Ke Shih B_AX_PLE_EMPTY_QUE_DMAC_MPDU_TX | B_AX_PLE_EMPTY_QTA_DMAC_H2C | 1871e3ec7017SPing-Ke Shih B_AX_PLE_EMPTY_QUE_DMAC_SEC_TX | B_AX_WDE_EMPTY_QUE_DMAC_PKTIN | 1872e3ec7017SPing-Ke Shih B_AX_WDE_EMPTY_QTA_DMAC_HIF | B_AX_WDE_EMPTY_QTA_DMAC_WLAN_CPU | 1873e3ec7017SPing-Ke Shih B_AX_WDE_EMPTY_QTA_DMAC_PKTIN | B_AX_WDE_EMPTY_QTA_DMAC_CPUIO | 1874e3ec7017SPing-Ke Shih B_AX_PLE_EMPTY_QTA_DMAC_B0_TXPL | 1875e3ec7017SPing-Ke Shih B_AX_PLE_EMPTY_QTA_DMAC_B1_TXPL | 1876e3ec7017SPing-Ke Shih B_AX_PLE_EMPTY_QTA_DMAC_MPDU_TX | 1877e3ec7017SPing-Ke Shih B_AX_PLE_EMPTY_QTA_DMAC_CPUIO | 1878e3ec7017SPing-Ke Shih B_AX_WDE_EMPTY_QTA_DMAC_DATA_CPU | 1879e3ec7017SPing-Ke Shih B_AX_PLE_EMPTY_QTA_DMAC_WLAN_CPU; 1880e3ec7017SPing-Ke Shih val32 = rtw89_read32(rtwdev, R_AX_DLE_EMPTY0); 1881e3ec7017SPing-Ke Shih 1882e3ec7017SPing-Ke Shih if ((val32 & msk32) == msk32) 1883e3ec7017SPing-Ke Shih return true; 1884e3ec7017SPing-Ke Shih 1885e3ec7017SPing-Ke Shih return false; 1886e3ec7017SPing-Ke Shih } 1887e3ec7017SPing-Ke Shih 1888cf7b8b80SPing-Ke Shih static void _patch_ss2f_path(struct rtw89_dev *rtwdev) 1889cf7b8b80SPing-Ke Shih { 1890cf7b8b80SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 1891cf7b8b80SPing-Ke Shih 1892cf7b8b80SPing-Ke Shih if (chip->chip_id == RTL8852A || chip->chip_id == RTL8852B) 1893cf7b8b80SPing-Ke Shih return; 1894cf7b8b80SPing-Ke Shih 1895cf7b8b80SPing-Ke Shih rtw89_write32_mask(rtwdev, R_AX_SS2FINFO_PATH, B_AX_SS_DEST_QUEUE_MASK, 1896cf7b8b80SPing-Ke Shih SS2F_PATH_WLCPU); 1897cf7b8b80SPing-Ke Shih } 1898cf7b8b80SPing-Ke Shih 1899e3ec7017SPing-Ke Shih static int sta_sch_init(struct rtw89_dev *rtwdev) 1900e3ec7017SPing-Ke Shih { 1901e3ec7017SPing-Ke Shih u32 p_val; 1902e3ec7017SPing-Ke Shih u8 val; 1903e3ec7017SPing-Ke Shih int ret; 1904e3ec7017SPing-Ke Shih 1905e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 1906e3ec7017SPing-Ke Shih if (ret) 1907e3ec7017SPing-Ke Shih return ret; 1908e3ec7017SPing-Ke Shih 1909e3ec7017SPing-Ke Shih val = rtw89_read8(rtwdev, R_AX_SS_CTRL); 1910e3ec7017SPing-Ke Shih val |= B_AX_SS_EN; 1911e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_SS_CTRL, val); 1912e3ec7017SPing-Ke Shih 1913e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read32, p_val, p_val & B_AX_SS_INIT_DONE_1, 1914e3ec7017SPing-Ke Shih 1, TRXCFG_WAIT_CNT, false, rtwdev, R_AX_SS_CTRL); 1915e3ec7017SPing-Ke Shih if (ret) { 1916e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]STA scheduler init\n"); 1917e3ec7017SPing-Ke Shih return ret; 1918e3ec7017SPing-Ke Shih } 1919e3ec7017SPing-Ke Shih 19209a1ab283SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_SS_CTRL, B_AX_SS_WARM_INIT_FLG); 19219a1ab283SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_SS_CTRL, B_AX_SS_NONEMPTY_SS2FINFO_EN); 1922cf7b8b80SPing-Ke Shih 1923cf7b8b80SPing-Ke Shih _patch_ss2f_path(rtwdev); 1924e3ec7017SPing-Ke Shih 1925e3ec7017SPing-Ke Shih return 0; 1926e3ec7017SPing-Ke Shih } 1927e3ec7017SPing-Ke Shih 1928e3ec7017SPing-Ke Shih static int mpdu_proc_init(struct rtw89_dev *rtwdev) 1929e3ec7017SPing-Ke Shih { 1930e3ec7017SPing-Ke Shih int ret; 1931e3ec7017SPing-Ke Shih 1932e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 1933e3ec7017SPing-Ke Shih if (ret) 1934e3ec7017SPing-Ke Shih return ret; 1935e3ec7017SPing-Ke Shih 1936e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_ACTION_FWD0, TRXCFG_MPDU_PROC_ACT_FRWD); 1937e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_TF_FWD, TRXCFG_MPDU_PROC_TF_FRWD); 1938e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_MPDU_PROC, 1939e3ec7017SPing-Ke Shih B_AX_APPEND_FCS | B_AX_A_ICV_ERR); 1940e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_CUT_AMSDU_CTRL, TRXCFG_MPDU_PROC_CUT_CTRL); 1941e3ec7017SPing-Ke Shih 1942e3ec7017SPing-Ke Shih return 0; 1943e3ec7017SPing-Ke Shih } 1944e3ec7017SPing-Ke Shih 1945e3ec7017SPing-Ke Shih static int sec_eng_init(struct rtw89_dev *rtwdev) 1946e3ec7017SPing-Ke Shih { 1947b61adeedSPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 1948e3ec7017SPing-Ke Shih u32 val = 0; 1949e3ec7017SPing-Ke Shih int ret; 1950e3ec7017SPing-Ke Shih 1951e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 1952e3ec7017SPing-Ke Shih if (ret) 1953e3ec7017SPing-Ke Shih return ret; 1954e3ec7017SPing-Ke Shih 1955e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, R_AX_SEC_ENG_CTRL); 1956e3ec7017SPing-Ke Shih /* init clock */ 1957e3ec7017SPing-Ke Shih val |= (B_AX_CLK_EN_CGCMP | B_AX_CLK_EN_WAPI | B_AX_CLK_EN_WEP_TKIP); 1958e3ec7017SPing-Ke Shih /* init TX encryption */ 1959e3ec7017SPing-Ke Shih val |= (B_AX_SEC_TX_ENC | B_AX_SEC_RX_DEC); 1960e3ec7017SPing-Ke Shih val |= (B_AX_MC_DEC | B_AX_BC_DEC); 1961b61adeedSPing-Ke Shih if (chip->chip_id == RTL8852A || chip->chip_id == RTL8852B) 1962e3ec7017SPing-Ke Shih val &= ~B_AX_TX_PARTIAL_MODE; 1963e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_SEC_ENG_CTRL, val); 1964e3ec7017SPing-Ke Shih 1965e3ec7017SPing-Ke Shih /* init MIC ICV append */ 1966e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, R_AX_SEC_MPDU_PROC); 1967e3ec7017SPing-Ke Shih val |= (B_AX_APPEND_ICV | B_AX_APPEND_MIC); 1968e3ec7017SPing-Ke Shih 1969e3ec7017SPing-Ke Shih /* option init */ 1970e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_SEC_MPDU_PROC, val); 1971e3ec7017SPing-Ke Shih 1972b61adeedSPing-Ke Shih if (chip->chip_id == RTL8852C) 1973b61adeedSPing-Ke Shih rtw89_write32_mask(rtwdev, R_AX_SEC_DEBUG1, 1974b61adeedSPing-Ke Shih B_AX_TX_TIMEOUT_SEL_MASK, AX_TX_TO_VAL); 1975b61adeedSPing-Ke Shih 1976e3ec7017SPing-Ke Shih return 0; 1977e3ec7017SPing-Ke Shih } 1978e3ec7017SPing-Ke Shih 1979e3ec7017SPing-Ke Shih static int dmac_init(struct rtw89_dev *rtwdev, u8 mac_idx) 1980e3ec7017SPing-Ke Shih { 1981e3ec7017SPing-Ke Shih int ret; 1982e3ec7017SPing-Ke Shih 1983e3ec7017SPing-Ke Shih ret = dle_init(rtwdev, rtwdev->mac.qta_mode, RTW89_QTA_INVALID); 1984e3ec7017SPing-Ke Shih if (ret) { 1985e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]DLE init %d\n", ret); 1986e3ec7017SPing-Ke Shih return ret; 1987e3ec7017SPing-Ke Shih } 1988e3ec7017SPing-Ke Shih 1989e07a9968SPing-Ke Shih ret = preload_init(rtwdev, RTW89_MAC_0, rtwdev->mac.qta_mode); 1990e07a9968SPing-Ke Shih if (ret) { 1991e07a9968SPing-Ke Shih rtw89_err(rtwdev, "[ERR]preload init %d\n", ret); 1992e07a9968SPing-Ke Shih return ret; 1993e07a9968SPing-Ke Shih } 1994e07a9968SPing-Ke Shih 1995e3ec7017SPing-Ke Shih ret = hfc_init(rtwdev, true, true, true); 1996e3ec7017SPing-Ke Shih if (ret) { 1997e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]HCI FC init %d\n", ret); 1998e3ec7017SPing-Ke Shih return ret; 1999e3ec7017SPing-Ke Shih } 2000e3ec7017SPing-Ke Shih 2001e3ec7017SPing-Ke Shih ret = sta_sch_init(rtwdev); 2002e3ec7017SPing-Ke Shih if (ret) { 2003e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]STA SCH init %d\n", ret); 2004e3ec7017SPing-Ke Shih return ret; 2005e3ec7017SPing-Ke Shih } 2006e3ec7017SPing-Ke Shih 2007e3ec7017SPing-Ke Shih ret = mpdu_proc_init(rtwdev); 2008e3ec7017SPing-Ke Shih if (ret) { 2009e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]MPDU Proc init %d\n", ret); 2010e3ec7017SPing-Ke Shih return ret; 2011e3ec7017SPing-Ke Shih } 2012e3ec7017SPing-Ke Shih 2013e3ec7017SPing-Ke Shih ret = sec_eng_init(rtwdev); 2014e3ec7017SPing-Ke Shih if (ret) { 2015e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]Security Engine init %d\n", ret); 2016e3ec7017SPing-Ke Shih return ret; 2017e3ec7017SPing-Ke Shih } 2018e3ec7017SPing-Ke Shih 2019e3ec7017SPing-Ke Shih return ret; 2020e3ec7017SPing-Ke Shih } 2021e3ec7017SPing-Ke Shih 2022e3ec7017SPing-Ke Shih static int addr_cam_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2023e3ec7017SPing-Ke Shih { 2024e3ec7017SPing-Ke Shih u32 val, reg; 2025e3ec7017SPing-Ke Shih u16 p_val; 2026e3ec7017SPing-Ke Shih int ret; 2027e3ec7017SPing-Ke Shih 2028e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2029e3ec7017SPing-Ke Shih if (ret) 2030e3ec7017SPing-Ke Shih return ret; 2031e3ec7017SPing-Ke Shih 2032e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_ADDR_CAM_CTRL, mac_idx); 2033e3ec7017SPing-Ke Shih 2034e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, reg); 2035e3ec7017SPing-Ke Shih val |= u32_encode_bits(0x7f, B_AX_ADDR_CAM_RANGE_MASK) | 2036e3ec7017SPing-Ke Shih B_AX_ADDR_CAM_CLR | B_AX_ADDR_CAM_EN; 2037e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2038e3ec7017SPing-Ke Shih 2039e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read16, p_val, !(p_val & B_AX_ADDR_CAM_CLR), 2040ad275d0aSPing-Ke Shih 1, TRXCFG_WAIT_CNT, false, rtwdev, reg); 2041e3ec7017SPing-Ke Shih if (ret) { 2042e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]ADDR_CAM reset\n"); 2043e3ec7017SPing-Ke Shih return ret; 2044e3ec7017SPing-Ke Shih } 2045e3ec7017SPing-Ke Shih 2046e3ec7017SPing-Ke Shih return 0; 2047e3ec7017SPing-Ke Shih } 2048e3ec7017SPing-Ke Shih 2049e3ec7017SPing-Ke Shih static int scheduler_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2050e3ec7017SPing-Ke Shih { 2051e3ec7017SPing-Ke Shih u32 ret; 2052e3ec7017SPing-Ke Shih u32 reg; 205360b2ede9SChia-Yuan Li u32 val; 2054e3ec7017SPing-Ke Shih 2055e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2056e3ec7017SPing-Ke Shih if (ret) 2057e3ec7017SPing-Ke Shih return ret; 2058e3ec7017SPing-Ke Shih 2059c49154ffSPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_PREBKF_CFG_1, mac_idx); 2060ee546904SChia-Yuan Li if (rtwdev->chip->chip_id == RTL8852C) 2061ee546904SChia-Yuan Li rtw89_write32_mask(rtwdev, reg, B_AX_SIFS_MACTXEN_T1_MASK, 2062ee546904SChia-Yuan Li SIFS_MACTXEN_T1_V1); 2063ee546904SChia-Yuan Li else 2064ee546904SChia-Yuan Li rtw89_write32_mask(rtwdev, reg, B_AX_SIFS_MACTXEN_T1_MASK, 2065ee546904SChia-Yuan Li SIFS_MACTXEN_T1); 2066c49154ffSPing-Ke Shih 2067c49154ffSPing-Ke Shih if (rtwdev->chip->chip_id == RTL8852B) { 2068c49154ffSPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_SCH_EXT_CTRL, mac_idx); 2069c49154ffSPing-Ke Shih rtw89_write32_set(rtwdev, reg, B_AX_PORT_RST_TSF_ADV); 2070c49154ffSPing-Ke Shih } 2071c49154ffSPing-Ke Shih 2072c49154ffSPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_CCA_CFG_0, mac_idx); 2073c49154ffSPing-Ke Shih rtw89_write32_clr(rtwdev, reg, B_AX_BTCCA_EN); 2074c49154ffSPing-Ke Shih 2075e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_PREBKF_CFG_0, mac_idx); 207660b2ede9SChia-Yuan Li if (rtwdev->chip->chip_id == RTL8852C) { 207760b2ede9SChia-Yuan Li val = rtw89_read32_mask(rtwdev, R_AX_SEC_ENG_CTRL, 207860b2ede9SChia-Yuan Li B_AX_TX_PARTIAL_MODE); 207960b2ede9SChia-Yuan Li if (!val) 208060b2ede9SChia-Yuan Li rtw89_write32_mask(rtwdev, reg, B_AX_PREBKF_TIME_MASK, 208160b2ede9SChia-Yuan Li SCH_PREBKF_24US); 208260b2ede9SChia-Yuan Li } else { 208360b2ede9SChia-Yuan Li rtw89_write32_mask(rtwdev, reg, B_AX_PREBKF_TIME_MASK, 208460b2ede9SChia-Yuan Li SCH_PREBKF_24US); 208560b2ede9SChia-Yuan Li } 2086e3ec7017SPing-Ke Shih 2087e3ec7017SPing-Ke Shih return 0; 2088e3ec7017SPing-Ke Shih } 2089e3ec7017SPing-Ke Shih 209019e28c7fSChin-Yen Lee int rtw89_mac_typ_fltr_opt(struct rtw89_dev *rtwdev, 2091e3ec7017SPing-Ke Shih enum rtw89_machdr_frame_type type, 2092e3ec7017SPing-Ke Shih enum rtw89_mac_fwd_target fwd_target, 2093e3ec7017SPing-Ke Shih u8 mac_idx) 2094e3ec7017SPing-Ke Shih { 2095e3ec7017SPing-Ke Shih u32 reg; 2096e3ec7017SPing-Ke Shih u32 val; 2097e3ec7017SPing-Ke Shih 2098e3ec7017SPing-Ke Shih switch (fwd_target) { 2099e3ec7017SPing-Ke Shih case RTW89_FWD_DONT_CARE: 2100e3ec7017SPing-Ke Shih val = RX_FLTR_FRAME_DROP; 2101e3ec7017SPing-Ke Shih break; 2102e3ec7017SPing-Ke Shih case RTW89_FWD_TO_HOST: 2103e3ec7017SPing-Ke Shih val = RX_FLTR_FRAME_TO_HOST; 2104e3ec7017SPing-Ke Shih break; 2105e3ec7017SPing-Ke Shih case RTW89_FWD_TO_WLAN_CPU: 2106e3ec7017SPing-Ke Shih val = RX_FLTR_FRAME_TO_WLCPU; 2107e3ec7017SPing-Ke Shih break; 2108e3ec7017SPing-Ke Shih default: 2109e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]set rx filter fwd target err\n"); 2110e3ec7017SPing-Ke Shih return -EINVAL; 2111e3ec7017SPing-Ke Shih } 2112e3ec7017SPing-Ke Shih 2113e3ec7017SPing-Ke Shih switch (type) { 2114e3ec7017SPing-Ke Shih case RTW89_MGNT: 2115e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_MGNT_FLTR, mac_idx); 2116e3ec7017SPing-Ke Shih break; 2117e3ec7017SPing-Ke Shih case RTW89_CTRL: 2118e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_CTRL_FLTR, mac_idx); 2119e3ec7017SPing-Ke Shih break; 2120e3ec7017SPing-Ke Shih case RTW89_DATA: 2121e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_DATA_FLTR, mac_idx); 2122e3ec7017SPing-Ke Shih break; 2123e3ec7017SPing-Ke Shih default: 2124e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]set rx filter type err\n"); 2125e3ec7017SPing-Ke Shih return -EINVAL; 2126e3ec7017SPing-Ke Shih } 2127e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2128e3ec7017SPing-Ke Shih 2129e3ec7017SPing-Ke Shih return 0; 2130e3ec7017SPing-Ke Shih } 2131e3ec7017SPing-Ke Shih 2132e3ec7017SPing-Ke Shih static int rx_fltr_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2133e3ec7017SPing-Ke Shih { 2134e3ec7017SPing-Ke Shih int ret, i; 2135e3ec7017SPing-Ke Shih u32 mac_ftlr, plcp_ftlr; 2136e3ec7017SPing-Ke Shih 2137e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2138e3ec7017SPing-Ke Shih if (ret) 2139e3ec7017SPing-Ke Shih return ret; 2140e3ec7017SPing-Ke Shih 2141e3ec7017SPing-Ke Shih for (i = RTW89_MGNT; i <= RTW89_DATA; i++) { 2142e3ec7017SPing-Ke Shih ret = rtw89_mac_typ_fltr_opt(rtwdev, i, RTW89_FWD_TO_HOST, 2143e3ec7017SPing-Ke Shih mac_idx); 2144e3ec7017SPing-Ke Shih if (ret) 2145e3ec7017SPing-Ke Shih return ret; 2146e3ec7017SPing-Ke Shih } 2147e3ec7017SPing-Ke Shih mac_ftlr = rtwdev->hal.rx_fltr; 2148e3ec7017SPing-Ke Shih plcp_ftlr = B_AX_CCK_CRC_CHK | B_AX_CCK_SIG_CHK | 2149e3ec7017SPing-Ke Shih B_AX_LSIG_PARITY_CHK_EN | B_AX_SIGA_CRC_CHK | 2150e3ec7017SPing-Ke Shih B_AX_VHT_SU_SIGB_CRC_CHK | B_AX_VHT_MU_SIGB_CRC_CHK | 2151e3ec7017SPing-Ke Shih B_AX_HE_SIGB_CRC_CHK; 2152e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, rtw89_mac_reg_by_idx(R_AX_RX_FLTR_OPT, mac_idx), 2153e3ec7017SPing-Ke Shih mac_ftlr); 2154e3ec7017SPing-Ke Shih rtw89_write16(rtwdev, rtw89_mac_reg_by_idx(R_AX_PLCP_HDR_FLTR, mac_idx), 2155e3ec7017SPing-Ke Shih plcp_ftlr); 2156e3ec7017SPing-Ke Shih 2157e3ec7017SPing-Ke Shih return 0; 2158e3ec7017SPing-Ke Shih } 2159e3ec7017SPing-Ke Shih 2160e3ec7017SPing-Ke Shih static void _patch_dis_resp_chk(struct rtw89_dev *rtwdev, u8 mac_idx) 2161e3ec7017SPing-Ke Shih { 2162e3ec7017SPing-Ke Shih u32 reg, val32; 2163e3ec7017SPing-Ke Shih u32 b_rsp_chk_nav, b_rsp_chk_cca; 2164e3ec7017SPing-Ke Shih 2165e3ec7017SPing-Ke Shih b_rsp_chk_nav = B_AX_RSP_CHK_TXNAV | B_AX_RSP_CHK_INTRA_NAV | 2166e3ec7017SPing-Ke Shih B_AX_RSP_CHK_BASIC_NAV; 2167e3ec7017SPing-Ke Shih b_rsp_chk_cca = B_AX_RSP_CHK_SEC_CCA_80 | B_AX_RSP_CHK_SEC_CCA_40 | 2168e3ec7017SPing-Ke Shih B_AX_RSP_CHK_SEC_CCA_20 | B_AX_RSP_CHK_BTCCA | 2169e3ec7017SPing-Ke Shih B_AX_RSP_CHK_EDCCA | B_AX_RSP_CHK_CCA; 2170e3ec7017SPing-Ke Shih 2171e3ec7017SPing-Ke Shih switch (rtwdev->chip->chip_id) { 2172e3ec7017SPing-Ke Shih case RTL8852A: 2173e3ec7017SPing-Ke Shih case RTL8852B: 2174e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_RSP_CHK_SIG, mac_idx); 2175e3ec7017SPing-Ke Shih val32 = rtw89_read32(rtwdev, reg) & ~b_rsp_chk_nav; 2176e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val32); 2177e3ec7017SPing-Ke Shih 2178e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_0, mac_idx); 2179e3ec7017SPing-Ke Shih val32 = rtw89_read32(rtwdev, reg) & ~b_rsp_chk_cca; 2180e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val32); 2181e3ec7017SPing-Ke Shih break; 2182e3ec7017SPing-Ke Shih default: 2183e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_RSP_CHK_SIG, mac_idx); 2184e3ec7017SPing-Ke Shih val32 = rtw89_read32(rtwdev, reg) | b_rsp_chk_nav; 2185e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val32); 2186e3ec7017SPing-Ke Shih 2187e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_0, mac_idx); 2188e3ec7017SPing-Ke Shih val32 = rtw89_read32(rtwdev, reg) | b_rsp_chk_cca; 2189e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val32); 2190e3ec7017SPing-Ke Shih break; 2191e3ec7017SPing-Ke Shih } 2192e3ec7017SPing-Ke Shih } 2193e3ec7017SPing-Ke Shih 2194e3ec7017SPing-Ke Shih static int cca_ctrl_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2195e3ec7017SPing-Ke Shih { 2196e3ec7017SPing-Ke Shih u32 val, reg; 2197e3ec7017SPing-Ke Shih int ret; 2198e3ec7017SPing-Ke Shih 2199e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2200e3ec7017SPing-Ke Shih if (ret) 2201e3ec7017SPing-Ke Shih return ret; 2202e3ec7017SPing-Ke Shih 2203e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_CCA_CONTROL, mac_idx); 2204e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, reg); 2205e3ec7017SPing-Ke Shih val |= (B_AX_TB_CHK_BASIC_NAV | B_AX_TB_CHK_BTCCA | 2206e3ec7017SPing-Ke Shih B_AX_TB_CHK_EDCCA | B_AX_TB_CHK_CCA_P20 | 2207e3ec7017SPing-Ke Shih B_AX_SIFS_CHK_BTCCA | B_AX_SIFS_CHK_CCA_P20 | 2208e3ec7017SPing-Ke Shih B_AX_CTN_CHK_INTRA_NAV | 2209e3ec7017SPing-Ke Shih B_AX_CTN_CHK_BASIC_NAV | B_AX_CTN_CHK_BTCCA | 2210e3ec7017SPing-Ke Shih B_AX_CTN_CHK_EDCCA | B_AX_CTN_CHK_CCA_S80 | 2211e3ec7017SPing-Ke Shih B_AX_CTN_CHK_CCA_S40 | B_AX_CTN_CHK_CCA_S20 | 221298ed6159SPing-Ke Shih B_AX_CTN_CHK_CCA_P20); 2213e3ec7017SPing-Ke Shih val &= ~(B_AX_TB_CHK_TX_NAV | B_AX_TB_CHK_CCA_S80 | 2214e3ec7017SPing-Ke Shih B_AX_TB_CHK_CCA_S40 | B_AX_TB_CHK_CCA_S20 | 2215e3ec7017SPing-Ke Shih B_AX_SIFS_CHK_CCA_S80 | B_AX_SIFS_CHK_CCA_S40 | 221698ed6159SPing-Ke Shih B_AX_SIFS_CHK_CCA_S20 | B_AX_CTN_CHK_TXNAV | 221798ed6159SPing-Ke Shih B_AX_SIFS_CHK_EDCCA); 2218e3ec7017SPing-Ke Shih 2219e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2220e3ec7017SPing-Ke Shih 2221e3ec7017SPing-Ke Shih _patch_dis_resp_chk(rtwdev, mac_idx); 2222e3ec7017SPing-Ke Shih 2223e3ec7017SPing-Ke Shih return 0; 2224e3ec7017SPing-Ke Shih } 2225e3ec7017SPing-Ke Shih 222619cb9427SPing-Ke Shih static int nav_ctrl_init(struct rtw89_dev *rtwdev) 222719cb9427SPing-Ke Shih { 222819cb9427SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_WMAC_NAV_CTL, B_AX_WMAC_PLCP_UP_NAV_EN | 222919cb9427SPing-Ke Shih B_AX_WMAC_TF_UP_NAV_EN | 223019cb9427SPing-Ke Shih B_AX_WMAC_NAV_UPPER_EN); 2231c060dc51SPing-Ke Shih rtw89_write32_mask(rtwdev, R_AX_WMAC_NAV_CTL, B_AX_WMAC_NAV_UPPER_MASK, NAV_25MS); 223219cb9427SPing-Ke Shih 223319cb9427SPing-Ke Shih return 0; 223419cb9427SPing-Ke Shih } 223519cb9427SPing-Ke Shih 2236e3ec7017SPing-Ke Shih static int spatial_reuse_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2237e3ec7017SPing-Ke Shih { 2238e3ec7017SPing-Ke Shih u32 reg; 2239e3ec7017SPing-Ke Shih int ret; 2240e3ec7017SPing-Ke Shih 2241e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2242e3ec7017SPing-Ke Shih if (ret) 2243e3ec7017SPing-Ke Shih return ret; 2244e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_RX_SR_CTRL, mac_idx); 2245e3ec7017SPing-Ke Shih rtw89_write8_clr(rtwdev, reg, B_AX_SR_EN); 2246e3ec7017SPing-Ke Shih 2247e3ec7017SPing-Ke Shih return 0; 2248e3ec7017SPing-Ke Shih } 2249e3ec7017SPing-Ke Shih 2250e3ec7017SPing-Ke Shih static int tmac_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2251e3ec7017SPing-Ke Shih { 2252e3ec7017SPing-Ke Shih u32 reg; 2253e3ec7017SPing-Ke Shih int ret; 2254e3ec7017SPing-Ke Shih 2255e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2256e3ec7017SPing-Ke Shih if (ret) 2257e3ec7017SPing-Ke Shih return ret; 2258e3ec7017SPing-Ke Shih 2259e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_MAC_LOOPBACK, mac_idx); 2260e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, reg, B_AX_MACLBK_EN); 2261e3ec7017SPing-Ke Shih 226275fd91aaSPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TCR0, mac_idx); 226375fd91aaSPing-Ke Shih rtw89_write32_mask(rtwdev, reg, B_AX_TCR_UDF_THSD_MASK, TCR_UDF_THSD); 226475fd91aaSPing-Ke Shih 226575fd91aaSPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TXD_FIFO_CTRL, mac_idx); 226675fd91aaSPing-Ke Shih rtw89_write32_mask(rtwdev, reg, B_AX_TXDFIFO_HIGH_MCS_THRE_MASK, TXDFIFO_HIGH_MCS_THRE); 226775fd91aaSPing-Ke Shih rtw89_write32_mask(rtwdev, reg, B_AX_TXDFIFO_LOW_MCS_THRE_MASK, TXDFIFO_LOW_MCS_THRE); 226875fd91aaSPing-Ke Shih 2269e3ec7017SPing-Ke Shih return 0; 2270e3ec7017SPing-Ke Shih } 2271e3ec7017SPing-Ke Shih 2272e3ec7017SPing-Ke Shih static int trxptcl_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2273e3ec7017SPing-Ke Shih { 22749ef9edb9SChia-Yuan Li const struct rtw89_chip_info *chip = rtwdev->chip; 22759ef9edb9SChia-Yuan Li const struct rtw89_rrsr_cfgs *rrsr = chip->rrsr_cfgs; 2276e3ec7017SPing-Ke Shih u32 reg, val, sifs; 2277e3ec7017SPing-Ke Shih int ret; 2278e3ec7017SPing-Ke Shih 2279e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2280e3ec7017SPing-Ke Shih if (ret) 2281e3ec7017SPing-Ke Shih return ret; 2282e3ec7017SPing-Ke Shih 2283e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_0, mac_idx); 2284e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, reg); 2285e3ec7017SPing-Ke Shih val &= ~B_AX_WMAC_SPEC_SIFS_CCK_MASK; 2286e3ec7017SPing-Ke Shih val |= FIELD_PREP(B_AX_WMAC_SPEC_SIFS_CCK_MASK, WMAC_SPEC_SIFS_CCK); 2287e3ec7017SPing-Ke Shih 2288e3ec7017SPing-Ke Shih switch (rtwdev->chip->chip_id) { 2289e3ec7017SPing-Ke Shih case RTL8852A: 2290e3ec7017SPing-Ke Shih sifs = WMAC_SPEC_SIFS_OFDM_52A; 2291e3ec7017SPing-Ke Shih break; 2292e3ec7017SPing-Ke Shih case RTL8852B: 2293e3ec7017SPing-Ke Shih sifs = WMAC_SPEC_SIFS_OFDM_52B; 2294e3ec7017SPing-Ke Shih break; 2295e3ec7017SPing-Ke Shih default: 2296e3ec7017SPing-Ke Shih sifs = WMAC_SPEC_SIFS_OFDM_52C; 2297e3ec7017SPing-Ke Shih break; 2298e3ec7017SPing-Ke Shih } 2299e3ec7017SPing-Ke Shih val &= ~B_AX_WMAC_SPEC_SIFS_OFDM_MASK; 2300e3ec7017SPing-Ke Shih val |= FIELD_PREP(B_AX_WMAC_SPEC_SIFS_OFDM_MASK, sifs); 2301e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2302e3ec7017SPing-Ke Shih 2303e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_RXTRIG_TEST_USER_2, mac_idx); 2304e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, reg, B_AX_RXTRIG_FCSCHK_EN); 2305e3ec7017SPing-Ke Shih 23069ef9edb9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(rrsr->ref_rate.addr, mac_idx); 23079ef9edb9SChia-Yuan Li rtw89_write32_mask(rtwdev, reg, rrsr->ref_rate.mask, rrsr->ref_rate.data); 23089ef9edb9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(rrsr->rsc.addr, mac_idx); 23099ef9edb9SChia-Yuan Li rtw89_write32_mask(rtwdev, reg, rrsr->rsc.mask, rrsr->rsc.data); 23109ef9edb9SChia-Yuan Li 2311e3ec7017SPing-Ke Shih return 0; 2312e3ec7017SPing-Ke Shih } 2313e3ec7017SPing-Ke Shih 231418175197SPing-Ke Shih static void rst_bacam(struct rtw89_dev *rtwdev) 231518175197SPing-Ke Shih { 231618175197SPing-Ke Shih u32 val32; 231718175197SPing-Ke Shih int ret; 231818175197SPing-Ke Shih 231918175197SPing-Ke Shih rtw89_write32_mask(rtwdev, R_AX_RESPBA_CAM_CTRL, B_AX_BACAM_RST_MASK, 232018175197SPing-Ke Shih S_AX_BACAM_RST_ALL); 232118175197SPing-Ke Shih 232218175197SPing-Ke Shih ret = read_poll_timeout_atomic(rtw89_read32_mask, val32, val32 == 0, 232318175197SPing-Ke Shih 1, 1000, false, 232418175197SPing-Ke Shih rtwdev, R_AX_RESPBA_CAM_CTRL, B_AX_BACAM_RST_MASK); 232518175197SPing-Ke Shih if (ret) 232618175197SPing-Ke Shih rtw89_warn(rtwdev, "failed to reset BA CAM\n"); 232718175197SPing-Ke Shih } 232818175197SPing-Ke Shih 2329e3ec7017SPing-Ke Shih static int rmac_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2330e3ec7017SPing-Ke Shih { 2331e3ec7017SPing-Ke Shih #define TRXCFG_RMAC_CCA_TO 32 2332e3ec7017SPing-Ke Shih #define TRXCFG_RMAC_DATA_TO 15 2333e3ec7017SPing-Ke Shih #define RX_MAX_LEN_UNIT 512 2334e3ec7017SPing-Ke Shih #define PLD_RLS_MAX_PG 127 23354b0d341bSPing-Ke Shih #define RX_SPEC_MAX_LEN (11454 + RX_MAX_LEN_UNIT) 2336e3ec7017SPing-Ke Shih int ret; 2337e3ec7017SPing-Ke Shih u32 reg, rx_max_len, rx_qta; 2338e3ec7017SPing-Ke Shih u16 val; 2339e3ec7017SPing-Ke Shih 2340e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2341e3ec7017SPing-Ke Shih if (ret) 2342e3ec7017SPing-Ke Shih return ret; 2343e3ec7017SPing-Ke Shih 234418175197SPing-Ke Shih if (mac_idx == RTW89_MAC_0) 234518175197SPing-Ke Shih rst_bacam(rtwdev); 234618175197SPing-Ke Shih 2347e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_RESPBA_CAM_CTRL, mac_idx); 2348e3ec7017SPing-Ke Shih rtw89_write8_set(rtwdev, reg, B_AX_SSN_SEL); 2349e3ec7017SPing-Ke Shih 2350e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_DLK_PROTECT_CTL, mac_idx); 2351e3ec7017SPing-Ke Shih val = rtw89_read16(rtwdev, reg); 2352e3ec7017SPing-Ke Shih val = u16_replace_bits(val, TRXCFG_RMAC_DATA_TO, 2353e3ec7017SPing-Ke Shih B_AX_RX_DLK_DATA_TIME_MASK); 2354e3ec7017SPing-Ke Shih val = u16_replace_bits(val, TRXCFG_RMAC_CCA_TO, 2355e3ec7017SPing-Ke Shih B_AX_RX_DLK_CCA_TIME_MASK); 2356e3ec7017SPing-Ke Shih rtw89_write16(rtwdev, reg, val); 2357e3ec7017SPing-Ke Shih 2358e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_RCR, mac_idx); 2359e3ec7017SPing-Ke Shih rtw89_write8_mask(rtwdev, reg, B_AX_CH_EN_MASK, 0x1); 2360e3ec7017SPing-Ke Shih 2361e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_RX_FLTR_OPT, mac_idx); 2362e3ec7017SPing-Ke Shih if (mac_idx == RTW89_MAC_0) 2363e3ec7017SPing-Ke Shih rx_qta = rtwdev->mac.dle_info.c0_rx_qta; 2364e3ec7017SPing-Ke Shih else 2365e3ec7017SPing-Ke Shih rx_qta = rtwdev->mac.dle_info.c1_rx_qta; 23664b0d341bSPing-Ke Shih rx_qta = min_t(u32, rx_qta, PLD_RLS_MAX_PG); 23674b0d341bSPing-Ke Shih rx_max_len = rx_qta * rtwdev->mac.dle_info.ple_pg_size; 23684b0d341bSPing-Ke Shih rx_max_len = min_t(u32, rx_max_len, RX_SPEC_MAX_LEN); 23694b0d341bSPing-Ke Shih rx_max_len /= RX_MAX_LEN_UNIT; 2370e3ec7017SPing-Ke Shih rtw89_write32_mask(rtwdev, reg, B_AX_RX_MPDU_MAX_LEN_MASK, rx_max_len); 2371e3ec7017SPing-Ke Shih 2372e3ec7017SPing-Ke Shih if (rtwdev->chip->chip_id == RTL8852A && 2373e3ec7017SPing-Ke Shih rtwdev->hal.cv == CHIP_CBV) { 2374e3ec7017SPing-Ke Shih rtw89_write16_mask(rtwdev, 2375e3ec7017SPing-Ke Shih rtw89_mac_reg_by_idx(R_AX_DLK_PROTECT_CTL, mac_idx), 2376e3ec7017SPing-Ke Shih B_AX_RX_DLK_CCA_TIME_MASK, 0); 2377e3ec7017SPing-Ke Shih rtw89_write16_set(rtwdev, rtw89_mac_reg_by_idx(R_AX_RCR, mac_idx), 2378e3ec7017SPing-Ke Shih BIT(12)); 2379e3ec7017SPing-Ke Shih } 2380e3ec7017SPing-Ke Shih 2381e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_PLCP_HDR_FLTR, mac_idx); 2382e3ec7017SPing-Ke Shih rtw89_write8_clr(rtwdev, reg, B_AX_VHT_SU_SIGB_CRC_CHK); 2383e3ec7017SPing-Ke Shih 2384e3ec7017SPing-Ke Shih return ret; 2385e3ec7017SPing-Ke Shih } 2386e3ec7017SPing-Ke Shih 2387e3ec7017SPing-Ke Shih static int cmac_com_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2388e3ec7017SPing-Ke Shih { 23899ef9edb9SChia-Yuan Li enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id; 2390e3ec7017SPing-Ke Shih u32 val, reg; 2391e3ec7017SPing-Ke Shih int ret; 2392e3ec7017SPing-Ke Shih 2393e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2394e3ec7017SPing-Ke Shih if (ret) 2395e3ec7017SPing-Ke Shih return ret; 2396e3ec7017SPing-Ke Shih 2397e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TX_SUB_CARRIER_VALUE, mac_idx); 2398e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, reg); 2399e3ec7017SPing-Ke Shih val = u32_replace_bits(val, 0, B_AX_TXSC_20M_MASK); 2400e3ec7017SPing-Ke Shih val = u32_replace_bits(val, 0, B_AX_TXSC_40M_MASK); 2401e3ec7017SPing-Ke Shih val = u32_replace_bits(val, 0, B_AX_TXSC_80M_MASK); 2402e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2403e3ec7017SPing-Ke Shih 24049ef9edb9SChia-Yuan Li if (chip_id == RTL8852A || chip_id == RTL8852B) { 24059ef9edb9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(R_AX_PTCL_RRSR1, mac_idx); 24069ef9edb9SChia-Yuan Li rtw89_write32_mask(rtwdev, reg, B_AX_RRSR_RATE_EN_MASK, RRSR_OFDM_CCK_EN); 24079ef9edb9SChia-Yuan Li } 24089ef9edb9SChia-Yuan Li 2409e3ec7017SPing-Ke Shih return 0; 2410e3ec7017SPing-Ke Shih } 2411e3ec7017SPing-Ke Shih 2412e3ec7017SPing-Ke Shih static bool is_qta_dbcc(struct rtw89_dev *rtwdev, enum rtw89_qta_mode mode) 2413e3ec7017SPing-Ke Shih { 2414e3ec7017SPing-Ke Shih const struct rtw89_dle_mem *cfg; 2415e3ec7017SPing-Ke Shih 2416e3ec7017SPing-Ke Shih cfg = get_dle_mem_cfg(rtwdev, mode); 2417e3ec7017SPing-Ke Shih if (!cfg) { 2418e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]get_dle_mem_cfg\n"); 2419e3ec7017SPing-Ke Shih return false; 2420e3ec7017SPing-Ke Shih } 2421e3ec7017SPing-Ke Shih 2422e3ec7017SPing-Ke Shih return (cfg->ple_min_qt->cma1_dma && cfg->ple_max_qt->cma1_dma); 2423e3ec7017SPing-Ke Shih } 2424e3ec7017SPing-Ke Shih 2425e3ec7017SPing-Ke Shih static int ptcl_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2426e3ec7017SPing-Ke Shih { 2427e3ec7017SPing-Ke Shih u32 val, reg; 2428e3ec7017SPing-Ke Shih int ret; 2429e3ec7017SPing-Ke Shih 2430e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2431e3ec7017SPing-Ke Shih if (ret) 2432e3ec7017SPing-Ke Shih return ret; 2433e3ec7017SPing-Ke Shih 2434e3ec7017SPing-Ke Shih if (rtwdev->hci.type == RTW89_HCI_TYPE_PCIE) { 2435e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_SIFS_SETTING, mac_idx); 2436e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, reg); 2437e3ec7017SPing-Ke Shih val = u32_replace_bits(val, S_AX_CTS2S_TH_1K, 2438e3ec7017SPing-Ke Shih B_AX_HW_CTS2SELF_PKT_LEN_TH_MASK); 24399fb4862eSPing-Ke Shih val = u32_replace_bits(val, S_AX_CTS2S_TH_SEC_256B, 24409fb4862eSPing-Ke Shih B_AX_HW_CTS2SELF_PKT_LEN_TH_TWW_MASK); 2441e3ec7017SPing-Ke Shih val |= B_AX_HW_CTS2SELF_EN; 2442e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2443e3ec7017SPing-Ke Shih 2444e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_PTCL_FSM_MON, mac_idx); 2445e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, reg); 2446e3ec7017SPing-Ke Shih val = u32_replace_bits(val, S_AX_PTCL_TO_2MS, B_AX_PTCL_TX_ARB_TO_THR_MASK); 2447e3ec7017SPing-Ke Shih val &= ~B_AX_PTCL_TX_ARB_TO_MODE; 2448e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2449e3ec7017SPing-Ke Shih } 2450e3ec7017SPing-Ke Shih 24519fb4862eSPing-Ke Shih if (mac_idx == RTW89_MAC_0) { 24529fb4862eSPing-Ke Shih rtw89_write8_set(rtwdev, R_AX_PTCL_COMMON_SETTING_0, 24539fb4862eSPing-Ke Shih B_AX_CMAC_TX_MODE_0 | B_AX_CMAC_TX_MODE_1); 24549fb4862eSPing-Ke Shih rtw89_write8_clr(rtwdev, R_AX_PTCL_COMMON_SETTING_0, 24559fb4862eSPing-Ke Shih B_AX_PTCL_TRIGGER_SS_EN_0 | 24569fb4862eSPing-Ke Shih B_AX_PTCL_TRIGGER_SS_EN_1 | 24579fb4862eSPing-Ke Shih B_AX_PTCL_TRIGGER_SS_EN_UL); 24589fb4862eSPing-Ke Shih rtw89_write8_mask(rtwdev, R_AX_PTCLRPT_FULL_HDL, 24599fb4862eSPing-Ke Shih B_AX_SPE_RPT_PATH_MASK, FWD_TO_WLCPU); 24609fb4862eSPing-Ke Shih } else if (mac_idx == RTW89_MAC_1) { 24619fb4862eSPing-Ke Shih rtw89_write8_mask(rtwdev, R_AX_PTCLRPT_FULL_HDL_C1, 24629fb4862eSPing-Ke Shih B_AX_SPE_RPT_PATH_MASK, FWD_TO_WLCPU); 24639fb4862eSPing-Ke Shih } 2464e3ec7017SPing-Ke Shih 2465e3ec7017SPing-Ke Shih return 0; 2466e3ec7017SPing-Ke Shih } 2467e3ec7017SPing-Ke Shih 2468a0d99ebbSPing-Ke Shih static int cmac_dma_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2469a0d99ebbSPing-Ke Shih { 2470a0d99ebbSPing-Ke Shih enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id; 2471a0d99ebbSPing-Ke Shih u32 reg; 2472a0d99ebbSPing-Ke Shih int ret; 2473a0d99ebbSPing-Ke Shih 2474a0d99ebbSPing-Ke Shih if (chip_id != RTL8852A && chip_id != RTL8852B) 2475a0d99ebbSPing-Ke Shih return 0; 2476a0d99ebbSPing-Ke Shih 2477a0d99ebbSPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2478a0d99ebbSPing-Ke Shih if (ret) 2479a0d99ebbSPing-Ke Shih return ret; 2480a0d99ebbSPing-Ke Shih 2481a0d99ebbSPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_RXDMA_CTRL_0, mac_idx); 2482a0d99ebbSPing-Ke Shih rtw89_write8_clr(rtwdev, reg, RX_FULL_MODE); 2483a0d99ebbSPing-Ke Shih 2484a0d99ebbSPing-Ke Shih return 0; 2485a0d99ebbSPing-Ke Shih } 2486a0d99ebbSPing-Ke Shih 2487e3ec7017SPing-Ke Shih static int cmac_init(struct rtw89_dev *rtwdev, u8 mac_idx) 2488e3ec7017SPing-Ke Shih { 2489e3ec7017SPing-Ke Shih int ret; 2490e3ec7017SPing-Ke Shih 2491e3ec7017SPing-Ke Shih ret = scheduler_init(rtwdev, mac_idx); 2492e3ec7017SPing-Ke Shih if (ret) { 2493e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d SCH init %d\n", mac_idx, ret); 2494e3ec7017SPing-Ke Shih return ret; 2495e3ec7017SPing-Ke Shih } 2496e3ec7017SPing-Ke Shih 2497e3ec7017SPing-Ke Shih ret = addr_cam_init(rtwdev, mac_idx); 2498e3ec7017SPing-Ke Shih if (ret) { 2499e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d ADDR_CAM reset %d\n", mac_idx, 2500e3ec7017SPing-Ke Shih ret); 2501e3ec7017SPing-Ke Shih return ret; 2502e3ec7017SPing-Ke Shih } 2503e3ec7017SPing-Ke Shih 2504e3ec7017SPing-Ke Shih ret = rx_fltr_init(rtwdev, mac_idx); 2505e3ec7017SPing-Ke Shih if (ret) { 2506e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d RX filter init %d\n", mac_idx, 2507e3ec7017SPing-Ke Shih ret); 2508e3ec7017SPing-Ke Shih return ret; 2509e3ec7017SPing-Ke Shih } 2510e3ec7017SPing-Ke Shih 2511e3ec7017SPing-Ke Shih ret = cca_ctrl_init(rtwdev, mac_idx); 2512e3ec7017SPing-Ke Shih if (ret) { 2513e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d CCA CTRL init %d\n", mac_idx, 2514e3ec7017SPing-Ke Shih ret); 2515e3ec7017SPing-Ke Shih return ret; 2516e3ec7017SPing-Ke Shih } 2517e3ec7017SPing-Ke Shih 251819cb9427SPing-Ke Shih ret = nav_ctrl_init(rtwdev); 251919cb9427SPing-Ke Shih if (ret) { 252019cb9427SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d NAV CTRL init %d\n", mac_idx, 252119cb9427SPing-Ke Shih ret); 252219cb9427SPing-Ke Shih return ret; 252319cb9427SPing-Ke Shih } 252419cb9427SPing-Ke Shih 2525e3ec7017SPing-Ke Shih ret = spatial_reuse_init(rtwdev, mac_idx); 2526e3ec7017SPing-Ke Shih if (ret) { 2527e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d Spatial Reuse init %d\n", 2528e3ec7017SPing-Ke Shih mac_idx, ret); 2529e3ec7017SPing-Ke Shih return ret; 2530e3ec7017SPing-Ke Shih } 2531e3ec7017SPing-Ke Shih 2532e3ec7017SPing-Ke Shih ret = tmac_init(rtwdev, mac_idx); 2533e3ec7017SPing-Ke Shih if (ret) { 2534e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d TMAC init %d\n", mac_idx, ret); 2535e3ec7017SPing-Ke Shih return ret; 2536e3ec7017SPing-Ke Shih } 2537e3ec7017SPing-Ke Shih 2538e3ec7017SPing-Ke Shih ret = trxptcl_init(rtwdev, mac_idx); 2539e3ec7017SPing-Ke Shih if (ret) { 2540e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d TRXPTCL init %d\n", mac_idx, ret); 2541e3ec7017SPing-Ke Shih return ret; 2542e3ec7017SPing-Ke Shih } 2543e3ec7017SPing-Ke Shih 2544e3ec7017SPing-Ke Shih ret = rmac_init(rtwdev, mac_idx); 2545e3ec7017SPing-Ke Shih if (ret) { 2546e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d RMAC init %d\n", mac_idx, ret); 2547e3ec7017SPing-Ke Shih return ret; 2548e3ec7017SPing-Ke Shih } 2549e3ec7017SPing-Ke Shih 2550e3ec7017SPing-Ke Shih ret = cmac_com_init(rtwdev, mac_idx); 2551e3ec7017SPing-Ke Shih if (ret) { 2552e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d Com init %d\n", mac_idx, ret); 2553e3ec7017SPing-Ke Shih return ret; 2554e3ec7017SPing-Ke Shih } 2555e3ec7017SPing-Ke Shih 2556e3ec7017SPing-Ke Shih ret = ptcl_init(rtwdev, mac_idx); 2557e3ec7017SPing-Ke Shih if (ret) { 2558e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d PTCL init %d\n", mac_idx, ret); 2559e3ec7017SPing-Ke Shih return ret; 2560e3ec7017SPing-Ke Shih } 2561e3ec7017SPing-Ke Shih 2562a0d99ebbSPing-Ke Shih ret = cmac_dma_init(rtwdev, mac_idx); 2563a0d99ebbSPing-Ke Shih if (ret) { 2564a0d99ebbSPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d DMA init %d\n", mac_idx, ret); 2565a0d99ebbSPing-Ke Shih return ret; 2566a0d99ebbSPing-Ke Shih } 2567a0d99ebbSPing-Ke Shih 2568e3ec7017SPing-Ke Shih return ret; 2569e3ec7017SPing-Ke Shih } 2570e3ec7017SPing-Ke Shih 2571e3ec7017SPing-Ke Shih static int rtw89_mac_read_phycap(struct rtw89_dev *rtwdev, 2572e3ec7017SPing-Ke Shih struct rtw89_mac_c2h_info *c2h_info) 2573e3ec7017SPing-Ke Shih { 2574e3ec7017SPing-Ke Shih struct rtw89_mac_h2c_info h2c_info = {0}; 2575e3ec7017SPing-Ke Shih u32 ret; 2576e3ec7017SPing-Ke Shih 2577e3ec7017SPing-Ke Shih h2c_info.id = RTW89_FWCMD_H2CREG_FUNC_GET_FEATURE; 2578e3ec7017SPing-Ke Shih h2c_info.content_len = 0; 2579e3ec7017SPing-Ke Shih 2580e3ec7017SPing-Ke Shih ret = rtw89_fw_msg_reg(rtwdev, &h2c_info, c2h_info); 2581e3ec7017SPing-Ke Shih if (ret) 2582e3ec7017SPing-Ke Shih return ret; 2583e3ec7017SPing-Ke Shih 2584e3ec7017SPing-Ke Shih if (c2h_info->id != RTW89_FWCMD_C2HREG_FUNC_PHY_CAP) 2585e3ec7017SPing-Ke Shih return -EINVAL; 2586e3ec7017SPing-Ke Shih 2587e3ec7017SPing-Ke Shih return 0; 2588e3ec7017SPing-Ke Shih } 2589e3ec7017SPing-Ke Shih 2590e3ec7017SPing-Ke Shih int rtw89_mac_setup_phycap(struct rtw89_dev *rtwdev) 2591e3ec7017SPing-Ke Shih { 2592e3ec7017SPing-Ke Shih struct rtw89_hal *hal = &rtwdev->hal; 2593e3ec7017SPing-Ke Shih const struct rtw89_chip_info *chip = rtwdev->chip; 2594e3ec7017SPing-Ke Shih struct rtw89_mac_c2h_info c2h_info = {0}; 2595c7ad08c6SPing-Ke Shih u8 tx_nss; 2596c7ad08c6SPing-Ke Shih u8 rx_nss; 2597dc229d94SPing-Ke Shih u8 tx_ant; 2598dc229d94SPing-Ke Shih u8 rx_ant; 2599e3ec7017SPing-Ke Shih u32 ret; 2600e3ec7017SPing-Ke Shih 2601e3ec7017SPing-Ke Shih ret = rtw89_mac_read_phycap(rtwdev, &c2h_info); 2602e3ec7017SPing-Ke Shih if (ret) 2603e3ec7017SPing-Ke Shih return ret; 2604e3ec7017SPing-Ke Shih 2605c7ad08c6SPing-Ke Shih tx_nss = RTW89_GET_C2H_PHYCAP_TX_NSS(c2h_info.c2hreg); 2606c7ad08c6SPing-Ke Shih rx_nss = RTW89_GET_C2H_PHYCAP_RX_NSS(c2h_info.c2hreg); 2607dc229d94SPing-Ke Shih tx_ant = RTW89_GET_C2H_PHYCAP_ANT_TX_NUM(c2h_info.c2hreg); 2608dc229d94SPing-Ke Shih rx_ant = RTW89_GET_C2H_PHYCAP_ANT_RX_NUM(c2h_info.c2hreg); 2609c7ad08c6SPing-Ke Shih 2610c7ad08c6SPing-Ke Shih hal->tx_nss = tx_nss ? min_t(u8, tx_nss, chip->tx_nss) : chip->tx_nss; 2611c7ad08c6SPing-Ke Shih hal->rx_nss = rx_nss ? min_t(u8, rx_nss, chip->rx_nss) : chip->rx_nss; 2612e3ec7017SPing-Ke Shih 2613dc229d94SPing-Ke Shih if (tx_ant == 1) 2614dc229d94SPing-Ke Shih hal->antenna_tx = RF_B; 2615dc229d94SPing-Ke Shih if (rx_ant == 1) 2616dc229d94SPing-Ke Shih hal->antenna_rx = RF_B; 2617dc229d94SPing-Ke Shih 2618dc229d94SPing-Ke Shih if (tx_nss == 1 && tx_ant == 2 && rx_ant == 2) { 2619dc229d94SPing-Ke Shih hal->antenna_tx = RF_B; 2620dc229d94SPing-Ke Shih hal->tx_path_diversity = true; 2621dc229d94SPing-Ke Shih } 2622dc229d94SPing-Ke Shih 2623e3ec7017SPing-Ke Shih rtw89_debug(rtwdev, RTW89_DBG_FW, 2624e3ec7017SPing-Ke Shih "phycap hal/phy/chip: tx_nss=0x%x/0x%x/0x%x rx_nss=0x%x/0x%x/0x%x\n", 2625c7ad08c6SPing-Ke Shih hal->tx_nss, tx_nss, chip->tx_nss, 2626c7ad08c6SPing-Ke Shih hal->rx_nss, rx_nss, chip->rx_nss); 2627dc229d94SPing-Ke Shih rtw89_debug(rtwdev, RTW89_DBG_FW, 2628dc229d94SPing-Ke Shih "ant num/bitmap: tx=%d/0x%x rx=%d/0x%x\n", 2629dc229d94SPing-Ke Shih tx_ant, hal->antenna_tx, rx_ant, hal->antenna_rx); 2630dc229d94SPing-Ke Shih rtw89_debug(rtwdev, RTW89_DBG_FW, "TX path diversity=%d\n", hal->tx_path_diversity); 2631e3ec7017SPing-Ke Shih 2632e3ec7017SPing-Ke Shih return 0; 2633e3ec7017SPing-Ke Shih } 2634e3ec7017SPing-Ke Shih 2635e3ec7017SPing-Ke Shih static int rtw89_hw_sch_tx_en_h2c(struct rtw89_dev *rtwdev, u8 band, 2636e3ec7017SPing-Ke Shih u16 tx_en_u16, u16 mask_u16) 2637e3ec7017SPing-Ke Shih { 2638e3ec7017SPing-Ke Shih u32 ret; 2639e3ec7017SPing-Ke Shih struct rtw89_mac_c2h_info c2h_info = {0}; 2640e3ec7017SPing-Ke Shih struct rtw89_mac_h2c_info h2c_info = {0}; 2641e3ec7017SPing-Ke Shih struct rtw89_h2creg_sch_tx_en *h2creg = 2642e3ec7017SPing-Ke Shih (struct rtw89_h2creg_sch_tx_en *)h2c_info.h2creg; 2643e3ec7017SPing-Ke Shih 2644e3ec7017SPing-Ke Shih h2c_info.id = RTW89_FWCMD_H2CREG_FUNC_SCH_TX_EN; 2645e3ec7017SPing-Ke Shih h2c_info.content_len = sizeof(*h2creg) - RTW89_H2CREG_HDR_LEN; 2646e3ec7017SPing-Ke Shih h2creg->tx_en = tx_en_u16; 2647e3ec7017SPing-Ke Shih h2creg->mask = mask_u16; 2648e3ec7017SPing-Ke Shih h2creg->band = band; 2649e3ec7017SPing-Ke Shih 2650e3ec7017SPing-Ke Shih ret = rtw89_fw_msg_reg(rtwdev, &h2c_info, &c2h_info); 2651e3ec7017SPing-Ke Shih if (ret) 2652e3ec7017SPing-Ke Shih return ret; 2653e3ec7017SPing-Ke Shih 2654e3ec7017SPing-Ke Shih if (c2h_info.id != RTW89_FWCMD_C2HREG_FUNC_TX_PAUSE_RPT) 2655e3ec7017SPing-Ke Shih return -EINVAL; 2656e3ec7017SPing-Ke Shih 2657e3ec7017SPing-Ke Shih return 0; 2658e3ec7017SPing-Ke Shih } 2659e3ec7017SPing-Ke Shih 2660e3ec7017SPing-Ke Shih static int rtw89_set_hw_sch_tx_en(struct rtw89_dev *rtwdev, u8 mac_idx, 2661e3ec7017SPing-Ke Shih u16 tx_en, u16 tx_en_mask) 2662e3ec7017SPing-Ke Shih { 2663e3ec7017SPing-Ke Shih u32 reg = rtw89_mac_reg_by_idx(R_AX_CTN_TXEN, mac_idx); 2664e3ec7017SPing-Ke Shih u16 val; 2665e3ec7017SPing-Ke Shih int ret; 2666e3ec7017SPing-Ke Shih 2667e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2668e3ec7017SPing-Ke Shih if (ret) 2669e3ec7017SPing-Ke Shih return ret; 2670e3ec7017SPing-Ke Shih 2671e3ec7017SPing-Ke Shih if (test_bit(RTW89_FLAG_FW_RDY, rtwdev->flags)) 2672e3ec7017SPing-Ke Shih return rtw89_hw_sch_tx_en_h2c(rtwdev, mac_idx, 2673e3ec7017SPing-Ke Shih tx_en, tx_en_mask); 2674e3ec7017SPing-Ke Shih 2675e3ec7017SPing-Ke Shih val = rtw89_read16(rtwdev, reg); 2676e3ec7017SPing-Ke Shih val = (val & ~tx_en_mask) | (tx_en & tx_en_mask); 2677e3ec7017SPing-Ke Shih rtw89_write16(rtwdev, reg, val); 2678e3ec7017SPing-Ke Shih 2679e3ec7017SPing-Ke Shih return 0; 2680e3ec7017SPing-Ke Shih } 2681e3ec7017SPing-Ke Shih 2682de7ba639SPing-Ke Shih static int rtw89_set_hw_sch_tx_en_v1(struct rtw89_dev *rtwdev, u8 mac_idx, 2683de7ba639SPing-Ke Shih u32 tx_en, u32 tx_en_mask) 2684de7ba639SPing-Ke Shih { 2685de7ba639SPing-Ke Shih u32 reg = rtw89_mac_reg_by_idx(R_AX_CTN_DRV_TXEN, mac_idx); 2686de7ba639SPing-Ke Shih u32 val; 2687de7ba639SPing-Ke Shih int ret; 2688de7ba639SPing-Ke Shih 2689de7ba639SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2690de7ba639SPing-Ke Shih if (ret) 2691de7ba639SPing-Ke Shih return ret; 2692de7ba639SPing-Ke Shih 2693de7ba639SPing-Ke Shih val = rtw89_read32(rtwdev, reg); 2694de7ba639SPing-Ke Shih val = (val & ~tx_en_mask) | (tx_en & tx_en_mask); 2695de7ba639SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2696de7ba639SPing-Ke Shih 2697de7ba639SPing-Ke Shih return 0; 2698de7ba639SPing-Ke Shih } 2699de7ba639SPing-Ke Shih 2700e3ec7017SPing-Ke Shih int rtw89_mac_stop_sch_tx(struct rtw89_dev *rtwdev, u8 mac_idx, 2701d780f926SPing-Ke Shih u32 *tx_en, enum rtw89_sch_tx_sel sel) 2702e3ec7017SPing-Ke Shih { 2703e3ec7017SPing-Ke Shih int ret; 2704e3ec7017SPing-Ke Shih 2705e3ec7017SPing-Ke Shih *tx_en = rtw89_read16(rtwdev, 2706e3ec7017SPing-Ke Shih rtw89_mac_reg_by_idx(R_AX_CTN_TXEN, mac_idx)); 2707e3ec7017SPing-Ke Shih 2708e3ec7017SPing-Ke Shih switch (sel) { 2709e3ec7017SPing-Ke Shih case RTW89_SCH_TX_SEL_ALL: 2710de7ba639SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en(rtwdev, mac_idx, 0, 2711de7ba639SPing-Ke Shih B_AX_CTN_TXEN_ALL_MASK); 2712e3ec7017SPing-Ke Shih if (ret) 2713e3ec7017SPing-Ke Shih return ret; 2714e3ec7017SPing-Ke Shih break; 2715e3ec7017SPing-Ke Shih case RTW89_SCH_TX_SEL_HIQ: 2716e3ec7017SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en(rtwdev, mac_idx, 2717e3ec7017SPing-Ke Shih 0, B_AX_CTN_TXEN_HGQ); 2718e3ec7017SPing-Ke Shih if (ret) 2719e3ec7017SPing-Ke Shih return ret; 2720e3ec7017SPing-Ke Shih break; 2721e3ec7017SPing-Ke Shih case RTW89_SCH_TX_SEL_MG0: 2722e3ec7017SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en(rtwdev, mac_idx, 2723e3ec7017SPing-Ke Shih 0, B_AX_CTN_TXEN_MGQ); 2724e3ec7017SPing-Ke Shih if (ret) 2725e3ec7017SPing-Ke Shih return ret; 2726e3ec7017SPing-Ke Shih break; 2727e3ec7017SPing-Ke Shih case RTW89_SCH_TX_SEL_MACID: 2728de7ba639SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en(rtwdev, mac_idx, 0, 2729de7ba639SPing-Ke Shih B_AX_CTN_TXEN_ALL_MASK); 2730e3ec7017SPing-Ke Shih if (ret) 2731e3ec7017SPing-Ke Shih return ret; 2732e3ec7017SPing-Ke Shih break; 2733e3ec7017SPing-Ke Shih default: 2734e3ec7017SPing-Ke Shih return 0; 2735e3ec7017SPing-Ke Shih } 2736e3ec7017SPing-Ke Shih 2737e3ec7017SPing-Ke Shih return 0; 2738e3ec7017SPing-Ke Shih } 2739861e58c8SZong-Zhe Yang EXPORT_SYMBOL(rtw89_mac_stop_sch_tx); 2740e3ec7017SPing-Ke Shih 2741de7ba639SPing-Ke Shih int rtw89_mac_stop_sch_tx_v1(struct rtw89_dev *rtwdev, u8 mac_idx, 2742de7ba639SPing-Ke Shih u32 *tx_en, enum rtw89_sch_tx_sel sel) 2743de7ba639SPing-Ke Shih { 2744de7ba639SPing-Ke Shih int ret; 2745de7ba639SPing-Ke Shih 2746de7ba639SPing-Ke Shih *tx_en = rtw89_read32(rtwdev, 2747de7ba639SPing-Ke Shih rtw89_mac_reg_by_idx(R_AX_CTN_DRV_TXEN, mac_idx)); 2748de7ba639SPing-Ke Shih 2749de7ba639SPing-Ke Shih switch (sel) { 2750de7ba639SPing-Ke Shih case RTW89_SCH_TX_SEL_ALL: 2751de7ba639SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en_v1(rtwdev, mac_idx, 0, 2752de7ba639SPing-Ke Shih B_AX_CTN_TXEN_ALL_MASK_V1); 2753de7ba639SPing-Ke Shih if (ret) 2754de7ba639SPing-Ke Shih return ret; 2755de7ba639SPing-Ke Shih break; 2756de7ba639SPing-Ke Shih case RTW89_SCH_TX_SEL_HIQ: 2757de7ba639SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en_v1(rtwdev, mac_idx, 2758de7ba639SPing-Ke Shih 0, B_AX_CTN_TXEN_HGQ); 2759de7ba639SPing-Ke Shih if (ret) 2760de7ba639SPing-Ke Shih return ret; 2761de7ba639SPing-Ke Shih break; 2762de7ba639SPing-Ke Shih case RTW89_SCH_TX_SEL_MG0: 2763de7ba639SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en_v1(rtwdev, mac_idx, 2764de7ba639SPing-Ke Shih 0, B_AX_CTN_TXEN_MGQ); 2765de7ba639SPing-Ke Shih if (ret) 2766de7ba639SPing-Ke Shih return ret; 2767de7ba639SPing-Ke Shih break; 2768de7ba639SPing-Ke Shih case RTW89_SCH_TX_SEL_MACID: 2769de7ba639SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en_v1(rtwdev, mac_idx, 0, 2770de7ba639SPing-Ke Shih B_AX_CTN_TXEN_ALL_MASK_V1); 2771de7ba639SPing-Ke Shih if (ret) 2772de7ba639SPing-Ke Shih return ret; 2773de7ba639SPing-Ke Shih break; 2774de7ba639SPing-Ke Shih default: 2775de7ba639SPing-Ke Shih return 0; 2776de7ba639SPing-Ke Shih } 2777de7ba639SPing-Ke Shih 2778de7ba639SPing-Ke Shih return 0; 2779de7ba639SPing-Ke Shih } 2780de7ba639SPing-Ke Shih EXPORT_SYMBOL(rtw89_mac_stop_sch_tx_v1); 2781de7ba639SPing-Ke Shih 2782d780f926SPing-Ke Shih int rtw89_mac_resume_sch_tx(struct rtw89_dev *rtwdev, u8 mac_idx, u32 tx_en) 2783e3ec7017SPing-Ke Shih { 2784e3ec7017SPing-Ke Shih int ret; 2785e3ec7017SPing-Ke Shih 2786de7ba639SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en(rtwdev, mac_idx, tx_en, B_AX_CTN_TXEN_ALL_MASK); 2787e3ec7017SPing-Ke Shih if (ret) 2788e3ec7017SPing-Ke Shih return ret; 2789e3ec7017SPing-Ke Shih 2790e3ec7017SPing-Ke Shih return 0; 2791e3ec7017SPing-Ke Shih } 2792861e58c8SZong-Zhe Yang EXPORT_SYMBOL(rtw89_mac_resume_sch_tx); 2793e3ec7017SPing-Ke Shih 2794de7ba639SPing-Ke Shih int rtw89_mac_resume_sch_tx_v1(struct rtw89_dev *rtwdev, u8 mac_idx, u32 tx_en) 2795de7ba639SPing-Ke Shih { 2796de7ba639SPing-Ke Shih int ret; 2797de7ba639SPing-Ke Shih 2798de7ba639SPing-Ke Shih ret = rtw89_set_hw_sch_tx_en_v1(rtwdev, mac_idx, tx_en, 2799de7ba639SPing-Ke Shih B_AX_CTN_TXEN_ALL_MASK_V1); 2800de7ba639SPing-Ke Shih if (ret) 2801de7ba639SPing-Ke Shih return ret; 2802de7ba639SPing-Ke Shih 2803de7ba639SPing-Ke Shih return 0; 2804de7ba639SPing-Ke Shih } 2805de7ba639SPing-Ke Shih EXPORT_SYMBOL(rtw89_mac_resume_sch_tx_v1); 2806de7ba639SPing-Ke Shih 28078a1f6c88SZong-Zhe Yang u16 rtw89_mac_dle_buf_req(struct rtw89_dev *rtwdev, u16 buf_len, bool wd) 2808e3ec7017SPing-Ke Shih { 2809e3ec7017SPing-Ke Shih u32 val, reg; 2810e3ec7017SPing-Ke Shih int ret; 2811e3ec7017SPing-Ke Shih 2812e3ec7017SPing-Ke Shih reg = wd ? R_AX_WD_BUF_REQ : R_AX_PL_BUF_REQ; 2813e3ec7017SPing-Ke Shih val = buf_len; 2814e3ec7017SPing-Ke Shih val |= B_AX_WD_BUF_REQ_EXEC; 2815e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2816e3ec7017SPing-Ke Shih 2817e3ec7017SPing-Ke Shih reg = wd ? R_AX_WD_BUF_STATUS : R_AX_PL_BUF_STATUS; 2818e3ec7017SPing-Ke Shih 2819e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read32, val, val & B_AX_WD_BUF_STAT_DONE, 2820e3ec7017SPing-Ke Shih 1, 2000, false, rtwdev, reg); 2821e3ec7017SPing-Ke Shih if (ret) 2822e3ec7017SPing-Ke Shih return 0xffff; 2823e3ec7017SPing-Ke Shih 2824e3ec7017SPing-Ke Shih return FIELD_GET(B_AX_WD_BUF_STAT_PKTID_MASK, val); 2825e3ec7017SPing-Ke Shih } 2826e3ec7017SPing-Ke Shih 28278a1f6c88SZong-Zhe Yang int rtw89_mac_set_cpuio(struct rtw89_dev *rtwdev, 28288a1f6c88SZong-Zhe Yang struct rtw89_cpuio_ctrl *ctrl_para, bool wd) 2829e3ec7017SPing-Ke Shih { 2830e3ec7017SPing-Ke Shih u32 val, cmd_type, reg; 2831e3ec7017SPing-Ke Shih int ret; 2832e3ec7017SPing-Ke Shih 2833e3ec7017SPing-Ke Shih cmd_type = ctrl_para->cmd_type; 2834e3ec7017SPing-Ke Shih 2835e3ec7017SPing-Ke Shih reg = wd ? R_AX_WD_CPUQ_OP_2 : R_AX_PL_CPUQ_OP_2; 2836e3ec7017SPing-Ke Shih val = 0; 2837e3ec7017SPing-Ke Shih val = u32_replace_bits(val, ctrl_para->start_pktid, 2838e3ec7017SPing-Ke Shih B_AX_WD_CPUQ_OP_STRT_PKTID_MASK); 2839e3ec7017SPing-Ke Shih val = u32_replace_bits(val, ctrl_para->end_pktid, 2840e3ec7017SPing-Ke Shih B_AX_WD_CPUQ_OP_END_PKTID_MASK); 2841e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2842e3ec7017SPing-Ke Shih 2843e3ec7017SPing-Ke Shih reg = wd ? R_AX_WD_CPUQ_OP_1 : R_AX_PL_CPUQ_OP_1; 2844e3ec7017SPing-Ke Shih val = 0; 2845e3ec7017SPing-Ke Shih val = u32_replace_bits(val, ctrl_para->src_pid, 2846e3ec7017SPing-Ke Shih B_AX_CPUQ_OP_SRC_PID_MASK); 2847e3ec7017SPing-Ke Shih val = u32_replace_bits(val, ctrl_para->src_qid, 2848e3ec7017SPing-Ke Shih B_AX_CPUQ_OP_SRC_QID_MASK); 2849e3ec7017SPing-Ke Shih val = u32_replace_bits(val, ctrl_para->dst_pid, 2850e3ec7017SPing-Ke Shih B_AX_CPUQ_OP_DST_PID_MASK); 2851e3ec7017SPing-Ke Shih val = u32_replace_bits(val, ctrl_para->dst_qid, 2852e3ec7017SPing-Ke Shih B_AX_CPUQ_OP_DST_QID_MASK); 2853e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2854e3ec7017SPing-Ke Shih 2855e3ec7017SPing-Ke Shih reg = wd ? R_AX_WD_CPUQ_OP_0 : R_AX_PL_CPUQ_OP_0; 2856e3ec7017SPing-Ke Shih val = 0; 2857e3ec7017SPing-Ke Shih val = u32_replace_bits(val, cmd_type, 2858e3ec7017SPing-Ke Shih B_AX_CPUQ_OP_CMD_TYPE_MASK); 2859e3ec7017SPing-Ke Shih val = u32_replace_bits(val, ctrl_para->macid, 2860e3ec7017SPing-Ke Shih B_AX_CPUQ_OP_MACID_MASK); 2861e3ec7017SPing-Ke Shih val = u32_replace_bits(val, ctrl_para->pkt_num, 2862e3ec7017SPing-Ke Shih B_AX_CPUQ_OP_PKTNUM_MASK); 2863e3ec7017SPing-Ke Shih val |= B_AX_WD_CPUQ_OP_EXEC; 2864e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 2865e3ec7017SPing-Ke Shih 2866e3ec7017SPing-Ke Shih reg = wd ? R_AX_WD_CPUQ_OP_STATUS : R_AX_PL_CPUQ_OP_STATUS; 2867e3ec7017SPing-Ke Shih 2868e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read32, val, val & B_AX_WD_CPUQ_OP_STAT_DONE, 2869e3ec7017SPing-Ke Shih 1, 2000, false, rtwdev, reg); 2870e3ec7017SPing-Ke Shih if (ret) 2871e3ec7017SPing-Ke Shih return ret; 2872e3ec7017SPing-Ke Shih 2873e3ec7017SPing-Ke Shih if (cmd_type == CPUIO_OP_CMD_GET_1ST_PID || 2874e3ec7017SPing-Ke Shih cmd_type == CPUIO_OP_CMD_GET_NEXT_PID) 2875e3ec7017SPing-Ke Shih ctrl_para->pktid = FIELD_GET(B_AX_WD_CPUQ_OP_PKTID_MASK, val); 2876e3ec7017SPing-Ke Shih 2877e3ec7017SPing-Ke Shih return 0; 2878e3ec7017SPing-Ke Shih } 2879e3ec7017SPing-Ke Shih 2880e3ec7017SPing-Ke Shih static int dle_quota_change(struct rtw89_dev *rtwdev, enum rtw89_qta_mode mode) 2881e3ec7017SPing-Ke Shih { 2882e3ec7017SPing-Ke Shih const struct rtw89_dle_mem *cfg; 2883e3ec7017SPing-Ke Shih struct rtw89_cpuio_ctrl ctrl_para = {0}; 2884e3ec7017SPing-Ke Shih u16 pkt_id; 2885e3ec7017SPing-Ke Shih int ret; 2886e3ec7017SPing-Ke Shih 2887e3ec7017SPing-Ke Shih cfg = get_dle_mem_cfg(rtwdev, mode); 2888e3ec7017SPing-Ke Shih if (!cfg) { 2889e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]wd/dle mem cfg\n"); 2890e3ec7017SPing-Ke Shih return -EINVAL; 2891e3ec7017SPing-Ke Shih } 2892e3ec7017SPing-Ke Shih 28935f8c35b9SPing-Ke Shih if (dle_used_size(cfg->wde_size, cfg->ple_size) != 28945f8c35b9SPing-Ke Shih dle_expected_used_size(rtwdev, mode)) { 2895e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]wd/dle mem cfg\n"); 2896e3ec7017SPing-Ke Shih return -EINVAL; 2897e3ec7017SPing-Ke Shih } 2898e3ec7017SPing-Ke Shih 2899e3ec7017SPing-Ke Shih dle_quota_cfg(rtwdev, cfg, INVALID_QT_WCPU); 2900e3ec7017SPing-Ke Shih 2901e3ec7017SPing-Ke Shih pkt_id = rtw89_mac_dle_buf_req(rtwdev, 0x20, true); 2902e3ec7017SPing-Ke Shih if (pkt_id == 0xffff) { 2903e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]WDE DLE buf req\n"); 2904e3ec7017SPing-Ke Shih return -ENOMEM; 2905e3ec7017SPing-Ke Shih } 2906e3ec7017SPing-Ke Shih 2907e3ec7017SPing-Ke Shih ctrl_para.cmd_type = CPUIO_OP_CMD_ENQ_TO_HEAD; 2908e3ec7017SPing-Ke Shih ctrl_para.start_pktid = pkt_id; 2909e3ec7017SPing-Ke Shih ctrl_para.end_pktid = pkt_id; 2910e3ec7017SPing-Ke Shih ctrl_para.pkt_num = 0; 2911e3ec7017SPing-Ke Shih ctrl_para.dst_pid = WDE_DLE_PORT_ID_WDRLS; 2912e3ec7017SPing-Ke Shih ctrl_para.dst_qid = WDE_DLE_QUEID_NO_REPORT; 2913e3ec7017SPing-Ke Shih ret = rtw89_mac_set_cpuio(rtwdev, &ctrl_para, true); 2914e3ec7017SPing-Ke Shih if (ret) { 2915e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]WDE DLE enqueue to head\n"); 2916e3ec7017SPing-Ke Shih return -EFAULT; 2917e3ec7017SPing-Ke Shih } 2918e3ec7017SPing-Ke Shih 2919e3ec7017SPing-Ke Shih pkt_id = rtw89_mac_dle_buf_req(rtwdev, 0x20, false); 2920e3ec7017SPing-Ke Shih if (pkt_id == 0xffff) { 2921e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]PLE DLE buf req\n"); 2922e3ec7017SPing-Ke Shih return -ENOMEM; 2923e3ec7017SPing-Ke Shih } 2924e3ec7017SPing-Ke Shih 2925e3ec7017SPing-Ke Shih ctrl_para.cmd_type = CPUIO_OP_CMD_ENQ_TO_HEAD; 2926e3ec7017SPing-Ke Shih ctrl_para.start_pktid = pkt_id; 2927e3ec7017SPing-Ke Shih ctrl_para.end_pktid = pkt_id; 2928e3ec7017SPing-Ke Shih ctrl_para.pkt_num = 0; 2929e3ec7017SPing-Ke Shih ctrl_para.dst_pid = PLE_DLE_PORT_ID_PLRLS; 2930e3ec7017SPing-Ke Shih ctrl_para.dst_qid = PLE_DLE_QUEID_NO_REPORT; 2931e3ec7017SPing-Ke Shih ret = rtw89_mac_set_cpuio(rtwdev, &ctrl_para, false); 2932e3ec7017SPing-Ke Shih if (ret) { 2933e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]PLE DLE enqueue to head\n"); 2934e3ec7017SPing-Ke Shih return -EFAULT; 2935e3ec7017SPing-Ke Shih } 2936e3ec7017SPing-Ke Shih 2937e3ec7017SPing-Ke Shih return 0; 2938e3ec7017SPing-Ke Shih } 2939e3ec7017SPing-Ke Shih 2940e3ec7017SPing-Ke Shih static int band_idle_ck_b(struct rtw89_dev *rtwdev, u8 mac_idx) 2941e3ec7017SPing-Ke Shih { 2942e3ec7017SPing-Ke Shih int ret; 2943e3ec7017SPing-Ke Shih u32 reg; 2944e3ec7017SPing-Ke Shih u8 val; 2945e3ec7017SPing-Ke Shih 2946e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 2947e3ec7017SPing-Ke Shih if (ret) 2948e3ec7017SPing-Ke Shih return ret; 2949e3ec7017SPing-Ke Shih 2950e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_PTCL_TX_CTN_SEL, mac_idx); 2951e3ec7017SPing-Ke Shih 2952e3ec7017SPing-Ke Shih ret = read_poll_timeout(rtw89_read8, val, 2953e3ec7017SPing-Ke Shih (val & B_AX_PTCL_TX_ON_STAT) == 0, 2954e3ec7017SPing-Ke Shih SW_CVR_DUR_US, 2955e3ec7017SPing-Ke Shih SW_CVR_DUR_US * PTCL_IDLE_POLL_CNT, 2956e3ec7017SPing-Ke Shih false, rtwdev, reg); 2957e3ec7017SPing-Ke Shih if (ret) 2958e3ec7017SPing-Ke Shih return ret; 2959e3ec7017SPing-Ke Shih 2960e3ec7017SPing-Ke Shih return 0; 2961e3ec7017SPing-Ke Shih } 2962e3ec7017SPing-Ke Shih 2963e3ec7017SPing-Ke Shih static int band1_enable(struct rtw89_dev *rtwdev) 2964e3ec7017SPing-Ke Shih { 2965e3ec7017SPing-Ke Shih int ret, i; 2966e3ec7017SPing-Ke Shih u32 sleep_bak[4] = {0}; 2967e3ec7017SPing-Ke Shih u32 pause_bak[4] = {0}; 2968d780f926SPing-Ke Shih u32 tx_en; 2969e3ec7017SPing-Ke Shih 2970de7ba639SPing-Ke Shih ret = rtw89_chip_stop_sch_tx(rtwdev, 0, &tx_en, RTW89_SCH_TX_SEL_ALL); 2971e3ec7017SPing-Ke Shih if (ret) { 2972e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]stop sch tx %d\n", ret); 2973e3ec7017SPing-Ke Shih return ret; 2974e3ec7017SPing-Ke Shih } 2975e3ec7017SPing-Ke Shih 2976e3ec7017SPing-Ke Shih for (i = 0; i < 4; i++) { 2977e3ec7017SPing-Ke Shih sleep_bak[i] = rtw89_read32(rtwdev, R_AX_MACID_SLEEP_0 + i * 4); 2978e3ec7017SPing-Ke Shih pause_bak[i] = rtw89_read32(rtwdev, R_AX_SS_MACID_PAUSE_0 + i * 4); 2979e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_MACID_SLEEP_0 + i * 4, U32_MAX); 2980e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_SS_MACID_PAUSE_0 + i * 4, U32_MAX); 2981e3ec7017SPing-Ke Shih } 2982e3ec7017SPing-Ke Shih 2983e3ec7017SPing-Ke Shih ret = band_idle_ck_b(rtwdev, 0); 2984e3ec7017SPing-Ke Shih if (ret) { 2985e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]tx idle poll %d\n", ret); 2986e3ec7017SPing-Ke Shih return ret; 2987e3ec7017SPing-Ke Shih } 2988e3ec7017SPing-Ke Shih 2989e3ec7017SPing-Ke Shih ret = dle_quota_change(rtwdev, rtwdev->mac.qta_mode); 2990e3ec7017SPing-Ke Shih if (ret) { 2991e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]DLE quota change %d\n", ret); 2992e3ec7017SPing-Ke Shih return ret; 2993e3ec7017SPing-Ke Shih } 2994e3ec7017SPing-Ke Shih 2995e3ec7017SPing-Ke Shih for (i = 0; i < 4; i++) { 2996e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_MACID_SLEEP_0 + i * 4, sleep_bak[i]); 2997e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_SS_MACID_PAUSE_0 + i * 4, pause_bak[i]); 2998e3ec7017SPing-Ke Shih } 2999e3ec7017SPing-Ke Shih 3000de7ba639SPing-Ke Shih ret = rtw89_chip_resume_sch_tx(rtwdev, 0, tx_en); 3001e3ec7017SPing-Ke Shih if (ret) { 3002e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC1 resume sch tx %d\n", ret); 3003e3ec7017SPing-Ke Shih return ret; 3004e3ec7017SPing-Ke Shih } 3005e3ec7017SPing-Ke Shih 3006e3ec7017SPing-Ke Shih ret = cmac_func_en(rtwdev, 1, true); 3007e3ec7017SPing-Ke Shih if (ret) { 3008e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC1 func en %d\n", ret); 3009e3ec7017SPing-Ke Shih return ret; 3010e3ec7017SPing-Ke Shih } 3011e3ec7017SPing-Ke Shih 3012e3ec7017SPing-Ke Shih ret = cmac_init(rtwdev, 1); 3013e3ec7017SPing-Ke Shih if (ret) { 3014e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC1 init %d\n", ret); 3015e3ec7017SPing-Ke Shih return ret; 3016e3ec7017SPing-Ke Shih } 3017e3ec7017SPing-Ke Shih 3018e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_SYS_ISO_CTRL_EXTEND, 3019e3ec7017SPing-Ke Shih B_AX_R_SYM_FEN_WLBBFUN_1 | B_AX_R_SYM_FEN_WLBBGLB_1); 3020e3ec7017SPing-Ke Shih 3021e3ec7017SPing-Ke Shih return 0; 3022e3ec7017SPing-Ke Shih } 3023e3ec7017SPing-Ke Shih 3024eeadcd2aSChia-Yuan Li static void rtw89_wdrls_imr_enable(struct rtw89_dev *rtwdev) 3025eeadcd2aSChia-Yuan Li { 3026eeadcd2aSChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3027eeadcd2aSChia-Yuan Li 3028eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_WDRLS_ERR_IMR, B_AX_WDRLS_IMR_EN_CLR); 3029eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_WDRLS_ERR_IMR, imr->wdrls_imr_set); 3030eeadcd2aSChia-Yuan Li } 3031eeadcd2aSChia-Yuan Li 3032eeadcd2aSChia-Yuan Li static void rtw89_wsec_imr_enable(struct rtw89_dev *rtwdev) 3033eeadcd2aSChia-Yuan Li { 3034eeadcd2aSChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3035eeadcd2aSChia-Yuan Li 3036eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, imr->wsec_imr_reg, imr->wsec_imr_set); 3037eeadcd2aSChia-Yuan Li } 3038eeadcd2aSChia-Yuan Li 3039eeadcd2aSChia-Yuan Li static void rtw89_mpdu_trx_imr_enable(struct rtw89_dev *rtwdev) 3040eeadcd2aSChia-Yuan Li { 3041eeadcd2aSChia-Yuan Li enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id; 3042eeadcd2aSChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3043eeadcd2aSChia-Yuan Li 3044eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_MPDU_TX_ERR_IMR, 3045eeadcd2aSChia-Yuan Li B_AX_TX_GET_ERRPKTID_INT_EN | 3046eeadcd2aSChia-Yuan Li B_AX_TX_NXT_ERRPKTID_INT_EN | 3047eeadcd2aSChia-Yuan Li B_AX_TX_MPDU_SIZE_ZERO_INT_EN | 3048eeadcd2aSChia-Yuan Li B_AX_TX_OFFSET_ERR_INT_EN | 3049eeadcd2aSChia-Yuan Li B_AX_TX_HDR3_SIZE_ERR_INT_EN); 3050eeadcd2aSChia-Yuan Li if (chip_id == RTL8852C) 3051eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_MPDU_TX_ERR_IMR, 3052eeadcd2aSChia-Yuan Li B_AX_TX_ETH_TYPE_ERR_EN | 3053eeadcd2aSChia-Yuan Li B_AX_TX_LLC_PRE_ERR_EN | 3054eeadcd2aSChia-Yuan Li B_AX_TX_NW_TYPE_ERR_EN | 3055eeadcd2aSChia-Yuan Li B_AX_TX_KSRCH_ERR_EN); 3056eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_MPDU_TX_ERR_IMR, 3057eeadcd2aSChia-Yuan Li imr->mpdu_tx_imr_set); 3058eeadcd2aSChia-Yuan Li 3059eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_MPDU_RX_ERR_IMR, 3060eeadcd2aSChia-Yuan Li B_AX_GETPKTID_ERR_INT_EN | 3061eeadcd2aSChia-Yuan Li B_AX_MHDRLEN_ERR_INT_EN | 3062eeadcd2aSChia-Yuan Li B_AX_RPT_ERR_INT_EN); 3063eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_MPDU_RX_ERR_IMR, 3064eeadcd2aSChia-Yuan Li imr->mpdu_rx_imr_set); 3065eeadcd2aSChia-Yuan Li } 3066eeadcd2aSChia-Yuan Li 3067eeadcd2aSChia-Yuan Li static void rtw89_sta_sch_imr_enable(struct rtw89_dev *rtwdev) 3068eeadcd2aSChia-Yuan Li { 3069eeadcd2aSChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3070eeadcd2aSChia-Yuan Li 3071eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_STA_SCHEDULER_ERR_IMR, 3072eeadcd2aSChia-Yuan Li B_AX_SEARCH_HANG_TIMEOUT_INT_EN | 3073eeadcd2aSChia-Yuan Li B_AX_RPT_HANG_TIMEOUT_INT_EN | 3074eeadcd2aSChia-Yuan Li B_AX_PLE_B_PKTID_ERR_INT_EN); 3075eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_STA_SCHEDULER_ERR_IMR, 3076eeadcd2aSChia-Yuan Li imr->sta_sch_imr_set); 3077eeadcd2aSChia-Yuan Li } 3078eeadcd2aSChia-Yuan Li 3079eeadcd2aSChia-Yuan Li static void rtw89_txpktctl_imr_enable(struct rtw89_dev *rtwdev) 3080eeadcd2aSChia-Yuan Li { 3081eeadcd2aSChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3082eeadcd2aSChia-Yuan Li 3083eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, imr->txpktctl_imr_b0_reg, 3084eeadcd2aSChia-Yuan Li imr->txpktctl_imr_b0_clr); 3085eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, imr->txpktctl_imr_b0_reg, 3086eeadcd2aSChia-Yuan Li imr->txpktctl_imr_b0_set); 3087eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, imr->txpktctl_imr_b1_reg, 3088eeadcd2aSChia-Yuan Li imr->txpktctl_imr_b1_clr); 3089eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, imr->txpktctl_imr_b1_reg, 3090eeadcd2aSChia-Yuan Li imr->txpktctl_imr_b1_set); 3091eeadcd2aSChia-Yuan Li } 3092eeadcd2aSChia-Yuan Li 3093eeadcd2aSChia-Yuan Li static void rtw89_wde_imr_enable(struct rtw89_dev *rtwdev) 3094eeadcd2aSChia-Yuan Li { 3095eeadcd2aSChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3096eeadcd2aSChia-Yuan Li 3097eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_WDE_ERR_IMR, imr->wde_imr_clr); 3098eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_WDE_ERR_IMR, imr->wde_imr_set); 3099eeadcd2aSChia-Yuan Li } 3100eeadcd2aSChia-Yuan Li 3101eeadcd2aSChia-Yuan Li static void rtw89_ple_imr_enable(struct rtw89_dev *rtwdev) 3102eeadcd2aSChia-Yuan Li { 3103eeadcd2aSChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3104eeadcd2aSChia-Yuan Li 3105eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_PLE_ERR_IMR, imr->ple_imr_clr); 3106eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_PLE_ERR_IMR, imr->ple_imr_set); 3107eeadcd2aSChia-Yuan Li } 3108eeadcd2aSChia-Yuan Li 3109eeadcd2aSChia-Yuan Li static void rtw89_pktin_imr_enable(struct rtw89_dev *rtwdev) 3110eeadcd2aSChia-Yuan Li { 3111eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_PKTIN_ERR_IMR, 3112eeadcd2aSChia-Yuan Li B_AX_PKTIN_GETPKTID_ERR_INT_EN); 3113eeadcd2aSChia-Yuan Li } 3114eeadcd2aSChia-Yuan Li 3115eeadcd2aSChia-Yuan Li static void rtw89_dispatcher_imr_enable(struct rtw89_dev *rtwdev) 3116eeadcd2aSChia-Yuan Li { 3117eeadcd2aSChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3118eeadcd2aSChia-Yuan Li 3119eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_HOST_DISPATCHER_ERR_IMR, 3120eeadcd2aSChia-Yuan Li imr->host_disp_imr_clr); 3121eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_HOST_DISPATCHER_ERR_IMR, 3122eeadcd2aSChia-Yuan Li imr->host_disp_imr_set); 3123eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_CPU_DISPATCHER_ERR_IMR, 3124eeadcd2aSChia-Yuan Li imr->cpu_disp_imr_clr); 3125eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_CPU_DISPATCHER_ERR_IMR, 3126eeadcd2aSChia-Yuan Li imr->cpu_disp_imr_set); 3127eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_OTHER_DISPATCHER_ERR_IMR, 3128eeadcd2aSChia-Yuan Li imr->other_disp_imr_clr); 3129eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_OTHER_DISPATCHER_ERR_IMR, 3130eeadcd2aSChia-Yuan Li imr->other_disp_imr_set); 3131eeadcd2aSChia-Yuan Li } 3132eeadcd2aSChia-Yuan Li 3133eeadcd2aSChia-Yuan Li static void rtw89_cpuio_imr_enable(struct rtw89_dev *rtwdev) 3134eeadcd2aSChia-Yuan Li { 3135eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_CPUIO_ERR_IMR, B_AX_CPUIO_IMR_CLR); 3136eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_CPUIO_ERR_IMR, B_AX_CPUIO_IMR_SET); 3137eeadcd2aSChia-Yuan Li } 3138eeadcd2aSChia-Yuan Li 3139eeadcd2aSChia-Yuan Li static void rtw89_bbrpt_imr_enable(struct rtw89_dev *rtwdev) 3140eeadcd2aSChia-Yuan Li { 3141eeadcd2aSChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3142eeadcd2aSChia-Yuan Li 314375f1ed29SPing-Ke Shih rtw89_write32_set(rtwdev, imr->bbrpt_com_err_imr_reg, 3144eeadcd2aSChia-Yuan Li B_AX_BBRPT_COM_NULL_PLPKTID_ERR_INT_EN); 3145eeadcd2aSChia-Yuan Li rtw89_write32_clr(rtwdev, imr->bbrpt_chinfo_err_imr_reg, 3146eeadcd2aSChia-Yuan Li B_AX_BBRPT_CHINFO_IMR_CLR); 3147eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, imr->bbrpt_chinfo_err_imr_reg, 3148eeadcd2aSChia-Yuan Li imr->bbrpt_err_imr_set); 3149eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, imr->bbrpt_dfs_err_imr_reg, 3150eeadcd2aSChia-Yuan Li B_AX_BBRPT_DFS_TO_ERR_INT_EN); 3151eeadcd2aSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_LA_ERRFLAG, B_AX_LA_IMR_DATA_LOSS_ERR); 3152eeadcd2aSChia-Yuan Li } 3153eeadcd2aSChia-Yuan Li 3154d86369e9SChia-Yuan Li static void rtw89_scheduler_imr_enable(struct rtw89_dev *rtwdev, u8 mac_idx) 3155d86369e9SChia-Yuan Li { 3156d86369e9SChia-Yuan Li u32 reg; 3157d86369e9SChia-Yuan Li 3158d86369e9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(R_AX_SCHEDULE_ERR_IMR, mac_idx); 3159d86369e9SChia-Yuan Li rtw89_write32_clr(rtwdev, reg, B_AX_SORT_NON_IDLE_ERR_INT_EN | 3160d86369e9SChia-Yuan Li B_AX_FSM_TIMEOUT_ERR_INT_EN); 3161d86369e9SChia-Yuan Li rtw89_write32_set(rtwdev, reg, B_AX_FSM_TIMEOUT_ERR_INT_EN); 3162d86369e9SChia-Yuan Li } 3163d86369e9SChia-Yuan Li 3164d86369e9SChia-Yuan Li static void rtw89_ptcl_imr_enable(struct rtw89_dev *rtwdev, u8 mac_idx) 3165d86369e9SChia-Yuan Li { 3166d86369e9SChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3167d86369e9SChia-Yuan Li u32 reg; 3168d86369e9SChia-Yuan Li 3169d86369e9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(R_AX_PTCL_IMR0, mac_idx); 3170d86369e9SChia-Yuan Li rtw89_write32_clr(rtwdev, reg, imr->ptcl_imr_clr); 3171d86369e9SChia-Yuan Li rtw89_write32_set(rtwdev, reg, imr->ptcl_imr_set); 3172d86369e9SChia-Yuan Li } 3173d86369e9SChia-Yuan Li 3174d86369e9SChia-Yuan Li static void rtw89_cdma_imr_enable(struct rtw89_dev *rtwdev, u8 mac_idx) 3175d86369e9SChia-Yuan Li { 3176d86369e9SChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3177d86369e9SChia-Yuan Li enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id; 3178d86369e9SChia-Yuan Li u32 reg; 3179d86369e9SChia-Yuan Li 3180d86369e9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(imr->cdma_imr_0_reg, mac_idx); 3181d86369e9SChia-Yuan Li rtw89_write32_clr(rtwdev, reg, imr->cdma_imr_0_clr); 3182d86369e9SChia-Yuan Li rtw89_write32_set(rtwdev, reg, imr->cdma_imr_0_set); 3183d86369e9SChia-Yuan Li 3184d86369e9SChia-Yuan Li if (chip_id == RTL8852C) { 3185d86369e9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(imr->cdma_imr_1_reg, mac_idx); 3186d86369e9SChia-Yuan Li rtw89_write32_clr(rtwdev, reg, imr->cdma_imr_1_clr); 3187d86369e9SChia-Yuan Li rtw89_write32_set(rtwdev, reg, imr->cdma_imr_1_set); 3188d86369e9SChia-Yuan Li } 3189d86369e9SChia-Yuan Li } 3190d86369e9SChia-Yuan Li 3191d86369e9SChia-Yuan Li static void rtw89_phy_intf_imr_enable(struct rtw89_dev *rtwdev, u8 mac_idx) 3192d86369e9SChia-Yuan Li { 3193d86369e9SChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3194d86369e9SChia-Yuan Li u32 reg; 3195d86369e9SChia-Yuan Li 3196d86369e9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(imr->phy_intf_imr_reg, mac_idx); 3197d86369e9SChia-Yuan Li rtw89_write32_clr(rtwdev, reg, imr->phy_intf_imr_clr); 3198d86369e9SChia-Yuan Li rtw89_write32_set(rtwdev, reg, imr->phy_intf_imr_set); 3199d86369e9SChia-Yuan Li } 3200d86369e9SChia-Yuan Li 3201d86369e9SChia-Yuan Li static void rtw89_rmac_imr_enable(struct rtw89_dev *rtwdev, u8 mac_idx) 3202d86369e9SChia-Yuan Li { 3203d86369e9SChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3204d86369e9SChia-Yuan Li u32 reg; 3205d86369e9SChia-Yuan Li 3206d86369e9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(imr->rmac_imr_reg, mac_idx); 3207d86369e9SChia-Yuan Li rtw89_write32_clr(rtwdev, reg, imr->rmac_imr_clr); 3208d86369e9SChia-Yuan Li rtw89_write32_set(rtwdev, reg, imr->rmac_imr_set); 3209d86369e9SChia-Yuan Li } 3210d86369e9SChia-Yuan Li 3211d86369e9SChia-Yuan Li static void rtw89_tmac_imr_enable(struct rtw89_dev *rtwdev, u8 mac_idx) 3212d86369e9SChia-Yuan Li { 3213d86369e9SChia-Yuan Li const struct rtw89_imr_info *imr = rtwdev->chip->imr_info; 3214d86369e9SChia-Yuan Li u32 reg; 3215d86369e9SChia-Yuan Li 3216d86369e9SChia-Yuan Li reg = rtw89_mac_reg_by_idx(imr->tmac_imr_reg, mac_idx); 3217d86369e9SChia-Yuan Li rtw89_write32_clr(rtwdev, reg, imr->tmac_imr_clr); 3218d86369e9SChia-Yuan Li rtw89_write32_set(rtwdev, reg, imr->tmac_imr_set); 3219d86369e9SChia-Yuan Li } 3220d86369e9SChia-Yuan Li 3221e3ec7017SPing-Ke Shih static int rtw89_mac_enable_imr(struct rtw89_dev *rtwdev, u8 mac_idx, 3222e3ec7017SPing-Ke Shih enum rtw89_mac_hwmod_sel sel) 3223e3ec7017SPing-Ke Shih { 3224e3ec7017SPing-Ke Shih int ret; 3225e3ec7017SPing-Ke Shih 3226e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, sel); 3227e3ec7017SPing-Ke Shih if (ret) { 3228e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "MAC%d mac_idx%d is not ready\n", 3229e3ec7017SPing-Ke Shih sel, mac_idx); 3230e3ec7017SPing-Ke Shih return ret; 3231e3ec7017SPing-Ke Shih } 3232e3ec7017SPing-Ke Shih 3233e3ec7017SPing-Ke Shih if (sel == RTW89_DMAC_SEL) { 3234eeadcd2aSChia-Yuan Li rtw89_wdrls_imr_enable(rtwdev); 3235eeadcd2aSChia-Yuan Li rtw89_wsec_imr_enable(rtwdev); 3236eeadcd2aSChia-Yuan Li rtw89_mpdu_trx_imr_enable(rtwdev); 3237eeadcd2aSChia-Yuan Li rtw89_sta_sch_imr_enable(rtwdev); 3238eeadcd2aSChia-Yuan Li rtw89_txpktctl_imr_enable(rtwdev); 3239eeadcd2aSChia-Yuan Li rtw89_wde_imr_enable(rtwdev); 3240eeadcd2aSChia-Yuan Li rtw89_ple_imr_enable(rtwdev); 3241eeadcd2aSChia-Yuan Li rtw89_pktin_imr_enable(rtwdev); 3242eeadcd2aSChia-Yuan Li rtw89_dispatcher_imr_enable(rtwdev); 3243eeadcd2aSChia-Yuan Li rtw89_cpuio_imr_enable(rtwdev); 3244eeadcd2aSChia-Yuan Li rtw89_bbrpt_imr_enable(rtwdev); 3245e3ec7017SPing-Ke Shih } else if (sel == RTW89_CMAC_SEL) { 3246d86369e9SChia-Yuan Li rtw89_scheduler_imr_enable(rtwdev, mac_idx); 3247d86369e9SChia-Yuan Li rtw89_ptcl_imr_enable(rtwdev, mac_idx); 3248d86369e9SChia-Yuan Li rtw89_cdma_imr_enable(rtwdev, mac_idx); 3249d86369e9SChia-Yuan Li rtw89_phy_intf_imr_enable(rtwdev, mac_idx); 3250d86369e9SChia-Yuan Li rtw89_rmac_imr_enable(rtwdev, mac_idx); 3251d86369e9SChia-Yuan Li rtw89_tmac_imr_enable(rtwdev, mac_idx); 3252e3ec7017SPing-Ke Shih } else { 3253e3ec7017SPing-Ke Shih return -EINVAL; 3254e3ec7017SPing-Ke Shih } 3255e3ec7017SPing-Ke Shih 3256e3ec7017SPing-Ke Shih return 0; 3257e3ec7017SPing-Ke Shih } 3258e3ec7017SPing-Ke Shih 32599f405b01SPing-Ke Shih static void rtw89_mac_err_imr_ctrl(struct rtw89_dev *rtwdev, bool en) 32609f405b01SPing-Ke Shih { 32619f405b01SPing-Ke Shih enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id; 32629f405b01SPing-Ke Shih 32639f405b01SPing-Ke Shih rtw89_write32(rtwdev, R_AX_DMAC_ERR_IMR, 32649f405b01SPing-Ke Shih en ? DMAC_ERR_IMR_EN : DMAC_ERR_IMR_DIS); 32659f405b01SPing-Ke Shih rtw89_write32(rtwdev, R_AX_CMAC_ERR_IMR, 32669f405b01SPing-Ke Shih en ? CMAC0_ERR_IMR_EN : CMAC0_ERR_IMR_DIS); 32679f405b01SPing-Ke Shih if (chip_id != RTL8852B && rtwdev->mac.dle_info.c1_rx_qta) 32689f405b01SPing-Ke Shih rtw89_write32(rtwdev, R_AX_CMAC_ERR_IMR_C1, 32699f405b01SPing-Ke Shih en ? CMAC1_ERR_IMR_EN : CMAC1_ERR_IMR_DIS); 32709f405b01SPing-Ke Shih } 32719f405b01SPing-Ke Shih 3272e3ec7017SPing-Ke Shih static int rtw89_mac_dbcc_enable(struct rtw89_dev *rtwdev, bool enable) 3273e3ec7017SPing-Ke Shih { 3274e3ec7017SPing-Ke Shih int ret = 0; 3275e3ec7017SPing-Ke Shih 3276e3ec7017SPing-Ke Shih if (enable) { 3277e3ec7017SPing-Ke Shih ret = band1_enable(rtwdev); 3278e3ec7017SPing-Ke Shih if (ret) { 3279e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR] band1_enable %d\n", ret); 3280e3ec7017SPing-Ke Shih return ret; 3281e3ec7017SPing-Ke Shih } 3282e3ec7017SPing-Ke Shih 3283e3ec7017SPing-Ke Shih ret = rtw89_mac_enable_imr(rtwdev, RTW89_MAC_1, RTW89_CMAC_SEL); 3284e3ec7017SPing-Ke Shih if (ret) { 3285e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR] enable CMAC1 IMR %d\n", ret); 3286e3ec7017SPing-Ke Shih return ret; 3287e3ec7017SPing-Ke Shih } 3288e3ec7017SPing-Ke Shih } else { 3289e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR] disable dbcc is not implemented not\n"); 3290e3ec7017SPing-Ke Shih return -EINVAL; 3291e3ec7017SPing-Ke Shih } 3292e3ec7017SPing-Ke Shih 3293e3ec7017SPing-Ke Shih return 0; 3294e3ec7017SPing-Ke Shih } 3295e3ec7017SPing-Ke Shih 3296e3ec7017SPing-Ke Shih static int set_host_rpr(struct rtw89_dev *rtwdev) 3297e3ec7017SPing-Ke Shih { 3298e3ec7017SPing-Ke Shih if (rtwdev->hci.type == RTW89_HCI_TYPE_PCIE) { 3299e3ec7017SPing-Ke Shih rtw89_write32_mask(rtwdev, R_AX_WDRLS_CFG, 3300e3ec7017SPing-Ke Shih B_AX_WDRLS_MODE_MASK, RTW89_RPR_MODE_POH); 3301e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_RLSRPT0_CFG0, 3302e3ec7017SPing-Ke Shih B_AX_RLSRPT0_FLTR_MAP_MASK); 3303e3ec7017SPing-Ke Shih } else { 3304e3ec7017SPing-Ke Shih rtw89_write32_mask(rtwdev, R_AX_WDRLS_CFG, 3305e3ec7017SPing-Ke Shih B_AX_WDRLS_MODE_MASK, RTW89_RPR_MODE_STF); 3306e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_RLSRPT0_CFG0, 3307e3ec7017SPing-Ke Shih B_AX_RLSRPT0_FLTR_MAP_MASK); 3308e3ec7017SPing-Ke Shih } 3309e3ec7017SPing-Ke Shih 3310e3ec7017SPing-Ke Shih rtw89_write32_mask(rtwdev, R_AX_RLSRPT0_CFG1, B_AX_RLSRPT0_AGGNUM_MASK, 30); 3311e3ec7017SPing-Ke Shih rtw89_write32_mask(rtwdev, R_AX_RLSRPT0_CFG1, B_AX_RLSRPT0_TO_MASK, 255); 3312e3ec7017SPing-Ke Shih 3313e3ec7017SPing-Ke Shih return 0; 3314e3ec7017SPing-Ke Shih } 3315e3ec7017SPing-Ke Shih 3316e3ec7017SPing-Ke Shih static int rtw89_mac_trx_init(struct rtw89_dev *rtwdev) 3317e3ec7017SPing-Ke Shih { 3318e3ec7017SPing-Ke Shih enum rtw89_qta_mode qta_mode = rtwdev->mac.qta_mode; 3319e3ec7017SPing-Ke Shih int ret; 3320e3ec7017SPing-Ke Shih 3321e3ec7017SPing-Ke Shih ret = dmac_init(rtwdev, 0); 3322e3ec7017SPing-Ke Shih if (ret) { 3323e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]DMAC init %d\n", ret); 3324e3ec7017SPing-Ke Shih return ret; 3325e3ec7017SPing-Ke Shih } 3326e3ec7017SPing-Ke Shih 3327e3ec7017SPing-Ke Shih ret = cmac_init(rtwdev, 0); 3328e3ec7017SPing-Ke Shih if (ret) { 3329e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]CMAC%d init %d\n", 0, ret); 3330e3ec7017SPing-Ke Shih return ret; 3331e3ec7017SPing-Ke Shih } 3332e3ec7017SPing-Ke Shih 3333e3ec7017SPing-Ke Shih if (is_qta_dbcc(rtwdev, qta_mode)) { 3334e3ec7017SPing-Ke Shih ret = rtw89_mac_dbcc_enable(rtwdev, true); 3335e3ec7017SPing-Ke Shih if (ret) { 3336e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]dbcc_enable init %d\n", ret); 3337e3ec7017SPing-Ke Shih return ret; 3338e3ec7017SPing-Ke Shih } 3339e3ec7017SPing-Ke Shih } 3340e3ec7017SPing-Ke Shih 3341e3ec7017SPing-Ke Shih ret = rtw89_mac_enable_imr(rtwdev, RTW89_MAC_0, RTW89_DMAC_SEL); 3342e3ec7017SPing-Ke Shih if (ret) { 3343e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR] enable DMAC IMR %d\n", ret); 3344e3ec7017SPing-Ke Shih return ret; 3345e3ec7017SPing-Ke Shih } 3346e3ec7017SPing-Ke Shih 3347e3ec7017SPing-Ke Shih ret = rtw89_mac_enable_imr(rtwdev, RTW89_MAC_0, RTW89_CMAC_SEL); 3348e3ec7017SPing-Ke Shih if (ret) { 3349e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR] to enable CMAC0 IMR %d\n", ret); 3350e3ec7017SPing-Ke Shih return ret; 3351e3ec7017SPing-Ke Shih } 3352e3ec7017SPing-Ke Shih 33539f405b01SPing-Ke Shih rtw89_mac_err_imr_ctrl(rtwdev, true); 33549f405b01SPing-Ke Shih 3355e3ec7017SPing-Ke Shih ret = set_host_rpr(rtwdev); 3356e3ec7017SPing-Ke Shih if (ret) { 3357e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR] set host rpr %d\n", ret); 3358e3ec7017SPing-Ke Shih return ret; 3359e3ec7017SPing-Ke Shih } 3360e3ec7017SPing-Ke Shih 3361e3ec7017SPing-Ke Shih return 0; 3362e3ec7017SPing-Ke Shih } 3363e3ec7017SPing-Ke Shih 3364ec356ffbSChia-Yuan Li static void rtw89_disable_fw_watchdog(struct rtw89_dev *rtwdev) 3365ec356ffbSChia-Yuan Li { 3366ec356ffbSChia-Yuan Li u32 val32; 3367ec356ffbSChia-Yuan Li 3368ec356ffbSChia-Yuan Li rtw89_mac_mem_write(rtwdev, R_AX_WDT_CTRL, 3369ec356ffbSChia-Yuan Li WDT_CTRL_ALL_DIS, RTW89_MAC_MEM_CPU_LOCAL); 3370ec356ffbSChia-Yuan Li 3371ec356ffbSChia-Yuan Li val32 = rtw89_mac_mem_read(rtwdev, R_AX_WDT_STATUS, RTW89_MAC_MEM_CPU_LOCAL); 3372ec356ffbSChia-Yuan Li val32 |= B_AX_FS_WDT_INT; 3373ec356ffbSChia-Yuan Li val32 &= ~B_AX_FS_WDT_INT_MSK; 3374ec356ffbSChia-Yuan Li rtw89_mac_mem_write(rtwdev, R_AX_WDT_STATUS, val32, RTW89_MAC_MEM_CPU_LOCAL); 3375ec356ffbSChia-Yuan Li } 3376ec356ffbSChia-Yuan Li 33775f05bdb0SChih-Kang Chang void rtw89_mac_disable_cpu(struct rtw89_dev *rtwdev) 3378e3ec7017SPing-Ke Shih { 3379e3ec7017SPing-Ke Shih clear_bit(RTW89_FLAG_FW_RDY, rtwdev->flags); 3380e3ec7017SPing-Ke Shih 3381e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_WCPU_EN); 3382de78869dSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_WCPU_FW_CTRL, B_AX_WCPU_FWDL_EN | 3383de78869dSChia-Yuan Li B_AX_H2C_PATH_RDY | B_AX_FWDL_PATH_RDY); 3384e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_SYS_CLK_CTRL, B_AX_CPU_CLK_EN); 3385ec356ffbSChia-Yuan Li 3386ec356ffbSChia-Yuan Li rtw89_disable_fw_watchdog(rtwdev); 3387ec356ffbSChia-Yuan Li 3388de78869dSChia-Yuan Li rtw89_write32_clr(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN); 3389de78869dSChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_PLATFORM_EN); 3390e3ec7017SPing-Ke Shih } 3391e3ec7017SPing-Ke Shih 33925f05bdb0SChih-Kang Chang int rtw89_mac_enable_cpu(struct rtw89_dev *rtwdev, u8 boot_reason, bool dlfw) 3393e3ec7017SPing-Ke Shih { 3394e3ec7017SPing-Ke Shih u32 val; 3395e3ec7017SPing-Ke Shih int ret; 3396e3ec7017SPing-Ke Shih 3397e3ec7017SPing-Ke Shih if (rtw89_read32(rtwdev, R_AX_PLATFORM_ENABLE) & B_AX_WCPU_EN) 3398e3ec7017SPing-Ke Shih return -EFAULT; 3399e3ec7017SPing-Ke Shih 3400e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_HALT_H2C_CTRL, 0); 3401e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_HALT_C2H_CTRL, 0); 3402a63ae673SPing-Ke Shih rtw89_write32(rtwdev, R_AX_HALT_H2C, 0); 3403a63ae673SPing-Ke Shih rtw89_write32(rtwdev, R_AX_HALT_C2H, 0); 3404e3ec7017SPing-Ke Shih 3405e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_SYS_CLK_CTRL, B_AX_CPU_CLK_EN); 3406e3ec7017SPing-Ke Shih 3407e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, R_AX_WCPU_FW_CTRL); 3408e3ec7017SPing-Ke Shih val &= ~(B_AX_WCPU_FWDL_EN | B_AX_H2C_PATH_RDY | B_AX_FWDL_PATH_RDY); 3409e3ec7017SPing-Ke Shih val = u32_replace_bits(val, RTW89_FWDL_INITIAL_STATE, 3410e3ec7017SPing-Ke Shih B_AX_WCPU_FWDL_STS_MASK); 3411e3ec7017SPing-Ke Shih 3412e3ec7017SPing-Ke Shih if (dlfw) 3413e3ec7017SPing-Ke Shih val |= B_AX_WCPU_FWDL_EN; 3414e3ec7017SPing-Ke Shih 3415e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_WCPU_FW_CTRL, val); 3416e3ec7017SPing-Ke Shih rtw89_write16_mask(rtwdev, R_AX_BOOT_REASON, B_AX_BOOT_REASON_MASK, 3417e3ec7017SPing-Ke Shih boot_reason); 3418e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_WCPU_EN); 3419e3ec7017SPing-Ke Shih 3420e3ec7017SPing-Ke Shih if (!dlfw) { 3421e3ec7017SPing-Ke Shih mdelay(5); 3422e3ec7017SPing-Ke Shih 3423e3ec7017SPing-Ke Shih ret = rtw89_fw_check_rdy(rtwdev); 3424e3ec7017SPing-Ke Shih if (ret) 3425e3ec7017SPing-Ke Shih return ret; 3426e3ec7017SPing-Ke Shih } 3427e3ec7017SPing-Ke Shih 3428e3ec7017SPing-Ke Shih return 0; 3429e3ec7017SPing-Ke Shih } 3430e3ec7017SPing-Ke Shih 3431a7d82a7aSPing-Ke Shih static int rtw89_mac_dmac_pre_init(struct rtw89_dev *rtwdev) 3432e3ec7017SPing-Ke Shih { 3433a7d82a7aSPing-Ke Shih enum rtw89_core_chip_id chip_id = rtwdev->chip->chip_id; 3434e3ec7017SPing-Ke Shih u32 val; 3435e3ec7017SPing-Ke Shih int ret; 3436e3ec7017SPing-Ke Shih 3437a7d82a7aSPing-Ke Shih if (chip_id == RTL8852C) 3438a7d82a7aSPing-Ke Shih val = B_AX_MAC_FUNC_EN | B_AX_DMAC_FUNC_EN | B_AX_DISPATCHER_EN | 3439a7d82a7aSPing-Ke Shih B_AX_PKT_BUF_EN | B_AX_H_AXIDMA_EN; 3440a7d82a7aSPing-Ke Shih else 3441e3ec7017SPing-Ke Shih val = B_AX_MAC_FUNC_EN | B_AX_DMAC_FUNC_EN | B_AX_DISPATCHER_EN | 3442e3ec7017SPing-Ke Shih B_AX_PKT_BUF_EN; 3443e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_DMAC_FUNC_EN, val); 3444e3ec7017SPing-Ke Shih 3445e3ec7017SPing-Ke Shih val = B_AX_DISPATCHER_CLK_EN; 3446e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_DMAC_CLK_EN, val); 3447e3ec7017SPing-Ke Shih 3448a7d82a7aSPing-Ke Shih if (chip_id != RTL8852C) 3449a7d82a7aSPing-Ke Shih goto dle; 3450a7d82a7aSPing-Ke Shih 3451a7d82a7aSPing-Ke Shih val = rtw89_read32(rtwdev, R_AX_HAXI_INIT_CFG1); 3452a7d82a7aSPing-Ke Shih val &= ~(B_AX_DMA_MODE_MASK | B_AX_STOP_AXI_MST); 3453a7d82a7aSPing-Ke Shih val |= FIELD_PREP(B_AX_DMA_MODE_MASK, DMA_MOD_PCIE_1B) | 3454a7d82a7aSPing-Ke Shih B_AX_TXHCI_EN_V1 | B_AX_RXHCI_EN_V1; 3455a7d82a7aSPing-Ke Shih rtw89_write32(rtwdev, R_AX_HAXI_INIT_CFG1, val); 3456a7d82a7aSPing-Ke Shih 3457a7d82a7aSPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_HAXI_DMA_STOP1, 3458a7d82a7aSPing-Ke Shih B_AX_STOP_ACH0 | B_AX_STOP_ACH1 | B_AX_STOP_ACH3 | 3459a7d82a7aSPing-Ke Shih B_AX_STOP_ACH4 | B_AX_STOP_ACH5 | B_AX_STOP_ACH6 | 3460a7d82a7aSPing-Ke Shih B_AX_STOP_ACH7 | B_AX_STOP_CH8 | B_AX_STOP_CH9 | 3461a7d82a7aSPing-Ke Shih B_AX_STOP_CH12 | B_AX_STOP_ACH2); 3462a7d82a7aSPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_HAXI_DMA_STOP2, B_AX_STOP_CH10 | B_AX_STOP_CH11); 3463a7d82a7aSPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_PLATFORM_ENABLE, B_AX_AXIDMA_EN); 3464a7d82a7aSPing-Ke Shih 3465a7d82a7aSPing-Ke Shih dle: 3466e3ec7017SPing-Ke Shih ret = dle_init(rtwdev, RTW89_QTA_DLFW, rtwdev->mac.qta_mode); 3467e3ec7017SPing-Ke Shih if (ret) { 3468e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]DLE pre init %d\n", ret); 3469e3ec7017SPing-Ke Shih return ret; 3470e3ec7017SPing-Ke Shih } 3471e3ec7017SPing-Ke Shih 3472e3ec7017SPing-Ke Shih ret = hfc_init(rtwdev, true, false, true); 3473e3ec7017SPing-Ke Shih if (ret) { 3474e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[ERR]HCI FC pre init %d\n", ret); 3475e3ec7017SPing-Ke Shih return ret; 3476e3ec7017SPing-Ke Shih } 3477e3ec7017SPing-Ke Shih 3478e3ec7017SPing-Ke Shih return ret; 3479e3ec7017SPing-Ke Shih } 3480e3ec7017SPing-Ke Shih 348161ebeecbSPing-Ke Shih int rtw89_mac_enable_bb_rf(struct rtw89_dev *rtwdev) 3482e3ec7017SPing-Ke Shih { 3483e3ec7017SPing-Ke Shih rtw89_write8_set(rtwdev, R_AX_SYS_FUNC_EN, 3484e3ec7017SPing-Ke Shih B_AX_FEN_BBRSTB | B_AX_FEN_BB_GLB_RSTN); 3485e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, R_AX_WLRF_CTRL, 3486e3ec7017SPing-Ke Shih B_AX_WLRF1_CTRL_7 | B_AX_WLRF1_CTRL_1 | 3487e3ec7017SPing-Ke Shih B_AX_WLRF_CTRL_7 | B_AX_WLRF_CTRL_1); 3488e3ec7017SPing-Ke Shih rtw89_write8_set(rtwdev, R_AX_PHYREG_SET, PHYREG_SET_ALL_CYCLE); 348961ebeecbSPing-Ke Shih 349061ebeecbSPing-Ke Shih return 0; 3491e3ec7017SPing-Ke Shih } 349261ebeecbSPing-Ke Shih EXPORT_SYMBOL(rtw89_mac_enable_bb_rf); 3493e3ec7017SPing-Ke Shih 349414b6e9f4SPing-Ke Shih int rtw89_mac_disable_bb_rf(struct rtw89_dev *rtwdev) 3495e3ec7017SPing-Ke Shih { 3496e3ec7017SPing-Ke Shih rtw89_write8_clr(rtwdev, R_AX_SYS_FUNC_EN, 3497e3ec7017SPing-Ke Shih B_AX_FEN_BBRSTB | B_AX_FEN_BB_GLB_RSTN); 3498e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, R_AX_WLRF_CTRL, 3499e3ec7017SPing-Ke Shih B_AX_WLRF1_CTRL_7 | B_AX_WLRF1_CTRL_1 | 3500e3ec7017SPing-Ke Shih B_AX_WLRF_CTRL_7 | B_AX_WLRF_CTRL_1); 3501e3ec7017SPing-Ke Shih rtw89_write8_clr(rtwdev, R_AX_PHYREG_SET, PHYREG_SET_ALL_CYCLE); 350214b6e9f4SPing-Ke Shih 350314b6e9f4SPing-Ke Shih return 0; 3504e3ec7017SPing-Ke Shih } 350561ebeecbSPing-Ke Shih EXPORT_SYMBOL(rtw89_mac_disable_bb_rf); 3506e3ec7017SPing-Ke Shih 3507e3ec7017SPing-Ke Shih int rtw89_mac_partial_init(struct rtw89_dev *rtwdev) 3508e3ec7017SPing-Ke Shih { 3509e3ec7017SPing-Ke Shih int ret; 3510e3ec7017SPing-Ke Shih 3511e3ec7017SPing-Ke Shih ret = rtw89_mac_power_switch(rtwdev, true); 3512e3ec7017SPing-Ke Shih if (ret) { 3513e3ec7017SPing-Ke Shih rtw89_mac_power_switch(rtwdev, false); 3514e3ec7017SPing-Ke Shih ret = rtw89_mac_power_switch(rtwdev, true); 3515e3ec7017SPing-Ke Shih if (ret) 3516e3ec7017SPing-Ke Shih return ret; 3517e3ec7017SPing-Ke Shih } 3518e3ec7017SPing-Ke Shih 351952f12705SChin-Yen Lee rtw89_mac_ctrl_hci_dma_trx(rtwdev, true); 3520e3ec7017SPing-Ke Shih 3521a7d82a7aSPing-Ke Shih ret = rtw89_mac_dmac_pre_init(rtwdev); 3522a7d82a7aSPing-Ke Shih if (ret) 3523a7d82a7aSPing-Ke Shih return ret; 3524a7d82a7aSPing-Ke Shih 3525e3ec7017SPing-Ke Shih if (rtwdev->hci.ops->mac_pre_init) { 3526e3ec7017SPing-Ke Shih ret = rtwdev->hci.ops->mac_pre_init(rtwdev); 3527e3ec7017SPing-Ke Shih if (ret) 3528e3ec7017SPing-Ke Shih return ret; 3529e3ec7017SPing-Ke Shih } 3530e3ec7017SPing-Ke Shih 3531e3ec7017SPing-Ke Shih ret = rtw89_fw_download(rtwdev, RTW89_FW_NORMAL); 3532e3ec7017SPing-Ke Shih if (ret) 3533e3ec7017SPing-Ke Shih return ret; 3534e3ec7017SPing-Ke Shih 3535e3ec7017SPing-Ke Shih return 0; 3536e3ec7017SPing-Ke Shih } 3537e3ec7017SPing-Ke Shih 3538e3ec7017SPing-Ke Shih int rtw89_mac_init(struct rtw89_dev *rtwdev) 3539e3ec7017SPing-Ke Shih { 3540e3ec7017SPing-Ke Shih int ret; 3541e3ec7017SPing-Ke Shih 3542e3ec7017SPing-Ke Shih ret = rtw89_mac_partial_init(rtwdev); 3543e3ec7017SPing-Ke Shih if (ret) 3544e3ec7017SPing-Ke Shih goto fail; 3545e3ec7017SPing-Ke Shih 354661ebeecbSPing-Ke Shih ret = rtw89_chip_enable_bb_rf(rtwdev); 354761ebeecbSPing-Ke Shih if (ret) 354861ebeecbSPing-Ke Shih goto fail; 3549e3ec7017SPing-Ke Shih 3550e3ec7017SPing-Ke Shih ret = rtw89_mac_sys_init(rtwdev); 3551e3ec7017SPing-Ke Shih if (ret) 3552e3ec7017SPing-Ke Shih goto fail; 3553e3ec7017SPing-Ke Shih 3554e3ec7017SPing-Ke Shih ret = rtw89_mac_trx_init(rtwdev); 3555e3ec7017SPing-Ke Shih if (ret) 3556e3ec7017SPing-Ke Shih goto fail; 3557e3ec7017SPing-Ke Shih 3558e3ec7017SPing-Ke Shih if (rtwdev->hci.ops->mac_post_init) { 3559e3ec7017SPing-Ke Shih ret = rtwdev->hci.ops->mac_post_init(rtwdev); 3560e3ec7017SPing-Ke Shih if (ret) 3561e3ec7017SPing-Ke Shih goto fail; 3562e3ec7017SPing-Ke Shih } 3563e3ec7017SPing-Ke Shih 3564e3ec7017SPing-Ke Shih rtw89_fw_send_all_early_h2c(rtwdev); 3565e3ec7017SPing-Ke Shih rtw89_fw_h2c_set_ofld_cfg(rtwdev); 3566e3ec7017SPing-Ke Shih 3567e3ec7017SPing-Ke Shih return ret; 3568e3ec7017SPing-Ke Shih fail: 3569e3ec7017SPing-Ke Shih rtw89_mac_power_switch(rtwdev, false); 3570e3ec7017SPing-Ke Shih 3571e3ec7017SPing-Ke Shih return ret; 3572e3ec7017SPing-Ke Shih } 3573e3ec7017SPing-Ke Shih 3574e3ec7017SPing-Ke Shih static void rtw89_mac_dmac_tbl_init(struct rtw89_dev *rtwdev, u8 macid) 3575e3ec7017SPing-Ke Shih { 3576e3ec7017SPing-Ke Shih u8 i; 3577e3ec7017SPing-Ke Shih 3578e3ec7017SPing-Ke Shih for (i = 0; i < 4; i++) { 3579e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_FILTER_MODEL_ADDR, 3580e3ec7017SPing-Ke Shih DMAC_TBL_BASE_ADDR + (macid << 4) + (i << 2)); 3581e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY, 0); 3582e3ec7017SPing-Ke Shih } 3583e3ec7017SPing-Ke Shih } 3584e3ec7017SPing-Ke Shih 3585e3ec7017SPing-Ke Shih static void rtw89_mac_cmac_tbl_init(struct rtw89_dev *rtwdev, u8 macid) 3586e3ec7017SPing-Ke Shih { 3587e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_FILTER_MODEL_ADDR, 3588e3ec7017SPing-Ke Shih CMAC_TBL_BASE_ADDR + macid * CCTL_INFO_SIZE); 3589e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY, 0x4); 3590e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY + 4, 0x400A0004); 3591e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY + 8, 0); 3592e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY + 12, 0); 3593e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY + 16, 0); 3594e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY + 20, 0xE43000B); 3595e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY + 24, 0); 3596e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_INDIR_ACCESS_ENTRY + 28, 0xB8109); 3597e3ec7017SPing-Ke Shih } 3598e3ec7017SPing-Ke Shih 35991b73e77dSPing-Ke Shih int rtw89_mac_set_macid_pause(struct rtw89_dev *rtwdev, u8 macid, bool pause) 3600e3ec7017SPing-Ke Shih { 3601e3ec7017SPing-Ke Shih u8 sh = FIELD_GET(GENMASK(4, 0), macid); 3602e3ec7017SPing-Ke Shih u8 grp = macid >> 5; 3603e3ec7017SPing-Ke Shih int ret; 3604e3ec7017SPing-Ke Shih 3605e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, RTW89_MAC_0, RTW89_CMAC_SEL); 3606e3ec7017SPing-Ke Shih if (ret) 3607e3ec7017SPing-Ke Shih return ret; 3608e3ec7017SPing-Ke Shih 3609e3ec7017SPing-Ke Shih rtw89_fw_h2c_macid_pause(rtwdev, sh, grp, pause); 3610e3ec7017SPing-Ke Shih 3611e3ec7017SPing-Ke Shih return 0; 3612e3ec7017SPing-Ke Shih } 3613e3ec7017SPing-Ke Shih 3614e3ec7017SPing-Ke Shih static const struct rtw89_port_reg rtw_port_base = { 3615e3ec7017SPing-Ke Shih .port_cfg = R_AX_PORT_CFG_P0, 3616e3ec7017SPing-Ke Shih .tbtt_prohib = R_AX_TBTT_PROHIB_P0, 3617e3ec7017SPing-Ke Shih .bcn_area = R_AX_BCN_AREA_P0, 3618e3ec7017SPing-Ke Shih .bcn_early = R_AX_BCNERLYINT_CFG_P0, 3619e3ec7017SPing-Ke Shih .tbtt_early = R_AX_TBTTERLYINT_CFG_P0, 3620e3ec7017SPing-Ke Shih .tbtt_agg = R_AX_TBTT_AGG_P0, 3621e3ec7017SPing-Ke Shih .bcn_space = R_AX_BCN_SPACE_CFG_P0, 3622e3ec7017SPing-Ke Shih .bcn_forcetx = R_AX_BCN_FORCETX_P0, 3623e3ec7017SPing-Ke Shih .bcn_err_cnt = R_AX_BCN_ERR_CNT_P0, 3624e3ec7017SPing-Ke Shih .bcn_err_flag = R_AX_BCN_ERR_FLAG_P0, 3625e3ec7017SPing-Ke Shih .dtim_ctrl = R_AX_DTIM_CTRL_P0, 3626e3ec7017SPing-Ke Shih .tbtt_shift = R_AX_TBTT_SHIFT_P0, 3627e3ec7017SPing-Ke Shih .bcn_cnt_tmr = R_AX_BCN_CNT_TMR_P0, 3628e3ec7017SPing-Ke Shih .tsftr_l = R_AX_TSFTR_LOW_P0, 3629e3ec7017SPing-Ke Shih .tsftr_h = R_AX_TSFTR_HIGH_P0 3630e3ec7017SPing-Ke Shih }; 3631e3ec7017SPing-Ke Shih 3632e3ec7017SPing-Ke Shih #define BCN_INTERVAL 100 3633e3ec7017SPing-Ke Shih #define BCN_ERLY_DEF 160 3634e3ec7017SPing-Ke Shih #define BCN_SETUP_DEF 2 3635e3ec7017SPing-Ke Shih #define BCN_HOLD_DEF 200 3636e3ec7017SPing-Ke Shih #define BCN_MASK_DEF 0 3637e3ec7017SPing-Ke Shih #define TBTT_ERLY_DEF 5 3638e3ec7017SPing-Ke Shih #define BCN_SET_UNIT 32 3639e3ec7017SPing-Ke Shih #define BCN_ERLY_SET_DLY (10 * 2) 3640e3ec7017SPing-Ke Shih 3641e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_func_sw(struct rtw89_dev *rtwdev, 3642e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3643e3ec7017SPing-Ke Shih { 3644e3ec7017SPing-Ke Shih struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif); 3645e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3646e3ec7017SPing-Ke Shih 3647e3ec7017SPing-Ke Shih if (!rtw89_read32_port_mask(rtwdev, rtwvif, p->port_cfg, B_AX_PORT_FUNC_EN)) 3648e3ec7017SPing-Ke Shih return; 3649e3ec7017SPing-Ke Shih 3650e3ec7017SPing-Ke Shih rtw89_write32_port_clr(rtwdev, rtwvif, p->tbtt_prohib, B_AX_TBTT_SETUP_MASK); 3651e3ec7017SPing-Ke Shih rtw89_write32_port_mask(rtwdev, rtwvif, p->tbtt_prohib, B_AX_TBTT_HOLD_MASK, 1); 3652e3ec7017SPing-Ke Shih rtw89_write16_port_clr(rtwdev, rtwvif, p->tbtt_early, B_AX_TBTTERLY_MASK); 3653e3ec7017SPing-Ke Shih rtw89_write16_port_clr(rtwdev, rtwvif, p->bcn_early, B_AX_BCNERLY_MASK); 3654e3ec7017SPing-Ke Shih 3655e3ec7017SPing-Ke Shih msleep(vif->bss_conf.beacon_int + 1); 3656e3ec7017SPing-Ke Shih 3657e3ec7017SPing-Ke Shih rtw89_write32_port_clr(rtwdev, rtwvif, p->port_cfg, B_AX_PORT_FUNC_EN | 3658e3ec7017SPing-Ke Shih B_AX_BRK_SETUP); 3659e3ec7017SPing-Ke Shih rtw89_write32_port_set(rtwdev, rtwvif, p->port_cfg, B_AX_TSFTR_RST); 3660e3ec7017SPing-Ke Shih rtw89_write32_port(rtwdev, rtwvif, p->bcn_cnt_tmr, 0); 3661e3ec7017SPing-Ke Shih } 3662e3ec7017SPing-Ke Shih 3663e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_tx_rpt(struct rtw89_dev *rtwdev, 3664e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif, bool en) 3665e3ec7017SPing-Ke Shih { 3666e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3667e3ec7017SPing-Ke Shih 3668e3ec7017SPing-Ke Shih if (en) 3669e3ec7017SPing-Ke Shih rtw89_write32_port_set(rtwdev, rtwvif, p->port_cfg, B_AX_TXBCN_RPT_EN); 3670e3ec7017SPing-Ke Shih else 3671e3ec7017SPing-Ke Shih rtw89_write32_port_clr(rtwdev, rtwvif, p->port_cfg, B_AX_TXBCN_RPT_EN); 3672e3ec7017SPing-Ke Shih } 3673e3ec7017SPing-Ke Shih 3674e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_rx_rpt(struct rtw89_dev *rtwdev, 3675e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif, bool en) 3676e3ec7017SPing-Ke Shih { 3677e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3678e3ec7017SPing-Ke Shih 3679e3ec7017SPing-Ke Shih if (en) 3680e3ec7017SPing-Ke Shih rtw89_write32_port_set(rtwdev, rtwvif, p->port_cfg, B_AX_RXBCN_RPT_EN); 3681e3ec7017SPing-Ke Shih else 3682e3ec7017SPing-Ke Shih rtw89_write32_port_clr(rtwdev, rtwvif, p->port_cfg, B_AX_RXBCN_RPT_EN); 3683e3ec7017SPing-Ke Shih } 3684e3ec7017SPing-Ke Shih 3685e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_net_type(struct rtw89_dev *rtwdev, 3686e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3687e3ec7017SPing-Ke Shih { 3688e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3689e3ec7017SPing-Ke Shih 3690e3ec7017SPing-Ke Shih rtw89_write32_port_mask(rtwdev, rtwvif, p->port_cfg, B_AX_NET_TYPE_MASK, 3691e3ec7017SPing-Ke Shih rtwvif->net_type); 3692e3ec7017SPing-Ke Shih } 3693e3ec7017SPing-Ke Shih 3694e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_bcn_prct(struct rtw89_dev *rtwdev, 3695e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3696e3ec7017SPing-Ke Shih { 3697e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3698e3ec7017SPing-Ke Shih bool en = rtwvif->net_type != RTW89_NET_TYPE_NO_LINK; 3699e3ec7017SPing-Ke Shih u32 bits = B_AX_TBTT_PROHIB_EN | B_AX_BRK_SETUP; 3700e3ec7017SPing-Ke Shih 3701e3ec7017SPing-Ke Shih if (en) 3702e3ec7017SPing-Ke Shih rtw89_write32_port_set(rtwdev, rtwvif, p->port_cfg, bits); 3703e3ec7017SPing-Ke Shih else 3704e3ec7017SPing-Ke Shih rtw89_write32_port_clr(rtwdev, rtwvif, p->port_cfg, bits); 3705e3ec7017SPing-Ke Shih } 3706e3ec7017SPing-Ke Shih 3707e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_rx_sw(struct rtw89_dev *rtwdev, 3708e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3709e3ec7017SPing-Ke Shih { 3710e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3711e3ec7017SPing-Ke Shih bool en = rtwvif->net_type == RTW89_NET_TYPE_INFRA || 3712e3ec7017SPing-Ke Shih rtwvif->net_type == RTW89_NET_TYPE_AD_HOC; 3713e3ec7017SPing-Ke Shih u32 bit = B_AX_RX_BSSID_FIT_EN; 3714e3ec7017SPing-Ke Shih 3715e3ec7017SPing-Ke Shih if (en) 3716e3ec7017SPing-Ke Shih rtw89_write32_port_set(rtwdev, rtwvif, p->port_cfg, bit); 3717e3ec7017SPing-Ke Shih else 3718e3ec7017SPing-Ke Shih rtw89_write32_port_clr(rtwdev, rtwvif, p->port_cfg, bit); 3719e3ec7017SPing-Ke Shih } 3720e3ec7017SPing-Ke Shih 3721e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_rx_sync(struct rtw89_dev *rtwdev, 3722e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3723e3ec7017SPing-Ke Shih { 3724e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3725e3ec7017SPing-Ke Shih bool en = rtwvif->net_type == RTW89_NET_TYPE_INFRA || 3726e3ec7017SPing-Ke Shih rtwvif->net_type == RTW89_NET_TYPE_AD_HOC; 3727e3ec7017SPing-Ke Shih 3728e3ec7017SPing-Ke Shih if (en) 3729e3ec7017SPing-Ke Shih rtw89_write32_port_set(rtwdev, rtwvif, p->port_cfg, B_AX_TSF_UDT_EN); 3730e3ec7017SPing-Ke Shih else 3731e3ec7017SPing-Ke Shih rtw89_write32_port_clr(rtwdev, rtwvif, p->port_cfg, B_AX_TSF_UDT_EN); 3732e3ec7017SPing-Ke Shih } 3733e3ec7017SPing-Ke Shih 3734e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_tx_sw(struct rtw89_dev *rtwdev, 3735e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3736e3ec7017SPing-Ke Shih { 3737e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3738e3ec7017SPing-Ke Shih bool en = rtwvif->net_type == RTW89_NET_TYPE_AP_MODE || 3739e3ec7017SPing-Ke Shih rtwvif->net_type == RTW89_NET_TYPE_AD_HOC; 3740e3ec7017SPing-Ke Shih 3741e3ec7017SPing-Ke Shih if (en) 3742e3ec7017SPing-Ke Shih rtw89_write32_port_set(rtwdev, rtwvif, p->port_cfg, B_AX_BCNTX_EN); 3743e3ec7017SPing-Ke Shih else 3744e3ec7017SPing-Ke Shih rtw89_write32_port_clr(rtwdev, rtwvif, p->port_cfg, B_AX_BCNTX_EN); 3745e3ec7017SPing-Ke Shih } 3746e3ec7017SPing-Ke Shih 3747e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_bcn_intv(struct rtw89_dev *rtwdev, 3748e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3749e3ec7017SPing-Ke Shih { 3750e3ec7017SPing-Ke Shih struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif); 3751e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3752e3ec7017SPing-Ke Shih u16 bcn_int = vif->bss_conf.beacon_int ? vif->bss_conf.beacon_int : BCN_INTERVAL; 3753e3ec7017SPing-Ke Shih 3754e3ec7017SPing-Ke Shih rtw89_write32_port_mask(rtwdev, rtwvif, p->bcn_space, B_AX_BCN_SPACE_MASK, 3755e3ec7017SPing-Ke Shih bcn_int); 3756e3ec7017SPing-Ke Shih } 3757e3ec7017SPing-Ke Shih 3758283c3d88SPing-Ke Shih static void rtw89_mac_port_cfg_hiq_win(struct rtw89_dev *rtwdev, 3759283c3d88SPing-Ke Shih struct rtw89_vif *rtwvif) 3760283c3d88SPing-Ke Shih { 3761283c3d88SPing-Ke Shih static const u32 hiq_win_addr[RTW89_PORT_NUM] = { 3762283c3d88SPing-Ke Shih R_AX_P0MB_HGQ_WINDOW_CFG_0, R_AX_PORT_HGQ_WINDOW_CFG, 3763283c3d88SPing-Ke Shih R_AX_PORT_HGQ_WINDOW_CFG + 1, R_AX_PORT_HGQ_WINDOW_CFG + 2, 3764283c3d88SPing-Ke Shih R_AX_PORT_HGQ_WINDOW_CFG + 3, 3765283c3d88SPing-Ke Shih }; 3766283c3d88SPing-Ke Shih u8 win = rtwvif->net_type == RTW89_NET_TYPE_AP_MODE ? 16 : 0; 3767283c3d88SPing-Ke Shih u8 port = rtwvif->port; 3768283c3d88SPing-Ke Shih u32 reg; 3769283c3d88SPing-Ke Shih 3770283c3d88SPing-Ke Shih reg = rtw89_mac_reg_by_idx(hiq_win_addr[port], rtwvif->mac_idx); 3771283c3d88SPing-Ke Shih rtw89_write8(rtwdev, reg, win); 3772283c3d88SPing-Ke Shih } 3773283c3d88SPing-Ke Shih 3774283c3d88SPing-Ke Shih static void rtw89_mac_port_cfg_hiq_dtim(struct rtw89_dev *rtwdev, 3775283c3d88SPing-Ke Shih struct rtw89_vif *rtwvif) 3776283c3d88SPing-Ke Shih { 3777283c3d88SPing-Ke Shih struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif); 3778283c3d88SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3779283c3d88SPing-Ke Shih u32 addr; 3780283c3d88SPing-Ke Shih 3781283c3d88SPing-Ke Shih addr = rtw89_mac_reg_by_idx(R_AX_MD_TSFT_STMP_CTL, rtwvif->mac_idx); 3782283c3d88SPing-Ke Shih rtw89_write8_set(rtwdev, addr, B_AX_UPD_HGQMD | B_AX_UPD_TIMIE); 3783283c3d88SPing-Ke Shih 3784283c3d88SPing-Ke Shih rtw89_write16_port_mask(rtwdev, rtwvif, p->dtim_ctrl, B_AX_DTIM_NUM_MASK, 3785283c3d88SPing-Ke Shih vif->bss_conf.dtim_period); 3786283c3d88SPing-Ke Shih } 3787283c3d88SPing-Ke Shih 3788e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_bcn_setup_time(struct rtw89_dev *rtwdev, 3789e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3790e3ec7017SPing-Ke Shih { 3791e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3792e3ec7017SPing-Ke Shih 3793e3ec7017SPing-Ke Shih rtw89_write32_port_mask(rtwdev, rtwvif, p->tbtt_prohib, 3794e3ec7017SPing-Ke Shih B_AX_TBTT_SETUP_MASK, BCN_SETUP_DEF); 3795e3ec7017SPing-Ke Shih } 3796e3ec7017SPing-Ke Shih 3797e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_bcn_hold_time(struct rtw89_dev *rtwdev, 3798e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3799e3ec7017SPing-Ke Shih { 3800e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3801e3ec7017SPing-Ke Shih 3802e3ec7017SPing-Ke Shih rtw89_write32_port_mask(rtwdev, rtwvif, p->tbtt_prohib, 3803e3ec7017SPing-Ke Shih B_AX_TBTT_HOLD_MASK, BCN_HOLD_DEF); 3804e3ec7017SPing-Ke Shih } 3805e3ec7017SPing-Ke Shih 3806e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_bcn_mask_area(struct rtw89_dev *rtwdev, 3807e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3808e3ec7017SPing-Ke Shih { 3809e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3810e3ec7017SPing-Ke Shih 3811e3ec7017SPing-Ke Shih rtw89_write32_port_mask(rtwdev, rtwvif, p->bcn_area, 3812e3ec7017SPing-Ke Shih B_AX_BCN_MSK_AREA_MASK, BCN_MASK_DEF); 3813e3ec7017SPing-Ke Shih } 3814e3ec7017SPing-Ke Shih 3815e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_tbtt_early(struct rtw89_dev *rtwdev, 3816e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3817e3ec7017SPing-Ke Shih { 3818e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3819e3ec7017SPing-Ke Shih 3820e3ec7017SPing-Ke Shih rtw89_write16_port_mask(rtwdev, rtwvif, p->tbtt_early, 3821e3ec7017SPing-Ke Shih B_AX_TBTTERLY_MASK, TBTT_ERLY_DEF); 3822e3ec7017SPing-Ke Shih } 3823e3ec7017SPing-Ke Shih 3824e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_bss_color(struct rtw89_dev *rtwdev, 3825e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3826e3ec7017SPing-Ke Shih { 3827e3ec7017SPing-Ke Shih struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif); 3828e3ec7017SPing-Ke Shih static const u32 masks[RTW89_PORT_NUM] = { 3829e3ec7017SPing-Ke Shih B_AX_BSS_COLOB_AX_PORT_0_MASK, B_AX_BSS_COLOB_AX_PORT_1_MASK, 3830e3ec7017SPing-Ke Shih B_AX_BSS_COLOB_AX_PORT_2_MASK, B_AX_BSS_COLOB_AX_PORT_3_MASK, 3831e3ec7017SPing-Ke Shih B_AX_BSS_COLOB_AX_PORT_4_MASK, 3832e3ec7017SPing-Ke Shih }; 3833e3ec7017SPing-Ke Shih u8 port = rtwvif->port; 3834e3ec7017SPing-Ke Shih u32 reg_base; 3835e3ec7017SPing-Ke Shih u32 reg; 3836e3ec7017SPing-Ke Shih u8 bss_color; 3837e3ec7017SPing-Ke Shih 3838e3ec7017SPing-Ke Shih bss_color = vif->bss_conf.he_bss_color.color; 3839e3ec7017SPing-Ke Shih reg_base = port >= 4 ? R_AX_PTCL_BSS_COLOR_1 : R_AX_PTCL_BSS_COLOR_0; 3840e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(reg_base, rtwvif->mac_idx); 3841e3ec7017SPing-Ke Shih rtw89_write32_mask(rtwdev, reg, masks[port], bss_color); 3842e3ec7017SPing-Ke Shih } 3843e3ec7017SPing-Ke Shih 3844e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_mbssid(struct rtw89_dev *rtwdev, 3845e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3846e3ec7017SPing-Ke Shih { 3847e3ec7017SPing-Ke Shih u8 port = rtwvif->port; 3848e3ec7017SPing-Ke Shih u32 reg; 3849e3ec7017SPing-Ke Shih 3850e3ec7017SPing-Ke Shih if (rtwvif->net_type == RTW89_NET_TYPE_AP_MODE) 3851e3ec7017SPing-Ke Shih return; 3852e3ec7017SPing-Ke Shih 3853e3ec7017SPing-Ke Shih if (port == 0) { 3854e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_MBSSID_CTRL, rtwvif->mac_idx); 3855e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, reg, B_AX_P0MB_ALL_MASK); 3856e3ec7017SPing-Ke Shih } 3857e3ec7017SPing-Ke Shih } 3858e3ec7017SPing-Ke Shih 3859e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_hiq_drop(struct rtw89_dev *rtwdev, 3860e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3861e3ec7017SPing-Ke Shih { 3862e3ec7017SPing-Ke Shih u8 port = rtwvif->port; 3863e3ec7017SPing-Ke Shih u32 reg; 3864e3ec7017SPing-Ke Shih u32 val; 3865e3ec7017SPing-Ke Shih 3866e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_MBSSID_DROP_0, rtwvif->mac_idx); 3867e3ec7017SPing-Ke Shih val = rtw89_read32(rtwdev, reg); 3868e3ec7017SPing-Ke Shih val &= ~FIELD_PREP(B_AX_PORT_DROP_4_0_MASK, BIT(port)); 3869e3ec7017SPing-Ke Shih if (port == 0) 3870e3ec7017SPing-Ke Shih val &= ~BIT(0); 3871e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val); 3872e3ec7017SPing-Ke Shih } 3873e3ec7017SPing-Ke Shih 3874e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_func_en(struct rtw89_dev *rtwdev, 3875e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3876e3ec7017SPing-Ke Shih { 3877e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3878e3ec7017SPing-Ke Shih 3879e3ec7017SPing-Ke Shih rtw89_write32_port_set(rtwdev, rtwvif, p->port_cfg, B_AX_PORT_FUNC_EN); 3880e3ec7017SPing-Ke Shih } 3881e3ec7017SPing-Ke Shih 3882e3ec7017SPing-Ke Shih static void rtw89_mac_port_cfg_bcn_early(struct rtw89_dev *rtwdev, 3883e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif) 3884e3ec7017SPing-Ke Shih { 3885e3ec7017SPing-Ke Shih const struct rtw89_port_reg *p = &rtw_port_base; 3886e3ec7017SPing-Ke Shih 3887e3ec7017SPing-Ke Shih rtw89_write32_port_mask(rtwdev, rtwvif, p->bcn_early, B_AX_BCNERLY_MASK, 3888e3ec7017SPing-Ke Shih BCN_ERLY_DEF); 3889e3ec7017SPing-Ke Shih } 3890e3ec7017SPing-Ke Shih 3891704052f5SChia-Yuan Li static void rtw89_mac_port_cfg_tbtt_shift(struct rtw89_dev *rtwdev, 3892704052f5SChia-Yuan Li struct rtw89_vif *rtwvif) 3893704052f5SChia-Yuan Li { 3894704052f5SChia-Yuan Li const struct rtw89_port_reg *p = &rtw_port_base; 3895704052f5SChia-Yuan Li u16 val; 3896704052f5SChia-Yuan Li 3897704052f5SChia-Yuan Li if (rtwdev->chip->chip_id != RTL8852C) 3898704052f5SChia-Yuan Li return; 3899704052f5SChia-Yuan Li 3900704052f5SChia-Yuan Li if (rtwvif->wifi_role != RTW89_WIFI_ROLE_P2P_CLIENT && 3901704052f5SChia-Yuan Li rtwvif->wifi_role != RTW89_WIFI_ROLE_STATION) 3902704052f5SChia-Yuan Li return; 3903704052f5SChia-Yuan Li 3904704052f5SChia-Yuan Li val = FIELD_PREP(B_AX_TBTT_SHIFT_OFST_MAG, 1) | 3905704052f5SChia-Yuan Li B_AX_TBTT_SHIFT_OFST_SIGN; 3906704052f5SChia-Yuan Li 3907704052f5SChia-Yuan Li rtw89_write16_port_mask(rtwdev, rtwvif, p->tbtt_shift, 3908704052f5SChia-Yuan Li B_AX_TBTT_SHIFT_OFST_MASK, val); 3909704052f5SChia-Yuan Li } 3910704052f5SChia-Yuan Li 3911e3ec7017SPing-Ke Shih int rtw89_mac_vif_init(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif) 3912e3ec7017SPing-Ke Shih { 3913e3ec7017SPing-Ke Shih int ret; 3914e3ec7017SPing-Ke Shih 3915e3ec7017SPing-Ke Shih ret = rtw89_mac_port_update(rtwdev, rtwvif); 3916e3ec7017SPing-Ke Shih if (ret) 3917e3ec7017SPing-Ke Shih return ret; 3918e3ec7017SPing-Ke Shih 3919e3ec7017SPing-Ke Shih rtw89_mac_dmac_tbl_init(rtwdev, rtwvif->mac_id); 3920e3ec7017SPing-Ke Shih rtw89_mac_cmac_tbl_init(rtwdev, rtwvif->mac_id); 3921e3ec7017SPing-Ke Shih 39221b73e77dSPing-Ke Shih ret = rtw89_mac_set_macid_pause(rtwdev, rtwvif->mac_id, false); 3923e3ec7017SPing-Ke Shih if (ret) 3924e3ec7017SPing-Ke Shih return ret; 3925e3ec7017SPing-Ke Shih 3926ff66964aSPing-Ke Shih ret = rtw89_fw_h2c_role_maintain(rtwdev, rtwvif, NULL, RTW89_ROLE_CREATE); 3927e3ec7017SPing-Ke Shih if (ret) 3928e3ec7017SPing-Ke Shih return ret; 3929e3ec7017SPing-Ke Shih 3930e3ec7017SPing-Ke Shih ret = rtw89_cam_init(rtwdev, rtwvif); 3931e3ec7017SPing-Ke Shih if (ret) 3932e3ec7017SPing-Ke Shih return ret; 3933e3ec7017SPing-Ke Shih 393440822e07SPing-Ke Shih ret = rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL); 3935e3ec7017SPing-Ke Shih if (ret) 3936e3ec7017SPing-Ke Shih return ret; 3937e3ec7017SPing-Ke Shih 3938742c470bSPing-Ke Shih ret = rtw89_fw_h2c_default_cmac_tbl(rtwdev, rtwvif); 3939e3ec7017SPing-Ke Shih if (ret) 3940e3ec7017SPing-Ke Shih return ret; 3941e3ec7017SPing-Ke Shih 3942e3ec7017SPing-Ke Shih return 0; 3943e3ec7017SPing-Ke Shih } 3944e3ec7017SPing-Ke Shih 3945e3ec7017SPing-Ke Shih int rtw89_mac_vif_deinit(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif) 3946e3ec7017SPing-Ke Shih { 3947e3ec7017SPing-Ke Shih int ret; 3948e3ec7017SPing-Ke Shih 3949ff66964aSPing-Ke Shih ret = rtw89_fw_h2c_role_maintain(rtwdev, rtwvif, NULL, RTW89_ROLE_REMOVE); 3950e3ec7017SPing-Ke Shih if (ret) 3951e3ec7017SPing-Ke Shih return ret; 3952e3ec7017SPing-Ke Shih 3953e3ec7017SPing-Ke Shih rtw89_cam_deinit(rtwdev, rtwvif); 3954e3ec7017SPing-Ke Shih 395540822e07SPing-Ke Shih ret = rtw89_fw_h2c_cam(rtwdev, rtwvif, NULL, NULL); 3956e3ec7017SPing-Ke Shih if (ret) 3957e3ec7017SPing-Ke Shih return ret; 3958e3ec7017SPing-Ke Shih 3959e3ec7017SPing-Ke Shih return 0; 3960e3ec7017SPing-Ke Shih } 3961e3ec7017SPing-Ke Shih 3962e3ec7017SPing-Ke Shih int rtw89_mac_port_update(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif) 3963e3ec7017SPing-Ke Shih { 3964e3ec7017SPing-Ke Shih u8 port = rtwvif->port; 3965e3ec7017SPing-Ke Shih 3966e3ec7017SPing-Ke Shih if (port >= RTW89_PORT_NUM) 3967e3ec7017SPing-Ke Shih return -EINVAL; 3968e3ec7017SPing-Ke Shih 3969e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_func_sw(rtwdev, rtwvif); 3970e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_tx_rpt(rtwdev, rtwvif, false); 3971e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_rx_rpt(rtwdev, rtwvif, false); 3972e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_net_type(rtwdev, rtwvif); 3973e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_bcn_prct(rtwdev, rtwvif); 3974e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_rx_sw(rtwdev, rtwvif); 3975e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_rx_sync(rtwdev, rtwvif); 3976e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_tx_sw(rtwdev, rtwvif); 3977e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_bcn_intv(rtwdev, rtwvif); 3978283c3d88SPing-Ke Shih rtw89_mac_port_cfg_hiq_win(rtwdev, rtwvif); 3979283c3d88SPing-Ke Shih rtw89_mac_port_cfg_hiq_dtim(rtwdev, rtwvif); 3980283c3d88SPing-Ke Shih rtw89_mac_port_cfg_hiq_drop(rtwdev, rtwvif); 3981e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_bcn_setup_time(rtwdev, rtwvif); 3982e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_bcn_hold_time(rtwdev, rtwvif); 3983e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_bcn_mask_area(rtwdev, rtwvif); 3984e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_tbtt_early(rtwdev, rtwvif); 3985704052f5SChia-Yuan Li rtw89_mac_port_cfg_tbtt_shift(rtwdev, rtwvif); 3986e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_bss_color(rtwdev, rtwvif); 3987e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_mbssid(rtwdev, rtwvif); 3988e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_func_en(rtwdev, rtwvif); 3989e3ec7017SPing-Ke Shih fsleep(BCN_ERLY_SET_DLY); 3990e3ec7017SPing-Ke Shih rtw89_mac_port_cfg_bcn_early(rtwdev, rtwvif); 3991e3ec7017SPing-Ke Shih 3992e3ec7017SPing-Ke Shih return 0; 3993e3ec7017SPing-Ke Shih } 3994e3ec7017SPing-Ke Shih 39958d540f9dSKuan-Chung Chen static void rtw89_mac_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, 39968d540f9dSKuan-Chung Chen struct cfg80211_bss *bss, 39978d540f9dSKuan-Chung Chen void *data) 39988d540f9dSKuan-Chung Chen { 39998d540f9dSKuan-Chung Chen const struct cfg80211_bss_ies *ies; 40008d540f9dSKuan-Chung Chen const struct element *elem; 40018d540f9dSKuan-Chung Chen bool *tolerated = data; 40028d540f9dSKuan-Chung Chen 40038d540f9dSKuan-Chung Chen rcu_read_lock(); 40048d540f9dSKuan-Chung Chen ies = rcu_dereference(bss->ies); 40058d540f9dSKuan-Chung Chen elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, 40068d540f9dSKuan-Chung Chen ies->len); 40078d540f9dSKuan-Chung Chen 40088d540f9dSKuan-Chung Chen if (!elem || elem->datalen < 10 || 40098d540f9dSKuan-Chung Chen !(elem->data[10] & WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) 40108d540f9dSKuan-Chung Chen *tolerated = false; 40118d540f9dSKuan-Chung Chen rcu_read_unlock(); 40128d540f9dSKuan-Chung Chen } 40138d540f9dSKuan-Chung Chen 40148d540f9dSKuan-Chung Chen void rtw89_mac_set_he_obss_narrow_bw_ru(struct rtw89_dev *rtwdev, 40158d540f9dSKuan-Chung Chen struct ieee80211_vif *vif) 40168d540f9dSKuan-Chung Chen { 40178d540f9dSKuan-Chung Chen struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv; 40188d540f9dSKuan-Chung Chen struct ieee80211_hw *hw = rtwdev->hw; 40198d540f9dSKuan-Chung Chen bool tolerated = true; 40208d540f9dSKuan-Chung Chen u32 reg; 40218d540f9dSKuan-Chung Chen 40228d540f9dSKuan-Chung Chen if (!vif->bss_conf.he_support || vif->type != NL80211_IFTYPE_STATION) 40238d540f9dSKuan-Chung Chen return; 40248d540f9dSKuan-Chung Chen 40258d540f9dSKuan-Chung Chen if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) 40268d540f9dSKuan-Chung Chen return; 40278d540f9dSKuan-Chung Chen 40288d540f9dSKuan-Chung Chen cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef, 40298d540f9dSKuan-Chung Chen rtw89_mac_check_he_obss_narrow_bw_ru_iter, 40308d540f9dSKuan-Chung Chen &tolerated); 40318d540f9dSKuan-Chung Chen 40328d540f9dSKuan-Chung Chen reg = rtw89_mac_reg_by_idx(R_AX_RXTRIG_TEST_USER_2, rtwvif->mac_idx); 40338d540f9dSKuan-Chung Chen if (tolerated) 40348d540f9dSKuan-Chung Chen rtw89_write32_clr(rtwdev, reg, B_AX_RXTRIG_RU26_DIS); 40358d540f9dSKuan-Chung Chen else 40368d540f9dSKuan-Chung Chen rtw89_write32_set(rtwdev, reg, B_AX_RXTRIG_RU26_DIS); 40378d540f9dSKuan-Chung Chen } 40388d540f9dSKuan-Chung Chen 4039e3ec7017SPing-Ke Shih int rtw89_mac_add_vif(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif) 4040e3ec7017SPing-Ke Shih { 4041e3ec7017SPing-Ke Shih int ret; 4042e3ec7017SPing-Ke Shih 4043e3ec7017SPing-Ke Shih rtwvif->mac_id = rtw89_core_acquire_bit_map(rtwdev->mac_id_map, 4044e3ec7017SPing-Ke Shih RTW89_MAX_MAC_ID_NUM); 4045e3ec7017SPing-Ke Shih if (rtwvif->mac_id == RTW89_MAX_MAC_ID_NUM) 4046e3ec7017SPing-Ke Shih return -ENOSPC; 4047e3ec7017SPing-Ke Shih 4048e3ec7017SPing-Ke Shih ret = rtw89_mac_vif_init(rtwdev, rtwvif); 4049e3ec7017SPing-Ke Shih if (ret) 4050e3ec7017SPing-Ke Shih goto release_mac_id; 4051e3ec7017SPing-Ke Shih 4052e3ec7017SPing-Ke Shih return 0; 4053e3ec7017SPing-Ke Shih 4054e3ec7017SPing-Ke Shih release_mac_id: 4055e3ec7017SPing-Ke Shih rtw89_core_release_bit_map(rtwdev->mac_id_map, rtwvif->mac_id); 4056e3ec7017SPing-Ke Shih 4057e3ec7017SPing-Ke Shih return ret; 4058e3ec7017SPing-Ke Shih } 4059e3ec7017SPing-Ke Shih 4060e3ec7017SPing-Ke Shih int rtw89_mac_remove_vif(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif) 4061e3ec7017SPing-Ke Shih { 4062e3ec7017SPing-Ke Shih int ret; 4063e3ec7017SPing-Ke Shih 4064e3ec7017SPing-Ke Shih ret = rtw89_mac_vif_deinit(rtwdev, rtwvif); 4065e3ec7017SPing-Ke Shih rtw89_core_release_bit_map(rtwdev->mac_id_map, rtwvif->mac_id); 4066e3ec7017SPing-Ke Shih 4067e3ec7017SPing-Ke Shih return ret; 4068e3ec7017SPing-Ke Shih } 4069e3ec7017SPing-Ke Shih 4070e3ec7017SPing-Ke Shih static void 4071e3ec7017SPing-Ke Shih rtw89_mac_c2h_macid_pause(struct rtw89_dev *rtwdev, struct sk_buff *c2h, u32 len) 4072e3ec7017SPing-Ke Shih { 4073e3ec7017SPing-Ke Shih } 4074e3ec7017SPing-Ke Shih 407589590777SPo Hao Huang static bool rtw89_is_op_chan(struct rtw89_dev *rtwdev, u8 band, u8 channel) 407689590777SPo Hao Huang { 407789590777SPo Hao Huang struct rtw89_hw_scan_info *scan_info = &rtwdev->scan_info; 407889590777SPo Hao Huang 407989590777SPo Hao Huang return band == scan_info->op_band && channel == scan_info->op_pri_ch; 408089590777SPo Hao Huang } 408189590777SPo Hao Huang 408289590777SPo Hao Huang static void 408389590777SPo Hao Huang rtw89_mac_c2h_scanofld_rsp(struct rtw89_dev *rtwdev, struct sk_buff *c2h, 408489590777SPo Hao Huang u32 len) 408589590777SPo Hao Huang { 408689590777SPo Hao Huang struct ieee80211_vif *vif = rtwdev->scan_info.scanning_vif; 4087bd1056d4SPo-Hao Huang struct rtw89_vif *rtwvif = vif_to_rtwvif_safe(vif); 4088cbb145b9SZong-Zhe Yang struct rtw89_chan new; 40893a1e7cb1SPo-Hao Huang u8 reason, status, tx_fail, band, actual_period; 4090bd1056d4SPo-Hao Huang u32 last_chan = rtwdev->scan_info.last_chan_idx; 409189590777SPo Hao Huang u16 chan; 4092bd1056d4SPo-Hao Huang int ret; 409389590777SPo Hao Huang 409489590777SPo Hao Huang tx_fail = RTW89_GET_MAC_C2H_SCANOFLD_TX_FAIL(c2h->data); 409589590777SPo Hao Huang status = RTW89_GET_MAC_C2H_SCANOFLD_STATUS(c2h->data); 409689590777SPo Hao Huang chan = RTW89_GET_MAC_C2H_SCANOFLD_PRI_CH(c2h->data); 409789590777SPo Hao Huang reason = RTW89_GET_MAC_C2H_SCANOFLD_RSP(c2h->data); 409889590777SPo Hao Huang band = RTW89_GET_MAC_C2H_SCANOFLD_BAND(c2h->data); 40993a1e7cb1SPo-Hao Huang actual_period = RTW89_GET_MAC_C2H_ACTUAL_PERIOD(c2h->data); 410089590777SPo Hao Huang 410189590777SPo Hao Huang if (!(rtwdev->chip->support_bands & BIT(NL80211_BAND_6GHZ))) 410289590777SPo Hao Huang band = chan > 14 ? RTW89_BAND_5G : RTW89_BAND_2G; 410389590777SPo Hao Huang 410489590777SPo Hao Huang rtw89_debug(rtwdev, RTW89_DBG_HW_SCAN, 41053a1e7cb1SPo-Hao Huang "band: %d, chan: %d, reason: %d, status: %d, tx_fail: %d, actual: %d\n", 41063a1e7cb1SPo-Hao Huang band, chan, reason, status, tx_fail, actual_period); 410789590777SPo Hao Huang 410889590777SPo Hao Huang switch (reason) { 410989590777SPo Hao Huang case RTW89_SCAN_LEAVE_CH_NOTIFY: 411089590777SPo Hao Huang if (rtw89_is_op_chan(rtwdev, band, chan)) 411189590777SPo Hao Huang ieee80211_stop_queues(rtwdev->hw); 411289590777SPo Hao Huang return; 411389590777SPo Hao Huang case RTW89_SCAN_END_SCAN_NOTIFY: 4114bd1056d4SPo-Hao Huang if (rtwvif && rtwvif->scan_req && 4115bd1056d4SPo-Hao Huang last_chan < rtwvif->scan_req->n_channels) { 4116bd1056d4SPo-Hao Huang ret = rtw89_hw_scan_offload(rtwdev, vif, true); 4117bd1056d4SPo-Hao Huang if (ret) { 4118bd1056d4SPo-Hao Huang rtw89_hw_scan_abort(rtwdev, vif); 4119bd1056d4SPo-Hao Huang rtw89_warn(rtwdev, "HW scan failed: %d\n", ret); 4120bd1056d4SPo-Hao Huang } 4121bd1056d4SPo-Hao Huang } else { 412289590777SPo Hao Huang rtw89_hw_scan_complete(rtwdev, vif, false); 4123bd1056d4SPo-Hao Huang } 412489590777SPo Hao Huang break; 412589590777SPo Hao Huang case RTW89_SCAN_ENTER_CH_NOTIFY: 4126bb8152b3SZong-Zhe Yang rtw89_chan_create(&new, chan, chan, band, RTW89_CHANNEL_WIDTH_20); 4127cbb145b9SZong-Zhe Yang rtw89_assign_entity_chan(rtwdev, RTW89_SUB_ENTITY_0, &new); 412828000f7bSPo Hao Huang if (rtw89_is_op_chan(rtwdev, band, chan)) { 412928000f7bSPo Hao Huang rtw89_store_op_chan(rtwdev, false); 413089590777SPo Hao Huang ieee80211_wake_queues(rtwdev->hw); 413128000f7bSPo Hao Huang } 413289590777SPo Hao Huang break; 413389590777SPo Hao Huang default: 413489590777SPo Hao Huang return; 413589590777SPo Hao Huang } 413689590777SPo Hao Huang } 413789590777SPo Hao Huang 4138e3ec7017SPing-Ke Shih static void 4139e3ec7017SPing-Ke Shih rtw89_mac_c2h_rec_ack(struct rtw89_dev *rtwdev, struct sk_buff *c2h, u32 len) 4140e3ec7017SPing-Ke Shih { 4141e3ec7017SPing-Ke Shih rtw89_debug(rtwdev, RTW89_DBG_FW, 4142e3ec7017SPing-Ke Shih "C2H rev ack recv, cat: %d, class: %d, func: %d, seq : %d\n", 4143e3ec7017SPing-Ke Shih RTW89_GET_MAC_C2H_REV_ACK_CAT(c2h->data), 4144e3ec7017SPing-Ke Shih RTW89_GET_MAC_C2H_REV_ACK_CLASS(c2h->data), 4145e3ec7017SPing-Ke Shih RTW89_GET_MAC_C2H_REV_ACK_FUNC(c2h->data), 4146e3ec7017SPing-Ke Shih RTW89_GET_MAC_C2H_REV_ACK_H2C_SEQ(c2h->data)); 4147e3ec7017SPing-Ke Shih } 4148e3ec7017SPing-Ke Shih 4149e3ec7017SPing-Ke Shih static void 4150e3ec7017SPing-Ke Shih rtw89_mac_c2h_done_ack(struct rtw89_dev *rtwdev, struct sk_buff *c2h, u32 len) 4151e3ec7017SPing-Ke Shih { 4152e3ec7017SPing-Ke Shih rtw89_debug(rtwdev, RTW89_DBG_FW, 4153e3ec7017SPing-Ke Shih "C2H done ack recv, cat: %d, class: %d, func: %d, ret: %d, seq : %d\n", 4154e3ec7017SPing-Ke Shih RTW89_GET_MAC_C2H_DONE_ACK_CAT(c2h->data), 4155e3ec7017SPing-Ke Shih RTW89_GET_MAC_C2H_DONE_ACK_CLASS(c2h->data), 4156e3ec7017SPing-Ke Shih RTW89_GET_MAC_C2H_DONE_ACK_FUNC(c2h->data), 4157e3ec7017SPing-Ke Shih RTW89_GET_MAC_C2H_DONE_ACK_H2C_RETURN(c2h->data), 4158e3ec7017SPing-Ke Shih RTW89_GET_MAC_C2H_DONE_ACK_H2C_SEQ(c2h->data)); 4159e3ec7017SPing-Ke Shih } 4160e3ec7017SPing-Ke Shih 4161e3ec7017SPing-Ke Shih static void 4162e3ec7017SPing-Ke Shih rtw89_mac_c2h_log(struct rtw89_dev *rtwdev, struct sk_buff *c2h, u32 len) 4163e3ec7017SPing-Ke Shih { 4164e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "%*s", RTW89_GET_C2H_LOG_LEN(len), 4165e3ec7017SPing-Ke Shih RTW89_GET_C2H_LOG_SRT_PRT(c2h->data)); 4166e3ec7017SPing-Ke Shih } 4167e3ec7017SPing-Ke Shih 4168fccca934SPing-Ke Shih static void 4169fccca934SPing-Ke Shih rtw89_mac_c2h_bcn_cnt(struct rtw89_dev *rtwdev, struct sk_buff *c2h, u32 len) 4170fccca934SPing-Ke Shih { 4171fccca934SPing-Ke Shih } 4172fccca934SPing-Ke Shih 41732b8219e9SPo Hao Huang static void 41742b8219e9SPo Hao Huang rtw89_mac_c2h_pkt_ofld_rsp(struct rtw89_dev *rtwdev, struct sk_buff *c2h, 41752b8219e9SPo Hao Huang u32 len) 41762b8219e9SPo Hao Huang { 41772b8219e9SPo Hao Huang } 41782b8219e9SPo Hao Huang 4179f4a43c3bSDian-Syuan Yang static void 4180f4a43c3bSDian-Syuan Yang rtw89_mac_c2h_tsf32_toggle_rpt(struct rtw89_dev *rtwdev, struct sk_buff *c2h, 4181f4a43c3bSDian-Syuan Yang u32 len) 4182f4a43c3bSDian-Syuan Yang { 4183f4a43c3bSDian-Syuan Yang } 4184f4a43c3bSDian-Syuan Yang 4185e3ec7017SPing-Ke Shih static 4186e3ec7017SPing-Ke Shih void (* const rtw89_mac_c2h_ofld_handler[])(struct rtw89_dev *rtwdev, 4187e3ec7017SPing-Ke Shih struct sk_buff *c2h, u32 len) = { 4188e3ec7017SPing-Ke Shih [RTW89_MAC_C2H_FUNC_EFUSE_DUMP] = NULL, 4189e3ec7017SPing-Ke Shih [RTW89_MAC_C2H_FUNC_READ_RSP] = NULL, 41902b8219e9SPo Hao Huang [RTW89_MAC_C2H_FUNC_PKT_OFLD_RSP] = rtw89_mac_c2h_pkt_ofld_rsp, 4191e3ec7017SPing-Ke Shih [RTW89_MAC_C2H_FUNC_BCN_RESEND] = NULL, 4192e3ec7017SPing-Ke Shih [RTW89_MAC_C2H_FUNC_MACID_PAUSE] = rtw89_mac_c2h_macid_pause, 419389590777SPo Hao Huang [RTW89_MAC_C2H_FUNC_SCANOFLD_RSP] = rtw89_mac_c2h_scanofld_rsp, 4194f4a43c3bSDian-Syuan Yang [RTW89_MAC_C2H_FUNC_TSF32_TOGL_RPT] = rtw89_mac_c2h_tsf32_toggle_rpt, 4195e3ec7017SPing-Ke Shih }; 4196e3ec7017SPing-Ke Shih 4197e3ec7017SPing-Ke Shih static 4198e3ec7017SPing-Ke Shih void (* const rtw89_mac_c2h_info_handler[])(struct rtw89_dev *rtwdev, 4199e3ec7017SPing-Ke Shih struct sk_buff *c2h, u32 len) = { 4200e3ec7017SPing-Ke Shih [RTW89_MAC_C2H_FUNC_REC_ACK] = rtw89_mac_c2h_rec_ack, 4201e3ec7017SPing-Ke Shih [RTW89_MAC_C2H_FUNC_DONE_ACK] = rtw89_mac_c2h_done_ack, 4202e3ec7017SPing-Ke Shih [RTW89_MAC_C2H_FUNC_C2H_LOG] = rtw89_mac_c2h_log, 4203fccca934SPing-Ke Shih [RTW89_MAC_C2H_FUNC_BCN_CNT] = rtw89_mac_c2h_bcn_cnt, 4204e3ec7017SPing-Ke Shih }; 4205e3ec7017SPing-Ke Shih 4206e3ec7017SPing-Ke Shih void rtw89_mac_c2h_handle(struct rtw89_dev *rtwdev, struct sk_buff *skb, 4207e3ec7017SPing-Ke Shih u32 len, u8 class, u8 func) 4208e3ec7017SPing-Ke Shih { 4209e3ec7017SPing-Ke Shih void (*handler)(struct rtw89_dev *rtwdev, 4210e3ec7017SPing-Ke Shih struct sk_buff *c2h, u32 len) = NULL; 4211e3ec7017SPing-Ke Shih 4212e3ec7017SPing-Ke Shih switch (class) { 4213e3ec7017SPing-Ke Shih case RTW89_MAC_C2H_CLASS_INFO: 4214e3ec7017SPing-Ke Shih if (func < RTW89_MAC_C2H_FUNC_INFO_MAX) 4215e3ec7017SPing-Ke Shih handler = rtw89_mac_c2h_info_handler[func]; 4216e3ec7017SPing-Ke Shih break; 4217e3ec7017SPing-Ke Shih case RTW89_MAC_C2H_CLASS_OFLD: 4218e3ec7017SPing-Ke Shih if (func < RTW89_MAC_C2H_FUNC_OFLD_MAX) 4219e3ec7017SPing-Ke Shih handler = rtw89_mac_c2h_ofld_handler[func]; 4220e3ec7017SPing-Ke Shih break; 4221e3ec7017SPing-Ke Shih case RTW89_MAC_C2H_CLASS_FWDBG: 4222e3ec7017SPing-Ke Shih return; 4223e3ec7017SPing-Ke Shih default: 4224e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "c2h class %d not support\n", class); 4225e3ec7017SPing-Ke Shih return; 4226e3ec7017SPing-Ke Shih } 4227e3ec7017SPing-Ke Shih if (!handler) { 4228e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "c2h class %d func %d not support\n", class, 4229e3ec7017SPing-Ke Shih func); 4230e3ec7017SPing-Ke Shih return; 4231e3ec7017SPing-Ke Shih } 4232e3ec7017SPing-Ke Shih handler(rtwdev, skb, len); 4233e3ec7017SPing-Ke Shih } 4234e3ec7017SPing-Ke Shih 4235e3ec7017SPing-Ke Shih bool rtw89_mac_get_txpwr_cr(struct rtw89_dev *rtwdev, 4236e3ec7017SPing-Ke Shih enum rtw89_phy_idx phy_idx, 4237e3ec7017SPing-Ke Shih u32 reg_base, u32 *cr) 4238e3ec7017SPing-Ke Shih { 4239e3ec7017SPing-Ke Shih const struct rtw89_dle_mem *dle_mem = rtwdev->chip->dle_mem; 4240e3ec7017SPing-Ke Shih enum rtw89_qta_mode mode = dle_mem->mode; 4241e3ec7017SPing-Ke Shih u32 addr = rtw89_mac_reg_by_idx(reg_base, phy_idx); 4242e3ec7017SPing-Ke Shih 4243e3ec7017SPing-Ke Shih if (addr < R_AX_PWR_RATE_CTRL || addr > CMAC1_END_ADDR) { 4244e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[TXPWR] addr=0x%x exceed txpwr cr\n", 4245e3ec7017SPing-Ke Shih addr); 4246e3ec7017SPing-Ke Shih goto error; 4247e3ec7017SPing-Ke Shih } 4248e3ec7017SPing-Ke Shih 4249e3ec7017SPing-Ke Shih if (addr >= CMAC1_START_ADDR && addr <= CMAC1_END_ADDR) 4250e3ec7017SPing-Ke Shih if (mode == RTW89_QTA_SCC) { 4251e3ec7017SPing-Ke Shih rtw89_err(rtwdev, 4252e3ec7017SPing-Ke Shih "[TXPWR] addr=0x%x but hw not enable\n", 4253e3ec7017SPing-Ke Shih addr); 4254e3ec7017SPing-Ke Shih goto error; 4255e3ec7017SPing-Ke Shih } 4256e3ec7017SPing-Ke Shih 4257e3ec7017SPing-Ke Shih *cr = addr; 4258e3ec7017SPing-Ke Shih return true; 4259e3ec7017SPing-Ke Shih 4260e3ec7017SPing-Ke Shih error: 4261e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "[TXPWR] check txpwr cr 0x%x(phy%d) fail\n", 4262e3ec7017SPing-Ke Shih addr, phy_idx); 4263e3ec7017SPing-Ke Shih 4264e3ec7017SPing-Ke Shih return false; 4265e3ec7017SPing-Ke Shih } 4266861e58c8SZong-Zhe Yang EXPORT_SYMBOL(rtw89_mac_get_txpwr_cr); 4267e3ec7017SPing-Ke Shih 4268e3ec7017SPing-Ke Shih int rtw89_mac_cfg_ppdu_status(struct rtw89_dev *rtwdev, u8 mac_idx, bool enable) 4269e3ec7017SPing-Ke Shih { 4270e3ec7017SPing-Ke Shih u32 reg = rtw89_mac_reg_by_idx(R_AX_PPDU_STAT, mac_idx); 4271e3ec7017SPing-Ke Shih int ret = 0; 4272e3ec7017SPing-Ke Shih 4273e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 4274e3ec7017SPing-Ke Shih if (ret) 4275e3ec7017SPing-Ke Shih return ret; 4276e3ec7017SPing-Ke Shih 4277e3ec7017SPing-Ke Shih if (!enable) { 4278e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, reg, B_AX_PPDU_STAT_RPT_EN); 4279e3ec7017SPing-Ke Shih return ret; 4280e3ec7017SPing-Ke Shih } 4281e3ec7017SPing-Ke Shih 4282e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, B_AX_PPDU_STAT_RPT_EN | 4283e3ec7017SPing-Ke Shih B_AX_APP_MAC_INFO_RPT | 4284e3ec7017SPing-Ke Shih B_AX_APP_RX_CNT_RPT | B_AX_APP_PLCP_HDR_RPT | 4285e3ec7017SPing-Ke Shih B_AX_PPDU_STAT_RPT_CRC32); 4286e3ec7017SPing-Ke Shih rtw89_write32_mask(rtwdev, R_AX_HW_RPT_FWD, B_AX_FWD_PPDU_STAT_MASK, 4287e3ec7017SPing-Ke Shih RTW89_PRPT_DEST_HOST); 4288e3ec7017SPing-Ke Shih 4289e3ec7017SPing-Ke Shih return ret; 4290e3ec7017SPing-Ke Shih } 4291861e58c8SZong-Zhe Yang EXPORT_SYMBOL(rtw89_mac_cfg_ppdu_status); 4292e3ec7017SPing-Ke Shih 4293e3ec7017SPing-Ke Shih void rtw89_mac_update_rts_threshold(struct rtw89_dev *rtwdev, u8 mac_idx) 4294e3ec7017SPing-Ke Shih { 4295e3ec7017SPing-Ke Shih #define MAC_AX_TIME_TH_SH 5 4296e3ec7017SPing-Ke Shih #define MAC_AX_LEN_TH_SH 4 4297e3ec7017SPing-Ke Shih #define MAC_AX_TIME_TH_MAX 255 4298e3ec7017SPing-Ke Shih #define MAC_AX_LEN_TH_MAX 255 4299e3ec7017SPing-Ke Shih #define MAC_AX_TIME_TH_DEF 88 4300e3ec7017SPing-Ke Shih #define MAC_AX_LEN_TH_DEF 4080 4301e3ec7017SPing-Ke Shih struct ieee80211_hw *hw = rtwdev->hw; 4302e3ec7017SPing-Ke Shih u32 rts_threshold = hw->wiphy->rts_threshold; 4303e3ec7017SPing-Ke Shih u32 time_th, len_th; 4304e3ec7017SPing-Ke Shih u32 reg; 4305e3ec7017SPing-Ke Shih 4306e3ec7017SPing-Ke Shih if (rts_threshold == (u32)-1) { 4307e3ec7017SPing-Ke Shih time_th = MAC_AX_TIME_TH_DEF; 4308e3ec7017SPing-Ke Shih len_th = MAC_AX_LEN_TH_DEF; 4309e3ec7017SPing-Ke Shih } else { 4310e3ec7017SPing-Ke Shih time_th = MAC_AX_TIME_TH_MAX << MAC_AX_TIME_TH_SH; 4311e3ec7017SPing-Ke Shih len_th = rts_threshold; 4312e3ec7017SPing-Ke Shih } 4313e3ec7017SPing-Ke Shih 4314e3ec7017SPing-Ke Shih time_th = min_t(u32, time_th >> MAC_AX_TIME_TH_SH, MAC_AX_TIME_TH_MAX); 4315e3ec7017SPing-Ke Shih len_th = min_t(u32, len_th >> MAC_AX_LEN_TH_SH, MAC_AX_LEN_TH_MAX); 4316e3ec7017SPing-Ke Shih 4317e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_AGG_LEN_HT_0, mac_idx); 4318e3ec7017SPing-Ke Shih rtw89_write16_mask(rtwdev, reg, B_AX_RTS_TXTIME_TH_MASK, time_th); 4319e3ec7017SPing-Ke Shih rtw89_write16_mask(rtwdev, reg, B_AX_RTS_LEN_TH_MASK, len_th); 4320e3ec7017SPing-Ke Shih } 4321e3ec7017SPing-Ke Shih 4322e3ec7017SPing-Ke Shih void rtw89_mac_flush_txq(struct rtw89_dev *rtwdev, u32 queues, bool drop) 4323e3ec7017SPing-Ke Shih { 4324e3ec7017SPing-Ke Shih bool empty; 4325e3ec7017SPing-Ke Shih int ret; 4326e3ec7017SPing-Ke Shih 4327e3ec7017SPing-Ke Shih if (!test_bit(RTW89_FLAG_POWERON, rtwdev->flags)) 4328e3ec7017SPing-Ke Shih return; 4329e3ec7017SPing-Ke Shih 4330e3ec7017SPing-Ke Shih ret = read_poll_timeout(dle_is_txq_empty, empty, empty, 4331e3ec7017SPing-Ke Shih 10000, 200000, false, rtwdev); 4332e3ec7017SPing-Ke Shih if (ret && !drop && (rtwdev->total_sta_assoc || rtwdev->scanning)) 4333e3ec7017SPing-Ke Shih rtw89_info(rtwdev, "timed out to flush queues\n"); 4334e3ec7017SPing-Ke Shih } 4335e3ec7017SPing-Ke Shih 4336e3ec7017SPing-Ke Shih int rtw89_mac_coex_init(struct rtw89_dev *rtwdev, const struct rtw89_mac_ax_coex *coex) 4337e3ec7017SPing-Ke Shih { 4338e3ec7017SPing-Ke Shih u8 val; 4339e3ec7017SPing-Ke Shih u16 val16; 4340e3ec7017SPing-Ke Shih u32 val32; 4341e3ec7017SPing-Ke Shih int ret; 4342e3ec7017SPing-Ke Shih 4343e3ec7017SPing-Ke Shih rtw89_write8_set(rtwdev, R_AX_GPIO_MUXCFG, B_AX_ENBT); 4344e3ec7017SPing-Ke Shih rtw89_write8_set(rtwdev, R_AX_BTC_FUNC_EN, B_AX_PTA_WL_TX_EN); 4345e3ec7017SPing-Ke Shih rtw89_write8_set(rtwdev, R_AX_BT_COEX_CFG_2 + 1, B_AX_GNT_BT_POLARITY >> 8); 4346e3ec7017SPing-Ke Shih rtw89_write8_set(rtwdev, R_AX_CSR_MODE, B_AX_STATIS_BT_EN | B_AX_WL_ACT_MSK); 4347e3ec7017SPing-Ke Shih rtw89_write8_set(rtwdev, R_AX_CSR_MODE + 2, B_AX_BT_CNT_RST >> 16); 4348e3ec7017SPing-Ke Shih rtw89_write8_clr(rtwdev, R_AX_TRXPTCL_RESP_0 + 3, B_AX_RSP_CHK_BTCCA >> 24); 4349e3ec7017SPing-Ke Shih 4350e3ec7017SPing-Ke Shih val16 = rtw89_read16(rtwdev, R_AX_CCA_CFG_0); 4351e3ec7017SPing-Ke Shih val16 = (val16 | B_AX_BTCCA_EN) & ~B_AX_BTCCA_BRK_TXOP_EN; 4352e3ec7017SPing-Ke Shih rtw89_write16(rtwdev, R_AX_CCA_CFG_0, val16); 4353e3ec7017SPing-Ke Shih 4354e3ec7017SPing-Ke Shih ret = rtw89_mac_read_lte(rtwdev, R_AX_LTE_SW_CFG_2, &val32); 4355e3ec7017SPing-Ke Shih if (ret) { 4356e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "Read R_AX_LTE_SW_CFG_2 fail!\n"); 4357e3ec7017SPing-Ke Shih return ret; 4358e3ec7017SPing-Ke Shih } 4359e3ec7017SPing-Ke Shih val32 = val32 & B_AX_WL_RX_CTRL; 4360e3ec7017SPing-Ke Shih ret = rtw89_mac_write_lte(rtwdev, R_AX_LTE_SW_CFG_2, val32); 4361e3ec7017SPing-Ke Shih if (ret) { 4362e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "Write R_AX_LTE_SW_CFG_2 fail!\n"); 4363e3ec7017SPing-Ke Shih return ret; 4364e3ec7017SPing-Ke Shih } 4365e3ec7017SPing-Ke Shih 4366e3ec7017SPing-Ke Shih switch (coex->pta_mode) { 4367e3ec7017SPing-Ke Shih case RTW89_MAC_AX_COEX_RTK_MODE: 4368e3ec7017SPing-Ke Shih val = rtw89_read8(rtwdev, R_AX_GPIO_MUXCFG); 4369e3ec7017SPing-Ke Shih val &= ~B_AX_BTMODE_MASK; 4370e3ec7017SPing-Ke Shih val |= FIELD_PREP(B_AX_BTMODE_MASK, MAC_AX_BT_MODE_0_3); 4371e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_GPIO_MUXCFG, val); 4372e3ec7017SPing-Ke Shih 4373e3ec7017SPing-Ke Shih val = rtw89_read8(rtwdev, R_AX_TDMA_MODE); 4374e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_TDMA_MODE, val | B_AX_RTK_BT_ENABLE); 4375e3ec7017SPing-Ke Shih 4376e3ec7017SPing-Ke Shih val = rtw89_read8(rtwdev, R_AX_BT_COEX_CFG_5); 4377e3ec7017SPing-Ke Shih val &= ~B_AX_BT_RPT_SAMPLE_RATE_MASK; 4378e3ec7017SPing-Ke Shih val |= FIELD_PREP(B_AX_BT_RPT_SAMPLE_RATE_MASK, MAC_AX_RTK_RATE); 4379e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_BT_COEX_CFG_5, val); 4380e3ec7017SPing-Ke Shih break; 4381e3ec7017SPing-Ke Shih case RTW89_MAC_AX_COEX_CSR_MODE: 4382e3ec7017SPing-Ke Shih val = rtw89_read8(rtwdev, R_AX_GPIO_MUXCFG); 4383e3ec7017SPing-Ke Shih val &= ~B_AX_BTMODE_MASK; 4384e3ec7017SPing-Ke Shih val |= FIELD_PREP(B_AX_BTMODE_MASK, MAC_AX_BT_MODE_2); 4385e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_GPIO_MUXCFG, val); 4386e3ec7017SPing-Ke Shih 4387e3ec7017SPing-Ke Shih val16 = rtw89_read16(rtwdev, R_AX_CSR_MODE); 4388e3ec7017SPing-Ke Shih val16 &= ~B_AX_BT_PRI_DETECT_TO_MASK; 4389e3ec7017SPing-Ke Shih val16 |= FIELD_PREP(B_AX_BT_PRI_DETECT_TO_MASK, MAC_AX_CSR_PRI_TO); 4390e3ec7017SPing-Ke Shih val16 &= ~B_AX_BT_TRX_INIT_DETECT_MASK; 4391e3ec7017SPing-Ke Shih val16 |= FIELD_PREP(B_AX_BT_TRX_INIT_DETECT_MASK, MAC_AX_CSR_TRX_TO); 4392e3ec7017SPing-Ke Shih val16 &= ~B_AX_BT_STAT_DELAY_MASK; 4393e3ec7017SPing-Ke Shih val16 |= FIELD_PREP(B_AX_BT_STAT_DELAY_MASK, MAC_AX_CSR_DELAY); 4394e3ec7017SPing-Ke Shih val16 |= B_AX_ENHANCED_BT; 4395e3ec7017SPing-Ke Shih rtw89_write16(rtwdev, R_AX_CSR_MODE, val16); 4396e3ec7017SPing-Ke Shih 4397e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_BT_COEX_CFG_2, MAC_AX_CSR_RATE); 4398e3ec7017SPing-Ke Shih break; 4399e3ec7017SPing-Ke Shih default: 4400e3ec7017SPing-Ke Shih return -EINVAL; 4401e3ec7017SPing-Ke Shih } 4402e3ec7017SPing-Ke Shih 4403e3ec7017SPing-Ke Shih switch (coex->direction) { 4404e3ec7017SPing-Ke Shih case RTW89_MAC_AX_COEX_INNER: 4405e3ec7017SPing-Ke Shih val = rtw89_read8(rtwdev, R_AX_GPIO_MUXCFG + 1); 4406e3ec7017SPing-Ke Shih val = (val & ~BIT(2)) | BIT(1); 4407e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_GPIO_MUXCFG + 1, val); 4408e3ec7017SPing-Ke Shih break; 4409e3ec7017SPing-Ke Shih case RTW89_MAC_AX_COEX_OUTPUT: 4410e3ec7017SPing-Ke Shih val = rtw89_read8(rtwdev, R_AX_GPIO_MUXCFG + 1); 4411e3ec7017SPing-Ke Shih val = val | BIT(1) | BIT(0); 4412e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_GPIO_MUXCFG + 1, val); 4413e3ec7017SPing-Ke Shih break; 4414e3ec7017SPing-Ke Shih case RTW89_MAC_AX_COEX_INPUT: 4415e3ec7017SPing-Ke Shih val = rtw89_read8(rtwdev, R_AX_GPIO_MUXCFG + 1); 4416e3ec7017SPing-Ke Shih val = val & ~(BIT(2) | BIT(1)); 4417e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_GPIO_MUXCFG + 1, val); 4418e3ec7017SPing-Ke Shih break; 4419e3ec7017SPing-Ke Shih default: 4420e3ec7017SPing-Ke Shih return -EINVAL; 4421e3ec7017SPing-Ke Shih } 4422e3ec7017SPing-Ke Shih 4423e3ec7017SPing-Ke Shih return 0; 4424e3ec7017SPing-Ke Shih } 4425861e58c8SZong-Zhe Yang EXPORT_SYMBOL(rtw89_mac_coex_init); 4426e3ec7017SPing-Ke Shih 4427065cf8f9SChia-Yuan Li int rtw89_mac_coex_init_v1(struct rtw89_dev *rtwdev, 4428065cf8f9SChia-Yuan Li const struct rtw89_mac_ax_coex *coex) 4429065cf8f9SChia-Yuan Li { 4430065cf8f9SChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_BTC_CFG, 4431065cf8f9SChia-Yuan Li B_AX_BTC_EN | B_AX_BTG_LNA1_GAIN_SEL); 4432065cf8f9SChia-Yuan Li rtw89_write32_set(rtwdev, R_AX_BT_CNT_CFG, B_AX_BT_CNT_EN); 4433065cf8f9SChia-Yuan Li rtw89_write16_set(rtwdev, R_AX_CCA_CFG_0, B_AX_BTCCA_EN); 4434065cf8f9SChia-Yuan Li rtw89_write16_clr(rtwdev, R_AX_CCA_CFG_0, B_AX_BTCCA_BRK_TXOP_EN); 4435065cf8f9SChia-Yuan Li 4436065cf8f9SChia-Yuan Li switch (coex->pta_mode) { 4437065cf8f9SChia-Yuan Li case RTW89_MAC_AX_COEX_RTK_MODE: 4438065cf8f9SChia-Yuan Li rtw89_write32_mask(rtwdev, R_AX_BTC_CFG, B_AX_BTC_MODE_MASK, 4439065cf8f9SChia-Yuan Li MAC_AX_RTK_MODE); 4440065cf8f9SChia-Yuan Li rtw89_write32_mask(rtwdev, R_AX_RTK_MODE_CFG_V1, 4441065cf8f9SChia-Yuan Li B_AX_SAMPLE_CLK_MASK, MAC_AX_RTK_RATE); 4442065cf8f9SChia-Yuan Li break; 4443065cf8f9SChia-Yuan Li case RTW89_MAC_AX_COEX_CSR_MODE: 4444065cf8f9SChia-Yuan Li rtw89_write32_mask(rtwdev, R_AX_BTC_CFG, B_AX_BTC_MODE_MASK, 4445065cf8f9SChia-Yuan Li MAC_AX_CSR_MODE); 4446065cf8f9SChia-Yuan Li break; 4447065cf8f9SChia-Yuan Li default: 4448065cf8f9SChia-Yuan Li return -EINVAL; 4449065cf8f9SChia-Yuan Li } 4450065cf8f9SChia-Yuan Li 4451065cf8f9SChia-Yuan Li return 0; 4452065cf8f9SChia-Yuan Li } 4453065cf8f9SChia-Yuan Li EXPORT_SYMBOL(rtw89_mac_coex_init_v1); 4454065cf8f9SChia-Yuan Li 4455e3ec7017SPing-Ke Shih int rtw89_mac_cfg_gnt(struct rtw89_dev *rtwdev, 4456e3ec7017SPing-Ke Shih const struct rtw89_mac_ax_coex_gnt *gnt_cfg) 4457e3ec7017SPing-Ke Shih { 44588001c741SPing-Ke Shih u32 val = 0, ret; 4459e3ec7017SPing-Ke Shih 44608001c741SPing-Ke Shih if (gnt_cfg->band[0].gnt_bt) 44618001c741SPing-Ke Shih val |= B_AX_GNT_BT_RFC_S0_SW_VAL | B_AX_GNT_BT_BB_S0_SW_VAL; 44628001c741SPing-Ke Shih 44638001c741SPing-Ke Shih if (gnt_cfg->band[0].gnt_bt_sw_en) 44648001c741SPing-Ke Shih val |= B_AX_GNT_BT_RFC_S0_SW_CTRL | B_AX_GNT_BT_BB_S0_SW_CTRL; 44658001c741SPing-Ke Shih 44668001c741SPing-Ke Shih if (gnt_cfg->band[0].gnt_wl) 44678001c741SPing-Ke Shih val |= B_AX_GNT_WL_RFC_S0_SW_VAL | B_AX_GNT_WL_BB_S0_SW_VAL; 44688001c741SPing-Ke Shih 44698001c741SPing-Ke Shih if (gnt_cfg->band[0].gnt_wl_sw_en) 44708001c741SPing-Ke Shih val |= B_AX_GNT_WL_RFC_S0_SW_CTRL | B_AX_GNT_WL_BB_S0_SW_CTRL; 44718001c741SPing-Ke Shih 44728001c741SPing-Ke Shih if (gnt_cfg->band[1].gnt_bt) 44738001c741SPing-Ke Shih val |= B_AX_GNT_BT_RFC_S1_SW_VAL | B_AX_GNT_BT_BB_S1_SW_VAL; 44748001c741SPing-Ke Shih 44758001c741SPing-Ke Shih if (gnt_cfg->band[1].gnt_bt_sw_en) 44768001c741SPing-Ke Shih val |= B_AX_GNT_BT_RFC_S1_SW_CTRL | B_AX_GNT_BT_BB_S1_SW_CTRL; 44778001c741SPing-Ke Shih 44788001c741SPing-Ke Shih if (gnt_cfg->band[1].gnt_wl) 44798001c741SPing-Ke Shih val |= B_AX_GNT_WL_RFC_S1_SW_VAL | B_AX_GNT_WL_BB_S1_SW_VAL; 44808001c741SPing-Ke Shih 44818001c741SPing-Ke Shih if (gnt_cfg->band[1].gnt_wl_sw_en) 44828001c741SPing-Ke Shih val |= B_AX_GNT_WL_RFC_S1_SW_CTRL | B_AX_GNT_WL_BB_S1_SW_CTRL; 44838001c741SPing-Ke Shih 4484e3ec7017SPing-Ke Shih ret = rtw89_mac_write_lte(rtwdev, R_AX_LTE_SW_CFG_1, val); 4485e3ec7017SPing-Ke Shih if (ret) { 4486e3ec7017SPing-Ke Shih rtw89_err(rtwdev, "Write LTE fail!\n"); 4487e3ec7017SPing-Ke Shih return ret; 4488e3ec7017SPing-Ke Shih } 4489e3ec7017SPing-Ke Shih 4490e3ec7017SPing-Ke Shih return 0; 4491e3ec7017SPing-Ke Shih } 4492feed6541SChia-Yuan Li EXPORT_SYMBOL(rtw89_mac_cfg_gnt); 4493feed6541SChia-Yuan Li 4494feed6541SChia-Yuan Li int rtw89_mac_cfg_gnt_v1(struct rtw89_dev *rtwdev, 4495feed6541SChia-Yuan Li const struct rtw89_mac_ax_coex_gnt *gnt_cfg) 4496feed6541SChia-Yuan Li { 4497feed6541SChia-Yuan Li u32 val = 0; 4498feed6541SChia-Yuan Li 4499feed6541SChia-Yuan Li if (gnt_cfg->band[0].gnt_bt) 4500feed6541SChia-Yuan Li val |= B_AX_GNT_BT_RFC_S0_VAL | B_AX_GNT_BT_RX_VAL | 4501feed6541SChia-Yuan Li B_AX_GNT_BT_TX_VAL; 4502feed6541SChia-Yuan Li else 4503feed6541SChia-Yuan Li val |= B_AX_WL_ACT_VAL; 4504feed6541SChia-Yuan Li 4505feed6541SChia-Yuan Li if (gnt_cfg->band[0].gnt_bt_sw_en) 4506feed6541SChia-Yuan Li val |= B_AX_GNT_BT_RFC_S0_SWCTRL | B_AX_GNT_BT_RX_SWCTRL | 4507feed6541SChia-Yuan Li B_AX_GNT_BT_TX_SWCTRL | B_AX_WL_ACT_SWCTRL; 4508feed6541SChia-Yuan Li 4509feed6541SChia-Yuan Li if (gnt_cfg->band[0].gnt_wl) 4510feed6541SChia-Yuan Li val |= B_AX_GNT_WL_RFC_S0_VAL | B_AX_GNT_WL_RX_VAL | 4511feed6541SChia-Yuan Li B_AX_GNT_WL_TX_VAL | B_AX_GNT_WL_BB_VAL; 4512feed6541SChia-Yuan Li 4513feed6541SChia-Yuan Li if (gnt_cfg->band[0].gnt_wl_sw_en) 4514feed6541SChia-Yuan Li val |= B_AX_GNT_WL_RFC_S0_SWCTRL | B_AX_GNT_WL_RX_SWCTRL | 4515feed6541SChia-Yuan Li B_AX_GNT_WL_TX_SWCTRL | B_AX_GNT_WL_BB_SWCTRL; 4516feed6541SChia-Yuan Li 4517feed6541SChia-Yuan Li if (gnt_cfg->band[1].gnt_bt) 4518feed6541SChia-Yuan Li val |= B_AX_GNT_BT_RFC_S1_VAL | B_AX_GNT_BT_RX_VAL | 4519feed6541SChia-Yuan Li B_AX_GNT_BT_TX_VAL; 4520feed6541SChia-Yuan Li else 4521feed6541SChia-Yuan Li val |= B_AX_WL_ACT_VAL; 4522feed6541SChia-Yuan Li 4523feed6541SChia-Yuan Li if (gnt_cfg->band[1].gnt_bt_sw_en) 4524feed6541SChia-Yuan Li val |= B_AX_GNT_BT_RFC_S1_SWCTRL | B_AX_GNT_BT_RX_SWCTRL | 4525feed6541SChia-Yuan Li B_AX_GNT_BT_TX_SWCTRL | B_AX_WL_ACT_SWCTRL; 4526feed6541SChia-Yuan Li 4527feed6541SChia-Yuan Li if (gnt_cfg->band[1].gnt_wl) 4528feed6541SChia-Yuan Li val |= B_AX_GNT_WL_RFC_S1_VAL | B_AX_GNT_WL_RX_VAL | 4529feed6541SChia-Yuan Li B_AX_GNT_WL_TX_VAL | B_AX_GNT_WL_BB_VAL; 4530feed6541SChia-Yuan Li 4531feed6541SChia-Yuan Li if (gnt_cfg->band[1].gnt_wl_sw_en) 4532feed6541SChia-Yuan Li val |= B_AX_GNT_WL_RFC_S1_SWCTRL | B_AX_GNT_WL_RX_SWCTRL | 4533feed6541SChia-Yuan Li B_AX_GNT_WL_TX_SWCTRL | B_AX_GNT_WL_BB_SWCTRL; 4534feed6541SChia-Yuan Li 4535feed6541SChia-Yuan Li rtw89_write32(rtwdev, R_AX_GNT_SW_CTRL, val); 4536feed6541SChia-Yuan Li 4537feed6541SChia-Yuan Li return 0; 4538feed6541SChia-Yuan Li } 4539feed6541SChia-Yuan Li EXPORT_SYMBOL(rtw89_mac_cfg_gnt_v1); 4540e3ec7017SPing-Ke Shih 4541e3ec7017SPing-Ke Shih int rtw89_mac_cfg_plt(struct rtw89_dev *rtwdev, struct rtw89_mac_ax_plt *plt) 4542e3ec7017SPing-Ke Shih { 4543e3ec7017SPing-Ke Shih u32 reg; 454428e7ea8aSPing-Ke Shih u16 val; 4545e3ec7017SPing-Ke Shih int ret; 4546e3ec7017SPing-Ke Shih 4547e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, plt->band, RTW89_CMAC_SEL); 4548e3ec7017SPing-Ke Shih if (ret) 4549e3ec7017SPing-Ke Shih return ret; 4550e3ec7017SPing-Ke Shih 4551e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_BT_PLT, plt->band); 4552e3ec7017SPing-Ke Shih val = (plt->tx & RTW89_MAC_AX_PLT_LTE_RX ? B_AX_TX_PLT_GNT_LTE_RX : 0) | 4553e3ec7017SPing-Ke Shih (plt->tx & RTW89_MAC_AX_PLT_GNT_BT_TX ? B_AX_TX_PLT_GNT_BT_TX : 0) | 4554e3ec7017SPing-Ke Shih (plt->tx & RTW89_MAC_AX_PLT_GNT_BT_RX ? B_AX_TX_PLT_GNT_BT_RX : 0) | 4555e3ec7017SPing-Ke Shih (plt->tx & RTW89_MAC_AX_PLT_GNT_WL ? B_AX_TX_PLT_GNT_WL : 0) | 4556e3ec7017SPing-Ke Shih (plt->rx & RTW89_MAC_AX_PLT_LTE_RX ? B_AX_RX_PLT_GNT_LTE_RX : 0) | 4557e3ec7017SPing-Ke Shih (plt->rx & RTW89_MAC_AX_PLT_GNT_BT_TX ? B_AX_RX_PLT_GNT_BT_TX : 0) | 4558e3ec7017SPing-Ke Shih (plt->rx & RTW89_MAC_AX_PLT_GNT_BT_RX ? B_AX_RX_PLT_GNT_BT_RX : 0) | 455928e7ea8aSPing-Ke Shih (plt->rx & RTW89_MAC_AX_PLT_GNT_WL ? B_AX_RX_PLT_GNT_WL : 0) | 456028e7ea8aSPing-Ke Shih B_AX_PLT_EN; 456128e7ea8aSPing-Ke Shih rtw89_write16(rtwdev, reg, val); 4562e3ec7017SPing-Ke Shih 4563e3ec7017SPing-Ke Shih return 0; 4564e3ec7017SPing-Ke Shih } 4565e3ec7017SPing-Ke Shih 4566e3ec7017SPing-Ke Shih void rtw89_mac_cfg_sb(struct rtw89_dev *rtwdev, u32 val) 4567e3ec7017SPing-Ke Shih { 4568e3ec7017SPing-Ke Shih u32 fw_sb; 4569e3ec7017SPing-Ke Shih 4570e3ec7017SPing-Ke Shih fw_sb = rtw89_read32(rtwdev, R_AX_SCOREBOARD); 4571e3ec7017SPing-Ke Shih fw_sb = FIELD_GET(B_MAC_AX_SB_FW_MASK, fw_sb); 4572e3ec7017SPing-Ke Shih fw_sb = fw_sb & ~B_MAC_AX_BTGS1_NOTIFY; 4573e3ec7017SPing-Ke Shih if (!test_bit(RTW89_FLAG_POWERON, rtwdev->flags)) 4574e3ec7017SPing-Ke Shih fw_sb = fw_sb | MAC_AX_NOTIFY_PWR_MAJOR; 4575e3ec7017SPing-Ke Shih else 4576e3ec7017SPing-Ke Shih fw_sb = fw_sb | MAC_AX_NOTIFY_TP_MAJOR; 4577e3ec7017SPing-Ke Shih val = FIELD_GET(B_MAC_AX_SB_DRV_MASK, val); 4578e3ec7017SPing-Ke Shih val = B_AX_TOGGLE | 4579e3ec7017SPing-Ke Shih FIELD_PREP(B_MAC_AX_SB_DRV_MASK, val) | 4580e3ec7017SPing-Ke Shih FIELD_PREP(B_MAC_AX_SB_FW_MASK, fw_sb); 4581e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, R_AX_SCOREBOARD, val); 4582e3ec7017SPing-Ke Shih fsleep(1000); /* avoid BT FW loss information */ 4583e3ec7017SPing-Ke Shih } 4584e3ec7017SPing-Ke Shih 4585e3ec7017SPing-Ke Shih u32 rtw89_mac_get_sb(struct rtw89_dev *rtwdev) 4586e3ec7017SPing-Ke Shih { 4587e3ec7017SPing-Ke Shih return rtw89_read32(rtwdev, R_AX_SCOREBOARD); 4588e3ec7017SPing-Ke Shih } 4589e3ec7017SPing-Ke Shih 4590e3ec7017SPing-Ke Shih int rtw89_mac_cfg_ctrl_path(struct rtw89_dev *rtwdev, bool wl) 4591e3ec7017SPing-Ke Shih { 4592e3ec7017SPing-Ke Shih u8 val = rtw89_read8(rtwdev, R_AX_SYS_SDIO_CTRL + 3); 4593e3ec7017SPing-Ke Shih 4594e3ec7017SPing-Ke Shih val = wl ? val | BIT(2) : val & ~BIT(2); 4595e3ec7017SPing-Ke Shih rtw89_write8(rtwdev, R_AX_SYS_SDIO_CTRL + 3, val); 4596e3ec7017SPing-Ke Shih 4597e3ec7017SPing-Ke Shih return 0; 4598e3ec7017SPing-Ke Shih } 4599feed6541SChia-Yuan Li EXPORT_SYMBOL(rtw89_mac_cfg_ctrl_path); 4600feed6541SChia-Yuan Li 4601feed6541SChia-Yuan Li int rtw89_mac_cfg_ctrl_path_v1(struct rtw89_dev *rtwdev, bool wl) 4602feed6541SChia-Yuan Li { 4603feed6541SChia-Yuan Li struct rtw89_btc *btc = &rtwdev->btc; 4604feed6541SChia-Yuan Li struct rtw89_btc_dm *dm = &btc->dm; 4605feed6541SChia-Yuan Li struct rtw89_mac_ax_gnt *g = dm->gnt.band; 4606feed6541SChia-Yuan Li int i; 4607feed6541SChia-Yuan Li 4608feed6541SChia-Yuan Li if (wl) 4609feed6541SChia-Yuan Li return 0; 4610feed6541SChia-Yuan Li 4611feed6541SChia-Yuan Li for (i = 0; i < RTW89_PHY_MAX; i++) { 4612feed6541SChia-Yuan Li g[i].gnt_bt_sw_en = 1; 4613feed6541SChia-Yuan Li g[i].gnt_bt = 1; 4614feed6541SChia-Yuan Li g[i].gnt_wl_sw_en = 1; 4615feed6541SChia-Yuan Li g[i].gnt_wl = 0; 4616feed6541SChia-Yuan Li } 4617feed6541SChia-Yuan Li 4618feed6541SChia-Yuan Li return rtw89_mac_cfg_gnt_v1(rtwdev, &dm->gnt); 4619feed6541SChia-Yuan Li } 4620feed6541SChia-Yuan Li EXPORT_SYMBOL(rtw89_mac_cfg_ctrl_path_v1); 4621e3ec7017SPing-Ke Shih 4622e3ec7017SPing-Ke Shih bool rtw89_mac_get_ctrl_path(struct rtw89_dev *rtwdev) 4623e3ec7017SPing-Ke Shih { 4624e3ec7017SPing-Ke Shih u8 val = rtw89_read8(rtwdev, R_AX_SYS_SDIO_CTRL + 3); 4625e3ec7017SPing-Ke Shih 4626e3ec7017SPing-Ke Shih return FIELD_GET(B_AX_LTE_MUX_CTRL_PATH >> 24, val); 4627e3ec7017SPing-Ke Shih } 4628e3ec7017SPing-Ke Shih 46298c7e9cebSChing-Te Ku u16 rtw89_mac_get_plt_cnt(struct rtw89_dev *rtwdev, u8 band) 46308c7e9cebSChing-Te Ku { 46318c7e9cebSChing-Te Ku u32 reg; 46328c7e9cebSChing-Te Ku u16 cnt; 46338c7e9cebSChing-Te Ku 46348c7e9cebSChing-Te Ku reg = rtw89_mac_reg_by_idx(R_AX_BT_PLT, band); 46358c7e9cebSChing-Te Ku cnt = rtw89_read32_mask(rtwdev, reg, B_AX_BT_PLT_PKT_CNT_MASK); 46368c7e9cebSChing-Te Ku rtw89_write16_set(rtwdev, reg, B_AX_BT_PLT_RST); 46378c7e9cebSChing-Te Ku 46388c7e9cebSChing-Te Ku return cnt; 46398c7e9cebSChing-Te Ku } 46408c7e9cebSChing-Te Ku 4641e3ec7017SPing-Ke Shih static void rtw89_mac_bfee_ctrl(struct rtw89_dev *rtwdev, u8 mac_idx, bool en) 4642e3ec7017SPing-Ke Shih { 4643e3ec7017SPing-Ke Shih u32 reg; 4644e3ec7017SPing-Ke Shih u32 mask = B_AX_BFMEE_HT_NDPA_EN | B_AX_BFMEE_VHT_NDPA_EN | 4645e3ec7017SPing-Ke Shih B_AX_BFMEE_HE_NDPA_EN; 4646e3ec7017SPing-Ke Shih 4647e3ec7017SPing-Ke Shih rtw89_debug(rtwdev, RTW89_DBG_BF, "set bfee ndpa_en to %d\n", en); 4648e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_BFMEE_RESP_OPTION, mac_idx); 4649e3ec7017SPing-Ke Shih if (en) { 4650e3ec7017SPing-Ke Shih set_bit(RTW89_FLAG_BFEE_EN, rtwdev->flags); 4651e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, reg, mask); 4652e3ec7017SPing-Ke Shih } else { 4653e3ec7017SPing-Ke Shih clear_bit(RTW89_FLAG_BFEE_EN, rtwdev->flags); 4654e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, reg, mask); 4655e3ec7017SPing-Ke Shih } 4656e3ec7017SPing-Ke Shih } 4657e3ec7017SPing-Ke Shih 4658e3ec7017SPing-Ke Shih static int rtw89_mac_init_bfee(struct rtw89_dev *rtwdev, u8 mac_idx) 4659e3ec7017SPing-Ke Shih { 4660e3ec7017SPing-Ke Shih u32 reg; 4661e3ec7017SPing-Ke Shih u32 val32; 4662e3ec7017SPing-Ke Shih int ret; 4663e3ec7017SPing-Ke Shih 4664e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 4665e3ec7017SPing-Ke Shih if (ret) 4666e3ec7017SPing-Ke Shih return ret; 4667e3ec7017SPing-Ke Shih 4668e3ec7017SPing-Ke Shih /* AP mode set tx gid to 63 */ 4669e3ec7017SPing-Ke Shih /* STA mode set tx gid to 0(default) */ 4670e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_BFMER_CTRL_0, mac_idx); 4671e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, reg, B_AX_BFMER_NDP_BFEN); 4672e3ec7017SPing-Ke Shih 4673e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_CSI_RRSC, mac_idx); 4674e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, CSI_RRSC_BMAP); 4675e3ec7017SPing-Ke Shih 4676e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_BFMEE_RESP_OPTION, mac_idx); 4677e3ec7017SPing-Ke Shih val32 = FIELD_PREP(B_AX_BFMEE_BFRP_RX_STANDBY_TIMER_MASK, BFRP_RX_STANDBY_TIMER); 4678e3ec7017SPing-Ke Shih val32 |= FIELD_PREP(B_AX_BFMEE_NDP_RX_STANDBY_TIMER_MASK, NDP_RX_STANDBY_TIMER); 4679e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, val32); 4680e3ec7017SPing-Ke Shih rtw89_mac_bfee_ctrl(rtwdev, mac_idx, true); 4681e3ec7017SPing-Ke Shih 4682e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_CSI_CTRL_0, mac_idx); 4683e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, reg, B_AX_BFMEE_BFPARAM_SEL | 4684e3ec7017SPing-Ke Shih B_AX_BFMEE_USE_NSTS | 4685e3ec7017SPing-Ke Shih B_AX_BFMEE_CSI_GID_SEL | 4686e3ec7017SPing-Ke Shih B_AX_BFMEE_CSI_FORCE_RETE_EN); 4687e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_CSI_RATE, mac_idx); 4688e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, reg, 4689e3ec7017SPing-Ke Shih u32_encode_bits(CSI_INIT_RATE_HT, B_AX_BFMEE_HT_CSI_RATE_MASK) | 4690e3ec7017SPing-Ke Shih u32_encode_bits(CSI_INIT_RATE_VHT, B_AX_BFMEE_VHT_CSI_RATE_MASK) | 4691e3ec7017SPing-Ke Shih u32_encode_bits(CSI_INIT_RATE_HE, B_AX_BFMEE_HE_CSI_RATE_MASK)); 4692e3ec7017SPing-Ke Shih 469362440fbeSPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_CSIRPT_OPTION, mac_idx); 469462440fbeSPing-Ke Shih rtw89_write32_set(rtwdev, reg, 469562440fbeSPing-Ke Shih B_AX_CSIPRT_VHTSU_AID_EN | B_AX_CSIPRT_HESU_AID_EN); 469662440fbeSPing-Ke Shih 4697e3ec7017SPing-Ke Shih return 0; 4698e3ec7017SPing-Ke Shih } 4699e3ec7017SPing-Ke Shih 4700e3ec7017SPing-Ke Shih static int rtw89_mac_set_csi_para_reg(struct rtw89_dev *rtwdev, 4701e3ec7017SPing-Ke Shih struct ieee80211_vif *vif, 4702e3ec7017SPing-Ke Shih struct ieee80211_sta *sta) 4703e3ec7017SPing-Ke Shih { 4704e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv; 4705e3ec7017SPing-Ke Shih u8 mac_idx = rtwvif->mac_idx; 4706e3ec7017SPing-Ke Shih u8 nc = 1, nr = 3, ng = 0, cb = 1, cs = 1, ldpc_en = 1, stbc_en = 1; 4707e3ec7017SPing-Ke Shih u8 port_sel = rtwvif->port; 4708e3ec7017SPing-Ke Shih u8 sound_dim = 3, t; 4709046d2e7cSSriram R u8 *phy_cap = sta->deflink.he_cap.he_cap_elem.phy_cap_info; 4710e3ec7017SPing-Ke Shih u32 reg; 4711e3ec7017SPing-Ke Shih u16 val; 4712e3ec7017SPing-Ke Shih int ret; 4713e3ec7017SPing-Ke Shih 4714e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 4715e3ec7017SPing-Ke Shih if (ret) 4716e3ec7017SPing-Ke Shih return ret; 4717e3ec7017SPing-Ke Shih 4718e3ec7017SPing-Ke Shih if ((phy_cap[3] & IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER) || 4719e3ec7017SPing-Ke Shih (phy_cap[4] & IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER)) { 4720e3ec7017SPing-Ke Shih ldpc_en &= !!(phy_cap[1] & IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD); 4721e3ec7017SPing-Ke Shih stbc_en &= !!(phy_cap[2] & IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ); 4722e3ec7017SPing-Ke Shih t = FIELD_GET(IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK, 4723e3ec7017SPing-Ke Shih phy_cap[5]); 4724e3ec7017SPing-Ke Shih sound_dim = min(sound_dim, t); 4725e3ec7017SPing-Ke Shih } 4726046d2e7cSSriram R if ((sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) || 4727046d2e7cSSriram R (sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { 4728046d2e7cSSriram R ldpc_en &= !!(sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_RXLDPC); 4729046d2e7cSSriram R stbc_en &= !!(sta->deflink.vht_cap.cap & IEEE80211_VHT_CAP_RXSTBC_MASK); 4730e3ec7017SPing-Ke Shih t = FIELD_GET(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK, 4731046d2e7cSSriram R sta->deflink.vht_cap.cap); 4732e3ec7017SPing-Ke Shih sound_dim = min(sound_dim, t); 4733e3ec7017SPing-Ke Shih } 4734e3ec7017SPing-Ke Shih nc = min(nc, sound_dim); 4735e3ec7017SPing-Ke Shih nr = min(nr, sound_dim); 4736e3ec7017SPing-Ke Shih 4737e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_CSI_CTRL_0, mac_idx); 4738e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, reg, B_AX_BFMEE_BFPARAM_SEL); 4739e3ec7017SPing-Ke Shih 4740e3ec7017SPing-Ke Shih val = FIELD_PREP(B_AX_BFMEE_CSIINFO0_NC_MASK, nc) | 4741e3ec7017SPing-Ke Shih FIELD_PREP(B_AX_BFMEE_CSIINFO0_NR_MASK, nr) | 4742e3ec7017SPing-Ke Shih FIELD_PREP(B_AX_BFMEE_CSIINFO0_NG_MASK, ng) | 4743e3ec7017SPing-Ke Shih FIELD_PREP(B_AX_BFMEE_CSIINFO0_CB_MASK, cb) | 4744e3ec7017SPing-Ke Shih FIELD_PREP(B_AX_BFMEE_CSIINFO0_CS_MASK, cs) | 4745e3ec7017SPing-Ke Shih FIELD_PREP(B_AX_BFMEE_CSIINFO0_LDPC_EN, ldpc_en) | 4746e3ec7017SPing-Ke Shih FIELD_PREP(B_AX_BFMEE_CSIINFO0_STBC_EN, stbc_en); 4747e3ec7017SPing-Ke Shih 4748e3ec7017SPing-Ke Shih if (port_sel == 0) 4749e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_CSI_CTRL_0, mac_idx); 4750e3ec7017SPing-Ke Shih else 4751e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_CSI_CTRL_1, mac_idx); 4752e3ec7017SPing-Ke Shih 4753e3ec7017SPing-Ke Shih rtw89_write16(rtwdev, reg, val); 4754e3ec7017SPing-Ke Shih 4755e3ec7017SPing-Ke Shih return 0; 4756e3ec7017SPing-Ke Shih } 4757e3ec7017SPing-Ke Shih 4758e3ec7017SPing-Ke Shih static int rtw89_mac_csi_rrsc(struct rtw89_dev *rtwdev, 4759e3ec7017SPing-Ke Shih struct ieee80211_vif *vif, 4760e3ec7017SPing-Ke Shih struct ieee80211_sta *sta) 4761e3ec7017SPing-Ke Shih { 4762e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv; 4763e3ec7017SPing-Ke Shih u32 rrsc = BIT(RTW89_MAC_BF_RRSC_6M) | BIT(RTW89_MAC_BF_RRSC_24M); 4764e3ec7017SPing-Ke Shih u32 reg; 4765e3ec7017SPing-Ke Shih u8 mac_idx = rtwvif->mac_idx; 4766e3ec7017SPing-Ke Shih int ret; 4767e3ec7017SPing-Ke Shih 4768e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 4769e3ec7017SPing-Ke Shih if (ret) 4770e3ec7017SPing-Ke Shih return ret; 4771e3ec7017SPing-Ke Shih 4772046d2e7cSSriram R if (sta->deflink.he_cap.has_he) { 4773e3ec7017SPing-Ke Shih rrsc |= (BIT(RTW89_MAC_BF_RRSC_HE_MSC0) | 4774e3ec7017SPing-Ke Shih BIT(RTW89_MAC_BF_RRSC_HE_MSC3) | 4775e3ec7017SPing-Ke Shih BIT(RTW89_MAC_BF_RRSC_HE_MSC5)); 4776e3ec7017SPing-Ke Shih } 4777046d2e7cSSriram R if (sta->deflink.vht_cap.vht_supported) { 4778e3ec7017SPing-Ke Shih rrsc |= (BIT(RTW89_MAC_BF_RRSC_VHT_MSC0) | 4779e3ec7017SPing-Ke Shih BIT(RTW89_MAC_BF_RRSC_VHT_MSC3) | 4780e3ec7017SPing-Ke Shih BIT(RTW89_MAC_BF_RRSC_VHT_MSC5)); 4781e3ec7017SPing-Ke Shih } 4782046d2e7cSSriram R if (sta->deflink.ht_cap.ht_supported) { 4783e3ec7017SPing-Ke Shih rrsc |= (BIT(RTW89_MAC_BF_RRSC_HT_MSC0) | 4784e3ec7017SPing-Ke Shih BIT(RTW89_MAC_BF_RRSC_HT_MSC3) | 4785e3ec7017SPing-Ke Shih BIT(RTW89_MAC_BF_RRSC_HT_MSC5)); 4786e3ec7017SPing-Ke Shih } 4787e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_CSI_CTRL_0, mac_idx); 4788e3ec7017SPing-Ke Shih rtw89_write32_set(rtwdev, reg, B_AX_BFMEE_BFPARAM_SEL); 4789e3ec7017SPing-Ke Shih rtw89_write32_clr(rtwdev, reg, B_AX_BFMEE_CSI_FORCE_RETE_EN); 4790e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, 4791e3ec7017SPing-Ke Shih rtw89_mac_reg_by_idx(R_AX_TRXPTCL_RESP_CSI_RRSC, mac_idx), 4792e3ec7017SPing-Ke Shih rrsc); 4793e3ec7017SPing-Ke Shih 4794e3ec7017SPing-Ke Shih return 0; 4795e3ec7017SPing-Ke Shih } 4796e3ec7017SPing-Ke Shih 4797e3ec7017SPing-Ke Shih void rtw89_mac_bf_assoc(struct rtw89_dev *rtwdev, struct ieee80211_vif *vif, 4798e3ec7017SPing-Ke Shih struct ieee80211_sta *sta) 4799e3ec7017SPing-Ke Shih { 4800e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv; 4801e3ec7017SPing-Ke Shih 4802e3ec7017SPing-Ke Shih if (rtw89_sta_has_beamformer_cap(sta)) { 4803e3ec7017SPing-Ke Shih rtw89_debug(rtwdev, RTW89_DBG_BF, 4804e3ec7017SPing-Ke Shih "initialize bfee for new association\n"); 4805e3ec7017SPing-Ke Shih rtw89_mac_init_bfee(rtwdev, rtwvif->mac_idx); 4806e3ec7017SPing-Ke Shih rtw89_mac_set_csi_para_reg(rtwdev, vif, sta); 4807e3ec7017SPing-Ke Shih rtw89_mac_csi_rrsc(rtwdev, vif, sta); 4808e3ec7017SPing-Ke Shih } 4809e3ec7017SPing-Ke Shih } 4810e3ec7017SPing-Ke Shih 4811e3ec7017SPing-Ke Shih void rtw89_mac_bf_disassoc(struct rtw89_dev *rtwdev, struct ieee80211_vif *vif, 4812e3ec7017SPing-Ke Shih struct ieee80211_sta *sta) 4813e3ec7017SPing-Ke Shih { 4814e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv; 4815e3ec7017SPing-Ke Shih 4816e3ec7017SPing-Ke Shih rtw89_mac_bfee_ctrl(rtwdev, rtwvif->mac_idx, false); 4817e3ec7017SPing-Ke Shih } 4818e3ec7017SPing-Ke Shih 4819e3ec7017SPing-Ke Shih void rtw89_mac_bf_set_gid_table(struct rtw89_dev *rtwdev, struct ieee80211_vif *vif, 4820e3ec7017SPing-Ke Shih struct ieee80211_bss_conf *conf) 4821e3ec7017SPing-Ke Shih { 4822e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif = (struct rtw89_vif *)vif->drv_priv; 4823e3ec7017SPing-Ke Shih u8 mac_idx = rtwvif->mac_idx; 4824e3ec7017SPing-Ke Shih __le32 *p; 4825e3ec7017SPing-Ke Shih 4826e3ec7017SPing-Ke Shih rtw89_debug(rtwdev, RTW89_DBG_BF, "update bf GID table\n"); 4827e3ec7017SPing-Ke Shih 4828e3ec7017SPing-Ke Shih p = (__le32 *)conf->mu_group.membership; 4829e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, rtw89_mac_reg_by_idx(R_AX_GID_POSITION_EN0, mac_idx), 4830e3ec7017SPing-Ke Shih le32_to_cpu(p[0])); 4831e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, rtw89_mac_reg_by_idx(R_AX_GID_POSITION_EN1, mac_idx), 4832e3ec7017SPing-Ke Shih le32_to_cpu(p[1])); 4833e3ec7017SPing-Ke Shih 4834e3ec7017SPing-Ke Shih p = (__le32 *)conf->mu_group.position; 4835e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, rtw89_mac_reg_by_idx(R_AX_GID_POSITION0, mac_idx), 4836e3ec7017SPing-Ke Shih le32_to_cpu(p[0])); 4837e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, rtw89_mac_reg_by_idx(R_AX_GID_POSITION1, mac_idx), 4838e3ec7017SPing-Ke Shih le32_to_cpu(p[1])); 4839e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, rtw89_mac_reg_by_idx(R_AX_GID_POSITION2, mac_idx), 4840e3ec7017SPing-Ke Shih le32_to_cpu(p[2])); 4841e3ec7017SPing-Ke Shih rtw89_write32(rtwdev, rtw89_mac_reg_by_idx(R_AX_GID_POSITION3, mac_idx), 4842e3ec7017SPing-Ke Shih le32_to_cpu(p[3])); 4843e3ec7017SPing-Ke Shih } 4844e3ec7017SPing-Ke Shih 4845e3ec7017SPing-Ke Shih struct rtw89_mac_bf_monitor_iter_data { 4846e3ec7017SPing-Ke Shih struct rtw89_dev *rtwdev; 4847e3ec7017SPing-Ke Shih struct ieee80211_sta *down_sta; 4848e3ec7017SPing-Ke Shih int count; 4849e3ec7017SPing-Ke Shih }; 4850e3ec7017SPing-Ke Shih 4851e3ec7017SPing-Ke Shih static 4852e3ec7017SPing-Ke Shih void rtw89_mac_bf_monitor_calc_iter(void *data, struct ieee80211_sta *sta) 4853e3ec7017SPing-Ke Shih { 4854e3ec7017SPing-Ke Shih struct rtw89_mac_bf_monitor_iter_data *iter_data = 4855e3ec7017SPing-Ke Shih (struct rtw89_mac_bf_monitor_iter_data *)data; 4856e3ec7017SPing-Ke Shih struct ieee80211_sta *down_sta = iter_data->down_sta; 4857e3ec7017SPing-Ke Shih int *count = &iter_data->count; 4858e3ec7017SPing-Ke Shih 4859e3ec7017SPing-Ke Shih if (down_sta == sta) 4860e3ec7017SPing-Ke Shih return; 4861e3ec7017SPing-Ke Shih 4862e3ec7017SPing-Ke Shih if (rtw89_sta_has_beamformer_cap(sta)) 4863e3ec7017SPing-Ke Shih (*count)++; 4864e3ec7017SPing-Ke Shih } 4865e3ec7017SPing-Ke Shih 4866e3ec7017SPing-Ke Shih void rtw89_mac_bf_monitor_calc(struct rtw89_dev *rtwdev, 4867e3ec7017SPing-Ke Shih struct ieee80211_sta *sta, bool disconnect) 4868e3ec7017SPing-Ke Shih { 4869e3ec7017SPing-Ke Shih struct rtw89_mac_bf_monitor_iter_data data; 4870e3ec7017SPing-Ke Shih 4871e3ec7017SPing-Ke Shih data.rtwdev = rtwdev; 4872e3ec7017SPing-Ke Shih data.down_sta = disconnect ? sta : NULL; 4873e3ec7017SPing-Ke Shih data.count = 0; 4874e3ec7017SPing-Ke Shih ieee80211_iterate_stations_atomic(rtwdev->hw, 4875e3ec7017SPing-Ke Shih rtw89_mac_bf_monitor_calc_iter, 4876e3ec7017SPing-Ke Shih &data); 4877e3ec7017SPing-Ke Shih 4878e3ec7017SPing-Ke Shih rtw89_debug(rtwdev, RTW89_DBG_BF, "bfee STA count=%d\n", data.count); 4879e3ec7017SPing-Ke Shih if (data.count) 4880e3ec7017SPing-Ke Shih set_bit(RTW89_FLAG_BFEE_MON, rtwdev->flags); 4881e3ec7017SPing-Ke Shih else 4882e3ec7017SPing-Ke Shih clear_bit(RTW89_FLAG_BFEE_MON, rtwdev->flags); 4883e3ec7017SPing-Ke Shih } 4884e3ec7017SPing-Ke Shih 4885e3ec7017SPing-Ke Shih void _rtw89_mac_bf_monitor_track(struct rtw89_dev *rtwdev) 4886e3ec7017SPing-Ke Shih { 4887e3ec7017SPing-Ke Shih struct rtw89_traffic_stats *stats = &rtwdev->stats; 4888e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif; 48891646ce8fSYe Guojin bool en = stats->tx_tfc_lv <= stats->rx_tfc_lv; 4890e3ec7017SPing-Ke Shih bool old = test_bit(RTW89_FLAG_BFEE_EN, rtwdev->flags); 4891e3ec7017SPing-Ke Shih 4892e3ec7017SPing-Ke Shih if (en == old) 4893e3ec7017SPing-Ke Shih return; 4894e3ec7017SPing-Ke Shih 4895e3ec7017SPing-Ke Shih rtw89_for_each_rtwvif(rtwdev, rtwvif) 4896e3ec7017SPing-Ke Shih rtw89_mac_bfee_ctrl(rtwdev, rtwvif->mac_idx, en); 4897e3ec7017SPing-Ke Shih } 4898e3ec7017SPing-Ke Shih 4899e3ec7017SPing-Ke Shih static int 4900e3ec7017SPing-Ke Shih __rtw89_mac_set_tx_time(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, 4901e3ec7017SPing-Ke Shih u32 tx_time) 4902e3ec7017SPing-Ke Shih { 4903e3ec7017SPing-Ke Shih #define MAC_AX_DFLT_TX_TIME 5280 4904e3ec7017SPing-Ke Shih u8 mac_idx = rtwsta->rtwvif->mac_idx; 4905e3ec7017SPing-Ke Shih u32 max_tx_time = tx_time == 0 ? MAC_AX_DFLT_TX_TIME : tx_time; 4906e3ec7017SPing-Ke Shih u32 reg; 4907e3ec7017SPing-Ke Shih int ret = 0; 4908e3ec7017SPing-Ke Shih 4909e3ec7017SPing-Ke Shih if (rtwsta->cctl_tx_time) { 4910e3ec7017SPing-Ke Shih rtwsta->ampdu_max_time = (max_tx_time - 512) >> 9; 4911e3ec7017SPing-Ke Shih ret = rtw89_fw_h2c_txtime_cmac_tbl(rtwdev, rtwsta); 4912e3ec7017SPing-Ke Shih } else { 4913e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 4914e3ec7017SPing-Ke Shih if (ret) { 4915e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "failed to check cmac in set txtime\n"); 4916e3ec7017SPing-Ke Shih return ret; 4917e3ec7017SPing-Ke Shih } 4918e3ec7017SPing-Ke Shih 4919e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_AMPDU_AGG_LIMIT, mac_idx); 4920e3ec7017SPing-Ke Shih rtw89_write32_mask(rtwdev, reg, B_AX_AMPDU_MAX_TIME_MASK, 4921e3ec7017SPing-Ke Shih max_tx_time >> 5); 4922e3ec7017SPing-Ke Shih } 4923e3ec7017SPing-Ke Shih 4924e3ec7017SPing-Ke Shih return ret; 4925e3ec7017SPing-Ke Shih } 4926e3ec7017SPing-Ke Shih 4927e3ec7017SPing-Ke Shih int rtw89_mac_set_tx_time(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, 4928e3ec7017SPing-Ke Shih bool resume, u32 tx_time) 4929e3ec7017SPing-Ke Shih { 4930e3ec7017SPing-Ke Shih int ret = 0; 4931e3ec7017SPing-Ke Shih 4932e3ec7017SPing-Ke Shih if (!resume) { 4933e3ec7017SPing-Ke Shih rtwsta->cctl_tx_time = true; 4934e3ec7017SPing-Ke Shih ret = __rtw89_mac_set_tx_time(rtwdev, rtwsta, tx_time); 4935e3ec7017SPing-Ke Shih } else { 4936e3ec7017SPing-Ke Shih ret = __rtw89_mac_set_tx_time(rtwdev, rtwsta, tx_time); 4937e3ec7017SPing-Ke Shih rtwsta->cctl_tx_time = false; 4938e3ec7017SPing-Ke Shih } 4939e3ec7017SPing-Ke Shih 4940e3ec7017SPing-Ke Shih return ret; 4941e3ec7017SPing-Ke Shih } 4942e3ec7017SPing-Ke Shih 4943e3ec7017SPing-Ke Shih int rtw89_mac_get_tx_time(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta, 4944e3ec7017SPing-Ke Shih u32 *tx_time) 4945e3ec7017SPing-Ke Shih { 4946e3ec7017SPing-Ke Shih u8 mac_idx = rtwsta->rtwvif->mac_idx; 4947e3ec7017SPing-Ke Shih u32 reg; 4948e3ec7017SPing-Ke Shih int ret = 0; 4949e3ec7017SPing-Ke Shih 4950e3ec7017SPing-Ke Shih if (rtwsta->cctl_tx_time) { 4951e3ec7017SPing-Ke Shih *tx_time = (rtwsta->ampdu_max_time + 1) << 9; 4952e3ec7017SPing-Ke Shih } else { 4953e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 4954e3ec7017SPing-Ke Shih if (ret) { 4955e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "failed to check cmac in tx_time\n"); 4956e3ec7017SPing-Ke Shih return ret; 4957e3ec7017SPing-Ke Shih } 4958e3ec7017SPing-Ke Shih 4959e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_AMPDU_AGG_LIMIT, mac_idx); 4960e3ec7017SPing-Ke Shih *tx_time = rtw89_read32_mask(rtwdev, reg, B_AX_AMPDU_MAX_TIME_MASK) << 5; 4961e3ec7017SPing-Ke Shih } 4962e3ec7017SPing-Ke Shih 4963e3ec7017SPing-Ke Shih return ret; 4964e3ec7017SPing-Ke Shih } 4965e3ec7017SPing-Ke Shih 4966e3ec7017SPing-Ke Shih int rtw89_mac_set_tx_retry_limit(struct rtw89_dev *rtwdev, 4967e3ec7017SPing-Ke Shih struct rtw89_sta *rtwsta, 4968e3ec7017SPing-Ke Shih bool resume, u8 tx_retry) 4969e3ec7017SPing-Ke Shih { 4970e3ec7017SPing-Ke Shih int ret = 0; 4971e3ec7017SPing-Ke Shih 4972e3ec7017SPing-Ke Shih rtwsta->data_tx_cnt_lmt = tx_retry; 4973e3ec7017SPing-Ke Shih 4974e3ec7017SPing-Ke Shih if (!resume) { 4975e3ec7017SPing-Ke Shih rtwsta->cctl_tx_retry_limit = true; 4976e3ec7017SPing-Ke Shih ret = rtw89_fw_h2c_txtime_cmac_tbl(rtwdev, rtwsta); 4977e3ec7017SPing-Ke Shih } else { 4978e3ec7017SPing-Ke Shih ret = rtw89_fw_h2c_txtime_cmac_tbl(rtwdev, rtwsta); 4979e3ec7017SPing-Ke Shih rtwsta->cctl_tx_retry_limit = false; 4980e3ec7017SPing-Ke Shih } 4981e3ec7017SPing-Ke Shih 4982e3ec7017SPing-Ke Shih return ret; 4983e3ec7017SPing-Ke Shih } 4984e3ec7017SPing-Ke Shih 4985e3ec7017SPing-Ke Shih int rtw89_mac_get_tx_retry_limit(struct rtw89_dev *rtwdev, 4986e3ec7017SPing-Ke Shih struct rtw89_sta *rtwsta, u8 *tx_retry) 4987e3ec7017SPing-Ke Shih { 4988e3ec7017SPing-Ke Shih u8 mac_idx = rtwsta->rtwvif->mac_idx; 4989e3ec7017SPing-Ke Shih u32 reg; 4990e3ec7017SPing-Ke Shih int ret = 0; 4991e3ec7017SPing-Ke Shih 4992e3ec7017SPing-Ke Shih if (rtwsta->cctl_tx_retry_limit) { 4993e3ec7017SPing-Ke Shih *tx_retry = rtwsta->data_tx_cnt_lmt; 4994e3ec7017SPing-Ke Shih } else { 4995e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 4996e3ec7017SPing-Ke Shih if (ret) { 4997e3ec7017SPing-Ke Shih rtw89_warn(rtwdev, "failed to check cmac in rty_lmt\n"); 4998e3ec7017SPing-Ke Shih return ret; 4999e3ec7017SPing-Ke Shih } 5000e3ec7017SPing-Ke Shih 5001e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_TXCNT, mac_idx); 5002e3ec7017SPing-Ke Shih *tx_retry = rtw89_read32_mask(rtwdev, reg, B_AX_L_TXCNT_LMT_MASK); 5003e3ec7017SPing-Ke Shih } 5004e3ec7017SPing-Ke Shih 5005e3ec7017SPing-Ke Shih return ret; 5006e3ec7017SPing-Ke Shih } 5007e3ec7017SPing-Ke Shih 5008e3ec7017SPing-Ke Shih int rtw89_mac_set_hw_muedca_ctrl(struct rtw89_dev *rtwdev, 5009e3ec7017SPing-Ke Shih struct rtw89_vif *rtwvif, bool en) 5010e3ec7017SPing-Ke Shih { 5011e3ec7017SPing-Ke Shih u8 mac_idx = rtwvif->mac_idx; 5012e3ec7017SPing-Ke Shih u16 set = B_AX_MUEDCA_EN_0 | B_AX_SET_MUEDCATIMER_TF_0; 5013e3ec7017SPing-Ke Shih u32 reg; 5014e3ec7017SPing-Ke Shih u32 ret; 5015e3ec7017SPing-Ke Shih 5016e3ec7017SPing-Ke Shih ret = rtw89_mac_check_mac_en(rtwdev, mac_idx, RTW89_CMAC_SEL); 5017e3ec7017SPing-Ke Shih if (ret) 5018e3ec7017SPing-Ke Shih return ret; 5019e3ec7017SPing-Ke Shih 5020e3ec7017SPing-Ke Shih reg = rtw89_mac_reg_by_idx(R_AX_MUEDCA_EN, mac_idx); 5021e3ec7017SPing-Ke Shih if (en) 5022e3ec7017SPing-Ke Shih rtw89_write16_set(rtwdev, reg, set); 5023e3ec7017SPing-Ke Shih else 5024e3ec7017SPing-Ke Shih rtw89_write16_clr(rtwdev, reg, set); 5025e3ec7017SPing-Ke Shih 5026e3ec7017SPing-Ke Shih return 0; 5027e3ec7017SPing-Ke Shih } 50282a7e54dbSPing-Ke Shih 50292a7e54dbSPing-Ke Shih int rtw89_mac_write_xtal_si(struct rtw89_dev *rtwdev, u8 offset, u8 val, u8 mask) 50302a7e54dbSPing-Ke Shih { 50312a7e54dbSPing-Ke Shih u32 val32; 50322a7e54dbSPing-Ke Shih int ret; 50332a7e54dbSPing-Ke Shih 50342a7e54dbSPing-Ke Shih val32 = FIELD_PREP(B_AX_WL_XTAL_SI_ADDR_MASK, offset) | 50352a7e54dbSPing-Ke Shih FIELD_PREP(B_AX_WL_XTAL_SI_DATA_MASK, val) | 50362a7e54dbSPing-Ke Shih FIELD_PREP(B_AX_WL_XTAL_SI_BITMASK_MASK, mask) | 50372a7e54dbSPing-Ke Shih FIELD_PREP(B_AX_WL_XTAL_SI_MODE_MASK, XTAL_SI_NORMAL_WRITE) | 50382a7e54dbSPing-Ke Shih FIELD_PREP(B_AX_WL_XTAL_SI_CMD_POLL, 1); 50392a7e54dbSPing-Ke Shih rtw89_write32(rtwdev, R_AX_WLAN_XTAL_SI_CTRL, val32); 50402a7e54dbSPing-Ke Shih 50412a7e54dbSPing-Ke Shih ret = read_poll_timeout(rtw89_read32, val32, !(val32 & B_AX_WL_XTAL_SI_CMD_POLL), 50422a7e54dbSPing-Ke Shih 50, 50000, false, rtwdev, R_AX_WLAN_XTAL_SI_CTRL); 50432a7e54dbSPing-Ke Shih if (ret) { 50442a7e54dbSPing-Ke Shih rtw89_warn(rtwdev, "xtal si not ready(W): offset=%x val=%x mask=%x\n", 50452a7e54dbSPing-Ke Shih offset, val, mask); 50462a7e54dbSPing-Ke Shih return ret; 50472a7e54dbSPing-Ke Shih } 50482a7e54dbSPing-Ke Shih 50492a7e54dbSPing-Ke Shih return 0; 50502a7e54dbSPing-Ke Shih } 50512a7e54dbSPing-Ke Shih EXPORT_SYMBOL(rtw89_mac_write_xtal_si); 5052bdfbf06cSPing-Ke Shih 5053bdfbf06cSPing-Ke Shih int rtw89_mac_read_xtal_si(struct rtw89_dev *rtwdev, u8 offset, u8 *val) 5054bdfbf06cSPing-Ke Shih { 5055bdfbf06cSPing-Ke Shih u32 val32; 5056bdfbf06cSPing-Ke Shih int ret; 5057bdfbf06cSPing-Ke Shih 5058bdfbf06cSPing-Ke Shih val32 = FIELD_PREP(B_AX_WL_XTAL_SI_ADDR_MASK, offset) | 5059bdfbf06cSPing-Ke Shih FIELD_PREP(B_AX_WL_XTAL_SI_DATA_MASK, 0x00) | 5060bdfbf06cSPing-Ke Shih FIELD_PREP(B_AX_WL_XTAL_SI_BITMASK_MASK, 0x00) | 5061bdfbf06cSPing-Ke Shih FIELD_PREP(B_AX_WL_XTAL_SI_MODE_MASK, XTAL_SI_NORMAL_READ) | 5062bdfbf06cSPing-Ke Shih FIELD_PREP(B_AX_WL_XTAL_SI_CMD_POLL, 1); 5063bdfbf06cSPing-Ke Shih rtw89_write32(rtwdev, R_AX_WLAN_XTAL_SI_CTRL, val32); 5064bdfbf06cSPing-Ke Shih 5065bdfbf06cSPing-Ke Shih ret = read_poll_timeout(rtw89_read32, val32, !(val32 & B_AX_WL_XTAL_SI_CMD_POLL), 5066bdfbf06cSPing-Ke Shih 50, 50000, false, rtwdev, R_AX_WLAN_XTAL_SI_CTRL); 5067bdfbf06cSPing-Ke Shih if (ret) { 5068bdfbf06cSPing-Ke Shih rtw89_warn(rtwdev, "xtal si not ready(R): offset=%x\n", offset); 5069bdfbf06cSPing-Ke Shih return ret; 5070bdfbf06cSPing-Ke Shih } 5071bdfbf06cSPing-Ke Shih 5072bdfbf06cSPing-Ke Shih *val = rtw89_read8(rtwdev, R_AX_WLAN_XTAL_SI_CTRL + 1); 5073bdfbf06cSPing-Ke Shih 5074bdfbf06cSPing-Ke Shih return 0; 5075bdfbf06cSPing-Ke Shih } 507608484e1fSPing-Ke Shih EXPORT_SYMBOL(rtw89_mac_read_xtal_si); 50779a785583SZong-Zhe Yang 50789a785583SZong-Zhe Yang static 50799a785583SZong-Zhe Yang void rtw89_mac_pkt_drop_sta(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta) 50809a785583SZong-Zhe Yang { 50819a785583SZong-Zhe Yang static const enum rtw89_pkt_drop_sel sels[] = { 50829a785583SZong-Zhe Yang RTW89_PKT_DROP_SEL_MACID_BE_ONCE, 50839a785583SZong-Zhe Yang RTW89_PKT_DROP_SEL_MACID_BK_ONCE, 50849a785583SZong-Zhe Yang RTW89_PKT_DROP_SEL_MACID_VI_ONCE, 50859a785583SZong-Zhe Yang RTW89_PKT_DROP_SEL_MACID_VO_ONCE, 50869a785583SZong-Zhe Yang }; 50879a785583SZong-Zhe Yang struct rtw89_vif *rtwvif = rtwsta->rtwvif; 50889a785583SZong-Zhe Yang struct rtw89_pkt_drop_params params = {0}; 50899a785583SZong-Zhe Yang int i; 50909a785583SZong-Zhe Yang 50919a785583SZong-Zhe Yang params.mac_band = RTW89_MAC_0; 50929a785583SZong-Zhe Yang params.macid = rtwsta->mac_id; 50939a785583SZong-Zhe Yang params.port = rtwvif->port; 50949a785583SZong-Zhe Yang params.mbssid = 0; 50959a785583SZong-Zhe Yang params.tf_trs = rtwvif->trigger; 50969a785583SZong-Zhe Yang 50979a785583SZong-Zhe Yang for (i = 0; i < ARRAY_SIZE(sels); i++) { 50989a785583SZong-Zhe Yang params.sel = sels[i]; 50999a785583SZong-Zhe Yang rtw89_fw_h2c_pkt_drop(rtwdev, ¶ms); 51009a785583SZong-Zhe Yang } 51019a785583SZong-Zhe Yang } 51029a785583SZong-Zhe Yang 51039a785583SZong-Zhe Yang static void rtw89_mac_pkt_drop_vif_iter(void *data, struct ieee80211_sta *sta) 51049a785583SZong-Zhe Yang { 51059a785583SZong-Zhe Yang struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv; 51069a785583SZong-Zhe Yang struct rtw89_vif *rtwvif = rtwsta->rtwvif; 51079a785583SZong-Zhe Yang struct rtw89_dev *rtwdev = rtwvif->rtwdev; 51089a785583SZong-Zhe Yang struct rtw89_vif *target = data; 51099a785583SZong-Zhe Yang 51109a785583SZong-Zhe Yang if (rtwvif != target) 51119a785583SZong-Zhe Yang return; 51129a785583SZong-Zhe Yang 51139a785583SZong-Zhe Yang rtw89_mac_pkt_drop_sta(rtwdev, rtwsta); 51149a785583SZong-Zhe Yang } 51159a785583SZong-Zhe Yang 51169a785583SZong-Zhe Yang void rtw89_mac_pkt_drop_vif(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif) 51179a785583SZong-Zhe Yang { 51189a785583SZong-Zhe Yang ieee80211_iterate_stations_atomic(rtwdev->hw, 51199a785583SZong-Zhe Yang rtw89_mac_pkt_drop_vif_iter, 51209a785583SZong-Zhe Yang rtwvif); 51219a785583SZong-Zhe Yang } 512241d56769SChih-Kang Chang 512341d56769SChih-Kang Chang int rtw89_mac_ptk_drop_by_band_and_wait(struct rtw89_dev *rtwdev, 512441d56769SChih-Kang Chang enum rtw89_mac_idx band) 512541d56769SChih-Kang Chang { 512641d56769SChih-Kang Chang struct rtw89_pkt_drop_params params = {0}; 512741d56769SChih-Kang Chang bool empty; 512841d56769SChih-Kang Chang int i, ret = 0, try_cnt = 3; 512941d56769SChih-Kang Chang 513041d56769SChih-Kang Chang params.mac_band = band; 513141d56769SChih-Kang Chang params.sel = RTW89_PKT_DROP_SEL_BAND_ONCE; 513241d56769SChih-Kang Chang 513341d56769SChih-Kang Chang for (i = 0; i < try_cnt; i++) { 513441d56769SChih-Kang Chang ret = read_poll_timeout(mac_is_txq_empty, empty, empty, 50, 513541d56769SChih-Kang Chang 50000, false, rtwdev); 513641d56769SChih-Kang Chang if (ret) 513741d56769SChih-Kang Chang rtw89_fw_h2c_pkt_drop(rtwdev, ¶ms); 513841d56769SChih-Kang Chang else 513941d56769SChih-Kang Chang return 0; 514041d56769SChih-Kang Chang } 514141d56769SChih-Kang Chang return ret; 514241d56769SChih-Kang Chang } 5143