All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] kvaser_{pciefd,usb} fixes
@ 2021-12-08 11:09 Jimmy Assarsson
  2021-12-08 11:09 ` [PATCH v2 1/3] can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter Jimmy Assarsson
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jimmy Assarsson @ 2021-12-08 11:09 UTC (permalink / raw)
  To: linux-can; +Cc: Jimmy Assarsson, Jimmy Assarsson

The first patch fix increase of the correct
net_device_stats {rx,tx}_errors counter, for kvaser_pciefd.
The last two 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/20211207121531.42941-1-mailhol.vincent@wanadoo.fr

Jimmy Assarsson (3):
  can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter
  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               |  8 ++-
 .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c |  7 +-
 .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c  | 70 ++++++++++++++++---
 3 files changed, 72 insertions(+), 13 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter
  2021-12-08 11:09 [PATCH v2 0/3] kvaser_{pciefd,usb} fixes Jimmy Assarsson
@ 2021-12-08 11:09 ` Jimmy Assarsson
  2021-12-08 11:09 ` [PATCH v2 2/3] can: kvaser_usb: Use CAN_MHZ define in assignment of frequency Jimmy Assarsson
  2021-12-08 11:09 ` [PATCH v2 3/3] can: kvaser_usb: Get CAN clock frequency from device Jimmy Assarsson
  2 siblings, 0 replies; 6+ messages in thread
From: Jimmy Assarsson @ 2021-12-08 11:09 UTC (permalink / raw)
  To: linux-can; +Cc: Jimmy Assarsson, 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 <extja@kvaser.com>
---
Changes in v2:
  - Rebased on [PATCH v5 0/5] fix statistics and payload issues for
    error [1] series.

[1]
https://lore.kernel.org/all/20211207121531.42941-1-mailhol.vincent@wanadoo.fr

 drivers/net/can/kvaser_pciefd.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/kvaser_pciefd.c b/drivers/net/can/kvaser_pciefd.c
index 6fd6bed04577..017f2d36ffc3 100644
--- a/drivers/net/can/kvaser_pciefd.c
+++ b/drivers/net/can/kvaser_pciefd.c
@@ -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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] can: kvaser_usb: Use CAN_MHZ define in assignment of frequency
  2021-12-08 11:09 [PATCH v2 0/3] kvaser_{pciefd,usb} fixes Jimmy Assarsson
  2021-12-08 11:09 ` [PATCH v2 1/3] can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter Jimmy Assarsson
@ 2021-12-08 11:09 ` Jimmy Assarsson
  2021-12-08 11:09 ` [PATCH v2 3/3] can: kvaser_usb: Get CAN clock frequency from device Jimmy Assarsson
  2 siblings, 0 replies; 6+ messages in thread
From: Jimmy Assarsson @ 2021-12-08 11:09 UTC (permalink / raw)
  To: linux-can; +Cc: Jimmy Assarsson, Jimmy Assarsson

Use the CAN_MHZ define when assigning frequencies.

Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
---
Changes in v2:
  - Rebased on [PATCH v5 0/5] fix statistics and payload issues for
    error [1] series.

[1]
https://lore.kernel.org/all/20211207121531.42941-1-mailhol.vincent@wanadoo.fr

 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(-)

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 3cbb7f3051f1..48d87758e6d0 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
@@ -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,
diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
index 47fa7f5a11c6..533e25cb4337 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
@@ -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 */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] can: kvaser_usb: Get CAN clock frequency from device
  2021-12-08 11:09 [PATCH v2 0/3] kvaser_{pciefd,usb} fixes Jimmy Assarsson
  2021-12-08 11:09 ` [PATCH v2 1/3] can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter Jimmy Assarsson
  2021-12-08 11:09 ` [PATCH v2 2/3] can: kvaser_usb: Use CAN_MHZ define in assignment of frequency Jimmy Assarsson
@ 2021-12-08 11:09 ` Jimmy Assarsson
  2021-12-08 11:17   ` Marc Kleine-Budde
  2 siblings, 1 reply; 6+ messages in thread
From: Jimmy Assarsson @ 2021-12-08 11:09 UTC (permalink / raw)
  To: linux-can; +Cc: Jimmy Assarsson, Jimmy Assarsson

Get the CAN clock frequency from device, since the various Kvaser Leaf
products use different CAN clocks.

Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
---
Changes in v2:
  - Rebased on [PATCH v5 0/5] fix statistics and payload issues for
    error [1] series.

[1]
https://lore.kernel.org/all/20211207121531.42941-1-mailhol.vincent@wanadoo.fr

 .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c  | 69 ++++++++++++++++---
 1 file changed, 60 insertions(+), 9 deletions(-)

diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
index 533e25cb4337..093c092226b6 100644
--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
+++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
@@ -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)
@@ -470,6 +478,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;
@@ -485,14 +514,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;
 	}
 
@@ -1220,7 +1248,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;
@@ -1344,9 +1371,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,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 3/3] can: kvaser_usb: Get CAN clock frequency from device
  2021-12-08 11:09 ` [PATCH v2 3/3] can: kvaser_usb: Get CAN clock frequency from device Jimmy Assarsson
@ 2021-12-08 11:17   ` Marc Kleine-Budde
  2021-12-08 12:02     ` Jimmy Assarsson
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2021-12-08 11:17 UTC (permalink / raw)
  To: Jimmy Assarsson; +Cc: linux-can, Jimmy Assarsson

[-- Attachment #1: Type: text/plain, Size: 1687 bytes --]

On 08.12.2021 12:09:40, Jimmy Assarsson wrote:
> Get the CAN clock frequency from device, since the various Kvaser Leaf
> products use different CAN clocks.
> 
> Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
> ---
> Changes in v2:
>   - Rebased on [PATCH v5 0/5] fix statistics and payload issues for
>     error [1] series.
> 
> [1]
> https://lore.kernel.org/all/20211207121531.42941-1-mailhol.vincent@wanadoo.fr
> 
>  .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c  | 69 ++++++++++++++++---
>  1 file changed, 60 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
> index 533e25cb4337..093c092226b6 100644
> --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
> +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
> @@ -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;

Can you re-arrange the code, so that you don't need the forward
declarations?

Marc

-- 
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 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 3/3] can: kvaser_usb: Get CAN clock frequency from device
  2021-12-08 11:17   ` Marc Kleine-Budde
@ 2021-12-08 12:02     ` Jimmy Assarsson
  0 siblings, 0 replies; 6+ messages in thread
From: Jimmy Assarsson @ 2021-12-08 12:02 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can, Jimmy Assarsson

On 2021-12-08 12:17, Marc Kleine-Budde wrote:
> On 08.12.2021 12:09:40, Jimmy Assarsson wrote:
>> Get the CAN clock frequency from device, since the various Kvaser Leaf
>> products use different CAN clocks.
>>
>> Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
>> ---
>> Changes in v2:
>>    - Rebased on [PATCH v5 0/5] fix statistics and payload issues for
>>      error [1] series.
>>
>> [1]
>> https://lore.kernel.org/all/20211207121531.42941-1-mailhol.vincent@wanadoo.fr
>>
>>   .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c  | 69 ++++++++++++++++---
>>   1 file changed, 60 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
>> index 533e25cb4337..093c092226b6 100644
>> --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
>> +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
>> @@ -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;
> 
> Can you re-arrange the code, so that you don't need the forward
> declarations?
> 
> Marc

Fixed in v3;
https://lore.kernel.org/all/20211208115607.202859-1-extja@kvaser.com

Best regards,
jimmy

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-12-08 12:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-08 11:09 [PATCH v2 0/3] kvaser_{pciefd,usb} fixes Jimmy Assarsson
2021-12-08 11:09 ` [PATCH v2 1/3] can: kvaser_pciefd: Increase correct stats->{rx,tx}_errors counter Jimmy Assarsson
2021-12-08 11:09 ` [PATCH v2 2/3] can: kvaser_usb: Use CAN_MHZ define in assignment of frequency Jimmy Assarsson
2021-12-08 11:09 ` [PATCH v2 3/3] can: kvaser_usb: Get CAN clock frequency from device Jimmy Assarsson
2021-12-08 11:17   ` Marc Kleine-Budde
2021-12-08 12:02     ` Jimmy Assarsson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.