From patchwork Wed Sep 11 21:27:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13801143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 11A9DEE57DB for ; Wed, 11 Sep 2024 21:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=r+zUuX3TEbTMb9kGTTFtZ/4QRQvlQbBoikmP33WrT2E=; b=aCzYdxmoZpn6eZoIbG6XVBZtNU CHjaeySQIEPPU07ESduE7X2qrkYg+TwRuafUmG0gjhFXqcc6CHWWecW4KjkOqwvABdyUSyErGAKSG gzN+Qcknw8DcXzN9VWZ+DKvAkpZHZPmX80PU1qyYxgQjyQi0WDb5N+rzxzQ2/kCntjrEBpnP2A2tv uLsaJPBLl8xjE2n3f9BVK3AEcmtpT05nvdgVsNYOEYm7koSow8b5rf5RlfbDHLIKy29e85EcARXFN obSFKsQejRLeH8KvXcKifXtFBD6B5w4TvKDeh8vVGEUzCVo3Jg4BwFnMLhbiY5xzcPxpXpVobhx/X H1vPhY1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUx5-0000000B4Da-1BnI; Wed, 11 Sep 2024 21:32:39 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUrz-0000000B3Ca-2Yio for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 21:27:25 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 5172A1C0009; Wed, 11 Sep 2024 21:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726090042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r+zUuX3TEbTMb9kGTTFtZ/4QRQvlQbBoikmP33WrT2E=; b=c7vVVkaR6qgBhveBee5BJEAHpUWbU/OeW8RhW1fEPvcE223RWBnwwv2ik8ZhCQRI5uN9VP hApM8iG52eyHVTB9FhDmil9D8qrYeNHh5myaY+P7CSaIjDZfWsgWlffg6vNJ5YC69ENbgx IVTMRQNoeolDZwpoED3jLm6lCLQwmornnPu+QZ5y2xQ4XpPqSOKdePn6ENt7Z8Y+XHqKLb c4XYeNDyQTqiG3ojp9kmioBAGLpNJMdtJ98ADHKA7cYKRFIEUOZ41b8EG6lBo5VfpsDi5e d/8URapmbAJnk9KE7HcG9Chh7UrNCTxPwlXM7zlNBIU4Y5NvRrtizGJUuetbVQ== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?K=C3=B6ry_Maince?= =?utf-8?q?nt?= , Oleksij Rempel Subject: [PATCH net-next 5/7] net: phy: introduce ethtool_phy_ops to get and set phy configuration Date: Wed, 11 Sep 2024 23:27:09 +0200 Message-ID: <20240911212713.2178943-6-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> References: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_142723_944174_883F52B4 X-CRM114-Status: GOOD ( 16.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Expose phy-specific configuration hooks to get and set the state of an ethernet PHY's internal configuration. So far, these parameters include the loopback state of the PHY (host-side loopback) and the isolation state of the PHY. The .get_config() ethtool_phy_ops gets these status information from the phy_device's internal flags, while the .set_config() operation allows changing these configuration parameters. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy.c | 59 ++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy_device.c | 2 ++ include/linux/ethtool.h | 8 +++++ include/linux/phy.h | 21 +++++++++++++ 4 files changed, 90 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 4f3e742907cb..0cdb0fc30727 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1811,3 +1811,62 @@ int phy_ethtool_nway_reset(struct net_device *ndev) return ret; } EXPORT_SYMBOL(phy_ethtool_nway_reset); + +/** + * phy_get_config - Get PHY configuration parameters + * @phydev: the PHY device to act upon + * @phy_cfg: The configuration to apply + */ + +int phy_get_config(struct phy_device *phydev, + struct phy_device_config *phy_cfg) +{ + mutex_lock(&phydev->lock); + phy_cfg->isolate = phydev->isolated; + phy_cfg->loopback = phydev->loopback_enabled; + mutex_unlock(&phydev->lock); + + return 0; +} + +/** + * phy_set_config - Set PHY configuration parameters + * @phydev: the PHY device to act upon + * @phy_cfg: the configuration to apply + * @extack: a netlink extack for useful error reporting + */ + +int phy_set_config(struct phy_device *phydev, + const struct phy_device_config *phy_cfg, + struct netlink_ext_ack *extack) +{ + bool loopback_change, isolate_change; + int ret; + + /* As the phydev's loopback and isolation state are protected by the + * phy lock, check first if we'll need to perform the action, + * then do them as a second step. + */ + mutex_lock(&phydev->lock); + isolate_change = (phy_cfg->isolate != phydev->isolated); + loopback_change = (phy_cfg->loopback != phydev->loopback_enabled); + mutex_unlock(&phydev->lock); + + if (isolate_change) { + ret = phy_isolate(phydev, phy_cfg->isolate); + if (ret) { + NL_SET_ERR_MSG(extack, "Error while configuring PHY isolation"); + return ret; + } + } + + if (loopback_change) { + ret = phy_loopback(phydev, phy_cfg->loopback); + if (ret) { + NL_SET_ERR_MSG(extack, "Error while configuring PHY loopback"); + return ret; + } + } + + return 0; +} diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 2a3db1043626..0714a2b83d18 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3845,6 +3845,8 @@ static const struct ethtool_phy_ops phy_ethtool_phy_ops = { .get_plca_status = phy_ethtool_get_plca_status, .start_cable_test = phy_start_cable_test, .start_cable_test_tdr = phy_start_cable_test_tdr, + .get_config = phy_get_config, + .set_config = phy_set_config, }; static const struct phylib_stubs __phylib_stubs = { diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 12f6dc567598..480ee99a69a5 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -1140,6 +1140,7 @@ struct phy_device; struct phy_tdr_config; struct phy_plca_cfg; struct phy_plca_status; +struct phy_device_config; /** * struct ethtool_phy_ops - Optional PHY device options @@ -1151,6 +1152,8 @@ struct phy_plca_status; * @get_plca_status: Get PLCA configuration. * @start_cable_test: Start a cable test * @start_cable_test_tdr: Start a Time Domain Reflectometry cable test + * @get_config: Retrieve phy device configuration parameters + * @set_config: Set phy device configuration parameters * * All operations are optional (i.e. the function pointer may be set to %NULL) * and callers must take this into account. Callers must hold the RTNL lock. @@ -1172,6 +1175,11 @@ struct ethtool_phy_ops { int (*start_cable_test_tdr)(struct phy_device *phydev, struct netlink_ext_ack *extack, const struct phy_tdr_config *config); + int (*get_config)(struct phy_device *phydev, + struct phy_device_config *phy_cfg); + int (*set_config)(struct phy_device *phydev, + const struct phy_device_config *phy_cfg, + struct netlink_ext_ack *extack); }; /** diff --git a/include/linux/phy.h b/include/linux/phy.h index f0a8a5459fbe..ee0364d2afc3 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -887,6 +887,22 @@ enum phy_led_modes { __PHY_LED_MODES_NUM, }; +/** + * struct phy_device_config - General PHY device configuration parameters for + * status reporting and bulk configuration + * + * A structure containing generic PHY device information, allowing to expose + * internal status to userspace, and perform PHY configuration in a controlled + * manner. + * + * @isolate: The MII-side isolation status of the PHY + * @loopback: The loopback state of the PHY + */ +struct phy_device_config { + bool isolate; + bool loopback; +}; + /** * struct phy_led: An LED driven by the PHY * @@ -2067,6 +2083,11 @@ int phy_ethtool_set_plca_cfg(struct phy_device *phydev, struct netlink_ext_ack *extack); int phy_ethtool_get_plca_status(struct phy_device *phydev, struct phy_plca_status *plca_st); +int phy_get_config(struct phy_device *phydev, + struct phy_device_config *phy_cfg); +int phy_set_config(struct phy_device *phydev, + const struct phy_device_config *phy_cfg, + struct netlink_ext_ack *extack); int __phy_hwtstamp_get(struct phy_device *phydev, struct kernel_hwtstamp_config *config);