12774f206SBjoern A. Zeeb // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 22774f206SBjoern A. Zeeb /* Copyright(c) 2018-2019 Realtek Corporation. 32774f206SBjoern A. Zeeb */ 42774f206SBjoern A. Zeeb 52774f206SBjoern A. Zeeb #include "main.h" 62774f206SBjoern A. Zeeb #include "reg.h" 72774f206SBjoern A. Zeeb #include "bf.h" 82774f206SBjoern A. Zeeb #include "debug.h" 92774f206SBjoern A. Zeeb 102774f206SBjoern A. Zeeb void rtw_bf_disassoc(struct rtw_dev *rtwdev, struct ieee80211_vif *vif, 112774f206SBjoern A. Zeeb struct ieee80211_bss_conf *bss_conf) 122774f206SBjoern A. Zeeb { 132774f206SBjoern A. Zeeb struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 142774f206SBjoern A. Zeeb struct rtw_bfee *bfee = &rtwvif->bfee; 152774f206SBjoern A. Zeeb struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 162774f206SBjoern A. Zeeb 172774f206SBjoern A. Zeeb if (bfee->role == RTW_BFEE_NONE) 182774f206SBjoern A. Zeeb return; 192774f206SBjoern A. Zeeb 202774f206SBjoern A. Zeeb if (bfee->role == RTW_BFEE_MU) 212774f206SBjoern A. Zeeb bfinfo->bfer_mu_cnt--; 222774f206SBjoern A. Zeeb else if (bfee->role == RTW_BFEE_SU) 232774f206SBjoern A. Zeeb bfinfo->bfer_su_cnt--; 242774f206SBjoern A. Zeeb 252774f206SBjoern A. Zeeb rtw_chip_config_bfee(rtwdev, rtwvif, bfee, false); 262774f206SBjoern A. Zeeb 272774f206SBjoern A. Zeeb bfee->role = RTW_BFEE_NONE; 282774f206SBjoern A. Zeeb } 292774f206SBjoern A. Zeeb 302774f206SBjoern A. Zeeb void rtw_bf_assoc(struct rtw_dev *rtwdev, struct ieee80211_vif *vif, 312774f206SBjoern A. Zeeb struct ieee80211_bss_conf *bss_conf) 322774f206SBjoern A. Zeeb { 332774f206SBjoern A. Zeeb struct ieee80211_hw *hw = rtwdev->hw; 342774f206SBjoern A. Zeeb struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 352774f206SBjoern A. Zeeb struct rtw_bfee *bfee = &rtwvif->bfee; 362774f206SBjoern A. Zeeb struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 372774f206SBjoern A. Zeeb struct rtw_chip_info *chip = rtwdev->chip; 382774f206SBjoern A. Zeeb struct ieee80211_sta *sta; 392774f206SBjoern A. Zeeb struct ieee80211_sta_vht_cap *vht_cap; 402774f206SBjoern A. Zeeb struct ieee80211_sta_vht_cap *ic_vht_cap; 412774f206SBjoern A. Zeeb const u8 *bssid = bss_conf->bssid; 422774f206SBjoern A. Zeeb u32 sound_dim; 432774f206SBjoern A. Zeeb u8 i; 442774f206SBjoern A. Zeeb 452774f206SBjoern A. Zeeb if (!(chip->band & RTW_BAND_5G)) 462774f206SBjoern A. Zeeb return; 472774f206SBjoern A. Zeeb 482774f206SBjoern A. Zeeb rcu_read_lock(); 492774f206SBjoern A. Zeeb 502774f206SBjoern A. Zeeb sta = ieee80211_find_sta(vif, bssid); 512774f206SBjoern A. Zeeb if (!sta) { 522774f206SBjoern A. Zeeb #if defined(__linux__) 532774f206SBjoern A. Zeeb rtw_warn(rtwdev, "failed to find station entry for bss %pM\n", 542774f206SBjoern A. Zeeb bssid); 552774f206SBjoern A. Zeeb #elif defined(__FreeBSD__) 562774f206SBjoern A. Zeeb rtw_warn(rtwdev, "failed to find station entry for bss %6D\n", 572774f206SBjoern A. Zeeb bssid, ":"); 582774f206SBjoern A. Zeeb #endif 592774f206SBjoern A. Zeeb goto out_unlock; 602774f206SBjoern A. Zeeb } 612774f206SBjoern A. Zeeb 622774f206SBjoern A. Zeeb ic_vht_cap = &hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap; 63*6cf748adSBjoern A. Zeeb vht_cap = &sta->deflink.vht_cap; 642774f206SBjoern A. Zeeb 652774f206SBjoern A. Zeeb if ((ic_vht_cap->cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && 662774f206SBjoern A. Zeeb (vht_cap->cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { 672774f206SBjoern A. Zeeb if (bfinfo->bfer_mu_cnt >= chip->bfer_mu_max_num) { 682774f206SBjoern A. Zeeb rtw_dbg(rtwdev, RTW_DBG_BF, "mu bfer number over limit\n"); 692774f206SBjoern A. Zeeb goto out_unlock; 702774f206SBjoern A. Zeeb } 712774f206SBjoern A. Zeeb 722774f206SBjoern A. Zeeb ether_addr_copy(bfee->mac_addr, bssid); 732774f206SBjoern A. Zeeb bfee->role = RTW_BFEE_MU; 742774f206SBjoern A. Zeeb bfee->p_aid = (bssid[5] << 1) | (bssid[4] >> 7); 752774f206SBjoern A. Zeeb bfee->aid = bss_conf->aid; 762774f206SBjoern A. Zeeb bfinfo->bfer_mu_cnt++; 772774f206SBjoern A. Zeeb 782774f206SBjoern A. Zeeb rtw_chip_config_bfee(rtwdev, rtwvif, bfee, true); 792774f206SBjoern A. Zeeb } else if ((ic_vht_cap->cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) && 802774f206SBjoern A. Zeeb (vht_cap->cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { 812774f206SBjoern A. Zeeb if (bfinfo->bfer_su_cnt >= chip->bfer_su_max_num) { 822774f206SBjoern A. Zeeb rtw_dbg(rtwdev, RTW_DBG_BF, "su bfer number over limit\n"); 832774f206SBjoern A. Zeeb goto out_unlock; 842774f206SBjoern A. Zeeb } 852774f206SBjoern A. Zeeb 862774f206SBjoern A. Zeeb sound_dim = vht_cap->cap & 872774f206SBjoern A. Zeeb IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; 882774f206SBjoern A. Zeeb sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; 892774f206SBjoern A. Zeeb 902774f206SBjoern A. Zeeb ether_addr_copy(bfee->mac_addr, bssid); 912774f206SBjoern A. Zeeb bfee->role = RTW_BFEE_SU; 922774f206SBjoern A. Zeeb bfee->sound_dim = (u8)sound_dim; 932774f206SBjoern A. Zeeb bfee->g_id = 0; 942774f206SBjoern A. Zeeb bfee->p_aid = (bssid[5] << 1) | (bssid[4] >> 7); 952774f206SBjoern A. Zeeb bfinfo->bfer_su_cnt++; 962774f206SBjoern A. Zeeb for (i = 0; i < chip->bfer_su_max_num; i++) { 972774f206SBjoern A. Zeeb if (!test_bit(i, bfinfo->bfer_su_reg_maping)) { 982774f206SBjoern A. Zeeb set_bit(i, bfinfo->bfer_su_reg_maping); 992774f206SBjoern A. Zeeb bfee->su_reg_index = i; 1002774f206SBjoern A. Zeeb break; 1012774f206SBjoern A. Zeeb } 1022774f206SBjoern A. Zeeb } 1032774f206SBjoern A. Zeeb 1042774f206SBjoern A. Zeeb rtw_chip_config_bfee(rtwdev, rtwvif, bfee, true); 1052774f206SBjoern A. Zeeb } 1062774f206SBjoern A. Zeeb 1072774f206SBjoern A. Zeeb out_unlock: 1082774f206SBjoern A. Zeeb rcu_read_unlock(); 1092774f206SBjoern A. Zeeb } 1102774f206SBjoern A. Zeeb 1112774f206SBjoern A. Zeeb void rtw_bf_init_bfer_entry_mu(struct rtw_dev *rtwdev, 1122774f206SBjoern A. Zeeb struct mu_bfer_init_para *param) 1132774f206SBjoern A. Zeeb { 1142774f206SBjoern A. Zeeb u16 mu_bf_ctl = 0; 1152774f206SBjoern A. Zeeb u8 *addr = param->bfer_address; 1162774f206SBjoern A. Zeeb int i; 1172774f206SBjoern A. Zeeb 1182774f206SBjoern A. Zeeb for (i = 0; i < ETH_ALEN; i++) 1192774f206SBjoern A. Zeeb rtw_write8(rtwdev, REG_ASSOCIATED_BFMER0_INFO + i, addr[i]); 1202774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 6, param->paid); 1212774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20, param->csi_para); 1222774f206SBjoern A. Zeeb 1232774f206SBjoern A. Zeeb mu_bf_ctl = rtw_read16(rtwdev, REG_WMAC_MU_BF_CTL) & 0xC000; 1242774f206SBjoern A. Zeeb mu_bf_ctl |= param->my_aid | (param->csi_length_sel << 12); 1252774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, mu_bf_ctl); 1262774f206SBjoern A. Zeeb } 1272774f206SBjoern A. Zeeb 1282774f206SBjoern A. Zeeb void rtw_bf_cfg_sounding(struct rtw_dev *rtwdev, struct rtw_vif *vif, 1292774f206SBjoern A. Zeeb enum rtw_trx_desc_rate rate) 1302774f206SBjoern A. Zeeb { 1312774f206SBjoern A. Zeeb u32 psf_ctl = 0; 1322774f206SBjoern A. Zeeb u8 csi_rsc = 0x1; 1332774f206SBjoern A. Zeeb 1342774f206SBjoern A. Zeeb psf_ctl = rtw_read32(rtwdev, REG_BBPSF_CTRL) | 1352774f206SBjoern A. Zeeb BIT_WMAC_USE_NDPARATE | 1362774f206SBjoern A. Zeeb (csi_rsc << 13); 1372774f206SBjoern A. Zeeb 1382774f206SBjoern A. Zeeb rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 1392774f206SBjoern A. Zeeb RTW_SND_CTRL_SOUNDING); 1402774f206SBjoern A. Zeeb rtw_write8(rtwdev, REG_SND_PTCL_CTRL + 3, 0x26); 1412774f206SBjoern A. Zeeb rtw_write8_clr(rtwdev, REG_RXFLTMAP1, BIT_RXFLTMAP1_BF_REPORT_POLL); 1422774f206SBjoern A. Zeeb rtw_write8_clr(rtwdev, REG_RXFLTMAP4, BIT_RXFLTMAP4_BF_REPORT_POLL); 1432774f206SBjoern A. Zeeb 1442774f206SBjoern A. Zeeb if (vif->net_type == RTW_NET_AP_MODE) 1452774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_BBPSF_CTRL, psf_ctl | BIT(12)); 1462774f206SBjoern A. Zeeb else 1472774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_BBPSF_CTRL, psf_ctl & ~BIT(12)); 1482774f206SBjoern A. Zeeb } 1492774f206SBjoern A. Zeeb 1502774f206SBjoern A. Zeeb void rtw_bf_cfg_mu_bfee(struct rtw_dev *rtwdev, struct cfg_mumimo_para *param) 1512774f206SBjoern A. Zeeb { 1522774f206SBjoern A. Zeeb u8 mu_tbl_sel; 1532774f206SBjoern A. Zeeb u8 mu_valid; 1542774f206SBjoern A. Zeeb 1552774f206SBjoern A. Zeeb mu_valid = rtw_read8(rtwdev, REG_MU_TX_CTL) & 1562774f206SBjoern A. Zeeb ~BIT_MASK_R_MU_TABLE_VALID; 1572774f206SBjoern A. Zeeb 1582774f206SBjoern A. Zeeb rtw_write8(rtwdev, REG_MU_TX_CTL, 1592774f206SBjoern A. Zeeb (mu_valid | BIT(0) | BIT(1)) & ~(BIT(7))); 1602774f206SBjoern A. Zeeb 1612774f206SBjoern A. Zeeb mu_tbl_sel = rtw_read8(rtwdev, REG_MU_TX_CTL + 1) & 0xF8; 1622774f206SBjoern A. Zeeb 1632774f206SBjoern A. Zeeb rtw_write8(rtwdev, REG_MU_TX_CTL + 1, mu_tbl_sel); 1642774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_MU_STA_GID_VLD, param->given_gid_tab[0]); 1652774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO, param->given_user_pos[0]); 1662774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO + 4, 1672774f206SBjoern A. Zeeb param->given_user_pos[1]); 1682774f206SBjoern A. Zeeb 1692774f206SBjoern A. Zeeb rtw_write8(rtwdev, REG_MU_TX_CTL + 1, mu_tbl_sel | 1); 1702774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_MU_STA_GID_VLD, param->given_gid_tab[1]); 1712774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO, param->given_user_pos[2]); 1722774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO + 4, 1732774f206SBjoern A. Zeeb param->given_user_pos[3]); 1742774f206SBjoern A. Zeeb } 1752774f206SBjoern A. Zeeb 1762774f206SBjoern A. Zeeb void rtw_bf_del_bfer_entry_mu(struct rtw_dev *rtwdev) 1772774f206SBjoern A. Zeeb { 1782774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO, 0); 1792774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 4, 0); 1802774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, 0); 1812774f206SBjoern A. Zeeb rtw_write8(rtwdev, REG_MU_TX_CTL, 0); 1822774f206SBjoern A. Zeeb } 1832774f206SBjoern A. Zeeb 1842774f206SBjoern A. Zeeb void rtw_bf_del_sounding(struct rtw_dev *rtwdev) 1852774f206SBjoern A. Zeeb { 1862774f206SBjoern A. Zeeb rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 0); 1872774f206SBjoern A. Zeeb } 1882774f206SBjoern A. Zeeb 1892774f206SBjoern A. Zeeb void rtw_bf_enable_bfee_su(struct rtw_dev *rtwdev, struct rtw_vif *vif, 1902774f206SBjoern A. Zeeb struct rtw_bfee *bfee) 1912774f206SBjoern A. Zeeb { 1922774f206SBjoern A. Zeeb u8 nc_index = hweight8(rtwdev->hal.antenna_rx) - 1; 1932774f206SBjoern A. Zeeb u8 nr_index = bfee->sound_dim; 1942774f206SBjoern A. Zeeb u8 grouping = 0, codebookinfo = 1, coefficientsize = 3; 1952774f206SBjoern A. Zeeb u32 addr_bfer_info, addr_csi_rpt, csi_param; 1962774f206SBjoern A. Zeeb u8 i; 1972774f206SBjoern A. Zeeb 1982774f206SBjoern A. Zeeb rtw_dbg(rtwdev, RTW_DBG_BF, "config as an su bfee\n"); 1992774f206SBjoern A. Zeeb 2002774f206SBjoern A. Zeeb switch (bfee->su_reg_index) { 2012774f206SBjoern A. Zeeb case 1: 2022774f206SBjoern A. Zeeb addr_bfer_info = REG_ASSOCIATED_BFMER1_INFO; 2032774f206SBjoern A. Zeeb addr_csi_rpt = REG_TX_CSI_RPT_PARAM_BW20 + 2; 2042774f206SBjoern A. Zeeb break; 2052774f206SBjoern A. Zeeb case 0: 2062774f206SBjoern A. Zeeb default: 2072774f206SBjoern A. Zeeb addr_bfer_info = REG_ASSOCIATED_BFMER0_INFO; 2082774f206SBjoern A. Zeeb addr_csi_rpt = REG_TX_CSI_RPT_PARAM_BW20; 2092774f206SBjoern A. Zeeb break; 2102774f206SBjoern A. Zeeb } 2112774f206SBjoern A. Zeeb 2122774f206SBjoern A. Zeeb /* Sounding protocol control */ 2132774f206SBjoern A. Zeeb rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 2142774f206SBjoern A. Zeeb RTW_SND_CTRL_SOUNDING); 2152774f206SBjoern A. Zeeb 2162774f206SBjoern A. Zeeb /* MAC address/Partial AID of Beamformer */ 2172774f206SBjoern A. Zeeb for (i = 0; i < ETH_ALEN; i++) 2182774f206SBjoern A. Zeeb rtw_write8(rtwdev, addr_bfer_info + i, bfee->mac_addr[i]); 2192774f206SBjoern A. Zeeb 2202774f206SBjoern A. Zeeb csi_param = (u16)((coefficientsize << 10) | 2212774f206SBjoern A. Zeeb (codebookinfo << 8) | 2222774f206SBjoern A. Zeeb (grouping << 6) | 2232774f206SBjoern A. Zeeb (nr_index << 3) | 2242774f206SBjoern A. Zeeb nc_index); 2252774f206SBjoern A. Zeeb rtw_write16(rtwdev, addr_csi_rpt, csi_param); 2262774f206SBjoern A. Zeeb 2272774f206SBjoern A. Zeeb /* ndp rx standby timer */ 2282774f206SBjoern A. Zeeb rtw_write8(rtwdev, REG_SND_PTCL_CTRL + 3, RTW_NDP_RX_STANDBY_TIME); 2292774f206SBjoern A. Zeeb } 2302774f206SBjoern A. Zeeb EXPORT_SYMBOL(rtw_bf_enable_bfee_su); 2312774f206SBjoern A. Zeeb 2322774f206SBjoern A. Zeeb /* nc index: 1 2T2R 0 1T1R 2332774f206SBjoern A. Zeeb * nr index: 1 use Nsts 0 use reg setting 2342774f206SBjoern A. Zeeb * codebookinfo: 1 802.11ac 3 802.11n 2352774f206SBjoern A. Zeeb */ 2362774f206SBjoern A. Zeeb void rtw_bf_enable_bfee_mu(struct rtw_dev *rtwdev, struct rtw_vif *vif, 2372774f206SBjoern A. Zeeb struct rtw_bfee *bfee) 2382774f206SBjoern A. Zeeb { 2392774f206SBjoern A. Zeeb struct rtw_bf_info *bf_info = &rtwdev->bf_info; 2402774f206SBjoern A. Zeeb struct mu_bfer_init_para param; 2412774f206SBjoern A. Zeeb u8 nc_index = hweight8(rtwdev->hal.antenna_rx) - 1; 2422774f206SBjoern A. Zeeb u8 nr_index = 1; 2432774f206SBjoern A. Zeeb u8 grouping = 0, codebookinfo = 1, coefficientsize = 0; 2442774f206SBjoern A. Zeeb u32 csi_param; 2452774f206SBjoern A. Zeeb 2462774f206SBjoern A. Zeeb rtw_dbg(rtwdev, RTW_DBG_BF, "config as an mu bfee\n"); 2472774f206SBjoern A. Zeeb 2482774f206SBjoern A. Zeeb csi_param = (u16)((coefficientsize << 10) | 2492774f206SBjoern A. Zeeb (codebookinfo << 8) | 2502774f206SBjoern A. Zeeb (grouping << 6) | 2512774f206SBjoern A. Zeeb (nr_index << 3) | 2522774f206SBjoern A. Zeeb nc_index); 2532774f206SBjoern A. Zeeb 2542774f206SBjoern A. Zeeb rtw_dbg(rtwdev, RTW_DBG_BF, "nc=%d nr=%d group=%d codebookinfo=%d coefficientsize=%d\n", 2552774f206SBjoern A. Zeeb nc_index, nr_index, grouping, codebookinfo, 2562774f206SBjoern A. Zeeb coefficientsize); 2572774f206SBjoern A. Zeeb 2582774f206SBjoern A. Zeeb param.paid = bfee->p_aid; 2592774f206SBjoern A. Zeeb param.csi_para = csi_param; 2602774f206SBjoern A. Zeeb param.my_aid = bfee->aid & 0xfff; 2612774f206SBjoern A. Zeeb param.csi_length_sel = HAL_CSI_SEG_4K; 2622774f206SBjoern A. Zeeb ether_addr_copy(param.bfer_address, bfee->mac_addr); 2632774f206SBjoern A. Zeeb 2642774f206SBjoern A. Zeeb rtw_bf_init_bfer_entry_mu(rtwdev, ¶m); 2652774f206SBjoern A. Zeeb 2662774f206SBjoern A. Zeeb bf_info->cur_csi_rpt_rate = DESC_RATE6M; 2672774f206SBjoern A. Zeeb rtw_bf_cfg_sounding(rtwdev, vif, DESC_RATE6M); 2682774f206SBjoern A. Zeeb 2692774f206SBjoern A. Zeeb /* accept action_no_ack */ 2702774f206SBjoern A. Zeeb rtw_write16_set(rtwdev, REG_RXFLTMAP0, BIT_RXFLTMAP0_ACTIONNOACK); 2712774f206SBjoern A. Zeeb 2722774f206SBjoern A. Zeeb /* accept NDPA and BF report poll */ 2732774f206SBjoern A. Zeeb rtw_write16_set(rtwdev, REG_RXFLTMAP1, BIT_RXFLTMAP1_BF); 2742774f206SBjoern A. Zeeb } 2752774f206SBjoern A. Zeeb EXPORT_SYMBOL(rtw_bf_enable_bfee_mu); 2762774f206SBjoern A. Zeeb 2772774f206SBjoern A. Zeeb void rtw_bf_remove_bfee_su(struct rtw_dev *rtwdev, 2782774f206SBjoern A. Zeeb struct rtw_bfee *bfee) 2792774f206SBjoern A. Zeeb { 2802774f206SBjoern A. Zeeb struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 2812774f206SBjoern A. Zeeb 2822774f206SBjoern A. Zeeb rtw_dbg(rtwdev, RTW_DBG_BF, "remove as a su bfee\n"); 2832774f206SBjoern A. Zeeb rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 2842774f206SBjoern A. Zeeb RTW_SND_CTRL_REMOVE); 2852774f206SBjoern A. Zeeb 2862774f206SBjoern A. Zeeb switch (bfee->su_reg_index) { 2872774f206SBjoern A. Zeeb case 0: 2882774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO, 0); 2892774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 4, 0); 2902774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20, 0); 2912774f206SBjoern A. Zeeb break; 2922774f206SBjoern A. Zeeb case 1: 2932774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_ASSOCIATED_BFMER1_INFO, 0); 2942774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_ASSOCIATED_BFMER1_INFO + 4, 0); 2952774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20 + 2, 0); 2962774f206SBjoern A. Zeeb break; 2972774f206SBjoern A. Zeeb } 2982774f206SBjoern A. Zeeb 2992774f206SBjoern A. Zeeb clear_bit(bfee->su_reg_index, bfinfo->bfer_su_reg_maping); 3002774f206SBjoern A. Zeeb bfee->su_reg_index = 0xFF; 3012774f206SBjoern A. Zeeb } 3022774f206SBjoern A. Zeeb EXPORT_SYMBOL(rtw_bf_remove_bfee_su); 3032774f206SBjoern A. Zeeb 3042774f206SBjoern A. Zeeb void rtw_bf_remove_bfee_mu(struct rtw_dev *rtwdev, 3052774f206SBjoern A. Zeeb struct rtw_bfee *bfee) 3062774f206SBjoern A. Zeeb { 3072774f206SBjoern A. Zeeb struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 3082774f206SBjoern A. Zeeb 3092774f206SBjoern A. Zeeb rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 3102774f206SBjoern A. Zeeb RTW_SND_CTRL_REMOVE); 3112774f206SBjoern A. Zeeb 3122774f206SBjoern A. Zeeb rtw_bf_del_bfer_entry_mu(rtwdev); 3132774f206SBjoern A. Zeeb 3142774f206SBjoern A. Zeeb if (bfinfo->bfer_su_cnt == 0 && bfinfo->bfer_mu_cnt == 0) 3152774f206SBjoern A. Zeeb rtw_bf_del_sounding(rtwdev); 3162774f206SBjoern A. Zeeb } 3172774f206SBjoern A. Zeeb EXPORT_SYMBOL(rtw_bf_remove_bfee_mu); 3182774f206SBjoern A. Zeeb 3192774f206SBjoern A. Zeeb void rtw_bf_set_gid_table(struct rtw_dev *rtwdev, struct ieee80211_vif *vif, 3202774f206SBjoern A. Zeeb struct ieee80211_bss_conf *conf) 3212774f206SBjoern A. Zeeb { 3222774f206SBjoern A. Zeeb struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 3232774f206SBjoern A. Zeeb struct rtw_bfee *bfee = &rtwvif->bfee; 3242774f206SBjoern A. Zeeb struct cfg_mumimo_para param; 3252774f206SBjoern A. Zeeb 3262774f206SBjoern A. Zeeb if (bfee->role != RTW_BFEE_MU) { 3272774f206SBjoern A. Zeeb rtw_dbg(rtwdev, RTW_DBG_BF, "this vif is not mu bfee\n"); 3282774f206SBjoern A. Zeeb return; 3292774f206SBjoern A. Zeeb } 3302774f206SBjoern A. Zeeb 3312774f206SBjoern A. Zeeb param.grouping_bitmap = 0; 3322774f206SBjoern A. Zeeb param.mu_tx_en = 0; 3332774f206SBjoern A. Zeeb memset(param.sounding_sts, 0, 6); 3342774f206SBjoern A. Zeeb memcpy(param.given_gid_tab, conf->mu_group.membership, 8); 3352774f206SBjoern A. Zeeb memcpy(param.given_user_pos, conf->mu_group.position, 16); 3362774f206SBjoern A. Zeeb rtw_dbg(rtwdev, RTW_DBG_BF, "STA0: gid_valid=0x%x, user_position_l=0x%x, user_position_h=0x%x\n", 3372774f206SBjoern A. Zeeb param.given_gid_tab[0], param.given_user_pos[0], 3382774f206SBjoern A. Zeeb param.given_user_pos[1]); 3392774f206SBjoern A. Zeeb 3402774f206SBjoern A. Zeeb rtw_dbg(rtwdev, RTW_DBG_BF, "STA1: gid_valid=0x%x, user_position_l=0x%x, user_position_h=0x%x\n", 3412774f206SBjoern A. Zeeb param.given_gid_tab[1], param.given_user_pos[2], 3422774f206SBjoern A. Zeeb param.given_user_pos[3]); 3432774f206SBjoern A. Zeeb 3442774f206SBjoern A. Zeeb rtw_bf_cfg_mu_bfee(rtwdev, ¶m); 3452774f206SBjoern A. Zeeb } 3462774f206SBjoern A. Zeeb EXPORT_SYMBOL(rtw_bf_set_gid_table); 3472774f206SBjoern A. Zeeb 3482774f206SBjoern A. Zeeb void rtw_bf_phy_init(struct rtw_dev *rtwdev) 3492774f206SBjoern A. Zeeb { 3502774f206SBjoern A. Zeeb u8 tmp8; 3512774f206SBjoern A. Zeeb u32 tmp32; 3522774f206SBjoern A. Zeeb u8 retry_limit = 0xA; 3532774f206SBjoern A. Zeeb u8 ndpa_rate = 0x10; 3542774f206SBjoern A. Zeeb u8 ack_policy = 3; 3552774f206SBjoern A. Zeeb 3562774f206SBjoern A. Zeeb tmp32 = rtw_read32(rtwdev, REG_MU_TX_CTL); 3572774f206SBjoern A. Zeeb /* Enable P1 aggr new packet according to P0 transfer time */ 3582774f206SBjoern A. Zeeb tmp32 |= BIT_MU_P1_WAIT_STATE_EN; 3592774f206SBjoern A. Zeeb /* MU Retry Limit */ 3602774f206SBjoern A. Zeeb tmp32 &= ~BIT_MASK_R_MU_RL; 3612774f206SBjoern A. Zeeb tmp32 |= (retry_limit << BIT_SHIFT_R_MU_RL) & BIT_MASK_R_MU_RL; 3622774f206SBjoern A. Zeeb /* Disable Tx MU-MIMO until sounding done */ 3632774f206SBjoern A. Zeeb tmp32 &= ~BIT_EN_MU_MIMO; 3642774f206SBjoern A. Zeeb /* Clear validity of MU STAs */ 3652774f206SBjoern A. Zeeb tmp32 &= ~BIT_MASK_R_MU_TABLE_VALID; 3662774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_MU_TX_CTL, tmp32); 3672774f206SBjoern A. Zeeb 3682774f206SBjoern A. Zeeb /* MU-MIMO Option as default value */ 3692774f206SBjoern A. Zeeb tmp8 = ack_policy << BIT_SHIFT_WMAC_TXMU_ACKPOLICY; 3702774f206SBjoern A. Zeeb tmp8 |= BIT_WMAC_TXMU_ACKPOLICY_EN; 3712774f206SBjoern A. Zeeb rtw_write8(rtwdev, REG_WMAC_MU_BF_OPTION, tmp8); 3722774f206SBjoern A. Zeeb 3732774f206SBjoern A. Zeeb /* MU-MIMO Control as default value */ 3742774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, 0); 3752774f206SBjoern A. Zeeb /* Set MU NDPA rate & BW source */ 3762774f206SBjoern A. Zeeb rtw_write32_set(rtwdev, REG_TXBF_CTRL, BIT_USE_NDPA_PARAMETER); 3772774f206SBjoern A. Zeeb /* Set NDPA Rate */ 3782774f206SBjoern A. Zeeb rtw_write8(rtwdev, REG_NDPA_OPT_CTRL, ndpa_rate); 3792774f206SBjoern A. Zeeb 3802774f206SBjoern A. Zeeb rtw_write32_mask(rtwdev, REG_BBPSF_CTRL, BIT_MASK_CSI_RATE, 3812774f206SBjoern A. Zeeb DESC_RATE6M); 3822774f206SBjoern A. Zeeb } 3832774f206SBjoern A. Zeeb EXPORT_SYMBOL(rtw_bf_phy_init); 3842774f206SBjoern A. Zeeb 3852774f206SBjoern A. Zeeb void rtw_bf_cfg_csi_rate(struct rtw_dev *rtwdev, u8 rssi, u8 cur_rate, 3862774f206SBjoern A. Zeeb u8 fixrate_en, u8 *new_rate) 3872774f206SBjoern A. Zeeb { 3882774f206SBjoern A. Zeeb u32 csi_cfg; 3892774f206SBjoern A. Zeeb u16 cur_rrsr; 3902774f206SBjoern A. Zeeb 3912774f206SBjoern A. Zeeb csi_cfg = rtw_read32(rtwdev, REG_BBPSF_CTRL) & ~BIT_MASK_CSI_RATE; 3922774f206SBjoern A. Zeeb cur_rrsr = rtw_read16(rtwdev, REG_RRSR); 3932774f206SBjoern A. Zeeb 3942774f206SBjoern A. Zeeb if (rssi >= 40) { 3952774f206SBjoern A. Zeeb if (cur_rate != DESC_RATE54M) { 3962774f206SBjoern A. Zeeb cur_rrsr |= BIT(DESC_RATE54M); 3972774f206SBjoern A. Zeeb csi_cfg |= (DESC_RATE54M & BIT_MASK_CSI_RATE_VAL) << 3982774f206SBjoern A. Zeeb BIT_SHIFT_CSI_RATE; 3992774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_RRSR, cur_rrsr); 4002774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_BBPSF_CTRL, csi_cfg); 4012774f206SBjoern A. Zeeb } 4022774f206SBjoern A. Zeeb *new_rate = DESC_RATE54M; 4032774f206SBjoern A. Zeeb } else { 4042774f206SBjoern A. Zeeb if (cur_rate != DESC_RATE24M) { 4052774f206SBjoern A. Zeeb cur_rrsr &= ~BIT(DESC_RATE54M); 4062774f206SBjoern A. Zeeb csi_cfg |= (DESC_RATE54M & BIT_MASK_CSI_RATE_VAL) << 4072774f206SBjoern A. Zeeb BIT_SHIFT_CSI_RATE; 4082774f206SBjoern A. Zeeb rtw_write16(rtwdev, REG_RRSR, cur_rrsr); 4092774f206SBjoern A. Zeeb rtw_write32(rtwdev, REG_BBPSF_CTRL, csi_cfg); 4102774f206SBjoern A. Zeeb } 4112774f206SBjoern A. Zeeb *new_rate = DESC_RATE24M; 4122774f206SBjoern A. Zeeb } 4132774f206SBjoern A. Zeeb } 4142774f206SBjoern A. Zeeb EXPORT_SYMBOL(rtw_bf_cfg_csi_rate); 415