From nobody Mon Feb 9 12:39:00 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1599170228; cv=none; d=zohomail.com; s=zohoarc; b=Q+r/VNoIrTDcUfQl5aDdSmRAfiIfkvM7f7DgrablZ7DbQ/EX326mTz4tDQ9BIv5dpgmYryR3kdpCXvGaqtA/ms2r1mV98+FjpNUczFw7kgKuHA1YJ8RewfQRw1OiJ8U8lalfgcLb8Azzv6BQaa1IhUgtpERJDPYj/K5frF4G1i4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599170228; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FF0bxEw0ElC8hKQeIKvA48SLVZNCLDGtphnbTPhApKo=; b=DoHKdJJmOouayjJuP1H1EzxlKv0+37ZB2Vho7oXav60Q9IpbZyqVMeKfG2Bx7mdUGQDZ4IxkjzwnFKUOaIIqkZzX7IMV2aRJLUtbs8mOSt0hVZYnmljCu7xMHneMrm3QlVSe4erEb1SuM7Al9q/RQ/KPntfvO64+/Zop/vv+69k= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599170228602626.914491487289; Thu, 3 Sep 2020 14:57:08 -0700 (PDT) Received: from localhost ([::1]:40420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDxEB-0007Zj-JH for importer@patchew.org; Thu, 03 Sep 2020 17:57:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDxBI-00041c-0G for qemu-devel@nongnu.org; Thu, 03 Sep 2020 17:54:08 -0400 Received: from relay.felk.cvut.cz ([2001:718:2:1611:0:1:0:70]:15294) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDxBF-0005pN-Sb for qemu-devel@nongnu.org; Thu, 03 Sep 2020 17:54:07 -0400 Received: from cmp.felk.cvut.cz (haar.felk.cvut.cz [147.32.84.19]) by relay.felk.cvut.cz (8.15.2/8.15.2) with ESMTP id 083Lr4X5032152; Thu, 3 Sep 2020 23:53:04 +0200 (CEST) (envelope-from pisa@cmp.felk.cvut.cz) Received: from haar.felk.cvut.cz (localhost [127.0.0.1]) by cmp.felk.cvut.cz (8.14.0/8.12.3/SuSE Linux 0.6) with ESMTP id 083Lr4oc026578; Thu, 3 Sep 2020 23:53:04 +0200 Received: (from pisa@localhost) by haar.felk.cvut.cz (8.14.0/8.13.7/Submit) id 083Lr3ox026577; Thu, 3 Sep 2020 23:53:03 +0200 From: Pavel Pisa To: qemu-devel@nongnu.org, Paolo Bonzini Subject: [PATCH v2 3/7] net/can: Add can_dlc2len and can_len2dlc for CAN FD. Date: Thu, 3 Sep 2020 23:48:19 +0200 Message-Id: <6a97808de22470e4ea18224fcb6f0ca34f310a5a.1599168753.git.pisa@cmp.felk.cvut.cz> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FELK-MailScanner-Information: X-MailScanner-ID: 083Lr4X5032152 X-FELK-MailScanner: Found to be clean X-FELK-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-0.098, required 6, BAYES_00 -0.50, KHOP_HELO_FCRDNS 0.40, SPF_HELO_NONE 0.00, SPF_NONE 0.00) X-FELK-MailScanner-From: pisa@cmp.felk.cvut.cz X-FELK-MailScanner-Watermark: 1599774785.44982@yik3D8LALACQgp87AGA3wQ Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2001:718:2:1611:0:1:0:70; envelope-from=pisa@cmp.felk.cvut.cz; helo=relay.felk.cvut.cz X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/03 17:39:24 X-ACL-Warn: Detected OS = ??? X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marek Vasut , Vikram Garhwal , Jiri Novak , Stefan Hajnoczi , Deniz Eren , Markus Armbruster , Oleksij Rempel , Konrad Frederic , Jan Kiszka , Jan Charvat , Oliver Hartkopp , Ondrej Ille , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Jan Charvat Signed-off-by: Jan Charvat Signed-off-by: Pavel Pisa Reviewed-by: Vikram Garhwal --- 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 1547091ff4..8e59ac95ae 100644 --- a/include/net/can_emu.h +++ b/include/net/can_emu.h @@ -123,4 +123,8 @@ int can_bus_client_set_filters(CanBusClientState *, const struct qemu_can_filter *filters, size_t filters_cnt); =20 +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" =20 +/* CAN DLC to real data length conversion helpers */ + +static const uint8_t dlc2len[] =3D { + 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[] =3D { + 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; =20 --=20 2.20.1