2022-07-08 18:16:39

by Frank Jungclaus

[permalink] [raw]
Subject: [PATCH 1/6] can: esd_usb: Allow REC and TEC to return to zero

We don't get any further EVENT from an esd CAN USB device for changes
on REC or TEC while those counters converge to 0 (with ecc == 0).
So when handling the "Back to ACTIVE"-event force txerr =
rxerr = 0, otherwise the berr-counters might stay on values like 95
forever ...

Signed-off-by: Frank Jungclaus <[email protected]>
---
drivers/net/can/usb/esd_usb.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
index 8a4bf2961f3d..0b907bc54b70 100644
--- a/drivers/net/can/usb/esd_usb.c
+++ b/drivers/net/can/usb/esd_usb.c
@@ -229,10 +229,14 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,

if (id == ESD_EV_CAN_ERROR_EXT) {
u8 state = msg->msg.rx.data[0];
- u8 ecc = msg->msg.rx.data[1];
+ u8 ecc = msg->msg.rx.data[1];
u8 rxerr = msg->msg.rx.data[2];
u8 txerr = msg->msg.rx.data[3];

+ netdev_dbg(priv->netdev,
+ "CAN_ERR_EV_EXT: dlc=%#02x state=%02x ecc=%02x rec=%02x tec=%02x\n",
+ msg->msg.rx.dlc, state, ecc, rxerr, txerr);
+
skb = alloc_can_err_skb(priv->netdev, &cf);
if (skb == NULL) {
stats->rx_dropped++;
@@ -259,6 +263,15 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
break;
default:
priv->can.state = CAN_STATE_ERROR_ACTIVE;
+ /* We don't get any further EVENT for changes on
+ * REC or TEC while converging to 0, once we are
+ * back on ACTIVE.
+ * So force txerr = rxerr = 0, otherwise the
+ * berr-counters might stay on values like
+ * 95 forever ...
+ */
+ txerr = 0;
+ rxerr = 0;
break;
}
} else {
@@ -292,6 +305,7 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
CAN_ERR_CRTL_TX_PASSIVE :
CAN_ERR_CRTL_RX_PASSIVE;
}
+
cf->data[6] = txerr;
cf->data[7] = rxerr;
}
--
2.25.1