All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent MAILHOL <mailhol.vincent@wanadoo.fr>
To: Frank Jungclaus <frank.jungclaus@esd.eu>
Cc: linux-can@vger.kernel.org,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Wolfgang Grandegger" <wg@grandegger.com>,
	"Stefan Mätje" <stefan.maetje@esd.eu>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/6] can: esd_usb: Improved behavior on esd CAN_ERROR_EXT event (3)
Date: Tue, 12 Jul 2022 23:39:28 +0900	[thread overview]
Message-ID: <CAMZ6Rq+QBO1yTX_o6GV0yhdBj-RzZSRGWDZBS0fs7zbSTy4hmA@mail.gmail.com> (raw)
In-Reply-To: <20220708181235.4104943-5-frank.jungclaus@esd.eu>

On Tue. 9 Jul. 2022 at 03:15, Frank Jungclaus <frank.jungclaus@esd.eu> wrote:
> Started a rework initiated by Vincents remark about "You should not
> report the greatest of txerr and rxerr but the one which actually
> increased." Now setting CAN_ERR_CRTL_[RT]X_WARNING and
> CAN_ERR_CRTL_[RT]X_PASSIVE depending on REC and TEC
>
> Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
> ---
>  drivers/net/can/usb/esd_usb.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
> index 0a402a23d7ac..588caba1453b 100644
> --- a/drivers/net/can/usb/esd_usb.c
> +++ b/drivers/net/can/usb/esd_usb.c
> @@ -304,11 +304,17 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
>                         /* Store error in CAN protocol (location) in data[3] */
>                         cf->data[3] = ecc & SJA1000_ECC_SEG;
>
> -                       if (priv->can.state == CAN_STATE_ERROR_WARNING ||
> -                           priv->can.state == CAN_STATE_ERROR_PASSIVE) {
> -                               cf->data[1] = (txerr > rxerr) ?
> -                                       CAN_ERR_CRTL_TX_PASSIVE :
> -                                       CAN_ERR_CRTL_RX_PASSIVE;
> +                       /* Store error status of CAN-controller in data[1] */
> +                       if (priv->can.state == CAN_STATE_ERROR_WARNING) {
> +                               if (txerr >= 96)
> +                                       cf->data[1] |= CAN_ERR_CRTL_TX_WARNING;

As far as I understand, those flags should be set only when the
threshold is *reached*:
https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/can/error.h#L69

I don't think you should set it if the error state does not change.

Here, you probably want to compare the new value  with the previous
one (stored in struct can_berr_counter) to decide whether or not the
flags should be set.


> +                               if (rxerr >= 96)
> +                                       cf->data[1] |= CAN_ERR_CRTL_RX_WARNING;
> +                       } else if (priv->can.state == CAN_STATE_ERROR_PASSIVE) {
> +                               if (txerr >= 128)
> +                                       cf->data[1] |= CAN_ERR_CRTL_TX_PASSIVE;
> +                               if (rxerr >= 128)
> +                                       cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
>                         }
>
>                         cf->data[6] = txerr;
> --
> 2.25.1
>

  reply	other threads:[~2022-07-12 14:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08 18:12 [PATCH 0/6] More preparation for supporting esd CAN-USB/3 Frank Jungclaus
2022-07-08 18:12 ` [PATCH 1/6] can: esd_usb: Allow REC and TEC to return to zero Frank Jungclaus
2022-07-08 18:12 ` [PATCH 2/6] can: esd_usb: Improved behavior on esd CAN_ERROR_EXT event (1) Frank Jungclaus
2022-07-08 18:12 ` [PATCH 3/6] can: esd_usb: Improved behavior on esd CAN_ERROR_EXT event (2) Frank Jungclaus
2022-07-08 18:12 ` [PATCH 4/6] can: esd_usb: Improved behavior on esd CAN_ERROR_EXT event (3) Frank Jungclaus
2022-07-12 14:39   ` Vincent MAILHOL [this message]
2022-07-12 16:08     ` Frank Jungclaus
2022-07-08 18:12 ` [PATCH 5/6] can: esd_usb: Improved support for CAN_CTRLMODE_BERR_REPORTING Frank Jungclaus
2022-07-12  3:05   ` Vincent MAILHOL
2022-07-08 18:12 ` [PATCH 6/6] can: esd_usb: Improved decoding for ESD_EV_CAN_ERROR_EXT messages Frank Jungclaus
2022-07-12  1:33   ` Vincent MAILHOL
2022-07-12 15:38     ` Frank Jungclaus

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=CAMZ6Rq+QBO1yTX_o6GV0yhdBj-RzZSRGWDZBS0fs7zbSTy4hmA@mail.gmail.com \
    --to=mailhol.vincent@wanadoo.fr \
    --cc=frank.jungclaus@esd.eu \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=stefan.maetje@esd.eu \
    --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.