All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
	kernel@pengutronix.de, Marc Kleine-Budde <mkl@pengutronix.de>,
	Srinivas Neeli <sneeli@xilinx.com>
Subject: [PATCH net-next 02/17] can: bittiming: can_calc_bittiming(): prefer small bit rate pre-scalers over larger ones
Date: Tue, 19 Apr 2022 17:25:39 +0200	[thread overview]
Message-ID: <20220419152554.2925353-3-mkl@pengutronix.de> (raw)
In-Reply-To: <20220419152554.2925353-1-mkl@pengutronix.de>

The CiA (CAN in Automation) lists in their Newsletter 1/2018 in the
"Recommendation for the CAN FD bit-timing" [1] article several
recommendations, one of them is:

| Recommendation 3: Choose BRPA and BRPD as low as possible

[1] https://can-newsletter.org/uploads/media/raw/f6a36d1461371a2f86ef0011a513712c.pdf

With the current bit timing algorithm Srinivas Neeli noticed that on
the Xilinx Versal ACAP board the CAN data bit timing parameters are
not calculated optimally. For most bit rates, the bit rate
prescaler (BRP) is != 1, although it's possible to configure the
requested with a bit rate with a prescaler of 1:

| Data Bit timing parameters for xilinx_can_fd2i with 79.999999 MHz ref clock (cmd-line) using algo 'v4.8'
|  nominal                                  real  Bitrt    nom   real  SampP
|  Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP  Bitrate  Error  SampP  SampP  Error
| 12000000     12   2    2    2   1   1 11428571   4.8%  75.0%  71.4%   4.8%
| 10000000     25   1    1    1   1   2  9999999   0.0%  75.0%  75.0%   0.0%
|  8000000     12   3    3    3   1   1  7999999   0.0%  75.0%  70.0%   6.7%
|  5000000     50   1    1    1   1   4  4999999   0.0%  75.0%  75.0%   0.0%
|  4000000     62   1    1    1   1   5  3999999   0.0%  75.0%  75.0%   0.0%
|  2000000    125   1    1    1   1  10  1999999   0.0%  75.0%  75.0%   0.0%
|  1000000    250   1    1    1   1  20   999999   0.0%  75.0%  75.0%   0.0%

The bit timing parameter calculation algorithm iterates effectively
from low to high BRP values. It selects a new best parameter set, if
the sample point error of the current parameter set is equal or less
to old best parameter set.

If the given hardware constraints (clock rate and bit timing parameter
constants) don't allow a sample point error of 0, the algorithm will
first find a valid bit timing parameter set with a low BRP, but then
will accept parameter sets with higher BRPs that have the same sample
point error.

This patch changes the algorithm to only accept a new parameter set,
if the resulting sample point error is lower. This leads to the
following data bit timing parameter for the Versal ACAP board:

| Data Bit timing parameters for xilinx_can_fd2i with 79.999999 MHz ref clock (cmd-line) using algo 'can-next'
|  nominal                                  real  Bitrt    nom   real  SampP
|  Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP  Bitrate  Error  SampP  SampP  Error
| 12000000     12   2    2    2   1   1 11428571   4.8%  75.0%  71.4%   4.8%
| 10000000     12   2    3    2   1   1  9999999   0.0%  75.0%  75.0%   0.0%
|  8000000     12   3    3    3   1   1  7999999   0.0%  75.0%  70.0%   6.7%
|  5000000     12   5    6    4   1   1  4999999   0.0%  75.0%  75.0%   0.0%
|  4000000     12   7    7    5   1   1  3999999   0.0%  75.0%  75.0%   0.0%
|  2000000     12  14   15   10   1   1  1999999   0.0%  75.0%  75.0%   0.0%
|  1000000     25  14   15   10   1   2   999999   0.0%  75.0%  75.0%   0.0%

Note: Due to HW constraints a data bit rate of 1 MBit/s with BRP = 1 is not possible.

Link: https://lore.kernel.org/all/20220318144913.873614-1-mkl@pengutronix.de
Link: https://lore.kernel.org/all/20220113203004.jf2rqj2pirhgx72i@pengutronix.de
Cc: Srinivas Neeli <sneeli@xilinx.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/dev/bittiming.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/dev/bittiming.c b/drivers/net/can/dev/bittiming.c
index 2103bcca9012..c1e76f0a5064 100644
--- a/drivers/net/can/dev/bittiming.c
+++ b/drivers/net/can/dev/bittiming.c
@@ -116,7 +116,7 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
 
 		can_update_sample_point(btc, sample_point_nominal, tseg / 2,
 					&tseg1, &tseg2, &sample_point_error);
-		if (sample_point_error > best_sample_point_error)
+		if (sample_point_error >= best_sample_point_error)
 			continue;
 
 		best_sample_point_error = sample_point_error;
-- 
2.35.1



  parent reply	other threads:[~2022-04-19 15:26 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19 15:25 [PATCH net-next 0/17] pull-request: can-next 2022-04-19 Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 01/17] can: rx-offload: rename can_rx_offload_queue_sorted() -> can_rx_offload_queue_timestamp() Marc Kleine-Budde
2022-04-20 10:30   ` patchwork-bot+netdevbpf
2022-04-19 15:25 ` Marc Kleine-Budde [this message]
2022-04-19 15:25 ` [PATCH net-next 03/17] can: Fix Links to Technologic Systems web resources Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 04/17] can: mscan: mpc5xxx_can: Prepare cleanup of powerpc's asm/prom.h Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 05/17] can: flexcan: using pm_runtime_resume_and_get instead of pm_runtime_get_sync Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 06/17] MAINTAINERS: rectify entry for XILINX CAN DRIVER Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 07/17] can: xilinx_can: mark bit timing constants as const Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 08/17] dt-bindings: can: renesas,rcar-canfd: document r8a77961 support Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 09/17] dt-binding: can: mcp251xfd: add binding information for mcp251863 Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 10/17] can: mcp251xfd: add support " Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 11/17] dt-bindings: vendor-prefix: add prefix for the Czech Technical University in Prague Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 12/17] dt-bindings: net: can: binding for CTU CAN FD open-source IP core Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 13/17] can: ctucanfd: add support for CTU CAN FD open-source IP core - bus independent part Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 14/17] can: ctucanfd: CTU CAN FD open-source IP core - PCI bus support Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 15/17] can: ctucanfd: CTU CAN FD open-source IP core - platform/SoC support Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 16/17] docs: ctucanfd: CTU CAN FD open-source IP core documentation Marc Kleine-Budde
2022-04-19 15:25 ` [PATCH net-next 17/17] MAINTAINERS: Add maintainers for CTU CAN FD IP core driver Marc Kleine-Budde

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=20220419152554.2925353-3-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sneeli@xilinx.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.