Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp249997lqb; Tue, 28 May 2024 14:34:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUkQEcFJDnOVR0YZKG7pd7AHswEdj1v4spAQMlDJB3ahHdWTzi6YeqqvT6qWKaULMr4yqA+l3m5v69Nf0P+7MckiUqd9GApdiwwD73D9w== X-Google-Smtp-Source: AGHT+IGPD3CGKbh4nWL+JsLurv4I7AcfurdSeY++hPXBHg+BgaclovR6H2J7A/HQtXHF/kzmBDdA X-Received: by 2002:a17:906:368a:b0:a5a:542d:ae0a with SMTP id a640c23a62f3a-a6265114fcfmr846593266b.63.1716932041227; Tue, 28 May 2024 14:34:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716932041; cv=pass; d=google.com; s=arc-20160816; b=SHZ/86iFyrZQDH9Z/DWucvhUOkAcd3vgzJb0zrPWYvifT1BpXV4lnILV1oq2LdRZTz VsY08G8gGBhDQu0lIHrBU4PBgh22267dfndVo+dtnHQ33CeDgMF0+JSR7IWaFuer6NJl /PWgDUmi2gIp4+dkXBYVsGMAlPJBowC4WlYU8ZcZID9EYCs41STkOPYc3rcvoyVCK7w5 ZEv1PgCAK0x/PM4Z3SB/I1Fk0XvKhh4ZqhIVeQzmisbZ94n+gC6Go+YYhzk5cQJPFBUQ rAiNn1Ni+jGqz1/6kjTvmZiBFB+Ufw69w8YOLgCG5V5jcTDJa8IxfxZolA6DgcKNEh7g HmEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from:dkim-signature; bh=6vhThz2uHhAOvCrL+Jmx1EoJgVbnrP3onOwtfo9fPd4=; fh=rc3p4XN/cjC7uOCKYLMLy027Ez3rRCYUT6McBLR8/eg=; b=zTDdaytUeR+CouwkCvHojFV5hcKr6/fZDYTxKx2/+M9Mtw4G8UdxtjR2RYZGFOZUZg nsxGRDQpfAYRgYWSqHxp03t/zbo49UBQx9I7wqk3gxtBA1ABAg2pWInlNXIncbm3kNQ8 G1FAnH/bXYhHL+BrRi1MFeSWmaGJjcg2Ww4iZEm4JBrPl53rqdKRAy39EIzFsrZNcyg/ eCEsyLV2Tku48Gw4Z6KBP5fb2wcF8+WmBI1/erCCju8eGAaU9pMmp70fs8qqJlbjKi40 IqOzKZPUG59FIDd7cSYwJDxKUD+Fqmzws2ci36464nuTqR0luLdFD3i2SplpCe4b3UAX qPDA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=CGFebcQl; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-193120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a63437cb47bsi123883966b.996.2024.05.28.14.34.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 14:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=CGFebcQl; arc=pass (i=1 spf=pass spfdomain=microchip.com dkim=pass dkdomain=microchip.com dmarc=pass fromdomain=microchip.com); spf=pass (google.com: domain of linux-kernel+bounces-193120-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193120-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microchip.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F24C01F255F6 for ; Tue, 28 May 2024 21:34:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C49FA17BB1D; Tue, 28 May 2024 21:33:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="CGFebcQl" Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B64F17B414; Tue, 28 May 2024 21:33:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.154.123 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716932031; cv=none; b=B0dXLeNOSBCFjkLuMLJkH4FSkremfgCXzd52B/bLRPDgxCEjRA89pC1ENk4Sl1DPX8dF03A92FcI2pZ/ZDFG4mwNpc2S6GkgRpUkiKM0MdXbCA5PQOTmsiPM09frGDSAC82UnW812v6KhnaAev9i0GScyk2EXmMq2QUTdKJl88Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716932031; c=relaxed/simple; bh=C3NNE7YrkGqYzxJz0dFrHqlrvx3sXS2Sk13NyrD/kkY=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=D5eu1dPqBueuEWq28+DdhyvtMucu+d0hA96+V0ED8jX0aezE65cG2B/HNiwH5RumVJ3yDQpzQ6Qc0QY/XyCzZVluFEwKTvlOc0eUuywhLOQNpy8te600gGmyOnogz8Se5EYhO3LHILn32XdsKtK4ry+4M6BvOW7FmDC598NHLeY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=CGFebcQl; arc=none smtp.client-ip=68.232.154.123 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1716932029; x=1748468029; h=from:to:cc:subject:date:message-id:mime-version; bh=C3NNE7YrkGqYzxJz0dFrHqlrvx3sXS2Sk13NyrD/kkY=; b=CGFebcQlp1jTZmKd292M3uhJuRaKcsIfeKYsD93upm+etILa4lFn7Am8 WmQ58xepOccYQN7A1uluU1rcUQvtu/OT/IA+TNj2iOI6P1vB1FijruJnj Sv2fwqcyvHSksX4wAKmBWy2GhiZW8ze3zYmmpKalTdmRYnbYut2YP6N5q h1idU6v2pO0lDUgRFcSeogS/s7q2xwxDCJxCuMs/0JRapSZxjwslGigy7 qN9wmUSBQxs52Iikx84Y/1l66MDLRFg3AE7aZW5LHXMIiL65xD1cNbNY1 dOQydcI89ZZelCasiMRVR4UU0soEQOnZqLocFisA7v95LOTKeuS1b8D18 g==; X-CSE-ConnectionGUID: 0qU0OGtxR26d9eErQO6dUw== X-CSE-MsgGUID: 7Tjtpp5vTqifS0uytiHkSQ== X-IronPort-AV: E=Sophos;i="6.08,196,1712646000"; d="scan'208";a="194022040" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 May 2024 14:33:48 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 28 May 2024 14:33:39 -0700 Received: from hat-linux.microchip.com (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Tue, 28 May 2024 14:33:38 -0700 From: To: Andrew Lunn , Heiner Kallweit , Russell King , Robert Hancock CC: Vivien Didelot , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , "Jakub Kicinski" , Paolo Abeni , , , , Tristram Ha Subject: [PATCH net] net: phy: micrel: fix KSZ9477 PHY issues after suspend/resume Date: Tue, 28 May 2024 14:37:00 -0700 Message-ID: <1716932220-3622-1-git-send-email-Tristram.Ha@microchip.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain From: Tristram Ha When the PHY is powered up after powered down most of the registers are reset, so the PHY setup code needs to be done again. In addition the interrupt register will need to be setup again so that link status indication works again. Fixes: 26dd2974c5b5 ("net: phy: micrel: Move KSZ9477 errata fixes to PHY driver") Signed-off-by: Tristram Ha --- drivers/net/phy/micrel.c | 60 +++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 2b8f8b7f1517..902d9a262c8a 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -1918,7 +1918,7 @@ static const struct ksz9477_errata_write ksz9477_errata_writes[] = { {0x01, 0x75, 0x0060}, {0x01, 0xd3, 0x7777}, {0x1c, 0x06, 0x3008}, - {0x1c, 0x08, 0x2000}, + {0x1c, 0x08, 0x2001}, /* Transmit waveform amplitude can be improved (1000BASE-T, 100BASE-TX, 10BASE-Te) */ {0x1c, 0x04, 0x00d0}, @@ -1939,7 +1939,7 @@ static const struct ksz9477_errata_write ksz9477_errata_writes[] = { {0x1c, 0x20, 0xeeee}, }; -static int ksz9477_config_init(struct phy_device *phydev) +static int ksz9477_phy_errata(struct phy_device *phydev) { int err; int i; @@ -1967,16 +1967,26 @@ static int ksz9477_config_init(struct phy_device *phydev) return err; } + return err; +} + +static int ksz9477_config_init(struct phy_device *phydev) +{ + int err; + + /* Only KSZ9897 family of switches needs this fix. */ + if ((phydev->phy_id & 0xf) == 1) { + err = ksz9477_phy_errata(phydev); + if (err) + return err; + } + /* According to KSZ9477 Errata DS80000754C (Module 4) all EEE modes * in this switch shall be regarded as broken. */ if (phydev->dev_flags & MICREL_NO_EEE) phydev->eee_broken_modes = -1; - err = genphy_restart_aneg(phydev); - if (err) - return err; - return kszphy_config_init(phydev); } @@ -2085,6 +2095,42 @@ static int kszphy_resume(struct phy_device *phydev) return 0; } +static int ksz9477_resume(struct phy_device *phydev) +{ + int ret; + + /* No need to initialize registers if not powered down. */ + ret = phy_read(phydev, MII_BMCR); + if (ret < 0) + return ret; + if (!(ret & BMCR_PDOWN)) + return 0; + + genphy_resume(phydev); + + /* After switching from power-down to normal mode, an internal global + * reset is automatically generated. Wait a minimum of 1 ms before + * read/write access to the PHY registers. + */ + usleep_range(1000, 2000); + + /* Only KSZ9897 family of switches needs this fix. */ + if ((phydev->phy_id & 0xf) == 1) { + ret = ksz9477_phy_errata(phydev); + if (ret) + return ret; + } + + /* Enable PHY Interrupts */ + if (phy_interrupt_is_valid(phydev)) { + phydev->interrupts = PHY_INTERRUPT_ENABLED; + if (phydev->drv->config_intr) + phydev->drv->config_intr(phydev); + } + + return 0; +} + static int kszphy_probe(struct phy_device *phydev) { const struct kszphy_type *type = phydev->drv->driver_data; @@ -5493,7 +5539,7 @@ static struct phy_driver ksphy_driver[] = { .config_intr = kszphy_config_intr, .handle_interrupt = kszphy_handle_interrupt, .suspend = genphy_suspend, - .resume = genphy_resume, + .resume = ksz9477_resume, .get_features = ksz9477_get_features, } }; -- 2.34.1