From patchwork Wed Aug 18 12:27:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 500280 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT 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 D1A5DC4338F for ; Wed, 18 Aug 2021 12:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4FBE61029 for ; Wed, 18 Aug 2021 12:29:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235627AbhHRMa0 (ORCPT ); Wed, 18 Aug 2021 08:30:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236690AbhHRMaV (ORCPT ); Wed, 18 Aug 2021 08:30:21 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3EBBC0613A3 for ; Wed, 18 Aug 2021 05:29:43 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id u16so3259879wrn.5 for ; Wed, 18 Aug 2021 05:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=engleder-embedded-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M5wvJU9nS0PBB383gj3PbquvMXX21vpI+F/H85bw73U=; b=x2aEwTrMuhsjoEDCymOGwiImM5i8Ny+fc9dfU/2HMZCqSTPjd8svCc0dXh1FYreWEf ywRk7OWnUIHaw5+YnzsPMT/pqjyKEWORBvX60vm+jT/aTjjOO4g4S116D89ZTaB04l+p 46+PAkAfe0mayC9N9F0vVoX9NGEcPVlCzUio2YSCaYqQshHQ65q0qSnamhZqk394j2AZ SnsZragb7q9zK0yuzc/hv/ZvMfNHB1NTgwb5VAU4mg9AfsyvBqRdaeINLpXm/iduZhDK QjAxyf/ZtmTBUm2+32+HFmYIKOq1UtRriT9EurJ/Yk0wyCIt8aS5+iqroQSbPZmAyKyA 1eNQ== 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=M5wvJU9nS0PBB383gj3PbquvMXX21vpI+F/H85bw73U=; b=pbN18radS5gXsJFGacS+TUHezGCFJyHlpVQHPbvZbQfzTM/A/gmhG9myhz+B5iKnpc 2GKPknxxZUB+h1GLKZYQKtO06Mh9OL69dMzPKOyH6ZNNjHP8NhSJBrtwA+1WZ48zP/3r otLeiG2lQmaKCCigmwcv2rp4f9o30xnSuDVAHOPHcBv0brYwSgJfIRcXQ77G4xux6P7A 2pkHxYK4cTJRQ4i9/PUoURbWXWRqawdkeOJvN086bXvKySYmAo1M+KZcXT4J3bnDXIDS ymTmMfjKrz6Tf7PH22PHsy305jQHY9PM7yI1tB6W5/fr1gkod3cQtAsAGUmG9vtb2hvn YVcg== X-Gm-Message-State: AOAM530THvvDfr+9+Jz9d8QkuUXiWpZwha46sCKvHckD+ob+wJj/h0Ye nvHxIN6vU8ZvAGzH6zytSBW2NQ== X-Google-Smtp-Source: ABdhPJwx3R40DJstcMGFSXmn7/8lPUj4y/dpGByViPuuXdJRuRP+qdKmFNqCmk8xzMXi8h0OpWOsYw== X-Received: by 2002:adf:f741:: with SMTP id z1mr10236267wrp.201.1629289782643; Wed, 18 Aug 2021 05:29:42 -0700 (PDT) Received: from hornet.engleder.at (dynamic-2el0lv6sxxeorz8a81-pd01.res.v6.highway.a1.net. [2001:871:23a:b9:6e3b:e5ff:fe2c:34c1]) by smtp.gmail.com with ESMTPSA id u16sm5554869wmc.41.2021.08.18.05.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 05:29:42 -0700 (PDT) From: Gerhard Engleder To: andrew@lunn.ch Cc: netdev@vger.kernel.org, Gerhard Engleder Subject: [PATCH net-next 1/2] net: phy: Support set_loopback override Date: Wed, 18 Aug 2021 14:27:35 +0200 Message-Id: <20210818122736.4877-2-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210818122736.4877-1-gerhard@engleder-embedded.com> References: <20210818122736.4877-1-gerhard@engleder-embedded.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org phy_read_status and various other PHY functions support PHY specific overriding of driver functions by using a PHY specific pointer to the PHY driver. Add support of PHY specific override to phy_loopback too. Signed-off-by: Gerhard Engleder --- drivers/net/phy/phy_device.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 107aa6d7bc6b..ba5ad86ec826 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1821,11 +1821,10 @@ EXPORT_SYMBOL(phy_resume); int phy_loopback(struct phy_device *phydev, bool enable) { - struct phy_driver *phydrv = to_phy_driver(phydev->mdio.dev.driver); int ret = 0; - if (!phydrv) - return -ENODEV; + if (!phydev->drv) + return -EIO; mutex_lock(&phydev->lock); @@ -1839,8 +1838,8 @@ int phy_loopback(struct phy_device *phydev, bool enable) goto out; } - if (phydrv->set_loopback) - ret = phydrv->set_loopback(phydev, enable); + if (phydev->drv->set_loopback) + ret = phydev->drv->set_loopback(phydev, enable); else ret = genphy_loopback(phydev, enable); From patchwork Wed Aug 18 12:27:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 499547 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.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT 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 1FD18C432BE for ; Wed, 18 Aug 2021 12:29:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 043E061029 for ; Wed, 18 Aug 2021 12:29:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236767AbhHRMa2 (ORCPT ); Wed, 18 Aug 2021 08:30:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236732AbhHRMaW (ORCPT ); Wed, 18 Aug 2021 08:30:22 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54734C0613A4 for ; Wed, 18 Aug 2021 05:29:47 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id q6so3256663wrv.6 for ; Wed, 18 Aug 2021 05:29:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=engleder-embedded-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=41vzQz17yY023l5WeMyfnRBC0yKCfFsWSJLJ4kmuWB0=; b=s5SBUVqh/uAwzJzYu2B+6dPatfUFRtDv3zRhWwNrPRYlxqD3DQ+isw2GBFXfhtzc1b K+VCxlWSha/+1CHlQR0WclWl8zGOv0dmMtbvUaGI30HmQZfZjSdvYiAAFBJMmqOBQqsN qzEhiUjgaQeha+WDZuqjNy98UtS13KtRsNUrXy4BJvut/MAbBoA5lEEfT/HY/uEW2S+V S60q6zmnHq/7cRec2F9uk617Qt5DJwxuNh6+iwwighG58JgLHlctDRxXJ25bwmipggKL HnZwKc70E5pjAU0e3G1aONSPm6S+74m/yuTfHN4aFkVtG6SgBQNAJcPT6hvmiWku1uw+ rxHg== 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=41vzQz17yY023l5WeMyfnRBC0yKCfFsWSJLJ4kmuWB0=; b=pDW9Hizg9PFvuIFc5777U9yWFvM/4QYYO1CI1p8C3Qz9JsI3Z62Nw/9KYMtSGUdsWs jJxEBoJmE6LDxMbIIcSgkmLyjKXPWl7bpkw9+Nl+zQFJMKEogkwZOQ7BgU+T0VUoPQ+5 JVPmg5Xq2XN6Mof7P+Qc3/yRqFDMxsSnUQMIaGenoimLePfsRuwOZe6NLKw9mM4G302z 2yw7KkPhS4pzE2vn/rODEWm6YI6lBUoHlYoWZZ/27gfSjqxVq9lUeXgUq1wZVDBvC5MF td7UqcYmcsg17YevtHAWzIBUcdgfsvdjlD4A99oPiSgG3ZIPfkztT4o5T2lpv/V7Zqsh gS/Q== X-Gm-Message-State: AOAM530CLtGUAasl95MxBEFRqFjPmy5x1WnqDBDL+HPL8623BHmny+xy ONDBEC9KGH5htK4z2q0t2OSKQA== X-Google-Smtp-Source: ABdhPJzNpUqiYkdXgLZsBcbRHUna1WJozPTEv1vNoz2fGDtHSZCDot/kqH7XAovpj/fLeBbCNXFJHQ== X-Received: by 2002:a5d:6349:: with SMTP id b9mr10263347wrw.341.1629289785972; Wed, 18 Aug 2021 05:29:45 -0700 (PDT) Received: from hornet.engleder.at (dynamic-2el0lv6sxxeorz8a81-pd01.res.v6.highway.a1.net. [2001:871:23a:b9:6e3b:e5ff:fe2c:34c1]) by smtp.gmail.com with ESMTPSA id u16sm5554869wmc.41.2021.08.18.05.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 05:29:45 -0700 (PDT) From: Gerhard Engleder To: andrew@lunn.ch Cc: netdev@vger.kernel.org, Gerhard Engleder Subject: [PATCH net-next 2/2] net: phy: gmii2rgmii: Support PHY loopback Date: Wed, 18 Aug 2021 14:27:36 +0200 Message-Id: <20210818122736.4877-3-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210818122736.4877-1-gerhard@engleder-embedded.com> References: <20210818122736.4877-1-gerhard@engleder-embedded.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Configure speed if loopback is used. read_status is not called for loopback. Signed-off-by: Gerhard Engleder --- drivers/net/phy/xilinx_gmii2rgmii.c | 46 ++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 151c2a3f0b3a..8dcb49ed1f3d 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -27,12 +27,28 @@ struct gmii2rgmii { struct mdio_device *mdio; }; -static int xgmiitorgmii_read_status(struct phy_device *phydev) +static void xgmiitorgmii_configure(struct gmii2rgmii *priv, int speed) { - struct gmii2rgmii *priv = mdiodev_get_drvdata(&phydev->mdio); struct mii_bus *bus = priv->mdio->bus; int addr = priv->mdio->addr; - u16 val = 0; + u16 val; + + val = mdiobus_read(bus, addr, XILINX_GMII2RGMII_REG); + val &= ~XILINX_GMII2RGMII_SPEED_MASK; + + if (speed == SPEED_1000) + val |= BMCR_SPEED1000; + else if (speed == SPEED_100) + val |= BMCR_SPEED100; + else + val |= BMCR_SPEED10; + + mdiobus_write(bus, addr, XILINX_GMII2RGMII_REG, val); +} + +static int xgmiitorgmii_read_status(struct phy_device *phydev) +{ + struct gmii2rgmii *priv = mdiodev_get_drvdata(&phydev->mdio); int err; if (priv->phy_drv->read_status) @@ -42,17 +58,24 @@ static int xgmiitorgmii_read_status(struct phy_device *phydev) if (err < 0) return err; - val = mdiobus_read(bus, addr, XILINX_GMII2RGMII_REG); - val &= ~XILINX_GMII2RGMII_SPEED_MASK; + xgmiitorgmii_configure(priv, phydev->speed); - if (phydev->speed == SPEED_1000) - val |= BMCR_SPEED1000; - else if (phydev->speed == SPEED_100) - val |= BMCR_SPEED100; + return 0; +} + +static int xgmiitorgmii_set_loopback(struct phy_device *phydev, bool enable) +{ + struct gmii2rgmii *priv = mdiodev_get_drvdata(&phydev->mdio); + int err; + + if (priv->phy_drv->set_loopback) + err = priv->phy_drv->set_loopback(phydev, enable); else - val |= BMCR_SPEED10; + err = genphy_loopback(phydev, enable); + if (err < 0) + return err; - mdiobus_write(bus, addr, XILINX_GMII2RGMII_REG, val); + xgmiitorgmii_configure(priv, phydev->speed); return 0; } @@ -90,6 +113,7 @@ static int xgmiitorgmii_probe(struct mdio_device *mdiodev) memcpy(&priv->conv_phy_drv, priv->phy_dev->drv, sizeof(struct phy_driver)); priv->conv_phy_drv.read_status = xgmiitorgmii_read_status; + priv->conv_phy_drv.set_loopback = xgmiitorgmii_set_loopback; mdiodev_set_drvdata(&priv->phy_dev->mdio, priv); priv->phy_dev->drv = &priv->conv_phy_drv;