From patchwork Tue Oct 22 18:31:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Ren X-Patchwork-Id: 1181585 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ba1l/6Dw"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46yMXv2whtz9sPc for ; Wed, 23 Oct 2019 05:31:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732505AbfJVSbk (ORCPT ); Tue, 22 Oct 2019 14:31:40 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34197 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729666AbfJVSbj (ORCPT ); Tue, 22 Oct 2019 14:31:39 -0400 Received: by mail-pl1-f193.google.com with SMTP id k7so8752399pll.1; Tue, 22 Oct 2019 11:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PqWdmEQdcmjmFLWvTGjLwPx6VnrOcgWy0kGCVc8BpHs=; b=Ba1l/6Dw6t1lnoMAIkJiOq+J0wvmYQt3HrbWxfkZZwJqmgte9pw5puY+Tt/hFyYnuO p/RQ20eiVf7492Lv/978INFbuTskGlqwP7+9Lyq5GtztSi6+eC9GIH4a04jB9s8sx7av 7ZLc0U5W7DySJHpAGeycaVi+yHVUTf88KO7+KGWVE6yRb3On9IWmoZK6mw6/QyQHx/6O W5vJppKgGSEbO6Yxq7kENXFnBw+kVNqRqmMUQapgHHd6HRKRuIVV2aTcsoItxhmaiWvJ hLVUw1UTXOXT+z1Kk5qTpqTppFVW91Ks6qqPcLPhCJu76FG50wVK/Rb6wmywAZjDi+z/ C8AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PqWdmEQdcmjmFLWvTGjLwPx6VnrOcgWy0kGCVc8BpHs=; b=mfmkhgyfYylVst/MB1odNcBa+vcPyBI0t6cxS3aZY45sQBhZGvtvvdlj/GpxJRLUH1 I8kCiMCNXPNnJ7Mdmhqrs6gSFjsi3nS59/m5REHEzKmLLg7kqq1vbz6m9UdYyZAYMsOb QqU8JcAP45rCd8OcwgKj9f7cfVdEXVSL1MaLhFFTV5Ftc1UhbppCJiGtVmENJzZoWU+D Cb9mZKqpsNFZVECp/Obe6acmOEUoA9kkfPA0W+feYHUu87Ih/J5qHx8je2XUE+yzTTXs NS7Ltd8i8E+OSOJPA2vuUj9h8TTcmIQ83xXfnAxaFZeFcKs0g1nZDVSiEqomMHFIuAuB Fn8g== X-Gm-Message-State: APjAAAWo1ObRQxcFwWmMHSQY8/s3Y38/2uZWfobJmII1TNhxEHjTeCA6 joBDPtYQ5UBPIEjfdtXCa3Q= X-Google-Smtp-Source: APXvYqx+EjDcV+i7mxpvdqEU3QZ476yYSpRSo4mPRljkGHInUZyuVnDAxjXmAnuvXtfLdgE96vfwlw== X-Received: by 2002:a17:902:9a93:: with SMTP id w19mr5033569plp.316.1571769098674; Tue, 22 Oct 2019 11:31:38 -0700 (PDT) Received: from taoren-ubuntu-R90MNF91.thefacebook.com ([2620:10d:c090:200::2398]) by smtp.gmail.com with ESMTPSA id m19sm16787947pjl.28.2019.10.22.11.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 11:31:38 -0700 (PDT) From: rentao.bupt@gmail.com To: "David S . Miller" , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , Vladimir Oltean , Arun Parameswaran , Justin Chen , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org Cc: Tao Ren Subject: [PATCH net-next v10 1/3] net: phy: modify assignment to OR for dev_flags in phy_attach_direct Date: Tue, 22 Oct 2019 11:31:06 -0700 Message-Id: <20191022183108.14029-2-rentao.bupt@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191022183108.14029-1-rentao.bupt@gmail.com> References: <20191022183108.14029-1-rentao.bupt@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tao Ren Modify the assignment to OR when dealing with phydev->dev_flags in phy_attach_direct function, and this is to make sure dev_flags set in driver's probe callback won't be lost. Suggested-by: Andrew Lunn CC: Heiner Kallweit CC: Vladimir Oltean Signed-off-by: Tao Ren Reviewed-by: Andrew Lunn Reviewed-by: Florian Fainelli --- Changes: - nothing is changed in v1-v9: it's given v10 to align with the version of patch series. drivers/net/phy/phy_device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index adb66a2fae18..f1f60bd4865a 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1270,7 +1270,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, phydev_err(phydev, "error creating 'phy_standalone' sysfs entry\n"); } - phydev->dev_flags = flags; + phydev->dev_flags |= flags; phydev->interface = interface; From patchwork Tue Oct 22 18:31:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tao Ren X-Patchwork-Id: 1181586 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="n6c/fck6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46yMY14nKHz9sPf for ; Wed, 23 Oct 2019 05:31:49 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732552AbfJVSbq (ORCPT ); Tue, 22 Oct 2019 14:31:46 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36547 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729696AbfJVSbp (ORCPT ); Tue, 22 Oct 2019 14:31:45 -0400 Received: by mail-pf1-f194.google.com with SMTP id y22so11176798pfr.3; Tue, 22 Oct 2019 11:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vWaIJ7mJACYuUZWcgVyk29Ot7LMWvhaWUYWmlLLazNY=; b=n6c/fck6D5uQP9IBlnQADwqjS5dd2RiFKiRXiAMBaPQlal3nVeXCqtFQCe/4P7MtLU ZFeHzMYQBAOlUANLzxUgiY9i80u0a3IGdQZDrTzeJlqOsuGFVruTD0dD6y1sZxn7B7vf DvR6/8nmBYhaevIq3T+9aP83u+rB3STDi6eo82CXcA5fm1Cu7Y2fxrMiP6OjD4u1EkjN IKm2sY3PfrfNxjhye953IBkNXBTr3aKB07gCUkGDLbp2gxKUZUm54S+EWMlkNukggfPE v6Wyi+0nheA86bd5TBYwlSigl42G+VVAHOvY1TM6jIL+ybnCQjW1oIdQ7g2w0GlE4QJU t0ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vWaIJ7mJACYuUZWcgVyk29Ot7LMWvhaWUYWmlLLazNY=; b=ho3zW0XNC9cIoJmAikwm4YPwrYiL1QtWhsbIeKe+eAwoR2rbLGI2CWhpF18zS0BVoS CNvN7//zOZtMovi2KIXbku1sAtEZcHXGICNPpiz8gGT52SOHZ4l90D8yMOZd4pmbygSF vgpAu3KeVaXXeohWXbhtlhSQJ0gGUd1ESg/07A5gk5UErI/iGkOexfM8n46h8jBV7dHz TSHp0cABE4QtwwS9S0VsLksiKzD/yzP74i/3pGTNULqt+OTOVcxwFFaeKow1M0vzCEbi u7wfAPApI1Y1LmnHTE3lYIGEqqGMrSLKqBG9eWPYskknzlpy6sdsU/thesCYRkZVvTDT uJsw== X-Gm-Message-State: APjAAAWnuHKcXf1T3/z2JsY7HV9twSquUodgF79FU/poh+MhsZGbH5mR ZIXJibJg8MzUrbyVDzydj3w= X-Google-Smtp-Source: APXvYqze8zh8kfWLbKpniz3dVlUYK19lj6aPZsJq05GqAxGM2KnHA+7uV3v2Y8Bcr+oezkADhBTutQ== X-Received: by 2002:a17:90a:9f8a:: with SMTP id o10mr6355889pjp.91.1571769103665; Tue, 22 Oct 2019 11:31:43 -0700 (PDT) Received: from taoren-ubuntu-R90MNF91.thefacebook.com ([2620:10d:c090:200::2398]) by smtp.gmail.com with ESMTPSA id m19sm16787947pjl.28.2019.10.22.11.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 11:31:43 -0700 (PDT) From: rentao.bupt@gmail.com To: "David S . Miller" , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , Vladimir Oltean , Arun Parameswaran , Justin Chen , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org Cc: Tao Ren Subject: [PATCH net-next v10 2/3] net: phy: add support for clause 37 auto-negotiation Date: Tue, 22 Oct 2019 11:31:07 -0700 Message-Id: <20191022183108.14029-3-rentao.bupt@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191022183108.14029-1-rentao.bupt@gmail.com> References: <20191022183108.14029-1-rentao.bupt@gmail.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Heiner Kallweit This patch adds support for clause 37 1000Base-X auto-negotiation. Signed-off-by: Heiner Kallweit Signed-off-by: Tao Ren Tested-by: René van Dorst Reviewed-by: Andrew Lunn --- No change in v9/v10. Changes in v8: - Rebased the patch on top of net-next HEAD. Changes in v7: - Update "if (AUTONEG_ENABLE != phydev->autoneg)" to "if (phydev->autoneg != AUTONEG_ENABLE)" so checkpatch.pl is happy. Changes in v6: - add "Signed-off-by: Tao Ren " Changes in v1-v5: - nothing changed. It's given v5 just to align with the version of patch series. drivers/net/phy/phy_device.c | 139 +++++++++++++++++++++++++++++++++++ include/linux/phy.h | 4 + 2 files changed, 143 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index f1f60bd4865a..fa71998fea51 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1607,6 +1607,40 @@ static int genphy_config_advert(struct phy_device *phydev) return changed; } +/** + * genphy_c37_config_advert - sanitize and advertise auto-negotiation parameters + * @phydev: target phy_device struct + * + * Description: Writes MII_ADVERTISE with the appropriate values, + * after sanitizing the values to make sure we only advertise + * what is supported. Returns < 0 on error, 0 if the PHY's advertisement + * hasn't changed, and > 0 if it has changed. This function is intended + * for Clause 37 1000Base-X mode. + */ +static int genphy_c37_config_advert(struct phy_device *phydev) +{ + u16 adv = 0; + + /* Only allow advertising what this PHY supports */ + linkmode_and(phydev->advertising, phydev->advertising, + phydev->supported); + + if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, + phydev->advertising)) + adv |= ADVERTISE_1000XFULL; + if (linkmode_test_bit(ETHTOOL_LINK_MODE_Pause_BIT, + phydev->advertising)) + adv |= ADVERTISE_1000XPAUSE; + if (linkmode_test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, + phydev->advertising)) + adv |= ADVERTISE_1000XPSE_ASYM; + + return phy_modify_changed(phydev, MII_ADVERTISE, + ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE | + ADVERTISE_1000XHALF | ADVERTISE_1000XPSE_ASYM, + adv); +} + /** * genphy_config_eee_advert - disable unwanted eee mode advertisement * @phydev: target phy_device struct @@ -1715,6 +1749,54 @@ int __genphy_config_aneg(struct phy_device *phydev, bool changed) } EXPORT_SYMBOL(__genphy_config_aneg); +/** + * genphy_c37_config_aneg - restart auto-negotiation or write BMCR + * @phydev: target phy_device struct + * + * Description: If auto-negotiation is enabled, we configure the + * advertising, and then restart auto-negotiation. If it is not + * enabled, then we write the BMCR. This function is intended + * for use with Clause 37 1000Base-X mode. + */ +int genphy_c37_config_aneg(struct phy_device *phydev) +{ + int err, changed; + + if (phydev->autoneg != AUTONEG_ENABLE) + return genphy_setup_forced(phydev); + + err = phy_modify(phydev, MII_BMCR, BMCR_SPEED1000 | BMCR_SPEED100, + BMCR_SPEED1000); + if (err) + return err; + + changed = genphy_c37_config_advert(phydev); + if (changed < 0) /* error */ + return changed; + + if (!changed) { + /* Advertisement hasn't changed, but maybe aneg was never on to + * begin with? Or maybe phy was isolated? + */ + int ctl = phy_read(phydev, MII_BMCR); + + if (ctl < 0) + return ctl; + + if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE)) + changed = 1; /* do restart aneg */ + } + + /* Only restart aneg if we are advertising something different + * than we were before. + */ + if (changed > 0) + return genphy_restart_aneg(phydev); + + return 0; +} +EXPORT_SYMBOL(genphy_c37_config_aneg); + /** * genphy_aneg_done - return auto-negotiation status * @phydev: target phy_device struct @@ -1886,6 +1968,63 @@ int genphy_read_status(struct phy_device *phydev) } EXPORT_SYMBOL(genphy_read_status); +/** + * genphy_c37_read_status - check the link status and update current link state + * @phydev: target phy_device struct + * + * Description: Check the link, then figure out the current state + * by comparing what we advertise with what the link partner + * advertises. This function is for Clause 37 1000Base-X mode. + */ +int genphy_c37_read_status(struct phy_device *phydev) +{ + int lpa, err, old_link = phydev->link; + + /* Update the link, but return if there was an error */ + err = genphy_update_link(phydev); + if (err) + return err; + + /* why bother the PHY if nothing can have changed */ + if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) + return 0; + + phydev->duplex = DUPLEX_UNKNOWN; + phydev->pause = 0; + phydev->asym_pause = 0; + + if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { + lpa = phy_read(phydev, MII_LPA); + if (lpa < 0) + return lpa; + + linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, + phydev->lp_advertising, lpa & LPA_LPACK); + linkmode_mod_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, + phydev->lp_advertising, lpa & LPA_1000XFULL); + linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, + phydev->lp_advertising, lpa & LPA_1000XPAUSE); + linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, + phydev->lp_advertising, + lpa & LPA_1000XPAUSE_ASYM); + + phy_resolve_aneg_linkmode(phydev); + } else if (phydev->autoneg == AUTONEG_DISABLE) { + int bmcr = phy_read(phydev, MII_BMCR); + + if (bmcr < 0) + return bmcr; + + if (bmcr & BMCR_FULLDPLX) + phydev->duplex = DUPLEX_FULL; + else + phydev->duplex = DUPLEX_HALF; + } + + return 0; +} +EXPORT_SYMBOL(genphy_c37_read_status); + /** * genphy_soft_reset - software reset the PHY via BMCR_RESET bit * @phydev: target phy_device struct diff --git a/include/linux/phy.h b/include/linux/phy.h index 9a0e981df502..78436d58ce7c 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1106,6 +1106,10 @@ int genphy_read_mmd_unsupported(struct phy_device *phdev, int devad, int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum, u16 regnum, u16 val); +/* Clause 37 */ +int genphy_c37_config_aneg(struct phy_device *phydev); +int genphy_c37_read_status(struct phy_device *phydev); + /* Clause 45 PHY */ int genphy_c45_restart_aneg(struct phy_device *phydev); int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart); From patchwork Tue Oct 22 18:31:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tao Ren X-Patchwork-Id: 1181587 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gXKklKpH"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46yMY807KDz9sPj for ; Wed, 23 Oct 2019 05:31:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732629AbfJVSbu (ORCPT ); Tue, 22 Oct 2019 14:31:50 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:32952 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729696AbfJVSbt (ORCPT ); Tue, 22 Oct 2019 14:31:49 -0400 Received: by mail-pf1-f194.google.com with SMTP id c184so1651227pfb.0; Tue, 22 Oct 2019 11:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gq0C8TRzKJcucJI81WWH6nhSTS0UHGvhSIPibYL1P8M=; b=gXKklKpHfMMjD1q19dng7Ut1n/RrMM0Run8pcJG/MzUFJdTZLZ3STV8JpGKX3B+sGb 9N8T/7SsLZEQJVjrb+Lw7TPVhXt43Ide0/mZkByYUpTm++TexXBgj20gShXWytVWxqU/ bmpogeYIuqoi9jXnlfxdU9wlMs3WQ035hdluf75ZmeDm9fOJR7sIuCecMYt5v+un5FVm m5LVMZCd8XXYRIwyJALjfLhBIiLBteNxjrb/YpexVbVeyU/yqtyr1ruC8qJPMCOGlvOW xrXKeX7Rmua/Wa51sXhV2bj+FcQdOyfikAHtScbQy+FF3ogwd+genf348F5grF9ziTot BCCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gq0C8TRzKJcucJI81WWH6nhSTS0UHGvhSIPibYL1P8M=; b=Nd+H4LI6lYwdXj95zcvb+6qmoIIuO8idN+qbW3BRy13rGWItkfkkW02qFg5P+e/qDQ ElIb/99mXJhuuxBdiBB4vDBk8Kgv2ofLj7uQgtqK+5pyPmn/mZsKJW3rirjiJDBkbX4I vkl7CUQskxYsDz5k7hSz1bKjTsIOf1Jv5Y8ivtLPH1gxZj01OKCMaSfpXd0prXIFKFsO dr10M1fOcqgFY2yKkWxYZ597qWMqI1zZRX+6o/vkkHWDCfaEUy+9p8N0BUNbj8r3DU+v gIxM9U6XMvfeW7LpZO8YkFP59quqRhY3qGaBHDAQOVO5IDuccILQo9Zo94BexAuyN/81 7SvQ== X-Gm-Message-State: APjAAAVKv0aFuyBK2cEjkCvURdgcORdeiRxp1mvAhwD+bvJfnnokI/ZX c+3G21q88GiHRk771m/kguE= X-Google-Smtp-Source: APXvYqzvfJPyFJScJCflmvcyrpvAsGefMEB8NEz+27rayAOIbSazC/fsgICpBfsFwnHSv0ORPPHsiA== X-Received: by 2002:a63:cb0f:: with SMTP id p15mr5227906pgg.81.1571769107124; Tue, 22 Oct 2019 11:31:47 -0700 (PDT) Received: from taoren-ubuntu-R90MNF91.thefacebook.com ([2620:10d:c090:200::2398]) by smtp.gmail.com with ESMTPSA id m19sm16787947pjl.28.2019.10.22.11.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 11:31:46 -0700 (PDT) From: rentao.bupt@gmail.com To: "David S . Miller" , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , Vladimir Oltean , Arun Parameswaran , Justin Chen , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org Cc: Tao Ren Subject: [PATCH net-next v10 3/3] net: phy: broadcom: add 1000Base-X support for BCM54616S Date: Tue, 22 Oct 2019 11:31:08 -0700 Message-Id: <20191022183108.14029-4-rentao.bupt@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191022183108.14029-1-rentao.bupt@gmail.com> References: <20191022183108.14029-1-rentao.bupt@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tao Ren The BCM54616S PHY cannot work properly in RGMII->1000Base-X mode, mainly because genphy functions are designed for copper links, and 1000Base-X (clause 37) auto negotiation needs to be handled differently. This patch enables 1000Base-X support for BCM54616S by customizing 3 driver callbacks, and it's verified to be working on Facebook CMM BMC platform (RGMII->1000Base-KX): - probe: probe callback detects PHY's operation mode based on INTERF_SEL[1:0] pins and 1000X/100FX selection bit in SerDES 100-FX Control register. - config_aneg: calls genphy_c37_config_aneg when the PHY is running in 1000Base-X mode; otherwise, genphy_config_aneg will be called. - read_status: calls genphy_c37_read_status when the PHY is running in 1000Base-X mode; otherwise, genphy_read_status will be called. Note: BCM54616S PHY can also be configured in RGMII->100Base-FX mode, and 100Base-FX support is not available as of now. Signed-off-by: Tao Ren Acked-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- No changes in v8/v9/v10. Changes in v7: - Add comment "BCM54616S 100Base-FX is not supported". Changes in v6: - nothing changed. Changes in v5: - include Heiner's patch "net: phy: add support for clause 37 auto-negotiation" into the series. - use genphy_c37_config_aneg and genphy_c37_read_status in BCM54616S PHY driver's callback when the PHY is running in 1000Base-X mode. Changes in v4: - add bcm54616s_config_aneg_1000bx() to deal with auto negotiation in 1000Base-X mode. Changes in v3: - rename bcm5482_read_status to bcm54xx_read_status so the callback can be shared by BCM5482 and BCM54616S. Changes in v2: - Auto-detect PHY operation mode instead of passing DT node. - move PHY mode auto-detect logic from config_init to probe callback. - only set speed (not including duplex) in read_status callback. - update patch description with more background to avoid confusion. - patch #1 in the series ("net: phy: broadcom: set features explicitly for BCM54616") is dropped. drivers/net/phy/broadcom.c | 57 +++++++++++++++++++++++++++++++++++--- include/linux/brcmphy.h | 10 +++++-- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c index 4313c74b4fd8..7d68b28bb893 100644 --- a/drivers/net/phy/broadcom.c +++ b/drivers/net/phy/broadcom.c @@ -359,9 +359,9 @@ static int bcm5482_config_init(struct phy_device *phydev) /* * Select 1000BASE-X register set (primary SerDes) */ - reg = bcm_phy_read_shadow(phydev, BCM5482_SHD_MODE); - bcm_phy_write_shadow(phydev, BCM5482_SHD_MODE, - reg | BCM5482_SHD_MODE_1000BX); + reg = bcm_phy_read_shadow(phydev, BCM54XX_SHD_MODE); + bcm_phy_write_shadow(phydev, BCM54XX_SHD_MODE, + reg | BCM54XX_SHD_MODE_1000BX); /* * LED1=ACTIVITYLED, LED3=LINKSPD[2] @@ -427,12 +427,47 @@ static int bcm5481_config_aneg(struct phy_device *phydev) return ret; } +static int bcm54616s_probe(struct phy_device *phydev) +{ + int val, intf_sel; + + val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_MODE); + if (val < 0) + return val; + + /* The PHY is strapped in RGMII-fiber mode when INTERF_SEL[1:0] + * is 01b, and the link between PHY and its link partner can be + * either 1000Base-X or 100Base-FX. + * RGMII-1000Base-X is properly supported, but RGMII-100Base-FX + * support is still missing as of now. + */ + intf_sel = (val & BCM54XX_SHD_INTF_SEL_MASK) >> 1; + if (intf_sel == 1) { + val = bcm_phy_read_shadow(phydev, BCM54616S_SHD_100FX_CTRL); + if (val < 0) + return val; + + /* Bit 0 of the SerDes 100-FX Control register, when set + * to 1, sets the MII/RGMII -> 100BASE-FX configuration. + * When this bit is set to 0, it sets the GMII/RGMII -> + * 1000BASE-X configuration. + */ + if (!(val & BCM54616S_100FX_MODE)) + phydev->dev_flags |= PHY_BCM_FLAGS_MODE_1000BX; + } + + return 0; +} + static int bcm54616s_config_aneg(struct phy_device *phydev) { int ret; /* Aneg firsly. */ - ret = genphy_config_aneg(phydev); + if (phydev->dev_flags & PHY_BCM_FLAGS_MODE_1000BX) + ret = genphy_c37_config_aneg(phydev); + else + ret = genphy_config_aneg(phydev); /* Then we can set up the delay. */ bcm54xx_config_clock_delay(phydev); @@ -440,6 +475,18 @@ static int bcm54616s_config_aneg(struct phy_device *phydev) return ret; } +static int bcm54616s_read_status(struct phy_device *phydev) +{ + int err; + + if (phydev->dev_flags & PHY_BCM_FLAGS_MODE_1000BX) + err = genphy_c37_read_status(phydev); + else + err = genphy_read_status(phydev); + + return err; +} + static int brcm_phy_setbits(struct phy_device *phydev, int reg, int set) { int val; @@ -631,6 +678,8 @@ static struct phy_driver broadcom_drivers[] = { .config_aneg = bcm54616s_config_aneg, .ack_interrupt = bcm_phy_ack_intr, .config_intr = bcm_phy_config_intr, + .read_status = bcm54616s_read_status, + .probe = bcm54616s_probe, }, { .phy_id = PHY_ID_BCM5464, .phy_id_mask = 0xfffffff0, diff --git a/include/linux/brcmphy.h b/include/linux/brcmphy.h index 6db2d9a6e503..b475e7f20d28 100644 --- a/include/linux/brcmphy.h +++ b/include/linux/brcmphy.h @@ -200,9 +200,15 @@ #define BCM5482_SHD_SSD 0x14 /* 10100: Secondary SerDes control */ #define BCM5482_SHD_SSD_LEDM 0x0008 /* SSD LED Mode enable */ #define BCM5482_SHD_SSD_EN 0x0001 /* SSD enable */ -#define BCM5482_SHD_MODE 0x1f /* 11111: Mode Control Register */ -#define BCM5482_SHD_MODE_1000BX 0x0001 /* Enable 1000BASE-X registers */ +/* 10011: SerDes 100-FX Control Register */ +#define BCM54616S_SHD_100FX_CTRL 0x13 +#define BCM54616S_100FX_MODE BIT(0) /* 100-FX SerDes Enable */ + +/* 11111: Mode Control Register */ +#define BCM54XX_SHD_MODE 0x1f +#define BCM54XX_SHD_INTF_SEL_MASK GENMASK(2, 1) /* INTERF_SEL[1:0] */ +#define BCM54XX_SHD_MODE_1000BX BIT(0) /* Enable 1000-X registers */ /* * EXPANSION SHADOW ACCESS REGISTERS. (PHY REG 0x15, 0x16, and 0x17)