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 { 330bd95573STzu-En Huang struct ieee80211_hw *hw = rtwdev->hw; 340bd95573STzu-En Huang struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 350bd95573STzu-En Huang struct rtw_bfee *bfee = &rtwvif->bfee; 360bd95573STzu-En Huang struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 370bd95573STzu-En Huang struct rtw_chip_info *chip = rtwdev->chip; 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) { 520bd95573STzu-En Huang rtw_warn(rtwdev, "failed to find station entry for bss %pM\n", 530bd95573STzu-En Huang bssid); 540bd95573STzu-En Huang goto out_unlock; 550bd95573STzu-En Huang } 560bd95573STzu-En Huang 570bd95573STzu-En Huang ic_vht_cap = &hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap; 58*046d2e7cSSriram R vht_cap = &sta->deflink.vht_cap; 590bd95573STzu-En Huang 600bd95573STzu-En Huang if ((ic_vht_cap->cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && 610bd95573STzu-En Huang (vht_cap->cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)) { 620bd95573STzu-En Huang if (bfinfo->bfer_mu_cnt >= chip->bfer_mu_max_num) { 630bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "mu bfer number over limit\n"); 640bd95573STzu-En Huang goto out_unlock; 650bd95573STzu-En Huang } 660bd95573STzu-En Huang 670bd95573STzu-En Huang ether_addr_copy(bfee->mac_addr, bssid); 68aa7619a3STzu-En Huang bfee->role = RTW_BFEE_MU; 690bd95573STzu-En Huang bfee->p_aid = (bssid[5] << 1) | (bssid[4] >> 7); 700bd95573STzu-En Huang bfee->aid = bss_conf->aid; 710bd95573STzu-En Huang bfinfo->bfer_mu_cnt++; 720bd95573STzu-En Huang 7393ae973fSPing-Ke Shih rtw_chip_config_bfee(rtwdev, rtwvif, bfee, true); 740bd95573STzu-En Huang } else if ((ic_vht_cap->cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) && 750bd95573STzu-En Huang (vht_cap->cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) { 760bd95573STzu-En Huang if (bfinfo->bfer_su_cnt >= chip->bfer_su_max_num) { 770bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "su bfer number over limit\n"); 780bd95573STzu-En Huang goto out_unlock; 790bd95573STzu-En Huang } 800bd95573STzu-En Huang 810bd95573STzu-En Huang sound_dim = vht_cap->cap & 820bd95573STzu-En Huang IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK; 830bd95573STzu-En Huang sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT; 840bd95573STzu-En Huang 850bd95573STzu-En Huang ether_addr_copy(bfee->mac_addr, bssid); 86aa7619a3STzu-En Huang bfee->role = RTW_BFEE_SU; 870bd95573STzu-En Huang bfee->sound_dim = (u8)sound_dim; 880bd95573STzu-En Huang bfee->g_id = 0; 890bd95573STzu-En Huang bfee->p_aid = (bssid[5] << 1) | (bssid[4] >> 7); 900bd95573STzu-En Huang bfinfo->bfer_su_cnt++; 910bd95573STzu-En Huang for (i = 0; i < chip->bfer_su_max_num; i++) { 920bd95573STzu-En Huang if (!test_bit(i, bfinfo->bfer_su_reg_maping)) { 930bd95573STzu-En Huang set_bit(i, bfinfo->bfer_su_reg_maping); 940bd95573STzu-En Huang bfee->su_reg_index = i; 950bd95573STzu-En Huang break; 960bd95573STzu-En Huang } 970bd95573STzu-En Huang } 980bd95573STzu-En Huang 9993ae973fSPing-Ke Shih rtw_chip_config_bfee(rtwdev, rtwvif, bfee, true); 1000bd95573STzu-En Huang } 1010bd95573STzu-En Huang 1020bd95573STzu-En Huang out_unlock: 1030bd95573STzu-En Huang rcu_read_unlock(); 1040bd95573STzu-En Huang } 1050bd95573STzu-En Huang 1060bd95573STzu-En Huang void rtw_bf_init_bfer_entry_mu(struct rtw_dev *rtwdev, 1070bd95573STzu-En Huang struct mu_bfer_init_para *param) 1080bd95573STzu-En Huang { 1090bd95573STzu-En Huang u16 mu_bf_ctl = 0; 1100bd95573STzu-En Huang u8 *addr = param->bfer_address; 1110bd95573STzu-En Huang int i; 1120bd95573STzu-En Huang 1130bd95573STzu-En Huang for (i = 0; i < ETH_ALEN; i++) 1140bd95573STzu-En Huang rtw_write8(rtwdev, REG_ASSOCIATED_BFMER0_INFO + i, addr[i]); 1150bd95573STzu-En Huang rtw_write16(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 6, param->paid); 1160bd95573STzu-En Huang rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20, param->csi_para); 1170bd95573STzu-En Huang 1180bd95573STzu-En Huang mu_bf_ctl = rtw_read16(rtwdev, REG_WMAC_MU_BF_CTL) & 0xC000; 1190bd95573STzu-En Huang mu_bf_ctl |= param->my_aid | (param->csi_length_sel << 12); 1200bd95573STzu-En Huang rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, mu_bf_ctl); 1210bd95573STzu-En Huang } 1220bd95573STzu-En Huang 1230bd95573STzu-En Huang void rtw_bf_cfg_sounding(struct rtw_dev *rtwdev, struct rtw_vif *vif, 1240bd95573STzu-En Huang enum rtw_trx_desc_rate rate) 1250bd95573STzu-En Huang { 1260bd95573STzu-En Huang u32 psf_ctl = 0; 1270bd95573STzu-En Huang u8 csi_rsc = 0x1; 1280bd95573STzu-En Huang 1290bd95573STzu-En Huang psf_ctl = rtw_read32(rtwdev, REG_BBPSF_CTRL) | 1300bd95573STzu-En Huang BIT_WMAC_USE_NDPARATE | 1310bd95573STzu-En Huang (csi_rsc << 13); 1320bd95573STzu-En Huang 133a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 134a3fd1f9aSChin-Yen Lee RTW_SND_CTRL_SOUNDING); 1350bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL + 3, 0x26); 1360bd95573STzu-En Huang rtw_write8_clr(rtwdev, REG_RXFLTMAP1, BIT_RXFLTMAP1_BF_REPORT_POLL); 1370bd95573STzu-En Huang rtw_write8_clr(rtwdev, REG_RXFLTMAP4, BIT_RXFLTMAP4_BF_REPORT_POLL); 1380bd95573STzu-En Huang 1390bd95573STzu-En Huang if (vif->net_type == RTW_NET_AP_MODE) 1400bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, psf_ctl | BIT(12)); 1410bd95573STzu-En Huang else 1420bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, psf_ctl & ~BIT(12)); 1430bd95573STzu-En Huang } 1440bd95573STzu-En Huang 1450bd95573STzu-En Huang void rtw_bf_cfg_mu_bfee(struct rtw_dev *rtwdev, struct cfg_mumimo_para *param) 1460bd95573STzu-En Huang { 1470bd95573STzu-En Huang u8 mu_tbl_sel; 1480bd95573STzu-En Huang u8 mu_valid; 1490bd95573STzu-En Huang 1500bd95573STzu-En Huang mu_valid = rtw_read8(rtwdev, REG_MU_TX_CTL) & 1510bd95573STzu-En Huang ~BIT_MASK_R_MU_TABLE_VALID; 1520bd95573STzu-En Huang 1530bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL, 1540bd95573STzu-En Huang (mu_valid | BIT(0) | BIT(1)) & ~(BIT(7))); 1550bd95573STzu-En Huang 1560bd95573STzu-En Huang mu_tbl_sel = rtw_read8(rtwdev, REG_MU_TX_CTL + 1) & 0xF8; 1570bd95573STzu-En Huang 1580bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL + 1, mu_tbl_sel); 1590bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_GID_VLD, param->given_gid_tab[0]); 1600bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO, param->given_user_pos[0]); 1610bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO + 4, 1620bd95573STzu-En Huang param->given_user_pos[1]); 1630bd95573STzu-En Huang 1640bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL + 1, mu_tbl_sel | 1); 1650bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_GID_VLD, param->given_gid_tab[1]); 1660bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO, param->given_user_pos[2]); 1670bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO + 4, 1680bd95573STzu-En Huang param->given_user_pos[3]); 1690bd95573STzu-En Huang } 1700bd95573STzu-En Huang 1710bd95573STzu-En Huang void rtw_bf_del_bfer_entry_mu(struct rtw_dev *rtwdev) 1720bd95573STzu-En Huang { 1730bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO, 0); 1740bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 4, 0); 1750bd95573STzu-En Huang rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, 0); 1760bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL, 0); 1770bd95573STzu-En Huang } 1780bd95573STzu-En Huang 1790bd95573STzu-En Huang void rtw_bf_del_sounding(struct rtw_dev *rtwdev) 1800bd95573STzu-En Huang { 181a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 0); 1820bd95573STzu-En Huang } 1830bd95573STzu-En Huang 1840bd95573STzu-En Huang void rtw_bf_enable_bfee_su(struct rtw_dev *rtwdev, struct rtw_vif *vif, 1850bd95573STzu-En Huang struct rtw_bfee *bfee) 1860bd95573STzu-En Huang { 1875f4eab88STzu-En Huang u8 nc_index = hweight8(rtwdev->hal.antenna_rx) - 1; 1880bd95573STzu-En Huang u8 nr_index = bfee->sound_dim; 1890bd95573STzu-En Huang u8 grouping = 0, codebookinfo = 1, coefficientsize = 3; 1900bd95573STzu-En Huang u32 addr_bfer_info, addr_csi_rpt, csi_param; 1910bd95573STzu-En Huang u8 i; 1920bd95573STzu-En Huang 1930bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "config as an su bfee\n"); 1940bd95573STzu-En Huang 1950bd95573STzu-En Huang switch (bfee->su_reg_index) { 1960bd95573STzu-En Huang case 1: 1970bd95573STzu-En Huang addr_bfer_info = REG_ASSOCIATED_BFMER1_INFO; 1980bd95573STzu-En Huang addr_csi_rpt = REG_TX_CSI_RPT_PARAM_BW20 + 2; 1990bd95573STzu-En Huang break; 2000bd95573STzu-En Huang case 0: 2010bd95573STzu-En Huang default: 2020bd95573STzu-En Huang addr_bfer_info = REG_ASSOCIATED_BFMER0_INFO; 2030bd95573STzu-En Huang addr_csi_rpt = REG_TX_CSI_RPT_PARAM_BW20; 2040bd95573STzu-En Huang break; 2050bd95573STzu-En Huang } 2060bd95573STzu-En Huang 2070bd95573STzu-En Huang /* Sounding protocol control */ 208a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 209a3fd1f9aSChin-Yen Lee RTW_SND_CTRL_SOUNDING); 2100bd95573STzu-En Huang 2110bd95573STzu-En Huang /* MAC address/Partial AID of Beamformer */ 2120bd95573STzu-En Huang for (i = 0; i < ETH_ALEN; i++) 2130bd95573STzu-En Huang rtw_write8(rtwdev, addr_bfer_info + i, bfee->mac_addr[i]); 2140bd95573STzu-En Huang 2150bd95573STzu-En Huang csi_param = (u16)((coefficientsize << 10) | 2160bd95573STzu-En Huang (codebookinfo << 8) | 2170bd95573STzu-En Huang (grouping << 6) | 2180bd95573STzu-En Huang (nr_index << 3) | 2190bd95573STzu-En Huang nc_index); 2200bd95573STzu-En Huang rtw_write16(rtwdev, addr_csi_rpt, csi_param); 2210bd95573STzu-En Huang 2220bd95573STzu-En Huang /* ndp rx standby timer */ 2230bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL + 3, RTW_NDP_RX_STANDBY_TIME); 2240bd95573STzu-En Huang } 225449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_enable_bfee_su); 2260bd95573STzu-En Huang 2270bd95573STzu-En Huang /* nc index: 1 2T2R 0 1T1R 2280bd95573STzu-En Huang * nr index: 1 use Nsts 0 use reg setting 2290bd95573STzu-En Huang * codebookinfo: 1 802.11ac 3 802.11n 2300bd95573STzu-En Huang */ 2310bd95573STzu-En Huang void rtw_bf_enable_bfee_mu(struct rtw_dev *rtwdev, struct rtw_vif *vif, 2320bd95573STzu-En Huang struct rtw_bfee *bfee) 2330bd95573STzu-En Huang { 2340bd95573STzu-En Huang struct rtw_bf_info *bf_info = &rtwdev->bf_info; 2350bd95573STzu-En Huang struct mu_bfer_init_para param; 2365f4eab88STzu-En Huang u8 nc_index = hweight8(rtwdev->hal.antenna_rx) - 1; 2375f4eab88STzu-En Huang u8 nr_index = 1; 2380bd95573STzu-En Huang u8 grouping = 0, codebookinfo = 1, coefficientsize = 0; 2390bd95573STzu-En Huang u32 csi_param; 2400bd95573STzu-En Huang 2410bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "config as an mu bfee\n"); 2420bd95573STzu-En Huang 2430bd95573STzu-En Huang csi_param = (u16)((coefficientsize << 10) | 2440bd95573STzu-En Huang (codebookinfo << 8) | 2450bd95573STzu-En Huang (grouping << 6) | 2460bd95573STzu-En Huang (nr_index << 3) | 2470bd95573STzu-En Huang nc_index); 2480bd95573STzu-En Huang 2490bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "nc=%d nr=%d group=%d codebookinfo=%d coefficientsize=%d\n", 2500bd95573STzu-En Huang nc_index, nr_index, grouping, codebookinfo, 2510bd95573STzu-En Huang coefficientsize); 2520bd95573STzu-En Huang 2530bd95573STzu-En Huang param.paid = bfee->p_aid; 2540bd95573STzu-En Huang param.csi_para = csi_param; 2550bd95573STzu-En Huang param.my_aid = bfee->aid & 0xfff; 2560bd95573STzu-En Huang param.csi_length_sel = HAL_CSI_SEG_4K; 2570bd95573STzu-En Huang ether_addr_copy(param.bfer_address, bfee->mac_addr); 2580bd95573STzu-En Huang 2590bd95573STzu-En Huang rtw_bf_init_bfer_entry_mu(rtwdev, ¶m); 2600bd95573STzu-En Huang 2610bd95573STzu-En Huang bf_info->cur_csi_rpt_rate = DESC_RATE6M; 2620bd95573STzu-En Huang rtw_bf_cfg_sounding(rtwdev, vif, DESC_RATE6M); 2630bd95573STzu-En Huang 2640bd95573STzu-En Huang /* accept action_no_ack */ 2650bd95573STzu-En Huang rtw_write16_set(rtwdev, REG_RXFLTMAP0, BIT_RXFLTMAP0_ACTIONNOACK); 2660bd95573STzu-En Huang 2670bd95573STzu-En Huang /* accept NDPA and BF report poll */ 2680bd95573STzu-En Huang rtw_write16_set(rtwdev, REG_RXFLTMAP1, BIT_RXFLTMAP1_BF); 2690bd95573STzu-En Huang } 270449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_enable_bfee_mu); 2710bd95573STzu-En Huang 2720bd95573STzu-En Huang void rtw_bf_remove_bfee_su(struct rtw_dev *rtwdev, 2730bd95573STzu-En Huang struct rtw_bfee *bfee) 2740bd95573STzu-En Huang { 2750bd95573STzu-En Huang struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 2760bd95573STzu-En Huang 2770bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "remove as a su bfee\n"); 278a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 279a3fd1f9aSChin-Yen Lee RTW_SND_CTRL_REMOVE); 2800bd95573STzu-En Huang 2810bd95573STzu-En Huang switch (bfee->su_reg_index) { 2820bd95573STzu-En Huang case 0: 2830bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO, 0); 2840bd95573STzu-En Huang rtw_write16(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 4, 0); 2850bd95573STzu-En Huang rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20, 0); 2860bd95573STzu-En Huang break; 2870bd95573STzu-En Huang case 1: 2880bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER1_INFO, 0); 2890bd95573STzu-En Huang rtw_write16(rtwdev, REG_ASSOCIATED_BFMER1_INFO + 4, 0); 2900bd95573STzu-En Huang rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20 + 2, 0); 2910bd95573STzu-En Huang break; 2920bd95573STzu-En Huang } 2930bd95573STzu-En Huang 2940bd95573STzu-En Huang clear_bit(bfee->su_reg_index, bfinfo->bfer_su_reg_maping); 2950bd95573STzu-En Huang bfee->su_reg_index = 0xFF; 2960bd95573STzu-En Huang } 297449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_remove_bfee_su); 2980bd95573STzu-En Huang 2990bd95573STzu-En Huang void rtw_bf_remove_bfee_mu(struct rtw_dev *rtwdev, 3000bd95573STzu-En Huang struct rtw_bfee *bfee) 3010bd95573STzu-En Huang { 3020bd95573STzu-En Huang struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 3030bd95573STzu-En Huang 304a3fd1f9aSChin-Yen Lee rtw_write8_mask(rtwdev, REG_SND_PTCL_CTRL, BIT_MASK_BEAMFORM, 305a3fd1f9aSChin-Yen Lee RTW_SND_CTRL_REMOVE); 3060bd95573STzu-En Huang 3070bd95573STzu-En Huang rtw_bf_del_bfer_entry_mu(rtwdev); 3080bd95573STzu-En Huang 3090bd95573STzu-En Huang if (bfinfo->bfer_su_cnt == 0 && bfinfo->bfer_mu_cnt == 0) 3100bd95573STzu-En Huang rtw_bf_del_sounding(rtwdev); 3110bd95573STzu-En Huang } 312449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_remove_bfee_mu); 3130bd95573STzu-En Huang 3140bd95573STzu-En Huang void rtw_bf_set_gid_table(struct rtw_dev *rtwdev, struct ieee80211_vif *vif, 3150bd95573STzu-En Huang struct ieee80211_bss_conf *conf) 3160bd95573STzu-En Huang { 3170bd95573STzu-En Huang struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 3180bd95573STzu-En Huang struct rtw_bfee *bfee = &rtwvif->bfee; 3190bd95573STzu-En Huang struct cfg_mumimo_para param; 3200bd95573STzu-En Huang 3210bd95573STzu-En Huang if (bfee->role != RTW_BFEE_MU) { 3220bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "this vif is not mu bfee\n"); 3230bd95573STzu-En Huang return; 3240bd95573STzu-En Huang } 3250bd95573STzu-En Huang 3260bd95573STzu-En Huang param.grouping_bitmap = 0; 3270bd95573STzu-En Huang param.mu_tx_en = 0; 3280bd95573STzu-En Huang memset(param.sounding_sts, 0, 6); 3290bd95573STzu-En Huang memcpy(param.given_gid_tab, conf->mu_group.membership, 8); 3300bd95573STzu-En Huang memcpy(param.given_user_pos, conf->mu_group.position, 16); 3310bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "STA0: gid_valid=0x%x, user_position_l=0x%x, user_position_h=0x%x\n", 3320bd95573STzu-En Huang param.given_gid_tab[0], param.given_user_pos[0], 3330bd95573STzu-En Huang param.given_user_pos[1]); 3340bd95573STzu-En Huang 3350bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "STA1: gid_valid=0x%x, user_position_l=0x%x, user_position_h=0x%x\n", 3360bd95573STzu-En Huang param.given_gid_tab[1], param.given_user_pos[2], 3370bd95573STzu-En Huang param.given_user_pos[3]); 3380bd95573STzu-En Huang 3390bd95573STzu-En Huang rtw_bf_cfg_mu_bfee(rtwdev, ¶m); 3400bd95573STzu-En Huang } 341449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_set_gid_table); 3420bd95573STzu-En Huang 3430bd95573STzu-En Huang void rtw_bf_phy_init(struct rtw_dev *rtwdev) 3440bd95573STzu-En Huang { 3450bd95573STzu-En Huang u8 tmp8; 3460bd95573STzu-En Huang u32 tmp32; 3470bd95573STzu-En Huang u8 retry_limit = 0xA; 3480bd95573STzu-En Huang u8 ndpa_rate = 0x10; 3490bd95573STzu-En Huang u8 ack_policy = 3; 3500bd95573STzu-En Huang 3510bd95573STzu-En Huang tmp32 = rtw_read32(rtwdev, REG_MU_TX_CTL); 3520bd95573STzu-En Huang /* Enable P1 aggr new packet according to P0 transfer time */ 3530bd95573STzu-En Huang tmp32 |= BIT_MU_P1_WAIT_STATE_EN; 3540bd95573STzu-En Huang /* MU Retry Limit */ 3550bd95573STzu-En Huang tmp32 &= ~BIT_MASK_R_MU_RL; 3560bd95573STzu-En Huang tmp32 |= (retry_limit << BIT_SHIFT_R_MU_RL) & BIT_MASK_R_MU_RL; 3570bd95573STzu-En Huang /* Disable Tx MU-MIMO until sounding done */ 3580bd95573STzu-En Huang tmp32 &= ~BIT_EN_MU_MIMO; 3590bd95573STzu-En Huang /* Clear validity of MU STAs */ 3600bd95573STzu-En Huang tmp32 &= ~BIT_MASK_R_MU_TABLE_VALID; 3610bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_TX_CTL, tmp32); 3620bd95573STzu-En Huang 3630bd95573STzu-En Huang /* MU-MIMO Option as default value */ 3640bd95573STzu-En Huang tmp8 = ack_policy << BIT_SHIFT_WMAC_TXMU_ACKPOLICY; 3650bd95573STzu-En Huang tmp8 |= BIT_WMAC_TXMU_ACKPOLICY_EN; 3660bd95573STzu-En Huang rtw_write8(rtwdev, REG_WMAC_MU_BF_OPTION, tmp8); 3670bd95573STzu-En Huang 3680bd95573STzu-En Huang /* MU-MIMO Control as default value */ 3690bd95573STzu-En Huang rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, 0); 3700bd95573STzu-En Huang /* Set MU NDPA rate & BW source */ 3710bd95573STzu-En Huang rtw_write32_set(rtwdev, REG_TXBF_CTRL, BIT_USE_NDPA_PARAMETER); 3720bd95573STzu-En Huang /* Set NDPA Rate */ 3730bd95573STzu-En Huang rtw_write8(rtwdev, REG_NDPA_OPT_CTRL, ndpa_rate); 3740bd95573STzu-En Huang 3750bd95573STzu-En Huang rtw_write32_mask(rtwdev, REG_BBPSF_CTRL, BIT_MASK_CSI_RATE, 3760bd95573STzu-En Huang DESC_RATE6M); 3770bd95573STzu-En Huang } 378449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_phy_init); 3790bd95573STzu-En Huang 3800bd95573STzu-En Huang void rtw_bf_cfg_csi_rate(struct rtw_dev *rtwdev, u8 rssi, u8 cur_rate, 3810bd95573STzu-En Huang u8 fixrate_en, u8 *new_rate) 3820bd95573STzu-En Huang { 3830bd95573STzu-En Huang u32 csi_cfg; 3840bd95573STzu-En Huang u16 cur_rrsr; 3850bd95573STzu-En Huang 3860bd95573STzu-En Huang csi_cfg = rtw_read32(rtwdev, REG_BBPSF_CTRL) & ~BIT_MASK_CSI_RATE; 3870bd95573STzu-En Huang cur_rrsr = rtw_read16(rtwdev, REG_RRSR); 3880bd95573STzu-En Huang 3890bd95573STzu-En Huang if (rssi >= 40) { 3900bd95573STzu-En Huang if (cur_rate != DESC_RATE54M) { 3910bd95573STzu-En Huang cur_rrsr |= BIT(DESC_RATE54M); 3920bd95573STzu-En Huang csi_cfg |= (DESC_RATE54M & BIT_MASK_CSI_RATE_VAL) << 3930bd95573STzu-En Huang BIT_SHIFT_CSI_RATE; 3940bd95573STzu-En Huang rtw_write16(rtwdev, REG_RRSR, cur_rrsr); 3950bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, csi_cfg); 3960bd95573STzu-En Huang } 3970bd95573STzu-En Huang *new_rate = DESC_RATE54M; 3980bd95573STzu-En Huang } else { 3990bd95573STzu-En Huang if (cur_rate != DESC_RATE24M) { 4000bd95573STzu-En Huang cur_rrsr &= ~BIT(DESC_RATE54M); 4010bd95573STzu-En Huang csi_cfg |= (DESC_RATE54M & BIT_MASK_CSI_RATE_VAL) << 4020bd95573STzu-En Huang BIT_SHIFT_CSI_RATE; 4030bd95573STzu-En Huang rtw_write16(rtwdev, REG_RRSR, cur_rrsr); 4040bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, csi_cfg); 4050bd95573STzu-En Huang } 4060bd95573STzu-En Huang *new_rate = DESC_RATE24M; 4070bd95573STzu-En Huang } 4080bd95573STzu-En Huang } 409449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_cfg_csi_rate); 410