diff mbox series

[v2,1/3] wifi: rtl8xxxu: Move burst init to a function

Message ID bef90bf8-716f-c92f-9403-12ef2bfefc15@gmail.com (mailing list archive)
State Accepted
Commit bcfcb712e41401887930361946666549e8ba7747
Delegated to: Kalle Valo
Headers show
Series [v2,1/3] wifi: rtl8xxxu: Move burst init to a function | expand

Commit Message

Bitterblue Smith Nov. 5, 2022, 10:53 p.m. UTC
No changes to functionality, just moving code to make
rtl8xxxu_init_device look nicer.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
---
v2:
 - No change.
---
 .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  2 +
 .../realtek/rtl8xxxu/rtl8xxxu_8188f.c         |  1 +
 .../realtek/rtl8xxxu/rtl8xxxu_8723b.c         |  1 +
 .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 89 ++++++++++---------
 4 files changed, 52 insertions(+), 41 deletions(-)

Comments

Ping-Ke Shih Nov. 7, 2022, 2:40 a.m. UTC | #1
> -----Original Message-----
> From: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> Sent: Sunday, November 6, 2022 6:53 AM
> To: linux-wireless@vger.kernel.org
> Cc: Jes Sorensen <Jes.Sorensen@gmail.com>
> Subject: [PATCH v2 1/3] wifi: rtl8xxxu: Move burst init to a function
> 
> No changes to functionality, just moving code to make
> rtl8xxxu_init_device look nicer.
> 
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
> ---
> v2:
>  - No change.
> ---
>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  2 +
>  .../realtek/rtl8xxxu/rtl8xxxu_8188f.c         |  1 +
>  .../realtek/rtl8xxxu/rtl8xxxu_8723b.c         |  1 +
>  .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 89 ++++++++++---------
>  4 files changed, 52 insertions(+), 41 deletions(-)
> 

[...]

> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
> index 019f8ddd418b..282ad8a9b73d 100644
> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
> @@ -3886,6 +3886,52 @@ static void rtl8xxxu_init_queue_reserved_page(struct rtl8xxxu_priv *priv)
>  	rtl8xxxu_write32(priv, REG_RQPN, val32);
>  }
> 
> +void rtl8xxxu_init_burst(struct rtl8xxxu_priv *priv)
> +{
> +	u8 val8;
> +
> +	/*
> +	 * For USB high speed set 512B packets
> +	 */
> +	val8 = rtl8xxxu_read8(priv, REG_RXDMA_PRO_8723B);
> +	val8 &= ~(BIT(4) | BIT(5));
> +	val8 |= BIT(4);
> +	val8 |= BIT(1) | BIT(2) | BIT(3);

I think we can fix these magic numbers along with your patch.

#define DMA_MODE BIT(1)  // set 0x1
#define DMA_BURST_CNT GENMASK(3, 2) // set 0x3
#define DMA_BURST_SIZE GENMASK(5, 4) // set 0x1


> +	rtl8xxxu_write8(priv, REG_RXDMA_PRO_8723B, val8);
> +
> +	/*
> +	 * Enable single packet AMPDU
> +	 */
> +	val8 = rtl8xxxu_read8(priv, REG_HT_SINGLE_AMPDU_8723B);
> +	val8 |= BIT(7);

#define EN_SINGLE_AMPDU BIT(7)

> +	rtl8xxxu_write8(priv, REG_HT_SINGLE_AMPDU_8723B, val8);
> +
> +	rtl8xxxu_write16(priv, REG_MAX_AGGR_NUM, 0x0c14);
> +	if (priv->rtl_chip == RTL8723B)
> +		val8 = 0x5e;
> +	else if (priv->rtl_chip == RTL8188F)
> +		val8 = 0x70; /* 0x5e would make it very slow */
> +	rtl8xxxu_write8(priv, REG_AMPDU_MAX_TIME_8723B, val8);
> +	rtl8xxxu_write32(priv, REG_AGGLEN_LMT, 0xffffffff);
> +	rtl8xxxu_write8(priv, REG_RX_PKT_LIMIT, 0x18);
> +	rtl8xxxu_write8(priv, REG_PIFS, 0x00);
> +	if (priv->rtl_chip == RTL8188F) {
> +		rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL, FWHW_TXQ_CTRL_AMPDU_RETRY);
> +		rtl8xxxu_write32(priv, REG_FAST_EDCA_CTRL, 0x03086666);
> +	}
> +	if (priv->rtl_chip == RTL8723B)
> +		val8 = 0x50;
> +	else if (priv->rtl_chip == RTL8188F)
> +		val8 = 0x28; /* 0x50 would make the upload slow */
> +	rtl8xxxu_write8(priv, REG_USTIME_TSF_8723B, val8);
> +	rtl8xxxu_write8(priv, REG_USTIME_EDCA, val8);
> +
> +	/* to prevent mac is reseted by bus. */
> +	val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
> +	val8 |= BIT(5) | BIT(6);

#define WLOCK_1C BIT(5)
#define DIS_PRST BIT(6)

> +	rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
> +}
> +

[...]

I find some bit definitions, so we can have them meaningful names, and
please add proper prefix if need.

Ping-Ke
Bitterblue Smith Nov. 7, 2022, 3:50 p.m. UTC | #2
On 07/11/2022 04:40, Ping-Ke Shih wrote:
> 
> 
>> -----Original Message-----
>> From: Bitterblue Smith <rtl8821cerfe2@gmail.com>
>> Sent: Sunday, November 6, 2022 6:53 AM
>> To: linux-wireless@vger.kernel.org
>> Cc: Jes Sorensen <Jes.Sorensen@gmail.com>
>> Subject: [PATCH v2 1/3] wifi: rtl8xxxu: Move burst init to a function
>>
>> No changes to functionality, just moving code to make
>> rtl8xxxu_init_device look nicer.
>>
>> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
>> ---
>> v2:
>>  - No change.
>> ---
>>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  2 +
>>  .../realtek/rtl8xxxu/rtl8xxxu_8188f.c         |  1 +
>>  .../realtek/rtl8xxxu/rtl8xxxu_8723b.c         |  1 +
>>  .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 89 ++++++++++---------
>>  4 files changed, 52 insertions(+), 41 deletions(-)
>>
> 
> [...]
> 
>> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
>> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
>> index 019f8ddd418b..282ad8a9b73d 100644
>> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
>> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
>> @@ -3886,6 +3886,52 @@ static void rtl8xxxu_init_queue_reserved_page(struct rtl8xxxu_priv *priv)
>>  	rtl8xxxu_write32(priv, REG_RQPN, val32);
>>  }
>>
>> +void rtl8xxxu_init_burst(struct rtl8xxxu_priv *priv)
>> +{
>> +	u8 val8;
>> +
>> +	/*
>> +	 * For USB high speed set 512B packets
>> +	 */
>> +	val8 = rtl8xxxu_read8(priv, REG_RXDMA_PRO_8723B);
>> +	val8 &= ~(BIT(4) | BIT(5));
>> +	val8 |= BIT(4);
>> +	val8 |= BIT(1) | BIT(2) | BIT(3);
> 
> I think we can fix these magic numbers along with your patch.
> 
> #define DMA_MODE BIT(1)  // set 0x1
> #define DMA_BURST_CNT GENMASK(3, 2) // set 0x3
> #define DMA_BURST_SIZE GENMASK(5, 4) // set 0x1
> 

Thanks, but I think the bit definitions should be added in a separate patch,
which I will send soon. Same for the changes you suggested for patch 2/3.
Jes Sorensen Nov. 8, 2022, 1:56 p.m. UTC | #3
On 11/6/22 21:40, Ping-Ke Shih wrote:
> 
> 
>> -----Original Message-----
>> From: Bitterblue Smith <rtl8821cerfe2@gmail.com>
>> Sent: Sunday, November 6, 2022 6:53 AM
>> To: linux-wireless@vger.kernel.org
>> Cc: Jes Sorensen <Jes.Sorensen@gmail.com>
>> Subject: [PATCH v2 1/3] wifi: rtl8xxxu: Move burst init to a function
>>
>> No changes to functionality, just moving code to make
>> rtl8xxxu_init_device look nicer.
>>
>> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
>> ---
>> v2:
>>  - No change.
>> ---
>>  .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h  |  2 +
>>  .../realtek/rtl8xxxu/rtl8xxxu_8188f.c         |  1 +
>>  .../realtek/rtl8xxxu/rtl8xxxu_8723b.c         |  1 +
>>  .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 89 ++++++++++---------
>>  4 files changed, 52 insertions(+), 41 deletions(-)
>>
> 
> [...]
> 
>> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
>> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
>> index 019f8ddd418b..282ad8a9b73d 100644
>> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
>> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
>> @@ -3886,6 +3886,52 @@ static void rtl8xxxu_init_queue_reserved_page(struct rtl8xxxu_priv *priv)
>>  	rtl8xxxu_write32(priv, REG_RQPN, val32);
>>  }
>>
>> +void rtl8xxxu_init_burst(struct rtl8xxxu_priv *priv)
>> +{
>> +	u8 val8;
>> +
>> +	/*
>> +	 * For USB high speed set 512B packets
>> +	 */
>> +	val8 = rtl8xxxu_read8(priv, REG_RXDMA_PRO_8723B);
>> +	val8 &= ~(BIT(4) | BIT(5));
>> +	val8 |= BIT(4);
>> +	val8 |= BIT(1) | BIT(2) | BIT(3);
> 
> I think we can fix these magic numbers along with your patch.
> 
> #define DMA_MODE BIT(1)  // set 0x1
> #define DMA_BURST_CNT GENMASK(3, 2) // set 0x3
> #define DMA_BURST_SIZE GENMASK(5, 4) // set 0x1

Thanks for providing these definitions.

Jes
Kalle Valo Nov. 16, 2022, 9:26 a.m. UTC | #4
Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:

> No changes to functionality, just moving code to make
> rtl8xxxu_init_device look nicer.
> 
> Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>

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

bcfcb712e414 wifi: rtl8xxxu: Move burst init to a function
14566bbfdfaf wifi: rtl8xxxu: Split up rtl8xxxu_identify_chip
e948023d5fc8 wifi: rtl8xxxu: Rename rtl8xxxu_8188f_channel_to_group
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
index 6ff554ba0250..9f8b23160ed0 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
@@ -1485,6 +1485,7 @@  struct rtl8xxxu_fileops {
 	int (*parse_rx_desc) (struct rtl8xxxu_priv *priv, struct sk_buff *skb);
 	void (*init_aggregation) (struct rtl8xxxu_priv *priv);
 	void (*init_statistics) (struct rtl8xxxu_priv *priv);
+	void (*init_burst) (struct rtl8xxxu_priv *priv);
 	void (*enable_rf) (struct rtl8xxxu_priv *priv);
 	void (*disable_rf) (struct rtl8xxxu_priv *priv);
 	void (*usb_quirks) (struct rtl8xxxu_priv *priv);
@@ -1592,6 +1593,7 @@  void rtl8xxxu_gen1_init_aggregation(struct rtl8xxxu_priv *priv);
 void rtl8xxxu_gen1_enable_rf(struct rtl8xxxu_priv *priv);
 void rtl8xxxu_gen1_disable_rf(struct rtl8xxxu_priv *priv);
 void rtl8xxxu_gen2_disable_rf(struct rtl8xxxu_priv *priv);
+void rtl8xxxu_init_burst(struct rtl8xxxu_priv *priv);
 int rtl8xxxu_parse_rxdesc16(struct rtl8xxxu_priv *priv, struct sk_buff *skb);
 int rtl8xxxu_parse_rxdesc24(struct rtl8xxxu_priv *priv, struct sk_buff *skb);
 int rtl8xxxu_gen2_channel_to_group(int channel);
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
index 5a5b7fa4283c..5eadeb02a762 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8188f.c
@@ -1705,6 +1705,7 @@  struct rtl8xxxu_fileops rtl8188fu_fops = {
 	.parse_rx_desc = rtl8xxxu_parse_rxdesc24,
 	.init_aggregation = rtl8188fu_init_aggregation,
 	.init_statistics = rtl8188fu_init_statistics,
+	.init_burst = rtl8xxxu_init_burst,
 	.enable_rf = rtl8188f_enable_rf,
 	.disable_rf = rtl8188f_disable_rf,
 	.usb_quirks = rtl8188f_usb_quirks,
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
index 9214c1d3b644..27df8805cb18 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_8723b.c
@@ -1683,6 +1683,7 @@  struct rtl8xxxu_fileops rtl8723bu_fops = {
 	.parse_rx_desc = rtl8xxxu_parse_rxdesc24,
 	.init_aggregation = rtl8723bu_init_aggregation,
 	.init_statistics = rtl8723bu_init_statistics,
+	.init_burst = rtl8xxxu_init_burst,
 	.enable_rf = rtl8723b_enable_rf,
 	.disable_rf = rtl8xxxu_gen2_disable_rf,
 	.usb_quirks = rtl8xxxu_gen2_usb_quirks,
diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
index 019f8ddd418b..282ad8a9b73d 100644
--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
+++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
@@ -3886,6 +3886,52 @@  static void rtl8xxxu_init_queue_reserved_page(struct rtl8xxxu_priv *priv)
 	rtl8xxxu_write32(priv, REG_RQPN, val32);
 }
 
+void rtl8xxxu_init_burst(struct rtl8xxxu_priv *priv)
+{
+	u8 val8;
+
+	/*
+	 * For USB high speed set 512B packets
+	 */
+	val8 = rtl8xxxu_read8(priv, REG_RXDMA_PRO_8723B);
+	val8 &= ~(BIT(4) | BIT(5));
+	val8 |= BIT(4);
+	val8 |= BIT(1) | BIT(2) | BIT(3);
+	rtl8xxxu_write8(priv, REG_RXDMA_PRO_8723B, val8);
+
+	/*
+	 * Enable single packet AMPDU
+	 */
+	val8 = rtl8xxxu_read8(priv, REG_HT_SINGLE_AMPDU_8723B);
+	val8 |= BIT(7);
+	rtl8xxxu_write8(priv, REG_HT_SINGLE_AMPDU_8723B, val8);
+
+	rtl8xxxu_write16(priv, REG_MAX_AGGR_NUM, 0x0c14);
+	if (priv->rtl_chip == RTL8723B)
+		val8 = 0x5e;
+	else if (priv->rtl_chip == RTL8188F)
+		val8 = 0x70; /* 0x5e would make it very slow */
+	rtl8xxxu_write8(priv, REG_AMPDU_MAX_TIME_8723B, val8);
+	rtl8xxxu_write32(priv, REG_AGGLEN_LMT, 0xffffffff);
+	rtl8xxxu_write8(priv, REG_RX_PKT_LIMIT, 0x18);
+	rtl8xxxu_write8(priv, REG_PIFS, 0x00);
+	if (priv->rtl_chip == RTL8188F) {
+		rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL, FWHW_TXQ_CTRL_AMPDU_RETRY);
+		rtl8xxxu_write32(priv, REG_FAST_EDCA_CTRL, 0x03086666);
+	}
+	if (priv->rtl_chip == RTL8723B)
+		val8 = 0x50;
+	else if (priv->rtl_chip == RTL8188F)
+		val8 = 0x28; /* 0x50 would make the upload slow */
+	rtl8xxxu_write8(priv, REG_USTIME_TSF_8723B, val8);
+	rtl8xxxu_write8(priv, REG_USTIME_EDCA, val8);
+
+	/* to prevent mac is reseted by bus. */
+	val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
+	val8 |= BIT(5) | BIT(6);
+	rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
+}
+
 static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
 {
 	struct rtl8xxxu_priv *priv = hw->priv;
@@ -4139,48 +4185,9 @@  static int rtl8xxxu_init_device(struct ieee80211_hw *hw)
 	/*
 	 * Initialize burst parameters
 	 */
-	if (priv->rtl_chip == RTL8723B || priv->rtl_chip == RTL8188F) {
-		/*
-		 * For USB high speed set 512B packets
-		 */
-		val8 = rtl8xxxu_read8(priv, REG_RXDMA_PRO_8723B);
-		val8 &= ~(BIT(4) | BIT(5));
-		val8 |= BIT(4);
-		val8 |= BIT(1) | BIT(2) | BIT(3);
-		rtl8xxxu_write8(priv, REG_RXDMA_PRO_8723B, val8);
 
-		/*
-		 * For USB high speed set 512B packets
-		 */
-		val8 = rtl8xxxu_read8(priv, REG_HT_SINGLE_AMPDU_8723B);
-		val8 |= BIT(7);
-		rtl8xxxu_write8(priv, REG_HT_SINGLE_AMPDU_8723B, val8);
-
-		rtl8xxxu_write16(priv, REG_MAX_AGGR_NUM, 0x0c14);
-		if (priv->rtl_chip == RTL8723B)
-			val8 = 0x5e;
-		else if (priv->rtl_chip == RTL8188F)
-			val8 = 0x70; /* 0x5e would make it very slow */
-		rtl8xxxu_write8(priv, REG_AMPDU_MAX_TIME_8723B, val8);
-		rtl8xxxu_write32(priv, REG_AGGLEN_LMT, 0xffffffff);
-		rtl8xxxu_write8(priv, REG_RX_PKT_LIMIT, 0x18);
-		rtl8xxxu_write8(priv, REG_PIFS, 0x00);
-		if (priv->rtl_chip == RTL8188F) {
-			rtl8xxxu_write8(priv, REG_FWHW_TXQ_CTRL, FWHW_TXQ_CTRL_AMPDU_RETRY);
-			rtl8xxxu_write32(priv, REG_FAST_EDCA_CTRL, 0x03086666);
-		}
-		if (priv->rtl_chip == RTL8723B)
-			val8 = 0x50;
-		else if (priv->rtl_chip == RTL8188F)
-			val8 = 0x28; /* 0x50 would make the upload slow */
-		rtl8xxxu_write8(priv, REG_USTIME_TSF_8723B, val8);
-		rtl8xxxu_write8(priv, REG_USTIME_EDCA, val8);
-
-		/* to prevent mac is reseted by bus. */
-		val8 = rtl8xxxu_read8(priv, REG_RSV_CTRL);
-		val8 |= BIT(5) | BIT(6);
-		rtl8xxxu_write8(priv, REG_RSV_CTRL, val8);
-	}
+	if (priv->fops->init_burst)
+		priv->fops->init_burst(priv);
 
 	if (fops->init_aggregation)
 		fops->init_aggregation(priv);