Linux CAN drivers development
 help / color / mirror / Atom feed
* [RFC PATCH 0/6] This series originates from some tests I ran on a CAN communication for
@ 2024-10-14 15:24 Dario Binacchi
  2024-10-14 15:24 ` [RFC PATCH 1/6] can: dev: add generic function can_update_bus_error_stats() Dario Binacchi
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Dario Binacchi @ 2024-10-14 15:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-amarula, michael, Dario Binacchi, Alexandra Winter,
	Carolina Jubran, David S. Miller, Eric Dumazet, Frank Li,
	Gal Pressman, Haibo Chen, Han Xu, Jakub Kicinski, Kory Maincent,
	Marc Kleine-Budde, Paolo Abeni, Rob Herring, Sabrina Dubroca,
	Shannon Nelson, Uwe Kleine-König, Vincent Mailhol, linux-can,
	netdev

one of my clients that reports sporadic errors. After enabling BERR
reporting, I was surprised that the command:

ip -details -statistics link show can0

did not display the occurrence of different types of errors, but only the
generic ones for reception and transmission. In trying to export this
information, I felt that the code related to managing statistics and handling
CAN errors (CRC, STUF, BIT, ACK, and FORM) was quite duplicated in the
implementation of various drivers, and there wasn't a generic function like
in the case of state changes (i. e. can_change_state). This led to the idea
of adding can_update_bus_error_stats() and the helpers for setting up the
CAN error frame.

Regarding patch 5/6 ("can: netlink: extend stats to the error types (ack,
CRC, form, ..."), I ran

./scripts/check-uapi.sh

which found

"error - 1/934 UAPI headers compatible with x86 appear _not_ to be backwards
compatible."

I included it in the series because I am currently interested in understanding
whether the idea behind each of the submitted patches makes sense, and I can
adjust them later if the response is positive, following your suggestions.


Dario Binacchi (6):
  can: dev: add generic function can_update_bus_error_stats()
  can: flexcan: use can_update_bus_error_stats()
  can: dev: add helper macros to setup an error frame
  can: flexcan: use helper macros to setup the error frame
  can: netlink: extend stats to the error types (ack, CRC, form, ...)
  can: dev: update the error types stats (ack, CRC, form, ...)

 drivers/net/can/dev/dev.c              | 45 ++++++++++++++++++++++++++
 drivers/net/can/flexcan/flexcan-core.c | 29 +++++------------
 include/linux/can/dev.h                | 28 ++++++++++++++++
 include/uapi/linux/can/netlink.h       |  6 ++++
 4 files changed, 87 insertions(+), 21 deletions(-)

-- 
2.43.0


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

* [RFC PATCH 1/6] can: dev: add generic function can_update_bus_error_stats()
  2024-10-14 15:24 [RFC PATCH 0/6] This series originates from some tests I ran on a CAN communication for Dario Binacchi
@ 2024-10-14 15:24 ` Dario Binacchi
  2024-10-14 15:24 ` [RFC PATCH 2/6] can: flexcan: use can_update_bus_error_stats() Dario Binacchi
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Dario Binacchi @ 2024-10-14 15:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-amarula, michael, Dario Binacchi, Alexandra Winter,
	David S. Miller, Eric Dumazet, Gal Pressman, Jakub Kicinski,
	Kory Maincent, Marc Kleine-Budde, Paolo Abeni, Sabrina Dubroca,
	Shannon Nelson, Vincent Mailhol, linux-can, netdev

The function aims to generalize the statistics update by centralizing
the related code, thus avoiding code duplication.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

 drivers/net/can/dev/dev.c | 30 ++++++++++++++++++++++++++++++
 include/linux/can/dev.h   |  1 +
 2 files changed, 31 insertions(+)

diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c
index 6792c14fd7eb..0a3b1aad405b 100644
--- a/drivers/net/can/dev/dev.c
+++ b/drivers/net/can/dev/dev.c
@@ -16,6 +16,36 @@
 #include <linux/gpio/consumer.h>
 #include <linux/of.h>
 
+void can_update_bus_error_stats(struct net_device *dev, struct can_frame *cf)
+{
+	struct can_priv *priv = netdev_priv(dev);
+	bool rx_errors = false, tx_errors = false;
+
+	if (!cf || !(cf->can_id & (CAN_ERR_PROT | CAN_ERR_BUSERROR)))
+		return;
+
+	priv = netdev_priv(dev);
+	priv->can_stats.bus_error++;
+
+	if ((cf->can_id & CAN_ERR_ACK) && cf->data[3] == CAN_ERR_PROT_LOC_ACK)
+		tx_errors = true;
+	else if (cf->data[2] & (CAN_ERR_PROT_BIT1 | CAN_ERR_PROT_BIT0))
+		tx_errors = true;
+
+	if (cf->data[2] & (CAN_ERR_PROT_FORM | CAN_ERR_PROT_STUFF))
+		rx_errors = true;
+	else if ((cf->data[2] & CAN_ERR_PROT_BIT) &&
+		 (cf->data[3] == CAN_ERR_PROT_LOC_CRC_SEQ))
+		rx_errors = true;
+
+	if (rx_errors)
+		dev->stats.rx_errors++;
+
+	if (tx_errors)
+		dev->stats.tx_errors++;
+}
+EXPORT_SYMBOL_GPL(can_update_bus_error_stats);
+
 static void can_update_state_error_stats(struct net_device *dev,
 					 enum can_state new_state)
 {
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 23492213ea35..0977656b366d 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -201,6 +201,7 @@ void can_state_get_by_berr_counter(const struct net_device *dev,
 				   enum can_state *rx_state);
 void can_change_state(struct net_device *dev, struct can_frame *cf,
 		      enum can_state tx_state, enum can_state rx_state);
+void can_update_bus_error_stats(struct net_device *dev, struct can_frame *cf);
 
 #ifdef CONFIG_OF
 void of_can_transceiver(struct net_device *dev);
-- 
2.43.0


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

* [RFC PATCH 2/6] can: flexcan: use can_update_bus_error_stats()
  2024-10-14 15:24 [RFC PATCH 0/6] This series originates from some tests I ran on a CAN communication for Dario Binacchi
  2024-10-14 15:24 ` [RFC PATCH 1/6] can: dev: add generic function can_update_bus_error_stats() Dario Binacchi
@ 2024-10-14 15:24 ` Dario Binacchi
  2024-10-14 15:24 ` [RFC PATCH 3/6] can: dev: add helper macros to setup an error frame Dario Binacchi
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Dario Binacchi @ 2024-10-14 15:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-amarula, michael, Dario Binacchi, David S. Miller,
	Eric Dumazet, Frank Li, Haibo Chen, Jakub Kicinski,
	Marc Kleine-Budde, Paolo Abeni, Rob Herring,
	Uwe Kleine-König, Vincent Mailhol, linux-can, netdev

The patch delegates the statistics update in case of bus error to the
can_update_bus_error_stats().

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

 drivers/net/can/flexcan/flexcan-core.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
index ac1a860986df..790b8e162d73 100644
--- a/drivers/net/can/flexcan/flexcan-core.c
+++ b/drivers/net/can/flexcan/flexcan-core.c
@@ -819,7 +819,6 @@ static void flexcan_irq_bus_err(struct net_device *dev, u32 reg_esr)
 	struct flexcan_regs __iomem *regs = priv->regs;
 	struct sk_buff *skb;
 	struct can_frame *cf;
-	bool rx_errors = false, tx_errors = false;
 	u32 timestamp;
 	int err;
 
@@ -834,41 +833,31 @@ static void flexcan_irq_bus_err(struct net_device *dev, u32 reg_esr)
 	if (reg_esr & FLEXCAN_ESR_BIT1_ERR) {
 		netdev_dbg(dev, "BIT1_ERR irq\n");
 		cf->data[2] |= CAN_ERR_PROT_BIT1;
-		tx_errors = true;
 	}
 	if (reg_esr & FLEXCAN_ESR_BIT0_ERR) {
 		netdev_dbg(dev, "BIT0_ERR irq\n");
 		cf->data[2] |= CAN_ERR_PROT_BIT0;
-		tx_errors = true;
 	}
 	if (reg_esr & FLEXCAN_ESR_ACK_ERR) {
 		netdev_dbg(dev, "ACK_ERR irq\n");
 		cf->can_id |= CAN_ERR_ACK;
 		cf->data[3] = CAN_ERR_PROT_LOC_ACK;
-		tx_errors = true;
 	}
 	if (reg_esr & FLEXCAN_ESR_CRC_ERR) {
 		netdev_dbg(dev, "CRC_ERR irq\n");
 		cf->data[2] |= CAN_ERR_PROT_BIT;
 		cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ;
-		rx_errors = true;
 	}
 	if (reg_esr & FLEXCAN_ESR_FRM_ERR) {
 		netdev_dbg(dev, "FRM_ERR irq\n");
 		cf->data[2] |= CAN_ERR_PROT_FORM;
-		rx_errors = true;
 	}
 	if (reg_esr & FLEXCAN_ESR_STF_ERR) {
 		netdev_dbg(dev, "STF_ERR irq\n");
 		cf->data[2] |= CAN_ERR_PROT_STUFF;
-		rx_errors = true;
 	}
 
-	priv->can.can_stats.bus_error++;
-	if (rx_errors)
-		dev->stats.rx_errors++;
-	if (tx_errors)
-		dev->stats.tx_errors++;
+	can_update_bus_error_stats(dev, cf);
 
 	err = can_rx_offload_queue_timestamp(&priv->offload, skb, timestamp);
 	if (err)
-- 
2.43.0


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

* [RFC PATCH 3/6] can: dev: add helper macros to setup an error frame
  2024-10-14 15:24 [RFC PATCH 0/6] This series originates from some tests I ran on a CAN communication for Dario Binacchi
  2024-10-14 15:24 ` [RFC PATCH 1/6] can: dev: add generic function can_update_bus_error_stats() Dario Binacchi
  2024-10-14 15:24 ` [RFC PATCH 2/6] can: flexcan: use can_update_bus_error_stats() Dario Binacchi
@ 2024-10-14 15:24 ` Dario Binacchi
  2024-10-14 20:00   ` Marc Kleine-Budde
  2024-10-14 15:24 ` [RFC PATCH 4/6] can: flexcan: use helper macros to setup the " Dario Binacchi
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Dario Binacchi @ 2024-10-14 15:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-amarula, michael, Dario Binacchi, Marc Kleine-Budde,
	Vincent Mailhol, linux-can

These helpers can prevent errors and code duplication when setting up a
CAN error frame.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

 include/linux/can/dev.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 0977656b366d..0202526be6b0 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -23,6 +23,33 @@
 #include <linux/ethtool.h>
 #include <linux/netdevice.h>
 
+#define CAN_FRAME_ERROR_INIT(cf) \
+	((cf)->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR)
+
+#define CAN_FRAME_SET_ERR_BIT0(cf) \
+	((cf)->data[2] |= CAN_ERR_PROT_BIT0)
+
+#define CAN_FRAME_SET_ERR_BIT1(cf) \
+	((cf)->data[2] |= CAN_ERR_PROT_BIT1)
+
+#define CAN_FRAME_SET_ERR_ACK(cf) \
+	do { \
+		((cf)->can_id |= CAN_ERR_ACK); \
+		((cf)->data[3] = CAN_ERR_PROT_LOC_ACK); \
+	} while (0)
+
+#define CAN_FRAME_SET_ERR_CRC(cf) \
+	do { \
+		((cf)->data[2] |= CAN_ERR_PROT_BIT); \
+		((cf)->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ); \
+	} while (0)
+
+#define CAN_FRAME_SET_ERR_FORM(cf) \
+	((cf)->data[2] |= CAN_ERR_PROT_FORM)
+
+#define CAN_FRAME_SET_ERR_STUFF(cf) \
+	((cf)->data[2] |= CAN_ERR_PROT_STUFF)
+
 /*
  * CAN mode
  */
-- 
2.43.0


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

* [RFC PATCH 4/6] can: flexcan: use helper macros to setup the error frame
  2024-10-14 15:24 [RFC PATCH 0/6] This series originates from some tests I ran on a CAN communication for Dario Binacchi
                   ` (2 preceding siblings ...)
  2024-10-14 15:24 ` [RFC PATCH 3/6] can: dev: add helper macros to setup an error frame Dario Binacchi
@ 2024-10-14 15:24 ` Dario Binacchi
  2024-10-14 15:24 ` [RFC PATCH 5/6] can: netlink: extend stats to the error types (ack, CRC, form, ...) Dario Binacchi
  2024-10-14 15:24 ` [RFC PATCH 6/6] can: dev: update the error types stats " Dario Binacchi
  5 siblings, 0 replies; 9+ messages in thread
From: Dario Binacchi @ 2024-10-14 15:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-amarula, michael, Dario Binacchi, David S. Miller,
	Eric Dumazet, Frank Li, Haibo Chen, Han Xu, Jakub Kicinski,
	Marc Kleine-Budde, Paolo Abeni, Rob Herring,
	Uwe Kleine-König, Vincent Mailhol, linux-can, netdev

The patch replaces the code that directly accesses cf->data[] for setting
up the CAN error frame with the appropriate helper macros.

Se hai bisogno di ulteriori traduzioni o modifiche, non esitare a chiedere!
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

 drivers/net/can/flexcan/flexcan-core.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/net/can/flexcan/flexcan-core.c b/drivers/net/can/flexcan/flexcan-core.c
index 790b8e162d73..ca620c8f028c 100644
--- a/drivers/net/can/flexcan/flexcan-core.c
+++ b/drivers/net/can/flexcan/flexcan-core.c
@@ -828,33 +828,31 @@ static void flexcan_irq_bus_err(struct net_device *dev, u32 reg_esr)
 	if (unlikely(!skb))
 		return;
 
-	cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
+	CAN_FRAME_ERROR_INIT(cf);
 
 	if (reg_esr & FLEXCAN_ESR_BIT1_ERR) {
 		netdev_dbg(dev, "BIT1_ERR irq\n");
-		cf->data[2] |= CAN_ERR_PROT_BIT1;
+		CAN_FRAME_SET_ERR_BIT1(cf);
 	}
 	if (reg_esr & FLEXCAN_ESR_BIT0_ERR) {
 		netdev_dbg(dev, "BIT0_ERR irq\n");
-		cf->data[2] |= CAN_ERR_PROT_BIT0;
+		CAN_FRAME_SET_ERR_BIT0(cf);
 	}
 	if (reg_esr & FLEXCAN_ESR_ACK_ERR) {
 		netdev_dbg(dev, "ACK_ERR irq\n");
-		cf->can_id |= CAN_ERR_ACK;
-		cf->data[3] = CAN_ERR_PROT_LOC_ACK;
+		CAN_FRAME_SET_ERR_ACK(cf);
 	}
 	if (reg_esr & FLEXCAN_ESR_CRC_ERR) {
 		netdev_dbg(dev, "CRC_ERR irq\n");
-		cf->data[2] |= CAN_ERR_PROT_BIT;
-		cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ;
+		CAN_FRAME_SET_ERR_CRC(cf);
 	}
 	if (reg_esr & FLEXCAN_ESR_FRM_ERR) {
 		netdev_dbg(dev, "FRM_ERR irq\n");
-		cf->data[2] |= CAN_ERR_PROT_FORM;
+		CAN_FRAME_SET_ERR_FORM(cf);
 	}
 	if (reg_esr & FLEXCAN_ESR_STF_ERR) {
 		netdev_dbg(dev, "STF_ERR irq\n");
-		cf->data[2] |= CAN_ERR_PROT_STUFF;
+		CAN_FRAME_SET_ERR_STUFF(cf);
 	}
 
 	can_update_bus_error_stats(dev, cf);
-- 
2.43.0


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

* [RFC PATCH 5/6] can: netlink: extend stats to the error types (ack, CRC, form, ...)
  2024-10-14 15:24 [RFC PATCH 0/6] This series originates from some tests I ran on a CAN communication for Dario Binacchi
                   ` (3 preceding siblings ...)
  2024-10-14 15:24 ` [RFC PATCH 4/6] can: flexcan: use helper macros to setup the " Dario Binacchi
@ 2024-10-14 15:24 ` Dario Binacchi
  2024-10-14 15:24 ` [RFC PATCH 6/6] can: dev: update the error types stats " Dario Binacchi
  5 siblings, 0 replies; 9+ messages in thread
From: Dario Binacchi @ 2024-10-14 15:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-amarula, michael, Dario Binacchi, Marc Kleine-Budde,
	Vincent Mailhol, linux-can

The CAN bus protocol specifies 5 CAN error types:

- Bit Error [Transmitter]
- Bit Stuffing Error [Receiver]
- Form Error [Receiver]
- ACK Error (Acknowledgment) [Transmitter]
- CRC Error (Cyclic Redundancy Check) [Receiver]

The patch also adds the corresponding counters to the statistics. Since
each device/driver can determine which of these errors has occurred, why
not export this information along with the more general counters?

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---

 include/uapi/linux/can/netlink.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/uapi/linux/can/netlink.h b/include/uapi/linux/can/netlink.h
index 02ec32d69474..8b33549e7e19 100644
--- a/include/uapi/linux/can/netlink.h
+++ b/include/uapi/linux/can/netlink.h
@@ -114,6 +114,12 @@ struct can_device_stats {
 	__u32 bus_off;		/* Changes to bus off state */
 	__u32 arbitration_lost; /* Arbitration lost errors */
 	__u32 restarts;		/* CAN controller re-starts */
+	__u32 bit_error;        /* Bit error */
+	__u32 stuff_error;      /* Bit stuffing error */
+	__u32 form_error;       /* form error */
+	__u32 ack_error;        /* ack error */
+	__u32 crc_error;        /* CRC error */
+	__u32 pad;
 };
 
 /*
-- 
2.43.0


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

* [RFC PATCH 6/6] can: dev: update the error types stats (ack, CRC, form, ...)
  2024-10-14 15:24 [RFC PATCH 0/6] This series originates from some tests I ran on a CAN communication for Dario Binacchi
                   ` (4 preceding siblings ...)
  2024-10-14 15:24 ` [RFC PATCH 5/6] can: netlink: extend stats to the error types (ack, CRC, form, ...) Dario Binacchi
@ 2024-10-14 15:24 ` Dario Binacchi
  5 siblings, 0 replies; 9+ messages in thread
From: Dario Binacchi @ 2024-10-14 15:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-amarula, michael, Dario Binacchi, Carolina Jubran,
	David S. Miller, Eric Dumazet, Gal Pressman, Jakub Kicinski,
	Kory Maincent, Marc Kleine-Budde, Paolo Abeni, Sabrina Dubroca,
	Shannon Nelson, Vincent Mailhol, linux-can, netdev

The patch modifies can_update_bus_error_stats() by also updating the
counters related to the types of CAN errors.

Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>

---

 drivers/net/can/dev/dev.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c
index 0a3b1aad405b..f035e68044b3 100644
--- a/drivers/net/can/dev/dev.c
+++ b/drivers/net/can/dev/dev.c
@@ -27,16 +27,31 @@ void can_update_bus_error_stats(struct net_device *dev, struct can_frame *cf)
 	priv = netdev_priv(dev);
 	priv->can_stats.bus_error++;
 
-	if ((cf->can_id & CAN_ERR_ACK) && cf->data[3] == CAN_ERR_PROT_LOC_ACK)
+	if ((cf->can_id & CAN_ERR_ACK) && cf->data[3] == CAN_ERR_PROT_LOC_ACK) {
+		priv->can_stats.ack_error++;
 		tx_errors = true;
-	else if (cf->data[2] & (CAN_ERR_PROT_BIT1 | CAN_ERR_PROT_BIT0))
+	}
+
+	if (cf->data[2] & (CAN_ERR_PROT_BIT1 | CAN_ERR_PROT_BIT0)) {
+		priv->can_stats.bit_error++;
 		tx_errors = true;
+	}
 
-	if (cf->data[2] & (CAN_ERR_PROT_FORM | CAN_ERR_PROT_STUFF))
+	if (cf->data[2] & CAN_ERR_PROT_FORM) {
+		priv->can_stats.form_error++;
 		rx_errors = true;
-	else if ((cf->data[2] & CAN_ERR_PROT_BIT) &&
-		 (cf->data[3] == CAN_ERR_PROT_LOC_CRC_SEQ))
+	}
+
+	if (cf->data[2] & CAN_ERR_PROT_STUFF) {
+		priv->can_stats.stuff_error++;
 		rx_errors = true;
+	}
+
+	if ((cf->data[2] & CAN_ERR_PROT_BIT) &&
+	    cf->data[3] == CAN_ERR_PROT_LOC_CRC_SEQ) {
+		priv->can_stats.crc_error++;
+		rx_errors = true;
+	}
 
 	if (rx_errors)
 		dev->stats.rx_errors++;
-- 
2.43.0


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

* Re: [RFC PATCH 3/6] can: dev: add helper macros to setup an error frame
  2024-10-14 15:24 ` [RFC PATCH 3/6] can: dev: add helper macros to setup an error frame Dario Binacchi
@ 2024-10-14 20:00   ` Marc Kleine-Budde
  2024-10-15  7:47     ` Dario Binacchi
  0 siblings, 1 reply; 9+ messages in thread
From: Marc Kleine-Budde @ 2024-10-14 20:00 UTC (permalink / raw)
  To: Dario Binacchi
  Cc: linux-kernel, linux-amarula, michael, Vincent Mailhol, linux-can

[-- Attachment #1: Type: text/plain, Size: 532 bytes --]

On 14.10.2024 17:24:18, Dario Binacchi wrote:
> These helpers can prevent errors and code duplication when setting up a
> CAN error frame.

I personally don't like the ideas of using macros here. Is there a
reason not to use static inline functions?

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

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

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

* Re: [RFC PATCH 3/6] can: dev: add helper macros to setup an error frame
  2024-10-14 20:00   ` Marc Kleine-Budde
@ 2024-10-15  7:47     ` Dario Binacchi
  0 siblings, 0 replies; 9+ messages in thread
From: Dario Binacchi @ 2024-10-15  7:47 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: linux-kernel, linux-amarula, michael, Vincent Mailhol, linux-can

Hello Marc,

On Mon, Oct 14, 2024 at 10:00 PM Marc Kleine-Budde <mkl@pengutronix.de> wrote:
>
> On 14.10.2024 17:24:18, Dario Binacchi wrote:
> > These helpers can prevent errors and code duplication when setting up a
> > CAN error frame.
>
> I personally don't like the ideas of using macros here. Is there a
> reason not to use static inline functions?

I thought that the use of macros would certainly not introduce
additional overhead
compared to the previous version. In version 2, I will replace the
macros with inline
functions.

I noticed that the ACK error is handled differently by the drivers.

bxcan, flexcan, slcan, rcar_can.c, and xilinx_can, for example:
cf->can_id |= CAN_ERR_ACK;
cf->data[3] = CAN_ERR_PROT_LOC_ACK;

at91_can, mcp251xfd-core:
cf->can_id |= CAN_ERR_ACK;
cf->data[2] |= CAN_ERR_PROT_TX;

cc770, kvaser_pciefd and es58x_core only
cf->can_id |= CAN_ERR_ACK;

So, what is the correct/best way to notify a CAN frame error from an ACK?

Thanks and regards,
Dario

>
> Marc
>
> --
> Pengutronix e.K.                 | Marc Kleine-Budde          |
> Embedded Linux                   | https://www.pengutronix.de |
> Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
> Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |



-- 

Dario Binacchi

Senior Embedded Linux Developer

dario.binacchi@amarulasolutions.com

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
info@amarulasolutions.com

www.amarulasolutions.com

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

end of thread, other threads:[~2024-10-15  7:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14 15:24 [RFC PATCH 0/6] This series originates from some tests I ran on a CAN communication for Dario Binacchi
2024-10-14 15:24 ` [RFC PATCH 1/6] can: dev: add generic function can_update_bus_error_stats() Dario Binacchi
2024-10-14 15:24 ` [RFC PATCH 2/6] can: flexcan: use can_update_bus_error_stats() Dario Binacchi
2024-10-14 15:24 ` [RFC PATCH 3/6] can: dev: add helper macros to setup an error frame Dario Binacchi
2024-10-14 20:00   ` Marc Kleine-Budde
2024-10-15  7:47     ` Dario Binacchi
2024-10-14 15:24 ` [RFC PATCH 4/6] can: flexcan: use helper macros to setup the " Dario Binacchi
2024-10-14 15:24 ` [RFC PATCH 5/6] can: netlink: extend stats to the error types (ack, CRC, form, ...) Dario Binacchi
2024-10-14 15:24 ` [RFC PATCH 6/6] can: dev: update the error types stats " Dario Binacchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox