Commit 15ef2072 authored by Joakim Zhang's avatar Joakim Zhang Committed by Marc Kleine-Budde

can: flexcan: add correctable errors correction when HW supports ECC

commit cdce8448 ("can: flexcan: add vf610 support for FlexCAN")
From above commit by Stefan Agner, the patch just disables
non-correctable errors interrupt and freeze mode. It still can correct
the correctable errors since ECC enabled by default after reset (MECR[ECCDIS]=0,
enable memory error correct) if HW supports ECC.

commit 5e269324 ("can: flexcan: disable completely the ECC mechanism")
From above commit by Joakim Zhang, the patch disables ECC completely (assert
MECR[ECCDIS]) according to the explanation of FLEXCAN_QUIRK_DISABLE_MECR that
disable memory error detection. This cause correctable errors cannot be
corrected even HW supports ECC.

The error correction mechanism ensures that in this 13-bit word, errors
in one bit can be corrected (correctable errors) and errors in two bits can
be detected but not corrected (non-correctable errors). Errors in more than
two bits may not be detected.

If HW supports ECC, we can use this to correct the correctable errors detected
from FlexCAN memory. Then disable non-correctable errors interrupt and freeze
mode to avoid that put FlexCAN in freeze mode.

This patch adds correctable errors correction when HW supports ECC, and
modify explanation for FLEXCAN_QUIRK_DISABLE_MECR.
Signed-off-by: default avatarJoakim Zhang <qiangqing.zhang@nxp.com>
Link: https://lore.kernel.org/r/20200416093126.15242-1-qiangqing.zhang@nxp.comSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent ee97302d
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
#define FLEXCAN_QUIRK_DISABLE_RXFG BIT(2) #define FLEXCAN_QUIRK_DISABLE_RXFG BIT(2)
/* Enable EACEN and RRS bit in ctrl2 */ /* Enable EACEN and RRS bit in ctrl2 */
#define FLEXCAN_QUIRK_ENABLE_EACEN_RRS BIT(3) #define FLEXCAN_QUIRK_ENABLE_EACEN_RRS BIT(3)
/* Disable Memory error detection */ /* Disable non-correctable errors interrupt and freeze mode */
#define FLEXCAN_QUIRK_DISABLE_MECR BIT(4) #define FLEXCAN_QUIRK_DISABLE_MECR BIT(4)
/* Use timestamp based offloading */ /* Use timestamp based offloading */
#define FLEXCAN_QUIRK_USE_OFF_TIMESTAMP BIT(5) #define FLEXCAN_QUIRK_USE_OFF_TIMESTAMP BIT(5)
...@@ -1221,28 +1221,43 @@ static int flexcan_chip_start(struct net_device *dev) ...@@ -1221,28 +1221,43 @@ static int flexcan_chip_start(struct net_device *dev)
for (i = 0; i < priv->mb_count; i++) for (i = 0; i < priv->mb_count; i++)
priv->write(0, &regs->rximr[i]); priv->write(0, &regs->rximr[i]);
/* On Vybrid, disable memory error detection interrupts /* On Vybrid, disable non-correctable errors interrupt and
* and freeze mode. * freeze mode. It still can correct the correctable errors
* This also works around errata e5295 which generates * when HW supports ECC.
* false positive memory errors and put the device in *
* freeze mode. * This also works around errata e5295 which generates false
* positive memory errors and put the device in freeze mode.
*/ */
if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_MECR) { if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_MECR) {
/* Follow the protocol as described in "Detection /* Follow the protocol as described in "Detection
* and Correction of Memory Errors" to write to * and Correction of Memory Errors" to write to
* MECR register * MECR register (step 1 - 5)
*
* 1. By default, CTRL2[ECRWRE] = 0, MECR[ECRWRDIS] = 1
* 2. set CTRL2[ECRWRE]
*/ */
reg_ctrl2 = priv->read(&regs->ctrl2); reg_ctrl2 = priv->read(&regs->ctrl2);
reg_ctrl2 |= FLEXCAN_CTRL2_ECRWRE; reg_ctrl2 |= FLEXCAN_CTRL2_ECRWRE;
priv->write(reg_ctrl2, &regs->ctrl2); priv->write(reg_ctrl2, &regs->ctrl2);
/* 3. clear MECR[ECRWRDIS] */
reg_mecr = priv->read(&regs->mecr); reg_mecr = priv->read(&regs->mecr);
reg_mecr &= ~FLEXCAN_MECR_ECRWRDIS; reg_mecr &= ~FLEXCAN_MECR_ECRWRDIS;
priv->write(reg_mecr, &regs->mecr); priv->write(reg_mecr, &regs->mecr);
reg_mecr |= FLEXCAN_MECR_ECCDIS;
/* 4. all writes to MECR must keep MECR[ECRWRDIS] cleared */
reg_mecr &= ~(FLEXCAN_MECR_NCEFAFRZ | FLEXCAN_MECR_HANCEI_MSK | reg_mecr &= ~(FLEXCAN_MECR_NCEFAFRZ | FLEXCAN_MECR_HANCEI_MSK |
FLEXCAN_MECR_FANCEI_MSK); FLEXCAN_MECR_FANCEI_MSK);
priv->write(reg_mecr, &regs->mecr); priv->write(reg_mecr, &regs->mecr);
/* 5. after configuration done, lock MECR by either
* setting MECR[ECRWRDIS] or clearing CTRL2[ECRWRE]
*/
reg_mecr |= FLEXCAN_MECR_ECRWRDIS;
priv->write(reg_mecr, &regs->mecr);
reg_ctrl2 &= ~FLEXCAN_CTRL2_ECRWRE;
priv->write(reg_ctrl2, &regs->ctrl2);
} }
err = flexcan_transceiver_enable(priv); err = flexcan_transceiver_enable(priv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment