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; 580bd95573STzu-En Huang vht_cap = &sta->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 1330bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL, RTW_SND_CTRL_SOUNDING); 1340bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL + 3, 0x26); 1350bd95573STzu-En Huang rtw_write8_clr(rtwdev, REG_RXFLTMAP1, BIT_RXFLTMAP1_BF_REPORT_POLL); 1360bd95573STzu-En Huang rtw_write8_clr(rtwdev, REG_RXFLTMAP4, BIT_RXFLTMAP4_BF_REPORT_POLL); 1370bd95573STzu-En Huang 1380bd95573STzu-En Huang if (vif->net_type == RTW_NET_AP_MODE) 1390bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, psf_ctl | BIT(12)); 1400bd95573STzu-En Huang else 1410bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, psf_ctl & ~BIT(12)); 1420bd95573STzu-En Huang } 1430bd95573STzu-En Huang 1440bd95573STzu-En Huang void rtw_bf_cfg_mu_bfee(struct rtw_dev *rtwdev, struct cfg_mumimo_para *param) 1450bd95573STzu-En Huang { 1460bd95573STzu-En Huang u8 mu_tbl_sel; 1470bd95573STzu-En Huang u8 mu_valid; 1480bd95573STzu-En Huang 1490bd95573STzu-En Huang mu_valid = rtw_read8(rtwdev, REG_MU_TX_CTL) & 1500bd95573STzu-En Huang ~BIT_MASK_R_MU_TABLE_VALID; 1510bd95573STzu-En Huang 1520bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL, 1530bd95573STzu-En Huang (mu_valid | BIT(0) | BIT(1)) & ~(BIT(7))); 1540bd95573STzu-En Huang 1550bd95573STzu-En Huang mu_tbl_sel = rtw_read8(rtwdev, REG_MU_TX_CTL + 1) & 0xF8; 1560bd95573STzu-En Huang 1570bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL + 1, mu_tbl_sel); 1580bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_GID_VLD, param->given_gid_tab[0]); 1590bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO, param->given_user_pos[0]); 1600bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO + 4, 1610bd95573STzu-En Huang param->given_user_pos[1]); 1620bd95573STzu-En Huang 1630bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL + 1, mu_tbl_sel | 1); 1640bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_GID_VLD, param->given_gid_tab[1]); 1650bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO, param->given_user_pos[2]); 1660bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_STA_USER_POS_INFO + 4, 1670bd95573STzu-En Huang param->given_user_pos[3]); 1680bd95573STzu-En Huang } 1690bd95573STzu-En Huang 1700bd95573STzu-En Huang void rtw_bf_del_bfer_entry_mu(struct rtw_dev *rtwdev) 1710bd95573STzu-En Huang { 1720bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO, 0); 1730bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 4, 0); 1740bd95573STzu-En Huang rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, 0); 1750bd95573STzu-En Huang rtw_write8(rtwdev, REG_MU_TX_CTL, 0); 1760bd95573STzu-En Huang } 1770bd95573STzu-En Huang 1780bd95573STzu-En Huang void rtw_bf_del_sounding(struct rtw_dev *rtwdev) 1790bd95573STzu-En Huang { 1800bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL, 0); 1810bd95573STzu-En Huang } 1820bd95573STzu-En Huang 1830bd95573STzu-En Huang void rtw_bf_enable_bfee_su(struct rtw_dev *rtwdev, struct rtw_vif *vif, 1840bd95573STzu-En Huang struct rtw_bfee *bfee) 1850bd95573STzu-En Huang { 186*5f4eab88STzu-En Huang u8 nc_index = hweight8(rtwdev->hal.antenna_rx) - 1; 1870bd95573STzu-En Huang u8 nr_index = bfee->sound_dim; 1880bd95573STzu-En Huang u8 grouping = 0, codebookinfo = 1, coefficientsize = 3; 1890bd95573STzu-En Huang u32 addr_bfer_info, addr_csi_rpt, csi_param; 1900bd95573STzu-En Huang u8 i; 1910bd95573STzu-En Huang 1920bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "config as an su bfee\n"); 1930bd95573STzu-En Huang 1940bd95573STzu-En Huang switch (bfee->su_reg_index) { 1950bd95573STzu-En Huang case 1: 1960bd95573STzu-En Huang addr_bfer_info = REG_ASSOCIATED_BFMER1_INFO; 1970bd95573STzu-En Huang addr_csi_rpt = REG_TX_CSI_RPT_PARAM_BW20 + 2; 1980bd95573STzu-En Huang break; 1990bd95573STzu-En Huang case 0: 2000bd95573STzu-En Huang default: 2010bd95573STzu-En Huang addr_bfer_info = REG_ASSOCIATED_BFMER0_INFO; 2020bd95573STzu-En Huang addr_csi_rpt = REG_TX_CSI_RPT_PARAM_BW20; 2030bd95573STzu-En Huang break; 2040bd95573STzu-En Huang } 2050bd95573STzu-En Huang 2060bd95573STzu-En Huang /* Sounding protocol control */ 2070bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL, RTW_SND_CTRL_SOUNDING); 2080bd95573STzu-En Huang 2090bd95573STzu-En Huang /* MAC address/Partial AID of Beamformer */ 2100bd95573STzu-En Huang for (i = 0; i < ETH_ALEN; i++) 2110bd95573STzu-En Huang rtw_write8(rtwdev, addr_bfer_info + i, bfee->mac_addr[i]); 2120bd95573STzu-En Huang 2130bd95573STzu-En Huang csi_param = (u16)((coefficientsize << 10) | 2140bd95573STzu-En Huang (codebookinfo << 8) | 2150bd95573STzu-En Huang (grouping << 6) | 2160bd95573STzu-En Huang (nr_index << 3) | 2170bd95573STzu-En Huang nc_index); 2180bd95573STzu-En Huang rtw_write16(rtwdev, addr_csi_rpt, csi_param); 2190bd95573STzu-En Huang 2200bd95573STzu-En Huang /* ndp rx standby timer */ 2210bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL + 3, RTW_NDP_RX_STANDBY_TIME); 2220bd95573STzu-En Huang } 223449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_enable_bfee_su); 2240bd95573STzu-En Huang 2250bd95573STzu-En Huang /* nc index: 1 2T2R 0 1T1R 2260bd95573STzu-En Huang * nr index: 1 use Nsts 0 use reg setting 2270bd95573STzu-En Huang * codebookinfo: 1 802.11ac 3 802.11n 2280bd95573STzu-En Huang */ 2290bd95573STzu-En Huang void rtw_bf_enable_bfee_mu(struct rtw_dev *rtwdev, struct rtw_vif *vif, 2300bd95573STzu-En Huang struct rtw_bfee *bfee) 2310bd95573STzu-En Huang { 2320bd95573STzu-En Huang struct rtw_bf_info *bf_info = &rtwdev->bf_info; 2330bd95573STzu-En Huang struct mu_bfer_init_para param; 234*5f4eab88STzu-En Huang u8 nc_index = hweight8(rtwdev->hal.antenna_rx) - 1; 235*5f4eab88STzu-En Huang u8 nr_index = 1; 2360bd95573STzu-En Huang u8 grouping = 0, codebookinfo = 1, coefficientsize = 0; 2370bd95573STzu-En Huang u32 csi_param; 2380bd95573STzu-En Huang 2390bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "config as an mu bfee\n"); 2400bd95573STzu-En Huang 2410bd95573STzu-En Huang csi_param = (u16)((coefficientsize << 10) | 2420bd95573STzu-En Huang (codebookinfo << 8) | 2430bd95573STzu-En Huang (grouping << 6) | 2440bd95573STzu-En Huang (nr_index << 3) | 2450bd95573STzu-En Huang nc_index); 2460bd95573STzu-En Huang 2470bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "nc=%d nr=%d group=%d codebookinfo=%d coefficientsize=%d\n", 2480bd95573STzu-En Huang nc_index, nr_index, grouping, codebookinfo, 2490bd95573STzu-En Huang coefficientsize); 2500bd95573STzu-En Huang 2510bd95573STzu-En Huang param.paid = bfee->p_aid; 2520bd95573STzu-En Huang param.csi_para = csi_param; 2530bd95573STzu-En Huang param.my_aid = bfee->aid & 0xfff; 2540bd95573STzu-En Huang param.csi_length_sel = HAL_CSI_SEG_4K; 2550bd95573STzu-En Huang ether_addr_copy(param.bfer_address, bfee->mac_addr); 2560bd95573STzu-En Huang 2570bd95573STzu-En Huang rtw_bf_init_bfer_entry_mu(rtwdev, ¶m); 2580bd95573STzu-En Huang 2590bd95573STzu-En Huang bf_info->cur_csi_rpt_rate = DESC_RATE6M; 2600bd95573STzu-En Huang rtw_bf_cfg_sounding(rtwdev, vif, DESC_RATE6M); 2610bd95573STzu-En Huang 2620bd95573STzu-En Huang /* accept action_no_ack */ 2630bd95573STzu-En Huang rtw_write16_set(rtwdev, REG_RXFLTMAP0, BIT_RXFLTMAP0_ACTIONNOACK); 2640bd95573STzu-En Huang 2650bd95573STzu-En Huang /* accept NDPA and BF report poll */ 2660bd95573STzu-En Huang rtw_write16_set(rtwdev, REG_RXFLTMAP1, BIT_RXFLTMAP1_BF); 2670bd95573STzu-En Huang } 268449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_enable_bfee_mu); 2690bd95573STzu-En Huang 2700bd95573STzu-En Huang void rtw_bf_remove_bfee_su(struct rtw_dev *rtwdev, 2710bd95573STzu-En Huang struct rtw_bfee *bfee) 2720bd95573STzu-En Huang { 2730bd95573STzu-En Huang struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 2740bd95573STzu-En Huang 2750bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "remove as a su bfee\n"); 2760bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL, RTW_SND_CTRL_REMOVE); 2770bd95573STzu-En Huang 2780bd95573STzu-En Huang switch (bfee->su_reg_index) { 2790bd95573STzu-En Huang case 0: 2800bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER0_INFO, 0); 2810bd95573STzu-En Huang rtw_write16(rtwdev, REG_ASSOCIATED_BFMER0_INFO + 4, 0); 2820bd95573STzu-En Huang rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20, 0); 2830bd95573STzu-En Huang break; 2840bd95573STzu-En Huang case 1: 2850bd95573STzu-En Huang rtw_write32(rtwdev, REG_ASSOCIATED_BFMER1_INFO, 0); 2860bd95573STzu-En Huang rtw_write16(rtwdev, REG_ASSOCIATED_BFMER1_INFO + 4, 0); 2870bd95573STzu-En Huang rtw_write16(rtwdev, REG_TX_CSI_RPT_PARAM_BW20 + 2, 0); 2880bd95573STzu-En Huang break; 2890bd95573STzu-En Huang } 2900bd95573STzu-En Huang 2910bd95573STzu-En Huang clear_bit(bfee->su_reg_index, bfinfo->bfer_su_reg_maping); 2920bd95573STzu-En Huang bfee->su_reg_index = 0xFF; 2930bd95573STzu-En Huang } 294449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_remove_bfee_su); 2950bd95573STzu-En Huang 2960bd95573STzu-En Huang void rtw_bf_remove_bfee_mu(struct rtw_dev *rtwdev, 2970bd95573STzu-En Huang struct rtw_bfee *bfee) 2980bd95573STzu-En Huang { 2990bd95573STzu-En Huang struct rtw_bf_info *bfinfo = &rtwdev->bf_info; 3000bd95573STzu-En Huang 3010bd95573STzu-En Huang rtw_write8(rtwdev, REG_SND_PTCL_CTRL, RTW_SND_CTRL_REMOVE); 3020bd95573STzu-En Huang 3030bd95573STzu-En Huang rtw_bf_del_bfer_entry_mu(rtwdev); 3040bd95573STzu-En Huang 3050bd95573STzu-En Huang if (bfinfo->bfer_su_cnt == 0 && bfinfo->bfer_mu_cnt == 0) 3060bd95573STzu-En Huang rtw_bf_del_sounding(rtwdev); 3070bd95573STzu-En Huang } 308449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_remove_bfee_mu); 3090bd95573STzu-En Huang 3100bd95573STzu-En Huang void rtw_bf_set_gid_table(struct rtw_dev *rtwdev, struct ieee80211_vif *vif, 3110bd95573STzu-En Huang struct ieee80211_bss_conf *conf) 3120bd95573STzu-En Huang { 3130bd95573STzu-En Huang struct rtw_vif *rtwvif = (struct rtw_vif *)vif->drv_priv; 3140bd95573STzu-En Huang struct rtw_bfee *bfee = &rtwvif->bfee; 3150bd95573STzu-En Huang struct cfg_mumimo_para param; 3160bd95573STzu-En Huang 3170bd95573STzu-En Huang if (bfee->role != RTW_BFEE_MU) { 3180bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "this vif is not mu bfee\n"); 3190bd95573STzu-En Huang return; 3200bd95573STzu-En Huang } 3210bd95573STzu-En Huang 3220bd95573STzu-En Huang param.grouping_bitmap = 0; 3230bd95573STzu-En Huang param.mu_tx_en = 0; 3240bd95573STzu-En Huang memset(param.sounding_sts, 0, 6); 3250bd95573STzu-En Huang memcpy(param.given_gid_tab, conf->mu_group.membership, 8); 3260bd95573STzu-En Huang memcpy(param.given_user_pos, conf->mu_group.position, 16); 3270bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "STA0: gid_valid=0x%x, user_position_l=0x%x, user_position_h=0x%x\n", 3280bd95573STzu-En Huang param.given_gid_tab[0], param.given_user_pos[0], 3290bd95573STzu-En Huang param.given_user_pos[1]); 3300bd95573STzu-En Huang 3310bd95573STzu-En Huang rtw_dbg(rtwdev, RTW_DBG_BF, "STA1: gid_valid=0x%x, user_position_l=0x%x, user_position_h=0x%x\n", 3320bd95573STzu-En Huang param.given_gid_tab[1], param.given_user_pos[2], 3330bd95573STzu-En Huang param.given_user_pos[3]); 3340bd95573STzu-En Huang 3350bd95573STzu-En Huang rtw_bf_cfg_mu_bfee(rtwdev, ¶m); 3360bd95573STzu-En Huang } 337449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_set_gid_table); 3380bd95573STzu-En Huang 3390bd95573STzu-En Huang void rtw_bf_phy_init(struct rtw_dev *rtwdev) 3400bd95573STzu-En Huang { 3410bd95573STzu-En Huang u8 tmp8; 3420bd95573STzu-En Huang u32 tmp32; 3430bd95573STzu-En Huang u8 retry_limit = 0xA; 3440bd95573STzu-En Huang u8 ndpa_rate = 0x10; 3450bd95573STzu-En Huang u8 ack_policy = 3; 3460bd95573STzu-En Huang 3470bd95573STzu-En Huang tmp32 = rtw_read32(rtwdev, REG_MU_TX_CTL); 3480bd95573STzu-En Huang /* Enable P1 aggr new packet according to P0 transfer time */ 3490bd95573STzu-En Huang tmp32 |= BIT_MU_P1_WAIT_STATE_EN; 3500bd95573STzu-En Huang /* MU Retry Limit */ 3510bd95573STzu-En Huang tmp32 &= ~BIT_MASK_R_MU_RL; 3520bd95573STzu-En Huang tmp32 |= (retry_limit << BIT_SHIFT_R_MU_RL) & BIT_MASK_R_MU_RL; 3530bd95573STzu-En Huang /* Disable Tx MU-MIMO until sounding done */ 3540bd95573STzu-En Huang tmp32 &= ~BIT_EN_MU_MIMO; 3550bd95573STzu-En Huang /* Clear validity of MU STAs */ 3560bd95573STzu-En Huang tmp32 &= ~BIT_MASK_R_MU_TABLE_VALID; 3570bd95573STzu-En Huang rtw_write32(rtwdev, REG_MU_TX_CTL, tmp32); 3580bd95573STzu-En Huang 3590bd95573STzu-En Huang /* MU-MIMO Option as default value */ 3600bd95573STzu-En Huang tmp8 = ack_policy << BIT_SHIFT_WMAC_TXMU_ACKPOLICY; 3610bd95573STzu-En Huang tmp8 |= BIT_WMAC_TXMU_ACKPOLICY_EN; 3620bd95573STzu-En Huang rtw_write8(rtwdev, REG_WMAC_MU_BF_OPTION, tmp8); 3630bd95573STzu-En Huang 3640bd95573STzu-En Huang /* MU-MIMO Control as default value */ 3650bd95573STzu-En Huang rtw_write16(rtwdev, REG_WMAC_MU_BF_CTL, 0); 3660bd95573STzu-En Huang /* Set MU NDPA rate & BW source */ 3670bd95573STzu-En Huang rtw_write32_set(rtwdev, REG_TXBF_CTRL, BIT_USE_NDPA_PARAMETER); 3680bd95573STzu-En Huang /* Set NDPA Rate */ 3690bd95573STzu-En Huang rtw_write8(rtwdev, REG_NDPA_OPT_CTRL, ndpa_rate); 3700bd95573STzu-En Huang 3710bd95573STzu-En Huang rtw_write32_mask(rtwdev, REG_BBPSF_CTRL, BIT_MASK_CSI_RATE, 3720bd95573STzu-En Huang DESC_RATE6M); 3730bd95573STzu-En Huang } 374449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_phy_init); 3750bd95573STzu-En Huang 3760bd95573STzu-En Huang void rtw_bf_cfg_csi_rate(struct rtw_dev *rtwdev, u8 rssi, u8 cur_rate, 3770bd95573STzu-En Huang u8 fixrate_en, u8 *new_rate) 3780bd95573STzu-En Huang { 3790bd95573STzu-En Huang u32 csi_cfg; 3800bd95573STzu-En Huang u16 cur_rrsr; 3810bd95573STzu-En Huang 3820bd95573STzu-En Huang csi_cfg = rtw_read32(rtwdev, REG_BBPSF_CTRL) & ~BIT_MASK_CSI_RATE; 3830bd95573STzu-En Huang cur_rrsr = rtw_read16(rtwdev, REG_RRSR); 3840bd95573STzu-En Huang 3850bd95573STzu-En Huang if (rssi >= 40) { 3860bd95573STzu-En Huang if (cur_rate != DESC_RATE54M) { 3870bd95573STzu-En Huang cur_rrsr |= BIT(DESC_RATE54M); 3880bd95573STzu-En Huang csi_cfg |= (DESC_RATE54M & BIT_MASK_CSI_RATE_VAL) << 3890bd95573STzu-En Huang BIT_SHIFT_CSI_RATE; 3900bd95573STzu-En Huang rtw_write16(rtwdev, REG_RRSR, cur_rrsr); 3910bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, csi_cfg); 3920bd95573STzu-En Huang } 3930bd95573STzu-En Huang *new_rate = DESC_RATE54M; 3940bd95573STzu-En Huang } else { 3950bd95573STzu-En Huang if (cur_rate != DESC_RATE24M) { 3960bd95573STzu-En Huang cur_rrsr &= ~BIT(DESC_RATE54M); 3970bd95573STzu-En Huang csi_cfg |= (DESC_RATE54M & BIT_MASK_CSI_RATE_VAL) << 3980bd95573STzu-En Huang BIT_SHIFT_CSI_RATE; 3990bd95573STzu-En Huang rtw_write16(rtwdev, REG_RRSR, cur_rrsr); 4000bd95573STzu-En Huang rtw_write32(rtwdev, REG_BBPSF_CTRL, csi_cfg); 4010bd95573STzu-En Huang } 4020bd95573STzu-En Huang *new_rate = DESC_RATE24M; 4030bd95573STzu-En Huang } 4040bd95573STzu-En Huang } 405449be866SZong-Zhe Yang EXPORT_SYMBOL(rtw_bf_cfg_csi_rate); 406