Skip to contentSkip to conversation

wifi: rtw89: coex: improve BT-coexistence for RTL8922DE

PATCH In review Ping-Ke Shih 1 participant 17 messages Sep 16 – Sep 23 Realtek wireless driver (rtw89)

lore
Share & tools
lore

Ping-Ke Shih

author maintainer
#0 lore raw

cover wifi: rtw89: coex: improve BT-coexistence for RTL8922DE

The BT-coexistence of RTL8922DE is continuously developing and debugging. Add more firmware command/event formats, and update logic for the cases we found and fixed.

Ching-Te Ku (15):
wifi: rtw89: coex: fix SET_H2C_MACRO not sent for BTC_FEAT_H2C_MACRO
chips
wifi: rtw89: coex: fix out-of-bounds read of report gnt_val
wifi: rtw89: coex: fix rlink index bound check in _update_wl_info
wifi: rtw89: coex: support version 8 for gpio_dbg FCX report
wifi: rtw89: coex: support fcxtdma version 8 in TDMA policy
wifi: rtw89: coex: add fcxcysta v8 report support
wifi: rtw89: coex: route BT sub-reports by bt_id for dual-BT support
wifi: rtw89: coex: split bt_profile into per-device fields in trx H2C
wifi: rtw89: coex: add fcxtxpwr version dispatch for CXDRVINFO_TXPWR
wifi: rtw89: coex: set dbcc_en for dual-band-active MLO modes
wifi: rtw89: coex: evaluate CO-RX Hi-LNA request per band
wifi: rtw89: coex: detect BT HID activity from scoreboard
wifi: rtw89: coex: check null-tx fail ratio in nullsta report
wifi: rtw89: coex: detect BT slot flood via A2DP empty-streak in cysta
wifi: rtw89: coex: add AFH conflict detection on BT AFH report

 drivers/net/wireless/realtek/rtw89/coex.c | 481 +++++++++++++++++++---
 drivers/net/wireless/realtek/rtw89/core.h |  31 +-
 drivers/net/wireless/realtek/rtw89/fw.c   |  18 +-
 drivers/net/wireless/realtek/rtw89/fw.h   |  14 +-
 4 files changed, 478 insertions(+), 66 deletions(-)

base-commit: 73e3b1c94c7d5b4a113e7cbb42665dc2fe3b9d78

Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/15 wifi: rtw89: coex: fix SET_H2C_MACRO not sent for BTC_FEAT_H2C_MACRO chips

From: Ching-Te Ku <[email protected]>

For chips with BTC_FEAT_H2C_MACRO (e.g. RTL8922D), _send_fw_cmd buffers each BTC H2C command as a TLV entry into hbuf, then falls through to the shared rtw89_fw_h2c_raw_with_hdr call. The else- branch was missing the reassignment of h2c_func, buf, and len to SET_H2C_MACRO and hbuf before that shared send, causing each command to be delivered directly rather than through the MAC FW macro mechanism 8922D requires. Add the three assignments and reset hbuf after the macro is sent.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/net/wireless/realtek/rtw89/coex.c +7 -0
index b16af1291b93..3ef30bd962d9 100644
@@ -1102,6 +1102,10 @@ static int _send_fw_cmd(struct rtw89_dev *rtwdev, u8 h2c_class, u8 h2c_func,
 			    "[BTC], %s():Buffer H2C-MACRO cnt=%d/bt%d-func=%s/len=%d\n",
 			    __func__, btc->hbuf_cnt, bid,
 			    id_to_h2c(h2c_func_mask), len);
+
+		h2c_func = SET_H2C_MACRO;
+		buf = btc->hbuf;
+		len = btc->hbuf_len;
 	}
 
 	ret = rtw89_fw_h2c_raw_with_hdr(rtwdev, h2c_class, h2c_func, buf, len,
@@ -1111,6 +1115,9 @@ static int _send_fw_cmd(struct rtw89_dev *rtwdev, u8 h2c_class, u8 h2c_func,
 	else
 		pfwinfo->cnt_h2c++;
 
+	if (h2c_func == SET_H2C_MACRO)
+		_reset_h2c_macro(btc);
+
 	return ret;
 }
 
Signature · 1 line
2.25.1
author maintainer
#3 lore raw

PATCH 2/15 wifi: rtw89: coex: fix out-of-bounds read of report gnt_val

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

The firmware report control structures store gnt_val as either struct rtw89_mac_ax_gnt or a u8[4] array, so each element is four bytes wide. The destination dm->gnt_val[] uses struct rtw89_btc_gnt_ctrl, which is eight bytes. Copying sizeof(dm->gnt_val[i]) therefore read four bytes past the end of every source element on each loop iteration, across all affected report versions.

Bound the copy by the size of the source element instead, so the memcpy never reads beyond the report field.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/net/wireless/realtek/rtw89/coex.c +6 -6
index 3ef30bd962d9..f86311191171 100644
@@ -2050,7 +2050,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 
 			for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++)
 				memcpy(&dm->gnt_val[i], &prpt->v4.gnt_val[i],
-				       sizeof(dm->gnt_val[i]));
+				       sizeof(prpt->v4.gnt_val[i]));
 
 			bt->bcnt[BTC_BCNT_HIPRI_TX] =
 				le32_to_cpu(prpt->v4.bt_cnt[BTC_BCNT_HI_TX]);
@@ -2082,7 +2082,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 
 			for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++)
 				memcpy(&dm->gnt_val[i], &prpt->v5.gnt_val[i],
-				       sizeof(dm->gnt_val[i]));
+				       sizeof(prpt->v5.gnt_val[i]));
 
 			bt->bcnt[BTC_BCNT_HIPRI_TX] =
 				le16_to_cpu(prpt->v5.bt_cnt[BTC_BCNT_HI_TX]);
@@ -2109,7 +2109,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 
 			for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++)
 				memcpy(&dm->gnt_val[i], &prpt->v105.gnt_val[i],
-				       sizeof(dm->gnt_val[i]));
+				       sizeof(prpt->v105.gnt_val[i]));
 
 			bt->bcnt[BTC_BCNT_HIPRI_TX] =
 				le16_to_cpu(prpt->v105.bt_cnt[BTC_BCNT_HI_TX_V105]);
@@ -2135,7 +2135,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 
 			for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++)
 				memcpy(&dm->gnt_val[i], &prpt->v7.gnt_val[i],
-				       sizeof(dm->gnt_val[i]));
+				       sizeof(prpt->v7.gnt_val[i]));
 
 			bt->bcnt[BTC_BCNT_HIPRI_TX] =
 				le16_to_cpu(prpt->v7.bt_cnt[BTC_BCNT_HI_TX_V105]);
@@ -2167,7 +2167,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 
 			for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++)
 				memcpy(&dm->gnt_val[i], &prpt->v8.gnt_val[i],
-				       sizeof(dm->gnt_val[i]));
+				       sizeof(prpt->v8.gnt_val[i]));
 
 			bt->bcnt[BTC_BCNT_HIPRI_TX] =
 				le16_to_cpu(prpt->v8.bt_cnt[BTC_BCNT_HI_TX_V105]);
@@ -2212,7 +2212,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 
 			for (i = RTW89_PHY_0; i < RTW89_PHY_NUM; i++)
 				memcpy(&dm->gnt_val[i], &prpt->v9.gnt_val[i],
-				       sizeof(dm->gnt_val[i]));
+				       sizeof(prpt->v9.gnt_val[i]));
 
 			bt->bcnt[BTC_BCNT_HIPRI_TX] =
 				le16_to_cpu(prpt->v9.bt_cnt[BTC_BCNT_HI_TX_V105]);
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH 3/15 wifi: rtw89: coex: fix rlink index bound check in _update_wl_info

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

The rlink array is dimensioned [RTW89_BE_BTC_WL_MAX_ROLE_NUMBER] [RTW89_MAC_NUM], where rlink_id is the HW-band index selecting the second dimension. The guard rejected rlink_id only when it reached RTW89_BAND_NUM (3), but the array holds RTW89_MAC_NUM (2) entries, so rlink_id == 2 passed the check and led to out-of-bounds access when writing rlink[role_id][rlink_id], when scanning rlink[i][rlink_id] in the per-role loop, and inside _update_wl_mlo_info() where the same index reaches arrays sized by HW band.

Reject rlink_id at RTW89_MAC_NUM so it matches the actual array size.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/coex.c +1 -1
index f86311191171..279b75461fe2 100644
@@ -7605,7 +7605,7 @@ static void _update_wl_info(struct rtw89_dev *rtwdev, struct rtw89_btc_wl_link_i
 	u8 i, link_mode_ori;
 	u32 role_map = 0;
 
-	if (role_id >= RTW89_BE_BTC_WL_MAX_ROLE_NUMBER || rlink_id >= RTW89_BAND_NUM)
+	if (role_id >= RTW89_BE_BTC_WL_MAX_ROLE_NUMBER || rlink_id >= RTW89_MAC_NUM)
 		return;
 
 	/*
Signature · 1 line
2.25.1
author maintainer
#5 lore raw

PATCH 4/15 wifi: rtw89: coex: support version 8 for gpio_dbg FCX report

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

RTL8852C (FW >= 0.27.130) and RTL8922A/D (FW >= 0.35.94/0.35.111) set fcxgpiodbg to 8, but _chk_btc_report only handled version 7, causing it to fall through to goto err.

The gpio_dbg v8 struct is layout-compatible with v7, so extend the guard to accept version 8 using the existing v7 parsing path.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/coex.c +1 -1
index 279b75461fe2..62b86dc40e87 100644
@@ -1908,7 +1908,7 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 		break;
 	case BTC_RPT_TYPE_GPIO_DBG:
 		pcinfo = &pfwinfo->rpt_fbtc_gpio_dbg.cinfo;
-		if (ver->fcxgpiodbg == 7) {
+		if (ver->fcxgpiodbg == 7 || ver->fcxgpiodbg == 8) {
 			pfinfo = &pfwinfo->rpt_fbtc_gpio_dbg.finfo.v7;
 			pcinfo->req_len = sizeof(pfwinfo->rpt_fbtc_gpio_dbg.finfo.v7);
 			fwsubver->fcxgpiodbg = pfwinfo->rpt_fbtc_gpio_dbg.finfo.v7.fver;
Signature · 1 line
2.25.1
author maintainer
#6 lore raw

PATCH 5/15 wifi: rtw89: coex: support fcxtdma version 8 in TDMA policy

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

RTL8922A and RTL8922D firmware sets fcxtdma to 8, which shares the same TLV encoding as version 7. Extend the _append_tdma condition to accept version 8 so the TDMA policy is sent correctly for these chips.

Also enable the TDMA and CYCLE report types unconditionally in _set_fw_report_map so the firmware sends cycle statistics the driver relies on for coexistence decision-making.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/coex.c +3 -1
index 62b86dc40e87..3a5219fcc7b9 100644
@@ -2719,7 +2719,7 @@ static void _append_tdma(struct rtw89_dev *rtwdev)
 		tlv->len = sizeof(*v);
 		*v = dm->tdma;
 		btc->policy_len += BTC_TLV_HDR_LEN + sizeof(*v);
-	} else if (ver->fcxtdma == 7 || ver->fcxtdma == 4) {
+	} else if (ver->fcxtdma == 4 || ver->fcxtdma == 7 || ver->fcxtdma == 8) {
 		tlv_v7 = (struct rtw89_btc_btf_tlv_v7 *)&btc->policy[len];
 		tlv_v7->len = sizeof(dm->tdma);
 		tlv_v7->ver = ver->fcxtdma;
@@ -6639,6 +6639,8 @@ static void _set_fw_report_map(struct rtw89_dev *rtwdev)
 		return;
 	}
 
+	rpt_map |= rtw89_btc_fw_rpt_ver(rtwdev, RPT_EN_TDMA);
+	rpt_map |= rtw89_btc_fw_rpt_ver(rtwdev, RPT_EN_CYCLE);
 	rpt_map |= rtw89_btc_fw_rpt_ver(rtwdev, RPT_EN_MREG);
 
 	bitmap = rtw89_btc_fw_rpt_ver(rtwdev, RPT_EN_BT_SCAN_INFO);
Signature · 1 line
2.25.1
author maintainer
#7 lore raw

PATCH 6/15 wifi: rtw89: coex: add fcxcysta v8 report support

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

The firmware introduces coexistence cycle statistics report version 8 (fcxcysta v8). The v8 struct layout diverges from v7: it adds a per-slot WL RX error ratio array, a new CXBCN_BT_PROTECT_OK beacon counter, and extended slot step time tracking. Because of these layout differences, the v7 and v8 parsing paths in _chk_btc_report are now separate branches rather than sharing one handler.

The v8 error-checking path adds hang detection for E2G, W1, and B1 slot counts in addition to the BT_SLOT_FLOOD and CYCLE_HANG checks carried over from v7. A dedicated _show_fbtc_cysta_v8 display function is added to expose the new fields through the debugfs coex dump.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 199 ++++++++++++++++++++++
 drivers/net/wireless/realtek/rtw89/core.h |  26 +++
 2 files changed, 225 insertions(+)
drivers/net/wireless/realtek/rtw89/coex.c +199 -0
index 3a5219fcc7b9..785060acf508 100644
@@ -1841,6 +1841,11 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 			pcysta->v7 = pfwinfo->rpt_fbtc_cysta.finfo.v7;
 			pcinfo->req_len = sizeof(pfwinfo->rpt_fbtc_cysta.finfo.v7);
 			fwsubver->fcxcysta = pfwinfo->rpt_fbtc_cysta.finfo.v7.fver;
+		} else if (ver->fcxcysta == 8) {
+			pfinfo = &pfwinfo->rpt_fbtc_cysta.finfo.v8;
+			pcysta->v8 = pfwinfo->rpt_fbtc_cysta.finfo.v8;
+			pcinfo->req_len = sizeof(pfwinfo->rpt_fbtc_cysta.finfo.v8);
+			fwsubver->fcxcysta = pfwinfo->rpt_fbtc_cysta.finfo.v8.fver;
 		} else {
 			goto err;
 		}
@@ -2628,6 +2633,49 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 				     le16_to_cpu(pcysta->v7.cycles));
 			_chk_btc_err(rtwdev, BTC_DCNT_CYCLE_HANG,
 				     le16_to_cpu(pcysta->v7.cycles));
+		} else if (ver->fcxcysta == 8) {
+			if (dm->fddt_train == BTC_FDDT_ENABLE)
+				break;
+
+			pcysta = &pfwinfo->rpt_fbtc_cysta.finfo;
+
+			if (dm->tdma_now.type != CXTDMA_OFF) {
+				val16 = le16_to_cpu(pcysta->v8.cycle_time.tavg[CXT_WL]);
+				_chk_btc_err(rtwdev, BTC_DCNT_WL_SLOT_DRIFT, val16);
+
+				val1 = le32_to_cpu(pcysta->v8.leak_slot.cnt_rximr) *
+				       BTC_LEAK_AP_TH;
+				val2 = le16_to_cpu(pcysta->v8.slot_cnt[CXST_LK]);
+
+				val16 = le16_to_cpu(pcysta->v8.cycles);
+				if (dm->tdma_now.rxflctrl &&
+				    val16 >= BTC_CYSTA_CHK_PERIOD && val1 > val2)
+					dm->leak_ap = 1;
+			} else if (dm->tdma_now.ext_ctrl == CXECTL_EXT) {
+				val16 = le16_to_cpu(pcysta->v8.cycle_time.tavg[CXT_BT]);
+				_chk_btc_err(rtwdev, BTC_DCNT_BT_SLOT_DRIFT, val16);
+
+				val1 = le16_to_cpu(pcysta->v8.a2dp_ept.cnt_timeout) *
+				       BTC_SLOT_REQ_TH;
+				val2 = le16_to_cpu(pcysta->v8.a2dp_ept.cnt);
+
+				val16 = le16_to_cpu(pcysta->v8.cycles);
+				if (val16 >= BTC_CYSTA_CHK_PERIOD && val1 > val2)
+					dm->slot_req_more = 1;
+				else if (bt->link_info.status.map.connect == 0)
+					dm->slot_req_more = 0;
+			}
+
+			_chk_btc_err(rtwdev, BTC_DCNT_E2G_HANG,
+				     le16_to_cpu(pcysta->v8.slot_cnt[CXST_E2G]));
+			_chk_btc_err(rtwdev, BTC_DCNT_W1_HANG,
+				     le16_to_cpu(pcysta->v8.slot_cnt[CXST_W1]));
+			_chk_btc_err(rtwdev, BTC_DCNT_B1_HANG,
+				     le16_to_cpu(pcysta->v8.slot_cnt[CXST_B1]));
+			_chk_btc_err(rtwdev, BTC_DCNT_BT_SLOT_FLOOD,
+				     le16_to_cpu(pcysta->v8.cycles));
+			_chk_btc_err(rtwdev, BTC_DCNT_CYCLE_HANG,
+				     le16_to_cpu(pcysta->v8.cycles));
 		} else {
 			goto err;
 		}
@@ -10710,6 +10758,10 @@ static int _show_error(struct rtw89_dev *rtwdev, char *buf, size_t bufsz)
 		pcysta->v7 = pfwinfo->rpt_fbtc_cysta.finfo.v7;
 		except_cnt = pcysta->v7.except_cnt;
 		exception_map = le32_to_cpu(pcysta->v7.except_map);
+	} else if (ver->fcxcysta == 8) {
+		pcysta->v8 = pfwinfo->rpt_fbtc_cysta.finfo.v8;
+		except_cnt = pcysta->v8.except_cnt;
+		exception_map = le32_to_cpu(pcysta->v8.except_map);
 	} else {
 		return 0;
 	}
@@ -11652,6 +11704,151 @@ static int _show_fbtc_cysta_v7(struct rtw89_dev *rtwdev, char *buf, size_t bufsz
 	return p - buf;
 }
 
+static int _show_fbtc_cysta_v8(struct rtw89_dev *rtwdev, char *buf, size_t bufsz)
+{
+	struct rtw89_btc_bt_info *bt = &rtwdev->btc.cx.bt0;
+	struct rtw89_btc_bt_a2dp_desc *a2dp = &bt->link_info.a2dp_desc;
+	struct rtw89_btc_btf_fwinfo *pfwinfo = &rtwdev->btc.fwinfo;
+	struct rtw89_btc_fbtc_cysta_v8 *pcysta = NULL;
+	struct rtw89_btc_dm *dm = &rtwdev->btc.dm;
+	struct rtw89_btc_rpt_cmn_info *pcinfo;
+	char *p = buf, *end = buf + bufsz;
+	u16 cycle, c_begin, c_end, s_id;
+	u8 i, cnt = 0, divide_cnt;
+	u8 slot_pair;
+
+	pcinfo = &pfwinfo->rpt_fbtc_cysta.cinfo;
+	if (!pcinfo->valid)
+		return 0;
+
+	pcysta = &pfwinfo->rpt_fbtc_cysta.finfo.v8;
+	p += scnprintf(p, end - p, "\n %-15s : cycle:%d", "[slot_stat]",
+		       le16_to_cpu(pcysta->cycles));
+
+	for (i = 0; i < CXST_MAX; i++) {
+		if (!le16_to_cpu(pcysta->slot_cnt[i]))
+			continue;
+		p += scnprintf(p, end - p, ", %s:%d",
+			       id_to_slot(i),
+			       le16_to_cpu(pcysta->slot_cnt[i]));
+	}
+
+	if (dm->tdma_now.rxflctrl)
+		p += scnprintf(p, end - p, ", leak_rx:%d",
+			       le32_to_cpu(pcysta->leak_slot.cnt_rximr));
+
+	if (pcysta->collision_cnt)
+		p += scnprintf(p, end - p, ", collision:%d",
+			       pcysta->collision_cnt);
+
+	if (pcysta->skip_cnt)
+		p += scnprintf(p, end - p, ", skip:%d",
+			       le16_to_cpu(pcysta->skip_cnt));
+
+	p += scnprintf(p, end - p,
+		       "\n %-15s : avg_t[wl:%d/bt:%d/lk:%d.%03d]",
+		       "[cycle_stat]",
+		       le16_to_cpu(pcysta->cycle_time.tavg[CXT_WL]),
+		       le16_to_cpu(pcysta->cycle_time.tavg[CXT_BT]),
+		       le16_to_cpu(pcysta->leak_slot.tavg) / 1000,
+		       le16_to_cpu(pcysta->leak_slot.tavg) % 1000);
+	p += scnprintf(p, end - p,
+		       ", max_t[wl:%d/bt:%d(>%dms:%d)/lk:%d.%03d]",
+		       le16_to_cpu(pcysta->cycle_time.tmax[CXT_WL]),
+		       le16_to_cpu(pcysta->cycle_time.tmax[CXT_BT]),
+		       dm->bt_slot_flood, dm->cnt_dm[BTC_DCNT_BT_SLOT_FLOOD],
+		       le16_to_cpu(pcysta->leak_slot.tamx) / 1000,
+		       le16_to_cpu(pcysta->leak_slot.tamx) % 1000);
+	p += scnprintf(p, end - p, ", bcn[all:%d/ok:%d/in_bt:%d/in_bt_ok:%d]",
+		       le16_to_cpu(pcysta->bcn_cnt[CXBCN_ALL]),
+		       le16_to_cpu(pcysta->bcn_cnt[CXBCN_ALL_OK]),
+		       le16_to_cpu(pcysta->bcn_cnt[CXBCN_BT_SLOT]),
+		       le16_to_cpu(pcysta->bcn_cnt[CXBCN_BT_OK]));
+
+	if (a2dp->exist) {
+		p += scnprintf(p, end - p,
+			       "\n %-15s : a2dp_ept:%d, a2dp_late:%d(streak 2S:%d/max:%d)",
+			       "[a2dp_stat]",
+			       le16_to_cpu(pcysta->a2dp_ept.cnt),
+			       le16_to_cpu(pcysta->a2dp_ept.cnt_timeout),
+			       a2dp->no_empty_streak_2s,
+			       a2dp->no_empty_streak_max);
+
+		p += scnprintf(p, end - p, ", avg_t:%d, max_t:%d",
+			       le16_to_cpu(pcysta->a2dp_ept.tavg),
+			       le16_to_cpu(pcysta->a2dp_ept.tmax));
+	}
+
+	if (le16_to_cpu(pcysta->cycles) <= 1)
+		goto out;
+
+	slot_pair = BTC_CYCLE_SLOT_MAX / 2;
+
+	if (le16_to_cpu(pcysta->cycles) <= slot_pair)
+		c_begin = 1;
+	else
+		c_begin = le16_to_cpu(pcysta->cycles) - slot_pair + 1;
+
+	c_end = le16_to_cpu(pcysta->cycles);
+
+	if (a2dp->exist)
+		divide_cnt = 2;
+	else
+		divide_cnt = 6;
+
+	if (c_begin > c_end)
+		goto out;
+
+	for (cycle = c_begin; cycle <= c_end; cycle++) {
+		cnt++;
+		s_id = ((cycle - 1) % slot_pair) * 2;
+
+		if (cnt % divide_cnt == 1) {
+			if (a2dp->exist)
+				p += scnprintf(p, end - p, "\n %-15s : ",
+					       "[slotT_wermtan]");
+			else
+				p += scnprintf(p, end - p, "\n %-15s : ",
+					       "[slotT_rxerr]");
+		}
+
+		p += scnprintf(p, end - p, "->b%d",
+			       le16_to_cpu(pcysta->slot_step_time[s_id]));
+
+		if (a2dp->exist)
+			p += scnprintf(p, end - p, "(%d/%d/%d/%dM/%d/%d/%d)",
+				       pcysta->wl_rx_err_ratio[s_id],
+				       pcysta->a2dp_trx[s_id].empty_cnt,
+				       pcysta->a2dp_trx[s_id].retry_cnt,
+				       (pcysta->a2dp_trx[s_id].tx_rate ? 3 : 2),
+				       pcysta->a2dp_trx[s_id].tx_cnt,
+				       pcysta->a2dp_trx[s_id].ack_cnt,
+				       pcysta->a2dp_trx[s_id].nack_cnt);
+		else
+			p += scnprintf(p, end - p, "(%d)",
+				       pcysta->wl_rx_err_ratio[s_id]);
+
+		p += scnprintf(p, end - p, "->w%d",
+			       le16_to_cpu(pcysta->slot_step_time[s_id + 1]));
+
+		if (a2dp->exist)
+			p += scnprintf(p, end - p, "(%d/%d/%d/%dM/%d/%d/%d)",
+				       pcysta->wl_rx_err_ratio[s_id + 1],
+				       pcysta->a2dp_trx[s_id + 1].empty_cnt,
+				       pcysta->a2dp_trx[s_id + 1].retry_cnt,
+				       (pcysta->a2dp_trx[s_id + 1].tx_rate ? 3 : 2),
+				       pcysta->a2dp_trx[s_id + 1].tx_cnt,
+				       pcysta->a2dp_trx[s_id + 1].ack_cnt,
+				       pcysta->a2dp_trx[s_id + 1].nack_cnt);
+		else
+			p += scnprintf(p, end - p, "(%d)",
+				       pcysta->wl_rx_err_ratio[s_id + 1]);
+	}
+
+out:
+	return p - buf;
+}
+
 static int _show_fbtc_nullsta(struct rtw89_dev *rtwdev, char *buf, size_t bufsz)
 {
 	struct rtw89_btc *btc = &rtwdev->btc;
@@ -11901,6 +12098,8 @@ static int _show_fw_dm_msg(struct rtw89_dev *rtwdev, char *buf, size_t bufsz)
 		p += _show_fbtc_cysta_v105(rtwdev, p, end - p);
 	else if (ver->fcxcysta == 7)
 		p += _show_fbtc_cysta_v7(rtwdev, p, end - p);
+	else if (ver->fcxcysta == 8)
+		p += _show_fbtc_cysta_v8(rtwdev, p, end - p);
 
 	p += _show_fbtc_nullsta(rtwdev, p, end - p);
 
drivers/net/wireless/realtek/rtw89/core.h +26 -0
index 2e6d1be3a751..d1678a8b5872 100644
@@ -3665,6 +3665,31 @@ struct rtw89_btc_fbtc_cysta_v7 { /* statistics for cycles */
 	__le32 except_map;
 } __packed;
 
+struct rtw89_btc_fbtc_cysta_v8 { /* statistics for cycles */
+	u8 fver;
+	u8 rsvd;
+	u8 collision_cnt; /* counter for event/timer at the same time */
+	u8 except_cnt;
+
+	u8 wl_rx_err_ratio[BTC_CYCLE_SLOT_MAX];
+
+	struct rtw89_btc_fbtc_a2dp_trx_stat_v4 a2dp_trx[BTC_CYCLE_SLOT_MAX];
+
+	__le16 skip_cnt;
+	__le16 cycles; /* total cycle number */
+	__le16 rsvd1;
+
+	__le16 slot_step_time[BTC_CYCLE_SLOT_MAX]; /* record the wl/bt slot time */
+	__le16 slot_cnt[CXST_MAX]; /* slot count */
+	__le16 bcn_cnt[5]; /* CXBCN_BT_PROTECT_OK added in v8 */
+
+	struct rtw89_btc_fbtc_cycle_time_info_v5 cycle_time;
+	struct rtw89_btc_fbtc_cycle_a2dp_empty_info a2dp_ept;
+	struct rtw89_btc_fbtc_cycle_leak_info_v7 leak_slot;
+
+	__le32 except_map;
+} __packed;
+
 union rtw89_btc_fbtc_cysta_info {
 	struct rtw89_btc_fbtc_cysta_v2 v2;
 	struct rtw89_btc_fbtc_cysta_v3 v3;
@@ -3672,6 +3697,7 @@ union rtw89_btc_fbtc_cysta_info {
 	struct rtw89_btc_fbtc_cysta_v5 v5;
 	struct rtw89_btc_fbtc_cysta_v105 v105;
 	struct rtw89_btc_fbtc_cysta_v7 v7;
+	struct rtw89_btc_fbtc_cysta_v8 v8;
 };
 
 struct rtw89_btc_fbtc_cynullsta_v1 { /* cycle null statistics */
Signature · 1 line
2.25.1
author maintainer
#8 lore raw

PATCH 7/15 wifi: rtw89: coex: route BT sub-reports by bt_id for dual-BT support

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

RTL8922D supports dual BT (BT0 + BT1). The C2H report structs for fcxbtscan_v8 and fcxbtdevinfo carry a bt_id field that indicates which BT device sent the report; without routing the data always landed in bt0, silently dropping BT1 information.

fcxbtscan_v8: the existing code used a local 'tbt' for the scan array copy but then wrote scan_info_update to the outer 'bt' (always bt0). Reassign 'bt' from bt_id so the update flag reaches the correct device.

fcxbtdevinfo_v8: no bt_id routing existed at all. In v8 the rsvd byte carries bt_id; add a version check and redirect 'a2dp' to the selected device's a2dp descriptor.

btver_v8 and btafh_v8 already route correctly and are untouched.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/wireless/realtek/rtw89/coex.c +6 -3
index 785060acf508..2513af4d727c 100644
@@ -1591,11 +1591,10 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo)
 		} else if (ver->fcxbtscan == 8) {
 			struct rtw89_btc_fbtc_btscan_v8 *pscan_v8 =
 				(struct rtw89_btc_fbtc_btscan_v8 *)pfinfo;
-			struct rtw89_btc_bt_info *tbt =
-				pscan_v8->bt_id ? &btc->cx.bt1 : &btc->cx.bt0;
 
+			bt = pscan_v8->bt_id ? &btc->cx.bt1 : &btc->cx.bt0;
 			for (i = 0; i < CXSCAN_MAX; i++) {
-				tbt->scan_info_v2[i] = pscan_v8->para[i];
+				bt->scan_info_v2[i] = pscan_v8->para[i];
 				if ((pscan_v8->type & BIT(i)) &&
 				    pscan_v8->para[i].win == 0 &&
 				    pscan_v8->para[i].intvl == 0)
@@ -1653,6 +1652,10 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo)
 		break;
 	case BTC_RPT_TYPE_BT_DEVICE:
 		pdev = (struct rtw89_btc_fbtc_btdevinfo *)pfinfo;
+		if (ver->fcxbtdevinfo == 8) {
+			bt = pdev->rsvd ? &btc->cx.bt1 : &btc->cx.bt0;
+			a2dp = &bt->link_info.a2dp_desc;
+		}
 		a2dp->device_name = le32_to_cpu(pdev->dev_name);
 		a2dp->vendor_id = le16_to_cpu(pdev->vendor_id);
 		a2dp->flush_time = le32_to_cpu(pdev->flush_time);
Signature · 1 line
2.25.1
author maintainer
#9 lore raw

PATCH 8/15 wifi: rtw89: coex: split bt_profile into per-device fields in trx H2C

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

Rename bt_profile/rsvd2 to bt0_profile/bt1_profile in the DM trx_info struct and all three trx H2C structs (v7/v9/v107) to match the firmware interface for dual-BT devices.

Previously _update_bt_info() wrote all BT devices' profile maps into a single bt_profile field, so the last device to report overwrote the first. The firmware received bt1_profile as zero at all times because rsvd2 was never updated.

Fix _update_bt_info() to assign bt0_profile when bid==BTC_BT_1ST and bt1_profile otherwise, so the firmware H2C correctly reflects each BT device's active profiles independently.

---
 drivers/net/wireless/realtek/rtw89/coex.c |  7 ++++++-
 drivers/net/wireless/realtek/rtw89/core.h |  4 ++--
 drivers/net/wireless/realtek/rtw89/fw.c   | 12 ++++++------
 drivers/net/wireless/realtek/rtw89/fw.h   | 12 ++++++------
 4 files changed, 20 insertions(+), 15 deletions(-)
drivers/net/wireless/realtek/rtw89/coex.c +6 -1
index 2513af4d727c..b7b06b28009e 100644
@@ -9129,7 +9129,12 @@ static void _update_bt_info(struct rtw89_dev *rtwdev, u8 bid, u8 *buf, u32 len)
 	a2dp->exist = btinfo.lb2.a2dp;
 	pan->exist = btinfo.lb2.pan;
 	_update_bt_link_cnt(rtwdev, bt, is_bt_56g);
-	btc->dm.trx_info.bt_profile = u32_get_bits(btinfo.val, BT_PROFILE_PROTOCOL_MASK);
+	if (bid == BTC_BT_1ST)
+		btc->dm.trx_info.bt0_profile =
+			u32_get_bits(btinfo.val, BT_PROFILE_PROTOCOL_MASK);
+	else
+		btc->dm.trx_info.bt1_profile =
+			u32_get_bits(btinfo.val, BT_PROFILE_PROTOCOL_MASK);
 
 	/* parse raw info low-Byte3 */
 	btinfo.val = raw_info[BTC_BTINFO_L3];
drivers/net/wireless/realtek/rtw89/core.h +2 -2
index d1678a8b5872..7fee587a8162 100644
@@ -3840,8 +3840,8 @@ struct rtw89_btc_trx_info {
 
 	u8 cn; /* condition_num */
 	s8 nhm;
-	u8 bt_profile;
-	u8 rsvd2;
+	u8 bt0_profile;
+	u8 bt1_profile;
 
 	u16 tx_rate;
 	u16 rx_rate;
drivers/net/wireless/realtek/rtw89/fw.c +6 -6
index 63dd918b0989..33eb09e56f95 100644
@@ -7223,8 +7223,8 @@ int rtw89_fw_h2c_cxdrv_trx_v7(struct rtw89_dev *rtwdev, u8 type)
 	h2c->v7_u8.zb_rx_gain = trx->zb_rx_gain[BTC_BT_1ST];
 	h2c->v7_u8.cn = trx->cn;
 	h2c->v7_u8.nhm = trx->nhm;
-	h2c->v7_u8.bt_profile = trx->bt_profile;
-	h2c->v7_u8.rsvd2 = trx->rsvd2;
+	h2c->v7_u8.bt0_profile = trx->bt0_profile;
+	h2c->v7_u8.bt1_profile = trx->bt1_profile;
 	h2c->v7_le.tx_rate = cpu_to_le16(trx->tx_rate);
 	h2c->v7_le.rx_rate = cpu_to_le16(trx->rx_rate);
 	h2c->v7_le.tx_tp = cpu_to_le32(trx->tx_tp);
@@ -7290,8 +7290,8 @@ int rtw89_fw_h2c_cxdrv_trx_v9(struct rtw89_dev *rtwdev, u8 type)
 	}
 	h2c->v9_u8.cn = trx->cn;
 	h2c->v9_u8.nhm = trx->nhm;
-	h2c->v9_u8.bt_profile = trx->bt_profile;
-	h2c->v9_u8.rsvd2 = trx->rsvd2;
+	h2c->v9_u8.bt0_profile = trx->bt0_profile;
+	h2c->v9_u8.bt1_profile = trx->bt1_profile;
 	h2c->v9_le.tx_rate = cpu_to_le16(trx->tx_rate);
 	h2c->v9_le.rx_rate = cpu_to_le16(trx->rx_rate);
 	h2c->v9_le.tx_tp = cpu_to_le32(trx->tx_tp);
@@ -7348,8 +7348,8 @@ int rtw89_fw_h2c_cxdrv_trx_v107(struct rtw89_dev *rtwdev, u8 type)
 	h2c->v107_u8.bt_rx_gain = trx->bt_rx_gain[BTC_BT_1ST];
 	h2c->v107_u8.cn = trx->cn;
 	h2c->v107_u8.nhm = trx->nhm;
-	h2c->v107_u8.bt_profile = trx->bt_profile;
-	h2c->v107_u8.rsvd2 = trx->rsvd2;
+	h2c->v107_u8.bt0_profile = trx->bt0_profile;
+	h2c->v107_u8.bt1_profile = trx->bt1_profile;
 	h2c->v7_le.tx_rate = cpu_to_le16(trx->tx_rate);
 	h2c->v7_le.rx_rate = cpu_to_le16(trx->rx_rate);
 	h2c->v7_le.tx_tp = cpu_to_le32(trx->tx_tp);
drivers/net/wireless/realtek/rtw89/fw.h +6 -6
index a15a5967cabc..294399bf57b1 100644
@@ -2553,8 +2553,8 @@ struct rtw89_btc_trx_info_u8 {
 
 	u8 cn; /* condition_num */
 	s8 nhm;
-	u8 bt_profile;
-	u8 rsvd2;
+	u8 bt0_profile;
+	u8 bt1_profile;
 } __packed;
 
 struct rtw89_btc_trx_info_v7_u8 {
@@ -2572,8 +2572,8 @@ struct rtw89_btc_trx_info_v7_u8 {
 
 	u8 cn;
 	s8 nhm;
-	u8 bt_profile;
-	u8 rsvd2;
+	u8 bt0_profile;
+	u8 bt1_profile;
 } __packed;
 
 struct rtw89_btc_trx_info_v107_u8 {
@@ -2589,8 +2589,8 @@ struct rtw89_btc_trx_info_v107_u8 {
 
 	u8 cn;
 	s8 nhm;
-	u8 bt_profile;
-	u8 rsvd2;
+	u8 bt0_profile;
+	u8 bt1_profile;
 } __packed;
 
 struct rtw89_btc_trx_info_le {
Signature · 1 line
2.25.1
author maintainer
#10 lore raw

PATCH 9/15 wifi: rtw89: coex: add fcxtxpwr version dispatch for CXDRVINFO_TXPWR

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

Some firmware sends the TXPWR H2C with a version that differs from the one implied by fcxtrx. Add a dedicated fcxtxpwr field to rtw89_btc_ver so the TXPWR H2C version can be chosen independently. It defaults to 0, keeping every existing chip on the fcxtrx-based selection, and is set to 1 for the firmware that expects the versioned H2C: RTL8922A 0.35.111.0 and RTL8922D 0.35.94.0 and later.

The ver=1 TXPWR H2C shares the rtw89_h2c_cxtxpwr_v9 layout and only differs in the header version, so let rtw89_fw_h2c_cxtxpwr_v9() take the version as an argument instead of adding a near-identical function. Update the CXDRVINFO_TXPWR dispatch to send ver=1 when fcxtxpwr is set before falling through to the fcxtrx-based selection.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 52 ++++++++++++-----------
 drivers/net/wireless/realtek/rtw89/core.h |  1 +
 drivers/net/wireless/realtek/rtw89/fw.c   |  6 +--
 drivers/net/wireless/realtek/rtw89/fw.h   |  2 +-
 4 files changed, 32 insertions(+), 29 deletions(-)
drivers/net/wireless/realtek/rtw89/coex.c +27 -25
index b7b06b28009e..1fb4a7176179 100644
@@ -140,7 +140,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 10,   .frptmap = 5,    .fcxctrl = 9,  .fcxinit = 11,
 	 .fwevntrptl = 1, .fwc2hfunc = 4, .drvinfo_ver = 3, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 6,   .fcxmlo = 2,   .bt_desired = 8,
-	 .fcxtrx = 9,
+	 .fcxtrx = 9,     .fcxtxpwr = 1,
 	},
 	{RTL8922D, RTW89_FW_VER_CODE(0, 35, 94, 0),
 	 .fcxbtcrpt = 11, .fcxtdma = 8,    .fcxslots = 7, .fcxcysta = 8,
@@ -149,7 +149,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 10,    .frptmap = 5,    .fcxctrl = 9,  .fcxinit = 10,
 	 .fwevntrptl = 1,  .fwc2hfunc = 4, .drvinfo_ver = 3, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 6,   .fcxmlo = 2,   .bt_desired = 8,
-	 .fcxtrx = 9,
+	 .fcxtrx = 9,     .fcxtxpwr = 1,
 	},
 	{RTL8852BT, RTW89_FW_VER_CODE(0, 29, 133, 0),
 	 .fcxbtcrpt = 9, .fcxtdma = 7,    .fcxslots = 7, .fcxcysta = 7,
@@ -158,7 +158,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 7,   .frptmap = 5,    .fcxctrl = 7,  .fcxinit = 107,
 	 .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 103, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 8,
-	 .fcxtrx = 107,
+	 .fcxtrx = 107,  .fcxtxpwr = 0,
 	},
 	{RTL8852BT, RTW89_FW_VER_CODE(0, 29, 122, 0),
 	 .fcxbtcrpt = 8, .fcxtdma = 7,    .fcxslots = 7, .fcxcysta = 7,
@@ -167,7 +167,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 7,   .frptmap = 3,    .fcxctrl = 7,  .fcxinit = 7,
 	 .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 1, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 8,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852BT, RTW89_FW_VER_CODE(0, 29, 90, 0),
 	 .fcxbtcrpt = 7, .fcxtdma = 7,    .fcxslots = 7, .fcxcysta = 7,
@@ -176,7 +176,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 7,   .frptmap = 3,    .fcxctrl = 7,  .fcxinit = 7,
 	 .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 1, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 8,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8922A, RTW89_FW_VER_CODE(0, 35, 111, 0),
 	 .fcxbtcrpt = 11, .fcxtdma = 8,    .fcxslots = 7, .fcxcysta = 8,
@@ -185,7 +185,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 10,   .frptmap = 5,    .fcxctrl = 9,  .fcxinit = 11,
 	 .fwevntrptl = 1, .fwc2hfunc = 4, .drvinfo_ver = 3, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 6,   .fcxmlo = 2,   .bt_desired = 8,
-	 .fcxtrx = 9,
+	 .fcxtrx = 9,     .fcxtxpwr = 1,
 	},
 	{RTL8922A, RTW89_FW_VER_CODE(0, 35, 71, 0),
 	 .fcxbtcrpt = 8, .fcxtdma = 7,    .fcxslots = 7, .fcxcysta = 7,
@@ -194,7 +194,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 8,   .frptmap = 4,    .fcxctrl = 7,  .fcxinit = 7,
 	 .fwevntrptl = 1, .fwc2hfunc = 3, .drvinfo_ver = 3, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 1,  .fcxmlo = 1,   .bt_desired = 9,
-	 .fcxtrx = 7,
+	 .fcxtrx = 7,    .fcxtxpwr = 0,
 	},
 	{RTL8922A, RTW89_FW_VER_CODE(0, 35, 63, 0),
 	 .fcxbtcrpt = 8, .fcxtdma = 7,    .fcxslots = 7, .fcxcysta = 7,
@@ -203,7 +203,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 8,   .frptmap = 4,    .fcxctrl = 7,  .fcxinit = 7,
 	 .fwevntrptl = 1, .fwc2hfunc = 3, .drvinfo_ver = 2, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 1,  .fcxmlo = 1,   .bt_desired = 9,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8922A, RTW89_FW_VER_CODE(0, 35, 8, 0),
 	 .fcxbtcrpt = 8, .fcxtdma = 7,    .fcxslots = 7, .fcxcysta = 7,
@@ -212,7 +212,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 8,   .frptmap = 3,    .fcxctrl = 7,  .fcxinit = 7,
 	 .fwevntrptl = 1, .fwc2hfunc = 1, .drvinfo_ver = 1, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8851B, RTW89_FW_VER_CODE(0, 29, 133, 0),
 	 .fcxbtcrpt = 9, .fcxtdma = 7,    .fcxslots = 7, .fcxcysta = 7,
@@ -221,7 +221,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 7,   .frptmap = 5,    .fcxctrl = 7,  .fcxinit = 107,
 	 .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 103, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 8,
-	 .fcxtrx = 107,
+	 .fcxtrx = 107,  .fcxtxpwr = 0,
 	},
 	{RTL8851B, RTW89_FW_VER_CODE(0, 29, 29, 0),
 	 .fcxbtcrpt = 105, .fcxtdma = 3,    .fcxslots = 1, .fcxcysta = 5,
@@ -230,7 +230,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 2,   .frptmap = 3,    .fcxctrl = 1,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852C, RTW89_FW_VER_CODE(0, 27, 97, 0),
 	 .fcxbtcrpt = 4, .fcxtdma = 4,    .fcxslots = 2, .fcxcysta = 105,
@@ -239,7 +239,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 101, .frptmap = 3,    .fcxctrl = 1,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280,
 	 .max_role_num = 5, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 107,
+	 .fcxtrx = 107,  .fcxtxpwr = 0,
 	},
 	{RTL8852C, RTW89_FW_VER_CODE(0, 27, 57, 0),
 	 .fcxbtcrpt = 4, .fcxtdma = 3,    .fcxslots = 1, .fcxcysta = 3,
@@ -248,7 +248,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 1,   .frptmap = 3,    .fcxctrl = 1,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280,
 	 .max_role_num = 5, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852C, RTW89_FW_VER_CODE(0, 27, 42, 0),
 	 .fcxbtcrpt = 4, .fcxtdma = 3,    .fcxslots = 1, .fcxcysta = 3,
@@ -257,7 +257,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 1,   .frptmap = 2,    .fcxctrl = 1,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280,
 	 .max_role_num = 5, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852C, RTW89_FW_VER_CODE(0, 27, 0, 0),
 	 .fcxbtcrpt = 4, .fcxtdma = 3,    .fcxslots = 1, .fcxcysta = 3,
@@ -266,7 +266,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 1,   .frptmap = 2,    .fcxctrl = 1,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280,
 	 .max_role_num = 5, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852B, RTW89_FW_VER_CODE(0, 29, 133, 0),
 	 .fcxbtcrpt = 9, .fcxtdma = 7,    .fcxslots = 7, .fcxcysta = 7,
@@ -275,7 +275,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 7,   .frptmap = 105,  .fcxctrl = 7,  .fcxinit = 107,
 	 .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 103, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 8,
-	 .fcxtrx = 107,
+	 .fcxtrx = 107,  .fcxtxpwr = 0,
 	},
 	{RTL8852B, RTW89_FW_VER_CODE(0, 29, 122, 0),
 	 .fcxbtcrpt = 8, .fcxtdma = 7,    .fcxslots = 7, .fcxcysta = 7,
@@ -284,7 +284,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 7,   .frptmap = 3,    .fcxctrl = 7,  .fcxinit = 7,
 	 .fwevntrptl = 1, .fwc2hfunc = 2, .drvinfo_ver = 1, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 8,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852B, RTW89_FW_VER_CODE(0, 29, 29, 0),
 	 .fcxbtcrpt = 105, .fcxtdma = 3,  .fcxslots = 1, .fcxcysta = 5,
@@ -293,7 +293,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 2,   .frptmap = 3,    .fcxctrl = 1,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852B, RTW89_FW_VER_CODE(0, 29, 14, 0),
 	 .fcxbtcrpt = 5, .fcxtdma = 3,    .fcxslots = 1, .fcxcysta = 4,
@@ -302,7 +302,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 1,   .frptmap = 3,    .fcxctrl = 1,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1800,
 	 .max_role_num = 6, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852B, RTW89_FW_VER_CODE(0, 27, 0, 0),
 	 .fcxbtcrpt = 4, .fcxtdma = 3,    .fcxslots = 1, .fcxcysta = 3,
@@ -311,7 +311,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 1,   .frptmap = 1,    .fcxctrl = 1,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1280,
 	 .max_role_num = 5, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852A, RTW89_FW_VER_CODE(0, 13, 37, 0),
 	 .fcxbtcrpt = 4, .fcxtdma = 3,    .fcxslots = 1, .fcxcysta = 3,
@@ -320,7 +320,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 1,   .frptmap = 3,    .fcxctrl = 1,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 0, .drvinfo_ver = 0, .info_buf = 1280,
 	 .max_role_num = 5, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 	{RTL8852A, RTW89_FW_VER_CODE(0, 13, 0, 0),
 	 .fcxbtcrpt = 1, .fcxtdma = 1,    .fcxslots = 1, .fcxcysta = 2,
@@ -329,7 +329,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 0,   .frptmap = 0,    .fcxctrl = 0,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 0, .drvinfo_ver = 0, .info_buf = 1024,
 	 .max_role_num = 5, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 
 	/* keep it to be the last as default entry */
@@ -340,7 +340,7 @@ static const struct rtw89_btc_ver rtw89_btc_ver_defs[] = {
 	 .fwlrole = 0,   .frptmap = 0,    .fcxctrl = 0,  .fcxinit = 0,
 	 .fwevntrptl = 0, .fwc2hfunc = 1, .drvinfo_ver = 0, .info_buf = 1024,
 	 .max_role_num = 5, .fcxosi = 0,  .fcxmlo = 0,   .bt_desired = 7,
-	 .fcxtrx = 0,
+	 .fcxtrx = 0,    .fcxtxpwr = 0,
 	},
 };
 
@@ -3589,10 +3589,12 @@ static void _fw_set_drv_info(struct rtw89_dev *rtwdev, u8 index)
 		if (ver->drvinfo_ver == 3 || ver->drvinfo_ver == 103)
 			index = 4;
 
-		if (ver->fcxtrx == 7 || ver->fcxtrx == 107)
+		if (ver->fcxtxpwr == 1)
+			rtw89_fw_h2c_cxtxpwr_v9(rtwdev, index, 1);
+		else if (ver->fcxtrx == 7 || ver->fcxtrx == 107)
 			rtw89_fw_h2c_cxtxpwr_v7(rtwdev, index);
 		else if (ver->fcxtrx == 9)
-			rtw89_fw_h2c_cxtxpwr_v9(rtwdev, index);
+			rtw89_fw_h2c_cxtxpwr_v9(rtwdev, index, 9);
 		break;
 	case CXDRVINFO_FDDT:
 		if (ver->drvinfo_ver == 3 || ver->drvinfo_ver == 103)
drivers/net/wireless/realtek/rtw89/core.h +1 -0
index 7fee587a8162..57fa1ce080dd 100644
@@ -4390,6 +4390,7 @@ struct rtw89_btc_ver {
 	u8 fcxmlo;
 	u8 bt_desired;
 	u8 fcxtrx;
+	u8 fcxtxpwr;
 };
 
 struct rtw89_btc_btf_fwinfo {
drivers/net/wireless/realtek/rtw89/fw.c +3 -3
index 33eb09e56f95..5b33bdb5a3e8 100644
@@ -7458,7 +7458,7 @@ int rtw89_fw_h2c_cxtxpwr_v7(struct rtw89_dev *rtwdev, u8 type)
 	return ret;
 }
 
-int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type)
+int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type, u8 ver)
 {
 	struct rtw89_btc *btc = &rtwdev->btc;
 	struct rtw89_btc_dm *dm = &btc->dm;
@@ -7470,14 +7470,14 @@ int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type)
 
 	skb = rtw89_fw_h2c_alloc_skb_with_hdr(rtwdev, len);
 	if (!skb) {
-		rtw89_err(rtwdev, "failed to alloc skb for h2c cxdrv_ctrl\n");
+		rtw89_err(rtwdev, "failed to alloc skb for h2c cxtxpwr\n");
 		return -ENOMEM;
 	}
 	skb_put(skb, len);
 	h2c = (struct rtw89_h2c_cxtxpwr_v9 *)skb->data;
 
 	h2c->hdr.type = type;
-	h2c->hdr.ver = 9;
+	h2c->hdr.ver = ver;
 	h2c->hdr.len = sizeof(*h2c) - H2C_LEN_CXDRVHDR_V7;
 	if (dm->wl_tx_pwr_phy_map == BIT(RTW89_PHY_1))
 		h2c->pwr = rp.wl_tx_power[RTW89_PHY_1] & 0xff;
drivers/net/wireless/realtek/rtw89/fw.h +1 -1
index 294399bf57b1..5df3bb97249a 100644
@@ -5538,7 +5538,7 @@ int rtw89_fw_h2c_cxdrv_trx_v9(struct rtw89_dev *rtwdev, u8 type);
 int rtw89_fw_h2c_cxdrv_trx_v107(struct rtw89_dev *rtwdev, u8 type);
 int rtw89_fw_h2c_cxdrv_rfk(struct rtw89_dev *rtwdev, u8 type);
 int rtw89_fw_h2c_cxtxpwr_v7(struct rtw89_dev *rtwdev, u8 type);
-int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type);
+int rtw89_fw_h2c_cxtxpwr_v9(struct rtw89_dev *rtwdev, u8 type, u8 ver);
 int rtw89_fw_h2c_del_pkt_offload(struct rtw89_dev *rtwdev, u8 id);
 int rtw89_fw_h2c_add_pkt_offload(struct rtw89_dev *rtwdev, u8 *id,
 				 struct sk_buff *skb_ofld);
Signature · 1 line
2.25.1
author maintainer
#11 lore raw

PATCH 10/15 wifi: rtw89: coex: set dbcc_en for dual-band-active MLO modes

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

The 1+1, 2+2 and legacy DBCC link modes are inherently active on both hardware bands, but the multi-link update path left dbcc_en untouched for these modes, so it retained a stale value from a previous update and the coexistence logic could act on the wrong DBCC state.

Set dbcc_en directly in that branch, matching the single-band-active modes that already clear it explicitly.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wireless/realtek/rtw89/coex.c +2 -0
index 1fb4a7176179..7ee0bd441f7a 100644
@@ -7454,6 +7454,8 @@ static void _update_wl_mlo_info(struct rtw89_dev *rtwdev, u8 hw_band)
 			wl_rinfo->pta_req_band = RTW89_MAC_0;
 			wl_rinfo->dbcc_2g_phy = RTW89_PHY_0;
 		}
+
+		wl_rinfo->dbcc_en = 1; /* two HW-band both active */
 		break;
 	}
 
Signature · 1 line
2.25.1
author maintainer
#12 lore raw

PATCH 11/15 wifi: rtw89: coex: evaluate CO-RX Hi-LNA request per band

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

The CO-RX Hi-LNA request for the 2.4 GHz and 5/6 GHz bands was merged into a single scoreboard write gated by a combined condition. Once a co-rx band went away, for example after a 2.4 GHz disconnect, the write for the remaining band no longer covered the vanished band, so its Hi-LNA request stayed latched and could never be cleared to zero.

Evaluate and write each band's Hi-LNA request independently against the BT-mirrored state, so the request for a band is cleared as soon as that band stops being co-rx.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 29 ++++++++++++++---------
 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/net/wireless/realtek/rtw89/coex.c +18 -11
index 7ee0bd441f7a..f2cf5bdf65c7 100644
@@ -4051,8 +4051,8 @@ static void _set_bt_corx_table(struct rtw89_dev *rtwdev, bool en)
 	struct rtw89_btc_cx *cx = &btc->cx;
 	struct rtw89_btc_bt_info *bt = &cx->bt0;
 	struct rtw89_btc_dm *dm = &btc->dm;
-	u8 is_24g, is_56g, i;
-	u32 scbd_bit;
+	bool is_24g, is_56g, en_24g, en_56g;
+	u8 i;
 
 	/*
 	 * true: bt use Hi-LNA rx gain table (f/e/3/2) in -3x~-9xdBm for co-rx
@@ -4063,7 +4063,6 @@ static void _set_bt_corx_table(struct rtw89_dev *rtwdev, bool en)
 		return;
 
 	for (i = BTC_BT_1ST; i <= BTC_BT_2ND; i++) {
-		scbd_bit = 0;
 		if (i == BTC_BT_2ND) {
 			if (!(rtwdev->chip->para_ver & BTC_FEAT_DUAL_BT))
 				continue;
@@ -4074,14 +4073,22 @@ static void _set_bt_corx_table(struct rtw89_dev *rtwdev, bool en)
 			  dm->corx_map[BTC_RF_S1][i]) & BIT(RTW89_BAND_2G);
 		is_56g = (dm->corx_map[BTC_RF_S0][i] ||
 			  dm->corx_map[BTC_RF_S1][i]) & BIT(RTW89_BAND_5G);
-		if (is_24g)
-			scbd_bit |= BTC_WSCB_BT_HILNA;
-		if (is_56g)
-			scbd_bit |= BTC_WSCB_BT_HILNA_56G;
-
-		if ((is_24g && (en != (!!bt->hi_lna_rx))) ||
-		    (is_56g && (en != (!!bt->hi_lna_rx_6g))))
-			_write_scbd(rtwdev, i, scbd_bit, en);
+
+		/*
+		 * Request Hi-LNA only when that band is co-rx and enabled.
+		 * Evaluate each band bit independently against the BT-mirrored
+		 * state so the request can still be cleared once a CO-RX band
+		 * disappears (e.g. 2.4 GHz disconnect), avoiding a latched
+		 * Hi-LNA request.
+		 */
+		en_24g = is_24g && en;
+		en_56g = is_56g && en;
+
+		if (en_24g != (!!bt->hi_lna_rx))
+			_write_scbd(rtwdev, i, BTC_WSCB_BT_HILNA, en_24g);
+
+		if (en_56g != (!!bt->hi_lna_rx_6g))
+			_write_scbd(rtwdev, i, BTC_WSCB_BT_HILNA_56G, en_56g);
 	}
 }
 
Signature · 1 line
2.25.1
author maintainer
#13 lore raw

PATCH 12/15 wifi: rtw89: coex: detect BT HID activity from scoreboard

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

The BT scoreboard reports HID activity on a dedicated bit, but the driver only mirrored the A2DP, PAN and HFP activity bits into the BT link info. HID was therefore never marked present, so coexistence decisions that depend on an active HID device treated it as absent.

Read the HID activity bit alongside the other profile bits so that an active HID link is reflected in the BT link state.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wireless/realtek/rtw89/coex.c +2 -0
index f2cf5bdf65c7..2392883df528 100644
@@ -517,6 +517,7 @@ enum btc_b2w_scoreboard {
 	BTC_BSCB_BT_CONNECT_56G = BIT(17),
 	BTC_BSCB_BT_LNAB0_56G = BIT(18),
 	BTC_BSCB_BT_LNAB1_56G = BIT(19),
+	BTC_BSCB_HID_ACT = BIT(23),
 	BTC_BSCB_BT_15DOT4 = BIT(24),
 	BTC_BSCB_BT_PROTECT = BIT(27),
 	BTC_BSCB_PAN_ACT = BIT(28),
@@ -7955,6 +7956,7 @@ static void _update_bt_scbd(struct rtw89_dev *rtwdev, u8 bid)
 		bt_2g->a2dp_desc.exist = !!(val & BTC_BSCB_A2DP_ACT);
 		bt_2g->pan_desc.exist = !!(val & BTC_BSCB_PAN_ACT);
 		bt_2g->hfp_desc.exist = !!(val & BTC_BSCB_HFP_ACT);
+		bt_2g->hid_desc.exist = !!(val & BTC_BSCB_HID_ACT);
 
 		bt->lna_constrain = 4 + !!(val & BTC_BSCB_BT_LNAB0) +
 				    !!(val & BTC_BSCB_BT_LNAB1) * 2;
Signature · 1 line
2.25.1
author maintainer
#14 lore raw

PATCH 13/15 wifi: rtw89: coex: check null-tx fail ratio in nullsta report

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

Add a BTC_DCNT_NULL_TX_FAIL error check driven from the nullsta (fcxnullsta) report. When such a report is handled, _chk_btc_report() now invokes _chk_btc_err() for BTC_RPT_TYPE_NULLSTA.

The check reads the null-1 slot TX count, late count and ok count from the report, handling both fcxnullsta v7 and v2 layouts, and only evaluates once at least BTC_NULLTX_CHK_PERIOD (100) null-tx attempts have accumulated. A late-to-ok ratio worse than BTC_NULLTX_FAIL_TH (8) increments the fail counter while a healthy ratio resets it, and the null1_tx_late error flag is raised once the counter reaches BTC_CHK_HANG_MAX consecutive periods. The check is skipped while FDDT training is active.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 39 +++++++++++++++++++++++
 1 file changed, 39 insertions(+)
drivers/net/wireless/realtek/rtw89/coex.c +39 -0
index 2392883df528..f88431a0db87 100644
@@ -1317,14 +1317,19 @@ static void _get_reg_status(struct rtw89_dev *rtwdev, u8 type, u8 *val)
 #define BTC_CHK_WLSLOT_DRIFT_MAX 15
 #define BTC_CHK_BTSLOT_DRIFT_MAX 15
 #define BTC_CHK_HANG_MAX 3
+#define BTC_NULLTX_CHK_PERIOD 100
+#define BTC_NULLTX_FAIL_TH 8
 
 static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt)
 {
 	struct rtw89_btc *btc = &rtwdev->btc;
+	union rtw89_btc_fbtc_cynullsta_info *ns = &btc->fwinfo.rpt_fbtc_nullsta.finfo;
 	struct rtw89_btc_cx *cx = &btc->cx;
 	struct rtw89_btc_bt_info *bt = &cx->bt0;
 	struct rtw89_btc_wl_info *wl = &cx->wl;
 	struct rtw89_btc_dm *dm = &btc->dm;
+	const struct rtw89_btc_ver *ver = btc->ver;
+	u32 tx_cnt, late, ok;
 
 	rtw89_debug(rtwdev, RTW89_DBG_BTC,
 		    "[BTC], %s(): type:%d cnt:%d\n",
@@ -1514,6 +1519,37 @@ static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt)
 		else
 			dm->error.map.w2b_scbd_no_sync = false;
 		break;
+	case BTC_DCNT_NULL_TX_FAIL:
+		if (dm->fddt_train)
+			break;
+
+		if (ver->fcxnullsta == 7) {
+			ok = le32_to_cpu(ns->v7.result[1][1]);
+			late = le32_to_cpu(ns->v7.result[1][2]);
+			tx_cnt = le32_to_cpu(ns->v7.result[1][4]);
+		} else if (ver->fcxnullsta == 2) {
+			ok = le32_to_cpu(ns->v2.result[1][1]);
+			late = le32_to_cpu(ns->v2.result[1][2]);
+			tx_cnt = le32_to_cpu(ns->v2.result[1][4]);
+		} else if (ver->fcxnullsta == 1) {
+			ok = le32_to_cpu(ns->v1.result[1][1]);
+			late = le32_to_cpu(ns->v1.result[1][2]);
+			tx_cnt = 0;
+		} else {
+			break;
+		}
+
+		if (tx_cnt < BTC_NULLTX_CHK_PERIOD)
+			break;
+
+		if (late * BTC_NULLTX_FAIL_TH > ok)
+			dm->cnt_dm[BTC_DCNT_NULL_TX_FAIL]++;
+		else
+			dm->cnt_dm[BTC_DCNT_NULL_TX_FAIL] = 0;
+
+		dm->error.map.null1_tx_late =
+			dm->cnt_dm[BTC_DCNT_NULL_TX_FAIL] >= BTC_CHK_HANG_MAX;
+		break;
 	}
 }
 
@@ -2684,6 +2720,9 @@ static u32 _chk_btc_report(struct rtw89_dev *rtwdev,
 			goto err;
 		}
 		break;
+	case BTC_RPT_TYPE_NULLSTA:
+		_chk_btc_err(rtwdev, BTC_DCNT_NULL_TX_FAIL, 0);
+		break;
 	case BTC_RPT_TYPE_MREG:
 		if (ver->fcxmreg == 7)
 			break;
Signature · 1 line
2.25.1
author maintainer
#15 lore raw

PATCH 14/15 wifi: rtw89: coex: detect BT slot flood via A2DP empty-streak in cysta

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

Add a BTC_DCNT_BT_SLOT_FLOOD error check driven from the cysta (fcxcysta v7) report. It walks the most recent TDMA cycles, bounded to one BTC_CYCLE_SLOT_MAX window of wl/bt slot pairs, and is only evaluated in AUTO/AUTO2 or ext-control TDMA modes once enough cycles have accumulated; otherwise the counters and error flag are cleared.

For each cycle the BT slot step time is compared against the dm->bt_slot_flood threshold, increasing BTC_DCNT_BT_SLOT_FLOOD and raising the bt_slot_flood error flag when BT monopolises the medium. In the same pass the run of consecutive slots with no A2DP empty count is measured and stored in the a2dp descriptor as no_empty_streak_2s, with the running maximum kept in no_empty_streak_max.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 51 +++++++++++++++++++++++
 1 file changed, 51 insertions(+)
drivers/net/wireless/realtek/rtw89/coex.c +51 -0
index f88431a0db87..7cced933688b 100644
@@ -1324,11 +1324,15 @@ static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt)
 {
 	struct rtw89_btc *btc = &rtwdev->btc;
 	union rtw89_btc_fbtc_cynullsta_info *ns = &btc->fwinfo.rpt_fbtc_nullsta.finfo;
+	union rtw89_btc_fbtc_cysta_info *pcysta = &btc->fwinfo.rpt_fbtc_cysta.finfo;
 	struct rtw89_btc_cx *cx = &btc->cx;
 	struct rtw89_btc_bt_info *bt = &cx->bt0;
+	struct rtw89_btc_bt_a2dp_desc *a2dp = &bt->link_info.a2dp_desc;
 	struct rtw89_btc_wl_info *wl = &cx->wl;
 	struct rtw89_btc_dm *dm = &btc->dm;
 	const struct rtw89_btc_ver *ver = btc->ver;
+	u32 empty_streak = 0, empty_streak_max = 0;
+	u32 slot_pair, c_begin, c_end, cycle, s_id;
 	u32 tx_cnt, late, ok;
 
 	rtw89_debug(rtwdev, RTW89_DBG_BTC,
@@ -1485,6 +1489,53 @@ static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt)
 			dm->error.map.bt_slot_drift = false;
 
 		break;
+	case BTC_DCNT_BT_SLOT_FLOOD:
+		if (!btc->fwinfo.rpt_fbtc_cysta.cinfo.valid ||
+		    dm->cnt_dm[BTC_DCNT_CYCLE] == cnt)
+			break;
+
+		if (cnt < BTC_CYCLE_SLOT_MAX ||
+		    (dm->tdma_now.type != CXTDMA_AUTO &&
+		     dm->tdma_now.type != CXTDMA_AUTO2 &&
+		     dm->tdma_now.ext_ctrl != CXECTL_EXT)) {
+			dm->error.map.bt_slot_flood = false;
+			dm->cnt_dm[BTC_DCNT_BT_SLOT_FLOOD] = 0;
+			a2dp->no_empty_streak_2s = 0;
+			a2dp->no_empty_streak_max = 0;
+			break;
+		}
+
+		/* 1 cycle = 1 wl-slot + 1 bt-slot */
+		slot_pair = BTC_CYCLE_SLOT_MAX / 2;
+		if (cnt - dm->cnt_dm[BTC_DCNT_CYCLE] > slot_pair)
+			c_begin = cnt - slot_pair + 1;
+		else
+			c_begin = dm->cnt_dm[BTC_DCNT_CYCLE] + 1;
+
+		c_end = cnt;
+		for (cycle = c_begin; cycle <= c_end; cycle++) {
+			s_id = ((cycle - 1) % slot_pair) * 2;
+			if (le16_to_cpu(pcysta->v7.slot_step_time[s_id]) >=
+			    dm->bt_slot_flood)
+				dm->cnt_dm[BTC_DCNT_BT_SLOT_FLOOD]++;
+			/* calculate no-A2DP-empty streak count */
+			if (pcysta->v7.a2dp_trx[s_id].empty_cnt == 0 &&
+			    pcysta->v7.a2dp_trx[s_id + 1].empty_cnt == 0) {
+				empty_streak++;
+				if (empty_streak > empty_streak_max)
+					empty_streak_max = empty_streak;
+			} else {
+				empty_streak = 0;
+			}
+		}
+
+		a2dp->no_empty_streak_2s = empty_streak_max;
+		if (a2dp->no_empty_streak_2s > a2dp->no_empty_streak_max)
+			a2dp->no_empty_streak_max = a2dp->no_empty_streak_2s;
+
+		dm->error.map.bt_slot_flood =
+			!!dm->cnt_dm[BTC_DCNT_BT_SLOT_FLOOD];
+		break;
 	case BTC_DCNT_WL_STA_NTFY:
 		cnt = dm->cnt_notify[BTC_NCNT_WL_STA] -
 		      dm->cnt_notify[BTC_NCNT_WL_STA_LAST];
Signature · 1 line
2.25.1
author maintainer
#16 lore raw

PATCH 15/15 wifi: rtw89: coex: add AFH conflict detection on BT AFH report

In reply to Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

Extend the BTC_RPT_TYPE_BT_AFH handler to detect overlap between the BT AFH channel map and the WL 2.4 GHz channels in use. On each legacy AFH map update the legacy conflict counter and error flag are reset and the AFH update counter is advanced, then the 12-byte legacy AFH map is scanned against wl->ch_map[] to count conflicting and total channels and set the bt_afh_conflict error flag. The LE path mirrors this: on each LE map update the LE conflict counter and error flag are reset and the LE update counter advanced, then the 5-byte LE AFH map is scanned against wl->ch_map_le[] to set the bt_leafh_conflict error flag.

Both checks are gated by afh_en (WL 2.4 GHz AFH active) and by BT connection state (legacy: connect, LE: ble_connect or leaudio BIS/CIS). They are applied in all versioned branches (fcxbtafh 2/7/8) via a shared helper; fcxbtafh==1 has no map_type field, so conflict detection is skipped there.

---
 drivers/net/wireless/realtek/rtw89/coex.c | 66 +++++++++++++++++++++++
 1 file changed, 66 insertions(+)
drivers/net/wireless/realtek/rtw89/coex.c +66 -0
index 7cced933688b..305d8edb0d4d 100644
@@ -1604,6 +1604,69 @@ static void _chk_btc_err(struct rtw89_dev *rtwdev, u8 type, u32 cnt)
 	}
 }
 
+static void _update_bt_afh_conflict(struct rtw89_dev *rtwdev,
+				    struct rtw89_btc_bt_info *bt,
+				    u8 map_type)
+{
+	struct rtw89_btc *btc = &rtwdev->btc;
+	struct rtw89_btc_wl_info *wl = &btc->cx.wl;
+	struct rtw89_btc_dm *dm = &btc->dm;
+	struct rtw89_btc_bt_link_info *b = &bt->link_info;
+	struct rtw89_btc_bt_leaudio_desc *leaudio = &b->leaudio_desc;
+	u8 hw_band = wl->role_info.pta_req_band;
+	u32 cnt, cnt_ch, cnt_le, cnt_ch_le;
+	u8 i, omap, xmap, afh_en;
+
+	if (map_type & RPT_BT_AFH_SEQ_LEGACY) {
+		bt->bcnt[BTC_BCNT_AFH_UPDATE]++;
+		bt->bcnt[BTC_BCNT_AFH_CONFLICT] = 0;
+		dm->error.map.bt_afh_conflict = 0;
+	}
+
+	afh_en = wl->afh_info[hw_band][RTW89_BAND_2G].en;
+
+	for (i = 0; i < 12; i++) {
+		if (!(map_type & RPT_BT_AFH_SEQ_LEGACY) ||
+		    !b->status.map.connect)
+			break;
+
+		omap = b->afh_map[i];
+		xmap = omap & wl->ch_map[i];
+		cnt_ch = hweight8(omap);
+		cnt = afh_en ? hweight8(xmap) : 0;
+
+		if (i == 11) {
+			bt->bcnt[BTC_BCNT_AFH_CHN] = cnt_ch;
+			bt->bcnt[BTC_BCNT_AFH_CONFLICT] = cnt;
+			dm->error.map.bt_afh_conflict = !!cnt;
+		}
+	}
+
+	if (map_type & RPT_BT_AFH_SEQ_LE) {
+		bt->bcnt[BTC_BCNT_AFH_LE_UPDATE]++;
+		bt->bcnt[BTC_BCNT_AFH_LE_CONFLICT] = 0;
+		dm->error.map.bt_leafh_conflict = 0;
+	}
+
+	for (i = 0; i < 5; i++) {
+		if (!(map_type & RPT_BT_AFH_SEQ_LE) ||
+		    (!b->status.map.ble_connect &&
+		     !leaudio->bis_exist && !leaudio->cis_exist))
+			break;
+
+		omap = b->afh_map_le[i];
+		xmap = omap & wl->ch_map_le[i];
+		cnt_ch_le = hweight8(omap);
+		cnt_le = afh_en ? hweight8(xmap) : 0;
+
+		if (i == 4) {
+			bt->bcnt[BTC_BCNT_AFH_LE_CHN] = cnt_ch_le;
+			bt->bcnt[BTC_BCNT_AFH_LE_CONFLICT] = cnt_le;
+			dm->error.map.bt_leafh_conflict = !!cnt_le;
+		}
+	}
+}
+
 static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo)
 {
 	struct rtw89_btc *btc = &rtwdev->btc;
@@ -1704,6 +1767,7 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo)
 				memcpy(&bt_linfo->afh_map_le[0], pafh_v2->afh_le_a, 4);
 				memcpy(&bt_linfo->afh_map_le[4], pafh_v2->afh_le_b, 1);
 			}
+			_update_bt_afh_conflict(rtwdev, bt, pafh_v2->map_type);
 		} else if (ver->fcxbtafh == 7) {
 			pafh_v7 = (struct rtw89_btc_fbtc_btafh_v7 *)pfinfo;
 			if (pafh_v7->map_type & RPT_BT_AFH_SEQ_LEGACY) {
@@ -1715,6 +1779,7 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo)
 				memcpy(&bt_linfo->afh_map_le[0], pafh_v7->afh_le_a, 4);
 				memcpy(&bt_linfo->afh_map_le[4], pafh_v7->afh_le_b, 1);
 			}
+			_update_bt_afh_conflict(rtwdev, bt, pafh_v7->map_type);
 		} else if (ver->fcxbtafh == 8) {
 			struct rtw89_btc_fbtc_btafh_v8 *pafh_v8 =
 				(struct rtw89_btc_fbtc_btafh_v8 *)pfinfo;
@@ -1731,6 +1796,7 @@ static void _update_bt_report(struct rtw89_dev *rtwdev, u8 rpt_type, u8 *pfinfo)
 				memcpy(&tbt_linfo->afh_map_le[0], pafh_v8->afh_le_a, 4);
 				memcpy(&tbt_linfo->afh_map_le[4], pafh_v8->afh_le_b, 1);
 			}
+			_update_bt_afh_conflict(rtwdev, tbt, pafh_v8->map_type);
 		} else if (ver->fcxbtafh == 1) {
 			pafh_v1 = (struct rtw89_btc_fbtc_btafh *)pfinfo;
 			memcpy(&bt_linfo->afh_map[0], pafh_v1->afh_l, 4);
Signature · 1 line
2.25.1
author maintainer
#2 lore raw

Re: [PATCH rtw-next 01/15] wifi: rtw89: coex: fix SET_H2C_MACRO not sent for BTC_FEAT_H2C_MACRO chips

In reply to Ping-Ke Shih
Quoted 11 lines · Ping-Ke Shih

From: Ching-Te Ku <[email protected]>

For chips with BTC_FEAT_H2C_MACRO (e.g. RTL8922D), _send_fw_cmd buffers each BTC H2C command as a TLV entry into hbuf, then falls through to the shared rtw89_fw_h2c_raw_with_hdr call. The else- branch was missing the reassignment of h2c_func, buf, and len to SET_H2C_MACRO and hbuf before that shared send, causing each command to be delivered directly rather than through the MAC FW macro mechanism 8922D requires. Add the three assignments and reset hbuf after the macro is sent.

Quoted 2 lines

15 patch(es) applied to rtw-next branch of rtw.git, thanks.

a4eb406f1705 wifi: rtw89: coex: fix SET_H2C_MACRO not sent for BTC_FEAT_H2C_MACRO chips 0a53612e780c wifi: rtw89: coex: fix out-of-bounds read of report gnt_val 4b639de3bd85 wifi: rtw89: coex: fix rlink index bound check in _update_wl_info f9ce5e528df7 wifi: rtw89: coex: support version 8 for gpio_dbg FCX report 78aec73b9b9d wifi: rtw89: coex: support fcxtdma version 8 in TDMA policy 62edaf91541e wifi: rtw89: coex: add fcxcysta v8 report support d5a10f34689c wifi: rtw89: coex: route BT sub-reports by bt_id for dual-BT support d5f8a5e443a1 wifi: rtw89: coex: split bt_profile into per-device fields in trx H2C a8cdddb20b27 wifi: rtw89: coex: add fcxtxpwr version dispatch for CXDRVINFO_TXPWR 6e8e123df1d8 wifi: rtw89: coex: set dbcc_en for dual-band-active MLO modes b53e6acb7048 wifi: rtw89: coex: evaluate CO-RX Hi-LNA request per band 98ded88f18c0 wifi: rtw89: coex: detect BT HID activity from scoreboard 87abb9b102a4 wifi: rtw89: coex: check null-tx fail ratio in nullsta report c84836d628ed wifi: rtw89: coex: detect BT slot flood via A2DP empty-streak in cysta b55b58d9178b wifi: rtw89: coex: add AFH conflict detection on BT AFH report

---
https://github.com/pkshih/rtw.git