162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
262306a36Sopenharmony_ci/* Copyright(c) 2018-2019  Realtek Corporation.
362306a36Sopenharmony_ci */
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#ifndef __RTW_BF_H_
662306a36Sopenharmony_ci#define __RTW_BF_H_
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#define REG_TXBF_CTRL		0x042C
962306a36Sopenharmony_ci#define REG_RRSR		0x0440
1062306a36Sopenharmony_ci#define REG_NDPA_OPT_CTRL	0x045F
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#define REG_ASSOCIATED_BFMER0_INFO	0x06E4
1362306a36Sopenharmony_ci#define REG_ASSOCIATED_BFMER1_INFO	0x06EC
1462306a36Sopenharmony_ci#define REG_TX_CSI_RPT_PARAM_BW20	0x06F4
1562306a36Sopenharmony_ci#define REG_SND_PTCL_CTRL		0x0718
1662306a36Sopenharmony_ci#define BIT_DIS_CHK_VHTSIGB_CRC		BIT(6)
1762306a36Sopenharmony_ci#define BIT_DIS_CHK_VHTSIGA_CRC		BIT(5)
1862306a36Sopenharmony_ci#define BIT_MASK_BEAMFORM		(GENMASK(4, 0) | BIT(7))
1962306a36Sopenharmony_ci#define REG_MU_TX_CTL			0x14C0
2062306a36Sopenharmony_ci#define REG_MU_STA_GID_VLD		0x14C4
2162306a36Sopenharmony_ci#define REG_MU_STA_USER_POS_INFO	0x14C8
2262306a36Sopenharmony_ci#define REG_CSI_RRSR			0x1678
2362306a36Sopenharmony_ci#define REG_WMAC_MU_BF_OPTION		0x167C
2462306a36Sopenharmony_ci#define REG_WMAC_MU_BF_CTL		0x1680
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#define BIT_WMAC_USE_NDPARATE			BIT(30)
2762306a36Sopenharmony_ci#define BIT_WMAC_TXMU_ACKPOLICY_EN		BIT(6)
2862306a36Sopenharmony_ci#define BIT_USE_NDPA_PARAMETER			BIT(30)
2962306a36Sopenharmony_ci#define BIT_MU_P1_WAIT_STATE_EN			BIT(16)
3062306a36Sopenharmony_ci#define BIT_EN_MU_MIMO				BIT(7)
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define R_MU_RL				0xf
3362306a36Sopenharmony_ci#define BIT_SHIFT_R_MU_RL		12
3462306a36Sopenharmony_ci#define BIT_SHIFT_WMAC_TXMU_ACKPOLICY	4
3562306a36Sopenharmony_ci#define BIT_SHIFT_CSI_RATE		24
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#define BIT_MASK_R_MU_RL (R_MU_RL << BIT_SHIFT_R_MU_RL)
3862306a36Sopenharmony_ci#define BIT_MASK_R_MU_TABLE_VALID	0x3f
3962306a36Sopenharmony_ci#define BIT_MASK_CSI_RATE_VAL		0x3F
4062306a36Sopenharmony_ci#define BIT_MASK_CSI_RATE (BIT_MASK_CSI_RATE_VAL << BIT_SHIFT_CSI_RATE)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define BIT_RXFLTMAP0_ACTIONNOACK	BIT(14)
4362306a36Sopenharmony_ci#define BIT_RXFLTMAP1_BF		(BIT(4) | BIT(5))
4462306a36Sopenharmony_ci#define BIT_RXFLTMAP1_BF_REPORT_POLL	BIT(4)
4562306a36Sopenharmony_ci#define BIT_RXFLTMAP4_BF_REPORT_POLL	BIT(4)
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define RTW_NDP_RX_STANDBY_TIME	0x70
4862306a36Sopenharmony_ci#define RTW_SND_CTRL_REMOVE	0x98
4962306a36Sopenharmony_ci#define RTW_SND_CTRL_SOUNDING	0x9B
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_cienum csi_seg_len {
5262306a36Sopenharmony_ci	HAL_CSI_SEG_4K = 0,
5362306a36Sopenharmony_ci	HAL_CSI_SEG_8K = 1,
5462306a36Sopenharmony_ci	HAL_CSI_SEG_11K = 2,
5562306a36Sopenharmony_ci};
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_cistruct cfg_mumimo_para {
5862306a36Sopenharmony_ci	u8 sounding_sts[6];
5962306a36Sopenharmony_ci	u16 grouping_bitmap;
6062306a36Sopenharmony_ci	u8 mu_tx_en;
6162306a36Sopenharmony_ci	u32 given_gid_tab[2];
6262306a36Sopenharmony_ci	u32 given_user_pos[4];
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistruct mu_bfer_init_para {
6662306a36Sopenharmony_ci	u16 paid;
6762306a36Sopenharmony_ci	u16 csi_para;
6862306a36Sopenharmony_ci	u16 my_aid;
6962306a36Sopenharmony_ci	enum csi_seg_len csi_length_sel;
7062306a36Sopenharmony_ci	u8 bfer_address[ETH_ALEN];
7162306a36Sopenharmony_ci};
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_civoid rtw_bf_disassoc(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
7462306a36Sopenharmony_ci		     struct ieee80211_bss_conf *bss_conf);
7562306a36Sopenharmony_civoid rtw_bf_assoc(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
7662306a36Sopenharmony_ci		  struct ieee80211_bss_conf *bss_conf);
7762306a36Sopenharmony_civoid rtw_bf_init_bfer_entry_mu(struct rtw_dev *rtwdev,
7862306a36Sopenharmony_ci			       struct mu_bfer_init_para *param);
7962306a36Sopenharmony_civoid rtw_bf_cfg_sounding(struct rtw_dev *rtwdev, struct rtw_vif *vif,
8062306a36Sopenharmony_ci			 enum rtw_trx_desc_rate rate);
8162306a36Sopenharmony_civoid rtw_bf_cfg_mu_bfee(struct rtw_dev *rtwdev, struct cfg_mumimo_para *param);
8262306a36Sopenharmony_civoid rtw_bf_del_bfer_entry_mu(struct rtw_dev *rtwdev);
8362306a36Sopenharmony_civoid rtw_bf_del_sounding(struct rtw_dev *rtwdev);
8462306a36Sopenharmony_civoid rtw_bf_enable_bfee_su(struct rtw_dev *rtwdev, struct rtw_vif *vif,
8562306a36Sopenharmony_ci			   struct rtw_bfee *bfee);
8662306a36Sopenharmony_civoid rtw_bf_enable_bfee_mu(struct rtw_dev *rtwdev, struct rtw_vif *vif,
8762306a36Sopenharmony_ci			   struct rtw_bfee *bfee);
8862306a36Sopenharmony_civoid rtw_bf_remove_bfee_su(struct rtw_dev *rtwdev, struct rtw_bfee *bfee);
8962306a36Sopenharmony_civoid rtw_bf_remove_bfee_mu(struct rtw_dev *rtwdev, struct rtw_bfee *bfee);
9062306a36Sopenharmony_civoid rtw_bf_set_gid_table(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
9162306a36Sopenharmony_ci			  struct ieee80211_bss_conf *conf);
9262306a36Sopenharmony_civoid rtw_bf_phy_init(struct rtw_dev *rtwdev);
9362306a36Sopenharmony_civoid rtw_bf_cfg_csi_rate(struct rtw_dev *rtwdev, u8 rssi, u8 cur_rate,
9462306a36Sopenharmony_ci			 u8 fixrate_en, u8 *new_rate);
9562306a36Sopenharmony_cistatic inline void rtw_chip_config_bfee(struct rtw_dev *rtwdev, struct rtw_vif *vif,
9662306a36Sopenharmony_ci					struct rtw_bfee *bfee, bool enable)
9762306a36Sopenharmony_ci{
9862306a36Sopenharmony_ci	if (rtwdev->chip->ops->config_bfee)
9962306a36Sopenharmony_ci		rtwdev->chip->ops->config_bfee(rtwdev, vif, bfee, enable);
10062306a36Sopenharmony_ci}
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cistatic inline void rtw_chip_set_gid_table(struct rtw_dev *rtwdev,
10362306a36Sopenharmony_ci					  struct ieee80211_vif *vif,
10462306a36Sopenharmony_ci					  struct ieee80211_bss_conf *conf)
10562306a36Sopenharmony_ci{
10662306a36Sopenharmony_ci	if (rtwdev->chip->ops->set_gid_table)
10762306a36Sopenharmony_ci		rtwdev->chip->ops->set_gid_table(rtwdev, vif, conf);
10862306a36Sopenharmony_ci}
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_cistatic inline void rtw_chip_cfg_csi_rate(struct rtw_dev *rtwdev, u8 rssi, u8 cur_rate,
11162306a36Sopenharmony_ci					 u8 fixrate_en, u8 *new_rate)
11262306a36Sopenharmony_ci{
11362306a36Sopenharmony_ci	if (rtwdev->chip->ops->cfg_csi_rate)
11462306a36Sopenharmony_ci		rtwdev->chip->ops->cfg_csi_rate(rtwdev, rssi, cur_rate,
11562306a36Sopenharmony_ci						fixrate_en, new_rate);
11662306a36Sopenharmony_ci}
11762306a36Sopenharmony_ci#endif
118