netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: peakcan: report bus recovery as well
@ 2019-09-25  8:58 Jeroen Hofstee
  2019-10-04 21:15 ` Marc Kleine-Budde
  0 siblings, 1 reply; 2+ messages in thread
From: Jeroen Hofstee @ 2019-09-25  8:58 UTC (permalink / raw)
  To: linux-can
  Cc: Jeroen Hofstee, Stephane Grosjean, Wolfgang Grandegger,
	Marc Kleine-Budde, David S. Miller, Gustavo A. R. Silva,
	Nicolas Ferre, Greg Kroah-Hartman, Thomas Gleixner,
	open list:NETWORKING DRIVERS, open list

While the state changes are reported when the error counters increase
and decrease, there is no event when the bus recovers and the error
counters decrease again. So add those 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 <jhofstee@victronenergy.com>
Cc: Stephane Grosjean <s.grosjean@peak-system.com>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index 617da295b6c1..dd2a7f529012 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -436,8 +436,8 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,
 		}
 		if ((n & PCAN_USB_ERROR_BUS_LIGHT) == 0) {
 			/* no error (back to active state) */
-			mc->pdev->dev.can.state = CAN_STATE_ERROR_ACTIVE;
-			return 0;
+			new_state = CAN_STATE_ERROR_ACTIVE;
+			break;
 		}
 		break;
 
@@ -460,9 +460,9 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,
 		}
 
 		if ((n & PCAN_USB_ERROR_BUS_HEAVY) == 0) {
-			/* no error (back to active state) */
-			mc->pdev->dev.can.state = CAN_STATE_ERROR_ACTIVE;
-			return 0;
+			/* no error (back to warning state) */
+			new_state = CAN_STATE_ERROR_WARNING;
+			break;
 		}
 		break;
 
@@ -501,6 +501,11 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,
 		mc->pdev->dev.can.can_stats.error_warning++;
 		break;
 
+	case CAN_STATE_ERROR_ACTIVE:
+		cf->can_id |= CAN_ERR_CRTL;
+		cf->data[1] = CAN_ERR_CRTL_ACTIVE;
+		break;
+
 	default:
 		/* CAN_STATE_MAX (trick to handle other errors) */
 		cf->can_id |= CAN_ERR_CRTL;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] can: peakcan: report bus recovery as well
  2019-09-25  8:58 [PATCH] can: peakcan: report bus recovery as well Jeroen Hofstee
@ 2019-10-04 21:15 ` Marc Kleine-Budde
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Kleine-Budde @ 2019-10-04 21:15 UTC (permalink / raw)
  To: Jeroen Hofstee, linux-can
  Cc: Stephane Grosjean, Wolfgang Grandegger, David S. Miller,
	Gustavo A. R. Silva, Nicolas Ferre, Greg Kroah-Hartman,
	Thomas Gleixner, open list:NETWORKING DRIVERS, open list


[-- Attachment #1.1: Type: text/plain, Size: 812 bytes --]

On 9/25/19 10:58 AM, Jeroen Hofstee wrote:
> While the state changes are reported when the error counters increase
> and decrease, there is no event when the bus recovers and the error
> counters decrease again. So add those 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 <jhofstee@victronenergy.com>
> Cc: Stephane Grosjean <s.grosjean@peak-system.com>

Applied to linux-can.

Tnx,
Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-04 21:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25  8:58 [PATCH] can: peakcan: report bus recovery as well Jeroen Hofstee
2019-10-04 21:15 ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).