Skip to content

Commit 6e9e2ee

Browse files
kmaincentdavem330
authored andcommitted
net: ethtool: Add support for tsconfig command to get/set hwtstamp config
Introduce support for ETHTOOL_MSG_TSCONFIG_GET/SET ethtool netlink socket to read and configure hwtstamp configuration of a PHC provider. Note that simultaneous hwtstamp isn't supported; configuring a new one disables the previous setting. Signed-off-by: Kory Maincent <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b9e3f7d commit 6e9e2ee

File tree

10 files changed

+655
-26
lines changed

10 files changed

+655
-26
lines changed

Documentation/netlink/specs/ethtool.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,33 @@ attribute-sets:
14891489
-
14901490
name: downstream-sfp-name
14911491
type: string
1492+
-
1493+
name: tsconfig
1494+
attr-cnt-name: __ethtool-a-tsconfig-cnt
1495+
attributes:
1496+
-
1497+
name: unspec
1498+
type: unused
1499+
value: 0
1500+
-
1501+
name: header
1502+
type: nest
1503+
nested-attributes: header
1504+
-
1505+
name: hwtstamp-provider
1506+
type: nest
1507+
nested-attributes: ts-hwtstamp-provider
1508+
-
1509+
name: tx-types
1510+
type: nest
1511+
nested-attributes: bitset
1512+
-
1513+
name: rx-filters
1514+
type: nest
1515+
nested-attributes: bitset
1516+
-
1517+
name: hwtstamp-flags
1518+
type: u32
14921519

14931520
operations:
14941521
enum-model: directional
@@ -2314,3 +2341,32 @@ operations:
23142341
name: phy-ntf
23152342
doc: Notification for change in PHY devices.
23162343
notify: phy-get
2344+
-
2345+
name: tsconfig-get
2346+
doc: Get hwtstamp config.
2347+
2348+
attribute-set: tsconfig
2349+
2350+
do: &tsconfig-get-op
2351+
request:
2352+
attributes:
2353+
- header
2354+
reply:
2355+
attributes: &tsconfig
2356+
- header
2357+
- hwtstamp-provider
2358+
- tx-types
2359+
- rx-filters
2360+
- hwtstamp-flags
2361+
dump: *tsconfig-get-op
2362+
-
2363+
name: tsconfig-set
2364+
doc: Set hwtstamp config.
2365+
2366+
attribute-set: tsconfig
2367+
2368+
do:
2369+
request:
2370+
attributes: *tsconfig
2371+
reply:
2372+
attributes: *tsconfig

Documentation/networking/ethtool-netlink.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ Userspace to kernel:
237237
``ETHTOOL_MSG_MM_SET`` set MAC merge layer parameters
238238
``ETHTOOL_MSG_MODULE_FW_FLASH_ACT`` flash transceiver module firmware
239239
``ETHTOOL_MSG_PHY_GET`` get Ethernet PHY information
240+
``ETHTOOL_MSG_TSCONFIG_GET`` get hw timestamping configuration
241+
``ETHTOOL_MSG_TSCONFIG_SET`` set hw timestamping configuration
240242
===================================== =================================
241243

242244
Kernel to userspace:
@@ -286,6 +288,8 @@ Kernel to userspace:
286288
``ETHTOOL_MSG_MODULE_FW_FLASH_NTF`` transceiver module flash updates
287289
``ETHTOOL_MSG_PHY_GET_REPLY`` Ethernet PHY information
288290
``ETHTOOL_MSG_PHY_NTF`` Ethernet PHY information change
291+
``ETHTOOL_MSG_TSCONFIG_GET_REPLY`` hw timestamping configuration
292+
``ETHTOOL_MSG_TSCONFIG_SET_REPLY`` new hw timestamping configuration
289293
======================================== =================================
290294

291295
``GET`` requests are sent by userspace applications to retrieve device
@@ -2244,6 +2248,75 @@ Kernel response contents:
22442248
When ``ETHTOOL_A_PHY_UPSTREAM_TYPE`` is PHY_UPSTREAM_PHY, the PHY's parent is
22452249
another PHY.
22462250

2251+
TSCONFIG_GET
2252+
============
2253+
2254+
Retrieves the information about the current hardware timestamping source and
2255+
configuration.
2256+
2257+
It is similar to the deprecated ``SIOCGHWTSTAMP`` ioctl request.
2258+
2259+
Request contents:
2260+
2261+
==================================== ====== ==========================
2262+
``ETHTOOL_A_TSCONFIG_HEADER`` nested request header
2263+
==================================== ====== ==========================
2264+
2265+
Kernel response contents:
2266+
2267+
======================================== ====== ============================
2268+
``ETHTOOL_A_TSCONFIG_HEADER`` nested request header
2269+
``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` nested PTP hw clock provider
2270+
``ETHTOOL_A_TSCONFIG_TX_TYPES`` bitset hwtstamp Tx type
2271+
``ETHTOOL_A_TSCONFIG_RX_FILTERS`` bitset hwtstamp Rx filter
2272+
``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` u32 hwtstamp flags
2273+
======================================== ====== ============================
2274+
2275+
When set the ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` attribute identifies the
2276+
source of the hw timestamping provider. It is composed by
2277+
``ETHTOOL_A_TS_HWTSTAMP_PROVIDER_INDEX`` attribute which describe the index of
2278+
the PTP device and ``ETHTOOL_A_TS_HWTSTAMP_PROVIDER_QUALIFIER`` which describe
2279+
the qualifier of the timestamp.
2280+
2281+
When set the ``ETHTOOL_A_TSCONFIG_TX_TYPES``, ``ETHTOOL_A_TSCONFIG_RX_FILTERS``
2282+
and the ``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` attributes identify the Tx
2283+
type, the Rx filter and the flags configured for the current hw timestamping
2284+
provider. The attributes are propagated to the driver through the following
2285+
structure:
2286+
2287+
.. kernel-doc:: include/linux/net_tstamp.h
2288+
:identifiers: kernel_hwtstamp_config
2289+
2290+
TSCONFIG_SET
2291+
============
2292+
2293+
Set the information about the current hardware timestamping source and
2294+
configuration.
2295+
2296+
It is similar to the deprecated ``SIOCSHWTSTAMP`` ioctl request.
2297+
2298+
Request contents:
2299+
2300+
======================================== ====== ============================
2301+
``ETHTOOL_A_TSCONFIG_HEADER`` nested request header
2302+
``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` nested PTP hw clock provider
2303+
``ETHTOOL_A_TSCONFIG_TX_TYPES`` bitset hwtstamp Tx type
2304+
``ETHTOOL_A_TSCONFIG_RX_FILTERS`` bitset hwtstamp Rx filter
2305+
``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` u32 hwtstamp flags
2306+
======================================== ====== ============================
2307+
2308+
Kernel response contents:
2309+
2310+
======================================== ====== ============================
2311+
``ETHTOOL_A_TSCONFIG_HEADER`` nested request header
2312+
``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` nested PTP hw clock provider
2313+
``ETHTOOL_A_TSCONFIG_TX_TYPES`` bitset hwtstamp Tx type
2314+
``ETHTOOL_A_TSCONFIG_RX_FILTERS`` bitset hwtstamp Rx filter
2315+
``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` u32 hwtstamp flags
2316+
======================================== ====== ============================
2317+
2318+
For a description of each attribute, see ``TSCONFIG_GET``.
2319+
22472320
Request translation
22482321
===================
22492322

@@ -2352,4 +2425,6 @@ are netlink only.
23522425
n/a ``ETHTOOL_MSG_MM_SET``
23532426
n/a ``ETHTOOL_MSG_MODULE_FW_FLASH_ACT``
23542427
n/a ``ETHTOOL_MSG_PHY_GET``
2428+
``SIOCGHWTSTAMP`` ``ETHTOOL_MSG_TSCONFIG_GET``
2429+
``SIOCSHWTSTAMP`` ``ETHTOOL_MSG_TSCONFIG_SET``
23552430
=================================== =====================================

Documentation/networking/timestamping.rst

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ implicitly defined. ts[0] holds a software timestamp if set, ts[1]
525525
is again deprecated and ts[2] holds a hardware timestamp if set.
526526

527527

528-
3. Hardware Timestamping configuration: SIOCSHWTSTAMP and SIOCGHWTSTAMP
529-
=======================================================================
528+
3. Hardware Timestamping configuration: ETHTOOL_MSG_TSCONFIG_SET/GET
529+
====================================================================
530530

531531
Hardware time stamping must also be initialized for each device driver
532532
that is expected to do hardware time stamping. The parameter is defined in
@@ -539,12 +539,14 @@ include/uapi/linux/net_tstamp.h as::
539539
};
540540

541541
Desired behavior is passed into the kernel and to a specific device by
542-
calling ioctl(SIOCSHWTSTAMP) with a pointer to a struct ifreq whose
543-
ifr_data points to a struct hwtstamp_config. The tx_type and
544-
rx_filter are hints to the driver what it is expected to do. If
545-
the requested fine-grained filtering for incoming packets is not
546-
supported, the driver may time stamp more than just the requested types
547-
of packets.
542+
calling the tsconfig netlink socket ``ETHTOOL_MSG_TSCONFIG_SET``.
543+
The ``ETHTOOL_A_TSCONFIG_TX_TYPES``, ``ETHTOOL_A_TSCONFIG_RX_FILTERS`` and
544+
``ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS`` netlink attributes are then used to set
545+
the struct hwtstamp_config accordingly.
546+
547+
The ``ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER`` netlink nested attribute is used
548+
to select the source of the hardware time stamping. It is composed of an index
549+
for the device source and a qualifier for the type of time stamping.
548550

549551
Drivers are free to use a more permissive configuration than the requested
550552
configuration. It is expected that drivers should only implement directly the
@@ -563,9 +565,16 @@ Only a processes with admin rights may change the configuration. User
563565
space is responsible to ensure that multiple processes don't interfere
564566
with each other and that the settings are reset.
565567

566-
Any process can read the actual configuration by passing this
567-
structure to ioctl(SIOCGHWTSTAMP) in the same way. However, this has
568-
not been implemented in all drivers.
568+
Any process can read the actual configuration by requesting tsconfig netlink
569+
socket ``ETHTOOL_MSG_TSCONFIG_GET``.
570+
571+
The legacy configuration is the use of the ioctl(SIOCSHWTSTAMP) with a pointer
572+
to a struct ifreq whose ifr_data points to a struct hwtstamp_config.
573+
The tx_type and rx_filter are hints to the driver what it is expected to do.
574+
If the requested fine-grained filtering for incoming packets is not
575+
supported, the driver may time stamp more than just the requested types
576+
of packets. ioctl(SIOCGHWTSTAMP) is used in the same way as the
577+
ioctl(SIOCSHWTSTAMP). However, this has not been implemented in all drivers.
569578

570579
::
571580

@@ -610,9 +619,10 @@ not been implemented in all drivers.
610619
--------------------------------------------------------
611620

612621
A driver which supports hardware time stamping must support the
613-
SIOCSHWTSTAMP ioctl and update the supplied struct hwtstamp_config with
614-
the actual values as described in the section on SIOCSHWTSTAMP. It
615-
should also support SIOCGHWTSTAMP.
622+
ndo_hwtstamp_set NDO or the legacy SIOCSHWTSTAMP ioctl and update the
623+
supplied struct hwtstamp_config with the actual values as described in
624+
the section on SIOCSHWTSTAMP. It should also support ndo_hwtstamp_get or
625+
the legacy SIOCGHWTSTAMP.
616626

617627
Time stamps for received packets must be stored in the skb. To get a pointer
618628
to the shared time stamp structure of the skb call skb_hwtstamps(). Then

include/uapi/linux/ethtool_netlink_generated.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,18 @@ enum {
694694
ETHTOOL_A_PHY_MAX = (__ETHTOOL_A_PHY_CNT - 1)
695695
};
696696

697+
enum {
698+
ETHTOOL_A_TSCONFIG_UNSPEC,
699+
ETHTOOL_A_TSCONFIG_HEADER,
700+
ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER,
701+
ETHTOOL_A_TSCONFIG_TX_TYPES,
702+
ETHTOOL_A_TSCONFIG_RX_FILTERS,
703+
ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS,
704+
705+
__ETHTOOL_A_TSCONFIG_CNT,
706+
ETHTOOL_A_TSCONFIG_MAX = (__ETHTOOL_A_TSCONFIG_CNT - 1)
707+
};
708+
697709
enum {
698710
ETHTOOL_MSG_USER_NONE = 0,
699711
ETHTOOL_MSG_STRSET_GET = 1,
@@ -741,6 +753,8 @@ enum {
741753
ETHTOOL_MSG_MM_SET,
742754
ETHTOOL_MSG_MODULE_FW_FLASH_ACT,
743755
ETHTOOL_MSG_PHY_GET,
756+
ETHTOOL_MSG_TSCONFIG_GET,
757+
ETHTOOL_MSG_TSCONFIG_SET,
744758

745759
__ETHTOOL_MSG_USER_CNT,
746760
ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1)
@@ -794,6 +808,8 @@ enum {
794808
ETHTOOL_MSG_MODULE_FW_FLASH_NTF,
795809
ETHTOOL_MSG_PHY_GET_REPLY,
796810
ETHTOOL_MSG_PHY_NTF,
811+
ETHTOOL_MSG_TSCONFIG_GET_REPLY,
812+
ETHTOOL_MSG_TSCONFIG_SET_REPLY,
797813

798814
__ETHTOOL_MSG_KERNEL_CNT,
799815
ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1)

net/ethtool/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \
99
channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \
1010
tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \
1111
module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o mm.o \
12-
phy.o
12+
phy.o tsconfig.o

net/ethtool/common.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ int ethtool_net_get_ts_info_by_phc(struct net_device *dev,
797797
return -ENODEV;
798798
}
799799

800-
int
800+
struct phy_device *
801801
ethtool_phy_get_ts_info_by_phc(struct net_device *dev,
802802
struct kernel_ethtool_ts_info *info,
803803
struct hwtstamp_provider_desc *hwprov_desc)
@@ -806,7 +806,7 @@ ethtool_phy_get_ts_info_by_phc(struct net_device *dev,
806806

807807
/* Only precise qualifier is supported in phydev */
808808
if (hwprov_desc->qualifier != HWTSTAMP_PROVIDER_QUALIFIER_PRECISE)
809-
return -ENODEV;
809+
return ERR_PTR(-ENODEV);
810810

811811
/* Look in the phy topology */
812812
if (dev->link_topo) {
@@ -820,26 +820,26 @@ ethtool_phy_get_ts_info_by_phc(struct net_device *dev,
820820
ethtool_init_tsinfo(info);
821821
err = phy_ts_info(pdn->phy, info);
822822
if (err)
823-
return err;
823+
return ERR_PTR(err);
824824

825825
if (info->phc_index == hwprov_desc->index)
826-
return 0;
826+
return pdn->phy;
827827
}
828-
return -ENODEV;
828+
return ERR_PTR(-ENODEV);
829829
}
830830

831831
/* Look on the dev->phydev */
832832
if (phy_has_tsinfo(dev->phydev)) {
833833
ethtool_init_tsinfo(info);
834834
err = phy_ts_info(dev->phydev, info);
835835
if (err)
836-
return err;
836+
return ERR_PTR(err);
837837

838838
if (info->phc_index == hwprov_desc->index)
839-
return 0;
839+
return dev->phydev;
840840
}
841841

842-
return -ENODEV;
842+
return ERR_PTR(-ENODEV);
843843
}
844844

845845
int ethtool_get_ts_info_by_phc(struct net_device *dev,
@@ -849,8 +849,15 @@ int ethtool_get_ts_info_by_phc(struct net_device *dev,
849849
int err;
850850

851851
err = ethtool_net_get_ts_info_by_phc(dev, info, hwprov_desc);
852-
if (err == -ENODEV)
853-
err = ethtool_phy_get_ts_info_by_phc(dev, info, hwprov_desc);
852+
if (err == -ENODEV) {
853+
struct phy_device *phy;
854+
855+
phy = ethtool_phy_get_ts_info_by_phc(dev, info, hwprov_desc);
856+
if (IS_ERR(phy))
857+
err = PTR_ERR(phy);
858+
else
859+
err = 0;
860+
}
854861

855862
info->so_timestamping |= SOF_TIMESTAMPING_RX_SOFTWARE |
856863
SOF_TIMESTAMPING_SOFTWARE;

net/ethtool/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int ethtool_get_ts_info_by_phc(struct net_device *dev,
5656
int ethtool_net_get_ts_info_by_phc(struct net_device *dev,
5757
struct kernel_ethtool_ts_info *info,
5858
struct hwtstamp_provider_desc *hwprov_desc);
59-
int
59+
struct phy_device *
6060
ethtool_phy_get_ts_info_by_phc(struct net_device *dev,
6161
struct kernel_ethtool_ts_info *info,
6262
struct hwtstamp_provider_desc *hwprov_desc);

net/ethtool/netlink.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
394394
[ETHTOOL_MSG_PLCA_GET_STATUS] = &ethnl_plca_status_request_ops,
395395
[ETHTOOL_MSG_MM_GET] = &ethnl_mm_request_ops,
396396
[ETHTOOL_MSG_MM_SET] = &ethnl_mm_request_ops,
397+
[ETHTOOL_MSG_TSCONFIG_GET] = &ethnl_tsconfig_request_ops,
398+
[ETHTOOL_MSG_TSCONFIG_SET] = &ethnl_tsconfig_request_ops,
397399
};
398400

399401
static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -1243,6 +1245,22 @@ static const struct genl_ops ethtool_genl_ops[] = {
12431245
.policy = ethnl_phy_get_policy,
12441246
.maxattr = ARRAY_SIZE(ethnl_phy_get_policy) - 1,
12451247
},
1248+
{
1249+
.cmd = ETHTOOL_MSG_TSCONFIG_GET,
1250+
.doit = ethnl_default_doit,
1251+
.start = ethnl_default_start,
1252+
.dumpit = ethnl_default_dumpit,
1253+
.done = ethnl_default_done,
1254+
.policy = ethnl_tsconfig_get_policy,
1255+
.maxattr = ARRAY_SIZE(ethnl_tsconfig_get_policy) - 1,
1256+
},
1257+
{
1258+
.cmd = ETHTOOL_MSG_TSCONFIG_SET,
1259+
.flags = GENL_UNS_ADMIN_PERM,
1260+
.doit = ethnl_default_set_doit,
1261+
.policy = ethnl_tsconfig_set_policy,
1262+
.maxattr = ARRAY_SIZE(ethnl_tsconfig_set_policy) - 1,
1263+
},
12461264
};
12471265

12481266
static const struct genl_multicast_group ethtool_nl_mcgrps[] = {

0 commit comments

Comments
 (0)