From: Hayes Wang <hayeswang@realtek.com> To: <netdev@vger.kernel.org> Cc: <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>, <pmalani@chromium.org>, <grundler@chromium.org>, Hayes Wang <hayeswang@realtek.com> Subject: [PATCH net v2 5/9] r8152: Disable PLA MCU clock speed down Date: Wed, 22 Jan 2020 09:41:17 +0800 [thread overview] Message-ID: <1394712342-15778-353-Taiwan-albertk@realtek.com> (raw) In-Reply-To: <1394712342-15778-348-Taiwan-albertk@realtek.com> PLA MCU clock speed down could only be enabled when tx/rx are disabled. Otherwise, the packet lost may occur. Signed-off-by: Hayes Wang <hayeswang@realtek.com> --- drivers/net/usb/r8152.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index bc6b2f8aaa7e..1fb85c79bd33 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -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 */ -- 2.21.0
WARNING: multiple messages have this Message-ID (diff)
From: Hayes Wang <hayeswang@realtek.com> To: <kuba@kernel.org>, <davem@davemloft.net> Cc: <netdev@vger.kernel.org>, <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>, Hayes Wang <hayeswang@realtek.com> Subject: [PATCH net-next 3/6] r8152: add help function to change mtu Date: Fri, 16 Apr 2021 16:04:34 +0800 [thread overview] Message-ID: <1394712342-15778-353-Taiwan-albertk@realtek.com> (raw) Message-ID: <20210416080434.mEH61EKf8lZcClmNT98snyhIa5WT0lPZjkJRowbTtmI@z> (raw) In-Reply-To: <1394712342-15778-350-Taiwan-albertk@realtek.com> The different chips may have different requests when changing mtu. Therefore, add a new help function of rtl_ops to change mtu. Besides, reset the tx/rx after changing mtu. Additionally, add mtu_to_size() and size_to_mtu() macros to simplify the code. Signed-off-by: Hayes Wang <hayeswang@realtek.com> --- drivers/net/usb/r8152.c | 53 ++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 28c9b4dc1a60..3f465242a4f0 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -657,15 +657,13 @@ enum rtl_register_content { #define INTR_LINK 0x0004 -#define RTL8153_MAX_PACKET 9216 /* 9K */ -#define RTL8153_MAX_MTU (RTL8153_MAX_PACKET - VLAN_ETH_HLEN - \ - ETH_FCS_LEN) #define RTL8152_RMS (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN) #define RTL8153_RMS RTL8153_MAX_PACKET #define RTL8152_TX_TIMEOUT (5 * HZ) #define RTL8152_NAPI_WEIGHT 64 -#define rx_reserved_size(x) ((x) + VLAN_ETH_HLEN + ETH_FCS_LEN + \ - sizeof(struct rx_desc) + RX_ALIGN) +#define mtu_to_size(m) ((m) + VLAN_ETH_HLEN + ETH_FCS_LEN) +#define size_to_mtu(s) ((s) - VLAN_ETH_HLEN - ETH_FCS_LEN) +#define rx_reserved_size(x) (mtu_to_size(x) + sizeof(struct rx_desc) + RX_ALIGN) /* rtl8152 flags */ enum rtl8152_flags { @@ -795,6 +793,7 @@ struct r8152 { bool (*in_nway)(struct r8152 *tp); void (*hw_phy_cfg)(struct r8152 *tp); void (*autosuspend_en)(struct r8152 *tp, bool enable); + void (*change_mtu)(struct r8152 *tp); } rtl_ops; struct ups_info { @@ -1021,8 +1020,7 @@ enum tx_csum_stat { static const int multicast_filter_limit = 32; static unsigned int agg_buf_sz = 16384; -#define RTL_LIMITED_TSO_SIZE (agg_buf_sz - sizeof(struct tx_desc) - \ - VLAN_ETH_HLEN - ETH_FCS_LEN) +#define RTL_LIMITED_TSO_SIZE (size_to_mtu(agg_buf_sz) - sizeof(struct tx_desc)) static int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) @@ -2632,10 +2630,7 @@ static void rtl8152_nic_reset(struct r8152 *tp) static void set_tx_qlen(struct r8152 *tp) { - struct net_device *netdev = tp->netdev; - - tp->tx_qlen = agg_buf_sz / (netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN + - sizeof(struct tx_desc)); + tp->tx_qlen = agg_buf_sz / (mtu_to_size(tp->netdev->mtu) + sizeof(struct tx_desc)); } static inline u8 rtl8152_get_speed(struct r8152 *tp) @@ -4724,6 +4719,12 @@ static void r8153b_hw_phy_cfg(struct r8152 *tp) set_bit(PHY_RESET, &tp->flags); } +static void rtl8153_change_mtu(struct r8152 *tp) +{ + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, mtu_to_size(tp->netdev->mtu)); + ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_JUMBO); +} + static void r8153_first_init(struct r8152 *tp) { u32 ocp_data; @@ -4756,9 +4757,7 @@ static void r8153_first_init(struct r8152 *tp) rtl_rx_vlan_en(tp, tp->netdev->features & NETIF_F_HW_VLAN_CTAG_RX); - ocp_data = tp->netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; - ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, ocp_data); - ocp_write_byte(tp, MCU_TYPE_PLA, PLA_MTPS, MTPS_JUMBO); + rtl8153_change_mtu(tp); ocp_data = ocp_read_word(tp, MCU_TYPE_PLA, PLA_TCR0); ocp_data |= TCR0_AUTO_FIFO; @@ -4793,8 +4792,7 @@ static void r8153_enter_oob(struct r8152 *tp) wait_oob_link_list_ready(tp); - ocp_data = tp->netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; - ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, ocp_data); + ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, mtu_to_size(tp->netdev->mtu)); switch (tp->version) { case RTL_VER_03: @@ -6494,12 +6492,21 @@ static int rtl8152_change_mtu(struct net_device *dev, int new_mtu) dev->mtu = new_mtu; if (netif_running(dev)) { - u32 rms = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; - - ocp_write_word(tp, MCU_TYPE_PLA, PLA_RMS, rms); + if (tp->rtl_ops.change_mtu) + tp->rtl_ops.change_mtu(tp); - if (netif_carrier_ok(dev)) - r8153_set_rx_early_size(tp); + if (netif_carrier_ok(dev)) { + netif_stop_queue(dev); + napi_disable(&tp->napi); + tasklet_disable(&tp->tx_tl); + tp->rtl_ops.disable(tp); + tp->rtl_ops.enable(tp); + rtl_start_rx(tp); + tasklet_enable(&tp->tx_tl); + napi_enable(&tp->napi); + rtl8152_set_rx_mode(dev); + netif_wake_queue(dev); + } } mutex_unlock(&tp->control); @@ -6588,6 +6595,7 @@ static int rtl_ops_init(struct r8152 *tp) ops->in_nway = rtl8153_in_nway; ops->hw_phy_cfg = r8153_hw_phy_cfg; ops->autosuspend_en = rtl8153_runtime_enable; + ops->change_mtu = rtl8153_change_mtu; if (tp->udev->speed < USB_SPEED_SUPER) tp->rx_buf_sz = 16 * 1024; else @@ -6609,6 +6617,7 @@ static int rtl_ops_init(struct r8152 *tp) ops->in_nway = rtl8153_in_nway; ops->hw_phy_cfg = r8153b_hw_phy_cfg; ops->autosuspend_en = rtl8153b_runtime_enable; + ops->change_mtu = rtl8153_change_mtu; tp->rx_buf_sz = 32 * 1024; tp->eee_en = true; tp->eee_adv = MDIO_EEE_1000T | MDIO_EEE_100TX; @@ -6829,7 +6838,7 @@ static int rtl8152_probe(struct usb_interface *intf, netdev->max_mtu = ETH_DATA_LEN; break; default: - netdev->max_mtu = RTL8153_MAX_MTU; + netdev->max_mtu = size_to_mtu(9 * 1024); break; } -- 2.26.3
next prev parent reply other threads:[~2020-01-22 1:44 UTC|newest] Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-01-21 12:40 [PATCH net 0/9] r8152: serial fixes Hayes Wang 2020-01-21 12:40 ` [PATCH net 1/9] r8152: fix runtime resume for linking change Hayes Wang 2020-01-22 9:47 ` Sergei Shtylyov 2020-01-21 12:40 ` [PATCH net 2/9] r8152: reset flow control patch when linking on for RTL8153B Hayes Wang 2020-01-21 12:54 ` David Miller 2020-01-21 13:01 ` Joe Perches 2020-01-21 13:19 ` Hayes Wang 2020-01-21 12:40 ` [PATCH net 3/9] r8152: get default setting of WOL before initializing Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 0/4] r8152: minor adjustments Hayes Wang 2021-02-23 20:40 ` patchwork-bot+netdevbpf 2020-01-21 12:40 ` [PATCH net 4/9] r8152: disable U2P3 for RTL8153B Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 1/4] r8152: enable U1/U2 for USB_SPEED_SUPER Hayes Wang 2020-01-21 12:40 ` [PATCH net 5/9] r8152: Disable PLA MCU clock speed down Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 2/4] r8152: check if the pointer of the function exists Hayes Wang 2020-01-21 12:40 ` [PATCH net 6/9] r8152: disable test IO for RTL8153B Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 3/4] r8152: replace netif_err with dev_err Hayes Wang 2020-01-21 12:40 ` [PATCH net 7/9] r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B Hayes Wang 2021-02-19 9:04 ` [PATCH net-next 4/4] r8152: spilt rtl_set_eee_plus and r8153b_green_en Hayes Wang 2020-01-21 12:40 ` [PATCH net 8/9] r8152: avoid the MCU to clear the lanwake Hayes Wang 2021-02-19 9:38 ` [PATCH net] r8152: move r8153_mac_clk_spd Hayes Wang 2021-02-19 18:22 ` Jakub Kicinski 2021-02-22 6:19 ` Hayes Wang 2020-01-21 12:40 ` [PATCH net 9/9] r8152: disable DelayPhyPwrChg Hayes Wang 2020-01-22 7:02 ` Grant Grundler 2020-01-22 7:50 ` Hayes Wang 2021-03-03 8:39 ` [PATCH net] Revert "r8152: adjust the settings about MAC clock speed down for RTL8153" Hayes Wang 2021-03-04 1:00 ` patchwork-bot+netdevbpf 2020-01-22 1:41 ` [PATCH net v2 0/9] r8152: serial fixes Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 1/9] r8152: fix runtime resume for linking change Hayes Wang 2021-03-19 7:37 ` [PATCH net] r8152: limit the RX buffer size of RTL8153A for USB 2.0 Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 2/9] r8152: reset flow control patch when linking on for RTL8153B Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 0/6] r8152: support new chips Hayes Wang 2021-04-16 22:40 ` patchwork-bot+netdevbpf 2020-01-22 1:41 ` [PATCH net v2 3/9] r8152: get default setting of WOL before initializing Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 1/6] r8152: set inter fram gap time depending on speed Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 4/9] r8152: disable U2P3 for RTL8153B Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 2/6] r8152: adjust rtl8152_check_firmware function Hayes Wang 2020-01-22 1:41 ` Hayes Wang [this message] 2021-04-16 8:04 ` [PATCH net-next 3/6] r8152: add help function to change mtu Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 6/9] r8152: disable test IO for RTL8153B Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 4/6] r8152: support new chips Hayes Wang 2021-04-16 21:50 ` Jakub Kicinski 2021-04-20 7:00 ` Hayes Wang 2021-04-20 18:34 ` Jakub Kicinski 2021-04-21 2:23 ` Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 7/9] r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 5/6] r8152: support PHY firmware for RTL8156 series Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 8/9] r8152: avoid the MCU to clear the lanwake Hayes Wang 2021-04-16 8:04 ` [PATCH net-next 6/6] r8152: search the configuration of vendor mode Hayes Wang 2020-01-22 1:41 ` [PATCH net v2 9/9] r8152: disable DelayPhyPwrChg Hayes Wang 2021-04-20 12:40 ` [PATCH linux-firmware] rtl_nic: add new firmware for RTL8153 and RTL8156 series Hayes Wang 2021-03-05 9:34 ` [PATCH net] r8169: fix r8168fp_adjust_ocp_cmd function Hayes Wang 2021-03-05 11:48 ` Heiner Kallweit 2021-03-05 21:10 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 0/9] r8152: serial fixes Hayes Wang 2020-01-22 8:02 ` [PATCH net v3 1/9] r8152: fix runtime resume for linking change Hayes Wang 2021-04-23 9:44 ` [PATCH net-next 0/2] r8152: adjust REALTEK_USB_DEVICE Hayes Wang 2021-04-23 21:00 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 2/9] r8152: reset flow control patch when linking on for RTL8153B Hayes Wang 2021-04-23 9:44 ` [PATCH net-next 1/2] r8152: remove NCM mode from REALTEK_USB_DEVICE macro Hayes Wang 2020-01-22 8:02 ` [PATCH net v3 3/9] r8152: get default setting of WOL before initializing Hayes Wang 2021-04-23 9:44 ` [PATCH net-next 2/2] r8152: redefine REALTEK_USB_DEVICE macro Hayes Wang 2020-01-22 8:02 ` [PATCH net v3 4/9] r8152: disable U2P3 for RTL8153B Hayes Wang 2021-04-24 6:09 ` [PATCH net-next] r8152: remove some bit operations Hayes Wang 2021-04-26 1:30 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 5/9] r8152: Disable PLA MCU clock speed down Hayes Wang 2021-05-21 9:07 ` [PATCH net] r8152: check the informaton of the device Hayes Wang 2021-05-21 9:42 ` Greg KH 2021-05-22 3:13 ` Hayes Wang 2020-01-22 8:02 ` [PATCH net v3 6/9] r8152: disable test IO for RTL8153B Hayes Wang 2021-05-22 5:24 ` [PATCH net v2] r8152: check the informaton of the device Hayes Wang 2021-05-22 7:32 ` Greg KH 2021-05-22 8:07 ` Johan Hovold 2021-05-24 1:49 ` Hayes Wang 2021-05-24 7:44 ` Johan Hovold 2020-01-22 8:02 ` [PATCH net v3 7/9] r8152: don't enable U1U2 with USB_SPEED_HIGH for RTL8153B Hayes Wang 2021-05-24 6:49 ` [PATCH net v3] r8152: check the informaton of the device Hayes Wang 2021-05-24 8:00 ` Johan Hovold 2021-05-24 8:54 ` Hayes Wang 2021-05-24 9:13 ` Johan Hovold 2021-05-24 20:20 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 8/9] r8152: avoid the MCU to clear the lanwake Hayes Wang 2021-06-01 7:37 ` [PATCH net-next] r8152: support pauseparam of ethtool_ops Hayes Wang 2021-06-01 22:30 ` patchwork-bot+netdevbpf 2020-01-22 8:02 ` [PATCH net v3 9/9] r8152: disable DelayPhyPwrChg Hayes Wang 2021-06-17 10:00 ` [PATCH net-next] r8152: store the information of the pipes Hayes Wang 2021-06-17 19:20 ` patchwork-bot+netdevbpf 2020-01-23 10:21 ` [PATCH net v3 0/9] r8152: serial fixes David Miller 2021-04-22 8:48 ` [PATCH net-next] r8152: replace return with break for ram code speedup mode timeout Hayes Wang 2021-04-22 21:20 ` patchwork-bot+netdevbpf
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1394712342-15778-353-Taiwan-albertk@realtek.com \ --to=hayeswang@realtek.com \ --cc=grundler@chromium.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-usb@vger.kernel.org \ --cc=netdev@vger.kernel.org \ --cc=nic_swsd@realtek.com \ --cc=pmalani@chromium.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).