From patchwork Mon Mar 21 15:53:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12787444 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48A6EC433F5 for ; Mon, 21 Mar 2022 15:54:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348690AbiCUPzi (ORCPT ); Mon, 21 Mar 2022 11:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348660AbiCUPzh (ORCPT ); Mon, 21 Mar 2022 11:55:37 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE00565435; Mon, 21 Mar 2022 08:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1647878051; x=1679414051; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qYChFPbDAfyBQGSHc8vlsYhPBC61xJmrzqLud48m8FQ=; b=MAN3gXI/5WHsRPi35ZTlgfjzosPoBIsFc5h41Nj9d1PIB16ltvQBQmU6 NZCWDSlYscBG9CAIeGDiM4x6Ko3uJfWQL3NnNGdwxLMG8oHbdUPFHDQPZ 6EjtrIpsyNoKmkRxmgbMYMMaIKr7g/jxJAbrIcsiUD+Cm+EJUwZEwsuk5 si/VNu0o3MzIJqUV1Fyu0UExPooaKTJJ4r7v+LvrsK/J1nUc6x7JvuTTn bIOgwNKoAD26DzzR/LHAQhFJRcfPwT2phwr8ZznfjRp8smPpxRsvlbKJy 7ZSV9p8v3Kzw7u9Ib2oA51GyfqxF/L9l2cuglAbFmaCmjhWPBb2zsPDBb Q==; X-IronPort-AV: E=Sophos;i="5.90,199,1643698800"; d="scan'208";a="89617544" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Mar 2022 08:54:10 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Mar 2022 08:54:10 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Mar 2022 08:54:04 -0700 From: Arun Ramadoss To: , CC: Paolo Abeni , Jakub Kicinski , "David S. Miller" , Russell King , Heiner Kallweit , Andrew Lunn , Subject: [RFC Patch net-next 1/3] net: phy: lan87xx: added lan87xx_update_link routine Date: Mon, 21 Mar 2022 21:23:35 +0530 Message-ID: <20220321155337.16260-2-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220321155337.16260-1-arun.ramadoss@microchip.com> References: <20220321155337.16260-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The LAN87xx phydev->link has been updated via lan87xx_read_status routine. To get only the recent phydev->link status instead of various other status, refactored the code to have separate lan87xx_update_link routine. Signed-off-by: Arun Ramadoss --- drivers/net/phy/microchip_t1.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c index 389df3f4293c..bb4514254adc 100644 --- a/drivers/net/phy/microchip_t1.c +++ b/drivers/net/phy/microchip_t1.c @@ -674,7 +674,7 @@ static int lan87xx_cable_test_get_status(struct phy_device *phydev, return 0; } -static int lan87xx_read_status(struct phy_device *phydev) +static int lan87xx_update_link(struct phy_device *phydev) { int rc = 0; @@ -687,6 +687,17 @@ static int lan87xx_read_status(struct phy_device *phydev) else phydev->link = 0; + return rc; +} + +static int lan87xx_read_status(struct phy_device *phydev) +{ + int rc = 0; + + rc = lan87xx_update_link(phydev); + if (rc < 0) + return rc; + phydev->speed = SPEED_UNKNOWN; phydev->duplex = DUPLEX_UNKNOWN; phydev->pause = 0; From patchwork Mon Mar 21 15:53:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12787445 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5642DC433F5 for ; Mon, 21 Mar 2022 15:54:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348750AbiCUPzs (ORCPT ); Mon, 21 Mar 2022 11:55:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348791AbiCUPzp (ORCPT ); Mon, 21 Mar 2022 11:55:45 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 856E0A94E5; Mon, 21 Mar 2022 08:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1647878060; x=1679414060; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oFvBuAI3AFTfTX4VEPERgc9VNdNmgIoULtzLNBNUTuU=; b=1ZkJkalU1dQ9o93F8UbyQgi9gXVoYyLvUNW++AkYvhwtUhKJXr10iiXH uEGapbaZC+w6L/Htj6tEBQcXY21h7zMR+Aj9gY9G/ViesVgh08UBnV5q8 6nHN2Yp8/8pfMcO6ly+VV7o60mUNwMQsajM5jpkG1qeu7SmPaEe7lPqUo zin9z8CIxk3oAb9mXLhFeIIZAjjVw7R19KXm6cNgwmSYB1b4ygzVYORjH kIgfPfifntrysrykrADQm8mU1KMVSJ8D6v/T6K4C1xbu90M7YStBzYJZo Mef7aDMWr0cV1yIKXr8JekMDgjfbSlVsAEkn7ScaHwTO2iVIHCPAByo2l A==; X-IronPort-AV: E=Sophos;i="5.90,199,1643698800"; d="scan'208";a="89617579" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Mar 2022 08:54:19 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Mar 2022 08:54:19 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Mar 2022 08:54:14 -0700 From: Arun Ramadoss To: , CC: Paolo Abeni , Jakub Kicinski , "David S. Miller" , Russell King , Heiner Kallweit , Andrew Lunn , Subject: [RFC Patch net-next 2/3] net: phy: lan937x: added PHY_POLL_CABLE_TEST flag Date: Mon, 21 Mar 2022 21:23:36 +0530 Message-ID: <20220321155337.16260-3-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220321155337.16260-1-arun.ramadoss@microchip.com> References: <20220321155337.16260-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Added the phy_poll_cable_test flag for the lan937x phy driver. Tested using command - ethtool --cable-test Signed-off-by: Arun Ramadoss --- drivers/net/phy/microchip_t1.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c index bb4514254adc..2742d71a469f 100644 --- a/drivers/net/phy/microchip_t1.c +++ b/drivers/net/phy/microchip_t1.c @@ -759,6 +759,7 @@ static struct phy_driver microchip_t1_phy_driver[] = { { PHY_ID_MATCH_MODEL(PHY_ID_LAN937X), .name = "Microchip LAN937x T1", + .flags = PHY_POLL_CABLE_TEST, .features = PHY_BASIC_T1_FEATURES, .config_init = lan87xx_config_init, .suspend = genphy_suspend, From patchwork Mon Mar 21 15:53:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Ramadoss X-Patchwork-Id: 12787446 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11037C433F5 for ; Mon, 21 Mar 2022 15:54:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349069AbiCUP4D (ORCPT ); Mon, 21 Mar 2022 11:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349010AbiCUPzy (ORCPT ); Mon, 21 Mar 2022 11:55:54 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E5BE181160; Mon, 21 Mar 2022 08:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1647878068; x=1679414068; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YK/s9M5dM9W+oVehrs/ALR9xtLEfVnh8YMQ1VH2XiPU=; b=VY6DBu0RMLvNuqKRq2RZfQEDdtsnK4ULKnVSbvQt/FVN7AkmX182GhHS M9ZE4+VFyUMYqVec6Yc6PiPvFO3iPsgUq6RtyT1jA6Fha+MAzoSo2fF4S Ra7uNms+fno3JZQX/CJ/0H/Uo/JNN+lw1RBMhR1GjWGr0WfQcXJd6QTVS uCRHubIfuYUTGTd/J4gvjL5ZejtYANUXGj5RSpzfNox3k3Bl9hglgw1ON Jlngsv1y0KfbVqYHWaEIv/UAVxZR9Qrs+KwuES2JP7kaydVa/IFi5eoHJ Jdjq3U80xrA/frbPv9UB5trsMALlYJ8o3IQwdZsxI8PuwlYC2ohuSgtGe w==; X-IronPort-AV: E=Sophos;i="5.90,199,1643698800"; d="scan'208";a="152707589" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 21 Mar 2022 08:54:27 -0700 Received: from chn-vm-ex01.mchp-main.com (10.10.85.143) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Mon, 21 Mar 2022 08:54:27 -0700 Received: from CHE-LT-I17769U.microchip.com (10.10.115.15) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server id 15.1.2375.17 via Frontend Transport; Mon, 21 Mar 2022 08:54:22 -0700 From: Arun Ramadoss To: , CC: Paolo Abeni , Jakub Kicinski , "David S. Miller" , Russell King , Heiner Kallweit , Andrew Lunn , Subject: [RFC Patch net-next 3/3] net: phy: lan87xx: added ethtool SQI support Date: Mon, 21 Mar 2022 21:23:37 +0530 Message-ID: <20220321155337.16260-4-arun.ramadoss@microchip.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220321155337.16260-1-arun.ramadoss@microchip.com> References: <20220321155337.16260-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch add the support for measuring Signal Quality Index for LAN87xx and LAN937x T1 Phy. To get better accuracy of the SQI, readings are measured and its average is calculated. If the link is down, then routine return immediately. Signed-off-by: Arun Ramadoss --- drivers/net/phy/microchip_t1.c | 132 +++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/drivers/net/phy/microchip_t1.c b/drivers/net/phy/microchip_t1.c index 2742d71a469f..ebbf1e8067f6 100644 --- a/drivers/net/phy/microchip_t1.c +++ b/drivers/net/phy/microchip_t1.c @@ -9,6 +9,7 @@ #include #include #include +#include #define PHY_ID_LAN87XX 0x0007c150 #define PHY_ID_LAN937X 0x0007c180 @@ -68,7 +69,14 @@ #define T1_POST_LCK_MUFACT_CFG_REG 0x1C #define T1_TX_RX_FIFO_CFG_REG 0x02 #define T1_TX_LPF_FIR_CFG_REG 0x55 +#define T1_COEF_CLK_PWR_DN_CFG 0x04 +#define T1_COEF_RW_CTL_CFG 0x0D #define T1_SQI_CONFIG_REG 0x2E +#define T1_SQI_CONFIG2_REG 0x4A +#define T1_DCQ_MSE_REG 0xC1 +#define T1_MSE_VLD_MSK BIT(9) +#define T1_DCQ_SQI_REG 0xC3 +#define T1_DCQ_SQI_MSK GENMASK(3, 1) #define T1_MDIO_CONTROL2_REG 0x10 #define T1_INTERRUPT_SOURCE_REG 0x18 #define T1_INTERRUPT2_SOURCE_REG 0x08 @@ -82,6 +90,12 @@ #define T1_MODE_STAT_REG 0x11 #define T1_LINK_UP_MSK BIT(0) +/* SQI defines */ +#define LAN87XX_MAX_SQI 0x07 +#define LAN87XX_SQI_ENTRY 200 +#define SQI_AVG_MIN 40 +#define SQI_AVG_MAX 160 + #define DRIVER_AUTHOR "Nisar Sayed " #define DRIVER_DESC "Microchip LAN87XX/LAN937x T1 PHY driver" @@ -740,6 +754,120 @@ static int lan87xx_config_aneg(struct phy_device *phydev) return rc; } +static int lan87xx_sqi_cmp(const void *a, const void *b) +{ + return *(u16 *)a - *(u16 *)b; +} + +static int lan87xx_get_sqi(struct phy_device *phydev) +{ + u16 sqi_value[LAN87XX_SQI_ENTRY]; + u32 sqi_avg = 0; + int rc; + u8 i; + + rc = lan87xx_update_link(phydev); + if (rc < 0) + return rc; + + if (phydev->link == 0) + return sqi_avg; + + rc = access_ereg(phydev, PHYACC_ATTR_MODE_WRITE, + PHYACC_ATTR_BANK_DSP, T1_COEF_CLK_PWR_DN_CFG, 0x16d6); + if (rc < 0) + return rc; + + /* Enable SQI measurement */ + rc = access_ereg(phydev, PHYACC_ATTR_MODE_WRITE, + PHYACC_ATTR_BANK_DSP, T1_SQI_CONFIG_REG, 0x9572); + if (rc < 0) + return rc; + + /* Enable SQI Method 5 */ + rc = access_ereg(phydev, PHYACC_ATTR_MODE_WRITE, + PHYACC_ATTR_BANK_DSP, T1_SQI_CONFIG2_REG, 0x0001); + if (rc < 0) + return rc; + + /* Below effectively throws away first reading + * required delay before reading DSP. + */ + rc = access_ereg(phydev, PHYACC_ATTR_MODE_WRITE, + PHYACC_ATTR_BANK_DSP, T1_COEF_RW_CTL_CFG, 0x0301); + if (rc < 0) + return rc; + + usleep_range(40, 50); + + for (i = 0; i < LAN87XX_SQI_ENTRY; i++) { + rc = lan87xx_update_link(phydev); + if (rc < 0) + return rc; + + if (phydev->link == 0) + return sqi_avg; + + rc = access_ereg(phydev, PHYACC_ATTR_MODE_WRITE, + PHYACC_ATTR_BANK_DSP, + T1_COEF_RW_CTL_CFG, 0x0301); + if (rc < 0) + return rc; + + rc = access_ereg(phydev, PHYACC_ATTR_MODE_READ, + PHYACC_ATTR_BANK_DSP, T1_DCQ_SQI_REG, 0x0); + if (rc < 0) + return rc; + + sqi_value[i] = FIELD_GET(T1_DCQ_SQI_MSK, rc); + + rc = access_ereg(phydev, PHYACC_ATTR_MODE_READ, + PHYACC_ATTR_BANK_DSP, T1_DCQ_MSE_REG, 0x0); + if (rc < 0) + return rc; + + /* Check valid value. 0 - valid, 1 - Invalid + * if invalid, re-read the value after 250ms + */ + if (FIELD_GET(T1_MSE_VLD_MSK, rc) == 1) { + rc = access_ereg(phydev, PHYACC_ATTR_MODE_WRITE, + PHYACC_ATTR_BANK_DSP, + T1_COEF_RW_CTL_CFG, 0x0301); + if (rc < 0) + return rc; + + msleep(250); + + rc = access_ereg(phydev, PHYACC_ATTR_MODE_READ, + PHYACC_ATTR_BANK_DSP, + T1_DCQ_SQI_REG, 0x0); + if (rc < 0) + return rc; + + sqi_value[i] = FIELD_GET(T1_DCQ_SQI_MSK, rc); + } + } + + /* Sorting SQI values */ + sort(sqi_value, LAN87XX_SQI_ENTRY, sizeof(u16), lan87xx_sqi_cmp, NULL); + + /* Discarding outliers */ + for (i = 0; i < LAN87XX_SQI_ENTRY; i++) { + if (i >= SQI_AVG_MIN && i <= SQI_AVG_MAX) + sqi_avg += sqi_value[i]; + } + + /* Calculating SQI number */ + sqi_avg = DIV_ROUND_UP(sqi_avg, (SQI_AVG_MAX - SQI_AVG_MIN + 1)); + + return sqi_avg; +} + +static int lan87xx_get_sqi_max(struct phy_device *phydev) +{ + return LAN87XX_MAX_SQI; +} + static struct phy_driver microchip_t1_phy_driver[] = { { PHY_ID_MATCH_MODEL(PHY_ID_LAN87XX), @@ -753,6 +881,8 @@ static struct phy_driver microchip_t1_phy_driver[] = { .resume = genphy_resume, .config_aneg = lan87xx_config_aneg, .read_status = lan87xx_read_status, + .get_sqi = lan87xx_get_sqi, + .get_sqi_max = lan87xx_get_sqi_max, .cable_test_start = lan87xx_cable_test_start, .cable_test_get_status = lan87xx_cable_test_get_status, }, @@ -766,6 +896,8 @@ static struct phy_driver microchip_t1_phy_driver[] = { .resume = genphy_resume, .config_aneg = lan87xx_config_aneg, .read_status = lan87xx_read_status, + .get_sqi = lan87xx_get_sqi, + .get_sqi_max = lan87xx_get_sqi_max, .cable_test_start = lan87xx_cable_test_start, .cable_test_get_status = lan87xx_cable_test_get_status, }