Skip to contentSkip to conversation

r8152: serial fixes

PATCH Applied Hayes Wang 11 participants 64 messages Jan 21, 2020 – Jun 17, 2021

Subsystems (4)
lore
Share & tools
lore

Hayes Wang

author
#0 lore raw

cover r8152: serial fixes

These patches are used to fix some issues for RTL8153.

Hayes Wang (9):
r8152: fix runtime resume for linking change
r8152: reset flow control patch when linking on for RTL8153B
r8152: get default setting of WOL before initializing
r8152: disable U2P3 for RTL8153B
r8152: Disable PLA MCU clock speed down
r8152: disable test IO for RTL8153B
r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B
r8152: avoid the MCU to clear the lanwake
r8152: disable DelayPhyPwrChg

 drivers/net/usb/r8152.c | 124 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 113 insertions(+), 11 deletions(-)
Signature · 1 line
2.21.0
author
#1 lore raw

PATCH 1/9 r8152: fix runtime resume for linking change

Fix the runtime resume doesn't work normally for linking change.

1. Reset the settings and status of runtime suspend.
2. Sync the linking status.
3. Poll the linking change.

---
 drivers/net/usb/r8152.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/net/usb/r8152.c +21 -0
index 031cb8fff909..115559707683 100644
@@ -365,8 +365,10 @@
 #define DEBUG_LTSSM		0x0082
 
 /* PLA_EXTRA_STATUS */
+#define CUR_LINK_OK		BIT(15)
 #define U3P3_CHECK_EN		BIT(7)	/* RTL_VER_05 only */
 #define LINK_CHANGE_FLAG	BIT(8)
+#define POLL_LINK_CHG		BIT(0)
 
 /* USB_USB2PHY */
 #define USB2PHY_SUSPEND		0x0001
@@ -5387,6 +5389,16 @@ static void r8153_init(struct r8152 *tp)
 		else
 			ocp_data |= DYNAMIC_BURST;
 		ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
+
+		r8153_queue_wake(tp, false);
+
+		ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
+		if (rtl8152_get_speed(tp) & LINK_STATUS)
+			ocp_data |= CUR_LINK_OK;
+		else
+			ocp_data &= ~CUR_LINK_OK;
+		ocp_data |= POLL_LINK_CHG;
+		ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
 	}
 
 	ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2);
@@ -5416,6 +5428,7 @@ static void r8153_init(struct r8152 *tp)
 	ocp_write_word(tp, MCU_TYPE_USB, USB_CONNECT_TIMER, 0x0001);
 
 	r8153_power_cut_en(tp, false);
+	rtl_runtime_suspend_enable(tp, false);
 	r8153_u1u2en(tp, true);
 	r8153_mac_clk_spd(tp, false);
 	usb_enable_lpm(tp->udev);
@@ -5484,6 +5497,14 @@ static void r8153b_init(struct r8152 *tp)
 	r8153b_ups_en(tp, false);
 	r8153_queue_wake(tp, false);
 	rtl_runtime_suspend_enable(tp, false);
+
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
+	if (rtl8152_get_speed(tp) & LINK_STATUS)
+		ocp_data |= CUR_LINK_OK;
+	else
+		ocp_data &= ~CUR_LINK_OK;
+	ocp_data |= POLL_LINK_CHG;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
 	r8153b_u1u2en(tp, true);
 	usb_enable_lpm(tp->udev);
 
Signature · 1 line
2.21.0
#2 lore raw

Re: [PATCH net 1/9] r8152: fix runtime resume for linking change

Hello!

Quoted 1 line · Hayes Wang

Fix the runtime resume doesn't work normally for linking change.

s/doesn't work/not working/?

Quoted 5 lines

1. Reset the settings and status of runtime suspend.
2. Sync the linking status.
3. Poll the linking change.

[...]

MBR, Sergei

author
#3 lore raw

PATCH 2/9 r8152: reset flow control patch when linking on for RTL8153B

In reply to Hayes Wang

When linking ON, the patch of flow control has to be reset. This makes sure the patch works normally.

---
 drivers/net/usb/r8152.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/usb/r8152.c +10 -0
index 115559707683..64efd58279b3 100644
@@ -2857,6 +2857,7 @@ static void r8153_set_rx_early_size(struct r8152 *tp)
 
 static int rtl8153_enable(struct r8152 *tp)
 {
+	u32 ocp_data;
 	if (test_bit(RTL8152_UNPLUG, &tp->flags))
 		return -ENODEV;
 
@@ -2865,6 +2866,15 @@ static int rtl8153_enable(struct r8152 *tp)
 	r8153_set_rx_early_timeout(tp);
 	r8153_set_rx_early_size(tp);
 
+	if (tp->version == RTL_VER_09) {
+		ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK);
+		ocp_data &= ~FC_PATCH_TASK;
+		ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data);
+		usleep_range(1000, 2000);
+		ocp_data |= FC_PATCH_TASK;
+		ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data);
+	}
+
 	return rtl_enable(tp);
 }
 
Signature · 1 line
2.21.0
maintainer
#4 lore raw

Re: [PATCH net 2/9] r8152: reset flow control patch when linking on for RTL8153B

From: Hayes Wang <[email protected]>
Date: Tue, 21 Jan 2020 20:40:28 +0800

Quoted 13 lines

When linking ON, the patch of flow control has to be reset. This makes sure the patch works normally.

---
 drivers/net/usb/r8152.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/usb/r8152.c +0 -0
index 115559707683..64efd58279b3 100644

drivers/net/usb/r8152.c static void r8153_set_rx_early_size(struct r8152 *tp) · line 2863

Quoted 7 lines
drivers/net/usb/r8152.c +1 -0
@@ -2857,6 +2857,7 @@ static void r8153_set_rx_early_size(struct r8152 *tp)
 
 static int rtl8153_enable(struct r8152 *tp)
 {
+	u32 ocp_data;
 	if (test_bit(RTL8152_UNPLUG, &tp->flags))
 		return -ENODEV;
 

Please put an empty line after the local variable declarations.

Thank you.

#5 lore raw

Re: [PATCH net 2/9] r8152: reset flow control patch when linking on for RTL8153B

Quoted 5 lines · David Miller

From: Hayes Wang <[email protected]>
Date: Tue, 21 Jan 2020 20:40:28 +0800

Quoted 2 lines

When linking ON, the patch of flow control has to be reset. This makes sure the patch works normally.

[]

Quoted 1 line

drivers/net/usb/r8152.c

Quoted 1 line
drivers/net/usb/r8152.c +0 -0

[]

Quoted 10 lines

drivers/net/usb/r8152.c static void r8153_set_rx_early_size(struct r8152 *tp) · line 2863

Quoted 8 lines
drivers/net/usb/r8152.c +1 -0
@@ -2857,6 +2857,7 @@ static void r8153_set_rx_early_size(struct r8152 *tp)
 
 static int rtl8153_enable(struct r8152 *tp)
 {
+     u32 ocp_data;
      if (test_bit(RTL8152_UNPLUG, &tp->flags))
              return -ENODEV;
 

Please put an empty line after the local variable declarations.

Local scoping is generally better.

Perhaps declare ocp_data inside the if branch
where it's used.

author
#6 lore raw

RE: [PATCH net 2/9] r8152: reset flow control patch when linking on for RTL8153B

Joe Perches [mailto:[email protected]]

Quoted 2 lines

Sent: Tuesday, January 21, 2020 9:01 PM
To: David Miller; Hayes Wang

[...]

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

static int rtl8153_enable(struct r8152 *tp)
{

+     u32 ocp_data;
      if (test_bit(RTL8152_UNPLUG, &tp->flags))
              return -ENODEV;
Quoted 6 lines
Quoted 1 line

Please put an empty line after the local variable declarations.

Local scoping is generally better.

Perhaps declare ocp_data inside the if branch
where it's used.

OK. I would move it.

Best Regards,
Hayes

author
#7 lore raw

PATCH 3/9 r8152: get default setting of WOL before initializing

In reply to Hayes Wang

Initailization would reset runtime suspend by tp->saved_wolopts, so the tp->saved_wolopts should be set before initializing.

---
 drivers/net/usb/r8152.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/usb/r8152.c +5 -4
index 64efd58279b3..e29e1a13e811 100644
@@ -6738,6 +6738,11 @@ static int rtl8152_probe(struct usb_interface *intf,
 
 	intf->needs_remote_wakeup = 1;
 
+	if (!rtl_can_wakeup(tp))
+		__rtl_set_wol(tp, 0);
+	else
+		tp->saved_wolopts = __rtl_get_wol(tp);
+
 	tp->rtl_ops.init(tp);
 #if IS_BUILTIN(CONFIG_USB_RTL8152)
 	/* Retry in case request_firmware() is not ready yet. */
@@ -6755,10 +6760,6 @@ static int rtl8152_probe(struct usb_interface *intf,
 		goto out1;
 	}
 
-	if (!rtl_can_wakeup(tp))
-		__rtl_set_wol(tp, 0);
-
-	tp->saved_wolopts = __rtl_get_wol(tp);
 	if (tp->saved_wolopts)
 		device_set_wakeup_enable(&udev->dev, true);
 	else
Signature · 1 line
2.21.0
#8 lore raw

Re: [PATCH net-next 0/4] r8152: minor adjustments

This series was applied to netdev/net.git (refs/heads/master):

Hello:

This series was applied to netdev/net.git (refs/heads/master):

Quoted 9 lines · On Fri, 19 Feb 2021 17:04:39 +0800 you wrote:

These patches are used to adjust the code.

Hayes Wang (4):
r8152: enable U1/U2 for USB_SPEED_SUPER
r8152: check if the pointer of the function exists
r8152: replace netif_err with dev_err
r8152: spilt rtl_set_eee_plus and r8153b_green_en

[...]

Here is the summary with links:
- [net-next,1/4] r8152: enable U1/U2 for USB_SPEED_SUPER

    https://git.kernel.org/netdev/net/c/7a0ae61acde2
  - [net-next,2/4] r8152: check if the pointer of the function exists
    https://git.kernel.org/netdev/net/c/c79515e47935
  - [net-next,3/4] r8152: replace netif_err with dev_err
    https://git.kernel.org/netdev/net/c/156c32076112
  - [net-next,4/4] r8152: spilt rtl_set_eee_plus and r8153b_green_en
    https://git.kernel.org/netdev/net/c/40fa7568ac23

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

author
#9 lore raw

PATCH 4/9 r8152: disable U2P3 for RTL8153B

In reply to Hayes Wang

Enable U2P3 may miss zero packet for bulk-in.

---
 drivers/net/usb/r8152.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/usb/r8152.c +0 -3
index e29e1a13e811..0a118fd83692 100644
@@ -3388,7 +3388,6 @@ static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable)
 		r8153b_ups_en(tp, false);
 		r8153_queue_wake(tp, false);
 		rtl_runtime_suspend_enable(tp, false);
-		r8153_u2p3en(tp, true);
 		r8153b_u1u2en(tp, true);
 	}
 }
@@ -4687,7 +4686,6 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp)
 
 	r8153_aldps_en(tp, true);
 	r8152b_enable_fc(tp);
-	r8153_u2p3en(tp, true);
 
 	set_bit(PHY_RESET, &tp->flags);
 }
@@ -5017,7 +5015,6 @@ static void rtl8153b_up(struct r8152 *tp)
 	ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B);
 
 	r8153_aldps_en(tp, true);
-	r8153_u2p3en(tp, true);
 	r8153b_u1u2en(tp, true);
 }
 
Signature · 1 line
2.21.0
author
#10 lore raw

PATCH 5/9 r8152: Disable PLA MCU clock speed down

In reply to Hayes Wang

PLA MCU clock speed down could only be enabled when tx/rx are disabled. Otherwise, the packet lost may occur.

---
 drivers/net/usb/r8152.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/usb/r8152.c +17 -0
index 0a118fd83692..eabc7b43d48b 100644
@@ -324,6 +324,7 @@
 #define MAC_CLK_SPDWN_EN	BIT(15)
 
 /* PLA_MAC_PWR_CTRL3 */
+#define PLA_MCU_SPDWN_EN	BIT(14)
 #define PKT_AVAIL_SPDWN_EN	0x0100
 #define SUSPEND_SPDWN_EN	0x0004
 #define U1U2_SPDWN_EN		0x0002
@@ -5004,6 +5005,8 @@ static void rtl8153_down(struct r8152 *tp)
 
 static void rtl8153b_up(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags))
 		return;
 
@@ -5014,17 +5017,27 @@ static void rtl8153b_up(struct r8152 *tp)
 	r8153_first_init(tp);
 	ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B);
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data &= ~PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
 	r8153_aldps_en(tp, true);
 	r8153b_u1u2en(tp, true);
 }
 
 static void rtl8153b_down(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags)) {
 		rtl_drop_queued_tx(tp);
 		return;
 	}
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data |= PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
 	r8153b_u1u2en(tp, false);
 	r8153_u2p3en(tp, false);
 	r8153b_power_cut_en(tp, false);
@@ -5520,6 +5533,10 @@ static void r8153b_init(struct r8152 *tp)
 	ocp_data |= MAC_CLK_SPDWN_EN;
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data);
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data &= ~PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
 	set_bit(GREEN_ETHERNET, &tp->flags);
 
 	/* rx aggregation */
Signature · 1 line
2.21.0
author
#11 lore raw

PATCH 6/9 r8152: disable test IO for RTL8153B

In reply to Hayes Wang

For RTL8153B with QFN32, disable test IO. Otherwise, it may casue abnormal behavior for the device randomly.

---
 drivers/net/usb/r8152.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/usb/r8152.c +10 -0
index eabc7b43d48b..958c7c342bfb 100644
@@ -312,6 +312,7 @@
 /* PLA_PHY_PWR */
 #define TX_10M_IDLE_EN		0x0080
 #define PFM_PWM_SWITCH		0x0040
+#define TEST_IO_OFF		BIT(4)
 
 /* PLA_MAC_PWR_CTRL */
 #define D3_CLK_GATED_EN		0x00004000
@@ -5537,6 +5538,15 @@ static void r8153b_init(struct r8152 *tp)
 	ocp_data &= ~PLA_MCU_SPDWN_EN;
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
 
+	if (tp->version == RTL_VER_09) {
+		/* Disable Test IO for 32QFN */
+		if (ocp_read_byte(tp, MCU_TYPE_PLA, 0xdc00) & BIT(5)) {
+			ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
+			ocp_data |= TEST_IO_OFF;
+			ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
+		}
+	}
+
 	set_bit(GREEN_ETHERNET, &tp->flags);
 
 	/* rx aggregation */
Signature · 1 line
2.21.0
author
#12 lore raw

PATCH 7/9 r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B

In reply to Hayes Wang

For certain platforms, it causes USB reset periodically.

---
 drivers/net/usb/r8152.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/usb/r8152.c +8 -3
index 958c7c342bfb..73256dfe77d7 100644
@@ -3390,7 +3390,8 @@ static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable)
 		r8153b_ups_en(tp, false);
 		r8153_queue_wake(tp, false);
 		rtl_runtime_suspend_enable(tp, false);
-		r8153b_u1u2en(tp, true);
+		if (tp->udev->speed != USB_SPEED_HIGH)
+			r8153b_u1u2en(tp, true);
 	}
 }
 
@@ -5023,7 +5024,9 @@ static void rtl8153b_up(struct r8152 *tp)
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
 
 	r8153_aldps_en(tp, true);
-	r8153b_u1u2en(tp, true);
+
+	if (tp->udev->speed != USB_SPEED_HIGH)
+		r8153b_u1u2en(tp, true);
 }
 
 static void rtl8153b_down(struct r8152 *tp)
@@ -5526,7 +5529,9 @@ static void r8153b_init(struct r8152 *tp)
 		ocp_data &= ~CUR_LINK_OK;
 	ocp_data |= POLL_LINK_CHG;
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
-	r8153b_u1u2en(tp, true);
+
+	if (tp->udev->speed != USB_SPEED_HIGH)
+		r8153b_u1u2en(tp, true);
 	usb_enable_lpm(tp->udev);
 
 	/* MAC clock speed down */
Signature · 1 line
2.21.0
author
#13 lore raw

PATCH 8/9 r8152: avoid the MCU to clear the lanwake

In reply to Hayes Wang

Avoid the MCU to clear the lanwake after suspending. It may cause the WOL fail. Disable LANWAKE_CLR_EN before suspending. Besides,enable it and reset the lanwake status when resuming or initializing.

---
 drivers/net/usb/r8152.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/net/usb/r8152.c +33 -0
index 73256dfe77d7..0998b9587943 100644
@@ -68,6 +68,7 @@
 #define PLA_LED_FEATURE		0xdd92
 #define PLA_PHYAR		0xde00
 #define PLA_BOOT_CTRL		0xe004
+#define PLA_LWAKE_CTRL_REG	0xe007
 #define PLA_GPHY_INTR_IMR	0xe022
 #define PLA_EEE_CR		0xe040
 #define PLA_EEEP_CR		0xe080
@@ -95,6 +96,7 @@
 #define PLA_TALLYCNT		0xe890
 #define PLA_SFF_STS_7		0xe8de
 #define PLA_PHYSTATUS		0xe908
+#define PLA_CONFIG6		0xe90a /* CONFIG6 */
 #define PLA_BP_BA		0xfc26
 #define PLA_BP_0		0xfc28
 #define PLA_BP_1		0xfc2a
@@ -300,6 +302,9 @@
 #define LINK_ON_WAKE_EN		0x0010
 #define LINK_OFF_WAKE_EN	0x0008
 
+/* PLA_CONFIG6 */
+#define LANWAKE_CLR_EN		BIT(0)
+
 /* PLA_CONFIG5 */
 #define BWF_EN			0x0040
 #define MWF_EN			0x0020
@@ -356,6 +361,9 @@
 /* PLA_BOOT_CTRL */
 #define AUTOLOAD_DONE		0x0002
 
+/* PLA_LWAKE_CTRL_REG */
+#define LANWAKE_PIN		BIT(7)
+
 /* PLA_SUSPEND_FLAG */
 #define LINK_CHG_EVENT		BIT(0)
 
@@ -4967,6 +4975,8 @@ static void rtl8152_down(struct r8152 *tp)
 
 static void rtl8153_up(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags))
 		return;
 
@@ -4974,6 +4984,15 @@ static void rtl8153_up(struct r8152 *tp)
 	r8153_u2p3en(tp, false);
 	r8153_aldps_en(tp, false);
 	r8153_first_init(tp);
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
+	ocp_data |= LANWAKE_CLR_EN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG);
+	ocp_data &= ~LANWAKE_PIN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
+
 	r8153_aldps_en(tp, true);
 
 	switch (tp->version) {
@@ -4992,11 +5011,17 @@ static void rtl8153_up(struct r8152 *tp)
 
 static void rtl8153_down(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags)) {
 		rtl_drop_queued_tx(tp);
 		return;
 	}
 
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
+	ocp_data &= ~LANWAKE_CLR_EN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
+
 	r8153_u1u2en(tp, false);
 	r8153_u2p3en(tp, false);
 	r8153_power_cut_en(tp, false);
@@ -5457,6 +5482,14 @@ static void r8153_init(struct r8152 *tp)
 	r8153_mac_clk_spd(tp, false);
 	usb_enable_lpm(tp->udev);
 
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
+	ocp_data |= LANWAKE_CLR_EN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG);
+	ocp_data &= ~LANWAKE_PIN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
+
 	/* rx aggregation */
 	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
 	ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN);
Signature · 1 line
2.21.0
maintainer
#14 lore raw

Re: [PATCH net] r8152: move r8153_mac_clk_spd

Quoted 8 lines · On Fri, 19 Feb 2021 17:38:03 +0800 Hayes Wang wrote:

Move calling r8153_mac_clk_spd() from r8153_first_init() to rtl8153_up(), and from r8153_enter_oob() to rtl8153_down().

r8153_mac_clk_spd() is used for RTL8153A. However, RTL8153B use r8153_first_init() and r8153_enter_oob(), too. Therefore, r8153_mac_clk_spd() needs to be moved.

Any word on what user-visible misbehavior this causes?

Can you provide a Fixes tag?

author
#15 lore raw

RE: [PATCH net] r8152: move r8153_mac_clk_spd

Jakub Kicinski <[email protected]>

Quoted 1 line

Sent: Saturday, February 20, 2021 2:23 AM

[...]

Quoted 1 line

Any word on what user-visible misbehavior this causes?

I think it influences the power saving for suspending. I am checking it with our engineers.

Quoted 1 line

Can you provide a Fixes tag?

Yes. I will add it when I updating this patch.

Best Regards,
Hayes

author
#16 lore raw

PATCH 9/9 r8152: disable DelayPhyPwrChg

In reply to Hayes Wang

Enable DelayPhyPwrChg let the device fail enter the power saving mode of P3.

---
 drivers/net/usb/r8152.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/usb/r8152.c +9 -1
index 0998b9587943..c999a58ddda9 100644
@@ -31,7 +31,7 @@
 #define NETNEXT_VERSION		"11"
 
 /* Information for net */
-#define NET_VERSION		"10"
+#define NET_VERSION		"11"
 
 #define DRIVER_VERSION		"v1." NETNEXT_VERSION "." NET_VERSION
 #define DRIVER_AUTHOR "Realtek linux nic maintainers <[email protected]>"
@@ -109,6 +109,7 @@
 #define PLA_BP_EN		0xfc38
 
 #define USB_USB2PHY		0xb41e
+#define USB_SSPHYLINK1		0xb426
 #define USB_SSPHYLINK2		0xb428
 #define USB_U2P3_CTRL		0xb460
 #define USB_CSR_DUMMY1		0xb464
@@ -384,6 +385,9 @@
 #define USB2PHY_SUSPEND		0x0001
 #define USB2PHY_L1		0x0002
 
+/* USB_SSPHYLINK1 */
+#define DELAY_PHY_PWR_CHG	BIT(1)
+
 /* USB_SSPHYLINK2 */
 #define pwd_dn_scale_mask	0x3ffe
 #define pwd_dn_scale(x)		((x) << 1)
@@ -4993,6 +4997,10 @@ static void rtl8153_up(struct r8152 *tp)
 	ocp_data &= ~LANWAKE_PIN;
 	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1);
+	ocp_data &= ~DELAY_PHY_PWR_CHG;
+	ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1, ocp_data);
+
 	r8153_aldps_en(tp, true);
 
 	switch (tp->version) {
Signature · 1 line
2.21.0
#17 lore raw

Re: [PATCH net 9/9] r8152: disable DelayPhyPwrChg

Quoted 3 lines · Hayes Wang

Enable DelayPhyPwrChg let the device fail enter the power saving mode of P3.

Hayes,
I'm very curious about this commit message: why would one want this to fail?

Did you mean "don't allow the phy to enter P3 power saving mode"? If P3 power saving mode is broken, what is the symptom? How long is the delay when this is still enabled? (to help identify failures when this is still enabled)

BTW, I've reviewed all the patches and don't see any obvious issues with them - though I don't have the technical documents to verify any changes in behavior.

I did see two typos in the commit messages that could be corrected if you need to send out v3:
[PATCH net 5/9] r8152: Disable PLA MCU clock speed down
s/packet lost/packet loss/

[PATCH net 6/9] r8152: disable test IO for RTL8153B
s/casue/cause

cheers,
grant

Quoted 51 lines
---
 drivers/net/usb/r8152.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/usb/r8152.c +9 -2
index 0998b9587943..c999a58ddda9 100644
@@ -31,7 +31,7 @@
 #define NETNEXT_VERSION                "11"
 
 /* Information for net */
-#define NET_VERSION            "10"
+#define NET_VERSION            "11"
 
 #define DRIVER_VERSION         "v1." NETNEXT_VERSION "." NET_VERSION
 #define DRIVER_AUTHOR "Realtek linux nic maintainers <[email protected]>"
@@ -109,6 +109,7 @@
 #define PLA_BP_EN              0xfc38
 
 #define USB_USB2PHY            0xb41e
+#define USB_SSPHYLINK1         0xb426
 #define USB_SSPHYLINK2         0xb428
 #define USB_U2P3_CTRL          0xb460
 #define USB_CSR_DUMMY1         0xb464
@@ -384,6 +385,9 @@
 #define USB2PHY_SUSPEND                0x0001
 #define USB2PHY_L1             0x0002
 
+/* USB_SSPHYLINK1 */
+#define DELAY_PHY_PWR_CHG      BIT(1)
+
 /* USB_SSPHYLINK2 */
 #define pwd_dn_scale_mask      0x3ffe
 #define pwd_dn_scale(x)                ((x) << 1)
@@ -4993,6 +4997,10 @@ static void rtl8153_up(struct r8152 *tp)
        ocp_data &= ~LANWAKE_PIN;
        ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
 
+       ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1);
+       ocp_data &= ~DELAY_PHY_PWR_CHG;
+       ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1, ocp_data);
+
        r8153_aldps_en(tp, true);
 
        switch (tp->version) {
--

2.21.0

author
#18 lore raw

RE: [PATCH net 9/9] r8152: disable DelayPhyPwrChg

Grant Grundler [mailto:[email protected]]

Quoted 1 line

Sent: Wednesday, January 22, 2020 3:03 PM

[...]

Quoted 2 lines

Did you mean "don't allow the phy to enter P3 power saving mode"? If P3 power saving mode is broken, what is the symptom?

Yes.
It increases power consumption.

PS. the "phy" is for USB, not for Ethernet.

Quoted 2 lines

How long is the delay when this is still enabled? (to help identify failures when this is still enabled)

When this is enable, the device would wait an internal signal which wouldn't be triggered. Then, the device couldn't enter P3 mode, so the power consumption is increased.

Best Regards,
Hayes

#19 lore raw

Re: [PATCH net] Revert "r8152: adjust the settings about MAC clock speed down for RTL8153"

In reply to Hayes Wang
This patch was applied to netdev/net.git (refs/heads/master):

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

Quoted 9 lines · On Wed, 3 Mar 2021 16:39:47 +0800 you wrote:

This reverts commit 134f98bcf1b898fb9d6f2b91bc85dd2e5478b4b8.

The r8153_mac_clk_spd() is used for RTL8153A only, because the register table of RTL8153B is different from RTL8153A. However, this function would be called when RTL8153B calls r8153_first_init() and r8153_enter_oob(). That causes RTL8153B becomes unstable when suspending and resuming. The worst case may let the device stop working.

[...]

Here is the summary with links:
- [net] Revert "r8152: adjust the settings about MAC clock speed down for RTL8153"

    https://git.kernel.org/netdev/net/c/4b5dc1a94d4f

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

author
#20 lore raw

v2 cover r8152: serial fixes

In reply to Hayes Wang

v2:
For patch #2, move declaring the variable "ocp_data".

v1:
These patches are used to fix some issues for RTL8153.

Hayes Wang (9):
r8152: fix runtime resume for linking change
r8152: reset flow control patch when linking on for RTL8153B
r8152: get default setting of WOL before initializing
r8152: disable U2P3 for RTL8153B
r8152: Disable PLA MCU clock speed down
r8152: disable test IO for RTL8153B
r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B
r8152: avoid the MCU to clear the lanwake
r8152: disable DelayPhyPwrChg

 drivers/net/usb/r8152.c | 124 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 113 insertions(+), 11 deletions(-)
Signature · 1 line
2.21.0
author
#21 lore raw

PATCH v2 1/9 r8152: fix runtime resume for linking change

Fix the runtime resume doesn't work normally for linking change.

1. Reset the settings and status of runtime suspend.
2. Sync the linking status.
3. Poll the linking change.

---
 drivers/net/usb/r8152.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/net/usb/r8152.c +21 -0
index 031cb8fff909..115559707683 100644
@@ -365,8 +365,10 @@
 #define DEBUG_LTSSM		0x0082
 
 /* PLA_EXTRA_STATUS */
+#define CUR_LINK_OK		BIT(15)
 #define U3P3_CHECK_EN		BIT(7)	/* RTL_VER_05 only */
 #define LINK_CHANGE_FLAG	BIT(8)
+#define POLL_LINK_CHG		BIT(0)
 
 /* USB_USB2PHY */
 #define USB2PHY_SUSPEND		0x0001
@@ -5387,6 +5389,16 @@ static void r8153_init(struct r8152 *tp)
 		else
 			ocp_data |= DYNAMIC_BURST;
 		ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
+
+		r8153_queue_wake(tp, false);
+
+		ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
+		if (rtl8152_get_speed(tp) & LINK_STATUS)
+			ocp_data |= CUR_LINK_OK;
+		else
+			ocp_data &= ~CUR_LINK_OK;
+		ocp_data |= POLL_LINK_CHG;
+		ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
 	}
 
 	ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2);
@@ -5416,6 +5428,7 @@ static void r8153_init(struct r8152 *tp)
 	ocp_write_word(tp, MCU_TYPE_USB, USB_CONNECT_TIMER, 0x0001);
 
 	r8153_power_cut_en(tp, false);
+	rtl_runtime_suspend_enable(tp, false);
 	r8153_u1u2en(tp, true);
 	r8153_mac_clk_spd(tp, false);
 	usb_enable_lpm(tp->udev);
@@ -5484,6 +5497,14 @@ static void r8153b_init(struct r8152 *tp)
 	r8153b_ups_en(tp, false);
 	r8153_queue_wake(tp, false);
 	rtl_runtime_suspend_enable(tp, false);
+
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
+	if (rtl8152_get_speed(tp) & LINK_STATUS)
+		ocp_data |= CUR_LINK_OK;
+	else
+		ocp_data &= ~CUR_LINK_OK;
+	ocp_data |= POLL_LINK_CHG;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
 	r8153b_u1u2en(tp, true);
 	usb_enable_lpm(tp->udev);
 
Signature · 1 line
2.21.0
author
#22 lore raw

PATCH v2 2/9 r8152: reset flow control patch when linking on for RTL8153B

In reply to Hayes Wang

When linking ON, the patch of flow control has to be reset. This makes sure the patch works normally.

---
 drivers/net/usb/r8152.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/usb/r8152.c +11 -0
index 115559707683..504db2348a3e 100644
@@ -2865,6 +2865,17 @@ static int rtl8153_enable(struct r8152 *tp)
 	r8153_set_rx_early_timeout(tp);
 	r8153_set_rx_early_size(tp);
 
+	if (tp->version == RTL_VER_09) {
+		u32 ocp_data;
+
+		ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK);
+		ocp_data &= ~FC_PATCH_TASK;
+		ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data);
+		usleep_range(1000, 2000);
+		ocp_data |= FC_PATCH_TASK;
+		ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data);
+	}
+
 	return rtl_enable(tp);
 }
 
Signature · 1 line
2.21.0
#23 lore raw

Re: [PATCH net-next 0/6] r8152: support new chips

This series was applied to netdev/net-next.git (refs/heads/master):

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

Quoted 11 lines · On Fri, 16 Apr 2021 16:04:31 +0800 you wrote:

Support new RTL8153 and RTL8156 series.

Hayes Wang (6):
r8152: set inter fram gap time depending on speed
r8152: adjust rtl8152_check_firmware function
r8152: add help function to change mtu
r8152: support new chips
r8152: support PHY firmware for RTL8156 series
r8152: search the configuration of vendor mode

[...]

Here is the summary with links:
- [net-next,1/6] r8152: set inter fram gap time depending on speed

    https://git.kernel.org/netdev/net-next/c/5133bcc74815
  - [net-next,2/6] r8152: adjust rtl8152_check_firmware function
    https://git.kernel.org/netdev/net-next/c/a8a7be178e81
  - [net-next,3/6] r8152: add help function to change mtu
    https://git.kernel.org/netdev/net-next/c/67ce1a806f16
  - [net-next,4/6] r8152: support new chips
    https://git.kernel.org/netdev/net-next/c/195aae321c82
  - [net-next,5/6] r8152: support PHY firmware for RTL8156 series
    https://git.kernel.org/netdev/net-next/c/4a51b0e8a014
  - [net-next,6/6] r8152: search the configuration of vendor mode
    https://git.kernel.org/netdev/net-next/c/c2198943e33b

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

author
#24 lore raw

PATCH v2 3/9 r8152: get default setting of WOL before initializing

In reply to Hayes Wang

Initailization would reset runtime suspend by tp->saved_wolopts, so the tp->saved_wolopts should be set before initializing.

---
 drivers/net/usb/r8152.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/usb/r8152.c +5 -4
index 504db2348a3e..c3217a5c2fe1 100644
@@ -6739,6 +6739,11 @@ static int rtl8152_probe(struct usb_interface *intf,
 
 	intf->needs_remote_wakeup = 1;
 
+	if (!rtl_can_wakeup(tp))
+		__rtl_set_wol(tp, 0);
+	else
+		tp->saved_wolopts = __rtl_get_wol(tp);
+
 	tp->rtl_ops.init(tp);
 #if IS_BUILTIN(CONFIG_USB_RTL8152)
 	/* Retry in case request_firmware() is not ready yet. */
@@ -6756,10 +6761,6 @@ static int rtl8152_probe(struct usb_interface *intf,
 		goto out1;
 	}
 
-	if (!rtl_can_wakeup(tp))
-		__rtl_set_wol(tp, 0);
-
-	tp->saved_wolopts = __rtl_get_wol(tp);
 	if (tp->saved_wolopts)
 		device_set_wakeup_enable(&udev->dev, true);
 	else
Signature · 1 line
2.21.0
author
#25 lore raw

PATCH v2 4/9 r8152: disable U2P3 for RTL8153B

In reply to Hayes Wang

Enable U2P3 may miss zero packet for bulk-in.

---
 drivers/net/usb/r8152.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/usb/r8152.c +0 -3
index c3217a5c2fe1..bc6b2f8aaa7e 100644
@@ -3389,7 +3389,6 @@ static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable)
 		r8153b_ups_en(tp, false);
 		r8153_queue_wake(tp, false);
 		rtl_runtime_suspend_enable(tp, false);
-		r8153_u2p3en(tp, true);
 		r8153b_u1u2en(tp, true);
 	}
 }
@@ -4688,7 +4687,6 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp)
 
 	r8153_aldps_en(tp, true);
 	r8152b_enable_fc(tp);
-	r8153_u2p3en(tp, true);
 
 	set_bit(PHY_RESET, &tp->flags);
 }
@@ -5018,7 +5016,6 @@ static void rtl8153b_up(struct r8152 *tp)
 	ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B);
 
 	r8153_aldps_en(tp, true);
-	r8153_u2p3en(tp, true);
 	r8153b_u1u2en(tp, true);
 }
 
Signature · 1 line
2.21.0
author
#26 lore raw

PATCH v2 5/9 r8152: Disable PLA MCU clock speed down

In reply to Hayes Wang

PLA MCU clock speed down could only be enabled when tx/rx are disabled. Otherwise, the packet lost may occur.

---
 drivers/net/usb/r8152.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/usb/r8152.c +17 -0
index bc6b2f8aaa7e..1fb85c79bd33 100644
@@ -324,6 +324,7 @@
 #define MAC_CLK_SPDWN_EN	BIT(15)
 
 /* PLA_MAC_PWR_CTRL3 */
+#define PLA_MCU_SPDWN_EN	BIT(14)
 #define PKT_AVAIL_SPDWN_EN	0x0100
 #define SUSPEND_SPDWN_EN	0x0004
 #define U1U2_SPDWN_EN		0x0002
@@ -5005,6 +5006,8 @@ static void rtl8153_down(struct r8152 *tp)
 
 static void rtl8153b_up(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags))
 		return;
 
@@ -5015,17 +5018,27 @@ static void rtl8153b_up(struct r8152 *tp)
 	r8153_first_init(tp);
 	ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B);
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data &= ~PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
 	r8153_aldps_en(tp, true);
 	r8153b_u1u2en(tp, true);
 }
 
 static void rtl8153b_down(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags)) {
 		rtl_drop_queued_tx(tp);
 		return;
 	}
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data |= PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
 	r8153b_u1u2en(tp, false);
 	r8153_u2p3en(tp, false);
 	r8153b_power_cut_en(tp, false);
@@ -5521,6 +5534,10 @@ static void r8153b_init(struct r8152 *tp)
 	ocp_data |= MAC_CLK_SPDWN_EN;
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data);
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data &= ~PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
 	set_bit(GREEN_ETHERNET, &tp->flags);
 
 	/* rx aggregation */
Signature · 1 line
2.21.0
author
#27 lore raw

PATCH v2 6/9 r8152: disable test IO for RTL8153B

In reply to Hayes Wang

For RTL8153B with QFN32, disable test IO. Otherwise, it may casue abnormal behavior for the device randomly.

---
 drivers/net/usb/r8152.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/usb/r8152.c +10 -0
index 1fb85c79bd33..7efeddad1fc8 100644
@@ -312,6 +312,7 @@
 /* PLA_PHY_PWR */
 #define TX_10M_IDLE_EN		0x0080
 #define PFM_PWM_SWITCH		0x0040
+#define TEST_IO_OFF		BIT(4)
 
 /* PLA_MAC_PWR_CTRL */
 #define D3_CLK_GATED_EN		0x00004000
@@ -5538,6 +5539,15 @@ static void r8153b_init(struct r8152 *tp)
 	ocp_data &= ~PLA_MCU_SPDWN_EN;
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
 
+	if (tp->version == RTL_VER_09) {
+		/* Disable Test IO for 32QFN */
+		if (ocp_read_byte(tp, MCU_TYPE_PLA, 0xdc00) & BIT(5)) {
+			ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
+			ocp_data |= TEST_IO_OFF;
+			ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
+		}
+	}
+
 	set_bit(GREEN_ETHERNET, &tp->flags);
 
 	/* rx aggregation */
Signature · 1 line
2.21.0
maintainer
#28 lore raw

Re: [PATCH net-next 4/6] r8152: support new chips

Quoted 74 lines · On Fri, 16 Apr 2021 16:04:35 +0800 Hayes Wang wrote:

Support RTL8153C, RTL8153D, RTL8156A, and RTL8156B. The RTL8156A and RTL8156B are the 2.5G ethernet.

(quoted diff) +68 -0
+	switch (tp->version) {
+	case RTL_VER_10:
+		data = ocp_reg_read(tp, 0xad40);
+		data &= ~0x3ff;
+		data |= BIT(7) | BIT(2);
+		ocp_reg_write(tp, 0xad40, data);
+
+		data = ocp_reg_read(tp, 0xad4e);
+		data |= BIT(4);
+		ocp_reg_write(tp, 0xad4e, data);
+		data = ocp_reg_read(tp, 0xad16);
+		data &= ~0x3ff;
+		data |= 0x6;
+		ocp_reg_write(tp, 0xad16, data);
+		data = ocp_reg_read(tp, 0xad32);
+		data &= ~0x3f;
+		data |= 6;
+		ocp_reg_write(tp, 0xad32, data);
+		data = ocp_reg_read(tp, 0xac08);
+		data &= ~(BIT(12) | BIT(8));
+		ocp_reg_write(tp, 0xac08, data);
+		data = ocp_reg_read(tp, 0xac8a);
+		data |= BIT(12) | BIT(13) | BIT(14);
+		data &= ~BIT(15);
+		ocp_reg_write(tp, 0xac8a, data);
+		data = ocp_reg_read(tp, 0xad18);
+		data |= BIT(10);
+		ocp_reg_write(tp, 0xad18, data);
+		data = ocp_reg_read(tp, 0xad1a);
+		data |= 0x3ff;
+		ocp_reg_write(tp, 0xad1a, data);
+		data = ocp_reg_read(tp, 0xad1c);
+		data |= 0x3ff;
+		ocp_reg_write(tp, 0xad1c, data);
+
+		data = sram_read(tp, 0x80ea);
+		data &= ~0xff00;
+		data |= 0xc400;
+		sram_write(tp, 0x80ea, data);
+		data = sram_read(tp, 0x80eb);
+		data &= ~0x0700;
+		data |= 0x0300;
+		sram_write(tp, 0x80eb, data);
+		data = sram_read(tp, 0x80f8);
+		data &= ~0xff00;
+		data |= 0x1c00;
+		sram_write(tp, 0x80f8, data);
+		data = sram_read(tp, 0x80f1);
+		data &= ~0xff00;
+		data |= 0x3000;
+		sram_write(tp, 0x80f1, data);
 
+	switch (tp->version) {
+	case RTL_VER_12:
+		ocp_reg_write(tp, 0xbf86, 0x9000);
+		data = ocp_reg_read(tp, 0xc402);
+		data |= BIT(10);
+		ocp_reg_write(tp, 0xc402, data);
+		data &= ~BIT(10);
+		ocp_reg_write(tp, 0xc402, data);
+		ocp_reg_write(tp, 0xbd86, 0x1010);
+		ocp_reg_write(tp, 0xbd88, 0x1010);
+		data = ocp_reg_read(tp, 0xbd4e);
+		data &= ~(BIT(10) | BIT(11));
+		data |= BIT(11);
+		ocp_reg_write(tp, 0xbd4e, data);
+		data = ocp_reg_read(tp, 0xbf46);
+		data &= ~0xf00;
+		data |= 0x700;

Review

Quoted 10 lines
(quoted diff) +9 -0
+		ocp_reg_write(tp, 0xbf46, data);
 
+	data = r8153_phy_status(tp, 0);
+	switch (data) {
+	case PHY_STAT_EXT_INIT:
+		rtl8152_apply_firmware(tp, true);
+
+		data = ocp_reg_read(tp, 0xa466);
+		data &= ~BIT(0);
+		ocp_reg_write(tp, 0xa466, data);

What are all these magic constants? :(

Review static int rtl8152_probe(struct usb_interface *intf, · line 8947

Quoted 8 lines
(quoted diff) +3 -1
@@ -6878,7 +8942,11 @@ static int rtl8152_probe(struct usb_interface *intf,
 	set_ethernet_addr(tp);
 
 	usb_set_intfdata(intf, tp);
-	netif_napi_add(netdev, &tp->napi, r8152_poll, RTL8152_NAPI_WEIGHT);
+
+	if (tp->support_2500full)
+		netif_napi_add(netdev, &tp->napi, r8152_poll, 256);

why 256? We have 100G+ drivers all using 64 what's special here?

Quoted 2 lines
(quoted diff) +2 -0
+	else
+		netif_napi_add(netdev, &tp->napi, r8152_poll, 64);
author
#29 lore raw

RE: [PATCH net-next 4/6] r8152: support new chips

Jakub Kicinski <[email protected]>

Quoted 44 lines

Sent: Saturday, April 17, 2021 5:50 AM

Quoted 43 lines
(quoted diff) +43 -0
+	switch (tp->version) {
+	case RTL_VER_10:
+		data = ocp_reg_read(tp, 0xad40);
+		data &= ~0x3ff;
+		data |= BIT(7) | BIT(2);
+		ocp_reg_write(tp, 0xad40, data);
+
+		data = ocp_reg_read(tp, 0xad4e);
+		data |= BIT(4);
+		ocp_reg_write(tp, 0xad4e, data);
+		data = ocp_reg_read(tp, 0xad16);
+		data &= ~0x3ff;
+		data |= 0x6;
+		ocp_reg_write(tp, 0xad16, data);
+		data = ocp_reg_read(tp, 0xad32);
+		data &= ~0x3f;
+		data |= 6;
+		ocp_reg_write(tp, 0xad32, data);
+		data = ocp_reg_read(tp, 0xac08);
+		data &= ~(BIT(12) | BIT(8));
+		ocp_reg_write(tp, 0xac08, data);
+		data = ocp_reg_read(tp, 0xac8a);
+		data |= BIT(12) | BIT(13) | BIT(14);
+		data &= ~BIT(15);
+		ocp_reg_write(tp, 0xac8a, data);
+		data = ocp_reg_read(tp, 0xad18);
+		data |= BIT(10);
+		ocp_reg_write(tp, 0xad18, data);
+		data = ocp_reg_read(tp, 0xad1a);
+		data |= 0x3ff;
+		ocp_reg_write(tp, 0xad1a, data);
+		data = ocp_reg_read(tp, 0xad1c);
+		data |= 0x3ff;
+		ocp_reg_write(tp, 0xad1c, data);
+
+		data = sram_read(tp, 0x80ea);
+		data &= ~0xff00;
+		data |= 0xc400;
+		sram_write(tp, 0x80ea, data);
+		data = sram_read(tp, 0x80eb);
+		data &= ~0x0700;
+		data |= 0x0300;
+		sram_write(tp, 0x80eb, data);
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		data = sram_read(tp, 0x80f8);
+		data &= ~0xff00;
+		data |= 0x1c00;
+		sram_write(tp, 0x80f8, data);
+		data = sram_read(tp, 0x80f1);
+		data &= ~0xff00;
+		data |= 0x3000;
+		sram_write(tp, 0x80f1, data);

These are the parameters of PHY.
Some are used for speed down about power saving.
And some are used for performance.

Quoted 10 lines
Quoted 10 lines
(quoted diff) +10 -0
+	switch (tp->version) {
+	case RTL_VER_12:
+		ocp_reg_write(tp, 0xbf86, 0x9000);
+		data = ocp_reg_read(tp, 0xc402);
+		data |= BIT(10);
+		ocp_reg_write(tp, 0xc402, data);
+		data &= ~BIT(10);
+		ocp_reg_write(tp, 0xc402, data);
+		ocp_reg_write(tp, 0xbd86, 0x1010);
+		ocp_reg_write(tp, 0xbd88, 0x1010);
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+		data = ocp_reg_read(tp, 0xbd4e);
+		data &= ~(BIT(10) | BIT(11));
+		data |= BIT(11);
+		ocp_reg_write(tp, 0xbd4e, data);
+		data = ocp_reg_read(tp, 0xbf46);
+		data &= ~0xf00;
+		data |= 0x700;
+		ocp_reg_write(tp, 0xbf46, data);

These are used to adjust the clock of GPHY.
It influences the linking.

Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+	data = r8153_phy_status(tp, 0);
+	switch (data) {
+	case PHY_STAT_EXT_INIT:
+		rtl8152_apply_firmware(tp, true);
+
+		data = ocp_reg_read(tp, 0xa466);
+		data &= ~BIT(0);
+		ocp_reg_write(tp, 0xa466, data);

These let the PHY exit PHY_STAT_EXT_INIT state.

Quoted 1 line

What are all these magic constants? :(

I think it is difficult for me to make all magic values meaningful. The PHY setting is very complex. Only PHY engineers know what are the settings mean.

Quoted 12 lines

Review static int rtl8152_probe(struct usb_interface

Quoted 1 line
(quoted diff) +0 -0
@@ -6878,7 +8942,11 @@ static int rtl8152_probe(struct usb_interface

*intf,

Review static int rtl8152_probe(struct usb_interface · line 8947

Quoted 7 lines
(quoted diff) +3 -1
 	set_ethernet_addr(tp);
 
 	usb_set_intfdata(intf, tp);
-	netif_napi_add(netdev, &tp->napi, r8152_poll, RTL8152_NAPI_WEIGHT);
+
+	if (tp->support_2500full)
+		netif_napi_add(netdev, &tp->napi, r8152_poll, 256);

why 256? We have 100G+ drivers all using 64 what's special here?

Quoted 2 lines

Review static int rtl8152_probe(struct usb_interface · line 8949

Quoted 2 lines
(quoted diff) +2 -0
+	else
+		netif_napi_add(netdev, &tp->napi, r8152_poll, 64);

We test 2.5G Ethernet on some embedded platform. And we find 64 is not large enough, and the performance couldn't reach 2.5 G bits/s.

Best Regards,
Hayes

maintainer
#30 lore raw

Re: [PATCH net-next 4/6] r8152: support new chips

Quoted 11 lines · On Tue, 20 Apr 2021 07:00:39 +0000 Hayes Wang wrote:
Quoted 11 lines

Review static int rtl8152_probe(struct usb_interface *intf, · line 8947

Quoted 8 lines
(quoted diff) +3 -1
@@ -6878,7 +8942,11 @@ static int rtl8152_probe(struct usb_interface *intf,  
 	set_ethernet_addr(tp);
 
 	usb_set_intfdata(intf, tp);
-	netif_napi_add(netdev, &tp->napi, r8152_poll, RTL8152_NAPI_WEIGHT);
+
+	if (tp->support_2500full)
+		netif_napi_add(netdev, &tp->napi, r8152_poll, 256);  

why 256? We have 100G+ drivers all using 64 what's special here?

Quoted 6 lines
Quoted 2 lines

Review static int rtl8152_probe(struct usb_interface *intf, · line 8949

Quoted 2 lines
(quoted diff) +2 -0
+	else
+		netif_napi_add(netdev, &tp->napi, r8152_poll, 64);  

We test 2.5G Ethernet on some embedded platform. And we find 64 is not large enough, and the performance couldn't reach 2.5 G bits/s.

Did you manage to identify what the cause is?

NAPI will keep calling your driver if the budget was exhausted, the only difference between 64 and 256 should be the setup cost of the driver's internal loop. And perhaps more frequent GRO flush - what's the CONFIG_HZ set to?

author
#31 lore raw

RE: [PATCH net-next 4/6] r8152: support new chips

Jakub Kicinski <[email protected]>

Quoted 1 line

Sent: Wednesday, April 21, 2021 2:34 AM

[...]

Quoted 10 lines
Quoted 3 lines

We test 2.5G Ethernet on some embedded platform. And we find 64 is not large enough, and the performance couldn't reach 2.5 G bits/s.

Did you manage to identify what the cause is?

NAPI will keep calling your driver if the budget was exhausted, the only difference between 64 and 256 should be the setup cost of the driver's internal loop. And perhaps more frequent GRO flush - what's the CONFIG_HZ set to?

I am not sure. It is more than one year ago.
The CONFIG_HZ may be 250.

First, the CPU of that platform is slower than a x86 platform. Then, the rx data comes very fast, because of the 2.5G Ethernet. We find the budget is always exhausted, when the traffic is busy.

Best Regards,
Hayes

author
#32 lore raw

PATCH v2 7/9 r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B

In reply to Hayes Wang

For certain platforms, it causes USB reset periodically.

---
 drivers/net/usb/r8152.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/usb/r8152.c +8 -3
index 7efeddad1fc8..b1a00f29455b 100644
@@ -3391,7 +3391,8 @@ static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable)
 		r8153b_ups_en(tp, false);
 		r8153_queue_wake(tp, false);
 		rtl_runtime_suspend_enable(tp, false);
-		r8153b_u1u2en(tp, true);
+		if (tp->udev->speed != USB_SPEED_HIGH)
+			r8153b_u1u2en(tp, true);
 	}
 }
 
@@ -5024,7 +5025,9 @@ static void rtl8153b_up(struct r8152 *tp)
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
 
 	r8153_aldps_en(tp, true);
-	r8153b_u1u2en(tp, true);
+
+	if (tp->udev->speed != USB_SPEED_HIGH)
+		r8153b_u1u2en(tp, true);
 }
 
 static void rtl8153b_down(struct r8152 *tp)
@@ -5527,7 +5530,9 @@ static void r8153b_init(struct r8152 *tp)
 		ocp_data &= ~CUR_LINK_OK;
 	ocp_data |= POLL_LINK_CHG;
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
-	r8153b_u1u2en(tp, true);
+
+	if (tp->udev->speed != USB_SPEED_HIGH)
+		r8153b_u1u2en(tp, true);
 	usb_enable_lpm(tp->udev);
 
 	/* MAC clock speed down */
Signature · 1 line
2.21.0
author
#33 lore raw

PATCH v2 8/9 r8152: avoid the MCU to clear the lanwake

In reply to Hayes Wang

Avoid the MCU to clear the lanwake after suspending. It may cause the WOL fail. Disable LANWAKE_CLR_EN before suspending. Besides,enable it and reset the lanwake status when resuming or initializing.

---
 drivers/net/usb/r8152.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/net/usb/r8152.c +33 -0
index b1a00f29455b..c037fc7adcea 100644
@@ -68,6 +68,7 @@
 #define PLA_LED_FEATURE		0xdd92
 #define PLA_PHYAR		0xde00
 #define PLA_BOOT_CTRL		0xe004
+#define PLA_LWAKE_CTRL_REG	0xe007
 #define PLA_GPHY_INTR_IMR	0xe022
 #define PLA_EEE_CR		0xe040
 #define PLA_EEEP_CR		0xe080
@@ -95,6 +96,7 @@
 #define PLA_TALLYCNT		0xe890
 #define PLA_SFF_STS_7		0xe8de
 #define PLA_PHYSTATUS		0xe908
+#define PLA_CONFIG6		0xe90a /* CONFIG6 */
 #define PLA_BP_BA		0xfc26
 #define PLA_BP_0		0xfc28
 #define PLA_BP_1		0xfc2a
@@ -300,6 +302,9 @@
 #define LINK_ON_WAKE_EN		0x0010
 #define LINK_OFF_WAKE_EN	0x0008
 
+/* PLA_CONFIG6 */
+#define LANWAKE_CLR_EN		BIT(0)
+
 /* PLA_CONFIG5 */
 #define BWF_EN			0x0040
 #define MWF_EN			0x0020
@@ -356,6 +361,9 @@
 /* PLA_BOOT_CTRL */
 #define AUTOLOAD_DONE		0x0002
 
+/* PLA_LWAKE_CTRL_REG */
+#define LANWAKE_PIN		BIT(7)
+
 /* PLA_SUSPEND_FLAG */
 #define LINK_CHG_EVENT		BIT(0)
 
@@ -4968,6 +4976,8 @@ static void rtl8152_down(struct r8152 *tp)
 
 static void rtl8153_up(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags))
 		return;
 
@@ -4975,6 +4985,15 @@ static void rtl8153_up(struct r8152 *tp)
 	r8153_u2p3en(tp, false);
 	r8153_aldps_en(tp, false);
 	r8153_first_init(tp);
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
+	ocp_data |= LANWAKE_CLR_EN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG);
+	ocp_data &= ~LANWAKE_PIN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
+
 	r8153_aldps_en(tp, true);
 
 	switch (tp->version) {
@@ -4993,11 +5012,17 @@ static void rtl8153_up(struct r8152 *tp)
 
 static void rtl8153_down(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags)) {
 		rtl_drop_queued_tx(tp);
 		return;
 	}
 
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
+	ocp_data &= ~LANWAKE_CLR_EN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
+
 	r8153_u1u2en(tp, false);
 	r8153_u2p3en(tp, false);
 	r8153_power_cut_en(tp, false);
@@ -5458,6 +5483,14 @@ static void r8153_init(struct r8152 *tp)
 	r8153_mac_clk_spd(tp, false);
 	usb_enable_lpm(tp->udev);
 
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
+	ocp_data |= LANWAKE_CLR_EN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG);
+	ocp_data &= ~LANWAKE_PIN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
+
 	/* rx aggregation */
 	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
 	ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN);
Signature · 1 line
2.21.0
author
#34 lore raw

PATCH v2 9/9 r8152: disable DelayPhyPwrChg

In reply to Hayes Wang

Enable DelayPhyPwrChg let the device fail enter the power saving mode of P3.

---
 drivers/net/usb/r8152.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/usb/r8152.c +9 -1
index c037fc7adcea..3f425f974d03 100644
@@ -31,7 +31,7 @@
 #define NETNEXT_VERSION		"11"
 
 /* Information for net */
-#define NET_VERSION		"10"
+#define NET_VERSION		"11"
 
 #define DRIVER_VERSION		"v1." NETNEXT_VERSION "." NET_VERSION
 #define DRIVER_AUTHOR "Realtek linux nic maintainers <[email protected]>"
@@ -109,6 +109,7 @@
 #define PLA_BP_EN		0xfc38
 
 #define USB_USB2PHY		0xb41e
+#define USB_SSPHYLINK1		0xb426
 #define USB_SSPHYLINK2		0xb428
 #define USB_U2P3_CTRL		0xb460
 #define USB_CSR_DUMMY1		0xb464
@@ -384,6 +385,9 @@
 #define USB2PHY_SUSPEND		0x0001
 #define USB2PHY_L1		0x0002
 
+/* USB_SSPHYLINK1 */
+#define DELAY_PHY_PWR_CHG	BIT(1)
+
 /* USB_SSPHYLINK2 */
 #define pwd_dn_scale_mask	0x3ffe
 #define pwd_dn_scale(x)		((x) << 1)
@@ -4994,6 +4998,10 @@ static void rtl8153_up(struct r8152 *tp)
 	ocp_data &= ~LANWAKE_PIN;
 	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1);
+	ocp_data &= ~DELAY_PHY_PWR_CHG;
+	ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1, ocp_data);
+
 	r8153_aldps_en(tp, true);
 
 	switch (tp->version) {
Signature · 1 line
2.21.0
#35 lore raw

Re: [PATCH linux-firmware] rtl_nic: add new firmware for RTL8153 and RTL8156 series

Applied and pushed out.

josh

Quoted 183 lines · Hayes Wang

1. rtl8153c-1 v1 03/31/21.
2. rtl8156a-2 v1 04/15/21.
3. rtl8156b-2 v1 04/15/21.

---
 WHENCE                |   3 +++
 rtl_nic/rtl8153c-1.fw | Bin 0 -> 816 bytes
 rtl_nic/rtl8156a-2.fw | Bin 0 -> 3816 bytes
 rtl_nic/rtl8156b-2.fw | Bin 0 -> 5448 bytes
 4 files changed, 3 insertions(+)
 create mode 100644 rtl_nic/rtl8153c-1.fw
 create mode 100644 rtl_nic/rtl8156a-2.fw
 create mode 100644 rtl_nic/rtl8156b-2.fw
WHENCE +3 -0
index 9699246..e6497c5 100644
@@ -3260,6 +3260,9 @@ File: rtl_nic/rtl8153a-2.fw
 File: rtl_nic/rtl8153a-3.fw
 File: rtl_nic/rtl8153a-4.fw
 File: rtl_nic/rtl8153b-2.fw
+File: rtl_nic/rtl8153c-1.fw
+File: rtl_nic/rtl8156a-2.fw
+File: rtl_nic/rtl8156b-2.fw
 
 Licence: Redistributable. See LICENCE.rtlwifi_firmware.txt for details.
 
rtl_nic/rtl8153c-1.fw new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..5c3d1c468e5307c588ff347b57f7d0ca719f8341
GIT binary patch
rtl_nic/rtl8156a-2.fw new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..eec923b2cc01b8927f727c381508e00b61dbbe37
GIT binary patch
rtl_nic/rtl8156b-2.fw new file binary +0 -1
new file mode 100644
index 0000000000000000000000000000000000000000..7bf4dda806e30772949ddd10ed30703d89b2a833
GIT binary patch
 
--

2.26.3

Acked-by on the v2 series
#36 lore raw

Re: [PATCH net] r8169: fix r8168fp_adjust_ocp_cmd function

In reply to Hayes Wang
Quoted 14 lines · Hayes Wang

The (0xBAF70000 & 0x00FFF000) << 6 should be (0xf70 << 18).

Fixes 561535b0f239 ("r8169: fix OCP access on RTL8117")
---
 drivers/net/ethernet/realtek/r8169_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -0
index f704da3f214c..7aad0ba53372 100644

drivers/net/ethernet/realtek/r8169_main.c static void r8168fp_adjust_ocp_cmd(struct rtl8169_private *tp, u32 *cmd, int typ · line 773

Quoted 8 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -1
@@ -767,7 +767,7 @@ static void r8168fp_adjust_ocp_cmd(struct rtl8169_private *tp, u32 *cmd, int typ
 	if (type == ERIAR_OOB &&
 	    (tp->mac_version == RTL_GIGA_MAC_VER_52 ||
 	     tp->mac_version == RTL_GIGA_MAC_VER_53))
-		*cmd |= 0x7f0 << 18;
+		*cmd |= 0xf70 << 18;
 }
 
 DECLARE_RTL_COND(rtl_eriar_cond)
#37 lore raw

Re: [PATCH net] r8169: fix r8168fp_adjust_ocp_cmd function

In reply to Hayes Wang
This patch was applied to netdev/net.git (refs/heads/master):

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

Quoted 7 lines · On Fri, 5 Mar 2021 17:34:41 +0800 you wrote:

The (0xBAF70000 & 0x00FFF000) << 6 should be (0xf70 << 18).

Fixes 561535b0f239 ("r8169: fix OCP access on RTL8117")
---
 drivers/net/ethernet/realtek/r8169_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Here is the summary with links:
- [net] r8169: fix r8168fp_adjust_ocp_cmd function

    https://git.kernel.org/netdev/net/c/abbf9a0ef884

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

author
#38 lore raw

v3 cover r8152: serial fixes

In reply to Hayes Wang

v3:
1. Fix the typos for patch #5 and #6.
2. Modify the commit message of patch #9.

v2:
For patch #2, move declaring the variable "ocp_data".

v1:
These patches are used to fix some issues for RTL8153.

Hayes Wang (9):
r8152: fix runtime resume for linking change
r8152: reset flow control patch when linking on for RTL8153B
r8152: get default setting of WOL before initializing
r8152: disable U2P3 for RTL8153B
r8152: Disable PLA MCU clock speed down
r8152: disable test IO for RTL8153B
r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B
r8152: avoid the MCU to clear the lanwake
r8152: disable DelayPhyPwrChg

 drivers/net/usb/r8152.c | 124 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 113 insertions(+), 11 deletions(-)
Signature · 1 line
2.21.0
author
#39 lore raw

PATCH v3 1/9 r8152: fix runtime resume for linking change

Fix the runtime resume doesn't work normally for linking change.

1. Reset the settings and status of runtime suspend.
2. Sync the linking status.
3. Poll the linking change.

---
 drivers/net/usb/r8152.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/net/usb/r8152.c +21 -0
index 031cb8fff909..115559707683 100644
@@ -365,8 +365,10 @@
 #define DEBUG_LTSSM		0x0082
 
 /* PLA_EXTRA_STATUS */
+#define CUR_LINK_OK		BIT(15)
 #define U3P3_CHECK_EN		BIT(7)	/* RTL_VER_05 only */
 #define LINK_CHANGE_FLAG	BIT(8)
+#define POLL_LINK_CHG		BIT(0)
 
 /* USB_USB2PHY */
 #define USB2PHY_SUSPEND		0x0001
@@ -5387,6 +5389,16 @@ static void r8153_init(struct r8152 *tp)
 		else
 			ocp_data |= DYNAMIC_BURST;
 		ocp_write_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY1, ocp_data);
+
+		r8153_queue_wake(tp, false);
+
+		ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
+		if (rtl8152_get_speed(tp) & LINK_STATUS)
+			ocp_data |= CUR_LINK_OK;
+		else
+			ocp_data &= ~CUR_LINK_OK;
+		ocp_data |= POLL_LINK_CHG;
+		ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
 	}
 
 	ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_CSR_DUMMY2);
@@ -5416,6 +5428,7 @@ static void r8153_init(struct r8152 *tp)
 	ocp_write_word(tp, MCU_TYPE_USB, USB_CONNECT_TIMER, 0x0001);
 
 	r8153_power_cut_en(tp, false);
+	rtl_runtime_suspend_enable(tp, false);
 	r8153_u1u2en(tp, true);
 	r8153_mac_clk_spd(tp, false);
 	usb_enable_lpm(tp->udev);
@@ -5484,6 +5497,14 @@ static void r8153b_init(struct r8152 *tp)
 	r8153b_ups_en(tp, false);
 	r8153_queue_wake(tp, false);
 	rtl_runtime_suspend_enable(tp, false);
+
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS);
+	if (rtl8152_get_speed(tp) & LINK_STATUS)
+		ocp_data |= CUR_LINK_OK;
+	else
+		ocp_data &= ~CUR_LINK_OK;
+	ocp_data |= POLL_LINK_CHG;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
 	r8153b_u1u2en(tp, true);
 	usb_enable_lpm(tp->udev);
 
Signature · 1 line
2.21.0
#40 lore raw

Re: [PATCH net-next 0/2] r8152: adjust REALTEK_USB_DEVICE

This series was applied to netdev/net-next.git (refs/heads/master):

Hello:

This series was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Fri, 23 Apr 2021 17:44:53 +0800 you wrote:

Modify REALTEK_USB_DEVICE macro.

Hayes Wang (2):
r8152: remove NCM mode from REALTEK_USB_DEVICE macro
r8152: redefine REALTEK_USB_DEVICE macro

 drivers/net/usb/r8152.c | 71 ++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 44 deletions(-)

Here is the summary with links:
- [net-next,1/2] r8152: remove NCM mode from REALTEK_USB_DEVICE macro

    https://git.kernel.org/netdev/net-next/c/e7865ea51b0b
  - [net-next,2/2] r8152: redefine REALTEK_USB_DEVICE macro
    https://git.kernel.org/netdev/net-next/c/55319eeb5bbc

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

author
#41 lore raw

PATCH v3 2/9 r8152: reset flow control patch when linking on for RTL8153B

In reply to Hayes Wang

When linking ON, the patch of flow control has to be reset. This makes sure the patch works normally.

---
 drivers/net/usb/r8152.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/usb/r8152.c +11 -0
index 115559707683..504db2348a3e 100644
@@ -2865,6 +2865,17 @@ static int rtl8153_enable(struct r8152 *tp)
 	r8153_set_rx_early_timeout(tp);
 	r8153_set_rx_early_size(tp);
 
+	if (tp->version == RTL_VER_09) {
+		u32 ocp_data;
+
+		ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_TASK);
+		ocp_data &= ~FC_PATCH_TASK;
+		ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data);
+		usleep_range(1000, 2000);
+		ocp_data |= FC_PATCH_TASK;
+		ocp_write_word(tp, MCU_TYPE_USB, USB_FW_TASK, ocp_data);
+	}
+
 	return rtl_enable(tp);
 }
 
Signature · 1 line
2.21.0
author
#42 lore raw

PATCH v3 3/9 r8152: get default setting of WOL before initializing

In reply to Hayes Wang

Initailization would reset runtime suspend by tp->saved_wolopts, so the tp->saved_wolopts should be set before initializing.

---
 drivers/net/usb/r8152.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/net/usb/r8152.c +5 -4
index 504db2348a3e..c3217a5c2fe1 100644
@@ -6739,6 +6739,11 @@ static int rtl8152_probe(struct usb_interface *intf,
 
 	intf->needs_remote_wakeup = 1;
 
+	if (!rtl_can_wakeup(tp))
+		__rtl_set_wol(tp, 0);
+	else
+		tp->saved_wolopts = __rtl_get_wol(tp);
+
 	tp->rtl_ops.init(tp);
 #if IS_BUILTIN(CONFIG_USB_RTL8152)
 	/* Retry in case request_firmware() is not ready yet. */
@@ -6756,10 +6761,6 @@ static int rtl8152_probe(struct usb_interface *intf,
 		goto out1;
 	}
 
-	if (!rtl_can_wakeup(tp))
-		__rtl_set_wol(tp, 0);
-
-	tp->saved_wolopts = __rtl_get_wol(tp);
 	if (tp->saved_wolopts)
 		device_set_wakeup_enable(&udev->dev, true);
 	else
Signature · 1 line
2.21.0
author
#43 lore raw

PATCH v3 4/9 r8152: disable U2P3 for RTL8153B

In reply to Hayes Wang

Enable U2P3 may miss zero packet for bulk-in.

---
 drivers/net/usb/r8152.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/usb/r8152.c +0 -3
index c3217a5c2fe1..bc6b2f8aaa7e 100644
@@ -3389,7 +3389,6 @@ static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable)
 		r8153b_ups_en(tp, false);
 		r8153_queue_wake(tp, false);
 		rtl_runtime_suspend_enable(tp, false);
-		r8153_u2p3en(tp, true);
 		r8153b_u1u2en(tp, true);
 	}
 }
@@ -4688,7 +4687,6 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp)
 
 	r8153_aldps_en(tp, true);
 	r8152b_enable_fc(tp);
-	r8153_u2p3en(tp, true);
 
 	set_bit(PHY_RESET, &tp->flags);
 }
@@ -5018,7 +5016,6 @@ static void rtl8153b_up(struct r8152 *tp)
 	ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B);
 
 	r8153_aldps_en(tp, true);
-	r8153_u2p3en(tp, true);
 	r8153b_u1u2en(tp, true);
 }
 
Signature · 1 line
2.21.0
#44 lore raw

Re: [PATCH net-next] r8152: remove some bit operations

This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Sat, 24 Apr 2021 14:09:03 +0800 you wrote:

Remove DELL_TB_RX_AGG_BUG and LENOVO_MACPASSTHRU flags of rtl8152_flags. They are only set when initializing and wouldn't be change. It is enough to record them with variables.

---
 drivers/net/usb/r8152.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Here is the summary with links:
- [net-next] r8152: remove some bit operations

    https://git.kernel.org/netdev/net-next/c/9c68011bd7e4

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

author
#45 lore raw

PATCH v3 5/9 r8152: Disable PLA MCU clock speed down

In reply to Hayes Wang

PLA MCU clock speed down could only be enabled when tx/rx are disabled. Otherwise, the packet loss may occur.

---
 drivers/net/usb/r8152.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/net/usb/r8152.c +17 -0
index bc6b2f8aaa7e..1fb85c79bd33 100644
@@ -324,6 +324,7 @@
 #define MAC_CLK_SPDWN_EN	BIT(15)
 
 /* PLA_MAC_PWR_CTRL3 */
+#define PLA_MCU_SPDWN_EN	BIT(14)
 #define PKT_AVAIL_SPDWN_EN	0x0100
 #define SUSPEND_SPDWN_EN	0x0004
 #define U1U2_SPDWN_EN		0x0002
@@ -5005,6 +5006,8 @@ static void rtl8153_down(struct r8152 *tp)
 
 static void rtl8153b_up(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags))
 		return;
 
@@ -5015,17 +5018,27 @@ static void rtl8153b_up(struct r8152 *tp)
 	r8153_first_init(tp);
 	ocp_write_dword(tp, MCU_TYPE_USB, USB_RX_BUF_TH, RX_THR_B);
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data &= ~PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
 	r8153_aldps_en(tp, true);
 	r8153b_u1u2en(tp, true);
 }
 
 static void rtl8153b_down(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags)) {
 		rtl_drop_queued_tx(tp);
 		return;
 	}
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data |= PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
 	r8153b_u1u2en(tp, false);
 	r8153_u2p3en(tp, false);
 	r8153b_power_cut_en(tp, false);
@@ -5521,6 +5534,10 @@ static void r8153b_init(struct r8152 *tp)
 	ocp_data |= MAC_CLK_SPDWN_EN;
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL2, ocp_data);
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3);
+	ocp_data &= ~PLA_MCU_SPDWN_EN;
+	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
+
 	set_bit(GREEN_ETHERNET, &tp->flags);
 
 	/* rx aggregation */
Signature · 1 line
2.21.0
maintainer
#46 lore raw

Re: [PATCH net] r8152: check the informaton of the device

Quoted 71 lines · Hayes Wang

Verify some fields of the USB descriptor to make sure the driver could be used by the device.

Reported-by [email protected]
Fixes c2198943e33b ("r8152: search the configuration of vendor mode")
---
 drivers/net/usb/r8152.c | 71 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 69 insertions(+), 2 deletions(-)
drivers/net/usb/r8152.c +52 -0
index 136ea06540ff..f348350f5da1 100644
@@ -8107,6 +8107,69 @@ static void r8156b_init(struct r8152 *tp)
 	tp->coalesce = 15000;	/* 15 us */
 }
 
+static bool rtl_check_vendor_ok(struct usb_interface *intf)
+{
+	struct usb_host_interface *alt = intf->cur_altsetting;
+	struct usb_host_endpoint *in = NULL, *out = NULL, *intr = NULL;
+	unsigned int ep;
+
+	if (alt->desc.bNumEndpoints < 3) {
+		dev_err(&intf->dev, "Unexpected bNumEndpoints %d\n", alt->desc.bNumEndpoints);
+		return false;
+	}
+
+	for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
+		struct usb_host_endpoint *e;
+
+		e = alt->endpoint + ep;
+
+		/* ignore endpoints which cannot transfer data */
+		if (!usb_endpoint_maxp(&e->desc))
+			continue;
+
+		switch (e->desc.bmAttributes) {
+		case USB_ENDPOINT_XFER_INT:
+			if (!usb_endpoint_dir_in(&e->desc))
+				continue;
+			if (!intr)
+				intr = e;
+			break;
+		case USB_ENDPOINT_XFER_BULK:
+			if (usb_endpoint_dir_in(&e->desc)) {
+				if (!in)
+					in = e;
+			} else if (!out) {
+				out = e;
+			}
+			break;
+		default:
+			continue;
+		}
+	}
+
+	if (!in || !out || !intr) {
+		dev_err(&intf->dev, "Miss Endpoints\n");
+		return false;
+	}
+
+	if ((in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != 1) {
+		dev_err(&intf->dev, "Invalid Rx Endpoints\n");
+		return false;
+	}
+
+	if ((out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != 2) {
+		dev_err(&intf->dev, "Invalid Tx Endpoints\n");

drivers/net/usb/r8152.c static void r8156b_init(struct r8152 *tp) · line 8171

Quoted 10 lines
drivers/net/usb/r8152.c +10 -0
+		return false;
+	}
+
+	if ((intr->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != 3) {
+		dev_err(&intf->dev, "Invalid interrupt Endpoints\n");
+		return false;
+	}
+
+	return true;
+}

We have a USB core function that does all of the above for you, why not use that instead?

Look at usb_find_common_endpoints() and usb_find_common_endpoints_reverse() and at the very least usb_find_bulk_in_endpoint() and related functions. Please don't open-code this type of logic, it's easy to get things wrong.

thanks,

greg k-h

author
#47 lore raw

RE: [PATCH net] r8152: check the informaton of the device

Greg KH <[email protected]>

Quoted 1 line

Sent: Friday, May 21, 2021 5:43 PM

[...]

Quoted 7 lines

We have a USB core function that does all of the above for you, why not use that instead?

Look at usb_find_common_endpoints() and usb_find_common_endpoints_reverse() and at the very least usb_find_bulk_in_endpoint() and related functions. Please don't open-code this type of logic, it's easy to get things wrong.

Fine. Thanks.

Best Regards,
Hayes

author
#48 lore raw

PATCH v3 6/9 r8152: disable test IO for RTL8153B

In reply to Hayes Wang

For RTL8153B with QFN32, disable test IO. Otherwise, it may cause abnormal behavior for the device randomly.

---
 drivers/net/usb/r8152.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/usb/r8152.c +10 -0
index 1fb85c79bd33..7efeddad1fc8 100644
@@ -312,6 +312,7 @@
 /* PLA_PHY_PWR */
 #define TX_10M_IDLE_EN		0x0080
 #define PFM_PWM_SWITCH		0x0040
+#define TEST_IO_OFF		BIT(4)
 
 /* PLA_MAC_PWR_CTRL */
 #define D3_CLK_GATED_EN		0x00004000
@@ -5538,6 +5539,15 @@ static void r8153b_init(struct r8152 *tp)
 	ocp_data &= ~PLA_MCU_SPDWN_EN;
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
 
+	if (tp->version == RTL_VER_09) {
+		/* Disable Test IO for 32QFN */
+		if (ocp_read_byte(tp, MCU_TYPE_PLA, 0xdc00) & BIT(5)) {
+			ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR);
+			ocp_data |= TEST_IO_OFF;
+			ocp_write_word(tp, MCU_TYPE_PLA, PLA_PHY_PWR, ocp_data);
+		}
+	}
+
 	set_bit(GREEN_ETHERNET, &tp->flags);
 
 	/* rx aggregation */
Signature · 1 line
2.21.0
maintainer Reviewed-by on v3 6/9
#49 lore raw

Re: [PATCH net v2] r8152: check the informaton of the device

Quoted 6 lines · Hayes Wang

Verify some fields of the USB descriptor to make sure the driver could be used by the device.

Besides, remove the check of endpoint number in rtl8152_probe(). It has been done in rtl_check_vendor_ok().

Quoted 8 lines
Reported-by [email protected]
Fixes c2198943e33b ("r8152: search the configuration of vendor mode")

---
v2:
Use usb_find_common_endpoints() and usb_endpoint_num() to replace original code.

Much better, just some tiny grammer changes below:

Quoted 17 lines

remove the check of endpoint number in rtl8152_probe(). It has been done in rtl_check_vendor_ok().

 drivers/net/usb/r8152.c | 44 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)
drivers/net/usb/r8152.c +2 -0
index 136ea06540ff..6e5230d6c721 100644
@@ -8107,6 +8107,39 @@ static void r8156b_init(struct r8152 *tp)
 	tp->coalesce = 15000;	/* 15 us */
 }
 
+static bool rtl_check_vendor_ok(struct usb_interface *intf)
+{

drivers/net/usb/r8152.c static void r8156b_init(struct r8152 *tp) · line 8121

Quoted 10 lines
drivers/net/usb/r8152.c +10 -0
+	struct usb_host_interface *alt = intf->cur_altsetting;
+	struct usb_endpoint_descriptor *in, *out, *intr;
+
+	if (alt->desc.bNumEndpoints < 3) {
+		dev_err(&intf->dev, "Unexpected bNumEndpoints %d\n", alt->desc.bNumEndpoints);
+		return false;
+	}
+
+	if (usb_find_common_endpoints(alt, &in, &out, &intr, NULL) < 0) {
+		dev_err(&intf->dev, "Miss Endpoints\n");

"Miss" feels ackward, how about "Invalid number of endpoints"?

drivers/net/usb/r8152.c static void r8156b_init(struct r8152 *tp) · line 8126

Quoted 5 lines
drivers/net/usb/r8152.c +5 -0
+		return false;
+	}
+
+	if (usb_endpoint_num(in) != 1) {
+		dev_err(&intf->dev, "Invalid Rx Endpoint\n");

"Invalid number of Rx endpoints"

drivers/net/usb/r8152.c static void r8156b_init(struct r8152 *tp) · line 8131

Quoted 5 lines
drivers/net/usb/r8152.c +5 -0
+		return false;
+	}
+
+	if (usb_endpoint_num(out) != 2) {
+		dev_err(&intf->dev, "Invalid Tx Endpoint\n");

"Invalid number of RX endpoints"

drivers/net/usb/r8152.c static void r8156b_init(struct r8152 *tp) · line 8136

Quoted 5 lines
drivers/net/usb/r8152.c +5 -0
+		return false;
+	}
+
+	if (usb_endpoint_num(intr) != 3) {
+		dev_err(&intf->dev, "Invalid interrupt Endpoint\n");

"Invalid number of interrupt endpoints"

But really, this doesn't matter, all is good if you don't want to change this :)

#50 lore raw

Re: [PATCH net v2] r8152: check the informaton of the device

Quoted 33 lines · Greg Kroah-Hartman
Quoted 6 lines · Hayes Wang

Verify some fields of the USB descriptor to make sure the driver could be used by the device.

Besides, remove the check of endpoint number in rtl8152_probe(). It has been done in rtl_check_vendor_ok().

Quoted 8 lines
Reported-by [email protected]
Fixes c2198943e33b ("r8152: search the configuration of vendor mode")

---
v2:
Use usb_find_common_endpoints() and usb_endpoint_num() to replace original code.

Much better, just some tiny grammer changes below:

Quoted 15 lines

remove the check of endpoint number in rtl8152_probe(). It has been done in rtl_check_vendor_ok().

 drivers/net/usb/r8152.c | 44 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 5 deletions(-)
drivers/net/usb/r8152.c +0 -0
index 136ea06540ff..6e5230d6c721 100644
@@ -8107,6 +8107,39 @@ static void r8156b_init(struct r8152 *tp)
 	tp->coalesce = 15000;	/* 15 us */
 }
 
Quoted 9 lines

drivers/net/usb/r8152.c static void r8156b_init(struct r8152 *tp) · line 8118

Quoted 9 lines
drivers/net/usb/r8152.c +9 -0
+static bool rtl_check_vendor_ok(struct usb_interface *intf)
+{
+	struct usb_host_interface *alt = intf->cur_altsetting;
+	struct usb_endpoint_descriptor *in, *out, *intr;
+
+	if (alt->desc.bNumEndpoints < 3) {
+		dev_err(&intf->dev, "Unexpected bNumEndpoints %d\n", alt->desc.bNumEndpoints);
+		return false;
+	}

This check is now redundant and can be removed.

Quoted 5 lines

drivers/net/usb/r8152.c static void r8156b_init(struct r8152 *tp) · line 8121

Quoted 3 lines
drivers/net/usb/r8152.c +3 -0
+
+	if (usb_find_common_endpoints(alt, &in, &out, &intr, NULL) < 0) {
+		dev_err(&intf->dev, "Miss Endpoints\n");

"Miss" feels ackward, how about "Invalid number of endpoints"?

The helper also checks the type and direction so perhaps something like "expected endpoints not found" (or just "missing endpoints") which is more precise.

Quoted 7 lines

drivers/net/usb/r8152.c static void r8156b_init(struct r8152 *tp) · line 8126

Quoted 5 lines
drivers/net/usb/r8152.c +5 -0
+		return false;
+	}
+
+	if (usb_endpoint_num(in) != 1) {
+		dev_err(&intf->dev, "Invalid Rx Endpoint\n");

"Invalid number of Rx endpoints"

Here it is the endpoint number (address) that is being checked so "number of" would be wrong.

That said, perhaps none of these checks are even needed a bit depending on how the driver is implemented. That is, if it hardcodes the endpoint addresses or uses the result from usb_find_common_endpoints() above (which I realise now that it does not so these checks are probably still needed).

Quoted 2 lines

drivers/net/usb/r8152.c static void r8156b_init(struct r8152 *tp) · line 8128

Quoted 2 lines
drivers/net/usb/r8152.c +2 -0
+		return false;
+	}

Johan

author
#51 lore raw

RE: [PATCH net v2] r8152: check the informaton of the device

Johan Hovold <[email protected]>

Quoted 1 line

Sent: Saturday, May 22, 2021 4:07 PM

[...]

Quoted 5 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (usb_endpoint_num(in) != 1) {
+		dev_err(&intf->dev, "Invalid Rx Endpoint\n");

"Invalid number of Rx endpoints"

Quoted 8 lines

Here it is the endpoint number (address) that is being checked so "number of" would be wrong.

That said, perhaps none of these checks are even needed a bit depending on how the driver is implemented. That is, if it hardcodes the endpoint addresses or uses the result from usb_find_common_endpoints() above (which I realise now that it does not so these checks are probably still needed).

The purpose of the checks is to find out the fake devices. That is, even the device supports in, out, and interrupt endpoints, it is treated as fake or malicious device, if the addresses of these endpoints are wrong. Therefore, I would keep the checks.

Best Regards,
Hayes

#52 lore raw

Re: [PATCH net v2] r8152: check the informaton of the device

Quoted 17 lines · Hayes Wang

Johan Hovold <[email protected]>

Quoted 1 line

Sent: Saturday, May 22, 2021 4:07 PM

[...]

Quoted 5 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (usb_endpoint_num(in) != 1) {
+		dev_err(&intf->dev, "Invalid Rx Endpoint\n");

"Invalid number of Rx endpoints"

Quoted 8 lines

Here it is the endpoint number (address) that is being checked so "number of" would be wrong.

That said, perhaps none of these checks are even needed a bit depending on how the driver is implemented. That is, if it hardcodes the endpoint addresses or uses the result from usb_find_common_endpoints() above (which I realise now that it does not so these checks are probably still needed).

Quoted 4 lines

The purpose of the checks is to find out the fake devices. That is, even the device supports in, out, and interrupt endpoints, it is treated as fake or malicious device, if the addresses of these endpoints are wrong. Therefore, I would keep the checks.

Strictly, you need to check for bad input which could cause your driver to crash or malfunction. Generally you don't need to verify endpoint addresses unless the driver is hardcoding those. But since that is precisely what this particular driver is doing, these checks indeed need to stay.

Johan

author
#53 lore raw

PATCH v3 7/9 r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B

In reply to Hayes Wang

For certain platforms, it causes USB reset periodically.

---
 drivers/net/usb/r8152.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/usb/r8152.c +8 -3
index 7efeddad1fc8..b1a00f29455b 100644
@@ -3391,7 +3391,8 @@ static void rtl8153b_runtime_enable(struct r8152 *tp, bool enable)
 		r8153b_ups_en(tp, false);
 		r8153_queue_wake(tp, false);
 		rtl_runtime_suspend_enable(tp, false);
-		r8153b_u1u2en(tp, true);
+		if (tp->udev->speed != USB_SPEED_HIGH)
+			r8153b_u1u2en(tp, true);
 	}
 }
 
@@ -5024,7 +5025,9 @@ static void rtl8153b_up(struct r8152 *tp)
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL3, ocp_data);
 
 	r8153_aldps_en(tp, true);
-	r8153b_u1u2en(tp, true);
+
+	if (tp->udev->speed != USB_SPEED_HIGH)
+		r8153b_u1u2en(tp, true);
 }
 
 static void rtl8153b_down(struct r8152 *tp)
@@ -5527,7 +5530,9 @@ static void r8153b_init(struct r8152 *tp)
 		ocp_data &= ~CUR_LINK_OK;
 	ocp_data |= POLL_LINK_CHG;
 	ocp_write_word(tp, MCU_TYPE_PLA, PLA_EXTRA_STATUS, ocp_data);
-	r8153b_u1u2en(tp, true);
+
+	if (tp->udev->speed != USB_SPEED_HIGH)
+		r8153b_u1u2en(tp, true);
 	usb_enable_lpm(tp->udev);
 
 	/* MAC clock speed down */
Signature · 1 line
2.21.0
Reviewed-by on v3 7/9
#54 lore raw

Re: [PATCH net v3] r8152: check the informaton of the device

Quoted 72 lines · Hayes Wang

Verify some fields of the USB descriptor to make sure the driver could be used by the device.

Besides, remove the check of endpoint number in rtl8152_probe(). usb_find_common_endpoints() includes it.

Reported-by [email protected]
Fixes c2198943e33b ("r8152: search the configuration of vendor mode")

---
v3:
Remove the check of endpoint number in rtl_check_vendor_ok().

Adjust the error message and ccommit message.

v2:
Use usb_find_common_endpoints() and usb_endpoint_num() to replace original code.

remove the check of endpoint number in rtl8152_probe(). It has been done in rtl_check_vendor_ok().

 drivers/net/usb/r8152.c | 42 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 5 deletions(-)
drivers/net/usb/r8152.c +31 -0
index 136ea06540ff..f6abb2fbf972 100644
@@ -8107,6 +8107,37 @@ static void r8156b_init(struct r8152 *tp)
 	tp->coalesce = 15000;	/* 15 us */
 }
 
+static bool rtl_check_vendor_ok(struct usb_interface *intf)
+{
+	struct usb_host_interface *alt = intf->cur_altsetting;
+	struct usb_endpoint_descriptor *in, *out, *intr;
+
+	if (usb_find_common_endpoints(alt, &in, &out, &intr, NULL) < 0) {
+		dev_err(&intf->dev, "Expected endpoints are not found\n");
+		return false;
+	}
+
+	/* Check Rx endpoint address */
+	if (usb_endpoint_num(in) != 1) {
+		dev_err(&intf->dev, "Invalid Rx endpoint address\n");
+		return false;
+	}
+
+	/* Check Tx endpoint address */
+	if (usb_endpoint_num(out) != 2) {
+		dev_err(&intf->dev, "Invalid Tx endpoint address\n");
+		return false;
+	}
+
+	/* Check interrupt endpoint address */
+	if (usb_endpoint_num(intr) != 3) {
+		dev_err(&intf->dev, "Invalid interrupt endpoint address\n");
+		return false;
+	}
+
+	return true;
+}
+
 static bool rtl_vendor_mode(struct usb_interface *intf)
 {
 	struct usb_host_interface *alt = intf->cur_altsetting;
@@ -8115,12 +8146,15 @@ static bool rtl_vendor_mode(struct usb_interface *intf)
 	int i, num_configs;
 
 	if (alt->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC)

drivers/net/usb/r8152.c static bool rtl_vendor_mode(struct usb_interface *intf) · line 8157

Quoted 10 lines
drivers/net/usb/r8152.c +4 -1
-		return true;
+		return rtl_check_vendor_ok(intf);
 
 	/* The vendor mode is not always config #1, so to find it out. */
 	udev = interface_to_usbdev(intf);
 	c = udev->config;
 	num_configs = udev->descriptor.bNumConfigurations;
+	if (num_configs < 2)
+		return false;
+

Nit: This check looks unnecessary also as the driver can handle a single configuration just fine, and by removing it you'd be logging "Unexpected Device\n" below also in the single config case.

Quoted 14 lines
drivers/net/usb/r8152.c +2 -1
 	for (i = 0; i < num_configs; (i++, c++)) {
 		struct usb_interface_descriptor	*desc = NULL;
 
@@ -8135,7 +8169,8 @@ static bool rtl_vendor_mode(struct usb_interface *intf)
 		}
 	}
 
-	WARN_ON_ONCE(i == num_configs);
+	if (i == num_configs)
+		dev_err(&intf->dev, "Unexpected Device\n");
 
 	return false;
 }

drivers/net/usb/r8152.c static int rtl8152_probe(struct usb_interface *intf, · line 9421

Quoted 9 lines
drivers/net/usb/r8152.c +0 -3
@@ -9381,9 +9416,6 @@ static int rtl8152_probe(struct usb_interface *intf,
 	if (!rtl_vendor_mode(intf))
 		return -ENODEV;
 
-	if (intf->cur_altsetting->desc.bNumEndpoints < 3)
-		return -ENODEV;
-
 	usb_reset_device(udev);
 	netdev = alloc_etherdev(sizeof(struct r8152));
 	if (!netdev) {

Other than that, looks good to me now.

Johan

author
#55 lore raw

RE: [PATCH net v3] r8152: check the informaton of the device

Johan Hovold <[email protected]>

Quoted 1 line

Sent: Monday, May 24, 2021 4:01 PM

[...]

Quoted 11 lines

Review

Quoted 7 lines
(quoted diff) +3 -0
 	/* The vendor mode is not always config #1, so to find it out. */
 	udev = interface_to_usbdev(intf);
 	c = udev->config;
 	num_configs = udev->descriptor.bNumConfigurations;
+	if (num_configs < 2)
+		return false;
+

Nit: This check looks unnecessary also as the driver can handle a single configuration just fine, and by removing it you'd be logging "Unexpected Device\n" below also in the single config case.

I just want to distinguish the devices.
It is acceptable if the device contains only one configuration. A mistake occurs if the device has more configurations and there is no expected one.
I would remove it if you think it is better.

Best Regards,
Hayes

#56 lore raw

Re: [PATCH net v3] r8152: check the informaton of the device

Quoted 15 lines · Hayes Wang

Johan Hovold <[email protected]>

Quoted 1 line

Sent: Monday, May 24, 2021 4:01 PM

[...]

Quoted 11 lines

Review

Quoted 7 lines
(quoted diff) +3 -0
 	/* The vendor mode is not always config #1, so to find it out. */
 	udev = interface_to_usbdev(intf);
 	c = udev->config;
 	num_configs = udev->descriptor.bNumConfigurations;
+	if (num_configs < 2)
+		return false;
+

Nit: This check looks unnecessary also as the driver can handle a single configuration just fine, and by removing it you'd be logging "Unexpected Device\n" below also in the single config case.

Quoted 5 lines

I just want to distinguish the devices.
It is acceptable if the device contains only one configuration. A mistake occurs if the device has more configurations and there is no expected one.
I would remove it if you think it is better.

I'm fine with keeping the check too (e.g. as an optimisation of sort), it's just a bit inconsistent to not log an error in that one error path.

Johan

#57 lore raw

Re: [PATCH net v3] r8152: check the informaton of the device

In reply to Hayes Wang
This patch was applied to netdev/net.git (refs/heads/master):

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

Quoted 6 lines · On Mon, 24 May 2021 14:49:42 +0800 you wrote:

Verify some fields of the USB descriptor to make sure the driver could be used by the device.

Besides, remove the check of endpoint number in rtl8152_probe(). usb_find_common_endpoints() includes it.

Quoted 6 lines
Reported-by [email protected]
Fixes c2198943e33b ("r8152: search the configuration of vendor mode")

[...]

Here is the summary with links:
- [net,v3] r8152: check the informaton of the device

    https://git.kernel.org/netdev/net/c/1a44fb38cc65

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

author
#58 lore raw

PATCH v3 8/9 r8152: avoid the MCU to clear the lanwake

In reply to Hayes Wang

Avoid the MCU to clear the lanwake after suspending. It may cause the WOL fail. Disable LANWAKE_CLR_EN before suspending. Besides,enable it and reset the lanwake status when resuming or initializing.

---
 drivers/net/usb/r8152.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/net/usb/r8152.c +33 -0
index b1a00f29455b..c037fc7adcea 100644
@@ -68,6 +68,7 @@
 #define PLA_LED_FEATURE		0xdd92
 #define PLA_PHYAR		0xde00
 #define PLA_BOOT_CTRL		0xe004
+#define PLA_LWAKE_CTRL_REG	0xe007
 #define PLA_GPHY_INTR_IMR	0xe022
 #define PLA_EEE_CR		0xe040
 #define PLA_EEEP_CR		0xe080
@@ -95,6 +96,7 @@
 #define PLA_TALLYCNT		0xe890
 #define PLA_SFF_STS_7		0xe8de
 #define PLA_PHYSTATUS		0xe908
+#define PLA_CONFIG6		0xe90a /* CONFIG6 */
 #define PLA_BP_BA		0xfc26
 #define PLA_BP_0		0xfc28
 #define PLA_BP_1		0xfc2a
@@ -300,6 +302,9 @@
 #define LINK_ON_WAKE_EN		0x0010
 #define LINK_OFF_WAKE_EN	0x0008
 
+/* PLA_CONFIG6 */
+#define LANWAKE_CLR_EN		BIT(0)
+
 /* PLA_CONFIG5 */
 #define BWF_EN			0x0040
 #define MWF_EN			0x0020
@@ -356,6 +361,9 @@
 /* PLA_BOOT_CTRL */
 #define AUTOLOAD_DONE		0x0002
 
+/* PLA_LWAKE_CTRL_REG */
+#define LANWAKE_PIN		BIT(7)
+
 /* PLA_SUSPEND_FLAG */
 #define LINK_CHG_EVENT		BIT(0)
 
@@ -4968,6 +4976,8 @@ static void rtl8152_down(struct r8152 *tp)
 
 static void rtl8153_up(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags))
 		return;
 
@@ -4975,6 +4985,15 @@ static void rtl8153_up(struct r8152 *tp)
 	r8153_u2p3en(tp, false);
 	r8153_aldps_en(tp, false);
 	r8153_first_init(tp);
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
+	ocp_data |= LANWAKE_CLR_EN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG);
+	ocp_data &= ~LANWAKE_PIN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
+
 	r8153_aldps_en(tp, true);
 
 	switch (tp->version) {
@@ -4993,11 +5012,17 @@ static void rtl8153_up(struct r8152 *tp)
 
 static void rtl8153_down(struct r8152 *tp)
 {
+	u32 ocp_data;
+
 	if (test_bit(RTL8152_UNPLUG, &tp->flags)) {
 		rtl_drop_queued_tx(tp);
 		return;
 	}
 
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
+	ocp_data &= ~LANWAKE_CLR_EN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
+
 	r8153_u1u2en(tp, false);
 	r8153_u2p3en(tp, false);
 	r8153_power_cut_en(tp, false);
@@ -5458,6 +5483,14 @@ static void r8153_init(struct r8152 *tp)
 	r8153_mac_clk_spd(tp, false);
 	usb_enable_lpm(tp->udev);
 
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6);
+	ocp_data |= LANWAKE_CLR_EN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_CONFIG6, ocp_data);
+
+	ocp_data = ocp_read_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG);
+	ocp_data &= ~LANWAKE_PIN;
+	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
+
 	/* rx aggregation */
 	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_USB_CTRL);
 	ocp_data &= ~(RX_AGG_DISABLE | RX_ZERO_EN);
Signature · 1 line
2.21.0
#59 lore raw

Re: [PATCH net-next] r8152: support pauseparam of ethtool_ops

This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 6 lines · On Tue, 1 Jun 2021 15:37:12 +0800 you wrote:

Support get_pauseparam and set_pauseparam of ethtool_ops.

---
 drivers/net/usb/r8152.c | 75 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

Here is the summary with links:
- [net-next] r8152: support pauseparam of ethtool_ops

    https://git.kernel.org/netdev/net-next/c/163d01c56e80

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

author
#60 lore raw

PATCH v3 9/9 r8152: disable DelayPhyPwrChg

In reply to Hayes Wang

When enabling this, the device would wait an internal signal which wouldn't be triggered. Then, the device couldn't enter P3 mode, so the power consumption is increased.

---
 drivers/net/usb/r8152.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/usb/r8152.c +9 -1
index c037fc7adcea..3f425f974d03 100644
@@ -31,7 +31,7 @@
 #define NETNEXT_VERSION		"11"
 
 /* Information for net */
-#define NET_VERSION		"10"
+#define NET_VERSION		"11"
 
 #define DRIVER_VERSION		"v1." NETNEXT_VERSION "." NET_VERSION
 #define DRIVER_AUTHOR "Realtek linux nic maintainers <[email protected]>"
@@ -109,6 +109,7 @@
 #define PLA_BP_EN		0xfc38
 
 #define USB_USB2PHY		0xb41e
+#define USB_SSPHYLINK1		0xb426
 #define USB_SSPHYLINK2		0xb428
 #define USB_U2P3_CTRL		0xb460
 #define USB_CSR_DUMMY1		0xb464
@@ -384,6 +385,9 @@
 #define USB2PHY_SUSPEND		0x0001
 #define USB2PHY_L1		0x0002
 
+/* USB_SSPHYLINK1 */
+#define DELAY_PHY_PWR_CHG	BIT(1)
+
 /* USB_SSPHYLINK2 */
 #define pwd_dn_scale_mask	0x3ffe
 #define pwd_dn_scale(x)		((x) << 1)
@@ -4994,6 +4998,10 @@ static void rtl8153_up(struct r8152 *tp)
 	ocp_data &= ~LANWAKE_PIN;
 	ocp_write_byte(tp, MCU_TYPE_PLA, PLA_LWAKE_CTRL_REG, ocp_data);
 
+	ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1);
+	ocp_data &= ~DELAY_PHY_PWR_CHG;
+	ocp_write_word(tp, MCU_TYPE_USB, USB_SSPHYLINK1, ocp_data);
+
 	r8153_aldps_en(tp, true);
 
 	switch (tp->version) {
Signature · 1 line
2.21.0
#61 lore raw

Re: [PATCH net-next] r8152: store the information of the pipes

This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Thu, 17 Jun 2021 18:00:15 +0800 you wrote:

Store the information of the pipes to avoid calling usb_rcvctrlpipe(), usb_sndctrlpipe(), usb_rcvbulkpipe(), usb_sndbulkpipe(), and usb_rcvintpipe() frequently.

---
 drivers/net/usb/r8152.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Here is the summary with links:
- [net-next] r8152: store the information of the pipes

    https://git.kernel.org/netdev/net-next/c/b67fda9a8280

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

maintainer
#62 lore raw
In reply to Hayes Wang

From: Hayes Wang <[email protected]>
Date: Wed, 22 Jan 2020 16:02:04 +0800

Quoted 9 lines

v3:
1. Fix the typos for patch #5 and #6.
2. Modify the commit message of patch #9.

v2:
For patch #2, move declaring the variable "ocp_data".

v1:
These patches are used to fix some issues for RTL8153.

Series applied, thank you.

#63 lore raw

Re: [PATCH net-next] r8152: replace return with break for ram code speedup mode timeout

In reply to Hayes Wang
This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 9 lines · On Thu, 22 Apr 2021 16:48:02 +0800 you wrote:

When the timeout occurs, we still have to run the following process for releasing patch request. Otherwise, the PHY would keep no link. Therefore, use break to stop the loop of loading firmware and release the patch request rather than return the function directly.

Fixes 4a51b0e8a014 ("r8152: support PHY firmware for RTL8156 series")

[...]

Here is the summary with links:
- [net-next] r8152: replace return with break for ram code speedup mode timeout

    https://git.kernel.org/netdev/net-next/c/f49c35b89b78

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html