From: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
To: linux-kernel@vger.kernel.org, intel-wired-lan@lists.osuosl.org,
netdev@vger.kernel.org, linux-kselftest@vger.kernel.org
Cc: jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com,
davem@davemloft.net, kuba@kernel.org, richardcochran@gmail.com,
shuah@kernel.org, arkadiusz.kubalewski@intel.com, arnd@arndb.de,
nikolay@nvidia.com, cong.wang@bytedance.com,
colin.king@canonical.com, gustavoars@kernel.org
Subject: [RFC net-next 5/7] selftests/net: Add test app for SIOC{S|G}SYNCE
Date: Mon, 16 Aug 2021 18:07:15 +0200 [thread overview]
Message-ID: <20210816160717.31285-6-arkadiusz.kubalewski@intel.com> (raw)
In-Reply-To: <20210816160717.31285-1-arkadiusz.kubalewski@intel.com>
Test usage of new netdev IOCTLs: SIOCSSYNCE and SIOCGSYNCE.
Allow set or get the netdev driver configuration
of PHY reference clock on output pins.
Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
---
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/phy_ref_clk.c | 138 ++++++++++++++++++++++
2 files changed, 139 insertions(+)
create mode 100644 tools/testing/selftests/net/phy_ref_clk.c
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index 4f9f73e7a299..ace9a5130478 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -39,6 +39,7 @@ TEST_GEN_FILES += hwtstamp_config rxtimestamp timestamping txtimestamp
TEST_GEN_FILES += ipsec
TEST_GEN_FILES += ioam6_parser
TEST_GEN_FILES += gro
+TEST_GEN_FILES += phy_ref_clk
TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls
TEST_GEN_FILES += toeplitz
diff --git a/tools/testing/selftests/net/phy_ref_clk.c b/tools/testing/selftests/net/phy_ref_clk.c
new file mode 100644
index 000000000000..dc07cf3d4569
--- /dev/null
+++ b/tools/testing/selftests/net/phy_ref_clk.c
@@ -0,0 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * This program allows to test behavior of netdev after sending
+ * SyncE related ioctl: SIOCGSYNCE and SIOCSSYNCE.
+ * SIOCGSYNCE - was designed to check how output pin on PHY port
+ * was configured.
+ * SIOCSSYNCE - was designed to configure (enable or disable)
+ * one of the pins, that PHY can propagate its recovered clock
+ * signal onto.
+ *
+ * Copyright (C) 2021 Intel Corporation.
+ * Author: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <arpa/inet.h>
+#include <net/if.h>
+
+#include <asm/types.h>
+#include <linux/sockios.h>
+#include <linux/net_synce.h>
+
+static void usage(const char *error)
+{
+ if (error)
+ printf("invalid: %s\n\n", error);
+ printf("phy_ref_clk <interface> <pin_id> [enable]\n\n"
+ "Enable or disable phy-recovered reference clock signal on given output pin.\n"
+ "Depending on HW configuration, phy recovered clock may be enabled\n"
+ "or disabled on one of output pins which are at hardware's disposal\n\n"
+ "Params:\n"
+ " <interface> - name of netdev implementing SIOCGSYNCE and SIOCSSYNCE\n"
+ " <pin_id> - pin on which clock recovered from PHY shall be propagated\n"
+ " (0-X), X - number of output pins at HW disposal\n"
+ " In case no other arguments are given, ask the driver\n"
+ " for the current config of recovered clock on the interface.\n\n"
+ " [enable] - if pin shal be enabled or disabled (0/1)\n\n");
+ exit(1);
+}
+
+static int get_ref_clk(const char *ifname, __u8 pin)
+{
+ struct synce_ref_clk_cfg ref_clk;
+ struct ifreq ifdata;
+ int sd, rc;
+
+ if (!ifname || *ifname == '\0')
+ return -1;
+
+ memset(&ifdata, 0, sizeof(ifdata));
+
+ strncpy(ifdata.ifr_name, ifname, IFNAMSIZ);
+
+ sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
+ if (sd < 0) {
+ printf("socket failed\n");
+ return -1;
+ }
+
+ ref_clk.pin_id = pin;
+ ifdata.ifr_data = (void *)&ref_clk;
+
+ rc = ioctl(sd, SIOCGSYNCE, (char *)&ifdata);
+ close(sd);
+ if (rc != 0) {
+ printf("ioctl(SIOCGSYNCE) failed\n");
+ return rc;
+ }
+ printf("GET: pin %u is %s\n",
+ ref_clk.pin_id, ref_clk.enable ? "enabled" : "disabled");
+
+ return 0;
+}
+
+static int set_ref_clk(const char *ifname, __u8 pin, _Bool enable)
+{
+ struct synce_ref_clk_cfg ref_clk;
+ struct ifreq ifdata;
+ int sd, rc;
+
+ if (!ifname || *ifname == '\0')
+ return -1;
+
+ memset(&ifdata, 0, sizeof(ifdata));
+
+ strcpy(ifdata.ifr_name, ifname);
+
+ sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
+ if (sd < 0) {
+ printf("socket failed\n");
+ return -1;
+ }
+
+ ref_clk.pin_id = pin;
+ ref_clk.enable = enable;
+ ifdata.ifr_data = (void *)&ref_clk;
+
+ rc = ioctl(sd, SIOCSSYNCE, (char *)&ifdata);
+ close(sd);
+ if (rc != 0) {
+ printf("ioctl(SIOCSSYNCE) failed\n");
+ return rc;
+ }
+ printf("SET: pin %u is %s",
+ ref_clk.pin_id, ref_clk.enable ? "enabled" : "disabled");
+
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ _Bool enable;
+ __u8 pin;
+ int ret;
+
+ if (argc > 4 || argc < 3)
+ usage("argument count");
+
+ ret = sscanf(argv[2], "%u", &pin);
+ if (ret != 1)
+ usage(argv[2]);
+
+ if (argc == 3) {
+ ret = get_ref_clk(argv[1], pin);
+ } else if (argc == 4) {
+ ret = sscanf(argv[3], "%u", &enable);
+ if (ret != 1)
+ usage(argv[3]);
+ ret = set_ref_clk(argv[1], pin, enable);
+ }
+ return ret;
+}
--
2.24.0
next prev parent reply other threads:[~2021-08-16 16:18 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-16 16:07 [RFC net-next 0/7] Add basic SyncE interfaces Arkadiusz Kubalewski
2021-08-16 16:07 ` [RFC net-next 1/7] ptp: Add interface for acquiring DPLL state Arkadiusz Kubalewski
2021-08-16 23:54 ` Richard Cochran
2021-08-17 9:41 ` Machnikowski, Maciej
2021-08-18 17:02 ` Richard Cochran
2021-08-18 18:14 ` [Intel-wired-lan] " Keller, Jacob E
2021-08-18 22:36 ` Machnikowski, Maciej
2021-08-19 15:34 ` Richard Cochran
2021-08-19 15:40 ` Machnikowski, Maciej
2021-08-20 15:55 ` Richard Cochran
2021-08-20 18:30 ` Machnikowski, Maciej
2021-08-22 1:50 ` Richard Cochran
2021-08-22 2:30 ` Richard Cochran
2021-08-23 8:29 ` Machnikowski, Maciej
2021-08-30 21:06 ` Richard Cochran
2021-08-31 9:29 ` Machnikowski, Maciej
2021-08-16 16:07 ` [RFC net-next 2/7] selftests/ptp: Add usage of PTP_DPLL_GETSTATE ioctl in testptp Arkadiusz Kubalewski
2021-08-16 23:54 ` Richard Cochran
2021-08-16 16:07 ` [RFC net-next 3/7] ice: add get_dpll_state ptp interface usage Arkadiusz Kubalewski
2021-08-16 16:07 ` [RFC net-next 4/7] net: add ioctl interface for recover reference clock on netdev Arkadiusz Kubalewski
2021-08-16 19:46 ` Arnd Bergmann
2021-08-17 10:35 ` Kubalewski, Arkadiusz
2021-08-22 1:25 ` Richard Cochran
2021-08-16 16:07 ` Arkadiusz Kubalewski [this message]
2021-08-16 16:07 ` [RFC net-next 6/7] ice: add SIOC{S|G}SYNCE interface usage to recover reference signal Arkadiusz Kubalewski
2021-08-16 16:07 ` [RFC net-next 7/7] ice: add sysfs interface to configure PHY recovered " Arkadiusz Kubalewski
2021-08-18 17:05 ` [RFC net-next 0/7] Add basic SyncE interfaces Richard Cochran
2021-08-18 17:08 ` Richard Cochran
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=20210816160717.31285-6-arkadiusz.kubalewski@intel.com \
--to=arkadiusz.kubalewski@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=arnd@arndb.de \
--cc=colin.king@canonical.com \
--cc=cong.wang@bytedance.com \
--cc=davem@davemloft.net \
--cc=gustavoars@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jesse.brandeburg@intel.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nikolay@nvidia.com \
--cc=richardcochran@gmail.com \
--cc=shuah@kernel.org \
/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).