devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Larsson <andreas@gaisler.com>
To: Wolfgang Grandegger <wg@grandegger.com>
Cc: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>,
	devicetree-discuss@lists.ozlabs.org, software@gaisler.com
Subject: Re: [PATCH v3] can: grcan: Add device driver for GRCAN and GRHCAN cores
Date: Wed, 07 Nov 2012 08:32:36 +0100	[thread overview]
Message-ID: <509A0E94.1040103@gaisler.com> (raw)
In-Reply-To: <509786C0.9070703@grandegger.com>

On 11/05/2012 10:28 AM, Wolfgang Grandegger wrote:
> On 11/01/2012 05:08 PM, Andreas Larsson wrote:
>> On 2012-10-31 21:21, Wolfgang Grandegger wrote:
...
>> Yes, the hardware becomes error active after having monitored 11
>> consecutive recessive bits on the bus 128 times (as allowed by the 2.0
>> CAN spec). There is no way of turning this off, so to conform to the
>> normal linux procedure of not doing this, I shut down the device on bus
>> off interrupt.
>
> This should be handled in the following way:
>
> 1. If priv->can.restart_ms == 0: do *not* allow automatic restart
>     That's what you alredy have implemented.
>
> 2. If priv->can.restart_ms  > 0 : do allow automatic restart.
>     This requires to send CAN_ERR_RESTARTED when the system goes
>     bus-on. See at91_can and mcp251x as example.
>
>> In addition I have thrown out the arbitration lost error frame
>> generation as arbitration errors can not be singled out. The TXLOSS
>> interrupt might be due to arbitration error, but is also triggered in
>> great numbers when there is no one else on the can bus or when there is
>> a problem with the hardware interface or the bus itself.
>>
>> This is how things look currently with no one else on the bus:
>> ~ # cansend can0 123#45
>>    can0  20000004  [8] 00 08 00 00 00 00 60 00   ERRORFRAME
>>          controller-problem{tx-error-warning}
>>          error-counter-tx-rx{{96}{0}}
>>    can0  20000004  [8] 00 20 00 00 00 00 80 00   ERRORFRAME
>>          controller-problem{tx-error-passive}
>>          error-counter-tx-rx{{128}{0}}
>> ~ #
>>
>> And this is how it looks with a short-circuited bus:
>> ~ # cansend can0 123#45
>>    can0  20000004  [8] 00 08 00 00 00 00 90 00   ERRORFRAME
>>          controller-problem{tx-error-warning}
>>          error-counter-tx-rx{{144}{0}}
>>    can0  20000004  [8] 00 20 00 00 00 00 98 00   ERRORFRAME
>>          controller-problem{tx-error-passive}
>>          error-counter-tx-rx{{152}{0}}
>>    can0  20000040  [8] 00 00 00 00 00 00 00 00   ERRORFRAME
>>          bus-off
>> ~ #
>
> This looks good now. Just the automatic restart is missing as described
> above.

When doing the bus_off handling as in at91_can, on a short-circuited bus with 
restart-ms != 0, the result of a cansend is an endless and frequent stream of

   can0  20000004  [8] 00 20 00 00 00 00 88 00   ERRORFRAME
         controller-problem{tx-error-passive}
         error-counter-tx-rx{{136}{0}}
   can0  20000040  [8] 00 00 00 00 00 00 80 00   ERRORFRAME
         bus-off
         error-counter-tx-rx{{128}{0}}
   can0  20000104  [8] 00 00 00 00 00 00 10 00   ERRORFRAME
         controller-problem{}
         restarted-after-bus-off
         error-counter-tx-rx{{16}{0}}
   can0  20000004  [8] 00 10 00 00 00 00 57 80   ERRORFRAME
         controller-problem{rx-error-passive}
         error-counter-tx-rx{{87}{128}}
   can0  20000040  [8] 00 00 00 00 00 00 80 00   ERRORFRAME
         bus-off
         error-counter-tx-rx{{128}{0}}
   can0  20000104  [8] 00 00 00 00 00 00 08 00   ERRORFRAME
         controller-problem{}
         restarted-after-bus-off
         error-counter-tx-rx{{8}{0}}
   can0  20000004  [8] 00 10 00 00 00 00 57 80   ERRORFRAME
         controller-problem{rx-error-passive}
         error-counter-tx-rx{{87}{128}}
   can0  20000040  [8] 00 00 00 00 00 00 80 00   ERRORFRAME
         bus-off
         error-counter-tx-rx{{128}{0}}
   can0  20000104  [8] 00 00 00 00 00 00 08 00   ERRORFRAME
         controller-problem{}
         restarted-after-bus-off
         error-counter-tx-rx{{8}{0}}
   [...]

as the grcan core continues to try to resend the frame when it comes back again. 
To mimic the sja1000 behavior as closely as possible, I guess that the driver 
also would need to make sure that the tx and rx buffers are cleaned out so that 
this resending does not happen, right?

To do this, the hardware needs to be stopped anyway. Therefore, in my opinion it 
is much simpler to handle it as it is in v5: always shut down the hardware on 
bus off and, in the case of a non-zero restart_ms, let restart timer trigger 
can_restart that will call grcan_set_mode which will restart the hardware with 
empty buffers. Do you see any problems with this approach?

The added benefit of this approach is that then the actual millisecond value of 
the non-zero restart_ms is used instead of having the hardware quickly restart 
regardless of the value.

In any case I have some other fixes for v6.

Cheers,
Andreas

  reply	other threads:[~2012-11-07  7:32 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5076999F.6070302@pengutronix.de>
2012-10-23  9:57 ` [PATCH v2] can: grcan: Add device driver for GRCAN and GRHCAN cores Andreas Larsson
2012-10-23 16:26   ` Wolfgang Grandegger
2012-10-24 13:31     ` Andreas Larsson
2012-10-30  9:06       ` [PATCH v3] " Andreas Larsson
2012-10-30 10:07         ` Wolfgang Grandegger
2012-10-30 16:24           ` Andreas Larsson
2012-10-31 12:51             ` Wolfgang Grandegger
2012-10-31 16:33               ` Andreas Larsson
2012-10-31 16:39                 ` [PATCH v4] " Andreas Larsson
2012-10-31 20:21                 ` [PATCH v3] " Wolfgang Grandegger
2012-11-01 16:08                   ` Andreas Larsson
2012-11-02 14:23                     ` [PATCH v5] " Andreas Larsson
2012-11-05  9:28                     ` [PATCH v3] " Wolfgang Grandegger
2012-11-07  7:32                       ` Andreas Larsson [this message]
2012-11-07 11:15                         ` Wolfgang Grandegger
2012-11-07 12:55                           ` Andreas Larsson
2012-11-07 15:20                             ` [PATCH v6] " Andreas Larsson
2012-11-08  8:29                               ` Wolfgang Grandegger
2012-11-08  9:27                                 ` Marc Kleine-Budde
2012-11-08 10:37                                   ` Andreas Larsson
     [not found]                                   ` <509B7B1E.5040509-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-11-08 13:10                                     ` [PATCH v7] " Andreas Larsson
2012-11-09  0:01                                       ` Marc Kleine-Budde
2012-11-12 14:57                                         ` [PATCH v8] " Andreas Larsson
2012-11-13 21:15                                           ` Marc Kleine-Budde
2012-11-14  7:50                                             ` Andreas Larsson
2012-11-14  8:43                                               ` Marc Kleine-Budde
2012-11-14 11:02                                                 ` Andreas Larsson
2012-11-14 11:22                                                   ` Marc Kleine-Budde
2012-11-14 15:07                                                     ` Andreas Larsson
2012-11-14 15:12                                                       ` Marc Kleine-Budde
2012-11-15  7:47                                                         ` [PATCH v9] " Andreas Larsson
2012-11-15 20:32                                                           ` Marc Kleine-Budde
2012-11-16  6:17                                                             ` Andreas Larsson
2012-11-08 10:33                                 ` [PATCH v6] " Andreas Larsson
2012-10-30  9:29       ` [PATCH v2] " Wolfgang Grandegger

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=509A0E94.1040103@gaisler.com \
    --to=andreas@gaisler.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=software@gaisler.com \
    --cc=wg@grandegger.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).