diff mbox series

[1/6] can: esd_usb: Allow REC and TEC to return to zero

Message ID 20220708181235.4104943-2-frank.jungclaus@esd.eu (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series More preparation for supporting esd CAN-USB/3 | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 5 maintainers not CCed: edumazet@google.com socketcan@esd.eu pabeni@redhat.com kuba@kernel.org davem@davemloft.net
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 37 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Frank Jungclaus July 8, 2022, 6:12 p.m. UTC
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 <frank.jungclaus@esd.eu>
---
 drivers/net/can/usb/esd_usb.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

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;
 		}