9ed92328c397f4a2ef4ce4b057f144c2f0782799
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 790-v5.13-r8152-set-inter-fram-gap-time-depending-on-speed.patch
1 From f1bbbb260a8016373adf239c716d2da90e6ced0b Mon Sep 17 00:00:00 2001
2 From: Hayes Wang <hayeswang@realtek.com>
3 Date: Fri, 16 Apr 2021 16:04:32 +0800
4 Subject: [PATCH] r8152: set inter fram gap time depending on speed
5
6 commit 5133bcc7481528e36fff0a3b056601efb704fb32 upstream.
7
8 Set the maximum inter frame gap time (144ns) for speed 10M/half and
9 100M/half. It improves the performance for those speeds. And, there
10 is no effect for the other speeds.
11
12 For 10M/half and 100M/half, the fast inter frame gap time let the
13 device couldn't use the feature of the aggregation effectively,
14 because the transfer would be completed fastly. Therefore, use the
15 maximum value to improve the effect of the aggregation. However, you
16 may not feel the improvement for fast CPUs, because they compensate
17 for the effect of the aggregation.
18
19 Signed-off-by: Hayes Wang <hayeswang@realtek.com>
20 Signed-off-by: David S. Miller <davem@davemloft.net>
21 ---
22 drivers/net/usb/r8152.c | 28 ++++++++++++++++++++++++++++
23 1 file changed, 28 insertions(+)
24
25 --- a/drivers/net/usb/r8152.c
26 +++ b/drivers/net/usb/r8152.c
27 @@ -249,6 +249,9 @@
28
29 /* PLA_TCR1 */
30 #define VERSION_MASK 0x7cf0
31 +#define IFG_MASK (BIT(3) | BIT(9) | BIT(8))
32 +#define IFG_144NS BIT(9)
33 +#define IFG_96NS (BIT(9) | BIT(8))
34
35 /* PLA_MTPS */
36 #define MTPS_JUMBO (12 * 1024 / 64)
37 @@ -2749,6 +2752,29 @@ static int rtl_stop_rx(struct r8152 *tp)
38 return 0;
39 }
40
41 +static void rtl_set_ifg(struct r8152 *tp, u16 speed)
42 +{
43 + u32 ocp_data;
44 +
45 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR1);
46 + ocp_data &= ~IFG_MASK;
47 + if ((speed & (_10bps | _100bps)) && !(speed & FULL_DUP)) {
48 + ocp_data |= IFG_144NS;
49 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR1, ocp_data);
50 +
51 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4);
52 + ocp_data &= ~TX10MIDLE_EN;
53 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data);
54 + } else {
55 + ocp_data |= IFG_96NS;
56 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_TCR1, ocp_data);
57 +
58 + ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4);
59 + ocp_data |= TX10MIDLE_EN;
60 + ocp_write_word(tp, MCU_TYPE_PLA, PLA_MAC_PWR_CTRL4, ocp_data);
61 + }
62 +}
63 +
64 static inline void r8153b_rx_agg_chg_indicate(struct r8152 *tp)
65 {
66 ocp_write_byte(tp, MCU_TYPE_USB, USB_UPT_RXDMA_OWN,
67 @@ -2852,6 +2878,8 @@ static int rtl8153_enable(struct r8152 *
68 r8153_set_rx_early_timeout(tp);
69 r8153_set_rx_early_size(tp);
70
71 + rtl_set_ifg(tp, rtl8152_get_speed(tp));
72 +
73 if (tp->version == RTL_VER_09) {
74 u32 ocp_data;
75