All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephane Grosjean <s.grosjean@peak-system.com>
To: Wolfgang Grandegger <wg@grandegger.com>
Cc: Oliver Hartkopp <socketcan@hartkopp.net>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	linux-can Mailing List <linux-can@vger.kernel.org>
Subject: Re: [PATCH v3] can/sja1000: add support for PEAK-System PCMCIA card
Date: Tue, 14 Feb 2012 10:14:57 +0100	[thread overview]
Message-ID: <4F3A2611.90703@peak-system.com> (raw)
In-Reply-To: <4F397145.8040007@grandegger.com>


Le 13/02/2012 21:23, Wolfgang Grandegger a écrit :
> On 02/13/2012 08:55 PM, Oliver Hartkopp wrote:
>> What happens, if inside this inner while() statement the unplug happens?
>>
>> Do we get two correct CAN frames and then we get eight CAN frames like this:
>>
>> 12345677 4 AA BB CC DD
>> 12345678 6 AA BB CC DD EE FF
>> 1FFFFFFF 8 FF FF FF FF FF FF FF FF
>> 1FFFFFFF 8 FF FF FF FF FF FF FF FF
>> 1FFFFFFF 8 FF FF FF FF FF FF FF FF
>> 1FFFFFFF 8 FF FF FF FF FF FF FF FF
>> 1FFFFFFF 8 FF FF FF FF FF FF FF FF
>> 1FFFFFFF 8 FF FF FF FF FF FF FF FF
>> 1FFFFFFF 8 FF FF FF FF FF FF FF FF
>> 1FFFFFFF 8 FF FF FF FF FF FF FF FF
>>
>> ???
> Do you have seen such traces with the "device present" check in the
> custom handler? I doubt.

Well if I may interfere: since the driver "remove()" entry point is 
called and the netdev interface is destroyed next, nobody can truly says 
if these frames have time to be processed until the client application. 
The problem is not here.

> First it is unlikely, that the unplug will happen when data from the
> device gets processed. And if, the check in the while loop will not
> change a lot, in contrast to the check in the custom handler. If it
> happens while processing the data, we will get grap... but well...
>
>> Sending nothing is preferred to sending wrong data :-)
> You cannot avoid sending crap under any circumstances. Also be aware
> that the while loop will normally process just *one* message, and rarely
> more.

cannot say that, this is arch dependent.

>>> Of course, the loop should be limited in sja1000_interrupt anyway.
>>
>> IMO checking for absent hardware in the custom isr is fine and should fix most
>> of the problems (as we can already see in the ems_pcmcia driver).

cannot say that: all the tests I made @1xMbps bitrate show that the 
issue at least occurs 3/4 of time in the sja1000_interrupt, not in the 
custom isr. This also is obviously arch dependent.

>> But adding the patch which is checking two times for status != 0xFF reduces
>> the race conditions to almost zero. Having a while() statement that
>> potentially produces wrong data doesn't heal the problem IMO.
> I disagree. It will not change a lot. Measurements may proof that I'm
> wrong, though.

What about the fix Oliver talked about in one his first e-mail:

> The used status register has a bit for bus-off which is "1" in the bus-off
> case. Assuming RX interrupts can only occur in a 'bus-on' state, this bit can
> be assumed to be '0'.

IMHO, this is the best proposal: while the sja1000_interrupt() requests 
for the SR, it seems normal that it does some semantic checks about what 
it got.

So the fix could be something like this instead:

         while ((isrc = priv->read_reg(priv, REG_IR)) && (n < 
SJA1000_MAX_IRQ)) {
                 n++;
                 status = priv->read_reg(priv, REG_SR);

+               if (status & (SR_RBS|SR_BS) == (SR_RBS|SR_BS)) {
+                       /* what? something is rotten in my kingdom... */
+                       n = 0;
+                       break; /* or goto post_irq; as you want... */
+               }

                 if (isrc & IRQ_RI) {
                         /* receive interrupt */
                         while (status & SR_RBS) {
                                 sja1000_rx(dev);
                                 status = priv->read_reg(priv, REG_SR);
+                               if (status & (SR_RBS|SR_BS) == 
(SR_RBS|SR_BS)) {
+                                       /* what? something is rotten in 
my kingdom, here also... */
+                                       n = 0;
+                                       goto post_irq;
                                 }
                         }
                 }
         }

+post_irq:
         if (priv->post_irq)
                 priv->post_irq(priv);


Of course, in order to definitely say asta lavista to the potential 
infinite loop, we can use a for(;;) loop instead of the while()...

What are your opinion?

Stéphane
--
PEAK-System Technik GmbH, Otto-Roehm-Strasse 69, D-64293 Darmstadt 
Geschaeftsleitung: A.Gach/U.Wilhelm,St.Nr.:007/241/13586 FA Darmstadt 
HRB-9183 Darmstadt, Ust.IdNr.:DE 202220078, WEE-Reg.-Nr.: DE39305391 
Tel.+49 (0)6151-817320 / Fax:+49 (0)6151-817329, info@peak-system.com

  reply	other threads:[~2012-02-14  9:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-06 15:56 [PATCH v3] can/sja1000: add support for PEAK-System PCMCIA card Stephane Grosjean
2012-02-13  9:14 ` Marc Kleine-Budde
2012-02-13 10:01   ` Stephane Grosjean
2012-02-13 10:14     ` Wolfgang Grandegger
2012-02-13 10:41       ` Oliver Hartkopp
2012-02-13 11:02         ` Wolfgang Grandegger
2012-02-13 11:06           ` Marc Kleine-Budde
2012-02-13 11:08             ` Wolfgang Grandegger
2012-02-13 19:55               ` Oliver Hartkopp
2012-02-13 20:23                 ` Wolfgang Grandegger
2012-02-14  9:14                   ` Stephane Grosjean [this message]
2012-02-14  9:30                     ` Wolfgang Grandegger
2012-02-14  9:59                   ` Oliver Hartkopp
2012-02-14 10:16                     ` Stephane Grosjean
2012-02-14 16:41                       ` Oliver Hartkopp
2012-02-15  7:03                         ` Wolfgang Grandegger
2012-02-15  8:05                           ` Oliver Hartkopp
2012-02-15  8:37                             ` Wolfgang Grandegger
2012-02-15 19:32                               ` Oliver Hartkopp
2012-02-15 11:52                           ` Stephane Grosjean
2012-02-15 15:06                             ` Wolfgang Grandegger
2012-02-15 16:00                               ` Stephane Grosjean
2012-02-15 19:46                               ` Oliver Hartkopp
2012-02-13 10:46       ` Stephane Grosjean
2012-02-13 10:56         ` 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=4F3A2611.90703@peak-system.com \
    --to=s.grosjean@peak-system.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=socketcan@hartkopp.net \
    --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 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.