[PATCH can-next 11/21] can: rockchip_canfd: add functions to check if CAN-FD frames are equal

Marc Kleine-Budde posted 21 patches 1 year, 6 months ago
There is a newer version of this series
[PATCH can-next 11/21] can: rockchip_canfd: add functions to check if CAN-FD frames are equal
Posted by Marc Kleine-Budde 1 year, 6 months ago
Add a pair new functions to check if 2 struct canfd_frame are equal.
The 1st checks if the header of the CAN frames are equal, the 2nd
checks if the data portion are equal:

- rkcanfd_can_frame_header_equal()
- rkcanfd_can_frame_data_equal()

This functionality is needed in the next patch.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/rockchip/rockchip_canfd-rx.c | 42 ++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c
index c7b316e52580..df5280375ca9 100644
--- a/drivers/net/can/rockchip/rockchip_canfd-rx.c
+++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c
@@ -6,6 +6,48 @@
 
 #include "rockchip_canfd.h"
 
+static bool rkcanfd_can_frame_header_equal(const struct canfd_frame *const cfd1,
+					   const struct canfd_frame *const cfd2,
+					   const bool is_canfd)
+{
+	const u8 mask_flags = CANFD_BRS | CANFD_ESI | CANFD_FDF;
+	canid_t mask = CAN_EFF_FLAG;
+
+	if (canfd_sanitize_len(cfd1->len) != canfd_sanitize_len(cfd2->len))
+		return false;
+
+	if (!is_canfd)
+		mask |= CAN_RTR_FLAG;
+
+	if (cfd1->can_id & CAN_EFF_FLAG)
+		mask |= CAN_EFF_MASK;
+	else
+		mask |= CAN_SFF_MASK;
+
+	if ((cfd1->can_id & mask) != (cfd2->can_id & mask))
+		return false;
+
+	if (is_canfd &&
+	    (cfd1->flags & mask_flags) != (cfd2->flags & mask_flags))
+		return false;
+
+	return true;
+}
+
+static bool rkcanfd_can_frame_data_equal(const struct canfd_frame *cfd1,
+					 const struct canfd_frame *cfd2,
+					 const bool is_canfd)
+{
+	u8 len;
+
+	if (!is_canfd && (cfd1->can_id & CAN_RTR_FLAG))
+		return true;
+
+	len = canfd_sanitize_len(cfd1->len);
+
+	return !memcmp(cfd1->data, cfd2->data, len);
+}
+
 static unsigned int
 rkcanfd_fifo_header_to_cfd_header(const struct rkcanfd_priv *priv,
 				  const struct rkcanfd_fifo_header *header,

-- 
2.43.0
Re: [PATCH can-next 11/21] can: rockchip_canfd: add functions to check if CAN-FD frames are equal
Posted by Simon Horman 1 year, 6 months ago
On Mon, Jul 29, 2024 at 03:05:42PM +0200, Marc Kleine-Budde wrote:
> Add a pair new functions to check if 2 struct canfd_frame are equal.
> The 1st checks if the header of the CAN frames are equal, the 2nd
> checks if the data portion are equal:
> 
> - rkcanfd_can_frame_header_equal()
> - rkcanfd_can_frame_data_equal()
> 
> This functionality is needed in the next patch.

nit: I would squash this into the next patch as
     rkcanfd_can_frame_header_equal() is defined but
     unused in this patch, which is flagged by
     allmodconfig W=1 builds.

...
Re: [PATCH can-next 11/21] can: rockchip_canfd: add functions to check if CAN-FD frames are equal
Posted by Marc Kleine-Budde 1 year, 6 months ago
On 30.07.2024 17:37:30, Simon Horman wrote:
> On Mon, Jul 29, 2024 at 03:05:42PM +0200, Marc Kleine-Budde wrote:
> > Add a pair new functions to check if 2 struct canfd_frame are equal.
> > The 1st checks if the header of the CAN frames are equal, the 2nd
> > checks if the data portion are equal:
> > 
> > - rkcanfd_can_frame_header_equal()
> > - rkcanfd_can_frame_data_equal()
> > 
> > This functionality is needed in the next patch.
> 
> nit: I would squash this into the next patch as
>      rkcanfd_can_frame_header_equal() is defined but
>      unused in this patch, which is flagged by
>      allmodconfig W=1 builds.

Makes sense, done.

Thanks,
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   |