kvaser_{pciefd,usb} fixes
v3 cover kvaser_{pciefd,usb} fixes
The first patch fix increase of the correctnet_device_stats {rx,tx}_errors counter, for kvaser_pciefd.
The last three patches fix the CAN clock frequency for Kvaser Leaf devices, for kvaser_usb.
Note that this series contains patches for both kvaser_usb and kvaser_pciefd driver.
Dropped patches;
[PATCH v1 1_5] can: kvaser_pciefd: Do not increase stats->rx_{packets,bytes} for error frames
[PATCH v1 3_5] can: kvaser_usb: Do not increase stats->rx_{packets,bytes} for error frames
and rebased on [PATCH v5 0/5] fix statistics and payload issues for error [1] series.
[1]
https://lore.kernel.org/all/[email protected]
Jimmy Assarsson (4):
can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter
can: kvaser_usb: Use CAN_MHZ define in assignment of frequency
can: kvaser_usb: Rearrange kvaser_usb_leaf_dev_cfg to avoid forward
declaration
can: kvaser_usb: Get CAN clock frequency from device
drivers/net/can/kvaser_pciefd.c | 8 +- .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 7 +- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 102 +++++++++++++----- 3 files changed, 85 insertions(+), 32 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/4 can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter
Check the direction bit in the error frame packet (EPACK) to determine which net_device_stats {rx,tx}_errors counter to increase.
---
Changes in v3:
- No changes.
Changes in v2:
- Rebased on [PATCH v5 0/5] fix statistics and payload issues for error [1] series.
[1]
https://lore.kernel.org/all/[email protected]
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 {
@@ -1286,7 +1289,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.34.1
Marc Kleine-Budde
maintainerRe: [PATCH v3 1/4] can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter
Quoted 4 lines · Jimmy Assarsson
Check the direction bit in the error frame packet (EPACK) to determine which
net_device_stats{rx,tx}_errors counter to increase.Signed-off-by Jimmy Assarsson <[email protected]>
Is this a fix that should be applied to the stable kernels? If so, which commit is fixed by this?
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 |
Marc Kleine-Budde
maintainerRe: [PATCH v3 1/4] can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter
Quoted 8 lines · Marc Kleine-Budde
Quoted 4 lines · Jimmy Assarsson
Check the direction bit in the error frame packet (EPACK) to determine which
net_device_stats{rx,tx}_errors counter to increase.Signed-off-by Jimmy Assarsson <[email protected]>Is this a fix that should be applied to the stable kernels? If so, which commit is fixed by this?
To me it looks like the problematic code has been in the mainline kernel since it was added. So I'll add a
| Fixes: 26ad340e582d ("can: kvaser_pciefd: Add driver for Kvaser PCIEcan devices")
tag, add stable on Cc and upstream this via net/master. Ok?
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 |
Re: [PATCH v3 1/4] can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter
Quoted 10 lines · Marc Kleine-Budde
Quoted 8 lines · Marc Kleine-Budde
Quoted 4 lines · Jimmy Assarsson
Check the direction bit in the error frame packet (EPACK) to determine which
net_device_stats{rx,tx}_errors counter to increase.Signed-off-by Jimmy Assarsson <[email protected]>Is this a fix that should be applied to the stable kernels? If so, which commit is fixed by this?
Quoted 6 lines
To me it looks like the problematic code has been in the mainline kernel since it was added. So I'll add a
| Fixes:
26ad340e582d("can:kvaser_pciefd: Add driver for Kvaser PCIEcan devices")tag, add stable on Cc and upstream this via net/master. Ok?
Sorry, forgot to add the Fixes tag.
Yes, it's correct :)
Thanks!
jimmy
Quoted 2 lines
regards,
Marc
PATCH v3 2/4 can: kvaser_usb: Use CAN_MHZ define in assignment of frequency
In reply to Jimmy AssarssonUse the CAN_MHZ define when assigning frequencies.
---
Changes in v3:
No changes.
Changes in v2:
- Rebased on [PATCH v5 0/5] fix statistics and payload issues for error [1] series.
[1]
https://lore.kernel.org/all/[email protected]
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>
@@ -2039,7 +2040,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,
@@ -2048,7 +2049,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,
@@ -2056,7 +2057,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.34.1
Marc Kleine-Budde
maintainerRe: [PATCH v3 2/4] can: kvaser_usb: Use CAN_MHZ define in assignment of frequency
Quoted 1 line · Jimmy Assarsson
Use the
CAN_MHZdefine when assigning frequencies.
I've change this to use MEGA /* Hz */, as CAN_MHZ has just been removed from the kernel, same for patch 4.
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 |
PATCH v3 3/4 can: kvaser_usb: Rearrange kvaser_usb_leaf_dev_cfg to avoid forward declaration
In reply to Jimmy AssarssonRearrange kvaser_usb_leaf_dev_cfg and kvaser_usb_leaf_bittiming_const. And remove forward declaration of kvaser_usb_leaf_dev_cfg.
--- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 43 +++++++++---------- 1 file changed, 20 insertions(+), 23 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +20 -23
@@ -29,9 +29,6 @@#include "kvaser_usb.h" -/* Forward declaration */ -static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg; -#define CAN_USB_CLOCK (8 * CAN_MHZ)#define MAX_USBCAN_NET_DEVICES 2
@@ -341,6 +338,26 @@ struct kvaser_usb_err_summary { }; }; +static const struct can_bittiming_const kvaser_usb_leaf_bittiming_const = { + .name ="kvaser_usb" , + .tseg1_min =KVASER_USB_TSEG1_MIN , + .tseg1_max =KVASER_USB_TSEG1_MAX , + .tseg2_min =KVASER_USB_TSEG2_MIN , + .tseg2_max =KVASER_USB_TSEG2_MAX , + .sjw_max =KVASER_USB_SJW_MAX , + .brp_min =KVASER_USB_BRP_MIN , + .brp_max =KVASER_USB_BRP_MAX , + .brp_inc =KVASER_USB_BRP_INC , +}; + +static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg = { + .clock = { + .freq =CAN_USB_CLOCK , + }, + .timestamp_freq =1 , + .bittiming_const = &kvaser_usb_leaf_bittiming_const, +}; +static void * kvaser_usb_leaf_frame_to_cmd(const struct kvaser_usb_net_priv *priv, const struct sk_buff *skb, int *cmd_len,
@@ -1226,18 +1243,6 @@ static int kvaser_usb_leaf_init_card(struct kvaser_usb *dev)return 0 ; } -static const struct can_bittiming_const kvaser_usb_leaf_bittiming_const = { - .name ="kvaser_usb" , - .tseg1_min =KVASER_USB_TSEG1_MIN , - .tseg1_max =KVASER_USB_TSEG1_MAX , - .tseg2_min =KVASER_USB_TSEG2_MIN , - .tseg2_max =KVASER_USB_TSEG2_MAX , - .sjw_max =KVASER_USB_SJW_MAX , - .brp_min =KVASER_USB_BRP_MIN , - .brp_max =KVASER_USB_BRP_MAX , - .brp_inc =KVASER_USB_BRP_INC , -}; -static int kvaser_usb_leaf_set_bittiming (struct net_device *netdev) {struct kvaser_usb_net_priv *priv =netdev_priv (netdev);
@@ -1343,11 +1348,3 @@ const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops = { .dev_read_bulk_callback = kvaser_usb_leaf_read_bulk_callback, .dev_frame_to_cmd = kvaser_usb_leaf_frame_to_cmd, }; - -static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg = { - .clock = { - .freq =CAN_USB_CLOCK , - }, - .timestamp_freq =1 , - .bittiming_const = &kvaser_usb_leaf_bittiming_const, -};
Signature · 1 line
2.34.1
PATCH v3 4/4 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.
---
Changes in v3:
- Rearranged kvaser_usb_leaf_dev_cfg_{8,16,24,32}mhz and removed forward declarations.
Changes in v2:
- Rebased on [PATCH v5 0/5] fix statistics and payload issues for error [1] series.
[1]
https://lore.kernel.org/all/[email protected]
.../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 62 ++++++++++++++++--- 1 file changed, 55 insertions(+), 7 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +55 -7
@@ -29,7 +29,6 @@#include "kvaser_usb.h" -#define CAN_USB_CLOCK (8 * CAN_MHZ)#define MAX_USBCAN_NET_DEVICES 2/* Command header size */
@@ -78,6 +77,12 @@#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)
@@ -350,9 +355,33 @@ static const struct can_bittiming_const kvaser_usb_leaf_bittiming_const = { .brp_inc = KVASER_USB_BRP_INC, }; -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 =CAN_USB_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 =32 *CAN_MHZ , }, .timestamp_freq =1 , .bittiming_const = &kvaser_usb_leaf_bittiming_const,
@@ -487,6 +516,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;
@@ -502,14 +552,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 ; }
@@ -1237,7 +1286,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 ;
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerRe: [PATCH v3 4/4] can: kvaser_usb: Get CAN clock frequency from device
Quoted 2 lines · Jimmy Assarsson
Get the CAN clock frequency from device, since the various Kvaser Leaf products use different CAN clocks.
Help me classify this patch. Is existing hardware that uses this driver broken without that patch?
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 |
Re: [PATCH v3 4/4] can: kvaser_usb: Get CAN clock frequency from device
Quoted 6 lines · Marc Kleine-Budde
Quoted 2 lines · Jimmy Assarsson
Get the CAN clock frequency from device, since the various Kvaser Leaf products use different CAN clocks.
Help me classify this patch. Is existing hardware that uses this driver broken without that patch?
Yes multiple old devices are affected by this bug.
devices)
Best regards,
jimmy
Quoted 2 lines
regards,
Marc