From patchwork Tue Dec 18 22:36:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1015782 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="MM6ed/bt"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43KHDn3SXpz9s3Z for ; Wed, 19 Dec 2018 12:22:17 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 1F301C21E0D; Wed, 19 Dec 2018 01:21:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=RCVD_IN_SORBS_WEB, SPF_HELO_PASS, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id F3ABBC21F85; Wed, 19 Dec 2018 01:20:46 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 80B52C21E52; Tue, 18 Dec 2018 22:36:56 +0000 (UTC) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150048.outbound.protection.outlook.com [40.107.15.48]) by lists.denx.de (Postfix) with ESMTPS id EF1D4C21C2F for ; Tue, 18 Dec 2018 22:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DsLi274hgFvfiwqA26w+2GWFIXMOqxtgHdJmmT85Ucc=; b=MM6ed/btAJBH6eEc01/daBRxkSWHGqmJMet+icYqRT1IdIi/ibIj2FGxgamysfRGDb9hKKSacZ2MXphjPj3H7bruojms7WUzPyzS6oLW9alJjhn7+5AdZqzoubipZaPhcTZfyMEUcIcOERIxMQF3JTxunZm8S5w8BrK20JZmhic= Received: from DB7PR04MB5163.eurprd04.prod.outlook.com (20.176.235.75) by DB7PR04MB4905.eurprd04.prod.outlook.com (20.176.234.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1446.17; Tue, 18 Dec 2018 22:36:53 +0000 Received: from DB7PR04MB5163.eurprd04.prod.outlook.com ([fe80::646c:d897:34a6:2ef2]) by DB7PR04MB5163.eurprd04.prod.outlook.com ([fe80::646c:d897:34a6:2ef2%2]) with mapi id 15.20.1425.023; Tue, 18 Dec 2018 22:36:53 +0000 From: Vladimir Oltean To: "joe.hershberger@ni.com" Thread-Topic: [PATCH 1/2] net: phy: promote phy_{read, write}_mmd_indirect from ti.c to generic code Thread-Index: AQHUlyIsrZnEDAqu/UGq8jmm3zBDAQ== Date: Tue, 18 Dec 2018 22:36:53 +0000 Message-ID: <1545172561-28687-2-git-send-email-vladimir.oltean@nxp.com> References: <1545172561-28687-1-git-send-email-vladimir.oltean@nxp.com> In-Reply-To: <1545172561-28687-1-git-send-email-vladimir.oltean@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: VI1PR0102CA0063.eurprd01.prod.exchangelabs.com (2603:10a6:803::40) To DB7PR04MB5163.eurprd04.prod.outlook.com (2603:10a6:10:1d::11) authentication-results: spf=none (sender IP is ) smtp.mailfrom=vladimir.oltean@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [86.34.165.90] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB7PR04MB4905; 6:WNiDvfw52Ub2O+TE9CVXg2jON16qSF5pykP2Y6b25VkmnlpLp0yXwrVWqkVngJTxQQ6pyC3MebKwVK63Mx2RDQ8Z7IbaALQ45vlQk+hfwZH7GbSIa2NvlKVoZtgfWVR09OhLiU27uKFS3mTygMmBzLcdLwrpiO5PVyl0txgd0yc2C6F1GzUMevNsZb5Ac7ai/bK9lPap1jquCyEO3C+L20kzeGkRH8gdPDAX+t7u3M8DwzcIn+8b6LTvb4n6ZFCvzV9MCJHZA2i6kHBecAOkkzYMpbZnP0bhMgiPq1wpamt13q+UE0E4Ng7bO96s0PPQunTAZF/D0LwZuVW/gXDhzuO4wTlLI86OBbvUReFvjXk7ZVvCGejyNN9W7YtqpV471w0GpTH5SDPFjD3ECzVurxE/oYNuScIOmqDnVDB4T1LE1SRvgsX8MJNCfrmz0/LYQKJpaEGeK0INi2rxKEQb+w==; 5:GaaiK2/hdhttizZkGc0tlh1kaCkU6fvrDy/D8IiHx34ekuTUIVJoSza/nleA5OU+SuYC4rsJNZEQMzB3AQ3cgREE8x5RmxBgc5XqCjE5r0VMizfIn3dFOhDvreDjJB9pepzRm7e02AJ4JZSObgF4thNoicSPKW4sG9tDztNArmM=; 7:ZRY18WSQPVOMRdd6oBFzD3gauTM3iqxh3XkgLpMJZsXzGQVe9aLJlG5/Yq8FCLkZ31pyK5IcDB8MWRFb5xMWOMeYdMsNUt6vMGYUkzHIY6ujd0+G7A+oyYb7lRbIsFdYaNky3IBamm+29lrvZb2N7A== x-ms-office365-filtering-correlation-id: 3e61c368-8715-45ab-158d-08d665394f34 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB7PR04MB4905; x-ms-traffictypediagnostic: DB7PR04MB4905: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231475)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(201708071742011)(7699051)(76991095); SRVR:DB7PR04MB4905; BCL:0; PCL:0; RULEID:; SRVR:DB7PR04MB4905; x-forefront-prvs: 08902E536D x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(366004)(346002)(376002)(39860400002)(136003)(199004)(189003)(53936002)(5024004)(14444005)(2616005)(86362001)(575784001)(4326008)(256004)(3846002)(6116002)(476003)(6512007)(305945005)(6486002)(5640700003)(106356001)(2501003)(6916009)(446003)(11346002)(97736004)(486006)(44832011)(105586002)(6436002)(71200400001)(71190400001)(186003)(5660300001)(52116002)(81156014)(81166006)(36756003)(50226002)(25786009)(8936002)(68736007)(14454004)(66066001)(99286004)(102836004)(2351001)(6506007)(386003)(76176011)(26005)(316002)(54906003)(7736002)(478600001)(2906002)(8676002)(41533002)(142933001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR04MB4905; H:DB7PR04MB5163.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: +fZZYcD3WPT5eYs29mlbm9Q1lWulwE6Iu1XOcV2/PJq7jqe/2hPxTH2x2BiTHapEAVu8su738KjHb1fJ3PkZRJQYjdVCbmAKNkNci4dcDnEJJYiFLFQqWNbe0VjrxAMOAiL9o2cjN+WvEqnO0cfYET97s05zA7iPbUNXWUp7HsdrniAu+QAUmaI4eo43dbPL8i7HCi3jCjf5nSZQDqp+opWYgGfuSo9ohv31yr13AHUPxdHas8wwoNTTneJcCJGeGZfak3sFupCkfKDpfuEFaJGhmTwyzn/4idXWeiDO4zZT5mK4PGWexlqtNQwRMGvw spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e61c368-8715-45ab-158d-08d665394f34 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Dec 2018 22:36:53.8660 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4905 X-Mailman-Approved-At: Wed, 19 Dec 2018 01:20:43 +0000 Cc: "u-boot@lists.denx.de" , Vladimir Oltean Subject: [U-Boot] [PATCH 1/2] net: phy: promote phy_{read, write}_mmd_indirect from ti.c to generic code X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" * These are convenience functions for accessing PHY MMD registers through clause 22 (indirectly through registers 0xD and 0xE), and are exported in the Linux phylib as well. Signed-off-by: Vladimir Oltean Acked-by: Joe Hershberger --- drivers/net/phy/phy.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/ti.c | 76 --------------------------------------------------- include/linux/mdio.h | 10 +++++++ include/phy.h | 37 +++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 76 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index e837eb7..e71a269 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -17,6 +17,7 @@ #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -954,3 +955,70 @@ int phy_get_interface_by_name(const char *str) return -1; } + +/** + * phy_read_mmd_indirect - reads data from the MMD registers + * @phydev: The PHY device bus + * @prtad: MMD Address + * @devad: MMD DEVAD + * @addr: PHY address on the MII bus + * + * Description: it reads data from the MMD registers (clause 22 to access to + * clause 45) of the specified phy address. + * To read these registers we have: + * 1) Write reg 13 // DEVAD + * 2) Write reg 14 // MMD Address + * 3) Write reg 13 // MMD Data Command for MMD DEVAD + * 3) Read reg 14 // Read MMD data + */ +int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, + int devad, int addr) +{ + int value = -1; + + /* Write the desired MMD Devad */ + phy_write(phydev, addr, MII_MMD_CTRL, devad); + + /* Write the desired MMD register address */ + phy_write(phydev, addr, MII_MMD_DATA, prtad); + + /* Select the Function : DATA with no post increment */ + phy_write(phydev, addr, MII_MMD_CTRL, (devad | MII_MMD_CTRL_NOINCR)); + + /* Read the content of the MMD's selected register */ + value = phy_read(phydev, addr, MII_MMD_DATA); + return value; +} + +/** + * phy_write_mmd_indirect - writes data to the MMD registers + * @phydev: The PHY device + * @prtad: MMD Address + * @devad: MMD DEVAD + * @addr: PHY address on the MII bus + * @data: data to write in the MMD register + * + * Description: Write data from the MMD registers of the specified + * phy address. + * To write these registers we have: + * 1) Write reg 13 // DEVAD + * 2) Write reg 14 // MMD Address + * 3) Write reg 13 // MMD Data Command for MMD DEVAD + * 3) Write reg 14 // Write MMD data + */ +void phy_write_mmd_indirect(struct phy_device *phydev, int prtad, + int devad, int addr, u32 data) +{ + /* Write the desired MMD Devad */ + phy_write(phydev, addr, MII_MMD_CTRL, devad); + + /* Write the desired MMD register address */ + phy_write(phydev, addr, MII_MMD_DATA, prtad); + + /* Select the Function : DATA with no post increment */ + phy_write(phydev, addr, MII_MMD_CTRL, (devad | MII_MMD_CTRL_NOINCR)); + + /* Write the data into MMD's selected register */ + phy_write(phydev, addr, MII_MMD_DATA, data); +} + diff --git a/drivers/net/phy/ti.c b/drivers/net/phy/ti.c index 6db6edd..915d6bf 100644 --- a/drivers/net/phy/ti.c +++ b/drivers/net/phy/ti.c @@ -73,16 +73,6 @@ #define MII_DP83867_CFG2_SPEEDOPT_INTLOW 0x2000 #define MII_DP83867_CFG2_MASK 0x003F -#define MII_MMD_CTRL 0x0d /* MMD Access Control Register */ -#define MII_MMD_DATA 0x0e /* MMD Access Data Register */ - -/* MMD Access Control register fields */ -#define MII_MMD_CTRL_DEVAD_MASK 0x1f /* Mask MMD DEVAD*/ -#define MII_MMD_CTRL_ADDR 0x0000 /* Address */ -#define MII_MMD_CTRL_NOINCR 0x4000 /* no post increment */ -#define MII_MMD_CTRL_INCR_RDWT 0x8000 /* post increment on reads & writes */ -#define MII_MMD_CTRL_INCR_ON_WT 0xC000 /* post increment on writes only */ - /* User setting - can be taken from DTS */ #define DEFAULT_RX_ID_DELAY DP83867_RGMIIDCTL_2_25_NS #define DEFAULT_TX_ID_DELAY DP83867_RGMIIDCTL_2_75_NS @@ -116,72 +106,6 @@ struct dp83867_private { int clk_output_sel; }; -/** - * phy_read_mmd_indirect - reads data from the MMD registers - * @phydev: The PHY device bus - * @prtad: MMD Address - * @devad: MMD DEVAD - * @addr: PHY address on the MII bus - * - * Description: it reads data from the MMD registers (clause 22 to access to - * clause 45) of the specified phy address. - * To read these registers we have: - * 1) Write reg 13 // DEVAD - * 2) Write reg 14 // MMD Address - * 3) Write reg 13 // MMD Data Command for MMD DEVAD - * 3) Read reg 14 // Read MMD data - */ -int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, - int devad, int addr) -{ - int value = -1; - - /* Write the desired MMD Devad */ - phy_write(phydev, addr, MII_MMD_CTRL, devad); - - /* Write the desired MMD register address */ - phy_write(phydev, addr, MII_MMD_DATA, prtad); - - /* Select the Function : DATA with no post increment */ - phy_write(phydev, addr, MII_MMD_CTRL, (devad | MII_MMD_CTRL_NOINCR)); - - /* Read the content of the MMD's selected register */ - value = phy_read(phydev, addr, MII_MMD_DATA); - return value; -} - -/** - * phy_write_mmd_indirect - writes data to the MMD registers - * @phydev: The PHY device - * @prtad: MMD Address - * @devad: MMD DEVAD - * @addr: PHY address on the MII bus - * @data: data to write in the MMD register - * - * Description: Write data from the MMD registers of the specified - * phy address. - * To write these registers we have: - * 1) Write reg 13 // DEVAD - * 2) Write reg 14 // MMD Address - * 3) Write reg 13 // MMD Data Command for MMD DEVAD - * 3) Write reg 14 // Write MMD data - */ -void phy_write_mmd_indirect(struct phy_device *phydev, int prtad, - int devad, int addr, u32 data) -{ - /* Write the desired MMD Devad */ - phy_write(phydev, addr, MII_MMD_CTRL, devad); - - /* Write the desired MMD register address */ - phy_write(phydev, addr, MII_MMD_DATA, prtad); - - /* Select the Function : DATA with no post increment */ - phy_write(phydev, addr, MII_MMD_CTRL, (devad | MII_MMD_CTRL_NOINCR)); - - /* Write the data into MMD's selected register */ - phy_write(phydev, addr, MII_MMD_DATA, data); -} - static int dp83867_config_port_mirroring(struct phy_device *phydev) { struct dp83867_private *dp83867 = diff --git a/include/linux/mdio.h b/include/linux/mdio.h index 6e821d9..87704a0 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -13,6 +13,16 @@ #include +#define MII_MMD_CTRL 0x0d /* MMD Access Control Register */ +#define MII_MMD_DATA 0x0e /* MMD Access Data Register */ + +/* MMD Access Control register fields */ +#define MII_MMD_CTRL_DEVAD_MASK 0x1f /* Mask MMD DEVAD*/ +#define MII_MMD_CTRL_ADDR 0x0000 /* Address */ +#define MII_MMD_CTRL_NOINCR 0x4000 /* no post increment */ +#define MII_MMD_CTRL_INCR_RDWT 0x8000 /* post increment on reads & writes */ +#define MII_MMD_CTRL_INCR_ON_WT 0xC000 /* post increment on writes only */ + /* MDIO Manageable Devices (MMDs). */ #define MDIO_MMD_PMAPMD 1 /* Physical Medium Attachment/ * Physical Medium Dependent */ diff --git a/include/phy.h b/include/phy.h index b86fdfb..71fe151 100644 --- a/include/phy.h +++ b/include/phy.h @@ -274,6 +274,43 @@ static inline bool phy_interface_is_sgmii(struct phy_device *phydev) phydev->interface <= PHY_INTERFACE_MODE_QSGMII; } +/** + * phy_read_mmd_indirect - reads data from the MMD registers + * @phydev: The PHY device bus + * @prtad: MMD Address + * @devad: MMD DEVAD + * @addr: PHY address on the MII bus + * + * Description: it reads data from the MMD registers (clause 22 to access to + * clause 45) of the specified phy address. + * To read these registers we have: + * 1) Write reg 13 // DEVAD + * 2) Write reg 14 // MMD Address + * 3) Write reg 13 // MMD Data Command for MMD DEVAD + * 3) Read reg 14 // Read MMD data + */ +int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, + int devad, int addr); + +/** + * phy_write_mmd_indirect - writes data to the MMD registers + * @phydev: The PHY device + * @prtad: MMD Address + * @devad: MMD DEVAD + * @addr: PHY address on the MII bus + * @data: data to write in the MMD register + * + * Description: Write data from the MMD registers of the specified + * phy address. + * To write these registers we have: + * 1) Write reg 13 // DEVAD + * 2) Write reg 14 // MMD Address + * 3) Write reg 13 // MMD Data Command for MMD DEVAD + * 3) Write reg 14 // Write MMD data + */ +void phy_write_mmd_indirect(struct phy_device *phydev, int prtad, + int devad, int addr, u32 data); + /* PHY UIDs for various PHYs that are referenced in external code */ #define PHY_UID_CS4340 0x13e51002 #define PHY_UID_CS4223 0x03e57003 From patchwork Tue Dec 18 22:36:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1015783 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="qXmJE7ef"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43KHFL4pGbz9s3Z for ; Wed, 19 Dec 2018 12:22:42 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C7619C21ED5; Wed, 19 Dec 2018 01:21:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=RCVD_IN_SORBS_WEB, SPF_HELO_PASS, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id CC872C21FD2; Wed, 19 Dec 2018 01:20:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A965DC21C2F; Tue, 18 Dec 2018 22:36:57 +0000 (UTC) Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-eopbgr150041.outbound.protection.outlook.com [40.107.15.41]) by lists.denx.de (Postfix) with ESMTPS id 43EAFC21C2F for ; Tue, 18 Dec 2018 22:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TWfZ8+fQbgGHBncfTWzMM4Sj+eUb4myjMKtccqOMabA=; b=qXmJE7efcXMEvNDIGITBdcaQiVLioXz/P5ryMrpYdi4ZT49iaQKlD00+qqxuMGjGq/ZhFS3Rn3d4sKQCiFBQTYNpTix4RbDwgXYCqbOY70Lrg8bvTLOoejluEP4m4KTExxnlcL6TKZx2lE4pMwvh7nGTSP29mKPTlCt7oXTx9VM= Received: from DB7PR04MB5163.eurprd04.prod.outlook.com (20.176.235.75) by DB7PR04MB4905.eurprd04.prod.outlook.com (20.176.234.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1446.17; Tue, 18 Dec 2018 22:36:56 +0000 Received: from DB7PR04MB5163.eurprd04.prod.outlook.com ([fe80::646c:d897:34a6:2ef2]) by DB7PR04MB5163.eurprd04.prod.outlook.com ([fe80::646c:d897:34a6:2ef2%2]) with mapi id 15.20.1425.023; Tue, 18 Dec 2018 22:36:56 +0000 From: Vladimir Oltean To: "joe.hershberger@ni.com" Thread-Topic: [PATCH 2/2] net: phy: at803x: Address packet drops at low traffic rate due to SmartEEE feature Thread-Index: AQHUlyIu/h93sCDBvEmbOOOgKq7EWA== Date: Tue, 18 Dec 2018 22:36:56 +0000 Message-ID: <1545172561-28687-3-git-send-email-vladimir.oltean@nxp.com> References: <1545172561-28687-1-git-send-email-vladimir.oltean@nxp.com> In-Reply-To: <1545172561-28687-1-git-send-email-vladimir.oltean@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: VI1PR0102CA0063.eurprd01.prod.exchangelabs.com (2603:10a6:803::40) To DB7PR04MB5163.eurprd04.prod.outlook.com (2603:10a6:10:1d::11) authentication-results: spf=none (sender IP is ) smtp.mailfrom=vladimir.oltean@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [86.34.165.90] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB7PR04MB4905; 6:7f11qr1iQQBY2PAOx72lMGPlZh/+MgNsUezFoVXHDZxTVzHxkwY2um68yqcAvf/W1amxN8UonOWHazcihwcPQa4HoY0l4RrVp6w/vvWbWpl8iBHnRMuHFB6wrBIg1v24iB2vtfRwGo4nyhfazZoKD6VljY7r8pz0lBFXJ53VeK5d/k80oC8Ia/EBM6IFRdsT8MsBfrq1vXJ15UnG4ck6qKM4KQnD+nlG/punp7DvRuojhZWUQ84lka4aZAa6JRdYL1MCyz1qWmaX95QNXDHlf96J18vE508nAnRorfB4EJiNpPOvwfarGP9tsnyLnLZ9ZB6XJFn0RiToz4W5t2z0PqiSriPpGt5Mwtgml8EUpG4yEeEjsPaW2FAVk8yry3U13uEW/rWCYH9QGmcE/1c5jRjS2tSkH2tXHe6vjKs7274ILEB6Yy22a+4UyxPGpRl/yisFTXLdfL2oJ67Ts+qSHg==; 5:mf/23sLsq1a98BeZBJeE/T6NuoOmyuFv4TGQ8YXWTbL8jNeV8sDXOzxkl36ORHskW6hGziSJcZ6Vqggqp5TRoy07TpdLv6mDS1EWA+Pe8j4lsnARaCzfhIG1DgzDL8wCliHz1RZdG5khCq52iY8lU3Naz/tOGk2gueHBB9oZP+M=; 7:IGk3JYSS2wWKNk1Vkg32wJXJ2nHVD4yOu3mGVAiEuICHCwBR7v71l8B3IHmrGgSStqepUCWYLSn5wpu6QMZmM1AN5+qmww+ie6PDC2uMPa2EV3TIXfa380L+FaBOCMXzU4YH5o7GSMgBO6Tvz0aV5g== x-ms-office365-filtering-correlation-id: b8e7557d-4438-4ac4-41c6-08d6653950ab x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB7PR04MB4905; x-ms-traffictypediagnostic: DB7PR04MB4905: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(3230021)(999002)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231475)(944501520)(52105112)(6055026)(148016)(149066)(150057)(6041310)(20161123564045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(201708071742011)(7699051)(76991095); SRVR:DB7PR04MB4905; BCL:0; PCL:0; RULEID:; SRVR:DB7PR04MB4905; x-forefront-prvs: 08902E536D x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(366004)(346002)(376002)(39860400002)(136003)(199004)(189003)(53936002)(2616005)(86362001)(575784001)(4326008)(256004)(3846002)(6116002)(476003)(6512007)(305945005)(6486002)(5640700003)(106356001)(2501003)(6916009)(446003)(11346002)(97736004)(486006)(44832011)(105586002)(6436002)(71200400001)(71190400001)(186003)(5660300001)(52116002)(81156014)(81166006)(36756003)(50226002)(25786009)(8936002)(68736007)(14454004)(66066001)(99286004)(102836004)(2351001)(6506007)(386003)(76176011)(26005)(316002)(54906003)(7736002)(478600001)(2906002)(8676002)(16453002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR04MB4905; H:DB7PR04MB5163.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 2DqThkC3foCTbTXYUNhE459brIT0inTg17MSTSbm35LBHV0H4hZ+1PdK3aD05HUdlkIXg1tsSAveKnlELa3Svm1PydK5tK27UT0N6G6e1SUxVJQGoetJw0bKK9cphnHvh9FUxWELJC7J8AmtWjWc3tidjzRCkwI+ww0JWKnSO/OdV4CzXP89Iq4toEkWW3FnCjGZk/gBcnunMFtVCVHIo33hvLd7cGHiNqX2suKcKyWQDLVcQynwPrEVJhJLNEmnMovLUoWi6Tw1s419d6xVLud3H9YarijcGxSElMXrTR71VGEYcG7Nc82WNpizGITH spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8e7557d-4438-4ac4-41c6-08d6653950ab X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Dec 2018 22:36:56.2447 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4905 X-Mailman-Approved-At: Wed, 19 Dec 2018 01:20:43 +0000 Cc: "u-boot@lists.denx.de" , Vladimir Oltean Subject: [U-Boot] [PATCH 2/2] net: phy: at803x: Address packet drops at low traffic rate due to SmartEEE feature X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" * According to the AR8031 and AR8035 datasheets, smartEEE mode (active by default) makes the PHY enter sleep after a configurable idle time. It does this autonomously, without LPI (Low Power Idle) signals coming from MAC. AR8021 does not appear to support this. * This patch allows disabling the SmartEEE feature of above PHYs. * Tested with ping (default of 1 second interval) over back-to-back RGMII between 2 boards having AR8035 at both ends: - Without SmartEEE: 225 packets transmitted, 145 received, 35% packet loss, time 229334ms - With SmartEEE: 144 packets transmitted, 144 received, 0% packet loss, time 146378ms Signed-off-by: Vladimir Oltean Acked-by: Joe Hershberger --- drivers/net/phy/Kconfig | 21 +++++++++++++++++++++ drivers/net/phy/atheros.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 3dc0822..6abe8c5 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -94,6 +94,27 @@ config PHY_AQUANTIA_FW_NAME config PHY_ATHEROS bool "Atheros Ethernet PHYs support" +config PHY_ATHEROS_SMART_EEE + depends on PHY_ATHEROS + default y + tristate "SmartEEE feature for Atheros PHYs" + help + Enables the Atheros SmartEEE feature (not IEEE 802.3az). When 2 PHYs + which support this feature are connected back-to-back, they may + negotiate a low-power sleep mode autonomously, without the Ethernet + controller's knowledge. This setting may cause issues under 2 known + circumstances (both noticed at low traffic rates): + - If the voltage rails on the PHY are unstable, then the PHY can + actually reset as it enters the low power state. This means that + the frames it is supposed to buffer until it wakes up are going + to be dropped instead. + - If 1588/PTP synchronization is the only traffic source over this + PHY, the delays caused by the sleep/wakeup time are going to add + to the synchronization error between the master and the slave. + Default y, which means that the PHY's out-of-reset state is not + changed (SmartEEE active). To work around the issues described + above, change to n. + config PHY_BROADCOM bool "Broadcom Ethernet PHYs support" diff --git a/drivers/net/phy/atheros.c b/drivers/net/phy/atheros.c index 3783d15..a3c84fd 100644 --- a/drivers/net/phy/atheros.c +++ b/drivers/net/phy/atheros.c @@ -5,6 +5,7 @@ * Copyright 2011, 2013 Freescale Semiconductor, Inc. * author Andy Fleming */ +#include #include #include @@ -17,6 +18,23 @@ #define AR803x_DEBUG_REG_0 0x0 #define AR803x_RGMII_RX_CLK_DLY 0x8000 +#define AR803X_LPI_EN BIT(8) + +static void ar803x_enable_smart_eee(struct phy_device *phydev, bool on) +{ + int value; + + /* 5.1.11 Smart_eee control3 */ + value = phy_read_mmd_indirect(phydev, 0x805D, MDIO_MMD_PCS, + MDIO_DEVAD_NONE); + if (on) + value |= AR803X_LPI_EN; + else + value &= ~AR803X_LPI_EN; + phy_write_mmd_indirect(phydev, 0x805D, MDIO_MMD_PCS, + MDIO_DEVAD_NONE, value); +} + static int ar8021_config(struct phy_device *phydev) { phy_write(phydev, MDIO_DEVAD_NONE, 0x00, 0x1200); @@ -29,6 +47,11 @@ static int ar8021_config(struct phy_device *phydev) static int ar8031_config(struct phy_device *phydev) { +#ifdef CONFIG_PHY_ATHEROS_SMART_EEE + ar803x_enable_smart_eee(phydev, true); +#else + ar803x_enable_smart_eee(phydev, false); +#endif if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID || phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { phy_write(phydev, MDIO_DEVAD_NONE, AR803x_PHY_DEBUG_ADDR_REG, @@ -57,6 +80,11 @@ static int ar8035_config(struct phy_device *phydev) { int regval; +#ifdef CONFIG_PHY_ATHEROS_SMART_EEE + ar803x_enable_smart_eee(phydev, true); +#else + ar803x_enable_smart_eee(phydev, false); +#endif phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x0007); phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016); phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);