netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joakim Zhang <qiangqing.zhang@nxp.com>
To: mkl@pengutronix.de, linux-can@vger.kernel.org
Cc: linux-imx@nxp.com, netdev@vger.kernel.org
Subject: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function
Date: Mon, 28 Sep 2020 00:07:59 +0800	[thread overview]
Message-ID: <20200927160801.28569-2-qiangqing.zhang@nxp.com> (raw)
In-Reply-To: <20200927160801.28569-1-qiangqing.zhang@nxp.com>

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. 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.

Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
ChangeLogs:
V1->V2:
	* update commit messages, add a datasheet reference.
	* initialize block memory instead of trivial memory.
	* inilialize reserved memory.
---
 drivers/net/can/flexcan.c | 67 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index e86925134009..aca0fc40ae9b 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -309,6 +309,40 @@ struct flexcan_regs {
 
 static_assert(sizeof(struct flexcan_regs) == 0x4 + 0xc08);
 
+/* Structure of memory need be initialized for ECC feature */
+static const struct flexcan_ram_int {
+	u32 offset;
+	u16 len;
+} ram_init[] = {
+	/* ranging from 0x0080 to 0x0ADF, ram details as below list:
+	 * 0x0080--0x087F:	128 MBs
+	 * 0x0880--0x0A7F:	128 RXIMRs
+	 * 0x0A80--0x0A97:	6 RXFIRs
+	 * 0x0A98--0x0A9F:	Reserved
+	 * 0x0AA0--0x0AA3:	RXMGMASK
+	 * 0x0AA4--0x0AA7:	RXFGMASK
+	 * 0x0AA8--0x0AAB:	RX14MASK
+	 * 0x0AAC--0x0AAF:	RX15MASK
+	 * 0x0AB0--0x0ABF:	TX_SMB
+	 * 0x0AC0--0x0ACF:	RX_SMB0
+	 * 0x0AD0--0x0ADF:	RX_SMB1
+	 */
+	{
+		.offset = 0x80,
+		.len = (0xadf - 0x80) / sizeof(u32) + 1,
+	},
+	/* ranging from 0x0F28 to 0x0FFF when CAN FD feature is enabled,
+	 * ram details as below list:
+	 * 0x0F28--0x0F6F:	TX_SMB_FD
+	 * 0x0F70--0x0FB7:	RX_SMB0_FD
+	 * 0x0FB8--0x0FFF:	RX_SMB0_FD
+	 */
+	{
+		.offset = 0xf28,
+		.len = (0xfff - 0xf28) / sizeof(u32) + 1,
+	},
+};
+
 struct flexcan_devtype_data {
 	u32 quirks;		/* quirks needed for different IP cores */
 };
@@ -1292,6 +1326,36 @@ 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;
+	int i;
+
+	/* 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(&regs->ctrl2);
+	reg_ctrl2 |= FLEXCAN_CTRL2_WRMFRZ;
+	priv->write(reg_ctrl2, &regs->ctrl2);
+
+	for (i = 0; i < ram_init[0].len; i++)
+		priv->write(0, (void __iomem *)regs + ram_init[0].offset + sizeof(u32) * i);
+
+	if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
+		for (i = 0; i < ram_init[1].len; i++)
+			priv->write(0, (void __iomem *)regs + ram_init[1].offset + sizeof(u32) * i);
+
+	reg_ctrl2 &= ~FLEXCAN_CTRL2_WRMFRZ;
+	priv->write(reg_ctrl2, &regs->ctrl2);
+}
+
 /* flexcan_chip_start
  *
  * this functions is entered with clocks enabled
@@ -1316,6 +1380,9 @@ static int flexcan_chip_start(struct net_device *dev)
 	if (err)
 		goto out_chip_disable;
 
+	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_MECR)
+		flexcan_init_ram(dev);
+
 	flexcan_set_bittiming(dev);
 
 	/* MCR
-- 
2.17.1


  reply	other threads:[~2020-09-27  8:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-27 16:07 [PATCH V2 0/3] patch set for flexcan Joakim Zhang
2020-09-27 16:07 ` Joakim Zhang [this message]
2020-09-27 19:51   ` [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function Marc Kleine-Budde
2020-09-28  2:00     ` Joakim Zhang
2020-09-27 19:57   ` Marc Kleine-Budde
2020-09-28  2:29     ` Joakim Zhang
2020-09-28  5:23       ` Joakim Zhang
2020-09-28  6:20         ` Marc Kleine-Budde
2020-09-27 16:08 ` [PATCH V2 2/3] can: flexcan: add flexcan driver for i.MX8MP Joakim Zhang
2020-09-27 16:08 ` [PATCH V2 3/3] can: flexcan: disable runtime PM if register flexcandev failed Joakim Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200927160801.28569-2-qiangqing.zhang@nxp.com \
    --to=qiangqing.zhang@nxp.com \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).