diff mbox series

[SRU,B/E/F] can: peak_canfd: provide hw timestamps in rx skbs

Message ID 20200421183824.11442-1-sultan.alsawaf@canonical.com
State New
Headers show
Series [SRU,B/E/F] can: peak_canfd: provide hw timestamps in rx skbs | expand

Commit Message

Sultan Alsawaf April 21, 2020, 6:38 p.m. UTC
From: Stephane Grosjean <s.grosjean@peak-system.com>

BugLink: https://bugs.launchpad.net/bugs/1874124

PEAK-System's CAN FD interfaces based on an IP core provide a timestamp
for each CAN and STATUS message received. This patch transfers these
received timestamps (clocked in microseconds) to hardware timestamps
(clocked in nanoseconds) in the corresponding skbs raised to the network
layer.

Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
(cherry picked from commit 2b1a4547c122dcb9999e1a876236b44408c7d01c)
Signed-off-by: Sultan Alsawaf <sultan.alsawaf@canonical.com>
---
 drivers/net/can/peak_canfd/peak_canfd.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Comments

Khalid Elmously April 22, 2020, 7:32 a.m. UTC | #1
On 2020-04-21 11:38:24 , Sultan Alsawaf wrote:
> From: Stephane Grosjean <s.grosjean@peak-system.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1874124
> 
> PEAK-System's CAN FD interfaces based on an IP core provide a timestamp
> for each CAN and STATUS message received. This patch transfers these
> received timestamps (clocked in microseconds) to hardware timestamps
> (clocked in nanoseconds) in the corresponding skbs raised to the network
> layer.
> 
> Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> (cherry picked from commit 2b1a4547c122dcb9999e1a876236b44408c7d01c)
> Signed-off-by: Sultan Alsawaf <sultan.alsawaf@canonical.com>
> ---
>  drivers/net/can/peak_canfd/peak_canfd.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c
> index 6b0c6a99fc8d..e1876fbf7b14 100644
> --- a/drivers/net/can/peak_canfd/peak_canfd.c
> +++ b/drivers/net/can/peak_canfd/peak_canfd.c
> @@ -232,6 +232,20 @@ static int pucan_setup_rx_barrier(struct peak_canfd_priv *priv)
>  	return pucan_write_cmd(priv);
>  }
>  
> +static int pucan_netif_rx(struct sk_buff *skb, __le32 ts_low, __le32 ts_high)
> +{
> +	struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
> +	u64 ts_us;
> +
> +	ts_us = (u64)le32_to_cpu(ts_high) << 32;
> +	ts_us |= le32_to_cpu(ts_low);
> +
> +	/* IP core timestamps are µs. */
> +	hwts->hwtstamp = ns_to_ktime(ts_us * NSEC_PER_USEC);
> +
> +	return netif_rx(skb);
> +}
> +
>  /* handle the reception of one CAN frame */
>  static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
>  			       struct pucan_rx_msg *msg)
> @@ -299,7 +313,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
>  	stats->rx_bytes += cf->len;
>  	stats->rx_packets++;
>  
> -	netif_rx(skb);
> +	pucan_netif_rx(skb, msg->ts_low, msg->ts_high);
>  
>  	return 0;
>  }
> @@ -393,7 +407,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
>  
>  	stats->rx_packets++;
>  	stats->rx_bytes += cf->can_dlc;
> -	netif_rx(skb);
> +	pucan_netif_rx(skb, msg->ts_low, msg->ts_high);
>  
>  	return 0;
>  }

A link to the salesforce in the bug is fine.

Acked-by: Khalid Elmously <khalid.elmously@canonical.com>
Andrea Righi April 22, 2020, 7:39 a.m. UTC | #2
On Tue, Apr 21, 2020 at 11:38:24AM -0700, Sultan Alsawaf wrote:
> From: Stephane Grosjean <s.grosjean@peak-system.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1874124
> 
> PEAK-System's CAN FD interfaces based on an IP core provide a timestamp
> for each CAN and STATUS message received. This patch transfers these
> received timestamps (clocked in microseconds) to hardware timestamps
> (clocked in nanoseconds) in the corresponding skbs raised to the network
> layer.
> 
> Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> (cherry picked from commit 2b1a4547c122dcb9999e1a876236b44408c7d01c)
> Signed-off-by: Sultan Alsawaf <sultan.alsawaf@canonical.com>

Clean cherry pick, looks good to me.

Acked-by: Andrea Righi <andrea.righi@canonical.com>

> ---
>  drivers/net/can/peak_canfd/peak_canfd.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c
> index 6b0c6a99fc8d..e1876fbf7b14 100644
> --- a/drivers/net/can/peak_canfd/peak_canfd.c
> +++ b/drivers/net/can/peak_canfd/peak_canfd.c
> @@ -232,6 +232,20 @@ static int pucan_setup_rx_barrier(struct peak_canfd_priv *priv)
>  	return pucan_write_cmd(priv);
>  }
>  
> +static int pucan_netif_rx(struct sk_buff *skb, __le32 ts_low, __le32 ts_high)
> +{
> +	struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
> +	u64 ts_us;
> +
> +	ts_us = (u64)le32_to_cpu(ts_high) << 32;
> +	ts_us |= le32_to_cpu(ts_low);
> +
> +	/* IP core timestamps are µs. */
> +	hwts->hwtstamp = ns_to_ktime(ts_us * NSEC_PER_USEC);
> +
> +	return netif_rx(skb);
> +}
> +
>  /* handle the reception of one CAN frame */
>  static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
>  			       struct pucan_rx_msg *msg)
> @@ -299,7 +313,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
>  	stats->rx_bytes += cf->len;
>  	stats->rx_packets++;
>  
> -	netif_rx(skb);
> +	pucan_netif_rx(skb, msg->ts_low, msg->ts_high);
>  
>  	return 0;
>  }
> @@ -393,7 +407,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
>  
>  	stats->rx_packets++;
>  	stats->rx_bytes += cf->can_dlc;
> -	netif_rx(skb);
> +	pucan_netif_rx(skb, msg->ts_low, msg->ts_high);
>  
>  	return 0;
>  }
> -- 
> 2.20.1
> 
> 
> -- 
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
Kelsey Skunberg April 24, 2020, 5:20 p.m. UTC | #3
On 2020-04-21 11:38:24 , Sultan Alsawaf wrote:
> From: Stephane Grosjean <s.grosjean@peak-system.com>
> 
> BugLink: https://bugs.launchpad.net/bugs/1874124
> 
> PEAK-System's CAN FD interfaces based on an IP core provide a timestamp
> for each CAN and STATUS message received. This patch transfers these
> received timestamps (clocked in microseconds) to hardware timestamps
> (clocked in nanoseconds) in the corresponding skbs raised to the network
> layer.
> 
> Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> (cherry picked from commit 2b1a4547c122dcb9999e1a876236b44408c7d01c)
> Signed-off-by: Sultan Alsawaf <sultan.alsawaf@canonical.com>
> ---

Applied to master-next for Bionic, Eoan, and Focal. Thank you! 

-Kelsey

>  drivers/net/can/peak_canfd/peak_canfd.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c
> index 6b0c6a99fc8d..e1876fbf7b14 100644
> --- a/drivers/net/can/peak_canfd/peak_canfd.c
> +++ b/drivers/net/can/peak_canfd/peak_canfd.c
> @@ -232,6 +232,20 @@ static int pucan_setup_rx_barrier(struct peak_canfd_priv *priv)
>  	return pucan_write_cmd(priv);
>  }
>  
> +static int pucan_netif_rx(struct sk_buff *skb, __le32 ts_low, __le32 ts_high)
> +{
> +	struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
> +	u64 ts_us;
> +
> +	ts_us = (u64)le32_to_cpu(ts_high) << 32;
> +	ts_us |= le32_to_cpu(ts_low);
> +
> +	/* IP core timestamps are µs. */
> +	hwts->hwtstamp = ns_to_ktime(ts_us * NSEC_PER_USEC);
> +
> +	return netif_rx(skb);
> +}
> +
>  /* handle the reception of one CAN frame */
>  static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
>  			       struct pucan_rx_msg *msg)
> @@ -299,7 +313,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
>  	stats->rx_bytes += cf->len;
>  	stats->rx_packets++;
>  
> -	netif_rx(skb);
> +	pucan_netif_rx(skb, msg->ts_low, msg->ts_high);
>  
>  	return 0;
>  }
> @@ -393,7 +407,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
>  
>  	stats->rx_packets++;
>  	stats->rx_bytes += cf->can_dlc;
> -	netif_rx(skb);
> +	pucan_netif_rx(skb, msg->ts_low, msg->ts_high);
>  
>  	return 0;
>  }
> -- 
> 2.20.1
> 
> 
> -- 
> kernel-team mailing list
> kernel-team@lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team
diff mbox series

Patch

diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c
index 6b0c6a99fc8d..e1876fbf7b14 100644
--- a/drivers/net/can/peak_canfd/peak_canfd.c
+++ b/drivers/net/can/peak_canfd/peak_canfd.c
@@ -232,6 +232,20 @@  static int pucan_setup_rx_barrier(struct peak_canfd_priv *priv)
 	return pucan_write_cmd(priv);
 }
 
+static int pucan_netif_rx(struct sk_buff *skb, __le32 ts_low, __le32 ts_high)
+{
+	struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
+	u64 ts_us;
+
+	ts_us = (u64)le32_to_cpu(ts_high) << 32;
+	ts_us |= le32_to_cpu(ts_low);
+
+	/* IP core timestamps are µs. */
+	hwts->hwtstamp = ns_to_ktime(ts_us * NSEC_PER_USEC);
+
+	return netif_rx(skb);
+}
+
 /* handle the reception of one CAN frame */
 static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
 			       struct pucan_rx_msg *msg)
@@ -299,7 +313,7 @@  static int pucan_handle_can_rx(struct peak_canfd_priv *priv,
 	stats->rx_bytes += cf->len;
 	stats->rx_packets++;
 
-	netif_rx(skb);
+	pucan_netif_rx(skb, msg->ts_low, msg->ts_high);
 
 	return 0;
 }
@@ -393,7 +407,7 @@  static int pucan_handle_status(struct peak_canfd_priv *priv,
 
 	stats->rx_packets++;
 	stats->rx_bytes += cf->can_dlc;
-	netif_rx(skb);
+	pucan_netif_rx(skb, msg->ts_low, msg->ts_high);
 
 	return 0;
 }