can: flexcan: small fix and ISO CAN-FD support
Subsystems (3)
cover can: flexcan: small fix and ISO CAN-FD support
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:
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(-)
Signature · 1 line
2.20.1
PATCH 1/2 can: flexcan: use ctrlmode to enable CAN-FD
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.
--- drivers/net/can/flexcan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/can/flexcan.c +1 -1
@@ -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 ;
Signature · 1 line
2.20.1
PATCH 2/2 can: flexcan: add support for ISO CAN-FD
In reply to Michael WalleUp 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.
--- drivers/net/can/flexcan.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/net/can/flexcan.c +16 -3
@@ -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 (®s->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, ®s->mcr); + priv->write (reg_ctrl2, ®s->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;
Signature · 1 line
2.20.1
RE: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
Quoted 46 lines
-----Original Message-----
From: Michael Walle <[email protected]>
Sent: 2020年6月30日 2:18
To: [email protected]; [email protected]; [email protected]
Cc: Wolfgang Grandegger <[email protected]>; Marc Kleine-Budde <[email protected]>; David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Joakim Zhang <[email protected]>; dl-linux-imx <[email protected]>; Michael Walle <[email protected]>
Subject: [PATCH 2/2] can: flexcan: add support for ISO CAN-FDUp 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 <[email protected]>--- drivers/net/can/flexcan.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)drivers/net/can/flexcan.c index renamed from drivers/net/can/flexcan.c +0
-0
183e094f8d66..a92d3cdf4195100644drivers/net/can/flexcan.c +7
-2@@ -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 (®s->ctrl2);
drivers/net/can/flexcan.c static int flexcan_chip_start(struct net_device · line 1363
Quoted 10 lines
drivers/net/can/flexcan.c +7
-1+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
Quoted 17 lines
drivers/net/can/flexcan.c +2
-0netdev_dbg (dev,"%s: writing mcr=0x%08x" , __func__, reg_mcr); priv->write (reg_mcr, ®s->mcr); + priv->write (reg_ctrl2, ®s->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
Re: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
[+ Oliver]
Hi Joakim,
Am 2020-06-30 04:42, schrieb Joakim Zhang:
Quoted 58 lines
Quoted 56 lines
-----Original Message-----
From: Michael Walle <[email protected]>
Sent: 2020年6月30日 2:18
To: [email protected]; [email protected]; [email protected]
Cc: Wolfgang Grandegger <[email protected]>; Marc Kleine-Budde <[email protected]>; David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Joakim Zhang <[email protected]>; dl-linux-imx <[email protected]>; Michael Walle <[email protected]>
Subject: [PATCH 2/2] can: flexcan: add support for ISO CAN-FDUp 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 <[email protected]>--- drivers/net/can/flexcan.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)drivers/net/can/flexcan.c index renamed from drivers/net/can/flexcan.c +0
-0
183e094f8d66..a92d3cdf4195100644drivers/net/can/flexcan.c +1
-0@@ -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)drivers/net/can/flexcan.c +13
-3else 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 (®s->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 ;
[..]
Quoted 3 lines
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.
Quoted 1 line
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
Re: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
Quoted 79 lines · Michael Walle
[+ Oliver]
Hi Joakim,
Am 2020-06-30 04:42, schrieb Joakim Zhang:
Quoted 57 lines
Quoted 55 lines
-----Original Message-----
From: Michael Walle <[email protected]>
Sent: 2020年6月30日 2:18
To: [email protected]; [email protected]; [email protected]
Cc: Wolfgang Grandegger <[email protected]>; Marc Kleine-Budde <[email protected]>; David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Joakim Zhang <[email protected]>; dl-linux-imx <[email protected]>; Michael Walle <[email protected]>
Subject: [PATCH 2/2] can: flexcan: add support for ISO CAN-FDUp 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 <[email protected]>---
drivers/net/can/flexcan.c | 19 ++++++++++++++++---1 file changed, 16 insertions(+), 3 deletions(-)drivers/net/can/flexcan.c index renamed from drivers/net/can/flexcan.c +0
-0
183e094f8d66..a92d3cdf4195100644drivers/net/can/flexcan.c +1
-0@@ -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(®s->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;[..]
Quoted 3 lines
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 onvs.
Quoted 1 line
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_ISOdepends onCAN_CTRLMODE_FD. I.e. wetherCAN_CTRLMODE_FD_NON_ISOcan only be set ifCAN_CTRLMODE_FDis also set.Only the following piece of code, which might be a hint that you have to set
CAN_CTRLMODE_FDif you wan't to useCAN_CTRLMODE_FD_NON_ISO:
Quoted 7 lines
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_ISOcan be set withoutCAN_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
Re: [PATCH 2/2] can: flexcan: add support for ISO CAN-FD
Am 2020-06-30 18:15, schrieb Oliver Hartkopp:
Quoted 54 lines · Michael Walle
Quoted 53 lines
[+ Oliver]
Hi Joakim,
Am 2020-06-30 04:42, schrieb Joakim Zhang:
Quoted 48 lines
Quoted 48 lines
-----Original Message-----
From: Michael Walle <[email protected]>
Sent: 2020年6月30日 2:18
To: [email protected]; [email protected]; [email protected]
Cc: Wolfgang Grandegger <[email protected]>; Marc Kleine-Budde <[email protected]>; David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Joakim Zhang <[email protected]>; dl-linux-imx <[email protected]>; Michael Walle <[email protected]>
Subject: [PATCH 2/2] can: flexcan: add support for ISO CAN-FDUp 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 <[email protected]>---
drivers/net/can/flexcan.c | 19 ++++++++++++++++---1 file changed, 16 insertions(+), 3 deletions(-)drivers/net/can/flexcan.c index renamed from drivers/net/can/flexcan.c +0
-0
183e094f8d66..a92d3cdf4195100644drivers/net/can/flexcan.c +1
-0@@ -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(®s->ctrl2);
+ if (priv->can.ctrlmode&CAN_CTRLMODE_FD) {
reg_mcr|=FLEXCAN_MCR_FDEN;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
- 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]
Quoted 30 lines
Quoted 16 lines
[..]
Quoted 3 lines
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 onvs.
Quoted 1 line
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_ISOdepends onCAN_CTRLMODE_FD. I.e. wetherCAN_CTRLMODE_FD_NON_ISOcan only be set ifCAN_CTRLMODE_FDis also set.Only the following piece of code, which might be a hint that you have to set
CAN_CTRLMODE_FDif you wan't to useCAN_CTRLMODE_FD_NON_ISO:Quoted 7 lines
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_ISOcan be set withoutCAN_CTRLMODE_FD, what should be the mode if both are set at the same time?
CAN_CTRLMODE_FD_NON_ISOis only relevant whenCAN_CTRLMODE_FDis set.So in the example from above
ip link set can0 up type can bitrate 1000000 dbitrate 5000000 fd-non-iso on
Quoted 8 lines
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