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, Srinivas Neeli <srinivas.neeli@xilinx.com>,
	Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net-next 01/22] can: xilinx_can: add Transmitter Delay Compensation (TDC) feature support
Date: Sat, 25 Jun 2022 14:03:14 +0200	[thread overview]
Message-ID: <20220625120335.324697-2-mkl@pengutronix.de> (raw)
In-Reply-To: <20220625120335.324697-1-mkl@pengutronix.de>

From: Srinivas Neeli <srinivas.neeli@xilinx.com>

This patch adds Transmitter Delay Compensation (TDC) feature support.

In the case of higher measured loop delay with higher bit rates, bit
stuff errors are observed. Enabling the TDC feature in CAN-FD
controllers will compensate for the measured loop delay in the receive
path.

Link: https://lore.kernel.org/all/20220609103157.1425730-1-srinivas.neeli@xilinx.com
Signed-off-by: Srinivas Neeli <srinivas.neeli@xilinx.com>
Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
[mkl: fix indention]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/xilinx_can.c | 66 +++++++++++++++++++++++++++++++++---
 1 file changed, 61 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 8a3b7b103ca4..70dcb45078bf 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /* Xilinx CAN device driver
  *
- * Copyright (C) 2012 - 2014 Xilinx, Inc.
+ * Copyright (C) 2012 - 2022 Xilinx, Inc.
  * Copyright (C) 2009 PetaLogix. All rights reserved.
  * Copyright (C) 2017 - 2018 Sandvik Mining and Construction Oy
  *
@@ -9,6 +9,7 @@
  * This driver is developed for Axi CAN IP and for Zynq CANPS Controller.
  */
 
+#include <linux/bitfield.h>
 #include <linux/clk.h>
 #include <linux/errno.h>
 #include <linux/init.h>
@@ -86,6 +87,8 @@ enum xcan_reg {
 #define XCAN_MSR_LBACK_MASK		0x00000002 /* Loop back mode select */
 #define XCAN_MSR_SLEEP_MASK		0x00000001 /* Sleep mode select */
 #define XCAN_BRPR_BRP_MASK		0x000000FF /* Baud rate prescaler */
+#define XCAN_BRPR_TDCO_MASK		GENMASK(12, 8)  /* TDCO */
+#define XCAN_2_BRPR_TDCO_MASK		GENMASK(13, 8)  /* TDCO for CANFD 2.0 */
 #define XCAN_BTR_SJW_MASK		0x00000180 /* Synchronous jump width */
 #define XCAN_BTR_TS2_MASK		0x00000070 /* Time segment 2 */
 #define XCAN_BTR_TS1_MASK		0x0000000F /* Time segment 1 */
@@ -99,6 +102,7 @@ enum xcan_reg {
 #define XCAN_ESR_STER_MASK		0x00000004 /* Stuff error */
 #define XCAN_ESR_FMER_MASK		0x00000002 /* Form error */
 #define XCAN_ESR_CRCER_MASK		0x00000001 /* CRC error */
+#define XCAN_SR_TDCV_MASK		GENMASK(22, 16) /* TDCV Value */
 #define XCAN_SR_TXFLL_MASK		0x00000400 /* TX FIFO is full */
 #define XCAN_SR_ESTAT_MASK		0x00000180 /* Error status */
 #define XCAN_SR_ERRWRN_MASK		0x00000040 /* Error warning */
@@ -132,6 +136,7 @@ enum xcan_reg {
 #define XCAN_DLCR_BRS_MASK		0x04000000 /* BRS Mask in DLC */
 
 /* CAN register bit shift - XCAN_<REG>_<BIT>_SHIFT */
+#define XCAN_BRPR_TDC_ENABLE		BIT(16) /* Transmitter Delay Compensation (TDC) Enable */
 #define XCAN_BTR_SJW_SHIFT		7  /* Synchronous jump width */
 #define XCAN_BTR_TS2_SHIFT		4  /* Time segment 2 */
 #define XCAN_BTR_SJW_SHIFT_CANFD	16 /* Synchronous jump width */
@@ -276,6 +281,26 @@ static const struct can_bittiming_const xcan_data_bittiming_const_canfd2 = {
 	.brp_inc = 1,
 };
 
+/* Transmission Delay Compensation constants for CANFD 1.0 */
+static const struct can_tdc_const xcan_tdc_const_canfd = {
+	.tdcv_min = 0,
+	.tdcv_max = 0, /* Manual mode not supported. */
+	.tdco_min = 0,
+	.tdco_max = 32,
+	.tdcf_min = 0, /* Filter window not supported */
+	.tdcf_max = 0,
+};
+
+/* Transmission Delay Compensation constants for CANFD 2.0 */
+static const struct can_tdc_const xcan_tdc_const_canfd2 = {
+	.tdcv_min = 0,
+	.tdcv_max = 0, /* Manual mode not supported. */
+	.tdco_min = 0,
+	.tdco_max = 64,
+	.tdcf_min = 0, /* Filter window not supported */
+	.tdcf_max = 0,
+};
+
 /**
  * xcan_write_reg_le - Write a value to the device register little endian
  * @priv:	Driver private data structure
@@ -424,6 +449,14 @@ static int xcan_set_bittiming(struct net_device *ndev)
 	    priv->devtype.cantype == XAXI_CANFD_2_0) {
 		/* Setting Baud Rate prescalar value in F_BRPR Register */
 		btr0 = dbt->brp - 1;
+		if (can_tdc_is_enabled(&priv->can)) {
+			if (priv->devtype.cantype == XAXI_CANFD)
+				btr0 |= FIELD_PREP(XCAN_BRPR_TDCO_MASK, priv->can.tdc.tdco) |
+					XCAN_BRPR_TDC_ENABLE;
+			else
+				btr0 |= FIELD_PREP(XCAN_2_BRPR_TDCO_MASK, priv->can.tdc.tdco) |
+					XCAN_BRPR_TDC_ENABLE;
+		}
 
 		/* Setting Time Segment 1 in BTR Register */
 		btr1 = dbt->prop_seg + dbt->phase_seg1 - 1;
@@ -1483,6 +1516,22 @@ static int xcan_get_berr_counter(const struct net_device *ndev,
 	return 0;
 }
 
+/**
+ * xcan_get_auto_tdcv - Get Transmitter Delay Compensation Value
+ * @ndev:	Pointer to net_device structure
+ * @tdcv:	Pointer to TDCV value
+ *
+ * Return: 0 on success
+ */
+static int xcan_get_auto_tdcv(const struct net_device *ndev, u32 *tdcv)
+{
+	struct xcan_priv *priv = netdev_priv(ndev);
+
+	*tdcv = FIELD_GET(XCAN_SR_TDCV_MASK, priv->read_reg(priv, XCAN_SR_OFFSET));
+
+	return 0;
+}
+
 static const struct net_device_ops xcan_netdev_ops = {
 	.ndo_open	= xcan_open,
 	.ndo_stop	= xcan_close,
@@ -1735,17 +1784,24 @@ static int xcan_probe(struct platform_device *pdev)
 	priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
 					CAN_CTRLMODE_BERR_REPORTING;
 
-	if (devtype->cantype == XAXI_CANFD)
+	if (devtype->cantype == XAXI_CANFD) {
 		priv->can.data_bittiming_const =
 			&xcan_data_bittiming_const_canfd;
+		priv->can.tdc_const = &xcan_tdc_const_canfd;
+	}
 
-	if (devtype->cantype == XAXI_CANFD_2_0)
+	if (devtype->cantype == XAXI_CANFD_2_0) {
 		priv->can.data_bittiming_const =
 			&xcan_data_bittiming_const_canfd2;
+		priv->can.tdc_const = &xcan_tdc_const_canfd2;
+	}
 
 	if (devtype->cantype == XAXI_CANFD ||
-	    devtype->cantype == XAXI_CANFD_2_0)
-		priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD;
+	    devtype->cantype == XAXI_CANFD_2_0) {
+		priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD |
+						CAN_CTRLMODE_TDC_AUTO;
+		priv->can.do_get_auto_tdcv = xcan_get_auto_tdcv;
+	}
 
 	priv->reg_base = addr;
 	priv->tx_max = tx_max;

base-commit: 27f2533bcc6e909b85d3c1b738fa1f203ed8a835
-- 
2.35.1



  reply	other threads:[~2022-06-25 12:06 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-25 12:03 [PATCH net-next 0/22] pull-request: can-next 2022-06-25 Marc Kleine-Budde
2022-06-25 12:03 ` Marc Kleine-Budde [this message]
2022-06-27 11:00   ` [PATCH net-next 01/22] can: xilinx_can: add Transmitter Delay Compensation (TDC) feature support patchwork-bot+netdevbpf
2022-06-25 12:03 ` [PATCH net-next 02/22] can: xilinx_can: fix typo prescalar -> prescaler Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 03/22] can: m_can: " Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 04/22] can: netlink: allow configuring of fixed bit rates without need for do_set_bittiming callback Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 05/22] can: Kconfig: rename config symbol CAN_DEV into CAN_NETLINK Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 06/22] can: Kconfig: turn menu "CAN Device Drivers" into a menuconfig using CAN_DEV Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 07/22] can: bittiming: move bittiming calculation functions to calc_bittiming.c Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 08/22] can: Kconfig: add CONFIG_CAN_RX_OFFLOAD Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 09/22] net: Kconfig: move the CAN device menu to the "Device Drivers" section Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 10/22] can: skb: move can_dropped_invalid_skb() and can_skb_headroom_valid() to skb.c Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 11/22] can: skb: drop tx skb if in listen only mode Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 12/22] can: Break loopback loop on loopback documentation Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 13/22] can: etas_es58x: replace es58x_device::rx_max_packet_size by usb_maxpacket() Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 14/22] can: etas_es58x: fix signedness of USB RX and TX pipes Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 15/22] dt-bindings: can: mpfs: document the mpfs CAN controller Marc Kleine-Budde
2022-06-27 11:05   ` Conor.Dooley
2022-06-25 12:03 ` [PATCH net-next 16/22] riscv: dts: microchip: add mpfs's CAN controllers Marc Kleine-Budde
2022-06-27  7:12   ` Conor.Dooley
2022-06-27  7:30     ` Marc Kleine-Budde
2022-06-27 11:17       ` Conor.Dooley
2022-06-27 11:17         ` Conor.Dooley
2022-06-27 11:23         ` Marc Kleine-Budde
2022-06-27 11:23           ` Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 17/22] can: netlink: allow configuring of fixed data bit rates without need for do_set_data_bittiming callback Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 18/22] can/esd_usb2: Rename esd_usb2.c to esd_usb.c Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 19/22] can/esd_usb: Add an entry to the MAINTAINERS file Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 20/22] can/esd_usb: Rename all terms USB2 to USB Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 21/22] can/esd_usb: Fixed some checkpatch.pl warnings Marc Kleine-Budde
2022-06-25 12:03 ` [PATCH net-next 22/22] can/esd_usb: Update to copyright, M_AUTHOR and M_DESCRIPTION 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=20220625120335.324697-2-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=mailhol.vincent@wanadoo.fr \
    --cc=netdev@vger.kernel.org \
    --cc=srinivas.neeli@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.