linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Andreas Larsson <andreas@gaisler.com>
Cc: linux-can@vger.kernel.org, software@gaisler.com
Subject: Re: [PATCH v2] can: sja1000: Add support for listen-only mode and one-shot mode
Date: Tue, 18 Sep 2012 19:17:09 +0200	[thread overview]
Message-ID: <5058AC95.5070406@pengutronix.de> (raw)
In-Reply-To: <1347986041-5358-1-git-send-email-andreas@gaisler.com>

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

On 09/18/2012 06:34 PM, Andreas Larsson wrote:
> One-shot mode correctly refrains from trying to resend frames that
> fail. However, all can frames are echoed back by can_get_echo_skb
> regardless of whether they were transmitted successfully or not. When
> in one-shot mode, sja1000 generates a transmit interrupt both for a
> successful and a failed transmission. It is not possible to
> distinguish between the cases and therefore not possible to refrain
> from echoing back a frame that was not transmitted successfully.

Stupid hardware :/

> Signed-off-by: Andreas Larsson <andreas@gaisler.com>
> ---
>  drivers/net/can/sja1000/sja1000.c |   15 ++++++++++++---
>  1 files changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
> index 4c4f33d..1a2159e 100644
> --- a/drivers/net/can/sja1000/sja1000.c
> +++ b/drivers/net/can/sja1000/sja1000.c
> @@ -141,6 +141,7 @@ static void set_normal_mode(struct net_device *dev)
>  	struct sja1000_priv *priv = netdev_priv(dev);
>  	unsigned char status = priv->read_reg(priv, REG_MOD);
>  	int i;
> +	u8 mod;
	u8 mod = 0;

Why inside the loop, see below? Better do it here:

	if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
		mod |= MOD_LOM;

(The compiler would probably move it out of the loop anyway)

>  
>  	for (i = 0; i < 100; i++) {
>  		/* check reset bit */
> @@ -156,7 +157,10 @@ static void set_normal_mode(struct net_device *dev)
>  		}
>  
>  		/* set chip to normal mode */
> -		priv->write_reg(priv, REG_MOD, 0x00);
> +		mod = 0;
> +		if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
> +			mod |= MOD_LOM;
> +		priv->write_reg(priv, REG_MOD, mod);
>  		udelay(10);
>  		status = priv->read_reg(priv, REG_MOD);
>  	}
> @@ -278,6 +282,7 @@ static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb,
>  	canid_t id;
>  	uint8_t dreg;
>  	int i;
> +	u8 cmd;
>  
>  	if (can_dropped_invalid_skb(dev, skb))
>  		return NETDEV_TX_OK;
> @@ -310,7 +315,10 @@ static netdev_tx_t sja1000_start_xmit(struct sk_buff *skb,
>  
>  	can_put_echo_skb(skb, dev, 0);
>  
> -	sja1000_write_cmdreg(priv, CMD_TR);
> +	cmd = CMD_TR;
> +	if (priv->can.ctrlmode & CAN_CTRLMODE_ONE_SHOT)
> +		cmd |= CMD_AT;
> +	sja1000_write_cmdreg(priv, cmd);
>  
>  	return NETDEV_TX_OK;
>  }
> @@ -605,7 +613,8 @@ struct net_device *alloc_sja1000dev(int sizeof_priv)
>  	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_BERR_REPORTING | CAN_CTRLMODE_LISTENONLY |
> +		CAN_CTRLMODE_ONE_SHOT;
>  
>  	spin_lock_init(&priv->cmdreg_lock);
>  
> 

Marc
-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

  reply	other threads:[~2012-09-18 17:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-17 15:58 [PATCH] can: sja1000: Add support for listen-only mode and one-shot mode Andreas Larsson
2012-09-18 13:46 ` Marc Kleine-Budde
2012-09-18 14:11   ` Wolfgang Grandegger
2012-09-18 15:54     ` Andreas Larsson
2012-09-18 16:16       ` Ira W. Snyder
2012-09-18 16:20         ` Marc Kleine-Budde
2012-09-18 16:34       ` [PATCH v2] " Andreas Larsson
2012-09-18 17:17         ` Marc Kleine-Budde [this message]
2012-09-18 17:23           ` Oliver Hartkopp
2012-09-19  5:55             ` Andreas Larsson
2012-09-18 18:27         ` Wolfgang Grandegger
2012-09-19  5:56           ` Andreas Larsson
2012-09-19  7:12             ` [PATCH v3] " Andreas Larsson
2012-09-19  7:33               ` Wolfgang Grandegger
2012-09-19 10:24                 ` [PATCH v4] " Andreas Larsson
2012-09-19 16:49                   ` Oliver Hartkopp
2012-09-20  7:50                     ` [PATCH v5] " Andreas Larsson
2012-09-21  8:08                       ` Marc Kleine-Budde
2012-09-21  8:12                         ` Andreas Larsson

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=5058AC95.5070406@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=andreas@gaisler.com \
    --cc=linux-can@vger.kernel.org \
    --cc=software@gaisler.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 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).