From patchwork Fri Sep 13 15:14:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 828189 Delivered-To: patch@linaro.org Received: by 2002:adf:a2d0:0:b0:367:895a:4699 with SMTP id t16csp301241wra; Fri, 13 Sep 2024 08:19:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWhoPig5MHDtEEXrgpB3pTolgNdRyg1GSvN2wP6CL0OItT58mAZcoMG8I/qK89wfkOLXV86Uw==@linaro.org X-Google-Smtp-Source: AGHT+IGOCEgaA5XZg9d2PB6WWkP3MRlwmZLxFp/kAgKH+r//6galIriaYOepSh5RJrxc8z+tX0Dn X-Received: by 2002:a05:6102:c0f:b0:493:c3b2:b5ba with SMTP id ada2fe7eead31-49d4f5b8e46mr2846390137.6.1726240771677; Fri, 13 Sep 2024 08:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726240771; cv=none; d=google.com; s=arc-20240605; b=ejJqQqECJEPH91NWpuQl/UVgrX+9od4JKBLcTS2wpog2Zot9G0+qbIEtGpg/za3VBs MNttFkk0OS5QkD4tBoKGmFHvLAuALuD8ZnuzdsZzGTjhQ66lpbzZhvxodWfHSZe/iEI8 7w2FkZ3pEk+jeDrSpTeVQup9tpeV5ZODwtax8b0J9ML5EkO70AwHQhZNikrfPZTcA8wE 9FYuUf2MSV3zEqeUmfGBLDJeYPejt5HKeFPA28nwL0alybiAWDtUQrM81juCfdVssciW pfZU6rfM2QWA7M9eZ6SmJoC1QjvpCCAx3ar+eZWuN4nxWJGVoedtVhhRLXuxlQwfJD4y 71bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=SdBENGCYVeHnIteVeEyvDPFnPAvCbtcxZIQLKQyP3eU=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=ZYPCfXacn5O2/TkoGSHVvnI/8sVaUWOnrJYVLRUx3IaSHSsKJebMpVye9pZZ6VQ7k1 pYA2dVkPDK56gbiLBCF8pCJzOPairpBmawiT9tbXPe+i6jfbUFcDbVxT7ruYr99pS73T 418SreskF7mcMx7FTo4sKsgLfW+OyiFoN4O0vD2oJplIrzjnQAGuOEmVeLMxVyFsyzpr VRl1VQkG8zZ3YtbnX//BIgVeRqjzqzrx+bcPyeioWFwmPikn+m83hmxNXMXOYjgF/xBC Wb/lVwIq0Y+Ki4amjBvo9vjEs/804RWLDhbKNmyAmHCiDRvvFJ5lrxn7YEFzvqEk1b9W NjdA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YpEVlmrv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ada2fe7eead31-49c16db01b4si2610676137.320.2024.09.13.08.19.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 13 Sep 2024 08:19:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YpEVlmrv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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) -static uint8_t canfd_dlc_array[8] = {8, 12, 16, 20, 24, 32, 48, 64}; - static void canfd_update_irq(XlnxVersalCANFDState *s) { const bool irq = (s->regs[R_INTERRUPT_STATUS_REGISTER] & @@ -897,59 +895,19 @@ static void regs2frame(XlnxVersalCANFDState *s, qemu_can_frame *frame, } 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 64) - * 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 |= QEMU_CAN_FRMF_TYPE_FD; - if (dlc_value < 8) { - frame->can_dlc = dlc_value; - } else { - assert((dlc_value - 8) < ARRAY_SIZE(canfd_dlc_array)); - frame->can_dlc = canfd_dlc_array[dlc_value - 8]; - } - if (FIELD_EX32(dlc_reg_val, TB0_DLC_REGISTER, BRS)) { frame->flags |= 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 = 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 = dlc_value; - } - if (is_rtr) { frame->can_id |= QEMU_CAN_RTR_FLAG; } } + frame->can_dlc = can_dlc2len(dlc_value); + for (j = 0; j < frame->can_dlc; j++) { val = 8 * (3 - i); @@ -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 = frame->can_dlc; uint8_t rx_reg_num = 0; uint32_t dlc_reg_val = 0; @@ -1053,17 +1010,10 @@ static void store_rx_sequential(XlnxVersalCANFDState *s, s->regs[store_location] = frame_to_reg_id(frame); - dlc = frame->can_dlc; + dlc_reg_val = FIELD_DP32(0, RB_DLC_REGISTER, DLC, can_len2dlc(dlc)); if (frame->flags & QEMU_CAN_FRMF_TYPE_FD) { - is_canfd_frame = true; - - /* Store dlc value in Xilinx specific format. */ - for (i = 0; i < ARRAY_SIZE(canfd_dlc_array); i++) { - if (canfd_dlc_array[i] == frame->can_dlc) { - dlc_reg_val = FIELD_DP32(0, RB_DLC_REGISTER, DLC, 8 + i); - } - } + dlc_reg_val |= FIELD_DP32(0, RB_DLC_REGISTER, FDF, 1); if (frame->flags & QEMU_CAN_FRMF_BRS) { dlc_reg_val |= 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 |= FIELD_DP32(0, RB_DLC_REGISTER, ESI, 1); } - } else { - is_canfd_frame = false; - - if (frame->can_dlc > 8) { - dlc = 8; - } - - dlc_reg_val = FIELD_DP32(0, RB_DLC_REGISTER, DLC, dlc); } - dlc_reg_val |= FIELD_DP32(0, RB_DLC_REGISTER, FDF, is_canfd_frame); dlc_reg_val |= FIELD_DP32(0, RB_DLC_REGISTER, TIMESTAMP, rx_timestamp); dlc_reg_val |= FIELD_DP32(0, RB_DLC_REGISTER, MATCHED_FILTER_INDEX, filter_index);