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