From patchwork Wed Jan 6 10:47:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12001319 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79DEAC433E0 for ; Wed, 6 Jan 2021 10:50:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 257D52310E for ; Wed, 6 Jan 2021 10:50:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726366AbhAFKuk (ORCPT ); Wed, 6 Jan 2021 05:50:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725925AbhAFKuj (ORCPT ); Wed, 6 Jan 2021 05:50:39 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CC9EC06134C for ; Wed, 6 Jan 2021 02:49:59 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id g185so2229630wmf.3 for ; Wed, 06 Jan 2021 02:49:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=sv8+etW+yK2uhdrudJJQBqucmERfPpVDUieqOwNOibc=; b=iaD6IW6J+80GrIbKbJ1yJ9XAQ0mNArIsnYcq/uQoION6zsGCrx1dt4iJqmJdVs/9T0 BmWsW35Kxm6JZjw4/8fQUa75CTqEm3wXBmflmIm2MO9MYKJxG7wkmt7kV1bcfZSEOeDJ QutWqhJ/bPb082g03SLi5Qhn1Z7x08sL3RhgZCq27hvr25BDiti5C3aCIOq5i9rAO+ct Q+Pc7kWfd6mvI23O7E5Tu2aACYjwCj5khqjgUJGIBrxFOh038HledO33A5V7UDy0EVOa OMDLmqKMAaNRYL4qB+KZDdjpSXRzyP/iXdhoHggfIFD2UC2Qeq5kEXDskGykRBeX7NOJ 7OOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=sv8+etW+yK2uhdrudJJQBqucmERfPpVDUieqOwNOibc=; b=MB5d4I29fqdJ5J4KXz3t9vNvMM8uBG6JrT0xWLs0vqBxX+witmmoLXWmYwqXDSyKKa 7nXqlCqN7MQDbOxiA0qaNmgYaHAaNBxldmg/G1g2NE6yXlaZQh98a9XMOboZ1pvSkMNG J13nNCqQv2EnS2wWQJWbBSaldGWYanKLCBWY8Yh9hwFePWFNvoY6dkHDqouvi2ViRBvH Q3c4g1ORQvPGscK3cpAnnmwg1VMnp0gW1TMgJbvTGbmmtSSMFR6fDD4lOIMu+XQZ8vGR uUvIGGV30Lmwf5R2HYRAvIuo+4iG2xzT46cOTS719WzgtqIO43kOR3kwN1ShiMl71TyI 0Tpg== X-Gm-Message-State: AOAM531MezsBxIbrsEuZ/C4FXclL8O6j28Yt57JnbLzY7aWkrpUeYJD5 GG0ud4ZHLjvA8tNCbRb0rBvNiK+Viz8= X-Google-Smtp-Source: ABdhPJyobVlQRKc77fS+h+njEdK+xXYYu3ZHkPGeVollLVu1s3wcRYeuy5mTusIU1oaC9Dlp03Kzeg== X-Received: by 2002:a7b:cb9a:: with SMTP id m26mr3130244wmi.130.1609930197724; Wed, 06 Jan 2021 02:49:57 -0800 (PST) Received: from ?IPv6:2003:ea:8f06:5500:e1db:b990:7e09:f1cf? (p200300ea8f065500e1dbb9907e09f1cf.dip0.t-ipconnect.de. [2003:ea:8f06:5500:e1db:b990:7e09:f1cf]) by smtp.googlemail.com with ESMTPSA id l20sm2685912wrh.82.2021.01.06.02.49.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Jan 2021 02:49:57 -0800 (PST) Subject: [PATCH net-next 1/2] r8169: move ERI access functions to avoid forward declaration From: Heiner Kallweit To: Jakub Kicinski , David Miller , Realtek linux nic maintainers Cc: "netdev@vger.kernel.org" References: <9303c2cf-c521-beea-c09f-63b5dfa91b9c@gmail.com> Message-ID: Date: Wed, 6 Jan 2021 11:47:08 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <9303c2cf-c521-beea-c09f-63b5dfa91b9c@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org No functional change here. We just move a code block to avoid a function forward declaration in a subsequent change. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/realtek/r8169_main.c | 128 +++++++++++----------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index a569abe7f..dd56f33b2 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -746,6 +746,70 @@ static const struct rtl_cond name = { \ \ static bool name ## _check(struct rtl8169_private *tp) +static void r8168fp_adjust_ocp_cmd(struct rtl8169_private *tp, u32 *cmd, int type) +{ + /* based on RTL8168FP_OOBMAC_BASE in vendor driver */ + if (tp->mac_version == RTL_GIGA_MAC_VER_52 && type == ERIAR_OOB) + *cmd |= 0x7f0 << 18; +} + +DECLARE_RTL_COND(rtl_eriar_cond) +{ + return RTL_R32(tp, ERIAR) & ERIAR_FLAG; +} + +static void _rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, + u32 val, int type) +{ + u32 cmd = ERIAR_WRITE_CMD | type | mask | addr; + + BUG_ON((addr & 3) || (mask == 0)); + RTL_W32(tp, ERIDR, val); + r8168fp_adjust_ocp_cmd(tp, &cmd, type); + RTL_W32(tp, ERIAR, cmd); + + rtl_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); +} + +static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, + u32 val) +{ + _rtl_eri_write(tp, addr, mask, val, ERIAR_EXGMAC); +} + +static u32 _rtl_eri_read(struct rtl8169_private *tp, int addr, int type) +{ + u32 cmd = ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr; + + r8168fp_adjust_ocp_cmd(tp, &cmd, type); + RTL_W32(tp, ERIAR, cmd); + + return rtl_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? + RTL_R32(tp, ERIDR) : ~0; +} + +static u32 rtl_eri_read(struct rtl8169_private *tp, int addr) +{ + return _rtl_eri_read(tp, addr, ERIAR_EXGMAC); +} + +static void rtl_w0w1_eri(struct rtl8169_private *tp, int addr, u32 p, u32 m) +{ + u32 val = rtl_eri_read(tp, addr); + + rtl_eri_write(tp, addr, ERIAR_MASK_1111, (val & ~m) | p); +} + +static void rtl_eri_set_bits(struct rtl8169_private *tp, int addr, u32 p) +{ + rtl_w0w1_eri(tp, addr, p, 0); +} + +static void rtl_eri_clear_bits(struct rtl8169_private *tp, int addr, u32 m) +{ + rtl_w0w1_eri(tp, addr, 0, m); +} + static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) { if (reg & 0xffff0001) { @@ -1009,70 +1073,6 @@ static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; } -static void r8168fp_adjust_ocp_cmd(struct rtl8169_private *tp, u32 *cmd, int type) -{ - /* based on RTL8168FP_OOBMAC_BASE in vendor driver */ - if (tp->mac_version == RTL_GIGA_MAC_VER_52 && type == ERIAR_OOB) - *cmd |= 0x7f0 << 18; -} - -DECLARE_RTL_COND(rtl_eriar_cond) -{ - return RTL_R32(tp, ERIAR) & ERIAR_FLAG; -} - -static void _rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, - u32 val, int type) -{ - u32 cmd = ERIAR_WRITE_CMD | type | mask | addr; - - BUG_ON((addr & 3) || (mask == 0)); - RTL_W32(tp, ERIDR, val); - r8168fp_adjust_ocp_cmd(tp, &cmd, type); - RTL_W32(tp, ERIAR, cmd); - - rtl_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); -} - -static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, - u32 val) -{ - _rtl_eri_write(tp, addr, mask, val, ERIAR_EXGMAC); -} - -static u32 _rtl_eri_read(struct rtl8169_private *tp, int addr, int type) -{ - u32 cmd = ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr; - - r8168fp_adjust_ocp_cmd(tp, &cmd, type); - RTL_W32(tp, ERIAR, cmd); - - return rtl_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? - RTL_R32(tp, ERIDR) : ~0; -} - -static u32 rtl_eri_read(struct rtl8169_private *tp, int addr) -{ - return _rtl_eri_read(tp, addr, ERIAR_EXGMAC); -} - -static void rtl_w0w1_eri(struct rtl8169_private *tp, int addr, u32 p, u32 m) -{ - u32 val = rtl_eri_read(tp, addr); - - rtl_eri_write(tp, addr, ERIAR_MASK_1111, (val & ~m) | p); -} - -static void rtl_eri_set_bits(struct rtl8169_private *tp, int addr, u32 p) -{ - rtl_w0w1_eri(tp, addr, p, 0); -} - -static void rtl_eri_clear_bits(struct rtl8169_private *tp, int addr, u32 m) -{ - rtl_w0w1_eri(tp, addr, 0, m); -} - static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u16 reg) { RTL_W32(tp, OCPAR, 0x0fu << 12 | (reg & 0x0fff)); From patchwork Wed Jan 6 10:49:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 12001321 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E803C433E6 for ; Wed, 6 Jan 2021 10:50:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FC8323105 for ; Wed, 6 Jan 2021 10:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725906AbhAFKul (ORCPT ); Wed, 6 Jan 2021 05:50:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725925AbhAFKuk (ORCPT ); Wed, 6 Jan 2021 05:50:40 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66EE2C06134D for ; Wed, 6 Jan 2021 02:50:00 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id r4so2210811wmh.5 for ; Wed, 06 Jan 2021 02:50:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=OzrWtwD329kfifIWHgcYNhGhf/dx4oIAVUb+Kkcmpc0=; b=Fm6Y2ErHHzEYWvowMU3Rlycdr6WGKM18Y1x/OPNzEqHzMyqRJl1SvZM5xdmzXV8pGi ok46rjzS5Nm9YVcdBzSajZikb5ZMpkjVYhs4LoMVhPA62oscx50wiOwf+8j1OsuLQi3t Qu6ghQpbm7FEWKmAW8r+GkUmVdtmBQkHwDsO1XZipkgXC/mWXNSQq/iLlb5b1jgQJd9E hGSteZeUoSVb8GJSHH7oW88vt6TmStpalEe6k0eF8yWG7aMn+e22PuCmYs49R9ZS++8i MRhX+5QSPn77BQbSQfRfrqv9ecIrusSrfhOYUYSlpeqjctMB8Pgf78FfYdJlIzcEFTAf /Q+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OzrWtwD329kfifIWHgcYNhGhf/dx4oIAVUb+Kkcmpc0=; b=OhwNeYjJTemddVHhALBrDLMDfq3WalFjMYf77nQglDtfCcjqPiCiFSBS5W7Sc5G0FC GA2BHw8M0MpWcW26LleQ8RPTbxK1zj6dfw4/aZKIUHDF6ccFnv+Y/5rnMZKxe8QNdswQ 8HiAHRU4H5faIj8LOoJWZxM732ZSjM3KwpSWUUTMeeVNavdtXqfA5ZnfwaIOBLk7QXKN bWGnrGlzX9sflsWV1sHfKfrAGGDY5gg/Te/b1SGzgh1a5QUZgKsMOPgp5mq4HU+SYor3 Tmsbvh26uuumGnopyOuYUsjOEE5O0kq/3vZtjeLVGsTUM/Nb7YrSmsbTXsMXkgQHOAUG aeYg== X-Gm-Message-State: AOAM531pFaj8ycWArIqhjU4ThQdawW8lxRYfvx2i0aHJ9yCtouXJAGGg Scsd+6eM/epMDaCcGB9P0dng0eFztj8= X-Google-Smtp-Source: ABdhPJxNo5kcqrwMPOgKxq51dbUVPtRAMlPaaOZHJkVOVCSlpcyZE8AuNUZ/IZ1Jy9xqRf5OFVod0g== X-Received: by 2002:a7b:cf08:: with SMTP id l8mr3169992wmg.189.1609930198895; Wed, 06 Jan 2021 02:49:58 -0800 (PST) Received: from ?IPv6:2003:ea:8f06:5500:e1db:b990:7e09:f1cf? (p200300ea8f065500e1dbb9907e09f1cf.dip0.t-ipconnect.de. [2003:ea:8f06:5500:e1db:b990:7e09:f1cf]) by smtp.googlemail.com with ESMTPSA id s133sm2507402wmf.38.2021.01.06.02.49.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Jan 2021 02:49:58 -0800 (PST) Subject: [PATCH net-next 2/2] r8169: improve RTL8168g PHY suspend quirk From: Heiner Kallweit To: Jakub Kicinski , David Miller , Realtek linux nic maintainers Cc: "netdev@vger.kernel.org" References: <9303c2cf-c521-beea-c09f-63b5dfa91b9c@gmail.com> Message-ID: Date: Wed, 6 Jan 2021 11:49:50 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <9303c2cf-c521-beea-c09f-63b5dfa91b9c@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org According to Realtek the ERI register 0x1a8 quirk is needed to work around a hw issue with the PHY on RTL8168g. The register needs to be changed before powering down the PHY. Currently we don't meet this requirement, however I'm not aware of any problems caused by this. Therefore I see the change as an improvement. The PHY driver has no means to access the chip ERI registers, therefore we have to intercept MDIO writes to BMCR register. If the BMCR_PDOWN bit is going to be set, then let's apply the quirk before actually powering down the PHY. Signed-off-by: Heiner Kallweit --- drivers/net/ethernet/realtek/r8169_main.c | 52 +++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index dd56f33b2..a8284feb4 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -872,6 +872,25 @@ static void r8168_mac_ocp_modify(struct rtl8169_private *tp, u32 reg, u16 mask, r8168_mac_ocp_write(tp, reg, (data & ~mask) | set); } +/* Work around a hw issue with RTL8168g PHY, the quirk disables + * PHY MCU interrupts before PHY power-down. + */ +static void rtl8168g_phy_suspend_quirk(struct rtl8169_private *tp, int value) +{ + switch (tp->mac_version) { + case RTL_GIGA_MAC_VER_40: + case RTL_GIGA_MAC_VER_41: + case RTL_GIGA_MAC_VER_49: + if (value & BMCR_RESET || !(value & BMCR_PDOWN)) + rtl_eri_set_bits(tp, 0x1a8, 0xfc000000); + else + rtl_eri_clear_bits(tp, 0x1a8, 0xfc000000); + break; + default: + break; + } +}; + static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) { if (reg == 0x1f) { @@ -882,6 +901,9 @@ static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) if (tp->ocp_base != OCP_STD_PHY_BASE) reg -= 0x10; + if (tp->ocp_base == OCP_STD_PHY_BASE && reg == MII_BMCR) + rtl8168g_phy_suspend_quirk(tp, value); + r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); } @@ -2210,20 +2232,8 @@ static void rtl_pll_power_down(struct rtl8169_private *tp) case RTL_GIGA_MAC_VER_25 ... RTL_GIGA_MAC_VER_26: case RTL_GIGA_MAC_VER_32 ... RTL_GIGA_MAC_VER_33: case RTL_GIGA_MAC_VER_37: - case RTL_GIGA_MAC_VER_39: - case RTL_GIGA_MAC_VER_43: - case RTL_GIGA_MAC_VER_44: - case RTL_GIGA_MAC_VER_45: - case RTL_GIGA_MAC_VER_46: - case RTL_GIGA_MAC_VER_47: - case RTL_GIGA_MAC_VER_48: - case RTL_GIGA_MAC_VER_50 ... RTL_GIGA_MAC_VER_63: - RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); - break; - case RTL_GIGA_MAC_VER_40: - case RTL_GIGA_MAC_VER_41: - case RTL_GIGA_MAC_VER_49: - rtl_eri_clear_bits(tp, 0x1a8, 0xfc000000); + case RTL_GIGA_MAC_VER_39 ... RTL_GIGA_MAC_VER_41: + case RTL_GIGA_MAC_VER_43 ... RTL_GIGA_MAC_VER_63: RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); break; default: @@ -2241,19 +2251,9 @@ static void rtl_pll_power_up(struct rtl8169_private *tp) case RTL_GIGA_MAC_VER_43: RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); break; - case RTL_GIGA_MAC_VER_44: - case RTL_GIGA_MAC_VER_45: - case RTL_GIGA_MAC_VER_46: - case RTL_GIGA_MAC_VER_47: - case RTL_GIGA_MAC_VER_48: - case RTL_GIGA_MAC_VER_50 ... RTL_GIGA_MAC_VER_63: - RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); - break; - case RTL_GIGA_MAC_VER_40: - case RTL_GIGA_MAC_VER_41: - case RTL_GIGA_MAC_VER_49: + case RTL_GIGA_MAC_VER_40 ... RTL_GIGA_MAC_VER_41: + case RTL_GIGA_MAC_VER_44 ... RTL_GIGA_MAC_VER_63: RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); - rtl_eri_set_bits(tp, 0x1a8, 0xfc000000); break; default: break;