can: error: set of fixes and improvement on txerr and rxerr reporting
Subsystems (10)
cover 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).
Vincent Mailhol (12):
can: pch_can: do not report txerr and rxerr during bus-off
can: rcar_can: do not report txerr and rxerr during bus-off
can: sja1000: do not report txerr and rxerr during bus-off
can: slcan: do not report txerr and rxerr during bus-off
can: hi311x: do not report txerr and rxerr during bus-off
can: sun4i_can: do not report txerr and rxerr during bus-off
can: kvaser_usb_hydra: do not report txerr and rxerr during bus-off
can: kvaser_usb_leaf: do not report txerr and rxerr during bus-off
can: usb_8dev: do not report txerr and rxerr during bus-off
can: error: specify the values of data[5..7] of CAN error frames
can: add CAN_ERR_CNT flag to notify availability of error counter
can: error: add definitions for the different CAN error thresholds
drivers/net/can/c_can/c_can_main.c | 6 +++--- drivers/net/can/cc770/cc770.c | 1 + drivers/net/can/ctucanfd/ctucanfd_base.c | 5 +++-- drivers/net/can/grcan.c | 1 + drivers/net/can/ifi_canfd/ifi_canfd.c | 4 ++-- drivers/net/can/janz-ican3.c | 4 ++-- drivers/net/can/kvaser_pciefd.c | 2 +- drivers/net/can/m_can/m_can.c | 4 ++-- drivers/net/can/pch_can.c | 7 ++++--- drivers/net/can/peak_canfd/peak_canfd.c | 6 +++--- drivers/net/can/rcar/rcar_can.c | 9 +++++---- drivers/net/can/rcar/rcar_canfd.c | 4 ++-- drivers/net/can/sja1000/sja1000.c | 8 +++++--- drivers/net/can/slcan/slcan-core.c | 13 ++++++------ drivers/net/can/spi/hi311x.c | 6 ++++-- .../net/can/spi/mcp251xfd/mcp251xfd-core.c | 1 + drivers/net/can/sun4i_can.c | 10 +++++----- drivers/net/can/ti_hecc.c | 1 + drivers/net/can/usb/esd_usb.c | 3 ++- .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 14 +++++++++---- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 7 +++++-- drivers/net/can/usb/peak_usb/pcan_usb.c | 1 + drivers/net/can/usb/usb_8dev.c | 8 +++++--- drivers/net/can/xilinx_can.c | 1 + include/uapi/linux/can/error.h | 20 ++++++++++++++++++- 25 files changed, 94 insertions(+), 52 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/12 can: pch_can: do not report txerr and rxerr during bus-off
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/pch_can.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/can/pch_can.c +3 -3
@@ -496,6 +496,9 @@ static void pch_can_error(struct net_device *ndev, u32 status) cf->can_id |=CAN_ERR_BUSOFF ; priv->can.can_stats.bus_off++;can_bus_off (ndev); + }else { + cf->data[6 ] = errc &PCH_TEC ; + cf->data[7 ] = (errc &PCH_REC ) >>8 ; } errc =ioread32 (&priv->regs->errc);
@@ -556,9 +559,6 @@ static void pch_can_error(struct net_device *ndev, u32 status)break ; } - cf->data[6 ] = errc &PCH_TEC ; - cf->data[7 ] = (errc &PCH_REC ) >>8 ; - priv->can.state = state;netif_receive_skb (skb); }
Signature · 1 line
2.35.1
PATCH 2/12 can: rcar_can: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/rcar/rcar_can.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/can/rcar/rcar_can.c +4 -4
@@ -232,11 +232,8 @@ static void rcar_can_error(struct net_device *ndev)if (eifr & (RCAR_CAN_EIFR_EWIF |RCAR_CAN_EIFR_EPIF )) { txerr =readb (&priv->regs->tecr); rxerr =readb (&priv->regs->recr); -if (skb) { +if (skb) cf->can_id |=CAN_ERR_CRTL ; - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; - } }if (eifr &RCAR_CAN_EIFR_BEIF ) {int rx_errors =0 , tx_errors =0 ;
@@ -336,6 +333,9 @@ static void rcar_can_error(struct net_device *ndev)can_bus_off (ndev);if (skb) cf->can_id |=CAN_ERR_BUSOFF ; + }else if (skb) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; }if (eifr &RCAR_CAN_EIFR_ORIF ) {netdev_dbg (priv->ndev,"Receive overrun error interrupt\n" );
Signature · 1 line
2.35.1
PATCH 3/12 can: sja1000: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/sja1000/sja1000.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/can/sja1000/sja1000.c +4 -3
@@ -402,9 +402,6 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) txerr = priv->read_reg (priv,SJA1000_TXERR ); rxerr = priv->read_reg (priv,SJA1000_RXERR ); - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; -if (isrc &IRQ_DOI ) {/* data overrun interrupt */ netdev_dbg (dev,"data overrun interrupt\n" );
@@ -426,6 +423,10 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)else state =CAN_STATE_ERROR_ACTIVE ; } +if (state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + }if (isrc &IRQ_BEI ) {/* bus error interrupt */ priv->can.can_stats.bus_error++;
Signature · 1 line
2.35.1
PATCH 4/12 can: slcan: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
alloc_can_err_skb() already sets cf to NULL if the allocation fails [1], so the redundant cf = NULL assignment gets removed.
[1] https://elixir.bootlin.com/linux/latest/source/drivers/net/can/dev/skb.c#L187
--- drivers/net/can/slcan/slcan-core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/net/can/slcan/slcan-core.c +5 -7
@@ -306,19 +306,17 @@ static void slc_bump_state(struct slcan *sl)return ; skb =alloc_can_err_skb (dev, &cf); -if (skb) { - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; - }else { - cf =NULL ; - } tx_state = txerr >= rxerr ? state :0 ; rx_state = txerr <= rxerr ? state :0 ;can_change_state (dev, cf, tx_state, rx_state); -if (state ==CAN_STATE_BUS_OFF ) +if (state ==CAN_STATE_BUS_OFF ) {can_bus_off (dev); + }else if (skb) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + }if (skb)netif_rx (skb);
Signature · 1 line
2.35.1
PATCH 5/12 can: hi311x: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/spi/hi311x.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/can/spi/hi311x.c +3 -2
@@ -667,8 +667,6 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id) txerr =hi3110_read (spi,HI3110_READ_TEC ); rxerr =hi3110_read (spi,HI3110_READ_REC ); - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; tx_state = txerr >= rxerr ? new_state :0 ; rx_state = txerr <= rxerr ? new_state :0 ;can_change_state (net, cf, tx_state, rx_state);
@@ -681,6 +679,9 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id)hi3110_hw_sleep (spi);break ; } + }else { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; } }
Signature · 1 line
2.35.1
PATCH 6/12 can: sun4i_can: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/sun4i_can.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/can/sun4i_can.c +4 -5
@@ -535,11 +535,6 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status) rxerr = (errc >>16 ) &0xFF ; txerr = errc &0xFF ; -if (skb) { - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; - } -if (isrc &SUN4I_INT_DATA_OR ) {/* data overrun interrupt */ netdev_dbg (dev,"data overrun interrupt\n" );
@@ -570,6 +565,10 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)else state =CAN_STATE_ERROR_ACTIVE ; } +if (skb && state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + }if (isrc &SUN4I_INT_BUS_ERR ) {/* bus error interrupt */ netdev_dbg (dev,"bus error interrupt\n" );
Signature · 1 line
2.35.1
PATCH 7/12 can: kvaser_usb_hydra: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +8 -4
@@ -917,8 +917,10 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, new_state < CAN_STATE_BUS_OFF) priv->can.can_stats.restarts++; - cf->data[6 ] = bec->txerr; - cf->data[7 ] = bec->rxerr; +if (new_state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = bec->txerr; + cf->data[7 ] = bec->rxerr; + }netif_rx (skb); }
@@ -1069,8 +1071,10 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv, shhwtstamps->hwtstamp = hwtstamp; cf->can_id |=CAN_ERR_BUSERROR ; - cf->data[6 ] = bec.txerr; - cf->data[7 ] = bec.rxerr; +if (new_state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = bec.txerr; + cf->data[7 ] = bec.rxerr; + }netif_rx (skb);
Signature · 1 line
2.35.1
PATCH 8/12 can: kvaser_usb_leaf: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +4 -2
@@ -836,8 +836,10 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,break ; } - cf->data[6 ] = es->txerr; - cf->data[7 ] = es->rxerr; +if (new_state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = es->txerr; + cf->data[7 ] = es->rxerr; + }netif_rx (skb); }
Signature · 1 line
2.35.1
PATCH 9/12 can: usb_8dev: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/usb/usb_8dev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/can/usb/usb_8dev.c +4 -3
@@ -438,9 +438,10 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv,if (rx_errors) stats->rx_errors++; - - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; +if (priv->can.state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + } priv->bec.txerr = txerr; priv->bec.rxerr = rxerr;
Signature · 1 line
2.35.1
PATCH 10/12 can: error: specify the values of data[5..7] of CAN error frames
In reply to Vincent MailholCurrently, data[5..7] of struct can_frame, when used as a CAN error frame, are defined as being "controller specific". Device specific behaviours are problematic because it prevents someone from writing code which is portable between devices.
As a matter of fact, data[5] is never used, data[6] is always used to report TX error counter and data[7] is always used to report RX error counter. can-utils also relies on this.
This patch updates the comment in the uapi header to specify that data[5] is reserved (and thus should not be used) and that data[6..7] are used for error counters.
--- include/uapi/linux/can/error.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/uapi/linux/can/error.h +4 -1
@@ -120,6 +120,9 @@#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70/* 0111 0000 */ #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80/* 1000 0000 */ -/* controller specific additional information / data[5..7] */ +/* data[5] is reserved (do not use) */ + +/* TX error counter / data[6] */ +/* TX error counter / data[7] */ #endif /* _UAPI_CAN_ERROR_H */
Signature · 1 line
2.35.1
Re: [PATCH v1 10/12] can: error: specify the values of data[5..7] of CAN error frames
Hi Vincent,
I'm a bit late to the party, but shouldn't the patch do that what you promise in the commit message? See at the end.
Best regards,
Stefan
Am Mittwoch, den 13.07.2022, 00:31 +0900 schrieb Vincent Mailhol:
Quoted 24 lines
Currently, data[5..7] of struct
can_frame, when used as a CAN error frame, are defined as being "controller specific". Device specific behaviours are problematic because it prevents someone from writing code which is portable between devices.As a matter of fact, data[5] is never used, data[6] is always used to report TX error counter and data[7] is always used to report RX error counter. can-utils also relies on this.
This patch updates the comment in the uapi header to specify that data[5] is reserved (and thus should not be used) and that data[6..7] are used for error counters.
Fixes 0d66548a10cb ("[CAN]: Add PF_CAN core module")Signed-off-by Vincent Mailhol <[email protected]>--- include/uapi/linux/can/error.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)include/uapi/linux/can/error.h +0
-0
include/uapi/linux/can/error.h line 126
Quoted 8 lines
include/uapi/linux/can/error.h +4
-1@@ -120,6 +120,9 @@#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70/* 0111 0000 */ #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80/* 1000 0000 */ -/* controller specific additional information / data[5..7] */ +/* data[5] is reserved (do not use) */ + +/* TX error counter / data[6] */ +/* TX error counter / data[7] */
/* RX error counter / data[7] */
^
Quoted 1 line
include/uapi/linux/can/error.h +0
-0#endif /* _UAPI_CAN_ERROR_H */
Re: [PATCH v1 10/12] can: error: specify the values of data[5..7] of CAN error frames
Quoted 36 lines · Stefan Mätje
Hi Vincent,
I'm a bit late to the party, but shouldn't the patch do that what you promise in the commit message? See at the end.
Best regards,
StefanAm Mittwoch, den 13.07.2022, 00:31 +0900 schrieb Vincent Mailhol:
Quoted 27 lines
Currently, data[5..7] of struct
can_frame, when used as a CAN error frame, are defined as being "controller specific". Device specific behaviours are problematic because it prevents someone from writing code which is portable between devices.As a matter of fact, data[5] is never used, data[6] is always used to report TX error counter and data[7] is always used to report RX error counter. can-utils also relies on this.
This patch updates the comment in the uapi header to specify that data[5] is reserved (and thus should not be used) and that data[6..7] are used for error counters.
Fixes 0d66548a10cb ("[CAN]: Add PF_CAN core module")Signed-off-by Vincent Mailhol <[email protected]>--- include/uapi/linux/can/error.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)include/uapi/linux/can/error.h +0
-0@@ -120,6 +120,9 @@#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70/* 0111 0000 */ #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80/* 1000 0000 */
Quoted 8 lines
include/uapi/linux/can/error.h line 126
Quoted 5 lines
include/uapi/linux/can/error.h +4
-1-/* controller specific additional information / data[5..7] */ +/* data[5] is reserved (do not use) */ + +/* TX error counter / data[6] */ +/* TX error counter / data[7] */ /* RX error counter / data[7] */
^
Maybe I should pay a visit to my ophthalmologist? Thank you for spotting the typo, I will send a v2.
Yours sincerely,
Vincent Mailhol
PATCH 11/12 can: add CAN_ERR_CNT flag to notify availability of error counter
In reply to Vincent MailholAdd 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.
--- drivers/net/can/c_can/c_can_main.c | 6 +++--- drivers/net/can/cc770/cc770.c | 1 + drivers/net/can/ctucanfd/ctucanfd_base.c | 5 +++-- drivers/net/can/grcan.c | 1 + drivers/net/can/ifi_canfd/ifi_canfd.c | 4 ++-- drivers/net/can/janz-ican3.c | 4 ++-- drivers/net/can/kvaser_pciefd.c | 2 +- drivers/net/can/m_can/m_can.c | 4 ++-- drivers/net/can/pch_can.c | 1 + drivers/net/can/peak_canfd/peak_canfd.c | 6 +++--- drivers/net/can/rcar/rcar_can.c | 1 + drivers/net/can/rcar/rcar_canfd.c | 4 ++-- drivers/net/can/sja1000/sja1000.c | 1 + drivers/net/can/slcan/slcan-core.c | 1 + drivers/net/can/spi/hi311x.c | 1 + drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 1 + drivers/net/can/sun4i_can.c | 1 + drivers/net/can/ti_hecc.c | 1 + drivers/net/can/usb/esd_usb.c | 3 ++- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 2 ++ drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 1 + drivers/net/can/usb/peak_usb/pcan_usb.c | 1 + drivers/net/can/usb/usb_8dev.c | 1 + drivers/net/can/xilinx_can.c | 1 + include/uapi/linux/can/error.h | 2 ++ 25 files changed, 38 insertions(+), 18 deletions(-)
drivers/net/can/c_can/c_can_main.c +3 -3
@@ -953,14 +953,14 @@ static int c_can_handle_state_change(struct net_device *dev,switch (error_type) {case C_CAN_NO_ERROR :/* error warning state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; 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 ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -970,7 +970,7 @@ static int c_can_handle_state_change(struct net_device *dev,break ;case C_CAN_ERROR_PASSIVE :/* error passive state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ;if (rx_err_passive) cf->data[1 ] |=CAN_ERR_CRTL_RX_PASSIVE ;if (bec.txerr >127 )
drivers/net/can/cc770/cc770.c +1 -0
@@ -512,6 +512,7 @@ static int cc770_err(struct net_device *dev, u8 status)/* Use extended functions of the CC770 */ if (priv->control_normal_mode &CTRL_EAF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] =cc770_read_reg (priv, tx_error_counter); cf->data[7 ] =cc770_read_reg (priv, rx_error_counter); }
drivers/net/can/ctucanfd/ctucanfd_base.c +3 -2
@@ -847,7 +847,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)case CAN_STATE_ERROR_PASSIVE : priv->can.can_stats.error_passive++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.rxerr >127 ) ?CAN_ERR_CRTL_RX_PASSIVE :CAN_ERR_CRTL_TX_PASSIVE ;
@@ -858,7 +858,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)case CAN_STATE_ERROR_WARNING : priv->can.can_stats.error_warning++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] |= (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -867,6 +867,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr) }break ;case CAN_STATE_ERROR_ACTIVE : + cf->can_id |=CAN_ERR_CNT ; cf->data[1 ] =CAN_ERR_CRTL_ACTIVE ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr;
drivers/net/can/grcan.c +1 -0
@@ -671,6 +671,7 @@ static void grcan_err(struct net_device *dev, u32 sources, u32 status)/* There are no others at this point */ break ; } + cf.can_id |=CAN_ERR_CNT ; cf.data[6 ] = txerr; cf.data[7 ] = rxerr; priv->can.state = state;
drivers/net/can/ifi_canfd/ifi_canfd.c +2 -2
@@ -492,7 +492,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,switch (new_state) {case CAN_STATE_ERROR_WARNING :/* error warning state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -501,7 +501,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,break ;case CAN_STATE_ERROR_PASSIVE :/* error passive state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] |=CAN_ERR_CRTL_RX_PASSIVE ;if (bec.txerr >127 ) cf->data[1 ] |=CAN_ERR_CRTL_TX_PASSIVE ;
drivers/net/can/janz-ican3.c +2 -2
@@ -1127,7 +1127,7 @@ static int ican3_handle_cevtind(struct ican3_dev *mod, struct ican3_msg *msg)/* bus error interrupt */ if (isrc ==CEVTIND_BEI ) { mod->can.can_stats.bus_error++; - cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR ; + cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR |CAN_ERR_CNT ;switch (ecc &ECC_MASK ) {case ECC_BIT :
@@ -1153,7 +1153,7 @@ static int ican3_handle_cevtind(struct ican3_dev *mod, struct ican3_msg *msg)if (state != mod->can.state && (state ==CAN_STATE_ERROR_WARNING || state ==CAN_STATE_ERROR_PASSIVE )) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ;if (state ==CAN_STATE_ERROR_WARNING ) { mod->can.can_stats.error_warning++; cf->data[1] = (txerr > rxerr) ?
drivers/net/can/kvaser_pciefd.c +1 -1
@@ -1306,7 +1306,7 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, shhwtstamps->hwtstamp =ns_to_ktime (div_u64 (p->timestamp *1000 , can->kv_pcie->freq_to_ticks_div)); - cf->can_id |=CAN_ERR_BUSERROR ; + cf->can_id |=CAN_ERR_BUSERROR |CAN_ERR_CNT ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr;
drivers/net/can/m_can/m_can.c +2 -2
@@ -741,7 +741,7 @@ static int m_can_handle_state_change(struct net_device *dev,switch (new_state) {case CAN_STATE_ERROR_WARNING :/* error warning state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -750,7 +750,7 @@ static int m_can_handle_state_change(struct net_device *dev,break ;case CAN_STATE_ERROR_PASSIVE :/* error passive state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; ecr =m_can_read (cdev,M_CAN_ECR );if (ecr &ECR_RP ) cf->data[1 ] |=CAN_ERR_CRTL_RX_PASSIVE ;
drivers/net/can/pch_can.c +1 -0
@@ -497,6 +497,7 @@ static void pch_can_error(struct net_device *ndev, u32 status) priv->can.can_stats.bus_off++;can_bus_off (ndev); }else { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = errc &PCH_TEC ; cf->data[7 ] = (errc &PCH_REC ) >>8 ; }
drivers/net/can/peak_canfd/peak_canfd.c +3 -3
@@ -373,7 +373,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv, priv->can.state =CAN_STATE_ERROR_PASSIVE ; priv->can.can_stats.error_passive++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (priv->bec.txerr > priv->bec.rxerr) ?CAN_ERR_CRTL_TX_PASSIVE :CAN_ERR_CRTL_RX_PASSIVE ;
@@ -386,7 +386,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv, priv->can.state =CAN_STATE_ERROR_WARNING ; priv->can.can_stats.error_warning++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (priv->bec.txerr > priv->bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -430,7 +430,7 @@ static int pucan_handle_cache_critical(struct peak_canfd_priv *priv)return -ENOMEM ; } - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] =CAN_ERR_CRTL_RX_OVERFLOW ; cf->data[6 ] = priv->bec.txerr;
drivers/net/can/rcar/rcar_can.c +1 -0
@@ -334,6 +334,7 @@ static void rcar_can_error(struct net_device *ndev)if (skb) cf->can_id |=CAN_ERR_BUSOFF ; }else if (skb) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/rcar/rcar_canfd.c +2 -2
@@ -1052,7 +1052,7 @@ static void rcar_canfd_error(struct net_device *ndev, u32 cerfl,netdev_dbg (ndev,"Error warning interrupt\n" ); priv->can.state =CAN_STATE_ERROR_WARNING ; priv->can.can_stats.error_warning++; - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = txerr > rxerr ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ; cf->data[6 ] = txerr;
@@ -1062,7 +1062,7 @@ static void rcar_canfd_error(struct net_device *ndev, u32 cerfl,netdev_dbg (ndev,"Error passive interrupt\n" ); priv->can.state =CAN_STATE_ERROR_PASSIVE ; priv->can.can_stats.error_passive++; - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = txerr > rxerr ?CAN_ERR_CRTL_TX_PASSIVE :CAN_ERR_CRTL_RX_PASSIVE ; cf->data[6 ] = txerr;
drivers/net/can/sja1000/sja1000.c +1 -0
@@ -424,6 +424,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) state =CAN_STATE_ERROR_ACTIVE ; }if (state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/slcan/slcan-core.c +1 -0
@@ -314,6 +314,7 @@ static void slc_bump_state(struct slcan *sl)if (state ==CAN_STATE_BUS_OFF ) {can_bus_off (dev); }else if (skb) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/spi/hi311x.c +1 -0
@@ -680,6 +680,7 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id)break ; } }else { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
@@ -1098,6 +1098,7 @@ static int mcp251xfd_handle_cerrif(struct mcp251xfd_priv *priv) err =mcp251xfd_get_berr_counter (priv->ndev, &bec);if (err)return err; + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; }
drivers/net/can/sun4i_can.c +1 -0
@@ -566,6 +566,7 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status) state =CAN_STATE_ERROR_ACTIVE ; }if (skb && state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/ti_hecc.c +1 -0
@@ -662,6 +662,7 @@ static void ti_hecc_change_state(struct net_device *ndev,can_change_state (priv->ndev, cf, tx_state, rx_state);if (max (tx_state, rx_state) !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] =hecc_read (priv,HECC_CANTEC ); cf->data[7 ] =hecc_read (priv,HECC_CANREC ); }
drivers/net/can/usb/esd_usb.c +2 -1
@@ -265,7 +265,8 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, priv->can.can_stats.bus_error++; stats->rx_errors++; - cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR ; + cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR | +CAN_ERR_CNT ;switch (ecc &SJA1000_ECC_MASK ) {case SJA1000_ECC_BIT :
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +2 -0
@@ -918,6 +918,7 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, priv->can.can_stats.restarts++;if (new_state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = bec->txerr; cf->data[7 ] = bec->rxerr; }
@@ -1072,6 +1073,7 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv, cf->can_id |=CAN_ERR_BUSERROR ;if (new_state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; }
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +1 -0
@@ -837,6 +837,7 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev, }if (new_state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = es->txerr; cf->data[7 ] = es->rxerr; }
drivers/net/can/usb/peak_usb/pcan_usb.c +1 -0
@@ -506,6 +506,7 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,/* Supply TX/RX error counters in case of * controller error. */ + cf->can_id =CAN_ERR_CNT ; cf->data[6 ] = mc->pdev->bec.txerr; cf->data[7 ] = mc->pdev->bec.rxerr; }
drivers/net/can/usb/usb_8dev.c +1 -0
@@ -439,6 +439,7 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv,if (rx_errors) stats->rx_errors++;if (priv->can.state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/xilinx_can.c +1 -0
@@ -965,6 +965,7 @@ static void xcan_set_error_state(struct net_device *ndev,can_change_state (ndev, cf, tx_state, rx_state);if (cf) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
include/uapi/linux/can/error.h +2 -0
@@ -57,6 +57,8 @@#define CAN_ERR_BUSOFF 0x00000040U/* bus off */ #define CAN_ERR_BUSERROR 0x00000080U/* bus error (may flood!) */ #define CAN_ERR_RESTARTED 0x00000100U/* controller restarted */ +#define CAN_ERR_CNT 0x00000200U/* TX error counter / data[6] */ +/* RX error counter / data[7] */ /* arbitration lost in bit ... / data[0] */ #define CAN_ERR_LOSTARB_UNSPEC 0x00/* unspecified */
Signature · 1 line
2.35.1
PATCH 12/12 can: error: add definitions for the different CAN error thresholds
In reply to Vincent MailholCurrently, drivers are using magic numbers to derive the CAN error states from the error counter. Add three macro declarations to remediate this.
For reference, the error-active, error-passive and bus-off are defined in ISO 11898, section 12.1.4.2 "Error counting". Although ISO 11898 does not define error-warning state, this extra value is also commonly used and is thus also added.
---
Strictly speaking, this does not need to be part of the uapi but I still think it is beneficial to have it here. Thank you for your comments.
Also, if anyone knows which standard originally defined the error-warning, let me know.
--- include/uapi/linux/can/error.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/uapi/linux/can/error.h +13 -0
@@ -127,4 +127,17 @@/* TX error counter / data[6] */ /* TX error counter / data[7] */ +/* CAN state thresholds +* +* Error counter Error state +* ----------------------------------- +* 0 - 95 Error-active +* 96 - 127 Error-warning +* 128 - 255 Error-passive +* 256 and greater Bus-off +*/ +#define CAN_ERROR_WARNING_THRESHOLD 96 +#define CAN_ERROR_PASSIVE_THRESHOLD 128 +#define CAN_BUS_OFF_THRESHOLD 256 +#endif /* _UAPI_CAN_ERROR_H */
Signature · 1 line
2.35.1
v2 cover can: error: set of fixes and improvement on txerr and rxerr reporting
In reply to Vincent MailholThis 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:
* 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).
Vincent Mailhol (12):
can: pch_can: do not report txerr and rxerr during bus-off
can: rcar_can: do not report txerr and rxerr during bus-off
can: sja1000: do not report txerr and rxerr during bus-off
can: slcan: do not report txerr and rxerr during bus-off
can: hi311x: do not report txerr and rxerr during bus-off
can: sun4i_can: do not report txerr and rxerr during bus-off
can: kvaser_usb_hydra: do not report txerr and rxerr during bus-off
can: kvaser_usb_leaf: do not report txerr and rxerr during bus-off
can: usb_8dev: do not report txerr and rxerr during bus-off
can: error: specify the values of data[5..7] of CAN error frames
can: add CAN_ERR_CNT flag to notify availability of error counter
can: error: add definitions for the different CAN error thresholds
drivers/net/can/c_can/c_can_main.c | 6 +++--- drivers/net/can/cc770/cc770.c | 1 + drivers/net/can/ctucanfd/ctucanfd_base.c | 5 +++-- drivers/net/can/grcan.c | 1 + drivers/net/can/ifi_canfd/ifi_canfd.c | 4 ++-- drivers/net/can/janz-ican3.c | 4 ++-- drivers/net/can/kvaser_pciefd.c | 2 +- drivers/net/can/m_can/m_can.c | 4 ++-- drivers/net/can/pch_can.c | 7 ++++--- drivers/net/can/peak_canfd/peak_canfd.c | 6 +++--- drivers/net/can/rcar/rcar_can.c | 9 +++++---- drivers/net/can/rcar/rcar_canfd.c | 4 ++-- drivers/net/can/sja1000/sja1000.c | 8 +++++--- drivers/net/can/slcan/slcan-core.c | 13 ++++++------ drivers/net/can/spi/hi311x.c | 6 ++++-- .../net/can/spi/mcp251xfd/mcp251xfd-core.c | 1 + drivers/net/can/sun4i_can.c | 10 +++++----- drivers/net/can/ti_hecc.c | 1 + drivers/net/can/usb/esd_usb.c | 3 ++- .../net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 14 +++++++++---- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 7 +++++-- drivers/net/can/usb/peak_usb/pcan_usb.c | 1 + drivers/net/can/usb/usb_8dev.c | 8 +++++--- drivers/net/can/xilinx_can.c | 1 + include/uapi/linux/can/error.h | 20 ++++++++++++++++++- 25 files changed, 94 insertions(+), 52 deletions(-)
Signature · 1 line
2.35.1
PATCH v2 1/12 can: pch_can: do not report txerr and rxerr during bus-off
During bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/pch_can.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/can/pch_can.c +3 -3
@@ -496,6 +496,9 @@ static void pch_can_error(struct net_device *ndev, u32 status) cf->can_id |=CAN_ERR_BUSOFF ; priv->can.can_stats.bus_off++;can_bus_off (ndev); + }else { + cf->data[6 ] = errc &PCH_TEC ; + cf->data[7 ] = (errc &PCH_REC ) >>8 ; } errc =ioread32 (&priv->regs->errc);
@@ -556,9 +559,6 @@ static void pch_can_error(struct net_device *ndev, u32 status)break ; } - cf->data[6 ] = errc &PCH_TEC ; - cf->data[7 ] = (errc &PCH_REC ) >>8 ; - priv->can.state = state;netif_receive_skb (skb); }
Signature · 1 line
2.35.1
PATCH v2 2/12 can: rcar_can: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/rcar/rcar_can.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/can/rcar/rcar_can.c +4 -4
@@ -232,11 +232,8 @@ static void rcar_can_error(struct net_device *ndev)if (eifr & (RCAR_CAN_EIFR_EWIF |RCAR_CAN_EIFR_EPIF )) { txerr =readb (&priv->regs->tecr); rxerr =readb (&priv->regs->recr); -if (skb) { +if (skb) cf->can_id |=CAN_ERR_CRTL ; - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; - } }if (eifr &RCAR_CAN_EIFR_BEIF ) {int rx_errors =0 , tx_errors =0 ;
@@ -336,6 +333,9 @@ static void rcar_can_error(struct net_device *ndev)can_bus_off (ndev);if (skb) cf->can_id |=CAN_ERR_BUSOFF ; + }else if (skb) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; }if (eifr &RCAR_CAN_EIFR_ORIF ) {netdev_dbg (priv->ndev,"Receive overrun error interrupt\n" );
Signature · 1 line
2.35.1
PATCH v2 3/12 can: sja1000: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/sja1000/sja1000.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/can/sja1000/sja1000.c +4 -3
@@ -402,9 +402,6 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) txerr = priv->read_reg (priv,SJA1000_TXERR ); rxerr = priv->read_reg (priv,SJA1000_RXERR ); - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; -if (isrc &IRQ_DOI ) {/* data overrun interrupt */ netdev_dbg (dev,"data overrun interrupt\n" );
@@ -426,6 +423,10 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)else state =CAN_STATE_ERROR_ACTIVE ; } +if (state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + }if (isrc &IRQ_BEI ) {/* bus error interrupt */ priv->can.can_stats.bus_error++;
Signature · 1 line
2.35.1
PATCH v2 4/12 can: slcan: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
alloc_can_err_skb() already sets cf to NULL if the allocation fails [1], so the redundant cf = NULL assignment gets removed.
[1] https://elixir.bootlin.com/linux/latest/source/drivers/net/can/dev/skb.c#L187
--- drivers/net/can/slcan/slcan-core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/net/can/slcan/slcan-core.c +5 -7
@@ -306,19 +306,17 @@ static void slc_bump_state(struct slcan *sl)return ; skb =alloc_can_err_skb (dev, &cf); -if (skb) { - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; - }else { - cf =NULL ; - } tx_state = txerr >= rxerr ? state :0 ; rx_state = txerr <= rxerr ? state :0 ;can_change_state (dev, cf, tx_state, rx_state); -if (state ==CAN_STATE_BUS_OFF ) +if (state ==CAN_STATE_BUS_OFF ) {can_bus_off (dev); + }else if (skb) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + }if (skb)netif_rx (skb);
Signature · 1 line
2.35.1
PATCH v2 5/12 can: hi311x: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/spi/hi311x.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/can/spi/hi311x.c +3 -2
@@ -667,8 +667,6 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id) txerr =hi3110_read (spi,HI3110_READ_TEC ); rxerr =hi3110_read (spi,HI3110_READ_REC ); - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; tx_state = txerr >= rxerr ? new_state :0 ; rx_state = txerr <= rxerr ? new_state :0 ;can_change_state (net, cf, tx_state, rx_state);
@@ -681,6 +679,9 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id)hi3110_hw_sleep (spi);break ; } + }else { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; } }
Signature · 1 line
2.35.1
PATCH v2 6/12 can: sun4i_can: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/sun4i_can.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/can/sun4i_can.c +4 -5
@@ -535,11 +535,6 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status) rxerr = (errc >>16 ) &0xFF ; txerr = errc &0xFF ; -if (skb) { - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; - } -if (isrc &SUN4I_INT_DATA_OR ) {/* data overrun interrupt */ netdev_dbg (dev,"data overrun interrupt\n" );
@@ -570,6 +565,10 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status)else state =CAN_STATE_ERROR_ACTIVE ; } +if (skb && state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + }if (isrc &SUN4I_INT_BUS_ERR ) {/* bus error interrupt */ netdev_dbg (dev,"bus error interrupt\n" );
Signature · 1 line
2.35.1
PATCH v2 7/12 can: kvaser_usb_hydra: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +8 -4
@@ -917,8 +917,10 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, new_state < CAN_STATE_BUS_OFF) priv->can.can_stats.restarts++; - cf->data[6 ] = bec->txerr; - cf->data[7 ] = bec->rxerr; +if (new_state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = bec->txerr; + cf->data[7 ] = bec->rxerr; + }netif_rx (skb); }
@@ -1069,8 +1071,10 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv, shhwtstamps->hwtstamp = hwtstamp; cf->can_id |=CAN_ERR_BUSERROR ; - cf->data[6 ] = bec.txerr; - cf->data[7 ] = bec.rxerr; +if (new_state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = bec.txerr; + cf->data[7 ] = bec.rxerr; + }netif_rx (skb);
Signature · 1 line
2.35.1
PATCH v2 8/12 can: kvaser_usb_leaf: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +4 -2
@@ -836,8 +836,10 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,break ; } - cf->data[6 ] = es->txerr; - cf->data[7 ] = es->rxerr; +if (new_state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = es->txerr; + cf->data[7 ] = es->rxerr; + }netif_rx (skb); }
Signature · 1 line
2.35.1
PATCH v2 9/12 can: usb_8dev: do not report txerr and rxerr during bus-off
In reply to Vincent MailholDuring bus off, the error count is greater than 255 and can not fit in a u8.
--- drivers/net/can/usb/usb_8dev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/can/usb/usb_8dev.c +4 -3
@@ -438,9 +438,10 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv,if (rx_errors) stats->rx_errors++; - - cf->data[6 ] = txerr; - cf->data[7 ] = rxerr; +if (priv->can.state !=CAN_STATE_BUS_OFF ) { + cf->data[6 ] = txerr; + cf->data[7 ] = rxerr; + } priv->bec.txerr = txerr; priv->bec.rxerr = rxerr;
Signature · 1 line
2.35.1
PATCH v2 10/12 can: error: specify the values of data[5..7] of CAN error frames
In reply to Vincent MailholCurrently, data[5..7] of struct can_frame, when used as a CAN error frame, are defined as being "controller specific". Device specific behaviours are problematic because it prevents someone from writing code which is portable between devices.
As a matter of fact, data[5] is never used, data[6] is always used to report TX error counter and data[7] is always used to report RX error counter. can-utils also relies on this.
This patch updates the comment in the uapi header to specify that data[5] is reserved (and thus should not be used) and that data[6..7] are used for error counters.
--- include/uapi/linux/can/error.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/uapi/linux/can/error.h +4 -1
@@ -120,6 +120,9 @@#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70/* 0111 0000 */ #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80/* 1000 0000 */ -/* controller specific additional information / data[5..7] */ +/* data[5] is reserved (do not use) */ + +/* TX error counter / data[6] */ +/* RX error counter / data[7] */ #endif /* _UAPI_CAN_ERROR_H */
Signature · 1 line
2.35.1
PATCH v2 11/12 can: add CAN_ERR_CNT flag to notify availability of error counter
In reply to Vincent MailholAdd 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.
--- drivers/net/can/c_can/c_can_main.c | 6 +++--- drivers/net/can/cc770/cc770.c | 1 + drivers/net/can/ctucanfd/ctucanfd_base.c | 5 +++-- drivers/net/can/grcan.c | 1 + drivers/net/can/ifi_canfd/ifi_canfd.c | 4 ++-- drivers/net/can/janz-ican3.c | 4 ++-- drivers/net/can/kvaser_pciefd.c | 2 +- drivers/net/can/m_can/m_can.c | 4 ++-- drivers/net/can/pch_can.c | 1 + drivers/net/can/peak_canfd/peak_canfd.c | 6 +++--- drivers/net/can/rcar/rcar_can.c | 1 + drivers/net/can/rcar/rcar_canfd.c | 4 ++-- drivers/net/can/sja1000/sja1000.c | 1 + drivers/net/can/slcan/slcan-core.c | 1 + drivers/net/can/spi/hi311x.c | 1 + drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c | 1 + drivers/net/can/sun4i_can.c | 1 + drivers/net/can/ti_hecc.c | 1 + drivers/net/can/usb/esd_usb.c | 3 ++- drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c | 2 ++ drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 1 + drivers/net/can/usb/peak_usb/pcan_usb.c | 1 + drivers/net/can/usb/usb_8dev.c | 1 + drivers/net/can/xilinx_can.c | 1 + include/uapi/linux/can/error.h | 2 ++ 25 files changed, 38 insertions(+), 18 deletions(-)
drivers/net/can/c_can/c_can_main.c +3 -3
@@ -953,14 +953,14 @@ static int c_can_handle_state_change(struct net_device *dev,switch (error_type) {case C_CAN_NO_ERROR :/* error warning state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; 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 ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -970,7 +970,7 @@ static int c_can_handle_state_change(struct net_device *dev,break ;case C_CAN_ERROR_PASSIVE :/* error passive state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ;if (rx_err_passive) cf->data[1 ] |=CAN_ERR_CRTL_RX_PASSIVE ;if (bec.txerr >127 )
drivers/net/can/cc770/cc770.c +1 -0
@@ -512,6 +512,7 @@ static int cc770_err(struct net_device *dev, u8 status)/* Use extended functions of the CC770 */ if (priv->control_normal_mode &CTRL_EAF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] =cc770_read_reg (priv, tx_error_counter); cf->data[7 ] =cc770_read_reg (priv, rx_error_counter); }
drivers/net/can/ctucanfd/ctucanfd_base.c +3 -2
@@ -847,7 +847,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)case CAN_STATE_ERROR_PASSIVE : priv->can.can_stats.error_passive++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.rxerr >127 ) ?CAN_ERR_CRTL_RX_PASSIVE :CAN_ERR_CRTL_TX_PASSIVE ;
@@ -858,7 +858,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr)case CAN_STATE_ERROR_WARNING : priv->can.can_stats.error_warning++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] |= (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -867,6 +867,7 @@ static void ctucan_err_interrupt(struct net_device *ndev, u32 isr) }break ;case CAN_STATE_ERROR_ACTIVE : + cf->can_id |=CAN_ERR_CNT ; cf->data[1 ] =CAN_ERR_CRTL_ACTIVE ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr;
drivers/net/can/grcan.c +1 -0
@@ -671,6 +671,7 @@ static void grcan_err(struct net_device *dev, u32 sources, u32 status)/* There are no others at this point */ break ; } + cf.can_id |=CAN_ERR_CNT ; cf.data[6 ] = txerr; cf.data[7 ] = rxerr; priv->can.state = state;
drivers/net/can/ifi_canfd/ifi_canfd.c +2 -2
@@ -492,7 +492,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,switch (new_state) {case CAN_STATE_ERROR_WARNING :/* error warning state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -501,7 +501,7 @@ static int ifi_canfd_handle_state_change(struct net_device *ndev,break ;case CAN_STATE_ERROR_PASSIVE :/* error passive state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] |=CAN_ERR_CRTL_RX_PASSIVE ;if (bec.txerr >127 ) cf->data[1 ] |=CAN_ERR_CRTL_TX_PASSIVE ;
drivers/net/can/janz-ican3.c +2 -2
@@ -1127,7 +1127,7 @@ static int ican3_handle_cevtind(struct ican3_dev *mod, struct ican3_msg *msg)/* bus error interrupt */ if (isrc ==CEVTIND_BEI ) { mod->can.can_stats.bus_error++; - cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR ; + cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR |CAN_ERR_CNT ;switch (ecc &ECC_MASK ) {case ECC_BIT :
@@ -1153,7 +1153,7 @@ static int ican3_handle_cevtind(struct ican3_dev *mod, struct ican3_msg *msg)if (state != mod->can.state && (state ==CAN_STATE_ERROR_WARNING || state ==CAN_STATE_ERROR_PASSIVE )) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ;if (state ==CAN_STATE_ERROR_WARNING ) { mod->can.can_stats.error_warning++; cf->data[1] = (txerr > rxerr) ?
drivers/net/can/kvaser_pciefd.c +1 -1
@@ -1306,7 +1306,7 @@ static int kvaser_pciefd_rx_error_frame(struct kvaser_pciefd_can *can, shhwtstamps->hwtstamp =ns_to_ktime (div_u64 (p->timestamp *1000 , can->kv_pcie->freq_to_ticks_div)); - cf->can_id |=CAN_ERR_BUSERROR ; + cf->can_id |=CAN_ERR_BUSERROR |CAN_ERR_CNT ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr;
drivers/net/can/m_can/m_can.c +2 -2
@@ -741,7 +741,7 @@ static int m_can_handle_state_change(struct net_device *dev,switch (new_state) {case CAN_STATE_ERROR_WARNING :/* error warning state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (bec.txerr > bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -750,7 +750,7 @@ static int m_can_handle_state_change(struct net_device *dev,break ;case CAN_STATE_ERROR_PASSIVE :/* error passive state */ - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; ecr =m_can_read (cdev,M_CAN_ECR );if (ecr &ECR_RP ) cf->data[1 ] |=CAN_ERR_CRTL_RX_PASSIVE ;
drivers/net/can/pch_can.c +1 -0
@@ -497,6 +497,7 @@ static void pch_can_error(struct net_device *ndev, u32 status) priv->can.can_stats.bus_off++;can_bus_off (ndev); }else { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = errc &PCH_TEC ; cf->data[7 ] = (errc &PCH_REC ) >>8 ; }
drivers/net/can/peak_canfd/peak_canfd.c +3 -3
@@ -373,7 +373,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv, priv->can.state =CAN_STATE_ERROR_PASSIVE ; priv->can.can_stats.error_passive++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (priv->bec.txerr > priv->bec.rxerr) ?CAN_ERR_CRTL_TX_PASSIVE :CAN_ERR_CRTL_RX_PASSIVE ;
@@ -386,7 +386,7 @@ static int pucan_handle_status(struct peak_canfd_priv *priv, priv->can.state =CAN_STATE_ERROR_WARNING ; priv->can.can_stats.error_warning++;if (skb) { - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = (priv->bec.txerr > priv->bec.rxerr) ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ;
@@ -430,7 +430,7 @@ static int pucan_handle_cache_critical(struct peak_canfd_priv *priv)return -ENOMEM ; } - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] =CAN_ERR_CRTL_RX_OVERFLOW ; cf->data[6 ] = priv->bec.txerr;
drivers/net/can/rcar/rcar_can.c +1 -0
@@ -334,6 +334,7 @@ static void rcar_can_error(struct net_device *ndev)if (skb) cf->can_id |=CAN_ERR_BUSOFF ; }else if (skb) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/rcar/rcar_canfd.c +2 -2
@@ -1052,7 +1052,7 @@ static void rcar_canfd_error(struct net_device *ndev, u32 cerfl,netdev_dbg (ndev,"Error warning interrupt\n" ); priv->can.state =CAN_STATE_ERROR_WARNING ; priv->can.can_stats.error_warning++; - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = txerr > rxerr ?CAN_ERR_CRTL_TX_WARNING :CAN_ERR_CRTL_RX_WARNING ; cf->data[6 ] = txerr;
@@ -1062,7 +1062,7 @@ static void rcar_canfd_error(struct net_device *ndev, u32 cerfl,netdev_dbg (ndev,"Error passive interrupt\n" ); priv->can.state =CAN_STATE_ERROR_PASSIVE ; priv->can.can_stats.error_passive++; - cf->can_id |=CAN_ERR_CRTL ; + cf->can_id |=CAN_ERR_CRTL |CAN_ERR_CNT ; cf->data[1 ] = txerr > rxerr ?CAN_ERR_CRTL_TX_PASSIVE :CAN_ERR_CRTL_RX_PASSIVE ; cf->data[6 ] = txerr;
drivers/net/can/sja1000/sja1000.c +1 -0
@@ -424,6 +424,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) state =CAN_STATE_ERROR_ACTIVE ; }if (state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/slcan/slcan-core.c +1 -0
@@ -314,6 +314,7 @@ static void slc_bump_state(struct slcan *sl)if (state ==CAN_STATE_BUS_OFF ) {can_bus_off (dev); }else if (skb) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/spi/hi311x.c +1 -0
@@ -680,6 +680,7 @@ static irqreturn_t hi3110_can_ist(int irq, void *dev_id)break ; } }else { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c +1 -0
@@ -1098,6 +1098,7 @@ static int mcp251xfd_handle_cerrif(struct mcp251xfd_priv *priv) err =mcp251xfd_get_berr_counter (priv->ndev, &bec);if (err)return err; + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; }
drivers/net/can/sun4i_can.c +1 -0
@@ -566,6 +566,7 @@ static int sun4i_can_err(struct net_device *dev, u8 isrc, u8 status) state =CAN_STATE_ERROR_ACTIVE ; }if (skb && state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/ti_hecc.c +1 -0
@@ -662,6 +662,7 @@ static void ti_hecc_change_state(struct net_device *ndev,can_change_state (priv->ndev, cf, tx_state, rx_state);if (max (tx_state, rx_state) !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] =hecc_read (priv,HECC_CANTEC ); cf->data[7 ] =hecc_read (priv,HECC_CANREC ); }
drivers/net/can/usb/esd_usb.c +2 -1
@@ -265,7 +265,8 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv, priv->can.can_stats.bus_error++; stats->rx_errors++; - cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR ; + cf->can_id |=CAN_ERR_PROT |CAN_ERR_BUSERROR | +CAN_ERR_CNT ;switch (ecc &SJA1000_ECC_MASK ) {case SJA1000_ECC_BIT :
drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c +2 -0
@@ -918,6 +918,7 @@ static void kvaser_usb_hydra_update_state(struct kvaser_usb_net_priv *priv, priv->can.can_stats.restarts++;if (new_state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = bec->txerr; cf->data[7 ] = bec->rxerr; }
@@ -1072,6 +1073,7 @@ kvaser_usb_hydra_error_frame(struct kvaser_usb_net_priv *priv, cf->can_id |=CAN_ERR_BUSERROR ;if (new_state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = bec.txerr; cf->data[7 ] = bec.rxerr; }
drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +1 -0
@@ -837,6 +837,7 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev, }if (new_state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = es->txerr; cf->data[7 ] = es->rxerr; }
drivers/net/can/usb/peak_usb/pcan_usb.c +1 -0
@@ -506,6 +506,7 @@ static int pcan_usb_decode_error(struct pcan_usb_msg_context *mc, u8 n,/* Supply TX/RX error counters in case of * controller error. */ + cf->can_id =CAN_ERR_CNT ; cf->data[6 ] = mc->pdev->bec.txerr; cf->data[7 ] = mc->pdev->bec.rxerr; }
drivers/net/can/usb/usb_8dev.c +1 -0
@@ -439,6 +439,7 @@ static void usb_8dev_rx_err_msg(struct usb_8dev_priv *priv,if (rx_errors) stats->rx_errors++;if (priv->can.state !=CAN_STATE_BUS_OFF ) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
drivers/net/can/xilinx_can.c +1 -0
@@ -965,6 +965,7 @@ static void xcan_set_error_state(struct net_device *ndev,can_change_state (ndev, cf, tx_state, rx_state);if (cf) { + cf->can_id |=CAN_ERR_CNT ; cf->data[6 ] = txerr; cf->data[7 ] = rxerr; }
include/uapi/linux/can/error.h +2 -0
@@ -57,6 +57,8 @@#define CAN_ERR_BUSOFF 0x00000040U/* bus off */ #define CAN_ERR_BUSERROR 0x00000080U/* bus error (may flood!) */ #define CAN_ERR_RESTARTED 0x00000100U/* controller restarted */ +#define CAN_ERR_CNT 0x00000200U/* TX error counter / data[6] */ +/* RX error counter / data[7] */ /* arbitration lost in bit ... / data[0] */ #define CAN_ERR_LOSTARB_UNSPEC 0x00/* unspecified */
Signature · 1 line
2.35.1
PATCH v2 12/12 can: error: add definitions for the different CAN error thresholds
In reply to Vincent MailholCurrently, drivers are using magic numbers to derive the CAN error states from the error counter. Add three macro declarations to remediate this.
For reference, the error-active, error-passive and bus-off are defined in ISO 11898, section 12.1.4.2 "Error counting". Although ISO 11898 does not define error-warning state, this extra value is also commonly used and is thus also added.
---
Strictly speaking, this does not need to be part of the uapi but I still think it is beneficial to have it here. Thank you for your comments.
Also, if anyone knows which standard originally defined the error-warning, let me know.
--- include/uapi/linux/can/error.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/uapi/linux/can/error.h +13 -0
@@ -127,4 +127,17 @@/* TX error counter / data[6] */ /* RX error counter / data[7] */ +/* CAN state thresholds +* +* Error counter Error state +* ----------------------------------- +* 0 - 95 Error-active +* 96 - 127 Error-warning +* 128 - 255 Error-passive +* 256 and greater Bus-off +*/ +#define CAN_ERROR_WARNING_THRESHOLD 96 +#define CAN_ERROR_PASSIVE_THRESHOLD 128 +#define CAN_BUS_OFF_THRESHOLD 256 +#endif /* _UAPI_CAN_ERROR_H */
Signature · 1 line
2.35.1
Marc Kleine-Budde
maintainerQuoted 19 lines · Vincent Mailhol
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_idthat data[6..7] were populated (in order to be consistent with other fields).
Quoted 7 lines
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).
IMHO the patches 1..10 are not so critical that they need to go upstream via net. Especially that we're already at -rc7. I'll take all via can-next, OK?
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 24 lines · Marc Kleine-Budde
Quoted 23 lines · Vincent Mailhol
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_idthat 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.
Quoted 7 lines
Quoted 3 lines
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).IMHO the patches 1..10 are not so critical that they need to go upstream via net. Especially that we're already at -rc7. I'll take all via can-next, OK?
Absolutely OK. Nothing critical here.