2020-01-30 05:31:55

by Tony Chuang

[permalink] [raw]
Subject: [PATCH v2 0/2] rtw88: some driver fixes

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

This set includes some driver fixes

v1 -> v2
* The remaining 2 patches are dropped by Kalle because have comments
* Adjust the patches according to the suggestions in comments

Chien-Hsun Liao (1):
rtw88: 8822c: modify rf protection setting

Ping-Ke Shih (1):
rtw88: Use secondary channel offset enumeration

drivers/net/wireless/realtek/rtw88/mac.c | 6 +++---
drivers/net/wireless/realtek/rtw88/main.c | 14 +++++++-------
drivers/net/wireless/realtek/rtw88/main.h | 10 ++++++++++
drivers/net/wireless/realtek/rtw88/phy.c | 10 ----------
drivers/net/wireless/realtek/rtw88/rtw8822b.c | 2 +-
drivers/net/wireless/realtek/rtw88/rtw8822c.c | 17 ++++++++++++++++-
drivers/net/wireless/realtek/rtw88/rtw8822c.h | 5 +++++
7 files changed, 42 insertions(+), 22 deletions(-)

--
2.17.1


2020-01-30 05:31:56

by Tony Chuang

[permalink] [raw]
Subject: [PATCH v2 2/2] rtw88: 8822c: modify rf protection setting

From: Chien-Hsun Liao <[email protected]>

According to some experiments, the original RF register protection
setting of 8822c cannot perfectly make sure that there is no hardware
PI write (direct) during direct write. Modify the setting so that the
hardware block of PI would be turned off via rtw8822c_rstb_3wire()
during the direct write, to avoid RF register racing.

Note that 8822b uses SIPI write (indirect), so 8822b does not
have such problem.

Signed-off-by: Chien-Hsun Liao <[email protected]>
Signed-off-by: Yan-Hsuan Chuang <[email protected]>
---

v1 -> v2
* Add more descriptions

drivers/net/wireless/realtek/rtw88/phy.c | 10 ----------
drivers/net/wireless/realtek/rtw88/rtw8822c.c | 15 +++++++++++++++
drivers/net/wireless/realtek/rtw88/rtw8822c.h | 5 +++++
3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw88/phy.c b/drivers/net/wireless/realtek/rtw88/phy.c
index eea9d888fbf1..8793dd22188f 100644
--- a/drivers/net/wireless/realtek/rtw88/phy.c
+++ b/drivers/net/wireless/realtek/rtw88/phy.c
@@ -749,20 +749,10 @@ bool rtw_phy_write_rf_reg(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
direct_addr = base_addr[rf_path] + (addr << 2);
mask &= RFREG_MASK;

- if (addr == RF_CFGCH) {
- rtw_write32_mask(rtwdev, REG_RSV_CTRL, BITS_RFC_DIRECT, DISABLE_PI);
- rtw_write32_mask(rtwdev, REG_WLRF1, BITS_RFC_DIRECT, DISABLE_PI);
- }
-
rtw_write32_mask(rtwdev, direct_addr, mask, data);

udelay(1);

- if (addr == RF_CFGCH) {
- rtw_write32_mask(rtwdev, REG_RSV_CTRL, BITS_RFC_DIRECT, ENABLE_PI);
- rtw_write32_mask(rtwdev, REG_WLRF1, BITS_RFC_DIRECT, ENABLE_PI);
- }
-
return true;
}

diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
index 4c416d603b33..fb621881fbd1 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
@@ -1289,6 +1289,17 @@ static int rtw8822c_mac_init(struct rtw_dev *rtwdev)
return 0;
}

+static void rtw8822c_rstb_3wire(struct rtw_dev *rtwdev, bool enable)
+{
+ if (enable) {
+ rtw_write32_mask(rtwdev, REG_RSTB, BIT_RSTB_3WIRE, 0x1);
+ rtw_write32_mask(rtwdev, REG_ANAPAR_A, BIT_ANAPAR_UPDATE, 0x1);
+ rtw_write32_mask(rtwdev, REG_ANAPAR_B, BIT_ANAPAR_UPDATE, 0x1);
+ } else {
+ rtw_write32_mask(rtwdev, REG_RSTB, BIT_RSTB_3WIRE, 0x0);
+ }
+}
+
static void rtw8822c_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw)
{
#define RF18_BAND_MASK (BIT(16) | BIT(9) | BIT(8))
@@ -1337,6 +1348,8 @@ static void rtw8822c_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw)
break;
}

+ rtw8822c_rstb_3wire(rtwdev, false);
+
rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE2, 0x04, 0x01);
rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWA, 0x1f, 0x12);
rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD0, 0xfffff, rf_rxbb);
@@ -1349,6 +1362,8 @@ static void rtw8822c_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw)

rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, rf_reg18);
rtw_write_rf(rtwdev, RF_PATH_B, RF_CFGCH, RFREG_MASK, rf_reg18);
+
+ rtw8822c_rstb_3wire(rtwdev, true);
}

static void rtw8822c_toggle_igi(struct rtw_dev *rtwdev)
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.h b/drivers/net/wireless/realtek/rtw88/rtw8822c.h
index abd9f300bedd..dfd8662a0c0e 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.h
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.h
@@ -190,6 +190,8 @@ const struct rtw_table name ## _tbl = { \
#define BIT_3WIRE_TX_EN BIT(0)
#define BIT_3WIRE_RX_EN BIT(1)
#define BIT_3WIRE_PI_ON BIT(28)
+#define REG_ANAPAR_A 0x1830
+#define BIT_ANAPAR_UPDATE BIT(29)
#define REG_RXAGCCTL0 0x18ac
#define BITS_RXAGC_CCK GENMASK(15, 12)
#define BITS_RXAGC_OFDM GENMASK(8, 4)
@@ -223,6 +225,8 @@ const struct rtw_table name ## _tbl = { \
#define BIT_CCK_BLK_EN BIT(1)
#define BIT_CCK_OFDM_BLK_EN (BIT(0) | BIT(1))
#define REG_CCAMSK 0x1c80
+#define REG_RSTB 0x1c90
+#define BIT_RSTB_3WIRE BIT(8)
#define REG_RX_BREAK 0x1d2c
#define BIT_COM_RX_GCK_EN BIT(31)
#define REG_RXFNCTL 0x1d30
@@ -243,6 +247,7 @@ const struct rtw_table name ## _tbl = { \
#define REG_OFDM_TXCNT 0x2de0
#define REG_ORITXCODE2 0x4100
#define REG_3WIRE2 0x410c
+#define REG_ANAPAR_B 0x4130
#define REG_RXAGCCTL 0x41ac
#define REG_DCKB_I_0 0x41bc
#define REG_DCKB_I_1 0x41c0
--
2.17.1

2020-01-30 05:33:43

by Tony Chuang

[permalink] [raw]
Subject: [PATCH v2 1/2] rtw88: Use secondary channel offset enumeration

From: Ping-Ke Shih <[email protected]>

The hardware value of secondary channel offset isn't very intuitive. This
commit adds enumeration, so we can easier to check the logic with the
suffix of enumeration name, likes _UPPER or _LOWER.

Signed-off-by: Ping-Ke Shih <[email protected]>
Signed-off-by: Yan-Hsuan Chuang <[email protected]>
---

v1 -> v2
* rename RTW_SC_20_UPPERST to RTW_SC_20_UPMOST

drivers/net/wireless/realtek/rtw88/mac.c | 6 +++---
drivers/net/wireless/realtek/rtw88/main.c | 14 +++++++-------
drivers/net/wireless/realtek/rtw88/main.h | 10 ++++++++++
drivers/net/wireless/realtek/rtw88/rtw8822b.c | 2 +-
drivers/net/wireless/realtek/rtw88/rtw8822c.c | 2 +-
5 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw88/mac.c b/drivers/net/wireless/realtek/rtw88/mac.c
index cadf0abbe16b..ec2c1adcb900 100644
--- a/drivers/net/wireless/realtek/rtw88/mac.c
+++ b/drivers/net/wireless/realtek/rtw88/mac.c
@@ -17,10 +17,10 @@ void rtw_set_channel_mac(struct rtw_dev *rtwdev, u8 channel, u8 bw,

txsc20 = primary_ch_idx;
if (bw == RTW_CHANNEL_WIDTH_80) {
- if (txsc20 == 1 || txsc20 == 3)
- txsc40 = 9;
+ if (txsc20 == RTW_SC_20_UPPER || txsc20 == RTW_SC_20_UPMOST)
+ txsc40 = RTW_SC_40_UPPER;
else
- txsc40 = 10;
+ txsc40 = RTW_SC_40_LOWER;
}
rtw_write8(rtwdev, REG_DATA_SC,
BIT_TXSC_20M(txsc20) | BIT_TXSC_40M(txsc40));
diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
index 2845d2838f7b..6318d44d9525 100644
--- a/drivers/net/wireless/realtek/rtw88/main.c
+++ b/drivers/net/wireless/realtek/rtw88/main.c
@@ -317,15 +317,15 @@ void rtw_get_channel_params(struct cfg80211_chan_def *chandef,
case NL80211_CHAN_WIDTH_20_NOHT:
case NL80211_CHAN_WIDTH_20:
bandwidth = RTW_CHANNEL_WIDTH_20;
- primary_chan_idx = 0;
+ primary_chan_idx = RTW_SC_DONT_CARE;
break;
case NL80211_CHAN_WIDTH_40:
bandwidth = RTW_CHANNEL_WIDTH_40;
if (primary_freq > center_freq) {
- primary_chan_idx = 1;
+ primary_chan_idx = RTW_SC_20_UPPER;
center_chan -= 2;
} else {
- primary_chan_idx = 2;
+ primary_chan_idx = RTW_SC_20_LOWER;
center_chan += 2;
}
break;
@@ -333,10 +333,10 @@ void rtw_get_channel_params(struct cfg80211_chan_def *chandef,
bandwidth = RTW_CHANNEL_WIDTH_80;
if (primary_freq > center_freq) {
if (primary_freq - center_freq == 10) {
- primary_chan_idx = 1;
+ primary_chan_idx = RTW_SC_20_UPPER;
center_chan -= 2;
} else {
- primary_chan_idx = 3;
+ primary_chan_idx = RTW_SC_20_UPMOST;
center_chan -= 6;
}
/* assign the center channel used
@@ -345,10 +345,10 @@ void rtw_get_channel_params(struct cfg80211_chan_def *chandef,
cch_by_bw[RTW_CHANNEL_WIDTH_40] = center_chan + 4;
} else {
if (center_freq - primary_freq == 10) {
- primary_chan_idx = 2;
+ primary_chan_idx = RTW_SC_20_LOWER;
center_chan += 2;
} else {
- primary_chan_idx = 4;
+ primary_chan_idx = RTW_SC_20_LOWEST;
center_chan += 6;
}
/* assign the center channel used
diff --git a/drivers/net/wireless/realtek/rtw88/main.h b/drivers/net/wireless/realtek/rtw88/main.h
index f334d201bfb5..d11f3a26b7bf 100644
--- a/drivers/net/wireless/realtek/rtw88/main.h
+++ b/drivers/net/wireless/realtek/rtw88/main.h
@@ -99,6 +99,16 @@ enum rtw_bandwidth {
RTW_CHANNEL_WIDTH_10 = 6,
};

+enum rtw_sc_offset {
+ RTW_SC_DONT_CARE = 0,
+ RTW_SC_20_UPPER = 1,
+ RTW_SC_20_LOWER = 2,
+ RTW_SC_20_UPMOST = 3,
+ RTW_SC_20_LOWEST = 4,
+ RTW_SC_40_UPPER = 9,
+ RTW_SC_40_LOWER = 10,
+};
+
enum rtw_net_type {
RTW_NET_NO_LINK = 0,
RTW_NET_AD_HOC = 1,
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822b.c b/drivers/net/wireless/realtek/rtw88/rtw8822b.c
index 4bc14b1a6340..2eed777ee692 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822b.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822b.c
@@ -645,7 +645,7 @@ static void rtw8822b_set_channel_bb(struct rtw_dev *rtwdev, u8 channel, u8 bw,
rtw_write32_mask(rtwdev, REG_ADC160, BIT(30), 0x1);
break;
case RTW_CHANNEL_WIDTH_40:
- if (primary_ch_idx == 1)
+ if (primary_ch_idx == RTW_SC_20_UPPER)
rtw_write32_set(rtwdev, REG_RXSB, BIT(4));
else
rtw_write32_clr(rtwdev, REG_RXSB, BIT(4));
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
index 3865097696d4..4c416d603b33 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
@@ -1482,7 +1482,7 @@ static void rtw8822c_set_channel_bb(struct rtw_dev *rtwdev, u8 channel, u8 bw,
break;
case RTW_CHANNEL_WIDTH_40:
rtw_write32_mask(rtwdev, REG_CCKSB, BIT(4),
- (primary_ch_idx == 1 ? 1 : 0));
+ (primary_ch_idx == RTW_SC_20_UPPER ? 1 : 0));
rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xf, 0x5);
rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xc0, 0x0);
rtw_write32_mask(rtwdev, REG_TXBWCTL, 0xff00,
--
2.17.1

2020-01-30 06:39:28

by Chris Chiu

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] rtw88: Use secondary channel offset enumeration

On Thu, Jan 30, 2020 at 1:31 PM <[email protected]> wrote:
>
> From: Ping-Ke Shih <[email protected]>
>
> The hardware value of secondary channel offset isn't very intuitive. This
> commit adds enumeration, so we can easier to check the logic with the
> suffix of enumeration name, likes _UPPER or _LOWER.
>
> Signed-off-by: Ping-Ke Shih <[email protected]>
> Signed-off-by: Yan-Hsuan Chuang <[email protected]>
> ---
Reviewed-by: Chris Chiu <[email protected]>
>
> v1 -> v2
> * rename RTW_SC_20_UPPERST to RTW_SC_20_UPMOST
>
> drivers/net/wireless/realtek/rtw88/mac.c | 6 +++---
> drivers/net/wireless/realtek/rtw88/main.c | 14 +++++++-------
> drivers/net/wireless/realtek/rtw88/main.h | 10 ++++++++++
> drivers/net/wireless/realtek/rtw88/rtw8822b.c | 2 +-
> drivers/net/wireless/realtek/rtw88/rtw8822c.c | 2 +-
> 5 files changed, 22 insertions(+), 12 deletions(-)
>

2020-01-30 06:40:42

by Chris Chiu

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] rtw88: 8822c: modify rf protection setting

On Thu, Jan 30, 2020 at 1:31 PM <[email protected]> wrote:
>
> From: Chien-Hsun Liao <[email protected]>
>
> According to some experiments, the original RF register protection
> setting of 8822c cannot perfectly make sure that there is no hardware
> PI write (direct) during direct write. Modify the setting so that the
> hardware block of PI would be turned off via rtw8822c_rstb_3wire()
> during the direct write, to avoid RF register racing.
>
> Note that 8822b uses SIPI write (indirect), so 8822b does not
> have such problem.
>
> Signed-off-by: Chien-Hsun Liao <[email protected]>
> Signed-off-by: Yan-Hsuan Chuang <[email protected]>
> ---
Reviewed-by: Chris Chiu <[email protected]>
>
> v1 -> v2
> * Add more descriptions
>
> drivers/net/wireless/realtek/rtw88/phy.c | 10 ----------
> drivers/net/wireless/realtek/rtw88/rtw8822c.c | 15 +++++++++++++++
> drivers/net/wireless/realtek/rtw88/rtw8822c.h | 5 +++++
> 3 files changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/net/wireless/realtek/rtw88/phy.c b/drivers/net/wireless/realtek/rtw88/phy.c
> index eea9d888fbf1..8793dd22188f 100644
> --- a/drivers/net/wireless/realtek/rtw88/phy.c
> +++ b/drivers/net/wireless/realtek/rtw88/phy.c
> @@ -749,20 +749,10 @@ bool rtw_phy_write_rf_reg(struct rtw_dev *rtwdev, enum rtw_rf_path rf_path,
> direct_addr = base_addr[rf_path] + (addr << 2);
> mask &= RFREG_MASK;
>
> - if (addr == RF_CFGCH) {
> - rtw_write32_mask(rtwdev, REG_RSV_CTRL, BITS_RFC_DIRECT, DISABLE_PI);
> - rtw_write32_mask(rtwdev, REG_WLRF1, BITS_RFC_DIRECT, DISABLE_PI);
> - }
> -
> rtw_write32_mask(rtwdev, direct_addr, mask, data);
>
> udelay(1);
>
> - if (addr == RF_CFGCH) {
> - rtw_write32_mask(rtwdev, REG_RSV_CTRL, BITS_RFC_DIRECT, ENABLE_PI);
> - rtw_write32_mask(rtwdev, REG_WLRF1, BITS_RFC_DIRECT, ENABLE_PI);
> - }
> -
> return true;
> }
>
> diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
> index 4c416d603b33..fb621881fbd1 100644
> --- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
> +++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
> @@ -1289,6 +1289,17 @@ static int rtw8822c_mac_init(struct rtw_dev *rtwdev)
> return 0;
> }
>
> +static void rtw8822c_rstb_3wire(struct rtw_dev *rtwdev, bool enable)
> +{
> + if (enable) {
> + rtw_write32_mask(rtwdev, REG_RSTB, BIT_RSTB_3WIRE, 0x1);
> + rtw_write32_mask(rtwdev, REG_ANAPAR_A, BIT_ANAPAR_UPDATE, 0x1);
> + rtw_write32_mask(rtwdev, REG_ANAPAR_B, BIT_ANAPAR_UPDATE, 0x1);
> + } else {
> + rtw_write32_mask(rtwdev, REG_RSTB, BIT_RSTB_3WIRE, 0x0);
> + }
> +}
> +
> static void rtw8822c_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw)
> {
> #define RF18_BAND_MASK (BIT(16) | BIT(9) | BIT(8))
> @@ -1337,6 +1348,8 @@ static void rtw8822c_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw)
> break;
> }
>
> + rtw8822c_rstb_3wire(rtwdev, false);
> +
> rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWE2, 0x04, 0x01);
> rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWA, 0x1f, 0x12);
> rtw_write_rf(rtwdev, RF_PATH_A, RF_LUTWD0, 0xfffff, rf_rxbb);
> @@ -1349,6 +1362,8 @@ static void rtw8822c_set_channel_rf(struct rtw_dev *rtwdev, u8 channel, u8 bw)
>
> rtw_write_rf(rtwdev, RF_PATH_A, RF_CFGCH, RFREG_MASK, rf_reg18);
> rtw_write_rf(rtwdev, RF_PATH_B, RF_CFGCH, RFREG_MASK, rf_reg18);
> +
> + rtw8822c_rstb_3wire(rtwdev, true);
> }
>
> static void rtw8822c_toggle_igi(struct rtw_dev *rtwdev)
> diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.h b/drivers/net/wireless/realtek/rtw88/rtw8822c.h
> index abd9f300bedd..dfd8662a0c0e 100644
> --- a/drivers/net/wireless/realtek/rtw88/rtw8822c.h
> +++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.h
> @@ -190,6 +190,8 @@ const struct rtw_table name ## _tbl = { \
> #define BIT_3WIRE_TX_EN BIT(0)
> #define BIT_3WIRE_RX_EN BIT(1)
> #define BIT_3WIRE_PI_ON BIT(28)
> +#define REG_ANAPAR_A 0x1830
> +#define BIT_ANAPAR_UPDATE BIT(29)
> #define REG_RXAGCCTL0 0x18ac
> #define BITS_RXAGC_CCK GENMASK(15, 12)
> #define BITS_RXAGC_OFDM GENMASK(8, 4)
> @@ -223,6 +225,8 @@ const struct rtw_table name ## _tbl = { \
> #define BIT_CCK_BLK_EN BIT(1)
> #define BIT_CCK_OFDM_BLK_EN (BIT(0) | BIT(1))
> #define REG_CCAMSK 0x1c80
> +#define REG_RSTB 0x1c90
> +#define BIT_RSTB_3WIRE BIT(8)
> #define REG_RX_BREAK 0x1d2c
> #define BIT_COM_RX_GCK_EN BIT(31)
> #define REG_RXFNCTL 0x1d30
> @@ -243,6 +247,7 @@ const struct rtw_table name ## _tbl = { \
> #define REG_OFDM_TXCNT 0x2de0
> #define REG_ORITXCODE2 0x4100
> #define REG_3WIRE2 0x410c
> +#define REG_ANAPAR_B 0x4130
> #define REG_RXAGCCTL 0x41ac
> #define REG_DCKB_I_0 0x41bc
> #define REG_DCKB_I_1 0x41c0
> --
> 2.17.1
>

2020-02-12 16:22:08

by Kalle Valo

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] rtw88: Use secondary channel offset enumeration

<[email protected]> wrote:

> From: Ping-Ke Shih <[email protected]>
>
> The hardware value of secondary channel offset isn't very intuitive. This
> commit adds enumeration, so we can easier to check the logic with the
> suffix of enumeration name, likes _UPPER or _LOWER.
>
> Signed-off-by: Ping-Ke Shih <[email protected]>
> Signed-off-by: Yan-Hsuan Chuang <[email protected]>
> Reviewed-by: Chris Chiu <[email protected]>

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

40fb04b22f31 rtw88: Use secondary channel offset enumeration
9c714b7caa17 rtw88: 8822c: modify rf protection setting

--
https://patchwork.kernel.org/patch/11357419/

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