All of lore.kernel.org
 help / color / mirror / Atom feed
From: pisa@cmp.felk.cvut.cz
To: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Cc: Marek Vasut <marex@denx.de>,
	Oliver Hartkopp <socketcan@hartkopp.net>,
	Jiri Novak <jnovak@fel.cvut.cz>,
	Stefan Hajnoczi <stefanha@gmail.com>,
	Deniz Eren <deniz.eren@icloud.com>,
	Markus Armbruster <armbru@redhat.com>,
	Oleksij Rempel <o.rempel@pengutronix.de>,
	Konrad Frederic <frederic.konrad@adacore.com>,
	Jan Charvat <charvj10@fel.cvut.cz>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	Ondrej Ille <ondrej.ille@gmail.com>,
	Pavel Pisa <pisa@cmp.felk.cvut.cz>
Subject: [PATCH v1 3/6] net/can: Add can_dlc2len and can_len2dlc for CAN FD.
Date: Tue, 14 Jul 2020 14:20:16 +0200	[thread overview]
Message-ID: <30758547c49f254b3965fc12500735bea8265c97.1594725647.git.pisa@cmp.felk.cvut.cz> (raw)
In-Reply-To: <cover.1594725647.git.pisa@cmp.felk.cvut.cz>

From: Jan Charvat <charvj10@fel.cvut.cz>

Signed-off-by: Jan Charvat <charvj10@fel.cvut.cz>
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
---
 include/net/can_emu.h |  4 ++++
 net/can/can_core.c    | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/net/can_emu.h b/include/net/can_emu.h
index c6164dcfb4..7d395fbb9b 100644
--- a/include/net/can_emu.h
+++ b/include/net/can_emu.h
@@ -127,4 +127,8 @@ int can_bus_client_set_filters(CanBusClientState *,
                                const struct qemu_can_filter *filters,
                                size_t filters_cnt);
 
+uint8_t can_dlc2len(uint8_t can_dlc);
+
+uint8_t can_len2dlc(uint8_t len);
+
 #endif
diff --git a/net/can/can_core.c b/net/can/can_core.c
index 90f4d8576a..0115d78794 100644
--- a/net/can/can_core.c
+++ b/net/can/can_core.c
@@ -33,6 +33,42 @@
 #include "net/can_emu.h"
 #include "qom/object_interfaces.h"
 
+/* CAN DLC to real data length conversion helpers */
+
+static const uint8_t dlc2len[] = {
+    0, 1, 2, 3, 4, 5, 6, 7,
+    8, 12, 16, 20, 24, 32, 48, 64
+};
+
+/* get data length from can_dlc with sanitized can_dlc */
+uint8_t can_dlc2len(uint8_t can_dlc)
+{
+    return dlc2len[can_dlc & 0x0F];
+}
+
+static const uint8_t len2dlc[] = {
+    0, 1, 2, 3, 4, 5, 6, 7, 8,                              /* 0 - 8 */
+    9, 9, 9, 9,                                             /* 9 - 12 */
+    10, 10, 10, 10,                                         /* 13 - 16 */
+    11, 11, 11, 11,                                         /* 17 - 20 */
+    12, 12, 12, 12,                                         /* 21 - 24 */
+    13, 13, 13, 13, 13, 13, 13, 13,                         /* 25 - 32 */
+    14, 14, 14, 14, 14, 14, 14, 14,                         /* 33 - 40 */
+    14, 14, 14, 14, 14, 14, 14, 14,                         /* 41 - 48 */
+    15, 15, 15, 15, 15, 15, 15, 15,                         /* 49 - 56 */
+    15, 15, 15, 15, 15, 15, 15, 15                          /* 57 - 64 */
+};
+
+/* map the sanitized data length to an appropriate data length code */
+uint8_t can_len2dlc(uint8_t len)
+{
+    if (unlikely(len > 64)) {
+        return 0xF;
+    }
+
+    return len2dlc[len];
+}
+
 struct CanBusState {
     Object object;
 
-- 
2.20.1



  parent reply	other threads:[~2020-07-14 12:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 12:20 [PATCH v1 0/6] CTU CAN FD core support pisa
2020-07-14 12:20 ` [PATCH v1 1/6] net/can: Initial host SocketCan support for CAN FD pisa
2020-09-01 20:01   ` Vikram Garhwal
2020-09-02  7:51     ` Pavel Pisa
2020-09-03  5:20       ` Vikram Garhwal
2020-09-03  5:29         ` Vikram Garhwal
2020-07-14 12:20 ` [PATCH v1 2/6] hw/net/can: sja1000 ignore CAN FD frames pisa
2020-09-01 17:07   ` Vikram Garhwal
2020-07-14 12:20 ` pisa [this message]
2020-09-03  5:43   ` [PATCH v1 3/6] net/can: Add can_dlc2len and can_len2dlc for CAN FD Vikram Garhwal
2020-09-03  6:12     ` Pavel Pisa
2020-09-03  6:38       ` Vikram Garhwal
2020-07-14 12:20 ` [PATCH v1 4/6] hw/net/can/ctucafd: Add CTU CAN FD core register definitions pisa
2020-07-14 12:20 ` [PATCH v1 5/6] hw/net/can: CTU CAN FD IP open hardware core emulation pisa
2020-07-24  9:46   ` Pavel Pisa
2020-07-14 12:20 ` [PATCH v1 6/6] hw/net/can: Documentation for " pisa
2020-07-14 12:47 ` [PATCH v1 0/6] CTU CAN FD core support no-reply
2020-07-14 13:45   ` [PATCH v1 0/6] CTU CAN FD core support - patchew report Pavel Pisa
2020-07-14 12:48 ` [PATCH v1 0/6] CTU CAN FD core support no-reply
2020-07-30 15:29 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=30758547c49f254b3965fc12500735bea8265c97.1594725647.git.pisa@cmp.felk.cvut.cz \
    --to=pisa@cmp.felk.cvut.cz \
    --cc=armbru@redhat.com \
    --cc=charvj10@fel.cvut.cz \
    --cc=deniz.eren@icloud.com \
    --cc=frederic.konrad@adacore.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jnovak@fel.cvut.cz \
    --cc=marex@denx.de \
    --cc=o.rempel@pengutronix.de \
    --cc=ondrej.ille@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=socketcan@hartkopp.net \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.