From patchwork Thu May 19 13:56:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 12855258 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 13C63C433F5 for ; Thu, 19 May 2022 15:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vXCPsw/KbfcuR0ia4NPdrjUC8Dq7TgdIk5+Nv9HO9D0=; b=3po+eifWSaWd0I RPhhBv6u7BmBdi2kgM+xQDd0oWP0IU/PL4A+tsCRR7klpTVCpmHwFW4JpM7weFF7rj9icW7GLWNbG U+oMmNtD7K4cdJ6edpt60rP5slLWbDVgXxBs5e4b7LqzwiCpPNtb3hHWPUMxr6o4SDDirLIbVl4zK t0sDtGudc7ux1zbp2e6S5ck01QPngVG5+LW4+tBQecX6vLt9rEcgesgEKVRWQfsNcbjmzr27ir3e7 M31Y685qS6k9OYMOJ9LblKSO3qXiME+tjUfIHT1FeGlqwcTy/fU/vkHTMnyf/wfbr+556Y1Af2aEX tCB1qcTvn25s5ddcugrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrhfN-007gZg-G2; Thu, 19 May 2022 15:02:18 +0000 Received: from relay1-d.mail.gandi.net ([2001:4b98:dc4:8::221]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrgeH-007BcP-58 for linux-arm-kernel@lists.infradead.org; Thu, 19 May 2022 13:57:07 +0000 Received: (Authenticated sender: maxime.chevallier@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id AB19924000A; Thu, 19 May 2022 13:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1652968623; 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=pWGVazQWGDDZgzON711pAZLPzapDACfEJlg6W1kTnfg=; b=BhkmYgd0BYKmyoJAXqAKqMjHEUFihdXTXN70fxztHSnrObK3NtNQFzMboMqwt+XpzQQBq8 Yckb+AaL2hE1pmmtEbLR6rLBxyeepVgkzziIS882Uojd76piQeLymSa7cHjUN3tFnQqX0A /HiQNag2wBM6NiYjZFQdF4ixegzRmBH+6+CkP1eh5m73aUKH14Fldg3uY3qgC8C7HSl3Zy 7wfbsiUhnuFoVNDgwX9BUFpRq6lxwsuk3Xj7UuEefU8Fxxi8GiIk7GXCHkAaaT3zBG67iM OmCXXf7ZSi2i5fa5SWdwzpMMobse/smQ6HYAlkS6nDQCtYamQECNfPh5KOY35A== From: Maxime Chevallier To: davem@davemloft.net, Rob Herring Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , linux-arm-kernel@lists.infradead.org, Richard Cochran , Horatiu.Vultur@microchip.com, Allan.Nielsen@microchip.com, UNGLinuxDriver@microchip.com Subject: [PATCH net-next 4/6] net: phy: Add support for inband extensions Date: Thu, 19 May 2022 15:56:45 +0200 Message-Id: <20220519135647.465653-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519135647.465653-1-maxime.chevallier@bootlin.com> References: <20220519135647.465653-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220519_065705_579892_FB7D3102 X-CRM114-Status: GOOD ( 16.56 ) 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 The USXGMII Standard by Cisco introduces the notion of extensions used in the preamble. The standard proposes a "PCH" extension, which allows passing timestamps in the preamble. However, other alternatives are possible, like Microchip's "MCH" mode, that allows passing indication to a PHY telling whether or not the PHY should timestamp an outgoing packet, therefore removing the need for the PHY to have an internal classifier. This commit allows reporting the various extensions a PHY supports, without tying them to the actual PHY mode. This is done 1) because there are multiple variants of the USXGMII mode, like QUSGMII and OUSGMII, and 2) because other non-cisco standards might one day propose a similar mechanism. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy.c | 68 +++++++++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 25 +++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index beb2b66da132..bbd3d7620609 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1475,3 +1475,71 @@ int phy_ethtool_nway_reset(struct net_device *ndev) return phy_restart_aneg(phydev); } EXPORT_SYMBOL(phy_ethtool_nway_reset); + +/** + * PHY modes in the USXGMII family can have extensions, with data transmitted + * in the frame preamble. + * For now, only QUSGMII is supported, but other variants like USGMII and + * OUSGMII can be added in the future. + */ +static inline bool phy_interface_has_inband_ext(phy_interface_t interface) +{ + return interface == PHY_INTERFACE_MODE_QUSGMII; +} + +bool phy_inband_ext_available(struct phy_device *phydev, u32 ext) +{ + return !!(phydev->inband_ext.available & ext); +} +EXPORT_SYMBOL(phy_inband_ext_available); + +bool phy_inband_ext_enabled(struct phy_device *phydev, u32 ext) +{ + return !!(phydev->inband_ext.enabled & ext); +} +EXPORT_SYMBOL(phy_inband_ext_enabled); + +static int phy_set_inband_ext(struct phy_device *phydev, u32 mask, u32 ext) +{ + int ret; + + if (!phy_interface_has_inband_ext(phydev->interface)) + return -EOPNOTSUPP; + + if (!phydev->drv->inband_ext_config) + return -EOPNOTSUPP; + + ret = phydev->drv->inband_ext_config(phydev, mask, ext); + if (ret) + return ret; + + phydev->inband_ext.enabled &= ~mask; + phydev->inband_ext.enabled |= (mask & ext); + + return 0; +} + +int phy_inband_ext_enable(struct phy_device *phydev, u32 ext) +{ + return phy_set_inband_ext(phydev, ext, ext); +} +EXPORT_SYMBOL(phy_inband_ext_enable); + +int phy_inband_ext_disable(struct phy_device *phydev, u32 ext) +{ + return phy_set_inband_ext(phydev, ext, 0); +} +EXPORT_SYMBOL(phy_inband_ext_disable); + +int phy_inband_ext_set_available(struct phy_device *phydev, u32 mask, u32 ext) +{ + if (!(mask & phydev->drv->inband_ext)) + return -EOPNOTSUPP; + + phydev->inband_ext.available &= ~mask; + phydev->inband_ext.available |= (mask & ext); + + return 0; +} +EXPORT_SYMBOL(phy_inband_ext_set_available); + diff --git a/include/linux/phy.h b/include/linux/phy.h index 4a2731c78590..6b08f49bce5b 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -190,6 +190,21 @@ static inline void phy_interface_set_rgmii(unsigned long *intf) __set_bit(PHY_INTERFACE_MODE_RGMII_TXID, intf); } +/* + * TODO : Doc + */ +enum { + __PHY_INBAND_EXT_PCH = 0, +}; + +#define PHY_INBAND_EXT_PCH BIT(__PHY_INBAND_EXT_PCH) + +int phy_inband_ext_enable(struct phy_device *phydev, u32 ext); +int phy_inband_ext_disable(struct phy_device *phydev, u32 ext); +int phy_inband_ext_set_available(struct phy_device *phydev, u32 mask, u32 ext); +bool phy_inband_ext_available(struct phy_device *phydev, u32 ext); +bool phy_inband_ext_enabled(struct phy_device *phydev, u32 ext); + /* * phy_supported_speeds - return all speeds currently supported by a PHY device */ @@ -275,7 +290,6 @@ static inline const char *phy_modes(phy_interface_t interface) } } - #define PHY_INIT_TIMEOUT 100000 #define PHY_FORCE_TIMEOUT 10 @@ -635,6 +649,11 @@ struct phy_device { phy_interface_t interface; + struct { + u32 available; + u32 enabled; + } inband_ext; + /* * forced speed & duplex (no autoneg) * partner speed & duplex & pause (autoneg) @@ -766,6 +785,7 @@ struct phy_driver { u32 phy_id_mask; const unsigned long * const features; u32 flags; + u32 inband_ext; const void *driver_data; /** @@ -935,6 +955,9 @@ struct phy_driver { int (*get_sqi)(struct phy_device *dev); /** @get_sqi_max: Get the maximum signal quality indication */ int (*get_sqi_max)(struct phy_device *dev); + + int (*inband_ext_config)(struct phy_device *dev, u32 features, + u32 mask); }; #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv)