can: kvaser_usb: Add hardware timestamp support to all devices
v2 cover can: kvaser_usb: Add hardware timestamp support to all devices
From: Jimmy Assarsson <[email protected]>
This patch series add hardware timestamp support to all devices supported by the kvaser_usb driver.
The first patches resolves a known issue; "Hardware timestamps are not set for CAN Tx frames". I can't remember why this wasn't implemented in the first version of the hydra driver.
Followed by, hardware timestamp support for leaf and usbcan based devices.
The final patches are removing code used for selecting the correct ethtool and netdev ops.
Note: This patch series depends on patch
"can: kvaser_usb: Explicitly initialize family in leafimx..." [1].
[1] https://lore.kernel.org/linux-can/[email protected]
Changes in v2:
- Replaced patch 3/15
can: kvaser_usb: Add function kvaser_usb_ticks_to_ktime()
with a new patch
can: kvaser_usb: Add helper functions to convert device timestamp into ktime
and put it first in this series
- Resolved Vincent MAILHOL's review comments regarding duplicated code when converting timestamps [2] [3]
- As pointed out by Vincent MAILHOL [4], the clock overflow commands is not
dispatched in this patch
moved code from 10/15
can: kvaser_usb: leaf: Add structs for Tx ACK and clock overflow commands
to 11/15
can: kvaser_usb: leaf: Store MSB of timestamp
where it's actually used
[2] https://lore.kernel.org/linux-can/CAMZ6RqKSa-6KjvgfmN9eL7A=A65gMkYsRrnaF41Azhsc45FA2Q@mail.gmail.com/
[3] https://lore.kernel.org/linux-can/CAMZ6Rq+Xd7+th=dKV+vrqzRtS+GY-xq2UziH1CURcQ3HxEXMqQ@mail.gmail.com/
[4] https://lore.kernel.org/linux-can/CAMZ6RqKqJX6eqogS2598BFm-AN1uOBbBGL+MkoJtR=-z379Q=w@mail.gmail.com/
Jimmy Assarsson (15):
can: kvaser_usb: Add helper functions to convert device timestamp into
ktime
can: kvaser_usb: hydra: kvaser_usb_hydra_ktime_from_rx_cmd: Drop {rx_}
in function name
can: kvaser_usb: hydra: Add struct for Tx ACK commands
can: kvaser_usb: hydra: Set hardware timestamp on transmitted packets
can: kvaser_usb: leaf: Add struct for Tx ACK commands
can: kvaser_usb: leaf: Assign correct timestamp_freq for
kvaser_usb_leaf_imx_dev_cfg_{16,24,32}mhz
can: kvaser_usb: leaf: Replace kvaser_usb_leaf_m32c_dev_cfg with
kvaser_usb_leaf_m32c_dev_cfg_{16,24,32}mhz can: kvaser_usb: leaf: kvaser_usb_leaf_tx_acknowledge: Rename local
variable
can: kvaser_usb: leaf: Add hardware timestamp support to leaf based
devices
can: kvaser_usb: leaf: Add structs for Tx ACK and clock overflow
commands
can: kvaser_usb: leaf: Store MSB of timestamp
can: kvaser_usb: leaf: Add hardware timestamp support to usbcan
devices
can: kvaser_usb: Remove KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP
can: kvaser_usb: Remove struct variables
kvaser_usb_{ethtool,netdev}_ops
can: kvaser_usb: Rename kvaser_usb_{ethtool,netdev}_ops_hwts to
kvaser_usb_{ethtool,netdev}_ops
drivers/net/can/usb/kvaser_usb/kvaser_usb.h | 26 +++- .../net/can/usb/kvaser_usb/kvaser_usb_core.c | 21 +--- .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 41 +++++-- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 114 +++++++++++++++--- 4 files changed, 153 insertions(+), 49 deletions(-)
Signature · 1 line
2.45.2
PATCH v2 1/15 can: kvaser_usb: Add helper functions to convert device timestamp into ktime
Add helper function kvaser_usb_ticks_to_ktime() that converts from device ticks to ktime.
And kvaser_usb_timestamp{48,64}_to_ktime() that converts from device 48-bit or 64-bit timestamp, to ktime.
---
Changes in v2:
- New in v2. Replaces
can: kvaser_usb: Add function kvaser_usb_ticks_to_ktime()
- Add two more helper functions, kvaser_usb_timestamp{48,64}_to_ktime()
for converting timestamps, suggested by Vincent MAILHOL [2][3]
[2] https://lore.kernel.org/linux-can/CAMZ6RqKSa-6KjvgfmN9eL7A=A65gMkYsRrnaF41Azhsc45FA2Q@mail.gmail.com/
[3] https://lore.kernel.org/linux-can/CAMZ6Rq+Xd7+th=dKV+vrqzRtS+GY-xq2UziH1CURcQ3HxEXMqQ@mail.gmail.com/
drivers/net/can/usb/kvaser_usb/kvaser_usb.h | 24 +++++++++++++++++++ .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 10 ++++---- 2 files changed, 28 insertions(+), 6 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb.h +24 -0
@@ -22,6 +22,8 @@*/ #include <linux/completion.h> +#include <linux/ktime.h> +#include <linux/math64.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/usb.h>
@@ -216,4 +218,26 @@ int kvaser_usb_can_rx_over_error(struct net_device *netdev);extern const struct can_bittiming_const kvaser_usb_flexc_bittiming_const; +static inline ktime_t kvaser_usb_ticks_to_ktime (const struct kvaser_usb_dev_cfg *cfg, +u64 ticks) +{ +return ns_to_ktime (div_u64 (ticks *1000 , cfg->timestamp_freq)); +} + +static inline ktime_t kvaser_usb_timestamp48_to_ktime (const struct kvaser_usb_dev_cfg *cfg, +const __le16 *timestamp) +{ +u64 ticks =le16_to_cpu (timestamp[0 ]) | + (u64)(le16_to_cpu (timestamp[1 ])) <<16 | + (u64)(le16_to_cpu (timestamp[2 ])) <<32 ; + +return kvaser_usb_ticks_to_ktime (cfg, ticks); +} + +static inline ktime_t kvaser_usb_timestamp64_to_ktime (const struct kvaser_usb_dev_cfg *cfg, +__le64 timestamp) +{ +return kvaser_usb_ticks_to_ktime (cfg,le64_to_cpu (timestamp)); +} +#endif /* KVASER_USB_H */
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +4 -6
@@ -526,19 +526,17 @@ static ktime_t kvaser_usb_hydra_ktime_from_rx_cmd(const struct kvaser_usb_dev_cfg *cfg, const struct kvaser_cmd *cmd) { - u64 ticks; + ktime_t hwtstamp = 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); + hwtstamp =kvaser_usb_timestamp64_to_ktime (cfg, cmd_ext->rx_can.timestamp); }else { - 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 ; + hwtstamp =kvaser_usb_timestamp48_to_ktime (cfg, cmd->rx_can.timestamp); } -return ns_to_ktime (div_u64 (ticks *1000 , cfg->timestamp_freq)); +return hwtstamp; } static int kvaser_usb_hydra_send_simple_cmd(struct kvaser_usb *dev,
Signature · 1 line
2.45.2
Re: [PATCH can-next v2 01/15] can: kvaser_usb: Add helper functions to convert device timestamp into ktime
Quoted 75 lines · Jimmy Assarsson
Add helper function
kvaser_usb_ticks_to_ktime()that converts from device ticks to ktime.
And kvaser_usb_timestamp{48,64}_to_ktime() that converts from device 48-bit or 64-bit timestamp, to ktime.Signed-off-by Jimmy Assarsson <[email protected]>---
Changes in v2:
- New in v2. Replaces
can:kvaser_usb: Add functionkvaser_usb_ticks_to_ktime()
- Add two more helper functions, kvaser_usb_timestamp{48,64}_to_ktime()
for converting timestamps, suggested by Vincent MAILHOL [2][3]
[2] https://lore.kernel.org/linux-can/CAMZ6RqKSa-6KjvgfmN9eL7A=A65gMkYsRrnaF41Azhsc45FA2Q@mail.gmail.com/
[3] https://lore.kernel.org/linux-can/CAMZ6Rq+Xd7+th=dKV+vrqzRtS+GY-xq2UziH1CURcQ3HxEXMqQ@mail.gmail.com/drivers/net/can/usb/kvaser_usb/kvaser_usb.h | 24 +++++++++++++++++++ .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 10 ++++---- 2 files changed, 28 insertions(+), 6 deletions(-)drivers/net/can/usb/kvaser_usb/kvaser_usb.h +24
-0@@ -22,6 +22,8 @@*/ #include <linux/completion.h> +#include <linux/ktime.h> +#include <linux/math64.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/usb.h> @@ -216,4 +218,26 @@ int kvaser_usb_can_rx_over_error(struct net_device *netdev);extern const struct can_bittiming_const kvaser_usb_flexc_bittiming_const; +static inline ktime_t kvaser_usb_ticks_to_ktime (const struct kvaser_usb_dev_cfg *cfg, +u64 ticks) +{ +return ns_to_ktime (div_u64 (ticks *1000 , cfg->timestamp_freq)); +} + +static inline ktime_t kvaser_usb_timestamp48_to_ktime (const struct kvaser_usb_dev_cfg *cfg, +const __le16 *timestamp) +{ +u64 ticks =le16_to_cpu (timestamp[0 ]) | + (u64)(le16_to_cpu (timestamp[1 ])) <<16 | + (u64)(le16_to_cpu (timestamp[2 ])) <<32 ; + +return kvaser_usb_ticks_to_ktime (cfg, ticks); +} + +static inline ktime_t kvaser_usb_timestamp64_to_ktime (const struct kvaser_usb_dev_cfg *cfg, +__le64 timestamp) +{ +return kvaser_usb_ticks_to_ktime (cfg,le64_to_cpu (timestamp)); +} +#endif /* KVASER_USB_H */ drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +2
-2@@ -526,19 +526,17 @@ static ktime_t kvaser_usb_hydra_ktime_from_rx_cmd(const struct kvaser_usb_dev_cfg *cfg, const struct kvaser_cmd *cmd) { - u64 ticks; + ktime_t hwtstamp = 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); + hwtstamp =kvaser_usb_timestamp64_to_ktime (cfg, cmd_ext->rx_can.timestamp);
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c static ktime_t · line 540
Quoted 10 lines
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +2
-4}else { - 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 ; + hwtstamp =kvaser_usb_timestamp48_to_ktime (cfg, cmd->rx_can.timestamp); } -return ns_to_ktime (div_u64 (ticks *1000 , cfg->timestamp_freq)); +return hwtstamp; }
Nitpick: this can slightly be simplified by dropping the hwtstamp local variable:
kvaser_usb_hydra_ktime_from_rx_cmd(const struct kvaser_usb_dev_cfg *cfg,
const struct kvaser_cmd *cmd)
{
if (cmd->header.cmd_no == CMD_EXTENDED) {
struct kvaser_cmd_ext *cmd_ext = (struct kvaser_cmd_ext *)cmd;return kvaser_usb_timestamp64_to_ktime(cfg,
cmd_ext->rx_can.timestamp);
} else {
return kvaser_usb_timestamp48_to_ktime(cfg,
cmd->rx_can.timestamp);
}}
Quoted 5 lines
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +0
-1static int kvaser_usb_hydra_send_simple_cmd(struct kvaser_usb *dev, --2.45.2
Re: [PATCH can-next v2 01/15] can: kvaser_usb: Add helper functions to convert device timestamp into ktime
Quoted 96 lines · Vincent MAILHOL
Quoted 75 lines · Jimmy Assarsson
Add helper function
kvaser_usb_ticks_to_ktime()that converts from device ticks to ktime.
And kvaser_usb_timestamp{48,64}_to_ktime() that converts from device 48-bit or 64-bit timestamp, to ktime.Signed-off-by Jimmy Assarsson <[email protected]>---
Changes in v2:
- New in v2. Replaces
can:kvaser_usb: Add functionkvaser_usb_ticks_to_ktime()
- Add two more helper functions, kvaser_usb_timestamp{48,64}_to_ktime()
for converting timestamps, suggested by Vincent MAILHOL [2][3]
[2] https://lore.kernel.org/linux-can/CAMZ6RqKSa-6KjvgfmN9eL7A=A65gMkYsRrnaF41Azhsc45FA2Q@mail.gmail.com/
[3] https://lore.kernel.org/linux-can/CAMZ6Rq+Xd7+th=dKV+vrqzRtS+GY-xq2UziH1CURcQ3HxEXMqQ@mail.gmail.com/drivers/net/can/usb/kvaser_usb/kvaser_usb.h | 24 +++++++++++++++++++ .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 10 ++++---- 2 files changed, 28 insertions(+), 6 deletions(-)drivers/net/can/usb/kvaser_usb/kvaser_usb.h +24
-0@@ -22,6 +22,8 @@*/ #include <linux/completion.h> +#include <linux/ktime.h> +#include <linux/math64.h> #include <linux/spinlock.h> #include <linux/types.h> #include <linux/usb.h> @@ -216,4 +218,26 @@ int kvaser_usb_can_rx_over_error(struct net_device *netdev);extern const struct can_bittiming_const kvaser_usb_flexc_bittiming_const; +static inline ktime_t kvaser_usb_ticks_to_ktime (const struct kvaser_usb_dev_cfg *cfg, +u64 ticks) +{ +return ns_to_ktime (div_u64 (ticks *1000 , cfg->timestamp_freq)); +} + +static inline ktime_t kvaser_usb_timestamp48_to_ktime (const struct kvaser_usb_dev_cfg *cfg, +const __le16 *timestamp) +{ +u64 ticks =le16_to_cpu (timestamp[0 ]) | + (u64)(le16_to_cpu (timestamp[1 ])) <<16 | + (u64)(le16_to_cpu (timestamp[2 ])) <<32 ; + +return kvaser_usb_ticks_to_ktime (cfg, ticks); +} + +static inline ktime_t kvaser_usb_timestamp64_to_ktime (const struct kvaser_usb_dev_cfg *cfg, +__le64 timestamp) +{ +return kvaser_usb_ticks_to_ktime (cfg,le64_to_cpu (timestamp)); +} +#endif /* KVASER_USB_H */ drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +2
-2@@ -526,19 +526,17 @@ static ktime_t kvaser_usb_hydra_ktime_from_rx_cmd(const struct kvaser_usb_dev_cfg *cfg, const struct kvaser_cmd *cmd) { - u64 ticks; + ktime_t hwtstamp = 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); + hwtstamp =kvaser_usb_timestamp64_to_ktime (cfg, cmd_ext->rx_can.timestamp);drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c static ktime_t · line 540
Quoted 10 lines
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +2
-4}else { - 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 ; + hwtstamp =kvaser_usb_timestamp48_to_ktime (cfg, cmd->rx_can.timestamp); } -return ns_to_ktime (div_u64 (ticks *1000 , cfg->timestamp_freq)); +return hwtstamp; }Nitpick: this can slightly be simplified by dropping the hwtstamp local variable:
kvaser_usb_hydra_ktime_from_rx_cmd(const struct kvaser_usb_dev_cfg *cfg, const struct kvaser_cmd *cmd) { if (cmd->header.cmd_no == CMD_EXTENDED) { struct kvaser_cmd_ext *cmd_ext = (struct kvaser_cmd_ext *)cmd;
Quoted 7 lines
return kvaser_usb_timestamp64_to_ktime(cfg,
cmd_ext->rx_can.timestamp); } else { return kvaser_usb_timestamp48_to_ktime(cfg, cmd->rx_can.timestamp); }}
I'll keep it as is. I prefer to have a single return at the end of the function.
Regards,
/jimmy
PATCH v2 2/15 can: kvaser_usb: hydra: kvaser_usb_hydra_ktime_from_rx_cmd: Drop {rx_} in function name
In reply to Jimmy AssarssonRename function, since this function will be used for more than just the rx commands.
---
Changes in v2:
- No changes
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +4 -5
@@ -522,9 +522,8 @@ kvaser_usb_hydra_net_priv_from_cmd(const struct kvaser_usb *dev,return priv; } -static ktime_t -kvaser_usb_hydra_ktime_from_rx_cmd (const struct kvaser_usb_dev_cfg *cfg, -const struct kvaser_cmd *cmd) +static ktime_t kvaser_usb_hydra_ktime_from_cmd (const struct kvaser_usb_dev_cfg *cfg, +const struct kvaser_cmd *cmd) {ktime_t hwtstamp =0 ;
@@ -1232,7 +1231,7 @@ static void kvaser_usb_hydra_rx_msg_std(const struct kvaser_usb *dev, stats = &priv->netdev->stats; flags = cmd->rx_can.flags; - hwtstamp =kvaser_usb_hydra_ktime_from_rx_cmd (dev->cfg, cmd); + hwtstamp =kvaser_usb_hydra_ktime_from_cmd (dev->cfg, cmd);if (flags &KVASER_USB_HYDRA_CF_FLAG_ERROR_FRAME ) { kvaser_usb_hydra_error_frame(priv, &cmd->rx_can.err_frame_data,
@@ -1300,7 +1299,7 @@ static void kvaser_usb_hydra_rx_msg_ext(const struct kvaser_usb *dev,KVASER_USB_KCAN_DATA_DLC_SHIFT ; flags =le32_to_cpu (cmd->rx_can.flags); - hwtstamp =kvaser_usb_hydra_ktime_from_rx_cmd (dev->cfg, std_cmd); + hwtstamp =kvaser_usb_hydra_ktime_from_cmd (dev->cfg, std_cmd);if (flags &KVASER_USB_HYDRA_CF_FLAG_ERROR_FRAME ) { kvaser_usb_hydra_error_frame(priv, &cmd->rx_can.err_frame_data,
Signature · 1 line
2.45.2
PATCH v2 3/15 can: kvaser_usb: hydra: Add struct for Tx ACK commands
In reply to Jimmy AssarssonAdd, 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.
---
Changes in v2:
- Utilize new helper functions, from
can: kvaser_usb: Add helper functions to convert device timestamp into ktime
.../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +17 -2
@@ -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;
@@ -530,9 +540,14 @@ static ktime_t kvaser_usb_hydra_ktime_from_cmd(const struct kvaser_usb_dev_cfg *if (cmd->header.cmd_no ==CMD_EXTENDED ) {struct kvaser_cmd_ext *cmd_ext = (struct kvaser_cmd_ext *)cmd; - hwtstamp =kvaser_usb_timestamp64_to_ktime (cfg, cmd_ext->rx_can.timestamp); - }else { +if (cmd_ext->cmd_no_ext ==CMD_RX_MESSAGE_FD ) + hwtstamp =kvaser_usb_timestamp64_to_ktime (cfg, cmd_ext->rx_can.timestamp); +else if (cmd_ext->cmd_no_ext ==CMD_TX_ACKNOWLEDGE_FD ) + hwtstamp =kvaser_usb_timestamp64_to_ktime (cfg, cmd_ext->tx_ack.timestamp); + }else if (cmd->header.cmd_no ==CMD_RX_MESSAGE ) { hwtstamp =kvaser_usb_timestamp48_to_ktime (cfg, cmd->rx_can.timestamp); + }else if (cmd->header.cmd_no ==CMD_TX_ACKNOWLEDGE ) { + hwtstamp =kvaser_usb_timestamp48_to_ktime (cfg, cmd->tx_ack.timestamp); }return hwtstamp;
Signature · 1 line
2.45.2
PATCH v2 4/15 can: kvaser_usb: hydra: Set hardware timestamp on transmitted packets
In reply to Jimmy AssarssonSet hardware timestamp on transmitted packets.
---
Changes in v2:
- No changes
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +4 -1
@@ -10,7 +10,6 @@* - Transition from CAN_STATE_ERROR_WARNING to CAN_STATE_ERROR_ACTIVE is only * reported after a call to do_get_berr_counter(), since firmware does not * distinguish between ERROR_WARNING and ERROR_ACTIVE. -* - Hardware timestamps are not set for CAN Tx frames. */ #include <linux/completion.h>
@@ -1187,6 +1186,7 @@ static void kvaser_usb_hydra_tx_acknowledge(const struct kvaser_usb *dev,bool one_shot_fail = false;bool is_err_frame = false;u16 transid =kvaser_usb_hydra_get_cmd_transid (cmd); +struct sk_buff *skb; priv =kvaser_usb_hydra_net_priv_from_cmd (dev, cmd);if (!priv)
@@ -1213,6 +1213,9 @@ static void kvaser_usb_hydra_tx_acknowledge(const struct kvaser_usb *dev,spin_lock_irqsave (&priv->tx_contexts_lock, irq_flags); + skb = priv->can.echo_skb[context->echo_index]; +if (skb) +skb_hwtstamps (skb)->hwtstamp =kvaser_usb_hydra_ktime_from_cmd (dev->cfg, cmd); len =can_get_echo_skb (priv->netdev, context->echo_index,NULL ); context->echo_index = dev->max_tx_urbs; --priv->active_tx_contexts;
Signature · 1 line
2.45.2
PATCH v2 5/15 can: kvaser_usb: leaf: Add struct for Tx ACK commands
In reply to Jimmy AssarssonAdd, struct leaf_cmd_tx_acknowledge, for Tx ACK commands received from leaf devices (M32C and leafimx28).
---
Changes in v2:
- No changes
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +9 -1
@@ -235,6 +235,13 @@ struct kvaser_cmd_tx_acknowledge_header {u8 tid; } __packed; +struct leaf_cmd_tx_acknowledge { +u8 channel; +u8 tid; +__le16 time[3 ]; +u8 padding[2 ]; +} __packed; +struct leaf_cmd_can_error_event {u8 tid;u8 flags;
@@ -347,6 +354,7 @@ struct kvaser_cmd {struct leaf_cmd_error_event error_event;struct kvaser_cmd_cap_req cap_req;struct kvaser_cmd_cap_res cap_res; +struct leaf_cmd_tx_acknowledge tx_ack; }__packed leaf;union {
@@ -370,7 +378,7 @@ static const u8 kvaser_usb_leaf_cmd_sizes_leaf[] = { [CMD_START_CHIP_REPLY] = kvaser_fsize(u.simple), [CMD_STOP_CHIP_REPLY] = kvaser_fsize(u.simple), [CMD_GET_CARD_INFO_REPLY] = kvaser_fsize(u.cardinfo), - [CMD_TX_ACKNOWLEDGE] = kvaser_fsize(u.tx_acknowledge_header), + [CMD_TX_ACKNOWLEDGE] = kvaser_fsize(u.leaf.tx_ack), [CMD_GET_SOFTWARE_INFO_REPLY] = kvaser_fsize(u.leaf.softinfo), [CMD_RX_STD_MESSAGE] = kvaser_fsize(u.leaf.rx_can), [CMD_RX_EXT_MESSAGE] = kvaser_fsize(u.leaf.rx_can),
Signature · 1 line
2.45.2
PATCH v2 6/15 can: kvaser_usb: leaf: Assign correct timestamp_freq for kvaser_usb_leaf_imx_dev_cfg_{16,24,32}mhz
In reply to Jimmy AssarssonAssign correct timestamp_freq to kvaser_usb_leaf_imx_dev_cfg_{16,24,32}mhz. Since the driver didn't utilize the value, this didn't cause any problems.
---
Changes in v2:
- No changes
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +3 -3
@@ -483,7 +483,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_16mhz = { .clock = { .freq = 16 * MEGA /* Hz */, }, - .timestamp_freq = 1, + .timestamp_freq = 16, .bittiming_const = &kvaser_usb_flexc_bittiming_const, };
@@ -491,7 +491,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_24mhz = { .clock = { .freq = 24 * MEGA /* Hz */, }, - .timestamp_freq = 1, + .timestamp_freq = 24, .bittiming_const = &kvaser_usb_flexc_bittiming_const, };
@@ -499,7 +499,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_32mhz = { .clock = { .freq = 32 * MEGA /* Hz */, }, - .timestamp_freq = 1, + .timestamp_freq = 32, .bittiming_const = &kvaser_usb_flexc_bittiming_const, };
Signature · 1 line
2.45.2
PATCH v2 7/15 can: kvaser_usb: leaf: Replace kvaser_usb_leaf_m32c_dev_cfg with kvaser_usb_leaf_m32c_dev_cfg_{16,24,32}mhz
In reply to Jimmy AssarssonAdd new struct kvaser_usb_dev_cfg constants,
kvaser_usb_leaf_m32c_dev_cfg_{16,24,32}mhz,
for M32C based leaf devices.
Note that the bittiming parameters are always calculated for 16MHz clock, while the timestamps are in the actual clock frequency of the device.
---
Changes in v2:
- No changes
.../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +30 -3
@@ -471,11 +471,27 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_usbcan_dev_cfg = { .bittiming_const = &kvaser_usb_leaf_m16c_bittiming_const, }; -static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_m32c_dev_cfg = { +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_m32c_dev_cfg_16mhz = { .clock = { .freq =16 *MEGA /* Hz */ , }, - .timestamp_freq =1 , + .timestamp_freq =16 , + .bittiming_const = &kvaser_usb_leaf_m32c_bittiming_const, +}; + +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_m32c_dev_cfg_24mhz = { + .clock = { + .freq =16 *MEGA /* Hz */ , + }, + .timestamp_freq =24 , + .bittiming_const = &kvaser_usb_leaf_m32c_bittiming_const, +}; + +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_m32c_dev_cfg_32mhz = { + .clock = { + .freq =16 *MEGA /* Hz */ , + }, + .timestamp_freq =32 , .bittiming_const = &kvaser_usb_leaf_m32c_bittiming_const, };
@@ -686,8 +702,19 @@ static void kvaser_usb_leaf_get_software_info_leaf(struct kvaser_usb *dev,if (dev->driver_info->quirks &KVASER_USB_QUIRK_IGNORE_CLK_FREQ ) {/* Firmware expects bittiming parameters calculated for 16MHz * clock, regardless of the actual clock +* Though, the reported freq is used for timestamps */ - dev->cfg = &kvaser_usb_leaf_m32c_dev_cfg; +switch (sw_options &KVASER_USB_LEAF_SWOPTION_FREQ_MASK ) { +case KVASER_USB_LEAF_SWOPTION_FREQ_16_MHZ_CLK : + dev->cfg = &kvaser_usb_leaf_m32c_dev_cfg_16mhz; +break ; +case KVASER_USB_LEAF_SWOPTION_FREQ_24_MHZ_CLK : + dev->cfg = &kvaser_usb_leaf_m32c_dev_cfg_24mhz; +break ; +case KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK : + dev->cfg = &kvaser_usb_leaf_m32c_dev_cfg_32mhz; +break ; + } }else {switch (sw_options &KVASER_USB_LEAF_SWOPTION_FREQ_MASK ) {case KVASER_USB_LEAF_SWOPTION_FREQ_16_MHZ_CLK :
Signature · 1 line
2.45.2
PATCH v2 8/15 can: kvaser_usb: leaf: kvaser_usb_leaf_tx_acknowledge: Rename local variable
In reply to Jimmy AssarssonRename local variable skb to err_skb.
---
Changes in v2:
- No changes
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +4 -4
@@ -936,14 +936,14 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev,/* Sometimes the state change doesn't come after a bus-off event */ if (priv->can.restart_ms && priv->can.state ==CAN_STATE_BUS_OFF ) { -struct sk_buff *skb; +struct sk_buff *err_skb;struct can_frame *cf; - skb =alloc_can_err_skb (priv->netdev, &cf); -if (skb) { + err_skb =alloc_can_err_skb (priv->netdev, &cf); +if (err_skb) { cf->can_id |=CAN_ERR_RESTARTED ; -netif_rx (skb); +netif_rx (err_skb); }else {netdev_err (priv->netdev,"No memory left for err_skb\n" );
Signature · 1 line
2.45.2
PATCH v2 9/15 can: kvaser_usb: leaf: Add hardware timestamp support to leaf based devices
In reply to Jimmy AssarssonAdd hardware timestamp support to leaf based devices (M32C and leafimx).
---
Changes in v2:
- Utilize new helper functions, from
can: kvaser_usb: Add helper functions to convert device timestamp into ktime
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 11 +++++++---- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +7 -4
@@ -106,14 +106,16 @@ static const struct kvaser_usb_driver_info kvaser_usb_driver_info_usbcan = { };static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf = { - .quirks =KVASER_USB_QUIRK_IGNORE_CLK_FREQ , + .quirks =KVASER_USB_QUIRK_IGNORE_CLK_FREQ | +KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , .family =KVASER_LEAF , .ops = &kvaser_usb_leaf_dev_ops, };static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err = { .quirks =KVASER_USB_QUIRK_HAS_TXRX_ERRORS | -KVASER_USB_QUIRK_IGNORE_CLK_FREQ , +KVASER_USB_QUIRK_IGNORE_CLK_FREQ | +KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , .family =KVASER_LEAF , .ops = &kvaser_usb_leaf_dev_ops, };
@@ -121,13 +123,14 @@ static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err = {static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err_listen = { .quirks =KVASER_USB_QUIRK_HAS_TXRX_ERRORS |KVASER_USB_QUIRK_HAS_SILENT_MODE | -KVASER_USB_QUIRK_IGNORE_CLK_FREQ , +KVASER_USB_QUIRK_IGNORE_CLK_FREQ | +KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , .family =KVASER_LEAF , .ops = &kvaser_usb_leaf_dev_ops, };static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leafimx = { - .quirks =0 , + .quirks =KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , .family =KVASER_LEAF , .ops = &kvaser_usb_leaf_dev_ops, };
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +15 -0
@@ -915,6 +915,8 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev,struct kvaser_usb_net_priv *priv;unsigned long flags;u8 channel, tid; +struct sk_buff *skb; +ktime_t hwtstamp =0 ; channel = cmd->u.tx_acknowledge_header.channel; tid = cmd->u.tx_acknowledge_header.tid;
@@ -954,9 +956,19 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev, priv->can.state =CAN_STATE_ERROR_ACTIVE ; } +switch (dev->driver_info->family) { +case KVASER_LEAF : + hwtstamp =kvaser_usb_timestamp48_to_ktime (dev->cfg, cmd->u.leaf.tx_ack.time); +break ; +case KVASER_USBCAN : +break ; + }spin_lock_irqsave (&priv->tx_contexts_lock, flags); + skb = priv->can.echo_skb[context->echo_index]; +if (skb) +skb_hwtstamps (skb)->hwtstamp = hwtstamp; stats->tx_packets++; stats->tx_bytes +=can_get_echo_skb (priv->netdev, context->echo_index,NULL );
@@ -1334,6 +1346,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,struct net_device_stats *stats;u8 channel = cmd->u.rx_can_header.channel;const u8 *rx_data =NULL ;/* GCC */ +ktime_t hwtstamp =0 ;if (channel >= dev->nchannels) { dev_err(&dev->intf->dev,
@@ -1364,6 +1377,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,switch (dev->driver_info->family) {case KVASER_LEAF : rx_data = cmd->u.leaf.rx_can.data; + hwtstamp =kvaser_usb_timestamp48_to_ktime (dev->cfg, cmd->u.leaf.rx_can.time);break ;case KVASER_USBCAN : rx_data = cmd->u.usbcan.rx_can.data;
@@ -1410,6 +1424,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,memcpy (cf->data, &rx_data[6 ], cf->len); } +skb_hwtstamps (skb)->hwtstamp = hwtstamp; stats->rx_packets++;if (!(cf->can_id &CAN_RTR_FLAG )) stats->rx_bytes += cf->len;
Signature · 1 line
2.45.2
PATCH v2 10/15 can: kvaser_usb: leaf: Add structs for Tx ACK and clock overflow commands
In reply to Jimmy AssarssonFor usbcan devices (M16C), add struct usbcan_cmd_tx_acknowledge for Tx ACK commands and struct usbcan_cmd_clk_overflow_event for clock overflow event commands.
---
Changes in v2:
- Keep the "ignored events/commands" comments, since the patch that
actually dispatches the command, is later in this series
Pointed out by Vincent MAILHOL [1]
[1] https://lore.kernel.org/linux-can/CAMZ6RqKqJX6eqogS2598BFm-AN1uOBbBGL+MkoJtR=-z379Q=w@mail.gmail.com/
.../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +17 -2
@@ -242,6 +242,13 @@ struct leaf_cmd_tx_acknowledge {u8 padding[2 ]; } __packed; +struct usbcan_cmd_tx_acknowledge { +u8 channel; +u8 tid; +__le16 time; +u8 padding[2 ]; +} __packed; +struct leaf_cmd_can_error_event {u8 tid;u8 flags;
@@ -288,6 +295,12 @@ struct usbcan_cmd_error_event {__le16 padding; } __packed; +struct usbcan_cmd_clk_overflow_event { +u8 tid; +u8 padding; +__le32 time; +} __packed; +struct kvaser_cmd_ctrl_mode {u8 tid;u8 channel;
@@ -363,6 +376,8 @@ struct kvaser_cmd {struct usbcan_cmd_chip_state_event chip_state_event;struct usbcan_cmd_can_error_event can_error_event;struct usbcan_cmd_error_event error_event; +struct usbcan_cmd_tx_acknowledge tx_ack; +struct usbcan_cmd_clk_overflow_event clk_overflow_event; }__packed usbcan;struct kvaser_cmd_tx_can tx_can;
@@ -396,7 +411,7 @@ static const u8 kvaser_usb_leaf_cmd_sizes_usbcan[] = { [CMD_START_CHIP_REPLY] = kvaser_fsize(u.simple), [CMD_STOP_CHIP_REPLY] = kvaser_fsize(u.simple), [CMD_GET_CARD_INFO_REPLY] = kvaser_fsize(u.cardinfo), - [CMD_TX_ACKNOWLEDGE] = kvaser_fsize(u.tx_acknowledge_header), + [CMD_TX_ACKNOWLEDGE] = kvaser_fsize(u.usbcan.tx_ack), [CMD_GET_SOFTWARE_INFO_REPLY] = kvaser_fsize(u.usbcan.softinfo), [CMD_RX_STD_MESSAGE] = kvaser_fsize(u.usbcan.rx_can), [CMD_RX_EXT_MESSAGE] = kvaser_fsize(u.usbcan.rx_can),
@@ -404,7 +419,7 @@ static const u8 kvaser_usb_leaf_cmd_sizes_usbcan[] = { [CMD_CAN_ERROR_EVENT] = kvaser_fsize(u.usbcan.can_error_event), [CMD_ERROR_EVENT] = kvaser_fsize(u.usbcan.error_event),/* ignored events: */ - [CMD_USBCAN_CLOCK_OVERFLOW_EVENT] = CMD_SIZE_ANY, + [CMD_USBCAN_CLOCK_OVERFLOW_EVENT] = kvaser_fsize(u.usbcan.clk_overflow_event), };/* Summary of a kvaser error event, for a unified Leaf/Usbcan error
Signature · 1 line
2.45.2
PATCH v2 11/15 can: kvaser_usb: leaf: Store MSB of timestamp
In reply to Jimmy AssarssonStore MSB of timestamp, provided from the device via the clock overflow event, for usbcan devices (M16C).
---
Changes in v2:
- Remove the "ignored events/commands" comments, since here we handle the clock overflow command
drivers/net/can/usb/kvaser_usb/kvaser_usb.h | 1 + drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb.h +1 -0
@@ -70,6 +70,7 @@ struct kvaser_usb_dev_card_data {u32 ctrlmode_supported;u32 capabilities;struct kvaser_usb_dev_card_data_hydra hydra; +u32 usbcan_timestamp_msb; };/* Context for an outstanding, not yet ACKed, transmission */
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +8 -3
@@ -119,6 +119,9 @@/* Extended CAN identifier flag */ #define KVASER_EXTENDED_FRAME BIT(31) +/* USBCanII timestamp */ +#define KVASER_USB_USBCAN_CLK_OVERFLOW_MASK GENMASK(31, 16) +struct kvaser_cmd_simple {u8 tid;u8 channel;
@@ -418,7 +421,6 @@ static const u8 kvaser_usb_leaf_cmd_sizes_usbcan[] = { [CMD_CHIP_STATE_EVENT] = kvaser_fsize(u.usbcan.chip_state_event), [CMD_CAN_ERROR_EVENT] = kvaser_fsize(u.usbcan.can_error_event), [CMD_ERROR_EVENT] = kvaser_fsize(u.usbcan.error_event), -/* ignored events: */ [CMD_USBCAN_CLOCK_OVERFLOW_EVENT] = kvaser_fsize(u.usbcan.clk_overflow_event), };
@@ -1573,7 +1575,7 @@ static void kvaser_usb_leaf_get_busparams_reply(const struct kvaser_usb *dev,complete (&priv->get_busparams_comp); } -static void kvaser_usb_leaf_handle_command (const struct kvaser_usb *dev, +static void kvaser_usb_leaf_handle_command (struct kvaser_usb *dev,const struct kvaser_cmd *cmd) {if (kvaser_usb_leaf_verify_size (dev, cmd) <0 )
@@ -1619,12 +1621,15 @@ static void kvaser_usb_leaf_handle_command(const struct kvaser_usb *dev,kvaser_usb_leaf_get_busparams_reply (dev, cmd);break ; -/* Ignored commands */ case CMD_USBCAN_CLOCK_OVERFLOW_EVENT :if (dev->driver_info->family !=KVASER_USBCAN ) goto warn; + dev->card_data.usbcan_timestamp_msb = +le32_to_cpu (cmd->u.usbcan.clk_overflow_event.time) & +KVASER_USB_USBCAN_CLK_OVERFLOW_MASK ;break ; +/* Ignored commands */ case CMD_FLUSH_QUEUE_REPLY :if (dev->driver_info->family !=KVASER_LEAF ) goto warn;
Signature · 1 line
2.45.2
PATCH v2 12/15 can: kvaser_usb: leaf: Add hardware timestamp support to usbcan devices
In reply to Jimmy AssarssonAdd hardware timestamp support for all usbcan based devices (M16C). The usbcan firmware is slightly different compared to the other Kvaser USB interfaces:
- The timestamp is provided by a 32-bit counter, with 10us resolution. Hence, the hardware timestamp will wrap after less than 12 hours.
- Each Rx CAN or Tx ACK command only contains the 16-bits LSB of the timestamp counter.
- The 16-bits MSB are sent in an asynchronous event (command), if any change occurred in the MSB since the last event.
---
Changes in v2:
- Add new helper function kvaser_usb_usbcan_timestamp_to_ktime()
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 3 ++- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +2 -1
@@ -100,7 +100,8 @@ static const struct kvaser_usb_driver_info kvaser_usb_driver_info_hydra = {static const struct kvaser_usb_driver_info kvaser_usb_driver_info_usbcan = { .quirks =KVASER_USB_QUIRK_HAS_TXRX_ERRORS | -KVASER_USB_QUIRK_HAS_SILENT_MODE , +KVASER_USB_QUIRK_HAS_SILENT_MODE | +KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , .family =KVASER_USBCAN , .ops = &kvaser_usb_leaf_dev_ops, };
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +12 -0
@@ -121,6 +121,7 @@/* USBCanII timestamp */ #define KVASER_USB_USBCAN_CLK_OVERFLOW_MASK GENMASK(31, 16) +#define KVASER_USB_USBCAN_TIMESTAMP_FACTOR 10struct kvaser_cmd_simple {u8 tid;
@@ -536,6 +537,15 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_32mhz = { .bittiming_const = &kvaser_usb_flexc_bittiming_const, }; +static inline ktime_t kvaser_usb_usbcan_timestamp_to_ktime (const struct kvaser_usb *dev, +__le16 timestamp) +{ +u64 ticks =le16_to_cpu (timestamp) | + dev->card_data.usbcan_timestamp_msb; + +return kvaser_usb_ticks_to_ktime (dev->cfg, ticks *KVASER_USB_USBCAN_TIMESTAMP_FACTOR ); +} +static int kvaser_usb_leaf_verify_size (const struct kvaser_usb *dev,const struct kvaser_cmd *cmd) {
@@ -978,6 +988,7 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev, hwtstamp =kvaser_usb_timestamp48_to_ktime (dev->cfg, cmd->u.leaf.tx_ack.time);break ;case KVASER_USBCAN : + hwtstamp =kvaser_usb_usbcan_timestamp_to_ktime (dev, cmd->u.usbcan.tx_ack.time);break ; }
@@ -1398,6 +1409,7 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,break ;case KVASER_USBCAN : rx_data = cmd->u.usbcan.rx_can.data; + hwtstamp =kvaser_usb_usbcan_timestamp_to_ktime (dev, cmd->u.usbcan.rx_can.time);break ; }
Signature · 1 line
2.45.2
PATCH v2 13/15 can: kvaser_usb: Remove KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP
In reply to Jimmy AssarssonRemove KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP, since all devices got hardware timestamp support.
---
Changes in v2:
- No changes
drivers/net/can/usb/kvaser_usb/kvaser_usb.h | 1 - .../net/can/usb/kvaser_usb/kvaser_usb_core.c | 26 ++++++------------- 2 files changed, 8 insertions(+), 19 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb.h +0 -1
@@ -41,7 +41,6 @@#define KVASER_USB_QUIRK_HAS_SILENT_MODE BIT(0)#define KVASER_USB_QUIRK_HAS_TXRX_ERRORS BIT(1)#define KVASER_USB_QUIRK_IGNORE_CLK_FREQ BIT(2) -#define KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP BIT(3)/* Device capabilities */ #define KVASER_USB_CAP_BERR_CAP 0x01
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +8 -18
@@ -94,29 +94,26 @@#define USB_MINI_PCIE_1XCAN_PRODUCT_ID 0x011Bstatic const struct kvaser_usb_driver_info kvaser_usb_driver_info_hydra = { - .quirks =KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , + .quirks =0 , .ops = &kvaser_usb_hydra_dev_ops, };static const struct kvaser_usb_driver_info kvaser_usb_driver_info_usbcan = { .quirks =KVASER_USB_QUIRK_HAS_TXRX_ERRORS | -KVASER_USB_QUIRK_HAS_SILENT_MODE | -KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , +KVASER_USB_QUIRK_HAS_SILENT_MODE , .family =KVASER_USBCAN , .ops = &kvaser_usb_leaf_dev_ops, };static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf = { - .quirks =KVASER_USB_QUIRK_IGNORE_CLK_FREQ | -KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , + .quirks =KVASER_USB_QUIRK_IGNORE_CLK_FREQ , .family =KVASER_LEAF , .ops = &kvaser_usb_leaf_dev_ops, };static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err = { .quirks =KVASER_USB_QUIRK_HAS_TXRX_ERRORS | -KVASER_USB_QUIRK_IGNORE_CLK_FREQ | -KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , +KVASER_USB_QUIRK_IGNORE_CLK_FREQ , .family =KVASER_LEAF , .ops = &kvaser_usb_leaf_dev_ops, };
@@ -124,14 +121,13 @@ static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err = {static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err_listen = { .quirks =KVASER_USB_QUIRK_HAS_TXRX_ERRORS |KVASER_USB_QUIRK_HAS_SILENT_MODE | -KVASER_USB_QUIRK_IGNORE_CLK_FREQ | -KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , +KVASER_USB_QUIRK_IGNORE_CLK_FREQ , .family =KVASER_LEAF , .ops = &kvaser_usb_leaf_dev_ops, };static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leafimx = { - .quirks =KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP , + .quirks =0 , .family =KVASER_LEAF , .ops = &kvaser_usb_leaf_dev_ops, };
@@ -862,14 +858,8 @@ static int kvaser_usb_init_one(struct kvaser_usb *dev, int channel) netdev->flags |=IFF_ECHO ; - netdev->netdev_ops = &kvaser_usb_netdev_ops; -if (driver_info->quirks &KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP ) { - netdev->netdev_ops = &kvaser_usb_netdev_ops_hwts; - netdev->ethtool_ops = &kvaser_usb_ethtool_ops_hwts; - }else { - netdev->netdev_ops = &kvaser_usb_netdev_ops; - netdev->ethtool_ops = &kvaser_usb_ethtool_ops; - } + netdev->netdev_ops = &kvaser_usb_netdev_ops_hwts; + netdev->ethtool_ops = &kvaser_usb_ethtool_ops_hwts;SET_NETDEV_DEV (netdev, &dev->intf->dev); netdev->dev_id = channel;
Signature · 1 line
2.45.2
PATCH v2 14/15 can: kvaser_usb: Remove struct variables kvaser_usb_{ethtool,netdev}_ops
In reply to Jimmy AssarssonRemove no longer used struct variables, kvaser_usb_ethtool_ops and kvaser_usb_netdev_ops.
---
Changes in v2:
- No changes
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 11 ----------- 1 file changed, 11 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +0 -11
@@ -753,13 +753,6 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb,return ret; } -static const struct net_device_ops kvaser_usb_netdev_ops = { - .ndo_open = kvaser_usb_open, - .ndo_stop = kvaser_usb_close, - .ndo_start_xmit = kvaser_usb_start_xmit, - .ndo_change_mtu = can_change_mtu, -}; -static const struct net_device_ops kvaser_usb_netdev_ops_hwts = { .ndo_open = kvaser_usb_open, .ndo_stop = kvaser_usb_close,
@@ -768,10 +761,6 @@ static const struct net_device_ops kvaser_usb_netdev_ops_hwts = { .ndo_change_mtu = can_change_mtu, }; -static const struct ethtool_ops kvaser_usb_ethtool_ops = { - .get_ts_info = ethtool_op_get_ts_info, -}; -static const struct ethtool_ops kvaser_usb_ethtool_ops_hwts = { .get_ts_info = can_ethtool_op_get_ts_info_hwts, };
Signature · 1 line
2.45.2
PATCH v2 15/15 can: kvaser_usb: Rename kvaser_usb_{ethtool,netdev}_ops_hwts to kvaser_usb_{ethtool,netdev}_ops
In reply to Jimmy AssarssonNow when we only got one set of ethtool_ops and netdev_ops, remove the "hwts" suffix from the struct variables kvaser_usb_{ethtool,netdev}_ops_hwts.
---
Changes in v2:
- No changes
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +4 -4
@@ -753,7 +753,7 @@ static netdev_tx_t kvaser_usb_start_xmit(struct sk_buff *skb,return ret; } -static const struct net_device_ops kvaser_usb_netdev_ops_hwts = { +static const struct net_device_ops kvaser_usb_netdev_ops = { .ndo_open = kvaser_usb_open, .ndo_stop = kvaser_usb_close, .ndo_eth_ioctl = can_eth_ioctl_hwts,
@@ -761,7 +761,7 @@ static const struct net_device_ops kvaser_usb_netdev_ops_hwts = { .ndo_change_mtu = can_change_mtu, }; -static const struct ethtool_ops kvaser_usb_ethtool_ops_hwts = { +static const struct ethtool_ops kvaser_usb_ethtool_ops = { .get_ts_info = can_ethtool_op_get_ts_info_hwts, };
@@ -847,8 +847,8 @@ static int kvaser_usb_init_one(struct kvaser_usb *dev, int channel) netdev->flags |=IFF_ECHO ; - netdev->netdev_ops = &kvaser_usb_netdev_ops_hwts; - netdev->ethtool_ops = &kvaser_usb_ethtool_ops_hwts; + netdev->netdev_ops = &kvaser_usb_netdev_ops; + netdev->ethtool_ops = &kvaser_usb_ethtool_ops;SET_NETDEV_DEV (netdev, &dev->intf->dev); netdev->dev_id = channel;
Signature · 1 line
2.45.2
Quoted 11 lines · Jimmy Assarsson
From: Jimmy Assarsson <[email protected]>
This patch series add hardware timestamp support to all devices supported by the
kvaser_usbdriver.The first patches resolves a known issue; "Hardware timestamps are not set for CAN Tx frames". I can't remember why this wasn't implemented in the first version of the hydra driver.
Followed by, hardware timestamp support for leaf and usbcan based devices.
Quoted 7 lines
The final patches are removing code used for selecting the correct ethtool and netdev ops.
Note: This patch series depends on patch
"can:kvaser_usb: Explicitly initialize family in leafimx..." [1].
Thanks for taking care of the TX timestamps!
I left one nitpick which is notwithstanding. With or without my comment addressed and for the full series:
Quoted 18 lines · Vincent MAILHOL
Quoted 17 lines · Jimmy Assarsson
From: Jimmy Assarsson <[email protected]>
This patch series add hardware timestamp support to all devices supported by the
kvaser_usbdriver.The first patches resolves a known issue; "Hardware timestamps are not set for CAN Tx frames". I can't remember why this wasn't implemented in the first version of the hydra driver.
Followed by, hardware timestamp support for leaf and usbcan based devices.
The final patches are removing code used for selecting the correct ethtool and netdev ops.
Note: This patch series depends on patch
"can:kvaser_usb: Explicitly initialize family in leafimx..." [1].
Quoted 8 lines
Quoted 1 line
Thanks for taking care of the TX timestamps!
I left one nitpick which is notwithstanding. With or without my comment addressed and for the full series:
Reviewed-by Vincent Mailhol <[email protected]>
Again, thanks for reviewing!
Regards,
jimmy