idpf: add initial PTP support
Subsystems (3)
v6 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.
v5 -> v6: change locking mechanism in get_ts_info, clean timestamp fields when preparing flow descriptor, add Rx filter
v4 -> v5: fix spin unlock when Tx timestamp index is requested v3 -> v4: change timestamp filters dependent on Tx timestamp cap, rewrite function that extends Tx timestamp value, minor fixes 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 | 74 +- .../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 | 45 + drivers/net/ethernet/intel/idpf/idpf_main.c | 9 +- drivers/net/ethernet/intel/idpf/idpf_ptp.c | 983 ++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_ptp.h | 350 +++++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 174 +++- 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, 2858 insertions(+), 102 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: d142eb657bb0367effe3c1a43f170dda379176b2
Signature · 1 line
2.31.1
PATCH v6 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
@@ -530,6 +530,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;
@@ -587,6 +588,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
@@ -163,6 +163,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)
@@ -900,7 +901,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 = ∩︀
@@ -3029,6 +3031,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
@@ -3091,6 +3097,7 @@ void idpf_vc_core_deinit(struct idpf_adapter *adapter)if (!remove_in_prog)idpf_vc_xn_shutdown (adapter->vcxn_mngr); +idpf_ptp_release (adapter);idpf_deinit_task (adapter);idpf_intr_rel (adapter);
Signature · 1 line
2.31.1
PATCH v6 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 v6 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 v6 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 v6 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 v6 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 v6 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;
@@ -3133,6 +3135,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;
@@ -3167,6 +3170,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
PATCH v6 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.
---
v5 -> v6: change locking mechanism in get_ts_info, clean timestamp fields when preparing flow descriptor to prevent collisions with PHY timestamping
v4 -> v5: fix the spin_unlock_bh when the Tx timestamp is requested and the list of free latches is empty
v3 -> v4: change Tx timestamp filters based on the PTP capabilities, use list_for_each_entry_safe when deleting list items, rewrite function that extends Tx timestamp value to 64 bits, minor fixes 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 | 72 +++++- .../net/ethernet/intel/idpf/idpf_lan_txrx.h | 13 +- drivers/net/ethernet/intel/idpf/idpf_lib.c | 45 ++++ drivers/net/ethernet/intel/idpf/idpf_ptp.c | 230 ++++++++++++++++- drivers/net/ethernet/intel/idpf/idpf_ptp.h | 51 ++++ drivers/net/ethernet/intel/idpf/idpf_txrx.c | 144 ++++++++++- 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, 813 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 +71 -1
120 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 +45 -0
61 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_ptp.c +228 -2
309 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_ptp.h +51 -0
98 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.c +137 -7
227 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
@@ -3176,8 +3176,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
PATCH v6 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.
---
v5 -> v6: add Rx filter
v2 -> v3: add disable Rx timestamp
v1 -> v2: extend commit message
.../net/ethernet/intel/idpf/idpf_ethtool.c | 2 + 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 +- 4 files changed, 123 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_ethtool.c +2 -0
@@ -1332,6 +1332,8 @@ static void idpf_get_timestamp_filters(const struct idpf_vport *vport, info->so_timestamping =SOF_TIMESTAMPING_RX_HARDWARE |SOF_TIMESTAMPING_RAW_HARDWARE ; + info->rx_filters =BIT (HWTSTAMP_FILTER_NONE ) |BIT (HWTSTAMP_FILTER_ALL ); +if (!vport->tx_tstamp_caps || vport->adapter->ptp->tx_tstamp_access ==IDPF_PTP_NONE )return ;
drivers/net/ethernet/intel/idpf/idpf_ptp.c +85 -1
115 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.c +30 -0
@@ -3174,6 +3174,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
@@ -3199,6 +3226,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);skb_record_rx_queue (skb, rxq->idx);
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
PATCH v6 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 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_main.c +2 -3
@@ -198,9 +198,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" , -WQ_UNBOUND |WQ_MEM_RECLAIM ,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