Skip to contentSkip to conversation

can: mcp251xfd: Increase poll timeout

PATCH Superseded Marek Vasut 4 participants 14 messages May 4, 2023 – Jun 11, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 can: mcp251xfd: Increase poll timeout

From: Fedor Ross <[email protected]>

Make MCP251XFD_POLL_TIMEOUT_US timeout calculation dynamic. Use maximum of 1ms and bit time of one full 72 bytes CANFD frame at the current bitrate. This seems to be necessary when configuring low bit rates like 10 Kbit/s for example. Otherwise during polling for the CAN controller to enter 'Normal CAN 2.0 mode' the timeout limit is exceeded and the configuration fails with:

$ ip link set dev can1 up type can bitrate 10000
[  731.911072] mcp251xfd spi2.1 can1: Controller failed to enter mode CAN 2.0 Mode (6) and stays in Configuration Mode (4) (con=0x068b0760, osc=0x00000468).
[  731.927192] mcp251xfd spi2.1 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[  731.938101] A link change request failed with some changes committed already. Interface can1 may have been left with an inconsistent configuration, please check.
RTNETLINK answers: Connection timed out
Fixes 55e5b97f003e8 ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN")

---
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Manivannan Sadhasivam <[email protected]>
Cc: Marc Kleine-Budde <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Thomas Kopp <[email protected]>
Cc: Wolfgang Grandegger <[email protected]>
Cc: [email protected]

---
 drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +3 -1
index 68df6d4641b5c..9908843798cef 100644
@@ -227,6 +227,7 @@ static int
 __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,
 			  const u8 mode_req, bool nowait)
 {
+	const struct can_bittiming *bt = &priv->can.bittiming;
 	u32 con = 0, con_reqop, osc = 0;
 	u8 mode;
 	int err;
@@ -251,7 +252,8 @@ __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,
 				       FIELD_GET(MCP251XFD_REG_CON_OPMOD_MASK,
 						 con) == mode_req,
 				       MCP251XFD_POLL_SLEEP_US,
-				       MCP251XFD_POLL_TIMEOUT_US);
+				       max(MCP251XFD_POLL_TIMEOUT_US,
+					   576 * USEC_PER_SEC / bt->bitrate));
 	if (err != -ETIMEDOUT && err != -EBADMSG)
 		return err;
 
Signature · 1 line
2.39.2
#1 lore raw
Quoted 5 lines · Marek Vasut

From: Fedor Ross <[email protected]>

Make MCP251XFD_POLL_TIMEOUT_US timeout calculation dynamic. Use maximum of 1ms and bit time of one full 72 bytes CANFD frame at the current bitrate.

The 1ms was arbitrary chosen by me during development. The previous driver by Martin Sperl uses a hardcoded loop of 256 retries and no explicit sleep.

The datasheet "MCP25xxFD Family Reference Manual" says it needs an idle bus.

Quoted 44 lines

This seems to be necessary when configuring low
bit rates like 10 Kbit/s for example. Otherwise during polling for the CAN controller to enter 'Normal CAN 2.0 mode' the timeout limit is exceeded and the configuration fails with:

$ ip link set dev can1 up type can bitrate 10000
[  731.911072] mcp251xfd spi2.1 can1: Controller failed to enter mode CAN 2.0 Mode (6) and stays in Configuration Mode (4) (con=0x068b0760, osc=0x00000468).
[  731.927192] mcp251xfd spi2.1 can1: CRC read error at address 0x0e0c (length=4, data=00 00 00 00, CRC=0x0000) retrying.
[  731.938101] A link change request failed with some changes committed already. Interface can1 may have been left with an inconsistent configuration, please check.
RTNETLINK answers: Connection timed out
Fixes 55e5b97f003e8 ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN")

---
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Manivannan Sadhasivam <[email protected]>
Cc: Marc Kleine-Budde <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Thomas Kopp <[email protected]>
Cc: Wolfgang Grandegger <[email protected]>
Cc: [email protected]

---
 drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
index 68df6d4641b5c..9908843798cef 100644
@@ -227,6 +227,7 @@ static int
 __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,
 			  const u8 mode_req, bool nowait)
 {
+	const struct can_bittiming *bt = &priv->can.bittiming;
 	u32 con = 0, con_reqop, osc = 0;
 	u8 mode;
 	int err;

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv, · line 256

Quoted 6 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2 -1
@@ -251,7 +252,8 @@ __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,
 				       FIELD_GET(MCP251XFD_REG_CON_OPMOD_MASK,
 						 con) == mode_req,
 				       MCP251XFD_POLL_SLEEP_US,
-				       MCP251XFD_POLL_TIMEOUT_US);
+				       max(MCP251XFD_POLL_TIMEOUT_US,
+					   576 * USEC_PER_SEC / bt->bitrate));

Let's use CANFD_FRAME_LEN_MAX * BITS_PER_BYTE instead of 576. I can fix this while applying.

Quoted 7 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +0 -0
 	if (err != -ETIMEDOUT && err != -EBADMSG)
 		return err;
 
Signature · 1 line
2.39.2

Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |
#2 lore raw
Quoted 2 lines

The datasheet "MCP25xxFD Family Reference Manual" says it needs an idle bus.

Technically what's needed is an idle condition on the bus as specified in the ISO. i.e. 11 consecutive sampled recessive bits after a full frame (if one is currently in transmission).

Quoted 54 lines
Quoted 7 lines

This seems to be necessary when configuring low
bit rates like 10 Kbit/s for example. Otherwise during polling for the CAN controller to enter 'Normal CAN 2.0 mode' the timeout limit is exceeded and the configuration fails with:

$ ip link set dev can1 up type can bitrate 10000
[  731.911072] mcp251xfd spi2.1 can1: Controller failed to enter mode CAN

2.0 Mode (6) and stays in Configuration Mode (4) (con=0x068b0760, osc=0x00000468).

Quoted 1 line
[  731.927192] mcp251xfd spi2.1 can1: CRC read error at address 0x0e0c

(length=4, data=00 00 00 00, CRC=0x0000) retrying.

Quoted 1 line
[  731.938101] A link change request failed with some changes committed

already. Interface can1 may have been left with an inconsistent configuration, please check.

Quoted 3 lines

RTNETLINK answers: Connection timed out

Fixes 55e5b97f003e8 ("can: mcp25xxfd: add driver for Microchip

MCP25xxFD SPI CAN")

Quoted 15 lines

---
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Manivannan Sadhasivam <[email protected]>
Cc: Marc Kleine-Budde <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Thomas Kopp <[email protected]>
Cc: Wolfgang Grandegger <[email protected]>
Cc: [email protected]

Review

Quoted 5 lines
---
 drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct

Quoted 12 lines

index 68df6d4641b5c..9908843798cef 100644

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
@@ -227,6 +227,7 @@ static int
 __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,
 			  const u8 mode_req, bool nowait)
 {
+	const struct can_bittiming *bt = &priv->can.bittiming;
 	u32 con = 0, con_reqop, osc = 0;
 	u8 mode;
 	int err;
@@ -251,7 +252,8 @@ __mcp251xfd_chip_set_mode(const struct

mcp251xfd_priv *priv,

Quoted 1 line

FIELD_GET(MCP251XFD_REG_CON_OPMOD_MASK,

Quoted 9 lines

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv, · line 256

Quoted 5 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2 -1
 						 con) == mode_req,
 				       MCP251XFD_POLL_SLEEP_US,
-				       MCP251XFD_POLL_TIMEOUT_US);
+				       max(MCP251XFD_POLL_TIMEOUT_US,
+					   576 * USEC_PER_SEC / bt->bitrate));

Let's use CANFD_FRAME_LEN_MAX * BITS_PER_BYTE instead of 576. I can fix this while applying.

So, I'd suggest CANFD_FRAME_LEN_MAX * BITS_PER_BYTE + 11 + stuffbits, as far as I can tell the CANFD_FRAME_LEN_MAX ignores stuffbits, so as an overapproximation something like (CANFD_FRAME_LEN_MAX * BITS_PER_BYTE) * 1.2 + 11. It's unlikely that it will actually be necessary but it makes it clear where the numbers are coming from.

Best Regards,
Thomas

#3 lore raw
Quoted 6 lines · On 05.05.2023 07:07:03, [email protected] wrote:
Quoted 2 lines

The datasheet "MCP25xxFD Family Reference Manual" says it needs an idle bus.

Technically what's needed is an idle condition on the bus as specified in the ISO. i.e. 11 consecutive sampled recessive bits after a full frame (if one is currently in transmission).

Right. What happens if another CAN frames comes before there are 11 consecutive sampled recessive bits? The IFS for CAN is 3 bits?

Quoted 26 lines
Quoted 17 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct

Quoted 12 lines

index 68df6d4641b5c..9908843798cef 100644

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
@@ -227,6 +227,7 @@ static int
 __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,
 			  const u8 mode_req, bool nowait)
 {
+	const struct can_bittiming *bt = &priv->can.bittiming;
 	u32 con = 0, con_reqop, osc = 0;
 	u8 mode;
 	int err;
@@ -251,7 +252,8 @@ __mcp251xfd_chip_set_mode(const struct

mcp251xfd_priv *priv,

Quoted 1 line

FIELD_GET(MCP251XFD_REG_CON_OPMOD_MASK,

Quoted 9 lines

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv, · line 256

Quoted 5 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2 -1
 						 con) == mode_req,
 				       MCP251XFD_POLL_SLEEP_US,
-				       MCP251XFD_POLL_TIMEOUT_US);
+				       max(MCP251XFD_POLL_TIMEOUT_US,
+					   576 * USEC_PER_SEC / bt->bitrate));

Let's use CANFD_FRAME_LEN_MAX * BITS_PER_BYTE instead of 576. I can fix this while applying.

Quoted 4 lines

So, I'd suggest CANFD_FRAME_LEN_MAX * BITS_PER_BYTE + 11 + stuffbits, as far as I can tell the CANFD_FRAME_LEN_MAX ignores stuffbits, so as an overapproximation something like (CANFD_FRAME_LEN_MAX * BITS_PER_BYTE) * 1.2 + 11.

..and a define for the 11 and a comment for the * 1.2

Quoted 2 lines

It's unlikely that it will actually be
necessary but it makes it clear where the numbers are coming from.

Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |
#4 lore raw
Quoted 10 lines · On 05.05.2023 07:07:03, [email protected] wrote:
Quoted 6 lines
Quoted 2 lines

The datasheet "MCP25xxFD Family Reference Manual" says it needs an idle bus.

Technically what's needed is an idle condition on the bus as specified in the ISO. i.e. 11 consecutive sampled recessive bits after a full frame (if one is currently in transmission).

Right. What happens if another CAN frames comes before there are 11 consecutive sampled recessive bits? The IFS for CAN is 3 bits?

Not quite. Between the Frames is an IFS that's correct but the IFS consists of an Intermission which is 3 bits long + a bus idle condition of 11 bits. Regular frames have to wait for the IFS to elapse BUT there's an exception for error frames and overload frames. EF may be up to 12 bit, OF are 8 dominant + 8 recessive bits, browsing through the spec I think only 2 OFs can happen consecutively. Adding another 32 bits to the formula should cover this.

Quoted 25 lines
Quoted 16 lines
Quoted 16 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct

Quoted 12 lines

index 68df6d4641b5c..9908843798cef 100644

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
@@ -227,6 +227,7 @@ static int
 __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,
 			  const u8 mode_req, bool nowait)
 {
+	const struct can_bittiming *bt = &priv->can.bittiming;
 	u32 con = 0, con_reqop, osc = 0;
 	u8 mode;
 	int err;
@@ -251,7 +252,8 @@ __mcp251xfd_chip_set_mode(const struct

mcp251xfd_priv *priv,

Quoted 1 line
Quoted 8 lines
Quoted 8 lines

FIELD_GET(MCP251XFD_REG_CON_OPMOD_MASK,

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv, · line 256

Quoted 5 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2 -1
 						 con) == mode_req,
 				       MCP251XFD_POLL_SLEEP_US,
-				       MCP251XFD_POLL_TIMEOUT_US);
+				       max(MCP251XFD_POLL_TIMEOUT_US,
+					   576 * USEC_PER_SEC / bt->bitrate));

Let's use CANFD_FRAME_LEN_MAX * BITS_PER_BYTE instead of 576. I can

fix

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

this while applying.

So, I'd suggest CANFD_FRAME_LEN_MAX * BITS_PER_BYTE + 11 + stuffbits, as far as I can tell the CANFD_FRAME_LEN_MAX ignores stuffbits, so as an overapproximation something like (CANFD_FRAME_LEN_MAX * BITS_PER_BYTE) * 1.2 + 11.

..and a define for the 11 and a comment for the * 1.2

Right, I think definitions for the 11 and the 1.2 make sense in the include/linux/can/length.h anyway.

#5 lore raw
Quoted 51 lines · On 05.05.2023 08:21:36, [email protected] wrote:
Quoted 10 lines · On 05.05.2023 07:07:03, [email protected] wrote:
Quoted 6 lines
Quoted 2 lines

The datasheet "MCP25xxFD Family Reference Manual" says it needs an idle bus.

Technically what's needed is an idle condition on the bus as specified in the ISO. i.e. 11 consecutive sampled recessive bits after a full frame (if one is currently in transmission).

Right. What happens if another CAN frames comes before there are 11 consecutive sampled recessive bits? The IFS for CAN is 3 bits?

Not quite. Between the Frames is an IFS that's correct but the IFS consists of an Intermission which is 3 bits long + a bus idle condition of 11 bits. Regular frames have to wait for the IFS to elapse BUT there's an exception for error frames and overload frames. EF may be up to 12 bit, OF are 8 dominant + 8 recessive bits, browsing through the spec I think only 2 OFs can happen consecutively. Adding another 32 bits to the formula should cover this.

Quoted 32 lines
Quoted 16 lines
Quoted 16 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct

Quoted 12 lines

index 68df6d4641b5c..9908843798cef 100644

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
@@ -227,6 +227,7 @@ static int
 __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,
 			  const u8 mode_req, bool nowait)
 {
+	const struct can_bittiming *bt = &priv->can.bittiming;
 	u32 con = 0, con_reqop, osc = 0;
 	u8 mode;
 	int err;
@@ -251,7 +252,8 @@ __mcp251xfd_chip_set_mode(const struct

mcp251xfd_priv *priv,

Quoted 1 line
Quoted 8 lines
Quoted 8 lines

FIELD_GET(MCP251XFD_REG_CON_OPMOD_MASK,

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv, · line 256

Quoted 5 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +2 -1
 						 con) == mode_req,
 				       MCP251XFD_POLL_SLEEP_US,
-				       MCP251XFD_POLL_TIMEOUT_US);
+				       max(MCP251XFD_POLL_TIMEOUT_US,
+					   576 * USEC_PER_SEC / bt->bitrate));

Let's use CANFD_FRAME_LEN_MAX * BITS_PER_BYTE instead of 576. I can

fix

Quoted 6 lines
Quoted 2 lines

this while applying.

So, I'd suggest CANFD_FRAME_LEN_MAX * BITS_PER_BYTE + 11 + stuffbits, as far as I can tell the CANFD_FRAME_LEN_MAX ignores stuffbits, so as an overapproximation something like (CANFD_FRAME_LEN_MAX * BITS_PER_BYTE) * 1.2 + 11.

Quoted 4 lines
Quoted 2 lines

..and a define for the 11 and a comment for the * 1.2

Right, I think definitions for the 11 and the 1.2 make sense in the include/linux/can/length.h anyway.

Sounds good, make this a separate patch.

Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |
#6 lore raw
In reply to [email protected]
Quoted 12 lines
Quoted 2 lines · On 05.05.2023 07:07:03, [email protected] wrote:
Quoted 1 line
Quoted 1 line

The datasheet "MCP25xxFD Family Reference Manual" says it needs an

idle

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

bus.

Technically what's needed is an idle condition on the bus as specified in the ISO. i.e. 11 consecutive sampled recessive bits after a full frame (if one is currently in transmission).

Right. What happens if another CAN frames comes before there are 11 consecutive sampled recessive bits? The IFS for CAN is 3 bits?

Quoted 6 lines

Not quite. Between the Frames is an IFS that's correct but the IFS consists of an Intermission which is 3 bits long + a bus idle condition of 11 bits. Regular frames have to wait for the IFS to elapse BUT there's an exception for error frames and overload frames. EF may be up to 12 bit, OF are 8 dominant + 8 recessive bits, browsing through the spec I think only 2 OFs can happen consecutively. Adding another 32 bits to the formula should cover this.

Re-reading the spec again I noticed that the part where I wrote that there's an "idle condition" after the intermission is wrong. What follows the intermission is just "bus idle", defined two paragraphs later as "The period of bus idle may be of arbitrary length." The 11 recessive bits can be removed from the formula again. The longest period (under the assumption there aren't multiple/continuous errors on the bus) will be Frame + Error Frame (12 bit) + 2 x Overload Frame.

Quoted 32 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct

Quoted 12 lines

index 68df6d4641b5c..9908843798cef 100644

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
@@ -227,6 +227,7 @@ static int
 __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,
 			  const u8 mode_req, bool nowait)
 {
+	const struct can_bittiming *bt = &priv->can.bittiming;
 	u32 con = 0, con_reqop, osc = 0;
 	u8 mode;
 	int err;
@@ -251,7 +252,8 @@ __mcp251xfd_chip_set_mode(const struct

mcp251xfd_priv *priv,

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

FIELD_GET(MCP251XFD_REG_CON_OPMOD_MASK,

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c __mcp251xfd_chip_set_mode(const struct mcp251xfd_priv *priv,

Quoted 4 lines
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -1
 						 con) == mode_req,
 				       MCP251XFD_POLL_SLEEP_US,
-				       MCP251XFD_POLL_TIMEOUT_US);
+

max(MCP251XFD_POLL_TIMEOUT_US,

Quoted 4 lines
Quoted 1 line
Quoted 1 line

drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c

Quoted 1 line
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
+					   576 * USEC_PER_SEC / bt-

bitrate));

Quoted 2 lines
Quoted 2 lines

Let's use CANFD_FRAME_LEN_MAX * BITS_PER_BYTE instead of 576. I

can

Quoted 4 lines

fix

Quoted 3 lines
Quoted 2 lines

this while applying.

So, I'd suggest CANFD_FRAME_LEN_MAX * BITS_PER_BYTE + 11 +

stuffbits,

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

as far as I can tell the CANFD_FRAME_LEN_MAX ignores stuffbits, so as an overapproximation something like (CANFD_FRAME_LEN_MAX * BITS_PER_BYTE) * 1.2 + 11.

..and a define for the 11 and a comment for the * 1.2

Right, I think definitions for the 11 and the 1.2 make sense in the include/linux/can/length.h anyway.

Best Regards,
Thomas

#7 lore raw
Quoted 20 lines · On Wed. 10 May 2023 at 15:30, <[email protected]> wrote:
Quoted 13 lines
Quoted 3 lines · On 05.05.2023 07:07:03, [email protected] wrote:
Quoted 1 line
Quoted 1 line

The datasheet "MCP25xxFD Family Reference Manual" says it needs an

idle

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

bus.

Technically what's needed is an idle condition on the bus as specified in the ISO. i.e. 11 consecutive sampled recessive bits after a full frame (if one is currently in transmission).

Right. What happens if another CAN frames comes before there are 11 consecutive sampled recessive bits? The IFS for CAN is 3 bits?

Quoted 6 lines

Not quite. Between the Frames is an IFS that's correct but the IFS consists of an Intermission which is 3 bits long + a bus idle condition of 11 bits. Regular frames have to wait for the IFS to elapse BUT there's an exception for error frames and overload frames. EF may be up to 12 bit, OF are 8 dominant + 8 recessive bits, browsing through the spec I think only 2 OFs can happen consecutively. Adding another 32 bits to the formula should cover this.

Quoted 8 lines

Re-reading the spec again I noticed that the part where I wrote that there's an "idle condition" after the intermission is wrong. What follows the intermission is just "bus idle", defined two paragraphs later as "The period of bus idle may be of arbitrary length." The 11 recessive bits can be removed from the formula again. The longest period (under the assumption there aren't multiple/continuous errors on the bus) will be Frame + Error Frame (12 bit) + 2 x Overload Frame.

          ^^^^^^^^^^^^^^^^^^^^

How did you find that a error frame is 12 bits? From section 10.4.4 "Specification of EF", I can read:

The EF shall consist of two different fields. The first field shall be given by the superposition of error flags contributed from different nodes. The second field shall be the error delimiter.

Then:

Two forms of error flag may be used, the active error flag and the passive error flag, where

- the active error flag shall consist of 6 consecutive dominant bits, and

- the passive error flag shall consist of 6 consecutive recessive bits unless it is overwritten by dominant bits from other nodes.

Finally:

The error delimiter shall consist of 8 recessive bits.

So the error frame should be 14 bits (6 + 8), not 12, right?

For the great total, if you want the absolute worst case, you should consider that:

- The error frame may start at any point. For example, you may observe the first two bits of the intermission and have it broken by an error frame. It may also appear in the middle of a data frame. So you may consider cases such as: partial frame + error frame + intermission + frame + ...

- The overload frame is required to "destroy the fixed form of the intermission field". So even if not explicitly specified, I think that overload frame may start after the second recessive bits of the intermission, e.g. frame + 2 bits of intermission + overload frame + 2 bits of intermission + overload frame + full 3 bits intermission

- An error frame or an overload frame may trigger another error frame if a node does not correctly receive one of the bits in the fixed form delimiter. The only exception is the last bit of that delimiter (c.f. section 10.11 "Error detection" paragraph d) "Form error"). In other words, you can have the two overload frames, then an error frame, then two overload frames again.

This is to say that the worst case scenario is just not something worth consideration.

The assumption that only one error frame occurs is pretty arbitrary. I would suggest making it simpler and simply ignore error and overload frames. As long as frame + intermission works well in empirical tests, I would suggest to stay with that and call it a day.

#8 lore raw
Quoted 53 lines · On Wed. 10 May 2023 at 15:30, <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · On 05.05.2023 07:07:03, [email protected] wrote:
Quoted 1 line
Quoted 1 line

The datasheet "MCP25xxFD Family Reference Manual" says it needs

an

Quoted 11 lines
Quoted 11 lines

idle

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

bus.

Technically what's needed is an idle condition on the bus as specified in the ISO. i.e. 11 consecutive sampled recessive bits after a full frame (if one is currently in transmission).

Right. What happens if another CAN frames comes before there are 11 consecutive sampled recessive bits? The IFS for CAN is 3 bits?

Not quite. Between the Frames is an IFS that's correct but the IFS consists

of

Quoted 6 lines
Quoted 5 lines

an Intermission which is 3 bits long + a bus idle condition of 11 bits. Regular frames have to wait for the IFS to elapse BUT there's an exception for error frames and overload frames. EF may be up to 12 bit, OF are 8 dominant + 8 recessive bits, browsing through the spec I think only 2 OFs can happen consecutively. Adding another 32 bits to the formula should cover this.

Quoted 8 lines

Re-reading the spec again I noticed that the part where I wrote that there's an "idle condition" after the intermission is wrong. What follows the intermission is just "bus idle", defined two paragraphs later as "The period of bus idle may be of arbitrary length." The 11 recessive bits can be removed from the formula again. The longest period (under the assumption there aren't multiple/continuous errors on the bus) will be Frame + Error Frame (12 bit) + 2 x Overload Frame.

          ^^^^^^^^^^^^^^^^^^^^

How did you find that a error frame is 12 bits? From section 10.4.4 "Specification of EF", I can read:

The EF shall consist of two different fields. The first field shall be given by the superposition of error flags contributed from different nodes. The second field shall be the error delimiter.

Then:

Two forms of error flag may be used, the active error flag and the passive error flag, where

- the active error flag shall consist of 6 consecutive dominant bits, and

- the passive error flag shall consist of 6 consecutive recessive bits unless it is overwritten by dominant bits from other nodes.

Quoted 5 lines

Finally:

The error delimiter shall consist of 8 recessive bits.

So the error frame should be 14 bits (6 + 8), not 12, right?

That was imprecise, you're right - I meant an Error Flag, not Frame and hence the 8 recessive bits were missing. There's an active error flag + passive error flag though which can be 6 bits long each. In section 10.4.4.2 The total length of this sequence may vary between a minimum of 6 bit and a maximum of 12 bit.

Quoted 24 lines

For the great total, if you want the absolute worst case, you should consider that:

- The error frame may start at any point. For example, you may observe the first two bits of the intermission and have it broken by an error frame. It may also appear in the middle of a data frame. So you may consider cases such as: partial frame + error frame + intermission + frame + ...

- The overload frame is required to "destroy the fixed form of the intermission field". So even if not explicitly specified, I think that overload frame may start after the second recessive bits of the intermission, e.g. frame + 2 bits of intermission + overload frame + 2 bits of intermission + overload frame + full 3 bits intermission

- An error frame or an overload frame may trigger another error frame if a node does not correctly receive one of the bits in the fixed form delimiter. The only exception is the last bit of that delimiter (c.f. section 10.11 "Error detection" paragraph d) "Form error"). In other words, you can have the two overload frames, then an error frame, then two overload frames again.

Quoted 2 lines

This is to say that the worst case scenario is just not something worth consideration.

ACK

Quoted 4 lines

The assumption that only one error frame occurs is pretty arbitrary. I would suggest making it simpler and simply ignore error and overload frames. As long as frame + intermission works well in empirical tests, I would suggest to stay with that and call it a day.

Correct, that's why I wrote: (under the assumption there aren't multiple/continuous errors on the bus) but I agree that's a pretty arbitrary limit. So I'm fine with changing it to one or two full-sized frames + intermission)

Best Regards,
Thomas

#9 lore raw
Quoted 54 lines · Le mer. 10 mai 2023 à 18:18, <[email protected]> a écrit :
Quoted 54 lines · On Wed. 10 May 2023 at 15:30, <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · On 05.05.2023 07:07:03, [email protected] wrote:
Quoted 1 line
Quoted 1 line

The datasheet "MCP25xxFD Family Reference Manual" says it needs

an

Quoted 11 lines
Quoted 11 lines

idle

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

bus.

Technically what's needed is an idle condition on the bus as specified in the ISO. i.e. 11 consecutive sampled recessive bits after a full frame (if one is currently in transmission).

Right. What happens if another CAN frames comes before there are 11 consecutive sampled recessive bits? The IFS for CAN is 3 bits?

Not quite. Between the Frames is an IFS that's correct but the IFS consists

of

Quoted 6 lines
Quoted 5 lines

an Intermission which is 3 bits long + a bus idle condition of 11 bits. Regular frames have to wait for the IFS to elapse BUT there's an exception for error frames and overload frames. EF may be up to 12 bit, OF are 8 dominant + 8 recessive bits, browsing through the spec I think only 2 OFs can happen consecutively. Adding another 32 bits to the formula should cover this.

Quoted 8 lines

Re-reading the spec again I noticed that the part where I wrote that there's an "idle condition" after the intermission is wrong. What follows the intermission is just "bus idle", defined two paragraphs later as "The period of bus idle may be of arbitrary length." The 11 recessive bits can be removed from the formula again. The longest period (under the assumption there aren't multiple/continuous errors on the bus) will be Frame + Error Frame (12 bit) + 2 x Overload Frame.

          ^^^^^^^^^^^^^^^^^^^^

How did you find that a error frame is 12 bits? From section 10.4.4 "Specification of EF", I can read:

The EF shall consist of two different fields. The first field shall be given by the superposition of error flags contributed from different nodes. The second field shall be the error delimiter.

Then:

Two forms of error flag may be used, the active error flag and the passive error flag, where

- the active error flag shall consist of 6 consecutive dominant bits, and

- the passive error flag shall consist of 6 consecutive recessive bits unless it is overwritten by dominant bits from other nodes.

Quoted 6 lines
Quoted 5 lines

Finally:

The error delimiter shall consist of 8 recessive bits.

So the error frame should be 14 bits (6 + 8), not 12, right?

That was imprecise, you're right - I meant an Error Flag, not Frame and hence the 8 recessive bits were missing. There's an active error flag + passive error flag though which can be 6 bits long each. In section 10.4.4.2 The total length of this sequence may vary between a minimum of 6 bit and a maximum of 12 bit.

The active error flag and the passive error flag may both occur, but in that case, they occur as a superposition (c.f. above quotation). This also means that the passive error flag is seen if and only if all the nodes send a passive error flag. As long as one node sends an active error flag, the superposition will hide any other passive error flag.

So, I think that the error flag is always 6.

Quoted 16 lines
Quoted 16 lines

For the great total, if you want the absolute worst case, you should consider that:

- The error frame may start at any point. For example, you may observe the first two bits of the intermission and have it broken by an error frame. It may also appear in the middle of a data frame. So you may consider cases such as: partial frame + error frame + intermission + frame + ...

- The overload frame is required to "destroy the fixed form of the intermission field". So even if not explicitly specified, I think that overload frame may start after the second recessive bits of the intermission, e.g. frame + 2 bits of intermission + overload frame + 2 bits of intermission + overload frame + full 3 bits intermission

Quoted 7 lines
Quoted 7 lines

- An error frame or an overload frame may trigger another error frame if a node does not correctly receive one of the bits in the fixed form delimiter. The only exception is the last bit of that delimiter (c.f. section 10.11 "Error detection" paragraph d) "Form error"). In other words, you can have the two overload frames, then an error frame, then two overload frames again.

Correcting myself: that last example was invalid. There are at maximum two overload frames before the next data or remote frame. So the presence of an error frame should not reset the overload frame count.

Quoted 10 lines
Quoted 2 lines

This is to say that the worst case scenario is just not something worth consideration.

ACK

Quoted 4 lines

The assumption that only one error frame occurs is pretty arbitrary. I would suggest making it simpler and simply ignore error and overload frames. As long as frame + intermission works well in empirical tests, I would suggest to stay with that and call it a day.

Correct, that's why I wrote: (under the assumption there aren't multiple/continuous errors on the bus) but I agree that's a pretty arbitrary limit. So I'm fine with changing it to one or two full-sized frames + intermission)

ACK. At the end, you have the hardware, so you should decide what is the best delay to fix the issue. I just hope that my message was helpful to simplify the formula.

Quoted 2 lines

Best Regards,
Thomas

#10 lore raw
Quoted 65 lines
Quoted 9 lines
Quoted 9 lines

an

Quoted 8 lines
Quoted 8 lines

idle

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

bus.

Technically what's needed is an idle condition on the bus as specified in the ISO. i.e. 11 consecutive sampled recessive bits after a full frame (if one is currently in transmission).

Right. What happens if another CAN frames comes before there are

11

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

consecutive sampled recessive bits? The IFS for CAN is 3 bits?

Not quite. Between the Frames is an IFS that's correct but the IFS

consists

Quoted 2 lines
Quoted 2 lines

of

Quoted 1 line
Quoted 1 line

an Intermission which is 3 bits long + a bus idle condition of 11 bits.

Regular

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

frames have to wait for the IFS to elapse BUT there's an exception for

error

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

frames and overload frames. EF may be up to 12 bit, OF are 8 dominant

+ 8

Quoted 33 lines
Quoted 33 lines
Quoted 11 lines
Quoted 2 lines

recessive bits, browsing through the spec I think only 2 OFs can happen consecutively. Adding another 32 bits to the formula should cover this.

Re-reading the spec again I noticed that the part where I wrote that there's an "idle condition" after the intermission is wrong. What follows the intermission is just "bus idle", defined two paragraphs later as "The period of bus idle may be of arbitrary length." The 11 recessive bits can be removed from the formula again. The longest period (under the assumption there aren't multiple/continuous errors on the bus) will be Frame + Error Frame (12 bit) + 2 x Overload Frame.

          ^^^^^^^^^^^^^^^^^^^^

How did you find that a error frame is 12 bits? From section 10.4.4 "Specification of EF", I can read:

The EF shall consist of two different fields. The first field shall be given by the superposition of error flags contributed from different nodes. The second field shall be the error delimiter.

Then:

Two forms of error flag may be used, the active error flag and the passive error flag, where

- the active error flag shall consist of 6 consecutive dominant bits, and

- the passive error flag shall consist of 6 consecutive recessive bits unless it is overwritten by dominant bits from other nodes.

Quoted 6 lines
Quoted 5 lines

Finally:

The error delimiter shall consist of 8 recessive bits.

So the error frame should be 14 bits (6 + 8), not 12, right?

That was imprecise, you're right - I meant an Error Flag, not Frame and hence

the 8 recessive bits were missing. There's an active error flag + passive error flag though which can be 6 bits long each. In section 10.4.4.2 The total length of this sequence may vary between a minimum of 6 bit and a maximum of 12 bit.

Quoted 8 lines

The active error flag and the passive error flag may both occur, but in that case, they occur as a superposition (c.f. above quotation). This also means that the passive error flag is seen if and only if all the nodes send a passive error flag. As long as one node sends an active error flag, the superposition will hide any other passive error flag.

So, I think that the error flag is always 6.

I think if one node detects a bit error (that's not on the bus but inside the receiving node) on the second bit of the intermission it will start sending the 6 dominant bits, starting on the third bit of the intermission. Now, according to 10.4.2.2 " A node sampling a dominant bit during its suspend transmission time or at the third bit of intermission shall accept it as SOF.", treating the next 5 dominant bits as part of the ID of a new DF and only then sending its own error flag, giving a total of 12 dominant bits followed by 8 recessive bits EF delimiter etc. Am I missing something here? For this (I believe worst case when only considering 1 EF you could deduct one bittime - the third bit in the intermission)

Quoted 37 lines
Quoted 16 lines
Quoted 16 lines

For the great total, if you want the absolute worst case, you should consider that:

- The error frame may start at any point. For example, you may observe the first two bits of the intermission and have it broken by an error frame. It may also appear in the middle of a data frame. So you may consider cases such as: partial frame + error frame + intermission + frame + ...

- The overload frame is required to "destroy the fixed form of the intermission field". So even if not explicitly specified, I think that overload frame may start after the second recessive bits of the intermission, e.g. frame + 2 bits of intermission + overload frame + 2 bits of intermission + overload frame + full 3 bits intermission

Quoted 7 lines
Quoted 7 lines

- An error frame or an overload frame may trigger another error frame if a node does not correctly receive one of the bits in the fixed form delimiter. The only exception is the last bit of that delimiter (c.f. section 10.11 "Error detection" paragraph d) "Form error"). In other words, you can have the two overload frames, then an error frame, then two overload frames again.

Correcting myself: that last example was invalid. There are at maximum two overload frames before the next data or remote frame. So the presence of an error frame should not reset the overload frame count.

Quoted 9 lines
Quoted 2 lines

This is to say that the worst case scenario is just not something worth consideration.

ACK

Quoted 4 lines

The assumption that only one error frame occurs is pretty arbitrary. I would suggest making it simpler and simply ignore error and overload frames. As long as frame + intermission works well in empirical tests, I would suggest to stay with that and call it a day.

Quoted 8 lines
Quoted 1 line

Correct, that's why I wrote: (under the assumption there aren't

multiple/continuous errors on the bus) but I agree that's a pretty arbitrary limit. So I'm fine with changing it to one or two full-sized frames + intermission)

ACK. At the end, you have the hardware, so you should decide what is the best delay to fix the issue. I just hope that my message was helpful to simplify the formula.

I agree a simple formula will be the best way forward as the rest is academic only anyway.

Best Regards,
Thomas

#11 lore raw
Quoted 41 lines · On Wed. 10 May 2023 at 19:39, <[email protected]> wrote:
Quoted 41 lines
Quoted 30 lines
Quoted 30 lines
Quoted 8 lines

Re-reading the spec again I noticed that the part where I wrote that there's an "idle condition" after the intermission is wrong. What follows the intermission is just "bus idle", defined two paragraphs later as "The period of bus idle may be of arbitrary length." The 11 recessive bits can be removed from the formula again. The longest period (under the assumption there aren't multiple/continuous errors on the bus) will be Frame + Error Frame (12 bit) + 2 x Overload Frame.

          ^^^^^^^^^^^^^^^^^^^^

How did you find that a error frame is 12 bits? From section 10.4.4 "Specification of EF", I can read:

The EF shall consist of two different fields. The first field shall be given by the superposition of error flags contributed from different nodes. The second field shall be the error delimiter.

Then:

Two forms of error flag may be used, the active error flag and the passive error flag, where

- the active error flag shall consist of 6 consecutive dominant bits, and

- the passive error flag shall consist of 6 consecutive recessive bits unless it is overwritten by dominant bits from other nodes.

Quoted 6 lines
Quoted 5 lines

Finally:

The error delimiter shall consist of 8 recessive bits.

So the error frame should be 14 bits (6 + 8), not 12, right?

That was imprecise, you're right - I meant an Error Flag, not Frame and hence

the 8 recessive bits were missing. There's an active error flag + passive error flag though which can be 6 bits long each. In section 10.4.4.2 The total length of this sequence may vary between a minimum of 6 bit and a maximum of 12 bit.

Quoted 8 lines
Quoted 8 lines

The active error flag and the passive error flag may both occur, but in that case, they occur as a superposition (c.f. above quotation). This also means that the passive error flag is seen if and only if all the nodes send a passive error flag. As long as one node sends an active error flag, the superposition will hide any other passive error flag.

So, I think that the error flag is always 6.

Actually, you were right on the total but not on the reasoning (active error flag + passive error flag 6 bits long each). The error flags are actually between 6 and 12 bits but not because of consecutive active and passive error flags. Even if the field is a superposition of error flags, the nodes do not necessarily start to transmit their error flag simultaneously on the same bit. The worst case is when node A sends an error flag, then node B detects the error condition on the last bit of A's error flag (bit #6). In that case, B starts to transmit his error flag after A's error flag is completed (bit #7) and B finishes sending its error frame on bit #12, thus the total of 6 + 6 = 12. But these may very well be all dominant bits!

Quoted 1 line

I think if one node detects a bit error (that's not on the bus but inside the receiving node) on the second bit of the intermission it will start sending the 6 dominant bits, starting on the third bit of the intermission. Now, according to 10.4.2.2 " A node sampling a dominant bit during its suspend transmission time or at the third bit of intermission shall accept it as SOF.", treating the next 5 dominant bits as part of the ID of a new DF and only then sending its own error flag, giving a total of 12 dominant bits followed by 8 recessive bits EF delimiter etc. Am I missing something here? For this (I believe worst case when only considering 1 EF you could deduct one bittime - the third bit in the intermission)

If a node detects a bit error on the second bit of the intermission, it means that it was expecting a recessive bit and measured a dominant one. Thus, it should interpret it as the beginning of an overload flag. Consequently, on the third bit of the intermission, that faulty node starts to emit an overload flag and according to paragraph 10.4.5.2, all the other nodes shall also start sending an overload flag.
In fact, we could nearly say that an overload frame is an error frame sent during intermission. 10.4.6.2 "Intermission" clarifies this saying that:

During the intermission [...] only signalling of overload condition
is allowed.

The disambiguation between error and overload can be done only because both can not coexist at the same time!

ISO 11898-1 is such a rabbit hole... sights...

#12 lore raw

On 10.05.2023 20:19:38, Vincent Mailhol wrote:
[...]

Quoted 1 line

ISO 11898-1 is such a rabbit hole... sights...

How do we proceed?

I like Marek's approach of defining the delay first in the driver and then moving it to a common header in the second patch to facilitate backporting.

Do we agree on the maximum number of bits to wait in the worst case?

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |
#13 lore raw
Quoted 11 lines · Marc Kleine-Budde

On 10.05.2023 20:19:38, Vincent Mailhol wrote:
[...]

Quoted 1 line

ISO 11898-1 is such a rabbit hole... sights...

How do we proceed?

I like Marek's approach of defining the delay first in the driver and then moving it to a common header in the second patch to facilitate backporting.

Do we agree on the maximum number of bits to wait in the worst case?

Is any further change expected from me to this patch ?