kvaser_{pciefd,usb} fixes
cover kvaser_{pciefd,usb} fixes
The first patches fix net_device_stats when receiving error frames. The last two patches fix the CAN clock frequency for Kvaser Leaf devices.
Note that this series contains patches for both kvaser_usb and kvaser_pciefd driver.
Jimmy Assarsson (5):
can: kvaser_pciefd: Do not increase stats->rx_{packets,bytes} for
error frames
can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter
can: kvaser_usb: Do not increase stats->rx_{packets,bytes} for error
frames
can: kvaser_usb: Use CAN_MHZ define in assignment of frequency
can: kvaser_usb: Get CAN clock frequency from device
drivers/net/can/kvaser_pciefd.c | 11 +-- .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 13 ++-- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 70 ++++++++++++++++--- 3 files changed, 72 insertions(+), 22 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/5 can: kvaser_pciefd: Do not increase stats->rx_{packets,bytes} for error frames
Do not increase net_device_stats rx_{packets,bytes} when receiving error frames.
--- drivers/net/can/kvaser_pciefd.c | 3 --- 1 file changed, 3 deletions(-)
drivers/net/can/kvaser_pciefd.c +0 -3
@@ -1304,9 +1304,6 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; - stats->rx_packets++; - stats->rx_bytes += cf->len; -netif_rx (skb);return 0 ; }
Signature · 1 line
2.31.1
Re: [PATCH v1 1/5] can: kvaser_pciefd: Do not increase stats->rx_{packets,bytes} for error frames
Quoted 13 lines · Jimmy Assarsson
Do not increase
net_device_statsrx_{packets,bytes} when receiving error frames.Signed-off-by Jimmy Assarsson <[email protected]>--- drivers/net/can/kvaser_pciefd.c | 3 --- 1 file changed, 3 deletions(-)drivers/net/can/kvaser_pciefd.c +0
-0
drivers/net/can/kvaser_pciefd.c static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, · line 1309
Quoted 9 lines
drivers/net/can/kvaser_pciefd.c +0
-3@@ -1304,9 +1304,6 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; - stats->rx_packets++; - stats->rx_bytes += cf->len; -netif_rx (skb);return 0 ; }
I think that this patch makes sense because the CAN error frames do not exists on the wire: only an error flag is transmitted.
However, the current consensus is that the rx_packets and rx_bytes statistics should be incremented for CAN error frames. And I think that consistency between the drivers is the first priority.
I inquired here in the past to ask if it made sense to stop increasing the rx stats for CAN error frames:
But the discussion did not raise interest. I am fine to send a tree wide cleaning patch, but first, I would like to have people agree on this.
Re: [PATCH v1 1/5] can: kvaser_pciefd: Do not increase stats->rx_{packets,bytes} for error frames
Quoted 31 lines · Vincent Mailhol
Quoted 13 lines · Jimmy Assarsson
Do not increase
net_device_statsrx_{packets,bytes} when receiving error frames.Signed-off-by Jimmy Assarsson <[email protected]>--- drivers/net/can/kvaser_pciefd.c | 3 --- 1 file changed, 3 deletions(-)drivers/net/can/kvaser_pciefd.c +0
-0drivers/net/can/kvaser_pciefd.c static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, · line 1309
Quoted 9 lines
drivers/net/can/kvaser_pciefd.c +0
-3@@ -1304,9 +1304,6 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; - stats->rx_packets++; - stats->rx_bytes += cf->len; -netif_rx (skb);return 0 ; }I think that this patch makes sense because the CAN error frames do not exists on the wire: only an error flag is transmitted.
However, the current consensus is that the
rx_packetsandrx_bytesstatistics should be incremented for CAN error frames. And I think that consistency between the drivers is the first priority.
Quoted 8 lines
I inquired here in the past to ask if it made sense to stop increasing the rx stats for CAN error frames:
But the discussion did not raise interest. I am fine to send a tree wide cleaning patch, but first, I would like to have people agree on this.
Thanks, I've not seen that discussion.
I agree, it doesn't make sense for a user to see the rx_packets and rx_bytes increase, when in reality they didn't receive any valid frames.
This change started as a request from one of our customers, that got confused by the increase of rx_packets, when connected to a bus with wrong bitrate.
I'm in favour of a tree wide patch.
Best regards,
jimmy
PATCH 2/5 can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter
In reply to Jimmy AssarssonCheck the direction bit in the error frame packet (EPACK) to determine which net_device_stats {rx,tx}_errors counter to increase.
--- drivers/net/can/kvaser_pciefd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/can/kvaser_pciefd.c +7 -1
@@ -248,6 +248,9 @@ MODULE_DESCRIPTION("CAN driver for Kvaser CAN/PCIe devices");#define KVASER_PCIEFD_SPACK_EWLR BIT(23)#define KVASER_PCIEFD_SPACK_EPLR BIT(24) +/* Kvaser KCAN_EPACK second word */ +#define KVASER_PCIEFD_EPACK_DIR_TX BIT(0) +struct kvaser_pciefd ;struct kvaser_pciefd_can {
@@ -1285,7 +1288,10 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, can->err_rep_cnt++; can->can.can_stats.bus_error++; - stats->rx_errors++; +if (p->header[1 ] &KVASER_PCIEFD_EPACK_DIR_TX ) + stats->tx_errors++; +else + stats->rx_errors++; can->bec.txerr = bec.txerr; can->bec.rxerr = bec.rxerr;
Signature · 1 line
2.31.1
PATCH 3/5 can: kvaser_usb: Do not increase stats->rx_{packets,bytes} for error frames
In reply to Jimmy AssarssonDo not increase net_device_stats rx_{packets,bytes} when receiving error frames.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +0 -6
@@ -920,8 +920,6 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, cf->data[7 ] = bec->rxerr; stats = &netdev->stats; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); }
@@ -1074,8 +1072,6 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv, cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); priv->bec.txerr = bec.txerr;
@@ -1109,8 +1105,6 @@ static void kvaser_usb_hydra_one_shot_fail(struct kvaser_usb_net_priv *priv, } stats->tx_errors++; - stats->rx_packets++; - stats->rx_bytes += cf->len;netif_rx (skb); }
Signature · 1 line
2.31.1
PATCH 4/5 can: kvaser_usb: Use CAN_MHZ define in assignment of frequency
In reply to Jimmy AssarssonUse the CAN_MHZ define when assigning frequencies.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 7 ++++--- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +4 -3
@@ -25,6 +25,7 @@#include <linux/usb.h> #include <linux/can.h> +#include <linux/can/bittiming.h> #include <linux/can/dev.h> #include <linux/can/error.h> #include <linux/can/netlink.h>
@@ -2034,7 +2035,7 @@ const struct kvaser_usb_dev_ops kvaser_usb_hydra_dev_ops = {static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_kcan = { .clock = { - .freq =80000000 , + .freq =80 *CAN_MHZ , }, .timestamp_freq =80 , .bittiming_const = &kvaser_usb_hydra_kcan_bittiming_c,
@@ -2043,7 +2044,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_kcan = {static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_flexc = { .clock = { - .freq =24000000 , + .freq =24 *CAN_MHZ , }, .timestamp_freq =1 , .bittiming_const = &kvaser_usb_hydra_flexc_bittiming_c,
@@ -2051,7 +2052,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_flexc = {static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_rt = { .clock = { - .freq =80000000 , + .freq =80 *CAN_MHZ , }, .timestamp_freq =24 , .bittiming_const = &kvaser_usb_hydra_rt_bittiming_c,
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +2 -1
@@ -22,6 +22,7 @@#include <linux/usb.h> #include <linux/can.h> +#include <linux/can/bittiming.h> #include <linux/can/dev.h> #include <linux/can/error.h> #include <linux/can/netlink.h>
@@ -31,7 +32,7 @@/* Forward declaration */ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg; -#define CAN_USB_CLOCK 8000000 +#define CAN_USB_CLOCK (8 * CAN_MHZ)#define MAX_USBCAN_NET_DEVICES 2/* Command header size */
Signature · 1 line
2.31.1
Re: [PATCH v1 4/5] can: kvaser_usb: Use CAN_MHZ define in assignment of frequency
Quoted 1 line · Jimmy Assarsson
Use the
CAN_MHZdefine when assigning frequencies.
Maybe we should use the HZ_PER_MHZ define introduced in kernel 5.15 in linux/units.h. It also got defines for KILO and MEGA, which we also got in linux/can/bittiming.h.
What do you think?
...
Quoted 5 lines
static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_kcan = { .clock = {drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +1
-1- .freq = 80000000, + .freq = 80 * CAN_MHZ, },
Re: [PATCH v1 4/5] can: kvaser_usb: Use CAN_MHZ define in assignment of frequency
Quoted 9 lines · Jimmy Assarsson
Quoted 1 line · Jimmy Assarsson
Use the
CAN_MHZdefine when assigning frequencies.Maybe we should use the
HZ_PER_MHZdefine introduced in kernel 5.15 inlinux/units.h. It also got defines for KILO and MEGA, which we also got inlinux/can/bittiming.h.What do you think?
With the recent changes in linux/units.h, I am perfectly fine to remove the CAN_MHZ, CAN_KBPS and CAN_MBPS macros from linux/can/bittiming.h.
I am just bothered by the name of the macro HZ_PER_MHZ. Hertz per Mega Hertz is a ratio without a unit. The clock speed is expressed in hertz. So:
.frep = 80 * MEGA,
Re: [PATCH v1 4/5] can: kvaser_usb: Use CAN_MHZ define in assignment of frequency
(I inadvertently sent my previous message while I was still writing it, resending with full comments)
Quoted 9 lines · Jimmy Assarsson
Quoted 1 line · Jimmy Assarsson
Use the
CAN_MHZdefine when assigning frequencies.Maybe we should use the
HZ_PER_MHZdefine introduced in kernel 5.15 inlinux/units.h. It also got defines for KILO and MEGA, which we also got inlinux/can/bittiming.h.What do you think?
With the recent changes in linux/units.h, I am perfectly fine to remove the CAN_MHZ, CAN_KBPS and CAN_MBPS macros from linux/can/bittiming.h.
I am just bothered by the name of the macro HZ_PER_MHZ. Hertz per Mega Hertz is a ratio without a unit (physically speaking). The clock speed is expressed in hertz. So:
| .frep = 80 * MEGA,
would make more sense.
I see HZ_PER_MHZ as something used for conversion, e.g.:
| freq_in_hz = HZ_PER_MHZ * frep_in_mhz;
Yours sincerely,
Vincent Mailhol
PATCH 5/5 can: kvaser_usb: Get CAN clock frequency from device
In reply to Jimmy AssarssonGet the CAN clock frequency from device, since the various Kvaser Leaf products use different CAN clocks.
--- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 69 ++++++++++++++++--- 1 file changed, 60 insertions(+), 9 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +60 -9
@@ -29,10 +29,12 @@#include "kvaser_usb.h" -/* Forward declaration */ -static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg; +/* Forward declarations */ +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_8mhz; +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_16mhz; +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_24mhz; +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_32mhz; -#define CAN_USB_CLOCK (8 * CAN_MHZ)#define MAX_USBCAN_NET_DEVICES 2/* Command header size */
@@ -81,6 +83,12 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg;#define CMD_LEAF_LOG_MESSAGE 106 +/* Leaf frequency options */ +#define KVASER_USB_LEAF_SWOPTION_FREQ_MASK 0x60 +#define KVASER_USB_LEAF_SWOPTION_FREQ_16_MHZ_CLK 0 +#define KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK BIT(5) +#define KVASER_USB_LEAF_SWOPTION_FREQ_24_MHZ_CLK BIT(6) +/* error factors */ #define M16C_EF_ACKE BIT(0)#define M16C_EF_CRCE BIT(1)
@@ -472,6 +480,27 @@ static int kvaser_usb_leaf_send_simple_cmd(const struct kvaser_usb *dev,return rc; } +static void kvaser_usb_leaf_get_software_info_leaf (struct kvaser_usb *dev, +const struct leaf_cmd_softinfo *softinfo) +{ +u32 sw_options =le32_to_cpu (softinfo->sw_options); + + dev->fw_version =le32_to_cpu (softinfo->fw_version); + dev->max_tx_urbs =le16_to_cpu (softinfo->max_outstanding_tx); + +switch (sw_options &KVASER_USB_LEAF_SWOPTION_FREQ_MASK ) { +case KVASER_USB_LEAF_SWOPTION_FREQ_16_MHZ_CLK : + dev->cfg = &kvaser_usb_leaf_dev_cfg_16mhz; +break ; +case KVASER_USB_LEAF_SWOPTION_FREQ_24_MHZ_CLK : + dev->cfg = &kvaser_usb_leaf_dev_cfg_24mhz; +break ; +case KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK : + dev->cfg = &kvaser_usb_leaf_dev_cfg_32mhz; +break ; + } +} +static int kvaser_usb_leaf_get_software_info_inner (struct kvaser_usb *dev) {struct kvaser_cmd cmd;
@@ -487,14 +516,13 @@ static int kvaser_usb_leaf_get_software_info_inner(struct kvaser_usb *dev)switch (dev->card_data.leaf.family) {case KVASER_LEAF : - dev->fw_version =le32_to_cpu (cmd.u.leaf.softinfo.fw_version); - dev->max_tx_urbs = -le16_to_cpu (cmd.u.leaf.softinfo.max_outstanding_tx); +kvaser_usb_leaf_get_software_info_leaf (dev, &cmd.u.leaf.softinfo);break ;case KVASER_USBCAN : dev->fw_version =le32_to_cpu (cmd.u.usbcan.softinfo.fw_version); dev->max_tx_urbs =le16_to_cpu (cmd.u.usbcan.softinfo.max_outstanding_tx); + dev->cfg = &kvaser_usb_leaf_dev_cfg_8mhz;break ; }
@@ -1226,7 +1254,6 @@ static int kvaser_usb_leaf_init_card(struct kvaser_usb *dev) {struct kvaser_usb_dev_card_data *card_data = &dev->card_data; - dev->cfg = &kvaser_usb_leaf_dev_cfg; card_data->ctrlmode_supported |=CAN_CTRLMODE_3_SAMPLES ;return 0 ;
@@ -1350,9 +1377,33 @@ const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops = { .dev_frame_to_cmd = kvaser_usb_leaf_frame_to_cmd, }; -static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg = { +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_8mhz = { + .clock = { + .freq =8 *CAN_MHZ , + }, + .timestamp_freq =1 , + .bittiming_const = &kvaser_usb_leaf_bittiming_const, +}; + +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_16mhz = { + .clock = { + .freq =16 *CAN_MHZ , + }, + .timestamp_freq =1 , + .bittiming_const = &kvaser_usb_leaf_bittiming_const, +}; + +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_24mhz = { + .clock = { + .freq =24 *CAN_MHZ , + }, + .timestamp_freq =1 , + .bittiming_const = &kvaser_usb_leaf_bittiming_const, +}; + +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_32mhz = { .clock = { - .freq =CAN_USB_CLOCK , + .freq =32 *CAN_MHZ , }, .timestamp_freq =1 , .bittiming_const = &kvaser_usb_leaf_bittiming_const,
Signature · 1 line
2.31.1
Marc Kleine-Budde
maintainerQuoted 5 lines · Jimmy Assarsson
The first patches fix
net_device_statswhen receiving error frames. The last two patches fix the CAN clock frequency for Kvaser Leaf devices.Note that this series contains patches for both
kvaser_usbandkvaser_pciefddriver.
What's left of this series, after applying Vincent's stats cleanup [1] series?
[1]
https://lore.kernel.org/all/[email protected]/
Can you send a series only containing the remaining patches?
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 7 lines · Marc Kleine-Budde
Quoted 5 lines · Jimmy Assarsson
The first patches fix
net_device_statswhen receiving error frames. The last two patches fix the CAN clock frequency for Kvaser Leaf devices.Note that this series contains patches for both
kvaser_usbandkvaser_pciefddriver.
Quoted 7 lines
What's left of this series, after applying Vincent's stats cleanup [1] series?
[1]
https://lore.kernel.org/all/[email protected]/Can you send a series only containing the remaining patches?
Fixed https://lore.kernel.org/all/[email protected]
Best regards,
jimmy
Quoted 3 lines
regards,
Marc