netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Richard Cochran <richardcochran@gmail.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Michael Chan <michael.chan@broadcom.com>,
	Pavan Chebbi <pavan.chebbi@broadcom.com>,
	Tariq Toukan <tariqt@nvidia.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Mark Bloch <mbloch@nvidia.com>,
	Vadim Fedorenko <vadim.fedorenko@linux.dev>
Cc: netdev@vger.kernel.org
Subject: [PATCH net-next 4/4] selftests: drv-net: add HW timestamping tests
Date: Mon, 22 Sep 2025 16:51:18 +0000	[thread overview]
Message-ID: <20250922165118.10057-5-vadim.fedorenko@linux.dev> (raw)
In-Reply-To: <20250922165118.10057-1-vadim.fedorenko@linux.dev>

Add simple tests to validate that the driver sets up timestamping
configuration according to what is reported in capabilities.

For RX timestamping we allow driver to fallback to wider scope for
timestamping if filter is applied. That actually means that driver
can enable ptpv2-event when it reports ptpv2-l4-event is supported,
but not vice versa.

Signed-off-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
---
 .../selftests/drivers/net/hw/nic_timestamp.py | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/hw/nic_timestamp.py

diff --git a/tools/testing/selftests/drivers/net/hw/nic_timestamp.py b/tools/testing/selftests/drivers/net/hw/nic_timestamp.py
new file mode 100755
index 000000000000..758d00c6f965
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/hw/nic_timestamp.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+import datetime
+import random
+from lib.py import ksft_run, ksft_exit, ksft_ge, ksft_eq, KsftSkipEx
+from lib.py import NetDrvEnv, EthtoolFamily, NlError
+
+def _getHWTimeStampSupport(cfg):
+    tsinfo = cfg.ethnl.tsinfo_get({'header': {'dev-name': cfg.ifname}})
+    ctx = {}
+    tx = tsinfo.get('tx-types', {})
+    rx = tsinfo.get('rx-filters', {})
+
+    bits = tx.get('bits', {})
+    ctx['tx'] = bits.get('bit', [])
+    bits = rx.get('bits', {})
+    ctx['rx'] = bits.get('bit', [])
+    return ctx
+
+def _getHWTimeStampConfig(cfg):
+    try:
+        tscfg = cfg.ethnl.tsconfig_get({'header': {'dev-name': cfg.ifname}})
+    except NlError as e:
+        if e.error == errno.EOPNOTSUPP:
+            raise KsftSkipEx("timestamping configuration is not supported via netlink") from e
+        raise
+    return tscfg
+
+def _setHWTimeStampConfig(cfg, ts):
+    ts['header'] = {'dev-name': cfg.ifname}
+    try:
+        res = cfg.ethnl.tsconfig_set(ts)
+    except NlError as e:
+	    if e.error == errno.EOPNOTSUPP:
+	        raise KsftSkipEx("timestamping configuration is not supported via netlink") from e
+	    raise
+    return res
+
+def test_hwtstamp_tx(cfg):
+    orig_tscfg = _getHWTimeStampConfig(cfg)
+    ts = _getHWTimeStampSupport(cfg)
+    tx = ts['tx']
+    for t in tx:
+        tscfg = orig_tscfg
+        tscfg['tx-types']['bits']['bit'] = [t]
+        res = _setHWTimeStampConfig(cfg, tscfg)
+        ksft_eq(res['tx-types']['bits']['bit'], [t])
+    _setHWTimeStampConfig(cfg, orig_tscfg)
+
+def test_hwtstamp_rx(cfg):
+    orig_tscfg = _getHWTimeStampConfig(cfg)
+    ts = _getHWTimeStampSupport(cfg)
+    rx = ts['rx']
+    for r in rx:
+        tscfg = orig_tscfg
+        tscfg['rx-filters']['bits']['bit'] = [r]
+        res = _setHWTimeStampConfig(cfg, tscfg)
+        if res is None:
+            res = _getHWTimeStampConfig(cfg)
+        if r['index'] == 0 or r['index'] == 1:
+            ksft_eq(res['rx-filters']['bits']['bit'][0]['index'], r['index'])
+        else:
+            # the driver can fallback to some value which has higher coverage for timestamping
+            ksft_ge(res['rx-filters']['bits']['bit'][0]['index'], r['index'])
+    _setHWTimeStampConfig(cfg, orig_tscfg)
+
+def main() -> None:
+    with NetDrvEnv(__file__, nsim_test=False) as cfg:
+        cfg.ethnl = EthtoolFamily()
+        ksft_run([test_hwtstamp_tx, test_hwtstamp_rx], args=(cfg,))
+        ksft_exit()
+
+if __name__ == "__main__":
+    main()
-- 
2.47.3


      parent reply	other threads:[~2025-09-22 17:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-22 16:51 [PATCH net-next 0/4] convert 3 drivers to ndo_hwtstamp API Vadim Fedorenko
2025-09-22 16:51 ` [PATCH net-next 1/4] tg3: convert to ndo_hwtstamp_get() and ndo_hwtstamp_set() Vadim Fedorenko
2025-09-22 22:15   ` Michael Chan
2025-09-23  3:47   ` Pavan Chebbi
2025-09-22 16:51 ` [PATCH net-next 2/4] bnxt_en: " Vadim Fedorenko
2025-09-22 22:17   ` Michael Chan
2025-09-23  3:48   ` Pavan Chebbi
2025-09-22 16:51 ` [PATCH net-next 3/4] mlx5: " Vadim Fedorenko
2025-09-23 17:44   ` Carolina Jubran
2025-09-23 20:48     ` Vadim Fedorenko
2025-09-22 16:51 ` Vadim Fedorenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250922165118.10057-5-vadim.fedorenko@linux.dev \
    --to=vadim.fedorenko@linux.dev \
    --cc=andrew+netdev@lunn.ch \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=michael.chan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.chebbi@broadcom.com \
    --cc=richardcochran@gmail.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).