Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: peak_usb: report bus recovery as well

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>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Jeroen Hofstee and committed by
Marc Kleine-Budde
128a1b87 f7a1337f

+10 -5
+10 -5
drivers/net/can/usb/peak_usb/pcan_usb.c
··· 436 436 } 437 437 if ((n & PCAN_USB_ERROR_BUS_LIGHT) == 0) { 438 438 /* no error (back to active state) */ 439 - mc->pdev->dev.can.state = CAN_STATE_ERROR_ACTIVE; 440 - return 0; 439 + new_state = CAN_STATE_ERROR_ACTIVE; 440 + break; 441 441 } 442 442 break; 443 443 ··· 460 460 } 461 461 462 462 if ((n & PCAN_USB_ERROR_BUS_HEAVY) == 0) { 463 - /* no error (back to active state) */ 464 - mc->pdev->dev.can.state = CAN_STATE_ERROR_ACTIVE; 465 - return 0; 463 + /* no error (back to warning state) */ 464 + new_state = CAN_STATE_ERROR_WARNING; 465 + break; 466 466 } 467 467 break; 468 468 ··· 499 499 cf->data[1] |= CAN_ERR_CRTL_TX_WARNING | 500 500 CAN_ERR_CRTL_RX_WARNING; 501 501 mc->pdev->dev.can.can_stats.error_warning++; 502 + break; 503 + 504 + case CAN_STATE_ERROR_ACTIVE: 505 + cf->can_id |= CAN_ERR_CRTL; 506 + cf->data[1] = CAN_ERR_CRTL_ACTIVE; 502 507 break; 503 508 504 509 default: