From patchwork Thu May 23 01:20:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 1103764 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="CTObZHEY"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 458Wsj6gZPz9s3Z for ; Thu, 23 May 2019 11:20:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729717AbfEWBU5 (ORCPT ); Wed, 22 May 2019 21:20:57 -0400 Received: from mail-eopbgr140053.outbound.protection.outlook.com ([40.107.14.53]:5421 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728620AbfEWBUz (ORCPT ); Wed, 22 May 2019 21:20:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5uAzXV8JMOWsId2yIrQ4zG605K6vTgw7EUDy6poptFc=; b=CTObZHEYA6+NjiMxzoM8mLCdpNd+ffVNN9yHvpvjxAo0JxKeKCRp2M3DVRJfg1q/ehklKnl/juu3fSBcy9m2TiBvJjbxAeoTSnVFjMGNa3zpLkFT+d0H8jWp2TL0BCuVX/0KBX8G+00Gldxz+T4uHl6mJMKhThD9JAEAEDDuLPE= Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com (10.175.24.138) by VI1PR0402MB3677.eurprd04.prod.outlook.com (52.134.15.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.18; Thu, 23 May 2019 01:20:37 +0000 Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053]) by VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053%8]) with mapi id 15.20.1900.020; Thu, 23 May 2019 01:20:37 +0000 From: Ioana Ciornei To: "linux@armlinux.org.uk" , "f.fainelli@gmail.com" , "andrew@lunn.ch" , "hkallweit1@gmail.com" , "maxime.chevallier@bootlin.com" , "olteanv@gmail.com" CC: "netdev@vger.kernel.org" , "davem@davemloft.net" Subject: [RFC PATCH net-next 1/9] net: phy: Add phy_sysfs_create_links helper function Thread-Topic: [RFC PATCH net-next 1/9] net: phy: Add phy_sysfs_create_links helper function Thread-Index: AQHVEQW6ka0B/USdJUSpLPDAdytcPw== Date: Thu, 23 May 2019 01:20:37 +0000 Message-ID: <20190523011958.14944-2-ioana.ciornei@nxp.com> References: <20190523011958.14944-1-ioana.ciornei@nxp.com> In-Reply-To: <20190523011958.14944-1-ioana.ciornei@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::19) To VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ioana.ciornei@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [5.12.225.227] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 180851e6-2db8-4a5d-2bd8-08d6df1cdc6b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR0402MB3677; x-ms-traffictypediagnostic: VI1PR0402MB3677: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2201; x-forefront-prvs: 00462943DE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(346002)(376002)(199004)(189003)(25786009)(6512007)(316002)(2201001)(26005)(186003)(86362001)(2501003)(1076003)(36756003)(71200400001)(256004)(71190400001)(5660300002)(4326008)(66066001)(6486002)(5024004)(6436002)(3846002)(7736002)(305945005)(71446004)(99286004)(52116002)(50226002)(81156014)(8676002)(81166006)(8936002)(54906003)(110136005)(2906002)(6116002)(478600001)(68736007)(102836004)(76176011)(53936002)(486006)(2616005)(66446008)(6506007)(386003)(66946007)(73956011)(66556008)(44832011)(14454004)(476003)(11346002)(66476007)(64756008)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3677; H:VI1PR0402MB2800.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: haFmn2NygSBuC2FbbQkl0aygB7NWIxvsECIC5wtCF1hmRxaeu68ec/F8/YQ/zdAaHNyZaGj4I4M9qMR9X1jZuwpWqNRwv71oKXUUxZUPUqVj6qT93s3V8W4VHpitBJCJsGFukgVCQeKdESv6slomlHfNKRzpwgFeFtfF7hp1TGjHw0Qu0pLTlfoXWJdCiMn1fRvNGTpiKLH0qyOqiJ33405fcArhNy8mo3M3cp5FSpacsewnecNwLYlMebLsICY4hcDjyu6jo6OuucZnA9BNd32Ut9LXkmefGWquztdNIWNJDvjO4c/flHmQOtBTgppOej+WWeyrjQ3S7KsybUsWWlW4kIitA4prrRFH5VwcQ+Jl8HeKx00qkkJ+sGx3sVrtmqPpA/zeQACt7uFFQ/xSyXouuKZ2Ad904jY/1M73Hkc= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 180851e6-2db8-4a5d-2bd8-08d6df1cdc6b X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2019 01:20:37.2685 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3677 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean This is a cosmetic patch that wraps the operation of creating sysfs links between the netdev->phydev and the phydev->attached_dev. This is needed to keep the indentation level in check in a follow-up patch where this function will be guarded against the existence of a phydev->attached_dev. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- drivers/net/phy/phy_device.c | 43 ++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index dcc93a873174..5cb01b9db7b5 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1133,6 +1133,31 @@ void phy_attached_print(struct phy_device *phydev, const char *fmt, ...) } EXPORT_SYMBOL(phy_attached_print); +static void phy_sysfs_create_links(struct phy_device *phydev) +{ + struct net_device *dev = phydev->attached_dev; + int err; + + err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj, + "attached_dev"); + if (err) + return; + + err = sysfs_create_link_nowarn(&dev->dev.kobj, + &phydev->mdio.dev.kobj, + "phydev"); + if (err) { + dev_err(&dev->dev, "could not add device link to %s err %d\n", + kobject_name(&phydev->mdio.dev.kobj), + err); + /* non-fatal - some net drivers can use one netdevice + * with more then one phy + */ + } + + phydev->sysfs_links = true; +} + /** * phy_attach_direct - attach a network device to a given PHY device pointer * @dev: network device to attach @@ -1216,23 +1241,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, */ phydev->sysfs_links = false; - err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj, - "attached_dev"); - if (!err) { - err = sysfs_create_link_nowarn(&dev->dev.kobj, - &phydev->mdio.dev.kobj, - "phydev"); - if (err) { - dev_err(&dev->dev, "could not add device link to %s err %d\n", - kobject_name(&phydev->mdio.dev.kobj), - err); - /* non-fatal - some net drivers can use one netdevice - * with more then one phy - */ - } - - phydev->sysfs_links = true; - } + phy_sysfs_create_links(phydev); phydev->dev_flags = flags; From patchwork Thu May 23 01:20:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 1103760 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="OI553NKk"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 458WsZ6RpTz9s3Z for ; Thu, 23 May 2019 11:20:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729551AbfEWBUs (ORCPT ); Wed, 22 May 2019 21:20:48 -0400 Received: from mail-eopbgr140079.outbound.protection.outlook.com ([40.107.14.79]:16354 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727305AbfEWBUs (ORCPT ); Wed, 22 May 2019 21:20:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BtrS7ZaWGF3HSzSz1MTGpRIeGSJU8vBOmHJ6j+BHJJU=; b=OI553NKkYKvixLDJWhQ5fwS4NFx2iibPwXQtc0T9QaYHtTmsYFDBl9rxo9RHCVhzuGlHJpd8xE2p33LY1b9U4enZg+SC7t1ZiEG620Jb3RZOMO3evmC/m99z28mH4YDE58BMgJnFd+oqztaaigxENa7Lsw1MTee3Ip2yO4E0AQA= Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com (10.175.24.138) by VI1PR0402MB3677.eurprd04.prod.outlook.com (52.134.15.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.18; Thu, 23 May 2019 01:20:38 +0000 Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053]) by VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053%8]) with mapi id 15.20.1900.020; Thu, 23 May 2019 01:20:38 +0000 From: Ioana Ciornei To: "linux@armlinux.org.uk" , "f.fainelli@gmail.com" , "andrew@lunn.ch" , "hkallweit1@gmail.com" , "maxime.chevallier@bootlin.com" , "olteanv@gmail.com" CC: "netdev@vger.kernel.org" , "davem@davemloft.net" , Ioana Ciornei Subject: [RFC PATCH net-next 2/9] net: phy: Guard against the presence of a netdev Thread-Topic: [RFC PATCH net-next 2/9] net: phy: Guard against the presence of a netdev Thread-Index: AQHVEQW66VSOZj2NTUKIRdrxG/7Xxw== Date: Thu, 23 May 2019 01:20:38 +0000 Message-ID: <20190523011958.14944-3-ioana.ciornei@nxp.com> References: <20190523011958.14944-1-ioana.ciornei@nxp.com> In-Reply-To: <20190523011958.14944-1-ioana.ciornei@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::19) To VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ioana.ciornei@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [5.12.225.227] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 2b7071d8-e702-4c11-9a79-08d6df1cdd0a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR0402MB3677; x-ms-traffictypediagnostic: VI1PR0402MB3677: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 00462943DE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(346002)(376002)(199004)(189003)(25786009)(6512007)(316002)(2201001)(26005)(186003)(86362001)(2501003)(1076003)(36756003)(71200400001)(256004)(71190400001)(5660300002)(4326008)(66066001)(6486002)(14444005)(5024004)(6436002)(3846002)(7736002)(305945005)(71446004)(99286004)(52116002)(50226002)(81156014)(8676002)(81166006)(8936002)(54906003)(110136005)(2906002)(6116002)(478600001)(68736007)(102836004)(76176011)(53936002)(486006)(2616005)(66446008)(6506007)(386003)(66946007)(73956011)(66556008)(44832011)(14454004)(476003)(11346002)(66476007)(64756008)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3677; H:VI1PR0402MB2800.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: qIY4kxEHZMA6xNvW+d/e9czURj+8RM7jBTdNMX4N69nxxbydwIobVBM3MQBZJORrbE14DxZNkVw8lbpbDoeZURzYNXQMbzweZjbnVnJ9O7dKOQryNFrtn5tPd5/K074OSPhrrNfbylXbFsTOt2Bge1vKIHMUJ9oWFkD+WKjZdxIkAnMn/dbrREafDx4QWRspYLvYZEHB2a8rEDmoUY2hQZOFOQpFfos/SDr1YinGLixYtGmOVXj/L9exg8Y7B9yq3Z7A1YL0sLLo7KL/oq8QSmPB9mMTHzpvMt8RpDoMvTX6NNh2KJQbNKx4uyWmuipt/3veLu7JuiEt+pp6CnaG9UhAnHqQDWneMP8IQFJayHON0Hm01qlrQIcYqFFI6+GSRmCEYhZ/5McpOCsnkUyeFdRYv6YcqUEuncugZK6IEaE= Content-ID: <1355E22E72533F46A2600ED7F6A88924@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b7071d8-e702-4c11-9a79-08d6df1cdd0a X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2019 01:20:38.3644 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3677 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org A prerequisite for PHYLIB to work in the absence of a struct net_device is to not access pointers to it. Changes are needed in the following areas: - Printing: In some places netdev_err was replaced with phydev_err. - Incrementing reference count to the parent MDIO bus driver: If there is no net device, then the reference count should definitely be incremented since there is no chance that it was an Ethernet driver who registered the MDIO bus. - Sysfs links are not created in case there is no attached_dev. - No netif_carrier_off is done if there is no attached_dev. Signed-off-by: Ioana Ciornei Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- drivers/net/phy/phy_device.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 5cb01b9db7b5..25cc7c33f8dd 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1138,6 +1138,9 @@ static void phy_sysfs_create_links(struct phy_device *phydev) struct net_device *dev = phydev->attached_dev; int err; + if (!dev) + return; + err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj, "attached_dev"); if (err) @@ -1176,9 +1179,9 @@ static void phy_sysfs_create_links(struct phy_device *phydev) int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, u32 flags, phy_interface_t interface) { - struct module *ndev_owner = dev->dev.parent->driver->owner; struct mii_bus *bus = phydev->mdio.bus; struct device *d = &phydev->mdio.dev; + struct module *ndev_owner = NULL; bool using_genphy = false; int err; @@ -1187,8 +1190,10 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, * our own module->refcnt here, otherwise we would not be able to * unload later on. */ + if (dev) + ndev_owner = dev->dev.parent->driver->owner; if (ndev_owner != bus->owner && !try_module_get(bus->owner)) { - dev_err(&dev->dev, "failed to get the bus module\n"); + phydev_err(phydev, "failed to get the bus module\n"); return -EIO; } @@ -1207,7 +1212,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, } if (!try_module_get(d->driver->owner)) { - dev_err(&dev->dev, "failed to get the device driver module\n"); + phydev_err(phydev, "failed to get the device driver module\n"); err = -EIO; goto error_put_device; } @@ -1228,8 +1233,10 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, } phydev->phy_link_change = phy_link_change; - phydev->attached_dev = dev; - dev->phydev = phydev; + if (dev) { + phydev->attached_dev = dev; + dev->phydev = phydev; + } /* Some Ethernet drivers try to connect to a PHY device before * calling register_netdevice() -> netdev_register_kobject() and @@ -1252,7 +1259,8 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, /* Initial carrier state is off as the phy is about to be * (re)initialized. */ - netif_carrier_off(phydev->attached_dev); + if (dev) + netif_carrier_off(phydev->attached_dev); /* Do initial configuration here, now that * we have certain key parameters @@ -1358,16 +1366,19 @@ EXPORT_SYMBOL_GPL(phy_driver_is_genphy_10g); void phy_detach(struct phy_device *phydev) { struct net_device *dev = phydev->attached_dev; - struct module *ndev_owner = dev->dev.parent->driver->owner; + struct module *ndev_owner = NULL; struct mii_bus *bus; if (phydev->sysfs_links) { - sysfs_remove_link(&dev->dev.kobj, "phydev"); + if (dev) + sysfs_remove_link(&dev->dev.kobj, "phydev"); sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev"); } phy_suspend(phydev); - phydev->attached_dev->phydev = NULL; - phydev->attached_dev = NULL; + if (dev) { + phydev->attached_dev->phydev = NULL; + phydev->attached_dev = NULL; + } phydev->phylink = NULL; phy_led_triggers_unregister(phydev); @@ -1390,6 +1401,8 @@ void phy_detach(struct phy_device *phydev) bus = phydev->mdio.bus; put_device(&phydev->mdio.dev); + if (dev) + ndev_owner = dev->dev.parent->driver->owner; if (ndev_owner != bus->owner) module_put(bus->owner); From patchwork Thu May 23 01:20:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 1103761 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="B/JjzN+H"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 458Wsd0gvcz9s3Z for ; Thu, 23 May 2019 11:20:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729609AbfEWBUu (ORCPT ); Wed, 22 May 2019 21:20:50 -0400 Received: from mail-eopbgr140079.outbound.protection.outlook.com ([40.107.14.79]:16354 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729451AbfEWBUt (ORCPT ); Wed, 22 May 2019 21:20:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E4SMmMLBda6rfk6x4+ck/5XTiTZGJvii0y1lKndeIj4=; b=B/JjzN+HAwiBe7IdiDQ4DCBSF4k29uKabvLlGfjC9FbsHTmpTfjpulXl/4VZaxe1rNUEwgs5MmsPD9rpg+ii9xUZ23XRK23gRDLpfr23D6ZeVaQBaLadBuUQ1obr7y4XlgDxBLCddqKlFbH5xmNw/J5FtzY0+WrBBo1x3doiNAY= Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com (10.175.24.138) by VI1PR0402MB3677.eurprd04.prod.outlook.com (52.134.15.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.18; Thu, 23 May 2019 01:20:39 +0000 Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053]) by VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053%8]) with mapi id 15.20.1900.020; Thu, 23 May 2019 01:20:39 +0000 From: Ioana Ciornei To: "linux@armlinux.org.uk" , "f.fainelli@gmail.com" , "andrew@lunn.ch" , "hkallweit1@gmail.com" , "maxime.chevallier@bootlin.com" , "olteanv@gmail.com" CC: "netdev@vger.kernel.org" , "davem@davemloft.net" , Ioana Ciornei Subject: [RFC PATCH net-next 3/9] net: phy: Add phy_standalone sysfs entry Thread-Topic: [RFC PATCH net-next 3/9] net: phy: Add phy_standalone sysfs entry Thread-Index: AQHVEQW7wDCFQR6sQUWynBU/WT9lsQ== Date: Thu, 23 May 2019 01:20:39 +0000 Message-ID: <20190523011958.14944-4-ioana.ciornei@nxp.com> References: <20190523011958.14944-1-ioana.ciornei@nxp.com> In-Reply-To: <20190523011958.14944-1-ioana.ciornei@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::19) To VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ioana.ciornei@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [5.12.225.227] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bc7e1da0-b263-4fdc-2eae-08d6df1cdd77 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR0402MB3677; x-ms-traffictypediagnostic: VI1PR0402MB3677: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1265; x-forefront-prvs: 00462943DE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(346002)(376002)(199004)(189003)(25786009)(6512007)(316002)(2201001)(26005)(186003)(86362001)(2501003)(1076003)(36756003)(71200400001)(256004)(71190400001)(5660300002)(4326008)(66066001)(6486002)(5024004)(6436002)(3846002)(7736002)(305945005)(71446004)(99286004)(52116002)(50226002)(81156014)(8676002)(81166006)(8936002)(54906003)(110136005)(2906002)(6116002)(478600001)(68736007)(102836004)(76176011)(53936002)(486006)(2616005)(66446008)(6506007)(386003)(66946007)(73956011)(66556008)(44832011)(14454004)(476003)(11346002)(66476007)(64756008)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3677; H:VI1PR0402MB2800.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 7lB4HZV4stnPEkom/G9P/PgHso//Ro3phxVzfGfaLxyWzU10WJttRM1JZl8di7nPif9gawWIoajXNpmbSleCEYbgPG/RT9iudaXhVp8GB9mWi9X4pfmc6QYmKM0vnuLdGdXgYPVao+IULYgF6IeTF56gn2nRB6P9lW3aY80SBThSc60o0HtpTkB0CHcLWTVNMwOowJBOpXQGIPrTTc7bJcflLTl+hlJ5awt+or3k6HufE+Wmuv+QVXT+SaI7i608uR5qms9rXaBPnk/yiSXEYTJ+8pDK/ne9IzLpjkGK786mMkpEkHyc0eNZ9asSRevale985t1HVvWLvrJegt1ZYsNrtNy4ObzxvQBXZVVhGdm+OqmQK3OSU9ZjOBXXPaxGjWPpwGjdSaj94IKjJwA2LJSwQ7o/3ei/JqoGtzi/KmU= Content-ID: <33E3276CA698984A85EE38FC362475A8@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc7e1da0-b263-4fdc-2eae-08d6df1cdd77 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2019 01:20:39.1651 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3677 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Export a phy_standalone device attribute that is meant to give the indication that this PHY lacks an attached_dev and its corresponding sysfs link. Signed-off-by: Ioana Ciornei --- drivers/net/phy/phy_device.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 25cc7c33f8dd..30e0e73d5f86 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -537,10 +537,22 @@ phy_has_fixups_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(phy_has_fixups); +static ssize_t phy_standalone_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct phy_device *phydev = to_phy_device(dev); + + return sprintf(buf, "%d\n", !phydev->attached_dev); +} + +static DEVICE_ATTR_RO(phy_standalone); + static struct attribute *phy_dev_attrs[] = { &dev_attr_phy_id.attr, &dev_attr_phy_interface.attr, &dev_attr_phy_has_fixups.attr, + &dev_attr_phy_standalone.attr, NULL, }; ATTRIBUTE_GROUPS(phy_dev); From patchwork Thu May 23 01:20:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 1103762 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="HHoEqwbr"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 458Wsd71jxz9s5c for ; Thu, 23 May 2019 11:20:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729654AbfEWBUw (ORCPT ); Wed, 22 May 2019 21:20:52 -0400 Received: from mail-eopbgr140079.outbound.protection.outlook.com ([40.107.14.79]:16354 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727305AbfEWBUv (ORCPT ); Wed, 22 May 2019 21:20:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wm2oYE1rcUJkQj55BQHORYpyZsRACuN8y4ewln+WphY=; b=HHoEqwbrj0ibTykziagXE6IXlJQb3oKUAEblq5dqRQRrGBHnRN4jLlq3iK2rw7cvmzLwe9Sc9I0jLI15wbx6OvAQxTX8vbwrIxSIQMsQdKnRPhbbuafV+RGUZTG3ZMORlgp8+RwtTfksjM7cyIDDub3rMsMHp17bCg7yGH9KrxY= Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com (10.175.24.138) by VI1PR0402MB3677.eurprd04.prod.outlook.com (52.134.15.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.18; Thu, 23 May 2019 01:20:39 +0000 Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053]) by VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053%8]) with mapi id 15.20.1900.020; Thu, 23 May 2019 01:20:39 +0000 From: Ioana Ciornei To: "linux@armlinux.org.uk" , "f.fainelli@gmail.com" , "andrew@lunn.ch" , "hkallweit1@gmail.com" , "maxime.chevallier@bootlin.com" , "olteanv@gmail.com" CC: "netdev@vger.kernel.org" , "davem@davemloft.net" , Ioana Ciornei Subject: [RFC PATCH net-next 4/9] net: phylink: Add phylink_mac_link_{up, down} wrapper functions Thread-Topic: [RFC PATCH net-next 4/9] net: phylink: Add phylink_mac_link_{up,down} wrapper functions Thread-Index: AQHVEQW75UFmDToYo0yQOLuc7h77EA== Date: Thu, 23 May 2019 01:20:39 +0000 Message-ID: <20190523011958.14944-5-ioana.ciornei@nxp.com> References: <20190523011958.14944-1-ioana.ciornei@nxp.com> In-Reply-To: <20190523011958.14944-1-ioana.ciornei@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::19) To VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ioana.ciornei@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [5.12.225.227] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ecc1ff6e-5b74-4caa-4c65-08d6df1cddee x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR0402MB3677; x-ms-traffictypediagnostic: VI1PR0402MB3677: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1443; x-forefront-prvs: 00462943DE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(346002)(376002)(199004)(189003)(25786009)(6512007)(316002)(2201001)(26005)(186003)(86362001)(2501003)(1076003)(36756003)(71200400001)(256004)(71190400001)(5660300002)(4326008)(66066001)(6486002)(6436002)(3846002)(7736002)(305945005)(71446004)(99286004)(52116002)(50226002)(81156014)(8676002)(81166006)(8936002)(54906003)(110136005)(2906002)(6116002)(478600001)(68736007)(102836004)(76176011)(53936002)(486006)(2616005)(66446008)(6506007)(386003)(66946007)(73956011)(66556008)(44832011)(14454004)(476003)(11346002)(66476007)(64756008)(446003)(142933001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3677; H:VI1PR0402MB2800.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: ZUkfXhcp6Tl6S4dIYrpCW9TWeSCxZYAfOfLXfq4FbatoNQO9lfekoSc1dtzWFWTVAZngA2rFwIErh+o4VkMYB1DKzJ0MTooEablF7yy6YGPOszl7H382t6uHo8N7FagIbSdWXLy1F4LsnuzOZmsuSmwjn9GSEMiX10VNmGfdWEOHtPTQVDNojsSom/Kp26mJxu4ZU1fmx1DUmUUQe25H7goDIlaHU0gLK/PEAZIeZgg8bHdQep9SY9uHScG2x0dzCGoTCqVPykeTpJaX1Eh2rUGIs8+QUDxcR3nzm9f5qLmA67R167lqXuW64U1jd5heQ2nsbhOH9OF7jRmkOV0SGJKDRT6x1oIROnRbol8hzaeFWLpcxRQuQxDCRWKMxMRkqlsrWOkl1hCV4AiEopDVrm/RDKkWspiZkhye+XZBx0M= Content-ID: <5B6B6497E921FB42AE4BE7BC86F96F8C@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ecc1ff6e-5b74-4caa-4c65-08d6df1cddee X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2019 01:20:39.8657 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3677 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is a cosmetic patch that reduces the clutter in phylink_resolve around calling the .mac_link_up/.mac_link_down driver callbacks. In a further patch this logic will be extended to emit notifications in case a net device does not exist. Signed-off-by: Ioana Ciornei Reviewed-by: Florian Fainelli --- drivers/net/phy/phylink.c | 50 +++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 89750c7dfd6f..68cfe31240cc 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -395,6 +395,34 @@ static const char *phylink_pause_to_str(int pause) } } +static void phylink_mac_link_up(struct phylink *pl, + struct phylink_link_state link_state) +{ + struct net_device *ndev = pl->netdev; + + pl->ops->mac_link_up(ndev, pl->link_an_mode, + pl->phy_state.interface, + pl->phydev); + + netif_carrier_on(ndev); + + netdev_info(ndev, + "Link is Up - %s/%s - flow control %s\n", + phy_speed_to_str(link_state.speed), + phy_duplex_to_str(link_state.duplex), + phylink_pause_to_str(link_state.pause)); +} + +static void phylink_mac_link_down(struct phylink *pl) +{ + struct net_device *ndev = pl->netdev; + + netif_carrier_off(ndev); + pl->ops->mac_link_down(ndev, pl->link_an_mode, + pl->phy_state.interface); + netdev_info(ndev, "Link is Down\n"); +} + static void phylink_resolve(struct work_struct *w) { struct phylink *pl = container_of(w, struct phylink, resolve); @@ -450,24 +478,10 @@ static void phylink_resolve(struct work_struct *w) } if (link_state.link != netif_carrier_ok(ndev)) { - if (!link_state.link) { - netif_carrier_off(ndev); - pl->ops->mac_link_down(ndev, pl->link_an_mode, - pl->phy_state.interface); - netdev_info(ndev, "Link is Down\n"); - } else { - pl->ops->mac_link_up(ndev, pl->link_an_mode, - pl->phy_state.interface, - pl->phydev); - - netif_carrier_on(ndev); - - netdev_info(ndev, - "Link is Up - %s/%s - flow control %s\n", - phy_speed_to_str(link_state.speed), - phy_duplex_to_str(link_state.duplex), - phylink_pause_to_str(link_state.pause)); - } + if (!link_state.link) + phylink_mac_link_down(pl); + else + phylink_mac_link_up(pl, link_state); } if (!link_state.link && pl->mac_link_dropped) { pl->mac_link_dropped = false; From patchwork Thu May 23 01:20:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 1103763 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="qv2FtLWm"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 458Wsh4TXmz9s3Z for ; Thu, 23 May 2019 11:20:56 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729679AbfEWBUz (ORCPT ); Wed, 22 May 2019 21:20:55 -0400 Received: from mail-eopbgr140079.outbound.protection.outlook.com ([40.107.14.79]:16354 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729451AbfEWBUy (ORCPT ); Wed, 22 May 2019 21:20:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AssAJrGNL8nRQXoHd1zgVg3ofuOLLb0yrJNgF9SXLjU=; b=qv2FtLWmZbCLKMAU9NG7m0oKKrHpaoV2eIukSYl7hEVrFnbuAC6WdtwX1LC7+mpsWiWC4PuO9yx9Tx4e1hWFDm4xuFsyqjeo32eE1FV1033B6e8k4j8kyzkMEUGEsyAEb/N3F1jDeldLhIwE/3+IaeTuAW7amf/rKC/QJJtxxqg= Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com (10.175.24.138) by VI1PR0402MB3677.eurprd04.prod.outlook.com (52.134.15.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.18; Thu, 23 May 2019 01:20:40 +0000 Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053]) by VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053%8]) with mapi id 15.20.1900.020; Thu, 23 May 2019 01:20:40 +0000 From: Ioana Ciornei To: "linux@armlinux.org.uk" , "f.fainelli@gmail.com" , "andrew@lunn.ch" , "hkallweit1@gmail.com" , "maxime.chevallier@bootlin.com" , "olteanv@gmail.com" CC: "netdev@vger.kernel.org" , "davem@davemloft.net" , Ioana Ciornei Subject: [RFC PATCH net-next 5/9] net: phylink: Add phylink_create_raw Thread-Topic: [RFC PATCH net-next 5/9] net: phylink: Add phylink_create_raw Thread-Index: AQHVEQW8O+LbHNLMy02dz0XkU/eeIQ== Date: Thu, 23 May 2019 01:20:40 +0000 Message-ID: <20190523011958.14944-6-ioana.ciornei@nxp.com> References: <20190523011958.14944-1-ioana.ciornei@nxp.com> In-Reply-To: <20190523011958.14944-1-ioana.ciornei@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::19) To VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ioana.ciornei@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [5.12.225.227] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c40025e5-06a6-42d2-80bc-08d6df1cde59 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR0402MB3677; x-ms-traffictypediagnostic: VI1PR0402MB3677: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:462; x-forefront-prvs: 00462943DE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(346002)(376002)(199004)(189003)(25786009)(6512007)(316002)(2201001)(26005)(186003)(86362001)(2501003)(30864003)(1076003)(36756003)(71200400001)(256004)(71190400001)(5660300002)(4326008)(66066001)(6486002)(14444005)(6436002)(3846002)(7736002)(305945005)(71446004)(99286004)(52116002)(50226002)(81156014)(8676002)(81166006)(8936002)(54906003)(110136005)(2906002)(6116002)(478600001)(68736007)(102836004)(76176011)(53936002)(486006)(2616005)(66446008)(6506007)(386003)(66946007)(73956011)(66556008)(44832011)(14454004)(476003)(11346002)(66476007)(64756008)(446003)(309714004); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3677; H:VI1PR0402MB2800.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 1oxLQ/4O+CXE1gfmF90yaiF05F3gxn5mIdK9v9kjDsOiTUL+lwNZTz6dqc+/Q7uHakvbIPB7ClHfUJ4bMi/JY8TH4omiItvD2ctCMjyTMq5QCXSYbzkWqFjTb/OjRwNhspYV+ei6DxR/ZGH3JXNptxGui6x8n+MiiFxHfXmMC1p4hQ7SgO5yClZ4Zx7KKg9g3h+fBBSsMimUtk1/HL3fUPHpFlkiPIITds5K9OCu57aK4GiUUkAyRKV04lsU89o5VWFcLaA5Ox6Icnd3KFFj6OCyI2ouOT/q1cYrM4ozQfyWg0RLta6sz9DR4/5E/DVEqsBhHqSAFNir48u0GYrHtZ3HRhwhd9WsdHVUNJjViF+TP0ylAJTrMx0J8ZPOD4XgenRA8UlnSoVf1Kj6nox+wuflD7//plj1K7gw2s/VECQ= Content-ID: <61D3FD4078656942A67DA5088A845916@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c40025e5-06a6-42d2-80bc-08d6df1cde59 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2019 01:20:40.5923 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3677 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This adds a new entry point to PHYLINK that does not require a net_device structure. The main intended use are DSA ports that do not have net devices registered for them (mainly because doing so would be redundant - see Documentation/networking/dsa/dsa.rst for details). So far DSA has been using PHYLIB fixed PHYs for these ports, driven manually with genphy instead of starting a full PHY state machine, but this does not scale well when there are actual PHYs that need a driver on those ports, or when a fixed-link is requested in DT that has a speed unsupported by the fixed PHY C22 emulation (such as SGMII-2500). The proposed solution comes in the form of a notifier chain owned by the PHYLINK instance, and the passing of phylink_notifier_info structures back to the driver through a blocking notifier call. The event API exposed by the new notifier mechanism is a 1:1 mapping to the existing PHYLINK mac_ops, plus the PHYLINK fixed-link callback. Both the standard phylink_create() function, as well as its raw variant, call the same underlying function which initializes either the netdev field or the notifier block of the PHYLINK instance. All PHYLINK driver callbacks have been extended to call the notifier chain in case the instance is a raw one. Signed-off-by: Ioana Ciornei Signed-off-by: Vladimir Oltean --- drivers/net/phy/phylink.c | 189 ++++++++++++++++++++++++++++++-------- include/linux/phylink.h | 21 +++++ 2 files changed, 174 insertions(+), 36 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 68cfe31240cc..7b6b233c1a07 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "sfp.h" #include "swphy.h" @@ -41,6 +42,8 @@ struct phylink { /* private: */ struct net_device *netdev; const struct phylink_mac_ops *ops; + struct notifier_block *nb; + struct blocking_notifier_head notifier_chain; unsigned long phylink_disable_state; /* bitmask of disables */ struct phy_device *phydev; @@ -111,7 +114,16 @@ static const char *phylink_an_mode_str(unsigned int mode) static int phylink_validate(struct phylink *pl, unsigned long *supported, struct phylink_link_state *state) { - pl->ops->validate(pl->netdev, supported, state); + struct phylink_notifier_info info = { + .supported = supported, + .state = state, + }; + + if (pl->ops) + pl->ops->validate(pl->netdev, supported, state); + else + blocking_notifier_call_chain(&pl->notifier_chain, + PHYLINK_VALIDATE, &info); return phylink_is_empty_linkmode(supported) ? -EINVAL : 0; } @@ -290,6 +302,12 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode) static void phylink_mac_config(struct phylink *pl, const struct phylink_link_state *state) { + struct phylink_notifier_info info = { + .link_an_mode = pl->link_an_mode, + /* Discard const pointer */ + .state = (struct phylink_link_state *)state, + }; + netdev_dbg(pl->netdev, "%s: mode=%s/%s/%s/%s adv=%*pb pause=%02x link=%u an=%u\n", __func__, phylink_an_mode_str(pl->link_an_mode), @@ -299,7 +317,12 @@ static void phylink_mac_config(struct phylink *pl, __ETHTOOL_LINK_MODE_MASK_NBITS, state->advertising, state->pause, state->link, state->an_enabled); - pl->ops->mac_config(pl->netdev, pl->link_an_mode, state); + if (pl->ops) + pl->ops->mac_config(pl->netdev, pl->link_an_mode, state); + else + blocking_notifier_call_chain(&pl->notifier_chain, + PHYLINK_MAC_CONFIG, &info); + } static void phylink_mac_config_up(struct phylink *pl, @@ -311,13 +334,22 @@ static void phylink_mac_config_up(struct phylink *pl, static void phylink_mac_an_restart(struct phylink *pl) { - if (pl->link_config.an_enabled && - phy_interface_mode_is_8023z(pl->link_config.interface)) + if (!pl->link_config.an_enabled && + !phy_interface_mode_is_8023z(pl->link_config.interface)) + return; + + if (pl->ops) pl->ops->mac_an_restart(pl->netdev); + else + blocking_notifier_call_chain(&pl->notifier_chain, + PHYLINK_MAC_AN_RESTART, NULL); } static int phylink_get_mac_state(struct phylink *pl, struct phylink_link_state *state) { + struct phylink_notifier_info info = { + .state = state, + }; struct net_device *ndev = pl->netdev; linkmode_copy(state->advertising, pl->link_config.advertising); @@ -330,7 +362,12 @@ static int phylink_get_mac_state(struct phylink *pl, struct phylink_link_state * state->an_complete = 0; state->link = 1; - return pl->ops->mac_link_state(ndev, state); + if (pl->ops) + return pl->ops->mac_link_state(ndev, state); + else + return blocking_notifier_call_chain(&pl->notifier_chain, + PHYLINK_MAC_LINK_STATE, + &info); } /* The fixed state is... fixed except for the link state, @@ -338,9 +375,17 @@ static int phylink_get_mac_state(struct phylink *pl, struct phylink_link_state * */ static void phylink_get_fixed_state(struct phylink *pl, struct phylink_link_state *state) { + struct phylink_notifier_info info = { + .state = state, + }; + *state = pl->link_config; if (pl->get_fixed_state) pl->get_fixed_state(pl->netdev, state); + else if (pl->nb) + blocking_notifier_call_chain(&pl->notifier_chain, + PHYLINK_GET_FIXED_STATE, + &info); else if (pl->link_gpio) state->link = !!gpiod_get_value_cansleep(pl->link_gpio); } @@ -399,28 +444,54 @@ static void phylink_mac_link_up(struct phylink *pl, struct phylink_link_state link_state) { struct net_device *ndev = pl->netdev; + struct phylink_notifier_info info = { + .link_an_mode = pl->link_an_mode, + .interface = pl->phy_state.interface, + .phydev = pl->phydev, + }; - pl->ops->mac_link_up(ndev, pl->link_an_mode, + if (pl->ops) { + pl->ops->mac_link_up(ndev, pl->link_an_mode, pl->phy_state.interface, pl->phydev); - netif_carrier_on(ndev); + netif_carrier_on(ndev); - netdev_info(ndev, - "Link is Up - %s/%s - flow control %s\n", - phy_speed_to_str(link_state.speed), - phy_duplex_to_str(link_state.duplex), - phylink_pause_to_str(link_state.pause)); + netdev_info(ndev, + "Link is Up - %s/%s - flow control %s\n", + phy_speed_to_str(link_state.speed), + phy_duplex_to_str(link_state.duplex), + phylink_pause_to_str(link_state.pause)); + } else { + blocking_notifier_call_chain(&pl->notifier_chain, + PHYLINK_MAC_LINK_UP, &info); + phydev_info(pl->phydev, + "Link is Up - %s/%s - flow control %s\n", + phy_speed_to_str(link_state.speed), + phy_duplex_to_str(link_state.duplex), + phylink_pause_to_str(link_state.pause)); + } } static void phylink_mac_link_down(struct phylink *pl) { struct net_device *ndev = pl->netdev; + struct phylink_notifier_info info = { + .link_an_mode = pl->link_an_mode, + .interface = pl->phy_state.interface, + .phydev = pl->phydev, + }; - netif_carrier_off(ndev); - pl->ops->mac_link_down(ndev, pl->link_an_mode, + if (pl->ops) { + netif_carrier_off(ndev); + pl->ops->mac_link_down(ndev, pl->link_an_mode, pl->phy_state.interface); - netdev_info(ndev, "Link is Down\n"); + netdev_info(ndev, "Link is Down\n"); + } else { + blocking_notifier_call_chain(&pl->notifier_chain, + PHYLINK_MAC_LINK_DOWN, &info); + phydev_info(pl->phydev, "Link is Down\n"); + } } static void phylink_resolve(struct work_struct *w) @@ -477,7 +548,10 @@ static void phylink_resolve(struct work_struct *w) } } - if (link_state.link != netif_carrier_ok(ndev)) { + /* Take the branch without checking the carrier status + * if there is no netdevice. + */ + if (!pl->ops || link_state.link != netif_carrier_ok(ndev)) { if (!link_state.link) phylink_mac_link_down(pl); else @@ -546,24 +620,12 @@ static int phylink_register_sfp(struct phylink *pl, return 0; } -/** - * phylink_create() - create a phylink instance - * @ndev: a pointer to the &struct net_device - * @fwnode: a pointer to a &struct fwnode_handle describing the network - * interface - * @iface: the desired link mode defined by &typedef phy_interface_t - * @ops: a pointer to a &struct phylink_mac_ops for the MAC. - * - * Create a new phylink instance, and parse the link parameters found in @np. - * This will parse in-band modes, fixed-link or SFP configuration. - * - * Returns a pointer to a &struct phylink, or an error-pointer value. Users - * must use IS_ERR() to check for errors from this function. - */ -struct phylink *phylink_create(struct net_device *ndev, - struct fwnode_handle *fwnode, - phy_interface_t iface, - const struct phylink_mac_ops *ops) +static inline struct phylink * +__phylink_create_raw(struct net_device *ndev, + struct notifier_block *nb, + struct fwnode_handle *fwnode, + phy_interface_t iface, + const struct phylink_mac_ops *ops) { struct phylink *pl; int ret; @@ -574,7 +636,17 @@ struct phylink *phylink_create(struct net_device *ndev, mutex_init(&pl->state_mutex); INIT_WORK(&pl->resolve, phylink_resolve); - pl->netdev = ndev; + + if (ndev) { + pl->netdev = ndev; + } else if (nb) { + BLOCKING_INIT_NOTIFIER_HEAD(&pl->notifier_chain); + blocking_notifier_chain_register(&pl->notifier_chain, nb); + pl->nb = nb; + } else { + return ERR_PTR(-EINVAL); + } + pl->phy_state.interface = iface; pl->link_interface = iface; if (iface == PHY_INTERFACE_MODE_MOCA) @@ -616,8 +688,52 @@ struct phylink *phylink_create(struct net_device *ndev, return pl; } + +/** + * phylink_create() - create a phylink instance + * @ndev: a pointer to the &struct net_device + * @fwnode: a pointer to a &struct fwnode_handle describing the network + * interface + * @iface: the desired link mode defined by &typedef phy_interface_t + * @ops: a pointer to a &struct phylink_mac_ops for the MAC. + * + * Create a new phylink instance, and parse the link parameters found in @np. + * This will parse in-band modes, fixed-link or SFP configuration. + * + * Returns a pointer to a &struct phylink, or an error-pointer value. Users + * must use IS_ERR() to check for errors from this function. + */ +struct phylink *phylink_create(struct net_device *ndev, + struct fwnode_handle *fwnode, + phy_interface_t iface, + const struct phylink_mac_ops *ops) +{ + return __phylink_create_raw(ndev, NULL, fwnode, iface, ops); +} EXPORT_SYMBOL_GPL(phylink_create); +/** + * phylink_create_raw() - create a raw phylink instance + * @nb: a pointer to a struct notifier_block which which will be called on + * on phylink events + * @fwnode: a pointer to a &struct fwnode_handle describing the network + * interface + * @iface: the desired link mode defined by &typedef phy_interface_t + * + * Create a new raw phylink instance, and parse the link parameters found in + * @np. This will parse in-band modes, fixed-link or SFP configuration. + * + * Returns a pointer to a &struct phylink, or an error-pointer value. Users + * must use IS_ERR() to check for errors from this function. + */ +struct phylink *phylink_create_raw(struct notifier_block *nb, + struct fwnode_handle *fwnode, + phy_interface_t iface) +{ + return __phylink_create_raw(NULL, nb, fwnode, iface, NULL); +} +EXPORT_SYMBOL_GPL(phylink_create_raw); + /** * phylink_destroy() - cleanup and destroy the phylink instance * @pl: a pointer to a &struct phylink returned from phylink_create() @@ -909,7 +1025,8 @@ void phylink_start(struct phylink *pl) phy_modes(pl->link_config.interface)); /* Always set the carrier off */ - netif_carrier_off(pl->netdev); + if (pl->netdev) + netif_carrier_off(pl->netdev); /* Apply the link configuration to the MAC when starting. This allows * a fixed-link to start with the correct parameters, and also diff --git a/include/linux/phylink.h b/include/linux/phylink.h index 6411c624f63a..d171156eab4e 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -54,6 +54,24 @@ struct phylink_link_state { unsigned int an_complete:1; }; +enum phylink_cmd { + PHYLINK_VALIDATE = 1, + PHYLINK_MAC_LINK_STATE, + PHYLINK_MAC_AN_RESTART, + PHYLINK_MAC_CONFIG, + PHYLINK_MAC_LINK_DOWN, + PHYLINK_MAC_LINK_UP, + PHYLINK_GET_FIXED_STATE, +}; + +struct phylink_notifier_info { + struct phylink_link_state *state; + unsigned long *supported; + u8 link_an_mode; + phy_interface_t interface; + struct phy_device *phydev; +}; + /** * struct phylink_mac_ops - MAC operations structure. * @validate: Validate and update the link configuration. @@ -200,6 +218,9 @@ void mac_link_up(struct net_device *ndev, unsigned int mode, struct phylink *phylink_create(struct net_device *, struct fwnode_handle *, phy_interface_t iface, const struct phylink_mac_ops *ops); +struct phylink *phylink_create_raw(struct notifier_block *nb, + struct fwnode_handle *fwnode, + phy_interface_t iface); void phylink_destroy(struct phylink *); int phylink_connect_phy(struct phylink *, struct phy_device *); From patchwork Thu May 23 01:20:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 1103765 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="FOXQv8tR"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 458Wsm3kbpz9s3Z for ; Thu, 23 May 2019 11:21:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729728AbfEWBU7 (ORCPT ); Wed, 22 May 2019 21:20:59 -0400 Received: from mail-eopbgr140079.outbound.protection.outlook.com ([40.107.14.79]:16354 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727305AbfEWBU4 (ORCPT ); Wed, 22 May 2019 21:20:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PZE1HEs855IKvG1tej4rexC+BzZUTipRRpFOrexWja8=; b=FOXQv8tRZ1x6fEQpYOUStxHb8Y+8nBVEjLQxFJlMULkOpe2zzhvgUKoVa854AdBoknhVpDf7PutEqbX23qTHVyjUmqLvppM8Qmv2wNgVpmT7xnBNin46NmEgMr/8c66a0ORJZgFLDqPDjfzNfI9BuWlWuM5sdTWNlQ124PjZ+/E= Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com (10.175.24.138) by VI1PR0402MB3677.eurprd04.prod.outlook.com (52.134.15.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.18; Thu, 23 May 2019 01:20:41 +0000 Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053]) by VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053%8]) with mapi id 15.20.1900.020; Thu, 23 May 2019 01:20:41 +0000 From: Ioana Ciornei To: "linux@armlinux.org.uk" , "f.fainelli@gmail.com" , "andrew@lunn.ch" , "hkallweit1@gmail.com" , "maxime.chevallier@bootlin.com" , "olteanv@gmail.com" CC: "netdev@vger.kernel.org" , "davem@davemloft.net" , Ioana Ciornei Subject: [RFC PATCH net-next 6/9] net: phylink: Make fixed link notifier calls edge-triggered Thread-Topic: [RFC PATCH net-next 6/9] net: phylink: Make fixed link notifier calls edge-triggered Thread-Index: AQHVEQW8B3YiCXx0IE+aCfWuomIaRw== Date: Thu, 23 May 2019 01:20:41 +0000 Message-ID: <20190523011958.14944-7-ioana.ciornei@nxp.com> References: <20190523011958.14944-1-ioana.ciornei@nxp.com> In-Reply-To: <20190523011958.14944-1-ioana.ciornei@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::19) To VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ioana.ciornei@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [5.12.225.227] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 04584d4d-8581-4cb1-9fa5-08d6df1cdec5 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR0402MB3677; x-ms-traffictypediagnostic: VI1PR0402MB3677: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3044; x-forefront-prvs: 00462943DE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(346002)(376002)(199004)(189003)(25786009)(6512007)(316002)(2201001)(26005)(186003)(86362001)(2501003)(1076003)(36756003)(71200400001)(256004)(71190400001)(5660300002)(4326008)(66066001)(6486002)(14444005)(6436002)(3846002)(7736002)(305945005)(71446004)(99286004)(52116002)(50226002)(81156014)(8676002)(81166006)(8936002)(54906003)(110136005)(2906002)(6116002)(478600001)(68736007)(102836004)(76176011)(53936002)(486006)(2616005)(66446008)(6506007)(386003)(66946007)(73956011)(66556008)(44832011)(14454004)(476003)(11346002)(66476007)(64756008)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3677; H:VI1PR0402MB2800.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: em1czy2CJZLfzmplp/W0u5biNfo4CGul8Gf/XflxfK7ODVYgcFYgiMO2Gz7LQ5ktRs8WWZ12SLZBDRpU34b2V3pCl9+xrroFPe0FVmviC4Po9R+6CV4Z6StZ7GCuRWHtzpES3OKvHzO+/S2guTnRbdrZkY5TMcD/74tarT0fspf6dmg6Mgf5PwEcdqBjmbjkBHK+vxR4nyOBApPZRHx3xXLxuj9eMfk+CRd9PiE0WV2vKRkp3DjaQVlK3v+PTBjo5r7WMnXAzys/CVlmTB3x8nKvcrHgM7s4zu6uxZck7ea6DtQ1UeWLnuElHoxBlRC1qr233jiJJqCCE428SNrptyhAqLAVORNkUpglJSp53WhWBWTPRYZ/bcxFkhr+e0w5rlaTVmsRpdU16WNrTRv4ylZVLIVeNDpdsMXmDt9pCvg= Content-ID: <9BA0AA7583D09644B887C91BA1B62D6A@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04584d4d-8581-4cb1-9fa5-08d6df1cdec5 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2019 01:20:41.2318 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3677 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Otherwise .mac_link_up and .mac_link_down on fixed-link interfaces are called every second. On a raw phylink instance we cannot call netdev_carrier_ok for an indication of the last state of the link, so keep track and update this in a new field of the phylink structure. Signed-off-by: Ioana Ciornei --- drivers/net/phy/phylink.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 7b6b233c1a07..3bc91b249990 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -44,6 +44,7 @@ struct phylink { const struct phylink_mac_ops *ops; struct notifier_block *nb; struct blocking_notifier_head notifier_chain; + unsigned int old_link_state:1; unsigned long phylink_disable_state; /* bitmask of disables */ struct phy_device *phydev; @@ -499,6 +500,7 @@ static void phylink_resolve(struct work_struct *w) struct phylink *pl = container_of(w, struct phylink, resolve); struct phylink_link_state link_state; struct net_device *ndev = pl->netdev; + int link_changed; mutex_lock(&pl->state_mutex); if (pl->phylink_disable_state) { @@ -548,10 +550,13 @@ static void phylink_resolve(struct work_struct *w) } } - /* Take the branch without checking the carrier status - * if there is no netdevice. - */ - if (!pl->ops || link_state.link != netif_carrier_ok(ndev)) { + if (pl->ops) + link_changed = (link_state.link != netif_carrier_ok(ndev)); + else + link_changed = (link_state.link != pl->old_link_state); + + if (link_changed) { + pl->old_link_state = link_state.link; if (!link_state.link) phylink_mac_link_down(pl); else From patchwork Thu May 23 01:20:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 1103768 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="bjzjQ21u"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 458Wt02HScz9s3Z for ; Thu, 23 May 2019 11:21:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729817AbfEWBVL (ORCPT ); Wed, 22 May 2019 21:21:11 -0400 Received: from mail-eopbgr140053.outbound.protection.outlook.com ([40.107.14.53]:5421 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728352AbfEWBVL (ORCPT ); Wed, 22 May 2019 21:21:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q2EdBvi7LxmJ6rD1fEByMsJDH0u0sWhBMOApO8R6ChY=; b=bjzjQ21ulZxPQMP1tBMQ3twOQCnl7ZzCZYv+NSaiIREFI+W9lqAPLgcybrajmzvnZ2K4njqKuKLukDh5JSneIO5M/75zffU8QHEP4h9jBgtP2SaQOFghJJZi7/0YFaZdLdtl4aerNeieURTo4X+r3NPBD0p5nDQRpSqJkHLrqn4= Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com (10.175.24.138) by VI1PR0402MB3677.eurprd04.prod.outlook.com (52.134.15.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.18; Thu, 23 May 2019 01:20:42 +0000 Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053]) by VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053%8]) with mapi id 15.20.1900.020; Thu, 23 May 2019 01:20:42 +0000 From: Ioana Ciornei To: "linux@armlinux.org.uk" , "f.fainelli@gmail.com" , "andrew@lunn.ch" , "hkallweit1@gmail.com" , "maxime.chevallier@bootlin.com" , "olteanv@gmail.com" CC: "netdev@vger.kernel.org" , "davem@davemloft.net" , Ioana Ciornei Subject: [RFC PATCH net-next 7/9] net: dsa: Move the phylink driver calls into port.c Thread-Topic: [RFC PATCH net-next 7/9] net: dsa: Move the phylink driver calls into port.c Thread-Index: AQHVEQW865/ec3v+bkaKV7+otlyqGw== Date: Thu, 23 May 2019 01:20:41 +0000 Message-ID: <20190523011958.14944-8-ioana.ciornei@nxp.com> References: <20190523011958.14944-1-ioana.ciornei@nxp.com> In-Reply-To: <20190523011958.14944-1-ioana.ciornei@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::19) To VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ioana.ciornei@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [5.12.225.227] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 80b23386-39b5-414b-0a2a-08d6df1cdf29 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR0402MB3677; x-ms-traffictypediagnostic: VI1PR0402MB3677: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 00462943DE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(346002)(376002)(199004)(189003)(25786009)(6512007)(316002)(2201001)(26005)(186003)(86362001)(2501003)(1076003)(36756003)(71200400001)(256004)(71190400001)(5660300002)(4326008)(66066001)(6486002)(14444005)(6436002)(3846002)(7736002)(305945005)(71446004)(99286004)(52116002)(50226002)(81156014)(8676002)(81166006)(8936002)(54906003)(110136005)(2906002)(6116002)(478600001)(68736007)(102836004)(76176011)(53936002)(486006)(2616005)(66446008)(6506007)(386003)(66946007)(73956011)(66556008)(44832011)(14454004)(476003)(11346002)(66476007)(64756008)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3677; H:VI1PR0402MB2800.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: ha1FQYhc22uE1UyFzsQ83K+gV3ZJBbJSeWIpfvu7tEjBwDX2keI6nJ1+cs1YwTvjO1e+XmuDlWgQNbGMgcsoQaaZy+aXQRM36z+hfsCcJ4biZZxjDwwL3ZGWkj7LNuHkcixaunYjo/lYAyXmIWZfQUYBfCsXoMLHKyiAIb5gKg5u0t8vWLHwKns8kyW3VZDKz8TeDqs1A+RpJVE/NhJNOcjobUBapfzM/s4+F9/sRBetUDyULckyhNAVT9/wZmWOjpxRfdjufC4aQ2yUgGOowARaNL8JRr6W8V89Vn72WeelX/nmy6Lo3Mm/gAZwJEMArczSW+PoDUYg3WMh0LZW8Oc595klJp2a0elfWq6bU/Na5/qveBcmnw7sZfFWeY/8I22uMvgXJ92fVrWT7Z7rx0U/efMnSnPWUsZ8HqZ41/g= Content-ID: <5EB9B9F03E807E4F8B1F3328AA3890E3@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 80b23386-39b5-414b-0a2a-08d6df1cdf29 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2019 01:20:42.0054 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3677 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In order to have a common handling of PHYLINK for the slave and non-user ports, the DSA core glue logic (between PHYLINK and the driver) must use an API that does not rely on a struct net_device. These will also be called by the CPU-port-handling code in a further patch. Signed-off-by: Ioana Ciornei Suggested-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- net/dsa/dsa_priv.h | 19 +++++++++ net/dsa/port.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ net/dsa/slave.c | 49 ++++------------------- 3 files changed, 122 insertions(+), 42 deletions(-) diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 8f1222324646..da70da65bdc5 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -161,6 +161,25 @@ int dsa_port_vlan_del(struct dsa_port *dp, const struct switchdev_obj_port_vlan *vlan); int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags); int dsa_port_vid_del(struct dsa_port *dp, u16 vid); +void dsa_port_phylink_validate(struct dsa_port *dp, + unsigned long *supported, + struct phylink_link_state *state); +int dsa_port_phylink_mac_link_state(struct dsa_port *dp, + struct phylink_link_state *state); +void dsa_port_phylink_mac_config(struct dsa_port *dp, + unsigned int mode, + const struct phylink_link_state *state); +void dsa_port_phylink_mac_an_restart(struct dsa_port *dp); +void dsa_port_phylink_mac_link_down(struct dsa_port *dp, + unsigned int mode, + phy_interface_t interface, + struct phy_device *phydev); +void dsa_port_phylink_mac_link_up(struct dsa_port *dp, + unsigned int mode, + phy_interface_t interface, + struct phy_device *phydev); +void dsa_port_phylink_fixed_state(struct dsa_port *dp, + struct phylink_link_state *state); int dsa_port_link_register_of(struct dsa_port *dp); void dsa_port_link_unregister_of(struct dsa_port *dp); diff --git a/net/dsa/port.c b/net/dsa/port.c index ed8ba9daa3ba..d0f955e8b731 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -422,6 +422,102 @@ static struct phy_device *dsa_port_get_phy_device(struct dsa_port *dp) return phydev; } +void dsa_port_phylink_validate(struct dsa_port *dp, + unsigned long *supported, + struct phylink_link_state *state) +{ + struct dsa_switch *ds = dp->ds; + + if (!ds->ops->phylink_validate) + return; + + ds->ops->phylink_validate(ds, dp->index, supported, state); +} +EXPORT_SYMBOL(dsa_port_phylink_validate); + +int dsa_port_phylink_mac_link_state(struct dsa_port *dp, + struct phylink_link_state *state) +{ + struct dsa_switch *ds = dp->ds; + + /* Only called for SGMII and 802.3z */ + if (!ds->ops->phylink_mac_link_state) + return -EOPNOTSUPP; + + return ds->ops->phylink_mac_link_state(ds, dp->index, state); +} +EXPORT_SYMBOL(dsa_port_phylink_mac_link_state); + +void dsa_port_phylink_mac_config(struct dsa_port *dp, + unsigned int mode, + const struct phylink_link_state *state) +{ + struct dsa_switch *ds = dp->ds; + + if (!ds->ops->phylink_mac_config) + return; + + ds->ops->phylink_mac_config(ds, dp->index, mode, state); +} +EXPORT_SYMBOL(dsa_port_phylink_mac_config); + +void dsa_port_phylink_mac_an_restart(struct dsa_port *dp) +{ + struct dsa_switch *ds = dp->ds; + + if (!ds->ops->phylink_mac_an_restart) + return; + + ds->ops->phylink_mac_an_restart(ds, dp->index); +} +EXPORT_SYMBOL(dsa_port_phylink_mac_an_restart); + +void dsa_port_phylink_mac_link_down(struct dsa_port *dp, + unsigned int mode, + phy_interface_t interface, + struct phy_device *phydev) +{ + struct dsa_switch *ds = dp->ds; + + if (!ds->ops->phylink_mac_link_down) { + if (ds->ops->adjust_link && phydev) + ds->ops->adjust_link(ds, dp->index, phydev); + return; + } + + ds->ops->phylink_mac_link_down(ds, dp->index, mode, interface); +} +EXPORT_SYMBOL(dsa_port_phylink_mac_link_down); + +void dsa_port_phylink_mac_link_up(struct dsa_port *dp, + unsigned int mode, + phy_interface_t interface, + struct phy_device *phydev) +{ + struct dsa_switch *ds = dp->ds; + + if (!ds->ops->phylink_mac_link_up) { + if (ds->ops->adjust_link && phydev) + ds->ops->adjust_link(ds, dp->index, phydev); + return; + } + + ds->ops->phylink_mac_link_up(ds, dp->index, mode, interface, phydev); +} +EXPORT_SYMBOL(dsa_port_phylink_mac_link_up); + +void dsa_port_phylink_fixed_state(struct dsa_port *dp, + struct phylink_link_state *state) +{ + struct dsa_switch *ds = dp->ds; + + /* No need to check that this operation is valid, the callback would + * not be called if it was not. + */ + ds->ops->phylink_fixed_state(ds, dp->index, state); +} +EXPORT_SYMBOL(dsa_port_phylink_fixed_state); + static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable) { struct dsa_switch *ds = dp->ds; diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 9892ca1f6859..308066da8a0f 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1169,25 +1169,16 @@ static void dsa_slave_phylink_validate(struct net_device *dev, struct phylink_link_state *state) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct dsa_switch *ds = dp->ds; - - if (!ds->ops->phylink_validate) - return; - ds->ops->phylink_validate(ds, dp->index, supported, state); + dsa_port_phylink_validate(dp, supported, state); } static int dsa_slave_phylink_mac_link_state(struct net_device *dev, struct phylink_link_state *state) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct dsa_switch *ds = dp->ds; - - /* Only called for SGMII and 802.3z */ - if (!ds->ops->phylink_mac_link_state) - return -EOPNOTSUPP; - return ds->ops->phylink_mac_link_state(ds, dp->index, state); + return dsa_port_phylink_mac_link_state(dp, state); } static void dsa_slave_phylink_mac_config(struct net_device *dev, @@ -1195,23 +1186,15 @@ static void dsa_slave_phylink_mac_config(struct net_device *dev, const struct phylink_link_state *state) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct dsa_switch *ds = dp->ds; - - if (!ds->ops->phylink_mac_config) - return; - ds->ops->phylink_mac_config(ds, dp->index, mode, state); + dsa_port_phylink_mac_config(dp, mode, state); } static void dsa_slave_phylink_mac_an_restart(struct net_device *dev) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct dsa_switch *ds = dp->ds; - - if (!ds->ops->phylink_mac_an_restart) - return; - ds->ops->phylink_mac_an_restart(ds, dp->index); + dsa_port_phylink_mac_an_restart(dp); } static void dsa_slave_phylink_mac_link_down(struct net_device *dev, @@ -1219,15 +1202,8 @@ static void dsa_slave_phylink_mac_link_down(struct net_device *dev, phy_interface_t interface) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct dsa_switch *ds = dp->ds; - - if (!ds->ops->phylink_mac_link_down) { - if (ds->ops->adjust_link && dev->phydev) - ds->ops->adjust_link(ds, dp->index, dev->phydev); - return; - } - ds->ops->phylink_mac_link_down(ds, dp->index, mode, interface); + dsa_port_phylink_mac_link_down(dp, mode, interface, dev->phydev); } static void dsa_slave_phylink_mac_link_up(struct net_device *dev, @@ -1236,15 +1212,8 @@ static void dsa_slave_phylink_mac_link_up(struct net_device *dev, struct phy_device *phydev) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct dsa_switch *ds = dp->ds; - if (!ds->ops->phylink_mac_link_up) { - if (ds->ops->adjust_link && dev->phydev) - ds->ops->adjust_link(ds, dp->index, dev->phydev); - return; - } - - ds->ops->phylink_mac_link_up(ds, dp->index, mode, interface, phydev); + dsa_port_phylink_mac_link_up(dp, mode, interface, phydev); } static const struct phylink_mac_ops dsa_slave_phylink_mac_ops = { @@ -1268,12 +1237,8 @@ static void dsa_slave_phylink_fixed_state(struct net_device *dev, struct phylink_link_state *state) { struct dsa_port *dp = dsa_slave_to_port(dev); - struct dsa_switch *ds = dp->ds; - /* No need to check that this operation is valid, the callback would - * not be called if it was not. - */ - ds->ops->phylink_fixed_state(ds, dp->index, state); + dsa_port_phylink_fixed_state(dp, state); } /* slave device setup *******************************************************/ From patchwork Thu May 23 01:20:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 1103766 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="C43ZIDoN"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 458Wsp2j1Yz9s3Z for ; Thu, 23 May 2019 11:21:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729776AbfEWBVB (ORCPT ); Wed, 22 May 2019 21:21:01 -0400 Received: from mail-eopbgr140079.outbound.protection.outlook.com ([40.107.14.79]:16354 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729698AbfEWBU6 (ORCPT ); Wed, 22 May 2019 21:20:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZRWYz6R6X6M1iGdQ6RL2Yl52XqqofgwS6//GVP654zU=; b=C43ZIDoNNxHLgg9W95EGBu3VB2ksNM894j7SXc9HTekATMujT8Z8aF0rxHBaHbisLZR2NAYsh0UMjuMSdSqQCCrplQE0jIjR85wHQIFIeH9S0WUFgY1LS7jMIURyAnoSuIHa9WpQzM51Tv0l7VcYVoIwItFKWYAuiKNo/ZONmVk= Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com (10.175.24.138) by VI1PR0402MB3677.eurprd04.prod.outlook.com (52.134.15.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.18; Thu, 23 May 2019 01:20:43 +0000 Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053]) by VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053%8]) with mapi id 15.20.1900.020; Thu, 23 May 2019 01:20:43 +0000 From: Ioana Ciornei To: "linux@armlinux.org.uk" , "f.fainelli@gmail.com" , "andrew@lunn.ch" , "hkallweit1@gmail.com" , "maxime.chevallier@bootlin.com" , "olteanv@gmail.com" CC: "netdev@vger.kernel.org" , "davem@davemloft.net" , Ioana Ciornei Subject: [RFC PATCH net-next 8/9] net: dsa: Use PHYLINK for the CPU/DSA ports Thread-Topic: [RFC PATCH net-next 8/9] net: dsa: Use PHYLINK for the CPU/DSA ports Thread-Index: AQHVEQW9dR5vtmHsY06KY7+uMrFNCg== Date: Thu, 23 May 2019 01:20:42 +0000 Message-ID: <20190523011958.14944-9-ioana.ciornei@nxp.com> References: <20190523011958.14944-1-ioana.ciornei@nxp.com> In-Reply-To: <20190523011958.14944-1-ioana.ciornei@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::19) To VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ioana.ciornei@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [5.12.225.227] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8bb6fe00-0355-401e-6208-08d6df1cdfb5 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR0402MB3677; x-ms-traffictypediagnostic: VI1PR0402MB3677: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3826; x-forefront-prvs: 00462943DE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(346002)(376002)(199004)(189003)(25786009)(6512007)(316002)(2201001)(26005)(186003)(86362001)(2501003)(1076003)(36756003)(71200400001)(256004)(71190400001)(5660300002)(4326008)(66066001)(6486002)(14444005)(5024004)(6436002)(3846002)(7736002)(305945005)(71446004)(99286004)(52116002)(50226002)(81156014)(8676002)(81166006)(8936002)(54906003)(110136005)(2906002)(6116002)(478600001)(68736007)(102836004)(76176011)(53936002)(486006)(2616005)(66446008)(6506007)(386003)(66946007)(73956011)(66556008)(44832011)(14454004)(476003)(11346002)(66476007)(64756008)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3677; H:VI1PR0402MB2800.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: KGajA+7HqnKMIN3AGThBwJM5VQjG+rcy77keKrNxCcbVR1w+M4lnD2EZQ+HHzBcfCNFhVkh4RyAnaT/UmPYaOXMUmW6ZXWfrA0KmOLRdzkPuOdH3daF2n1gGNK30ni80uDkxTeUMtmhSq/beIjOqVZVHm42RWe4hIxdtyuc8uJO7I6PkE5ot62ipKD0NI33tw5by4HjmbGjqd+7mRLy6aYMenwPQv0Xc0jBG/n6bcM1OK8HEC+bGv54ydyizKmQjDJIwxzn3CU9/+26dFx+y/DhIdTm3EW5e55QRMxWmuuMEiOCPd4Kzcmq+y7oi4DesJpMSpRuTiRmErAoN7XLytLc6NwyEe1OJRIOmMnTJgfNdi4BVbjqlLyl8yhSVHIpxunPuIegDuFz3gcxs7gqYc9AH64S6XT/e9s6xtxOZhf4= Content-ID: <50F9FF48CDF9A04C912CE1D55353072D@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8bb6fe00-0355-401e-6208-08d6df1cdfb5 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2019 01:20:42.7690 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3677 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This completely removes the usage of PHYLIB from DSA, namely for the aforementioned switch ports which used to drive a software PHY manually using genphy operations. For these ports, the newly introduced phylink_create_raw API must be used, and the callbacks are received through a notifier block registered per dsa_port, but otherwise the implementation is fairly straightforward, and the handling of the regular vs raw PHYLINK instances is common from the perspective of the driver. What changes for drivers: The .adjust_link callback is no longer called for the fixed-link CPU/DSA ports and drivers must migrate to standard PHYLINK operations (e.g. .phylink_mac_config). The reason why we can't do anything for them is because PHYLINK does not wrap the fixed link state behind a phydev object, so we cannot wrap .phylink_mac_config into .adjust_link unless we fabricate a phy_device structure. Signed-off-by: Ioana Ciornei --- include/net/dsa.h | 3 + net/dsa/port.c | 137 +++++++++++++++++++++------------------------- 2 files changed, 64 insertions(+), 76 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 685294817712..87616ff00919 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -212,6 +212,9 @@ struct dsa_port { * Original copy of the master netdev net_device_ops */ const struct net_device_ops *orig_ndo_ops; + + /* Listener for phylink events on ports with no netdev */ + struct notifier_block nb; }; struct dsa_switch { diff --git a/net/dsa/port.c b/net/dsa/port.c index d0f955e8b731..31bd07dd42db 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "dsa_priv.h" @@ -511,104 +512,88 @@ void dsa_port_phylink_fixed_state(struct dsa_port *dp, { struct dsa_switch *ds = dp->ds; - /* No need to check that this operation is valid, the callback would - * not be called if it was not. + /* We need to check that the callback exists because phylink raw will + * send PHYLINK_GET_FIXED_STATE events without an explicit register. */ - ds->ops->phylink_fixed_state(ds, dp->index, state); + if (ds->ops->phylink_fixed_state) + ds->ops->phylink_fixed_state(ds, dp->index, state); } EXPORT_SYMBOL(dsa_port_phylink_fixed_state); -static int dsa_port_setup_phy_of(struct dsa_port *dp, bool enable) -{ - struct dsa_switch *ds = dp->ds; - struct phy_device *phydev; - int port = dp->index; - int err = 0; - - phydev = dsa_port_get_phy_device(dp); - if (!phydev) - return 0; - - if (IS_ERR(phydev)) - return PTR_ERR(phydev); - - if (enable) { - err = genphy_config_init(phydev); - if (err < 0) - goto err_put_dev; - - err = genphy_resume(phydev); - if (err < 0) - goto err_put_dev; - - err = genphy_read_status(phydev); - if (err < 0) - goto err_put_dev; - } else { - err = genphy_suspend(phydev); - if (err < 0) - goto err_put_dev; +static int dsa_cpu_port_event(struct notifier_block *nb, + unsigned long event, void *ptr) +{ + struct phylink_notifier_info *info = ptr; + struct dsa_port *dp = container_of(nb, struct dsa_port, nb); + + switch (event) { + case PHYLINK_VALIDATE: + dsa_port_phylink_validate(dp, info->supported, info->state); + break; + case PHYLINK_MAC_AN_RESTART: + dsa_port_phylink_mac_an_restart(dp); + break; + case PHYLINK_MAC_CONFIG: + dsa_port_phylink_mac_config(dp, info->link_an_mode, + info->state); + break; + case PHYLINK_MAC_LINK_DOWN: + dsa_port_phylink_mac_link_down(dp, info->link_an_mode, + info->interface, info->phydev); + break; + case PHYLINK_MAC_LINK_UP: + dsa_port_phylink_mac_link_up(dp, info->link_an_mode, + info->interface, info->phydev); + break; + case PHYLINK_GET_FIXED_STATE: + dsa_port_phylink_fixed_state(dp, info->state); + break; + default: + return NOTIFY_OK; } - if (ds->ops->adjust_link) - ds->ops->adjust_link(ds, port, phydev); - - dev_dbg(ds->dev, "enabled port's phy: %s", phydev_name(phydev)); - -err_put_dev: - put_device(&phydev->mdio.dev); - return err; + return NOTIFY_DONE; } -static int dsa_port_fixed_link_register_of(struct dsa_port *dp) +int dsa_port_link_register_of(struct dsa_port *dp) { - struct device_node *dn = dp->dn; - struct dsa_switch *ds = dp->ds; - struct phy_device *phydev; - int port = dp->index; - int mode; - int err; + struct device_node *port_dn = dp->dn; + int mode, err; - err = of_phy_register_fixed_link(dn); - if (err) { - dev_err(ds->dev, - "failed to register the fixed PHY of port %d\n", - port); - return err; - } - - phydev = of_phy_find_device(dn); - - mode = of_get_phy_mode(dn); + mode = of_get_phy_mode(port_dn); if (mode < 0) mode = PHY_INTERFACE_MODE_NA; - phydev->interface = mode; - genphy_config_init(phydev); - genphy_read_status(phydev); + dp->nb.notifier_call = dsa_cpu_port_event; + dp->pl = phylink_create_raw(&dp->nb, of_fwnode_handle(port_dn), mode); + if (IS_ERR(dp->pl)) { + pr_err("error creating PHYLINK: %ld\n", PTR_ERR(dp->pl)); + return PTR_ERR(dp->pl); + } - if (ds->ops->adjust_link) - ds->ops->adjust_link(ds, port, phydev); + err = phylink_of_phy_connect(dp->pl, port_dn, 0); + if (err) { + pr_err("could not attach to PHY: %d\n", err); + goto err_phy_connect; + } - put_device(&phydev->mdio.dev); + rtnl_lock(); + phylink_start(dp->pl); + rtnl_unlock(); return 0; -} -int dsa_port_link_register_of(struct dsa_port *dp) -{ - if (of_phy_is_fixed_link(dp->dn)) - return dsa_port_fixed_link_register_of(dp); - else - return dsa_port_setup_phy_of(dp, true); +err_phy_connect: + phylink_destroy(dp->pl); + return err; } void dsa_port_link_unregister_of(struct dsa_port *dp) { - if (of_phy_is_fixed_link(dp->dn)) - of_phy_deregister_fixed_link(dp->dn); - else - dsa_port_setup_phy_of(dp, false); + rtnl_lock(); + phylink_disconnect_phy(dp->pl); + rtnl_unlock(); + phylink_destroy(dp->pl); } int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data) From patchwork Thu May 23 01:20:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ioana Ciornei X-Patchwork-Id: 1103767 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="XS9UBe0I"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 458Wss0Gyvz9s3Z for ; Thu, 23 May 2019 11:21:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729793AbfEWBVD (ORCPT ); Wed, 22 May 2019 21:21:03 -0400 Received: from mail-eopbgr140079.outbound.protection.outlook.com ([40.107.14.79]:16354 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727305AbfEWBVC (ORCPT ); Wed, 22 May 2019 21:21:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XKXLI8LZP3mvoxWJLTOYXXX5jX8l4mVBtl3lhiuTu3E=; b=XS9UBe0Iq7FcGrB41ljRRrpKyqfWbKLwp7gbGN5pV0WbnDxCnbbXeLFH3GDr+lEsVQ3BHx6qB3JF/a2et+AAbpygpzrDMUIjBPu09MgTJUKKi9vrko1O/RBZgcgwBGbA/+DpbCwl+aAyi5TZmvxp7OVjuyb5CPd9rEjMWoH998E= Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com (10.175.24.138) by VI1PR0402MB3677.eurprd04.prod.outlook.com (52.134.15.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.18; Thu, 23 May 2019 01:20:43 +0000 Received: from VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053]) by VI1PR0402MB2800.eurprd04.prod.outlook.com ([fe80::f494:9fa1:ebae:6053%8]) with mapi id 15.20.1900.020; Thu, 23 May 2019 01:20:43 +0000 From: Ioana Ciornei To: "linux@armlinux.org.uk" , "f.fainelli@gmail.com" , "andrew@lunn.ch" , "hkallweit1@gmail.com" , "maxime.chevallier@bootlin.com" , "olteanv@gmail.com" CC: "netdev@vger.kernel.org" , "davem@davemloft.net" , Ioana Ciornei Subject: [RFC PATCH net-next 9/9] net: dsa: sja1105: Fix broken fixed-link interfaces on user ports Thread-Topic: [RFC PATCH net-next 9/9] net: dsa: sja1105: Fix broken fixed-link interfaces on user ports Thread-Index: AQHVEQW9DS1DMtkTyEezAnqhFkmpow== Date: Thu, 23 May 2019 01:20:43 +0000 Message-ID: <20190523011958.14944-10-ioana.ciornei@nxp.com> References: <20190523011958.14944-1-ioana.ciornei@nxp.com> In-Reply-To: <20190523011958.14944-1-ioana.ciornei@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1P18901CA0009.EURP189.PROD.OUTLOOK.COM (2603:10a6:801::19) To VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ioana.ciornei@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.21.0 x-originating-ip: [5.12.225.227] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e59ca706-0b43-41d2-260e-08d6df1ce013 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR0402MB3677; x-ms-traffictypediagnostic: VI1PR0402MB3677: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2043; x-forefront-prvs: 00462943DE x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(136003)(396003)(366004)(346002)(376002)(199004)(189003)(25786009)(6512007)(316002)(2201001)(26005)(186003)(86362001)(2501003)(1076003)(36756003)(71200400001)(256004)(71190400001)(5660300002)(4326008)(66066001)(6486002)(14444005)(6436002)(3846002)(7736002)(305945005)(71446004)(99286004)(52116002)(50226002)(81156014)(8676002)(81166006)(8936002)(54906003)(110136005)(2906002)(6116002)(478600001)(68736007)(102836004)(76176011)(53936002)(486006)(2616005)(66446008)(6506007)(386003)(66946007)(73956011)(66556008)(44832011)(14454004)(476003)(11346002)(66476007)(64756008)(446003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0402MB3677; H:VI1PR0402MB2800.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: jx4AVBYmDt9Lx0gp55sknhQDHtYskdM+5YB///cHTuwJ2H2XFt3kEIWlYhFQuYZ77IHS5dVLCH7feVpLF70bEWM3PxaEP0ynrDZZMMpzuDFYETzXC5dTDzL9nltxmWOYWU+P1FAJOn/djq9PE3VQrGZAtUC9ZGiaeEISA4GDxUfo23aV3uMsPRpKyra99gTrT2tQOkz1Mmcw7G1JTAFl/dl3qv958zpwZvRbwc9tFvxA8UEcFi1LGGr1U5Ra64Tq9WFIbQttOzyUSI4mLRBJ+fFJ5a8GHSOX/pZJ/AsVepty1YsbPq11UdYqG1AE3n4bXZQcEBQpC1o3VIF7Bz2so+pGzeEEEZhSqR/YmWzTtN0tQ1mqG2bHnh8543hESBjRc2ii6Ey+nr5Vg6/QgKAHOaA6pP38QurXzUS+TH4IsTM= Content-ID: <8815CBCC343E864B8EEE7ABCAD9B6F3A@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e59ca706-0b43-41d2-260e-08d6df1ce013 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2019 01:20:43.3935 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3677 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean PHYLIB and PHYLINK handle fixed-link interfaces differently. PHYLIB wraps them in a software PHY ("pseudo fixed link") phydev construct such that .adjust_link driver callbacks see an unified API. Whereas PHYLINK simply creates a phylink_link_state structure and passes it to .mac_config. At the time the driver was introduced, DSA was using PHYLIB for the CPU/cascade ports (the ones with no net devices) and PHYLINK for everything else. As explained below: commit aab9c4067d2389d0adfc9c53806437df7b0fe3d5 Author: Florian Fainelli Date: Thu May 10 13:17:36 2018 -0700 net: dsa: Plug in PHYLINK support Drivers that utilize fixed links for user-facing ports (e.g: bcm_sf2) will need to implement phylink_mac_ops from now on to preserve functionality, since PHYLINK *does not* create a phy_device instance for fixed links. In the above patch, DSA guards the .phylink_mac_config callback against a NULL phydev pointer. Therefore, .adjust_link is not called in case of a fixed-link user port. This patch fixes the situation by converting the driver from using .adjust_link to .phylink_mac_config. This can be done now in a unified fashion for both slave and CPU/cascade ports because DSA now uses PHYLINK for all ports. Signed-off-by: Vladimir Oltean Signed-off-by: Ioana Ciornei Reviewed-by: Florian Fainelli --- drivers/net/dsa/sja1105/sja1105_main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 0663b78a2f6c..cfdefd9f1905 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -734,15 +734,16 @@ static int sja1105_adjust_port_config(struct sja1105_private *priv, int port, return sja1105_clocking_setup_port(priv, port); } -static void sja1105_adjust_link(struct dsa_switch *ds, int port, - struct phy_device *phydev) +static void sja1105_mac_config(struct dsa_switch *ds, int port, + unsigned int link_an_mode, + const struct phylink_link_state *state) { struct sja1105_private *priv = ds->priv; - if (!phydev->link) + if (!state->link) sja1105_adjust_port_config(priv, port, 0, false); else - sja1105_adjust_port_config(priv, port, phydev->speed, true); + sja1105_adjust_port_config(priv, port, state->speed, true); } static void sja1105_phylink_validate(struct dsa_switch *ds, int port, @@ -1515,9 +1516,9 @@ static int sja1105_set_ageing_time(struct dsa_switch *ds, static const struct dsa_switch_ops sja1105_switch_ops = { .get_tag_protocol = sja1105_get_tag_protocol, .setup = sja1105_setup, - .adjust_link = sja1105_adjust_link, .set_ageing_time = sja1105_set_ageing_time, .phylink_validate = sja1105_phylink_validate, + .phylink_mac_config = sja1105_mac_config, .get_strings = sja1105_get_strings, .get_ethtool_stats = sja1105_get_ethtool_stats, .get_sset_count = sja1105_get_sset_count,