Skip to contentSkip to conversation

ethtool: add interface caps and PHY tests

RFC In review Shubham Das 2 participants 11 messages Sep 30 – Oct 5

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover ethtool: add interface caps and PHY tests

This series adds two new ethtool netlink commands:

1. intf-caps-get: Discovers the functional block layout of a network interface. Each block represents a hardware point (MAC/PHY/MODULE) at a specific 802.3 sublayer (RS/PCS/FEC/PMA/PMD) with its supported capabilities (loopback, test patterns, BERT, error injection).

2. Add ETHTOOL_MSG_PHY_TEST_GET and ETHTOOL_MSG_PHY_TEST_SET for per-block, per-lane PHY testing using test patterns, BERT (Bit Error Ratio Test), and error injection. The block_id from intf-caps-get identifies which hardware point to test.

The block model uses:
- component: identifies the hardware entity (MAC, PHY, or module).
- sublayer: identifies the 802.3 sublayer (RS, PCS, FEC, PMA, or PMD).
- instance: identifies multiple instances of the same component, such as internal and external PHYs.
- depth: identifies the host-side or line-side block within the same sublayer.

Prior discussion on this proposal:
https://lore.kernel.org/netdev/SN7PR11MB810923BBDEC398E860099150FF1B2

Shubham Das (2):
ethtool: add interface capabilities query (intf-caps-get)
ethtool: add PHY test framework (phy-test-get, phy-test-set)

 Documentation/netlink/specs/ethtool.yaml      | 211 ++++++++++++++++++
 include/linux/ethtool.h                       |  94 ++++++++
 include/linux/phy.h                           |  16 ++
 include/linux/phylink.h                       |   7 +
 .../uapi/linux/ethtool_netlink_generated.h    | 106 +++++++++
 net/ethtool/Makefile                          |   2 +-
 net/ethtool/intf_caps.c                       | 130 +++++++++++
 net/ethtool/netlink.c                         |  24 ++
 net/ethtool/netlink.h                         |  10 +
 net/ethtool/phytest.c                         | 183 +++++++++++++++
 10 files changed, 782 insertions(+), 1 deletion(-)
 create mode 100644 net/ethtool/intf_caps.c
 create mode 100644 net/ethtool/phytest.c

base-commit: 001b5d347d8ba39b2dccaefcc57967b18caec8fe

Signature · 1 line
2.25.1
#1 lore raw

RFC 1/2 ethtool: add interface capabilities query (intf-caps-get)

Modern network interfaces contain multiple functional blocks along the data path (MAC, PHY, MODULE), each at different 802.3 sublayers (RS, PCS, FEC, PMA, PMD). Currently there is no standard way for userspace to discover this topology or query which blocks support loopback, pattern generation, or BERT.

Add ETHTOOL_MSG_INTF_CAPS_GET so drivers can expose the block layout and per-block capabilities. This allows userspace to discover the interface topology and testing capabilities dynamically, rather than relying on device-specific knowledge.

Each block reports:
- id: unique block identifier for per-block commands
- component: MAC, PHY, or MODULE
- sublayer: RS, PCS, FEC, PMA, PMD, or NONE
- instance: distinguishes multiple instances of the same component (e.g., internal vs external PHY, host vs port MAC)
- name: driver-chosen label (e.g., host-pma, ext-phy-pma)
- depth: ordering within same (component, sublayer) tuple
- lanes: number of SerDes lanes at this block
- loopback_supported: bitmask of supported loopback directions
- supported_tx_patterns: bitmask of patterns block can generate
- supported_rx_patterns: bitmask of patterns block can check
- error_inject_supported: block supports bit error injection
- bert_supported: block supports BERT (Bit Error Ratio Test)

---
 Documentation/netlink/specs/ethtool.yaml      |  99 +++++++++++++
 include/linux/ethtool.h                       |  49 +++++++
 include/linux/phy.h                           |   8 ++
 include/linux/phylink.h                       |   3 +
 .../uapi/linux/ethtool_netlink_generated.h    |  48 +++++++
 net/ethtool/Makefile                          |   2 +-
 net/ethtool/intf_caps.c                       | 130 ++++++++++++++++++
 net/ethtool/netlink.c                         |  10 ++
 net/ethtool/netlink.h                         |   3 +
 9 files changed, 351 insertions(+), 1 deletion(-)
 create mode 100644 net/ethtool/intf_caps.c
Documentation/netlink/specs/ethtool.yaml +99 -0
index 5dd4d1b5d94b..77d77a896fb0 100644
@@ -210,6 +210,25 @@ definitions:
       -
         name: discard
         value: 31
+  -
+    name: intf-component
+    type: enum
+    doc: Type of hardware component in the interface.
+    entries:
+      - mac
+      - phy
+      - module
+  -
+    name: intf-sublayer
+    type: enum
+    doc: 802.3 sublayer within a component.
+    entries:
+      - none
+      - rs
+      - pcs
+      - fec
+      - pma
+      - pmd
 
 attribute-sets:
   -
@@ -1905,6 +1924,73 @@ attribute-sets:
         name: link
         type: nest
         nested-attributes: mse-snapshot
+  -
+    name: intf-block
+    doc: A single functional block in the interface.
+    attributes:
+      -
+        name: id
+        type: u32
+      -
+        name: component
+        type: u32
+        enum: intf-component
+      -
+        name: sublayer
+        type: u32
+        enum: intf-sublayer
+      -
+        name: instance
+        type: u32
+        doc: |
+          Identifies the hardware entity when multiple instances of
+          the same component exist in the interface. The driver
+          assigns instance numbers sequentially based on position in
+          the physical path. Defaults to 0 when only one instance of
+          a given component exists.
+          For PHY: instance 0 is the internal/host-side PHY,
+          instance 1 is an external PHY further along the path
+          toward the line side.
+          For MAC: instance 0 is the host-facing MAC, instance 1 is
+          a secondary MAC further along the data path (e.g., behind
+          an embedded switch).
+      -
+        name: name
+        type: string
+      -
+        name: depth
+        type: u8
+      -
+        name: lanes
+        type: u32
+      -
+        name: loopback-supported
+        type: u32
+      -
+        name: supported-tx-patterns
+        type: u32
+      -
+        name: supported-rx-patterns
+        type: u32
+      -
+        name: error-inject-supported
+        type: flag
+      -
+        name: bert-supported
+        type: flag
+  -
+    name: intf-caps
+    doc: Interface capabilities message.
+    attributes:
+      -
+        name: header
+        type: nest
+        nested-attributes: header
+      -
+        name: blocks
+        type: nest
+        nested-attributes: intf-block
+        multi-attr: true
 
 operations:
   enum-model: directional
@@ -2859,6 +2945,19 @@ operations:
             - worst-channel
             - link
       dump: *mse-get-op
+    -
+      name: intf-caps-get
+      doc: Get interface capabilities (functional block layout).
+      attribute-set: intf-caps
+      do: &intf-caps-get-op
+        request:
+          attributes:
+            - header
+        reply:
+          attributes:
+            - header
+            - blocks
+      dump: *intf-caps-get-op
 
 mcast-groups:
   list:
include/linux/ethtool.h +49 -0

61 lines not on this page · raw message

include/linux/phy.h +8 -0
index 5f8d65868e0f..f3c5bc976b4a 100644
@@ -1391,6 +1391,14 @@ struct phy_driver {
 	 * shall be returned if speed selection is not supported.
 	 */
 	int (*set_loopback)(struct phy_device *dev, bool enable, int speed);
+
+	/**
+	 * @get_intf_caps: Report functional blocks and capabilities of the PHY.
+	 */
+	int (*get_intf_caps)(struct phy_device *dev,
+			     struct ethtool_intf_block *blocks,
+			     u32 max_blocks);
+
 	/** @get_sqi: Get the signal quality indication */
 	int (*get_sqi)(struct phy_device *dev);
 	/** @get_sqi_max: Get the maximum signal quality indication */
include/linux/phylink.h +3 -0
index 2bc0db3d52ac..86a91a4436fe 100644
@@ -765,6 +765,9 @@ int phylink_ethtool_set_pauseparam(struct phylink *,
 int phylink_get_eee_err(struct phylink *);
 int phylink_ethtool_get_eee(struct phylink *link, struct ethtool_keee *eee);
 int phylink_ethtool_set_eee(struct phylink *link, struct ethtool_keee *eee);
+int phylink_ethtool_get_intf_caps(struct phylink *pl,
+				  struct ethtool_intf_block *blocks,
+				  u32 max_blocks);
 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
 int phylink_speed_down(struct phylink *pl, bool sync);
 int phylink_speed_up(struct phylink *pl);
include/uapi/linux/ethtool_netlink_generated.h +48 -0

64 lines not on this page · raw message

net/ethtool/Makefile +1 -1
index 629c10916670..773b21c7ab7c 100644
@@ -9,4 +9,4 @@ ethtool_nl-y	:= netlink.o bitset.o strset.o linkinfo.o linkmodes.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 \
-		   phy.o tsconfig.o mse.o
+		   phy.o tsconfig.o mse.o intf_caps.o
net/ethtool/intf_caps.c new file +130 -0

130 lines not on this page · raw message

net/ethtool/netlink.c +10 -0
index 1af395b54330..bf0040a519fa 100644
@@ -431,6 +431,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
 	[ETHTOOL_MSG_TSCONFIG_SET]	= &ethnl_tsconfig_request_ops,
 	[ETHTOOL_MSG_PHY_GET]		= &ethnl_phy_request_ops,
 	[ETHTOOL_MSG_MSE_GET]		= &ethnl_mse_request_ops,
+	[ETHTOOL_MSG_INTF_CAPS_GET]	= &ethnl_intf_caps_request_ops,
 };
 
 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -1572,6 +1573,15 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.policy = ethnl_mse_get_policy,
 		.maxattr = ARRAY_SIZE(ethnl_mse_get_policy) - 1,
 	},
+	{
+		.cmd	= ETHTOOL_MSG_INTF_CAPS_GET,
+		.doit	= ethnl_default_doit,
+		.start	= ethnl_default_start,
+		.dumpit	= ethnl_default_dumpit,
+		.done	= ethnl_default_done,
+		.policy = ethnl_intf_caps_get_policy,
+		.maxattr = ETHTOOL_A_INTF_CAPS_HEADER,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +3 -0
index 3e969a070f9f..73fd23dbc1e3 100644
@@ -474,6 +474,7 @@ 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 ethnl_request_ops ethnl_intf_caps_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];
@@ -530,6 +531,8 @@ 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_TSCONFIG_HEADER + 1];
 extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX + 1];
 extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER + 1];
+extern const struct nla_policy
+ethnl_intf_caps_get_policy[ETHTOOL_A_INTF_CAPS_HEADER + 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);
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [RFC net-next 1/2] ethtool: add interface capabilities query (intf-caps-get)

net/ethtool/netlink.h extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1]; · line 535

Quoted 3 lines

extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER + 1];

net/ethtool/netlink.h +2 -0
+extern const struct nla_policy
+ethnl_intf_caps_get_policy[ETHTOOL_A_INTF_CAPS_HEADER + 1];

That is odd wrapping. As far as i can see, no other declaration is wrapped like this. Is this because of the 80 character rules? It is better to keep with the existing coding style.

Andrew

---
pw-bot: cr

#3 lore raw

RE: [RFC net-next 1/2] ethtool: add interface capabilities query (intf-caps-get)

Quoted 8 lines

net/ethtool/netlink.h extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1]; · line 535

Quoted 4 lines

extern const struct nla_policy
ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER + 1];

net/ethtool/netlink.h +2 -0
+extern const struct nla_policy
+ethnl_intf_caps_get_policy[ETHTOOL_A_INTF_CAPS_HEADER + 1];

That is odd wrapping. As far as i can see, no other declaration is wrapped like this. Is this because of the 80 character rules? It is better to keep with the existing coding style.

Thanks for the review. Agreed, that wrapping is unnecessary and inconsistent with the existing declarations. I've corrected it and will include the change in v2.

Quoted 4 lines

Andrew

---
pw-bot: cr

#4 lore raw

RFC 1/2 ethtool: Add interface capability get support

In reply to Shubham Das

Add the --interface-capabilities command to display the interface block topology and per-block support for loopback, PRBS, BERT, and error injection.

Each block reports:
- id: unique block identifier for per-block commands
- component: MAC, PHY, or MODULE
- sublayer: RS, PCS, FEC, PMA, PMD, or NONE
- instance: distinguishes multiple instances of the same component (for example, internal vs external PHY, host vs port MAC)
- name: driver-chosen label (for example, host-pma, ext-phy-pma)
- depth: ordering within the same (component, sublayer) tuple
- lanes: number of SerDes lanes at this block
- loopback_supported: supported loopback direction bitmask
- supported_tx_patterns: patterns the block can generate
- supported_rx_patterns: patterns the block can check
- error_inject_supported: block supports bit error injection
- bert_supported: block supports BERT (Bit Error Ratio Test)

Example:
ethtool --interface-capabilities eth1

---
 Makefile.am                            |   1 +
 ethtool.c                              |   5 +
 netlink/extapi.h                       |   2 +
 netlink/intf_caps.c                    | 230 +++++++++++++++++++++++++
 uapi/linux/ethtool_netlink_generated.h |  73 ++++++++
 5 files changed, 311 insertions(+)
 create mode 100644 netlink/intf_caps.c
Makefile.am +1 -0
index db22be4..67f1be4 100644
@@ -55,6 +55,7 @@ ethtool_SOURCES += \
 		  netlink/pse-pd.c \
 		  netlink/phy.c \
 		  netlink/tsconfig.c \
+		  netlink/intf_caps.c \
 		  netlink/mse.c \
 		  uapi/linux/const.h uapi/linux/ethtool.h \
 		  uapi/linux/ethtool_netlink.h \
ethtool.c +5 -0
index 30a1d97..bb36754 100644
@@ -6514,6 +6514,11 @@ static const struct option args[] = {
 		.nlfunc	= nl_gmse,
 		.help	= "Show Mean Square Error (MSE) diagnostics",
 	},
+	{
+		.opts	= "--interface-capabilities",
+		.nlfunc	= nl_get_intf_caps,
+		.help	= "Show interface block capabilities",
+	},
 	{
 		.opts	= "-h|--help",
 		.no_dev	= true,
netlink/extapi.h +2 -0
index e10af62..696f829 100644
@@ -67,6 +67,7 @@ void nl_monitor_usage(void);
 int nl_get_eeprom_page(struct cmd_context *ctx,
 		       struct ethtool_module_eeprom *request);
 
+int nl_get_intf_caps(struct cmd_context *ctx);
 #else /* ETHTOOL_ENABLE_NETLINK */
 
 static inline void netlink_run_handler(struct cmd_context *ctx __maybe_unused,
@@ -142,6 +143,7 @@ nl_get_eeprom_page(struct cmd_context *ctx __maybe_unused,
 #define nl_flash_module_fw	NULL
 #define nl_get_phy		NULL
 #define nl_gmse			NULL
+#define nl_get_intf_caps	NULL
 
 #endif /* ETHTOOL_ENABLE_NETLINK */
 
netlink/intf_caps.c new file +230 -0

230 lines not on this page · raw message

uapi/linux/ethtool_netlink_generated.h +73 -0

91 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw

cover add interface caps and PHY tests

In reply to Shubham Das

This series adds two new ethtool netlink commands:

1. intf-caps-get: Discovers the functional block layout of a network interface. Each block represents a hardware point (MAC/PHY/MODULE) at a specific 802.3 sublayer (RS/PCS/FEC/PMA/PMD) with its supported capabilities (loopback, test patterns, BERT, error injection).

2. Add ETHTOOL_MSG_PHY_TEST_GET and ETHTOOL_MSG_PHY_TEST_SET for per-block, per-lane PHY testing using test patterns, BERT (Bit Error Ratio Test), and error injection. The block_id from intf-caps-get identifies which hardware point to test.

The block model uses:
- component: identifies the hardware entity (MAC, PHY, or module).
- sublayer: identifies the 802.3 sublayer (RS, PCS, FEC, PMA, or PMD).
- instance: identifies multiple instances of the same component, such as internal and external PHYs.
- depth: identifies the host-side or line-side block within the same sublayer.

Prior discussion on this proposal:
https://lore.kernel.org/netdev/SN7PR11MB810923BBDEC398E860099150FF1B2

Shubham Das (2):
ethtool: Add interface capability get support
ethtool: Add PHY test and BERT support

 Makefile.am                            |   2 +
 ethtool.c                              |  21 ++
 netlink/desc-ethtool.c                 |  18 ++
 netlink/extapi.h                       |   6 +
 netlink/intf_caps.c                    | 230 ++++++++++++++++
 netlink/phytest.c                      | 352 +++++++++++++++++++++++++
 uapi/linux/ethtool_netlink_generated.h | 104 ++++++++
 7 files changed, 733 insertions(+)
 create mode 100644 netlink/intf_caps.c
 create mode 100644 netlink/phytest.c

base-commit: ec1ef702cb5e8bda6bd5fe3b2213419c8427bb7c

Signature · 1 line
2.25.1
#6 lore raw

RFC 2/2 ethtool: add PHY test framework

In reply to Shubham Das

Add ETHTOOL_MSG_PHY_TEST_GET and ETHTOOL_MSG_PHY_TEST_SET to configure and monitor PHY test functions on individual interface blocks and lanes.

The framework uses the block identifier returned by ETHTOOL_MSG_INTF_CAPS_GET to select the hardware block under test. This allows userspace to target test operations at specific PHY, MAC, or module datapath components exposed by the driver.

Supported test patterns:
- PRBS: prbs7, prbs9, prbs11, prbs13, prbs15, prbs23, prbs31
- PRBS quaternary (PAM4): prbs13q, prbs31q
- SSPRQ (Short Stress Pattern Random Quaternary)
- Square wave: square-nrz, square-pam4 (JP03A)
- TX linearity (LIN, IEEE 802.3 94.2.9.4)
- Scrambled idle
- 8b/10b comma: K28.5, K28.7

Supported test actions:
- bert start / stop: bit error ratio measurement
- inject-errors N: inject bit errors into the TX stream
- active-tests: bitmask showing which tests are running

Usage flow:
1. ethtool --get-intf-caps eth1 # discover testable blocks
2. ethtool --phy-test eth1 block 3 lane 0 tx-pattern prbs31
3. ethtool --phy-test eth2 block 3 lane 0 rx-pattern prbs31
4. ethtool --phy-test eth2 block 3 lane 0 bert start
5. ethtool --show-phy-test eth2 block 3 # read BERT counters
6. ethtool --phy-test eth2 block 3 lane 0 inject-errors 5

     # verify checker
  7. ethtool --show-phy-test eth2 block 3  # confirm error count increased
  8. ethtool --phy-test eth2 block 3 lane 0 bert stop
---
 Documentation/netlink/specs/ethtool.yaml      | 112 +++++++++++
 include/linux/ethtool.h                       |  45 +++++
 include/linux/phy.h                           |   8 +
 include/linux/phylink.h                       |   4 +
 .../uapi/linux/ethtool_netlink_generated.h    |  58 ++++++
 net/ethtool/Makefile                          |   2 +-
 net/ethtool/netlink.c                         |  14 ++
 net/ethtool/netlink.h                         |   7 +
 net/ethtool/phytest.c                         | 183 ++++++++++++++++++
 9 files changed, 432 insertions(+), 1 deletion(-)
 create mode 100644 net/ethtool/phytest.c
Documentation/netlink/specs/ethtool.yaml +112 -0
index 77d77a896fb0..6b6949ca27b2 100644
@@ -229,6 +229,37 @@ definitions:
       - fec
       - pma
       - pmd
+  -
+    name: phy-test-pattern
+    type: enum
+    doc: PHY test pattern types for PRBS generation/checking.
+    entries:
+      - off
+      - prbs7
+      - prbs9
+      - prbs11
+      - prbs13
+      - prbs15
+      - prbs23
+      - prbs31
+      - ssprq
+      - prbs13q
+      - prbs31q
+      - square-nrz
+      - square-pam4
+      - tx-linearity
+      - scrambled-idle
+      - k28-5
+      - k28-7
+  -
+    name: phy-test-action
+    type: enum
+    doc: BERT control actions.
+    entries:
+      - none
+      - start
+      - stop
+      - clear
 
 attribute-sets:
   -
@@ -1991,6 +2022,51 @@ attribute-sets:
         type: nest
         nested-attributes: intf-block
         multi-attr: true
+  -
+    name: phy-test
+    doc: PHY test configuration and status.
+    attributes:
+      -
+        name: header
+        type: nest
+        nested-attributes: header
+      -
+        name: block-id
+        type: u32
+      -
+        name: lane
+        type: u32
+      -
+        name: tx-pattern
+        type: u32
+        enum: phy-test-pattern
+      -
+        name: rx-pattern
+        type: u32
+        enum: phy-test-pattern
+      -
+        name: bert-action
+        type: u32
+        enum: phy-test-action
+      -
+        name: inject-error-count
+        type: u32
+      -
+        name: active-tests
+        type: u32
+        doc: Bitmask of currently running tests (bit 0 = BERT).
+      -
+        name: checker-lock
+        type: u8
+      -
+        name: error-count
+        type: u64
+      -
+        name: total-bits-sent
+        type: u64
+      -
+        name: supported-test-patterns
+        type: u32
 
 operations:
   enum-model: directional
@@ -2958,6 +3034,42 @@ operations:
             - header
             - blocks
       dump: *intf-caps-get-op
+    -
+      name: phy-test-get
+      doc: Get PHY test status (patterns, BERT counters).
+      attribute-set: phy-test
+      do:
+        request:
+          attributes:
+            - header
+            - block-id
+            - lane
+        reply:
+          attributes:
+            - header
+            - block-id
+            - lane
+            - tx-pattern
+            - rx-pattern
+            - supported-test-patterns
+            - active-tests
+            - checker-lock
+            - error-count
+            - total-bits-sent
+    -
+      name: phy-test-set
+      doc: Configure PHY test (set patterns, start/stop BERT, inject errors).
+      attribute-set: phy-test
+      do:
+        request:
+          attributes:
+            - header
+            - block-id
+            - lane
+            - tx-pattern
+            - rx-pattern
+            - bert-action
+            - inject-error-count
 
 mcast-groups:
   list:
include/linux/ethtool.h +45 -0

57 lines not on this page · raw message

include/linux/phy.h +8 -0
index f3c5bc976b4a..032f3a57a90b 100644
@@ -1399,6 +1399,14 @@ struct phy_driver {
 			     struct ethtool_intf_block *blocks,
 			     u32 max_blocks);
 
+	/** @set_phy_test: Configure PRBS/BERT on this PHY. */
+	int (*set_phy_test)(struct phy_device *dev,
+			    struct ethtool_phy_test *test);
+
+	/** @get_phy_test: Get PRBS/BERT status from this PHY. */
+	int (*get_phy_test)(struct phy_device *dev,
+			    struct ethtool_phy_test *test);
+
 	/** @get_sqi: Get the signal quality indication */
 	int (*get_sqi)(struct phy_device *dev);
 	/** @get_sqi_max: Get the maximum signal quality indication */
include/linux/phylink.h +4 -0
index 86a91a4436fe..0df8cbf09c56 100644
@@ -768,6 +768,10 @@ int phylink_ethtool_set_eee(struct phylink *link, struct ethtool_keee *eee);
 int phylink_ethtool_get_intf_caps(struct phylink *pl,
 				  struct ethtool_intf_block *blocks,
 				  u32 max_blocks);
+int phylink_ethtool_get_phy_test(struct phylink *pl,
+				 struct ethtool_phy_test *test);
+int phylink_ethtool_set_phy_test(struct phylink *pl,
+				 struct ethtool_phy_test *test);
 int phylink_mii_ioctl(struct phylink *, struct ifreq *, int);
 int phylink_speed_down(struct phylink *pl, bool sync);
 int phylink_speed_up(struct phylink *pl);
include/uapi/linux/ethtool_netlink_generated.h +58 -0

74 lines not on this page · raw message

net/ethtool/Makefile +1 -1
index 773b21c7ab7c..7dd2c5624ced 100644
@@ -9,4 +9,4 @@ ethtool_nl-y	:= netlink.o bitset.o strset.o linkinfo.o linkmodes.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 \
-		   phy.o tsconfig.o mse.o intf_caps.o
+		   phy.o tsconfig.o mse.o intf_caps.o phytest.o
net/ethtool/netlink.c +14 -0
index bf0040a519fa..c15c1488e267 100644
@@ -432,6 +432,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
 	[ETHTOOL_MSG_PHY_GET]		= &ethnl_phy_request_ops,
 	[ETHTOOL_MSG_MSE_GET]		= &ethnl_mse_request_ops,
 	[ETHTOOL_MSG_INTF_CAPS_GET]	= &ethnl_intf_caps_request_ops,
+	[ETHTOOL_MSG_PHY_TEST_GET]	= &ethnl_phy_test_request_ops,
 };
 
 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -1582,6 +1583,19 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.policy = ethnl_intf_caps_get_policy,
 		.maxattr = ETHTOOL_A_INTF_CAPS_HEADER,
 	},
+	{
+		.cmd	= ETHTOOL_MSG_PHY_TEST_GET,
+		.doit	= ethnl_default_doit,
+		.policy = ethnl_phy_test_get_policy,
+		.maxattr = ARRAY_SIZE(ethnl_phy_test_get_policy) - 1,
+	},
+	{
+		.cmd	= ETHTOOL_MSG_PHY_TEST_SET,
+		.flags	= GENL_UNS_ADMIN_PERM,
+		.doit	= ethnl_set_phy_test,
+		.policy = ethnl_phy_test_set_policy,
+		.maxattr = ARRAY_SIZE(ethnl_phy_test_set_policy) - 1,
+	},
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +7 -0
index 73fd23dbc1e3..99055ee080a1 100644
@@ -475,6 +475,7 @@ 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 ethnl_request_ops ethnl_intf_caps_request_ops;
+extern const struct ethnl_request_ops ethnl_phy_test_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];
@@ -533,6 +534,12 @@ extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX
 extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER + 1];
 extern const struct nla_policy
 ethnl_intf_caps_get_policy[ETHTOOL_A_INTF_CAPS_HEADER + 1];
+extern const struct nla_policy
+ethnl_phy_test_get_policy[ETHTOOL_A_PHY_TEST_LANE + 1];
+extern const struct nla_policy
+ethnl_phy_test_set_policy[ETHTOOL_A_PHY_TEST_MAX + 1];
+
+int ethnl_set_phy_test(struct sk_buff *skb, struct genl_info *info);
 
 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);
net/ethtool/phytest.c new file +183 -0

183 lines not on this page · raw message

Signature · 1 line
2.25.1
#7 lore raw

RFC 2/2 ethtool: Add PHY test and BERT support

In reply to Shubham Das

Add ETHTOOL_MSG_PHY_TEST_GET and ETHTOOL_MSG_PHY_TEST_SET to configure and monitor PHY test functions, including TX/RX patterns, BERT control, error injection, and test status reporting.

Supported test patterns:
- PRBS: prbs7, prbs9, prbs11, prbs13, prbs15, prbs23, prbs31
- PRBS quaternary (PAM4): prbs13q, prbs31q
- SSPRQ (Short Stress Pattern Random Quaternary)
- Square wave: square-nrz, square-pam4 (JP03A)
- TX linearity (LIN, IEEE 802.3 94.2.9.4)
- Scrambled idle
- 8b/10b comma: K28.5, K28.7

Supported test actions:
- bert start / stop: bit error ratio measurement
- inject-errors N: inject bit errors into the TX stream
- active-tests: bitmask showing which tests are running

Usage flow:
1. ethtool --get-intf-caps eth1 # discover testable blocks
2. ethtool --phy-test eth1 block 3 lane 0 tx-pattern prbs31
3. ethtool --phy-test eth2 block 3 lane 0 rx-pattern prbs31
4. ethtool --phy-test eth2 block 3 lane 0 bert start
5. ethtool --show-phy-test eth2 block 3 # read BERT counters
6. ethtool --phy-test eth2 block 3 lane 0 inject-errors 5

     # verify checker
  7. ethtool --show-phy-test eth2 block 3  # confirm error count increased
  8. ethtool --phy-test eth2 block 3 lane 0 bert stop
---
 Makefile.am                            |   1 +
 ethtool.c                              |  16 ++
 netlink/desc-ethtool.c                 |  18 ++
 netlink/extapi.h                       |   4 +
 netlink/phytest.c                      | 354 +++++++++++++++++++++++++
 uapi/linux/ethtool_netlink_generated.h |  31 +++
 6 files changed, 424 insertions(+)
 create mode 100644 netlink/phytest.c
Makefile.am +1 -0
index 67f1be4..b20f561 100644
@@ -55,6 +55,7 @@ ethtool_SOURCES += \
 		  netlink/pse-pd.c \
 		  netlink/phy.c \
 		  netlink/tsconfig.c \
+		  netlink/phytest.c \
 		  netlink/intf_caps.c \
 		  netlink/mse.c \
 		  uapi/linux/const.h uapi/linux/ethtool.h \
ethtool.c +16 -0
index bb36754..ff6194f 100644
@@ -6514,6 +6514,22 @@ static const struct option args[] = {
 		.nlfunc	= nl_gmse,
 		.help	= "Show Mean Square Error (MSE) diagnostics",
 	},
+	{
+		.opts	= "--show-phy-test",
+		.nlfunc	= nl_get_phy_test,
+		.help	= "Show PHY test configuration and supported patterns",
+	},
+	{
+		.opts	= "--phy-test",
+		.nlfunc	= nl_set_phy_test,
+		.help	= "Configure PHY test patterns and BERT",
+		.xhelp  = "             [ block N ]\n"
+			  "             lane N\n"
+			  "             [ tx-pattern off|prbs7|prbs9|prbs11|prbs13|prbs15|prbs23|prbs31|ssprq|prbs13q|prbs31q|square ]\n"
+			  "             [ rx-pattern off|prbs7|prbs9|prbs11|prbs13|prbs15|prbs23|prbs31|ssprq|prbs13q|prbs31q|square ]\n"
+			  "             [ bert start|stop ]\n"
+			  "             [ inject-errors N ]\n"
+	},
 	{
 		.opts	= "--interface-capabilities",
 		.nlfunc	= nl_get_intf_caps,
netlink/desc-ethtool.c +18 -0
index e8d6c59..f8320c8 100644
@@ -666,6 +666,21 @@ static const struct pretty_nla_desc __mse_desc[] = {
 	NLATTR_DESC_NESTED(ETHTOOL_A_MSE_LINK, mse_snapshot),
 };
 
+static const struct pretty_nla_desc __phy_test_desc[] = {
+	NLATTR_DESC_INVALID(ETHTOOL_A_PHY_TEST_UNSPEC),
+	NLATTR_DESC_NESTED(ETHTOOL_A_PHY_TEST_HEADER, header),
+	NLATTR_DESC_U32(ETHTOOL_A_PHY_TEST_BLOCK_ID),
+	NLATTR_DESC_U32(ETHTOOL_A_PHY_TEST_LANE),
+	NLATTR_DESC_U32(ETHTOOL_A_PHY_TEST_TX_PATTERN),
+	NLATTR_DESC_U32(ETHTOOL_A_PHY_TEST_RX_PATTERN),
+	NLATTR_DESC_U32(ETHTOOL_A_PHY_TEST_BERT_ACTION),
+	NLATTR_DESC_U32(ETHTOOL_A_PHY_TEST_INJECT_ERROR_COUNT),
+	NLATTR_DESC_U32(ETHTOOL_A_PHY_TEST_ACTIVE_TESTS),
+	NLATTR_DESC_U8(ETHTOOL_A_PHY_TEST_CHECKER_LOCK),
+	NLATTR_DESC_U64(ETHTOOL_A_PHY_TEST_ERROR_COUNT),
+	NLATTR_DESC_U64(ETHTOOL_A_PHY_TEST_TOTAL_BITS_SENT),
+};
+
 const struct pretty_nlmsg_desc ethnl_umsg_desc[] = {
 	NLMSG_DESC_INVALID(ETHTOOL_MSG_USER_NONE),
 	NLMSG_DESC(ETHTOOL_MSG_STRSET_GET, strset),
@@ -719,6 +734,8 @@ const struct pretty_nlmsg_desc ethnl_umsg_desc[] = {
 	NLMSG_DESC(ETHTOOL_MSG_RSS_CREATE_ACT, rss),
 	NLMSG_DESC(ETHTOOL_MSG_RSS_DELETE_ACT, rss),
 	NLMSG_DESC(ETHTOOL_MSG_MSE_GET, mse),
+	NLMSG_DESC(ETHTOOL_MSG_PHY_TEST_SET, phy_test),
+	NLMSG_DESC(ETHTOOL_MSG_PHY_TEST_GET, phy_test),
 };
 
 const unsigned int ethnl_umsg_n_desc = ARRAY_SIZE(ethnl_umsg_desc);
@@ -779,6 +796,7 @@ const struct pretty_nlmsg_desc ethnl_kmsg_desc[] = {
 	NLMSG_DESC(ETHTOOL_MSG_RSS_CREATE_NTF, rss),
 	NLMSG_DESC(ETHTOOL_MSG_RSS_DELETE_NTF, rss),
 	NLMSG_DESC(ETHTOOL_MSG_MSE_GET_REPLY, mse),
+	NLMSG_DESC(ETHTOOL_MSG_PHY_TEST_GET_REPLY, phy_test),
 };
 
 const unsigned int ethnl_kmsg_n_desc = ARRAY_SIZE(ethnl_kmsg_desc);
netlink/extapi.h +4 -0
index 696f829..3700f6f 100644
@@ -67,6 +67,8 @@ void nl_monitor_usage(void);
 int nl_get_eeprom_page(struct cmd_context *ctx,
 		       struct ethtool_module_eeprom *request);
 
+int nl_get_phy_test(struct cmd_context *ctx);
+int nl_set_phy_test(struct cmd_context *ctx);
 int nl_get_intf_caps(struct cmd_context *ctx);
 #else /* ETHTOOL_ENABLE_NETLINK */
 
@@ -143,6 +145,8 @@ nl_get_eeprom_page(struct cmd_context *ctx __maybe_unused,
 #define nl_flash_module_fw	NULL
 #define nl_get_phy		NULL
 #define nl_gmse			NULL
+#define nl_get_phy_test		NULL
+#define nl_set_phy_test		NULL
 #define nl_get_intf_caps	NULL
 
 #endif /* ETHTOOL_ENABLE_NETLINK */
netlink/phytest.c new file +354 -0

354 lines not on this page · raw message

uapi/linux/ethtool_netlink_generated.h +31 -0
index 7b9860a..3ec5cb5 100644
@@ -909,8 +909,36 @@ enum phy_test_pattern {
 	PHY_TEST_PATTERN_MAX = (__PHY_TEST_PATTERN_COUNT - 1)
 };
 
+enum phy_test_action {
+	PHY_TEST_ACTION_NONE,
+	PHY_TEST_ACTION_START,
+	PHY_TEST_ACTION_STOP,
+	PHY_TEST_ACTION_CLEAR,
+	__PHY_TEST_ACTION_COUNT,
+	PHY_TEST_ACTION_MAX = (__PHY_TEST_ACTION_COUNT - 1)
+};
+
+enum {
+	ETHTOOL_A_PHY_TEST_UNSPEC,
+	ETHTOOL_A_PHY_TEST_HEADER,
+	ETHTOOL_A_PHY_TEST_BLOCK_ID,
+	ETHTOOL_A_PHY_TEST_LANE,
+	ETHTOOL_A_PHY_TEST_TX_PATTERN,
+	ETHTOOL_A_PHY_TEST_RX_PATTERN,
+	ETHTOOL_A_PHY_TEST_BERT_ACTION,
+	ETHTOOL_A_PHY_TEST_INJECT_ERROR_COUNT,
+	ETHTOOL_A_PHY_TEST_ACTIVE_TESTS,
+	ETHTOOL_A_PHY_TEST_CHECKER_LOCK,
+	ETHTOOL_A_PHY_TEST_ERROR_COUNT,
+	ETHTOOL_A_PHY_TEST_TOTAL_BITS_SENT,
+	ETHTOOL_A_PHY_TEST_SUPPORTED_TEST_PATTERNS,
+	__ETHTOOL_A_PHY_TEST_CNT,
+	ETHTOOL_A_PHY_TEST_MAX = (__ETHTOOL_A_PHY_TEST_CNT - 1)
+};
+
 #define LOOPBACK_SUPPORT_LOCAL         1U
 #define LOOPBACK_SUPPORT_REMOTE        2U
+
 enum {
 	ETHTOOL_MSG_USER_NONE = 0,
 	ETHTOOL_MSG_STRSET_GET = 1,
@@ -965,6 +993,8 @@ enum {
 	ETHTOOL_MSG_RSS_DELETE_ACT,
 	ETHTOOL_MSG_MSE_GET,
 	ETHTOOL_MSG_INTF_CAPS_GET,
+	ETHTOOL_MSG_PHY_TEST_GET,
+	ETHTOOL_MSG_PHY_TEST_SET,
 
 	__ETHTOOL_MSG_USER_CNT,
 	ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1)
@@ -1027,6 +1057,7 @@ enum {
 	ETHTOOL_MSG_RSS_DELETE_NTF,
 	ETHTOOL_MSG_MSE_GET_REPLY,
 	ETHTOOL_MSG_INTF_CAPS_GET_REPLY,
+	ETHTOOL_MSG_PHY_TEST_GET_REPLY,
 
 	__ETHTOOL_MSG_KERNEL_CNT,
 	ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1)
Signature · 1 line
2.25.1
maintainer
#8 lore raw
In reply to Shubham Das
Quoted 20 lines · Shubham Das

This series adds two new ethtool netlink commands:

1. intf-caps-get: Discovers the functional block layout of a network interface. Each block represents a hardware point (MAC/PHY/MODULE) at a specific 802.3 sublayer (RS/PCS/FEC/PMA/PMD) with its supported capabilities (loopback, test patterns, BERT, error injection).

2. Add ETHTOOL_MSG_PHY_TEST_GET and ETHTOOL_MSG_PHY_TEST_SET for per-block, per-lane PHY testing using test patterns, BERT (Bit Error Ratio Test), and error injection. The block_id from intf-caps-get identifies which hardware point to test.

The block model uses:
- component: identifies the hardware entity (MAC, PHY, or module).
- sublayer: identifies the 802.3 sublayer (RS, PCS, FEC, PMA, or PMD).
- instance: identifies multiple instances of the same component, such as internal and external PHYs.
- depth: identifies the host-side or line-side block within the same sublayer.

Quoted 2 lines

Prior discussion on this proposal:
https://lore.kernel.org/netdev/SN7PR11MB810923BBDEC398E860099150FF1B2

When adding new APIs you also need to include a user, so we can see the API in action.

Andrew

---
pw-bot: cr

#9 lore raw
Quoted 22 lines · Shubham Das
Quoted 8 lines

This series adds two new ethtool netlink commands:

1. intf-caps-get: Discovers the functional block layout of a network interface. Each block represents a hardware point (MAC/PHY/MODULE) at a specific 802.3 sublayer (RS/PCS/FEC/PMA/PMD) with its supported capabilities (loopback, test patterns, BERT, error injection).

2. Add ETHTOOL_MSG_PHY_TEST_GET and ETHTOOL_MSG_PHY_TEST_SET for

per-block,

Quoted 12 lines

per-lane PHY testing using test patterns, BERT (Bit Error Ratio Test), and error injection. The block_id from intf-caps-get identifies which hardware point to test.

The block model uses:
- component: identifies the hardware entity (MAC, PHY, or module).
- sublayer: identifies the 802.3 sublayer (RS, PCS, FEC, PMA, or PMD).
- instance: identifies multiple instances of the same component, such as internal and external PHYs.
- depth: identifies the host-side or line-side block within the same sublayer.

Quoted 6 lines
Quoted 2 lines

Prior discussion on this proposal:

https://lore.kernel.org/netdev/SN7PR11MB810923BBDEC398E860099150FF1B2

When adding new APIs you also need to include a user, so we can see the API in action.

Thanks for the feedback.

The intended users of this API are the IXD and IDPF drivers. The initial driver support has already been merged, and the PHY test/capability functionality in this series has been implemented and exercised in Intel's development tree.

However, there are still a few prerequisite patches required for this functionality that are not upstream yet. As a result, I am currently unable to post the corresponding IXD/IDPF changes that plug into these APIs as part of this series.

I can share ethtool command output and test logs demonstrating the API in use (PHY capability reporting, PHY test execution, etc.) if that would help validate the interface until the remaining dependencies and driver changes are posted upstream.

Quoted 4 lines

Andrew

---
pw-bot: cr

maintainer
#10 lore raw
Quoted 3 lines

I can share ethtool command output and test logs demonstrating the API in use (PHY capability reporting, PHY test execution, etc.) if that would help validate the interface until the remaining dependencies and driver changes are posted upstream.

The code is not going to be merged until the driver side is ready. So there is no rush.

Andrew