linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* SJA1000 loopback feature
@ 2014-06-16 16:20 Nikita Edward Baruzdin
  2014-06-16 18:56 ` Oliver Hartkopp
  0 siblings, 1 reply; 11+ messages in thread
From: Nikita Edward Baruzdin @ 2014-06-16 16:20 UTC (permalink / raw)
  To: linux-can

[-- Attachment #1: Type: text/plain, Size: 1868 bytes --]

Hello.

We have several logical units working on the same CAN interface of a
SJA1000-based CAN controller. We need them to communicate with each other even
in a situation of one physical node on the bus. Thus we need some kind of a
loopback functionality for that. Software loopback works fine aside from the
fact it is performed only after an actual transmission has happened (which is a
problem with a one-node bus).

There is a CAN_CTRLMODE_LOOPBACK netlink option, but I didn't find any
description of its semantics. And as far as I understand every controller
interpretes it in its own way. For example, MCP2510 implies the loopback mode is
a silent (listen-only) mode and Bosch C_CAN controller disregards actual
rx-input in this mode according to the documentation. Hence the first question
is: what does CAN_CTRLMODE_LOOPBACK mean precisely?

I've also found out that this option is not implemented for SJA1000. Actually,
SJA1000 has nothing called a "loopback" feature but instead it has a Self Test
Mode, that seems like a reasonable solution for our problem. In this mode no
acknowledgement is required for the successful transmission, so software
loopback is working. However, it is not in the SJA1000 driver at the moment.

It is also possible to have the hardware loopback for SJA1000 with the Self
Reception Request feature (a message is transmitted and received simultaneously,
not implemented in sja1000 module as well), although we don't need it for our
specific case.

So the next question is: how should we implement those features for SJA1000?

I attached a patch that adds support for the Self Test Mode using the
CAN_CTRLMODE_LOOPBACK netlink option. As it is not exactly a loopback mode we
enable with that option, it might be a better idea to have a separate one for
that, smth like CAN_CTRLMODE_SELF_TEST. What do you think?

Regards,
Nikita

[-- Attachment #2: 0001-can-sja1000-add-Self-Test-Mode-support.patch --]
[-- Type: text/x-patch, Size: 1799 bytes --]

From 15d7abec6d72c207a742b00c1b50a6b32f42717d Mon Sep 17 00:00:00 2001
From: Nikita Edward Baruzdin <nebaruzdin@lvk.cs.msu.su>
Date: Mon, 16 Jun 2014 17:34:10 +0400
Subject: [PATCH] can: sja1000: add Self Test Mode support

This adds support for SJA1000 Self Test Mode (mode in which CAN controller will
perform a successful transmission, even if there is no acknowledge received)
through the use of CAN_CTRLMODE_LOOPBACK netlink option.

Signed-off-by: Nikita Edward Baruzdin <nebaruzdin@lvk.cs.msu.su>
---
 drivers/net/can/sja1000/sja1000.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 7164a99..6526a46 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -160,6 +160,8 @@ static void set_normal_mode(struct net_device *dev)
 		/* set chip to normal mode */
 		if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
 			priv->write_reg(priv, SJA1000_MOD, MOD_LOM);
+		else if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)
+			priv->write_reg(priv, SJA1000_MOD, MOD_STM);
 		else
 			priv->write_reg(priv, SJA1000_MOD, 0x00);
 
@@ -622,9 +624,11 @@ struct net_device *alloc_sja1000dev(int sizeof_priv)
 	priv->can.do_set_bittiming = sja1000_set_bittiming;
 	priv->can.do_set_mode = sja1000_set_mode;
 	priv->can.do_get_berr_counter = sja1000_get_berr_counter;
-	priv->can.ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES |
-		CAN_CTRLMODE_BERR_REPORTING | CAN_CTRLMODE_LISTENONLY |
-		CAN_CTRLMODE_ONE_SHOT;
+	priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK
+				     | CAN_CTRLMODE_LISTENONLY
+				     | CAN_CTRLMODE_3_SAMPLES
+				     | CAN_CTRLMODE_ONE_SHOT
+				     | CAN_CTRLMODE_BERR_REPORTING;
 
 	spin_lock_init(&priv->cmdreg_lock);
 
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-06-19 20:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-16 16:20 SJA1000 loopback feature Nikita Edward Baruzdin
2014-06-16 18:56 ` Oliver Hartkopp
2014-06-17 11:41   ` Nikita Edward Baruzdin
2014-06-17 12:13     ` Alexander GQ Gerasiov
2014-06-18 19:51       ` Oliver Hartkopp
2014-06-19 12:44         ` Alexander GQ Gerasiov
2014-06-19 14:55           ` Oliver Hartkopp
2014-06-19 16:01             ` Alexander GQ Gerasiov
2014-06-19 17:43               ` Oliver Hartkopp
2014-06-19 18:07                 ` Alexander GQ Gerasiov
2014-06-19 20:32                   ` vcan to can0 bridging Kurt Van Dijck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).