From nobody Sun Nov 24 05:25:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1726240771; cv=none; d=zohomail.com; s=zohoarc; b=bOqChoIZf8Kc6/9Tii7Xt3heI+uj3h926RBxCANacewuS3ixghFVmTIiguVSAY/m/b2q6J36BjC8IXIOSvWeqGWyl5kkGR2SmBwsq8likb7Th3wxYG8qXz5TPRQTCh3SdpI/kDLP8NV/EoacvhfZqMtbS4n6PzRWCjwnvTNesik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726240771; h=Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To:Cc; bh=SdBENGCYVeHnIteVeEyvDPFnPAvCbtcxZIQLKQyP3eU=; b=e7cf10rNrEkvIUBiOnfL1K66vnbDRlCZajCaK0gJeWg7flBYkoscPGkQ3NEGPf77kHm48d2MpalkQNvaVsVTwE124EqvfkF+cX5MF0QGlh2yLedqhNqfTeFBK1/oUnbpfq4qsAI/rHQxOKUjN4AY4bDy+qhdMpF1IH2uutt2UNM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726240771960195.61033807750675; Fri, 13 Sep 2024 08:19:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sp80p-0004Yj-Or; Fri, 13 Sep 2024 11:15:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sp80D-0002M6-Ai for qemu-devel@nongnu.org; Fri, 13 Sep 2024 11:14:29 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sp80A-0007p2-Sq for qemu-devel@nongnu.org; Fri, 13 Sep 2024 11:14:29 -0400 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-37747c1d928so744815f8f.1 for ; Fri, 13 Sep 2024 08:14:26 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42d9b16bfbfsm29152325e9.22.2024.09.13.08.14.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 08:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726240465; x=1726845265; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=SdBENGCYVeHnIteVeEyvDPFnPAvCbtcxZIQLKQyP3eU=; b=YpEVlmrvy0n8UVcKxw+RvAT6jHUe0sbXubyUzcGccN7RSQEcSFwI2ws7JxRQMPGJYz L7bqScTWdzElmJwSqegkxC5eeg3W7fV+1FvGnqpPhLRuqL4uTZjehDu05rg/nE2Nwsp4 SRL6gicn71C7Ux0Mgxz31jiJl1bOz3CTnzksm7YWmPHXTVq92ehhCiiUKeC+NKr7GqBs zOWhX2yHSFrP2s2iekND+KNA1hx7EsvL4ntd8EUWFR106ApSs7NpBOMAR9xBQSfJKliI gEv/LbZKt/iVUAzy8MTk6ErJ3XTU1bx+TvofXyo5Sojm5RJkQwncWaEJT6x6pDQbSuy5 5ydw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726240465; x=1726845265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SdBENGCYVeHnIteVeEyvDPFnPAvCbtcxZIQLKQyP3eU=; b=gdextGy39qhXOtDC8oRJiOGDyRnTlrUVEosCD3wDsxvxlLJjyoCFhh4JRwmsHqoKxZ UB16lXT5rb/Adej4ijjsEVJE1E7J4tioM2ak3MbiXIPsMADT8Sp8B1VQulwI59cXPUgZ X39b3ltYYxEVioxZTw7Mg5Pu67kjWuE8at6eXKkzEmwbEX+1KhINgYni7x9QUQDz2Pxr xAWZZhanVuqXA7oV5ciCd0V2Ug8Gzal3z8nEo3gnRz5EqeN68jx7SGaknz1YN4me/v9A 9ljQ+TpXOsTVHre/3bDd8wqDvD7wD2e7jiYnDQ8jP/SZXPcQQ64ILrFIa27IbJITl0DC v8Uw== X-Gm-Message-State: AOJu0Yz/FcWYjmeNTTnRbV+dohub4XNBEbCZuZSZgULXzWEXaTCwSIYg baY4Xxv0x//KVibKkfI/5xU3BihLjK3pnj7s0kKBSle+6xn5Gffzqhw7PpbgCwsPkI1JZPTVv9G C X-Google-Smtp-Source: AGHT+IHqTUnm0eIFsETyDK5qcPdmD3nx4Pkic5UaKt45z5LCdGwuvdvDkMAM0mFLwRVhe/cBtVtoiw== X-Received: by 2002:a05:6000:b82:b0:371:828a:741d with SMTP id ffacd0b85a97d-378d61e2866mr2136777f8f.21.1726240465350; Fri, 13 Sep 2024 08:14:25 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 22/27] hw/net/can/xlnx-versal-canfd: Simplify DLC conversions Date: Fri, 13 Sep 2024 16:14:06 +0100 Message-Id: <20240913151411.2167922-23-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240913151411.2167922-1-peter.maydell@linaro.org> References: <20240913151411.2167922-1-peter.maydell@linaro.org> 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=2a00:1450:4864:20::430; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x430.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1726240773047116600 Content-Type: text/plain; charset="utf-8" From: Doug Brown Use QEMU's helper functions can_dlc2len() and can_len2dlc() for translating between the raw DLC value and the SocketCAN length value. This also has the side effect of correctly handling received CAN FD frames with a DLC of 0-8, which was broken previously. Signed-off-by: Doug Brown Reviewed-by: Pavel Pisa Reviewed-by: Francisco Iglesias Message-id: 20240827034927.66659-7-doug@schmorgal.com Signed-off-by: Peter Maydell --- hw/net/can/xlnx-versal-canfd.c | 67 ++-------------------------------- 1 file changed, 4 insertions(+), 63 deletions(-) diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c index bcfffee1cc2..ccfed364cc9 100644 --- a/hw/net/can/xlnx-versal-canfd.c +++ b/hw/net/can/xlnx-versal-canfd.c @@ -678,8 +678,6 @@ REG32(RB_DW15_REGISTER_1, 0x4144) FIELD(RB_DW15_REGISTER_1, DATA_BYTES62, 8, 8) FIELD(RB_DW15_REGISTER_1, DATA_BYTES63, 0, 8) =20 -static uint8_t canfd_dlc_array[8] =3D {8, 12, 16, 20, 24, 32, 48, 64}; - static void canfd_update_irq(XlnxVersalCANFDState *s) { const bool irq =3D (s->regs[R_INTERRUPT_STATUS_REGISTER] & @@ -897,59 +895,19 @@ static void regs2frame(XlnxVersalCANFDState *s, qemu_= can_frame *frame, } =20 if (FIELD_EX32(dlc_reg_val, TB0_DLC_REGISTER, FDF)) { - /* - * CANFD frame. - * Converting dlc(0 to 15) 4 Byte data to plain length(i.e. 0 to 6= 4) - * 1 Byte data. This is done to make it work with SocketCAN. - * On actual CANFD frame, this value can't be more than 0xF. - * Conversion table for DLC to plain length: - * - * DLC Plain Length - * 0 - 8 0 - 8 - * 9 9 - 12 - * 10 13 - 16 - * 11 17 - 20 - * 12 21 - 24 - * 13 25 - 32 - * 14 33 - 48 - * 15 49 - 64 - */ - frame->flags |=3D QEMU_CAN_FRMF_TYPE_FD; =20 - if (dlc_value < 8) { - frame->can_dlc =3D dlc_value; - } else { - assert((dlc_value - 8) < ARRAY_SIZE(canfd_dlc_array)); - frame->can_dlc =3D canfd_dlc_array[dlc_value - 8]; - } - if (FIELD_EX32(dlc_reg_val, TB0_DLC_REGISTER, BRS)) { frame->flags |=3D QEMU_CAN_FRMF_BRS; } } else { - /* - * FD Format bit not set that means it is a CAN Frame. - * Conversion table for classic CAN: - * - * DLC Plain Length - * 0 - 7 0 - 7 - * 8 - 15 8 - */ - - if (dlc_value > 8) { - frame->can_dlc =3D 8; - qemu_log_mask(LOG_GUEST_ERROR, "Maximum DLC value for Classic = CAN" - " frame is 8. Only 8 byte data will be sent.\n"); - } else { - frame->can_dlc =3D dlc_value; - } - if (is_rtr) { frame->can_id |=3D QEMU_CAN_RTR_FLAG; } } =20 + frame->can_dlc =3D can_dlc2len(dlc_value); + for (j =3D 0; j < frame->can_dlc; j++) { val =3D 8 * (3 - i); =20 @@ -1007,7 +965,6 @@ static void store_rx_sequential(XlnxVersalCANFDState *= s, bool rx_fifo_id, uint8_t filter_index) { int i; - bool is_canfd_frame; uint8_t dlc =3D frame->can_dlc; uint8_t rx_reg_num =3D 0; uint32_t dlc_reg_val =3D 0; @@ -1053,17 +1010,10 @@ static void store_rx_sequential(XlnxVersalCANFDStat= e *s, =20 s->regs[store_location] =3D frame_to_reg_id(frame); =20 - dlc =3D frame->can_dlc; + dlc_reg_val =3D FIELD_DP32(0, RB_DLC_REGISTER, DLC, can_len2dlc(dl= c)); =20 if (frame->flags & QEMU_CAN_FRMF_TYPE_FD) { - is_canfd_frame =3D true; - - /* Store dlc value in Xilinx specific format. */ - for (i =3D 0; i < ARRAY_SIZE(canfd_dlc_array); i++) { - if (canfd_dlc_array[i] =3D=3D frame->can_dlc) { - dlc_reg_val =3D FIELD_DP32(0, RB_DLC_REGISTER, DLC, 8 = + i); - } - } + dlc_reg_val |=3D FIELD_DP32(0, RB_DLC_REGISTER, FDF, 1); =20 if (frame->flags & QEMU_CAN_FRMF_BRS) { dlc_reg_val |=3D FIELD_DP32(0, RB_DLC_REGISTER, BRS, 1); @@ -1071,17 +1021,8 @@ static void store_rx_sequential(XlnxVersalCANFDState= *s, if (frame->flags & QEMU_CAN_FRMF_ESI) { dlc_reg_val |=3D FIELD_DP32(0, RB_DLC_REGISTER, ESI, 1); } - } else { - is_canfd_frame =3D false; - - if (frame->can_dlc > 8) { - dlc =3D 8; - } - - dlc_reg_val =3D FIELD_DP32(0, RB_DLC_REGISTER, DLC, dlc); } =20 - dlc_reg_val |=3D FIELD_DP32(0, RB_DLC_REGISTER, FDF, is_canfd_fram= e); dlc_reg_val |=3D FIELD_DP32(0, RB_DLC_REGISTER, TIMESTAMP, rx_time= stamp); dlc_reg_val |=3D FIELD_DP32(0, RB_DLC_REGISTER, MATCHED_FILTER_IND= EX, filter_index); --=20 2.34.1