idpf: add initial PTP support
Subsystems (3)
v3 cover idpf: add initial PTP support
This patch series introduces support for Precision Time Protocol (PTP) to Intel(R) Infrastructure Data Path Function (IDPF) driver. PTP feature is supported when the PTP capability is negotiated with the Control Plane (CP). IDPF creates a PTP clock and sets a set of supported functions.
During the PTP initialization, IDPF requests a set of PTP capabilities and receives a writeback from the CP with the set of supported options. These options are:
- get time of the PTP clock
- get cross timestamp
- set the time of the PTP clock
- adjust the PTP clock
- Tx timestamping
Each feature is considered to have direct access, where the operations on PCIe BAR registers are allowed, or the mailbox access, where the virtchnl messages are used to perform any PTP action. Mailbox access means that PTP requests are sent to the CP through dedicated secondary mailbox and the CP reads/writes/modifies desired resource - PTP Clock or Tx timestamp registers.
Tx timestamp capabilities are negotiated only for vports that have UPLINK_VPORT flag set by the CP. Capabilities provide information about the number of available Tx timestamp latches, their indexes and size of the Tx timestamp value. IDPF requests Tx timestamp by setting the TSYN bit and the requested timestamp index in the context descriptor for the PTP packets. When the completion tag for that packet is received, IDPF schedules a worker to read the Tx timestamp value.
Current implementation of the IDPF driver does not allow to get stable Tx timestamping, when more than 1 request per 1 second is sent to the driver. Debug is in progress, however PTP feature seems to be affected by the IDPF transmit flow, as the Tx timestamping relies on the completion tag.
v2 -> v3: fix minor issues, revert idpf_for_each_vport changes, extend idpf_ptp_set_rx_tstamp, split tstamp statistics v1 -> v2: add stats for timestamping, use ndo_hwtamp_get/set, fix minor spelling issues
Milena Olech (10):
idpf: add initial PTP support
virtchnl: add PTP virtchnl definitions
idpf: move virtchnl structures to the header file
idpf: negotiate PTP capabilities and get PTP clock
idpf: add mailbox access to read PTP clock time
idpf: add PTP clock configuration
idpf: add Tx timestamp capabilities negotiation
idpf: add Tx timestamp flows
idpf: add support for Rx timestamping
idpf: change the method for mailbox workqueue allocation
drivers/net/ethernet/intel/idpf/Kconfig | 1 + drivers/net/ethernet/intel/idpf/Makefile | 3 + drivers/net/ethernet/intel/idpf/idpf.h | 34 + .../ethernet/intel/idpf/idpf_controlq_api.h | 3 + drivers/net/ethernet/intel/idpf/idpf_dev.c | 14 + .../net/ethernet/intel/idpf/idpf_ethtool.c | 69 +- .../ethernet/intel/idpf/idpf_lan_pf_regs.h | 4 + .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 13 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 47 + drivers/net/ethernet/intel/idpf/idpf_main.c | 8 +- drivers/net/ethernet/intel/idpf/idpf_ptp.c | 989 ++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_ptp.h | 351 +++++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 169 ++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 18 +- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 160 ++- .../net/ethernet/intel/idpf/idpf_virtchnl.h | 84 ++ .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 677 ++++++++++++ drivers/net/ethernet/intel/idpf/virtchnl2.h | 314 +++++- 18 files changed, 2857 insertions(+), 101 deletions(-) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_ptp.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_ptp.h create mode 100644 drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c
base-commit: 925d17a63a913ff2061aae2632d6f08ab6b07afc
Signature · 1 line
2.31.1
PATCH v3 1/10 idpf: add initial PTP support
PTP feature is supported if the VIRTCHNL2_CAP_PTP is negotiated during the capabilities recognition. Initial PTP support includes PTP initialization and registration of the clock.
--- drivers/net/ethernet/intel/idpf/Kconfig | 1 + drivers/net/ethernet/intel/idpf/Makefile | 1 + drivers/net/ethernet/intel/idpf/idpf.h | 3 + drivers/net/ethernet/intel/idpf/idpf_main.c | 4 + drivers/net/ethernet/intel/idpf/idpf_ptp.c | 89 +++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_ptp.h | 32 +++++++ .../net/ethernet/intel/idpf/idpf_virtchnl.c | 9 +- 7 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_ptp.c create mode 100644 drivers/net/ethernet/intel/idpf/idpf_ptp.h
drivers/net/ethernet/intel/idpf/Kconfig +1 -0
@@ -4,6 +4,7 @@ config IDPF tristate "Intel(R) Infrastructure Data Path Function Support" depends on PCI_MSI + depends on PTP_1588_CLOCK_OPTIONAL select DIMLIB select LIBETH help
drivers/net/ethernet/intel/idpf/Makefile +1 -0
@@ -17,3 +17,4 @@ idpf-y := \ idpf_vf_dev.o idpf-$(CONFIG_IDPF_SINGLEQ) += idpf_singleq_txrx.o +idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_ptp.o
drivers/net/ethernet/intel/idpf/idpf.h +3 -0
@@ -531,6 +531,7 @@ struct idpf_vc_xn_manager;* @vector_lock: Lock to protect vector distribution * @queue_lock: Lock to protect queue distribution * @vc_buf_lock: Lock to protect virtchnl buffer +* @ptp: Storage for PTP-related data */ struct idpf_adapter {struct pci_dev *pdev;
@@ -589,6 +590,8 @@ struct idpf_adapter {struct mutex vector_lock;struct mutex queue_lock;struct mutex vc_buf_lock; + +struct idpf_ptp *ptp; };/**
drivers/net/ethernet/intel/idpf/idpf_main.c +4 -0
@@ -187,6 +187,10 @@ static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_free; } + err =pci_enable_ptm (pdev,NULL ); +if (err) +pci_dbg (pdev,"PCIe PTM is not supported by PCIe bus/controller\n" ); +/* set up for high or low dma */ err =dma_set_mask_and_coherent (dev,DMA_BIT_MASK (64 ));if (err) {
drivers/net/ethernet/intel/idpf/idpf_ptp.c new file +89 -0
89 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_ptp.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2024 Intel Corporation */ + +#ifndef _IDPF_PTP_H +#define _IDPF_PTP_H + +#include <linux/ptp_clock_kernel.h> + +/** +* struct idpf_ptp - PTP parameters +* @info: structure defining PTP hardware capabilities +* @clock: pointer to registered PTP clock device +* @adapter: back pointer to the adapter +*/ +struct idpf_ptp { +struct ptp_clock_info info; +struct ptp_clock *clock; +struct idpf_adapter *adapter; +}; + +#if IS_ENABLED (CONFIG_PTP_1588_CLOCK ) +int idpf_ptp_init (struct idpf_adapter *adapter); +void idpf_ptp_release (struct idpf_adapter *adapter); +#else /* CONFIG_PTP_1588_CLOCK */ +static inline int idpf_ptp_init (struct idpf_adapter *adapter) +{ +return 0 ; +} + +static inline void idpf_ptp_release (struct idpf_adapter *adapter) { } +#endif /* CONFIG_PTP_1588_CLOCK */ +#endif /* _IDPF_PTP_H */
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +8 -1
@@ -5,6 +5,7 @@#include "idpf.h" #include "idpf_virtchnl.h" +#include "idpf_ptp.h" #define IDPF_VC_XN_MIN_TIMEOUT_MSEC 2000#define IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC (60 * 1000)
@@ -896,7 +897,8 @@ static int idpf_send_get_caps_msg(struct idpf_adapter *adapter)VIRTCHNL2_CAP_MACFILTER |VIRTCHNL2_CAP_SPLITQ_QSCHED |VIRTCHNL2_CAP_PROMISC | - VIRTCHNL2_CAP_LOOPBACK); +VIRTCHNL2_CAP_LOOPBACK | + VIRTCHNL2_CAP_PTP); xn_params.vc_op =VIRTCHNL2_OP_GET_CAPS ; xn_params.send_buf.iov_base = ∩︀
@@ -3025,6 +3027,10 @@ int idpf_vc_core_init(struct idpf_adapter *adapter) goto err_intr_req; } + err =idpf_ptp_init (adapter); +if (err) +pci_err (adapter->pdev,"PTP init failed, err=%pe\n" ,ERR_PTR (err)); +idpf_init_avail_queues (adapter);/* Skew the delay for init tasks for each function based on fn number
@@ -3080,6 +3086,7 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter)if (!test_bit (IDPF_VC_CORE_INIT , adapter->flags))return ; +idpf_ptp_release (adapter);idpf_deinit_task (adapter);idpf_intr_rel (adapter);idpf_vc_xn_shutdown (adapter->vcxn_mngr);
Signature · 1 line
2.31.1
PATCH v3 2/10 virtchnl: add PTP virtchnl definitions
In reply to Milena OlechPTP capabilities are negotiated using virtchnl commands. There are two available modes of the PTP support: direct and mailbox. When the direct access to PTP resources is negotiated, virtchnl messages returns a set of registers that allow read/write directly. When the mailbox access to PTP resources is negotiated, virtchnl messages are used to access PTP clock and to read the timestamp values.
Virtchnl API covers both modes and exposes a set of PTP capabilities.
Using virtchnl API, the driver recognizes also HW abilities - maximum adjustment of the clock and the basic increment value.
Additionally, API allows to configure the secondary mailbox, dedicated exclusively for PTP purposes.
---
v1 -> v2: fix struct description
drivers/net/ethernet/intel/idpf/virtchnl2.h | 302 ++++++++++++++++++++ 1 file changed, 302 insertions(+)
drivers/net/ethernet/intel/idpf/virtchnl2.h +302 -0
@@ -68,6 +68,16 @@ enum virtchnl2_op {VIRTCHNL2_OP_ADD_MAC_ADDR =535 ,VIRTCHNL2_OP_DEL_MAC_ADDR =536 ,VIRTCHNL2_OP_CONFIG_PROMISCUOUS_MODE =537 , + +/* TimeSync opcodes */ +VIRTCHNL2_OP_PTP_GET_CAPS =541 , +VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP =542 , +VIRTCHNL2_OP_PTP_GET_DEV_CLK_TIME =543 , +VIRTCHNL2_OP_PTP_GET_CROSS_TIME =544 , +VIRTCHNL2_OP_PTP_SET_DEV_CLK_TIME =545 , +VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_FINE =546 , +VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_TIME =547 , + VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP_CAPS = 548, };/**
@@ -1270,4 +1280,296 @@ struct virtchnl2_promisc_info { };VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_promisc_info); +/** +* enum virtchnl2_ptp_caps - PTP capabilities +* @VIRTCHNL2_CAP_PTP_GET_DEVICE_CLK_TIME: direct access to get the time of +* device clock +* @VIRTCHNL2_CAP_PTP_GET_DEVICE_CLK_TIME_MB: mailbox access to get the time of +* device clock +* @VIRTCHNL2_CAP_PTP_GET_CROSS_TIME: direct access to cross timestamp +* @VIRTCHNL2_CAP_PTP_GET_CROSS_TIME_MB: mailbox access to cross timestamp +* @VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME: direct access to set the time of +* device clock +* @VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME_MB: mailbox access to set the time of +* device clock +* @VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK: direct access to adjust the time of device +* clock +* @VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK_MB: mailbox access to adjust the time of +* device clock +* @VIRTCHNL2_CAP_PTP_TX_TSTAMPS: direct access to the Tx timestamping +* @VIRTCHNL2_CAP_PTP_TX_TSTAMPS_MB: mailbox access to the Tx timestamping +* +* PF/VF negotiates a set of supported PTP capabilities with the Control Plane. +* There are two access methods - mailbox (_MB) and direct. +* PTP capabilities enables Main Timer operations: get/set/adjust Main Timer, +* cross timestamping and the Tx timestamping. +*/ +enum virtchnl2_ptp_caps { +VIRTCHNL2_CAP_PTP_GET_DEVICE_CLK_TIME =BIT (0 ), +VIRTCHNL2_CAP_PTP_GET_DEVICE_CLK_TIME_MB =BIT (1 ), +VIRTCHNL2_CAP_PTP_GET_CROSS_TIME =BIT (2 ), +VIRTCHNL2_CAP_PTP_GET_CROSS_TIME_MB =BIT (3 ), +VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME =BIT (4 ), +VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME_MB =BIT (5 ), +VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK =BIT (6 ), +VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK_MB =BIT (7 ), +VIRTCHNL2_CAP_PTP_TX_TSTAMPS =BIT (8 ), +VIRTCHNL2_CAP_PTP_TX_TSTAMPS_MB =BIT (9 ), +}; + +/** +* struct virtchnl2_ptp_clk_reg_offsets - Offsets of device and PHY clocks +* registers. +* @dev_clk_ns_l: Device clock low register offset +* @dev_clk_ns_h: Device clock high register offset +* @phy_clk_ns_l: PHY clock low register offset +* @phy_clk_ns_h: PHY clock high register offset +* @cmd_sync_trigger: The command sync trigger register offset +* @pad: Padding for future extensions +*/ +struct virtchnl2_ptp_clk_reg_offsets { +__le32 dev_clk_ns_l; +__le32 dev_clk_ns_h; +__le32 phy_clk_ns_l; +__le32 phy_clk_ns_h; +__le32 cmd_sync_trigger; +u8 pad[4 ]; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (24 , virtchnl2_ptp_clk_reg_offsets); + +/** +* struct virtchnl2_ptp_cross_time_reg_offsets - Offsets of the device cross +* time registers. +* @sys_time_ns_l: System time low register offset +* @sys_time_ns_h: System time high register offset +* @cmd_sync_trigger: The command sync trigger register offset +* @pad: Padding for future extensions +*/ +struct virtchnl2_ptp_cross_time_reg_offsets { +__le32 sys_time_ns_l; +__le32 sys_time_ns_h; +__le32 cmd_sync_trigger; +u8 pad[4 ]; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_ptp_cross_time_reg_offsets); + +/** +* struct virtchnl2_ptp_clk_adj_reg_offsets - Offsets of device and PHY clocks +* adjustments registers. +* @dev_clk_cmd_type: Device clock command type register offset +* @dev_clk_incval_l: Device clock increment value low register offset +* @dev_clk_incval_h: Device clock increment value high registers offset +* @dev_clk_shadj_l: Device clock shadow adjust low register offset +* @dev_clk_shadj_h: Device clock shadow adjust high register offset +* @phy_clk_cmd_type: PHY timer command type register offset +* @phy_clk_incval_l: PHY timer increment value low register offset +* @phy_clk_incval_h: PHY timer increment value high register offset +* @phy_clk_shadj_l: PHY timer shadow adjust low register offset +* @phy_clk_shadj_h: PHY timer shadow adjust high register offset +*/ +struct virtchnl2_ptp_clk_adj_reg_offsets { +__le32 dev_clk_cmd_type; +__le32 dev_clk_incval_l; +__le32 dev_clk_incval_h; +__le32 dev_clk_shadj_l; +__le32 dev_clk_shadj_h; +__le32 phy_clk_cmd_type; +__le32 phy_clk_incval_l; +__le32 phy_clk_incval_h; +__le32 phy_clk_shadj_l; +__le32 phy_clk_shadj_h; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (40 , virtchnl2_ptp_clk_adj_reg_offsets); + +/** +* struct virtchnl2_ptp_tx_tstamp_latch_caps - PTP Tx timestamp latch +* capabilities. +* @tx_latch_reg_offset_l: Tx timestamp latch low register offset +* @tx_latch_reg_offset_h: Tx timestamp latch high register offset +* @index: Latch index provided to the Tx descriptor +* @pad: Padding for future extensions +*/ +struct virtchnl2_ptp_tx_tstamp_latch_caps { +__le32 tx_latch_reg_offset_l; +__le32 tx_latch_reg_offset_h; +u8 index; +u8 pad[7 ]; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_ptp_tx_tstamp_latch_caps); + +/** +* struct virtchnl2_ptp_get_vport_tx_tstamp_caps - Structure that defines Tx +* tstamp entries. +* @vport_id: Vport number +* @num_latches: Total number of latches +* @tstamp_ns_lo_bit: First bit for nanosecond part of the timestamp +* @tstamp_ns_hi_bit: Last bit for nanosecond part of the timestamp +* @pad: Padding for future tstamp granularity extensions +* @tstamp_latches: Capabilities of Tx timestamp entries +* +* PF/VF sends this message to negotiate the Tx timestamp latches for each +* Vport. +* +* Associated with VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP_CAPS. +*/ +struct virtchnl2_ptp_get_vport_tx_tstamp_caps { +__le32 vport_id; +__le16 num_latches; +u8 tstamp_ns_lo_bit; +u8 tstamp_ns_hi_bit; +u8 pad[8 ]; + + struct virtchnl2_ptp_tx_tstamp_latch_caps tstamp_latches[] +__counted_by_le (num_latches); +}; +VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_ptp_get_vport_tx_tstamp_caps); + +/** +* struct virtchnl2_ptp_get_caps - Get PTP capabilities +* @caps: PTP capability bitmap. See enum virtchnl2_ptp_caps +* @max_adj: The maximum possible frequency adjustment +* @base_incval: The default timer increment value +* @peer_mbx_q_id: ID of the PTP Device Control daemon queue +* @peer_id: Peer ID for PTP Device Control daemon +* @secondary_mbx: Indicates to the driver that it should create a secondary +* mailbox to inetract with control plane for PTP +* @pad: Padding for future extensions +* @clk_offsets: Main timer and PHY registers offsets +* @cross_time_offsets: Cross time registers offsets +* @clk_adj_offsets: Offsets needed to adjust the PHY and the main timer +* +* PF/VF sends this message to negotiate PTP capabilities. CP updates bitmap +* with supported features and fulfills appropriate structures. +* If HW uses primary MBX for PTP: secondary_mbx is set to false. +* If HW uses secondary MBX for PTP: secondary_mbx is set to true. +* Control plane has 2 MBX and the driver has 1 MBX, send to peer +* driver may be used to send a message using valid ptp_peer_mb_q_id and +* ptp_peer_id. +* If HW does not use send to peer driver: secondary_mbx is no care field and +* peer_mbx_q_id holds invalid value (0xFFFF). +* +* Associated with VIRTCHNL2_OP_PTP_GET_CAPS. +*/ +struct virtchnl2_ptp_get_caps { +__le32 caps; +__le32 max_adj; +__le64 base_incval; +__le16 peer_mbx_q_id; +u8 peer_id; +u8 secondary_mbx; +u8 pad[4 ]; + +struct virtchnl2_ptp_clk_reg_offsets clk_offsets; +struct virtchnl2_ptp_cross_time_reg_offsets cross_time_offsets; +struct virtchnl2_ptp_clk_adj_reg_offsets clk_adj_offsets; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (104 , virtchnl2_ptp_get_caps); + +/** +* struct virtchnl2_ptp_tx_tstamp_latch - Structure that describes tx tstamp +* values, index and validity. +* @tstamp: Timestamp value +* @index: Timestamp index from which the value is read +* @valid: Timestamp validity +* @pad: Padding for future extensions +*/ +struct virtchnl2_ptp_tx_tstamp_latch { +__le64 tstamp; +u8 index; +u8 valid; +u8 pad[6 ]; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_ptp_tx_tstamp_latch); + +/** +* struct virtchnl2_ptp_get_vport_tx_tstamp_latches - Tx timestamp latches +* associated with the vport. +* @vport_id: Number of vport that requests the timestamp +* @num_latches: Number of latches +* @get_devtime_with_txtstmp: Flag to request device time along with Tx timestamp +* @pad: Padding for future extensions +* @device_time: device time if get_devtime_with_txtstmp was set in request +* @tstamp_latches: PTP TX timestamp latch +* +* PF/VF sends this message to receive a specified number of timestamps +* entries. +* +* Associated with VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP. +*/ +struct virtchnl2_ptp_get_vport_tx_tstamp_latches { +__le32 vport_id; +__le16 num_latches; +u8 get_devtime_with_txtstmp; +u8 pad[1 ]; +__le64 device_time; + + struct virtchnl2_ptp_tx_tstamp_latch tstamp_latches[] +__counted_by_le (num_latches); +}; +VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_ptp_get_vport_tx_tstamp_latches); + +/** +* struct virtchnl2_ptp_get_dev_clk_time - Associated with message +* VIRTCHNL2_OP_PTP_GET_DEV_CLK_TIME. +* @dev_time_ns: Device clock time value in nanoseconds +* +* PF/VF sends this message to receive the time from the main timer. +*/ +struct virtchnl2_ptp_get_dev_clk_time { +__le64 dev_time_ns; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_ptp_get_dev_clk_time); + +/** +* struct virtchnl2_ptp_get_cross_time: Associated with message +* VIRTCHNL2_OP_PTP_GET_CROSS_TIME. +* @sys_time_ns: System counter value expressed in nanoseconds, read +* synchronously with device time +* @dev_time_ns: Device clock time value expressed in nanoseconds +* +* PF/VF sends this message to receive the cross time. +*/ +struct virtchnl2_ptp_get_cross_time { +__le64 sys_time_ns; +__le64 dev_time_ns; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (16 , virtchnl2_ptp_get_cross_time); + +/** +* struct virtchnl2_ptp_set_dev_clk_time: Associated with message +* VIRTCHNL2_OP_PTP_SET_DEV_CLK_TIME. +* @dev_time_ns: Device time value expressed in nanoseconds to set +* +* PF/VF sends this message to set the time of the main timer. +*/ +struct virtchnl2_ptp_set_dev_clk_time { +__le64 dev_time_ns; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_ptp_set_dev_clk_time); + +/** +* struct virtchnl2_ptp_adj_dev_clk_fine: Associated with message +* VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_FINE. +* @incval: Source timer increment value per clock cycle +* +* PF/VF sends this message to adjust the frequency of the main timer by the +* indicated scaled ppm. +*/ +struct virtchnl2_ptp_adj_dev_clk_fine { +__le64 incval; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_ptp_adj_dev_clk_fine); + +/** +* struct virtchnl2_ptp_adj_dev_clk_time: Associated with message +* VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_TIME. +* @delta: Offset in nanoseconds to adjust the time by +* +* PF/VF sends this message to adjust the time of the main timer by the delta. +*/ +struct virtchnl2_ptp_adj_dev_clk_time { +__le64 delta; +}; +VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_ptp_adj_dev_clk_time); +#endif /* _VIRTCHNL_2_H_ */
Signature · 1 line
2.31.1
PATCH v3 3/10 idpf: move virtchnl structures to the header file
In reply to Milena OlechMove virtchnl structures to the header file to expose them for the PTP virtchnl file.
---
v1 -> v2: fix commit message title
.../net/ethernet/intel/idpf/idpf_virtchnl.c | 86 +------------------ .../net/ethernet/intel/idpf/idpf_virtchnl.h | 84 ++++++++++++++++++ 2 files changed, 86 insertions(+), 84 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +2 -84
@@ -7,88 +7,6 @@#include "idpf_virtchnl.h" #include "idpf_ptp.h" -#define IDPF_VC_XN_MIN_TIMEOUT_MSEC 2000 -#define IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC (60 * 1000) -#define IDPF_VC_XN_IDX_M GENMASK(7, 0) -#define IDPF_VC_XN_SALT_M GENMASK(15, 8) -#define IDPF_VC_XN_RING_LEN U8_MAX - -/** -* enum idpf_vc_xn_state - Virtchnl transaction status -* @IDPF_VC_XN_IDLE: not expecting a reply, ready to be used -* @IDPF_VC_XN_WAITING: expecting a reply, not yet received -* @IDPF_VC_XN_COMPLETED_SUCCESS: a reply was expected and received, -* buffer updated -* @IDPF_VC_XN_COMPLETED_FAILED: a reply was expected and received, but there -* was an error, buffer not updated -* @IDPF_VC_XN_SHUTDOWN: transaction object cannot be used, VC torn down -* @IDPF_VC_XN_ASYNC: transaction sent asynchronously and doesn't have the -* return context; a callback may be provided to handle -* return -*/ -enum idpf_vc_xn_state { -IDPF_VC_XN_IDLE =1 , -IDPF_VC_XN_WAITING , -IDPF_VC_XN_COMPLETED_SUCCESS , -IDPF_VC_XN_COMPLETED_FAILED , -IDPF_VC_XN_SHUTDOWN , -IDPF_VC_XN_ASYNC , -}; - -struct idpf_vc_xn ; -/* Callback for asynchronous messages */ -typedef int (*async_vc_cb ) (struct idpf_adapter *,struct idpf_vc_xn *, -const struct idpf_ctlq_msg *); - -/** -* struct idpf_vc_xn - Data structure representing virtchnl transactions -* @completed: virtchnl event loop uses that to signal when a reply is -* available, uses kernel completion API -* @state: virtchnl event loop stores the data below, protected by the -* completion's lock. -* @reply_sz: Original size of reply, may be > reply_buf.iov_len; it will be -* truncated on its way to the receiver thread according to -* reply_buf.iov_len. -* @reply: Reference to the buffer(s) where the reply data should be written -* to. May be 0-length (then NULL address permitted) if the reply data -* should be ignored. -* @async_handler: if sent asynchronously, a callback can be provided to handle -* the reply when it's received -* @vc_op: corresponding opcode sent with this transaction -* @idx: index used as retrieval on reply receive, used for cookie -* @salt: changed every message to make unique, used for cookie -*/ -struct idpf_vc_xn { -struct completion completed; -enum idpf_vc_xn_state state; -size_t reply_sz; -struct kvec reply; -async_vc_cb async_handler; -u32 vc_op; -u8 idx; -u8 salt; -}; - -/** -* struct idpf_vc_xn_params - Parameters for executing transaction -* @send_buf: kvec for send buffer -* @recv_buf: kvec for recv buffer, may be NULL, must then have zero length -* @timeout_ms: timeout to wait for reply -* @async: send message asynchronously, will not wait on completion -* @async_handler: If sent asynchronously, optional callback handler. The user -* must be careful when using async handlers as the memory for -* the recv_buf _cannot_ be on stack if this is async. -* @vc_op: virtchnl op to send -*/ -struct idpf_vc_xn_params { -struct kvec send_buf; -struct kvec recv_buf; -int timeout_ms; -bool async; -async_vc_cb async_handler; -u32 vc_op; -}; -/** * struct idpf_vc_xn_manager - Manager for tracking transactions * @ring: backing and lookup for transactions
@@ -450,8 +368,8 @@ static void idpf_vc_xn_push_free(struct idpf_vc_xn_manager *vcxn_mngr,* >= @recv_buf.iov_len, but we never overflow @@recv_buf_iov_base). < 0 for * error. */ -static ssize_t idpf_vc_xn_exec (struct idpf_adapter *adapter, -const struct idpf_vc_xn_params *params) +ssize_t idpf_vc_xn_exec (struct idpf_adapter *adapter, +const struct idpf_vc_xn_params *params) {const struct kvec *send_buf = ¶ms->send_buf;struct idpf_vc_xn *xn;
drivers/net/ethernet/intel/idpf/idpf_virtchnl.h +84 -0
96 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 4/10 idpf: negotiate PTP capabilities and get PTP clock
In reply to Milena OlechPTP capabilities are negotiated using virtchnl command. Add get capabilities function, direct access to read the PTP clock time and direct access to read the cross timestamp - system time and PTP clock time. Set initial PTP capabilities exposed to the stack.
---
v1 -> v2: change the size of access fields in ptp struct, remove CONFIG_PCIE_PTM dependency
drivers/net/ethernet/intel/idpf/Makefile | 2 + drivers/net/ethernet/intel/idpf/idpf.h | 2 + drivers/net/ethernet/intel/idpf/idpf_dev.c | 14 + .../ethernet/intel/idpf/idpf_lan_pf_regs.h | 4 + drivers/net/ethernet/intel/idpf/idpf_ptp.c | 263 ++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_ptp.h | 89 ++++++ .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 95 +++++++ 7 files changed, 469 insertions(+) create mode 100644 drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c
drivers/net/ethernet/intel/idpf/Makefile +2 -0
@@ -17,4 +17,6 @@ idpf-y := \ idpf_vf_dev.o idpf-$(CONFIG_IDPF_SINGLEQ) += idpf_singleq_txrx.o + idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_ptp.o +idpf-$(CONFIG_PTP_1588_CLOCK) += idpf_virtchnl_ptp.o
drivers/net/ethernet/intel/idpf/idpf.h +2 -0
@@ -189,6 +189,7 @@ struct idpf_vport_max_q {* @mb_intr_reg_init: Mailbox interrupt register initialization * @reset_reg_init: Reset register initialization * @trigger_reset: Trigger a reset to occur +* @ptp_reg_init: PTP register initialization */ struct idpf_reg_ops {void (*ctlq_reg_init)(struct idpf_ctlq_create_info *cq);
@@ -197,6 +198,7 @@ struct idpf_reg_ops {void (*reset_reg_init)(struct idpf_adapter *adapter);void (*trigger_reset)(struct idpf_adapter *adapter,enum idpf_flags trig_cause); +void (*ptp_reg_init)(const struct idpf_adapter *adapter); };/**
drivers/net/ethernet/intel/idpf/idpf_dev.c +14 -0
@@ -4,6 +4,7 @@#include "idpf.h" #include "idpf_lan_pf_regs.h" #include "idpf_virtchnl.h" +#include "idpf_ptp.h" #define IDPF_PF_ITR_IDX_SPACING 0x4
@@ -148,6 +149,18 @@ static void idpf_trigger_reset(struct idpf_adapter *adapter, idpf_get_reg_addr(adapter, PFGEN_CTRL)); } +/** +* idpf_ptp_reg_init - Initialize required registers +* @adapter: Driver specific private structure +* +* Set the bits required for enabling shtime and cmd execution +*/ +static void idpf_ptp_reg_init (const struct idpf_adapter *adapter) +{ + adapter->ptp->cmd.shtime_enable_mask =PF_GLTSYN_CMD_SYNC_SHTIME_EN_M ; + adapter->ptp->cmd.exec_cmd_mask =PF_GLTSYN_CMD_SYNC_EXEC_CMD_M ; +} +/** * idpf_reg_ops_init - Initialize register API function pointers * @adapter: Driver specific private structure
@@ -159,6 +172,7 @@ static void idpf_reg_ops_init(struct idpf_adapter *adapter) adapter->dev_ops.reg_ops.mb_intr_reg_init = idpf_mb_intr_reg_init; adapter->dev_ops.reg_ops.reset_reg_init = idpf_reset_reg_init; adapter->dev_ops.reg_ops.trigger_reset = idpf_trigger_reset; + adapter->dev_ops.reg_ops.ptp_reg_init = idpf_ptp_reg_init; }/**
drivers/net/ethernet/intel/idpf/idpf_lan_pf_regs.h +4 -0
@@ -53,6 +53,10 @@#define PF_FW_ATQH_ATQH_M GENMASK(9, 0)#define PF_FW_ATQT (PF_FW_BASE + 0x24) +/* Timesync registers */ +#define PF_GLTSYN_CMD_SYNC_EXEC_CMD_M GENMASK(1, 0) +#define PF_GLTSYN_CMD_SYNC_SHTIME_EN_M BIT(2) +/* Interrupts */ #define PF_GLINT_BASE 0x08900000#define PF_GLINT_DYN_CTL (_INT) (PF_GLINT_BASE + ((_INT) * 0x1000))
drivers/net/ethernet/intel/idpf/idpf_ptp.c +263 -0
281 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_ptp.h +89 -0
115 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 5/10 idpf: add mailbox access to read PTP clock time
In reply to Milena OlechWhen the access to read PTP clock is specified as mailbox, the driver needs to send virtchnl message to perform PTP actions. Message is sent using idpf_mbq_opc_send_msg_to_peer_drv mailbox opcode, with the parameters received during PTP capabilities negotiation.
Add functions to recognize PTP messages, move them to dedicated secondary mailbox, read the PTP clock time and cross timestamp using mailbox messages.
--- .../ethernet/intel/idpf/idpf_controlq_api.h | 3 + drivers/net/ethernet/intel/idpf/idpf_ptp.c | 66 +++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_ptp.h | 43 ++++++++++ .../net/ethernet/intel/idpf/idpf_virtchnl.c | 47 +++++++++++ .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 83 +++++++++++++++++++ 5 files changed, 242 insertions(+)
drivers/net/ethernet/intel/idpf/idpf_controlq_api.h +3 -0
@@ -123,9 +123,12 @@ struct idpf_ctlq_info {/** * enum idpf_mbx_opc - PF/VF mailbox commands * @idpf_mbq_opc_send_msg_to_cp: used by PF or VF to send a message to its CP +* @idpf_mbq_opc_send_msg_to_peer_drv: used by PF or VF to send a message to +* any peer driver */ enum idpf_mbx_opc { idpf_mbq_opc_send_msg_to_cp =0x0801 , + idpf_mbq_opc_send_msg_to_peer_drv =0x0804 , };/* API supported for control queue management */
drivers/net/ethernet/intel/idpf/idpf_ptp.c +66 -0
94 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_ptp.h +43 -0
77 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +47 -0
59 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +83 -0
98 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 6/10 idpf: add PTP clock configuration
In reply to Milena OlechPTP clock configuration operations - set time, adjust time and adjust frequency are required to control the clock and maintain synchronization process.
Extend get PTP capabilities function to request for the clock adjustments and add functions to enable these actions using dedicated virtchnl messages.
--- drivers/net/ethernet/intel/idpf/idpf_ptp.c | 191 ++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_ptp.h | 43 +++- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 3 + .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 142 ++++++++++++- 4 files changed, 376 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_ptp.c +191 -0
@@ -48,6 +48,20 @@ void idpf_ptp_get_features_access(const struct idpf_adapter *adapter) ptp->get_cross_tstamp_access =idpf_ptp_get_access (adapter, direct, mailbox); + +/* Set the device clock time */ + direct =VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME ; + mailbox =VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME ; + ptp->set_dev_clk_time_access =idpf_ptp_get_access (adapter, + direct, + mailbox); + +/* Adjust the device clock time */ + direct =VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK ; + mailbox =VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK_MB ; + ptp->adj_dev_clk_time_access =idpf_ptp_get_access (adapter, + direct, + mailbox); }/**
@@ -296,6 +310,154 @@ static int idpf_ptp_gettimex64(struct ptp_clock_info *info,return 0 ; } +/** +* idpf_ptp_settime64 - Set the time of the clock +* @info: the driver's PTP info structure +* @ts: timespec64 structure that holds the new time value +* +* Set the device clock to the user input value. The conversion from timespec +* to ns happens in the write function. +* +* Return: 0 on success, -errno otherwise. +*/ +static int idpf_ptp_settime64 (struct ptp_clock_info *info, +const struct timespec64 *ts) +{ +struct idpf_adapter *adapter =idpf_ptp_info_to_adapter (info); +enum idpf_ptp_access access; +int err; +u64 ns; + + access = adapter->ptp->set_dev_clk_time_access; +if (access !=IDPF_PTP_MAILBOX ) +return -EOPNOTSUPP ; + + ns =timespec64_to_ns (ts); + + err =idpf_ptp_set_dev_clk_time (adapter, ns); +if (err) { +pci_err (adapter->pdev,"Failed to set the time, err: %pe\n" ,ERR_PTR (err)); +return err; + } + +return 0 ; +} + +/** +* idpf_ptp_adjtime_nonatomic - Do a non-atomic clock adjustment +* @info: the driver's PTP info structure +* @delta: Offset in nanoseconds to adjust the time by +* +* Return: 0 on success, -errno otherwise. +*/ +static int idpf_ptp_adjtime_nonatomic (struct ptp_clock_info *info,s64 delta) +{ +struct timespec64 now, then; +int err; + + err =idpf_ptp_gettimex64 (info, &now,NULL ); +if (err) +return err; + + then =ns_to_timespec64 (delta); + now =timespec64_add (now, then); + +return idpf_ptp_settime64 (info, &now); +} + +/** +* idpf_ptp_adjtime - Adjust the time of the clock by the indicated delta +* @info: the driver's PTP info structure +* @delta: Offset in nanoseconds to adjust the time by +* +* Return: 0 on success, -errno otherwise. +*/ +static int idpf_ptp_adjtime (struct ptp_clock_info *info,s64 delta) +{ +struct idpf_adapter *adapter =idpf_ptp_info_to_adapter (info); +enum idpf_ptp_access access; +int err; + + access = adapter->ptp->adj_dev_clk_time_access; +if (access !=IDPF_PTP_MAILBOX ) +return -EOPNOTSUPP ; + +/* Hardware only supports atomic adjustments using signed 32-bit +* integers. For any adjustment outside this range, perform +* a non-atomic get->adjust->set flow. +*/ +if (delta >S32_MAX || delta <S32_MIN ) +return idpf_ptp_adjtime_nonatomic (info, delta); + + err =idpf_ptp_adj_dev_clk_time (adapter, delta); +if (err) { +pci_err (adapter->pdev,"Failed to adjust the clock with delta %lld err: %pe\n" , delta,ERR_PTR (err)); +return err; + } + +return 0 ; +} + +/** +* idpf_ptp_adjfine - Adjust clock increment rate +* @info: the driver's PTP info structure +* @scaled_ppm: Parts per million with 16-bit fractional field +* +* Adjust the frequency of the clock by the indicated scaled ppm from the +* base frequency. +* +* Return: 0 on success, -errno otherwise. +*/ +static int idpf_ptp_adjfine (struct ptp_clock_info *info,long scaled_ppm) +{ +struct idpf_adapter *adapter =idpf_ptp_info_to_adapter (info); +enum idpf_ptp_access access; +u64 incval, diff; +int err; + + access = adapter->ptp->adj_dev_clk_time_access; +if (access !=IDPF_PTP_MAILBOX ) +return -EOPNOTSUPP ; + + incval = adapter->ptp->base_incval; + + diff =adjust_by_scaled_ppm (incval, scaled_ppm); + err =idpf_ptp_adj_dev_clk_fine (adapter, diff); +if (err) +pci_err (adapter->pdev,"Failed to adjust clock increment rate for scaled ppm %ld %pe\n" , scaled_ppm,ERR_PTR (err)); + +return 0 ; +} + +/** +* idpf_ptp_verify_pin - Verify if pin supports requested pin function +* @info: the driver's PTP info structure +* @pin: Pin index +* @func: Assigned function +* @chan: Assigned channel +* +* Return: EOPNOTSUPP as not supported yet. +*/ +static int idpf_ptp_verify_pin (struct ptp_clock_info *info,unsigned int pin, +enum ptp_pin_function func,unsigned int chan) +{ +return -EOPNOTSUPP ; +} + +/** +* idpf_ptp_gpio_enable - Enable/disable ancillary features of PHC +* @info: the driver's PTP info structure +* @rq: The requested feature to change +* @on: Enable/disable flag +* +* Return: EOPNOTSUPP as not supported yet. +*/ +static int idpf_ptp_gpio_enable (struct ptp_clock_info *info, +struct ptp_clock_request *rq,int on) +{ +return -EOPNOTSUPP ; +} +/** * idpf_ptp_set_caps - Set PTP capabilities * @adapter: Driver specific private structure
@@ -310,7 +472,13 @@ static void idpf_ptp_set_caps(const struct idpf_adapter *adapter) KBUILD_MODNAME, pci_name(adapter->pdev)); info->owner =THIS_MODULE ; + info->max_adj = adapter->ptp->max_adj; info->gettimex64 = idpf_ptp_gettimex64; + info->settime64 = idpf_ptp_settime64; + info->adjfine = idpf_ptp_adjfine; + info->adjtime = idpf_ptp_adjtime; + info->verify = idpf_ptp_verify_pin; + info->enable = idpf_ptp_gpio_enable;#if IS_ENABLED (CONFIG_ARM_ARCH_TIMER ) info->getcrosststamp = idpf_ptp_get_crosststamp;
@@ -361,6 +529,7 @@ static int idpf_ptp_create_clock(const struct idpf_adapter *adapter)*/ int idpf_ptp_init (struct idpf_adapter *adapter) { +struct timespec64 ts;int err;if (!idpf_is_cap_ena (adapter,IDPF_OTHER_CAPS ,VIRTCHNL2_CAP_PTP )) {
@@ -388,10 +557,32 @@ int idpf_ptp_init(struct idpf_adapter *adapter)if (err) goto free_ptp; +/* Write the default increment time value if the clock adjustments +* are enabled. +*/ +if (adapter->ptp->adj_dev_clk_time_access !=IDPF_PTP_NONE ) { + err =idpf_ptp_adj_dev_clk_fine (adapter, + adapter->ptp->base_incval); +if (err) + goto remove_clock; + } + +/* Write the initial time value if the set time operation is enabled */ +if (adapter->ptp->set_dev_clk_time_access !=IDPF_PTP_NONE ) { + ts =ktime_to_timespec64 (ktime_get_real ()); + err =idpf_ptp_settime64 (&adapter->ptp->info, &ts); +if (err) + goto remove_clock; + } +pci_dbg (adapter->pdev,"PTP init successful\n" );return 0 ; +remove_clock: +ptp_clock_unregister (adapter->ptp->clock); + adapter->ptp->clock =NULL ; + free_ptp:kfree (adapter->ptp); adapter->ptp =NULL ;
drivers/net/ethernet/intel/idpf/idpf_ptp.h +42 -1
82 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +3 -0
@@ -166,6 +166,9 @@ static bool idpf_ptp_is_mb_msg(u32 op)switch (op) {case VIRTCHNL2_OP_PTP_GET_DEV_CLK_TIME :case VIRTCHNL2_OP_PTP_GET_CROSS_TIME : +case VIRTCHNL2_OP_PTP_SET_DEV_CLK_TIME : +case VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_FINE : +case VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_TIME :return true;default :return false;
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +140 -2
175 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 7/10 idpf: add Tx timestamp capabilities negotiation
In reply to Milena OlechTx timestamp capabilities are negotiated for the uplink Vport. Driver receives information about the number of available Tx timestamp latches, the size of Tx timestamp value and the set of indexes used for Tx timestamping.
Add function to get the Tx timestamp capabilities and parse the uplink vport flag.
---
v2 -> v3: revert changes in idpf_for_each_vport, fix minor issues v1 -> v2: change the idpf_for_each_vport macro
drivers/net/ethernet/intel/idpf/idpf.h | 9 ++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 64 +++++++++ drivers/net/ethernet/intel/idpf/idpf_ptp.h | 96 ++++++++++++- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 11 ++ .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 128 +++++++++++++++++- drivers/net/ethernet/intel/idpf/virtchnl2.h | 12 +- 6 files changed, 316 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/idpf/idpf.h +9 -0
@@ -292,6 +292,7 @@ struct idpf_port_stats {* @port_stats: per port csum, header split, and other offload stats * @link_up: True if link is up * @sw_marker_wq: workqueue for marker packets +* @tx_tstamp_caps: Capabilities negotiated for Tx timestamping */ struct idpf_vport {u16 num_txq;
@@ -336,6 +337,8 @@ struct idpf_vport {bool link_up;wait_queue_head_t sw_marker_wq; + +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; };/**
@@ -480,6 +483,12 @@ struct idpf_vport_config {struct idpf_vc_xn_manager ; +#define idpf_for_each_vport (adapter, iter) \ + for (struct idpf_vport **__##iter = &(adapter)->vports[0], \ + *iter = *__##iter; \ + __##iter < &(adapter)->vports[(adapter)->num_alloc_vports]; \ + iter = *(++__##iter)) +/** * struct idpf_adapter - Device data struct generated on probe * @pdev: PCI device struct given on probe
drivers/net/ethernet/intel/idpf/idpf_ptp.c +64 -0
82 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_ptp.h +95 -1
131 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +11 -0
@@ -169,6 +169,8 @@ static bool idpf_ptp_is_mb_msg(u32 op)case VIRTCHNL2_OP_PTP_SET_DEV_CLK_TIME :case VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_FINE :case VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_TIME : +case VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP_CAPS : +case VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP :return true;default :return false;
@@ -3120,6 +3122,7 @@ void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q)u16 rx_itr[] = {2 ,8 ,32 ,96 ,128 };struct idpf_rss_data *rss_data;u16 idx = vport->idx; +int err; vport_config = adapter->vport_config[idx]; rss_data = &vport_config->user_config.rss_data;
@@ -3154,6 +3157,14 @@ void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q)idpf_vport_alloc_vec_indexes (vport); vport->crc_enable = adapter->crc_enable; + +if (!(vport_msg->vport_flags & +cpu_to_le16 (VIRTCHNL2_VPORT_UPLINK_PORT ))) +return ; + + err =idpf_ptp_get_vport_tstamps_caps (vport); +if (err) +pci_dbg (vport->adapter->pdev,"Tx timestamping not supported\n" ); }/**
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +127 -1
137 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/virtchnl2.h +10 -2
@@ -569,6 +569,14 @@ struct virtchnl2_queue_reg_chunks { };VIRTCHNL2_CHECK_STRUCT_LEN (8 , virtchnl2_queue_reg_chunks); +/** +* enum virtchnl2_vport_flags - Vport flags that indicate vport capabilities. +* @VIRTCHNL2_VPORT_UPLINK_PORT: Representatives of underlying physical ports +*/ +enum virtchnl2_vport_flags { +VIRTCHNL2_VPORT_UPLINK_PORT =BIT (0 ), +}; +/** * struct virtchnl2_create_vport - Create vport config info. * @vport_type: See enum virtchnl2_vport_type.
@@ -587,7 +595,7 @@ VIRTCHNL2_CHECK_STRUCT_LEN(8, virtchnl2_queue_reg_chunks);* @max_mtu: Max MTU. CP populates this field on response. * @vport_id: Vport id. CP populates this field on response. * @default_mac_addr: Default MAC address. -* @pad: Padding. +* @vport_flags: See enum virtchnl2_vport_flags. * @rx_desc_ids: See VIRTCHNL2_RX_DESC_IDS definitions. * @tx_desc_ids: See VIRTCHNL2_TX_DESC_IDS definitions. * @pad1: Padding.
@@ -620,7 +628,7 @@ struct virtchnl2_create_vport {__le16 max_mtu;__le32 vport_id;u8 default_mac_addr[ETH_ALEN ]; -__le16 pad; +__le16 vport_flags;__le64 rx_desc_ids;__le64 tx_desc_ids;u8 pad1[72 ];
Signature · 1 line
2.31.1
Re: [PATCH v3 iwl-next 07/10] idpf: add Tx timestamp capabilities negotiation
Quoted 8 lines · Milena Olech
Tx timestamp capabilities are negotiated for the uplink Vport. Driver receives information about the number of available Tx timestamp latches, the size of Tx timestamp value and the set of indexes used for Tx timestamping.
Add function to get the Tx timestamp capabilities and parse the uplink vport flag.
Quoted 6 lines
Reviewed-by Alexander Lobakin <[email protected]>Co-developed-by Emil Tantilov <[email protected]>Signed-off-by Emil Tantilov <[email protected]>Co-developed-by Pavan Kumar Linga <[email protected]>Signed-off-by Pavan Kumar Linga <[email protected]>Signed-off-by Milena Olech <[email protected]>
PATCH v3 8/10 idpf: add Tx timestamp flows
In reply to Milena OlechAdd functions to request Tx timestamp for the PTP packets, read the Tx timestamp when the completion tag for that packet is being received, extend the Tx timestamp value and set the supported timestamping modes.
Tx timestamp is requested for the PTP packets by setting a TSYN bit and index value in the Tx context descriptor. The driver assumption is that the Tx timestamp value is ready to be read when the completion tag is received. Then the driver schedules delayed work and the Tx timestamp value read is requested through virtchnl message. At the end, the Tx timestamp value is extended to 64-bit and provided back to the skb.
---
v2 -> v3: change get_timestamp_filter function name, split stats into vport-based and tx queue-based
v1 -> v2: add timestamping stats, use ndo_hwtamp_get/ndo_hwstamp_set
drivers/net/ethernet/intel/idpf/idpf.h | 20 ++ .../net/ethernet/intel/idpf/idpf_ethtool.c | 69 ++++- .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 13 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 47 ++++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 236 +++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_ptp.h | 52 ++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 139 ++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 11 +- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 6 +- .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 235 +++++++++++++++++ 10 files changed, 814 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/idpf/idpf.h +20 -0
@@ -246,9 +246,23 @@ struct idpf_port_stats {u64_stats_t tx_busy;u64_stats_t tx_drops;u64_stats_t tx_dma_map_errs; +u64_stats_t tx_hwtstamp_skipped;struct virtchnl2_vport_stats vport_stats; }; +/** +* struct idpf_tx_tstamp_stats - Tx timestamp statistics +* @tx_hwtstamp_lock: Lock to protect Tx tstamp stats +* @tx_hwtstamp_discarded: Number of Tx skbs discarded due to cached PHC time +* being too old to correctly extend timestamp +* @tx_hwtstamp_flushed: Number of Tx skbs flushed due to interface closed +*/ +struct idpf_tx_tstamp_stats { +struct mutex tx_hwtstamp_lock; +u32 tx_hwtstamp_discarded; +u32 tx_hwtstamp_flushed; +}; +/** * struct idpf_vport - Handle for netdevices and queue resources * @num_txq: Number of allocated TX queues
@@ -293,6 +307,9 @@ struct idpf_port_stats {* @link_up: True if link is up * @sw_marker_wq: workqueue for marker packets * @tx_tstamp_caps: Capabilities negotiated for Tx timestamping +* @tstamp_config: The Tx tstamp config +* @tstamp_task: Tx timestamping task +* @tstamp_stats: Tx timestamping statistics */ struct idpf_vport {u16 num_txq;
@@ -339,6 +356,9 @@ struct idpf_vport {wait_queue_head_t sw_marker_wq;struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct kernel_hwtstamp_config tstamp_config; +struct work_struct tstamp_task; +struct idpf_tx_tstamp_stats tstamp_stats; };/**
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +68 -1
117 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_lan_txrx.h +12 -1
@@ -282,7 +282,18 @@ struct idpf_flex_tx_tso_ctx_qw {u8 flex; }; -struct idpf_flex_tx_ctx_desc { +union idpf_flex_tx_ctx_desc { +/* DTYPE = IDPF_TX_DESC_DTYPE_CTX (0x01) */ +struct { +__le64 qw0; +#define IDPF_TX_CTX_L2TAG2_M GENMASK_ULL(47, 32) +__le64 qw1; +#define IDPF_TX_CTX_DTYPE_M GENMASK_ULL(3, 0) +#define IDPF_TX_CTX_CMD_M GENMASK_ULL(15, 4) +#define IDPF_TX_CTX_TSYN_REG_M GENMASK_ULL(47, 30) +#define IDPF_TX_CTX_MSS_M GENMASK_ULL(50, 63) + } tsyn; +/* DTYPE = IDPF_TX_DESC_DTYPE_FLEX_TSO_CTX (0x05) */ struct {struct idpf_flex_tx_tso_ctx_qw qw0;
drivers/net/ethernet/intel/idpf/idpf_lib.c +47 -0
63 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_ptp.c +234 -2
315 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_ptp.h +52 -0
105 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.c +132 -7
216 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +9 -2
@@ -142,6 +142,7 @@ do { \#define IDPF_TX_FLAGS_IPV4 BIT(1)#define IDPF_TX_FLAGS_IPV6 BIT(2)#define IDPF_TX_FLAGS_TUNNEL BIT(3) +#define IDPF_TX_FLAGS_TSYN BIT(4)union idpf_tx_flex_desc {struct idpf_flex_tx_desc q;/* queue based scheduling */
@@ -445,6 +446,7 @@ struct idpf_tx_queue_stats {u64_stats_t q_busy;u64_stats_t skb_drops;u64_stats_t dma_map_errs; +u64_stats_t tstamp_skipped; };#define IDPF_ITR_DYNAMIC 1
@@ -619,6 +621,8 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64,* @compl_tag_bufid_m: Completion tag buffer id mask * @compl_tag_cur_gen: Used to keep track of current completion tag generation * @compl_tag_gen_max: To determine when compl_tag_cur_gen should be reset +* @cached_tstamp_caps: Tx timestamp capabilities negotiated with the CP +* @tstamp_task: Work that handles Tx timestamp read * @stats_sync: See struct u64_stats_sync * @q_stats: See union idpf_tx_queue_stats * @q_id: Queue id
@@ -632,7 +636,7 @@ struct idpf_tx_queue {struct idpf_base_tx_desc *base_tx;struct idpf_base_tx_ctx_desc *base_ctx;union idpf_tx_flex_desc *flex_tx; -struct idpf_flex_tx_ctx_desc *flex_ctx; +union idpf_flex_tx_ctx_desc *flex_ctx;void *desc_ring; };
@@ -668,6 +672,9 @@ struct idpf_tx_queue {u16 compl_tag_cur_gen;u16 compl_tag_gen_max; +struct idpf_ptp_vport_tx_tstamp_caps *cached_tstamp_caps; +struct work_struct *tstamp_task; +struct u64_stats_sync stats_sync;struct idpf_tx_queue_stats q_stats;__cacheline_group_end_aligned (read_write);
@@ -681,7 +688,7 @@ struct idpf_tx_queue {__cacheline_group_end_aligned (cold); }; libeth_cacheline_set_assert(struct idpf_tx_queue, 64, -88 +sizeof (struct u64_stats_sync ), +112 +sizeof (struct u64_stats_sync ), 24);/**
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +5 -1
@@ -3163,8 +3163,12 @@ void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q)return ; err =idpf_ptp_get_vport_tstamps_caps (vport); -if (err) +if (err) {pci_dbg (vport->adapter->pdev,"Tx timestamping not supported\n" ); +return ; + } + +INIT_WORK (&vport->tstamp_task, idpf_tstamp_task); }/**
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +235 -0
251 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH v3 iwl-next 08/10] idpf: add Tx timestamp flows
Quoted 35 lines · Milena Olech
Add functions to request Tx timestamp for the PTP packets, read the Tx timestamp when the completion tag for that packet is being received, extend the Tx timestamp value and set the supported timestamping modes.
Tx timestamp is requested for the PTP packets by setting a TSYN bit and index value in the Tx context descriptor. The driver assumption is that the Tx timestamp value is ready to be read when the completion tag is received. Then the driver schedules delayed work and the Tx timestamp value read is requested through virtchnl message. At the end, the Tx timestamp value is extended to 64-bit and provided back to the skb.
Co-developed-by Josh Hay <[email protected]>Signed-off-by Josh Hay <[email protected]>Signed-off-by Milena Olech <[email protected]>---
v2 -> v3: changeget_timestamp_filterfunction name, split stats into vport-based and tx queue-based
v1 -> v2: add timestamping stats, use ndo_hwtamp_get/ndo_hwstamp_setdrivers/net/ethernet/intel/idpf/idpf.h | 20 ++ .../net/ethernet/intel/idpf/idpf_ethtool.c | 69 ++++- .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 13 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 47 ++++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 236 +++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_ptp.h | 52 ++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 139 ++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 11 +- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 6 +- .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 235 +++++++++++++++++ 10 files changed, 814 insertions(+), 14 deletions(-)drivers/net/ethernet/intel/idpf/idpf_ethtool.c +3
-0+/** +* idpf_get_timestamp_filters - Get the supported timestamping mode +* @vport: Virtual port structure
drivers/net/ethernet/intel/idpf/idpf_ethtool.c static int idpf_get_link_ksettings(struct net_device *netdev, · line 1339
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +10
-0+* @info: ethtool timestamping info structure +* +* Get the Tx/Rx timestamp filters. +*/ +static void idpf_get_timestamp_filters (const struct idpf_vport *vport, +struct kernel_ethtool_ts_info *info) +{ +if (!vport->tx_tstamp_caps || + vport->adapter->ptp->tx_tstamp_access ==IDPF_PTP_NONE ) +return ;
Is making SOF_TIMESTAMPING_RX_HARDWARE and SOF_TIMESTAMPING_RAW_HARDWARE conditional on tx_tstamp_access intentional?
Quoted 12 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +12
-0+ + info->so_timestamping =SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + info->tx_types =BIT (HWTSTAMP_TX_OFF ) |BIT (HWTSTAMP_TX_ON ); +} + + +static int idpf_hwtstamp_get (struct net_device *netdev, +struct kernel_hwtstamp_config *config)
drivers/net/ethernet/intel/idpf/idpf_ethtool.c static int idpf_get_link_ksettings(struct net_device *netdev,
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +10
-0+{ +struct idpf_adapter *adapter =idpf_netdev_to_adapter (netdev); +struct idpf_vport *vport; + +idpf_vport_cfg_lock (adapter); + vport =idpf_netdev_to_vport (netdev); + +if (!idpf_ptp_get_vport_tstamp_capability (vport)) { +idpf_vport_cfg_unlock (adapter); +return -EOPNOTSUPP ;
Should this return an empty config and return 0, rather than return error?
Quoted 104 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +11
-0+ } + + *config = vport->tstamp_config; + +idpf_vport_cfg_unlock (adapter); + +return 0 ; +} +static const struct net_device_ops idpf_netdev_ops = { .ndo_open = idpf_open, .ndo_stop = idpf_stop,@@ -2383,4 +2428,6 @@ static const struct net_device_ops idpf_netdev_ops = { .ndo_get_stats64 = idpf_get_stats64, .ndo_set_features = idpf_set_features, .ndo_tx_timeout = idpf_tx_timeout, + .ndo_hwtstamp_get = idpf_hwtstamp_get, + .ndo_hwtstamp_set = idpf_hwtstamp_set, };drivers/net/ethernet/intel/idpf/idpf_ptp.c +56
-0@@ -317,6 +317,37 @@ static int idpf_ptp_gettimex64(struct ptp_clock_info *info,return 0 ; } +/** +* idpf_ptp_update_cached_phctime - Update the cached PHC time values +* @adapter: Driver specific private structure +* +* This function updates the system time values which are cached in the adapter +* structure. +* +* This function must be called periodically to ensure that the cached value +* is never more than 2 seconds old. +* +* Return 0 on success, negative otherwise. +*/ +static int idpf_ptp_update_cached_phctime (struct idpf_adapter *adapter) +{ +u64 systime; +int err; + + err =idpf_ptp_read_src_clk_reg (adapter, &systime,NULL ); +if (err) +return -EACCES ; + +/* Update the cached PHC time stored in the adapter structure. +* These values are used to extend Tx timestamp values to 64 bit +* expected by the stack. +*/ +WRITE_ONCE (adapter->ptp->cached_phc_time, systime); +WRITE_ONCE (adapter->ptp->cached_phc_jiffies, jiffies); + +return 0 ; +} +/** * idpf_ptp_settime64 - Set the time of the clock * @info: the driver's PTP info structure @@ -347,6 +378,11 @@ static int idpf_ptp_settime64(struct ptp_clock_info *info,return err; } + err =idpf_ptp_update_cached_phctime (adapter); +if (err) +pci_warn (adapter->pdev, +"Unable to immediately update cached PHC time\n" ); +return 0 ; }@@ -402,6 +438,11 @@ static int idpf_ptp_adjtime(struct ptp_clock_info *info, s64 delta)return err; } + err =idpf_ptp_update_cached_phctime (adapter); +if (err) +pci_warn (adapter->pdev, +"Unable to immediately update cached PHC time\n" ); +return 0 ; }@@ -465,6 +506,162 @@ static int idpf_ptp_gpio_enable(struct ptp_clock_info *info,return -EOPNOTSUPP ; } +/** +* idpf_ptp_tstamp_extend_32b_to_64b - Convert a 32b nanoseconds Tx timestamp +* to 64b. +* @cached_phc_time: recently cached copy of PHC time +* @in_timestamp: Ingress/egress 32b nanoseconds timestamp value +* +* Hardware captures timestamps which contain only 32 bits of nominal +* nanoseconds, as opposed to the 64bit timestamps that the stack expects. +* +* Return: Tx timestamp value extended to 64 bits based on cached PHC time. +*/ +u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time,u32 in_timestamp) +{ +u32 delta, phc_lo; +u64 ns;
drivers/net/ethernet/intel/idpf/idpf_ptp.c static int idpf_ptp_gpio_enable(struct ptp_clock_info *info, · line 533
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +10
-0+ + phc_lo =lower_32_bits (cached_phc_time); + delta = in_timestamp - phc_lo; + +if (delta >S32_MAX ) { + delta = phc_lo - in_timestamp; + ns = cached_phc_time - delta; + }else { + ns = cached_phc_time + delta; + }
If using s64 delta and ns, no need for branch?
Quoted 53 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +53
-0+ +return ns; +} + +/** +* idpf_ptp_extend_ts - Convert a 40b timestamp to 64b nanoseconds +* @vport: Virtual port structure +* @in_tstamp: Ingress/egress timestamp value +* +* It is assumed that the caller verifies the timestamp is valid prior to +* calling this function. +* +* Extract the 32bit nominal nanoseconds and extend them. Use the cached PHC +* time stored in the device private PTP structure as the basis for timestamp +* extension. +* +* Return: Tx timestamp value extended to 64 bits. +*/ +u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u64 in_tstamp) +{ +struct idpf_ptp *ptp = vport->adapter->ptp; +unsigned long discard_time; + + discard_time = ptp->cached_phc_jiffies +2 *HZ ; + +if (time_is_before_jiffies (discard_time)) { +mutex_lock (&vport->tstamp_stats.tx_hwtstamp_lock); + vport->tstamp_stats.tx_hwtstamp_discarded++; +mutex_unlock (&vport->tstamp_stats.tx_hwtstamp_lock); + +return 0 ; + } + +return idpf_ptp_tstamp_extend_32b_to_64b (ptp->cached_phc_time, +lower_32_bits (in_tstamp)); +} + +/** +* idpf_ptp_request_ts - Request an available Tx timestamp index +* @tx_q: Transmit queue on which the Tx timestamp is requested +* @skb: The SKB to associate with this timestamp request +* @idx: Index of the Tx timestamp latch +* +* Request tx timestamp index negotiated during PTP init that will be set into +* Tx descriptor. +* +* Return: 0 and the index that can be provided to Tx descriptor on success, +* -errno otherwise. +*/ +int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +u32 *idx) +{ +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp;
drivers/net/ethernet/intel/idpf/idpf_ptp.c static int idpf_ptp_gpio_enable(struct ptp_clock_info *info, · line 596
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +10
-0+struct list_head *head; + + head = &tx_q->cached_tstamp_caps->latches_free; +if (list_empty (head)) +return -ENOBUFS ; + +/* Get the index from the free latches list */ +spin_lock_bh (&tx_q->cached_tstamp_caps->lock_free); + ptp_tx_tstamp = list_first_entry(head, struct idpf_ptp_tx_tstamp, + list_member);
Racy, as list_empty is tested before taking the spin lock?
Quoted 766 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +105
-2+list_del (&ptp_tx_tstamp->list_member); +spin_unlock_bh (&tx_q->cached_tstamp_caps->lock_free); + + ptp_tx_tstamp->skb =skb_get (skb); +skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; + +/* Move the element to the used latches list */ +spin_lock_bh (&tx_q->cached_tstamp_caps->lock_in_use); +list_add (&ptp_tx_tstamp->list_member, + &tx_q->cached_tstamp_caps->latches_in_use); +spin_unlock_bh (&tx_q->cached_tstamp_caps->lock_in_use); + + *idx = ptp_tx_tstamp->idx; + +return 0 ; +} + +/** +* idpf_ptp_set_timestamp_mode - Setup driver for requested timestamp mode +* @vport: Virtual port structure +* @config: Hwtstamp settings requested or saved +* +* Return: 0 on success, -errno otherwise. +*/ +int idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config) +{ +switch (config->tx_type) { +case HWTSTAMP_TX_OFF : +case HWTSTAMP_TX_ON : +break ; +default : +return -EINVAL ; + } + + vport->tstamp_config.tx_type = config->tx_type; + +return 0 ; +} + +/** +* idpf_tstamp_task - Delayed task to handle Tx tstamps +* @work: work_struct handle +*/ +void idpf_tstamp_task (struct work_struct *work) +{ +struct idpf_vport *vport; + + vport = container_of(work, struct idpf_vport, tstamp_task); + +idpf_ptp_get_tx_tstamp (vport); +} + +/** +* idpf_ptp_do_aux_work - Do PTP periodic work +* @info: Driver's PTP info structure +* +* Return: Number of jiffies to periodic work. +*/ +static long idpf_ptp_do_aux_work (struct ptp_clock_info *info) +{ +struct idpf_adapter *adapter =idpf_ptp_info_to_adapter (info); + +idpf_ptp_update_cached_phctime (adapter); + +return msecs_to_jiffies (500 ); +} +/** * idpf_ptp_set_caps - Set PTP capabilities * @adapter: Driver specific private structure @@ -486,6 +683,7 @@ static void idpf_ptp_set_caps(const struct idpf_adapter *adapter) info->adjtime = idpf_ptp_adjtime; info->verify = idpf_ptp_verify_pin; info->enable = idpf_ptp_gpio_enable; + info->do_aux_work = idpf_ptp_do_aux_work;#if IS_ENABLED (CONFIG_ARM_ARCH_TIMER ) info->getcrosststamp = idpf_ptp_get_crosststamp;@@ -540,6 +738,8 @@ static void idpf_ptp_release_vport_tstamp(struct idpf_vport *vport)if (!idpf_ptp_get_vport_tstamp_capability (vport))return ; +cancel_work_sync (&vport->tstamp_task); +/* Remove list with free latches */ spin_lock (&vport->tx_tstamp_caps->lock_free);@@ -552,16 +752,21 @@ static void idpf_ptp_release_vport_tstamp(struct idpf_vport *vport)spin_unlock (&vport->tx_tstamp_caps->lock_free);/* Remove list with latches in use */ +mutex_lock (&vport->tstamp_stats.tx_hwtstamp_lock);spin_lock (&vport->tx_tstamp_caps->lock_in_use); head = &vport->tx_tstamp_caps->latches_in_use;list_for_each_entry_safe (ptp_tx_tstamp, tmp, head, list_member) { + vport->tstamp_stats.tx_hwtstamp_flushed++;list_del (&ptp_tx_tstamp->list_member);kfree (ptp_tx_tstamp); }spin_unlock (&vport->tx_tstamp_caps->lock_in_use); +mutex_unlock (&vport->tstamp_stats.tx_hwtstamp_lock); +mutex_destroy (&vport->tstamp_stats.tx_hwtstamp_lock); +kfree (vport->tx_tstamp_caps); vport->tx_tstamp_caps =NULL ; }@@ -578,6 +783,27 @@ static void idpf_ptp_release_tstamp(struct idpf_adapter *adapter)idpf_ptp_release_vport_tstamp (vport); } +/** +* idpf_ptp_get_txq_tstamp_capability - Verify the timestamping capability +* for a given tx queue. +* @txq: Transmit queue +* +* Since performing timestamp flows requires reading the device clock value and +* the support in the Control Plane, the function checks both factors and +* summarizes the support for the timestamping. +* +* Return: true if the timestamping is supported, false otherwise. +*/ +bool idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq) +{ +if (!txq || !txq->cached_tstamp_caps) +return false; +else if (txq->cached_tstamp_caps->access) +return true; +else +return false; +} +/** * idpf_ptp_init - Initialize PTP hardware clock support * @adapter: Driver specific private structure @@ -618,6 +844,8 @@ int idpf_ptp_init(struct idpf_adapter *adapter)if (err) goto free_ptp; +ptp_schedule_worker (adapter->ptp->clock,0 ); +/* Write the default increment time value if the clock adjustments * are enabled. */ @@ -641,6 +869,7 @@ int idpf_ptp_init(struct idpf_adapter *adapter)return 0 ; remove_clock: +ptp_cancel_worker_sync (adapter->ptp->clock);ptp_clock_unregister (adapter->ptp->clock); adapter->ptp->clock =NULL ;@@ -662,11 +891,14 @@ void idpf_ptp_release(struct idpf_adapter *adapter)if (!ptp)return ; -if (ptp->tx_tstamp_access !=IDPF_PTP_NONE ) +if (ptp->tx_tstamp_access !=IDPF_PTP_NONE && + ptp->get_dev_clk_time_access !=IDPF_PTP_NONE )idpf_ptp_release_tstamp (adapter); -if (ptp->clock) +if (ptp->clock) { +ptp_cancel_worker_sync (adapter->ptp->clock);ptp_clock_unregister (ptp->clock); + }kfree (ptp); adapter->ptp =NULL ;drivers/net/ethernet/intel/idpf/idpf_ptp.h +52
-0@@ -131,6 +131,7 @@ struct idpf_ptp_tx_tstamp {* @lock_in_use: the lock to the used latches list * @lock_free: the lock to free the latches list * @lock_status: the lock to the status tracker +* @access: indicates an access to Tx timestamp * @latches_free: the list of the free Tx timestamps latches * @latches_in_use: the list of the used Tx timestamps latches * @tx_tstamp_status: Tx tstamp status tracker @@ -142,6 +143,7 @@ struct idpf_ptp_vport_tx_tstamp_caps {spinlock_t lock_in_use;spinlock_t lock_free;spinlock_t lock_status; + bool access:1;struct list_head latches_free;struct list_head latches_in_use;struct idpf_ptp_tx_tstamp_status tx_tstamp_status[];@@ -155,6 +157,8 @@ struct idpf_ptp_vport_tx_tstamp_caps {* @base_incval: base increment value of the PTP clock * @max_adj: maximum adjustment of the PTP clock * @cmd: HW specific command masks +* @cached_phc_time: a cached copy of the PHC time for timestamp extension +* @cached_phc_jiffies: jiffies when cached_phc_time was last updated * @dev_clk_regs: the set of registers to access the device clock * @caps: PTP capabilities negotiated with the Control Plane * @get_dev_clk_time_access: access type for getting the device clock time @@ -172,6 +176,8 @@ struct idpf_ptp {u64 base_incval;u64 max_adj;struct idpf_ptp_cmd cmd; +u64 cached_phc_time; +unsigned long cached_phc_jiffies;struct idpf_ptp_dev_clk_regs dev_clk_regs;u32 caps; enum idpf_ptp_access get_dev_clk_time_access:2;@@ -181,6 +187,7 @@ struct idpf_ptp { enum idpf_ptp_access tx_tstamp_access:2; u8 rsv:6;struct idpf_ptp_secondary_mbx secondary_mbx; + };/** @@ -234,6 +241,7 @@ int idpf_ptp_init(struct idpf_adapter *adapter);void idpf_ptp_release (struct idpf_adapter *adapter);int idpf_ptp_get_caps (struct idpf_adapter *adapter);void idpf_ptp_get_features_access (const struct idpf_adapter *adapter); +bool idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq);int idpf_ptp_get_dev_clk_time (struct idpf_adapter *adapter,struct idpf_ptp_dev_timers *dev_clk_time); int idpf_ptp_get_cross_time(struct idpf_adapter *adapter,@@ -242,6 +250,14 @@ int idpf_ptp_set_dev_clk_time(struct idpf_adapter *adapter, u64 time);int idpf_ptp_adj_dev_clk_fine (struct idpf_adapter *adapter,u64 incval);int idpf_ptp_adj_dev_clk_time (struct idpf_adapter *adapter,s64 delta);int idpf_ptp_get_vport_tstamps_caps (struct idpf_vport *vport); +int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport); +int idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config); +u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u64 in_tstamp); +u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time,u32 in_timestamp); +int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +u32 *idx); +void idpf_tstamp_task (struct work_struct *work);#else /* CONFIG_PTP_1588_CLOCK */ static inline int idpf_ptp_init (struct idpf_adapter *adapter) {@@ -258,6 +274,12 @@ static inline int idpf_ptp_get_caps(struct idpf_adapter *adapter)static inline void idpf_ptp_get_features_access (const struct idpf_adapter *adapter) { } +static inline bool +idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq) +{ +return false; +} +static inline int idpf_ptp_get_dev_clk_time (struct idpf_adapter *adapter,struct idpf_ptp_dev_timers *dev_clk_time)@@ -295,5 +317,35 @@ static inline int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)return -EOPNOTSUPP ; } +static inline int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport) +{ +return -EOPNOTSUPP ; +} + +static inline int +idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config) +{ +return -EOPNOTSUPP ; +} + +static inline u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u32 in_tstamp) +{ +return 0 ; +} + +static inline u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time, +u32 in_timestamp) +{ +return 0 ; +} + +static inline int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q, +struct sk_buff *skb,u32 *idx) +{ +return -EOPNOTSUPP ; +} + +static inline void idpf_tstamp_task (struct work_struct *work) { }#endif /* CONFIG_PTP_1588_CLOCK */ #endif /* _IDPF_PTP_H */ drivers/net/ethernet/intel/idpf/idpf_txrx.c +132
-7@@ -5,6 +5,7 @@#include <net/libeth/tx.h> #include "idpf.h" +#include "idpf_ptp.h" #include "idpf_virtchnl.h" struct idpf_tx_stash {@@ -1107,6 +1108,8 @@ void idpf_vport_queues_rel(struct idpf_vport *vport)*/ static int idpf_vport_init_fast_path_txqs (struct idpf_vport *vport) { +struct idpf_ptp_vport_tx_tstamp_caps *caps = vport->tx_tstamp_caps; +struct work_struct *tstamp_task = &vport->tstamp_task;int i, j, k =0 ; vport->txqs = kcalloc(vport->num_txq, sizeof(*vport->txqs),@@ -1121,6 +1124,12 @@ static int idpf_vport_init_fast_path_txqs(struct idpf_vport *vport)for (j =0 ; j < tx_grp->num_txq; j++, k++) { vport->txqs[k] = tx_grp->txqs[j]; vport->txqs[k]->idx = k; + +if (!caps) +continue ; + + vport->txqs[k]->cached_tstamp_caps = caps; + vport->txqs[k]->tstamp_task = tstamp_task; } }@@ -1654,6 +1663,40 @@ static void idpf_tx_handle_sw_marker(struct idpf_tx_queue *tx_q)wake_up (&vport->sw_marker_wq); } +/** +* idpf_tx_read_tstamp - schedule a work to read Tx timestamp value +* @txq: queue to read the timestamp from +* @skb: socket buffer to provide Tx timestamp value +* +* Schedule a work to read Tx timestamp value generated once the packet is +* transmitted. +*/ +static void idpf_tx_read_tstamp (struct idpf_tx_queue *txq,struct sk_buff *skb) +{ +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct idpf_ptp_tx_tstamp_status *tx_tstamp_status; + + tx_tstamp_caps = txq->cached_tstamp_caps; +spin_lock_bh (&tx_tstamp_caps->lock_status); + +for (u32 i =0 ; i < tx_tstamp_caps->num_entries; i++) { + tx_tstamp_status = &tx_tstamp_caps->tx_tstamp_status[i]; +if (tx_tstamp_status->state !=IDPF_PTP_FREE ) +continue ; + + tx_tstamp_status->skb = skb; + tx_tstamp_status->state =IDPF_PTP_REQUEST ; + +/* Fetch timestamp from completion descriptor through +* virtchnl msg to report to stack. +*/ +queue_work (system_unbound_wq, txq->tstamp_task); +break ; + } + +spin_unlock_bh (&tx_tstamp_caps->lock_status); +} +/** * idpf_tx_clean_stashed_bufs - clean bufs that were stored for * out of order completions @@ -1682,6 +1725,11 @@ static void idpf_tx_clean_stashed_bufs(struct idpf_tx_queue *txq,continue ;hash_del (&stash->hlist); + +if (stash->buf.type ==LIBETH_SQE_SKB && + (skb_shinfo (stash->buf.skb)->tx_flags &SKBTX_IN_PROGRESS )) +idpf_tx_read_tstamp (txq, stash->buf.skb); +libeth_tx_complete (&stash->buf, &cp);/* Push shadow buf back onto stack */ @@ -1876,8 +1924,12 @@ static bool idpf_tx_clean_buf_ring(struct idpf_tx_queue *txq, u16 compl_tag, idpf_tx_buf_compl_tag(tx_buf) != compl_tag))return false; -if (tx_buf->type ==LIBETH_SQE_SKB ) +if (tx_buf->type ==LIBETH_SQE_SKB ) { +if (skb_shinfo (tx_buf->skb)->tx_flags &SKBTX_IN_PROGRESS ) +idpf_tx_read_tstamp (txq, tx_buf->skb); +libeth_tx_complete (tx_buf, &cp); + }idpf_tx_clean_buf_ring_bump_ntc (txq, idx, tx_buf);@@ -2296,7 +2348,7 @@ void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb,* descriptor. Reset that here. */ tx_desc = &txq->flex_tx[idx]; -memset (tx_desc,0 ,sizeof (struct idpf_flex_tx_ctx_desc )); +memset (tx_desc,0 ,sizeof (*tx_desc));if (idx ==0 ) idx = txq->desc_count; idx--;@@ -2699,10 +2751,10 @@ static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs,* Since the TX buffer rings mimics the descriptor ring, update the tx buffer * ring entry to reflect that this index is a context descriptor */ -static struct idpf_flex_tx_ctx_desc * +static union idpf_flex_tx_ctx_desc *idpf_tx_splitq_get_ctx_desc (struct idpf_tx_queue *txq) { -struct idpf_flex_tx_ctx_desc *desc; +union idpf_flex_tx_ctx_desc *desc;int i = txq->next_to_use; txq->tx_buf[i].type =LIBETH_SQE_CTX ;@@ -2732,6 +2784,73 @@ netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb)return NETDEV_TX_OK ; } +#if (IS_ENABLED (CONFIG_PTP_1588_CLOCK )) +/** +* idpf_tx_tstamp - set up context descriptor for hardware timestamp +* @tx_q: queue to send buffer on +* @skb: pointer to the SKB we're sending +* @off: pointer to the offload struct +* +* Return: Positive index number on success, negative otherwise. +*/ +static int idpf_tx_tstamp (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +struct idpf_tx_offload_params *off) +{ +int err, idx; + +/* only timestamp the outbound packet if the user has requested it */ +if (likely (!(skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ))) +return -1 ; + +if (!idpf_ptp_get_txq_tstamp_capability (tx_q)) +return -1 ; + +/* Tx timestamps cannot be sampled when doing TSO */ +if (off->tx_flags &IDPF_TX_FLAGS_TSO ) +return -1 ; + +/* Grab an open timestamp slot */ + err =idpf_ptp_request_ts (tx_q, skb, &idx); +if (err) { +u64_stats_update_begin (&tx_q->stats_sync); +u64_stats_inc (&tx_q->q_stats.tstamp_skipped); +u64_stats_update_end (&tx_q->stats_sync); + +return -1 ; + } + + off->tx_flags |=IDPF_TX_FLAGS_TSYN ; + +return idx; +} + +/** +* idpf_tx_set_tstamp_desc - Set the Tx descriptor fields needed to generate +* PHY Tx timestamp +* @ctx_desc: Context descriptor +* @idx: Index of the Tx timestamp latch +*/ +static void idpf_tx_set_tstamp_desc (union idpf_flex_tx_ctx_desc *ctx_desc, +u32 idx) +{ + ctx_desc->tsyn.qw1 =le64_encode_bits (IDPF_TX_DESC_DTYPE_CTX , +IDPF_TX_CTX_DTYPE_M ) | +le64_encode_bits (IDPF_TX_CTX_DESC_TSYN , +IDPF_TX_CTX_CMD_M ) | +le64_encode_bits (idx,IDPF_TX_CTX_TSYN_REG_M ); +} +#else /* CONFIG_PTP_1588_CLOCK */ +static int idpf_tx_tstamp (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +struct idpf_tx_offload_params *off) +{ +return -1 ; +} + +static void idpf_tx_set_tstamp_desc (union idpf_flex_tx_ctx_desc *ctx_desc, +u32 idx) +{ } +#endif /* CONFIG_PTP_1588_CLOCK */ +/** * idpf_tx_splitq_frame - Sends buffer on Tx ring using flex descriptors * @skb: send buffer @@ -2743,9 +2862,10 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, struct idpf_tx_queue *tx_q) {struct idpf_tx_splitq_params tx_params = { }; +union idpf_flex_tx_ctx_desc *ctx_desc;struct idpf_tx_buf *first;unsigned int count; -int tso; +int tso, idx; count =idpf_tx_desc_count_required (tx_q, skb);if (unlikely (!count))@@ -2765,8 +2885,7 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,if (tso) {/* If tso is needed, set up context desc */ -struct idpf_flex_tx_ctx_desc *ctx_desc = -idpf_tx_splitq_get_ctx_desc (tx_q); + ctx_desc =idpf_tx_splitq_get_ctx_desc (tx_q); ctx_desc->tso.qw1.cmd_dtype = cpu_to_le16(IDPF_TX_DESC_DTYPE_FLEX_TSO_CTX |@@ -2784,6 +2903,12 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,u64_stats_update_end (&tx_q->stats_sync); } + idx =idpf_tx_tstamp (tx_q, skb, &tx_params.offload); +if (idx !=-1 ) { + ctx_desc =idpf_tx_splitq_get_ctx_desc (tx_q); +idpf_tx_set_tstamp_desc (ctx_desc, idx); + } +/* record the location of the first descriptor for this packet */ first = &tx_q->tx_buf[tx_q->next_to_use]; first->skb = skb;drivers/net/ethernet/intel/idpf/idpf_txrx.h +9
-2@@ -142,6 +142,7 @@ do { \#define IDPF_TX_FLAGS_IPV4 BIT(1)#define IDPF_TX_FLAGS_IPV6 BIT(2)#define IDPF_TX_FLAGS_TUNNEL BIT(3) +#define IDPF_TX_FLAGS_TSYN BIT(4)union idpf_tx_flex_desc {struct idpf_flex_tx_desc q;/* queue based scheduling */ @@ -445,6 +446,7 @@ struct idpf_tx_queue_stats {u64_stats_t q_busy;u64_stats_t skb_drops;u64_stats_t dma_map_errs; +u64_stats_t tstamp_skipped; };#define IDPF_ITR_DYNAMIC 1@@ -619,6 +621,8 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64,* @compl_tag_bufid_m: Completion tag buffer id mask * @compl_tag_cur_gen: Used to keep track of current completion tag generation * @compl_tag_gen_max: To determine when compl_tag_cur_gen should be reset +* @cached_tstamp_caps: Tx timestamp capabilities negotiated with the CP +* @tstamp_task: Work that handles Tx timestamp read * @stats_sync: See struct u64_stats_sync * @q_stats: See union idpf_tx_queue_stats * @q_id: Queue id @@ -632,7 +636,7 @@ struct idpf_tx_queue {struct idpf_base_tx_desc *base_tx;struct idpf_base_tx_ctx_desc *base_ctx;union idpf_tx_flex_desc *flex_tx; -struct idpf_flex_tx_ctx_desc *flex_ctx; +union idpf_flex_tx_ctx_desc *flex_ctx;void *desc_ring; };@@ -668,6 +672,9 @@ struct idpf_tx_queue {u16 compl_tag_cur_gen;u16 compl_tag_gen_max; +struct idpf_ptp_vport_tx_tstamp_caps *cached_tstamp_caps; +struct work_struct *tstamp_task; +struct u64_stats_sync stats_sync;struct idpf_tx_queue_stats q_stats;__cacheline_group_end_aligned (read_write);@@ -681,7 +688,7 @@ struct idpf_tx_queue {__cacheline_group_end_aligned (cold); }; libeth_cacheline_set_assert(struct idpf_tx_queue, 64, -88 +sizeof (struct u64_stats_sync ), +112 +sizeof (struct u64_stats_sync ), 24);/** drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +5
-1@@ -3163,8 +3163,12 @@ void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q)return ; err =idpf_ptp_get_vport_tstamps_caps (vport); -if (err) +if (err) {pci_dbg (vport->adapter->pdev,"Tx timestamping not supported\n" ); +return ; + } + +INIT_WORK (&vport->tstamp_task, idpf_tstamp_task); }/** drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +146
-0@@ -382,7 +382,9 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) goto get_tstamp_caps_out; } + tstamp_caps->access = true; tstamp_caps->num_entries = num_latches; +INIT_LIST_HEAD (&tstamp_caps->latches_in_use);INIT_LIST_HEAD (&tstamp_caps->latches_free);@@ -425,6 +427,9 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) vport->tx_tstamp_caps = tstamp_caps;kfree (rcv_tx_tstamp_caps); +/* Init mutex to protect tstamp statistics */ +mutex_init (&vport->tstamp_stats.tx_hwtstamp_lock); +return 0 ; err_free_ptp_tx_stamp_list:@@ -440,3 +445,233 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)return err; } + +/** +* idpf_ptp_update_tstamp_tracker - Update the Tx timestamp tracker based on +* the skb compatibility. +* @caps: Tx timestamp capabilities that monitor the latch status +* @skb: skb for which the tstamp value is returned through virtchnl message +* @current_state: Current state of the Tx timestamp latch +* @expected_state: Expected state of the Tx timestamp latch +* +* Find a proper skb tracker for which the Tx timestamp is received and change +* the state to expected value. +* +* Return: true if the tracker has been found and updated, false otherwise. +*/ +static bool +idpf_ptp_update_tstamp_tracker (struct idpf_ptp_vport_tx_tstamp_caps *caps, +struct sk_buff *skb, +enum idpf_ptp_tx_tstamp_state current_state, +enum idpf_ptp_tx_tstamp_state expected_state) +{ +bool updated = false; + +spin_lock (&caps->lock_status); +for (u16 i =0 ; i < caps->num_entries; i++) { +struct idpf_ptp_tx_tstamp_status *status; + + status = &caps->tx_tstamp_status[i]; + +if (skb == status->skb && status->state == current_state) { + status->state = expected_state; + updated = true; +break ; + } + } +spin_unlock (&caps->lock_status); + +return updated; +} + +/** +* idpf_ptp_get_tstamp_value - Get the Tx timestamp value and provide it +* back to the skb. +* @vport: Virtual port structure +* @tstamp_latch: Tx timestamp latch structure fulfilled by the Control Plane +* @ptp_tx_tstamp: Tx timestamp latch to add to the free list +* +* Read the value of the Tx timestamp for a given latch received from the +* Control Plane, extend it to 64 bit and provide back to the skb. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +idpf_ptp_get_tstamp_value (struct idpf_vport *vport, +struct virtchnl2_ptp_tx_tstamp_latch *tstamp_latch, +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp) +{ +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct skb_shared_hwtstamps shhwtstamps; +bool state_upd = false; +u8 tstamp_ns_lo_bit; +u64 tstamp; + + tx_tstamp_caps = vport->tx_tstamp_caps; + tstamp_ns_lo_bit = tx_tstamp_caps->tstamp_ns_lo_bit; + + ptp_tx_tstamp->tstamp =le64_to_cpu (tstamp_latch->tstamp); + ptp_tx_tstamp->tstamp >>= tstamp_ns_lo_bit; + + state_upd =idpf_ptp_update_tstamp_tracker (tx_tstamp_caps, + ptp_tx_tstamp->skb, +IDPF_PTP_READ_VALUE , +IDPF_PTP_FREE ); +if (!state_upd) +return -EINVAL ; + + tstamp =idpf_ptp_extend_ts (vport, ptp_tx_tstamp->tstamp); + shhwtstamps.hwtstamp =ns_to_ktime (tstamp); +skb_tstamp_tx (ptp_tx_tstamp->skb, &shhwtstamps); +consume_skb (ptp_tx_tstamp->skb); + +spin_lock (&tx_tstamp_caps->lock_free); +list_add (&ptp_tx_tstamp->list_member, + &tx_tstamp_caps->latches_free); +spin_unlock (&tx_tstamp_caps->lock_free); + +return 0 ; +} + +/** +* idpf_ptp_get_tx_tstamp_async_handler - Async callback for getting Tx tstamps +* @adapter: Driver specific private structure +* @xn: transaction for message +* @ctlq_msg: received message +* +* Read the tstamps Tx tstamp values from a received message and put them +* directly to the skb. The number of timestamps to read is specified by +* the virtchnl message. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +idpf_ptp_get_tx_tstamp_async_handler (struct idpf_adapter *adapter, +struct idpf_vc_xn *xn, +const struct idpf_ctlq_msg *ctlq_msg) +{ +struct virtchnl2_ptp_get_vport_tx_tstamp_latches *recv_tx_tstamp_msg; +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct virtchnl2_ptp_tx_tstamp_latch tstamp_latch; +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +struct idpf_vport *tstamp_vport =NULL ; +struct list_head *head; +u16 num_latches; +u32 vport_id; +int err; + + recv_tx_tstamp_msg = ctlq_msg->ctx.indirect.payload->va; + vport_id =le32_to_cpu (recv_tx_tstamp_msg->vport_id); + +idpf_for_each_vport (adapter, vport) { +if (!vport) +continue ; + +if (vport->vport_id == vport_id) { + tstamp_vport = vport; +break ; + } + } + +if (!tstamp_vport || !tstamp_vport->tx_tstamp_caps) +return -EINVAL ; + + tx_tstamp_caps = tstamp_vport->tx_tstamp_caps; + num_latches =le16_to_cpu (recv_tx_tstamp_msg->num_latches); + + head = &tx_tstamp_caps->latches_in_use; +spin_lock (&tx_tstamp_caps->lock_in_use); + +for (u16 i =0 ; i < num_latches; i++) { + tstamp_latch = recv_tx_tstamp_msg->tstamp_latches[i]; + +if (!tstamp_latch.valid)
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) · line 598
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +10
-0+continue ; + +if (list_empty (head)) { + err = -ENOBUFS ; + goto unlock; + } + +list_for_each_entry (ptp_tx_tstamp, head, list_member) { +if (tstamp_latch.index == ptp_tx_tstamp->idx) { +list_del (&ptp_tx_tstamp->list_member);
need list_for_each_entry_safe when calling list_del on members.
Quoted 82 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +79
-0+ err =idpf_ptp_get_tstamp_value (tstamp_vport, + &tstamp_latch, + ptp_tx_tstamp); +if (err) + goto unlock; + +break ; + } + } + } + +unlock: +spin_unlock (&tx_tstamp_caps->lock_in_use); + +return err; +} + +/** +* idpf_ptp_get_tx_tstamp - Send virtchnl get Tx timestamp latches message +* @vport: Virtual port structure +* +* Send virtchnl get Tx tstamp message to read the value of the HW timestamp. +* The message contains a list of indexes set in the Tx descriptors. +* +* Return: 0 on success, -errno otherwise. +*/ +int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport) +{ +struct virtchnl2_ptp_get_vport_tx_tstamp_latches *send_tx_tstamp_msg; +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct idpf_vc_xn_params xn_params = { + .vc_op =VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP , + .timeout_ms =IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC , + .async = true, + .async_handler = idpf_ptp_get_tx_tstamp_async_handler, + }; +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +int reply_sz, size, msg_size; +struct list_head *head; +bool state_upd; +u16 id =0 ; + + tx_tstamp_caps = vport->tx_tstamp_caps; + head = &tx_tstamp_caps->latches_in_use; + + size =struct_size (send_tx_tstamp_msg, tstamp_latches, + tx_tstamp_caps->num_entries); + send_tx_tstamp_msg =kzalloc (size,GFP_KERNEL ); +if (!send_tx_tstamp_msg) +return -ENOMEM ; + +spin_lock (&tx_tstamp_caps->lock_in_use); +list_for_each_entry (ptp_tx_tstamp, head, list_member) { +u8 idx; + + state_upd =idpf_ptp_update_tstamp_tracker (tx_tstamp_caps, + ptp_tx_tstamp->skb, +IDPF_PTP_REQUEST , +IDPF_PTP_READ_VALUE ); +if (!state_upd) +continue ; + + idx = ptp_tx_tstamp->idx; + send_tx_tstamp_msg->tstamp_latches[id].index = idx; + id++; + } +spin_unlock (&tx_tstamp_caps->lock_in_use); + + msg_size =struct_size (send_tx_tstamp_msg, tstamp_latches, id); + send_tx_tstamp_msg->vport_id =cpu_to_le32 (vport->vport_id); + send_tx_tstamp_msg->num_latches =cpu_to_le16 (id); + xn_params.send_buf.iov_base = send_tx_tstamp_msg; + xn_params.send_buf.iov_len = msg_size; + + reply_sz =idpf_vc_xn_exec (vport->adapter, &xn_params); +kfree (send_tx_tstamp_msg); + +return min (reply_sz,0 ); +}Signature · 1 line
2.31.1
RE: [PATCH v3 iwl-next 08/10] idpf: add Tx timestamp flows
Quoted 32 lines · On 01/07/2025 3:55PM Willem de Bruijn wrote:
Quoted 31 lines
Add functions to request Tx timestamp for the PTP packets, read the Tx timestamp when the completion tag for that packet is being received, extend the Tx timestamp value and set the supported timestamping modes.
Tx timestamp is requested for the PTP packets by setting a TSYN bit and index value in the Tx context descriptor. The driver assumption is that the Tx timestamp value is ready to be read when the completion tag is received. Then the driver schedules delayed work and the Tx timestamp value read is requested through virtchnl message. At the end, the Tx timestamp value is extended to 64-bit and provided back to the skb.
Co-developed-by Josh Hay <[email protected]>Signed-off-by Josh Hay <[email protected]>Signed-off-by Milena Olech <[email protected]>---
v2 -> v3: changeget_timestamp_filterfunction name, split stats into vport-based and tx queue-based
v1 -> v2: add timestamping stats, use ndo_hwtamp_get/ndo_hwstamp_setdrivers/net/ethernet/intel/idpf/idpf.h | 20 ++ .../net/ethernet/intel/idpf/idpf_ethtool.c | 69 ++++- .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 13 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 47 ++++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 236 +++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_ptp.h | 52 ++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 139 ++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 11 +- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 6 +- .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 235 +++++++++++++++++ 10 files changed, 814 insertions(+), 14 deletions(-)
Quoted 16 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c static int idpf_get_link_ksettings(struct net_device *netdev, · line 1339
Quoted 13 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +13
-0+/** +* idpf_get_timestamp_filters - Get the supported timestamping mode +* @vport: Virtual port structure +* @info: ethtool timestamping info structure +* +* Get the Tx/Rx timestamp filters. +*/ +static void idpf_get_timestamp_filters (const struct idpf_vport *vport, +struct kernel_ethtool_ts_info *info) +{ +if (!vport->tx_tstamp_caps || + vport->adapter->ptp->tx_tstamp_access ==IDPF_PTP_NONE ) +return ;Is making
SOF_TIMESTAMPING_RX_HARDWAREandSOF_TIMESTAMPING_RAW_HARDWAREconditional ontx_tstamp_accessintentional?
Hmmm, good catch.
I guess I will change the SOF_TIMESTAMPING_RX_HARDWARE to be not conditional.
About the SOF_TIMESTAMPING_RAW_HARDWARE - it should rely on the tx_statmp_access.
Quoted 18 lines
Quoted 18 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +17
-0+ + info->so_timestamping =SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + info->tx_types =BIT (HWTSTAMP_TX_OFF ) |BIT (HWTSTAMP_TX_ON ); +} + + +static int idpf_hwtstamp_get (struct net_device *netdev, +struct kernel_hwtstamp_config *config) +{ +struct idpf_adapter *adapter =idpf_netdev_to_adapter (netdev); +struct idpf_vport *vport; + +idpf_vport_cfg_lock (adapter);
Quoted 9 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c void idpf_free_dma_mem(struct idpf_hw *hw, struct idpf_dma_mem *mem) · line 2388
Quoted 5 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +5
-0+ vport =idpf_netdev_to_vport (netdev); + +if (!idpf_ptp_get_vport_tstamp_capability (vport)) { +idpf_vport_cfg_unlock (adapter); +return -EOPNOTSUPP ;Should this return an empty config and return 0, rather than return error?
I'd prefer to return NOTSUPP, as the feature itself relies on the CP policy.
Quoted 108 lines
Quoted 108 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +11
-0+ } + + *config = vport->tstamp_config; + +idpf_vport_cfg_unlock (adapter); + +return 0 ; +} +static const struct net_device_ops idpf_netdev_ops = { .ndo_open = idpf_open, .ndo_stop = idpf_stop,@@ -2383,4 +2428,6 @@ static const struct net_device_ops idpf_netdev_ops = { .ndo_get_stats64 = idpf_get_stats64, .ndo_set_features = idpf_set_features, .ndo_tx_timeout = idpf_tx_timeout, + .ndo_hwtstamp_get = idpf_hwtstamp_get, + .ndo_hwtstamp_set = idpf_hwtstamp_set, };drivers/net/ethernet/intel/idpf/idpf_ptp.c +60
-0@@ -317,6 +317,37 @@ static int idpf_ptp_gettimex64(struct ptp_clock_info *info,return 0 ; } +/** +* idpf_ptp_update_cached_phctime - Update the cached PHC time values +* @adapter: Driver specific private structure +* +* This function updates the system time values which are cached in the adapter +* structure. +* +* This function must be called periodically to ensure that the cached value +* is never more than 2 seconds old. +* +* Return 0 on success, negative otherwise. +*/ +static int idpf_ptp_update_cached_phctime (struct idpf_adapter *adapter) +{ +u64 systime; +int err; + + err =idpf_ptp_read_src_clk_reg (adapter, &systime,NULL ); +if (err) +return -EACCES ; + +/* Update the cached PHC time stored in the adapter structure. +* These values are used to extend Tx timestamp values to 64 bit +* expected by the stack. +*/ +WRITE_ONCE (adapter->ptp->cached_phc_time, systime); +WRITE_ONCE (adapter->ptp->cached_phc_jiffies, jiffies); + +return 0 ; +} +/** * idpf_ptp_settime64 - Set the time of the clock * @info: the driver's PTP info structure @@ -347,6 +378,11 @@ static int idpf_ptp_settime64(struct ptp_clock_info *info,return err; } + err =idpf_ptp_update_cached_phctime (adapter); +if (err) +pci_warn (adapter->pdev, +"Unable to immediately update cached PHC time\n" ); +return 0 ; }@@ -402,6 +438,11 @@ static int idpf_ptp_adjtime(struct ptp_clock_info *info, s64 delta)return err; } + err =idpf_ptp_update_cached_phctime (adapter); +if (err) +pci_warn (adapter->pdev, +"Unable to immediately update cached PHC time\n" ); +return 0 ; }@@ -465,6 +506,162 @@ static int idpf_ptp_gpio_enable(struct ptp_clock_info *info,return -EOPNOTSUPP ; } +/** +* idpf_ptp_tstamp_extend_32b_to_64b - Convert a 32b nanoseconds Tx timestamp +* to 64b. +* @cached_phc_time: recently cached copy of PHC time +* @in_timestamp: Ingress/egress 32b nanoseconds timestamp value +* +* Hardware captures timestamps which contain only 32 bits of nominal +* nanoseconds, as opposed to the 64bit timestamps that the stack expects. +* +* Return: Tx timestamp value extended to 64 bits based on cached PHC time. +*/ +u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time,u32 in_timestamp) +{ +u32 delta, phc_lo; +u64 ns; + + phc_lo =lower_32_bits (cached_phc_time); + delta = in_timestamp - phc_lo; +
Quoted 8 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c static int idpf_ptp_gpio_enable(struct ptp_clock_info *info, · line 533
Quoted 6 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +6
-0+if (delta >S32_MAX ) { + delta = phc_lo - in_timestamp; + ns = cached_phc_time - delta; + }else { + ns = cached_phc_time + delta; + }If using s64 delta and ns, no need for branch?
To make it more readable, I'll change the condition in v4. I'll check if the phc_lo is greater than in_stamp.
If phc_lo is bigger, then tx tstamp value was captured before caching PHC time and case 1 will be applicable.
Quoted 58 lines
Quoted 58 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +57
-0+ +return ns; +} + +/** +* idpf_ptp_extend_ts - Convert a 40b timestamp to 64b nanoseconds +* @vport: Virtual port structure +* @in_tstamp: Ingress/egress timestamp value +* +* It is assumed that the caller verifies the timestamp is valid prior to +* calling this function. +* +* Extract the 32bit nominal nanoseconds and extend them. Use the cached PHC +* time stored in the device private PTP structure as the basis for timestamp +* extension. +* +* Return: Tx timestamp value extended to 64 bits. +*/ +u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u64 in_tstamp) +{ +struct idpf_ptp *ptp = vport->adapter->ptp; +unsigned long discard_time; + + discard_time = ptp->cached_phc_jiffies +2 *HZ ; + +if (time_is_before_jiffies (discard_time)) { +mutex_lock (&vport->tstamp_stats.tx_hwtstamp_lock); + vport->tstamp_stats.tx_hwtstamp_discarded++; +mutex_unlock (&vport->tstamp_stats.tx_hwtstamp_lock); + +return 0 ; + } + +return idpf_ptp_tstamp_extend_32b_to_64b (ptp->cached_phc_time, +lower_32_bits (in_tstamp)); +} + +/** +* idpf_ptp_request_ts - Request an available Tx timestamp index +* @tx_q: Transmit queue on which the Tx timestamp is requested +* @skb: The SKB to associate with this timestamp request +* @idx: Index of the Tx timestamp latch +* +* Request tx timestamp index negotiated during PTP init that will be set into +* Tx descriptor. +* +* Return: 0 and the index that can be provided to Tx descriptor on success, +* -errno otherwise. +*/ +int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +u32 *idx) +{ +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +struct list_head *head; + + head = &tx_q->cached_tstamp_caps->latches_free; +if (list_empty (head))
Quoted 8 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c static int idpf_ptp_gpio_enable(struct ptp_clock_info *info, · line 596
Quoted 6 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +6
-0+return -ENOBUFS ; + +/* Get the index from the free latches list */ +spin_lock_bh (&tx_q->cached_tstamp_caps->lock_free); + ptp_tx_tstamp = list_first_entry(head, struct idpf_ptp_tx_tstamp, + list_member);Racy, as
list_emptyis tested before taking the spin lock?
You're correct, I'll change it.
Quoted 862 lines
Quoted 767 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +105
-2+list_del (&ptp_tx_tstamp->list_member); +spin_unlock_bh (&tx_q->cached_tstamp_caps->lock_free); + + ptp_tx_tstamp->skb =skb_get (skb); +skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; + +/* Move the element to the used latches list */ +spin_lock_bh (&tx_q->cached_tstamp_caps->lock_in_use); +list_add (&ptp_tx_tstamp->list_member, + &tx_q->cached_tstamp_caps->latches_in_use); +spin_unlock_bh (&tx_q->cached_tstamp_caps->lock_in_use); + + *idx = ptp_tx_tstamp->idx; + +return 0 ; +} + +/** +* idpf_ptp_set_timestamp_mode - Setup driver for requested timestamp mode +* @vport: Virtual port structure +* @config: Hwtstamp settings requested or saved +* +* Return: 0 on success, -errno otherwise. +*/ +int idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config) +{ +switch (config->tx_type) { +case HWTSTAMP_TX_OFF : +case HWTSTAMP_TX_ON : +break ; +default : +return -EINVAL ; + } + + vport->tstamp_config.tx_type = config->tx_type; + +return 0 ; +} + +/** +* idpf_tstamp_task - Delayed task to handle Tx tstamps +* @work: work_struct handle +*/ +void idpf_tstamp_task (struct work_struct *work) +{ +struct idpf_vport *vport; + + vport = container_of(work, struct idpf_vport, tstamp_task); + +idpf_ptp_get_tx_tstamp (vport); +} + +/** +* idpf_ptp_do_aux_work - Do PTP periodic work +* @info: Driver's PTP info structure +* +* Return: Number of jiffies to periodic work. +*/ +static long idpf_ptp_do_aux_work (struct ptp_clock_info *info) +{ +struct idpf_adapter *adapter =idpf_ptp_info_to_adapter (info); + +idpf_ptp_update_cached_phctime (adapter); + +return msecs_to_jiffies (500 ); +} +/** * idpf_ptp_set_caps - Set PTP capabilities * @adapter: Driver specific private structure @@ -486,6 +683,7 @@ static void idpf_ptp_set_caps(const struct idpf_adapter *adapter) info->adjtime = idpf_ptp_adjtime; info->verify = idpf_ptp_verify_pin; info->enable = idpf_ptp_gpio_enable; + info->do_aux_work = idpf_ptp_do_aux_work;#if IS_ENABLED (CONFIG_ARM_ARCH_TIMER ) info->getcrosststamp = idpf_ptp_get_crosststamp;@@ -540,6 +738,8 @@ static void idpf_ptp_release_vport_tstamp(struct idpf_vport *vport)if (!idpf_ptp_get_vport_tstamp_capability (vport))return ; +cancel_work_sync (&vport->tstamp_task); +/* Remove list with free latches */ spin_lock (&vport->tx_tstamp_caps->lock_free);@@ -552,16 +752,21 @@ static void idpf_ptp_release_vport_tstamp(struct idpf_vport *vport)spin_unlock (&vport->tx_tstamp_caps->lock_free);/* Remove list with latches in use */ +mutex_lock (&vport->tstamp_stats.tx_hwtstamp_lock);spin_lock (&vport->tx_tstamp_caps->lock_in_use); head = &vport->tx_tstamp_caps->latches_in_use;list_for_each_entry_safe (ptp_tx_tstamp, tmp, head, list_member) { + vport->tstamp_stats.tx_hwtstamp_flushed++;list_del (&ptp_tx_tstamp->list_member);kfree (ptp_tx_tstamp); }spin_unlock (&vport->tx_tstamp_caps->lock_in_use); +mutex_unlock (&vport->tstamp_stats.tx_hwtstamp_lock); +mutex_destroy (&vport->tstamp_stats.tx_hwtstamp_lock); +kfree (vport->tx_tstamp_caps); vport->tx_tstamp_caps =NULL ; }@@ -578,6 +783,27 @@ static void idpf_ptp_release_tstamp(struct idpf_adapter *adapter)idpf_ptp_release_vport_tstamp (vport); } +/** +* idpf_ptp_get_txq_tstamp_capability - Verify the timestamping capability +* for a given tx queue. +* @txq: Transmit queue +* +* Since performing timestamp flows requires reading the device clock value and +* the support in the Control Plane, the function checks both factors and +* summarizes the support for the timestamping. +* +* Return: true if the timestamping is supported, false otherwise. +*/ +bool idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq) +{ +if (!txq || !txq->cached_tstamp_caps) +return false; +else if (txq->cached_tstamp_caps->access) +return true; +else +return false; +} +/** * idpf_ptp_init - Initialize PTP hardware clock support * @adapter: Driver specific private structure @@ -618,6 +844,8 @@ int idpf_ptp_init(struct idpf_adapter *adapter)if (err) goto free_ptp; +ptp_schedule_worker (adapter->ptp->clock,0 ); +/* Write the default increment time value if the clock adjustments * are enabled. */ @@ -641,6 +869,7 @@ int idpf_ptp_init(struct idpf_adapter *adapter)return 0 ; remove_clock: +ptp_cancel_worker_sync (adapter->ptp->clock);ptp_clock_unregister (adapter->ptp->clock); adapter->ptp->clock =NULL ;@@ -662,11 +891,14 @@ void idpf_ptp_release(struct idpf_adapter *adapter)if (!ptp)return ; -if (ptp->tx_tstamp_access !=IDPF_PTP_NONE ) +if (ptp->tx_tstamp_access !=IDPF_PTP_NONE && + ptp->get_dev_clk_time_access !=IDPF_PTP_NONE )idpf_ptp_release_tstamp (adapter); -if (ptp->clock) +if (ptp->clock) { +ptp_cancel_worker_sync (adapter->ptp->clock);ptp_clock_unregister (ptp->clock); + }kfree (ptp); adapter->ptp =NULL ;drivers/net/ethernet/intel/idpf/idpf_ptp.h +52
-0@@ -131,6 +131,7 @@ struct idpf_ptp_tx_tstamp {* @lock_in_use: the lock to the used latches list * @lock_free: the lock to free the latches list * @lock_status: the lock to the status tracker +* @access: indicates an access to Tx timestamp * @latches_free: the list of the free Tx timestamps latches * @latches_in_use: the list of the used Tx timestamps latches * @tx_tstamp_status: Tx tstamp status tracker @@ -142,6 +143,7 @@ struct idpf_ptp_vport_tx_tstamp_caps {spinlock_t lock_in_use;spinlock_t lock_free;spinlock_t lock_status; + bool access:1;struct list_head latches_free;struct list_head latches_in_use;struct idpf_ptp_tx_tstamp_status tx_tstamp_status[];@@ -155,6 +157,8 @@ struct idpf_ptp_vport_tx_tstamp_caps {* @base_incval: base increment value of the PTP clock * @max_adj: maximum adjustment of the PTP clock * @cmd: HW specific command masks +* @cached_phc_time: a cached copy of the PHC time for timestamp extension +* @cached_phc_jiffies: jiffies when cached_phc_time was last updated * @dev_clk_regs: the set of registers to access the device clock * @caps: PTP capabilities negotiated with the Control Plane * @get_dev_clk_time_access: access type for getting the device clock time @@ -172,6 +176,8 @@ struct idpf_ptp {u64 base_incval;u64 max_adj;struct idpf_ptp_cmd cmd; +u64 cached_phc_time; +unsigned long cached_phc_jiffies;struct idpf_ptp_dev_clk_regs dev_clk_regs;u32 caps; enum idpf_ptp_access get_dev_clk_time_access:2;@@ -181,6 +187,7 @@ struct idpf_ptp { enum idpf_ptp_access tx_tstamp_access:2; u8 rsv:6;struct idpf_ptp_secondary_mbx secondary_mbx; + };/** @@ -234,6 +241,7 @@ int idpf_ptp_init(struct idpf_adapter *adapter);void idpf_ptp_release (struct idpf_adapter *adapter);int idpf_ptp_get_caps (struct idpf_adapter *adapter);void idpf_ptp_get_features_access (const struct idpf_adapter *adapter); +bool idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq);int idpf_ptp_get_dev_clk_time (struct idpf_adapter *adapter,struct idpf_ptp_dev_timers *dev_clk_time); int idpf_ptp_get_cross_time(struct idpf_adapter *adapter,@@ -242,6 +250,14 @@ int idpf_ptp_set_dev_clk_time(struct idpf_adapter *adapter, u64 time);int idpf_ptp_adj_dev_clk_fine (struct idpf_adapter *adapter,u64 incval);int idpf_ptp_adj_dev_clk_time (struct idpf_adapter *adapter,s64 delta);int idpf_ptp_get_vport_tstamps_caps (struct idpf_vport *vport); +int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport); +int idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config); +u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u64 in_tstamp); +u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time,u32 in_timestamp); +int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +u32 *idx); +void idpf_tstamp_task (struct work_struct *work);#else /* CONFIG_PTP_1588_CLOCK */ static inline int idpf_ptp_init (struct idpf_adapter *adapter) {@@ -258,6 +274,12 @@ static inline int idpf_ptp_get_caps(struct idpf_adapter *adapter)static inline void idpf_ptp_get_features_access (const struct idpf_adapter *adapter) { } +static inline bool +idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq) +{ +return false; +} +static inline int idpf_ptp_get_dev_clk_time (struct idpf_adapter *adapter,struct idpf_ptp_dev_timers *dev_clk_time)@@ -295,5 +317,35 @@ static inline int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)return -EOPNOTSUPP ; } +static inline int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport) +{ +return -EOPNOTSUPP ; +} + +static inline int +idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config) +{ +return -EOPNOTSUPP ; +} + +static inline u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u32 in_tstamp) +{ +return 0 ; +} + +static inline u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time, +u32 in_timestamp) +{ +return 0 ; +} + +static inline int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q, +struct sk_buff *skb,u32 *idx) +{ +return -EOPNOTSUPP ; +} + +static inline void idpf_tstamp_task (struct work_struct *work) { }#endif /* CONFIG_PTP_1588_CLOCK */ #endif /* _IDPF_PTP_H */ drivers/net/ethernet/intel/idpf/idpf_txrx.c +132
-7@@ -5,6 +5,7 @@#include <net/libeth/tx.h> #include "idpf.h" +#include "idpf_ptp.h" #include "idpf_virtchnl.h" struct idpf_tx_stash {@@ -1107,6 +1108,8 @@ void idpf_vport_queues_rel(struct idpf_vport *vport)*/ static int idpf_vport_init_fast_path_txqs (struct idpf_vport *vport) { +struct idpf_ptp_vport_tx_tstamp_caps *caps = vport->tx_tstamp_caps; +struct work_struct *tstamp_task = &vport->tstamp_task;int i, j, k =0 ; vport->txqs = kcalloc(vport->num_txq, sizeof(*vport->txqs),@@ -1121,6 +1124,12 @@ static int idpf_vport_init_fast_path_txqs(struct idpf_vport *vport)for (j =0 ; j < tx_grp->num_txq; j++, k++) { vport->txqs[k] = tx_grp->txqs[j]; vport->txqs[k]->idx = k; + +if (!caps) +continue ; + + vport->txqs[k]->cached_tstamp_caps = caps; + vport->txqs[k]->tstamp_task = tstamp_task; } }@@ -1654,6 +1663,40 @@ static void idpf_tx_handle_sw_marker(struct idpf_tx_queue *tx_q)wake_up (&vport->sw_marker_wq); } +/** +* idpf_tx_read_tstamp - schedule a work to read Tx timestamp value +* @txq: queue to read the timestamp from +* @skb: socket buffer to provide Tx timestamp value +* +* Schedule a work to read Tx timestamp value generated once the packet is +* transmitted. +*/ +static void idpf_tx_read_tstamp (struct idpf_tx_queue *txq,struct sk_buff *skb) +{ +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct idpf_ptp_tx_tstamp_status *tx_tstamp_status; + + tx_tstamp_caps = txq->cached_tstamp_caps; +spin_lock_bh (&tx_tstamp_caps->lock_status); + +for (u32 i =0 ; i < tx_tstamp_caps->num_entries; i++) { + tx_tstamp_status = &tx_tstamp_caps->tx_tstamp_status[i]; +if (tx_tstamp_status->state !=IDPF_PTP_FREE ) +continue ; + + tx_tstamp_status->skb = skb; + tx_tstamp_status->state =IDPF_PTP_REQUEST ; + +/* Fetch timestamp from completion descriptor through +* virtchnl msg to report to stack. +*/ +queue_work (system_unbound_wq, txq->tstamp_task); +break ; + } + +spin_unlock_bh (&tx_tstamp_caps->lock_status); +} +/** * idpf_tx_clean_stashed_bufs - clean bufs that were stored for * out of order completions @@ -1682,6 +1725,11 @@ static void idpf_tx_clean_stashed_bufs(struct idpf_tx_queue *txq,continue ;hash_del (&stash->hlist); + +if (stash->buf.type ==LIBETH_SQE_SKB && + (skb_shinfo (stash->buf.skb)->tx_flags &SKBTX_IN_PROGRESS )) +idpf_tx_read_tstamp (txq, stash->buf.skb); +libeth_tx_complete (&stash->buf, &cp);/* Push shadow buf back onto stack */ @@ -1876,8 +1924,12 @@ static bool idpf_tx_clean_buf_ring(struct idpf_tx_queue *txq, u16 compl_tag, idpf_tx_buf_compl_tag(tx_buf) != compl_tag))return false; -if (tx_buf->type ==LIBETH_SQE_SKB ) +if (tx_buf->type ==LIBETH_SQE_SKB ) { +if (skb_shinfo (tx_buf->skb)->tx_flags &SKBTX_IN_PROGRESS ) +idpf_tx_read_tstamp (txq, tx_buf->skb); +libeth_tx_complete (tx_buf, &cp); + }idpf_tx_clean_buf_ring_bump_ntc (txq, idx, tx_buf);@@ -2296,7 +2348,7 @@ void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb,* descriptor. Reset that here. */ tx_desc = &txq->flex_tx[idx]; -memset (tx_desc,0 ,sizeof (struct idpf_flex_tx_ctx_desc )); +memset (tx_desc,0 ,sizeof (*tx_desc));if (idx ==0 ) idx = txq->desc_count; idx--;@@ -2699,10 +2751,10 @@ static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs,* Since the TX buffer rings mimics the descriptor ring, update the tx buffer * ring entry to reflect that this index is a context descriptor */ -static struct idpf_flex_tx_ctx_desc * +static union idpf_flex_tx_ctx_desc *idpf_tx_splitq_get_ctx_desc (struct idpf_tx_queue *txq) { -struct idpf_flex_tx_ctx_desc *desc; +union idpf_flex_tx_ctx_desc *desc;int i = txq->next_to_use; txq->tx_buf[i].type =LIBETH_SQE_CTX ;@@ -2732,6 +2784,73 @@ netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb)return NETDEV_TX_OK ; } +#if (IS_ENABLED (CONFIG_PTP_1588_CLOCK )) +/** +* idpf_tx_tstamp - set up context descriptor for hardware timestamp +* @tx_q: queue to send buffer on +* @skb: pointer to the SKB we're sending +* @off: pointer to the offload struct +* +* Return: Positive index number on success, negative otherwise. +*/ +static int idpf_tx_tstamp (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +struct idpf_tx_offload_params *off) +{ +int err, idx; + +/* only timestamp the outbound packet if the user has requested it */ +if (likely (!(skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ))) +return -1 ; + +if (!idpf_ptp_get_txq_tstamp_capability (tx_q)) +return -1 ; + +/* Tx timestamps cannot be sampled when doing TSO */ +if (off->tx_flags &IDPF_TX_FLAGS_TSO ) +return -1 ; + +/* Grab an open timestamp slot */ + err =idpf_ptp_request_ts (tx_q, skb, &idx); +if (err) { +u64_stats_update_begin (&tx_q->stats_sync); +u64_stats_inc (&tx_q->q_stats.tstamp_skipped); +u64_stats_update_end (&tx_q->stats_sync); + +return -1 ; + } + + off->tx_flags |=IDPF_TX_FLAGS_TSYN ; + +return idx; +} + +/** +* idpf_tx_set_tstamp_desc - Set the Tx descriptor fields needed to generate +* PHY Tx timestamp +* @ctx_desc: Context descriptor +* @idx: Index of the Tx timestamp latch +*/ +static void idpf_tx_set_tstamp_desc (union idpf_flex_tx_ctx_desc *ctx_desc, +u32 idx) +{ + ctx_desc->tsyn.qw1 =le64_encode_bits (IDPF_TX_DESC_DTYPE_CTX , +IDPF_TX_CTX_DTYPE_M ) | +le64_encode_bits (IDPF_TX_CTX_DESC_TSYN , +IDPF_TX_CTX_CMD_M ) | +le64_encode_bits (idx,IDPF_TX_CTX_TSYN_REG_M ); +} +#else /* CONFIG_PTP_1588_CLOCK */ +static int idpf_tx_tstamp (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +struct idpf_tx_offload_params *off) +{ +return -1 ; +} + +static void idpf_tx_set_tstamp_desc (union idpf_flex_tx_ctx_desc *ctx_desc, +u32 idx) +{ } +#endif /* CONFIG_PTP_1588_CLOCK */ +/** * idpf_tx_splitq_frame - Sends buffer on Tx ring using flex descriptors * @skb: send buffer @@ -2743,9 +2862,10 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, struct idpf_tx_queue *tx_q) {struct idpf_tx_splitq_params tx_params = { }; +union idpf_flex_tx_ctx_desc *ctx_desc;struct idpf_tx_buf *first;unsigned int count; -int tso; +int tso, idx; count =idpf_tx_desc_count_required (tx_q, skb);if (unlikely (!count))@@ -2765,8 +2885,7 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,if (tso) {/* If tso is needed, set up context desc */ -struct idpf_flex_tx_ctx_desc *ctx_desc = -idpf_tx_splitq_get_ctx_desc (tx_q); + ctx_desc =idpf_tx_splitq_get_ctx_desc (tx_q); ctx_desc->tso.qw1.cmd_dtype = cpu_to_le16(IDPF_TX_DESC_DTYPE_FLEX_TSO_CTX |@@ -2784,6 +2903,12 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,u64_stats_update_end (&tx_q->stats_sync); } + idx =idpf_tx_tstamp (tx_q, skb, &tx_params.offload); +if (idx !=-1 ) { + ctx_desc =idpf_tx_splitq_get_ctx_desc (tx_q); +idpf_tx_set_tstamp_desc (ctx_desc, idx); + } +/* record the location of the first descriptor for this packet */ first = &tx_q->tx_buf[tx_q->next_to_use]; first->skb = skb;drivers/net/ethernet/intel/idpf/idpf_txrx.h +9
-2@@ -142,6 +142,7 @@ do { \#define IDPF_TX_FLAGS_IPV4 BIT(1)#define IDPF_TX_FLAGS_IPV6 BIT(2)#define IDPF_TX_FLAGS_TUNNEL BIT(3) +#define IDPF_TX_FLAGS_TSYN BIT(4)union idpf_tx_flex_desc {struct idpf_flex_tx_desc q;/* queue based scheduling */ @@ -445,6 +446,7 @@ struct idpf_tx_queue_stats {u64_stats_t q_busy;u64_stats_t skb_drops;u64_stats_t dma_map_errs; +u64_stats_t tstamp_skipped; };#define IDPF_ITR_DYNAMIC 1@@ -619,6 +621,8 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64,* @compl_tag_bufid_m: Completion tag buffer id mask * @compl_tag_cur_gen: Used to keep track of current completion tag generation * @compl_tag_gen_max: To determine when compl_tag_cur_gen should be reset +* @cached_tstamp_caps: Tx timestamp capabilities negotiated with the CP +* @tstamp_task: Work that handles Tx timestamp read * @stats_sync: See struct u64_stats_sync * @q_stats: See union idpf_tx_queue_stats * @q_id: Queue id @@ -632,7 +636,7 @@ struct idpf_tx_queue {struct idpf_base_tx_desc *base_tx;struct idpf_base_tx_ctx_desc *base_ctx;union idpf_tx_flex_desc *flex_tx; -struct idpf_flex_tx_ctx_desc *flex_ctx; +union idpf_flex_tx_ctx_desc *flex_ctx;void *desc_ring; };@@ -668,6 +672,9 @@ struct idpf_tx_queue {u16 compl_tag_cur_gen;u16 compl_tag_gen_max; +struct idpf_ptp_vport_tx_tstamp_caps *cached_tstamp_caps; +struct work_struct *tstamp_task; +struct u64_stats_sync stats_sync;struct idpf_tx_queue_stats q_stats;__cacheline_group_end_aligned (read_write);@@ -681,7 +688,7 @@ struct idpf_tx_queue {__cacheline_group_end_aligned (cold); }; libeth_cacheline_set_assert(struct idpf_tx_queue, 64, -88 +sizeof (struct u64_stats_sync ), +112 +sizeof (struct u64_stats_sync ), 24);/** drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +5
-1@@ -3163,8 +3163,12 @@ void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q)return ; err =idpf_ptp_get_vport_tstamps_caps (vport); -if (err) +if (err) {pci_dbg (vport->adapter->pdev,"Tx timestamping not supported\n" ); +return ; + } + +INIT_WORK (&vport->tstamp_task, idpf_tstamp_task); }/** drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +146
-0@@ -382,7 +382,9 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) goto get_tstamp_caps_out; } + tstamp_caps->access = true; tstamp_caps->num_entries = num_latches; +INIT_LIST_HEAD (&tstamp_caps->latches_in_use);INIT_LIST_HEAD (&tstamp_caps->latches_free);@@ -425,6 +427,9 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) vport->tx_tstamp_caps = tstamp_caps;kfree (rcv_tx_tstamp_caps); +/* Init mutex to protect tstamp statistics */ +mutex_init (&vport->tstamp_stats.tx_hwtstamp_lock); +return 0 ; err_free_ptp_tx_stamp_list:@@ -440,3 +445,233 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)return err; } + +/** +* idpf_ptp_update_tstamp_tracker - Update the Tx timestamp tracker based on +* the skb compatibility. +* @caps: Tx timestamp capabilities that monitor the latch status +* @skb: skb for which the tstamp value is returned through virtchnl message +* @current_state: Current state of the Tx timestamp latch +* @expected_state: Expected state of the Tx timestamp latch +* +* Find a proper skb tracker for which the Tx timestamp is received and change +* the state to expected value. +* +* Return: true if the tracker has been found and updated, false otherwise. +*/ +static bool +idpf_ptp_update_tstamp_tracker (struct idpf_ptp_vport_tx_tstamp_caps *caps, +struct sk_buff *skb, +enum idpf_ptp_tx_tstamp_state current_state, +enum idpf_ptp_tx_tstamp_state expected_state) +{ +bool updated = false; + +spin_lock (&caps->lock_status); +for (u16 i =0 ; i < caps->num_entries; i++) { +struct idpf_ptp_tx_tstamp_status *status; + + status = &caps->tx_tstamp_status[i]; + +if (skb == status->skb && status->state == current_state) { + status->state = expected_state; + updated = true; +break ; + } + } +spin_unlock (&caps->lock_status); + +return updated; +} + +/** +* idpf_ptp_get_tstamp_value - Get the Tx timestamp value and provide it +* back to the skb. +* @vport: Virtual port structure +* @tstamp_latch: Tx timestamp latch structure fulfilled by the Control Plane +* @ptp_tx_tstamp: Tx timestamp latch to add to the free list +* +* Read the value of the Tx timestamp for a given latch received from the +* Control Plane, extend it to 64 bit and provide back to the skb. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +idpf_ptp_get_tstamp_value (struct idpf_vport *vport, +struct virtchnl2_ptp_tx_tstamp_latch *tstamp_latch, +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp) +{ +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct skb_shared_hwtstamps shhwtstamps; +bool state_upd = false; +u8 tstamp_ns_lo_bit; +u64 tstamp; + + tx_tstamp_caps = vport->tx_tstamp_caps; + tstamp_ns_lo_bit = tx_tstamp_caps->tstamp_ns_lo_bit; + + ptp_tx_tstamp->tstamp =le64_to_cpu (tstamp_latch->tstamp); + ptp_tx_tstamp->tstamp >>= tstamp_ns_lo_bit; + + state_upd =idpf_ptp_update_tstamp_tracker (tx_tstamp_caps, + ptp_tx_tstamp->skb, +IDPF_PTP_READ_VALUE , +IDPF_PTP_FREE ); +if (!state_upd) +return -EINVAL ; + + tstamp =idpf_ptp_extend_ts (vport, ptp_tx_tstamp->tstamp); + shhwtstamps.hwtstamp =ns_to_ktime (tstamp); +skb_tstamp_tx (ptp_tx_tstamp->skb, &shhwtstamps); +consume_skb (ptp_tx_tstamp->skb); + +spin_lock (&tx_tstamp_caps->lock_free); +list_add (&ptp_tx_tstamp->list_member, + &tx_tstamp_caps->latches_free); +spin_unlock (&tx_tstamp_caps->lock_free); + +return 0 ; +} + +/** +* idpf_ptp_get_tx_tstamp_async_handler - Async callback for getting Tx tstamps +* @adapter: Driver specific private structure +* @xn: transaction for message +* @ctlq_msg: received message +* +* Read the tstamps Tx tstamp values from a received message and put them +* directly to the skb. The number of timestamps to read is specified by +* the virtchnl message. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +idpf_ptp_get_tx_tstamp_async_handler (struct idpf_adapter *adapter, +struct idpf_vc_xn *xn, +const struct idpf_ctlq_msg *ctlq_msg) +{ +struct virtchnl2_ptp_get_vport_tx_tstamp_latches *recv_tx_tstamp_msg; +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct virtchnl2_ptp_tx_tstamp_latch tstamp_latch; +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +struct idpf_vport *tstamp_vport =NULL ; +struct list_head *head; +u16 num_latches; +u32 vport_id; +int err; + + recv_tx_tstamp_msg = ctlq_msg->ctx.indirect.payload->va; + vport_id =le32_to_cpu (recv_tx_tstamp_msg->vport_id); + +idpf_for_each_vport (adapter, vport) { +if (!vport) +continue ; + +if (vport->vport_id == vport_id) { + tstamp_vport = vport; +break ; + } + } + +if (!tstamp_vport || !tstamp_vport->tx_tstamp_caps) +return -EINVAL ; + + tx_tstamp_caps = tstamp_vport->tx_tstamp_caps; + num_latches =le16_to_cpu (recv_tx_tstamp_msg->num_latches); + + head = &tx_tstamp_caps->latches_in_use; +spin_lock (&tx_tstamp_caps->lock_in_use); + +for (u16 i =0 ; i < num_latches; i++) { + tstamp_latch = recv_tx_tstamp_msg->tstamp_latches[i]; + +if (!tstamp_latch.valid)drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) · line 598
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +10
-0+continue ; + +if (list_empty (head)) { + err = -ENOBUFS ; + goto unlock; + } + +list_for_each_entry (ptp_tx_tstamp, head, list_member) { +if (tstamp_latch.index == ptp_tx_tstamp->idx) { +list_del (&ptp_tx_tstamp->list_member);need
list_for_each_entry_safewhen callinglist_delon members.Quoted 82 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +79
-0+ err =idpf_ptp_get_tstamp_value (tstamp_vport, + &tstamp_latch, + ptp_tx_tstamp); +if (err) + goto unlock; + +break ; + } + } + } + +unlock: +spin_unlock (&tx_tstamp_caps->lock_in_use); + +return err; +} + +/** +* idpf_ptp_get_tx_tstamp - Send virtchnl get Tx timestamp latches message +* @vport: Virtual port structure +* +* Send virtchnl get Tx tstamp message to read the value of the HW timestamp. +* The message contains a list of indexes set in the Tx descriptors. +* +* Return: 0 on success, -errno otherwise. +*/ +int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport) +{ +struct virtchnl2_ptp_get_vport_tx_tstamp_latches *send_tx_tstamp_msg; +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct idpf_vc_xn_params xn_params = { + .vc_op =VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP , + .timeout_ms =IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC , + .async = true, + .async_handler = idpf_ptp_get_tx_tstamp_async_handler, + }; +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +int reply_sz, size, msg_size; +struct list_head *head; +bool state_upd; +u16 id =0 ; + + tx_tstamp_caps = vport->tx_tstamp_caps; + head = &tx_tstamp_caps->latches_in_use; + + size =struct_size (send_tx_tstamp_msg, tstamp_latches, + tx_tstamp_caps->num_entries); + send_tx_tstamp_msg =kzalloc (size,GFP_KERNEL ); +if (!send_tx_tstamp_msg) +return -ENOMEM ; + +spin_lock (&tx_tstamp_caps->lock_in_use); +list_for_each_entry (ptp_tx_tstamp, head, list_member) { +u8 idx; + + state_upd =idpf_ptp_update_tstamp_tracker (tx_tstamp_caps, + ptp_tx_tstamp->skb, +IDPF_PTP_REQUEST , +IDPF_PTP_READ_VALUE ); +if (!state_upd) +continue ; + + idx = ptp_tx_tstamp->idx; + send_tx_tstamp_msg->tstamp_latches[id].index = idx; + id++; + } +spin_unlock (&tx_tstamp_caps->lock_in_use); + + msg_size =struct_size (send_tx_tstamp_msg, tstamp_latches, id); + send_tx_tstamp_msg->vport_id =cpu_to_le32 (vport->vport_id); + send_tx_tstamp_msg->num_latches =cpu_to_le16 (id); + xn_params.send_buf.iov_base = send_tx_tstamp_msg; + xn_params.send_buf.iov_len = msg_size; + + reply_sz =idpf_vc_xn_exec (vport->adapter, &xn_params); +kfree (send_tx_tstamp_msg); + +return min (reply_sz,0 ); +}Signature · 1 line
2.31.1
RE: [PATCH v3 iwl-next 08/10] idpf: add Tx timestamp flows
Quoted 51 lines · Milena
Quoted 32 lines · On 01/07/2025 3:55PM Willem de Bruijn wrote:
Quoted 31 lines
Add functions to request Tx timestamp for the PTP packets, read the Tx timestamp when the completion tag for that packet is being received, extend the Tx timestamp value and set the supported timestamping modes.
Tx timestamp is requested for the PTP packets by setting a TSYN bit and index value in the Tx context descriptor. The driver assumption is that the Tx timestamp value is ready to be read when the completion tag is received. Then the driver schedules delayed work and the Tx timestamp value read is requested through virtchnl message. At the end, the Tx timestamp value is extended to 64-bit and provided back to the skb.
Co-developed-by Josh Hay <[email protected]>Signed-off-by Josh Hay <[email protected]>Signed-off-by Milena Olech <[email protected]>---
v2 -> v3: changeget_timestamp_filterfunction name, split stats into vport-based and tx queue-based
v1 -> v2: add timestamping stats, use ndo_hwtamp_get/ndo_hwstamp_setdrivers/net/ethernet/intel/idpf/idpf.h | 20 ++ .../net/ethernet/intel/idpf/idpf_ethtool.c | 69 ++++- .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 13 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 47 ++++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 236 +++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_ptp.h | 52 ++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 139 ++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 11 +- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 6 +- .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 235 +++++++++++++++++ 10 files changed, 814 insertions(+), 14 deletions(-)Quoted 16 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c static int idpf_get_link_ksettings(struct net_device *netdev, · line 1339
Quoted 13 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +13
-0+/** +* idpf_get_timestamp_filters - Get the supported timestamping mode +* @vport: Virtual port structure +* @info: ethtool timestamping info structure +* +* Get the Tx/Rx timestamp filters. +*/ +static void idpf_get_timestamp_filters (const struct idpf_vport *vport, +struct kernel_ethtool_ts_info *info) +{ +if (!vport->tx_tstamp_caps || + vport->adapter->ptp->tx_tstamp_access ==IDPF_PTP_NONE ) +return ;Is making
SOF_TIMESTAMPING_RX_HARDWAREandSOF_TIMESTAMPING_RAW_HARDWAREconditional ontx_tstamp_accessintentional?
Quoted 6 lines
Hmmm, good catch.
I guess I will change theSOF_TIMESTAMPING_RX_HARDWAREto be not conditional.About the
SOF_TIMESTAMPING_RAW_HARDWARE- it should rely on thetx_statmp_access.
For Tx, but it also applies to Rx.
Quoted 28 lines
Quoted 18 lines
Quoted 18 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +17
-0+ + info->so_timestamping =SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + info->tx_types =BIT (HWTSTAMP_TX_OFF ) |BIT (HWTSTAMP_TX_ON ); +} + + +static int idpf_hwtstamp_get (struct net_device *netdev, +struct kernel_hwtstamp_config *config) +{ +struct idpf_adapter *adapter =idpf_netdev_to_adapter (netdev); +struct idpf_vport *vport; + +idpf_vport_cfg_lock (adapter);Quoted 9 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c void idpf_free_dma_mem(struct idpf_hw *hw, struct idpf_dma_mem *mem) · line 2388
Quoted 5 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +5
-0+ vport =idpf_netdev_to_vport (netdev); + +if (!idpf_ptp_get_vport_tstamp_capability (vport)) { +idpf_vport_cfg_unlock (adapter); +return -EOPNOTSUPP ;Should this return an empty config and return 0, rather than return error?
Quoted 2 lines
I'd prefer to return NOTSUPP, as the feature itself relies on the CP policy.
Does that make ethtool -T $DEV fail? It should ideally succeed while only advertising software receive timestamping (which is implemented device independent).
Quoted 117 lines
Quoted 108 lines
Quoted 108 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +11
-0+ } + + *config = vport->tstamp_config; + +idpf_vport_cfg_unlock (adapter); + +return 0 ; +} +static const struct net_device_ops idpf_netdev_ops = { .ndo_open = idpf_open, .ndo_stop = idpf_stop,@@ -2383,4 +2428,6 @@ static const struct net_device_ops idpf_netdev_ops = { .ndo_get_stats64 = idpf_get_stats64, .ndo_set_features = idpf_set_features, .ndo_tx_timeout = idpf_tx_timeout, + .ndo_hwtstamp_get = idpf_hwtstamp_get, + .ndo_hwtstamp_set = idpf_hwtstamp_set, };drivers/net/ethernet/intel/idpf/idpf_ptp.c +60
-0@@ -317,6 +317,37 @@ static int idpf_ptp_gettimex64(struct ptp_clock_info *info,return 0 ; } +/** +* idpf_ptp_update_cached_phctime - Update the cached PHC time values +* @adapter: Driver specific private structure +* +* This function updates the system time values which are cached in the adapter +* structure. +* +* This function must be called periodically to ensure that the cached value +* is never more than 2 seconds old. +* +* Return 0 on success, negative otherwise. +*/ +static int idpf_ptp_update_cached_phctime (struct idpf_adapter *adapter) +{ +u64 systime; +int err; + + err =idpf_ptp_read_src_clk_reg (adapter, &systime,NULL ); +if (err) +return -EACCES ; + +/* Update the cached PHC time stored in the adapter structure. +* These values are used to extend Tx timestamp values to 64 bit +* expected by the stack. +*/ +WRITE_ONCE (adapter->ptp->cached_phc_time, systime); +WRITE_ONCE (adapter->ptp->cached_phc_jiffies, jiffies); + +return 0 ; +} +/** * idpf_ptp_settime64 - Set the time of the clock * @info: the driver's PTP info structure @@ -347,6 +378,11 @@ static int idpf_ptp_settime64(struct ptp_clock_info *info,return err; } + err =idpf_ptp_update_cached_phctime (adapter); +if (err) +pci_warn (adapter->pdev, +"Unable to immediately update cached PHC time\n" ); +return 0 ; }@@ -402,6 +438,11 @@ static int idpf_ptp_adjtime(struct ptp_clock_info *info, s64 delta)return err; } + err =idpf_ptp_update_cached_phctime (adapter); +if (err) +pci_warn (adapter->pdev, +"Unable to immediately update cached PHC time\n" ); +return 0 ; }@@ -465,6 +506,162 @@ static int idpf_ptp_gpio_enable(struct ptp_clock_info *info,return -EOPNOTSUPP ; } +/** +* idpf_ptp_tstamp_extend_32b_to_64b - Convert a 32b nanoseconds Tx timestamp +* to 64b. +* @cached_phc_time: recently cached copy of PHC time +* @in_timestamp: Ingress/egress 32b nanoseconds timestamp value +* +* Hardware captures timestamps which contain only 32 bits of nominal +* nanoseconds, as opposed to the 64bit timestamps that the stack expects. +* +* Return: Tx timestamp value extended to 64 bits based on cached PHC time. +*/ +u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time,u32 in_timestamp) +{ +u32 delta, phc_lo; +u64 ns; + + phc_lo =lower_32_bits (cached_phc_time); + delta = in_timestamp - phc_lo; +Quoted 8 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c static int idpf_ptp_gpio_enable(struct ptp_clock_info *info, · line 533
Quoted 6 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +6
-0+if (delta >S32_MAX ) { + delta = phc_lo - in_timestamp; + ns = cached_phc_time - delta; + }else { + ns = cached_phc_time + delta; + }If using s64 delta and ns, no need for branch?
Quoted 5 lines
To make it more readable, I'll change the condition in v4. I'll check if the
phc_lois greater thanin_stamp.If
phc_lois bigger, then tx tstamp value was captured before caching PHC time and case 1 will be applicable.
My point is that with signed arithmetic there is no need to invert delta and switch from addition to deletion.
Quoted 931 lines
Quoted 58 lines
Quoted 58 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +57
-0+ +return ns; +} + +/** +* idpf_ptp_extend_ts - Convert a 40b timestamp to 64b nanoseconds +* @vport: Virtual port structure +* @in_tstamp: Ingress/egress timestamp value +* +* It is assumed that the caller verifies the timestamp is valid prior to +* calling this function. +* +* Extract the 32bit nominal nanoseconds and extend them. Use the cached PHC +* time stored in the device private PTP structure as the basis for timestamp +* extension. +* +* Return: Tx timestamp value extended to 64 bits. +*/ +u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u64 in_tstamp) +{ +struct idpf_ptp *ptp = vport->adapter->ptp; +unsigned long discard_time; + + discard_time = ptp->cached_phc_jiffies +2 *HZ ; + +if (time_is_before_jiffies (discard_time)) { +mutex_lock (&vport->tstamp_stats.tx_hwtstamp_lock); + vport->tstamp_stats.tx_hwtstamp_discarded++; +mutex_unlock (&vport->tstamp_stats.tx_hwtstamp_lock); + +return 0 ; + } + +return idpf_ptp_tstamp_extend_32b_to_64b (ptp->cached_phc_time, +lower_32_bits (in_tstamp)); +} + +/** +* idpf_ptp_request_ts - Request an available Tx timestamp index +* @tx_q: Transmit queue on which the Tx timestamp is requested +* @skb: The SKB to associate with this timestamp request +* @idx: Index of the Tx timestamp latch +* +* Request tx timestamp index negotiated during PTP init that will be set into +* Tx descriptor. +* +* Return: 0 and the index that can be provided to Tx descriptor on success, +* -errno otherwise. +*/ +int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +u32 *idx) +{ +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +struct list_head *head; + + head = &tx_q->cached_tstamp_caps->latches_free; +if (list_empty (head))Quoted 8 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c static int idpf_ptp_gpio_enable(struct ptp_clock_info *info, · line 596
Quoted 6 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +6
-0+return -ENOBUFS ; + +/* Get the index from the free latches list */ +spin_lock_bh (&tx_q->cached_tstamp_caps->lock_free); + ptp_tx_tstamp = list_first_entry(head, struct idpf_ptp_tx_tstamp, + list_member);Racy, as
list_emptyis tested before taking the spin lock?You're correct, I'll change it.
Quoted 862 lines
Quoted 767 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +105
-2+list_del (&ptp_tx_tstamp->list_member); +spin_unlock_bh (&tx_q->cached_tstamp_caps->lock_free); + + ptp_tx_tstamp->skb =skb_get (skb); +skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; + +/* Move the element to the used latches list */ +spin_lock_bh (&tx_q->cached_tstamp_caps->lock_in_use); +list_add (&ptp_tx_tstamp->list_member, + &tx_q->cached_tstamp_caps->latches_in_use); +spin_unlock_bh (&tx_q->cached_tstamp_caps->lock_in_use); + + *idx = ptp_tx_tstamp->idx; + +return 0 ; +} + +/** +* idpf_ptp_set_timestamp_mode - Setup driver for requested timestamp mode +* @vport: Virtual port structure +* @config: Hwtstamp settings requested or saved +* +* Return: 0 on success, -errno otherwise. +*/ +int idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config) +{ +switch (config->tx_type) { +case HWTSTAMP_TX_OFF : +case HWTSTAMP_TX_ON : +break ; +default : +return -EINVAL ; + } + + vport->tstamp_config.tx_type = config->tx_type; + +return 0 ; +} + +/** +* idpf_tstamp_task - Delayed task to handle Tx tstamps +* @work: work_struct handle +*/ +void idpf_tstamp_task (struct work_struct *work) +{ +struct idpf_vport *vport; + + vport = container_of(work, struct idpf_vport, tstamp_task); + +idpf_ptp_get_tx_tstamp (vport); +} + +/** +* idpf_ptp_do_aux_work - Do PTP periodic work +* @info: Driver's PTP info structure +* +* Return: Number of jiffies to periodic work. +*/ +static long idpf_ptp_do_aux_work (struct ptp_clock_info *info) +{ +struct idpf_adapter *adapter =idpf_ptp_info_to_adapter (info); + +idpf_ptp_update_cached_phctime (adapter); + +return msecs_to_jiffies (500 ); +} +/** * idpf_ptp_set_caps - Set PTP capabilities * @adapter: Driver specific private structure @@ -486,6 +683,7 @@ static void idpf_ptp_set_caps(const struct idpf_adapter *adapter) info->adjtime = idpf_ptp_adjtime; info->verify = idpf_ptp_verify_pin; info->enable = idpf_ptp_gpio_enable; + info->do_aux_work = idpf_ptp_do_aux_work;#if IS_ENABLED (CONFIG_ARM_ARCH_TIMER ) info->getcrosststamp = idpf_ptp_get_crosststamp;@@ -540,6 +738,8 @@ static void idpf_ptp_release_vport_tstamp(struct idpf_vport *vport)if (!idpf_ptp_get_vport_tstamp_capability (vport))return ; +cancel_work_sync (&vport->tstamp_task); +/* Remove list with free latches */ spin_lock (&vport->tx_tstamp_caps->lock_free);@@ -552,16 +752,21 @@ static void idpf_ptp_release_vport_tstamp(struct idpf_vport *vport)spin_unlock (&vport->tx_tstamp_caps->lock_free);/* Remove list with latches in use */ +mutex_lock (&vport->tstamp_stats.tx_hwtstamp_lock);spin_lock (&vport->tx_tstamp_caps->lock_in_use); head = &vport->tx_tstamp_caps->latches_in_use;list_for_each_entry_safe (ptp_tx_tstamp, tmp, head, list_member) { + vport->tstamp_stats.tx_hwtstamp_flushed++;list_del (&ptp_tx_tstamp->list_member);kfree (ptp_tx_tstamp); }spin_unlock (&vport->tx_tstamp_caps->lock_in_use); +mutex_unlock (&vport->tstamp_stats.tx_hwtstamp_lock); +mutex_destroy (&vport->tstamp_stats.tx_hwtstamp_lock); +kfree (vport->tx_tstamp_caps); vport->tx_tstamp_caps =NULL ; }@@ -578,6 +783,27 @@ static void idpf_ptp_release_tstamp(struct idpf_adapter *adapter)idpf_ptp_release_vport_tstamp (vport); } +/** +* idpf_ptp_get_txq_tstamp_capability - Verify the timestamping capability +* for a given tx queue. +* @txq: Transmit queue +* +* Since performing timestamp flows requires reading the device clock value and +* the support in the Control Plane, the function checks both factors and +* summarizes the support for the timestamping. +* +* Return: true if the timestamping is supported, false otherwise. +*/ +bool idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq) +{ +if (!txq || !txq->cached_tstamp_caps) +return false; +else if (txq->cached_tstamp_caps->access) +return true; +else +return false; +} +/** * idpf_ptp_init - Initialize PTP hardware clock support * @adapter: Driver specific private structure @@ -618,6 +844,8 @@ int idpf_ptp_init(struct idpf_adapter *adapter)if (err) goto free_ptp; +ptp_schedule_worker (adapter->ptp->clock,0 ); +/* Write the default increment time value if the clock adjustments * are enabled. */ @@ -641,6 +869,7 @@ int idpf_ptp_init(struct idpf_adapter *adapter)return 0 ; remove_clock: +ptp_cancel_worker_sync (adapter->ptp->clock);ptp_clock_unregister (adapter->ptp->clock); adapter->ptp->clock =NULL ;@@ -662,11 +891,14 @@ void idpf_ptp_release(struct idpf_adapter *adapter)if (!ptp)return ; -if (ptp->tx_tstamp_access !=IDPF_PTP_NONE ) +if (ptp->tx_tstamp_access !=IDPF_PTP_NONE && + ptp->get_dev_clk_time_access !=IDPF_PTP_NONE )idpf_ptp_release_tstamp (adapter); -if (ptp->clock) +if (ptp->clock) { +ptp_cancel_worker_sync (adapter->ptp->clock);ptp_clock_unregister (ptp->clock); + }kfree (ptp); adapter->ptp =NULL ;drivers/net/ethernet/intel/idpf/idpf_ptp.h +52
-0@@ -131,6 +131,7 @@ struct idpf_ptp_tx_tstamp {* @lock_in_use: the lock to the used latches list * @lock_free: the lock to free the latches list * @lock_status: the lock to the status tracker +* @access: indicates an access to Tx timestamp * @latches_free: the list of the free Tx timestamps latches * @latches_in_use: the list of the used Tx timestamps latches * @tx_tstamp_status: Tx tstamp status tracker @@ -142,6 +143,7 @@ struct idpf_ptp_vport_tx_tstamp_caps {spinlock_t lock_in_use;spinlock_t lock_free;spinlock_t lock_status; + bool access:1;struct list_head latches_free;struct list_head latches_in_use;struct idpf_ptp_tx_tstamp_status tx_tstamp_status[];@@ -155,6 +157,8 @@ struct idpf_ptp_vport_tx_tstamp_caps {* @base_incval: base increment value of the PTP clock * @max_adj: maximum adjustment of the PTP clock * @cmd: HW specific command masks +* @cached_phc_time: a cached copy of the PHC time for timestamp extension +* @cached_phc_jiffies: jiffies when cached_phc_time was last updated * @dev_clk_regs: the set of registers to access the device clock * @caps: PTP capabilities negotiated with the Control Plane * @get_dev_clk_time_access: access type for getting the device clock time @@ -172,6 +176,8 @@ struct idpf_ptp {u64 base_incval;u64 max_adj;struct idpf_ptp_cmd cmd; +u64 cached_phc_time; +unsigned long cached_phc_jiffies;struct idpf_ptp_dev_clk_regs dev_clk_regs;u32 caps; enum idpf_ptp_access get_dev_clk_time_access:2;@@ -181,6 +187,7 @@ struct idpf_ptp { enum idpf_ptp_access tx_tstamp_access:2; u8 rsv:6;struct idpf_ptp_secondary_mbx secondary_mbx; + };/** @@ -234,6 +241,7 @@ int idpf_ptp_init(struct idpf_adapter *adapter);void idpf_ptp_release (struct idpf_adapter *adapter);int idpf_ptp_get_caps (struct idpf_adapter *adapter);void idpf_ptp_get_features_access (const struct idpf_adapter *adapter); +bool idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq);int idpf_ptp_get_dev_clk_time (struct idpf_adapter *adapter,struct idpf_ptp_dev_timers *dev_clk_time); int idpf_ptp_get_cross_time(struct idpf_adapter *adapter,@@ -242,6 +250,14 @@ int idpf_ptp_set_dev_clk_time(struct idpf_adapter *adapter, u64 time);int idpf_ptp_adj_dev_clk_fine (struct idpf_adapter *adapter,u64 incval);int idpf_ptp_adj_dev_clk_time (struct idpf_adapter *adapter,s64 delta);int idpf_ptp_get_vport_tstamps_caps (struct idpf_vport *vport); +int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport); +int idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config); +u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u64 in_tstamp); +u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time,u32 in_timestamp); +int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +u32 *idx); +void idpf_tstamp_task (struct work_struct *work);#else /* CONFIG_PTP_1588_CLOCK */ static inline int idpf_ptp_init (struct idpf_adapter *adapter) {@@ -258,6 +274,12 @@ static inline int idpf_ptp_get_caps(struct idpf_adapter *adapter)static inline void idpf_ptp_get_features_access (const struct idpf_adapter *adapter) { } +static inline bool +idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq) +{ +return false; +} +static inline int idpf_ptp_get_dev_clk_time (struct idpf_adapter *adapter,struct idpf_ptp_dev_timers *dev_clk_time)@@ -295,5 +317,35 @@ static inline int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)return -EOPNOTSUPP ; } +static inline int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport) +{ +return -EOPNOTSUPP ; +} + +static inline int +idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config) +{ +return -EOPNOTSUPP ; +} + +static inline u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u32 in_tstamp) +{ +return 0 ; +} + +static inline u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time, +u32 in_timestamp) +{ +return 0 ; +} + +static inline int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q, +struct sk_buff *skb,u32 *idx) +{ +return -EOPNOTSUPP ; +} + +static inline void idpf_tstamp_task (struct work_struct *work) { }#endif /* CONFIG_PTP_1588_CLOCK */ #endif /* _IDPF_PTP_H */ drivers/net/ethernet/intel/idpf/idpf_txrx.c +132
-7@@ -5,6 +5,7 @@#include <net/libeth/tx.h> #include "idpf.h" +#include "idpf_ptp.h" #include "idpf_virtchnl.h" struct idpf_tx_stash {@@ -1107,6 +1108,8 @@ void idpf_vport_queues_rel(struct idpf_vport *vport)*/ static int idpf_vport_init_fast_path_txqs (struct idpf_vport *vport) { +struct idpf_ptp_vport_tx_tstamp_caps *caps = vport->tx_tstamp_caps; +struct work_struct *tstamp_task = &vport->tstamp_task;int i, j, k =0 ; vport->txqs = kcalloc(vport->num_txq, sizeof(*vport->txqs),@@ -1121,6 +1124,12 @@ static int idpf_vport_init_fast_path_txqs(struct idpf_vport *vport)for (j =0 ; j < tx_grp->num_txq; j++, k++) { vport->txqs[k] = tx_grp->txqs[j]; vport->txqs[k]->idx = k; + +if (!caps) +continue ; + + vport->txqs[k]->cached_tstamp_caps = caps; + vport->txqs[k]->tstamp_task = tstamp_task; } }@@ -1654,6 +1663,40 @@ static void idpf_tx_handle_sw_marker(struct idpf_tx_queue *tx_q)wake_up (&vport->sw_marker_wq); } +/** +* idpf_tx_read_tstamp - schedule a work to read Tx timestamp value +* @txq: queue to read the timestamp from +* @skb: socket buffer to provide Tx timestamp value +* +* Schedule a work to read Tx timestamp value generated once the packet is +* transmitted. +*/ +static void idpf_tx_read_tstamp (struct idpf_tx_queue *txq,struct sk_buff *skb) +{ +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct idpf_ptp_tx_tstamp_status *tx_tstamp_status; + + tx_tstamp_caps = txq->cached_tstamp_caps; +spin_lock_bh (&tx_tstamp_caps->lock_status); + +for (u32 i =0 ; i < tx_tstamp_caps->num_entries; i++) { + tx_tstamp_status = &tx_tstamp_caps->tx_tstamp_status[i]; +if (tx_tstamp_status->state !=IDPF_PTP_FREE ) +continue ; + + tx_tstamp_status->skb = skb; + tx_tstamp_status->state =IDPF_PTP_REQUEST ; + +/* Fetch timestamp from completion descriptor through +* virtchnl msg to report to stack. +*/ +queue_work (system_unbound_wq, txq->tstamp_task); +break ; + } + +spin_unlock_bh (&tx_tstamp_caps->lock_status); +} +/** * idpf_tx_clean_stashed_bufs - clean bufs that were stored for * out of order completions @@ -1682,6 +1725,11 @@ static void idpf_tx_clean_stashed_bufs(struct idpf_tx_queue *txq,continue ;hash_del (&stash->hlist); + +if (stash->buf.type ==LIBETH_SQE_SKB && + (skb_shinfo (stash->buf.skb)->tx_flags &SKBTX_IN_PROGRESS )) +idpf_tx_read_tstamp (txq, stash->buf.skb); +libeth_tx_complete (&stash->buf, &cp);/* Push shadow buf back onto stack */ @@ -1876,8 +1924,12 @@ static bool idpf_tx_clean_buf_ring(struct idpf_tx_queue *txq, u16 compl_tag, idpf_tx_buf_compl_tag(tx_buf) != compl_tag))return false; -if (tx_buf->type ==LIBETH_SQE_SKB ) +if (tx_buf->type ==LIBETH_SQE_SKB ) { +if (skb_shinfo (tx_buf->skb)->tx_flags &SKBTX_IN_PROGRESS ) +idpf_tx_read_tstamp (txq, tx_buf->skb); +libeth_tx_complete (tx_buf, &cp); + }idpf_tx_clean_buf_ring_bump_ntc (txq, idx, tx_buf);@@ -2296,7 +2348,7 @@ void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb,* descriptor. Reset that here. */ tx_desc = &txq->flex_tx[idx]; -memset (tx_desc,0 ,sizeof (struct idpf_flex_tx_ctx_desc )); +memset (tx_desc,0 ,sizeof (*tx_desc));if (idx ==0 ) idx = txq->desc_count; idx--;@@ -2699,10 +2751,10 @@ static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs,* Since the TX buffer rings mimics the descriptor ring, update the tx buffer * ring entry to reflect that this index is a context descriptor */ -static struct idpf_flex_tx_ctx_desc * +static union idpf_flex_tx_ctx_desc *idpf_tx_splitq_get_ctx_desc (struct idpf_tx_queue *txq) { -struct idpf_flex_tx_ctx_desc *desc; +union idpf_flex_tx_ctx_desc *desc;int i = txq->next_to_use; txq->tx_buf[i].type =LIBETH_SQE_CTX ;@@ -2732,6 +2784,73 @@ netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb)return NETDEV_TX_OK ; } +#if (IS_ENABLED (CONFIG_PTP_1588_CLOCK )) +/** +* idpf_tx_tstamp - set up context descriptor for hardware timestamp +* @tx_q: queue to send buffer on +* @skb: pointer to the SKB we're sending +* @off: pointer to the offload struct +* +* Return: Positive index number on success, negative otherwise. +*/ +static int idpf_tx_tstamp (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +struct idpf_tx_offload_params *off) +{ +int err, idx; + +/* only timestamp the outbound packet if the user has requested it */ +if (likely (!(skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ))) +return -1 ; + +if (!idpf_ptp_get_txq_tstamp_capability (tx_q)) +return -1 ; + +/* Tx timestamps cannot be sampled when doing TSO */ +if (off->tx_flags &IDPF_TX_FLAGS_TSO ) +return -1 ; + +/* Grab an open timestamp slot */ + err =idpf_ptp_request_ts (tx_q, skb, &idx); +if (err) { +u64_stats_update_begin (&tx_q->stats_sync); +u64_stats_inc (&tx_q->q_stats.tstamp_skipped); +u64_stats_update_end (&tx_q->stats_sync); + +return -1 ; + } + + off->tx_flags |=IDPF_TX_FLAGS_TSYN ; + +return idx; +} + +/** +* idpf_tx_set_tstamp_desc - Set the Tx descriptor fields needed to generate +* PHY Tx timestamp +* @ctx_desc: Context descriptor +* @idx: Index of the Tx timestamp latch +*/ +static void idpf_tx_set_tstamp_desc (union idpf_flex_tx_ctx_desc *ctx_desc, +u32 idx) +{ + ctx_desc->tsyn.qw1 =le64_encode_bits (IDPF_TX_DESC_DTYPE_CTX , +IDPF_TX_CTX_DTYPE_M ) | +le64_encode_bits (IDPF_TX_CTX_DESC_TSYN , +IDPF_TX_CTX_CMD_M ) | +le64_encode_bits (idx,IDPF_TX_CTX_TSYN_REG_M ); +} +#else /* CONFIG_PTP_1588_CLOCK */ +static int idpf_tx_tstamp (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +struct idpf_tx_offload_params *off) +{ +return -1 ; +} + +static void idpf_tx_set_tstamp_desc (union idpf_flex_tx_ctx_desc *ctx_desc, +u32 idx) +{ } +#endif /* CONFIG_PTP_1588_CLOCK */ +/** * idpf_tx_splitq_frame - Sends buffer on Tx ring using flex descriptors * @skb: send buffer @@ -2743,9 +2862,10 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, struct idpf_tx_queue *tx_q) {struct idpf_tx_splitq_params tx_params = { }; +union idpf_flex_tx_ctx_desc *ctx_desc;struct idpf_tx_buf *first;unsigned int count; -int tso; +int tso, idx; count =idpf_tx_desc_count_required (tx_q, skb);if (unlikely (!count))@@ -2765,8 +2885,7 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,if (tso) {/* If tso is needed, set up context desc */ -struct idpf_flex_tx_ctx_desc *ctx_desc = -idpf_tx_splitq_get_ctx_desc (tx_q); + ctx_desc =idpf_tx_splitq_get_ctx_desc (tx_q); ctx_desc->tso.qw1.cmd_dtype = cpu_to_le16(IDPF_TX_DESC_DTYPE_FLEX_TSO_CTX |@@ -2784,6 +2903,12 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,u64_stats_update_end (&tx_q->stats_sync); } + idx =idpf_tx_tstamp (tx_q, skb, &tx_params.offload); +if (idx !=-1 ) { + ctx_desc =idpf_tx_splitq_get_ctx_desc (tx_q); +idpf_tx_set_tstamp_desc (ctx_desc, idx); + } +/* record the location of the first descriptor for this packet */ first = &tx_q->tx_buf[tx_q->next_to_use]; first->skb = skb;drivers/net/ethernet/intel/idpf/idpf_txrx.h +9
-2@@ -142,6 +142,7 @@ do { \#define IDPF_TX_FLAGS_IPV4 BIT(1)#define IDPF_TX_FLAGS_IPV6 BIT(2)#define IDPF_TX_FLAGS_TUNNEL BIT(3) +#define IDPF_TX_FLAGS_TSYN BIT(4)union idpf_tx_flex_desc {struct idpf_flex_tx_desc q;/* queue based scheduling */ @@ -445,6 +446,7 @@ struct idpf_tx_queue_stats {u64_stats_t q_busy;u64_stats_t skb_drops;u64_stats_t dma_map_errs; +u64_stats_t tstamp_skipped; };#define IDPF_ITR_DYNAMIC 1@@ -619,6 +621,8 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64,* @compl_tag_bufid_m: Completion tag buffer id mask * @compl_tag_cur_gen: Used to keep track of current completion tag generation * @compl_tag_gen_max: To determine when compl_tag_cur_gen should be reset +* @cached_tstamp_caps: Tx timestamp capabilities negotiated with the CP +* @tstamp_task: Work that handles Tx timestamp read * @stats_sync: See struct u64_stats_sync * @q_stats: See union idpf_tx_queue_stats * @q_id: Queue id @@ -632,7 +636,7 @@ struct idpf_tx_queue {struct idpf_base_tx_desc *base_tx;struct idpf_base_tx_ctx_desc *base_ctx;union idpf_tx_flex_desc *flex_tx; -struct idpf_flex_tx_ctx_desc *flex_ctx; +union idpf_flex_tx_ctx_desc *flex_ctx;void *desc_ring; };@@ -668,6 +672,9 @@ struct idpf_tx_queue {u16 compl_tag_cur_gen;u16 compl_tag_gen_max; +struct idpf_ptp_vport_tx_tstamp_caps *cached_tstamp_caps; +struct work_struct *tstamp_task; +struct u64_stats_sync stats_sync;struct idpf_tx_queue_stats q_stats;__cacheline_group_end_aligned (read_write);@@ -681,7 +688,7 @@ struct idpf_tx_queue {__cacheline_group_end_aligned (cold); }; libeth_cacheline_set_assert(struct idpf_tx_queue, 64, -88 +sizeof (struct u64_stats_sync ), +112 +sizeof (struct u64_stats_sync ), 24);/** drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +5
-1@@ -3163,8 +3163,12 @@ void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q)return ; err =idpf_ptp_get_vport_tstamps_caps (vport); -if (err) +if (err) {pci_dbg (vport->adapter->pdev,"Tx timestamping not supported\n" ); +return ; + } + +INIT_WORK (&vport->tstamp_task, idpf_tstamp_task); }/** drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +146
-0@@ -382,7 +382,9 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) goto get_tstamp_caps_out; } + tstamp_caps->access = true; tstamp_caps->num_entries = num_latches; +INIT_LIST_HEAD (&tstamp_caps->latches_in_use);INIT_LIST_HEAD (&tstamp_caps->latches_free);@@ -425,6 +427,9 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) vport->tx_tstamp_caps = tstamp_caps;kfree (rcv_tx_tstamp_caps); +/* Init mutex to protect tstamp statistics */ +mutex_init (&vport->tstamp_stats.tx_hwtstamp_lock); +return 0 ; err_free_ptp_tx_stamp_list:@@ -440,3 +445,233 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)return err; } + +/** +* idpf_ptp_update_tstamp_tracker - Update the Tx timestamp tracker based on +* the skb compatibility. +* @caps: Tx timestamp capabilities that monitor the latch status +* @skb: skb for which the tstamp value is returned through virtchnl message +* @current_state: Current state of the Tx timestamp latch +* @expected_state: Expected state of the Tx timestamp latch +* +* Find a proper skb tracker for which the Tx timestamp is received and change +* the state to expected value. +* +* Return: true if the tracker has been found and updated, false otherwise. +*/ +static bool +idpf_ptp_update_tstamp_tracker (struct idpf_ptp_vport_tx_tstamp_caps *caps, +struct sk_buff *skb, +enum idpf_ptp_tx_tstamp_state current_state, +enum idpf_ptp_tx_tstamp_state expected_state) +{ +bool updated = false; + +spin_lock (&caps->lock_status); +for (u16 i =0 ; i < caps->num_entries; i++) { +struct idpf_ptp_tx_tstamp_status *status; + + status = &caps->tx_tstamp_status[i]; + +if (skb == status->skb && status->state == current_state) { + status->state = expected_state; + updated = true; +break ; + } + } +spin_unlock (&caps->lock_status); + +return updated; +} + +/** +* idpf_ptp_get_tstamp_value - Get the Tx timestamp value and provide it +* back to the skb. +* @vport: Virtual port structure +* @tstamp_latch: Tx timestamp latch structure fulfilled by the Control Plane +* @ptp_tx_tstamp: Tx timestamp latch to add to the free list +* +* Read the value of the Tx timestamp for a given latch received from the +* Control Plane, extend it to 64 bit and provide back to the skb. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +idpf_ptp_get_tstamp_value (struct idpf_vport *vport, +struct virtchnl2_ptp_tx_tstamp_latch *tstamp_latch, +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp) +{ +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct skb_shared_hwtstamps shhwtstamps; +bool state_upd = false; +u8 tstamp_ns_lo_bit; +u64 tstamp; + + tx_tstamp_caps = vport->tx_tstamp_caps; + tstamp_ns_lo_bit = tx_tstamp_caps->tstamp_ns_lo_bit; + + ptp_tx_tstamp->tstamp =le64_to_cpu (tstamp_latch->tstamp); + ptp_tx_tstamp->tstamp >>= tstamp_ns_lo_bit; + + state_upd =idpf_ptp_update_tstamp_tracker (tx_tstamp_caps, + ptp_tx_tstamp->skb, +IDPF_PTP_READ_VALUE , +IDPF_PTP_FREE ); +if (!state_upd) +return -EINVAL ; + + tstamp =idpf_ptp_extend_ts (vport, ptp_tx_tstamp->tstamp); + shhwtstamps.hwtstamp =ns_to_ktime (tstamp); +skb_tstamp_tx (ptp_tx_tstamp->skb, &shhwtstamps); +consume_skb (ptp_tx_tstamp->skb); + +spin_lock (&tx_tstamp_caps->lock_free); +list_add (&ptp_tx_tstamp->list_member, + &tx_tstamp_caps->latches_free); +spin_unlock (&tx_tstamp_caps->lock_free); + +return 0 ; +} + +/** +* idpf_ptp_get_tx_tstamp_async_handler - Async callback for getting Tx tstamps +* @adapter: Driver specific private structure +* @xn: transaction for message +* @ctlq_msg: received message +* +* Read the tstamps Tx tstamp values from a received message and put them +* directly to the skb. The number of timestamps to read is specified by +* the virtchnl message. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +idpf_ptp_get_tx_tstamp_async_handler (struct idpf_adapter *adapter, +struct idpf_vc_xn *xn, +const struct idpf_ctlq_msg *ctlq_msg) +{ +struct virtchnl2_ptp_get_vport_tx_tstamp_latches *recv_tx_tstamp_msg; +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct virtchnl2_ptp_tx_tstamp_latch tstamp_latch; +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +struct idpf_vport *tstamp_vport =NULL ; +struct list_head *head; +u16 num_latches; +u32 vport_id; +int err; + + recv_tx_tstamp_msg = ctlq_msg->ctx.indirect.payload->va; + vport_id =le32_to_cpu (recv_tx_tstamp_msg->vport_id); + +idpf_for_each_vport (adapter, vport) { +if (!vport) +continue ; + +if (vport->vport_id == vport_id) { + tstamp_vport = vport; +break ; + } + } + +if (!tstamp_vport || !tstamp_vport->tx_tstamp_caps) +return -EINVAL ; + + tx_tstamp_caps = tstamp_vport->tx_tstamp_caps; + num_latches =le16_to_cpu (recv_tx_tstamp_msg->num_latches); + + head = &tx_tstamp_caps->latches_in_use; +spin_lock (&tx_tstamp_caps->lock_in_use); + +for (u16 i =0 ; i < num_latches; i++) { + tstamp_latch = recv_tx_tstamp_msg->tstamp_latches[i]; + +if (!tstamp_latch.valid)drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) · line 598
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +10
-0+continue ; + +if (list_empty (head)) { + err = -ENOBUFS ; + goto unlock; + } + +list_for_each_entry (ptp_tx_tstamp, head, list_member) { +if (tstamp_latch.index == ptp_tx_tstamp->idx) { +list_del (&ptp_tx_tstamp->list_member);need
list_for_each_entry_safewhen callinglist_delon members.Quoted 82 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +79
-0+ err =idpf_ptp_get_tstamp_value (tstamp_vport, + &tstamp_latch, + ptp_tx_tstamp); +if (err) + goto unlock; + +break ; + } + } + } + +unlock: +spin_unlock (&tx_tstamp_caps->lock_in_use); + +return err; +} + +/** +* idpf_ptp_get_tx_tstamp - Send virtchnl get Tx timestamp latches message +* @vport: Virtual port structure +* +* Send virtchnl get Tx tstamp message to read the value of the HW timestamp. +* The message contains a list of indexes set in the Tx descriptors. +* +* Return: 0 on success, -errno otherwise. +*/ +int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport) +{ +struct virtchnl2_ptp_get_vport_tx_tstamp_latches *send_tx_tstamp_msg; +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct idpf_vc_xn_params xn_params = { + .vc_op =VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP , + .timeout_ms =IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC , + .async = true, + .async_handler = idpf_ptp_get_tx_tstamp_async_handler, + }; +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +int reply_sz, size, msg_size; +struct list_head *head; +bool state_upd; +u16 id =0 ; + + tx_tstamp_caps = vport->tx_tstamp_caps; + head = &tx_tstamp_caps->latches_in_use; + + size =struct_size (send_tx_tstamp_msg, tstamp_latches, + tx_tstamp_caps->num_entries); + send_tx_tstamp_msg =kzalloc (size,GFP_KERNEL ); +if (!send_tx_tstamp_msg) +return -ENOMEM ; + +spin_lock (&tx_tstamp_caps->lock_in_use); +list_for_each_entry (ptp_tx_tstamp, head, list_member) { +u8 idx; + + state_upd =idpf_ptp_update_tstamp_tracker (tx_tstamp_caps, + ptp_tx_tstamp->skb, +IDPF_PTP_REQUEST , +IDPF_PTP_READ_VALUE ); +if (!state_upd) +continue ; + + idx = ptp_tx_tstamp->idx; + send_tx_tstamp_msg->tstamp_latches[id].index = idx; + id++; + } +spin_unlock (&tx_tstamp_caps->lock_in_use); + + msg_size =struct_size (send_tx_tstamp_msg, tstamp_latches, id); + send_tx_tstamp_msg->vport_id =cpu_to_le32 (vport->vport_id); + send_tx_tstamp_msg->num_latches =cpu_to_le16 (id); + xn_params.send_buf.iov_base = send_tx_tstamp_msg; + xn_params.send_buf.iov_len = msg_size; + + reply_sz =idpf_vc_xn_exec (vport->adapter, &xn_params); +kfree (send_tx_tstamp_msg); + +return min (reply_sz,0 ); +}Signature · 1 line
2.31.1
RE: [PATCH v3 iwl-next 08/10] idpf: add Tx timestamp flows
Quoted 49 lines · On 01/10/2025 10:34PM Willem de Bruijn wrote:
Quoted 49 lines
Quoted 48 lines
Quoted 35 lines
Add functions to request Tx timestamp for the PTP packets, read the Tx timestamp when the completion tag for that packet is being received, extend the Tx timestamp value and set the supported timestamping modes.
Tx timestamp is requested for the PTP packets by setting a TSYN bit and index value in the Tx context descriptor. The driver assumption is that the Tx timestamp value is ready to be read when the completion tag is received. Then the driver schedules delayed work and the Tx timestamp value read is requested through virtchnl message. At the end, the Tx timestamp value is extended to 64-bit and provided back to the skb.
Co-developed-by Josh Hay <[email protected]>Signed-off-by Josh Hay <[email protected]>Signed-off-by Milena Olech <[email protected]>---
v2 -> v3: changeget_timestamp_filterfunction name, split stats into vport-based and tx queue-based
v1 -> v2: add timestamping stats, use ndo_hwtamp_get/ndo_hwstamp_setdrivers/net/ethernet/intel/idpf/idpf.h | 20 ++ .../net/ethernet/intel/idpf/idpf_ethtool.c | 69 ++++- .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 13 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 47 ++++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 236 +++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_ptp.h | 52 ++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 139 ++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 11 +- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 6 +- .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 235 +++++++++++++++++ 10 files changed, 814 insertions(+), 14 deletions(-)drivers/net/ethernet/intel/idpf/idpf_ethtool.c +3
-0+/** +* idpf_get_timestamp_filters - Get the supported timestamping mode +* @vport: Virtual port structure drivers/net/ethernet/intel/idpf/idpf_ethtool.c static int idpf_get_link_ksettings(struct net_device *netdev, · line 1339
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +10
-0+* @info: ethtool timestamping info structure +* +* Get the Tx/Rx timestamp filters. +*/ +static void idpf_get_timestamp_filters (const struct idpf_vport *vport, +struct kernel_ethtool_ts_info *info) +{ +if (!vport->tx_tstamp_caps || + vport->adapter->ptp->tx_tstamp_access ==IDPF_PTP_NONE ) +return ;Is making
SOF_TIMESTAMPING_RX_HARDWAREandSOF_TIMESTAMPING_RAW_HARDWAREconditional ontx_tstamp_accessintentional?
Quoted 8 lines
Quoted 6 lines
Hmmm, good catch.
I guess I will change theSOF_TIMESTAMPING_RX_HARDWAREto be not conditional.About the
SOF_TIMESTAMPING_RAW_HARDWARE- it should rely on thetx_statmp_access.For Tx, but it also applies to Rx.
Right, there was a misunderstanding because the documentation says:
"Report hardware timestamps as generated by
SOF_TIMESTAMPING_TX_HARDWARE when available."
So I assumed that it's Tx only.
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 12 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +12
-0+ + info->so_timestamping =SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + info->tx_types =BIT (HWTSTAMP_TX_OFF ) |BIT (HWTSTAMP_TX_ON ); +} + + +static int idpf_hwtstamp_get (struct net_device *netdev, +struct kernel_hwtstamp_config *config)drivers/net/ethernet/intel/idpf/idpf_ethtool.c static int idpf_get_link_ksettings(struct net_device *netdev,
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +10
-0+{ +struct idpf_adapter *adapter =idpf_netdev_to_adapter (netdev); +struct idpf_vport *vport; + +idpf_vport_cfg_lock (adapter); + vport =idpf_netdev_to_vport (netdev); + +if (!idpf_ptp_get_vport_tstamp_capability (vport)) { +idpf_vport_cfg_unlock (adapter); +return -EOPNOTSUPP ;Should this return an empty config and return 0, rather than return error?
Quoted 6 lines
Quoted 2 lines
I'd prefer to return NOTSUPP, as the feature itself relies on the CP policy.
Does that make ethtool -T $DEV fail? It should ideally succeed while only advertising software receive timestamping (which is implemented device independent).
Ok, I'll change then.
Quoted 118 lines
Quoted 118 lines
Quoted 117 lines
Quoted 105 lines
drivers/net/ethernet/intel/idpf/idpf_lib.c +11
-0+ } + + *config = vport->tstamp_config; + +idpf_vport_cfg_unlock (adapter); + +return 0 ; +} +static const struct net_device_ops idpf_netdev_ops = { .ndo_open = idpf_open, .ndo_stop = idpf_stop,@@ -2383,4 +2428,6 @@ static const struct net_device_ops idpf_netdev_ops = { .ndo_get_stats64 = idpf_get_stats64, .ndo_set_features = idpf_set_features, .ndo_tx_timeout = idpf_tx_timeout, + .ndo_hwtstamp_get = idpf_hwtstamp_get, + .ndo_hwtstamp_set = idpf_hwtstamp_set, };drivers/net/ethernet/intel/idpf/idpf_ptp.c +56
-0@@ -317,6 +317,37 @@ static int idpf_ptp_gettimex64(struct ptp_clock_info *info,return 0 ; } +/** +* idpf_ptp_update_cached_phctime - Update the cached PHC time values +* @adapter: Driver specific private structure +* +* This function updates the system time values which are cached in the adapter +* structure. +* +* This function must be called periodically to ensure that the cached value +* is never more than 2 seconds old. +* +* Return 0 on success, negative otherwise. +*/ +static int idpf_ptp_update_cached_phctime (struct idpf_adapter *adapter) +{ +u64 systime; +int err; + + err =idpf_ptp_read_src_clk_reg (adapter, &systime,NULL ); +if (err) +return -EACCES ; + +/* Update the cached PHC time stored in the adapter structure. +* These values are used to extend Tx timestamp values to 64 bit +* expected by the stack. +*/ +WRITE_ONCE (adapter->ptp->cached_phc_time, systime); +WRITE_ONCE (adapter->ptp->cached_phc_jiffies, jiffies); + +return 0 ; +} +/** * idpf_ptp_settime64 - Set the time of the clock * @info: the driver's PTP info structure @@ -347,6 +378,11 @@ static int idpf_ptp_settime64(struct ptp_clock_info *info,return err; } + err =idpf_ptp_update_cached_phctime (adapter); +if (err) +pci_warn (adapter->pdev, +"Unable to immediately update cached PHC time\n" ); +return 0 ; }@@ -402,6 +438,11 @@ static int idpf_ptp_adjtime(struct ptp_clock_info *info, s64 delta)return err; } + err =idpf_ptp_update_cached_phctime (adapter); +if (err) +pci_warn (adapter->pdev, +"Unable to immediately update cached PHC time\n" ); +return 0 ; }@@ -465,6 +506,162 @@ static int idpf_ptp_gpio_enable(struct ptp_clock_info *info,return -EOPNOTSUPP ; } +/** +* idpf_ptp_tstamp_extend_32b_to_64b - Convert a 32b nanoseconds Tx timestamp +* to 64b. +* @cached_phc_time: recently cached copy of PHC time +* @in_timestamp: Ingress/egress 32b nanoseconds timestamp value +* +* Hardware captures timestamps which contain only 32 bits of nominal +* nanoseconds, as opposed to the 64bit timestamps that the stack expects. +* +* Return: Tx timestamp value extended to 64 bits based on cached PHC time. +*/ +u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time,u32 in_timestamp) +{ +u32 delta, phc_lo; +u64 ns;drivers/net/ethernet/intel/idpf/idpf_ptp.c static int idpf_ptp_gpio_enable(struct ptp_clock_info *info, · line 533
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +10
-0+ + phc_lo =lower_32_bits (cached_phc_time); + delta = in_timestamp - phc_lo; + +if (delta >S32_MAX ) { + delta = phc_lo - in_timestamp; + ns = cached_phc_time - delta; + }else { + ns = cached_phc_time + delta; + }If using s64 delta and ns, no need for branch?
Quoted 8 lines
Quoted 5 lines
To make it more readable, I'll change the condition in v4. I'll check if the
phc_lois greater thanin_stamp.If
phc_lois bigger, then tx tstamp value was captured before caching PHC time and case 1 will be applicable.My point is that with signed arithmetic there is no need to invert delta and switch from addition to deletion.
This ns value is used - at the end of the day - in ns_to_ktime function, which requires u64, so IMO it is easier to differentiate at this point, rather than introducing new logic in f.e. idpf_ptp_extend_ts.
But to remove this condition signed delta is enough, and it may work.
Quoted 931 lines
Quoted 931 lines
Quoted 58 lines
Quoted 58 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +57
-0+ +return ns; +} + +/** +* idpf_ptp_extend_ts - Convert a 40b timestamp to 64b nanoseconds +* @vport: Virtual port structure +* @in_tstamp: Ingress/egress timestamp value +* +* It is assumed that the caller verifies the timestamp is valid prior to +* calling this function. +* +* Extract the 32bit nominal nanoseconds and extend them. Use the cached PHC +* time stored in the device private PTP structure as the basis for timestamp +* extension. +* +* Return: Tx timestamp value extended to 64 bits. +*/ +u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u64 in_tstamp) +{ +struct idpf_ptp *ptp = vport->adapter->ptp; +unsigned long discard_time; + + discard_time = ptp->cached_phc_jiffies +2 *HZ ; + +if (time_is_before_jiffies (discard_time)) { +mutex_lock (&vport->tstamp_stats.tx_hwtstamp_lock); + vport->tstamp_stats.tx_hwtstamp_discarded++; +mutex_unlock (&vport->tstamp_stats.tx_hwtstamp_lock); + +return 0 ; + } + +return idpf_ptp_tstamp_extend_32b_to_64b (ptp->cached_phc_time, +lower_32_bits (in_tstamp)); +} + +/** +* idpf_ptp_request_ts - Request an available Tx timestamp index +* @tx_q: Transmit queue on which the Tx timestamp is requested +* @skb: The SKB to associate with this timestamp request +* @idx: Index of the Tx timestamp latch +* +* Request tx timestamp index negotiated during PTP init that will be set into +* Tx descriptor. +* +* Return: 0 and the index that can be provided to Tx descriptor on success, +* -errno otherwise. +*/ +int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +u32 *idx) +{ +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +struct list_head *head; + + head = &tx_q->cached_tstamp_caps->latches_free; +if (list_empty (head))Quoted 8 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c static int idpf_ptp_gpio_enable(struct ptp_clock_info *info, · line 596
Quoted 6 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +6
-0+return -ENOBUFS ; + +/* Get the index from the free latches list */ +spin_lock_bh (&tx_q->cached_tstamp_caps->lock_free); + ptp_tx_tstamp = list_first_entry(head, struct idpf_ptp_tx_tstamp, + list_member);Racy, as
list_emptyis tested before taking the spin lock?You're correct, I'll change it.
Quoted 862 lines
Quoted 767 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +105
-2+list_del (&ptp_tx_tstamp->list_member); +spin_unlock_bh (&tx_q->cached_tstamp_caps->lock_free); + + ptp_tx_tstamp->skb =skb_get (skb); +skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; + +/* Move the element to the used latches list */ +spin_lock_bh (&tx_q->cached_tstamp_caps->lock_in_use); +list_add (&ptp_tx_tstamp->list_member, + &tx_q->cached_tstamp_caps->latches_in_use); +spin_unlock_bh (&tx_q->cached_tstamp_caps->lock_in_use); + + *idx = ptp_tx_tstamp->idx; + +return 0 ; +} + +/** +* idpf_ptp_set_timestamp_mode - Setup driver for requested timestamp mode +* @vport: Virtual port structure +* @config: Hwtstamp settings requested or saved +* +* Return: 0 on success, -errno otherwise. +*/ +int idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config) +{ +switch (config->tx_type) { +case HWTSTAMP_TX_OFF : +case HWTSTAMP_TX_ON : +break ; +default : +return -EINVAL ; + } + + vport->tstamp_config.tx_type = config->tx_type; + +return 0 ; +} + +/** +* idpf_tstamp_task - Delayed task to handle Tx tstamps +* @work: work_struct handle +*/ +void idpf_tstamp_task (struct work_struct *work) +{ +struct idpf_vport *vport; + + vport = container_of(work, struct idpf_vport, tstamp_task); + +idpf_ptp_get_tx_tstamp (vport); +} + +/** +* idpf_ptp_do_aux_work - Do PTP periodic work +* @info: Driver's PTP info structure +* +* Return: Number of jiffies to periodic work. +*/ +static long idpf_ptp_do_aux_work (struct ptp_clock_info *info) +{ +struct idpf_adapter *adapter =idpf_ptp_info_to_adapter (info); + +idpf_ptp_update_cached_phctime (adapter); + +return msecs_to_jiffies (500 ); +} +/** * idpf_ptp_set_caps - Set PTP capabilities * @adapter: Driver specific private structure @@ -486,6 +683,7 @@ static void idpf_ptp_set_caps(const struct idpf_adapter *adapter) info->adjtime = idpf_ptp_adjtime; info->verify = idpf_ptp_verify_pin; info->enable = idpf_ptp_gpio_enable; + info->do_aux_work = idpf_ptp_do_aux_work;#if IS_ENABLED (CONFIG_ARM_ARCH_TIMER ) info->getcrosststamp = idpf_ptp_get_crosststamp;@@ -540,6 +738,8 @@ static void idpf_ptp_release_vport_tstamp(struct idpf_vport *vport)if (!idpf_ptp_get_vport_tstamp_capability (vport))return ; +cancel_work_sync (&vport->tstamp_task); +/* Remove list with free latches */ spin_lock (&vport->tx_tstamp_caps->lock_free);@@ -552,16 +752,21 @@ static void idpf_ptp_release_vport_tstamp(struct idpf_vport *vport)spin_unlock (&vport->tx_tstamp_caps->lock_free);/* Remove list with latches in use */ +mutex_lock (&vport->tstamp_stats.tx_hwtstamp_lock);spin_lock (&vport->tx_tstamp_caps->lock_in_use); head = &vport->tx_tstamp_caps->latches_in_use;list_for_each_entry_safe (ptp_tx_tstamp, tmp, head, list_member) { + vport->tstamp_stats.tx_hwtstamp_flushed++;list_del (&ptp_tx_tstamp->list_member);kfree (ptp_tx_tstamp); }spin_unlock (&vport->tx_tstamp_caps->lock_in_use); +mutex_unlock (&vport->tstamp_stats.tx_hwtstamp_lock); +mutex_destroy (&vport->tstamp_stats.tx_hwtstamp_lock); +kfree (vport->tx_tstamp_caps); vport->tx_tstamp_caps =NULL ; }@@ -578,6 +783,27 @@ static void idpf_ptp_release_tstamp(struct idpf_adapter *adapter)idpf_ptp_release_vport_tstamp (vport); } +/** +* idpf_ptp_get_txq_tstamp_capability - Verify the timestamping capability +* for a given tx queue. +* @txq: Transmit queue +* +* Since performing timestamp flows requires reading the device clock value and +* the support in the Control Plane, the function checks both factors and +* summarizes the support for the timestamping. +* +* Return: true if the timestamping is supported, false otherwise. +*/ +bool idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq) +{ +if (!txq || !txq->cached_tstamp_caps) +return false; +else if (txq->cached_tstamp_caps->access) +return true; +else +return false; +} +/** * idpf_ptp_init - Initialize PTP hardware clock support * @adapter: Driver specific private structure @@ -618,6 +844,8 @@ int idpf_ptp_init(struct idpf_adapter *adapter)if (err) goto free_ptp; +ptp_schedule_worker (adapter->ptp->clock,0 ); +/* Write the default increment time value if the clock adjustments * are enabled. */ @@ -641,6 +869,7 @@ int idpf_ptp_init(struct idpf_adapter *adapter)return 0 ; remove_clock: +ptp_cancel_worker_sync (adapter->ptp->clock);ptp_clock_unregister (adapter->ptp->clock); adapter->ptp->clock =NULL ;@@ -662,11 +891,14 @@ void idpf_ptp_release(struct idpf_adapter *adapter)if (!ptp)return ; -if (ptp->tx_tstamp_access !=IDPF_PTP_NONE ) +if (ptp->tx_tstamp_access !=IDPF_PTP_NONE && + ptp->get_dev_clk_time_access !=IDPF_PTP_NONE )idpf_ptp_release_tstamp (adapter); -if (ptp->clock) +if (ptp->clock) { +ptp_cancel_worker_sync (adapter->ptp->clock);ptp_clock_unregister (ptp->clock); + }kfree (ptp); adapter->ptp =NULL ;drivers/net/ethernet/intel/idpf/idpf_ptp.h +52
-0@@ -131,6 +131,7 @@ struct idpf_ptp_tx_tstamp {* @lock_in_use: the lock to the used latches list * @lock_free: the lock to free the latches list * @lock_status: the lock to the status tracker +* @access: indicates an access to Tx timestamp * @latches_free: the list of the free Tx timestamps latches * @latches_in_use: the list of the used Tx timestamps latches * @tx_tstamp_status: Tx tstamp status tracker @@ -142,6 +143,7 @@ struct idpf_ptp_vport_tx_tstamp_caps {spinlock_t lock_in_use;spinlock_t lock_free;spinlock_t lock_status; + bool access:1;struct list_head latches_free;struct list_head latches_in_use;struct idpf_ptp_tx_tstamp_status tx_tstamp_status[];@@ -155,6 +157,8 @@ struct idpf_ptp_vport_tx_tstamp_caps {* @base_incval: base increment value of the PTP clock * @max_adj: maximum adjustment of the PTP clock * @cmd: HW specific command masks +* @cached_phc_time: a cached copy of the PHC time for timestamp extension +* @cached_phc_jiffies: jiffies when cached_phc_time was last updated * @dev_clk_regs: the set of registers to access the device clock * @caps: PTP capabilities negotiated with the Control Plane * @get_dev_clk_time_access: access type for getting the device clock time @@ -172,6 +176,8 @@ struct idpf_ptp {u64 base_incval;u64 max_adj;struct idpf_ptp_cmd cmd; +u64 cached_phc_time; +unsigned long cached_phc_jiffies;struct idpf_ptp_dev_clk_regs dev_clk_regs;u32 caps; enum idpf_ptp_access get_dev_clk_time_access:2;@@ -181,6 +187,7 @@ struct idpf_ptp { enum idpf_ptp_access tx_tstamp_access:2; u8 rsv:6;struct idpf_ptp_secondary_mbx secondary_mbx; + };/** @@ -234,6 +241,7 @@ int idpf_ptp_init(struct idpf_adapter *adapter);void idpf_ptp_release (struct idpf_adapter *adapter);int idpf_ptp_get_caps (struct idpf_adapter *adapter);void idpf_ptp_get_features_access (const struct idpf_adapter *adapter); +bool idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq);int idpf_ptp_get_dev_clk_time (struct idpf_adapter *adapter,struct idpf_ptp_dev_timers *dev_clk_time); int idpf_ptp_get_cross_time(struct idpf_adapter *adapter,@@ -242,6 +250,14 @@ int idpf_ptp_set_dev_clk_time(struct idpf_adapter *adapter, u64 time);int idpf_ptp_adj_dev_clk_fine (struct idpf_adapter *adapter,u64 incval);int idpf_ptp_adj_dev_clk_time (struct idpf_adapter *adapter,s64 delta);int idpf_ptp_get_vport_tstamps_caps (struct idpf_vport *vport); +int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport); +int idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config); +u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u64 in_tstamp); +u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time,u32 in_timestamp); +int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +u32 *idx); +void idpf_tstamp_task (struct work_struct *work);#else /* CONFIG_PTP_1588_CLOCK */ static inline int idpf_ptp_init (struct idpf_adapter *adapter) {@@ -258,6 +274,12 @@ static inline int idpf_ptp_get_caps(struct idpf_adapter *adapter)static inline void idpf_ptp_get_features_access (const struct idpf_adapter *adapter) { } +static inline bool +idpf_ptp_get_txq_tstamp_capability (struct idpf_tx_queue *txq) +{ +return false; +} +static inline int idpf_ptp_get_dev_clk_time (struct idpf_adapter *adapter,struct idpf_ptp_dev_timers *dev_clk_time)@@ -295,5 +317,35 @@ static inline int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)return -EOPNOTSUPP ; } +static inline int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport) +{ +return -EOPNOTSUPP ; +} + +static inline int +idpf_ptp_set_timestamp_mode (struct idpf_vport *vport, +struct kernel_hwtstamp_config *config) +{ +return -EOPNOTSUPP ; +} + +static inline u64 idpf_ptp_extend_ts (struct idpf_vport *vport,u32 in_tstamp) +{ +return 0 ; +} + +static inline u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time, +u32 in_timestamp) +{ +return 0 ; +} + +static inline int idpf_ptp_request_ts (struct idpf_tx_queue *tx_q, +struct sk_buff *skb,u32 *idx) +{ +return -EOPNOTSUPP ; +} + +static inline void idpf_tstamp_task (struct work_struct *work) { }#endif /* CONFIG_PTP_1588_CLOCK */ #endif /* _IDPF_PTP_H */ drivers/net/ethernet/intel/idpf/idpf_txrx.c +132
-7@@ -5,6 +5,7 @@#include <net/libeth/tx.h> #include "idpf.h" +#include "idpf_ptp.h" #include "idpf_virtchnl.h" struct idpf_tx_stash {@@ -1107,6 +1108,8 @@ void idpf_vport_queues_rel(struct idpf_vport *vport)*/ static int idpf_vport_init_fast_path_txqs (struct idpf_vport *vport) { +struct idpf_ptp_vport_tx_tstamp_caps *caps = vport->tx_tstamp_caps; +struct work_struct *tstamp_task = &vport->tstamp_task;int i, j, k =0 ; vport->txqs = kcalloc(vport->num_txq, sizeof(*vport->txqs),@@ -1121,6 +1124,12 @@ static int idpf_vport_init_fast_path_txqs(struct idpf_vport *vport)for (j =0 ; j < tx_grp->num_txq; j++, k++) { vport->txqs[k] = tx_grp->txqs[j]; vport->txqs[k]->idx = k; + +if (!caps) +continue ; + + vport->txqs[k]->cached_tstamp_caps = caps; + vport->txqs[k]->tstamp_task = tstamp_task; } }@@ -1654,6 +1663,40 @@ static void idpf_tx_handle_sw_marker(struct idpf_tx_queue *tx_q)wake_up (&vport->sw_marker_wq); } +/** +* idpf_tx_read_tstamp - schedule a work to read Tx timestamp value +* @txq: queue to read the timestamp from +* @skb: socket buffer to provide Tx timestamp value +* +* Schedule a work to read Tx timestamp value generated once the packet is +* transmitted. +*/ +static void idpf_tx_read_tstamp (struct idpf_tx_queue *txq,struct sk_buff *skb) +{ +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct idpf_ptp_tx_tstamp_status *tx_tstamp_status; + + tx_tstamp_caps = txq->cached_tstamp_caps; +spin_lock_bh (&tx_tstamp_caps->lock_status); + +for (u32 i =0 ; i < tx_tstamp_caps->num_entries; i++) { + tx_tstamp_status = &tx_tstamp_caps->tx_tstamp_status[i]; +if (tx_tstamp_status->state !=IDPF_PTP_FREE ) +continue ; + + tx_tstamp_status->skb = skb; + tx_tstamp_status->state =IDPF_PTP_REQUEST ; + +/* Fetch timestamp from completion descriptor through +* virtchnl msg to report to stack. +*/ +queue_work (system_unbound_wq, txq->tstamp_task); +break ; + } + +spin_unlock_bh (&tx_tstamp_caps->lock_status); +} +/** * idpf_tx_clean_stashed_bufs - clean bufs that were stored for * out of order completions @@ -1682,6 +1725,11 @@ static void idpf_tx_clean_stashed_bufs(struct idpf_tx_queue *txq,continue ;hash_del (&stash->hlist); + +if (stash->buf.type ==LIBETH_SQE_SKB && + (skb_shinfo (stash->buf.skb)->tx_flags &SKBTX_IN_PROGRESS )) +idpf_tx_read_tstamp (txq, stash->buf.skb); +libeth_tx_complete (&stash->buf, &cp);/* Push shadow buf back onto stack */ @@ -1876,8 +1924,12 @@ static bool idpf_tx_clean_buf_ring(struct idpf_tx_queue *txq, u16 compl_tag, idpf_tx_buf_compl_tag(tx_buf) != compl_tag))return false; -if (tx_buf->type ==LIBETH_SQE_SKB ) +if (tx_buf->type ==LIBETH_SQE_SKB ) { +if (skb_shinfo (tx_buf->skb)->tx_flags &SKBTX_IN_PROGRESS ) +idpf_tx_read_tstamp (txq, tx_buf->skb); +libeth_tx_complete (tx_buf, &cp); + }idpf_tx_clean_buf_ring_bump_ntc (txq, idx, tx_buf);@@ -2296,7 +2348,7 @@ void idpf_tx_dma_map_error(struct idpf_tx_queue *txq, struct sk_buff *skb,* descriptor. Reset that here. */ tx_desc = &txq->flex_tx[idx]; -memset (tx_desc,0 ,sizeof (struct idpf_flex_tx_ctx_desc )); +memset (tx_desc,0 ,sizeof (*tx_desc));if (idx ==0 ) idx = txq->desc_count; idx--;@@ -2699,10 +2751,10 @@ static bool idpf_chk_linearize(struct sk_buff *skb, unsigned int max_bufs,* Since the TX buffer rings mimics the descriptor ring, update the tx buffer * ring entry to reflect that this index is a context descriptor */ -static struct idpf_flex_tx_ctx_desc * +static union idpf_flex_tx_ctx_desc *idpf_tx_splitq_get_ctx_desc (struct idpf_tx_queue *txq) { -struct idpf_flex_tx_ctx_desc *desc; +union idpf_flex_tx_ctx_desc *desc;int i = txq->next_to_use; txq->tx_buf[i].type =LIBETH_SQE_CTX ;@@ -2732,6 +2784,73 @@ netdev_tx_t idpf_tx_drop_skb(struct idpf_tx_queue *tx_q, struct sk_buff *skb)return NETDEV_TX_OK ; } +#if (IS_ENABLED (CONFIG_PTP_1588_CLOCK )) +/** +* idpf_tx_tstamp - set up context descriptor for hardware timestamp +* @tx_q: queue to send buffer on +* @skb: pointer to the SKB we're sending +* @off: pointer to the offload struct +* +* Return: Positive index number on success, negative otherwise. +*/ +static int idpf_tx_tstamp (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +struct idpf_tx_offload_params *off) +{ +int err, idx; + +/* only timestamp the outbound packet if the user has requested it */ +if (likely (!(skb_shinfo (skb)->tx_flags &SKBTX_HW_TSTAMP ))) +return -1 ; + +if (!idpf_ptp_get_txq_tstamp_capability (tx_q)) +return -1 ; + +/* Tx timestamps cannot be sampled when doing TSO */ +if (off->tx_flags &IDPF_TX_FLAGS_TSO ) +return -1 ; + +/* Grab an open timestamp slot */ + err =idpf_ptp_request_ts (tx_q, skb, &idx); +if (err) { +u64_stats_update_begin (&tx_q->stats_sync); +u64_stats_inc (&tx_q->q_stats.tstamp_skipped); +u64_stats_update_end (&tx_q->stats_sync); + +return -1 ; + } + + off->tx_flags |=IDPF_TX_FLAGS_TSYN ; + +return idx; +} + +/** +* idpf_tx_set_tstamp_desc - Set the Tx descriptor fields needed to generate +* PHY Tx timestamp +* @ctx_desc: Context descriptor +* @idx: Index of the Tx timestamp latch +*/ +static void idpf_tx_set_tstamp_desc (union idpf_flex_tx_ctx_desc *ctx_desc, +u32 idx) +{ + ctx_desc->tsyn.qw1 =le64_encode_bits (IDPF_TX_DESC_DTYPE_CTX , +IDPF_TX_CTX_DTYPE_M ) | +le64_encode_bits (IDPF_TX_CTX_DESC_TSYN , +IDPF_TX_CTX_CMD_M ) | +le64_encode_bits (idx,IDPF_TX_CTX_TSYN_REG_M ); +} +#else /* CONFIG_PTP_1588_CLOCK */ +static int idpf_tx_tstamp (struct idpf_tx_queue *tx_q,struct sk_buff *skb, +struct idpf_tx_offload_params *off) +{ +return -1 ; +} + +static void idpf_tx_set_tstamp_desc (union idpf_flex_tx_ctx_desc *ctx_desc, +u32 idx) +{ } +#endif /* CONFIG_PTP_1588_CLOCK */ +/** * idpf_tx_splitq_frame - Sends buffer on Tx ring using flex descriptors * @skb: send buffer @@ -2743,9 +2862,10 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb, struct idpf_tx_queue *tx_q) {struct idpf_tx_splitq_params tx_params = { }; +union idpf_flex_tx_ctx_desc *ctx_desc;struct idpf_tx_buf *first;unsigned int count; -int tso; +int tso, idx; count =idpf_tx_desc_count_required (tx_q, skb);if (unlikely (!count))@@ -2765,8 +2885,7 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,if (tso) {/* If tso is needed, set up context desc */ -struct idpf_flex_tx_ctx_desc *ctx_desc = -idpf_tx_splitq_get_ctx_desc (tx_q); + ctx_desc =idpf_tx_splitq_get_ctx_desc (tx_q); ctx_desc->tso.qw1.cmd_dtype = cpu_to_le16(IDPF_TX_DESC_DTYPE_FLEX_TSO_CTX |@@ -2784,6 +2903,12 @@ static netdev_tx_t idpf_tx_splitq_frame(struct sk_buff *skb,u64_stats_update_end (&tx_q->stats_sync); } + idx =idpf_tx_tstamp (tx_q, skb, &tx_params.offload); +if (idx !=-1 ) { + ctx_desc =idpf_tx_splitq_get_ctx_desc (tx_q); +idpf_tx_set_tstamp_desc (ctx_desc, idx); + } +/* record the location of the first descriptor for this packet */ first = &tx_q->tx_buf[tx_q->next_to_use]; first->skb = skb;drivers/net/ethernet/intel/idpf/idpf_txrx.h +9
-2@@ -142,6 +142,7 @@ do { \#define IDPF_TX_FLAGS_IPV4 BIT(1)#define IDPF_TX_FLAGS_IPV6 BIT(2)#define IDPF_TX_FLAGS_TUNNEL BIT(3) +#define IDPF_TX_FLAGS_TSYN BIT(4)union idpf_tx_flex_desc {struct idpf_flex_tx_desc q;/* queue based scheduling */ @@ -445,6 +446,7 @@ struct idpf_tx_queue_stats {u64_stats_t q_busy;u64_stats_t skb_drops;u64_stats_t dma_map_errs; +u64_stats_t tstamp_skipped; };#define IDPF_ITR_DYNAMIC 1@@ -619,6 +621,8 @@ libeth_cacheline_set_assert(struct idpf_rx_queue, 64,* @compl_tag_bufid_m: Completion tag buffer id mask * @compl_tag_cur_gen: Used to keep track of current completion tag generation * @compl_tag_gen_max: To determine when compl_tag_cur_gen should be reset +* @cached_tstamp_caps: Tx timestamp capabilities negotiated with the CP +* @tstamp_task: Work that handles Tx timestamp read * @stats_sync: See struct u64_stats_sync * @q_stats: See union idpf_tx_queue_stats * @q_id: Queue id @@ -632,7 +636,7 @@ struct idpf_tx_queue {struct idpf_base_tx_desc *base_tx;struct idpf_base_tx_ctx_desc *base_ctx;union idpf_tx_flex_desc *flex_tx; -struct idpf_flex_tx_ctx_desc *flex_ctx; +union idpf_flex_tx_ctx_desc *flex_ctx;void *desc_ring; };@@ -668,6 +672,9 @@ struct idpf_tx_queue {u16 compl_tag_cur_gen;u16 compl_tag_gen_max; +struct idpf_ptp_vport_tx_tstamp_caps *cached_tstamp_caps; +struct work_struct *tstamp_task; +struct u64_stats_sync stats_sync;struct idpf_tx_queue_stats q_stats;__cacheline_group_end_aligned (read_write);@@ -681,7 +688,7 @@ struct idpf_tx_queue {__cacheline_group_end_aligned (cold); }; libeth_cacheline_set_assert(struct idpf_tx_queue, 64, -88 +sizeof (struct u64_stats_sync ), +112 +sizeof (struct u64_stats_sync ), 24);/** drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +5
-1@@ -3163,8 +3163,12 @@ void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q)return ; err =idpf_ptp_get_vport_tstamps_caps (vport); -if (err) +if (err) {pci_dbg (vport->adapter->pdev,"Tx timestamping not supported\n" ); +return ; + } + +INIT_WORK (&vport->tstamp_task, idpf_tstamp_task); }/** drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +146
-0@@ -382,7 +382,9 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) goto get_tstamp_caps_out; } + tstamp_caps->access = true; tstamp_caps->num_entries = num_latches; +INIT_LIST_HEAD (&tstamp_caps->latches_in_use);INIT_LIST_HEAD (&tstamp_caps->latches_free);@@ -425,6 +427,9 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) vport->tx_tstamp_caps = tstamp_caps;kfree (rcv_tx_tstamp_caps); +/* Init mutex to protect tstamp statistics */ +mutex_init (&vport->tstamp_stats.tx_hwtstamp_lock); +return 0 ; err_free_ptp_tx_stamp_list:@@ -440,3 +445,233 @@ int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)return err; } + +/** +* idpf_ptp_update_tstamp_tracker - Update the Tx timestamp tracker based on +* the skb compatibility. +* @caps: Tx timestamp capabilities that monitor the latch status +* @skb: skb for which the tstamp value is returned through virtchnl message +* @current_state: Current state of the Tx timestamp latch +* @expected_state: Expected state of the Tx timestamp latch +* +* Find a proper skb tracker for which the Tx timestamp is received and change +* the state to expected value. +* +* Return: true if the tracker has been found and updated, false otherwise. +*/ +static bool +idpf_ptp_update_tstamp_tracker (struct idpf_ptp_vport_tx_tstamp_caps *caps, +struct sk_buff *skb, +enum idpf_ptp_tx_tstamp_state current_state, +enum idpf_ptp_tx_tstamp_state expected_state) +{ +bool updated = false; + +spin_lock (&caps->lock_status); +for (u16 i =0 ; i < caps->num_entries; i++) { +struct idpf_ptp_tx_tstamp_status *status; + + status = &caps->tx_tstamp_status[i]; + +if (skb == status->skb && status->state == current_state) { + status->state = expected_state; + updated = true; +break ; + } + } +spin_unlock (&caps->lock_status); + +return updated; +} + +/** +* idpf_ptp_get_tstamp_value - Get the Tx timestamp value and provide it +* back to the skb. +* @vport: Virtual port structure +* @tstamp_latch: Tx timestamp latch structure fulfilled by the Control Plane +* @ptp_tx_tstamp: Tx timestamp latch to add to the free list +* +* Read the value of the Tx timestamp for a given latch received from the +* Control Plane, extend it to 64 bit and provide back to the skb. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +idpf_ptp_get_tstamp_value (struct idpf_vport *vport, +struct virtchnl2_ptp_tx_tstamp_latch *tstamp_latch, +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp) +{ +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct skb_shared_hwtstamps shhwtstamps; +bool state_upd = false; +u8 tstamp_ns_lo_bit; +u64 tstamp; + + tx_tstamp_caps = vport->tx_tstamp_caps; + tstamp_ns_lo_bit = tx_tstamp_caps->tstamp_ns_lo_bit; + + ptp_tx_tstamp->tstamp =le64_to_cpu (tstamp_latch->tstamp); + ptp_tx_tstamp->tstamp >>= tstamp_ns_lo_bit; + + state_upd =idpf_ptp_update_tstamp_tracker (tx_tstamp_caps, + ptp_tx_tstamp->skb, +IDPF_PTP_READ_VALUE , +IDPF_PTP_FREE ); +if (!state_upd) +return -EINVAL ; + + tstamp =idpf_ptp_extend_ts (vport, ptp_tx_tstamp->tstamp); + shhwtstamps.hwtstamp =ns_to_ktime (tstamp); +skb_tstamp_tx (ptp_tx_tstamp->skb, &shhwtstamps); +consume_skb (ptp_tx_tstamp->skb); + +spin_lock (&tx_tstamp_caps->lock_free); +list_add (&ptp_tx_tstamp->list_member, + &tx_tstamp_caps->latches_free); +spin_unlock (&tx_tstamp_caps->lock_free); + +return 0 ; +} + +/** +* idpf_ptp_get_tx_tstamp_async_handler - Async callback for getting Tx tstamps +* @adapter: Driver specific private structure +* @xn: transaction for message +* @ctlq_msg: received message +* +* Read the tstamps Tx tstamp values from a received message and put them +* directly to the skb. The number of timestamps to read is specified by +* the virtchnl message. +* +* Return: 0 on success, -errno otherwise. +*/ +static int +idpf_ptp_get_tx_tstamp_async_handler (struct idpf_adapter *adapter, +struct idpf_vc_xn *xn, +const struct idpf_ctlq_msg *ctlq_msg) +{ +struct virtchnl2_ptp_get_vport_tx_tstamp_latches *recv_tx_tstamp_msg; +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct virtchnl2_ptp_tx_tstamp_latch tstamp_latch; +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +struct idpf_vport *tstamp_vport =NULL ; +struct list_head *head; +u16 num_latches; +u32 vport_id; +int err; + + recv_tx_tstamp_msg = ctlq_msg->ctx.indirect.payload->va; + vport_id =le32_to_cpu (recv_tx_tstamp_msg->vport_id); + +idpf_for_each_vport (adapter, vport) { +if (!vport) +continue ; + +if (vport->vport_id == vport_id) { + tstamp_vport = vport; +break ; + } + } + +if (!tstamp_vport || !tstamp_vport->tx_tstamp_caps) +return -EINVAL ; + + tx_tstamp_caps = tstamp_vport->tx_tstamp_caps; + num_latches =le16_to_cpu (recv_tx_tstamp_msg->num_latches); + + head = &tx_tstamp_caps->latches_in_use; +spin_lock (&tx_tstamp_caps->lock_in_use); + +for (u16 i =0 ; i < num_latches; i++) { + tstamp_latch = recv_tx_tstamp_msg->tstamp_latches[i]; + +if (!tstamp_latch.valid)drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport) · line 598
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +10
-0+continue ; + +if (list_empty (head)) { + err = -ENOBUFS ; + goto unlock; + } + +list_for_each_entry (ptp_tx_tstamp, head, list_member) { +if (tstamp_latch.index == ptp_tx_tstamp->idx) { +list_del (&ptp_tx_tstamp->list_member);need
list_for_each_entry_safewhen callinglist_delon members.Quoted 82 lines
drivers/net/ethernet/intel/idpf/idpf_virtchnl_ptp.c +79
-0+ err =idpf_ptp_get_tstamp_value (tstamp_vport, + &tstamp_latch, + ptp_tx_tstamp); +if (err) + goto unlock; + +break ; + } + } + } + +unlock: +spin_unlock (&tx_tstamp_caps->lock_in_use); + +return err; +} + +/** +* idpf_ptp_get_tx_tstamp - Send virtchnl get Tx timestamp latches message +* @vport: Virtual port structure +* +* Send virtchnl get Tx tstamp message to read the value of the HW timestamp. +* The message contains a list of indexes set in the Tx descriptors. +* +* Return: 0 on success, -errno otherwise. +*/ +int idpf_ptp_get_tx_tstamp (struct idpf_vport *vport) +{ +struct virtchnl2_ptp_get_vport_tx_tstamp_latches *send_tx_tstamp_msg; +struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps; +struct idpf_vc_xn_params xn_params = { + .vc_op =VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP , + .timeout_ms =IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC , + .async = true, + .async_handler = idpf_ptp_get_tx_tstamp_async_handler, + }; +struct idpf_ptp_tx_tstamp *ptp_tx_tstamp; +int reply_sz, size, msg_size; +struct list_head *head; +bool state_upd; +u16 id =0 ; + + tx_tstamp_caps = vport->tx_tstamp_caps; + head = &tx_tstamp_caps->latches_in_use; + + size =struct_size (send_tx_tstamp_msg, tstamp_latches, + tx_tstamp_caps->num_entries); + send_tx_tstamp_msg =kzalloc (size,GFP_KERNEL ); +if (!send_tx_tstamp_msg) +return -ENOMEM ; + +spin_lock (&tx_tstamp_caps->lock_in_use); +list_for_each_entry (ptp_tx_tstamp, head, list_member) { +u8 idx; + + state_upd =idpf_ptp_update_tstamp_tracker (tx_tstamp_caps, + ptp_tx_tstamp->skb, +IDPF_PTP_REQUEST , +IDPF_PTP_READ_VALUE ); +if (!state_upd) +continue ; + + idx = ptp_tx_tstamp->idx; + send_tx_tstamp_msg->tstamp_latches[id].index = idx; + id++; + } +spin_unlock (&tx_tstamp_caps->lock_in_use); + + msg_size =struct_size (send_tx_tstamp_msg, tstamp_latches, id); + send_tx_tstamp_msg->vport_id =cpu_to_le32 (vport->vport_id); + send_tx_tstamp_msg->num_latches =cpu_to_le16 (id); + xn_params.send_buf.iov_base = send_tx_tstamp_msg; + xn_params.send_buf.iov_len = msg_size; + + reply_sz =idpf_vc_xn_exec (vport->adapter, &xn_params); +kfree (send_tx_tstamp_msg); + +return min (reply_sz,0 ); +}Signature · 1 line
2.31.1
RE: [PATCH v3 iwl-next 08/10] idpf: add Tx timestamp flows
Quoted 58 lines · Milena
Quoted 56 lines · On 01/10/2025 10:34PM Willem de Bruijn wrote:
Quoted 55 lines
Quoted 32 lines
Quoted 31 lines
Add functions to request Tx timestamp for the PTP packets, read the Tx timestamp when the completion tag for that packet is being received, extend the Tx timestamp value and set the supported timestamping modes.
Tx timestamp is requested for the PTP packets by setting a TSYN bit and index value in the Tx context descriptor. The driver assumption is that the Tx timestamp value is ready to be read when the completion tag is received. Then the driver schedules delayed work and the Tx timestamp value read is requested through virtchnl message. At the end, the Tx timestamp value is extended to 64-bit and provided back to the skb.
Co-developed-by Josh Hay <[email protected]>Signed-off-by Josh Hay <[email protected]>Signed-off-by Milena Olech <[email protected]>---
v2 -> v3: changeget_timestamp_filterfunction name, split stats into vport-based and tx queue-based
v1 -> v2: add timestamping stats, use ndo_hwtamp_get/ndo_hwstamp_setdrivers/net/ethernet/intel/idpf/idpf.h | 20 ++ .../net/ethernet/intel/idpf/idpf_ethtool.c | 69 ++++- .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 13 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 47 ++++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 236 +++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_ptp.h | 52 ++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 139 ++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.h | 11 +- .../net/ethernet/intel/idpf/idpf_virtchnl.c | 6 +- .../ethernet/intel/idpf/idpf_virtchnl_ptp.c | 235 +++++++++++++++++ 10 files changed, 814 insertions(+), 14 deletions(-)Quoted 16 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c static int idpf_get_link_ksettings(struct net_device *netdev, · line 1339
Quoted 13 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +13
-0+/** +* idpf_get_timestamp_filters - Get the supported timestamping mode +* @vport: Virtual port structure +* @info: ethtool timestamping info structure +* +* Get the Tx/Rx timestamp filters. +*/ +static void idpf_get_timestamp_filters (const struct idpf_vport *vport, +struct kernel_ethtool_ts_info *info) +{ +if (!vport->tx_tstamp_caps || + vport->adapter->ptp->tx_tstamp_access ==IDPF_PTP_NONE ) +return ;Is making
SOF_TIMESTAMPING_RX_HARDWAREandSOF_TIMESTAMPING_RAW_HARDWAREconditional ontx_tstamp_accessintentional?Hmmm, good catch.
I guess I will change theSOF_TIMESTAMPING_RX_HARDWAREto be not conditional.About the
SOF_TIMESTAMPING_RAW_HARDWARE- it should rely on thetx_statmp_access.
Quoted 7 lines
Quoted 1 line
For Tx, but it also applies to Rx.
Right, there was a misunderstanding because the documentation says:
"Report hardware timestamps as generated by
SOF_TIMESTAMPING_TX_HARDWAREwhen available."So I assumed that it's Tx only.
Indeed. This was fixed fairly recently in commit e503f82e304b. It now reads
"SOF_TIMESTAMPING_RAW_HARDWARE:
Report hardware timestamps as generated by SOF_TIMESTAMPING_TX_HARDWARE or SOF_TIMESTAMPING_RX_HARDWARE when available.
"
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 12 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +12
-0+ + info->so_timestamping =SOF_TIMESTAMPING_TX_SOFTWARE | +SOF_TIMESTAMPING_TX_HARDWARE | +SOF_TIMESTAMPING_RX_HARDWARE | +SOF_TIMESTAMPING_RAW_HARDWARE ; + + info->tx_types =BIT (HWTSTAMP_TX_OFF ) |BIT (HWTSTAMP_TX_ON ); +} + + +static int idpf_hwtstamp_get (struct net_device *netdev, +struct kernel_hwtstamp_config *config)drivers/net/ethernet/intel/idpf/idpf_ethtool.c static int idpf_get_link_ksettings(struct net_device *netdev,
Quoted 10 lines
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +10
-0+{ +struct idpf_adapter *adapter =idpf_netdev_to_adapter (netdev); +struct idpf_vport *vport; + +idpf_vport_cfg_lock (adapter); + vport =idpf_netdev_to_vport (netdev); + +if (!idpf_ptp_get_vport_tstamp_capability (vport)) { +idpf_vport_cfg_unlock (adapter); +return -EOPNOTSUPP ;Should this return an empty config and return 0, rather than return error?
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I'd prefer to return NOTSUPP, as the feature itself relies on the CP policy.
Does that make ethtool -T $DEV fail? It should ideally succeed while only advertising software receive timestamping (which is implemented device independent).
Ok, I'll change then.
I did not actually check whether it would return in failure at the application layer, to be clear. Just saying that if that would be the consequence, then that would not be good.
Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Quoted 19 lines
Quoted 19 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +19
-0+/** +* idpf_ptp_tstamp_extend_32b_to_64b - Convert a 32b nanoseconds Tx timestamp +* to 64b. +* @cached_phc_time: recently cached copy of PHC time +* @in_timestamp: Ingress/egress 32b nanoseconds timestamp value +* +* Hardware captures timestamps which contain only 32 bits of nominal +* nanoseconds, as opposed to the 64bit timestamps that the stack expects. +* +* Return: Tx timestamp value extended to 64 bits based on cached PHC time. +*/ +u64 idpf_ptp_tstamp_extend_32b_to_64b (u64 cached_phc_time,u32 in_timestamp) +{ +u32 delta, phc_lo; +u64 ns; + + phc_lo =lower_32_bits (cached_phc_time); + delta = in_timestamp - phc_lo; +Quoted 8 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c static int idpf_ptp_gpio_enable(struct ptp_clock_info *info, · line 533
Quoted 6 lines
drivers/net/ethernet/intel/idpf/idpf_ptp.c +6
-0+if (delta >S32_MAX ) { + delta = phc_lo - in_timestamp; + ns = cached_phc_time - delta; + }else { + ns = cached_phc_time + delta; + }If using s64 delta and ns, no need for branch?
To make it more readable, I'll change the condition in v4. I'll check if the
phc_lois greater thanin_stamp.If
phc_lois bigger, then tx tstamp value was captured before caching PHC time and case 1 will be applicable.
Quoted 8 lines
Quoted 2 lines
My point is that with signed arithmetic there is no need to invert delta and switch from addition to deletion.
This ns value is used - at the end of the day - in
ns_to_ktimefunction, which requires u64, so IMO it is easier to differentiate at this point, rather than introducing new logic in f.e.idpf_ptp_extend_ts.But to remove this condition signed delta is enough, and it may work.
Just a suggestion. Feel free to leave as is if you prefer.
PATCH v3 9/10 idpf: add support for Rx timestamping
In reply to Milena OlechAdd Rx timestamp function when the Rx timestamp value is read directly from the Rx descriptor. In order to extend the Rx timestamp value to 64 bit in hot path, the PHC time is cached in the receive groups. Add supported Rx timestamp modes.
---
v2 -> v3: add disable Rx timestamp
v1 -> v2: extend commit message
drivers/net/ethernet/intel/idpf/idpf_ptp.c | 86 ++++++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 30 +++++++ drivers/net/ethernet/intel/idpf/idpf_txrx.h | 7 +- 3 files changed, 121 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_ptp.c +85 -1
@@ -317,12 +317,41 @@ static int idpf_ptp_gettimex64(struct ptp_clock_info *info,return 0 ; } +/** +* idpf_ptp_update_phctime_rxq_grp - Update the cached PHC time for a given Rx +* queue group. +* @grp: receive queue group in which Rx timestamp is enabled +* @split: Indicates whether the queue model is split or single queue +* @systime: Cached system time +*/ +static void +idpf_ptp_update_phctime_rxq_grp (const struct idpf_rxq_group *grp,bool split, +u64 systime) +{ +struct idpf_rx_queue *rxq; +u16 i; + +if (!split) { +for (i =0 ; i < grp->singleq.num_rxq; i++) { + rxq = grp->singleq.rxqs[i]; +if (rxq) +WRITE_ONCE (rxq->cached_phc_time, systime); + } + }else { +for (i =0 ; i < grp->splitq.num_rxq_sets; i++) { + rxq = &grp->splitq.rxq_sets[i]->rxq; +if (rxq) +WRITE_ONCE (rxq->cached_phc_time, systime); + } + } +} +/** * idpf_ptp_update_cached_phctime - Update the cached PHC time values * @adapter: Driver specific private structure * * This function updates the system time values which are cached in the adapter -* structure. +* structure and the Rx queues. * * This function must be called periodically to ensure that the cached value * is never more than 2 seconds old.
@@ -345,6 +374,21 @@ static int idpf_ptp_update_cached_phctime(struct idpf_adapter *adapter)WRITE_ONCE (adapter->ptp->cached_phc_time, systime);WRITE_ONCE (adapter->ptp->cached_phc_jiffies, jiffies); +idpf_for_each_vport (adapter, vport) { +bool split; + +if (!vport || !vport->rxq_grps) +continue ; + + split =idpf_is_queue_model_split (vport->rxq_model); + +for (u16 i =0 ; i < vport->num_rxq_grp; i++) { +struct idpf_rxq_group *grp = &vport->rxq_grps[i]; + +idpf_ptp_update_phctime_rxq_grp (grp, split, systime); + } + } +return 0 ; }
@@ -611,6 +655,45 @@ int idpf_ptp_request_ts(struct idpf_tx_queue *tx_q, struct sk_buff *skb,return 0 ; } +/** +* idpf_ptp_set_rx_tstamp - Enable or disable Rx timestamping +* @vport: Virtual port structure +* @rx_filter: bool value for whether timestamps are enabled or disabled +*/ +static void idpf_ptp_set_rx_tstamp (struct idpf_vport *vport,int rx_filter) +{ +bool enable = true, splitq; + + vport->tstamp_config.rx_filter = rx_filter; + splitq =idpf_is_queue_model_split (vport->rxq_model); + +if (rx_filter ==HWTSTAMP_FILTER_NONE ) + enable = false; + +for (u16 i =0 ; i < vport->num_rxq_grp; i++) { +struct idpf_rxq_group *grp = &vport->rxq_grps[i]; +struct idpf_rx_queue *rx_queue; +u16 j, num_rxq; + +if (splitq) + num_rxq = grp->splitq.num_rxq_sets; +else + num_rxq = grp->singleq.num_rxq; + +for (j =0 ; j < num_rxq; j++) { +if (splitq) + rx_queue = &grp->splitq.rxq_sets[j]->rxq; +else + rx_queue = grp->singleq.rxqs[j]; + +if (enable) +idpf_queue_set (PTP , rx_queue); +else +idpf_queue_clear (PTP , rx_queue); + } + } +} +/** * idpf_ptp_set_timestamp_mode - Setup driver for requested timestamp mode * @vport: Virtual port structure
@@ -630,6 +713,7 @@ int idpf_ptp_set_timestamp_mode(struct idpf_vport *vport, } vport->tstamp_config.tx_type = config->tx_type; +idpf_ptp_set_rx_tstamp (vport, config->rx_filter);return 0 ; }
drivers/net/ethernet/intel/idpf/idpf_txrx.c +30 -0
@@ -3171,6 +3171,33 @@ static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb,return 0 ; } +/** +* idpf_rx_hwtstamp - check for an RX timestamp and pass up the stack +* @rxq: pointer to the rx queue that receives the timestamp +* @rx_desc: pointer to rx descriptor containing timestamp +* @skb: skb to put timestamp in +*/ +static void +idpf_rx_hwtstamp (const struct idpf_rx_queue *rxq, +const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc, +struct sk_buff *skb) +{ +u64 cached_time, ts_ns; +u32 ts_high; + +if (!(rx_desc->ts_low &VIRTCHNL2_RX_FLEX_TSTAMP_VALID )) +return ; + + cached_time =READ_ONCE (rxq->cached_phc_time); + + ts_high =le32_to_cpu (rx_desc->ts_high); + ts_ns =idpf_ptp_tstamp_extend_32b_to_64b (cached_time, ts_high); + + *skb_hwtstamps (skb) = (struct skb_shared_hwtstamps ) { + .hwtstamp =ns_to_ktime (ts_ns), + }; +} +/** * idpf_rx_process_skb_fields - Populate skb header fields from Rx descriptor * @rxq: Rx descriptor ring packet is being transacted on
@@ -3196,6 +3223,9 @@ idpf_rx_process_skb_fields(struct idpf_rx_queue *rxq, struct sk_buff *skb,/* process RSS/hash */ idpf_rx_hash (rxq, skb, rx_desc, decoded); +if (idpf_queue_has (PTP , rxq)) +idpf_rx_hwtstamp (rxq, rx_desc, skb); + skb->protocol =eth_type_trans (skb, rxq->netdev); if (le16_get_bits(rx_desc->hdrlen_flags,
drivers/net/ethernet/intel/idpf/idpf_txrx.h +6 -1
@@ -290,6 +290,8 @@ struct idpf_ptype_state {* @__IDPF_Q_POLL_MODE: Enable poll mode * @__IDPF_Q_CRC_EN: enable CRC offload in singleq mode * @__IDPF_Q_HSPLIT_EN: enable header split on Rx (splitq) +* @__IDPF_Q_PTP: indicates whether the Rx timestamping is enabled for the +* queue * @__IDPF_Q_FLAGS_NBITS: Must be last */ enum idpf_queue_flags_t {
@@ -300,6 +302,7 @@ enum idpf_queue_flags_t { __IDPF_Q_POLL_MODE, __IDPF_Q_CRC_EN, __IDPF_Q_HSPLIT_EN, + __IDPF_Q_PTP, __IDPF_Q_FLAGS_NBITS, };
@@ -498,6 +501,7 @@ struct idpf_txq_stash {* @next_to_alloc: RX buffer to allocate at * @skb: Pointer to the skb * @truesize: data buffer truesize in singleq +* @cached_phc_time: Cached PHC time for the Rx queue * @stats_sync: See struct u64_stats_sync * @q_stats: See union idpf_rx_queue_stats * @q_id: Queue id
@@ -545,6 +549,7 @@ struct idpf_rx_queue {struct sk_buff *skb;u32 truesize; +u64 cached_phc_time;struct u64_stats_sync stats_sync;struct idpf_rx_queue_stats q_stats;
@@ -564,7 +569,7 @@ struct idpf_rx_queue {__cacheline_group_end_aligned (cold); }; libeth_cacheline_set_assert(struct idpf_rx_queue, 64, -80 +sizeof (struct u64_stats_sync ), +88 +sizeof (struct u64_stats_sync ), 32);/**
Signature · 1 line
2.31.1
Re: [PATCH v3 iwl-next 09/10] idpf: add support for Rx timestamping
Quoted 6 lines · Milena Olech
Add Rx timestamp function when the Rx timestamp value is read directly from the Rx descriptor. In order to extend the Rx timestamp value to 64 bit in hot path, the PHC time is cached in the receive groups. Add supported Rx timestamp modes.
Signed-off-by Milena Olech <[email protected]>
PATCH v3 10/10 idpf: change the method for mailbox workqueue allocation
In reply to Milena OlechSince workqueues are created per CPU, the works scheduled to this workqueues are run on the CPU they were assigned. It may result in overloaded CPU that is not able to handle virtchnl messages in relatively short time. Allocating workqueue with WQ_UNBOUND and WQ_HIGHPRI flags allows scheduler to queue virtchl messages on less loaded CPUs, what eliminates delays.
--- drivers/net/ethernet/intel/idpf/idpf_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_main.c +2 -2
@@ -220,8 +220,8 @@ static int idpf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_serv_wq_alloc; } - adapter->mbx_wq =alloc_workqueue ("%s-%s-mbx" ,0 ,0 , -dev_driver_string (dev), + adapter->mbx_wq =alloc_workqueue ("%s-%s-mbx" ,WQ_UNBOUND |WQ_HIGHPRI , +0 ,dev_driver_string (dev),dev_name (dev));if (!adapter->mbx_wq) {dev_err (dev,"Failed to allocate mailbox workqueue\n" );
Signature · 1 line
2.31.1