can: kvaser_usb_leaf: Ignore stale bus-off after start
authorAnssi Hannula <anssi.hannula@bitwise.fi>
Mon, 10 Oct 2022 18:52:34 +0000 (20:52 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 26 Oct 2022 08:19:43 +0000 (10:19 +0200)
commitabb8670938b23a3be0772153125895c7e6742840
treedb03c98892d514b3dff696582f20e0a87af2e1bf
parenta11249acf802341294557895d8e5f6aef080253f
can: kvaser_usb_leaf: Ignore stale bus-off after start

With 0bfd:0124 Kvaser Mini PCI Express 2xHS FW 4.18.778 it was observed
that if the device was bus-off when stopped, at next start (either via
interface down/up or manual bus-off restart) the initial
CMD_CHIP_STATE_EVENT received just after CMD_START_CHIP_REPLY will have
the M16C_STATE_BUS_OFF bit still set, causing the interface to
immediately go bus-off again.

The bit seems to internally clear quickly afterwards but we do not get
another CMD_CHIP_STATE_EVENT.

Fix the issue by ignoring any initial bus-off state until we see at
least one bus-on state. Also, poll the state periodically until that
occurs.

It is possible we lose one actual immediately occurring bus-off event
here in which case the HW will auto-recover and we see the recovery
event. We will then catch the next bus-off event, if any.

This issue did not reproduce with 0bfd:0017 Kvaser Memorator
Professional HS/HS FW 2.0.50.

Fixes: 71873a9b38d1 ("can: kvaser_usb: Add support for more Kvaser Leaf v2 devices")
Tested-by: Jimmy Assarsson <extja@kvaser.com>
Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi>
Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
Link: https://lore.kernel.org/all/20221010185237.319219-9-extja@kvaser.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c