All of lore.kernel.org
 help / color / mirror / Atom feed
From: <Thomas.Kopp@microchip.com>
To: mkl@pengutronix.de, linux-can@vger.kernel.org
Subject: RE: mcp25xxfd: missing cerrif
Date: Tue, 18 Feb 2020 11:44:49 +0000	[thread overview]
Message-ID: <MN2PR11MB3645382ACDDB3CF132B92E25FB110@MN2PR11MB3645.namprd11.prod.outlook.com> (raw)
In-Reply-To: <a049ea8b-a3e2-ea39-d084-bd12b637cb9c@pengutronix.de>

> Hmmm. I think the question is, is there a dedicated warning state and
> if, how are the transitions from and to it?
I think the main confusion comes from the fact that error warning is not a state as defined in the ISO. The ISO defines three states: error-active, error-passive and bus-off.
The error warning is an interrupt that (most?) CAN IPs issue when the error counters exceeds 96. AFAIK this is only a convention though, not a spec (I know that Kvaser and the Bosch MCAN handle it like this).

> ACK. The documentation talks about error passive to error active, which
> means the diagram looks like this:
Not quite, that's how it should look like:
                     -- E > 95 --         -- E > 127 --               -- E > 255 --
                      /            \          /             \                    /             \
                    /              V         /               V                /               V
 --> error active  (error warning)      error passive    bus off
           ^              /                      ^         /
            \            /                         \       /
             -- E < 96 --                   -- E < 128 --

The enum in netlink.h mixes the error states plus some other states. To fulfill the ISO an interrupt from Error warning to Error active isn't really useful. I suppose that's why it's not implemented in the MCP2518FD.

enum can_state {
	CAN_STATE_ERROR_ACTIVE = 0,	/* RX/TX error count < 96 */
	CAN_STATE_ERROR_WARNING,	/* RX/TX error count < 128 */
	CAN_STATE_ERROR_PASSIVE,	/* RX/TX error count < 256 */
	CAN_STATE_BUS_OFF,		/* RX/TX error count >= 256 */
	CAN_STATE_STOPPED,		/* Device is stopped */
	CAN_STATE_SLEEPING,		/* Device is sleeping */
	CAN_STATE_MAX
};

Quickly looking at different CAN drivers in the kernel I don't really see a common pattern how this counter is used.
Taking the M_CAN driver as an example (drivers/net/can/m_can/m_can.c#L671) I see that a state change from error passive to error active (with the error warning bit being set) leads to the error warning counter being incremented and the state being updated to CAN_STATE_ERROR_WARNING.
I did not find a documentation on what this error counter is supposed to show - I suppose I didn't look in the right place. But while the number of times the device was in error warning state has technically gone up by one I would have expected that this counts the switches. Again, this is not based on documentation (I'm not really familiar with the SocketCAN so it's likely I missed something) but rather on what I would have expected intuitively.

One more thing I noticed in the mcan driver is that there doesn't seem to be a way to go from error warning to error active without ifdown/ifup. So the driver remains in in error warning state for a significant time.

Another example in the kvaser_usb_hydra.c:
 * Known issues:
 *  - Transition from CAN_STATE_ERROR_WARNING to CAN_STATE_ERROR_ACTIVE is only
 *    reported after a call to do_get_berr_counter(), since firmware does not
 *    distinguish between ERROR_WARNING and ERROR_ACTIVE.

> I think we have to discuss how the state diagram on socketcan should
>look like.

I agree. How would that discussion happen?

Best Regards,
Thomas 


      reply	other threads:[~2020-02-18 11:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 12:53 mcp25xxfd: missing cerrif Marc Kleine-Budde
2020-02-11 13:31 ` Thomas.Kopp
2020-02-11 13:51   ` Marc Kleine-Budde
2020-02-12  9:59     ` Thomas.Kopp
2020-02-14 13:59       ` Marc Kleine-Budde
2020-02-18 11:44         ` Thomas.Kopp [this message]

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=MN2PR11MB3645382ACDDB3CF132B92E25FB110@MN2PR11MB3645.namprd11.prod.outlook.com \
    --to=thomas.kopp@microchip.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    /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.