<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div id="divRplyFwdMsg">
<div style="direction: ltr;"> <span style="font-size: 11pt;">On Thu, Jan 22, 2026 at 07:04:47PM -0500, Soumyadeep Hore wrote:<br>
> Add a new file - idpf_ptp - to handle PTP virtchnl messages.<br>
> Keep the registers addresses in the PTP struct.<br>
><br>
> Signed-off-by: Soumyadeep Hore <soumyadeep.hore@intel.com><br>
> ---<br>
<br>
Some review feedback inline below. See also review feedback from AI review<br>
that was posted by Stephen.<br>
<br>
> drivers/net/intel/idpf/idpf_common_device.h | 4 +<br>
> drivers/net/intel/idpf/idpf_common_virtchnl.c | 34 +-<br>
> drivers/net/intel/idpf/idpf_ptp.c | 639 ++++++++++++++++++<br>
> drivers/net/intel/idpf/idpf_ptp.h | 227 +++++++<br>
> drivers/net/intel/idpf/meson.build | 1 +<br>
> 5 files changed, 903 insertions(+), 2 deletions(-)<br>
> create mode 100644 drivers/net/intel/idpf/idpf_ptp.c<br>
> create mode 100644 drivers/net/intel/idpf/idpf_ptp.h<br>
><br>
> diff --git a/drivers/net/intel/idpf/idpf_common_device.h b/drivers/net/intel/idpf/idpf_common_device.h<br>
> index c32dcfbb12..3c84b96225 100644<br>
> --- a/drivers/net/intel/idpf/idpf_common_device.h<br>
> +++ b/drivers/net/intel/idpf/idpf_common_device.h<br>
> @@ -90,6 +90,7 @@ struct idpf_adapter {<br>
> <br>
> /* For timestamp */<br>
> uint64_t time_hw;<br>
> + struct idpf_ptp *ptp;<br>
> <br>
> enum idpf_rx_func_type rx_func_type;<br>
> };<br>
> @@ -161,6 +162,9 @@ struct idpf_vport {<br>
> /* Event from ipf */<br>
> bool link_up;<br>
> uint32_t link_speed;<br>
> +<br>
> + /* For PTP */<br>
> + struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps;<br>
> };<br>
> <br>
> /* Message type read in virtual channel from PF */<br>
> diff --git a/drivers/net/intel/idpf/idpf_common_virtchnl.c b/drivers/net/intel/idpf/idpf_common_virtchnl.c<br>
> index e927d7415a..a28bc9bee6 100644<br>
> --- a/drivers/net/intel/idpf/idpf_common_virtchnl.c<br>
> +++ b/drivers/net/intel/idpf/idpf_common_virtchnl.c<br>
> @@ -4,6 +4,7 @@<br>
> <br>
> #include "idpf_common_virtchnl.h"<br>
> #include "idpf_common_logs.h"<br>
> +#include "idpf_ptp.h"<br>
> <br>
> #include <eal_export.h><br>
> <br>
> @@ -38,6 +39,28 @@ idpf_vc_clean(struct idpf_adapter *adapter)<br>
> return 0;<br>
> }<br>
> <br>
> +/**<br>
> + * idpf_ptp_is_mb_msg - Check if the message is PTP-related<br>
> + * @op: virtchnl opcode<br>
> + *<br>
> + * Returns true if msg is PTP-related, false otherwise<br>
> + */<br>
> +static inline bool idpf_ptp_is_mb_msg(uint32_t op)<br>
> +{<br>
<br>
The name of this function seems backward to me. We are not returning if<br>
it's a mailbox message, we are returning if it's PTP related, no? Therefore<br>
would idpf_mb_msg_is_ptp, not be a better name?<br>
<br>
> + switch (op) {<br>
> + case VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP:<br>
> + case VIRTCHNL2_OP_PTP_GET_DEV_CLK_TIME:<br>
> + case VIRTCHNL2_OP_PTP_GET_CROSS_TIME:<br>
> + case VIRTCHNL2_OP_PTP_SET_DEV_CLK_TIME:<br>
> + case VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_FINE:<br>
> + case VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_TIME:<br>
> + case VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP_CAPS:<br>
> + return true;<br>
> + default:<br>
> + return false;<br>
> + }<br>
> +}<br>
> +<br>
> static int<br>
> idpf_send_vc_msg(struct idpf_adapter *adapter, uint32_t op,<br>
> uint16_t msg_size, uint8_t *msg)<br>
> @@ -71,8 +94,15 @@ idpf_send_vc_msg(struct idpf_adapter *adapter, uint32_t op,<br>
> <br>
> memcpy(dma_mem->va, msg, msg_size);<br>
> <br>
> - ctlq_msg->opcode = idpf_mbq_opc_send_msg_to_pf;<br>
> - ctlq_msg->func_id = 0;<br>
> + if (idpf_ptp_is_mb_msg(op) && adapter->ptp->secondary_mbx.valid) {<br>
<br>
If the first of these is true and the second not, is that an error<br>
condition and do we need to handle it?</span></div>
<div style="direction: ltr; font-size: 11pt;"><br>
</div>
<div style="direction: ltr; font-size: 11pt;" class="elementToProof">No by default it should use primary mailbox for error conditions. Actually those are not error conditions but various cases where primary mail box is used for negotiation.<br>
<br>
> + ctlq_msg->opcode = idpf_mbq_opc_send_msg_to_peer_drv;<br>
> + ctlq_msg->func_id = adapter->ptp->secondary_mbx.peer_mbx_q_id;<br>
> + ctlq_msg->host_id = adapter->ptp->secondary_mbx.peer_id;<br>
> + } else {<br>
> + ctlq_msg->opcode = idpf_mbq_opc_send_msg_to_pf;<br>
> + ctlq_msg->func_id = 0;<br>
> + }<br>
> +<br>
> ctlq_msg->data_len = msg_size;<br>
> ctlq_msg->cookie.mbx.chnl_opcode = op;<br>
> ctlq_msg->cookie.mbx.chnl_retval = VIRTCHNL_STATUS_SUCCESS;<br>
> diff --git a/drivers/net/intel/idpf/idpf_ptp.c b/drivers/net/intel/idpf/idpf_ptp.c<br>
> new file mode 100644<br>
> index 0000000000..b8f6afa518<br>
> --- /dev/null<br>
> +++ b/drivers/net/intel/idpf/idpf_ptp.c<br>
> @@ -0,0 +1,639 @@<br>
> +/* SPDX-License-Identifier: BSD-3-Clause<br>
> + * Copyright(c) 2025 Intel Corporation<br>
> + */<br>
> +<br>
> +#include "idpf_ptp.h"<br>
> +#include <base/virtchnl2.h><br>
> +#include "idpf_common_virtchnl.h"<br>
> +<br>
> +/**<br>
> + * idpf_ptp_get_access - Determine the access type of the PTP features<br>
> + * @adapter: Driver specific private structure<br>
> + * @direct: Capability that indicates the direct access<br>
> + * @mailbox: Capability that indicates the mailbox access<br>
> + *<br>
> + * Return: the type of supported access for the PTP feature.<br>
> + */<br>
> +static enum idpf_ptp_access<br>
> +idpf_ptp_get_access(const struct idpf_adapter *adapter, u32 direct, u32 mailbox)<br>
> +{<br>
> + if (adapter->ptp->caps & direct)<br>
> + return IDPF_PTP_DIRECT;<br>
> + else if (adapter->ptp->caps & mailbox)<br>
> + return IDPF_PTP_MAILBOX;<br>
> + else<br>
> + return IDPF_PTP_NONE;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_get_features_access - Determine the access type of PTP features<br>
> + * @adapter: Driver specific private structure<br>
> + *<br>
> + * Fulfill the adapter structure with type of the supported PTP features<br>
> + * access.<br>
> + */<br>
> +static void idpf_ptp_get_features_access(const struct idpf_adapter *adapter)<br>
> +{<br>
> + struct idpf_ptp *ptp = adapter->ptp;<br>
> + u32 direct, mailbox;<br>
> +<br>
> + /* Get the device clock time */<br>
> + direct = VIRTCHNL2_CAP_PTP_GET_DEVICE_CLK_TIME;<br>
> + mailbox = VIRTCHNL2_CAP_PTP_GET_DEVICE_CLK_TIME_MB;<br>
> + ptp->get_dev_clk_time_access = (uint8_t)idpf_ptp_get_access(adapter,<br>
> + direct,<br>
> + mailbox);<br>
> +<br>
> + /* Get the cross timestamp */<br>
> + direct = VIRTCHNL2_CAP_PTP_GET_CROSS_TIME;<br>
> + mailbox = VIRTCHNL2_CAP_PTP_GET_CROSS_TIME_MB;<br>
> + ptp->get_cross_tstamp_access = (uint8_t)idpf_ptp_get_access(adapter,<br>
> + direct,<br>
> + mailbox);<br>
> +<br>
> + /* Set the device clock time */<br>
> + direct = VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME;<br>
> + mailbox = VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME_MB;<br>
> + ptp->set_dev_clk_time_access = (uint8_t)idpf_ptp_get_access(adapter,<br>
> + direct,<br>
> + mailbox);<br>
> +<br>
> + /* Adjust the device clock time */<br>
> + direct = VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK;<br>
> + mailbox = VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK_MB;<br>
> + ptp->adj_dev_clk_time_access = (uint8_t)idpf_ptp_get_access(adapter,<br>
> + direct,<br>
> + mailbox);<br>
> +<br>
> + /* Tx timestamping */<br>
> + direct = VIRTCHNL2_CAP_PTP_TX_TSTAMPS;<br>
> + mailbox = VIRTCHNL2_CAP_PTP_TX_TSTAMPS_MB;<br>
> + ptp->tx_tstamp_access = (uint8_t)idpf_ptp_get_access(adapter,<br>
> + direct,<br>
> + mailbox);<br>
> +}<br>
<br>
This function could be much shorter if you just removed the variables "direct"<br>
and "mailbox". Rather than doing<br>
<br>
direct = VIRTCHNL2_CAP_PTP_TX_TSTAMPS;<br>
mailbox = VIRTCHNL2_CAP_PTP_TX_TSTAMPS_MB;<br>
ptp->tx_tstamp_access = (uint8_t)idpf_ptp_get_access(adapter,<br>
direct,<br>
mailbox);<br>
<br>
You can shorten the 5 lines down to 3 as:<br>
<br>
ptp->tx_tstamp_access = idpf_ptp_get_access(adapter,<br>
VIRTCHNL2_CAP_PTP_TX_TSTAMPS,<br>
VIRTCHNL2_CAP_PTP_TX_TSTAMPS_MB);<br>
<br>
Furthermore, since all the defines used for mailbox are the same as those<br>
used for direct, except for an _MB suffix, you could use a macro to shorten<br>
thngs further if you want - maybe even fit each assignment on one line.<br>
For example (untested, and also shortening adapter to ad to fit one line):<br>
<br>
#define IDPF_PTP_ACCESS(a, d) (uint8_t)idpf_ptp_get_access(a, d, d##_MB)<br>
<br>
static void<br>
idpf_ptp_get_features_access(const struct idpf_adapter *ad)<br>
{<br>
struct idpf_ptp *ptp = ad->ptp;<br>
<br>
ptp->get_dev_clk_time_access = IDPF_PTP_ACCESS(ad, VIRTCHNL2_CAP_PTP_GET_DEVICE_CLK_TIME);<br>
ptp->get_cross_tstamp_access = IDPF_PTP_ACCESS(ad, VIRTCHNL2_CAP_PTP_GET_CROSS_TIME);<br>
ptp->set_dev_clk_time_access = IDPF_PTP_ACCESS(ad, VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME);<br>
ptp->adj_dev_clk_time_access = IDPF_PTP_ACCESS(ad, VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK);<br>
ptp->tx_stamp_access = IDPF_PTP_ACCESS(ad, VIRTCHNL2_CAP_PTP_TX_TSTAMPS);<br>
}<br>
<br>
Much shorter! :-)<br>
<br>
<br>
> +/**<br>
> + * idpf_ptp_get_caps - Send virtchnl get ptp capabilities message<br>
> + * @adapter: Driver specific private structure<br>
> + *<br>
> + * Send virtchnl get PTP capabilities message.<br>
> + *<br>
> + * Return: 0 on success, -errno on failure.<br>
> + */<br>
> +int idpf_ptp_get_caps(struct idpf_adapter *adapter)<br>
> +{<br>
> + struct virtchnl2_ptp_cross_time_reg_offsets cross_tstamp_offsets;<br>
> + struct virtchnl2_ptp_clk_adj_reg_offsets clk_adj_offsets;<br>
> + struct virtchnl2_ptp_get_caps send_ptp_caps_msg = { };<br>
<br>
Using {} is a GNU extension to C11, so its best to use {0} as initializer.<br>
<br>
> + struct virtchnl2_ptp_clk_reg_offsets clock_offsets;<br>
> + struct virtchnl2_ptp_get_caps *recv_ptp_caps_msg;<br>
> + struct idpf_cmd_info args = { };<br>
> + struct idpf_ptp_secondary_mbx *scnd_mbx;<br>
> + struct idpf_ptp *ptp = adapter->ptp;<br>
> + struct idpf_hw *hw = &adapter->hw;<br>
> + enum idpf_ptp_access access_type;<br>
> + int err;<br>
> + u32 temp_offset;<br>
> +<br>
> + send_ptp_caps_msg.caps = CPU_TO_LE32(VIRTCHNL2_CAP_PTP_GET_DEVICE_CLK_TIME |<br>
> + VIRTCHNL2_CAP_PTP_GET_DEVICE_CLK_TIME_MB |<br>
> + VIRTCHNL2_CAP_PTP_GET_CROSS_TIME |<br>
> + VIRTCHNL2_CAP_PTP_GET_CROSS_TIME_MB |<br>
> + VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME |<br>
> + VIRTCHNL2_CAP_PTP_SET_DEVICE_CLK_TIME_MB |<br>
> + VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK |<br>
> + VIRTCHNL2_CAP_PTP_ADJ_DEVICE_CLK_MB |<br>
> + VIRTCHNL2_CAP_PTP_TX_TSTAMPS |<br>
> + VIRTCHNL2_CAP_PTP_TX_TSTAMPS_MB);<br>
> +<br>
> + args.ops = VIRTCHNL2_OP_PTP_GET_CAPS;<br>
> + args.in_args = (uint8_t *)&send_ptp_caps_msg;<br>
> + args.in_args_size = sizeof(send_ptp_caps_msg);<br>
> +<br>
> + args.out_buffer = adapter->mbx_resp;<br>
> + args.out_size = sizeof(*recv_ptp_caps_msg);<br>
> +<br>
> + err = idpf_vc_cmd_execute(adapter, &args);<br>
> + if (err < 0)<br>
> + return err;<br>
> +<br>
> + recv_ptp_caps_msg = (struct virtchnl2_ptp_get_caps *)args.out_buffer;<br>
> + ptp->caps = LE32_TO_CPU(recv_ptp_caps_msg->caps);<br>
> + ptp->base_incval = LE64_TO_CPU(recv_ptp_caps_msg->base_incval);<br>
> + ptp->max_adj = LE32_TO_CPU(recv_ptp_caps_msg->max_adj);<br>
> +<br>
> + scnd_mbx = &ptp->secondary_mbx;<br>
> + scnd_mbx->peer_mbx_q_id = LE16_TO_CPU(recv_ptp_caps_msg->peer_mbx_q_id);<br>
> +<br>
> + /* if the ptp_mb_q_id holds invalid value (0xffff), the secondary<br>
> + * mailbox is not supported.<br>
> + */<br>
> + scnd_mbx->valid = scnd_mbx->peer_mbx_q_id != 0xffff;<br>
> + if (scnd_mbx->valid)<br>
> + scnd_mbx->peer_id = recv_ptp_caps_msg->peer_id;<br>
> +<br>
> + /* Determine the access type for the PTP features */<br>
> + idpf_ptp_get_features_access(adapter);<br>
> +<br>
> + access_type = (enum idpf_ptp_access)ptp->get_dev_clk_time_access;<br>
> + if (access_type != IDPF_PTP_DIRECT)<br>
> + goto cross_tstamp;<br>
> +<br>
> + clock_offsets = recv_ptp_caps_msg->clk_offsets;<br>
> +<br>
> + temp_offset = LE32_TO_CPU(clock_offsets.dev_clk_ns_l);<br>
> + ptp->dev_clk_regs.dev_clk_ns_l = IDPF_PCI_REG_ADDR(hw,<br>
> + temp_offset);<br>
<br>
No need to wrap these lines. Use the full 100 chars.<br>
(Also, when wrapping, double tab indent is sufficient, no need to put in 7<br>
tabs + spaces to try and align braces in cases like this)<br>
<br>
> + temp_offset = LE32_TO_CPU(clock_offsets.dev_clk_ns_h);<br>
> + ptp->dev_clk_regs.dev_clk_ns_h = IDPF_PCI_REG_ADDR(hw,<br>
> + temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clock_offsets.phy_clk_ns_l);<br>
> + ptp->dev_clk_regs.phy_clk_ns_l = IDPF_PCI_REG_ADDR(hw,<br>
> + temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clock_offsets.phy_clk_ns_h);<br>
> + ptp->dev_clk_regs.phy_clk_ns_h = IDPF_PCI_REG_ADDR(hw,<br>
> + temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clock_offsets.cmd_sync_trigger);<br>
> + ptp->dev_clk_regs.cmd_sync = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> +<br>
> +cross_tstamp:<br>
> + access_type = (enum idpf_ptp_access)ptp->get_cross_tstamp_access;<br>
> + if (access_type != IDPF_PTP_DIRECT)<br>
> + goto discipline_clock;<br>
> +<br>
> + cross_tstamp_offsets = recv_ptp_caps_msg->cross_time_offsets;<br>
> +<br>
> + temp_offset = LE32_TO_CPU(cross_tstamp_offsets.sys_time_ns_l);<br>
> + ptp->dev_clk_regs.sys_time_ns_l = IDPF_PCI_REG_ADDR(hw,<br>
> + temp_offset);<br>
<br>
Again, don't wrap. Also, this indentation used neither is a simple<br>
double-indent, nor does it align to brace so please use one style<br>
consistently.<br>
<br>
> + temp_offset = LE32_TO_CPU(cross_tstamp_offsets.sys_time_ns_h);<br>
> + ptp->dev_clk_regs.sys_time_ns_h = IDPF_PCI_REG_ADDR(hw,<br>
> + temp_offset);<br>
> + temp_offset = LE32_TO_CPU(cross_tstamp_offsets.cmd_sync_trigger);<br>
> + ptp->dev_clk_regs.cmd_sync = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> +<br>
> +discipline_clock:<br>
> + access_type = (enum idpf_ptp_access)ptp->adj_dev_clk_time_access;<br>
> + if (access_type != IDPF_PTP_DIRECT)<br>
> + return err;<br>
> +<br>
> + clk_adj_offsets = recv_ptp_caps_msg->clk_adj_offsets;<br>
> +<br>
> + /* Device clock offsets */<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.dev_clk_cmd_type);<br>
> + ptp->dev_clk_regs.cmd = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.dev_clk_incval_l);<br>
> + ptp->dev_clk_regs.incval_l = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.dev_clk_incval_h);<br>
> + ptp->dev_clk_regs.incval_h = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.dev_clk_shadj_l);<br>
> + ptp->dev_clk_regs.shadj_l = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.dev_clk_shadj_h);<br>
> + ptp->dev_clk_regs.shadj_h = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> +<br>
> + /* PHY clock offsets */<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.phy_clk_cmd_type);<br>
> + ptp->dev_clk_regs.phy_cmd = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.phy_clk_incval_l);<br>
> + ptp->dev_clk_regs.phy_incval_l = IDPF_PCI_REG_ADDR(hw,<br>
> + temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.phy_clk_incval_h);<br>
> + ptp->dev_clk_regs.phy_incval_h = IDPF_PCI_REG_ADDR(hw,<br>
> + temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.phy_clk_shadj_l);<br>
> + ptp->dev_clk_regs.phy_shadj_l = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> + temp_offset = LE32_TO_CPU(clk_adj_offsets.phy_clk_shadj_h);<br>
> + ptp->dev_clk_regs.phy_shadj_h = IDPF_PCI_REG_ADDR(hw, temp_offset);<br>
> +<br>
> + return err;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_enable_shtime - Enable shadow time and execute a command<br>
> + * @adapter: Driver specific private structure<br>
> + */<br>
> +static void idpf_ptp_enable_shtime(struct idpf_adapter *adapter)<br>
> +{<br>
> + uint32_t shtime_enable, exec_cmd;<br>
> +<br>
> + /* Get offsets */<br>
> + shtime_enable = adapter->ptp->cmd.shtime_enable_mask;<br>
> + exec_cmd = adapter->ptp->cmd.exec_cmd_mask;<br>
> +<br>
> + /* Set the shtime en and the sync field */<br>
> + IDPF_PCI_REG_WRITE(adapter->ptp->dev_clk_regs.cmd_sync, shtime_enable);<br>
> + IDPF_PCI_REG_WRITE(adapter->ptp->dev_clk_regs.cmd_sync, exec_cmd | shtime_enable);<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_get_dev_clk_time - Send virtchnl get device clk time message<br>
> + * @adapter: Driver specific private structure<br>
> + * @dev_clk_time: Pointer to the device clock structure where the value is set<br>
> + *<br>
> + * Send virtchnl get time message to get the time of the clock.<br>
> + *<br>
> + * Return: 0 on success, -errno otherwise.<br>
> + */<br>
> +int idpf_ptp_get_dev_clk_time(struct idpf_adapter *adapter,<br>
> + struct idpf_ptp_dev_timers *dev_clk_time)<br>
> +{<br>
> + struct virtchnl2_ptp_get_dev_clk_time get_dev_clk_time_msg = { };<br>
> + struct idpf_cmd_info args = { };<br>
<br>
As above, use {0} as initializer.<br>
<br>
> + int err;<br>
> + u64 dev_time;<br>
> +<br>
> + args.ops = VIRTCHNL2_OP_PTP_GET_DEV_CLK_TIME;<br>
> + args.in_args = (uint8_t *)&get_dev_clk_time_msg;<br>
> + args.in_args_size = sizeof(get_dev_clk_time_msg);<br>
> + args.out_buffer = adapter->mbx_resp;<br>
> + args.out_size = sizeof(get_dev_clk_time_msg);<br>
> +<br>
> + err = idpf_vc_cmd_execute(adapter, &args);<br>
> + if (err < 0)<br>
> + return err;<br>
> +<br>
> + get_dev_clk_time_msg = *(struct virtchnl2_ptp_get_dev_clk_time *)args.out_buffer;<br>
> + dev_time = LE64_TO_CPU(get_dev_clk_time_msg.dev_time_ns);<br>
> + dev_clk_time->dev_clk_time_ns = dev_time;<br>
> +<br>
> + return err;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_get_cross_time - Send virtchnl get cross time message<br>
> + * @adapter: Driver specific private structure<br>
> + * @cross_time: Pointer to the device clock structure where the value is set<br>
> + *<br>
> + * Send virtchnl get cross time message to get the time of the clock and the<br>
> + * system time.<br>
> + *<br>
> + * Return: 0 on success, -errno otherwise.<br>
> + */<br>
> +int idpf_ptp_get_cross_time(struct idpf_adapter *adapter,<br>
> + struct idpf_ptp_dev_timers *cross_time)<br>
> +{<br>
> + struct virtchnl2_ptp_get_cross_time cross_time_msg = { };<br>
> + struct idpf_cmd_info args = { };<br>
> + int err;<br>
> +<br>
> + args.ops = VIRTCHNL2_OP_PTP_GET_CROSS_TIME;<br>
> + args.in_args = (uint8_t *)&cross_time_msg;<br>
> + args.in_args_size = sizeof(cross_time_msg);<br>
> + args.out_buffer = adapter->mbx_resp;<br>
> + args.out_size = sizeof(cross_time_msg);<br>
> +<br>
> + err = idpf_vc_cmd_execute(adapter, &args);<br>
> + if (err < 0)<br>
> + return err;<br>
> +<br>
> + cross_time_msg = *(struct virtchnl2_ptp_get_cross_time *)args.out_buffer;<br>
> + cross_time->dev_clk_time_ns = LE64_TO_CPU(cross_time_msg.dev_time_ns);<br>
> + cross_time->sys_time_ns = LE64_TO_CPU(cross_time_msg.sys_time_ns);<br>
> +<br>
> + return err;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_set_dev_clk_time - Send virtchnl set device time message<br>
> + * @adapter: Driver specific private structure<br>
> + * @time: New time value<br>
> + *<br>
> + * Send virtchnl set time message to set the time of the clock.<br>
> + *<br>
> + * Return: 0 on success, -errno otherwise.<br>
> + */<br>
> +int idpf_ptp_set_dev_clk_time(struct idpf_adapter *adapter, u64 time)<br>
> +{<br>
> + struct virtchnl2_ptp_set_dev_clk_time set_dev_clk_time_msg = { };<br>
> + struct idpf_cmd_info args = { };<br>
> + int err;<br>
> +<br>
> + set_dev_clk_time_msg.dev_time_ns = CPU_TO_LE64(time);<br>
> +<br>
> + args.ops = VIRTCHNL2_OP_PTP_SET_DEV_CLK_TIME;<br>
> + args.in_args = (uint8_t *)&set_dev_clk_time_msg;<br>
> + args.in_args_size = sizeof(set_dev_clk_time_msg);<br>
> + args.out_buffer = adapter->mbx_resp;<br>
> + args.out_size = sizeof(set_dev_clk_time_msg);<br>
> +<br>
> + err = idpf_vc_cmd_execute(adapter, &args);<br>
> + if (err < 0)<br>
> + return err;<br>
> +<br>
> + return err;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_adj_dev_clk_time - Send virtchnl adj device clock time message<br>
> + * @adapter: Driver specific private structure<br>
> + * @delta: Offset in nanoseconds to adjust the time by<br>
> + *<br>
> + * Send virtchnl adj time message to adjust the clock by the indicated delta.<br>
> + *<br>
> + * Return: 0 on success, -errno otherwise.<br>
> + */<br>
> +int idpf_ptp_adj_dev_clk_time(struct idpf_adapter *adapter, int64_t delta)<br>
> +{<br>
> + struct virtchnl2_ptp_adj_dev_clk_time adj_dev_clk_time_msg = { };<br>
> + struct idpf_cmd_info args = { };<br>
> + int err;<br>
> +<br>
> + adj_dev_clk_time_msg.delta = CPU_TO_LE64(delta);<br>
> +<br>
> + args.ops = VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_TIME;<br>
> + args.in_args = (uint8_t *)&adj_dev_clk_time_msg;<br>
> + args.in_args_size = sizeof(adj_dev_clk_time_msg);<br>
> + args.out_buffer = adapter->mbx_resp;<br>
> + args.out_size = sizeof(adj_dev_clk_time_msg);<br>
> +<br>
> + err = idpf_vc_cmd_execute(adapter, &args);<br>
> + if (err < 0)<br>
> + return err;<br>
> +<br>
> + return err;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_adj_dev_clk_fine - Send virtchnl adj time message<br>
> + * @adapter: Driver specific private structure<br>
> + * @incval: Source timer increment value per clock cycle<br>
> + *<br>
> + * Send virtchnl adj fine message to adjust the frequency of the clock by<br>
> + * incval.<br>
> + *<br>
> + * Return: 0 on success, -errno otherwise.<br>
> + */<br>
> +int idpf_ptp_adj_dev_clk_fine(struct idpf_adapter *adapter, u64 incval)<br>
> +{<br>
> + struct virtchnl2_ptp_adj_dev_clk_fine adj_dev_clk_fine_msg = { };<br>
> + struct idpf_cmd_info args = { };<br>
> + int err;<br>
> +<br>
> + adj_dev_clk_fine_msg.incval = CPU_TO_LE64(incval);<br>
> +<br>
> + args.ops = VIRTCHNL2_OP_PTP_ADJ_DEV_CLK_FINE;<br>
> + args.in_args = (uint8_t *)&adj_dev_clk_fine_msg;<br>
> + args.in_args_size = sizeof(adj_dev_clk_fine_msg);<br>
> + args.out_buffer = adapter->mbx_resp;<br>
> + args.out_size = sizeof(adj_dev_clk_fine_msg);<br>
> +<br>
> + err = idpf_vc_cmd_execute(adapter, &args);<br>
> + if (err < 0)<br>
> + return err;<br>
> +<br>
> + return err;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_get_vport_tstamps_caps - Send virtchnl to get tstamps caps for vport<br>
> + * @vport: Virtual port structure<br>
> + *<br>
> + * Send virtchnl get vport tstamps caps message to receive the set of tstamp<br>
> + * capabilities per vport.<br>
> + *<br>
> + * Return: 0 on success, -errno otherwise.<br>
> + */<br>
> +int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)<br>
> +{<br>
> + struct virtchnl2_ptp_get_vport_tx_tstamp_caps send_tx_tstamp_caps = { };<br>
> + struct virtchnl2_ptp_get_vport_tx_tstamp_caps *rcv_tx_tstamp_caps;<br>
> + struct virtchnl2_ptp_tx_tstamp_latch_caps tx_tstamp_latch_caps;<br>
> + enum idpf_ptp_access tstamp_access, get_dev_clk_access;<br>
> + struct idpf_ptp_vport_tx_tstamp_caps *tstamp_caps;<br>
> + struct idpf_ptp *ptp = vport->adapter->ptp;<br>
> + struct idpf_cmd_info args = { };<br>
> + int err;<br>
> + u16 num_latches, i;<br>
> + u32 size;<br>
> +<br>
> + if (ptp == NULL)<br>
> + return -EOPNOTSUPP;<br>
> +<br>
> + tstamp_access = (enum idpf_ptp_access)ptp->tx_tstamp_access;<br>
> + get_dev_clk_access = (enum idpf_ptp_access)ptp->get_dev_clk_time_access;<br>
> + if (tstamp_access == IDPF_PTP_NONE ||<br>
> + get_dev_clk_access == IDPF_PTP_NONE)<br>
> + return -EOPNOTSUPP;<br>
> +<br>
> + send_tx_tstamp_caps.vport_id = CPU_TO_LE32(vport->vport_id);<br>
> +<br>
> + args.ops = VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP_CAPS;<br>
> + args.in_args = (uint8_t *)&send_tx_tstamp_caps;<br>
> + args.in_args_size = sizeof(send_tx_tstamp_caps);<br>
> + args.out_size = IDPF_CTLQ_MAX_BUF_LEN;<br>
> + args.out_buffer = vport->adapter->mbx_resp;<br>
> +<br>
> + err = idpf_vc_cmd_execute(vport->adapter, &args);<br>
> + if (err < 0)<br>
> + return err;<br>
> +<br>
> + rcv_tx_tstamp_caps = (struct virtchnl2_ptp_get_vport_tx_tstamp_caps *)<br>
> + args.out_buffer;<br>
> + num_latches = LE16_TO_CPU(rcv_tx_tstamp_caps->num_latches);<br>
> + size = sizeof(struct idpf_ptp_vport_tx_tstamp_caps) +<br>
> + sizeof(struct idpf_ptp_tx_tstamp) * num_latches;<br>
> + tstamp_caps = rte_zmalloc(NULL, size, 0);<br>
> + if (tstamp_caps == NULL)<br>
> + return -ENOMEM;<br>
> +<br>
> + tstamp_caps->access = true;<br>
> + tstamp_caps->num_entries = num_latches;<br>
> +<br>
> + tstamp_caps->tstamp_ns_lo_bit = rcv_tx_tstamp_caps->tstamp_ns_lo_bit;<br>
> +<br>
> + for (i = 0; i < tstamp_caps->num_entries; i++) {<br>
> + __le32 offset_l, offset_h;<br>
> +<br>
> + tx_tstamp_latch_caps = rcv_tx_tstamp_caps->tstamp_latches[i];<br>
> +<br>
> + if (tstamp_access == IDPF_PTP_DIRECT) {<br>
> + offset_l = tx_tstamp_latch_caps.tx_latch_reg_offset_l;<br>
> + offset_h = tx_tstamp_latch_caps.tx_latch_reg_offset_h;<br>
> + tstamp_caps->tx_tstamp[i].tx_latch_reg_offset_l = LE32_TO_CPU(offset_l);<br>
> + tstamp_caps->tx_tstamp[i].tx_latch_reg_offset_h = LE32_TO_CPU(offset_h);<br>
> + }<br>
> + tstamp_caps->tx_tstamp[i].idx = tx_tstamp_latch_caps.index;<br>
> + }<br>
> +<br>
> + tstamp_caps->latched_idx = -1;<br>
> + vport->tx_tstamp_caps = tstamp_caps;<br>
> +<br>
> + return err;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_get_tstamp_value - Get the Tx timestamp value and provide it<br>
> + * back to the skb.<br>
> + * @vport: Virtual port structure<br>
> + * @tstamp_latch: Tx timestamp latch structure fulfilled by the Control Plane<br>
> + * @tx_tstamp: Tx timestamp structure to be fulfilled with the timestamp value<br>
> + *<br>
> + * Read the value of the Tx timestamp for a given latch received from the<br>
> + * Control Plane.<br>
> + *<br>
> + * Return: 0 on success, -errno otherwise.<br>
> + */<br>
> +static int<br>
> +idpf_ptp_get_tstamp_value(struct idpf_vport *vport,<br>
> + struct virtchnl2_ptp_tx_tstamp_latch *tstamp_latch,<br>
> + struct idpf_ptp_tx_tstamp *tx_tstamp)<br>
> +{<br>
> + struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps;<br>
> + u8 tstamp_ns_lo_bit;<br>
> +<br>
> + tx_tstamp_caps = vport->tx_tstamp_caps;<br>
> + tstamp_ns_lo_bit = tx_tstamp_caps->tstamp_ns_lo_bit;<br>
> +<br>
> + tx_tstamp->tstamp = LE64_TO_CPU(tstamp_latch->tstamp);<br>
> + tx_tstamp->tstamp >>= tstamp_ns_lo_bit;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_get_tx_tstamp - Send virtchnl get Tx timestamp latches message<br>
> + * @vport: Virtual port structure<br>
> + *<br>
> + * Send virtchnl get Tx tstamp message to read the value of the HW timestamp.<br>
> + * The message contains a list of indexes set in the Tx descriptors.<br>
> + *<br>
> + * Return: 0 on success, -errno otherwise.<br>
> + */<br>
> +int idpf_ptp_get_tx_tstamp(struct idpf_vport *vport)<br>
> +{<br>
> + struct virtchnl2_ptp_get_vport_tx_tstamp_latches *send_tx_tstamp_msg;<br>
> + struct virtchnl2_ptp_get_vport_tx_tstamp_latches *recv_tx_tstamp_msg;<br>
> + struct idpf_ptp_vport_tx_tstamp_caps *tx_tstamp_caps;<br>
> + struct virtchnl2_ptp_tx_tstamp_latch tstamp_latch;<br>
> + struct idpf_ptp_tx_tstamp *ptp_tx_tstamp;<br>
> + struct idpf_cmd_info args = { };<br>
> + int size, msg_size;<br>
> + u32 vport_id;<br>
> + u16 num_latches, id;<br>
> + int err;<br>
> +<br>
> + tx_tstamp_caps = vport->tx_tstamp_caps;<br>
> + ptp_tx_tstamp = tx_tstamp_caps->tx_tstamp;<br>
> +<br>
> + size = sizeof(struct virtchnl2_ptp_get_vport_tx_tstamp_latches) +<br>
> + sizeof(struct virtchnl2_ptp_tx_tstamp_latch) *<br>
> + tx_tstamp_caps->num_entries;<br>
> + send_tx_tstamp_msg = rte_zmalloc(NULL, size, 0);<br>
> + if (send_tx_tstamp_msg == NULL)<br>
> + return -ENOMEM;<br>
> +<br>
> + for (id = 0; id < tx_tstamp_caps->num_entries; id++,<br>
> + ptp_tx_tstamp++)<br>
> + send_tx_tstamp_msg->tstamp_latches[id].index =<br>
> + ptp_tx_tstamp->idx;<br>
<br>
Identation in this loop badly needs to be reworked.<br>
<br>
> + send_tx_tstamp_msg->get_devtime_with_txtstmp = 1;<br>
> +<br>
> + msg_size = sizeof(struct virtchnl2_ptp_get_vport_tx_tstamp_latches) +<br>
> + sizeof(struct virtchnl2_ptp_tx_tstamp_latch) * id;<br>
> + send_tx_tstamp_msg->vport_id = CPU_TO_LE32(vport->vport_id);<br>
> + send_tx_tstamp_msg->num_latches = CPU_TO_LE16(id);<br>
> +<br>
> + args.ops = VIRTCHNL2_OP_PTP_GET_VPORT_TX_TSTAMP;<br>
> + args.in_args = (uint8_t *)send_tx_tstamp_msg;<br>
> + args.in_args_size = msg_size;<br>
> + args.out_size = msg_size;<br>
> + args.out_buffer = vport->adapter->mbx_resp;<br>
> +<br>
> + err = idpf_vc_cmd_execute(vport->adapter, &args);<br>
> + rte_free(send_tx_tstamp_msg);<br>
> + if (err < 0)<br>
> + return err;<br>
> +<br>
> + recv_tx_tstamp_msg = (struct virtchnl2_ptp_get_vport_tx_tstamp_latches *)<br>
> + args.out_buffer;<br>
> + vport_id = LE32_TO_CPU(recv_tx_tstamp_msg->vport_id);<br>
> + if (vport->vport_id != vport_id)<br>
> + return -EINVAL;<br>
> +<br>
> + num_latches = LE16_TO_CPU(recv_tx_tstamp_msg->num_latches);<br>
> +<br>
> + ptp_tx_tstamp = tx_tstamp_caps->tx_tstamp;<br>
> + for (id = 0; id < num_latches; id++, ptp_tx_tstamp++) {<br>
> + tstamp_latch = recv_tx_tstamp_msg->tstamp_latches[id];<br>
> +<br>
> + if (!tstamp_latch.valid)<br>
> + continue;<br>
> +<br>
> + err = idpf_ptp_get_tstamp_value(vport, &tstamp_latch,<br>
> + ptp_tx_tstamp);<br>
> + if (err == 0) {<br>
> + tx_tstamp_caps->latched_idx = id;<br>
> + vport->adapter->time_hw = recv_tx_tstamp_msg->device_time;<br>
> + }<br>
> + break;<br>
> + }<br>
> + return err;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_read_src_clk_reg_direct - Read directly the main timer value<br>
> + * @adapter: Driver specific private structure<br>
> + *<br>
> + * Return: the device clock time.<br>
> + */<br>
> +static u64 idpf_ptp_read_src_clk_reg_direct(struct idpf_adapter *adapter)<br>
> +{<br>
> + struct idpf_ptp *ptp = adapter->ptp;<br>
> + u32 hi, lo;<br>
> +<br>
> + idpf_ptp_enable_shtime(adapter);<br>
> +<br>
> + lo = IDPF_PCI_REG(ptp->dev_clk_regs.dev_clk_ns_l);<br>
> + hi = IDPF_PCI_REG(ptp->dev_clk_regs.dev_clk_ns_h);<br>
> +<br>
> + return ((u64)hi << 32) | lo;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_read_src_clk_reg_mailbox - Read the main timer value through mailbox<br>
> + * @adapter: Driver specific private structure<br>
> + * @src_clk: Returned main timer value in nanoseconds unit<br>
> + *<br>
> + * Return: 0 on success, -errno otherwise.<br>
> + */<br>
> +static int idpf_ptp_read_src_clk_reg_mailbox(struct idpf_adapter *adapter,<br>
> + u64 *src_clk)<br>
> +{<br>
> + struct idpf_ptp_dev_timers clk_time;<br>
> + int err;<br>
> +<br>
> + err = idpf_ptp_get_dev_clk_time(adapter, &clk_time);<br>
> + if (err)<br>
> + return err;<br>
> +<br>
> + *src_clk = clk_time.dev_clk_time_ns;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> +/**<br>
> + * idpf_ptp_read_src_clk_reg - Read the main timer value<br>
> + * @adapter: Driver specific private structure<br>
> + * @src_clk: Returned main timer value in nanoseconds unit<br>
> + *<br>
> + * Return: the device clock time on success, -errno otherwise.<br>
> + */<br>
> +int idpf_ptp_read_src_clk_reg(struct idpf_adapter *adapter, u64 *src_clk)<br>
> +{<br>
> + if (adapter->ptp == NULL)<br>
> + return 0;<br>
<br>
Should this not be an error, returning -EINVAL?<br>
<br>
> + switch ((enum idpf_ptp_access)adapter->ptp->get_dev_clk_time_access) {<br>
> + case IDPF_PTP_NONE:<br>
> + return -EOPNOTSUPP;<br>
<br>
Strictly speaking, you don't need this, it's handled by the default case.<br>
<br>
> + case IDPF_PTP_MAILBOX:<br>
> + return idpf_ptp_read_src_clk_reg_mailbox(adapter, src_clk);<br>
> + case IDPF_PTP_DIRECT:<br>
> + *src_clk = idpf_ptp_read_src_clk_reg_direct(adapter);<br>
> + break;<br>
<br>
Why have the function types for direct and mailbox different? Why not have<br>
both just take src_clk as parameter and return 0 on success, so you can<br>
have similar use of them. It would also possibly allow function pointer use<br>
in future, if they are the same types.<br>
<br>
> + default:<br>
> + return -EOPNOTSUPP;<br>
> + }<br>
> +<br>
> + return 0;<br>
> +}<br>
> diff --git a/drivers/net/intel/idpf/idpf_ptp.h b/drivers/net/intel/idpf/idpf_ptp.h<br>
> new file mode 100644<br>
> index 0000000000..68ac66ae91<br>
> --- /dev/null<br>
> +++ b/drivers/net/intel/idpf/idpf_ptp.h<br>
> @@ -0,0 +1,227 @@<br>
> +/* SPDX-License-Identifier: BSD-3-Clause<br>
> + * Copyright(c) 2025 Intel Corporation<br>
> + */<br>
> +<br>
> +#ifndef _IDPF_PTP_H_<br>
> +#define _IDPF_PTP_H_<br>
> +<br>
> +#include "idpf_osdep.h"<br>
> +#include <rte_time.h><br>
> +#include "idpf_common_device.h"<br>
> +<br>
> +/**<br>
> + * @struct idpf_ptp_cmd - PTP command masks<br>
> + * @exec_cmd_mask: mask to trigger command execution<br>
> + * @shtime_enable_mask: mask to enable shadow time<br>
> + */<br>
> +struct idpf_ptp_cmd {<br>
> + uint32_t exec_cmd_mask;<br>
> + uint32_t shtime_enable_mask;<br>
> +};<br>
> +<br>
> +/* @struct idpf_ptp_dev_clk_regs - PTP device registers<br>
> + * @dev_clk_ns_l: low part of the device clock register<br>
> + * @dev_clk_ns_h: high part of the device clock register<br>
> + * @phy_clk_ns_l: low part of the PHY clock register<br>
> + * @phy_clk_ns_h: high part of the PHY clock register<br>
> + * @sys_time_ns_l: low part of the system time register<br>
> + * @sys_time_ns_h: high part of the system time register<br>
> + * @incval_l: low part of the increment value register<br>
> + * @incval_h: high part of the increment value register<br>
> + * @shadj_l: low part of the shadow adjust register<br>
> + * @shadj_h: high part of the shadow adjust register<br>
> + * phy_incval_l: low part of the PHY increment value register<br>
> + * phy_incval_h: high part of the PHY increment value register<br>
> + * phy_shadj_l: low part of the PHY shadow adjust register<br>
> + * phy_shadj_h: high part of the PHY shadow adjust register<br>
> + * @cmd: PTP command register<br>
> + * @phy_cmd: PHY command register<br>
> + * @cmd_sync: PTP command synchronization register<br>
> + */<br>
> +struct idpf_ptp_dev_clk_regs {<br>
> + /* Main clock */<br>
> + volatile uint32_t *dev_clk_ns_l;<br>
> + volatile uint32_t *dev_clk_ns_h;<br>
> +<br>
> + /* PHY timer */<br>
> + volatile uint32_t *phy_clk_ns_l;<br>
> + volatile uint32_t *phy_clk_ns_h;<br>
> +<br>
> + /* System time */<br>
> + volatile uint32_t *sys_time_ns_l;<br>
> + volatile uint32_t *sys_time_ns_h;<br>
> +<br>
> + /* Main timer adjustments */<br>
> + volatile uint32_t *incval_l;<br>
> + volatile uint32_t *incval_h;<br>
> + volatile uint32_t *shadj_l;<br>
> + volatile uint32_t *shadj_h;<br>
> +<br>
> + /* PHY timer adjustments */<br>
> + volatile uint32_t *phy_incval_l;<br>
> + volatile uint32_t *phy_incval_h;<br>
> + volatile uint32_t *phy_shadj_l;<br>
> + volatile uint32_t *phy_shadj_h;<br>
> +<br>
> + /* Command */<br>
> + volatile uint32_t *cmd;<br>
> + volatile uint32_t *phy_cmd;<br>
> + volatile uint32_t *cmd_sync;<br>
> +};<br>
> +<br>
> +/**<br>
> + * @enum idpf_ptp_access - the type of access to PTP operations<br>
> + * @IDPF_PTP_NONE: no access<br>
> + * @IDPF_PTP_DIRECT: direct access through BAR registers<br>
> + * @IDPF_PTP_MAILBOX: access through mailbox messages<br>
> + */<br>
> +enum idpf_ptp_access {<br>
> + IDPF_PTP_NONE = 0,<br>
> + IDPF_PTP_DIRECT,<br>
> + IDPF_PTP_MAILBOX,<br>
> +};<br>
> +<br>
> +/**<br>
> + * @struct idpf_ptp_secondary_mbx - PTP secondary mailbox<br>
> + * @peer_mbx_q_id: PTP mailbox queue ID<br>
> + * @peer_id: Peer ID for PTP Device Control daemon<br>
> + * @valid: indicates whether secondary mailblox is supported by the Control<br>
> + * Plane<br>
> + */<br>
> +struct idpf_ptp_secondary_mbx {<br>
> + uint16_t peer_mbx_q_id;<br>
> + uint16_t peer_id;<br>
> + bool valid:1;<br>
> +};<br>
> +<br>
> +/**<br>
> + * @enum idpf_ptp_tx_tstamp_state - Tx timestamp states<br>
> + * @IDPF_PTP_FREE: Tx timestamp index free to use<br>
> + * @IDPF_PTP_REQUEST: Tx timestamp index set to the Tx descriptor<br>
> + * @IDPF_PTP_READ_VALUE: Tx timestamp value ready to be read<br>
> + */<br>
> +enum idpf_ptp_tx_tstamp_state {<br>
> + IDPF_PTP_FREE,<br>
> + IDPF_PTP_REQUEST,<br>
> + IDPF_PTP_READ_VALUE,<br>
> +};<br>
> +<br>
> +/**<br>
> + * @struct idpf_ptp_tx_tstamp - Parameters for Tx timestamping<br>
> + * @list_member: the list member structure<br>
> + * @tx_latch_reg_offset_l: Tx tstamp latch low register offset<br>
> + * @tx_latch_reg_offset_h: Tx tstamp latch high register offset<br>
> + * @tstamp: the Tx tstamp value<br>
> + * @idx: the index of the Tx tstamp<br>
> + */<br>
> +struct idpf_ptp_tx_tstamp {<br>
> + uint64_t tstamp;<br>
> + uint32_t tx_latch_reg_offset_l;<br>
> + uint32_t tx_latch_reg_offset_h;<br>
> + uint32_t idx;<br>
> +};<br>
> +<br>
> +/**<br>
> + * @struct idpf_ptp_vport_tx_tstamp_caps - Tx timestamp capabilities<br>
> + * @vport_id: the vport id<br>
> + * @num_entries: the number of negotiated Tx timestamp entries<br>
> + * @tstamp_ns_lo_bit: first bit for nanosecond part of the timestamp<br>
> + * @access: indicates an access to Tx timestamp<br>
> + * @latches_index: the index of the latched Tx timestamps<br>
> + * @tx_tstamp: array of Tx timestamp parameters<br>
> + */<br>
> +struct idpf_ptp_vport_tx_tstamp_caps {<br>
> + uint32_t vport_id;<br>
> + uint16_t num_entries;<br>
> + uint16_t tstamp_ns_lo_bit;<br>
> + uint16_t latched_idx;<br>
> + bool access:1;<br>
> + struct idpf_ptp_tx_tstamp tx_tstamp[];<br>
> +};<br>
> +<br>
> +/**<br>
> + * @struct idpf_ptp - PTP parameters<br>
> + * @base_incval: base increment value of the PTP clock<br>
> + * @max_adj: maximum adjustment of the PTP clock<br>
> + * @cmd: HW specific command masks<br>
> + * @dev_clk_regs: the set of registers to access the device clock<br>
> + * @caps: PTP capabilities negotiated with the Control Plane<br>
> + * @get_dev_clk_time_access: access type for getting the device clock time<br>
> + * @get_cross_tstamp_access: access type for the cross timestamping<br>
> + * @set_dev_clk_time_access: access type for setting the device clock time<br>
> + * @adj_dev_clk_time_access: access type for the adjusting the device clock<br>
> + * @tx_tstamp_access: access type for the Tx timestamp value read<br>
> + * @rsv: Reserved fields<br>
> + * @secondary_mbx: parameters for using dedicated PTP mailbox<br>
> + */<br>
> +struct idpf_ptp {<br>
> + uint64_t base_incval;<br>
> + uint64_t max_adj;<br>
> + struct idpf_ptp_cmd cmd;<br>
> + struct idpf_ptp_dev_clk_regs dev_clk_regs;<br>
> + uint32_t caps;<br>
> + uint8_t get_dev_clk_time_access:2;<br>
> + uint8_t get_cross_tstamp_access:2;<br>
> + uint8_t set_dev_clk_time_access:2;<br>
> + uint8_t adj_dev_clk_time_access:2;<br>
> + uint8_t tx_tstamp_access:2;<br>
> + uint8_t rsv:6;<br>
> + struct idpf_ptp_secondary_mbx secondary_mbx;<br>
> +};<br>
> +<br>
> +/**<br>
> + * @struct idpf_ptp_dev_timers - System time and device time values<br>
> + * @sys_time_ns: system time value expressed in nanoseconds<br>
> + * @dev_clk_time_ns: device clock time value expressed in nanoseconds<br>
> + */<br>
> +struct idpf_ptp_dev_timers {<br>
> + uint64_t sys_time_ns;<br>
> + uint64_t dev_clk_time_ns;<br>
> +};<br>
> +<br>
> +int idpf_ptp_get_caps(struct idpf_adapter *adapter);<br>
> +int idpf_ptp_read_src_clk_reg(struct idpf_adapter *adapter, uint64_t *src_clk);<br>
> +int idpf_ptp_get_dev_clk_time(struct idpf_adapter *adapter,<br>
> + struct idpf_ptp_dev_timers *dev_clk_time);<br>
> +int idpf_ptp_get_cross_time(struct idpf_adapter *adapter,<br>
> + struct idpf_ptp_dev_timers *cross_time);<br>
> +int idpf_ptp_set_dev_clk_time(struct idpf_adapter *adapter, uint64_t time);<br>
> +int idpf_ptp_adj_dev_clk_fine(struct idpf_adapter *adapter, uint64_t incval);<br>
> +int idpf_ptp_adj_dev_clk_time(struct idpf_adapter *adapter, int64_t delta);<br>
> +int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport);<br>
> +int idpf_ptp_get_tx_tstamp(struct idpf_vport *vport);<br>
> +<br>
> +/* Helper function to convert a 32b nanoseconds timestamp to 64b. */<br>
> +static inline uint64_t<br>
> +idpf_tstamp_convert_32b_64b(struct idpf_adapter *ad, uint32_t flag,<br>
> + bool is_rx, uint32_t in_timestamp)<br>
> +{<br>
> + const uint64_t mask = 0xFFFFFFFF;<br>
> + uint32_t phc_time_lo, delta;<br>
> + uint64_t ns;<br>
> +<br>
> + if (flag != 0)<br>
> + idpf_ptp_read_src_clk_reg(ad, &ad->time_hw);<br>
> +<br>
> + /* Extract the lower 32 bits of the PHC time */<br>
> + phc_time_lo = (uint32_t)(ad->time_hw);<br>
> +<br>
> + /* Calculate the delta between the lower 32bits of the cached PHC<br>
> + * time and the in_timestamp value.<br>
> + */<br>
> + delta = in_timestamp - phc_time_lo;<br>
> +<br>
> + if (delta > mask / 2) {<br>
> + /* Reverse the delta calculation here */<br>
> + delta = phc_time_lo - in_timestamp;<br>
> + ns = ad->time_hw - delta;<br>
> + } else {<br>
> + if (is_rx)<br>
> + ns = ad->time_hw - delta;<br>
> + else<br>
> + ns = ad->time_hw + delta;<br>
> + }<br>
> +<br>
> + return ns;<br>
> +}<br>
> +#endif /* _IDPF_PTP_H_ */<br>
> diff --git a/drivers/net/intel/idpf/meson.build b/drivers/net/intel/idpf/meson.build<br>
> index a805d02ea2..5a4a3c2259 100644<br>
> --- a/drivers/net/intel/idpf/meson.build<br>
> +++ b/drivers/net/intel/idpf/meson.build<br>
> @@ -18,6 +18,7 @@ sources += files(<br>
> <br>
> 'idpf_ethdev.c',<br>
> 'idpf_rxtx.c',<br>
> + 'idpf_ptp.c',<br>
<br>
All lists in DPDK should be in alphabetical order, unless there is a reason<br>
they can't be. Therefore, this new C file should be above idpf_rxtx.c in<br>
the list.<br>
<br>
> )<br>
> <br>
> if arch_subdir == 'x86' and dpdk_conf.get('RTE_IOVA_IN_MBUF') == 1<br>
> --<br>
> 2.47.1<br>
></div>
</div>
</body>
</html>