Skip to content

Commit

Permalink
wifi: rtw89: fw: update TX AMPDU parameter to CMAC table
Browse files Browse the repository at this point in the history
The CMAC table is used to define how hardware TX a certain packet, and
we can specify TX AMPDU size, so hardware can prepare proper retry window
buffer. Otherwise, it can't transmit with expected aggregation number.
Since each TID could have different aggregation number, the smallest number
is adopted to prevent over peer's receiving buffer.

Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/20240115033742.16372-5-pkshih@realtek.com
  • Loading branch information
Ping-Ke Shih authored and Kalle Valo committed Jan 18, 2024
1 parent 7e24cc8 commit 999db6f
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/net/wireless/realtek/rtw89/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,7 @@ struct rtw89_sta {
struct ewma_evm evm_min[RF_PATH_MAX];
struct ewma_evm evm_max[RF_PATH_MAX];
struct rtw89_ampdu_params ampdu_params[IEEE80211_NUM_TIDS];
DECLARE_BITMAP(ampdu_map, IEEE80211_NUM_TIDS);
struct ieee80211_rx_status rx_status;
u16 rx_hw_rate;
__le32 htc_template;
Expand Down Expand Up @@ -3200,6 +3201,9 @@ struct rtw89_chip_ops {
int (*h2c_assoc_cmac_tbl)(struct rtw89_dev *rtwdev,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta);
int (*h2c_ampdu_cmac_tbl)(struct rtw89_dev *rtwdev,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta);
int (*h2c_update_beacon)(struct rtw89_dev *rtwdev,
struct rtw89_vif *rtwvif);
int (*h2c_ba_cam)(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta,
Expand Down
66 changes: 66 additions & 0 deletions drivers/net/wireless/realtek/rtw89/fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,72 @@ int rtw89_fw_h2c_assoc_cmac_tbl_g7(struct rtw89_dev *rtwdev,
}
EXPORT_SYMBOL(rtw89_fw_h2c_assoc_cmac_tbl_g7);

int rtw89_fw_h2c_ampdu_cmac_tbl_g7(struct rtw89_dev *rtwdev,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
struct rtw89_sta *rtwsta = (struct rtw89_sta *)sta->drv_priv;
struct rtw89_h2c_cctlinfo_ud_g7 *h2c;
u32 len = sizeof(*h2c);
struct sk_buff *skb;
u16 agg_num = 0;
u8 ba_bmap = 0;
int ret;
u8 tid;

skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, len);
if (!skb) {
rtw89_err(rtwdev, "failed to alloc skb for ampdu cmac g7\n");
return -ENOMEM;
}
skb_put(skb, len);
h2c = (struct rtw89_h2c_cctlinfo_ud_g7 *)skb->data;

for_each_set_bit(tid, rtwsta->ampdu_map, IEEE80211_NUM_TIDS) {
if (agg_num == 0)
agg_num = rtwsta->ampdu_params[tid].agg_num;
else
agg_num = min(agg_num, rtwsta->ampdu_params[tid].agg_num);
}

if (agg_num <= 0x20)
ba_bmap = 3;
else if (agg_num > 0x20 && agg_num <= 0x40)
ba_bmap = 0;
else if (agg_num > 0x40 && agg_num <= 0x80)
ba_bmap = 1;
else if (agg_num > 0x80 && agg_num <= 0x100)
ba_bmap = 2;
else if (agg_num > 0x100 && agg_num <= 0x200)
ba_bmap = 4;
else if (agg_num > 0x200 && agg_num <= 0x400)
ba_bmap = 5;

h2c->c0 = le32_encode_bits(rtwsta->mac_id, CCTLINFO_G7_C0_MACID) |
le32_encode_bits(1, CCTLINFO_G7_C0_OP);

h2c->w3 = le32_encode_bits(ba_bmap, CCTLINFO_G7_W3_BA_BMAP);
h2c->m3 = cpu_to_le32(CCTLINFO_G7_W3_BA_BMAP);

rtw89_h2c_pkt_set_hdr(rtwdev, skb, FWCMD_TYPE_H2C,
H2C_CAT_MAC, H2C_CL_MAC_FR_EXCHG,
H2C_FUNC_MAC_CCTLINFO_UD_G7, 0, 0,
len);

ret = rtw89_h2c_tx(rtwdev, skb, false);
if (ret) {
rtw89_err(rtwdev, "failed to send h2c\n");
goto fail;
}

return 0;
fail:
dev_kfree_skb_any(skb);

return ret;
}
EXPORT_SYMBOL(rtw89_fw_h2c_ampdu_cmac_tbl_g7);

int rtw89_fw_h2c_txtime_cmac_tbl(struct rtw89_dev *rtwdev,
struct rtw89_sta *rtwsta)
{
Expand Down
15 changes: 15 additions & 0 deletions drivers/net/wireless/realtek/rtw89/fw.h
Original file line number Diff line number Diff line change
Expand Up @@ -3946,6 +3946,9 @@ int rtw89_fw_h2c_assoc_cmac_tbl(struct rtw89_dev *rtwdev,
int rtw89_fw_h2c_assoc_cmac_tbl_g7(struct rtw89_dev *rtwdev,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta);
int rtw89_fw_h2c_ampdu_cmac_tbl_g7(struct rtw89_dev *rtwdev,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta);
int rtw89_fw_h2c_txtime_cmac_tbl(struct rtw89_dev *rtwdev,
struct rtw89_sta *rtwsta);
int rtw89_fw_h2c_txpath_cmac_tbl(struct rtw89_dev *rtwdev,
Expand Down Expand Up @@ -4103,6 +4106,18 @@ static inline int rtw89_chip_h2c_assoc_cmac_tbl(struct rtw89_dev *rtwdev,
return chip->ops->h2c_assoc_cmac_tbl(rtwdev, vif, sta);
}

static inline int rtw89_chip_h2c_ampdu_cmac_tbl(struct rtw89_dev *rtwdev,
struct ieee80211_vif *vif,
struct ieee80211_sta *sta)
{
const struct rtw89_chip_info *chip = rtwdev->chip;

if (chip->ops->h2c_ampdu_cmac_tbl)
return chip->ops->h2c_ampdu_cmac_tbl(rtwdev, vif, sta);

return 0;
}

static inline
int rtw89_chip_h2c_ba_cam(struct rtw89_dev *rtwdev, struct rtw89_sta *rtwsta,
bool valid, struct ieee80211_ampdu_params *params)
Expand Down
4 changes: 4 additions & 0 deletions drivers/net/wireless/realtek/rtw89/mac80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ static int rtw89_ops_ampdu_action(struct ieee80211_hw *hw,
case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
mutex_lock(&rtwdev->mutex);
clear_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
clear_bit(tid, rtwsta->ampdu_map);
rtw89_chip_h2c_ampdu_cmac_tbl(rtwdev, vif, sta);
mutex_unlock(&rtwdev->mutex);
ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
break;
Expand All @@ -668,7 +670,9 @@ static int rtw89_ops_ampdu_action(struct ieee80211_hw *hw,
set_bit(RTW89_TXQ_F_AMPDU, &rtwtxq->flags);
rtwsta->ampdu_params[tid].agg_num = params->buf_size;
rtwsta->ampdu_params[tid].amsdu = params->amsdu;
set_bit(tid, rtwsta->ampdu_map);
rtw89_leave_ps_mode(rtwdev);
rtw89_chip_h2c_ampdu_cmac_tbl(rtwdev, vif, sta);
mutex_unlock(&rtwdev->mutex);
break;
case IEEE80211_AMPDU_RX_START:
Expand Down
1 change: 1 addition & 0 deletions drivers/net/wireless/realtek/rtw89/rtw8851b.c
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,7 @@ static const struct rtw89_chip_ops rtw8851b_chip_ops = {
.resume_sch_tx = rtw89_mac_resume_sch_tx,
.h2c_dctl_sec_cam = NULL,
.h2c_assoc_cmac_tbl = rtw89_fw_h2c_assoc_cmac_tbl,
.h2c_ampdu_cmac_tbl = NULL,
.h2c_update_beacon = rtw89_fw_h2c_update_beacon,
.h2c_ba_cam = rtw89_fw_h2c_ba_cam,

Expand Down
1 change: 1 addition & 0 deletions drivers/net/wireless/realtek/rtw89/rtw8852a.c
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,7 @@ static const struct rtw89_chip_ops rtw8852a_chip_ops = {
.resume_sch_tx = rtw89_mac_resume_sch_tx,
.h2c_dctl_sec_cam = NULL,
.h2c_assoc_cmac_tbl = rtw89_fw_h2c_assoc_cmac_tbl,
.h2c_ampdu_cmac_tbl = NULL,
.h2c_update_beacon = rtw89_fw_h2c_update_beacon,
.h2c_ba_cam = rtw89_fw_h2c_ba_cam,

Expand Down
1 change: 1 addition & 0 deletions drivers/net/wireless/realtek/rtw89/rtw8852b.c
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,7 @@ static const struct rtw89_chip_ops rtw8852b_chip_ops = {
.resume_sch_tx = rtw89_mac_resume_sch_tx,
.h2c_dctl_sec_cam = NULL,
.h2c_assoc_cmac_tbl = rtw89_fw_h2c_assoc_cmac_tbl,
.h2c_ampdu_cmac_tbl = NULL,
.h2c_update_beacon = rtw89_fw_h2c_update_beacon,
.h2c_ba_cam = rtw89_fw_h2c_ba_cam,

Expand Down
1 change: 1 addition & 0 deletions drivers/net/wireless/realtek/rtw89/rtw8852c.c
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,7 @@ static const struct rtw89_chip_ops rtw8852c_chip_ops = {
.resume_sch_tx = rtw89_mac_resume_sch_tx_v1,
.h2c_dctl_sec_cam = rtw89_fw_h2c_dctl_sec_cam_v1,
.h2c_assoc_cmac_tbl = rtw89_fw_h2c_assoc_cmac_tbl,
.h2c_ampdu_cmac_tbl = NULL,
.h2c_update_beacon = rtw89_fw_h2c_update_beacon,
.h2c_ba_cam = rtw89_fw_h2c_ba_cam,

Expand Down
1 change: 1 addition & 0 deletions drivers/net/wireless/realtek/rtw89/rtw8922a.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ static const struct rtw89_chip_ops rtw8922a_chip_ops = {
.pwr_off_func = rtw8922a_pwr_off_func,
.h2c_dctl_sec_cam = rtw89_fw_h2c_dctl_sec_cam_v2,
.h2c_assoc_cmac_tbl = rtw89_fw_h2c_assoc_cmac_tbl_g7,
.h2c_ampdu_cmac_tbl = rtw89_fw_h2c_ampdu_cmac_tbl_g7,
.h2c_update_beacon = rtw89_fw_h2c_update_beacon_be,
.h2c_ba_cam = rtw89_fw_h2c_ba_cam_v1,
};
Expand Down

0 comments on commit 999db6f

Please sign in to comment.