From nobody Wed Sep 10 01:55:28 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 702E030498F for ; Mon, 8 Sep 2025 12:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335591; cv=none; b=oWYzJV6fsfQ8FoQCE72/0ypMCnUiSWgXVwYAlR54W9ShwwhmDP4u2NC477egrwoeOUqvX6dSU4LpvxBWUGTSBSFGJQ4c44f8le/3uMbrjHaSMhwuwN9FPXPiIrpo0/iIgv/Dumbyus7h6eOU+fZonMlEqDPKfyPdeL/1ZhVlcfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335591; c=relaxed/simple; bh=AHql4L2MMECt8qFo3mpT1lE/2CSHmR0Zx7dNrqyXO1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NvKY0lRekqnLTyLSnx6k5VYrhnOo6J7d5uQwNUVwbBiDorpIqPCgMUbkTlEHsQAXFZDHoNKR7C7RQ27krFdAWNLv/OPeEXa4Qfz8wi0/vz52y7VY7n/4NREPN9y3EqHqg2ae8XvhmfzP396bZanqnTmOPvstrPkvYQdrxhlpz3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uvbG9-0003Ru-F8; Mon, 08 Sep 2025 14:46:13 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uvbG7-000Fin-2L; Mon, 08 Sep 2025 14:46:11 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.98.2) (envelope-from ) id 1uvbG7-0000000CKJK-2cyp; Mon, 08 Sep 2025 14:46:11 +0200 From: Oleksij Rempel To: Andrew Lunn , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Donald Hunter , Jonathan Corbet , Heiner Kallweit , Russell King , Kory Maincent , Maxime Chevallier , Nishanth Menon Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, linux-doc@vger.kernel.org, Michal Kubecek , Roan van Dijk Subject: [PATCH net-next v5 1/5] ethtool: introduce core UAPI and driver API for PHY MSE diagnostics Date: Mon, 8 Sep 2025 14:46:06 +0200 Message-ID: <20250908124610.2937939-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250908124610.2937939-1-o.rempel@pengutronix.de> References: <20250908124610.2937939-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add the base infrastructure for Mean Square Error (MSE) diagnostics, as proposed by the OPEN Alliance "Advanced diagnostic features for 100BASE-T1 automotive Ethernet PHYs" [1] specification. The OPEN Alliance spec defines only average MSE and average peak MSE over a fixed number of symbols. However, other PHYs, such as the KSZ9131, additionally expose a worst-peak MSE value latched since the last channel capture. This API accounts for such vendor extensions by adding a distinct capability bit and snapshot field. Channel-to-pair mapping is normally straightforward, but in some cases (e.g. 100BASE-TX with MDI-X resolution unknown) the mapping is ambiguous. If hardware does not expose MDI-X status, the exact pair cannot be determined. To avoid returning misleading per-channel data in this case, a LINK selector is defined for aggregate MSE measurements. All investigated devices differ in MSE configuration parameters, such as sample rate, number of analyzed symbols, and scaling factors. For example, the KSZ9131 uses different scaling for MSE and pMSE. To make this visible to userspace, scale limits and timing information are returned via get_mse_config(). Some PHYs sample very few symbols at high frequency (e.g. 2 =C2=B5s update rate). To cover such cases and allow for future high-speed PHYs with even shorter intervals, the refresh rate is reported as u64 in picoseconds. This patch defines new UAPI enums for MSE capability flags and channel selectors in ethtool_netlink (generated from YAML), kernel-side `struct phy_mse_config` and `struct phy_mse_snapshot`, and new phy_driver ops: - get_mse_config(): report supported capabilities, scaling, and sampling parameters for the current link mode - get_mse_snapshot(): retrieve a correlated set of MSE values from the latest measurement window These definitions form the core API; no driver implements them yet. [1] Signed-off-by: Oleksij Rempel --- changes v4: - remove -ENETDOWN as expected error value for get_mse_config() and get_mse_snapshot() - fix htmldocs builds --- Documentation/netlink/specs/ethtool.yaml | 78 ++++++++++++ include/linux/phy.h | 115 ++++++++++++++++++ .../uapi/linux/ethtool_netlink_generated.h | 54 ++++++++ 3 files changed, 247 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netli= nk/specs/ethtool.yaml index 13d8dcfa8dc5..969477f50d84 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -211,6 +211,84 @@ definitions: name: discard value: 31 =20 + - + name: phy-mse-capability + doc: | + Bitmask flags for MSE capabilities. + + These flags are used in the 'supported_caps' field of struct + phy_mse_config to indicate which measurement capabilities are suppor= ted + by the PHY hardware. + type: flags + name-prefix: phy-mse-cap- + entries: + - + name: avg + doc: Average MSE value is supported. + - + name: peak + doc: Current peak MSE value is supported. + - + name: worst-peak + doc: Worst-case peak MSE (latched high-water mark) is supported. + - + name: channel-a + doc: Diagnostics for Channel A are supported. + - + name: channel-b + doc: Diagnostics for Channel B are supported. + - + name: channel-c + doc: Diagnostics for Channel C are supported. + - + name: channel-d + doc: Diagnostics for Channel D are supported. + - + name: worst-channel + doc: | + Hardware or drivers can identify the single worst-performing cha= nnel + without needing to query each one individually. + - + name: link + doc: | + Hardware provides only a link-wide aggregate MSE or cannot map + the measurement to a specific channel/pair. Typical for media wh= ere + the MDI/MDI-X resolution or pair mapping is unknown (e.g. 100BAS= E-TX). + + - + name: phy-mse-channel + doc: | + Identifiers for the 'channel' parameter used to select which diagnos= tic + data to retrieve. + type: enum + name-prefix: phy-mse-channel- + entries: + - + name: a + value: 0 + doc: Request data for channel A. + - + name: b + doc: Request data for channel B. + - + name: c + doc: Request data for channel C. + - + name: d + doc: Request data for channel D. + - + name: link + doc: | + Request data for the link as a whole. Use when the PHY exposes o= nly + a link-wide aggregate MSE or cannot attribute results to any sin= gle + channel/pair (e.g. 100BASE-TX with unknown MDI/MDI-X mapping). + - + name: worst + doc: | + Request data for the single worst-performing channel. This is a + convenience for PHYs or drivers that can identify the worst chan= nel + in hardware. + attribute-sets: - name: header diff --git a/include/linux/phy.h b/include/linux/phy.h index 04553419adc3..4824ac9db08c 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -898,6 +898,74 @@ struct phy_led { =20 #define to_phy_led(d) container_of(d, struct phy_led, led_cdev) =20 +/** + * struct phy_mse_config - Configuration for Mean Square Error (MSE) measu= rement + * + * Describes the MSE measurement capabilities for the current link mode. T= hese + * properties are dynamic and may change when link settings are modified. + * Callers should re-query this configuration after any link state change = to + * ensure they have the most up-to-date information. + * + * Callers should only request measurements for channels and types that are + * indicated as supported by the @supported_caps bitmask. If @supported_ca= ps + * is 0, the device provides no MSE diagnostics, and driver operations sho= uld + * typically return -EOPNOTSUPP. + * + * Snapshot values for average and peak MSE can be normalized to a 0..1 ra= tio + * by dividing the raw snapshot by the corresponding @max_average_mse or + * @max_peak_mse value. + * + * @max_average_mse: The maximum value for an average MSE snapshot. This + * defines the scale for the measurement. If the PHY_MSE_CAP_AVG capabil= ity is + * supported, this value MUST be greater than 0. + * @max_peak_mse: The maximum value for a peak MSE snapshot. If either + * PHY_MSE_CAP_PEAK or PHY_MSE_CAP_WORST_PEAK is supported, this value M= UST + * be greater than 0. + * @refresh_rate_ps: The typical interval, in picoseconds, between hardware + * updates of the MSE values. This is an estimate, and callers should not + * assume synchronous sampling. + * @num_symbols: The number of symbols aggregated per hardware sample to + * calculate the MSE. + * @supported_caps: A bitmask of PHY_MSE_CAP_* values indicating which + * measurement types (e.g., average, peak) and channels + * (e.g., per-pair or link-wide) are supported. + */ +struct phy_mse_config { + u32 max_average_mse; + u32 max_peak_mse; + u64 refresh_rate_ps; + u64 num_symbols; + u32 supported_caps; +}; + +/** + * struct phy_mse_snapshot - A snapshot of Mean Square Error (MSE) diagnos= tics + * + * Holds a set of MSE diagnostic values that were all captured from a sing= le + * measurement window. + * + * The @channel field is an input parameter specified by the caller. Drive= rs + * must validate the requested channel against the capabilities returned by + * get_mse_config(). If an unsupported channel is requested, the driver mu= st + * return -EOPNOTSUPP and must not coerce the request to a different chann= el + * (e.g., changing a per-channel request to a link-wide one). + * + * @channel: Input: The requested channel for the measurement, which must + * be one of the PHY_MSE_CHANNEL_* constants. + * @average_mse: The average MSE value over the measurement window. + * @peak_mse: The peak MSE value observed within the measurement window. + * @worst_peak_mse: A latched high-water mark of the peak MSE. This value + * represents the worst (highest) peak seen since this field + * was last read. It MUST be cleared by the driver or hardware + * upon reading (i.e., it has read-to-clear semantics). + */ +struct phy_mse_snapshot { + u32 channel; + u32 average_mse; + u32 peak_mse; + u32 worst_peak_mse; +}; + /** * struct phy_driver - Driver structure for a particular PHY type * @@ -1179,6 +1247,53 @@ struct phy_driver { /** @get_sqi_max: Get the maximum signal quality indication */ int (*get_sqi_max)(struct phy_device *dev); =20 + /** + * @get_mse_config: Get configuration and scale of MSE measurement + * @dev: PHY device + * @config: Output (filled on success) + * + * Fill @config with the PHY's MSE configuration for the current + * link mode: scale limits (max_average_mse, max_peak_mse), update + * interval (refresh_rate_ps), sample length (num_symbols) and the + * capability bitmask (supported_caps). + * + * Implementations may defer configuration until hardware has + * converged; in that case they should return -EAGAIN and allow the + * caller to retry later. + * + * Return: 0 on success. On failure, returns a negative errno code, such + * as -EOPNOTSUPP if MSE measurement is not supported by the PHY or in + * the current link mode, or -EAGAIN if the configuration is not yet + * available. + */ + int (*get_mse_config)(struct phy_device *dev, + struct phy_mse_config *config); + + /** + * @get_mse_snapshot: Retrieve a snapshot of MSE diagnostic values + * @dev: PHY device + * @channel: Channel identifier (PHY_MSE_CHANNEL_*) + * @snapshot: Output (filled on success) + * + * Fill @snapshot with a correlated set of MSE values from the most + * recent measurement window. + * + * Callers must validate @channel against supported_caps returned by + * get_mse_config(). Drivers must not coerce @channel; if the requested + * selector is not implemented by the device or current link mode, + * the operation must fail. + * + * On success, @snapshot->channel MUST equal the requested @channel. + * worst_peak_mse is latched and must be treated as read-to-clear. + * + * Return: 0 on success. On failure, returns a negative errno code, such + * as -EOPNOTSUPP if MSE measurement is not supported by the PHY or in + * the current link mode, or -EAGAIN if the configuration is not yet + * available. + */ + int (*get_mse_snapshot)(struct phy_device *dev, u32 channel, + struct phy_mse_snapshot *snapshot); + /* PLCA RS interface */ /** @get_plca_cfg: Return the current PLCA configuration */ int (*get_plca_cfg)(struct phy_device *dev, diff --git a/include/uapi/linux/ethtool_netlink_generated.h b/include/uapi/= linux/ethtool_netlink_generated.h index 0af7b90101c1..d36faf5f20f4 100644 --- a/include/uapi/linux/ethtool_netlink_generated.h +++ b/include/uapi/linux/ethtool_netlink_generated.h @@ -77,6 +77,60 @@ enum ethtool_pse_event { ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR =3D 64, }; =20 +/** + * enum ethtool_phy_mse_capability - Bitmask flags for MSE capabilities. T= hese + * flags are used in the 'supported_caps' field of struct phy_mse_config= to + * indicate which measurement capabilities are supported by the PHY hard= ware. + * @PHY_MSE_CAP_AVG: Average MSE value is supported. + * @PHY_MSE_CAP_PEAK: Current peak MSE value is supported. + * @PHY_MSE_CAP_WORST_PEAK: Worst-case peak MSE (latched high-water mark) = is + * supported. + * @PHY_MSE_CAP_CHANNEL_A: Diagnostics for Channel A are supported. + * @PHY_MSE_CAP_CHANNEL_B: Diagnostics for Channel B are supported. + * @PHY_MSE_CAP_CHANNEL_C: Diagnostics for Channel C are supported. + * @PHY_MSE_CAP_CHANNEL_D: Diagnostics for Channel D are supported. + * @PHY_MSE_CAP_WORST_CHANNEL: Hardware or drivers can identify the single + * worst-performing channel without needing to query each one individual= ly. + * @PHY_MSE_CAP_LINK: Hardware provides only a link-wide aggregate MSE or + * cannot map the measurement to a specific channel/pair. Typical for me= dia + * where the MDI/MDI-X resolution or pair mapping is unknown (e.g. + * 100BASE-TX). + */ +enum ethtool_phy_mse_capability { + PHY_MSE_CAP_AVG =3D 1, + PHY_MSE_CAP_PEAK =3D 2, + PHY_MSE_CAP_WORST_PEAK =3D 4, + PHY_MSE_CAP_CHANNEL_A =3D 8, + PHY_MSE_CAP_CHANNEL_B =3D 16, + PHY_MSE_CAP_CHANNEL_C =3D 32, + PHY_MSE_CAP_CHANNEL_D =3D 64, + PHY_MSE_CAP_WORST_CHANNEL =3D 128, + PHY_MSE_CAP_LINK =3D 256, +}; + +/** + * enum ethtool_phy_mse_channel - Identifiers for the 'channel' parameter = used + * to select which diagnostic data to retrieve. + * @PHY_MSE_CHANNEL_A: Request data for channel A. + * @PHY_MSE_CHANNEL_B: Request data for channel B. + * @PHY_MSE_CHANNEL_C: Request data for channel C. + * @PHY_MSE_CHANNEL_D: Request data for channel D. + * @PHY_MSE_CHANNEL_LINK: Request data for the link as a whole. Use when t= he + * PHY exposes only a link-wide aggregate MSE or cannot attribute result= s to + * any single channel/pair (e.g. 100BASE-TX with unknown MDI/MDI-X mappi= ng). + * @PHY_MSE_CHANNEL_WORST: Request data for the single worst-performing + * channel. This is a convenience for PHYs or drivers that can identify = the + * worst channel in hardware. + */ +enum ethtool_phy_mse_channel { + PHY_MSE_CHANNEL_A, + PHY_MSE_CHANNEL_B, + PHY_MSE_CHANNEL_C, + PHY_MSE_CHANNEL_D, + PHY_MSE_CHANNEL_LINK, + PHY_MSE_CHANNEL_WORST, +}; + enum { ETHTOOL_A_HEADER_UNSPEC, ETHTOOL_A_HEADER_DEV_INDEX, --=20 2.47.3 From nobody Wed Sep 10 01:55:28 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 419BE302CAB for ; Mon, 8 Sep 2025 12:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335593; cv=none; b=G0XOEERbwXtljSWh962TBZFYyPFJwmUnmm6txwXCeJ4mJvLj9n8pKNB3z9VAS1kwcR6SNezVe418xnze60qszZDcFwLXMhKqS5bYh7tLZ3KCrRMMydMeeqlaunPGpsoWmuQIMBPi/w+jT1b0+49aGpvZMrlxZh4gVVQrdEc5FcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335593; c=relaxed/simple; bh=Tn4bVRJuF4JBmy1BVKoQ1YkKIXHXU/mV+zSkyQBecIU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lhl9VDZHzq15RTPR47EMRy96LgI8Qo8X7eolce9tzJmbQALGvJgSKisSzESlm1q007xGd4Mzb9dLbEK4UizTe1PzY/akA3irjUk3yYLxP3RnKRFCSX7A9Cehsq2pewRIykqz3XW5x/qUE+u2Yi1tN8pzcMxi7kzrEyizF3ln9AM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uvbG9-0003S6-F8; Mon, 08 Sep 2025 14:46:13 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uvbG7-000Fip-2U; Mon, 08 Sep 2025 14:46:11 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.98.2) (envelope-from ) id 1uvbG7-0000000CKJU-2pj4; Mon, 08 Sep 2025 14:46:11 +0200 From: Oleksij Rempel To: Andrew Lunn , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Donald Hunter , Jonathan Corbet , Heiner Kallweit , Russell King , Kory Maincent , Maxime Chevallier , Nishanth Menon Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, linux-doc@vger.kernel.org, Michal Kubecek , Roan van Dijk Subject: [PATCH net-next v5 2/5] ethtool: netlink: add ETHTOOL_MSG_MSE_GET and wire up PHY MSE access Date: Mon, 8 Sep 2025 14:46:07 +0200 Message-ID: <20250908124610.2937939-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250908124610.2937939-1-o.rempel@pengutronix.de> References: <20250908124610.2937939-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Introduce the userspace entry point for PHY MSE diagnostics via ethtool netlink. This exposes the core API added previously and returns both configuration and one or more snapshots. Userspace sends ETHTOOL_MSG_MSE_GET with an optional channel selector. The reply carries: - ETHTOOL_A_MSE_CONFIG: scale limits, timing, and supported capability bitmask - ETHTOOL_A_MSE_SNAPSHOT+: one or more snapshots, each tagged with the selected channel If no channel is requested, the kernel returns snapshots for all supported selectors (per=E2=80=91channel if available, otherwise WORST, otherwise LINK). Requests for unsupported selectors fail with -EOPNOTSUPP; link down returns -ENOLINK. Changes: - YAML: add attribute sets (mse, mse-config, mse-snapshot) and the mse-get operation - UAPI (generated): add ETHTOOL_A_MSE_* enums and message IDs, ETHTOOL_MSG_MSE_GET/REPLY - ethtool core: add net/ethtool/mse.c implementing the request, register genl op, and hook into ethnl dispatch - docs: document MSE_GET in ethtool-netlink.rst The include/uapi/linux/ethtool_netlink_generated.h is generated from Documentation/netlink/specs/ethtool.yaml. Signed-off-by: Oleksij Rempel --- changes v5: - add struct phy_mse_snapshot and phy_mse_config to the documentation changes v4: - s/__ethtool-a-mse/--ethtool-a-mse - remove duplicate kernel-doc line - fix htmldocs compile warnings --- Documentation/netlink/specs/ethtool.yaml | 88 +++++ Documentation/networking/ethtool-netlink.rst | 62 +++ .../uapi/linux/ethtool_netlink_generated.h | 37 ++ net/ethtool/Makefile | 2 +- net/ethtool/mse.c | 362 ++++++++++++++++++ net/ethtool/netlink.c | 10 + net/ethtool/netlink.h | 2 + 7 files changed, 562 insertions(+), 1 deletion(-) create mode 100644 net/ethtool/mse.c diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netli= nk/specs/ethtool.yaml index 969477f50d84..d69dd3fb534b 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -1899,6 +1899,79 @@ attribute-sets: type: uint enum: pse-event doc: List of events reported by the PSE controller + - + name: mse-config + attr-cnt-name: --ethtool-a-mse-config-cnt + attributes: + - + name: unspec + type: unused + value: 0 + - + name: max-average-mse + type: u32 + - + name: max-peak-mse + type: u32 + - + name: refresh-rate-ps + type: u64 + - + name: num-symbols + type: u64 + - + name: supported-caps + type: nest + nested-attributes: bitset + - + name: pad + type: pad + - + name: mse-snapshot + attr-cnt-name: --ethtool-a-mse-snapshot-cnt + attributes: + - + name: unspec + type: unused + value: 0 + - + name: channel + type: u32 + enum: phy-mse-channel + - + name: average-mse + type: u32 + - + name: peak-mse + type: u32 + - + name: worst-peak-mse + type: u32 + - + name: mse + attr-cnt-name: --ethtool-a-mse-cnt + attributes: + - + name: unspec + type: unused + value: 0 + - + name: header + type: nest + nested-attributes: header + - + name: channel + type: u32 + enum: phy-mse-channel + - + name: config + type: nest + nested-attributes: mse-config + - + name: snapshot + type: nest + multi-attr: true + nested-attributes: mse-snapshot operations: enum-model: directional @@ -2832,6 +2905,21 @@ operations: attributes: - header - context + - + name: mse-get + doc: Get PHY MSE measurement data and configuration. + attribute-set: mse + do: &mse-get-op + request: + attributes: + - header + - channel + reply: + attributes: &mse-reply + - header + - config + - snapshot + dump: *mse-get-op mcast-groups: list: diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/n= etworking/ethtool-netlink.rst index ab20c644af24..aae53f39c2b0 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -242,6 +242,7 @@ Userspace to kernel: ``ETHTOOL_MSG_RSS_SET`` set RSS settings ``ETHTOOL_MSG_RSS_CREATE_ACT`` create an additional RSS context ``ETHTOOL_MSG_RSS_DELETE_ACT`` delete an additional RSS context + ``ETHTOOL_MSG_MSE_GET`` get MSE diagnostic data =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Kernel to userspace: @@ -299,6 +300,7 @@ Kernel to userspace: ``ETHTOOL_MSG_RSS_CREATE_ACT_REPLY`` create an additional RSS context ``ETHTOOL_MSG_RSS_CREATE_NTF`` additional RSS context created ``ETHTOOL_MSG_RSS_DELETE_NTF`` additional RSS context deleted + ``ETHTOOL_MSG_MSE_GET_REPLY`` MSE diagnostic data =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D ``GET`` requests are sent by userspace applications to retrieve device @@ -2453,6 +2455,66 @@ Kernel response contents: For a description of each attribute, see ``TSCONFIG_GET``. +MSE_GET +=3D=3D=3D=3D=3D=3D=3D + +Retrieves detailed Mean Square Error (MSE) diagnostic information from the= PHY. + +Request Contents: + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + ETHTOOL_A_MSE_HEADER nested request header + ETHTOOL_A_MSE_CHANNEL u32 optional channel enum value + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +.. kernel-doc:: include/uapi/linux/ethtool_netlink_generated.h + :identifiers: phy_mse_channel + +The optional ``ETHTOOL_A_MSE_CHANNEL`` attribute allows the caller to requ= est +data for a specific channel. If omitted, the kernel will return snapshots = for +all supported channels. + +Kernel Response Contents: + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + ETHTOOL_A_MSE_HEADER nested reply header + ETHTOOL_A_MSE_CONFIG nested MSE measurement configurat= ion + ETHTOOL_A_MSE_SNAPSHOT+ nested one or more MSE snapshots + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +MSE Configuration +----------------- + +This nested attribute contains the full configuration properties for the M= SE +measurements + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + ETHTOOL_A_MSE_CONFIG_MAX_AVERAGE_MSE u32 max avg_mse sca= le + ETHTOOL_A_MSE_CONFIG_MAX_PEAK_MSE u32 max peak_mse sc= ale + ETHTOOL_A_MSE_CONFIG_REFRESH_RATE_PS u64 sample rate (ps) + ETHTOOL_A_MSE_CONFIG_NUM_SYMBOLS u64 symbols per sam= ple + ETHTOOL_A_MSE_CONFIG_SUPPORTED_CAPS bitset capability bitm= ask + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +See ``struct phy_mse_config`` Kernel documentation defined in +``include/linux/phy.h`` + +MSE Snapshot +------------ + +This nested attribute contains an atomic snapshot of MSE values for a spec= ific +channel or for the link as a whole. + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + ETHTOOL_A_MSE_SNAPSHOT_CHANNEL u32 channel enum va= lue + ETHTOOL_A_MSE_SNAPSHOT_AVERAGE_MSE u32 average MSE val= ue + ETHTOOL_A_MSE_SNAPSHOT_PEAK_MSE u32 current peak MSE + ETHTOOL_A_MSE_SNAPSHOT_WORST_PEAK_MSE u32 worst-case peak= MSE + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D= =3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D + +See ``struct phy_mse_snapshot`` Kernel documentation defined in +``include/linux/phy.h`` + Request translation =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/include/uapi/linux/ethtool_netlink_generated.h b/include/uapi/= linux/ethtool_netlink_generated.h index d36faf5f20f4..8317e4b230a5 100644 --- a/include/uapi/linux/ethtool_netlink_generated.h +++ b/include/uapi/linux/ethtool_netlink_generated.h @@ -898,6 +898,41 @@ enum { ETHTOOL_A_PSE_NTF_MAX =3D (__ETHTOOL_A_PSE_NTF_CNT - 1) }; +enum { + ETHTOOL_A_MSE_CONFIG_UNSPEC, + ETHTOOL_A_MSE_CONFIG_MAX_AVERAGE_MSE, + ETHTOOL_A_MSE_CONFIG_MAX_PEAK_MSE, + ETHTOOL_A_MSE_CONFIG_REFRESH_RATE_PS, + ETHTOOL_A_MSE_CONFIG_NUM_SYMBOLS, + ETHTOOL_A_MSE_CONFIG_SUPPORTED_CAPS, + ETHTOOL_A_MSE_CONFIG_PAD, + + __ETHTOOL_A_MSE_CONFIG_CNT, + ETHTOOL_A_MSE_CONFIG_MAX =3D (__ETHTOOL_A_MSE_CONFIG_CNT - 1) +}; + +enum { + ETHTOOL_A_MSE_SNAPSHOT_UNSPEC, + ETHTOOL_A_MSE_SNAPSHOT_CHANNEL, + ETHTOOL_A_MSE_SNAPSHOT_AVERAGE_MSE, + ETHTOOL_A_MSE_SNAPSHOT_PEAK_MSE, + ETHTOOL_A_MSE_SNAPSHOT_WORST_PEAK_MSE, + + __ETHTOOL_A_MSE_SNAPSHOT_CNT, + ETHTOOL_A_MSE_SNAPSHOT_MAX =3D (__ETHTOOL_A_MSE_SNAPSHOT_CNT - 1) +}; + +enum { + ETHTOOL_A_MSE_UNSPEC, + ETHTOOL_A_MSE_HEADER, + ETHTOOL_A_MSE_CHANNEL, + ETHTOOL_A_MSE_CONFIG, + ETHTOOL_A_MSE_SNAPSHOT, + + __ETHTOOL_A_MSE_CNT, + ETHTOOL_A_MSE_MAX =3D (__ETHTOOL_A_MSE_CNT - 1) +}; + enum { ETHTOOL_MSG_USER_NONE =3D 0, ETHTOOL_MSG_STRSET_GET =3D 1, @@ -950,6 +985,7 @@ enum { ETHTOOL_MSG_RSS_SET, ETHTOOL_MSG_RSS_CREATE_ACT, ETHTOOL_MSG_RSS_DELETE_ACT, + ETHTOOL_MSG_MSE_GET, __ETHTOOL_MSG_USER_CNT, ETHTOOL_MSG_USER_MAX =3D (__ETHTOOL_MSG_USER_CNT - 1) @@ -1010,6 +1046,7 @@ enum { ETHTOOL_MSG_RSS_CREATE_ACT_REPLY, ETHTOOL_MSG_RSS_CREATE_NTF, ETHTOOL_MSG_RSS_DELETE_NTF, + ETHTOOL_MSG_MSE_GET_REPLY, __ETHTOOL_MSG_KERNEL_CNT, ETHTOOL_MSG_KERNEL_MAX =3D (__ETHTOOL_MSG_KERNEL_CNT - 1) diff --git a/net/ethtool/Makefile b/net/ethtool/Makefile index a1490c4afe6b..1be76e8d584f 100644 --- a/net/ethtool/Makefile +++ b/net/ethtool/Makefile @@ -9,4 +9,4 @@ ethtool_nl-y :=3D netlink.o bitset.o strset.o linkinfo.o li= nkmodes.o rss.o \ channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \ tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \ module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o mm.o \ - phy.o tsconfig.o + phy.o tsconfig.o mse.o diff --git a/net/ethtool/mse.c b/net/ethtool/mse.c new file mode 100644 index 000000000000..78389491cc49 --- /dev/null +++ b/net/ethtool/mse.c @@ -0,0 +1,362 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include + +#include "netlink.h" +#include "common.h" + +#define PHY_MSE_CHANNEL_COUNT 4 + +struct mse_req_info { + struct ethnl_req_info base; +}; + +struct mse_snapshot_entry { + struct phy_mse_snapshot snapshot; + int channel; +}; + +struct mse_reply_data { + struct ethnl_reply_data base; + struct phy_mse_config config; + struct mse_snapshot_entry *snapshots; + unsigned int num_snapshots; +}; + +static inline struct mse_reply_data * +mse_repdata(const struct ethnl_reply_data *reply_base) +{ + return container_of(reply_base, struct mse_reply_data, base); +} + +const struct nla_policy ethnl_mse_get_policy[] =3D { + [ETHTOOL_A_MSE_HEADER] =3D NLA_POLICY_NESTED(ethnl_header_policy_phy), + [ETHTOOL_A_MSE_CHANNEL] =3D { .type =3D NLA_U32 }, +}; + +static int get_snapshot_if_supported(struct phy_device *phydev, + struct mse_reply_data *data, + unsigned int *idx, u32 cap_bit, + int channel_id) +{ + int ret; + + if (data->config.supported_caps & cap_bit) { + ret =3D phydev->drv->get_mse_snapshot(phydev, channel_id, + &data->snapshots[*idx].snapshot); + if (ret) + return ret; + data->snapshots[*idx].channel =3D channel_id; + (*idx)++; + } + + return 0; +} + +static int mse_get_channels(struct phy_device *phydev, + struct mse_reply_data *data) +{ + unsigned int i =3D 0; + int ret; + + if (!data->config.supported_caps) + return 0; + + data->snapshots =3D kcalloc(PHY_MSE_CHANNEL_COUNT, + sizeof(*data->snapshots), GFP_KERNEL); + if (!data->snapshots) + return -ENOMEM; + + /* Priority 1: Individual channels */ + ret =3D get_snapshot_if_supported(phydev, data, &i, PHY_MSE_CAP_CHANNEL_A, + PHY_MSE_CHANNEL_A); + if (ret) + return ret; + ret =3D get_snapshot_if_supported(phydev, data, &i, PHY_MSE_CAP_CHANNEL_B, + PHY_MSE_CHANNEL_B); + if (ret) + return ret; + ret =3D get_snapshot_if_supported(phydev, data, &i, PHY_MSE_CAP_CHANNEL_C, + PHY_MSE_CHANNEL_C); + if (ret) + return ret; + ret =3D get_snapshot_if_supported(phydev, data, &i, PHY_MSE_CAP_CHANNEL_D, + PHY_MSE_CHANNEL_D); + if (ret) + return ret; + + /* If any individual channels were found, we are done. */ + if (i > 0) { + data->num_snapshots =3D i; + return 0; + } + + /* Priority 2: Worst channel, if no individual channels supported. */ + ret =3D get_snapshot_if_supported(phydev, data, &i, + PHY_MSE_CAP_WORST_CHANNEL, + PHY_MSE_CHANNEL_WORST); + if (ret) + return ret; + + /* If worst channel was found, we are done. */ + if (i > 0) { + data->num_snapshots =3D i; + return 0; + } + + /* Priority 3: Link-wide, if nothing else is supported. */ + ret =3D get_snapshot_if_supported(phydev, data, &i, PHY_MSE_CAP_LINK, + PHY_MSE_CHANNEL_LINK); + if (ret) + return ret; + + data->num_snapshots =3D i; + return 0; +} + +static int mse_get_one_channel(struct phy_device *phydev, + struct mse_reply_data *data, int channel) +{ + u32 cap_bit =3D 0; + int ret; + + switch (channel) { + case PHY_MSE_CHANNEL_A: + cap_bit =3D PHY_MSE_CAP_CHANNEL_A; + break; + case PHY_MSE_CHANNEL_B: + cap_bit =3D PHY_MSE_CAP_CHANNEL_B; + break; + case PHY_MSE_CHANNEL_C: + cap_bit =3D PHY_MSE_CAP_CHANNEL_C; + break; + case PHY_MSE_CHANNEL_D: + cap_bit =3D PHY_MSE_CAP_CHANNEL_D; + break; + case PHY_MSE_CHANNEL_WORST: + cap_bit =3D PHY_MSE_CAP_WORST_CHANNEL; + break; + case PHY_MSE_CHANNEL_LINK: + cap_bit =3D PHY_MSE_CAP_LINK; + break; + default: + return -EINVAL; + } + + if (!(data->config.supported_caps & cap_bit)) + return -EOPNOTSUPP; + + data->snapshots =3D kzalloc(sizeof(*data->snapshots), GFP_KERNEL); + if (!data->snapshots) + return -ENOMEM; + + ret =3D phydev->drv->get_mse_snapshot(phydev, channel, + &data->snapshots[0].snapshot); + if (ret) + return ret; + + data->snapshots[0].channel =3D channel; + data->num_snapshots =3D 1; + return 0; +} + +static int mse_prepare_data(const struct ethnl_req_info *req_base, + struct ethnl_reply_data *reply_base, + const struct genl_info *info) +{ + struct mse_reply_data *data =3D mse_repdata(reply_base); + struct net_device *dev =3D reply_base->dev; + struct phy_device *phydev; + int ret; + + phydev =3D ethnl_req_get_phydev(req_base, info->attrs, + ETHTOOL_A_MSE_HEADER, info->extack); + if (IS_ERR(phydev)) + return PTR_ERR(phydev); + if (!phydev) + return -EOPNOTSUPP; + + ret =3D ethnl_ops_begin(dev); + if (ret) + return ret; + + mutex_lock(&phydev->lock); + + if (!phydev->drv || !phydev->drv->get_mse_config || + !phydev->drv->get_mse_snapshot) { + ret =3D -EOPNOTSUPP; + goto out_unlock; + } + if (!phydev->link) { + ret =3D -ENETDOWN; + goto out_unlock; + } + + ret =3D phydev->drv->get_mse_config(phydev, &data->config); + if (ret) + goto out_unlock; + + if (info->attrs[ETHTOOL_A_MSE_CHANNEL]) { + u32 channel =3D nla_get_u32(info->attrs[ETHTOOL_A_MSE_CHANNEL]); + + ret =3D mse_get_one_channel(phydev, data, channel); + } else { + ret =3D mse_get_channels(phydev, data); + } + +out_unlock: + mutex_unlock(&phydev->lock); + ethnl_ops_complete(dev); + if (ret) + kfree(data->snapshots); + return ret; +} + +static void mse_cleanup_data(struct ethnl_reply_data *reply_base) +{ + struct mse_reply_data *data =3D mse_repdata(reply_base); + + kfree(data->snapshots); +} + +static int mse_reply_size(const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + const struct mse_reply_data *data =3D mse_repdata(reply_base); + size_t len =3D 0; + unsigned int i; + + /* ETHTOOL_A_MSE_CONFIG */ + len +=3D nla_total_size(0); + if (data->config.supported_caps & PHY_MSE_CAP_AVG) + /* ETHTOOL_A_MSE_CONFIG_MAX_AVERAGE_MSE */ + len +=3D nla_total_size(sizeof(u32)); + if (data->config.supported_caps & (PHY_MSE_CAP_PEAK | + PHY_MSE_CAP_WORST_PEAK)) + /* ETHTOOL_A_MSE_CONFIG_MAX_PEAK_MSE */ + len +=3D nla_total_size(sizeof(u32)); + /* ETHTOOL_A_MSE_CONFIG_REFRESH_RATE_PS */ + len +=3D nla_total_size(sizeof(u64)); + /* ETHTOOL_A_MSE_CONFIG_NUM_SYMBOLS */ + len +=3D nla_total_size(sizeof(u64)); + /* ETHTOOL_A_MSE_CONFIG_SUPPORTED_CAPS */ + len +=3D nla_total_size(sizeof(u32)); + + for (i =3D 0; i < data->num_snapshots; i++) { + size_t snapshot_len =3D 0; + + /* ETHTOOL_A_MSE_SNAPSHOT */ + snapshot_len +=3D nla_total_size(0); + /* ETHTOOL_A_MSE_SNAPSHOT_CHANNEL */ + snapshot_len +=3D nla_total_size(sizeof(u32)); + + if (data->config.supported_caps & PHY_MSE_CAP_AVG) + snapshot_len +=3D nla_total_size(sizeof(u32)); + if (data->config.supported_caps & PHY_MSE_CAP_PEAK) + snapshot_len +=3D nla_total_size(sizeof(u32)); + if (data->config.supported_caps & PHY_MSE_CAP_WORST_PEAK) + snapshot_len +=3D nla_total_size(sizeof(u32)); + + len +=3D snapshot_len; + } + + return len; +} + +static int mse_fill_reply(struct sk_buff *skb, + const struct ethnl_req_info *req_base, + const struct ethnl_reply_data *reply_base) +{ + const struct mse_reply_data *data =3D mse_repdata(reply_base); + struct nlattr *config_nest, *snapshot_nest; + unsigned int i; + int ret; + + config_nest =3D nla_nest_start(skb, ETHTOOL_A_MSE_CONFIG); + if (!config_nest) + return -EMSGSIZE; + + if (data->config.supported_caps & PHY_MSE_CAP_AVG) + if (nla_put_u32(skb, ETHTOOL_A_MSE_CONFIG_MAX_AVERAGE_MSE, + data->config.max_average_mse)) + goto nla_put_config_failure; + + if (data->config.supported_caps & (PHY_MSE_CAP_PEAK | + PHY_MSE_CAP_WORST_PEAK)) + if (nla_put_u32(skb, ETHTOOL_A_MSE_CONFIG_MAX_PEAK_MSE, + data->config.max_peak_mse)) + goto nla_put_config_failure; + + if (nla_put_u64_64bit(skb, ETHTOOL_A_MSE_CONFIG_REFRESH_RATE_PS, + data->config.refresh_rate_ps, + ETHTOOL_A_MSE_CONFIG_PAD) || + nla_put_u64_64bit(skb, ETHTOOL_A_MSE_CONFIG_NUM_SYMBOLS, + data->config.num_symbols, + ETHTOOL_A_MSE_CONFIG_PAD) || + nla_put_u32(skb, ETHTOOL_A_MSE_CONFIG_SUPPORTED_CAPS, + data->config.supported_caps)) + goto nla_put_config_failure; + + nla_nest_end(skb, config_nest); + + for (i =3D 0; i < data->num_snapshots; i++) { + const struct mse_snapshot_entry *s =3D &data->snapshots[i]; + + snapshot_nest =3D nla_nest_start(skb, ETHTOOL_A_MSE_SNAPSHOT); + if (!snapshot_nest) + return -EMSGSIZE; + + ret =3D nla_put_u32(skb, ETHTOOL_A_MSE_SNAPSHOT_CHANNEL, + s->channel); + if (ret) + goto nla_put_failure; + + if (data->config.supported_caps & PHY_MSE_CAP_AVG) { + ret =3D nla_put_u32(skb, + ETHTOOL_A_MSE_SNAPSHOT_AVERAGE_MSE, + s->snapshot.average_mse); + if (ret) + goto nla_put_failure; + } + if (data->config.supported_caps & PHY_MSE_CAP_PEAK) { + ret =3D nla_put_u32(skb, ETHTOOL_A_MSE_SNAPSHOT_PEAK_MSE, + s->snapshot.peak_mse); + if (ret) + goto nla_put_failure; + } + if (data->config.supported_caps & PHY_MSE_CAP_WORST_PEAK) { + ret =3D nla_put_u32(skb, + ETHTOOL_A_MSE_SNAPSHOT_WORST_PEAK_MSE, + s->snapshot.worst_peak_mse); + if (ret) + goto nla_put_failure; + } + + nla_nest_end(skb, snapshot_nest); + } + + return 0; + +nla_put_config_failure: + nla_nest_cancel(skb, config_nest); + return -EMSGSIZE; + +nla_put_failure: + nla_nest_cancel(skb, snapshot_nest); + return -EMSGSIZE; +} + +const struct ethnl_request_ops ethnl_mse_request_ops =3D { + .request_cmd =3D ETHTOOL_MSG_MSE_GET, + .reply_cmd =3D ETHTOOL_MSG_MSE_GET_REPLY, + .hdr_attr =3D ETHTOOL_A_MSE_HEADER, + .req_info_size =3D sizeof(struct mse_req_info), + .reply_data_size =3D sizeof(struct mse_reply_data), + + .prepare_data =3D mse_prepare_data, + .cleanup_data =3D mse_cleanup_data, + .reply_size =3D mse_reply_size, + .fill_reply =3D mse_fill_reply, +}; diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 2f813f25f07e..6e5f0f4f815a 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -420,6 +420,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] =3D { [ETHTOOL_MSG_TSCONFIG_GET] =3D ðnl_tsconfig_request_ops, [ETHTOOL_MSG_TSCONFIG_SET] =3D ðnl_tsconfig_request_ops, [ETHTOOL_MSG_PHY_GET] =3D ðnl_phy_request_ops, + [ETHTOOL_MSG_MSE_GET] =3D ðnl_mse_request_ops, }; static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *= cb) @@ -1534,6 +1535,15 @@ static const struct genl_ops ethtool_genl_ops[] =3D { .policy =3D ethnl_rss_delete_policy, .maxattr =3D ARRAY_SIZE(ethnl_rss_delete_policy) - 1, }, + { + .cmd =3D ETHTOOL_MSG_MSE_GET, + .doit =3D ethnl_default_doit, + .start =3D ethnl_perphy_start, + .dumpit =3D ethnl_perphy_dumpit, + .done =3D ethnl_perphy_done, + .policy =3D ethnl_mse_get_policy, + .maxattr =3D ARRAY_SIZE(ethnl_mse_get_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] =3D { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 1d4f9ecb3d26..f9ebcfb327a6 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -442,6 +442,7 @@ extern const struct ethnl_request_ops ethnl_plca_status= _request_ops; extern const struct ethnl_request_ops ethnl_mm_request_ops; extern const struct ethnl_request_ops ethnl_phy_request_ops; extern const struct ethnl_request_ops ethnl_tsconfig_request_ops; +extern const struct ethnl_request_ops ethnl_mse_request_ops; extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS = + 1]; extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_= FLAGS + 1]; @@ -497,6 +498,7 @@ extern const struct nla_policy ethnl_module_fw_flash_ac= t_policy[ETHTOOL_A_MODULE extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER += 1]; extern const struct nla_policy ethnl_tsconfig_get_policy[ETHTOOL_A_TSCONFI= G_HEADER + 1]; extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFI= G_MAX + 1]; +extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_CHANNEL = + 1]; int ethnl_set_features(struct sk_buff *skb, struct genl_info *info); int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info); -- 2.47.3 From nobody Wed Sep 10 01:55:28 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A169304994 for ; Mon, 8 Sep 2025 12:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335591; cv=none; b=K8z3yDqBdTvUrQCNuLhWIPkSV+CinkFcBNuypAIKSZ1WlSy/475VhGKp4Pof6vJvwc6+dFwg4EQM+u6UOGve4gLCfUy+YKNCik+qWzNGdA+b6WI5EyYnktvQKZcnNUZ1zgRiaF1VwwEXgRtfAD6sCB9MyA1kr5D71bZn7kkV5z8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335591; c=relaxed/simple; bh=eIoIGMNmHpncgrZqDWheiR7G/ij0Gu/wz7/Y5EiAJMU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cUkZImmuag9bzz4HXk/EiVM02OkBOgCSFr/v8r9sw+rF+wZSLi1rlPBHf6NgAd2+Srlgs6YSTHg1bqicrpdSIpTzNua4dSoP9rJufAYx69xVP86R0+9yt9GZYQL2w40oIpg7sYDDLl7+ay7NNnqWsaSYqNHD52+cc7ODcnnRKEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uvbG9-0003S7-F8; Mon, 08 Sep 2025 14:46:13 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uvbG7-000Fiq-2a; Mon, 08 Sep 2025 14:46:11 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.98.2) (envelope-from ) id 1uvbG7-0000000CKJd-2xFm; Mon, 08 Sep 2025 14:46:11 +0200 From: Oleksij Rempel To: Andrew Lunn , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Donald Hunter , Jonathan Corbet , Heiner Kallweit , Russell King , Kory Maincent , Maxime Chevallier , Nishanth Menon Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, linux-doc@vger.kernel.org, Michal Kubecek , Roan van Dijk Subject: [PATCH net-next v5 3/5] ethtool: netlink: add lightweight MSE reporting to LINKSTATE_GET Date: Mon, 8 Sep 2025 14:46:08 +0200 Message-ID: <20250908124610.2937939-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250908124610.2937939-1-o.rempel@pengutronix.de> References: <20250908124610.2937939-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Extend ETHTOOL_MSG_LINKSTATE_GET to optionally return a simplified Mean Square Error (MSE) reading alongside existing link status fields. The new attributes are: - ETHTOOL_A_LINKSTATE_MSE_VALUE: current average MSE value - ETHTOOL_A_LINKSTATE_MSE_MAX: scale limit for the reported value - ETHTOOL_A_LINKSTATE_MSE_CHANNEL: source channel selector This path reuses the PHY MSE core API, but only retrieves a single value intended for quick link-health checks: * If the PHY supports a WORST channel selector, report its current average MSE. * Otherwise, if LINK-wide measurements are supported, report those. * If neither is available, omit the attributes. Unlike the full MSE_GET interface, LINKSTATE_GET does not expose per-channel or peak/worst-peak values and incurs minimal overhead. Drivers that implement get_mse_config() / get_mse_snapshot() will automatically populate this data. The intent is to provide tooling with a =E2=80=9Cfast path=E2=80=9D health = indicator without issuing a separate MSE_GET request, though the long-term overlap with the full interface may need reevaluation. Signed-off-by: Oleksij Rempel Reviewed-by: Kory Maincent --- changes v3: - add missing yaml spec --- Documentation/netlink/specs/ethtool.yaml | 9 ++ Documentation/networking/ethtool-netlink.rst | 9 ++ .../uapi/linux/ethtool_netlink_generated.h | 3 + net/ethtool/linkstate.c | 84 +++++++++++++++++++ 4 files changed, 105 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netli= nk/specs/ethtool.yaml index d69dd3fb534b..3f1f19c9c18a 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -708,6 +708,15 @@ attribute-sets: - name: ext-down-cnt type: u32 + - + name: mse-value + type: u32 + - + name: mse-max + type: u32 + - + name: mse-channel + type: u32 - name: debug attr-cnt-name: __ethtool-a-debug-cnt diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/n= etworking/ethtool-netlink.rst index aae53f39c2b0..b3ebd4da3562 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -530,6 +530,9 @@ Kernel response contents: ``ETHTOOL_A_LINKSTATE_EXT_STATE`` u8 link extended state ``ETHTOOL_A_LINKSTATE_EXT_SUBSTATE`` u8 link extended substate ``ETHTOOL_A_LINKSTATE_EXT_DOWN_CNT`` u32 count of link down events + ``ETHTOOL_A_LINKSTATE_MSE_VALUE`` u32 Current average MSE value + ``ETHTOOL_A_LINKSTATE_MSE_MAX`` u32 Max scale for average MSE + ``ETHTOOL_A_LINKSTATE_MSE_CHANNEL`` u32 Source of MSE value =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 For most NIC drivers, the value of ``ETHTOOL_A_LINKSTATE_LINK`` returns @@ -541,6 +544,12 @@ optional values. ethtool core can provide either both ``ETHTOOL_A_LINKSTATE_EXT_STATE`` and ``ETHTOOL_A_LINKSTATE_EXT_SUBSTATE``, or only ``ETHTOOL_A_LINKSTATE_EXT_STATE``, or none of them. =20 +``ETHTOOL_A_LINKSTATE_MSE_VALUE`` and ``ETHTOOL_A_LINKSTATE_MSE_MAX`` are +optional values. The MSE value provided by this interface is a lightweight, +less detailed version for quick health checks. If only one channel is used= , it +returns the current average MSE value. If multiple channels are supported,= it +returns the current average MSE of the channel with the worst MSE. + ``LINKSTATE_GET`` allows dump requests (kernel returns reply messages for = all devices supporting the request). =20 diff --git a/include/uapi/linux/ethtool_netlink_generated.h b/include/uapi/= linux/ethtool_netlink_generated.h index 8317e4b230a5..a9ef0ec11695 100644 --- a/include/uapi/linux/ethtool_netlink_generated.h +++ b/include/uapi/linux/ethtool_netlink_generated.h @@ -331,6 +331,9 @@ enum { ETHTOOL_A_LINKSTATE_EXT_STATE, ETHTOOL_A_LINKSTATE_EXT_SUBSTATE, ETHTOOL_A_LINKSTATE_EXT_DOWN_CNT, + ETHTOOL_A_LINKSTATE_MSE_VALUE, + ETHTOOL_A_LINKSTATE_MSE_MAX, + ETHTOOL_A_LINKSTATE_MSE_CHANNEL, =20 __ETHTOOL_A_LINKSTATE_CNT, ETHTOOL_A_LINKSTATE_MAX =3D (__ETHTOOL_A_LINKSTATE_CNT - 1) diff --git a/net/ethtool/linkstate.c b/net/ethtool/linkstate.c index 05a5f72c99fa..b27fb0ffc526 100644 --- a/net/ethtool/linkstate.c +++ b/net/ethtool/linkstate.c @@ -14,6 +14,9 @@ struct linkstate_reply_data { int link; int sqi; int sqi_max; + u32 mse_value; + u32 mse_max; + u32 mse_channel; struct ethtool_link_ext_stats link_stats; bool link_ext_state_provided; struct ethtool_link_ext_state_info ethtool_link_ext_state_info; @@ -76,6 +79,65 @@ static bool linkstate_sqi_valid(struct linkstate_reply_d= ata *data) data->sqi <=3D data->sqi_max; } =20 +static int linkstate_get_mse(struct phy_device *phydev, + struct linkstate_reply_data *data) +{ + struct phy_mse_snapshot snapshot =3D {}; + struct phy_mse_config config =3D {}; + int channel, ret; + + if (!phydev) + return -EOPNOTSUPP; + + mutex_lock(&phydev->lock); + + if (!phydev->drv || !phydev->drv->get_mse_config || + !phydev->drv->get_mse_snapshot) { + ret =3D -EOPNOTSUPP; + goto unlock; + } + + if (!phydev->link) { + ret =3D -ENETDOWN; + goto unlock; + } + + ret =3D phydev->drv->get_mse_config(phydev, &config); + if (ret) + goto unlock; + + if (config.supported_caps & PHY_MSE_CAP_WORST_CHANNEL) { + channel =3D PHY_MSE_CHANNEL_WORST; + } else if (config.supported_caps & PHY_MSE_CAP_LINK) { + channel =3D PHY_MSE_CHANNEL_LINK; + } else { + ret =3D -EOPNOTSUPP; + goto unlock; + } + + ret =3D phydev->drv->get_mse_snapshot(phydev, channel, &snapshot); + if (ret) + goto unlock; + + data->mse_value =3D snapshot.average_mse; + data->mse_max =3D config.max_average_mse; + data->mse_channel =3D channel; + +unlock: + mutex_unlock(&phydev->lock); + return ret; +} + +static bool linkstate_mse_critical_error(int err) +{ + return err < 0 && err !=3D -EOPNOTSUPP && err !=3D -ENETDOWN; +} + +static bool linkstate_mse_valid(struct linkstate_reply_data *data) +{ + return data->mse_max > 0 && data->mse_value <=3D data->mse_max; +} + static int linkstate_get_link_ext_state(struct net_device *dev, struct linkstate_reply_data *data) { @@ -125,6 +187,10 @@ static int linkstate_prepare_data(const struct ethnl_r= eq_info *req_base, goto out; data->sqi_max =3D ret; =20 + ret =3D linkstate_get_mse(phydev, data); + if (linkstate_mse_critical_error(ret)) + goto out; + if (dev->flags & IFF_UP) { ret =3D linkstate_get_link_ext_state(dev, data); if (ret < 0 && ret !=3D -EOPNOTSUPP && ret !=3D -ENODATA) @@ -164,6 +230,12 @@ static int linkstate_reply_size(const struct ethnl_req= _info *req_base, len +=3D nla_total_size(sizeof(u32)); /* LINKSTATE_SQI_MAX */ } =20 + if (linkstate_mse_valid(data)) { + len +=3D nla_total_size(sizeof(u32)); /* LINKSTATE_MSE_VALUE */ + len +=3D nla_total_size(sizeof(u32)); /* LINKSTATE_MSE_MAX */ + len +=3D nla_total_size(sizeof(u32)); /* LINKSTATE_MSE_CHANNEL */ + } + if (data->link_ext_state_provided) len +=3D nla_total_size(sizeof(u8)); /* LINKSTATE_EXT_STATE */ =20 @@ -195,6 +267,18 @@ static int linkstate_fill_reply(struct sk_buff *skb, return -EMSGSIZE; } =20 + if (linkstate_mse_valid(data)) { + if (nla_put_u32(skb, ETHTOOL_A_LINKSTATE_MSE_VALUE, + data->mse_value)) + return -EMSGSIZE; + if (nla_put_u32(skb, ETHTOOL_A_LINKSTATE_MSE_MAX, + data->mse_max)) + return -EMSGSIZE; + if (nla_put_u32(skb, ETHTOOL_A_LINKSTATE_MSE_CHANNEL, + data->mse_channel)) + return -EMSGSIZE; + } + if (data->link_ext_state_provided) { if (nla_put_u8(skb, ETHTOOL_A_LINKSTATE_EXT_STATE, data->ethtool_link_ext_state_info.link_ext_state)) --=20 2.47.3 From nobody Wed Sep 10 01:55:29 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A1F230499B for ; Mon, 8 Sep 2025 12:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335591; cv=none; b=VNqOGKoqJA3W2BCUomkd/kqTG/K29XzCNTxWv9Sas1SB1hP/nBvQw9Pu9J2YT1NOBOmib6e2MIqD6jJ1h+rllxtcfXJsT78BpTqpfi8T16d7g9LE3hNr+rmNZf7CYbMz/ZyKmfFbE20Y06mloM+Ql9gIr73Wb1oEaQLKdp1tWXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335591; c=relaxed/simple; bh=eqi5cWxql2GFQOQrFamav+SZLeSxTtB7OrfG1LHpA/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QFnYGWV2XeNkteyWn1kw8oJACLCZL3PY4Gl6bhQTbGmIIKsvOoIXWpkUjo8AsRvt+hKynBbmiFDrcoiha6uETzdS4pL592J2Dh/hIEoXbOGGqY8DTqSXBZUu5PYHNtP4a54TZ3ssgHgfNyU+iiaO4/WuIYNzk8n3qgR9v9huBUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uvbG9-0003S9-F8; Mon, 08 Sep 2025 14:46:13 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uvbG7-000Fis-2h; Mon, 08 Sep 2025 14:46:11 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.98.2) (envelope-from ) id 1uvbG7-0000000CKJo-34Ag; Mon, 08 Sep 2025 14:46:11 +0200 From: Oleksij Rempel To: Andrew Lunn , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Donald Hunter , Jonathan Corbet , Heiner Kallweit , Russell King , Kory Maincent , Maxime Chevallier , Nishanth Menon Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, linux-doc@vger.kernel.org, Michal Kubecek , Roan van Dijk Subject: [PATCH net-next v5 4/5] net: phy: micrel: add MSE interface support for KSZ9477 family Date: Mon, 8 Sep 2025 14:46:09 +0200 Message-ID: <20250908124610.2937939-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250908124610.2937939-1-o.rempel@pengutronix.de> References: <20250908124610.2937939-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Implement the get_mse_config() and get_mse_snapshot() PHY driver ops for KSZ9477-series integrated PHYs to demonstrate the new PHY MSE UAPI. These PHYs do not expose a documented direct MSE register, but the Signal Quality Indicator (SQI) registers are derived from the internal MSE computation. This hook maps SQI readings into the MSE interface so that tooling can retrieve the raw value together with metadata for correct interpretation in userspace. Behaviour: - For 1000BASE-T, report per-channel (A=E2=80=93D) values and support a WORST channel selector. - For 100BASE-TX, only LINK-wide measurements are available. - Report average MSE only, with a max scale based on KSZ9477_MMD_SQI_MASK and a fixed refresh rate of 2 =C2=B5s. This mapping differs from the OPEN Alliance SQI definition, which assigns thresholds such as pre-fail indices; the MSE interface instead provides the raw measurement, leaving interpretation to userspace. Signed-off-by: Oleksij Rempel --- drivers/net/phy/micrel.c | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index e403cbbcead5..075ac5093390 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -2320,6 +2320,80 @@ static int kszphy_get_sqi_max(struct phy_device *phy= dev) return KSZ9477_SQI_MAX; } =20 +static int kszphy_get_mse_config(struct phy_device *phydev, + struct phy_mse_config *config) +{ + if (phydev->speed =3D=3D SPEED_1000) + config->supported_caps |=3D PHY_MSE_CAP_CHANNEL_A | + PHY_MSE_CAP_CHANNEL_B | + PHY_MSE_CAP_CHANNEL_C | + PHY_MSE_CAP_CHANNEL_D | + PHY_MSE_CAP_WORST_CHANNEL; + else if (phydev->speed =3D=3D SPEED_100) + config->supported_caps |=3D PHY_MSE_CAP_LINK; + else + return -EOPNOTSUPP; + + config->max_average_mse =3D FIELD_MAX(KSZ9477_MMD_SQI_MASK); + config->refresh_rate_ps =3D 2000000; /* 2 us */ + /* Estimated from link modulation (125 MBd per channel) and documented + * refresh rate of 2 =C2=B5s + */ + config->num_symbols =3D 250; + + config->supported_caps |=3D PHY_MSE_CAP_AVG; + + return 0; +} + +static int kszphy_get_mse_snapshot(struct phy_device *phydev, u32 channel, + struct phy_mse_snapshot *snapshot) +{ + u8 num_channels; + int ret; + + if (phydev->speed =3D=3D SPEED_1000) + num_channels =3D 4; + else if (phydev->speed =3D=3D SPEED_100) + num_channels =3D 1; + else + return -EOPNOTSUPP; + + if (channel =3D=3D PHY_MSE_CHANNEL_WORST) { + u32 worst_val =3D 0; + int i; + + for (i =3D 0; i < num_channels; i++) { + ret =3D phy_read_mmd(phydev, MDIO_MMD_PMAPMD, + KSZ9477_MMD_SIGNAL_QUALITY_CHAN_A + i); + if (ret < 0) + return ret; + + ret =3D FIELD_GET(KSZ9477_MMD_SQI_MASK, ret); + if (ret > worst_val) + worst_val =3D ret; + } + snapshot->average_mse =3D worst_val; + } else if (channel =3D=3D PHY_MSE_CHANNEL_LINK && num_channels =3D=3D 1) { + ret =3D phy_read_mmd(phydev, MDIO_MMD_PMAPMD, + KSZ9477_MMD_SIGNAL_QUALITY_CHAN_A); + if (ret < 0) + return ret; + snapshot->average_mse =3D FIELD_GET(KSZ9477_MMD_SQI_MASK, ret); + } else if (channel >=3D PHY_MSE_CHANNEL_A && + channel <=3D PHY_MSE_CHANNEL_D) { + ret =3D phy_read_mmd(phydev, MDIO_MMD_PMAPMD, + KSZ9477_MMD_SIGNAL_QUALITY_CHAN_A + channel); + if (ret < 0) + return ret; + snapshot->average_mse =3D FIELD_GET(KSZ9477_MMD_SQI_MASK, ret); + } else { + return -EINVAL; + } + + return 0; +} + static void kszphy_enable_clk(struct phy_device *phydev) { struct kszphy_priv *priv =3D phydev->priv; @@ -6369,6 +6443,8 @@ static struct phy_driver ksphy_driver[] =3D { .cable_test_get_status =3D ksz9x31_cable_test_get_status, .get_sqi =3D kszphy_get_sqi, .get_sqi_max =3D kszphy_get_sqi_max, + .get_mse_config =3D kszphy_get_mse_config, + .get_mse_snapshot =3D kszphy_get_mse_snapshot, } }; =20 module_phy_driver(ksphy_driver); --=20 2.47.3 From nobody Wed Sep 10 01:55:29 2025 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8A0A304984 for ; Mon, 8 Sep 2025 12:46:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335591; cv=none; b=Wbvd83w09Bt5LBJBqbZWM6HjspQ7ehd6+5VtXH7H7Y/9nZo4tvlHz8A/9zKT9Gs+wFcLK7rOMIjYJumxs+QjBftSGwdZs3fj62DOvMvRZyZHc4nRT5UR/dXWMaitulNTQfVpIdxsnfhneYS6Zn87VtsOg55GfGIzAtPGRKg7bmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757335591; c=relaxed/simple; bh=KvPkdza+dT296uEARiCseHwuSIvLjN+tjNRKd1Gy8PY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HwNmNs5tunQEXt6QWaL6fm5QasKz2iNDLecgyg1w+k60N0iSXxLKHfd5rzlGUpl8ZRsYlywfN4LoRr0IvPK+lkd7x/qxmO94bOieo6dg/DKNAIQlz6rJ6EWjr7mY4/7/7m16CoZ3ThFoRADcNIrPv/6RtGbsym2tDHIlFBnGMxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uvbG9-0003SA-F8; Mon, 08 Sep 2025 14:46:13 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uvbG7-000Fiu-2r; Mon, 08 Sep 2025 14:46:11 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.98.2) (envelope-from ) id 1uvbG7-0000000CKJz-3AvL; Mon, 08 Sep 2025 14:46:11 +0200 From: Oleksij Rempel To: Andrew Lunn , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Donald Hunter , Jonathan Corbet , Heiner Kallweit , Russell King , Kory Maincent , Maxime Chevallier , Nishanth Menon Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com, linux-doc@vger.kernel.org, Michal Kubecek , Roan van Dijk Subject: [PATCH net-next v5 5/5] net: phy: dp83td510: add MSE interface support for 10BASE-T1L Date: Mon, 8 Sep 2025 14:46:10 +0200 Message-ID: <20250908124610.2937939-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250908124610.2937939-1-o.rempel@pengutronix.de> References: <20250908124610.2937939-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Implement get_mse_config() and get_mse_snapshot() for the DP83TD510E to expose its Mean Square Error (MSE) register via the new PHY MSE UAPI. The DP83TD510E does not document any peak MSE values; it only exposes a single average MSE register used internally to derive SQI. This implementation therefore advertises only PHY_MSE_CAP_AVG, along with LINK and channel-A selectors. Scaling is fixed to 0xFFFF, and the refresh interval/number of symbols are estimated from 10BASE-T1L symbol rate (7.5 MBd) and typical diagnostic intervals (~1 ms). For 10BASE-T1L deployments, SQI is a reliable indicator of link modulation quality once the link is established, but it does not indicate whether autonegotiation pulses will be correctly received in marginal conditions. MSE provides a direct measurement of slicer error rate that can be used to evaluate if autonegotiation is likely to succeed under a given cable length and condition. In practice, testing such scenarios often requires forcing a fixed-link setup to isolate MSE behaviour from the autonegotiation process. Signed-off-by: Oleksij Rempel --- drivers/net/phy/dp83td510.c | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/net/phy/dp83td510.c b/drivers/net/phy/dp83td510.c index 23af1ac194fa..094c070f3f96 100644 --- a/drivers/net/phy/dp83td510.c +++ b/drivers/net/phy/dp83td510.c @@ -249,6 +249,47 @@ struct dp83td510_priv { #define DP83TD510E_ALCD_COMPLETE BIT(15) #define DP83TD510E_ALCD_CABLE_LENGTH GENMASK(10, 0) =20 +static int dp83td510_get_mse_config(struct phy_device *phydev, + struct phy_mse_config *config) +{ + /* The DP83TD510E datasheet does not specify peak MSE values. + * It only provides a single MSE value which is used to derive SQI. + * Therefore, we only support the average MSE capability. + */ + config->supported_caps =3D PHY_MSE_CAP_AVG | PHY_MSE_CAP_LINK | + PHY_MSE_CAP_CHANNEL_A; + config->max_average_mse =3D 0xFFFF; + + /* The datasheet does not specify the refresh rate or symbol count, + * but based on similar PHYs and standards, we can assume a common + * value. For 10BaseT1L, the symbol rate is 7.5 MBd. A common + * diagnostic interval is around 1ms. + * 7.5e6 symbols/sec * 0.001 sec =3D 7500 symbols. + */ + config->refresh_rate_ps =3D 1000000000; /* 1 ms */ + config->num_symbols =3D 7500; + + return 0; +} + +static int dp83td510_get_mse_snapshot(struct phy_device *phydev, u32 chann= el, + struct phy_mse_snapshot *snapshot) +{ + int ret; + + if (channel !=3D PHY_MSE_CHANNEL_LINK && + channel !=3D PHY_MSE_CHANNEL_A) + return -EOPNOTSUPP; + + ret =3D phy_read_mmd(phydev, MDIO_MMD_VEND2, DP83TD510E_MSE_DETECT); + if (ret < 0) + return ret; + + snapshot->average_mse =3D ret; + + return 0; +} + static int dp83td510_led_brightness_set(struct phy_device *phydev, u8 inde= x, enum led_brightness brightness) { @@ -893,6 +934,9 @@ static struct phy_driver dp83td510_driver[] =3D { .get_phy_stats =3D dp83td510_get_phy_stats, .update_stats =3D dp83td510_update_stats, =20 + .get_mse_config =3D dp83td510_get_mse_config, + .get_mse_snapshot =3D dp83td510_get_mse_snapshot, + .led_brightness_set =3D dp83td510_led_brightness_set, .led_hw_is_supported =3D dp83td510_led_hw_is_supported, .led_hw_control_set =3D dp83td510_led_hw_control_set, --=20 2.47.3