patch set for flexcan
Subsystems (3)
v4 cover patch set for flexcan
Add Flexcan ECC support.
Joakim Zhang (3):
can: flexcan: initialize all flexcan memory for ECC function
can: flexcan: add flexcan driver for i.MX8MP
can: flexcan: disable runtime PM if register flexcandev failed
drivers/net/can/flexcan.c | 62 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH v4 1/3 can: flexcan: initialize all flexcan memory for ECC function
One issue was reported at a baremetal environment, which is used for FPGA verification. "The first transfer will fail for extended ID format(for both 2.0B and FD format), following frames can be transmitted and received successfully for extended format, and standard format don't have this issue. This issue occurred randomly with high possiblity, when it occurs, the transmitter will detect a BIT1 error, the receiver a CRC error. According to the spec, a non-correctable error may cause this transfer failure."
With FLEXCAN_QUIRK_DISABLE_MECR quirk, it supports correctable errors, disable non-correctable errors interrupt and freeze mode. Platform has ECC hardware support, but select this quirk, this issue may not come to light. Initialize all FlexCAN memory before accessing them, at least it can avoid non-correctable errors detected due to memory uninitialized. The internal region can't be initialized when the hardware doesn't support ECC.
According to IMX8MPRM, Rev.C, 04/2020. There is a NOTE at the section 11.8.3.13 Detection and correction of memory errors:
"All FlexCAN memory must be initialized before starting its operation in order to have the parity bits in memory properly updated. CTRL2[WRMFRZ] grants write access to all memory positions that require initialization, ranging from 0x080 to 0xADF and from 0xF28 to 0xFFF when the CAN FD feature is enabled. The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to be initialized as well. MCR[RFEN] must not be set during memory initialization."
Memory range from 0x080 to 0xADF, there are reserved memory (unimplemented by hardware, e.g. only configure 64 MBs), these memory can be initialized or not. In this patch, initialize all flexcan memory which includes reserved memory.
In this patch, create FLEXCAN_QUIRK_SUPPORT_ECC for platforms which has ECC feature. If you have a ECC platform in your hand, please select this qurik to initialize all flexcan memory firstly, then you can select FLEXCAN_QUIRK_DISABLE_MECR to only enable correctable errors.
---
ChangeLogs:V1->V2:
* update commit messages, add a datasheet reference.
* initialize block memory instead of trivial memory.
* inilialize reserved memory.V2->V3:
* add FLEXCAN_QUIRK_SUPPORT_ECC quirk.
* remove init_ram struct.V3->V4:
* move register definition into flexcan_reg.
--- drivers/net/can/flexcan.c | 51 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-)
drivers/net/can/flexcan.c +49 -2
@@ -239,6 +239,8 @@#define FLEXCAN_QUIRK_SETUP_STOP_MODE BIT(8)/* Support CAN-FD mode */ #define FLEXCAN_QUIRK_SUPPORT_FD BIT(9) +/* support memory detection and correction */ +#define FLEXCAN_QUIRK_SUPPORT_ECC BIT(10)/* Structure of the message buffer */ struct flexcan_mb {
@@ -292,7 +294,16 @@ struct flexcan_regs {u32 rximr[64 ];/* 0x880 - Not affected by Soft Reset */ u32 _reserved5[24 ];/* 0x980 */ u32 gfwr_mx6;/* 0x9e0 - MX6 */ -u32 _reserved6[63 ];/* 0x9e4 */ +u32 _reserved6[39 ];/* 0x9e4 */ +u32 _rxfir[6 ];/* 0xa80 */ +u32 _reserved8[2 ];/* 0xa98 */ +u32 _rxmgmask;/* 0xaa0 */ +u32 _rxfgmask;/* 0xaa4 */ +u32 _rx14mask;/* 0xaa8 */ +u32 _rx15mask;/* 0xaac */ +u32 tx_smb[4 ];/* 0xab0 */ +u32 rx_smb0[4 ];/* 0xac0 */ +u32 rx_smb1[4 ];/* 0xad0 */ u32 mecr;/* 0xae0 */ u32 erriar;/* 0xae4 */ u32 erridpr;/* 0xae8 */
@@ -305,9 +316,13 @@ struct flexcan_regs {u32 fdctrl;/* 0xc00 - Not affected by Soft Reset */ u32 fdcbt;/* 0xc04 - Not affected by Soft Reset */ u32 fdcrc;/* 0xc08 */ +u32 _reserved9[199 ];/* 0xc0c */ +u32 tx_smb_fd[18 ];/* 0xf28 */ +u32 rx_smb0_fd[18 ];/* 0xf70 */ +u32 rx_smb1_fd[18 ];/* 0xfb8 */ }; -static_assert (sizeof (struct flexcan_regs ) ==0x4 +0xc08 ); +static_assert (sizeof (struct flexcan_regs ) ==0x4 *18 +0xfb8 );struct flexcan_devtype_data {u32 quirks;/* quirks needed for different IP cores */
@@ -1292,6 +1307,35 @@ static void flexcan_set_bittiming(struct net_device *dev)return flexcan_set_bittiming_ctrl (dev); } +static void flexcan_init_ram (struct net_device *dev) +{ +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->regs; +u32 reg_ctrl2; + +/* 11.8.3.13 Detection and correction of memory errors: +* CTRL2[WRMFRZ] grants write access to all memory positions that +* require initialization, ranging from 0x080 to 0xADF and +* from 0xF28 to 0xFFF when the CAN FD feature is enabled. +* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to +* be initialized as well. MCR[RFEN] must not be set during memory +* initialization. +*/ + reg_ctrl2 = priv->read (®s->ctrl2); + reg_ctrl2 |=FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); + +memset_io (®s->mb[0 ][0 ],0 , + (u8 *)®s->rx_smb1[3 ] - ®s->mb[0 ][0 ] +0x4 ); + +if (priv->can.ctrlmode &CAN_CTRLMODE_FD ) +memset_io (®s->tx_smb_fd[0 ],0 , + (u8 *)®s->rx_smb1_fd[17 ] - (u8 *)®s->tx_smb_fd[0 ] +0x4 ); + + reg_ctrl2 &= ~FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); +} +/* flexcan_chip_start * * this functions is entered with clocks enabled
@@ -1316,6 +1360,9 @@ static int flexcan_chip_start(struct net_device *dev)if (err) goto out_chip_disable; +if (priv->devtype_data->quirks &FLEXCAN_QUIRK_SUPPORT_ECC ) +flexcan_init_ram (dev); +flexcan_set_bittiming (dev);/* MCR
Signature · 1 line
2.17.1
Marc Kleine-Budde
maintainerRe: [PATCH V4 1/3] can: flexcan: initialize all flexcan memory for ECC function
Quoted 111 lines · Joakim Zhang
One issue was reported at a baremetal environment, which is used for FPGA verification. "The first transfer will fail for extended ID format(for both 2.0B and FD format), following frames can be transmitted and received successfully for extended format, and standard format don't have this issue. This issue occurred randomly with high possiblity, when it occurs, the transmitter will detect a BIT1 error, the receiver a CRC error. According to the spec, a non-correctable error may cause this transfer failure."
With
FLEXCAN_QUIRK_DISABLE_MECRquirk, it supports correctable errors, disable non-correctable errors interrupt and freeze mode. Platform has ECC hardware support, but select this quirk, this issue may not come to light. Initialize all FlexCAN memory before accessing them, at least it can avoid non-correctable errors detected due to memory uninitialized. The internal region can't be initialized when the hardware doesn't support ECC.According to IMX8MPRM, Rev.C, 04/2020. There is a NOTE at the section 11.8.3.13 Detection and correction of memory errors:
"All FlexCAN memory must be initialized before starting its operation in order to have the parity bits in memory properly updated. CTRL2[WRMFRZ] grants write access to all memory positions that require initialization, ranging from0x080to0xADFand from0xF28to0xFFFwhen the CAN FD feature is enabled. The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to be initialized as well. MCR[RFEN] must not be set during memory initialization."Memory range from
0x080to0xADF, there are reserved memory (unimplemented by hardware, e.g. only configure 64 MBs), these memory can be initialized or not. In this patch, initialize all flexcan memory which includes reserved memory.In this patch, create
FLEXCAN_QUIRK_SUPPORT_ECCfor platforms which has ECC feature. If you have a ECC platform in your hand, please select this qurik to initialize all flexcan memory firstly, then you can selectFLEXCAN_QUIRK_DISABLE_MECRto only enable correctable errors.Signed-off-by Joakim Zhang <[email protected]>---
ChangeLogs:V1->V2:
* update commit messages, add a datasheet reference.
* initialize block memory instead of trivial memory.
* inilialize reserved memory.V2->V3:
* addFLEXCAN_QUIRK_SUPPORT_ECCquirk.
* removeinit_ramstruct.V3->V4:
* move register definition intoflexcan_reg.--- drivers/net/can/flexcan.c | 51 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-)drivers/net/can/flexcan.c +27
-2@@ -239,6 +239,8 @@#define FLEXCAN_QUIRK_SETUP_STOP_MODE BIT(8)/* Support CAN-FD mode */ #define FLEXCAN_QUIRK_SUPPORT_FD BIT(9) +/* support memory detection and correction */ +#define FLEXCAN_QUIRK_SUPPORT_ECC BIT(10)/* Structure of the message buffer */ struct flexcan_mb {@@ -292,7 +294,16 @@ struct flexcan_regs {u32 rximr[64 ];/* 0x880 - Not affected by Soft Reset */ u32 _reserved5[24 ];/* 0x980 */ u32 gfwr_mx6;/* 0x9e0 - MX6 */ -u32 _reserved6[63 ];/* 0x9e4 */ +u32 _reserved6[39 ];/* 0x9e4 */ +u32 _rxfir[6 ];/* 0xa80 */ +u32 _reserved8[2 ];/* 0xa98 */ +u32 _rxmgmask;/* 0xaa0 */ +u32 _rxfgmask;/* 0xaa4 */ +u32 _rx14mask;/* 0xaa8 */ +u32 _rx15mask;/* 0xaac */ +u32 tx_smb[4 ];/* 0xab0 */ +u32 rx_smb0[4 ];/* 0xac0 */ +u32 rx_smb1[4 ];/* 0xad0 */ u32 mecr;/* 0xae0 */ u32 erriar;/* 0xae4 */ u32 erridpr;/* 0xae8 */ @@ -305,9 +316,13 @@ struct flexcan_regs {u32 fdctrl;/* 0xc00 - Not affected by Soft Reset */ u32 fdcbt;/* 0xc04 - Not affected by Soft Reset */ u32 fdcrc;/* 0xc08 */ +u32 _reserved9[199 ];/* 0xc0c */ +u32 tx_smb_fd[18 ];/* 0xf28 */ +u32 rx_smb0_fd[18 ];/* 0xf70 */ +u32 rx_smb1_fd[18 ];/* 0xfb8 */ }; -static_assert (sizeof (struct flexcan_regs ) ==0x4 +0xc08 ); +static_assert (sizeof (struct flexcan_regs ) ==0x4 *18 +0xfb8 );struct flexcan_devtype_data {u32 quirks;/* quirks needed for different IP cores */ @@ -1292,6 +1307,35 @@ static void flexcan_set_bittiming(struct net_device *dev)return flexcan_set_bittiming_ctrl (dev); } +static void flexcan_init_ram (struct net_device *dev) +{ +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->regs; +u32 reg_ctrl2; + +/* 11.8.3.13 Detection and correction of memory errors: +* CTRL2[WRMFRZ] grants write access to all memory positions that +* require initialization, ranging from 0x080 to 0xADF and +* from 0xF28 to 0xFFF when the CAN FD feature is enabled.
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1329
Quoted 10 lines
drivers/net/can/flexcan.c +10
-0+* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to +* be initialized as well. MCR[RFEN] must not be set during memory +* initialization. +*/ + reg_ctrl2 = priv->read (®s->ctrl2); + reg_ctrl2 |=FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); + +memset_io (®s->mb[0 ][0 ],0 , + (u8 *)®s->rx_smb1[3 ] - ®s->mb[0 ][0 ] +0x4 );
why the cast?
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1333
Quoted 4 lines
drivers/net/can/flexcan.c +4
-0+ +if (priv->can.ctrlmode &CAN_CTRLMODE_FD ) +memset_io (®s->tx_smb_fd[0 ],0 , + (u8 *)®s->rx_smb1_fd[17 ] - (u8 *)®s->tx_smb_fd[0 ] +0x4 );
why the cast?
Quoted 10 lines
drivers/net/can/flexcan.c +5
-0+ + reg_ctrl2 &= ~FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); +} +/* flexcan_chip_start * * this functions is entered with clocks enabled
drivers/net/can/flexcan.c static int flexcan_chip_start(struct net_device *dev) · line 1368
Quoted 9 lines
drivers/net/can/flexcan.c +3
-0@@ -1316,6 +1360,9 @@ static int flexcan_chip_start(struct net_device *dev)if (err) goto out_chip_disable; +if (priv->devtype_data->quirks &FLEXCAN_QUIRK_SUPPORT_ECC ) +flexcan_init_ram (dev); +flexcan_set_bittiming (dev);/* MCR
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 V4 1/3] can: flexcan: initialize all flexcan memory for ECC function
Quoted 127 lines
-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2020年9月29日 20:34
To: Joakim Zhang <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V4 1/3] can: flexcan: initialize all flexcan memory for ECC functionQuoted 9 lines · Joakim Zhang
One issue was reported at a baremetal environment, which is used for FPGA verification. "The first transfer will fail for extended ID format(for both 2.0B and FD format), following frames can be transmitted and received successfully for extended format, and standard format don't have this issue. This issue occurred randomly with high possiblity, when it occurs, the transmitter will detect a BIT1 error, the receiver a CRC error. According to the spec, a non-correctable error may cause this transfer failure."
Quoted 5 lines
With
FLEXCAN_QUIRK_DISABLE_MECRquirk, it supports correctable errors, disable non-correctable errors interrupt and freeze mode. Platform has ECC hardware support, but select this quirk, this issue may not come to light. Initialize all FlexCAN memory before accessing them, at least it can avoid non-correctable errors detected due to memoryuninitialized.
Quoted 10 lines
The internal region can't be initialized when the hardware doesn't support ECC.
According to IMX8MPRM, Rev.C, 04/2020. There is a NOTE at the section 11.8.3.13 Detection and correction of memory errors:
"All FlexCAN memory must be initialized before starting its operation in order to have the parity bits in memory properly updated. CTRL2[WRMFRZ] grants write access to all memory positions that require initialization, ranging from0x080to0xADFand from0xF28to0xFFFwhen the CAN FD feature is enabled. The RXMGMASK, RX14MASK,RX15MASK,
Quoted 1 line
and RXFGMASK registers need to be initialized as well. MCR[RFEN] must not
be set during memory initialization."
Quoted 3 lines
Memory range from
0x080to0xADF, there are reserved memory (unimplemented by hardware, e.g. only configure 64 MBs), these memorycan be initialized or not.
Quoted 6 lines
In this patch, initialize all flexcan memory which includes reserved memory.
In this patch, create
FLEXCAN_QUIRK_SUPPORT_ECCfor platforms which has ECC feature. If you have a ECC platform in your hand, please select this qurik to initialize all flexcan memory firstly, then you can selectFLEXCAN_QUIRK_DISABLE_MECRto only enable correctableerrors.
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct
Quoted 64 lines
Signed-off-by Joakim Zhang <[email protected]>---
ChangeLogs:V1->V2:
* update commit messages, add a datasheet reference.
* initialize block memory instead of trivial memory.
* inilialize reserved memory.V2->V3:
* addFLEXCAN_QUIRK_SUPPORT_ECCquirk.
* removeinit_ramstruct.V3->V4:
* move register definition intoflexcan_reg.--- drivers/net/can/flexcan.c | 51 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-)drivers/net/can/flexcan.c +18
-2@@ -239,6 +239,8 @@#define FLEXCAN_QUIRK_SETUP_STOP_MODE BIT(8)/* Support CAN-FD mode */ #define FLEXCAN_QUIRK_SUPPORT_FD BIT(9) +/* support memory detection and correction */ #define +FLEXCAN_QUIRK_SUPPORT_ECC BIT(10) /* Structure of the message buffer */ struct flexcan_mb { @@ -292,7 +294,16 @@ struct flexcan_regs {u32 rximr[64 ];/* 0x880 - Not affected by Soft Reset */ u32 _reserved5[24 ];/* 0x980 */ u32 gfwr_mx6;/* 0x9e0 - MX6 */ -u32 _reserved6[63 ];/* 0x9e4 */ +u32 _reserved6[39 ];/* 0x9e4 */ +u32 _rxfir[6 ];/* 0xa80 */ +u32 _reserved8[2 ];/* 0xa98 */ +u32 _rxmgmask;/* 0xaa0 */ +u32 _rxfgmask;/* 0xaa4 */ +u32 _rx14mask;/* 0xaa8 */ +u32 _rx15mask;/* 0xaac */ +u32 tx_smb[4 ];/* 0xab0 */ +u32 rx_smb0[4 ];/* 0xac0 */ +u32 rx_smb1[4 ];/* 0xad0 */ u32 mecr;/* 0xae0 */ u32 erriar;/* 0xae4 */ u32 erridpr;/* 0xae8 */ @@ -305,9 +316,13 @@ struct flexcan_regs {u32 fdctrl;/* 0xc00 - Not affected by Soft Reset */ u32 fdcbt;/* 0xc04 - Not affected by Soft Reset */ u32 fdcrc;/* 0xc08 */ +u32 _reserved9[199 ];/* 0xc0c */ +u32 tx_smb_fd[18 ];/* 0xf28 */ +u32 rx_smb0_fd[18 ];/* 0xf70 */ +u32 rx_smb1_fd[18 ];/* 0xfb8 */ }; -static_assert (sizeof (struct flexcan_regs ) ==0x4 +0xc08 ); +static_assert (sizeof (struct flexcan_regs ) ==0x4 *18 +0xfb8 );struct flexcan_devtype_data {u32 quirks;/* quirks needed for different IP cores */ @@ -1292,6 +1307,35 @@ static void flexcan_set_bittiming(struct
net_device*dev)drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)
Quoted 12 lines
drivers/net/can/flexcan.c +10
-0return flexcan_set_bittiming_ctrl (dev); } +static void flexcan_init_ram (struct net_device *dev) { +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->regs; +u32 reg_ctrl2; + +/* 11.8.3.13 Detection and correction of memory errors: +* CTRL2[WRMFRZ] grants write access to all memory positions that +* require initialization, ranging from 0x080 to 0xADF and +* from 0xF28 to 0xFFF when the CAN FD feature is enabled. +* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to
Quoted 11 lines
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1329
Quoted 9 lines
drivers/net/can/flexcan.c +9
-0+* be initialized as well. MCR[RFEN] must not be set during memory +* initialization. +*/ + reg_ctrl2 = priv->read (®s->ctrl2); + reg_ctrl2 |=FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); + +memset_io (®s->mb[0 ][0 ],0 , + (u8 *)®s->rx_smb1[3 ] - ®s->mb[0 ][0 ] +0x4 );why the cast?
Due to mb is defined as a u8. And the count of memset_io is bytes.
Quoted 34 lines
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)
Quoted 4 lines
drivers/net/can/flexcan.c +4
-0+ +if (priv->can.ctrlmode &CAN_CTRLMODE_FD ) + memset_io(®s->tx_smb_fd[0], 0, + (u8 *)®s->rx_smb1_fd[17] - (u8 *)®s->tx_smb_fd[0] +
0x4);why the cast?
Quoted 8 lines
drivers/net/can/flexcan.c +4
-0+ + reg_ctrl2 &= ~FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); } +/* flexcan_chip_start * * this functions is entered with clocks enabled @@ -1316,6 +1360,9 drivers/net/can/flexcan.c static int flexcan_chip_start(struct net_device *dev) · line 1368
Quoted 10 lines
drivers/net/can/flexcan.c +3
-0@@ static int flexcan_chip_start(struct net_device *dev) if (err) goto out_chip_disable; +if (priv->devtype_data->quirks &FLEXCAN_QUIRK_SUPPORT_ECC ) +flexcan_init_ram (dev); +flexcan_set_bittiming (dev);/* MCR 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 |
Marc Kleine-Budde
maintainerRe: [PATCH V4 1/3] can: flexcan: initialize all flexcan memory for ECC function
Quoted 25 lines · Joakim Zhang
Quoted 13 lines
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)
Quoted 12 lines
drivers/net/can/flexcan.c +10
-0return flexcan_set_bittiming_ctrl (dev); } +static void flexcan_init_ram (struct net_device *dev) { +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->regs; +u32 reg_ctrl2; + +/* 11.8.3.13 Detection and correction of memory errors: +* CTRL2[WRMFRZ] grants write access to all memory positions that +* require initialization, ranging from 0x080 to 0xADF and +* from 0xF28 to 0xFFF when the CAN FD feature is enabled. +* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to
Quoted 11 lines
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1329
Quoted 9 lines
drivers/net/can/flexcan.c +9
-0+* be initialized as well. MCR[RFEN] must not be set during memory +* initialization. +*/ + reg_ctrl2 = priv->read (®s->ctrl2); + reg_ctrl2 |=FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); + +memset_io (®s->mb[0 ][0 ],0 , + (u8 *)®s->rx_smb1[3 ] - ®s->mb[0 ][0 ] +0x4 );why the cast?
Quoted 1 line
Due to mb is defined as a u8. And the count of
memset_iois bytes.
right. this is why you don't need the 2nd cast.
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 V4 1/3] can: flexcan: initialize all flexcan memory for ECC function
Quoted 36 lines
-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2020年9月29日 20:46
To: Joakim Zhang <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V4 1/3] can: flexcan: initialize all flexcan memory for ECC functionQuoted 12 lines · Joakim Zhang
Quoted 12 lines
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)
Quoted 12 lines
drivers/net/can/flexcan.c +10
-0return flexcan_set_bittiming_ctrl (dev); } +static void flexcan_init_ram (struct net_device *dev) { +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->regs; +u32 reg_ctrl2; + +/* 11.8.3.13 Detection and correction of memory errors: +* CTRL2[WRMFRZ] grants write access to all memory positions that +* require initialization, ranging from 0x080 to 0xADF and +* from 0xF28 to 0xFFF when the CAN FD feature is enabled. +* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers
Quoted 13 lines
Quoted 12 lines
need to
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1329
Quoted 9 lines
drivers/net/can/flexcan.c +9
-0+* be initialized as well. MCR[RFEN] must not be set during memory +* initialization. +*/ + reg_ctrl2 = priv->read (®s->ctrl2); + reg_ctrl2 |=FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); + +memset_io (®s->mb[0 ][0 ],0 , + (u8 *)®s->rx_smb1[3 ] - ®s->mb[0 ][0 ] +0x4 );why the cast?
Quoted 3 lines
Quoted 1 line
Due to mb is defined as a u8. And the count of
memset_iois bytes.right. this is why you don't need the 2nd cast.
Yes, do you need me send a patch to improve it with offsetof()?
Best Regards,
Joakim Zhang
Quoted 8 lines
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 |
Marc Kleine-Budde
maintainerRe: [PATCH V4 1/3] can: flexcan: initialize all flexcan memory for ECC function
Quoted 36 lines · Joakim Zhang
Quoted 36 lines
-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2020年9月29日 20:46
To: Joakim Zhang <[email protected]>; [email protected]
Cc: [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V4 1/3] can: flexcan: initialize all flexcan memory for ECC functionQuoted 12 lines · Joakim Zhang
Quoted 12 lines
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)
Quoted 12 lines
drivers/net/can/flexcan.c +10
-0return flexcan_set_bittiming_ctrl (dev); } +static void flexcan_init_ram (struct net_device *dev) { +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->regs; +u32 reg_ctrl2; + +/* 11.8.3.13 Detection and correction of memory errors: +* CTRL2[WRMFRZ] grants write access to all memory positions that +* require initialization, ranging from 0x080 to 0xADF and +* from 0xF28 to 0xFFF when the CAN FD feature is enabled. +* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers
Quoted 13 lines
Quoted 12 lines
need to
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1329
Quoted 9 lines
drivers/net/can/flexcan.c +9
-0+* be initialized as well. MCR[RFEN] must not be set during memory +* initialization. +*/ + reg_ctrl2 = priv->read (®s->ctrl2); + reg_ctrl2 |=FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); + +memset_io (®s->mb[0 ][0 ],0 , + (u8 *)®s->rx_smb1[3 ] - ®s->mb[0 ][0 ] +0x4 );why the cast?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Due to mb is defined as a u8. And the count of
memset_iois bytes.right. this is why you don't need the 2nd cast.
Yes, do you need me send a patch to improve it with
offsetof()?
If it looks better :), then yes :)
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 V4 1/3] can: flexcan: initialize all flexcan memory for ECC function
In reply to Marc Kleine-BuddeQuoted 116 lines · Marc Kleine-Budde
Quoted 115 lines · Joakim Zhang
One issue was reported at a baremetal environment, which is used for FPGA verification. "The first transfer will fail for extended ID format(for both 2.0B and FD format), following frames can be transmitted and received successfully for extended format, and standard format don't have this issue. This issue occurred randomly with high possiblity, when it occurs, the transmitter will detect a BIT1 error, the receiver a CRC error. According to the spec, a non-correctable error may cause this transfer failure."
With
FLEXCAN_QUIRK_DISABLE_MECRquirk, it supports correctable errors, disable non-correctable errors interrupt and freeze mode. Platform has ECC hardware support, but select this quirk, this issue may not come to light. Initialize all FlexCAN memory before accessing them, at least it can avoid non-correctable errors detected due to memory uninitialized. The internal region can't be initialized when the hardware doesn't support ECC.According to IMX8MPRM, Rev.C, 04/2020. There is a NOTE at the section 11.8.3.13 Detection and correction of memory errors:
"All FlexCAN memory must be initialized before starting its operation in order to have the parity bits in memory properly updated. CTRL2[WRMFRZ] grants write access to all memory positions that require initialization, ranging from0x080to0xADFand from0xF28to0xFFFwhen the CAN FD feature is enabled. The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to be initialized as well. MCR[RFEN] must not be set during memory initialization."Memory range from
0x080to0xADF, there are reserved memory (unimplemented by hardware, e.g. only configure 64 MBs), these memory can be initialized or not. In this patch, initialize all flexcan memory which includes reserved memory.In this patch, create
FLEXCAN_QUIRK_SUPPORT_ECCfor platforms which has ECC feature. If you have a ECC platform in your hand, please select this qurik to initialize all flexcan memory firstly, then you can selectFLEXCAN_QUIRK_DISABLE_MECRto only enable correctable errors.Signed-off-by Joakim Zhang <[email protected]>---
ChangeLogs:V1->V2:
* update commit messages, add a datasheet reference.
* initialize block memory instead of trivial memory.
* inilialize reserved memory.V2->V3:
* addFLEXCAN_QUIRK_SUPPORT_ECCquirk.
* removeinit_ramstruct.V3->V4:
* move register definition intoflexcan_reg.--- drivers/net/can/flexcan.c | 51 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-)drivers/net/can/flexcan.c +31
-2@@ -239,6 +239,8 @@#define FLEXCAN_QUIRK_SETUP_STOP_MODE BIT(8)/* Support CAN-FD mode */ #define FLEXCAN_QUIRK_SUPPORT_FD BIT(9) +/* support memory detection and correction */ +#define FLEXCAN_QUIRK_SUPPORT_ECC BIT(10)/* Structure of the message buffer */ struct flexcan_mb {@@ -292,7 +294,16 @@ struct flexcan_regs {u32 rximr[64 ];/* 0x880 - Not affected by Soft Reset */ u32 _reserved5[24 ];/* 0x980 */ u32 gfwr_mx6;/* 0x9e0 - MX6 */ -u32 _reserved6[63 ];/* 0x9e4 */ +u32 _reserved6[39 ];/* 0x9e4 */ +u32 _rxfir[6 ];/* 0xa80 */ +u32 _reserved8[2 ];/* 0xa98 */ +u32 _rxmgmask;/* 0xaa0 */ +u32 _rxfgmask;/* 0xaa4 */ +u32 _rx14mask;/* 0xaa8 */ +u32 _rx15mask;/* 0xaac */ +u32 tx_smb[4 ];/* 0xab0 */ +u32 rx_smb0[4 ];/* 0xac0 */ +u32 rx_smb1[4 ];/* 0xad0 */ u32 mecr;/* 0xae0 */ u32 erriar;/* 0xae4 */ u32 erridpr;/* 0xae8 */ @@ -305,9 +316,13 @@ struct flexcan_regs {u32 fdctrl;/* 0xc00 - Not affected by Soft Reset */ u32 fdcbt;/* 0xc04 - Not affected by Soft Reset */ u32 fdcrc;/* 0xc08 */ +u32 _reserved9[199 ];/* 0xc0c */ +u32 tx_smb_fd[18 ];/* 0xf28 */ +u32 rx_smb0_fd[18 ];/* 0xf70 */ +u32 rx_smb1_fd[18 ];/* 0xfb8 */ }; -static_assert (sizeof (struct flexcan_regs ) ==0x4 +0xc08 ); +static_assert (sizeof (struct flexcan_regs ) ==0x4 *18 +0xfb8 );struct flexcan_devtype_data {u32 quirks;/* quirks needed for different IP cores */ @@ -1292,6 +1307,35 @@ static void flexcan_set_bittiming(struct net_device *dev)return flexcan_set_bittiming_ctrl (dev); } +static void flexcan_init_ram (struct net_device *dev) +{ +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->regs; +u32 reg_ctrl2; + +/* 11.8.3.13 Detection and correction of memory errors: +* CTRL2[WRMFRZ] grants write access to all memory positions that +* require initialization, ranging from 0x080 to 0xADF and +* from 0xF28 to 0xFFF when the CAN FD feature is enabled. +* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to +* be initialized as well. MCR[RFEN] must not be set during memory +* initialization. +*/
Quoted 8 lines
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1329
Quoted 6 lines
drivers/net/can/flexcan.c +6
-0+ reg_ctrl2 = priv->read (®s->ctrl2); + reg_ctrl2 |=FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); + +memset_io (®s->mb[0 ][0 ],0 , + (u8 *)®s->rx_smb1[3 ] - ®s->mb[0 ][0 ] +0x4 );why the cast?
Doh. Of cource you need to case, but you should better cast both. :) ... or use offsetof()
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 |
Jakub Kicinski
maintainerRe: [PATCH V4 1/3] can: flexcan: initialize all flexcan memory for ECC function
In reply to Joakim ZhangQuoted 26 lines · On Wed, 30 Sep 2020 04:30:39 +0800 Joakim Zhang wrote:
drivers/net/can/flexcan.c +22
-0@@ -1292,6 +1307,35 @@ static void flexcan_set_bittiming(struct net_device *dev)return flexcan_set_bittiming_ctrl (dev); } +static void flexcan_init_ram (struct net_device *dev) +{ +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->regs; +u32 reg_ctrl2; + +/* 11.8.3.13 Detection and correction of memory errors: +* CTRL2[WRMFRZ] grants write access to all memory positions that +* require initialization, ranging from 0x080 to 0xADF and +* from 0xF28 to 0xFFF when the CAN FD feature is enabled. +* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to +* be initialized as well. MCR[RFEN] must not be set during memory +* initialization. +*/ + reg_ctrl2 = priv->read (®s->ctrl2); + reg_ctrl2 |=FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); + +memset_io (®s->mb[0 ][0 ],0 , + (u8 *)®s->rx_smb1[3 ] - ®s->mb[0 ][0 ] +0x4 ); + +if (priv->can.ctrlmode &CAN_CTRLMODE_FD )
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1341
Quoted 10 lines
drivers/net/can/flexcan.c +7
-0+memset_io (®s->tx_smb_fd[0 ],0 , + (u8 *)®s->rx_smb1_fd[17 ] - (u8 *)®s->tx_smb_fd[0 ] +0x4 ); + + reg_ctrl2 &= ~FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); +} +/* flexcan_chip_start * * this functions is entered with clocks enabled
drivers/net/can/flexcan.c:1329:20: warning: cast removes address space '__iomem' of expression drivers/net/can/flexcan.c:1329:43: error: subtraction of different types can't work (different address spaces)
Marc Kleine-Budde
maintainerRe: [PATCH V4 1/3] can: flexcan: initialize all flexcan memory for ECC function
Quoted 32 lines · Jakub Kicinski
Quoted 31 lines · On Wed, 30 Sep 2020 04:30:39 +0800 Joakim Zhang wrote:
drivers/net/can/flexcan.c +27
-0@@ -1292,6 +1307,35 @@ static void flexcan_set_bittiming(struct net_device *dev)return flexcan_set_bittiming_ctrl (dev); } +static void flexcan_init_ram (struct net_device *dev) +{ +struct flexcan_priv *priv =netdev_priv (dev); +struct flexcan_regs __iomem *regs = priv->regs; +u32 reg_ctrl2; + +/* 11.8.3.13 Detection and correction of memory errors: +* CTRL2[WRMFRZ] grants write access to all memory positions that +* require initialization, ranging from 0x080 to 0xADF and +* from 0xF28 to 0xFFF when the CAN FD feature is enabled. +* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers need to +* be initialized as well. MCR[RFEN] must not be set during memory +* initialization. +*/ + reg_ctrl2 = priv->read (®s->ctrl2); + reg_ctrl2 |=FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2); + +memset_io (®s->mb[0 ][0 ],0 , + (u8 *)®s->rx_smb1[3 ] - ®s->mb[0 ][0 ] +0x4 ); + +if (priv->can.ctrlmode &CAN_CTRLMODE_FD ) +memset_io (®s->tx_smb_fd[0 ],0 , + (u8 *)®s->rx_smb1_fd[17 ] - (u8 *)®s->tx_smb_fd[0 ] +0x4 ); + + reg_ctrl2 &= ~FLEXCAN_CTRL2_WRMFRZ ; + priv->write (reg_ctrl2, ®s->ctrl2);
Quoted 8 lines
drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1341
Quoted 5 lines
drivers/net/can/flexcan.c +2
-0+} +/* flexcan_chip_start * * this functions is entered with clocks enabled
drivers/net/can/flexcan.c:1329:20: warning: cast removes address space '__iomem' of expressiondrivers/net/can/flexcan.c:1329:43: error: subtraction of different types can't work (different address spaces)
Thanks, this patch is outdated, we use offset of now to calculate the range:
Quoted 3 lines
memset_io(®s->mb[0][0], 0, offsetof(struct flexcan_regs, rx_smb1[3]) - offsetof(struct flexcan_regs, mb[0][0]) + 0x4);
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 v4 2/3 can: flexcan: add flexcan driver for i.MX8MP
In reply to Joakim ZhangAdd flexcan driver for i.MX8MP, which supports CAN FD and ECC.
---
ChangeLogs:V1->V2:
* sort the order of the quirks by their value.V2->V3:
* add FLEXCAN_QUIRK_SUPPORT_ECC for i.MX8MP.V3->V4:
* no changes.
--- drivers/net/can/flexcan.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/can/flexcan.c +9 -0
@@ -214,6 +214,7 @@* MX53 FlexCAN2 03.00.00.00 yes no no no no no * MX6s FlexCAN3 10.00.12.00 yes yes no no yes no * MX8QM FlexCAN3 03.00.23.00 yes yes no no yes yes +* MX8MP FlexCAN3 03.00.17.01 yes yes no yes yes yes * VF610 FlexCAN3 ? no yes no yes yes? no * LS1021A FlexCAN2 03.00.04.00 no yes no no yes no * LX2160A FlexCAN3 03.00.23.00 no yes no no yes yes
@@ -391,6 +392,13 @@ static const struct flexcan_devtype_data fsl_imx8qm_devtype_data = { FLEXCAN_QUIRK_SUPPORT_FD, }; +static struct flexcan_devtype_data fsl_imx8mp_devtype_data = { + .quirks =FLEXCAN_QUIRK_DISABLE_RXFG |FLEXCAN_QUIRK_ENABLE_EACEN_RRS | +FLEXCAN_QUIRK_DISABLE_MECR |FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | +FLEXCAN_QUIRK_BROKEN_PERR_STATE |FLEXCAN_QUIRK_SETUP_STOP_MODE | +FLEXCAN_QUIRK_SUPPORT_FD |FLEXCAN_QUIRK_SUPPORT_ECC , +}; +static const struct flexcan_devtype_data fsl_vf610_devtype_data = { .quirks =FLEXCAN_QUIRK_DISABLE_RXFG |FLEXCAN_QUIRK_ENABLE_EACEN_RRS | FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP |
@@ -1892,6 +1900,7 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev)static const struct of_device_id flexcan_of_match[] = { { .compatible ="fsl,imx8qm-flexcan" , .data = &fsl_imx8qm_devtype_data, }, + { .compatible ="fsl,imx8mp-flexcan" , .data = &fsl_imx8mp_devtype_data, }, { .compatible ="fsl,imx6q-flexcan" , .data = &fsl_imx6q_devtype_data, }, { .compatible ="fsl,imx28-flexcan" , .data = &fsl_imx28_devtype_data, }, { .compatible ="fsl,imx53-flexcan" , .data = &fsl_imx25_devtype_data, },
Signature · 1 line
2.17.1
PATCH v4 3/3 can: flexcan: disable runtime PM if register flexcandev failed
In reply to Joakim ZhangDisable runtime PM if register flexcandev failed, and balance reference of usage_count.
---
ChangeLogs:V1->V4:
* no changes.
--- drivers/net/can/flexcan.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/can/flexcan.c +2 -0
@@ -2055,6 +2055,8 @@ static int flexcan_probe(struct platform_device *pdev)return 0 ; failed_register: +pm_runtime_put_noidle (&pdev->dev); +pm_runtime_disable (&pdev->dev);free_candev (dev);return err; }
Signature · 1 line
2.17.1