diff mbox series

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

Message ID 20240729-rockchip-canfd-v1-11-fa1250fd6be3@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series can: rockchip_canfd: add support for CAN-FD IP core found on Rockchip RK3568 | expand

Commit Message

Marc Kleine-Budde July 29, 2024, 1:05 p.m. UTC
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(+)

Comments

Simon Horman July 30, 2024, 4:37 p.m. UTC | #1
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.

...
Marc Kleine-Budde July 31, 2024, 8:02 a.m. UTC | #2
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
diff mbox series

Patch

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,