10bd95573STzu-En Huang // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 20bd95573STzu-En Huang /* Copyright(c) 2018-2019 Realtek Corporation. 30bd95573STzu-En Huang */ 40bd95573STzu-En Huang 50bd95573STzu-En Huang #include "main.h" 60bd95573STzu-En Huang #include "reg.h" 70bd95573STzu-En Huang #include "bf.h" 80bd95573STzu-En Huang #include "debug.h" 90bd95573STzu-En Huang 100bd95573STzu-En Huang void rtw_bf_disassoc(struct rtw_dev *rtwdev, struct ieee80211_vif *vif, 110bd95573STzu-En Huang struct ieee80211_bss_conf *bss_conf) 120bd95573STzu-En Huang { 130bd95573STzu-En Huang struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 140bd95573STzu-En Huang struct rtw_bfee *bfee = &rtwvif->bfee; 150bd95573STzu-En Huang struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 160bd95573STzu-En Huang 170bd95573STzu-En Huang if (bfee->role == RTW_BFEE_NONE) 180bd95573STzu-En Huang return; 190bd95573STzu-En Huang 200bd95573STzu-En Huang if (bfee->role == RTW_BFEE_MU) 210bd95573STzu-En Huang bfinfo->bfer_mu_cnt--; 220bd95573STzu-En Huang else if (bfee->role == RTW_BFEE_SU) 230bd95573STzu-En Huang bfinfo->bfer_su_cnt--; 240bd95573STzu-En Huang 2593ae973fSPing-Ke Shih rtw_chip_config_bfee(rtwdev, rtwvif, bfee, false); 260bd95573STzu-En Huang 270bd95573STzu-En Huang bfee->role = RTW_BFEE_NONE; 280bd95573STzu-En Huang } 290bd95573STzu-En Huang 300bd95573STzu-En Huang void rtw_bf_assoc(struct rtw_dev *rtwdev, struct ieee80211_vif *vif, 310bd95573STzu-En Huang struct ieee80211_bss_conf *bss_conf) 320bd95573STzu-En Huang { 33dcbf179cSPing-Ke Shih const struct rtw_chip_info *chip = rtwdev->chip; 340bd95573STzu-En Huang struct ieee80211_hw *hw = rtwdev->hw; 350bd95573STzu-En Huang struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 360bd95573STzu-En Huang struct rtw_bfee *bfee = &rtwvif->bfee; 370bd95573STzu-En Huang struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 380bd95573STzu-En Huang struct ieee80211_sta *sta; 390bd95573STzu-En Huang struct ieee80211_sta_vht_cap *vht_cap; 400bd95573STzu-En Huang struct ieee80211_sta_vht_cap *ic_vht_cap; 410bd95573STzu-En Huang const u8 *bssid = bss_conf->bssid; 420bd95573STzu-En Huang u32 sound_dim; 430bd95573STzu-En Huang u8 i; 440bd95573STzu-En Huang 450bd95573STzu-En Huang if (!(chip->band & RTW_BAND_5G)) 460bd95573STzu-En Huang return; 470bd95573STzu-En Huang 480bd95573STzu-En Huang rcu_read_lock(); 490bd95573STzu-En Huang 500bd95573STzu-En Huang sta = ieee80211_find_sta(vif, bssid); 510bd95573STzu-En Huang if (!sta) { 52*8a1e2fd8SMartin Blumenstingl rcu_read_unlock(); 53*8a1e2fd8SMartin Blumenstingl 540bd95573STzu-En Huang rtw_warn(rtwdev, "failed to find station entry for bss %pM\n", 550bd95573STzu-En Huang bssid); 56*8a1e2fd8SMartin Blumenstingl return; 570bd95573STzu-En Huang } 580bd95573STzu-En Huang 590bd95573STzu-En Huang ic_vht_cap = &hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap; 60046d2e7cSSriram R vht_cap = &sta->deflink.vht_cap; 610bd95573STzu-En Huang 62*8a1e2fd8SMartin Blumenstingl rcu_read_unlock(); 63*8a1e2fd8SMartin Blumenstingl 640bd95573STzu-En Huang if ((ic_vht_cap->cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && 650bd95573STzu-En Huang (vht_cap->cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { 660bd95573STzu-En Huang if (bfinfo->bfer_mu_cnt >= chip->bfer_mu_max_num) { 670bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "mu bfer number over limit\n"); 68*8a1e2fd8SMartin Blumenstingl return; 690bd95573STzu-En Huang } 700bd95573STzu-En Huang 710bd95573STzu-En Huang ether_addr_copy(bfee->mac_addr, bssid); 72aa7619a3STzu-En Huang bfee->role = RTW_BFEE_MU; 730bd95573STzu-En Huang bfee->p_aid = (bssid[5] << 1) | (bssid[4] >> 7); 74f276e20bSJohannes Berg bfee->aid = vif->cfg.aid; 750bd95573STzu-En Huang bfinfo->bfer_mu_cnt++; 760bd95573STzu-En Huang 7793ae973fSPing-Ke Shih rtw_chip_config_bfee(rtwdev, rtwvif, bfee, true); 780bd95573STzu-En Huang } else if ((ic_vht_cap->cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) && 790bd95573STzu-En Huang (vht_cap->cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { 800bd95573STzu-En Huang if (bfinfo->bfer_su_cnt >= chip->bfer_su_max_num) { 810bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "su bfer number over limit\n"); 82*8a1e2fd8SMartin Blumenstingl return; 830bd95573STzu-En Huang } 840bd95573STzu-En Huang 850bd95573STzu-En Huang sound_dim = vht_cap->cap & 860bd95573STzu-En Huang IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; 870bd95573STzu-En Huang sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; 880bd95573STzu-En Huang 890bd95573STzu-En Huang ether_addr_copy(bfee->mac_addr, bssid); 90aa7619a3STzu-En Huang bfee->role = RTW_BFEE_SU; 910bd95573STzu-En Huang bfee->sound_dim = (u8)sound_dim; 920bd95573STzu-En Huang bfee->g_id = 0; 930bd95573STzu-En Huang bfee->p_aid = (bssid[5] << 1) | (bssid[4] >> 7); 940bd95573STzu-En Huang bfinfo->bfer_su_cnt++; 950bd95573STzu-En Huang for (i = 0; i < chip->bfer_su_max_num; i++) { 960bd95573STzu-En Huang if (!test_bit(i, bfinfo->bfer_su_reg_maping)) { 970bd95573STzu-En Huang set_bit(i, bfinfo->bfer_su_reg_maping); 980bd95573STzu-En Huang bfee->su_reg_index = i; 990bd95573STzu-En Huang break; 1000bd95573STzu-En Huang } 1010bd95573STzu-En Huang } 1020bd95573STzu-En Huang 10393ae973fSPing-Ke Shih rtw_chip_config_bfee(rtwdev, rtwvif, bfee, true); 1040bd95573STzu-En Huang } 1050bd95573STzu-En Huang } 1060bd95573STzu-En Huang 1070bd95573STzu-En Huang void rtw_bf_init_bfer_entry_mu(struct rtw_dev *rtwdev, 1080bd95573STzu-En Huang struct mu_bfer_init_para *param) 1090bd95573STzu-En Huang { 1100bd95573STzu-En Huang u16 mu_bf_ctl = 0; 1110bd95573STzu-En Huang u8 *addr = param->bfer_address; 1120bd95573STzu-En Huang int i; 1130bd95573STzu-En Huang 1140bd95573STzu-En Huang for (i = 0; i < ETH_ALEN; i++) 1150bd95573STzu-En Huang rtw_write8(rtwdev, REG_ASSOCIATED_BFMER0_INFO + i, addr[i]); 1160bd95573STzu-En Huang rtw_write16(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 6, param->paid); 1170bd95573STzu-En Huang rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20, param->csi_para); 1180bd95573STzu-En Huang 1190bd95573STzu-En Huang mu_bf_ctl = rtw_read16(rtwdev, REG_WMAC_MU_BF_CTL) & 0xC000; 1200bd95573STzu-En Huang mu_bf_ctl |= param->my_aid | (param->csi_length_sel << 12); 1210bd95573STzu-En Huang rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, mu_bf_ctl); 1220bd95573STzu-En Huang } 1230bd95573STzu-En Huang 1240bd95573STzu-En Huang void rtw_bf_cfg_sounding(struct rtw_dev *rtwdev, struct rtw_vif *vif, 1250bd95573STzu-En Huang enum rtw_trx_desc_rate rate) 1260bd95573STzu-En Huang { 1270bd95573STzu-En Huang u32 psf_ctl = 0; 1280bd95573STzu-En Huang u8 csi_rsc = 0x1; 1290bd95573STzu-En Huang 1300bd95573STzu-En Huang psf_ctl = rtw_read32(rtwdev, REG_BBPSF_CTRL) | 1310bd95573STzu-En Huang BIT_WMAC_USE_NDPARATE | 1320bd95573STzu-En Huang (csi_rsc << 13); 1330bd95573STzu-En Huang 134a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 135a3fd1f9aSChin-Yen Lee RTW_SND_CTRL_SOUNDING); 1360bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL + 3, 0x26); 1370bd95573STzu-En Huang rtw_write8_clr(rtwdev, REG_RXFLTMAP1, BIT_RXFLTMAP1_BF_REPORT_POLL); 1380bd95573STzu-En Huang rtw_write8_clr(rtwdev, REG_RXFLTMAP4, BIT_RXFLTMAP4_BF_REPORT_POLL); 1390bd95573STzu-En Huang 1400bd95573STzu-En Huang if (vif->net_type == RTW_NET_AP_MODE) 1410bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, psf_ctl | BIT(12)); 1420bd95573STzu-En Huang else 1430bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, psf_ctl & ~BIT(12)); 1440bd95573STzu-En Huang } 1450bd95573STzu-En Huang 1460bd95573STzu-En Huang void rtw_bf_cfg_mu_bfee(struct rtw_dev *rtwdev, struct cfg_mumimo_para *param) 1470bd95573STzu-En Huang { 1480bd95573STzu-En Huang u8 mu_tbl_sel; 1490bd95573STzu-En Huang u8 mu_valid; 1500bd95573STzu-En Huang 1510bd95573STzu-En Huang mu_valid = rtw_read8(rtwdev, REG_MU_TX_CTL) & 1520bd95573STzu-En Huang ~BIT_MASK_R_MU_TABLE_VALID; 1530bd95573STzu-En Huang 1540bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL, 1550bd95573STzu-En Huang (mu_valid | BIT(0) | BIT(1)) & ~(BIT(7))); 1560bd95573STzu-En Huang 1570bd95573STzu-En Huang mu_tbl_sel = rtw_read8(rtwdev, REG_MU_TX_CTL + 1) & 0xF8; 1580bd95573STzu-En Huang 1590bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL + 1, mu_tbl_sel); 1600bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_GID_VLD, param->given_gid_tab[0]); 1610bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO, param->given_user_pos[0]); 1620bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO + 4, 1630bd95573STzu-En Huang param->given_user_pos[1]); 1640bd95573STzu-En Huang 1650bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL + 1, mu_tbl_sel | 1); 1660bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_GID_VLD, param->given_gid_tab[1]); 1670bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO, param->given_user_pos[2]); 1680bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO + 4, 1690bd95573STzu-En Huang param->given_user_pos[3]); 1700bd95573STzu-En Huang } 1710bd95573STzu-En Huang 1720bd95573STzu-En Huang void rtw_bf_del_bfer_entry_mu(struct rtw_dev *rtwdev) 1730bd95573STzu-En Huang { 1740bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO, 0); 1750bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 4, 0); 1760bd95573STzu-En Huang rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, 0); 1770bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL, 0); 1780bd95573STzu-En Huang } 1790bd95573STzu-En Huang 1800bd95573STzu-En Huang void rtw_bf_del_sounding(struct rtw_dev *rtwdev) 1810bd95573STzu-En Huang { 182a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 0); 1830bd95573STzu-En Huang } 1840bd95573STzu-En Huang 1850bd95573STzu-En Huang void rtw_bf_enable_bfee_su(struct rtw_dev *rtwdev, struct rtw_vif *vif, 1860bd95573STzu-En Huang struct rtw_bfee *bfee) 1870bd95573STzu-En Huang { 1885f4eab88STzu-En Huang u8 nc_index = hweight8(rtwdev->hal.antenna_rx) - 1; 1890bd95573STzu-En Huang u8 nr_index = bfee->sound_dim; 1900bd95573STzu-En Huang u8 grouping = 0, codebookinfo = 1, coefficientsize = 3; 1910bd95573STzu-En Huang u32 addr_bfer_info, addr_csi_rpt, csi_param; 1920bd95573STzu-En Huang u8 i; 1930bd95573STzu-En Huang 1940bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "config as an su bfee\n"); 1950bd95573STzu-En Huang 1960bd95573STzu-En Huang switch (bfee->su_reg_index) { 1970bd95573STzu-En Huang case 1: 1980bd95573STzu-En Huang addr_bfer_info = REG_ASSOCIATED_BFMER1_INFO; 1990bd95573STzu-En Huang addr_csi_rpt = REG_TX_CSI_RPT_PARAM_BW20 + 2; 2000bd95573STzu-En Huang break; 2010bd95573STzu-En Huang case 0: 2020bd95573STzu-En Huang default: 2030bd95573STzu-En Huang addr_bfer_info = REG_ASSOCIATED_BFMER0_INFO; 2040bd95573STzu-En Huang addr_csi_rpt = REG_TX_CSI_RPT_PARAM_BW20; 2050bd95573STzu-En Huang break; 2060bd95573STzu-En Huang } 2070bd95573STzu-En Huang 2080bd95573STzu-En Huang /* Sounding protocol control */ 209a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 210a3fd1f9aSChin-Yen Lee RTW_SND_CTRL_SOUNDING); 2110bd95573STzu-En Huang 2120bd95573STzu-En Huang /* MAC address/Partial AID of Beamformer */ 2130bd95573STzu-En Huang for (i = 0; i < ETH_ALEN; i++) 2140bd95573STzu-En Huang rtw_write8(rtwdev, addr_bfer_info + i, bfee->mac_addr[i]); 2150bd95573STzu-En Huang 2160bd95573STzu-En Huang csi_param = (u16)((coefficientsize << 10) | 2170bd95573STzu-En Huang (codebookinfo << 8) | 2180bd95573STzu-En Huang (grouping << 6) | 2190bd95573STzu-En Huang (nr_index << 3) | 2200bd95573STzu-En Huang nc_index); 2210bd95573STzu-En Huang rtw_write16(rtwdev, addr_csi_rpt, csi_param); 2220bd95573STzu-En Huang 2230bd95573STzu-En Huang /* ndp rx standby timer */ 2240bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL + 3, RTW_NDP_RX_STANDBY_TIME); 2250bd95573STzu-En Huang } 226449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_enable_bfee_su); 2270bd95573STzu-En Huang 2280bd95573STzu-En Huang /* nc index: 1 2T2R 0 1T1R 2290bd95573STzu-En Huang * nr index: 1 use Nsts 0 use reg setting 2300bd95573STzu-En Huang * codebookinfo: 1 802.11ac 3 802.11n 2310bd95573STzu-En Huang */ 2320bd95573STzu-En Huang void rtw_bf_enable_bfee_mu(struct rtw_dev *rtwdev, struct rtw_vif *vif, 2330bd95573STzu-En Huang struct rtw_bfee *bfee) 2340bd95573STzu-En Huang { 2350bd95573STzu-En Huang struct rtw_bf_info *bf_info = &rtwdev->bf_info; 2360bd95573STzu-En Huang struct mu_bfer_init_para param; 2375f4eab88STzu-En Huang u8 nc_index = hweight8(rtwdev->hal.antenna_rx) - 1; 2385f4eab88STzu-En Huang u8 nr_index = 1; 2390bd95573STzu-En Huang u8 grouping = 0, codebookinfo = 1, coefficientsize = 0; 2400bd95573STzu-En Huang u32 csi_param; 2410bd95573STzu-En Huang 2420bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "config as an mu bfee\n"); 2430bd95573STzu-En Huang 2440bd95573STzu-En Huang csi_param = (u16)((coefficientsize << 10) | 2450bd95573STzu-En Huang (codebookinfo << 8) | 2460bd95573STzu-En Huang (grouping << 6) | 2470bd95573STzu-En Huang (nr_index << 3) | 2480bd95573STzu-En Huang nc_index); 2490bd95573STzu-En Huang 2500bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "nc=%d nr=%d group=%d codebookinfo=%d coefficientsize=%d\n", 2510bd95573STzu-En Huang nc_index, nr_index, grouping, codebookinfo, 2520bd95573STzu-En Huang coefficientsize); 2530bd95573STzu-En Huang 2540bd95573STzu-En Huang param.paid = bfee->p_aid; 2550bd95573STzu-En Huang param.csi_para = csi_param; 2560bd95573STzu-En Huang param.my_aid = bfee->aid & 0xfff; 2570bd95573STzu-En Huang param.csi_length_sel = HAL_CSI_SEG_4K; 2580bd95573STzu-En Huang ether_addr_copy(param.bfer_address, bfee->mac_addr); 2590bd95573STzu-En Huang 2600bd95573STzu-En Huang rtw_bf_init_bfer_entry_mu(rtwdev, ¶m); 2610bd95573STzu-En Huang 2620bd95573STzu-En Huang bf_info->cur_csi_rpt_rate = DESC_RATE6M; 2630bd95573STzu-En Huang rtw_bf_cfg_sounding(rtwdev, vif, DESC_RATE6M); 2640bd95573STzu-En Huang 2650bd95573STzu-En Huang /* accept action_no_ack */ 2660bd95573STzu-En Huang rtw_write16_set(rtwdev, REG_RXFLTMAP0, BIT_RXFLTMAP0_ACTIONNOACK); 2670bd95573STzu-En Huang 2680bd95573STzu-En Huang /* accept NDPA and BF report poll */ 2690bd95573STzu-En Huang rtw_write16_set(rtwdev, REG_RXFLTMAP1, BIT_RXFLTMAP1_BF); 2700bd95573STzu-En Huang } 271449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_enable_bfee_mu); 2720bd95573STzu-En Huang 2730bd95573STzu-En Huang void rtw_bf_remove_bfee_su(struct rtw_dev *rtwdev, 2740bd95573STzu-En Huang struct rtw_bfee *bfee) 2750bd95573STzu-En Huang { 2760bd95573STzu-En Huang struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 2770bd95573STzu-En Huang 2780bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "remove as a su bfee\n"); 279a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 280a3fd1f9aSChin-Yen Lee RTW_SND_CTRL_REMOVE); 2810bd95573STzu-En Huang 2820bd95573STzu-En Huang switch (bfee->su_reg_index) { 2830bd95573STzu-En Huang case 0: 2840bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO, 0); 2850bd95573STzu-En Huang rtw_write16(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 4, 0); 2860bd95573STzu-En Huang rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20, 0); 2870bd95573STzu-En Huang break; 2880bd95573STzu-En Huang case 1: 2890bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER1_INFO, 0); 2900bd95573STzu-En Huang rtw_write16(rtwdev, REG_ASSOCIATED_BFMER1_INFO + 4, 0); 2910bd95573STzu-En Huang rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20 + 2, 0); 2920bd95573STzu-En Huang break; 2930bd95573STzu-En Huang } 2940bd95573STzu-En Huang 2950bd95573STzu-En Huang clear_bit(bfee->su_reg_index, bfinfo->bfer_su_reg_maping); 2960bd95573STzu-En Huang bfee->su_reg_index = 0xFF; 2970bd95573STzu-En Huang } 298449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_remove_bfee_su); 2990bd95573STzu-En Huang 3000bd95573STzu-En Huang void rtw_bf_remove_bfee_mu(struct rtw_dev *rtwdev, 3010bd95573STzu-En Huang struct rtw_bfee *bfee) 3020bd95573STzu-En Huang { 3030bd95573STzu-En Huang struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 3040bd95573STzu-En Huang 305a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 306a3fd1f9aSChin-Yen Lee RTW_SND_CTRL_REMOVE); 3070bd95573STzu-En Huang 3080bd95573STzu-En Huang rtw_bf_del_bfer_entry_mu(rtwdev); 3090bd95573STzu-En Huang 3100bd95573STzu-En Huang if (bfinfo->bfer_su_cnt == 0 && bfinfo->bfer_mu_cnt == 0) 3110bd95573STzu-En Huang rtw_bf_del_sounding(rtwdev); 3120bd95573STzu-En Huang } 313449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_remove_bfee_mu); 3140bd95573STzu-En Huang 3150bd95573STzu-En Huang void rtw_bf_set_gid_table(struct rtw_dev *rtwdev, struct ieee80211_vif *vif, 3160bd95573STzu-En Huang struct ieee80211_bss_conf *conf) 3170bd95573STzu-En Huang { 3180bd95573STzu-En Huang struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 3190bd95573STzu-En Huang struct rtw_bfee *bfee = &rtwvif->bfee; 3200bd95573STzu-En Huang struct cfg_mumimo_para param; 3210bd95573STzu-En Huang 3220bd95573STzu-En Huang if (bfee->role != RTW_BFEE_MU) { 3230bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "this vif is not mu bfee\n"); 3240bd95573STzu-En Huang return; 3250bd95573STzu-En Huang } 3260bd95573STzu-En Huang 3270bd95573STzu-En Huang param.grouping_bitmap = 0; 3280bd95573STzu-En Huang param.mu_tx_en = 0; 3290bd95573STzu-En Huang memset(param.sounding_sts, 0, 6); 3300bd95573STzu-En Huang memcpy(param.given_gid_tab, conf->mu_group.membership, 8); 3310bd95573STzu-En Huang memcpy(param.given_user_pos, conf->mu_group.position, 16); 3320bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "STA0: gid_valid=0x%x, user_position_l=0x%x, user_position_h=0x%x\n", 3330bd95573STzu-En Huang param.given_gid_tab[0], param.given_user_pos[0], 3340bd95573STzu-En Huang param.given_user_pos[1]); 3350bd95573STzu-En Huang 3360bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "STA1: gid_valid=0x%x, user_position_l=0x%x, user_position_h=0x%x\n", 3370bd95573STzu-En Huang param.given_gid_tab[1], param.given_user_pos[2], 3380bd95573STzu-En Huang param.given_user_pos[3]); 3390bd95573STzu-En Huang 3400bd95573STzu-En Huang rtw_bf_cfg_mu_bfee(rtwdev, ¶m); 3410bd95573STzu-En Huang } 342449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_set_gid_table); 3430bd95573STzu-En Huang 3440bd95573STzu-En Huang void rtw_bf_phy_init(struct rtw_dev *rtwdev) 3450bd95573STzu-En Huang { 3460bd95573STzu-En Huang u8 tmp8; 3470bd95573STzu-En Huang u32 tmp32; 3480bd95573STzu-En Huang u8 retry_limit = 0xA; 3490bd95573STzu-En Huang u8 ndpa_rate = 0x10; 3500bd95573STzu-En Huang u8 ack_policy = 3; 3510bd95573STzu-En Huang 3520bd95573STzu-En Huang tmp32 = rtw_read32(rtwdev, REG_MU_TX_CTL); 3530bd95573STzu-En Huang /* Enable P1 aggr new packet according to P0 transfer time */ 3540bd95573STzu-En Huang tmp32 |= BIT_MU_P1_WAIT_STATE_EN; 3550bd95573STzu-En Huang /* MU Retry Limit */ 3560bd95573STzu-En Huang tmp32 &= ~BIT_MASK_R_MU_RL; 3570bd95573STzu-En Huang tmp32 |= (retry_limit << BIT_SHIFT_R_MU_RL) & BIT_MASK_R_MU_RL; 3580bd95573STzu-En Huang /* Disable Tx MU-MIMO until sounding done */ 3590bd95573STzu-En Huang tmp32 &= ~BIT_EN_MU_MIMO; 3600bd95573STzu-En Huang /* Clear validity of MU STAs */ 3610bd95573STzu-En Huang tmp32 &= ~BIT_MASK_R_MU_TABLE_VALID; 3620bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_TX_CTL, tmp32); 3630bd95573STzu-En Huang 3640bd95573STzu-En Huang /* MU-MIMO Option as default value */ 3650bd95573STzu-En Huang tmp8 = ack_policy << BIT_SHIFT_WMAC_TXMU_ACKPOLICY; 3660bd95573STzu-En Huang tmp8 |= BIT_WMAC_TXMU_ACKPOLICY_EN; 3670bd95573STzu-En Huang rtw_write8(rtwdev, REG_WMAC_MU_BF_OPTION, tmp8); 3680bd95573STzu-En Huang 3690bd95573STzu-En Huang /* MU-MIMO Control as default value */ 3700bd95573STzu-En Huang rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, 0); 3710bd95573STzu-En Huang /* Set MU NDPA rate & BW source */ 3720bd95573STzu-En Huang rtw_write32_set(rtwdev, REG_TXBF_CTRL, BIT_USE_NDPA_PARAMETER); 3730bd95573STzu-En Huang /* Set NDPA Rate */ 3740bd95573STzu-En Huang rtw_write8(rtwdev, REG_NDPA_OPT_CTRL, ndpa_rate); 3750bd95573STzu-En Huang 3760bd95573STzu-En Huang rtw_write32_mask(rtwdev, REG_BBPSF_CTRL, BIT_MASK_CSI_RATE, 3770bd95573STzu-En Huang DESC_RATE6M); 3780bd95573STzu-En Huang } 379449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_phy_init); 3800bd95573STzu-En Huang 3810bd95573STzu-En Huang void rtw_bf_cfg_csi_rate(struct rtw_dev *rtwdev, u8 rssi, u8 cur_rate, 3820bd95573STzu-En Huang u8 fixrate_en, u8 *new_rate) 3830bd95573STzu-En Huang { 3840bd95573STzu-En Huang u32 csi_cfg; 3850bd95573STzu-En Huang u16 cur_rrsr; 3860bd95573STzu-En Huang 3870bd95573STzu-En Huang csi_cfg = rtw_read32(rtwdev, REG_BBPSF_CTRL) & ~BIT_MASK_CSI_RATE; 3880bd95573STzu-En Huang cur_rrsr = rtw_read16(rtwdev, REG_RRSR); 3890bd95573STzu-En Huang 3900bd95573STzu-En Huang if (rssi >= 40) { 3910bd95573STzu-En Huang if (cur_rate != DESC_RATE54M) { 3920bd95573STzu-En Huang cur_rrsr |= BIT(DESC_RATE54M); 3930bd95573STzu-En Huang csi_cfg |= (DESC_RATE54M & BIT_MASK_CSI_RATE_VAL) << 3940bd95573STzu-En Huang BIT_SHIFT_CSI_RATE; 3950bd95573STzu-En Huang rtw_write16(rtwdev, REG_RRSR, cur_rrsr); 3960bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, csi_cfg); 3970bd95573STzu-En Huang } 3980bd95573STzu-En Huang *new_rate = DESC_RATE54M; 3990bd95573STzu-En Huang } else { 4000bd95573STzu-En Huang if (cur_rate != DESC_RATE24M) { 4010bd95573STzu-En Huang cur_rrsr &= ~BIT(DESC_RATE54M); 4020bd95573STzu-En Huang csi_cfg |= (DESC_RATE54M & BIT_MASK_CSI_RATE_VAL) << 4030bd95573STzu-En Huang BIT_SHIFT_CSI_RATE; 4040bd95573STzu-En Huang rtw_write16(rtwdev, REG_RRSR, cur_rrsr); 4050bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, csi_cfg); 4060bd95573STzu-En Huang } 4070bd95573STzu-En Huang *new_rate = DESC_RATE24M; 4080bd95573STzu-En Huang } 4090bd95573STzu-En Huang } 410449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_cfg_csi_rate); 411