From nobody Mon Feb 9 21:23:14 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1594729987; cv=none; d=zohomail.com; s=zohoarc; b=VXEFzKMG/xOELj+6IanKNA2GjptROJfdlLYNc6B4GmXZtExemVzbE+wskiRiMb2fnpieRcUwuj+vPoHsKnwowwQ16OOQ3afI1hH83YtWp7Dl1EP5r/bdSmbfTIAcgNReSDKqOImc6e1z79IqjR0L3fnj4yr5FvIwlYN9iWOmYpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594729987; 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=zG9X0uXgcL2CRJUhJOx6jYFPRtibHoLyks3WJxRo6zI=; b=Gy4WPwdChQFSBwNERb+e12It0Of8ttbBJxjHmjuj2CtGoV68mlJ8sKctg8o7j8UBLyj4+86wNRiub3p+Y4BRsIrCdC1/FVFZbU+j0Q0hMcPyFIZeBUe3BvZxFYL35yTuvHzAtoSk6q4LWH3Il/sE485PGw7Ey5rRfWPzOhq2unY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1594729987633390.9347536019412; Tue, 14 Jul 2020 05:33:07 -0700 (PDT) Received: from localhost ([::1]:46640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jvK7O-0003JZ-69 for importer@patchew.org; Tue, 14 Jul 2020 08:33:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvK4b-00012A-5T for qemu-devel@nongnu.org; Tue, 14 Jul 2020 08:30:13 -0400 Received: from mxa2.seznam.cz ([2a02:598:2::90]:37217) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jvK4Z-0008Pm-J9 for qemu-devel@nongnu.org; Tue, 14 Jul 2020 08:30:12 -0400 Received: from email.seznam.cz by email-smtpc19b.ng.seznam.cz (email-smtpc19b.ng.seznam.cz [10.23.18.23]) id 5c84d78b9e3bc8ca59f633bf; Tue, 14 Jul 2020 14:30:09 +0200 (CEST) Received: from hathi.duckdns.org (2001:718:2:1654:e269:95ff:fec3:1c81 [2001:718:2:1654:e269:95ff:fec3:1c81]) by email-relay12.ng.seznam.cz (Seznam SMTPD 1.3.119) with ESMTP; Tue, 14 Jul 2020 14:30:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seznam.cz; s=beta; t=1594729809; bh=zG9X0uXgcL2CRJUhJOx6jYFPRtibHoLyks3WJxRo6zI=; h=Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=lucLEHNi3cqP2dfP5DZ04NgeHcsAEyMGrbMbiB5xQ04VwDxLvhmlec+bC9H3mbrQT uxshl9+bU+YZHm7Wy2aZk3tt2qh4vdzamiElmUzemVsn9qukVdqUXJI8+xmZQWmDPO fZVt2qjFhxdbxSWtfcsD/xQqsb3GG9p5lqqmEr9Q= From: pisa@cmp.felk.cvut.cz To: qemu-devel@nongnu.org, Paolo Bonzini 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 Message-Id: <30758547c49f254b3965fc12500735bea8265c97.1594725647.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 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: pass client-ip=2a02:598:2::90; envelope-from=autobot.majer@seznam.cz; helo=mxa2.seznam.cz X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=1, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=no 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 , Oliver Hartkopp , Jiri Novak , Stefan Hajnoczi , Deniz Eren , Markus Armbruster , Oleksij Rempel , Konrad Frederic , Jan Charvat , Jan Kiszka , Ondrej Ille , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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 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); =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