On Sat. 29 June 2024 at 04:56, Jimmy Assarsson <extja@xxxxxxxxxx> wrote: > Add, struct kvaser_cmd_tx_ack, for standard Tx ACK commands. > > Expand kvaser_usb_hydra_ktime_from_cmd() to extract timestamps from both > standard and extended Tx ACK commands. Unsupported commands are silently > ignored, and 0 is returned. > > Signed-off-by: Jimmy Assarsson <extja@xxxxxxxxxx> > --- > .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 23 ++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c > index a971fcb6158a..0be1cfe8d964 100644 > --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c > +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c > @@ -261,6 +261,15 @@ struct kvaser_cmd_tx_can { > u8 reserved[11]; > } __packed; > > +struct kvaser_cmd_tx_ack { > + __le32 id; > + u8 data[8]; > + u8 dlc; > + u8 flags; > + __le16 timestamp[3]; > + u8 reserved0[8]; > +} __packed; > + > struct kvaser_cmd_header { > u8 cmd_no; > /* The destination HE address is stored in 0..5 of he_addr. > @@ -297,6 +306,7 @@ struct kvaser_cmd { > > struct kvaser_cmd_rx_can rx_can; > struct kvaser_cmd_tx_can tx_can; > + struct kvaser_cmd_tx_ack tx_ack; > } __packed; > } __packed; > > @@ -525,16 +535,23 @@ kvaser_usb_hydra_net_priv_from_cmd(const struct kvaser_usb *dev, > static ktime_t kvaser_usb_hydra_ktime_from_cmd(const struct kvaser_usb_dev_cfg *cfg, > const struct kvaser_cmd *cmd) > { > - u64 ticks; > + u64 ticks = 0; > > if (cmd->header.cmd_no == CMD_EXTENDED) { > struct kvaser_cmd_ext *cmd_ext = (struct kvaser_cmd_ext *)cmd; > > - ticks = le64_to_cpu(cmd_ext->rx_can.timestamp); > - } else { > + if (cmd_ext->cmd_no_ext == CMD_RX_MESSAGE_FD) > + ticks = le64_to_cpu(cmd_ext->rx_can.timestamp); > + else if (cmd_ext->cmd_no_ext == CMD_TX_ACKNOWLEDGE_FD) > + ticks = le64_to_cpu(cmd_ext->tx_ack.timestamp); > + } else if (cmd->header.cmd_no == CMD_RX_MESSAGE) { > ticks = le16_to_cpu(cmd->rx_can.timestamp[0]); > ticks += (u64)(le16_to_cpu(cmd->rx_can.timestamp[1])) << 16; > ticks += (u64)(le16_to_cpu(cmd->rx_can.timestamp[2])) << 32; > + } else if (cmd->header.cmd_no == CMD_TX_ACKNOWLEDGE) { > + ticks = le16_to_cpu(cmd->tx_ack.timestamp[0]); > + ticks += (u64)(le16_to_cpu(cmd->tx_ack.timestamp[1])) << 16; > + ticks += (u64)(le16_to_cpu(cmd->tx_ack.timestamp[2])) << 32; Nitpick: the conversion of teh timestamp[3] array to the u64 tick is now duplicated. Maybe worth adding a kvaser_usb_hydra_convert_timestamp_to_ktime(__le16 *timestamp, u64 ticks); helper function to factorize this and the ns_to_ktime() all together? If you do so, it is better to add the new patch before this one. > } > > return ns_to_ktime(div_u64(ticks * 1000, cfg->timestamp_freq)); > -- > 2.45.2 > >