Skip to content

Commit 736611f

Browse files
committed
iavf: handle set and get timestamps ops
JIRA: https://issues.redhat.com/browse/RHEL-83568 commit 5153423 Author: Jacob Keller <jacob.e.keller@intel.com> Date: Wed Nov 6 12:37:30 2024 -0500 iavf: handle set and get timestamps ops Add handlers for the .ndo_hwtstamp_get and .ndo_hwtstamp_set ops which allow userspace to request timestamp enablement for the device. This support allows standard Linux applications to request the timestamping desired. As with other devices that support timestamping all packets, the driver will upgrade any request for timestamping of a specific type of packet to HWTSTAMP_FILTER_ALL. The current configuration is stored, so that it can be retrieved by calling .ndo_hwtstamp_get The Tx timestamps are not implemented yet so calling set ops for Tx path will end with EOPNOTSUPP error code. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Reviewed-by: Rahul Rameshbabu <rrameshbabu@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com> Tested-by: Rafal Romanowski <rafal.romanowski@intel.com> Co-developed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com> Signed-off-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com> Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
1 parent c0f8fca commit 736611f

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

drivers/net/ethernet/intel/iavf/iavf_main.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,6 +5137,25 @@ static netdev_features_t iavf_fix_features(struct net_device *netdev,
51375137
return iavf_fix_strip_features(adapter, features);
51385138
}
51395139

5140+
static int iavf_hwstamp_get(struct net_device *netdev,
5141+
struct kernel_hwtstamp_config *config)
5142+
{
5143+
struct iavf_adapter *adapter = netdev_priv(netdev);
5144+
5145+
*config = adapter->ptp.hwtstamp_config;
5146+
5147+
return 0;
5148+
}
5149+
5150+
static int iavf_hwstamp_set(struct net_device *netdev,
5151+
struct kernel_hwtstamp_config *config,
5152+
struct netlink_ext_ack *extack)
5153+
{
5154+
struct iavf_adapter *adapter = netdev_priv(netdev);
5155+
5156+
return iavf_ptp_set_ts_config(adapter, config, extack);
5157+
}
5158+
51405159
static int
51415160
iavf_verify_shaper(struct net_shaper_binding *binding,
51425161
const struct net_shaper *shaper,
@@ -5245,6 +5264,8 @@ static const struct net_device_ops iavf_netdev_ops = {
52455264
.ndo_set_features = iavf_set_features,
52465265
.ndo_setup_tc = iavf_setup_tc,
52475266
.net_shaper_ops = &iavf_shaper_ops,
5267+
.ndo_hwtstamp_get = iavf_hwstamp_get,
5268+
.ndo_hwtstamp_set = iavf_hwstamp_set,
52485269
};
52495270

52505271
/**

drivers/net/ethernet/intel/iavf/iavf_ptp.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,100 @@
77
#define iavf_clock_to_adapter(info) \
88
container_of_const(info, struct iavf_adapter, ptp.info)
99

10+
/**
11+
* iavf_ptp_disable_rx_tstamp - Disable timestamping in Rx rings
12+
* @adapter: private adapter structure
13+
*
14+
* Disable timestamp reporting for all Rx rings.
15+
*/
16+
static void iavf_ptp_disable_rx_tstamp(struct iavf_adapter *adapter)
17+
{
18+
for (u32 i = 0; i < adapter->num_active_queues; i++)
19+
adapter->rx_rings[i].flags &= ~IAVF_TXRX_FLAGS_HW_TSTAMP;
20+
}
21+
22+
/**
23+
* iavf_ptp_enable_rx_tstamp - Enable timestamping in Rx rings
24+
* @adapter: private adapter structure
25+
*
26+
* Enable timestamp reporting for all Rx rings.
27+
*/
28+
static void iavf_ptp_enable_rx_tstamp(struct iavf_adapter *adapter)
29+
{
30+
for (u32 i = 0; i < adapter->num_active_queues; i++)
31+
adapter->rx_rings[i].flags |= IAVF_TXRX_FLAGS_HW_TSTAMP;
32+
}
33+
34+
/**
35+
* iavf_ptp_set_timestamp_mode - Set device timestamping mode
36+
* @adapter: private adapter structure
37+
* @config: pointer to kernel_hwtstamp_config
38+
*
39+
* Set the timestamping mode requested from the userspace.
40+
*
41+
* Note: this function always translates Rx timestamp requests for any packet
42+
* category into HWTSTAMP_FILTER_ALL.
43+
*
44+
* Return: 0 on success, negative error code otherwise.
45+
*/
46+
static int iavf_ptp_set_timestamp_mode(struct iavf_adapter *adapter,
47+
struct kernel_hwtstamp_config *config)
48+
{
49+
/* Reserved for future extensions. */
50+
if (config->flags)
51+
return -EINVAL;
52+
53+
switch (config->tx_type) {
54+
case HWTSTAMP_TX_OFF:
55+
break;
56+
case HWTSTAMP_TX_ON:
57+
return -EOPNOTSUPP;
58+
default:
59+
return -ERANGE;
60+
}
61+
62+
if (config->rx_filter == HWTSTAMP_FILTER_NONE) {
63+
iavf_ptp_disable_rx_tstamp(adapter);
64+
return 0;
65+
} else if (config->rx_filter > HWTSTAMP_FILTER_NTP_ALL) {
66+
return -ERANGE;
67+
} else if (!(iavf_ptp_cap_supported(adapter,
68+
VIRTCHNL_1588_PTP_CAP_RX_TSTAMP))) {
69+
return -EOPNOTSUPP;
70+
}
71+
72+
config->rx_filter = HWTSTAMP_FILTER_ALL;
73+
iavf_ptp_enable_rx_tstamp(adapter);
74+
75+
return 0;
76+
}
77+
78+
/**
79+
* iavf_ptp_set_ts_config - Set timestamping configuration
80+
* @adapter: private adapter structure
81+
* @config: pointer to kernel_hwtstamp_config structure
82+
* @extack: pointer to netlink_ext_ack structure
83+
*
84+
* Program the requested timestamping configuration to the device.
85+
*
86+
* Return: 0 on success, negative error code otherwise.
87+
*/
88+
int iavf_ptp_set_ts_config(struct iavf_adapter *adapter,
89+
struct kernel_hwtstamp_config *config,
90+
struct netlink_ext_ack *extack)
91+
{
92+
int err;
93+
94+
err = iavf_ptp_set_timestamp_mode(adapter, config);
95+
if (err)
96+
return err;
97+
98+
/* Save successful settings for future reference */
99+
adapter->ptp.hwtstamp_config = *config;
100+
101+
return 0;
102+
}
103+
10104
/**
11105
* iavf_ptp_cap_supported - Check if a PTP capability is supported
12106
* @adapter: private adapter structure
@@ -321,4 +415,10 @@ void iavf_ptp_process_caps(struct iavf_adapter *adapter)
321415
iavf_ptp_release(adapter);
322416
else if (!adapter->ptp.clock && phc)
323417
iavf_ptp_init(adapter);
418+
419+
/* Check if the device lost access to Rx timestamp incoming packets */
420+
if (!iavf_ptp_cap_supported(adapter, VIRTCHNL_1588_PTP_CAP_RX_TSTAMP)) {
421+
adapter->ptp.hwtstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
422+
iavf_ptp_disable_rx_tstamp(adapter);
423+
}
324424
}

drivers/net/ethernet/intel/iavf/iavf_ptp.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ void iavf_ptp_release(struct iavf_adapter *adapter);
1212
void iavf_ptp_process_caps(struct iavf_adapter *adapter);
1313
bool iavf_ptp_cap_supported(const struct iavf_adapter *adapter, u32 cap);
1414
void iavf_virtchnl_send_ptp_cmd(struct iavf_adapter *adapter);
15+
int iavf_ptp_set_ts_config(struct iavf_adapter *adapter,
16+
struct kernel_hwtstamp_config *config,
17+
struct netlink_ext_ack *extack);
1518
#else /* IS_ENABLED(CONFIG_PTP_1588_CLOCK) */
1619
static inline void iavf_ptp_init(struct iavf_adapter *adapter) { }
1720
static inline void iavf_ptp_release(struct iavf_adapter *adapter) { }
@@ -23,5 +26,11 @@ static inline bool iavf_ptp_cap_supported(const struct iavf_adapter *adapter,
2326
}
2427

2528
static inline void iavf_virtchnl_send_ptp_cmd(struct iavf_adapter *adapter) { }
29+
static inline int iavf_ptp_set_ts_config(struct iavf_adapter *adapter,
30+
struct kernel_hwtstamp_config *config,
31+
struct netlink_ext_ack *extack)
32+
{
33+
return -1;
34+
}
2635
#endif /* IS_ENABLED(CONFIG_PTP_1588_CLOCK) */
2736
#endif /* _IAVF_PTP_H_ */

drivers/net/ethernet/intel/iavf/iavf_txrx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ struct iavf_ring {
252252
#define IAVF_TXRX_FLAGS_VLAN_TAG_LOC_L2TAG1 BIT(3)
253253
#define IAVF_TXR_FLAGS_VLAN_TAG_LOC_L2TAG2 BIT(4)
254254
#define IAVF_RXR_FLAGS_VLAN_TAG_LOC_L2TAG2_2 BIT(5)
255+
#define IAVF_TXRX_FLAGS_HW_TSTAMP BIT(6)
255256

256257
/* stats structs */
257258
struct iavf_queue_stats stats;

0 commit comments

Comments
 (0)