mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jimmy Assarsson <extja@kvaser.com>
To: Anssi Hannula <anssi.hannula@bitwise.fi>
Cc: linux-can@vger.kernel.org, Marc Kleine-Budde <mkl@pengutronix.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 05/12] can: kvaser_usb_leaf: Set Warning state even without bus errors
Date: Sat, 28 May 2022 09:35:02 +0200	[thread overview]
Message-ID: <78aba0b0-4669-c94b-13bb-3f4f1ac6ed50@kvaser.com> (raw)
In-Reply-To: <20220516134748.3724796-6-anssi.hannula@bitwise.fi>

On 5/16/22 15:47, Anssi Hannula wrote:
> kvaser_usb_leaf_rx_error_update_can_state() sets error state according
> to error counters when the hardware does not indicate a specific state
> directly.
> 
> However, this is currently gated behind a check for
> M16C_STATE_BUS_ERROR which does not always seem to be set when error
> counters are increasing, and may not be set when error counters are
> decreasing.
> 
> This causes the CAN_STATE_ERROR_WARNING state to not be set in some
> cases even when appropriate.
> 
> Change the code to set error state from counters even without
> M16C_STATE_BUS_ERROR.
> 
> The Error-Passive case seems superfluous as it is already set via
> M16C_STATE_BUS_PASSIVE flag above, but it is kept for now.
> 
> Tested with 0bfd:0124 Kvaser Mini PCI Express 2xHS FW 4.18.778.
> 
> Fixes: 080f40a6fa28 ("can: kvaser_usb: Add support for Kvaser CAN/USB devices")
> Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>

Looks good to me.
Tested-by: Jimmy Assarsson <extja@kvaser.com>

> ---
>   .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c  | 20 ++++++++-----------
>   1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
> index 09ade66256b2..d7f2d64a8083 100644
> --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
> +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
> @@ -775,20 +775,16 @@ kvaser_usb_leaf_rx_error_update_can_state(struct kvaser_usb_net_priv *priv,
>   		new_state = CAN_STATE_BUS_OFF;
>   	} else if (es->status & M16C_STATE_BUS_PASSIVE) {
>   		new_state = CAN_STATE_ERROR_PASSIVE;
> -	} else if (es->status & M16C_STATE_BUS_ERROR) {
> +	} else if ((es->status & M16C_STATE_BUS_ERROR) &&
> +		   cur_state >= CAN_STATE_BUS_OFF) {
>   		/* Guard against spurious error events after a busoff */
> -		if (cur_state < CAN_STATE_BUS_OFF) {
> -			if (es->txerr >= 128 || es->rxerr >= 128)
> -				new_state = CAN_STATE_ERROR_PASSIVE;
> -			else if (es->txerr >= 96 || es->rxerr >= 96)
> -				new_state = CAN_STATE_ERROR_WARNING;
> -			else if (cur_state > CAN_STATE_ERROR_ACTIVE)
> -				new_state = CAN_STATE_ERROR_ACTIVE;
> -		}
> -	}
> -
> -	if (!es->status)
> +	} else if (es->txerr >= 128 || es->rxerr >= 128) {
> +		new_state = CAN_STATE_ERROR_PASSIVE;
> +	} else if (es->txerr >= 96 || es->rxerr >= 96) {
> +		new_state = CAN_STATE_ERROR_WARNING;
> +	} else {
>   		new_state = CAN_STATE_ERROR_ACTIVE;
> +	}
>   
>   	if (new_state != cur_state) {
>   		tx_state = (es->txerr >= es->rxerr) ? new_state : 0;

  reply	other threads:[~2022-05-28  7:36 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 13:47 [PATCH 00/12] can: kvaser_usb: Various fixes Anssi Hannula
2022-05-16 13:47 ` [PATCH 01/12] can: kvaser_usb_leaf: Fix overread with an invalid command Anssi Hannula
2022-05-28  7:34   ` Jimmy Assarsson
2022-05-16 13:47 ` [PATCH 02/12] can: kvaser_usb: Fix use of uninitialized completion Anssi Hannula
2022-05-28  7:34   ` Jimmy Assarsson
2022-05-16 13:47 ` [PATCH 03/12] can: kvaser_usb: Fix possible completions during init_completion Anssi Hannula
2022-05-28  7:34   ` Jimmy Assarsson
2022-05-16 13:47 ` [PATCH 04/12] can: kvaser_usb: Mark Mini PCIe 2xHS as supporting error counters Anssi Hannula
2022-05-28  7:37   ` Jimmy Assarsson
2022-05-30 10:55     ` Anssi Hannula
2022-05-16 13:47 ` [PATCH 05/12] can: kvaser_usb_leaf: Set Warning state even without bus errors Anssi Hannula
2022-05-28  7:35   ` Jimmy Assarsson [this message]
2022-05-16 13:47 ` [PATCH 06/12] can: kvaser_usb_leaf: Fix TX queue out of sync after restart Anssi Hannula
2022-05-28  7:35   ` Jimmy Assarsson
2022-05-16 13:47 ` [PATCH 07/12] can: kvaser_usb_leaf: Fix CAN state " Anssi Hannula
2022-06-06 15:31   ` Jimmy Assarsson
2022-05-16 13:47 ` [PATCH 08/12] can: kvaser_usb_leaf: Fix improved state not being reported Anssi Hannula
2022-06-06 15:32   ` Jimmy Assarsson
2022-05-16 13:47 ` [PATCH 09/12] can: kvaser_usb_leaf: Fix silently failing bus params setup Anssi Hannula
2022-05-28  7:37   ` Jimmy Assarsson
2022-05-30 10:55     ` Anssi Hannula
2022-05-16 13:47 ` [PATCH 10/12] can: kvaser_usb_leaf: Fix wrong CAN state after stopping Anssi Hannula
2022-05-28  7:35   ` Jimmy Assarsson
2022-05-16 13:47 ` [PATCH 11/12] can: kvaser_usb_leaf: Ignore stale bus-off after start Anssi Hannula
2022-06-06 15:32   ` Jimmy Assarsson
2022-05-16 13:47 ` [PATCH 12/12] can: kvaser_usb_leaf: Fix bogus restart events Anssi Hannula
2022-05-28  7:35   ` Jimmy Assarsson
2022-05-17  8:41 ` [PATCH 00/12] can: kvaser_usb: Various fixes Jimmy Assarsson
2022-05-28  7:42   ` Jimmy Assarsson
2022-05-30 10:56     ` Anssi Hannula
2022-06-06 15:33       ` Jimmy Assarsson

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=78aba0b0-4669-c94b-13bb-3f4f1ac6ed50@kvaser.com \
    --to=extja@kvaser.com \
    --cc=anssi.hannula@bitwise.fi \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®