From patchwork Thu Nov 30 22:46:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 843207 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@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; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bv2UaP0v"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynsvs6XPKz9sBd for ; Fri, 1 Dec 2017 09:46:33 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751197AbdK3Wq3 (ORCPT ); Thu, 30 Nov 2017 17:46:29 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:42778 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750898AbdK3Wq1 (ORCPT ); Thu, 30 Nov 2017 17:46:27 -0500 Received: by mail-wm0-f67.google.com with SMTP id l141so495036wmg.1 for ; Thu, 30 Nov 2017 14:46:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=VZLAVWpBJ/hy45q32twWtVeh7GqM6BkXSfVfbWLIX+8=; b=bv2UaP0voTN2HDRy1wjlI3mtErG2Xq44gaKjmDYEP0fJuTqI2XnTCDjlA0NpuMqBhb bu++DEC8GY0joIHTKUBmAHRfdQCUtXfZ6hP0N5Jt+Alw5T4wa7fXJF/k8wefUHHUuLA8 NrEjxExLgIhZxwLLQjrfku6wLiRBbqUSQqkSCPwyo7h89EuxMKu9xj4DVPKkWg2TtutY ClRBsqclBaI/yYQCd+5OIJiF3qjD/r/BGvrlaUFef0uLbPIKvH0vIVk4B89Vj14CrHu4 TY16BrM8gONwyW+ljQ/7dkbt1t6fCE9xlf7OhI6Bbm/oLYp7XW5uI+Z/1ElqsrqIdR+t y5Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=VZLAVWpBJ/hy45q32twWtVeh7GqM6BkXSfVfbWLIX+8=; b=b0Anfa8emUQ5cQS3JIMOy69FPsiiOxSvuR8Hwac0IHJe5asinRA5cVpxsJwEfLs5rY mOHWQcegYsjkC5+M5R0cMUdi4cFxVa59Y0XggrTyQgBP2rJb9KPCd+GrMkxX9s5MKuKB 4lP8S91PGqZ88vmcJpIvxHss8AaiU3QTxohsKZzl5hZS6Xf880aAxlWgOmly7LSRWLTx zYV7roK414vw+3vL4TZHrjTccugusMNf7UtoUo2OjwcaorfNlM0HUgI+5cSLN5rDQRtW Uoc8QFYU3A8UFZwDhT7hWeQNUQzLOtVZNYtWk0VCWwmiKH4bJbzktw32EI44cbzL3IaC 7Gag== X-Gm-Message-State: AJaThX4HPOWoEU0KuQY57RHyi4V3e7ap1LKBmaeksSc2m0mr/7Eei7Rh f7ISBaV3vSpDUtSDVGFKjpP+0Q== X-Google-Smtp-Source: AGs4zMYsqDB0NwtuOyCy2ZKgNvQdvGfu4n6ldkw0oDZrzKzbQin4eFI2clCJXZAq38ixdRWqxjtjuw== X-Received: by 10.28.221.138 with SMTP id u132mr1694853wmg.113.1512081986277; Thu, 30 Nov 2017 14:46:26 -0800 (PST) Received: from ?IPv6:2003:ea:8bc0:e400:bc09:e6d3:e40e:c3ee? (p200300EA8BC0E400BC09E6D3E40EC3EE.dip0.t-ipconnect.de. [2003:ea:8bc0:e400:bc09:e6d3:e40e:c3ee]) by smtp.googlemail.com with ESMTPSA id g84sm5039430wmf.26.2017.11.30.14.46.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 14:46:25 -0800 (PST) From: Heiner Kallweit Subject: [PATCH net-next resubmit 1/2] net: phy: core: use genphy version of callbacks read_status and config_aneg per default To: David Miller , Florian Fainelli , Andrew Lunn Cc: "netdev@vger.kernel.org" Message-ID: Date: Thu, 30 Nov 2017 23:46:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org read_status and config_aneg are the only mandatory callbacks and most of the time the generic implementation is used by drivers. So make the core fall back to the generic version if a driver doesn't implement the respective callback. Also currently the core doesn't seem to verify that drivers implement the mandatory calls. If a driver doesn't do so we'd just get a NPE. With this patch this potential issue doesn't exit any longer. Signed-off-by: Heiner Kallweit Reviewed-by: Florian Fainelli --- drivers/net/phy/phy.c | 5 ++++- include/linux/phy.h | 33 ++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 2b1e67bc1..a0e7605dc 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -493,7 +493,10 @@ static int phy_start_aneg_priv(struct phy_device *phydev, bool sync) /* Invalidate LP advertising flags */ phydev->lp_advertising = 0; - err = phydev->drv->config_aneg(phydev); + if (phydev->drv->config_aneg) + err = phydev->drv->config_aneg(phydev); + else + err = genphy_config_aneg(phydev); if (err < 0) goto out_unlock; diff --git a/include/linux/phy.h b/include/linux/phy.h index dc82a07cb..958b5162a 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -497,13 +497,13 @@ struct phy_device { * flags: A bitfield defining certain other features this PHY * supports (like interrupts) * - * The drivers must implement config_aneg and read_status. All - * other functions are optional. Note that none of these - * functions should be called from interrupt time. The goal is - * for the bus read/write functions to be able to block when the - * bus transaction is happening, and be freed up by an interrupt - * (The MPC85xx has this ability, though it is not currently - * supported in the driver). + * All functions are optional. If config_aneg or read_status + * are not implemented, the phy core uses the genphy versions. + * Note that none of these functions should be called from + * interrupt time. The goal is for the bus read/write functions + * to be able to block when the bus transaction is happening, + * and be freed up by an interrupt (The MPC85xx has this ability, + * though it is not currently supported in the driver). */ struct phy_driver { struct mdio_driver_common mdiodrv; @@ -841,14 +841,6 @@ int phy_aneg_done(struct phy_device *phydev); int phy_stop_interrupts(struct phy_device *phydev); int phy_restart_aneg(struct phy_device *phydev); -static inline int phy_read_status(struct phy_device *phydev) -{ - if (!phydev->drv) - return -EIO; - - return phydev->drv->read_status(phydev); -} - #define phydev_err(_phydev, format, args...) \ dev_err(&_phydev->mdio.dev, format, ##args) @@ -890,6 +882,17 @@ int genphy_c45_read_pma(struct phy_device *phydev); int genphy_c45_pma_setup_forced(struct phy_device *phydev); int genphy_c45_an_disable_aneg(struct phy_device *phydev); +static inline int phy_read_status(struct phy_device *phydev) +{ + if (!phydev->drv) + return -EIO; + + if (phydev->drv->read_status) + return phydev->drv->read_status(phydev); + else + return genphy_read_status(phydev); +} + void phy_driver_unregister(struct phy_driver *drv); void phy_drivers_unregister(struct phy_driver *drv, int n); int phy_driver_register(struct phy_driver *new_driver, struct module *owner);