2019-09-26 10:31:43

by Jeroen Hofstee

[permalink] [raw]
Subject: [PATCH 2/2] can: C_CAN: add bus recovery events

While the state is update when the error counters increase and decrease,
there is no event when the bus recovers and the error counters decrease
again. So add that event as well.

Change the state going downward to be ERROR_PASSIVE -> ERROR_WARNING ->
ERROR_ACTIVE instead of directly to ERROR_ACTIVE again.

Signed-off-by: Jeroen Hofstee <[email protected]>
---
drivers/net/can/c_can/c_can.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c
index 502a181d02e7..5cfaab18e10b 100644
--- a/drivers/net/can/c_can/c_can.c
+++ b/drivers/net/can/c_can/c_can.c
@@ -912,6 +912,9 @@ static int c_can_handle_state_change(struct net_device *dev,
struct can_berr_counter bec;

switch (error_type) {
+ case C_CAN_NO_ERROR:
+ priv->can.state = CAN_STATE_ERROR_ACTIVE;
+ break;
case C_CAN_ERROR_WARNING:
/* error warning state */
priv->can.can_stats.error_warning++;
@@ -942,6 +945,13 @@ static int c_can_handle_state_change(struct net_device *dev,
ERR_CNT_RP_SHIFT;

switch (error_type) {
+ case C_CAN_NO_ERROR:
+ /* error warning state */
+ cf->can_id |= CAN_ERR_CRTL;
+ cf->data[1] = CAN_ERR_CRTL_ACTIVE;
+ cf->data[6] = bec.txerr;
+ cf->data[7] = bec.rxerr;
+ break;
case C_CAN_ERROR_WARNING:
/* error warning state */
cf->can_id |= CAN_ERR_CRTL;
@@ -1080,11 +1090,17 @@ static int c_can_poll(struct napi_struct *napi, int quota)
/* handle bus recovery events */
if ((!(curr & STATUS_BOFF)) && (last & STATUS_BOFF)) {
netdev_dbg(dev, "left bus off state\n");
- priv->can.state = CAN_STATE_ERROR_ACTIVE;
+ work_done += c_can_handle_state_change(dev, C_CAN_ERROR_PASSIVE);
}
+
if ((!(curr & STATUS_EPASS)) && (last & STATUS_EPASS)) {
netdev_dbg(dev, "left error passive state\n");
- priv->can.state = CAN_STATE_ERROR_ACTIVE;
+ work_done += c_can_handle_state_change(dev, C_CAN_ERROR_WARNING);
+ }
+
+ if ((!(curr & STATUS_EWARN)) && (last & STATUS_EWARN)) {
+ netdev_dbg(dev, "left error warning state\n");
+ work_done += c_can_handle_state_change(dev, C_CAN_NO_ERROR);
}

/* handle lec errors on the bus */
--
2.17.1


2019-10-01 07:42:04

by Kurt Van Dijck

[permalink] [raw]
Subject: Re: [PATCH 2/2] can: C_CAN: add bus recovery events

On do, 26 sep 2019 08:50:51 +0000, Jeroen Hofstee wrote:
> While the state is update when the error counters increase and decrease,
> there is no event when the bus recovers and the error counters decrease
> again. So add that event as well.
>
> Change the state going downward to be ERROR_PASSIVE -> ERROR_WARNING ->
> ERROR_ACTIVE instead of directly to ERROR_ACTIVE again.

This looks like a proper thing to do
Acked-by: Kurt Van Dijck <[email protected]>

2019-10-01 13:38:44

by Kurt Van Dijck

[permalink] [raw]
Subject: Re: [PATCH 2/2] can: C_CAN: add bus recovery events

On di, 01 okt 2019 09:40:57 +0200, Kurt Van Dijck wrote:
> On do, 26 sep 2019 08:50:51 +0000, Jeroen Hofstee wrote:
> > While the state is update when the error counters increase and decrease,
> > there is no event when the bus recovers and the error counters decrease
> > again. So add that event as well.
> >
> > Change the state going downward to be ERROR_PASSIVE -> ERROR_WARNING ->
> > ERROR_ACTIVE instead of directly to ERROR_ACTIVE again.
>
> This looks like a proper thing to do
> Acked-by: Kurt Van Dijck <[email protected]>

Thanks for this, now I see when the bus is normal again.

Tested-by: Kurt Van Dijck <[email protected]>