net: add struct kernel_hwtstamp_config and make net_hwtstamp_validate() use it
Jakub Kicinski suggested that we may want to add new UAPI for
controlling hardware timestamping through netlink in the future, and in
that case, we will be limited to the struct hwtstamp_config that is
currently passed in fixed binary format through the SIOCGHWTSTAMP and
SIOCSHWTSTAMP ioctls. It would be good if new kernel code already
started operating on an extensible kernel variant of that structure,
similar in concept to struct kernel_ethtool_coalesce vs struct
ethtool_coalesce.
Since struct hwtstamp_config is in include/uapi/linux/net_tstamp.h, here
we introduce include/linux/net_tstamp.h which shadows that other header,
but also includes it, so that existing includers of this header work as
before. In addition to that, we add the definition for the kernel-only
structure, and a helper which translates all fields by manual copying.
I am doing a manual copy in order to not force the alignment (or type)
of the fields of struct kernel_hwtstamp_config to be the same as of
struct hwtstamp_config, even though now, they are the same.
Link: https://lore.kernel.org/netdev/20230330223519.36ce7d23@kernel.org/
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-04-02 12:37:53 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
|
|
|
|
#ifndef _LINUX_NET_TIMESTAMPING_H_
|
|
|
|
#define _LINUX_NET_TIMESTAMPING_H_
|
|
|
|
|
|
|
|
#include <uapi/linux/net_tstamp.h>
|
|
|
|
|
2024-07-09 13:53:33 +00:00
|
|
|
#define SOF_TIMESTAMPING_SOFTWARE_MASK (SOF_TIMESTAMPING_RX_SOFTWARE | \
|
|
|
|
SOF_TIMESTAMPING_TX_SOFTWARE | \
|
|
|
|
SOF_TIMESTAMPING_SOFTWARE)
|
|
|
|
|
|
|
|
#define SOF_TIMESTAMPING_HARDWARE_MASK (SOF_TIMESTAMPING_RX_HARDWARE | \
|
|
|
|
SOF_TIMESTAMPING_TX_HARDWARE | \
|
|
|
|
SOF_TIMESTAMPING_RAW_HARDWARE)
|
|
|
|
|
2023-08-01 14:28:24 +00:00
|
|
|
enum hwtstamp_source {
|
2024-07-09 13:53:37 +00:00
|
|
|
HWTSTAMP_SOURCE_UNSPEC,
|
2023-08-01 14:28:24 +00:00
|
|
|
HWTSTAMP_SOURCE_NETDEV,
|
|
|
|
HWTSTAMP_SOURCE_PHYLIB,
|
|
|
|
};
|
|
|
|
|
2024-12-12 17:06:43 +00:00
|
|
|
/**
|
|
|
|
* struct hwtstamp_provider_desc - hwtstamp provider description
|
|
|
|
*
|
|
|
|
* @index: index of the hwtstamp provider.
|
|
|
|
* @qualifier: hwtstamp provider qualifier.
|
|
|
|
*/
|
|
|
|
struct hwtstamp_provider_desc {
|
|
|
|
int index;
|
|
|
|
enum hwtstamp_provider_qualifier qualifier;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct hwtstamp_provider - hwtstamp provider object
|
|
|
|
*
|
|
|
|
* @rcu_head: RCU callback used to free the struct.
|
|
|
|
* @source: source of the hwtstamp provider.
|
|
|
|
* @phydev: pointer of the phydev source in case a PTP coming from phylib
|
|
|
|
* @desc: hwtstamp provider description.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct hwtstamp_provider {
|
|
|
|
struct rcu_head rcu_head;
|
|
|
|
enum hwtstamp_source source;
|
|
|
|
struct phy_device *phydev;
|
|
|
|
struct hwtstamp_provider_desc desc;
|
|
|
|
};
|
|
|
|
|
net: add struct kernel_hwtstamp_config and make net_hwtstamp_validate() use it
Jakub Kicinski suggested that we may want to add new UAPI for
controlling hardware timestamping through netlink in the future, and in
that case, we will be limited to the struct hwtstamp_config that is
currently passed in fixed binary format through the SIOCGHWTSTAMP and
SIOCSHWTSTAMP ioctls. It would be good if new kernel code already
started operating on an extensible kernel variant of that structure,
similar in concept to struct kernel_ethtool_coalesce vs struct
ethtool_coalesce.
Since struct hwtstamp_config is in include/uapi/linux/net_tstamp.h, here
we introduce include/linux/net_tstamp.h which shadows that other header,
but also includes it, so that existing includers of this header work as
before. In addition to that, we add the definition for the kernel-only
structure, and a helper which translates all fields by manual copying.
I am doing a manual copy in order to not force the alignment (or type)
of the fields of struct kernel_hwtstamp_config to be the same as of
struct hwtstamp_config, even though now, they are the same.
Link: https://lore.kernel.org/netdev/20230330223519.36ce7d23@kernel.org/
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-04-02 12:37:53 +00:00
|
|
|
/**
|
|
|
|
* struct kernel_hwtstamp_config - Kernel copy of struct hwtstamp_config
|
|
|
|
*
|
|
|
|
* @flags: see struct hwtstamp_config
|
|
|
|
* @tx_type: see struct hwtstamp_config
|
|
|
|
* @rx_filter: see struct hwtstamp_config
|
2023-08-01 14:28:14 +00:00
|
|
|
* @ifr: pointer to ifreq structure from the original ioctl request, to pass to
|
|
|
|
* a legacy implementation of a lower driver
|
|
|
|
* @copied_to_user: request was passed to a legacy implementation which already
|
|
|
|
* copied the ioctl request back to user space
|
2023-08-01 14:28:24 +00:00
|
|
|
* @source: indication whether timestamps should come from the netdev or from
|
|
|
|
* an attached phylib PHY
|
2024-12-12 17:06:43 +00:00
|
|
|
* @qualifier: qualifier of the hwtstamp provider
|
net: add struct kernel_hwtstamp_config and make net_hwtstamp_validate() use it
Jakub Kicinski suggested that we may want to add new UAPI for
controlling hardware timestamping through netlink in the future, and in
that case, we will be limited to the struct hwtstamp_config that is
currently passed in fixed binary format through the SIOCGHWTSTAMP and
SIOCSHWTSTAMP ioctls. It would be good if new kernel code already
started operating on an extensible kernel variant of that structure,
similar in concept to struct kernel_ethtool_coalesce vs struct
ethtool_coalesce.
Since struct hwtstamp_config is in include/uapi/linux/net_tstamp.h, here
we introduce include/linux/net_tstamp.h which shadows that other header,
but also includes it, so that existing includers of this header work as
before. In addition to that, we add the definition for the kernel-only
structure, and a helper which translates all fields by manual copying.
I am doing a manual copy in order to not force the alignment (or type)
of the fields of struct kernel_hwtstamp_config to be the same as of
struct hwtstamp_config, even though now, they are the same.
Link: https://lore.kernel.org/netdev/20230330223519.36ce7d23@kernel.org/
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-04-02 12:37:53 +00:00
|
|
|
*
|
|
|
|
* Prefer using this structure for in-kernel processing of hardware
|
|
|
|
* timestamping configuration, over the inextensible struct hwtstamp_config
|
|
|
|
* exposed to the %SIOCGHWTSTAMP and %SIOCSHWTSTAMP ioctl UAPI.
|
|
|
|
*/
|
|
|
|
struct kernel_hwtstamp_config {
|
|
|
|
int flags;
|
|
|
|
int tx_type;
|
|
|
|
int rx_filter;
|
2023-08-01 14:28:14 +00:00
|
|
|
struct ifreq *ifr;
|
|
|
|
bool copied_to_user;
|
2023-08-01 14:28:24 +00:00
|
|
|
enum hwtstamp_source source;
|
2024-12-12 17:06:43 +00:00
|
|
|
enum hwtstamp_provider_qualifier qualifier;
|
net: add struct kernel_hwtstamp_config and make net_hwtstamp_validate() use it
Jakub Kicinski suggested that we may want to add new UAPI for
controlling hardware timestamping through netlink in the future, and in
that case, we will be limited to the struct hwtstamp_config that is
currently passed in fixed binary format through the SIOCGHWTSTAMP and
SIOCSHWTSTAMP ioctls. It would be good if new kernel code already
started operating on an extensible kernel variant of that structure,
similar in concept to struct kernel_ethtool_coalesce vs struct
ethtool_coalesce.
Since struct hwtstamp_config is in include/uapi/linux/net_tstamp.h, here
we introduce include/linux/net_tstamp.h which shadows that other header,
but also includes it, so that existing includers of this header work as
before. In addition to that, we add the definition for the kernel-only
structure, and a helper which translates all fields by manual copying.
I am doing a manual copy in order to not force the alignment (or type)
of the fields of struct kernel_hwtstamp_config to be the same as of
struct hwtstamp_config, even though now, they are the same.
Link: https://lore.kernel.org/netdev/20230330223519.36ce7d23@kernel.org/
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-04-02 12:37:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg,
|
|
|
|
const struct hwtstamp_config *cfg)
|
|
|
|
{
|
|
|
|
kernel_cfg->flags = cfg->flags;
|
|
|
|
kernel_cfg->tx_type = cfg->tx_type;
|
|
|
|
kernel_cfg->rx_filter = cfg->rx_filter;
|
|
|
|
}
|
|
|
|
|
2023-08-01 14:28:13 +00:00
|
|
|
static inline void hwtstamp_config_from_kernel(struct hwtstamp_config *cfg,
|
|
|
|
const struct kernel_hwtstamp_config *kernel_cfg)
|
|
|
|
{
|
|
|
|
cfg->flags = kernel_cfg->flags;
|
|
|
|
cfg->tx_type = kernel_cfg->tx_type;
|
|
|
|
cfg->rx_filter = kernel_cfg->rx_filter;
|
|
|
|
}
|
|
|
|
|
2023-08-01 14:28:24 +00:00
|
|
|
static inline bool kernel_hwtstamp_config_changed(const struct kernel_hwtstamp_config *a,
|
|
|
|
const struct kernel_hwtstamp_config *b)
|
|
|
|
{
|
|
|
|
return a->flags != b->flags ||
|
|
|
|
a->tx_type != b->tx_type ||
|
|
|
|
a->rx_filter != b->rx_filter;
|
|
|
|
}
|
|
|
|
|
net: add struct kernel_hwtstamp_config and make net_hwtstamp_validate() use it
Jakub Kicinski suggested that we may want to add new UAPI for
controlling hardware timestamping through netlink in the future, and in
that case, we will be limited to the struct hwtstamp_config that is
currently passed in fixed binary format through the SIOCGHWTSTAMP and
SIOCSHWTSTAMP ioctls. It would be good if new kernel code already
started operating on an extensible kernel variant of that structure,
similar in concept to struct kernel_ethtool_coalesce vs struct
ethtool_coalesce.
Since struct hwtstamp_config is in include/uapi/linux/net_tstamp.h, here
we introduce include/linux/net_tstamp.h which shadows that other header,
but also includes it, so that existing includers of this header work as
before. In addition to that, we add the definition for the kernel-only
structure, and a helper which translates all fields by manual copying.
I am doing a manual copy in order to not force the alignment (or type)
of the fields of struct kernel_hwtstamp_config to be the same as of
struct hwtstamp_config, even though now, they are the same.
Link: https://lore.kernel.org/netdev/20230330223519.36ce7d23@kernel.org/
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-04-02 12:37:53 +00:00
|
|
|
#endif /* _LINUX_NET_TIMESTAMPING_H_ */
|