Skip to content

Commit 1dbd874

Browse files
Merge branch 'can-error-set-of-fixes-and-improvement-on-txerr-and-rxerr-reporting'
Vincent Mailhol says: ==================== can: error: set of fixes and improvement on txerr and rxerr reporting This series is a collection of patches targeting the CAN error counter. The series is split in three blocks (with small relation to each other). Several drivers uses the data[6] and data[7] fields (both of type u8) of the CAN error frame to report those values. However, the maximum size an u8 can hold is 255 and the error counter can exceed this value if bus-off status occurs. As such, the first nine patches of this series make sure that no drivers try to report txerr or rxerr through the CAN error frame when bus-off status is reached. can_frame::data[5..7] are defined as being "controller specific". Controller specific behaviors are not something desirable (portability issue...) The tenth patch of this series specifies how can_frame::data[5..7] should be use and remove any "controller specific" freedom. The eleventh patch adds a flag to notify though can_frame::can_id that data[6..7] were populated (in order to be consistent with other fields). Finally, the twelfth and last patch add three macro values to specify the different error counter threshold with so far was hard-coded as magic numbers in the drivers. N.B.: * patches 1 to 10 are for net (stable). * patches 11 and 12 are for net-next (but depends on patches 1 to 10). ** Changelog ** v1 -> v2: https://lore.kernel.org/all/[email protected] * Fix typo in patch #10: data[7] of CAN error frames is for the RX error counter, not the TX one (this is litteraly a one byte change). ==================== As discussed take the whole series via can-next -> net-next. Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
2 parents d79ee9a + 3f9c262 commit 1dbd874

File tree

25 files changed

+94
-52
lines changed

25 files changed

+94
-52
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ static void pch_can_error(struct net_device *ndev, u32 status)
496496
cf->can_id |= CAN_ERR_BUSOFF;
497497
priv->can.can_stats.bus_off++;
498498
can_bus_off(ndev);
499+
} else {
500+
cf->can_id |= CAN_ERR_CNT;
501+
cf->data[6] = errc & PCH_TEC;
502+
cf->data[7] = (errc & PCH_REC) >> 8;
499503
}
500504

501505
errc = ioread32(&priv->regs->errc);
@@ -556,9 +560,6 @@ static void pch_can_error(struct net_device *ndev, u32 status)
556560
break;
557561
}
558562

559-
cf->data[6] = errc & PCH_TEC;
560-
cf->data[7] = (errc & PCH_REC) >> 8;
561-
562563
priv->can.state = state;
563564
netif_receive_skb(skb);
564565
}

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)