Skip to content

Commit 3e5c291

Browse files
vincent-mailholmarckleinebudde
authored andcommitted
can: add CAN_ERR_CNT flag to notify availability of error counter
Add a dedicated flag in uapi/linux/can/error.h to notify the userland that fields data[6] and data[7] of the CAN error frame were respectively populated with the tx and rx error counters. For all driver tree-wide, set up this flags whenever needed. Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Vincent Mailhol <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent e70a326 commit 3e5c291

File tree

25 files changed

+38
-18
lines changed

25 files changed

+38
-18
lines changed

drivers/net/can/c_can/c_can_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,14 +952,14 @@ static int c_can_handle_state_change(struct net_device *dev,
952952

953953
switch (error_type) {
954954
case C_CAN_NO_ERROR:
955-
cf->can_id |= CAN_ERR_CRTL;
955+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
956956
cf->data[1] = CAN_ERR_CRTL_ACTIVE;
957957
cf->data[6] = bec.txerr;
958958
cf->data[7] = bec.rxerr;
959959
break;
960960
case C_CAN_ERROR_WARNING:
961961
/* error warning state */
962-
cf->can_id |= CAN_ERR_CRTL;
962+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
963963
cf->data[1] = (bec.txerr > bec.rxerr) ?
964964
CAN_ERR_CRTL_TX_WARNING :
965965
CAN_ERR_CRTL_RX_WARNING;
@@ -969,7 +969,7 @@ static int c_can_handle_state_change(struct net_device *dev,
969969
break;
970970
case C_CAN_ERROR_PASSIVE:
971971
/* error passive state */
972-
cf->can_id |= CAN_ERR_CRTL;
972+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
973973
if (rx_err_passive)
974974
cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
975975
if (bec.txerr > 127)

drivers/net/can/cc770/cc770.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ static int cc770_err(struct net_device *dev, u8 status)
512512

513513
/* Use extended functions of the CC770 */
514514
if (priv->control_normal_mode & CTRL_EAF) {
515+
cf->can_id |= CAN_ERR_CNT;
515516
cf->data[6] = cc770_read_reg(priv, tx_error_counter);
516517
cf->data[7] = cc770_read_reg(priv, rx_error_counter);
517518
}

drivers/net/can/ctucanfd/ctucanfd_base.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)
847847
case CAN_STATE_ERROR_PASSIVE:
848848
priv->can.can_stats.error_passive++;
849849
if (skb) {
850-
cf->can_id |= CAN_ERR_CRTL;
850+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
851851
cf->data[1] = (bec.rxerr > 127) ?
852852
CAN_ERR_CRTL_RX_PASSIVE :
853853
CAN_ERR_CRTL_TX_PASSIVE;
@@ -858,7 +858,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)
858858
case CAN_STATE_ERROR_WARNING:
859859
priv->can.can_stats.error_warning++;
860860
if (skb) {
861-
cf->can_id |= CAN_ERR_CRTL;
861+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
862862
cf->data[1] |= (bec.txerr > bec.rxerr) ?
863863
CAN_ERR_CRTL_TX_WARNING :
864864
CAN_ERR_CRTL_RX_WARNING;
@@ -867,6 +867,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)
867867
}
868868
break;
869869
case CAN_STATE_ERROR_ACTIVE:
870+
cf->can_id |= CAN_ERR_CNT;
870871
cf->data[1] = CAN_ERR_CRTL_ACTIVE;
871872
cf->data[6] = bec.txerr;
872873
cf->data[7] = bec.rxerr;

drivers/net/can/grcan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ static void grcan_err(struct net_device *dev, u32 sources, u32 status)
671671
/* There are no others at this point */
672672
break;
673673
}
674+
cf.can_id |= CAN_ERR_CNT;
674675
cf.data[6] = txerr;
675676
cf.data[7] = rxerr;
676677
priv->can.state = state;

drivers/net/can/ifi_canfd/ifi_canfd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,
492492
switch (new_state) {
493493
case CAN_STATE_ERROR_WARNING:
494494
/* error warning state */
495-
cf->can_id |= CAN_ERR_CRTL;
495+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
496496
cf->data[1] = (bec.txerr > bec.rxerr) ?
497497
CAN_ERR_CRTL_TX_WARNING :
498498
CAN_ERR_CRTL_RX_WARNING;
@@ -501,7 +501,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,
501501
break;
502502
case CAN_STATE_ERROR_PASSIVE:
503503
/* error passive state */
504-
cf->can_id |= CAN_ERR_CRTL;
504+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
505505
cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
506506
if (bec.txerr > 127)
507507
cf->data[1] |= CAN_ERR_CRTL_TX_PASSIVE;

drivers/net/can/janz-ican3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ static int ican3_handle_cevtind(struct ican3_dev *mod, struct ican3_msg *msg)
11271127
/* bus error interrupt */
11281128
if (isrc == CEVTIND_BEI) {
11291129
mod->can.can_stats.bus_error++;
1130-
cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
1130+
cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR | CAN_ERR_CNT;
11311131

11321132
switch (ecc & ECC_MASK) {
11331133
case ECC_BIT:
@@ -1153,7 +1153,7 @@ static int ican3_handle_cevtind(struct ican3_dev *mod, struct ican3_msg *msg)
11531153

11541154
if (state != mod->can.state && (state == CAN_STATE_ERROR_WARNING ||
11551155
state == CAN_STATE_ERROR_PASSIVE)) {
1156-
cf->can_id |= CAN_ERR_CRTL;
1156+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
11571157
if (state == CAN_STATE_ERROR_WARNING) {
11581158
mod->can.can_stats.error_warning++;
11591159
cf->data[1] = (txerr > rxerr) ?

drivers/net/can/kvaser_pciefd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can,
13061306
shhwtstamps->hwtstamp =
13071307
ns_to_ktime(div_u64(p->timestamp * 1000,
13081308
can->kv_pcie->freq_to_ticks_div));
1309-
cf->can_id |= CAN_ERR_BUSERROR;
1309+
cf->can_id |= CAN_ERR_BUSERROR | CAN_ERR_CNT;
13101310

13111311
cf->data[6] = bec.txerr;
13121312
cf->data[7] = bec.rxerr;

drivers/net/can/m_can/m_can.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ static int m_can_handle_state_change(struct net_device *dev,
741741
switch (new_state) {
742742
case CAN_STATE_ERROR_WARNING:
743743
/* error warning state */
744-
cf->can_id |= CAN_ERR_CRTL;
744+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
745745
cf->data[1] = (bec.txerr > bec.rxerr) ?
746746
CAN_ERR_CRTL_TX_WARNING :
747747
CAN_ERR_CRTL_RX_WARNING;
@@ -750,7 +750,7 @@ static int m_can_handle_state_change(struct net_device *dev,
750750
break;
751751
case CAN_STATE_ERROR_PASSIVE:
752752
/* error passive state */
753-
cf->can_id |= CAN_ERR_CRTL;
753+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
754754
ecr = m_can_read(cdev, M_CAN_ECR);
755755
if (ecr & ECR_RP)
756756
cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;

drivers/net/can/pch_can.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ static void pch_can_error(struct net_device *ndev, u32 status)
497497
priv->can.can_stats.bus_off++;
498498
can_bus_off(ndev);
499499
} else {
500+
cf->can_id |= CAN_ERR_CNT;
500501
cf->data[6] = errc & PCH_TEC;
501502
cf->data[7] = (errc & PCH_REC) >> 8;
502503
}

drivers/net/can/peak_canfd/peak_canfd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
373373
priv->can.state = CAN_STATE_ERROR_PASSIVE;
374374
priv->can.can_stats.error_passive++;
375375
if (skb) {
376-
cf->can_id |= CAN_ERR_CRTL;
376+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
377377
cf->data[1] = (priv->bec.txerr > priv->bec.rxerr) ?
378378
CAN_ERR_CRTL_TX_PASSIVE :
379379
CAN_ERR_CRTL_RX_PASSIVE;
@@ -386,7 +386,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv,
386386
priv->can.state = CAN_STATE_ERROR_WARNING;
387387
priv->can.can_stats.error_warning++;
388388
if (skb) {
389-
cf->can_id |= CAN_ERR_CRTL;
389+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
390390
cf->data[1] = (priv->bec.txerr > priv->bec.rxerr) ?
391391
CAN_ERR_CRTL_TX_WARNING :
392392
CAN_ERR_CRTL_RX_WARNING;
@@ -430,7 +430,7 @@ static int pucan_handle_cache_critical(struct peak_canfd_priv *priv)
430430
return -ENOMEM;
431431
}
432432

433-
cf->can_id |= CAN_ERR_CRTL;
433+
cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT;
434434
cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
435435

436436
cf->data[6] = priv->bec.txerr;

0 commit comments

Comments
 (0)