Received: by 10.223.176.5 with SMTP id f5csp778327wra; Sat, 3 Feb 2018 10:04:04 -0800 (PST) X-Google-Smtp-Source: AH8x227qcrqNeOvN+OdKBMmsuAsXqOijTpDUing1NT/fmfNN4ttCVdlUhFCPffaUjOF4D0O6C1Gk X-Received: by 10.99.120.134 with SMTP id t128mr18883388pgc.313.1517681044689; Sat, 03 Feb 2018 10:04:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517681044; cv=none; d=google.com; s=arc-20160816; b=Ih/cYjhTKgBiOLMWCCs2i2qga5ynudlkOvrvvjwoXlwTcfetH+fuQSHLdG5jSjSzSY suLdj7Wv6Bm1yes5k8Q0DfGE3+iiQN7KfsjXGeTZQw/JwFLgee8v0iJTfE7dicTqXsb0 XhXKmOYS9R16ye6AzDO0Wp0FSxZ5eNntkRTwJpwimlTYK6qg2r5AsITCaIdqvHfO2+2p Cg2wSlFDBzTf0KE2JqEIoM2Liq26HFwW7/gZz7fmoHwFXc4qQTjkN7e+fV11SWWivB2B dkNFDWqj9Vvu1W1AvDP9a7oVd7ccpcsB8olbrMMEER+I4QS7WZZk2Y1qidWFt19KPHYA OEow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:message-id:date:thread-index:thread-topic:subject :cc:to:from:dkim-signature:arc-authentication-results; bh=VOXOg8lim7za5VekaSi5+JeV4MZR1tQ9XcvmXqvkD5U=; b=nLwnqUAFE5bYgdPw9EG9x9FL46kenik4oSGHVK26d0DcEIb4fIJeQFnZHthHbZWKIC lxnNnbB2LaBWspWJd5bk8k5ISi6r1BP9Fe9zYwHOlsiTGQcasUiRjq87s6ZRhPB8Hi1i OqSzzdDALSUmNuc/V7RFf01Jyx2LYGp8ZZwI0l0C7qUpsdW7iiirH3PKlvZPEZ5MkU7u JaMBxmsQ2e8My4no7JkarHhT6n9FZjIuJrkGY7adrdXHK7BcQj+8IBSCj02ohy8gPYcY l7Rvx5GhsWoJUg/ws72xKS2+tMDUBgdBXfWHX+6X/WJsByh8m7MctnAmg4baWGnvZLwO hHbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=JpT6I89g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e12-v6si4073231pls.381.2018.02.03.10.03.49; Sat, 03 Feb 2018 10:04:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=JpT6I89g; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752688AbeBCSAg (ORCPT + 99 others); Sat, 3 Feb 2018 13:00:36 -0500 Received: from mail-co1nam03on0122.outbound.protection.outlook.com ([104.47.40.122]:24267 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752235AbeBCSA3 (ORCPT ); Sat, 3 Feb 2018 13:00:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=VOXOg8lim7za5VekaSi5+JeV4MZR1tQ9XcvmXqvkD5U=; b=JpT6I89geyqzOBRytCJ7est4y9zLkx8OkMf/uH5pRXUxJfMkAsAN9vuhpmyr/+1xV5a5bIPBjFa6xzeSOjQylFgJiFgFNgqVa+c1qx2+iKpTsDjCkUnNhoM0SDxS+Xkk4OTNHjexQmk6DRilwDp9IrFEHEnCDZVkllM9HWOc8oM= Received: from BL0PR2101MB1027.namprd21.prod.outlook.com (52.132.20.161) by BL0PR2101MB1043.namprd21.prod.outlook.com (52.132.24.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.506.3; Sat, 3 Feb 2018 18:00:26 +0000 Received: from BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9]) by BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9%3]) with mapi id 15.20.0485.006; Sat, 3 Feb 2018 18:00:25 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Russell King , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 001/110] net: phy: fix resume handling Thread-Topic: [PATCH AUTOSEL for 4.14 001/110] net: phy: fix resume handling Thread-Index: AQHTnRjdCvnbE4pOgUe1DKcl1cdl9w== Date: Sat, 3 Feb 2018 18:00:25 +0000 Message-ID: <20180203180015.29073-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BL0PR2101MB1043;7:5ROY2B60DF7+p2QyVyyV2eMNYOW/CU6rKme8fm9EAgh2c6Wbwy6VvORpq6TOK7Mkqaf8E45QmbSd9iGbUAiMvCLmbOStY7560GM6Y+idpOb0aMVwm5u9vhHJJtnDT1QzI8vtDaTuCY3hoCRk52YkQ9HcSNoL4famunWlEQeS/6roQwdPvTKYFRGGMqGIZpml9rx6MoTuIB4DTcZvFJ1pyB5+cuM5SbtrsZx8HHMbIv3W0XUB5OamW8G+lkR9KrC3 x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10019020)(39380400002)(376002)(39860400002)(366004)(346002)(396003)(189003)(199004)(59450400001)(10290500003)(186003)(6486002)(14454004)(1076002)(102836004)(6506007)(26005)(6346003)(66066001)(10090500001)(5250100002)(36756003)(6512007)(2501003)(110136005)(99286004)(54906003)(5890100001)(478600001)(53936002)(72206003)(6436002)(316002)(305945005)(7736002)(2906002)(5660300001)(4326008)(106356001)(86362001)(97736004)(25786009)(22452003)(2900100001)(3846002)(107886003)(8676002)(8936002)(6116002)(3280700002)(105586002)(81156014)(81166006)(3660700001)(86612001)(68736007)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL0PR2101MB1043;H:BL0PR2101MB1027.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: d1603b30-5912-4abf-108a-08d56b3000b2 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:BL0PR2101MB1043; x-ms-traffictypediagnostic: BL0PR2101MB1043: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3231101)(2400082)(944501161)(93006095)(93001095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:BL0PR2101MB1043;BCL:0;PCL:0;RULEID:;SRVR:BL0PR2101MB1043; x-forefront-prvs: 05724A8921 received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: AdRTf/X8c+5eGbAAD5xAteM29aVc1Opq9UL3AoF+GpV6cVOkX1dlggYN15F0Nb2oVx9zz6rQtkPOD5lIuNSGHg== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1603b30-5912-4abf-108a-08d56b3000b2 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2018 18:00:25.5971 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1043 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Russell King [ Upstream commit f5e64032a799d4f54decc7eb6aafcdffb67f9ad9 ] When a PHY has the BMCR_PDOWN bit set, it may decide to ignore writes to other registers, or reset the registers to power-on defaults. Micrel PHYs do this for their interrupt registers. The current structure of phylib tries to enable interrupts before resuming (and releasing) the BMCR_PDOWN bit. This fails, causing Micrel PHYs to stop working after a suspend/resume sequence if they are using interrupts. Fix this by ensuring that the PHY driver resume methods do not take the phydev->lock mutex themselves, but the callers of phy_resume() take that lock. This then allows us to move the call to phy_resume() before we enable interrupts in phy_start(). Signed-off-by: Russell King Reviewed-by: Andrew Lunn Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/phy/at803x.c | 4 ---- drivers/net/phy/phy.c | 9 +++------ drivers/net/phy/phy_device.c | 10 ++++++---- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index 5f93e6add563..e911e4990b20 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -239,14 +239,10 @@ static int at803x_resume(struct phy_device *phydev) { int value; =20 - mutex_lock(&phydev->lock); - value =3D phy_read(phydev, MII_BMCR); value &=3D ~(BMCR_PDOWN | BMCR_ISOLATE); phy_write(phydev, MII_BMCR, value); =20 - mutex_unlock(&phydev->lock); - return 0; } =20 diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 2b1e67bc1e73..ed10d1fc8f59 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -828,7 +828,6 @@ EXPORT_SYMBOL(phy_stop); */ void phy_start(struct phy_device *phydev) { - bool do_resume =3D false; int err =3D 0; =20 mutex_lock(&phydev->lock); @@ -841,6 +840,9 @@ void phy_start(struct phy_device *phydev) phydev->state =3D PHY_UP; break; case PHY_HALTED: + /* if phy was suspended, bring the physical link up again */ + phy_resume(phydev); + /* make sure interrupts are re-enabled for the PHY */ if (phydev->irq !=3D PHY_POLL) { err =3D phy_enable_interrupts(phydev); @@ -849,17 +851,12 @@ void phy_start(struct phy_device *phydev) } =20 phydev->state =3D PHY_RESUMING; - do_resume =3D true; break; default: break; } mutex_unlock(&phydev->lock); =20 - /* if phy was suspended, bring the physical link up again */ - if (do_resume) - phy_resume(phydev); - phy_trigger_machine(phydev, true); } EXPORT_SYMBOL(phy_start); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 67f25ac29025..b15b31ca2618 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -135,7 +135,9 @@ static int mdio_bus_phy_resume(struct device *dev) if (!mdio_bus_phy_may_suspend(phydev)) goto no_resume; =20 + mutex_lock(&phydev->lock); ret =3D phy_resume(phydev); + mutex_unlock(&phydev->lock); if (ret < 0) return ret; =20 @@ -1026,7 +1028,9 @@ int phy_attach_direct(struct net_device *dev, struct = phy_device *phydev, if (err) goto error; =20 + mutex_lock(&phydev->lock); phy_resume(phydev); + mutex_unlock(&phydev->lock); phy_led_triggers_register(phydev); =20 return err; @@ -1157,6 +1161,8 @@ int phy_resume(struct phy_device *phydev) struct phy_driver *phydrv =3D to_phy_driver(phydev->mdio.dev.driver); int ret =3D 0; =20 + WARN_ON(!mutex_is_locked(&phydev->lock)); + if (phydev->drv && phydrv->resume) ret =3D phydrv->resume(phydev); =20 @@ -1639,13 +1645,9 @@ int genphy_resume(struct phy_device *phydev) { int value; =20 - mutex_lock(&phydev->lock); - value =3D phy_read(phydev, MII_BMCR); phy_write(phydev, MII_BMCR, value & ~BMCR_PDOWN); =20 - mutex_unlock(&phydev->lock); - return 0; } EXPORT_SYMBOL(genphy_resume); --=20 2.11.0