Skip to contentSkip to conversation

patch set for flexcan

PATCH Superseded Joakim Zhang 2 participants 10 messages Sep 27, 2020 – Sep 28, 2020

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover patch set for flexcan

can: flexcan: initialize all flexcan memory for ECC function
can: flexcan: add flexcan driver for i.MX8MP
These two patches add i.MX8MP driver support.

can: flexcan: disable runtime PM if register flexcandev failed Resend this patch as a small driver improvement.

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 | 78 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
Signature · 1 line
2.17.1
#1 lore raw

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

---
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(+)
drivers/net/can/flexcan.c +67 -0
index e86925134009..aca0fc40ae9b 100644
@@ -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
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

Quoted 70 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_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.

---
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(+)
drivers/net/can/flexcan.c +23 -0
index e86925134009..aca0fc40ae9b 100644
@@ -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,

drivers/net/can/flexcan.c struct flexcan_regs { · line 344

Quoted 10 lines
drivers/net/can/flexcan.c +10 -0
+	 * 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,
+	},
+};

As it's only two ranges, I think there's no need for this struct. Directly move code that into the for loops.

Quoted 42 lines
drivers/net/can/flexcan.c +31 -0
+
 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

drivers/net/can/flexcan.c static int flexcan_chip_start(struct net_device *dev) · line 1384

Quoted 5 lines
drivers/net/can/flexcan.c +2 -0
@@ -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);

Can you test this on both layerscape SoCs (fsl,ls1021ar2-flexcan and fsl,lx2160ar1-flexcan)

drivers/net/can/flexcan.c static int flexcan_chip_start(struct net_device *dev) · line 1388

Quoted 5 lines
drivers/net/can/flexcan.c +1 -0
+
 	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 |
#3 lore raw

RE: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

Quoted 89 lines

-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2020年9月28日 3:52
To: Joakim Zhang <[email protected]>; [email protected]
Cc: dl-linux-imx <[email protected]>; [email protected]
Subject: Re: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

Quoted 15 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_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.

Quoted 7 lines

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,

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 0x080 to 0xADF, there are reserved memory (unimplemented by hardware, e.g. only configure 64 MBs), these memory

can be initialized or not.

Quoted 50 lines

In this patch, initialize all flexcan memory which includes reserved memory.

---
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(+)
drivers/net/can/flexcan.c +28 -0
index e86925134009..aca0fc40ae9b 100644
@@ -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
+	 */
Quoted 8 lines

drivers/net/can/flexcan.c struct flexcan_regs { · line 344

Quoted 5 lines
drivers/net/can/flexcan.c +5 -0
+	{
+		.offset = 0xf28,
+		.len = (0xfff - 0xf28) / sizeof(u32) + 1,
+	},
+};

As it's only two ranges, I think there's no need for this struct. Directly move code that into the for loops.

OK.

Quoted 46 lines

drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct

Quoted 5 lines
drivers/net/can/flexcan.c +1 -0
+
 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)

drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)

Quoted 13 lines
drivers/net/can/flexcan.c +11 -0
 		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

Quoted 26 lines
drivers/net/can/flexcan.c +19 -0
+	 * 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)
drivers/net/can/flexcan.c +0 -0
 	if (err)
 		goto out_chip_disable;
Quoted 5 lines

drivers/net/can/flexcan.c static int flexcan_chip_start(struct net_device *dev) · line 1384

Quoted 2 lines
drivers/net/can/flexcan.c +2 -0
+	if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_MECR)
+		flexcan_init_ram(dev);

Can you test this on both layerscape SoCs (fsl,ls1021ar2-flexcan and fsl,lx2160ar1-flexcan)

Would ask Pankaj Bansal for help, since he is the owner of layerscape SoCs, these SoCs are unavailable at my side.

Best Regards,
Joakim Zhang

Quoted 13 lines

drivers/net/can/flexcan.c static int flexcan_chip_start(struct net_device *dev) · line 1388

Quoted 5 lines
drivers/net/can/flexcan.c +1 -0
+
 	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 |
#4 lore raw

Re: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

In reply to Joakim Zhang

On 9/27/20 6:07 PM, Joakim Zhang wrote:
[...]

Quoted 11 lines
drivers/net/can/flexcan.c +11 -0
+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.

drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev) · line 1349

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(&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);

As the write function only does endian conversion, and you're writing 0 here. What about using iowrite32_rep() and get rid of the for loop?

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 |
#5 lore raw

RE: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

Quoted 24 lines

-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2020年9月28日 3:58
To: Joakim Zhang <[email protected]>; [email protected]
Cc: dl-linux-imx <[email protected]>; [email protected]
Subject: Re: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

On 9/27/20 6:07 PM, Joakim Zhang wrote:
[...]

drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)

Quoted 11 lines
drivers/net/can/flexcan.c +11 -0
+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

Quoted 13 lines

drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)

Quoted 10 lines
drivers/net/can/flexcan.c +10 -0
+	 * 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);

As the write function only does endian conversion, and you're writing 0 here. What about using iowrite32_rep() and get rid of the for loop?

Thanks for this point, I will update in next version.

Best Regards,
Joakim Zhang

Quoted 7 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 |
#6 lore raw

RE: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

Quoted 48 lines

-----Original Message-----
From: Joakim Zhang <[email protected]>
Sent: 2020年9月28日 10:29
To: Marc Kleine-Budde <[email protected]>; [email protected]
Cc: dl-linux-imx <[email protected]>; [email protected]
Subject: RE: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

Quoted 11 lines

-----Original Message-----
From: Marc Kleine-Budde <[email protected]>
Sent: 2020年9月28日 3:58
To: Joakim Zhang <[email protected]>; [email protected]
Cc: dl-linux-imx <[email protected]>; [email protected]
Subject: Re: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

On 9/27/20 6:07 PM, Joakim Zhang wrote:
[...]

Quoted 11 lines

drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)

Quoted 11 lines
drivers/net/can/flexcan.c +11 -0
+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

Quoted 14 lines

need to

drivers/net/can/flexcan.c static void flexcan_set_bittiming(struct net_device *dev)

Quoted 10 lines
drivers/net/can/flexcan.c +10 -0
+	 * 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);

As the write function only does endian conversion, and you're writing 0 here. What about using iowrite32_rep() and get rid of the for loop?

Quoted 1 line

Thanks for this point, I will update in next version.

Ahhh.. I check iowrite32_rep() writes a buf to single address, no shift for address.

I prefer to use memset_io() here to initialize a block of io memory. What do you think?

Best Regards,
Joakim Zhang

Quoted 9 lines

Best Regards,
Joakim Zhang

Quoted 7 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 |
#7 lore raw

Re: [PATCH V2 1/3] can: flexcan: initialize all flexcan memory for ECC function

Quoted 10 lines · Joakim Zhang
Quoted 8 lines
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	for (i = 0; i < ram_init[0].len; i++)
+		priv->write(0, (void __iomem *)regs + ram_init[0].offset +
+sizeof(u32) * i);

As the write function only does endian conversion, and you're writing 0 here. What about using iowrite32_rep() and get rid of the for loop?

Thanks for this point, I will update in next version.

Ahhh.. I check iowrite32_rep() writes a buf to single address, no shift for address.

Doh! Right.

Quoted 2 lines

I prefer to use memset_io() here to initialize a block of io memory. What do you think?

Of course, that's the correct function for this!

regards,
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 |
#8 lore raw

PATCH v2 2/3 can: flexcan: add flexcan driver for i.MX8MP

In reply to Joakim Zhang

Add flexcan driver for i.MX8MP, which supports CAN FD and ECC.

---
ChangeLogs:
V1->V2:
* sort the order of the quirks by their value.

---
 drivers/net/can/flexcan.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/can/flexcan.c +9 -0
index aca0fc40ae9b..4844dbf77c9c 100644
@@ -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
@@ -410,6 +411,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,
+};
+
 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 |
@@ -1912,6 +1920,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
#9 lore raw

PATCH v2 3/3 can: flexcan: disable runtime PM if register flexcandev failed

In reply to Joakim Zhang

Disable runtime PM if register flexcandev failed, and balance reference of usage_count.

---
ChangeLogs:
V1->V2:
* no changes.

---
 drivers/net/can/flexcan.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/can/flexcan.c +2 -0
index 4844dbf77c9c..ee6d220a4b12 100644
@@ -2075,6 +2075,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