Skip to contentSkip to conversation

rtw88: minor driver updates

PATCH In review [email protected] 4 participants 17 messages Oct 25, 2019 – Nov 1, 2019 1 message not in the archive Realtek wireless driver (rtw88)

lore
Share & tools
lore
#0 lore raw

cover rtw88: minor driver updates

From: Yan-Hsuan Chuang <[email protected]>

This patch set contains some minor driver updates including RFE type 3 for RTL8822BE.

Also refine the tables with proper struct instead of arrays.

Tzu-En Huang (1):
rtw88: fix potential read outside array boundary

Yan-Hsuan Chuang (5):
rtw88: 8822b: add RFE type 3 support
rtw88: use rtw_phy_pg_cfg_pair struct, not arrays
rtw88: use a module parameter to control LPS enter
rtw88: rearrange if..else statements for rx rate indexes
rtw88: avoid FW info flood

 drivers/net/wireless/realtek/rtw88/mac.c      |  17 -
 drivers/net/wireless/realtek/rtw88/main.c     |  17 +-
 drivers/net/wireless/realtek/rtw88/phy.c      |  32 +-
 drivers/net/wireless/realtek/rtw88/phy.h      |  18 +
 drivers/net/wireless/realtek/rtw88/ps.h       |   2 -
 drivers/net/wireless/realtek/rtw88/rtw8822b.c |   4 +-
 .../wireless/realtek/rtw88/rtw8822b_table.c   | 829 ++++++++++++++++--
 .../wireless/realtek/rtw88/rtw8822b_table.h   |   2 +
 drivers/net/wireless/realtek/rtw88/rtw8822c.c |   4 +-
 .../wireless/realtek/rtw88/rtw8822c_table.c   |  94 +-
 drivers/net/wireless/realtek/rtw88/rx.c       |  14 +-
 11 files changed, 838 insertions(+), 195 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/6 rtw88: 8822b: add RFE type 3 support

From: Yan-Hsuan Chuang <[email protected]>

Some of the modules use RFE type 3, add corresponding tables for them.

---
 drivers/net/wireless/realtek/rtw88/rtw8822b.c |   4 +-
 .../wireless/realtek/rtw88/rtw8822b_table.c   | 642 ++++++++++++++++++
 .../wireless/realtek/rtw88/rtw8822b_table.h   |   2 +
 3 files changed, 647 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw88/rtw8822b.c +3 -1
index 6f4e7326068c..9508a95dd1f7 100644
@@ -391,6 +391,7 @@ struct rtw8822b_rfe_info {
 
 static const struct rtw8822b_rfe_info rtw8822b_rfe_info[] = {
 	[2] = I2GE5G_CCUT(efem),
+	[3] = IFEM_EXT_CCUT(ifem),
 	[5] = IFEM_EXT_CCUT(ifem),
 };
 
@@ -664,7 +665,7 @@ static void rtw8822b_set_channel_bb(struct rtw_dev *rtwdev, u8 channel, u8 bw,
 
 		rtw_write32_mask(rtwdev, REG_ADC160, BIT(30), 0x1);
 
-		if (rfe_option == 2) {
+		if (rfe_option == 2 || rfe_option == 3) {
 			rtw_write32_mask(rtwdev, REG_L1PKWT, 0x0000f000, 0x6);
 			rtw_write32_mask(rtwdev, REG_ADC40, BIT(10), 0x1);
 		}
@@ -2041,6 +2042,7 @@ static struct rtw_intf_phy_para_table phy_para_table_8822b = {
 
 static const struct rtw_rfe_def rtw8822b_rfe_defs[] = {
 	[2] = RTW_DEF_RFE(8822b, 2, 2),
+	[3] = RTW_DEF_RFE(8822b, 3, 0),
 	[5] = RTW_DEF_RFE(8822b, 5, 5),
 };
 
drivers/net/wireless/realtek/rtw88/rtw8822b_table.c +642 -0

654 lines not on this page · raw message

drivers/net/wireless/realtek/rtw88/rtw8822b_table.h +2 -0
index d4c268889368..4140e1ccb7b1 100644
@@ -9,9 +9,11 @@ extern const struct rtw_table rtw8822b_mac_tbl;
 extern const struct rtw_table rtw8822b_agc_tbl;
 extern const struct rtw_table rtw8822b_bb_tbl;
 extern const struct rtw_table rtw8822b_bb_pg_type2_tbl;
+extern const struct rtw_table rtw8822b_bb_pg_type3_tbl;
 extern const struct rtw_table rtw8822b_bb_pg_type5_tbl;
 extern const struct rtw_table rtw8822b_rf_a_tbl;
 extern const struct rtw_table rtw8822b_rf_b_tbl;
+extern const struct rtw_table rtw8822b_txpwr_lmt_type0_tbl;
 extern const struct rtw_table rtw8822b_txpwr_lmt_type2_tbl;
 extern const struct rtw_table rtw8822b_txpwr_lmt_type5_tbl;
 
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/6] rtw88: 8822b: add RFE type 3 support

Quoted 7 lines · <[email protected]> wrote:

From: Yan-Hsuan Chuang <[email protected]>

Some of the modules use RFE type 3, add corresponding tables for them.

5 patches applied to wireless-drivers-next.git, thanks.

7436a470b583 rtw88: 8822b: add RFE type 3 support 0b8db87da541 rtw88: use rtw_phy_pg_cfg_pair struct, not arrays ff0dfe5b0377 rtw88: rearrange if..else statements for rx rate indexes 18a0696e85fd rtw88: fix potential read outside array boundary 5195b9042640 rtw88: avoid FW info flood

Signature · 3 lines
https://patchwork.kernel.org/patch/11211887/

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

PATCH 2/6 rtw88: use rtw_phy_pg_cfg_pair struct, not arrays

In reply to [email protected]

From: Yan-Hsuan Chuang <[email protected]>

Use proper struct for BB PG tables.

TODO: we need to find a way to store the tables that have
condition values.

---
 drivers/net/wireless/realtek/rtw88/phy.c      |  15 +-
 drivers/net/wireless/realtek/rtw88/phy.h      |   9 +
 .../wireless/realtek/rtw88/rtw8822b_table.c   | 283 +++++++++---------
 .../wireless/realtek/rtw88/rtw8822c_table.c   |  94 +++---
 4 files changed, 199 insertions(+), 202 deletions(-)
drivers/net/wireless/realtek/rtw88/phy.c +2 -13
index 69e7edb629f4..4a41134c420e 100644
@@ -20,15 +20,6 @@ union phy_table_tile {
 	struct phy_cfg_pair cfg;
 };
 
-struct phy_pg_cfg_pair {
-	u32 band;
-	u32 rf_path;
-	u32 tx_num;
-	u32 addr;
-	u32 bitmask;
-	u32 data;
-};
-
 static const u32 db_invert_table[12][8] = {
 	{10,		13,		16,		20,
 	 25,		32,		40,		50},
@@ -1226,10 +1217,8 @@ static void rtw_phy_store_tx_power_by_rate(struct rtw_dev *rtwdev,
 
 void rtw_parse_tbl_bb_pg(struct rtw_dev *rtwdev, const struct rtw_table *tbl)
 {
-	const struct phy_pg_cfg_pair *p = tbl->data;
-	const struct phy_pg_cfg_pair *end = p + tbl->size / 6;
-
-	BUILD_BUG_ON(sizeof(struct phy_pg_cfg_pair) != sizeof(u32) * 6);
+	const struct rtw_phy_pg_cfg_pair *p = tbl->data;
+	const struct rtw_phy_pg_cfg_pair *end = p + tbl->size;
 
 	for (; p < end; p++) {
 		if (p->addr == 0xfe || p->addr == 0xffe) {
drivers/net/wireless/realtek/rtw88/phy.h +9 -0
index 0dc7720aaad7..c389ef274ed8 100644
@@ -66,6 +66,15 @@ struct rtw_txpwr_lmt_cfg_pair {
 	s8 txpwr_lmt;
 };
 
+struct rtw_phy_pg_cfg_pair {
+	u32 band;
+	u32 rf_path;
+	u32 tx_num;
+	u32 addr;
+	u32 bitmask;
+	u32 data;
+};
+
 #define RTW_DECL_TABLE_PHY_COND_CORE(name, cfg, path)	\
 const struct rtw_table name ## _tbl = {			\
 	.data = name,					\
drivers/net/wireless/realtek/rtw88/rtw8822b_table.c +141 -142

297 lines not on this page · raw message

drivers/net/wireless/realtek/rtw88/rtw8822c_table.c +47 -47

100 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

PATCH 3/6 rtw88: use a module parameter to control LPS enter

In reply to [email protected]

From: Yan-Hsuan Chuang <[email protected]>

If the number of packets is less than the LPS threshold, driver can then enter LPS mode.
And driver used to take RTW_LPS_THRESHOLD as the threshold. As the macro can not be changed after compiled, use a parameter instead.

The larger of the threshold, the more traffic required to leave power save mode, responsive time could be longer, but also the power consumption could be lower.

---
 drivers/net/wireless/realtek/rtw88/main.c | 7 +++++--
 drivers/net/wireless/realtek/rtw88/ps.h   | 2 --
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/net/wireless/realtek/rtw88/main.c +5 -2
index 7c1b89c4fb6c..bff8a0b129d9 100644
@@ -16,16 +16,19 @@
 #include "debug.h"
 #include "bf.h"
 
+unsigned int rtw_lps_threshold = 2;
 unsigned int rtw_fw_lps_deep_mode;
 EXPORT_SYMBOL(rtw_fw_lps_deep_mode);
 bool rtw_bf_support = true;
 unsigned int rtw_debug_mask;
 EXPORT_SYMBOL(rtw_debug_mask);
 
+module_param_named(lps_threshold, rtw_lps_threshold, uint, 0644);
 module_param_named(lps_deep_mode, rtw_fw_lps_deep_mode, uint, 0644);
 module_param_named(support_bf, rtw_bf_support, bool, 0644);
 module_param_named(debug_mask, rtw_debug_mask, uint, 0644);
 
+MODULE_PARM_DESC(lps_threshold, "Threshold of number of packets in every 2 seconds");
 MODULE_PARM_DESC(lps_deep_mode, "Deeper PS mode. If 0, deep PS is disabled");
 MODULE_PARM_DESC(support_bf, "Set Y to enable beamformee support");
 MODULE_PARM_DESC(debug_mask, "Debugging mask");
@@ -199,8 +202,8 @@ static void rtw_watch_dog_work(struct work_struct *work)
 	if (busy_traffic != test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags))
 		rtw_coex_wl_status_change_notify(rtwdev);
 
-	if (stats->tx_cnt > RTW_LPS_THRESHOLD ||
-	    stats->rx_cnt > RTW_LPS_THRESHOLD)
+	if (stats->tx_cnt > rtw_lps_threshold ||
+	    stats->rx_cnt > rtw_lps_threshold)
 		ps_active = true;
 	else
 		ps_active = false;
drivers/net/wireless/realtek/rtw88/ps.h +0 -2
index 25925eedbad4..fe43f8d96d04 100644
@@ -5,8 +5,6 @@
 #ifndef __RTW_PS_H_
 #define __RTW_PS_H_
 
-#define RTW_LPS_THRESHOLD	2
-
 #define POWER_MODE_ACK		BIT(6)
 #define POWER_MODE_PG		BIT(4)
 #define POWER_MODE_LCLK		BIT(0)
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH 3/6] rtw88: use a module parameter to control LPS enter

Quoted 25 lines · On Fri, Oct 25, 2019 at 5:33 PM <[email protected]> wrote:

From: Yan-Hsuan Chuang <[email protected]>

If the number of packets is less than the LPS threshold, driver can then enter LPS mode.
And driver used to take RTW_LPS_THRESHOLD as the threshold. As the macro can not be changed after compiled, use a parameter instead.

The larger of the threshold, the more traffic required to leave power save mode, responsive time could be longer, but also the power consumption could be lower.

---
 drivers/net/wireless/realtek/rtw88/main.c | 7 +++++--
 drivers/net/wireless/realtek/rtw88/ps.h   | 2 --
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/net/wireless/realtek/rtw88/main.c +0 -0
index 7c1b89c4fb6c..bff8a0b129d9 100644

drivers/net/wireless/realtek/rtw88/main.c static void rtw_watch_dog_work(struct work_struct *work) · line 209

Quoted 10 lines
drivers/net/wireless/realtek/rtw88/main.c +2 -2
@@ -199,8 +202,8 @@ static void rtw_watch_dog_work(struct work_struct *work)
        if (busy_traffic != test_bit(RTW_FLAG_BUSY_TRAFFIC, rtwdev->flags))
                rtw_coex_wl_status_change_notify(rtwdev);
 
-       if (stats->tx_cnt > RTW_LPS_THRESHOLD ||
-           stats->rx_cnt > RTW_LPS_THRESHOLD)
+       if (stats->tx_cnt > rtw_lps_threshold ||
+           stats->rx_cnt > rtw_lps_threshold)
                ps_active = true;
        else
                ps_active = false;

The naming of 'ps_active' is a bit confusing. Per the commit message, it will leave LPS
it tx/rx count > threshold. But I'll be misled by the name ps_active. Does it mean the
current condition is PS active and ready to power sleep? I'd like to rename it to old-fashioned
'lps_enter' to represent the action that would be taken. It would be easier for me to understand.

Chris

Quoted 3 lines

--
2.17.1

#6 lore raw

RE: [PATCH 3/6] rtw88: use a module parameter to control LPS enter

Quoted 49 lines · On Fri, Oct 25, 2019 at 5:33 PM <[email protected]> wrote:
Quoted 13 lines

From: Yan-Hsuan Chuang <[email protected]>

If the number of packets is less than the LPS threshold, driver can then enter LPS mode.
And driver used to take RTW_LPS_THRESHOLD as the threshold. As the macro can not be changed after compiled, use a parameter instead.

The larger of the threshold, the more traffic required to leave power save mode, responsive time could be longer, but also the power consumption could be lower.

Review

Quoted 7 lines
---
 drivers/net/wireless/realtek/rtw88/main.c | 7 +++++--
 drivers/net/wireless/realtek/rtw88/ps.h   | 2 --
 2 files changed, 5 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/wireless/realtek/rtw88/main.c

drivers/net/wireless/realtek/rtw88/main.c static void rtw_watch_dog_work(struct

Quoted 5 lines

index 7c1b89c4fb6c..bff8a0b129d9 100644

drivers/net/wireless/realtek/rtw88/main.c +0 -0
@@ -199,8 +202,8 @@ static void rtw_watch_dog_work(struct

work_struct *work)

drivers/net/wireless/realtek/rtw88/main.c static void rtw_watch_dog_work(struct · line 202

Quoted 1 line
drivers/net/wireless/realtek/rtw88/main.c +0 -0
        if (busy_traffic != test_bit(RTW_FLAG_BUSY_TRAFFIC,

rtwdev->flags))

drivers/net/wireless/realtek/rtw88/main.c static void rtw_watch_dog_work(struct work_struct *work) · line 209

Quoted 9 lines
drivers/net/wireless/realtek/rtw88/main.c +2 -2
                rtw_coex_wl_status_change_notify(rtwdev);
 
-       if (stats->tx_cnt > RTW_LPS_THRESHOLD ||
-           stats->rx_cnt > RTW_LPS_THRESHOLD)
+       if (stats->tx_cnt > rtw_lps_threshold ||
+           stats->rx_cnt > rtw_lps_threshold)
                ps_active = true;
        else
                ps_active = false;

The naming of 'ps_active' is a bit confusing. Per the commit message, it will leave LPS
it tx/rx count > threshold. But I'll be misled by the name ps_active. Does it mean the
current condition is PS active and ready to power sleep? I'd like to rename it to old-fashioned
'lps_enter' to represent the action that would be taken. It would be easier for me to understand.

Quoted 2 lines

Chris

I think according to the context, ps_active is good for me. But I can still send a separate patch to rename it. Or you can :)

Yan-Hsuan

Reviewed-by
#7 lore raw

Re: [PATCH 3/6] rtw88: use a module parameter to control LPS enter

Quoted 11 lines · Tony Chuang
Quoted 11 lines · On Fri, Oct 25, 2019 at 5:33 PM <[email protected]> wrote:
Quoted 9 lines

From: Yan-Hsuan Chuang <[email protected]>

If the number of packets is less than the LPS threshold, driver can then enter LPS mode.
And driver used to take RTW_LPS_THRESHOLD as the threshold. As the macro can not be changed after compiled, use a parameter instead.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The larger of the threshold, the more traffic required to leave power save mode, responsive time could be longer, but also the power consumption could be lower.

---

Quoted 33 lines
Quoted 33 lines

Review

Quoted 5 lines
 drivers/net/wireless/realtek/rtw88/main.c | 7 +++++--
 drivers/net/wireless/realtek/rtw88/ps.h   | 2 --
 2 files changed, 5 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/net/wireless/realtek/rtw88/main.c

drivers/net/wireless/realtek/rtw88/main.c static void rtw_watch_dog_work(struct

Quoted 5 lines

index 7c1b89c4fb6c..bff8a0b129d9 100644

drivers/net/wireless/realtek/rtw88/main.c +0 -0
@@ -199,8 +202,8 @@ static void rtw_watch_dog_work(struct

work_struct *work)

drivers/net/wireless/realtek/rtw88/main.c static void rtw_watch_dog_work(struct · line 202

Quoted 1 line
drivers/net/wireless/realtek/rtw88/main.c +0 -0
        if (busy_traffic != test_bit(RTW_FLAG_BUSY_TRAFFIC,

rtwdev->flags))

drivers/net/wireless/realtek/rtw88/main.c static void rtw_watch_dog_work(struct work_struct *work) · line 209

Quoted 9 lines
drivers/net/wireless/realtek/rtw88/main.c +2 -2
                rtw_coex_wl_status_change_notify(rtwdev);
 
-       if (stats->tx_cnt > RTW_LPS_THRESHOLD ||
-           stats->rx_cnt > RTW_LPS_THRESHOLD)
+       if (stats->tx_cnt > rtw_lps_threshold ||
+           stats->rx_cnt > rtw_lps_threshold)
                ps_active = true;
        else
                ps_active = false;

The naming of 'ps_active' is a bit confusing. Per the commit message, it will leave LPS
it tx/rx count > threshold. But I'll be misled by the name ps_active. Does it mean the
current condition is PS active and ready to power sleep? I'd like to rename it to old-fashioned
'lps_enter' to represent the action that would be taken. It would be easier for me to understand.

Quoted 8 lines
Quoted 2 lines

Chris

I think according to the context, ps_active is good for me. But I can still send a separate patch to rename it. Or you can :)

Yan-Hsuan

OK. Then I have no problem with this patch.

Chris

#8 lore raw

Re: [PATCH 3/6] rtw88: use a module parameter to control LPS enter

In reply to [email protected]
Quoted 8 lines · <[email protected]> wrote:

From: Yan-Hsuan Chuang <[email protected]>

If the number of packets is less than the LPS threshold, driver can then enter LPS mode.
And driver used to take RTW_LPS_THRESHOLD as the threshold. As the macro can not be changed after compiled, use a parameter instead.

Quoted 6 lines

The larger of the threshold, the more traffic required to leave power save mode, responsive time could be longer, but also the power consumption could be lower.

I don't think a module parameter should be used to control power save level, instead there should be a generic interface for that. Also the commit log does not give any explanation why this needs to be a module parameter.

Tony, there's a high barrier for adding new module parameters. It's a common phrase for me to say "module parameters are not windows .ini files". And to make it easier for everyone always submit controversial patches separately, do not hide within a bigger patchset.

Signature · 3 lines
https://patchwork.kernel.org/patch/11211881/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

RE: [PATCH 3/6] rtw88: use a module parameter to control LPS enter

From: Kalle Valo

Quoted 21 lines
Quoted 8 lines · <[email protected]> wrote:

From: Yan-Hsuan Chuang <[email protected]>

If the number of packets is less than the LPS threshold, driver can then enter LPS mode.
And driver used to take RTW_LPS_THRESHOLD as the threshold. As the macro can not be changed after compiled, use a parameter instead.

Quoted 6 lines

The larger of the threshold, the more traffic required to leave power save mode, responsive time could be longer, but also the power consumption could be lower.

I don't think a module parameter should be used to control power save level, instead there should be a generic interface for that. Also the commit log does not give any explanation why this needs to be a module parameter.

Quoted 8 lines

Tony, there's a high barrier for adding new module parameters. It's a common
phrase for me to say "module parameters are not windows .ini files". And to make it
easier for everyone always submit controversial patches separately, do not hide
within a bigger patchset.

Alright, I was thinking module parameters as a convenient tool for driver to control the behavior for debugging or out-of-band adjusting. But it seems like you treat it more carefully.

Actually this is just going to allow us to set different default values for different use cases. So is there a better way to control it. Or I should just change the value to a better one. By our experience, set this to 50 is a more reasonable value, such that some web surfing or background traffic wouldn't make the driver to leave PS mode.

Yan-Hsuan

#11 lore raw

Re: [PATCH 3/6] rtw88: use a module parameter to control LPS enter

Quoted 4 lines · Tony Chuang

Or I should just change the
value to a better one. By our experience, set this to 50 is a more reasonable value, such that some web surfing or background traffic wouldn't make the driver to leave PS mode.

FWIW, I think choosing a more reasonable default is definitely a good start, as long as this choice doesn't have huge downsides.

@Kalle: FYI, this (set to 50) is exactly the change that Tony is recommending to me for my distro, and I have the same qualms about supporting a growing number of module parameter tweaks like this. So, thanks for pushing back :)

Brian

#12 lore raw

RE: [PATCH 3/6] rtw88: use a module parameter to control LPS enter

Quoted 11 lines
Quoted 4 lines · Tony Chuang

Or I should just change the
value to a better one. By our experience, set this to 50 is a more reasonable value, such that some web surfing or background traffic wouldn't make the driver to leave PS mode.

FWIW, I think choosing a more reasonable default is definitely a good start, as long as this choice doesn't have huge downsides.

Quoted 7 lines

@Kalle: FYI, this (set to 50) is exactly the change that Tony is recommending to me for my distro, and I have the same qualms about supporting a growing number of module parameter tweaks like this. So, thanks for pushing back :)

Brian

I was afraid of you thinking that setting this to 50 is a strange thing. But it seems like you'd prefer to change the default value instead of adding a module parameter to control it. I think we can drop this one and I will send a patch to change the default value to 50.

Yan-Hsuan

#13 lore raw

Re: [PATCH 3/6] rtw88: use a module parameter to control LPS enter

Quoted 15 lines · Tony Chuang
Quoted 15 lines
Quoted 4 lines · Tony Chuang

Or I should just change the
value to a better one. By our experience, set this to 50 is a more reasonable value, such that some web surfing or background traffic wouldn't make the driver to leave PS mode.

FWIW, I think choosing a more reasonable default is definitely a good start, as long as this choice doesn't have huge downsides.

@Kalle: FYI, this (set to 50) is exactly the change that Tony is recommending to me for my distro, and I have the same qualms about supporting a growing number of module parameter tweaks like this. So, thanks for pushing back :)

Quoted 7 lines
Quoted 2 lines

Brian

I was afraid of you thinking that setting this to 50 is a strange thing. But it seems like you'd prefer to change the default value instead of adding a module parameter to control it. I think we can drop this one and I will send a patch to change the default value to 50.

Yeah, as the first step changing to 50 sounds good to me. Later, if needed, we can extend it to make it configurable from user space, either via the QoS framework or something else.

Signature · 1 line
Kalle Valo
#14 lore raw

Re: [PATCH 3/6] rtw88: use a module parameter to control LPS enter

In reply to Tony Chuang
Quoted 35 lines · Tony Chuang

From: Kalle Valo

Quoted 21 lines
Quoted 8 lines · <[email protected]> wrote:

From: Yan-Hsuan Chuang <[email protected]>

If the number of packets is less than the LPS threshold, driver can then enter LPS mode.
And driver used to take RTW_LPS_THRESHOLD as the threshold. As the macro can not be changed after compiled, use a parameter instead.

Quoted 6 lines

The larger of the threshold, the more traffic required to leave power save mode, responsive time could be longer, but also the power consumption could be lower.

I don't think a module parameter should be used to control power save level, instead there should be a generic interface for that. Also the commit log does not give any explanation why this needs to be a module parameter.

Quoted 8 lines

Tony, there's a high barrier for adding new module parameters. It's a common
phrase for me to say "module parameters are not windows .ini files". And to make it
easier for everyone always submit controversial patches separately, do not hide
within a bigger patchset.

Alright, I was thinking module parameters as a convenient tool for driver to control the behavior for debugging or out-of-band adjusting. But it seems like you treat it more carefully.

Quoted 5 lines

Actually this is just going to allow us to set different default values for different use cases. So is there a better way to control it. Or I should just change the value to a better one. By our experience, set this to 50 is a more reasonable value, such that some web surfing or background traffic wouldn't make the driver to leave PS mode.

I recall having a similar discussion something like 10 years ago. (Yes, I have been here for way too long). I think at the time recommendation was to use latency value from the QoS framework to make it possible for user space to change wireless power save aggressiveness. But I don't know if anyone really used that.

I was feeling nostalgic and decided to find some pointers:

https://lore.kernel.org/linux-wireless/[email protected]/

And it seems the patch was even applied:

195e294d21e8 mac80211: Determine dynamic PS timeout based on ps-qos network latency

This is for mac80211 dynamic ps feature, but I imagine we could somehow extend it to driver settings like the LPS threshold here. Something like this would be much more acceptable than having custom module parameters for each driver.

Signature · 1 line
Kalle Valo
#15 lore raw

PATCH 4/6 rtw88: rearrange if..else statements for rx rate indexes

In reply to [email protected]

From: Yan-Hsuan Chuang <[email protected]>

Driver just memset() rx_status to 0 before assigning rate indexes. And driver could never hit the 'else' because the driver checks if 'pkt_stat->rate >= DESC_RATEMCS0', so the 'else' statement can be removed.

Also rearrange the if..else statements because DESC_RATEMCS0 is actually larger than DESC_RATE1M ~ DESC_RATE54M, move the check of 'pkt_stat->rate >= DESC_RATEMCS0' to the last to keep an increasing order.

---
 drivers/net/wireless/realtek/rtw88/rx.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/net/wireless/realtek/rtw88/rx.c +6 -8
index 36887f998090..9b90339ab697 100644
@@ -160,19 +160,17 @@ void rtw_rx_fill_rx_status(struct rtw_dev *rtwdev,
 	else if (pkt_stat->rate >= DESC_RATEMCS0)
 		rx_status->encoding = RX_ENC_HT;
 
-	if (pkt_stat->rate >= DESC_RATEMCS0) {
-		rtw_desc_to_mcsrate(pkt_stat->rate, &rx_status->rate_idx,
-				    &rx_status->nss);
-	} else if (rx_status->band == NL80211_BAND_5GHZ &&
-		   pkt_stat->rate >= DESC_RATE6M &&
-		   pkt_stat->rate <= DESC_RATE54M) {
+	if (rx_status->band == NL80211_BAND_5GHZ &&
+	    pkt_stat->rate >= DESC_RATE6M &&
+	    pkt_stat->rate <= DESC_RATE54M) {
 		rx_status->rate_idx = pkt_stat->rate - DESC_RATE6M;
 	} else if (rx_status->band == NL80211_BAND_2GHZ &&
 		   pkt_stat->rate >= DESC_RATE1M &&
 		   pkt_stat->rate <= DESC_RATE54M) {
 		rx_status->rate_idx = pkt_stat->rate - DESC_RATE1M;
-	} else {
-		rx_status->rate_idx = 0;
+	} else if (pkt_stat->rate >= DESC_RATEMCS0) {
+		rtw_desc_to_mcsrate(pkt_stat->rate, &rx_status->rate_idx,
+				    &rx_status->nss);
 	}
 
 	rx_status->flag |= RX_FLAG_MACTIME_START;
Signature · 1 line
2.17.1
#16 lore raw

PATCH 5/6 rtw88: fix potential read outside array boundary

In reply to [email protected]

From: Tzu-En Huang <[email protected]>

The level of cckpd is from 0 to 4, and it is the index of array pd_lvl[] and cs_lvl[]. However, the length of both arrays are 4, which is smaller than the possible maximum input index. Enumerate cck level to make sure the max level will not be wrong if new level is added in future.

Fixes 479c4ee931a6 ("rtw88: add dynamic cck pd mechanism")
---
 drivers/net/wireless/realtek/rtw88/phy.c      | 17 ++++++++---------
 drivers/net/wireless/realtek/rtw88/phy.h      |  9 +++++++++
 drivers/net/wireless/realtek/rtw88/rtw8822c.c |  4 ++--
 3 files changed, 19 insertions(+), 11 deletions(-)
drivers/net/wireless/realtek/rtw88/phy.c +8 -9
index 4a41134c420e..4adba44dbd74 100644
@@ -109,7 +109,7 @@ static void rtw_phy_cck_pd_init(struct rtw_dev *rtwdev)
 
 	for (i = 0; i <= RTW_CHANNEL_WIDTH_40; i++) {
 		for (j = 0; j < RTW_RF_PATH_MAX; j++)
-			dm_info->cck_pd_lv[i][j] = 0;
+			dm_info->cck_pd_lv[i][j] = CCK_PD_LV0;
 	}
 
 	dm_info->cck_fa_avg = CCK_FA_AVG_RESET;
@@ -461,7 +461,6 @@ static void rtw_phy_dpk_track(struct rtw_dev *rtwdev)
 		chip->ops->dpk_track(rtwdev);
 }
 
-#define CCK_PD_LV_MAX		5
 #define CCK_PD_FA_LV1_MIN	1000
 #define CCK_PD_FA_LV0_MAX	500
 
@@ -471,10 +470,10 @@ static u8 rtw_phy_cck_pd_lv_unlink(struct rtw_dev *rtwdev)
 	u32 cck_fa_avg = dm_info->cck_fa_avg;
 
 	if (cck_fa_avg > CCK_PD_FA_LV1_MIN)
-		return 1;
+		return CCK_PD_LV1;
 
 	if (cck_fa_avg < CCK_PD_FA_LV0_MAX)
-		return 0;
+		return CCK_PD_LV0;
 
 	return CCK_PD_LV_MAX;
 }
@@ -494,15 +493,15 @@ static u8 rtw_phy_cck_pd_lv_link(struct rtw_dev *rtwdev)
 	u32 cck_fa_avg = dm_info->cck_fa_avg;
 
 	if (igi > CCK_PD_IGI_LV4_VAL && rssi > CCK_PD_RSSI_LV4_VAL)
-		return 4;
+		return CCK_PD_LV4;
 	if (igi > CCK_PD_IGI_LV3_VAL && rssi > CCK_PD_RSSI_LV3_VAL)
-		return 3;
+		return CCK_PD_LV3;
 	if (igi > CCK_PD_IGI_LV2_VAL || rssi > CCK_PD_RSSI_LV2_VAL)
-		return 2;
+		return CCK_PD_LV2;
 	if (cck_fa_avg > CCK_PD_FA_LV1_MIN)
-		return 1;
+		return CCK_PD_LV1;
 	if (cck_fa_avg < CCK_PD_FA_LV0_MAX)
-		return 0;
+		return CCK_PD_LV0;
 
 	return CCK_PD_LV_MAX;
 }
drivers/net/wireless/realtek/rtw88/phy.h +9 -0
index c389ef274ed8..af916d8784cd 100644
@@ -146,6 +146,15 @@ rtw_get_tx_power_params(struct rtw_dev *rtwdev, u8 path,
 			u8 rate, u8 bw, u8 ch, u8 regd,
 			struct rtw_power_params *pwr_param);
 
+enum rtw_phy_cck_pd_lv {
+	CCK_PD_LV0,
+	CCK_PD_LV1,
+	CCK_PD_LV2,
+	CCK_PD_LV3,
+	CCK_PD_LV4,
+	CCK_PD_LV_MAX,
+};
+
 #define	MASKBYTE0		0xff
 #define	MASKBYTE1		0xff00
 #define	MASKBYTE2		0xff0000
drivers/net/wireless/realtek/rtw88/rtw8822c.c +2 -2
index b77905196ffb..0c419332fd52 100644
@@ -3295,8 +3295,8 @@ rtw8822c_phy_cck_pd_set_reg(struct rtw_dev *rtwdev,
 static void rtw8822c_phy_cck_pd_set(struct rtw_dev *rtwdev, u8 new_lvl)
 {
 	struct rtw_dm_info *dm_info = &rtwdev->dm_info;
-	s8 pd_lvl[4] = {2, 4, 6, 8};
-	s8 cs_lvl[4] = {2, 2, 2, 4};
+	s8 pd_lvl[CCK_PD_LV_MAX] = {0, 2, 4, 6, 8};
+	s8 cs_lvl[CCK_PD_LV_MAX] = {0, 2, 2, 2, 4};
 	u8 cur_lvl;
 	u8 nrx, bw;
 
Signature · 1 line
2.17.1
#17 lore raw

PATCH 6/6 rtw88: avoid FW info flood

In reply to [email protected]

From: Yan-Hsuan Chuang <[email protected]>

The FW info was printed everytime driver is powered on, such as leaving IDLE state. It will flood the kernel log.

Move the FW info printing to callback when FW is loaded, so that will only be printed once when device is probed.

---
 drivers/net/wireless/realtek/rtw88/mac.c  | 17 -----------------
 drivers/net/wireless/realtek/rtw88/main.c | 10 ++++++++++
 2 files changed, 10 insertions(+), 17 deletions(-)
drivers/net/wireless/realtek/rtw88/mac.c +0 -17
index c471117b1472..507970387b2a 100644
@@ -567,21 +567,6 @@ download_firmware_to_mem(struct rtw_dev *rtwdev, const u8 *data,
 	return 0;
 }
 
-static void update_firmware_info(struct rtw_dev *rtwdev,
-				 struct rtw_fw_state *fw)
-{
-	const struct rtw_fw_hdr *fw_hdr =
-				(const struct rtw_fw_hdr *)fw->firmware->data;
-
-	fw->h2c_version = le16_to_cpu(fw_hdr->h2c_fmt_ver);
-	fw->version = le16_to_cpu(fw_hdr->version);
-	fw->sub_version = fw_hdr->subversion;
-	fw->sub_index = fw_hdr->subindex;
-
-	rtw_info(rtwdev, "Firmware version %u.%u.%u, H2C version %u\n",
-		 fw->version, fw->sub_version, fw->sub_index, fw->h2c_version);
-}
-
 static int
 start_download_firmware(struct rtw_dev *rtwdev, const u8 *data, u32 size)
 {
@@ -698,8 +683,6 @@ int rtw_download_firmware(struct rtw_dev *rtwdev, struct rtw_fw_state *fw)
 	if (ret)
 		goto dlfw_fail;
 
-	update_firmware_info(rtwdev, fw);
-
 	/* reset desc and index */
 	rtw_hci_setup(rtwdev);
 
drivers/net/wireless/realtek/rtw88/main.c +10 -0
index bff8a0b129d9..bace9c583abb 100644
@@ -1025,12 +1025,22 @@ static void rtw_load_firmware_cb(const struct firmware *firmware, void *context)
 {
 	struct rtw_dev *rtwdev = context;
 	struct rtw_fw_state *fw = &rtwdev->fw;
+	const struct rtw_fw_hdr *fw_hdr;
 
 	if (!firmware)
 		rtw_err(rtwdev, "failed to request firmware\n");
 
+	fw_hdr = (const struct rtw_fw_hdr *)firmware->data;
+	fw->h2c_version = le16_to_cpu(fw_hdr->h2c_fmt_ver);
+	fw->version = le16_to_cpu(fw_hdr->version);
+	fw->sub_version = fw_hdr->subversion;
+	fw->sub_index = fw_hdr->subindex;
+
 	fw->firmware = firmware;
 	complete_all(&fw->completion);
+
+	rtw_info(rtwdev, "Firmware version %u.%u.%u, H2C version %u\n",
+		 fw->version, fw->sub_version, fw->sub_index, fw->h2c_version);
 }
 
 static int rtw_load_firmware(struct rtw_dev *rtwdev, const char *fw_name)
Signature · 1 line
2.17.1