From: Jacob Keller <jacob.e.keller@intel.com>
To: Marc Kleine-Budde <mkl@pengutronix.de>, <netdev@vger.kernel.org>
Cc: <davem@davemloft.net>, <kuba@kernel.org>,
<linux-can@vger.kernel.org>, <kernel@pengutronix.de>,
Kelsey Maes <kelsey@vpprocess.com>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Subject: Re: [PATCH net 2/6] can: mcp251xfd: fix TDC setting for low data bit rates
Date: Tue, 6 May 2025 11:27:45 -0700 [thread overview]
Message-ID: <2f4e07d9-36c6-43ce-bfa8-3272598d7d43@intel.com> (raw)
In-Reply-To: <20250506135939.652543-3-mkl@pengutronix.de>
On 5/6/2025 6:56 AM, Marc Kleine-Budde wrote:
> From: Kelsey Maes <kelsey@vpprocess.com>
>
> The TDC is currently hardcoded enabled. This means that even for lower
> CAN-FD data bitrates (with a DBRP (data bitrate prescaler) > 2) a TDC
> is configured. This leads to a bus-off condition.
>
> ISO 11898-1 section 11.3.3 says "Transmitter delay compensation" (TDC)
> is only applicable if DBRP is 1 or 2.
>
> To fix the problem, switch the driver to use the TDC calculation
> provided by the CAN driver framework (which respects ISO 11898-1
> section 11.3.3). This has the positive side effect that userspace can
> control TDC as needed.
>
> Demonstration of the feature in action:
> | $ ip link set can0 up type can bitrate 125000 dbitrate 500000 fd on
> | $ ip -details link show can0
> | 3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
> | link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
> | can <FD> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
> | bitrate 125000 sample-point 0.875
> | tq 50 prop-seg 69 phase-seg1 70 phase-seg2 20 sjw 10 brp 2
> | mcp251xfd: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..256 brp_inc 1
> | dbitrate 500000 dsample-point 0.875
> | dtq 125 dprop-seg 6 dphase-seg1 7 dphase-seg2 2 dsjw 1 dbrp 5
> | mcp251xfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp_inc 1
> | tdcv 0..63 tdco 0..63
> | clock 40000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus spi parentdev spi0.0
> | $ ip link set can0 up type can bitrate 1000000 dbitrate 4000000 fd on
> | $ ip -details link show can0
> | 3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
> | link/can promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
> | can <FD,TDC-AUTO> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
> | bitrate 1000000 sample-point 0.750
> | tq 25 prop-seg 14 phase-seg1 15 phase-seg2 10 sjw 5 brp 1
> | mcp251xfd: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..256 brp_inc 1
> | dbitrate 4000000 dsample-point 0.700
> | dtq 25 dprop-seg 3 dphase-seg1 3 dphase-seg2 3 dsjw 1 dbrp 1
> | tdco 7
> | mcp251xfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp_inc 1
> | tdcv 0..63 tdco 0..63
> | clock 40000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 parentbus spi parentdev spi0.0
>
> There has been some confusion about the MCP2518FD using a relative or
> absolute TDCO due to the datasheet specifying a range of [-64,63]. I
> have a custom board with a 40 MHz clock and an estimated loop delay of
> 100 to 216 ns. During testing at a data bit rate of 4 Mbit/s I found
> that using can_get_relative_tdco() resulted in bus-off errors. The
> final TDCO value was 1 which corresponds to a 10% SSP in an absolute
> configuration. This behavior is expected if the TDCO value is really
> absolute and not relative. Using priv->can.tdc.tdco instead results in
> a final TDCO of 8, setting the SSP at exactly 80%. This configuration
> works.
>
> The automatic, manual, and off TDC modes were tested at speeds up to,
> and including, 8 Mbit/s on real hardware and behave as expected.
>
> Fixes: 55e5b97f003e ("can: mcp25xxfd: add driver for Microchip MCP25xxFD SPI CAN")
> Reported-by: Kelsey Maes <kelsey@vpprocess.com>
> Closes: https://lore.kernel.org/all/C2121586-C87F-4B23-A933-845362C29CA1@vpprocess.com
> Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
> Signed-off-by: Kelsey Maes <kelsey@vpprocess.com>
> Link: https://patch.msgid.link/20250430161501.79370-1-kelsey@vpprocess.com
> [mkl: add comment]
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
next prev parent reply other threads:[~2025-05-06 18:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 13:56 [PATCH net 0/6] pull-request: can 2025-05-06 Marc Kleine-Budde
2025-05-06 13:56 ` [PATCH net 1/6] can: m_can: m_can_class_allocate_dev(): initialize spin lock on device probe Marc Kleine-Budde
2025-05-06 18:25 ` Jacob Keller
2025-05-07 2:10 ` patchwork-bot+netdevbpf
2025-05-06 13:56 ` [PATCH net 2/6] can: mcp251xfd: fix TDC setting for low data bit rates Marc Kleine-Budde
2025-05-06 18:27 ` Jacob Keller [this message]
2025-05-06 13:56 ` [PATCH net 3/6] can: mcp251xfd: mcp251xfd_remove(): fix order of unregistration calls Marc Kleine-Budde
2025-05-06 18:28 ` Jacob Keller
2025-05-06 13:56 ` [PATCH net 4/6] can: rockchip_canfd: rkcanfd_remove(): " Marc Kleine-Budde
2025-05-06 18:29 ` Jacob Keller
2025-05-06 13:56 ` [PATCH net 5/6] can: mcan: m_can_class_unregister(): " Marc Kleine-Budde
2025-05-06 18:29 ` Jacob Keller
2025-05-06 13:56 ` [PATCH net 6/6] can: gw: fix RCU/BH usage in cgw_create_job() Marc Kleine-Budde
2025-05-06 18:31 ` Jacob Keller
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=2f4e07d9-36c6-43ce-bfa8-3272598d7d43@intel.com \
--to=jacob.e.keller@intel.com \
--cc=davem@davemloft.net \
--cc=kelsey@vpprocess.com \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--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