Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3685646pxb; Mon, 24 Jan 2022 15:19:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzw42gYLe9sBIQa+rzLjufRW63JWTmFKZWkRUjp+GoWkMJ0OMuuUJa0Dp1EPhoPHQIzJ6Hh X-Received: by 2002:a17:90b:3b47:: with SMTP id ot7mr601208pjb.143.1643066370784; Mon, 24 Jan 2022 15:19:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643066370; cv=none; d=google.com; s=arc-20160816; b=xBzfd84bPeOXgyOaTOfGxpJtXnK3BHNQYRaqtC/XuW7gJmlK76RnCid6OJClsZmlxd LP3MUckW4LR6bK1zaWZy60KirtZwNRiICcbjpHSgWonq2n6qCjG4gV2wDoQi7DXnw3Ey Z0MzH1rRT/hUbNnliUKYpBSQHYVmT2VQU9gfiCo4to8rc5iCWfp4Ww0Y2wSvuKSWp7/N vclsAIcpMwD8Ax6epQSExAlp3FPdOnRsxR6MAsnkQvCgJcPWci1RODsV1HtfO/DMWiMO /yUYnJPzgTBu7JHhXTLihw9mRJd8/UResLiOLz7pSKTJpFS+uQqv5OQrnNvw0UPNaMmG hfQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZVAkDwKYoPfKE+9DlJsU4ktGuEP1PXJNmyoQEpvgN4A=; b=Il8yJ2j7oJQ0LMNX2bLDQKArDd5stI7NrL+ruTMIvU39Rp9aQUTh0mRdqAyonQ2gdY l2TKZC/DXbna09f778mgbeswlOpGJ/ZzKDzGmt9moW6++uopcngfEjG/cMZxa5Lu+S4i rDoZcbJqE2fOexF/7N1cp1l/NT6jN1Opwy5QIchOsIJB0a4Iwf8l+pkw3ZlrpuUdrLw/ LI2IXHWorfSOYqg9aILQPPRZSNNMoNiEbQQRyKNUkjJJPKFhdBrzFcUeilqTgOUmQ/Rx vpWtrPHZHbov9ALBulp7kbLkccj4GVDbMxLJw5oCjYkRXf5jwQpWyjMROE1yaq8Zi+SS eeuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="JdB7B/TP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z3si577721pjn.35.2022.01.24.15.19.19; Mon, 24 Jan 2022 15:19:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="JdB7B/TP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1847019AbiAXXSP (ORCPT + 99 others); Mon, 24 Jan 2022 18:18:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1585997AbiAXWZb (ORCPT ); Mon, 24 Jan 2022 17:25:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABF36C08C5D8; Mon, 24 Jan 2022 12:54:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 49ACD611C2; Mon, 24 Jan 2022 20:54:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C2C5C340E5; Mon, 24 Jan 2022 20:54:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643057653; bh=pOMuClDdtMKtaAUzzkfbJsxX0oBaFCtga5RqV+vM42Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JdB7B/TPgQQDKVc1Fb521n139HvNNlilCJFfCPbB8jLRK3drjTdmJJC0JqH755z3O wUIEjWfO5ATOiIOJiOK19agwCNo8MVX+XeQJHY96Hxd6DxHyyg0vVavRnlLpp1ECG6 b/UfAHzl/UyBcpkiv4rishA9vWgx39CcheKnZi4c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mohammad Athari Bin Ismail , "David S. Miller" Subject: [PATCH 5.16 0035/1039] net: phy: marvell: add Marvell specific PHY loopback Date: Mon, 24 Jan 2022 19:30:24 +0100 Message-Id: <20220124184126.314205688@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mohammad Athari Bin Ismail commit 020a45aff1190c32b1087cd75b57fbf6bff46ea6 upstream. Existing genphy_loopback() is not applicable for Marvell PHY. Besides configuring bit-6 and bit-13 in Page 0 Register 0 (Copper Control Register), it is also required to configure same bits in Page 2 Register 21 (MAC Specific Control Register 2) according to speed of the loopback is operating. Tested working on Marvell88E1510 PHY for all speeds (1000/100/10Mbps). FIXME: Based on trial and error test, it seem 1G need to have delay between soft reset and loopback enablement. Fixes: 014068dcb5b1 ("net: phy: genphy_loopback: add link speed configuration") Cc: # 5.15.x Signed-off-by: Mohammad Athari Bin Ismail Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/marvell.c | 56 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -189,6 +189,8 @@ #define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII 0x4 #define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */ +#define MII_88E1510_MSCR_2 0x15 + #define MII_VCT5_TX_RX_MDI0_COUPLING 0x10 #define MII_VCT5_TX_RX_MDI1_COUPLING 0x11 #define MII_VCT5_TX_RX_MDI2_COUPLING 0x12 @@ -1932,6 +1934,58 @@ static void marvell_get_stats(struct phy data[i] = marvell_get_stat(phydev, i); } +static int m88e1510_loopback(struct phy_device *phydev, bool enable) +{ + int err; + + if (enable) { + u16 bmcr_ctl = 0, mscr2_ctl = 0; + + if (phydev->speed == SPEED_1000) + bmcr_ctl = BMCR_SPEED1000; + else if (phydev->speed == SPEED_100) + bmcr_ctl = BMCR_SPEED100; + + if (phydev->duplex == DUPLEX_FULL) + bmcr_ctl |= BMCR_FULLDPLX; + + err = phy_write(phydev, MII_BMCR, bmcr_ctl); + if (err < 0) + return err; + + if (phydev->speed == SPEED_1000) + mscr2_ctl = BMCR_SPEED1000; + else if (phydev->speed == SPEED_100) + mscr2_ctl = BMCR_SPEED100; + + err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE, + MII_88E1510_MSCR_2, BMCR_SPEED1000 | + BMCR_SPEED100, mscr2_ctl); + if (err < 0) + return err; + + /* Need soft reset to have speed configuration takes effect */ + err = genphy_soft_reset(phydev); + if (err < 0) + return err; + + /* FIXME: Based on trial and error test, it seem 1G need to have + * delay between soft reset and loopback enablement. + */ + if (phydev->speed == SPEED_1000) + msleep(1000); + + return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, + BMCR_LOOPBACK); + } else { + err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 0); + if (err < 0) + return err; + + return phy_config_aneg(phydev); + } +} + static int marvell_vct5_wait_complete(struct phy_device *phydev) { int i; @@ -3078,7 +3132,7 @@ static struct phy_driver marvell_drivers .get_sset_count = marvell_get_sset_count, .get_strings = marvell_get_strings, .get_stats = marvell_get_stats, - .set_loopback = genphy_loopback, + .set_loopback = m88e1510_loopback, .get_tunable = m88e1011_get_tunable, .set_tunable = m88e1011_set_tunable, .cable_test_start = marvell_vct7_cable_test_start,