Skip to contentSkip to conversation

wifi: rtw89: fix and generalize TSF functions

PATCH In review Ping-Ke Shih 2 participants 5 messages Jan 19, 2023 – Feb 13, 2023 Realtek wireless driver (rtw89)

lore
Share & tools
lore

Ping-Ke Shih

author maintainer
#0 lore raw

cover wifi: rtw89: fix and generalize TSF functions

For multiple VIF, we need to organize TSF to make interfaces operate properly, as well as time slot of BT coexistence mechanism. Normally, we only handle to avoid issuing conflicts of beacon in AP mode (or GO). So, use this patchset to prepare things for MCC.

Zong-Zhe Yang (3):
wifi: rtw89: correct unit for port offset and refine macro
wifi: rtw89: split out generic part of rtw89_mac_port_tsf_sync()
wifi: rtw89: mac: add function to get TSF

 drivers/net/wireless/realtek/rtw89/mac.c | 51 +++++++++++++++++++-----
 drivers/net/wireless/realtek/rtw89/mac.h | 17 +++++++-
 2 files changed, 56 insertions(+), 12 deletions(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH 1/3 wifi: rtw89: correct unit for port offset and refine macro

From: Zong-Zhe Yang <[email protected]>

Strictly speaking, the unit of the offset should be TU instead of ms. So, correct it and the macro for calculation. Then, to make the macro generic, the factor n is moved outside.

---
 drivers/net/wireless/realtek/rtw89/mac.c | 4 +++-
 drivers/net/wireless/realtek/rtw89/mac.h | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw89/mac.c +3 -1
index 5ab0590485e0d..ea34b4df21a75 100644
@@ -3930,10 +3930,12 @@ static void rtw89_mac_port_tsf_sync(struct rtw89_dev *rtwdev,
 
 	/* adjust offset randomly to avoid beacon conflict */
 	offset = offset - offset / 4 + get_random_u32() % (offset / 2);
-	val = RTW89_PORT_OFFSET_MS_TO_32US((*n_offset)++, offset);
+	val = (*n_offset) * RTW89_PORT_OFFSET_TU_TO_32US(offset);
 	reg = rtw89_mac_reg_by_idx(R_AX_PORT0_TSF_SYNC + rtwvif->port * 4,
 				   rtwvif->mac_idx);
 
+	(*n_offset)++;
+
 	rtw89_write32_mask(rtwdev, reg, B_AX_SYNC_PORT_SRC, rtwvif_src->port);
 	rtw89_write32_mask(rtwdev, reg, B_AX_SYNC_PORT_OFFSET_VAL, val);
 	rtw89_write32_set(rtwdev, reg, B_AX_SYNC_NOW);
drivers/net/wireless/realtek/rtw89/mac.h +1 -1
index f0b684b205f10..2556271597441 100644
@@ -168,7 +168,7 @@ enum rtw89_mac_ax_l0_to_l1_event {
 	MAC_AX_L0_TO_L1_EVENT_MAX = 15,
 };
 
-#define RTW89_PORT_OFFSET_MS_TO_32US(n, shift_ms) ((n) * (shift_ms) * 1000 / 32)
+#define RTW89_PORT_OFFSET_TU_TO_32US(shift_tu) ((shift_tu) * 1024 / 32)
 
 enum rtw89_mac_dbg_port_sel {
 	/* CMAC 0 related */
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/3] wifi: rtw89: correct unit for port offset and refine macro

Quoted 8 lines · Ping-Ke Shih

From: Zong-Zhe Yang <[email protected]>

Strictly speaking, the unit of the offset should be TU instead of ms. So, correct it and the macro for calculation. Then, to make the macro generic, the factor n is moved outside.

3 patches applied to wireless-next.git, thanks.

1120e6a6c5cd wifi: rtw89: correct unit for port offset and refine macro 42db7edd5c05 wifi: rtw89: split out generic part of rtw89_mac_port_tsf_sync() 76f478a34daf wifi: rtw89: mac: add function to get TSF

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
author maintainer
#3 lore raw

PATCH 2/3 wifi: rtw89: split out generic part of rtw89_mac_port_tsf_sync()

In reply to Ping-Ke Shih

From: Zong-Zhe Yang <[email protected]>

Originally, rtw89_mac_port_tsf_sync() contains randomization logic internally. However, not all situation, we need the randomization. So, split out the generic part from it. And, make the full logic of original one contained in rtw89_mac_port_tsf_sync_rand(). It will still be used by its original caller as before. Then, the generic one will be used in MCC (multi-channel concurrency) management flow. MCC will implement its logic to decide the offset for TSF sync.

---
 drivers/net/wireless/realtek/rtw89/mac.c | 33 +++++++++++++++---------
 drivers/net/wireless/realtek/rtw89/mac.h |  4 +++
 2 files changed, 25 insertions(+), 12 deletions(-)
drivers/net/wireless/realtek/rtw89/mac.c +21 -12
index ea34b4df21a75..c13edd33b1a48 100644
@@ -3918,27 +3918,36 @@ static void rtw89_mac_port_cfg_tbtt_shift(struct rtw89_dev *rtwdev,
 				B_AX_TBTT_SHIFT_OFST_MASK, val);
 }
 
-static void rtw89_mac_port_tsf_sync(struct rtw89_dev *rtwdev,
-				    struct rtw89_vif *rtwvif,
-				    struct rtw89_vif *rtwvif_src, u8 offset,
-				    int *n_offset)
+void rtw89_mac_port_tsf_sync(struct rtw89_dev *rtwdev,
+			     struct rtw89_vif *rtwvif,
+			     struct rtw89_vif *rtwvif_src,
+			     u16 offset_tu)
 {
 	u32 val, reg;
 
+	val = RTW89_PORT_OFFSET_TU_TO_32US(offset_tu);
+	reg = rtw89_mac_reg_by_idx(R_AX_PORT0_TSF_SYNC + rtwvif->port * 4,
+				   rtwvif->mac_idx);
+
+	rtw89_write32_mask(rtwdev, reg, B_AX_SYNC_PORT_SRC, rtwvif_src->port);
+	rtw89_write32_mask(rtwdev, reg, B_AX_SYNC_PORT_OFFSET_VAL, val);
+	rtw89_write32_set(rtwdev, reg, B_AX_SYNC_NOW);
+}
+
+static void rtw89_mac_port_tsf_sync_rand(struct rtw89_dev *rtwdev,
+					 struct rtw89_vif *rtwvif,
+					 struct rtw89_vif *rtwvif_src,
+					 u8 offset, int *n_offset)
+{
 	if (rtwvif->net_type != RTW89_NET_TYPE_AP_MODE || rtwvif == rtwvif_src)
 		return;
 
 	/* adjust offset randomly to avoid beacon conflict */
 	offset = offset - offset / 4 + get_random_u32() % (offset / 2);
-	val = (*n_offset) * RTW89_PORT_OFFSET_TU_TO_32US(offset);
-	reg = rtw89_mac_reg_by_idx(R_AX_PORT0_TSF_SYNC + rtwvif->port * 4,
-				   rtwvif->mac_idx);
+	rtw89_mac_port_tsf_sync(rtwdev, rtwvif, rtwvif_src,
+				(*n_offset) * offset);
 
 	(*n_offset)++;
-
-	rtw89_write32_mask(rtwdev, reg, B_AX_SYNC_PORT_SRC, rtwvif_src->port);
-	rtw89_write32_mask(rtwdev, reg, B_AX_SYNC_PORT_OFFSET_VAL, val);
-	rtw89_write32_set(rtwdev, reg, B_AX_SYNC_NOW);
 }
 
 static void rtw89_mac_port_tsf_resync_all(struct rtw89_dev *rtwdev)
@@ -3960,7 +3969,7 @@ static void rtw89_mac_port_tsf_resync_all(struct rtw89_dev *rtwdev)
 	offset /= (vif_aps + 1);
 
 	rtw89_for_each_rtwvif(rtwdev, tmp)
-		rtw89_mac_port_tsf_sync(rtwdev, tmp, src, offset, &n_offset);
+		rtw89_mac_port_tsf_sync_rand(rtwdev, tmp, src, offset, &n_offset);
 }
 
 int rtw89_mac_vif_init(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif)
drivers/net/wireless/realtek/rtw89/mac.h +4 -0
index 2556271597441..4c50527aad61b 100644
@@ -906,6 +906,10 @@ int rtw89_mac_write_lte(struct rtw89_dev *rtwdev, const u32 offset, u32 val);
 int rtw89_mac_read_lte(struct rtw89_dev *rtwdev, const u32 offset, u32 *val);
 int rtw89_mac_add_vif(struct rtw89_dev *rtwdev, struct rtw89_vif *vif);
 int rtw89_mac_port_update(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif);
+void rtw89_mac_port_tsf_sync(struct rtw89_dev *rtwdev,
+			     struct rtw89_vif *rtwvif,
+			     struct rtw89_vif *rtwvif_src,
+			     u16 offset_tu);
 void rtw89_mac_set_he_obss_narrow_bw_ru(struct rtw89_dev *rtwdev,
 					struct ieee80211_vif *vif);
 void rtw89_mac_stop_ap(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif);
Signature · 1 line
2.25.1
author maintainer
#4 lore raw

PATCH 3/3 wifi: rtw89: mac: add function to get TSF

In reply to Ping-Ke Shih

From: Zong-Zhe Yang <[email protected]>

Add mac function rtw89_mac_port_get_tsf() to get TSF by port. It will be used when MCC (multi-channel concurrency) calculates timing things.

---
 drivers/net/wireless/realtek/rtw89/mac.c | 18 ++++++++++++++++++
 drivers/net/wireless/realtek/rtw89/mac.h | 11 +++++++++++
 2 files changed, 29 insertions(+)
drivers/net/wireless/realtek/rtw89/mac.c +18 -0
index c13edd33b1a48..9e73ef6f9bc6e 100644
@@ -4061,6 +4061,24 @@ int rtw89_mac_port_update(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif)
 	return 0;
 }
 
+int rtw89_mac_port_get_tsf(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif,
+			   u64 *tsf)
+{
+	const struct rtw89_port_reg *p = &rtw_port_base;
+	u32 tsf_low, tsf_high;
+	int ret;
+
+	ret = rtw89_mac_check_mac_en(rtwdev, rtwvif->mac_idx, RTW89_CMAC_SEL);
+	if (ret)
+		return ret;
+
+	tsf_low = rtw89_read32_port(rtwdev, rtwvif, p->tsftr_l);
+	tsf_high = rtw89_read32_port(rtwdev, rtwvif, p->tsftr_h);
+	*tsf = (u64)tsf_high << 32 | tsf_low;
+
+	return 0;
+}
+
 static void rtw89_mac_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
 						      struct cfg80211_bss *bss,
 						      void *data)
drivers/net/wireless/realtek/rtw89/mac.h +11 -0
index 4c50527aad61b..553b38a6d2c31 100644
@@ -827,6 +827,15 @@ static inline u32 rtw89_mac_reg_by_port(u32 base, u8 port, u8 mac_idx)
 	return rtw89_mac_reg_by_idx(base + port * 0x40, mac_idx);
 }
 
+static inline u32
+rtw89_read32_port(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif, u32 base)
+{
+	u32 reg;
+
+	reg = rtw89_mac_reg_by_port(base, rtwvif->port, rtwvif->mac_idx);
+	return rtw89_read32(rtwdev, reg);
+}
+
 static inline u32
 rtw89_read32_port_mask(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif,
 		       u32 base, u32 mask)
@@ -910,6 +919,8 @@ void rtw89_mac_port_tsf_sync(struct rtw89_dev *rtwdev,
 			     struct rtw89_vif *rtwvif,
 			     struct rtw89_vif *rtwvif_src,
 			     u16 offset_tu);
+int rtw89_mac_port_get_tsf(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif,
+			   u64 *tsf);
 void rtw89_mac_set_he_obss_narrow_bw_ru(struct rtw89_dev *rtwdev,
 					struct ieee80211_vif *vif);
 void rtw89_mac_stop_ap(struct rtw89_dev *rtwdev, struct rtw89_vif *rtwvif);
Signature · 1 line
2.25.1