Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Chih Kai Hsu
Mon, 30 Nov 2026 06:31
[PATCH net-next v10 04/12] r8152: fix flow control for RTL8156/RTL8156B/RTL8157/RTL8159
Author: Chih Kai Hsu
Date: Mon, 30 Nov 2026 06:31
Date: Mon, 30 Nov 2026 06:31
218 lines
16200 bytes
16200 bytes
The flow-control setup that limits pause frames was incomplete or
missing on several chips:
- RTL8156A (VER_10/11): r8156_init() skipped them, so the FC timer and
FLOW_CTRL_PATCH_OPT setup that the FC_PATCH_TASK toggle in
rtl8156_enable() depends on was never done.
- RTL8157/RTL8159 (VER_16/17): no limit on the number of pause packets
was programmed, so they could keep sending pause frames
indefinitely.
Collect the per-family sequence into rtl_fc_pause_pkt_en() and call it
for all of them.
- VER_10/11: the FC timer + FLOW_CTRL_PATCH_OPT sequence that
RTL8153B (VER_09) already runs from its pre_fw/post_fw hooks,
applied directly instead.
- VER_12/13/15: the sequence r8156_init() already ran, moved here
unchanged.
- VER_16/17: limit pause packets with the new PLA_PAUSE_LIMIT register
instead of the FW patch. The datasheet gives a fixed count per link
speed, reproduced here by a log2-ratio computation. Because the
count follows the negotiated speed, this family is called from
rtl8156_enable() rather than from init.
SLOT_EN in PLA_RCR is cleared as well, which these chips did not do
before. With SLOT_EN clear, a pause frame is sent each time the
pause timer expires, which is what the pause limit relies on. The
clear is idempotent, so running it on every enable is harmless.
The speed decode covers every rate the driver advertises. With no
rate bit set, i.e. link down or a rate the driver does not
advertise (500 or 1250 Mbit/s), pause limiting is disabled rather
than programmed from a guessed speed.
In r8156_init(), split AUTO_SPEEDUP clearing from the flow-control FW
patch; it still applies to RTL8156B only.
Fixes: 195aae321c82 ("r8152: support new chips")
Fixes: fd3c7d080df5 ("r8152: Add support for the RTL8157 hardware")
Fixes: ad2a55b63b41 ("r8152: Add support for the RTL8159 chip")
Signed-off-by: Chih Kai Hsu <hsu.chih.kai@realtek.com>
---
drivers/net/usb/r8152.c | 128 +++++++++++++++++++++++++++++++++++-----
1 file changed, 113 insertions(+), 15 deletions(-)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 1517753f843ef..e58b010c734ad 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -87,6 +87,7 @@
#define PLA_MTPS 0xe615
#define PLA_TXFIFO_CTRL 0xe618
#define PLA_TXFIFO_FULL 0xe61a
+#define PLA_PAUSE_LIMIT 0xe61e
#define PLA_RSTTALLY 0xe800
#define PLA_CR 0xe813
#define PLA_CRWECR 0xe81c
@@ -293,6 +294,10 @@
#define MTPS_JUMBO (12 * 1024 / 64)
#define MTPS_DEFAULT (6 * 1024 / 64)
+/* PLA_PAUSE_LIMIT */
+#define PAUSE_LIMIT_EN BIT(3)
+#define PAUSE_LIMIT_MASK 0xf0
+
/* PLA_RSTTALLY */
#define TALLY_RESET 0x0001
@@ -5961,6 +5966,105 @@ static void r8152b_enter_oob(struct r8152 *tp)
RCR_APM | RCR_AM | RCR_AB);
}
+static void rtl_fc_pause_pkt_en(struct r8152 *tp, u16 speed)
+{
+ int log2_ratio, ratio;
+ u16 num_pause_pkts;
+ u32 ocp_data;
+
+ switch (tp->version) {
+ case RTL_VER_10:
+ case RTL_VER_11:
+ ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,
+ CTRL_TIMER_EN | (1000 / 8));
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_CTRL,
+ FLOW_CTRL_PATCH_OPT);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+ break;
+ case RTL_VER_12:
+ case RTL_VER_13:
+ case RTL_VER_15:
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_CPCR, FLOW_CTRL_EN);
+
+ /* enable fc timer and set timer to 600 ms. */
+ ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,
+ CTRL_TIMER_EN | (600 / 8));
+
+ ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL);
+ if (!(ocp_data & DACK_DET_EN))
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_CTRL,
+ FLOW_CTRL_PATCH_2);
+
+ ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
+ break;
+ case RTL_VER_16:
+ case RTL_VER_17:
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
+
+ num_pause_pkts = 0xa;
+ ratio = 10000;
+
+ if (speed & _10bps) {
+ ratio /= 10;
+ } else if (speed & _100bps) {
+ ratio /= 100;
+ } else if (speed & _1000bps) {
+ ratio /= 1000;
+ } else if (speed & _2500bps) {
+ ratio /= 2500;
+ } else if (speed & _5000bps) {
+ ratio /= 5000;
+ } else if (speed & _10000bps) {
+ ratio /= 10000;
+ } else {
+ /* Link down, or a rate the driver does not advertise
+ * (500 or 1250 Mbit/s). Disable the limit; the next
+ * link up programs it again.
+ */
+ dev_dbg(&tp->intf->dev,
+ "No known link speed (0x%04x), pause limit disabled\n",
+ speed);
+ ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,
+ PAUSE_LIMIT_EN);
+ break;
+ }
+
+ log2_ratio = ilog2(ratio);
+ num_pause_pkts -= log2_ratio;
+
+ /* Round ratio up to the next power of two if it is
+ * more than halfway there. Floating-point is avoided
+ * by rewriting ratio > 1.5 * 2^log2_ratio as
+ * 2 * ratio > 3 * 2^log2_ratio.
+ */
+ if (2 * ratio > 3 * (1 << log2_ratio))
+ num_pause_pkts--;
+
+ /* At most 2^num_pause_pkts pause packets would be sent.
+ *
+ * 10 Mbit/s -> 2^0
+ * 100 Mbit/s -> 2^3
+ * 1 Gbit/s -> 2^7
+ * 2.5 Gbit/s -> 2^8
+ * 5 Gbit/s -> 2^9
+ * 10 Gbit/s -> 2^10
+ */
+ ocp_word_w0w1(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,
+ PAUSE_LIMIT_MASK | PAUSE_LIMIT_EN,
+ num_pause_pkts << 4);
+
+ ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_PAUSE_LIMIT,
+ PAUSE_LIMIT_EN);
+ break;
+ default:
+ break;
+ }
+}
+
static int r8153_pre_firmware_1(struct r8152 *tp)
{
int i;
@@ -6404,6 +6508,10 @@ static int rtl8156_enable(struct r8152 *tp)
r8153_set_rx_early_size(tp);
speed = rtl8152_get_speed(tp);
+
+ if (tp->version >= RTL_VER_16)
+ rtl_fc_pause_pkt_en(tp, speed);
+
rtl_set_ifg(tp, speed);
if (tp->version >= RTL_VER_16)
@@ -8490,22 +8598,12 @@ static void r8156_init(struct r8152 *tp)
usb_enable_lpm(tp->udev);
- if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_15) {
- ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
-
- ocp_word_set_bits(tp, MCU_TYPE_PLA, PLA_CPCR, FLOW_CTRL_EN);
-
- /* enable fc timer and set timer to 600 ms. */
- ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER, CTRL_TIMER_EN | (600 / 8));
-
- ocp_data = ocp_read_word(tp, MCU_TYPE_USB, USB_FW_CTRL);
- if (!(ocp_read_word(tp, MCU_TYPE_PLA, PLA_POL_GPIO_CTRL) & DACK_DET_EN))
- ocp_data |= FLOW_CTRL_PATCH_2;
- ocp_data &= ~AUTO_SPEEDUP;
- ocp_write_word(tp, MCU_TYPE_USB, USB_FW_CTRL, ocp_data);
+ if (tp->version < RTL_VER_16)
+ rtl_fc_pause_pkt_en(tp, 0);
- ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
- }
+ if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_15)
+ /* Disable Auto Speed up */
+ ocp_word_clr_bits(tp, MCU_TYPE_USB, USB_FW_CTRL, AUTO_SPEEDUP);
r8156_mac_clk_spd(tp, true);
--
2.34.1
Re: [PATCH net-next v10 04/12] r8152: fix flow control for RTL8156/RTL8156B/RTL8157/RTL8159
Author: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 06:46
Date: Tue, 01 Dec 2026 06:46
128 lines
11872 bytes
11872 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Three fixes with different stable targets are packed into one
patch and one helper, rtl_fc_pause_pkt_en() in drivers/net/usb/r8152.c.
--
r8152: fix flow control for RTL8156/RTL8156B/RTL8157/RTL8159
This patch moves the flow-control setup for RTL8156, RTL8156B, RTL8157
and RTL8159 into a new helper, rtl_fc_pause_pkt_en(). It adds the
missing FC timer and FLOW_CTRL_PATCH_OPT setup for RTL8156A. It also
programs a new PLA_PAUSE_LIMIT register on RTL8157/RTL8159 from
rtl8156_enable(), based on the link speed.
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index 1517753f843ef..e58b010c734ad 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
[ ... ]
> @@ -5961,6 +5966,105 @@ static void r8152b_enter_oob(struct r8152 *tp)
> RCR_APM | RCR_AM | RCR_AB);
> }
>
> +static void rtl_fc_pause_pkt_en(struct r8152 *tp, u16 speed)
> +{
> + int log2_ratio, ratio;
> + u16 num_pause_pkts;
> + u32 ocp_data;
> +
> + switch (tp->version) {
> + case RTL_VER_10:
> + case RTL_VER_11:
> + ocp_write_word(tp, MCU_TYPE_USB, USB_FC_TIMER,
> + CTRL_TIMER_EN | (1000 / 8));
> +
> + ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_CTRL,
> + FLOW_CTRL_PATCH_OPT);
> +
> + ocp_word_set_bits(tp, MCU_TYPE_USB, USB_FW_TASK, FC_PATCH_TASK);
> + break;
> + case RTL_VER_12:
> + case RTL_VER_13:
> + case RTL_VER_15:
> + ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
[ ... ]
> + case RTL_VER_16:
> + case RTL_VER_17:
> + ocp_word_clr_bits(tp, MCU_TYPE_PLA, PLA_RCR, SLOT_EN);
[ ... ]
> @@ -6404,6 +6508,10 @@ static int rtl8156_enable(struct r8152 *tp)
> r8153_set_rx_early_size(tp);
>
> speed = rtl8152_get_speed(tp);
> +
> + if (tp->version >= RTL_VER_16)
> + rtl_fc_pause_pkt_en(tp, speed);
> +
> rtl_set_ifg(tp, speed);
>
> if (tp->version >= RTL_VER_16)
[ ... ]
> @@ -8490,22 +8598,12 @@ static void r8156_init(struct r8152 *tp)
>
> usb_enable_lpm(tp->udev);
>
> - if (tp->version >= RTL_VER_12 && tp->version <= RTL_VER_15) {
[ ... ]
> + if (tp->version < RTL_VER_16)
> + rtl_fc_pause_pkt_en(tp, 0);
[Severity: Low]
This isn't a runtime bug, but would stable have an easier time if this
patch were split up?
rtl_fc_pause_pkt_en() combines three separate changes:
- the RTL8156A (RTL_VER_10/11) FC timer and FLOW_CTRL_PATCH_OPT setup.
r8156_init() has lacked it since 195aae321c82 ("r8152: support new
chips").
- the new PLA_PAUSE_LIMIT and SLOT_EN setup for RTL8157/RTL8159
(RTL_VER_16/17). These chips only exist after fd3c7d080df5 and
ad2a55b63b41.
- an unchanged move of the RTL8156B (RTL_VER_12/13/15) sequence.
Stable trees picked by Fixes: 195aae321c82 don't have RTL_VER_16/17,
PLA_PAUSE_LIMIT, or the RTL_VER_16 handling in rtl8156_enable() that the
new call sits next to. The patch would not apply there. Someone would
have to split out the RTL8156A part by hand.
The RTL8156A fix is just the VER_10/11 case plus the new
rtl_fc_pause_pkt_en(tp, 0) call in r8156_init(). Could that go in its
own patch with Fixes: 195aae321c82? The VER_16/17 pause limit would then
be a separate patch with Fixes: fd3c7d080df5 / ad2a55b63b41. The
refactor into a common helper could come first, or be dropped.
Later patches in this series, such as "r8152: split r8156_init by
generation and factor out wait_autoload_done", keep the combined helper.
So this doesn't seem to be resolved later in the series.
Also, the subject says:
r8152: fix flow control for RTL8156/RTL8156B/RTL8157/RTL8159
The commit message says the VER_12/13/15 sequence is "moved here
unchanged", so no RTL8156B behavior seems to change. Should RTL8156B be
removed from the subject?
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130063123.2408-1-nic_swsd%40realtek.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads