From patchwork Tue Mar 30 13:54:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 12172641 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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,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 6210AC433E0 for ; Tue, 30 Mar 2021 13:58:01 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2900619BD for ; Tue, 30 Mar 2021 13:58:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2900619BD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ko/7WOODu3L9yMbXigeB01O0gjk3OItCAjM77NTGDP0=; b=M9ioRqRJpxgg5j+ALWf8k79yy 8GLmv+TtqCKQdOzTCJyS+BawypFHv0ikcg14IYqnQwNlLypPExnG/h1DEvA2SJgbN1uOQ8W3ws7vh uJlV6/ogU0CYvKQuGFz8mt4OYCkjGAqcISXc1b6e7Zttic3DqC4kt7ZxP/pe6EF+S2U6dqItcgykj z/d5gr8QElxyuwtAoR314Ho8/R2xa/ZR5032zg9WkNxKPtYJI07n/9KgFxEhesdjPkjyekurerdKg j+0vLDY5sPMpv5lduEgAy5vJ+ad7KAGthbE0xWMrJrlCoPGd3K5W/OSIP116iqoZ/2uNTLjBSLH++ jQJ/Db9pw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lREr6-003tD4-Qb; Tue, 30 Mar 2021 13:56:28 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lREp1-003sme-0u for linux-arm-kernel@lists.infradead.org; Tue, 30 Mar 2021 13:56:20 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lREos-0006Q2-3h; Tue, 30 Mar 2021 15:54:10 +0200 Received: from ore by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lREoq-0004RS-Nl; Tue, 30 Mar 2021 15:54:08 +0200 From: Oleksij Rempel To: Shawn Guo , Sascha Hauer , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Fugang Duan Cc: Oleksij Rempel , kernel@pengutronix.de, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com, Fabio Estevam , David Jander , Russell King , Philippe Schenker Subject: [PATCH net-next v1 1/3] net: phy: micrel: KSZ8081: add loopback support Date: Tue, 30 Mar 2021 15:54:05 +0200 Message-Id: <20210330135407.17010-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210330135407.17010-1-o.rempel@pengutronix.de> References: <20210330135407.17010-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210330_145619_316168_2B3A2316 X-CRM114-Status: GOOD ( 11.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org PHY loopback is needed for the ethernet controller self test support. This PHY was tested with the FEC sefltest. Signed-off-by: Oleksij Rempel Reviewed-by: Andrew Lunn --- drivers/net/phy/micrel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index a14a00328fa3..f05345f1c602 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -1311,6 +1311,7 @@ static struct phy_driver ksphy_driver[] = { .get_stats = kszphy_get_stats, .suspend = kszphy_suspend, .resume = kszphy_resume, + .set_loopback = genphy_loopback, }, { .phy_id = PHY_ID_KSZ8061, .name = "Micrel KSZ8061", From patchwork Tue Mar 30 13:54:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 12172637 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,DKIMWL_WL_HIGH, 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 11984C433C1 for ; Tue, 30 Mar 2021 13:57:38 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 89397619BD for ; Tue, 30 Mar 2021 13:57:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 89397619BD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=seQMFYKE0ZeWpQsYzBw6qzExjuBVowgLpui/F0isA50=; b=MY8TYuefNZTlcca7Lqjrtb8ay 6Z4s6Pn2U89yn5ABTj8qwsBufQcuQhjKZL3TCyE4DwvuYmmILM/kyM0+3EtjRAI33ZXkZq+0s26RE RsWMwoZCQOrTl8DIsEGtB6DbBQ2281SAMQeDtunOrnDfEfVNWtPadRP+9V0V5Gh8DUgg9sD/FABi7 vK9Qbz64kfmpX0AEcDPE5j9Ln8zME2erJMrK2c8W1ITmC/QofOZoINUitGHzKtVFiE7LBxM3gbg5F +wb26Ato2jncTQfYx0R6Rvg8a3d1/JjHKW7SgumHYBTdVPrKeQWuo4cVG0BjisMCM+LTDSvCSr5dD HcDbyWoGA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lREqw-003tAg-78; Tue, 30 Mar 2021 13:56:18 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lREou-003sks-Nt for linux-arm-kernel@lists.infradead.org; Tue, 30 Mar 2021 13:56:15 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lREos-0006Q3-3h; Tue, 30 Mar 2021 15:54:10 +0200 Received: from ore by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lREoq-0004Rb-Ol; Tue, 30 Mar 2021 15:54:08 +0200 From: Oleksij Rempel To: Shawn Guo , Sascha Hauer , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Fugang Duan Cc: Oleksij Rempel , kernel@pengutronix.de, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com, Fabio Estevam , David Jander , Russell King , Philippe Schenker Subject: [PATCH net-next v1 2/3] net: phy: at803x: AR8085: add loopback support Date: Tue, 30 Mar 2021 15:54:06 +0200 Message-Id: <20210330135407.17010-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210330135407.17010-1-o.rempel@pengutronix.de> References: <20210330135407.17010-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210330_145613_096696_2961BD1A X-CRM114-Status: GOOD ( 14.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org PHY loopback is needed for the ethernet controller self test support. This PHY was tested with the FEC sefltest. Signed-off-by: Oleksij Rempel --- drivers/net/phy/at803x.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index d7799beb811c..8679738cf2ab 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -326,6 +326,30 @@ static int at803x_resume(struct phy_device *phydev) return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0); } +static int at803x_loopback(struct phy_device *phydev, bool enable) +{ + int ret; + + if (enable) + ret = phy_clear_bits(phydev, MII_BMCR, BMCR_ANENABLE); + else + ret = phy_set_bits(phydev, MII_BMCR, BMCR_ANENABLE); + + if (ret) + return ret; + + ret = genphy_loopback(phydev, enable); + + /* + * Loop back needs some time to start transmitting packets in the loop. + * Documentation says nothing about it, so I take time which seems to + * work on AR8085. + */ + msleep(1); + + return ret; +} + static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev, unsigned int selector) { @@ -1128,6 +1152,7 @@ static struct phy_driver at803x_driver[] = { .get_wol = at803x_get_wol, .suspend = at803x_suspend, .resume = at803x_resume, + .set_loopback = at803x_loopback, /* PHY_GBIT_FEATURES */ .read_status = at803x_read_status, .config_intr = at803x_config_intr, From patchwork Tue Mar 30 13:54:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 12172627 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,DKIMWL_WL_HIGH, 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=unavailable 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 1B09DC433DB for ; Tue, 30 Mar 2021 13:56:06 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 80D4D61998 for ; Tue, 30 Mar 2021 13:56:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80D4D61998 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SoPrI8XMsagjpavFnfXZlIUwOWCFaZoOP+7LSt1yLSQ=; b=SNjLobP0+5h37aJs75Be7jber rMCwQQsE3nhD7KbZ+fljXBmnlbRdkiuKVasfVF7/aNuqHHisSPrFn3ofBHUWkAyPMbjJuro6TDiWf Y1ECvvUkjvL/jjk2LRVY4iadKo8FmnRGLQqTvruPVyWg5Tb+cwGtCCOMvu2j1ReBwaLCt8gnSzT6x /NYT3FonTJnI/jtQx5t56UH1so+r9rcRp4IWIjioIREdW5cAxG8la6JBcl5HIVsVg6UCj0gqDctZ+ 2T103Q21eKB2Vn7AuBD1KMdjBMWKVay+Pk7nkEn4NawJ4263HMr35HjXDVRS96XAa5eeZfcqGIfGq MgiAmmPwQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lREpC-003soo-8I; Tue, 30 Mar 2021 13:54:30 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lREp7-003snz-Sk for linux-arm-kernel@desiato.infradead.org; Tue, 30 Mar 2021 13:54:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=aNswm+IFeNAfeSiKFWrc2P9p4x1zTNQVKoJiBTvB+dY=; b=JCAGAmncuPpbLCFokiJ/2qqLZ6 E88p6UA6xW8MDZwgsjLPAWi19e/Pig/rQSSRhUVnDCDGlyy+7V2wVl4rD1nr71l3ptIC1KytsxEsu jvho2jUqXOU2o+BA+jGgxq0Uv9Nxk5QyhbvWmaF5NFaLY/M7CgDJ4WS7aLOpLbjdgudMmkVlt1w6p icKzsgnQLWOoWiytiVmTJYbOWkFn4o8j4cGutOAe4qfcYErsmc8uy2hZV33PU8IQyC+jxs25jhceR YfvnyULyrHKCv5w0fbKfHLD+NngIfuOuX2ZYLkidW0YSvtitXhP46dCB0MfuVFj9qDag/pElpMcMn oyMVCIwg==; Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lREox-0036cZ-GG for linux-arm-kernel@lists.infradead.org; Tue, 30 Mar 2021 13:54:23 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lREos-0006Q4-3h; Tue, 30 Mar 2021 15:54:10 +0200 Received: from ore by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1lREoq-0004Rk-Po; Tue, 30 Mar 2021 15:54:08 +0200 From: Oleksij Rempel To: Shawn Guo , Sascha Hauer , Andrew Lunn , Florian Fainelli , Heiner Kallweit , Fugang Duan Cc: Oleksij Rempel , kernel@pengutronix.de, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-imx@nxp.com, Fabio Estevam , David Jander , Russell King , Philippe Schenker Subject: [PATCH net-next v1 3/3] net: fec: add basic selftest support Date: Tue, 30 Mar 2021 15:54:07 +0200 Message-Id: <20210330135407.17010-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210330135407.17010-1-o.rempel@pengutronix.de> References: <20210330135407.17010-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210330_145417_288489_55E49540 X-CRM114-Status: GOOD ( 29.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Port some parts of the stmmac selftest to the FEC. This patch was tested on iMX6DL. With this tests it is possible to detect some basic issues like: - MAC loopback fail: most probably wrong clock configuration. - PHY loopback fail: incorrect RGMII timings, damaged traces, etc Signed-off-by: Oleksij Rempel Reported-by: kernel test robot --- drivers/net/ethernet/freescale/Makefile | 2 +- drivers/net/ethernet/freescale/fec.h | 6 + drivers/net/ethernet/freescale/fec_main.c | 6 + .../net/ethernet/freescale/fec_selftests.c | 425 ++++++++++++++++++ 4 files changed, 438 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/freescale/fec_selftests.c diff --git a/drivers/net/ethernet/freescale/Makefile b/drivers/net/ethernet/freescale/Makefile index 67c436400352..b936c6fe5911 100644 --- a/drivers/net/ethernet/freescale/Makefile +++ b/drivers/net/ethernet/freescale/Makefile @@ -4,7 +4,7 @@ # obj-$(CONFIG_FEC) += fec.o -fec-objs :=fec_main.o fec_ptp.o +fec-objs :=fec_main.o fec_ptp.o fec_selftests.o obj-$(CONFIG_FEC_MPC52xx) += fec_mpc52xx.o ifeq ($(CONFIG_FEC_MPC52xx_MDIO),y) diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index 0602d5d5d2ee..ade6a80934bf 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -467,6 +467,9 @@ struct bufdesc_ex { */ #define FEC_QUIRK_NO_HARD_RESET (1 << 18) +#define FEC_ENET_DRT (1 << 1) +#define FEC_ENET_LOOP (1 << 0) + struct bufdesc_prop { int qid; /* Address of Rx and Tx buffers */ @@ -604,6 +607,9 @@ void fec_ptp_start_cyclecounter(struct net_device *ndev); void fec_ptp_disable_hwts(struct net_device *ndev); int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr); int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr); +void fec_selftest(struct net_device *ndev, struct ethtool_test *etest, u64 *data); +int fec_selftest_get_count(void); +void fec_selftest_get_strings(u8 *data); /****************************************************************************/ #endif /* FEC_H */ diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 3db882322b2b..2ca72f7b5b7d 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -2474,6 +2474,9 @@ static void fec_enet_get_strings(struct net_device *netdev, { int i; switch (stringset) { + case ETH_SS_TEST: + fec_selftest_get_strings(data); + break; case ETH_SS_STATS: for (i = 0; i < ARRAY_SIZE(fec_stats); i++) memcpy(data + i * ETH_GSTRING_LEN, @@ -2485,6 +2488,8 @@ static void fec_enet_get_strings(struct net_device *netdev, static int fec_enet_get_sset_count(struct net_device *dev, int sset) { switch (sset) { + case ETH_SS_TEST: + return fec_selftest_get_count(); case ETH_SS_STATS: return ARRAY_SIZE(fec_stats); default: @@ -2738,6 +2743,7 @@ static const struct ethtool_ops fec_enet_ethtool_ops = { .set_wol = fec_enet_set_wol, .get_link_ksettings = phy_ethtool_get_link_ksettings, .set_link_ksettings = phy_ethtool_set_link_ksettings, + .self_test = fec_selftest, }; static int fec_enet_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) diff --git a/drivers/net/ethernet/freescale/fec_selftests.c b/drivers/net/ethernet/freescale/fec_selftests.c new file mode 100644 index 000000000000..788213a6454f --- /dev/null +++ b/drivers/net/ethernet/freescale/fec_selftests.c @@ -0,0 +1,425 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019 Synopsys, Inc. and/or its affiliates. + * stmmac Selftests Support + * + * Author: Jose Abreu + * + * Ported from stmmac to the FEC by: + * Copyright (C) 2021 Oleksij Rempel + */ + +#include +#include +#include + +#include "fec.h" + +struct fec_packet_attrs { + unsigned char *src; + unsigned char *dst; + u32 ip_src; + u32 ip_dst; + int tcp; + int sport; + int dport; + int timeout; + int size; + int max_size; + u8 id; + u16 queue_mapping; +}; + +struct fec_test_priv { + struct fec_packet_attrs *packet; + struct packet_type pt; + struct completion comp; + int double_vlan; + int vlan_id; + int ok; +}; + +struct fechdr { + __be32 version; + __be64 magic; + u8 id; +} __packed; + +static u8 fec_test_next_id; + +#define FEC_TEST_PKT_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \ + sizeof(struct fechdr)) +#define FEC_TEST_PKT_MAGIC 0xdeadcafecafedeadULL +#define FEC_LB_TIMEOUT msecs_to_jiffies(200) + +static struct sk_buff *fec_test_get_udp_skb(struct fec_enet_private *fep, + struct fec_packet_attrs *attr) +{ + struct sk_buff *skb = NULL; + struct udphdr *uhdr = NULL; + struct tcphdr *thdr = NULL; + struct fechdr *shdr; + struct ethhdr *ehdr; + struct iphdr *ihdr; + int iplen, size; + + size = attr->size + FEC_TEST_PKT_SIZE; + + if (attr->tcp) + size += sizeof(struct tcphdr); + else + size += sizeof(struct udphdr); + + if (attr->max_size && (attr->max_size > size)) + size = attr->max_size; + + skb = netdev_alloc_skb(fep->netdev, size); + if (!skb) + return NULL; + + prefetchw(skb->data); + + ehdr = skb_push(skb, ETH_HLEN); + skb_reset_mac_header(skb); + + skb_set_network_header(skb, skb->len); + ihdr = skb_put(skb, sizeof(*ihdr)); + + skb_set_transport_header(skb, skb->len); + if (attr->tcp) + thdr = skb_put(skb, sizeof(*thdr)); + else + uhdr = skb_put(skb, sizeof(*uhdr)); + eth_zero_addr(ehdr->h_dest); + if (attr->src) + ether_addr_copy(ehdr->h_source, attr->src); + if (attr->dst) + ether_addr_copy(ehdr->h_dest, attr->dst); + + ehdr->h_proto = htons(ETH_P_IP); + + if (attr->tcp) { + thdr->source = htons(attr->sport); + thdr->dest = htons(attr->dport); + thdr->doff = sizeof(struct tcphdr) / 4; + thdr->check = 0; + } else { + uhdr->source = htons(attr->sport); + uhdr->dest = htons(attr->dport); + uhdr->len = htons(sizeof(*shdr) + sizeof(*uhdr) + attr->size); + if (attr->max_size) + uhdr->len = htons(attr->max_size - + (sizeof(*ihdr) + sizeof(*ehdr))); + uhdr->check = 0; + } + + ihdr->ihl = 5; + ihdr->ttl = 32; + ihdr->version = 4; + if (attr->tcp) + ihdr->protocol = IPPROTO_TCP; + else + ihdr->protocol = IPPROTO_UDP; + iplen = sizeof(*ihdr) + sizeof(*shdr) + attr->size; + if (attr->tcp) + iplen += sizeof(*thdr); + else + iplen += sizeof(*uhdr); + + if (attr->max_size) + iplen = attr->max_size - sizeof(*ehdr); + + ihdr->tot_len = htons(iplen); + ihdr->frag_off = 0; + ihdr->saddr = htonl(attr->ip_src); + ihdr->daddr = htonl(attr->ip_dst); + ihdr->tos = 0; + ihdr->id = 0; + ip_send_check(ihdr); + + shdr = skb_put(skb, sizeof(*shdr)); + shdr->version = 0; + shdr->magic = cpu_to_be64(FEC_TEST_PKT_MAGIC); + attr->id = fec_test_next_id; + shdr->id = fec_test_next_id++; + + if (attr->size) + skb_put(skb, attr->size); + if (attr->max_size && (attr->max_size > skb->len)) + skb_put(skb, attr->max_size - skb->len); + + skb->csum = 0; + skb->ip_summed = CHECKSUM_PARTIAL; + if (attr->tcp) { + thdr->check = ~tcp_v4_check(skb->len, ihdr->saddr, ihdr->daddr, 0); + skb->csum_start = skb_transport_header(skb) - skb->head; + skb->csum_offset = offsetof(struct tcphdr, check); + } else { + udp4_hwcsum(skb, ihdr->saddr, ihdr->daddr); + } + + skb->protocol = htons(ETH_P_IP); + skb->pkt_type = PACKET_HOST; + skb->dev = fep->netdev; + + return skb; +} + +static int fec_test_loopback_validate(struct sk_buff *skb, + struct net_device *ndev, + struct packet_type *pt, + struct net_device *orig_ndev) +{ + struct fec_test_priv *tpriv = pt->af_packet_priv; + unsigned char *src = tpriv->packet->src; + unsigned char *dst = tpriv->packet->dst; + struct fechdr *shdr; + struct ethhdr *ehdr; + struct udphdr *uhdr; + struct tcphdr *thdr; + struct iphdr *ihdr; + + skb = skb_unshare(skb, GFP_ATOMIC); + if (!skb) + goto out; + + if (skb_linearize(skb)) + goto out; + if (skb_headlen(skb) < (FEC_TEST_PKT_SIZE - ETH_HLEN)) + goto out; + + ehdr = (struct ethhdr *)skb_mac_header(skb); + if (dst) { + if (!ether_addr_equal_unaligned(ehdr->h_dest, dst)) + goto out; + } + + if (src) { + if (!ether_addr_equal_unaligned(ehdr->h_source, src)) + goto out; + } + + ihdr = ip_hdr(skb); + if (tpriv->double_vlan) + ihdr = (struct iphdr *)(skb_network_header(skb) + 4); + + if (tpriv->packet->tcp) { + if (ihdr->protocol != IPPROTO_TCP) + goto out; + + thdr = (struct tcphdr *)((u8 *)ihdr + 4 * ihdr->ihl); + if (thdr->dest != htons(tpriv->packet->dport)) + goto out; + + shdr = (struct fechdr *)((u8 *)thdr + sizeof(*thdr)); + } else { + if (ihdr->protocol != IPPROTO_UDP) + goto out; + + uhdr = (struct udphdr *)((u8 *)ihdr + 4 * ihdr->ihl); + if (uhdr->dest != htons(tpriv->packet->dport)) + goto out; + + shdr = (struct fechdr *)((u8 *)uhdr + sizeof(*uhdr)); + } + + if (shdr->magic != cpu_to_be64(FEC_TEST_PKT_MAGIC)) + goto out; + if (tpriv->packet->id != shdr->id) + goto out; + + tpriv->ok = true; + complete(&tpriv->comp); +out: + kfree_skb(skb); + return 0; +} + +static int __fec_test_loopback(struct fec_enet_private *fep, + struct fec_packet_attrs *attr) +{ + struct fec_test_priv *tpriv; + struct sk_buff *skb = NULL; + int ret = 0; + + tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL); + if (!tpriv) + return -ENOMEM; + + tpriv->ok = false; + init_completion(&tpriv->comp); + + tpriv->pt.type = htons(ETH_P_IP); + tpriv->pt.func = fec_test_loopback_validate; + tpriv->pt.dev = fep->netdev; + tpriv->pt.af_packet_priv = tpriv; + tpriv->packet = attr; + + skb = fec_test_get_udp_skb(fep, attr); + if (!skb) { + ret = -ENOMEM; + goto cleanup; + } + + ret = dev_direct_xmit(skb, attr->queue_mapping); + if (ret) + goto cleanup; + + if (!attr->timeout) + attr->timeout = FEC_LB_TIMEOUT; + + wait_for_completion_timeout(&tpriv->comp, attr->timeout); + ret = tpriv->ok ? 0 : -ETIMEDOUT; + +cleanup: + kfree(tpriv); + return ret; +} + +static int fec_test_mac_loopback(struct net_device *ndev) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + struct fec_packet_attrs attr = { }; + + attr.dst = ndev->dev_addr; + return __fec_test_loopback(fep, &attr); +} + +static int fec_test_phy_loopback(struct net_device *ndev) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + struct fec_packet_attrs attr = { }; + + attr.dst = ndev->dev_addr; + return __fec_test_loopback(fep, &attr); +} + +static int fec_test_tcp(struct net_device *ndev) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + struct fec_packet_attrs attr = { }; + + attr.dst = ndev->dev_addr; + attr.tcp = true; + return __fec_test_loopback(fep, &attr); +} + +#define FEC_LOOPBACK_MAC 0 +#define FEC_LOOPBACK_PHY 1 + +static const struct fec_test { + char name[ETH_GSTRING_LEN]; + int lb; + int (*fn)(struct net_device *ndev); +} fec_selftests[] = { + { + .name = "MAC Loopback, UDP ", + .lb = FEC_LOOPBACK_MAC, + .fn = fec_test_mac_loopback, + }, { + .name = "PHY Loopback, UDP ", + .lb = FEC_LOOPBACK_PHY, + .fn = fec_test_phy_loopback, + }, { + .name = "PHY Loopback, TCP ", + .lb = FEC_LOOPBACK_PHY, + .fn = fec_test_tcp, + }, +}; + +void fec_selftest(struct net_device *ndev, + struct ethtool_test *etest, u64 *buf) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + int count = fec_selftest_get_count(); + u32 tmp, r_cntrl; + int i, ret; + + memset(buf, 0, sizeof(*buf) * count); + fec_test_next_id = 0; + + if (etest->flags != ETH_TEST_FL_OFFLINE) { + netdev_err(ndev, "Only offline tests are supported\n"); + etest->flags |= ETH_TEST_FL_FAILED; + return; + } else if (!netif_carrier_ok(ndev)) { + netdev_err(ndev, "You need valid Link to execute tests\n"); + etest->flags |= ETH_TEST_FL_FAILED; + return; + } + + /* Wait for queues drain */ + msleep(200); + for (i = 0; i < count; i++) { + ret = 0; + + + switch (fec_selftests[i].lb) { + case FEC_LOOPBACK_PHY: + ret = -EOPNOTSUPP; + if (ndev->phydev) + ret = phy_loopback(ndev->phydev, true); + if (!ret) + break; + fallthrough; + case FEC_LOOPBACK_MAC: + /* disable half duplex if present and enable MAC loop back */ + r_cntrl = readl(fep->hwp + FEC_R_CNTRL); + tmp = FEC_ENET_LOOP | (r_cntrl & ~FEC_ENET_DRT); + writel(tmp, fep->hwp + FEC_R_CNTRL); + break; + default: + ret = -EOPNOTSUPP; + break; + } + + /* + * First tests will always be MAC / PHY loobpack. If any of + * them is not supported we abort earlier. + */ + if (ret) { + netdev_err(ndev, "Loopback is not supported\n"); + etest->flags |= ETH_TEST_FL_FAILED; + break; + } + + ret = fec_selftests[i].fn(ndev); + if (ret && (ret != -EOPNOTSUPP)) + etest->flags |= ETH_TEST_FL_FAILED; + buf[i] = ret; + + switch (fec_selftests[i].lb) { + case FEC_LOOPBACK_PHY: + ret = -EOPNOTSUPP; + if (ndev->phydev) + ret = phy_loopback(ndev->phydev, false); + if (!ret) + break; + fallthrough; + case FEC_LOOPBACK_MAC: + writel(r_cntrl, fep->hwp + FEC_R_CNTRL); + break; + default: + break; + } + } +} + +int fec_selftest_get_count(void) +{ + return ARRAY_SIZE(fec_selftests); +} + +void fec_selftest_get_strings(u8 *data) +{ + u8 *p = data; + int i; + + for (i = 0; i < fec_selftest_get_count(); i++) { + snprintf(p, ETH_GSTRING_LEN, "%2d. %s", i + 1, + fec_selftests[i].name); + p += ETH_GSTRING_LEN; + } +} + +