netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] can: flexcan: small fix and ISO CAN-FD support
@ 2020-06-29 18:18 Michael Walle
  2020-06-29 18:18 ` [PATCH 1/2] can: flexcan: use ctrlmode to enable CAN-FD Michael Walle
  2020-06-29 18:18 ` [PATCH 2/2] can: flexcan: add support for ISO CAN-FD Michael Walle
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Walle @ 2020-06-29 18:18 UTC (permalink / raw)
  To: linux-can, netdev, linux-kernel
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David S . Miller,
	Jakub Kicinski, Joakim Zhang, dl-linux-imx, Michael Walle

Hi,

this patch series is based on:
https://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git/log/?h=flexcan

I took the liberty and ported and made some style changes to the ISO CAN-FD
patch from Joakim.

With these two patches applied for the branch above:
Tested-by: Michael Walle <michael@walle.cc>

Michael Walle (2):
  can: flexcan: use ctrlmode to enable CAN-FD
  can: flexcan: add support for ISO CAN-FD

 drivers/net/can/flexcan.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

-- 
2.20.1


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

* [PATCH 1/2] can: flexcan: use ctrlmode to enable CAN-FD
  2020-06-29 18:18 [PATCH 0/2] can: flexcan: small fix and ISO CAN-FD support Michael Walle
@ 2020-06-29 18:18 ` Michael Walle
  2020-06-29 18:18 ` [PATCH 2/2] can: flexcan: add support for ISO CAN-FD Michael Walle
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Walle @ 2020-06-29 18:18 UTC (permalink / raw)
  To: linux-can, netdev, linux-kernel
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David S . Miller,
	Jakub Kicinski, Joakim Zhang, dl-linux-imx, Michael Walle

The driver will enable CAN-FD mode according to the ctrlmode_supported,
which will always be true, if the controller supports it. This is wrong.
Use the correct ctrlmode instead.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/net/can/flexcan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 12043250e398..183e094f8d66 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -1345,7 +1345,7 @@ static int flexcan_chip_start(struct net_device *dev)
 		reg_mcr |= FLEXCAN_MCR_SRX_DIS;
 
 	/* MCR - CAN-FD */
-	if (priv->can.ctrlmode_supported & CAN_CTRLMODE_FD)
+	if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
 		reg_mcr |= FLEXCAN_MCR_FDEN;
 	else
 		reg_mcr &= ~FLEXCAN_MCR_FDEN;
-- 
2.20.1


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

* [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
  2020-06-29 18:18 [PATCH 0/2] can: flexcan: small fix and ISO CAN-FD support Michael Walle
  2020-06-29 18:18 ` [PATCH 1/2] can: flexcan: use ctrlmode to enable CAN-FD Michael Walle
@ 2020-06-29 18:18 ` Michael Walle
  2020-06-30  2:42   ` Joakim Zhang
  1 sibling, 1 reply; 7+ messages in thread
From: Michael Walle @ 2020-06-29 18:18 UTC (permalink / raw)
  To: linux-can, netdev, linux-kernel
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David S . Miller,
	Jakub Kicinski, Joakim Zhang, dl-linux-imx, Michael Walle

Up until now, the controller used non-ISO CAN-FD mode, although it
supports it. Add support for ISO mode, too. By default the hardware
is in non-ISO mode and an enable bit has to be explicitly set.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/net/can/flexcan.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 183e094f8d66..a92d3cdf4195 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -94,6 +94,7 @@
 #define FLEXCAN_CTRL2_MRP		BIT(18)
 #define FLEXCAN_CTRL2_RRS		BIT(17)
 #define FLEXCAN_CTRL2_EACEN		BIT(16)
+#define FLEXCAN_CTRL2_ISOCANFDEN	BIT(12)
 
 /* FLEXCAN memory error control register (MECR) bits */
 #define FLEXCAN_MECR_ECRWRDIS		BIT(31)
@@ -1344,14 +1345,25 @@ static int flexcan_chip_start(struct net_device *dev)
 	else
 		reg_mcr |= FLEXCAN_MCR_SRX_DIS;
 
-	/* MCR - CAN-FD */
-	if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
+	/* MCR, CTRL2
+	 *
+	 * CAN-FD mode
+	 * ISO CAN-FD mode
+	 */
+	reg_ctrl2 = priv->read(&regs->ctrl2);
+	if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
 		reg_mcr |= FLEXCAN_MCR_FDEN;
-	else
+		reg_ctrl2 |= FLEXCAN_CTRL2_ISOCANFDEN;
+	} else {
 		reg_mcr &= ~FLEXCAN_MCR_FDEN;
+	}
+
+	if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
+		reg_ctrl2 &= ~FLEXCAN_CTRL2_ISOCANFDEN;
 
 	netdev_dbg(dev, "%s: writing mcr=0x%08x", __func__, reg_mcr);
 	priv->write(reg_mcr, &regs->mcr);
+	priv->write(reg_ctrl2, &regs->ctrl2);
 
 	/* CTRL
 	 *
@@ -1952,6 +1964,7 @@ static int flexcan_probe(struct platform_device *pdev)
 
 	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SUPPORT_FD) {
 		priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD;
+		priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD_NON_ISO;
 		priv->can.bittiming_const = &flexcan_fd_bittiming_const;
 		priv->can.data_bittiming_const =
 			&flexcan_fd_data_bittiming_const;
-- 
2.20.1


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

* RE: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
  2020-06-29 18:18 ` [PATCH 2/2] can: flexcan: add support for ISO CAN-FD Michael Walle
@ 2020-06-30  2:42   ` Joakim Zhang
  2020-06-30  5:53     ` Michael Walle
  0 siblings, 1 reply; 7+ messages in thread
From: Joakim Zhang @ 2020-06-30  2:42 UTC (permalink / raw)
  To: Michael Walle, linux-can, netdev, linux-kernel
  Cc: Wolfgang Grandegger, Marc Kleine-Budde, David S . Miller,
	Jakub Kicinski, dl-linux-imx


> -----Original Message-----
> From: Michael Walle <michael@walle.cc>
> Sent: 2020年6月30日 2:18
> To: linux-can@vger.kernel.org; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Cc: Wolfgang Grandegger <wg@grandegger.com>; Marc Kleine-Budde
> <mkl@pengutronix.de>; David S . Miller <davem@davemloft.net>; Jakub
> Kicinski <kuba@kernel.org>; Joakim Zhang <qiangqing.zhang@nxp.com>;
> dl-linux-imx <linux-imx@nxp.com>; Michael Walle <michael@walle.cc>
> Subject: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
> 
> Up until now, the controller used non-ISO CAN-FD mode, although it supports it.
> Add support for ISO mode, too. By default the hardware is in non-ISO mode and
> an enable bit has to be explicitly set.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  drivers/net/can/flexcan.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index
> 183e094f8d66..a92d3cdf4195 100644
> --- a/drivers/net/can/flexcan.c
> +++ b/drivers/net/can/flexcan.c
> @@ -94,6 +94,7 @@
>  #define FLEXCAN_CTRL2_MRP		BIT(18)
>  #define FLEXCAN_CTRL2_RRS		BIT(17)
>  #define FLEXCAN_CTRL2_EACEN		BIT(16)
> +#define FLEXCAN_CTRL2_ISOCANFDEN	BIT(12)
> 
>  /* FLEXCAN memory error control register (MECR) bits */
>  #define FLEXCAN_MECR_ECRWRDIS		BIT(31)
> @@ -1344,14 +1345,25 @@ static int flexcan_chip_start(struct net_device
> *dev)
>  	else
>  		reg_mcr |= FLEXCAN_MCR_SRX_DIS;
> 
> -	/* MCR - CAN-FD */
> -	if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
> +	/* MCR, CTRL2
> +	 *
> +	 * CAN-FD mode
> +	 * ISO CAN-FD mode
> +	 */
> +	reg_ctrl2 = priv->read(&regs->ctrl2);
> +	if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
>  		reg_mcr |= FLEXCAN_MCR_FDEN;
> -	else
> +		reg_ctrl2 |= FLEXCAN_CTRL2_ISOCANFDEN;
> +	} else {
>  		reg_mcr &= ~FLEXCAN_MCR_FDEN;
> +	}
> +
> +	if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
> +		reg_ctrl2 &= ~FLEXCAN_CTRL2_ISOCANFDEN;


Hi Michael,

ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on
Above cmd can configure ISO CAN-FD.

However, if users want to configure NON-ISO CAN-FD, should use below cmd, what I did before.
ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on fd-non-iso on

Marc may not satisfy with it, to be honest, this looks not good, had better configure like below to enable NON-ISO CAN-FD.
ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd-non-iso on

I haven't got any good ideas yet.

Best Regards,
Joakim Zhang
>  	netdev_dbg(dev, "%s: writing mcr=0x%08x", __func__, reg_mcr);
>  	priv->write(reg_mcr, &regs->mcr);
> +	priv->write(reg_ctrl2, &regs->ctrl2);
> 
>  	/* CTRL
>  	 *
> @@ -1952,6 +1964,7 @@ static int flexcan_probe(struct platform_device
> *pdev)
> 
>  	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SUPPORT_FD) {
>  		priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD;
> +		priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD_NON_ISO;
>  		priv->can.bittiming_const = &flexcan_fd_bittiming_const;
>  		priv->can.data_bittiming_const =
>  			&flexcan_fd_data_bittiming_const;
> --
> 2.20.1


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

* Re: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
  2020-06-30  2:42   ` Joakim Zhang
@ 2020-06-30  5:53     ` Michael Walle
  2020-06-30 16:15       ` Oliver Hartkopp
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Walle @ 2020-06-30  5:53 UTC (permalink / raw)
  To: Joakim Zhang
  Cc: linux-can, netdev, linux-kernel, Wolfgang Grandegger,
	Marc Kleine-Budde, David S . Miller, Jakub Kicinski,
	dl-linux-imx, Oliver Hartkopp

[+ Oliver]

Hi Joakim,

Am 2020-06-30 04:42, schrieb Joakim Zhang:
>> -----Original Message-----
>> From: Michael Walle <michael@walle.cc>
>> Sent: 2020年6月30日 2:18
>> To: linux-can@vger.kernel.org; netdev@vger.kernel.org;
>> linux-kernel@vger.kernel.org
>> Cc: Wolfgang Grandegger <wg@grandegger.com>; Marc Kleine-Budde
>> <mkl@pengutronix.de>; David S . Miller <davem@davemloft.net>; Jakub
>> Kicinski <kuba@kernel.org>; Joakim Zhang <qiangqing.zhang@nxp.com>;
>> dl-linux-imx <linux-imx@nxp.com>; Michael Walle <michael@walle.cc>
>> Subject: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
>> 
>> Up until now, the controller used non-ISO CAN-FD mode, although it 
>> supports it.
>> Add support for ISO mode, too. By default the hardware is in non-ISO 
>> mode and
>> an enable bit has to be explicitly set.
>> 
>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>>  drivers/net/can/flexcan.c | 19 ++++++++++++++++---
>>  1 file changed, 16 insertions(+), 3 deletions(-)
>> 
>> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c 
>> index
>> 183e094f8d66..a92d3cdf4195 100644
>> --- a/drivers/net/can/flexcan.c
>> +++ b/drivers/net/can/flexcan.c
>> @@ -94,6 +94,7 @@
>>  #define FLEXCAN_CTRL2_MRP		BIT(18)
>>  #define FLEXCAN_CTRL2_RRS		BIT(17)
>>  #define FLEXCAN_CTRL2_EACEN		BIT(16)
>> +#define FLEXCAN_CTRL2_ISOCANFDEN	BIT(12)
>> 
>>  /* FLEXCAN memory error control register (MECR) bits */
>>  #define FLEXCAN_MECR_ECRWRDIS		BIT(31)
>> @@ -1344,14 +1345,25 @@ static int flexcan_chip_start(struct 
>> net_device
>> *dev)
>>  	else
>>  		reg_mcr |= FLEXCAN_MCR_SRX_DIS;
>> 
>> -	/* MCR - CAN-FD */
>> -	if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
>> +	/* MCR, CTRL2
>> +	 *
>> +	 * CAN-FD mode
>> +	 * ISO CAN-FD mode
>> +	 */
>> +	reg_ctrl2 = priv->read(&regs->ctrl2);
>> +	if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
>>  		reg_mcr |= FLEXCAN_MCR_FDEN;
>> -	else
>> +		reg_ctrl2 |= FLEXCAN_CTRL2_ISOCANFDEN;
>> +	} else {
>>  		reg_mcr &= ~FLEXCAN_MCR_FDEN;
>> +	}
>> +
>> +	if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
>> +		reg_ctrl2 &= ~FLEXCAN_CTRL2_ISOCANFDEN;
> 
> 

[..]
> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on
> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on \
>    fd-non-iso on

vs.

> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 
> fd-non-iso on

I haven't found anything if CAN_CTRLMODE_FD_NON_ISO depends on
CAN_CTRLMODE_FD. I.e. wether CAN_CTRLMODE_FD_NON_ISO can only be set if
CAN_CTRLMODE_FD is also set.

Only the following piece of code, which might be a hint that you
have to set CAN_CTRLMODE_FD if you wan't to use CAN_CTRLMODE_FD_NON_ISO:

drivers/net/can/dev.c:
   /* do not check for static fd-non-iso if 'fd' is disabled */
   if (!(maskedflags & CAN_CTRLMODE_FD))
           ctrlstatic &= ~CAN_CTRLMODE_FD_NON_ISO;

If CAN_CTRLMODE_FD_NON_ISO can be set without CAN_CTRLMODE_FD, what
should be the mode if both are set at the same time?

Marc? Oliver?

-michael

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

* Re: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
  2020-06-30  5:53     ` Michael Walle
@ 2020-06-30 16:15       ` Oliver Hartkopp
  2020-06-30 17:00         ` Michael Walle
  0 siblings, 1 reply; 7+ messages in thread
From: Oliver Hartkopp @ 2020-06-30 16:15 UTC (permalink / raw)
  To: Michael Walle, Joakim Zhang
  Cc: linux-can, netdev, linux-kernel, Wolfgang Grandegger,
	Marc Kleine-Budde, David S . Miller, Jakub Kicinski,
	dl-linux-imx



On 30.06.20 07:53, Michael Walle wrote:
> [+ Oliver]
> 
> Hi Joakim,
> 
> Am 2020-06-30 04:42, schrieb Joakim Zhang:
>>> -----Original Message-----
>>> From: Michael Walle <michael@walle.cc>
>>> Sent: 2020年6月30日 2:18
>>> To: linux-can@vger.kernel.org; netdev@vger.kernel.org;
>>> linux-kernel@vger.kernel.org
>>> Cc: Wolfgang Grandegger <wg@grandegger.com>; Marc Kleine-Budde
>>> <mkl@pengutronix.de>; David S . Miller <davem@davemloft.net>; Jakub
>>> Kicinski <kuba@kernel.org>; Joakim Zhang <qiangqing.zhang@nxp.com>;
>>> dl-linux-imx <linux-imx@nxp.com>; Michael Walle <michael@walle.cc>
>>> Subject: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
>>>
>>> Up until now, the controller used non-ISO CAN-FD mode, although it 
>>> supports it.
>>> Add support for ISO mode, too. By default the hardware is in non-ISO 
>>> mode and
>>> an enable bit has to be explicitly set.
>>>
>>> Signed-off-by: Michael Walle <michael@walle.cc>
>>> ---
>>>  drivers/net/can/flexcan.c | 19 ++++++++++++++++---
>>>  1 file changed, 16 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c index
>>> 183e094f8d66..a92d3cdf4195 100644
>>> --- a/drivers/net/can/flexcan.c
>>> +++ b/drivers/net/can/flexcan.c
>>> @@ -94,6 +94,7 @@
>>>  #define FLEXCAN_CTRL2_MRP        BIT(18)
>>>  #define FLEXCAN_CTRL2_RRS        BIT(17)
>>>  #define FLEXCAN_CTRL2_EACEN        BIT(16)
>>> +#define FLEXCAN_CTRL2_ISOCANFDEN    BIT(12)
>>>
>>>  /* FLEXCAN memory error control register (MECR) bits */
>>>  #define FLEXCAN_MECR_ECRWRDIS        BIT(31)
>>> @@ -1344,14 +1345,25 @@ static int flexcan_chip_start(struct net_device
>>> *dev)
>>>      else
>>>          reg_mcr |= FLEXCAN_MCR_SRX_DIS;
>>>
>>> -    /* MCR - CAN-FD */
>>> -    if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
>>> +    /* MCR, CTRL2
>>> +     *
>>> +     * CAN-FD mode
>>> +     * ISO CAN-FD mode
>>> +     */
>>> +    reg_ctrl2 = priv->read(&regs->ctrl2);
>>> +    if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
>>>          reg_mcr |= FLEXCAN_MCR_FDEN;
>>> -    else
>>> +        reg_ctrl2 |= FLEXCAN_CTRL2_ISOCANFDEN;
>>> +    } else {
>>>          reg_mcr &= ~FLEXCAN_MCR_FDEN;
>>> +    }
>>> +
>>> +    if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
>>> +        reg_ctrl2 &= ~FLEXCAN_CTRL2_ISOCANFDEN;
>>
>>
> 
> [..]
>> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on
>> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on \
>>    fd-non-iso on
> 
> vs.
> 
>> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 
>> fd-non-iso on
> 
> I haven't found anything if CAN_CTRLMODE_FD_NON_ISO depends on
> CAN_CTRLMODE_FD. I.e. wether CAN_CTRLMODE_FD_NON_ISO can only be set if
> CAN_CTRLMODE_FD is also set.
> 
> Only the following piece of code, which might be a hint that you
> have to set CAN_CTRLMODE_FD if you wan't to use CAN_CTRLMODE_FD_NON_ISO:
> 
> drivers/net/can/dev.c:
>    /* do not check for static fd-non-iso if 'fd' is disabled */
>    if (!(maskedflags & CAN_CTRLMODE_FD))
>            ctrlstatic &= ~CAN_CTRLMODE_FD_NON_ISO;
> 
> If CAN_CTRLMODE_FD_NON_ISO can be set without CAN_CTRLMODE_FD, what
> should be the mode if both are set at the same time?

CAN_CTRLMODE_FD_NON_ISO is only relevant when CAN_CTRLMODE_FD is set.

So in the example from above

ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd-non-iso on

either the setting of 'dbitrate 5000000' and 'fd-non-iso on' is pointless.

When switching to FD-mode with 'fd on' the FD relevant settings need to 
be applied.

FD ISO is the default.

Did this help or did I get anything wrong?

Best,
Oliver

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

* Re: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
  2020-06-30 16:15       ` Oliver Hartkopp
@ 2020-06-30 17:00         ` Michael Walle
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Walle @ 2020-06-30 17:00 UTC (permalink / raw)
  To: Oliver Hartkopp
  Cc: Joakim Zhang, linux-can, netdev, linux-kernel,
	Wolfgang Grandegger, Marc Kleine-Budde, David S . Miller,
	Jakub Kicinski, dl-linux-imx

Am 2020-06-30 18:15, schrieb Oliver Hartkopp:
> On 30.06.20 07:53, Michael Walle wrote:
>> [+ Oliver]
>> 
>> Hi Joakim,
>> 
>> Am 2020-06-30 04:42, schrieb Joakim Zhang:
>>>> -----Original Message-----
>>>> From: Michael Walle <michael@walle.cc>
>>>> Sent: 2020年6月30日 2:18
>>>> To: linux-can@vger.kernel.org; netdev@vger.kernel.org;
>>>> linux-kernel@vger.kernel.org
>>>> Cc: Wolfgang Grandegger <wg@grandegger.com>; Marc Kleine-Budde
>>>> <mkl@pengutronix.de>; David S . Miller <davem@davemloft.net>; Jakub
>>>> Kicinski <kuba@kernel.org>; Joakim Zhang <qiangqing.zhang@nxp.com>;
>>>> dl-linux-imx <linux-imx@nxp.com>; Michael Walle <michael@walle.cc>
>>>> Subject: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
>>>> 
>>>> Up until now, the controller used non-ISO CAN-FD mode, although it 
>>>> supports it.
>>>> Add support for ISO mode, too. By default the hardware is in non-ISO 
>>>> mode and
>>>> an enable bit has to be explicitly set.
>>>> 
>>>> Signed-off-by: Michael Walle <michael@walle.cc>
>>>> ---
>>>>  drivers/net/can/flexcan.c | 19 ++++++++++++++++---
>>>>  1 file changed, 16 insertions(+), 3 deletions(-)
>>>> 
>>>> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c 
>>>> index
>>>> 183e094f8d66..a92d3cdf4195 100644
>>>> --- a/drivers/net/can/flexcan.c
>>>> +++ b/drivers/net/can/flexcan.c
>>>> @@ -94,6 +94,7 @@
>>>>  #define FLEXCAN_CTRL2_MRP        BIT(18)
>>>>  #define FLEXCAN_CTRL2_RRS        BIT(17)
>>>>  #define FLEXCAN_CTRL2_EACEN        BIT(16)
>>>> +#define FLEXCAN_CTRL2_ISOCANFDEN    BIT(12)
>>>> 
>>>>  /* FLEXCAN memory error control register (MECR) bits */
>>>>  #define FLEXCAN_MECR_ECRWRDIS        BIT(31)
>>>> @@ -1344,14 +1345,25 @@ static int flexcan_chip_start(struct 
>>>> net_device
>>>> *dev)
>>>>      else
>>>>          reg_mcr |= FLEXCAN_MCR_SRX_DIS;
>>>> 
>>>> -    /* MCR - CAN-FD */
>>>> -    if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
>>>> +    /* MCR, CTRL2
>>>> +     *
>>>> +     * CAN-FD mode
>>>> +     * ISO CAN-FD mode
>>>> +     */
>>>> +    reg_ctrl2 = priv->read(&regs->ctrl2);
>>>> +    if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
>>>>          reg_mcr |= FLEXCAN_MCR_FDEN;
>>>> -    else
>>>> +        reg_ctrl2 |= FLEXCAN_CTRL2_ISOCANFDEN;
>>>> +    } else {
>>>>          reg_mcr &= ~FLEXCAN_MCR_FDEN;
>>>> +    }
>>>> +
>>>> +    if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
>>>> +        reg_ctrl2 &= ~FLEXCAN_CTRL2_ISOCANFDEN;

[1]

>> [..]
>>> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on
>>> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd on \
>>>    fd-non-iso on
>> 
>> vs.
>> 
>>> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 
>>> fd-non-iso on
>> 
>> I haven't found anything if CAN_CTRLMODE_FD_NON_ISO depends on
>> CAN_CTRLMODE_FD. I.e. wether CAN_CTRLMODE_FD_NON_ISO can only be set 
>> if
>> CAN_CTRLMODE_FD is also set.
>> 
>> Only the following piece of code, which might be a hint that you
>> have to set CAN_CTRLMODE_FD if you wan't to use 
>> CAN_CTRLMODE_FD_NON_ISO:
>> 
>> drivers/net/can/dev.c:
>>    /* do not check for static fd-non-iso if 'fd' is disabled */
>>    if (!(maskedflags & CAN_CTRLMODE_FD))
>>            ctrlstatic &= ~CAN_CTRLMODE_FD_NON_ISO;
>> 
>> If CAN_CTRLMODE_FD_NON_ISO can be set without CAN_CTRLMODE_FD, what
>> should be the mode if both are set at the same time?
> 
> CAN_CTRLMODE_FD_NON_ISO is only relevant when CAN_CTRLMODE_FD is set.
> 
> So in the example from above
> 
> ip link set can0 up type can bitrate 1000000 dbitrate 5000000 
> fd-non-iso on
> 
> either the setting of 'dbitrate 5000000' and 'fd-non-iso on' is 
> pointless.
> 
> When switching to FD-mode with 'fd on' the FD relevant settings need
> to be applied.
> 
> FD ISO is the default.
> 
> Did this help or did I get anything wrong?

Thanks for the explanation. Yes this helped a great deal and this
patch should be correct; it sets ISO mode if CAN_CTRLMODE_FD is set
and masks it again if CAN_CTRLMODE_FD_NON_ISO is set. See [1].

-michael

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

end of thread, other threads:[~2020-06-30 17:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 18:18 [PATCH 0/2] can: flexcan: small fix and ISO CAN-FD support Michael Walle
2020-06-29 18:18 ` [PATCH 1/2] can: flexcan: use ctrlmode to enable CAN-FD Michael Walle
2020-06-29 18:18 ` [PATCH 2/2] can: flexcan: add support for ISO CAN-FD Michael Walle
2020-06-30  2:42   ` Joakim Zhang
2020-06-30  5:53     ` Michael Walle
2020-06-30 16:15       ` Oliver Hartkopp
2020-06-30 17:00         ` Michael Walle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).