Skip to content

Commit a659712

Browse files
Joakim Zhangmarckleinebudde
authored andcommitted
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. Signed-off-by: Joakim Zhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mkl: wrap long lines] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent eb79a26 commit a659712

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

drivers/net/can/flexcan.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@
239239
#define FLEXCAN_QUIRK_SETUP_STOP_MODE BIT(8)
240240
/* Support CAN-FD mode */
241241
#define FLEXCAN_QUIRK_SUPPORT_FD BIT(9)
242+
/* support memory detection and correction */
243+
#define FLEXCAN_QUIRK_SUPPORT_ECC BIT(10)
242244

243245
/* Structure of the message buffer */
244246
struct flexcan_mb {
@@ -292,7 +294,16 @@ struct flexcan_regs {
292294
u32 rximr[64]; /* 0x880 - Not affected by Soft Reset */
293295
u32 _reserved5[24]; /* 0x980 */
294296
u32 gfwr_mx6; /* 0x9e0 - MX6 */
295-
u32 _reserved6[63]; /* 0x9e4 */
297+
u32 _reserved6[39]; /* 0x9e4 */
298+
u32 _rxfir[6]; /* 0xa80 */
299+
u32 _reserved8[2]; /* 0xa98 */
300+
u32 _rxmgmask; /* 0xaa0 */
301+
u32 _rxfgmask; /* 0xaa4 */
302+
u32 _rx14mask; /* 0xaa8 */
303+
u32 _rx15mask; /* 0xaac */
304+
u32 tx_smb[4]; /* 0xab0 */
305+
u32 rx_smb0[4]; /* 0xac0 */
306+
u32 rx_smb1[4]; /* 0xad0 */
296307
u32 mecr; /* 0xae0 */
297308
u32 erriar; /* 0xae4 */
298309
u32 erridpr; /* 0xae8 */
@@ -305,9 +316,13 @@ struct flexcan_regs {
305316
u32 fdctrl; /* 0xc00 - Not affected by Soft Reset */
306317
u32 fdcbt; /* 0xc04 - Not affected by Soft Reset */
307318
u32 fdcrc; /* 0xc08 */
319+
u32 _reserved9[199]; /* 0xc0c */
320+
u32 tx_smb_fd[18]; /* 0xf28 */
321+
u32 rx_smb0_fd[18]; /* 0xf70 */
322+
u32 rx_smb1_fd[18]; /* 0xfb8 */
308323
};
309324

310-
static_assert(sizeof(struct flexcan_regs) == 0x4 + 0xc08);
325+
static_assert(sizeof(struct flexcan_regs) == 0x4 * 18 + 0xfb8);
311326

312327
struct flexcan_devtype_data {
313328
u32 quirks; /* quirks needed for different IP cores */
@@ -1292,6 +1307,37 @@ static void flexcan_set_bittiming(struct net_device *dev)
12921307
return flexcan_set_bittiming_ctrl(dev);
12931308
}
12941309

1310+
static void flexcan_ram_init(struct net_device *dev)
1311+
{
1312+
struct flexcan_priv *priv = netdev_priv(dev);
1313+
struct flexcan_regs __iomem *regs = priv->regs;
1314+
u32 reg_ctrl2;
1315+
1316+
/* 11.8.3.13 Detection and correction of memory errors:
1317+
* CTRL2[WRMFRZ] grants write access to all memory positions
1318+
* that require initialization, ranging from 0x080 to 0xADF
1319+
* and from 0xF28 to 0xFFF when the CAN FD feature is enabled.
1320+
* The RXMGMASK, RX14MASK, RX15MASK, and RXFGMASK registers
1321+
* need to be initialized as well. MCR[RFEN] must not be set
1322+
* during memory initialization.
1323+
*/
1324+
reg_ctrl2 = priv->read(&regs->ctrl2);
1325+
reg_ctrl2 |= FLEXCAN_CTRL2_WRMFRZ;
1326+
priv->write(reg_ctrl2, &regs->ctrl2);
1327+
1328+
memset_io(&regs->mb[0][0], 0,
1329+
offsetof(struct flexcan_regs, rx_smb1[3]) -
1330+
offsetof(struct flexcan_regs, mb[0][0]) + 0x4);
1331+
1332+
if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
1333+
memset_io(&regs->tx_smb_fd[0], 0,
1334+
offsetof(struct flexcan_regs, rx_smb1_fd[17]) -
1335+
offsetof(struct flexcan_regs, tx_smb_fd[0]) + 0x4);
1336+
1337+
reg_ctrl2 &= ~FLEXCAN_CTRL2_WRMFRZ;
1338+
priv->write(reg_ctrl2, &regs->ctrl2);
1339+
}
1340+
12951341
/* flexcan_chip_start
12961342
*
12971343
* this functions is entered with clocks enabled
@@ -1316,6 +1362,9 @@ static int flexcan_chip_start(struct net_device *dev)
13161362
if (err)
13171363
goto out_chip_disable;
13181364

1365+
if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SUPPORT_ECC)
1366+
flexcan_ram_init(dev);
1367+
13191368
flexcan_set_bittiming(dev);
13201369

13211370
/* MCR

0 commit comments

Comments
 (0)