From patchwork Tue Aug 27 03:49:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13778807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AFDDAC5320E for ; Tue, 27 Aug 2024 03:51:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sinEI-0004vW-Qq; Mon, 26 Aug 2024 23:50:51 -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 1sinEG-0004uU-HW for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:48 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sinEE-0003pi-WB for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:48 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-204d391f53bso12762775ad.2 for ; Mon, 26 Aug 2024 20:50:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1724730645; x=1725335445; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UHA6cw5duNChzRkisU1kblSnuYm9RTmHim2/vThBDEc=; b=chVk0xlDvyOdOmUlRvCGIJXwixDR0Ny6fdDNB71mY0BFLDIJlVMcHCGM/ntq3Lt37E enbaCWcXTDw66OYp1Gn1dzmZBwi1MaSOUmrZWkhnQFDeW2MLenZgPnYGxrHlrmVwHwQn vkfcQVGp2bKBhJ1mSmop1ArhhZdSqoOBZ8g2M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724730645; x=1725335445; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UHA6cw5duNChzRkisU1kblSnuYm9RTmHim2/vThBDEc=; b=YLYYg2AeEc/vbOxd2BrrUjv27d6O5PpLCzmosQ/kGMPRw7NT7vhhGHwdcC8PZ68iQk pkQvBMdlDuVwYSb+GTw5APbExqBLTJIte7j1H7DAyuqLKHWo6Lykw0CMgCACbv83r5oi qJthlMkvcTdrb9b8IzoeLCLLshkM8QIf2Rw++pKgtoypf2bUzrgHHrcq+/qYRrfJhJii h6MqHgmOpBoqmp7CKki8yHZP1gLcIorqgBiS1Qh2e5c2W5XNaWOSNw3c73Wz/q5nLxtz AVo3KA/YF47b3U0rnV5xsTxWqs2O7bg4Wii0Qy2UxRuNcJBFuGQqLI4ASGMFV6BGKCuw j9sg== X-Forwarded-Encrypted: i=1; AJvYcCUvu5yF6tFYJtTQ4f/bFWuB7cypJvlU9K3Bea3cpKMYM+ZEux4O1kV2BjEwiXGQfRb3c8BX+/Muu/JK@nongnu.org X-Gm-Message-State: AOJu0YxDBUUHLtp5YpxYeETPSNDx7++yTexu4330SCNh5CRGcIiUUKbL rFLKvej+BEZajhHTpEY1ULc/T9VIFXDSteNUi1zzzubDZd5SYW8qREtcYTVs8VfcRTg9ZrWOSKW 2PLmSVQ== X-Google-Smtp-Source: AGHT+IFurwu+Jv5psvR4SfizAmgJWtpim4N3JALHfxN9irgZeiJuYfLBuJoEeLed+ZQQkiF5UeqTFw== X-Received: by 2002:a17:902:c942:b0:202:48a6:c882 with SMTP id d9443c01a7336-204df4e337dmr17398485ad.52.1724730644936; Mon, 26 Aug 2024 20:50:44 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd269sm74503625ad.135.2024.08.26.20.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 20:50:44 -0700 (PDT) From: Doug Brown To: Francisco Iglesias , Pavel Pisa Cc: Jason Wang , Paolo Bonzini , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH v2 1/7] hw/net/can/xlnx-versal-canfd: Fix interrupt level Date: Mon, 26 Aug 2024 20:49:21 -0700 Message-Id: <20240827034927.66659-2-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827034927.66659-1-doug@schmorgal.com> References: <20240827034927.66659-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=doug@schmorgal.com; helo=mail-pl1-x62b.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The interrupt level should be 0 or 1. The existing code was using the interrupt flags to determine the level. In the only machine currently supported (xlnx-versal-virt), the GICv3 was masking off all bits except bit 0 when applying it, resulting in the IRQ never being delivered. Signed-off-by: Doug Brown Reviewed-by: Francisco Iglesias Reviewed-by: Pavel Pisa --- hw/net/can/xlnx-versal-canfd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c index 5f083c21e9..ad0c4da3c8 100644 --- a/hw/net/can/xlnx-versal-canfd.c +++ b/hw/net/can/xlnx-versal-canfd.c @@ -682,8 +682,8 @@ static uint8_t canfd_dlc_array[8] = {8, 12, 16, 20, 24, 32, 48, 64}; static void canfd_update_irq(XlnxVersalCANFDState *s) { - unsigned int irq = s->regs[R_INTERRUPT_STATUS_REGISTER] & - s->regs[R_INTERRUPT_ENABLE_REGISTER]; + const bool irq = (s->regs[R_INTERRUPT_STATUS_REGISTER] & + s->regs[R_INTERRUPT_ENABLE_REGISTER]) != 0; g_autofree char *path = object_get_canonical_path(OBJECT(s)); /* RX watermark interrupts. */ From patchwork Tue Aug 27 03:49:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13778806 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD35DC52D6F for ; Tue, 27 Aug 2024 03:51:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sinEN-00052c-Li; Mon, 26 Aug 2024 23:50:57 -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 1sinEJ-0004vw-24 for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:51 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sinEG-0003pq-Hz for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:49 -0400 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-201df0b2df4so40715555ad.0 for ; Mon, 26 Aug 2024 20:50:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1724730647; x=1725335447; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6OPbVwUKXCH/ZUut8ds9FLbfn3e0300EaiaFIsbv4pw=; b=Noe43Pkj15yEUxwo040PnZkPKPzU9BSx2UrOCTG7CsPIGR5mW5E9E34wp4jiNNWVaS kPj8AdYgnXkvoB5opf2zx3GDb9HJl79UF6rdu9PKOekIHCiKVm/GS1wolXHQRFonHZI4 oqCT8EOqCgkeNyP00TVd28Utyf1JkO9vAEEZc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724730647; x=1725335447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6OPbVwUKXCH/ZUut8ds9FLbfn3e0300EaiaFIsbv4pw=; b=gB4iGc1ZU2tZmZCDQDs+C2cAtFx+dEowf2GD7dbd7L+2tunLJIgeNvf2ndEDFQBco/ cV1KmmX6J0LDgXncNStrdkULeuYsGzWfJqCW7q+OikHO7xsVCifb4Yi5rdCY4LHc6eJE xxacsAAKKUGiwsYxmUlTHCkzZPEVicvLBSMoBzAaWb9K2v82p4BpkPwxuUbZBV/Vf3QV k6H2Ffmioba+rimCemx6ZusIszBYkT3ziHBYY0seElfarF8prl8dDIu4kdhzaAB/XDOG OE73ZFpw6mcsYw23DdNsN4hXJS8w/V95wrFoVoIeSKxFllZme00icOVjgtNgfFggMInD /ymw== X-Forwarded-Encrypted: i=1; AJvYcCUUUblLKkppcVgsQGuI4p6fsXwfPSG+dvWcRA3qguAj9XqNGjraX2ebcgbITiMxY244ar9/+oVJg/qh@nongnu.org X-Gm-Message-State: AOJu0YydOP1Bnl+cNPLPU8rq3+AFPicYkHw20vpqTzz6s6Gs374OK/BY QVBwipilWi2W9v2cCQbEzB+LniEW3teCbBxjyohCLndaEFMyBKWM1OYCJ2fi6n4= X-Google-Smtp-Source: AGHT+IFOf+n6n/YjXR/TV5GKVYumayLespLoZ2LxMmi9p2CuaAcA3k6mzi0PIJDRJr23ukZymeHtiA== X-Received: by 2002:a17:902:d503:b0:202:3430:654e with SMTP id d9443c01a7336-2039e4f2573mr175015125ad.42.1724730647210; Mon, 26 Aug 2024 20:50:47 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd269sm74503625ad.135.2024.08.26.20.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 20:50:46 -0700 (PDT) From: Doug Brown To: Francisco Iglesias , Pavel Pisa Cc: Jason Wang , Paolo Bonzini , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH v2 2/7] hw/net/can/xlnx-versal-canfd: Fix CAN FD flag check Date: Mon, 26 Aug 2024 20:49:22 -0700 Message-Id: <20240827034927.66659-3-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827034927.66659-1-doug@schmorgal.com> References: <20240827034927.66659-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=doug@schmorgal.com; helo=mail-pl1-x62a.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org When checking the QEMU_CAN_FRMF_TYPE_FD flag, we need to ignore other potentially set flags. Before this change, received CAN FD frames from SocketCAN weren't being recognized as CAN FD. Signed-off-by: Doug Brown Reviewed-by: Pavel Pisa Reviewed-by: Francisco Iglesias Reviewed-by: Pavel Pisa --- hw/net/can/xlnx-versal-canfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c index ad0c4da3c8..8968672b84 100644 --- a/hw/net/can/xlnx-versal-canfd.c +++ b/hw/net/can/xlnx-versal-canfd.c @@ -1003,7 +1003,7 @@ static void store_rx_sequential(XlnxVersalCANFDState *s, dlc = frame->can_dlc; - if (frame->flags == QEMU_CAN_FRMF_TYPE_FD) { + if (frame->flags & QEMU_CAN_FRMF_TYPE_FD) { is_canfd_frame = true; /* Store dlc value in Xilinx specific format. */ From patchwork Tue Aug 27 03:49:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13778812 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A51CC5320E for ; Tue, 27 Aug 2024 03:52:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sinEQ-0005At-NV; Mon, 26 Aug 2024 23:50:58 -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 1sinEL-00050q-Sz for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:55 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sinEI-0003qK-LE for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:53 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1fc47abc040so43308285ad.0 for ; Mon, 26 Aug 2024 20:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1724730649; x=1725335449; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ror+zQ+DasxDMrRgs2ZAqV/eDrJt5Rr/T3wV9vKTaPA=; b=iwZi6GGqP0SV4O9nSpowq1P4uFAZOFM+HhsXiNFZjFqjR3Z/6r+Zm6X0Np5eIk9SZZ IvWgpbJigdxxQCgPj+y3dm4FEA+c6mufnaQtbArIbFaPVzq1qUAFXtGoO/j2v+WPpbLN D4vUD8uNLpDzU8eCupNI2RV8++NF35sUBYxXY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724730649; x=1725335449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ror+zQ+DasxDMrRgs2ZAqV/eDrJt5Rr/T3wV9vKTaPA=; b=DZXFqyPu6kA+q8oeZPP8fia4ETbFyVlA2u0OYyG/I44epK7BqRvKBVz/tytXpDAQai 1u2y4Gn3RFtVm84GPiZNDnfVz/KlnkOqqUsX6gkhcliKzydEx6AY8uDuRrEJZpIHfQ9E HeEs90j2zAEQKTdUdBaT0R78xztQUuajHQFp5UqBr3KN0raulIPwm2oLNNL5yKAedF0C ucjR/1RDFq3e/vZymyueFDiK9f90IB8zD3/MrLe2tMtZoaWbaxpMcVBKvkYNsk4hwaeS N1qgk4NpWurCJP4AQeBIdfgcqDX3IyZ01yP7aWaKOjqu+8thDyI15Mvkib+We3pI1IkI mvPA== X-Forwarded-Encrypted: i=1; AJvYcCWBCkuaWM+T04IhlkWEtZq3APuaqI3p7HKSHiltumwENPVqPhmOxlm6HzULKSCDpesbeL2ii4TA2mnE@nongnu.org X-Gm-Message-State: AOJu0YzICoqVOqadSEohgFy77WnMVaUKsbwPHJTKH1vpeYEGvJpLK0Kd dbZdENxtBj45W6NLQrL7ZStslnHzTHYek2e5XVs6yxty0wL6lnpSjErPwbITfKU= X-Google-Smtp-Source: AGHT+IH7r2rul8mzFc9QMCi4nmCHwJCYg4Z6YP/mq3st+xfgjYV5Tas+S2/vWDMwDPjdw1MAYnFUzg== X-Received: by 2002:a17:902:db09:b0:1fc:6a13:a39f with SMTP id d9443c01a7336-2039e48a2eemr167277755ad.25.1724730648755; Mon, 26 Aug 2024 20:50:48 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd269sm74503625ad.135.2024.08.26.20.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 20:50:48 -0700 (PDT) From: Doug Brown To: Francisco Iglesias , Pavel Pisa Cc: Jason Wang , Paolo Bonzini , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH v2 3/7] hw/net/can/xlnx-versal-canfd: Translate CAN ID registers Date: Mon, 26 Aug 2024 20:49:23 -0700 Message-Id: <20240827034927.66659-4-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827034927.66659-1-doug@schmorgal.com> References: <20240827034927.66659-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=doug@schmorgal.com; helo=mail-pl1-x629.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Previously the emulated CAN ID register was being set to the exact same value stored in qemu_can_frame.can_id. This doesn't work correctly because the Xilinx IP core uses a different bit arrangement than qemu_can_frame for all of its ID registers. Correct this problem for both RX and TX, including RX filtering. Signed-off-by: Doug Brown Reviewed-by: Francisco Iglesias Acked-by: Pavel Pisa --- hw/net/can/xlnx-versal-canfd.c | 53 ++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c index 8968672b84..1704b558d0 100644 --- a/hw/net/can/xlnx-versal-canfd.c +++ b/hw/net/can/xlnx-versal-canfd.c @@ -869,6 +869,8 @@ static void regs2frame(XlnxVersalCANFDState *s, qemu_can_frame *frame, uint32_t val = 0; uint32_t dlc_reg_val = 0; uint32_t dlc_value = 0; + uint32_t id_reg_val = 0; + bool is_rtr = false; /* Check that reg_num should be within TX register space. */ assert(reg_num <= R_TB_ID_REGISTER + (NUM_REGS_PER_MSG_SPACE * @@ -877,7 +879,20 @@ static void regs2frame(XlnxVersalCANFDState *s, qemu_can_frame *frame, dlc_reg_val = s->regs[reg_num + 1]; dlc_value = FIELD_EX32(dlc_reg_val, TB0_DLC_REGISTER, DLC); - frame->can_id = s->regs[reg_num]; + id_reg_val = s->regs[reg_num]; + if (FIELD_EX32(id_reg_val, TB_ID_REGISTER, IDE)) { + frame->can_id = (FIELD_EX32(id_reg_val, TB_ID_REGISTER, ID) << 18) | + (FIELD_EX32(id_reg_val, TB_ID_REGISTER, ID_EXT)) | + QEMU_CAN_EFF_FLAG; + if (FIELD_EX32(id_reg_val, TB_ID_REGISTER, RTR_RRS)) { + is_rtr = true; + } + } else { + frame->can_id = FIELD_EX32(id_reg_val, TB_ID_REGISTER, ID); + if (FIELD_EX32(id_reg_val, TB_ID_REGISTER, SRR_RTR_RRS)) { + is_rtr = true; + } + } if (FIELD_EX32(dlc_reg_val, TB0_DLC_REGISTER, FDF)) { /* @@ -923,6 +938,10 @@ static void regs2frame(XlnxVersalCANFDState *s, qemu_can_frame *frame, } else { frame->can_dlc = dlc_value; } + + if (is_rtr) { + frame->can_id |= QEMU_CAN_RTR_FLAG; + } } for (j = 0; j < frame->can_dlc; j++) { @@ -948,6 +967,33 @@ static void process_cancellation_requests(XlnxVersalCANFDState *s) canfd_update_irq(s); } +static uint32_t frame_to_reg_id(const qemu_can_frame *frame) +{ + uint32_t id_reg_val = 0; + const bool is_canfd_frame = frame->flags & QEMU_CAN_FRMF_TYPE_FD; + const bool is_rtr = !is_canfd_frame && (frame->can_id & QEMU_CAN_RTR_FLAG); + + if (frame->can_id & QEMU_CAN_EFF_FLAG) { + id_reg_val |= FIELD_DP32(0, RB_ID_REGISTER, ID, + (frame->can_id & QEMU_CAN_EFF_MASK) >> 18); + id_reg_val |= FIELD_DP32(0, RB_ID_REGISTER, ID_EXT, + frame->can_id & QEMU_CAN_EFF_MASK); + id_reg_val |= FIELD_DP32(0, RB_ID_REGISTER, IDE, 1); + id_reg_val |= FIELD_DP32(0, RB_ID_REGISTER, SRR_RTR_RRS, 1); + if (is_rtr) { + id_reg_val |= FIELD_DP32(0, RB_ID_REGISTER, RTR_RRS, 1); + } + } else { + id_reg_val |= FIELD_DP32(0, RB_ID_REGISTER, ID, + frame->can_id & QEMU_CAN_SFF_MASK); + if (is_rtr) { + id_reg_val |= FIELD_DP32(0, RB_ID_REGISTER, SRR_RTR_RRS, 1); + } + } + + return id_reg_val; +} + static void store_rx_sequential(XlnxVersalCANFDState *s, const qemu_can_frame *frame, uint32_t fill_level, uint32_t read_index, @@ -999,7 +1045,7 @@ static void store_rx_sequential(XlnxVersalCANFDState *s, NUM_REGS_PER_MSG_SPACE)); } - s->regs[store_location] = frame->can_id; + s->regs[store_location] = frame_to_reg_id(frame); dlc = frame->can_dlc; @@ -1090,11 +1136,12 @@ static void update_rx_sequential(XlnxVersalCANFDState *s, if (s->regs[R_ACCEPTANCE_FILTER_CONTROL_REGISTER]) { uint32_t acceptance_filter_status = s->regs[R_ACCEPTANCE_FILTER_CONTROL_REGISTER]; + const uint32_t reg_id = frame_to_reg_id(frame); for (i = 0; i < 32; i++) { if (acceptance_filter_status & 0x1) { uint32_t msg_id_masked = s->regs[R_AFMR_REGISTER + 2 * i] & - frame->can_id; + reg_id; uint32_t afir_id_masked = s->regs[R_AFIR_REGISTER + 2 * i] & s->regs[R_AFMR_REGISTER + 2 * i]; uint16_t std_msg_id_masked = FIELD_EX32(msg_id_masked, From patchwork Tue Aug 27 03:49:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13778810 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF086C5320E for ; Tue, 27 Aug 2024 03:52:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sinER-0005D4-6i; Mon, 26 Aug 2024 23:50:59 -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 1sinEN-000553-Pp for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:57 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sinEJ-0003qY-Rg for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:54 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-20230059241so40781015ad.3 for ; Mon, 26 Aug 2024 20:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1724730650; x=1725335450; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S0zsQlf6Fpb3LogkSdeHLWACnHhbNDLVL/P8RxdypHM=; b=emOTH1OSvNprDeGur9l+DepiM4vZ7VkUVv5X63f73hsn/eErEjxDNdRYOwhIywBIEc 5aeDabqQbpjUkSSyoz2rSyOYpwc6ePpEjRpkkFZAQvIiJCsHOXqJ1Si7zwOy/dmVdWMU Jt2bcM+feFoOec+1LbFkouMrJL6WWHKQaqrrg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724730650; x=1725335450; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S0zsQlf6Fpb3LogkSdeHLWACnHhbNDLVL/P8RxdypHM=; b=Dzotwy4DUp9BXTpGkTrdmogXbP8nHeSRdP0KhcJuUMQ0s9IHjDHCLjTJEfVqgcouk4 9xJ4jtlNRwtqWIDrRU+wzPfoDLHinNao4hdTjp63iLFOll4LF/3MaKw68Oi/KwPRDUSc UmIkqoZ6grlruX0rgXmND+/8opEGMOgNH8mFc1ktSqzegTdPFW6PZHioPytAh2WYjqKC Z85NTYf+DIo072m4SB9mDCRycz5XEAxKuz25hUGFAUtjQlrIqhS85LLrj1YTmUuftiVR sqJMSzbOFr6ysSqnCK4TSHLI8Yj9T8TWQLnXXjzKK6hO4lVJYdlOYLcUTz2tTTLH/5Ok KRcQ== X-Forwarded-Encrypted: i=1; AJvYcCWIWSzuAN1V12lOnzC3H97RAjjLXa6RMcla0HG2tkcahq/kKkuVzVn6iFa0DnSgF/aI9vPJwXa+ik8s@nongnu.org X-Gm-Message-State: AOJu0YwmpLgmcWllxE2N03grMJgL4cyZK+HLlfNHbKfiFwEhD9IX755f Zx0yBXB1YRbz3+Tlh3AIYrQ0qGwvqUZA9ibnIviXLNqjcDfnNIWz76nJEt3L+lo= X-Google-Smtp-Source: AGHT+IEwuUQ3gLat4m6or9KyVLa/RrfyK5pIfIYJe9KC8cESOTG7v7uh7oE0g8/jcAIfTVwoHF6kEQ== X-Received: by 2002:a17:903:2c7:b0:201:f1b5:24ac with SMTP id d9443c01a7336-2039e51279bmr139896365ad.54.1724730650264; Mon, 26 Aug 2024 20:50:50 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd269sm74503625ad.135.2024.08.26.20.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 20:50:49 -0700 (PDT) From: Doug Brown To: Francisco Iglesias , Pavel Pisa Cc: Jason Wang , Paolo Bonzini , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH v2 4/7] hw/net/can/xlnx-versal-canfd: Handle flags correctly Date: Mon, 26 Aug 2024 20:49:24 -0700 Message-Id: <20240827034927.66659-5-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827034927.66659-1-doug@schmorgal.com> References: <20240827034927.66659-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=doug@schmorgal.com; helo=mail-pl1-x635.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add support for QEMU_CAN_FRMF_ESI and QEMU_CAN_FRMF_BRS flags, and ensure frame->flags is always initialized to 0. Note that the Xilinx IP core doesn't allow manually setting the ESI bit during transmits, so it's only implemented for the receive case. Signed-off-by: Doug Brown Reviewed-by: Pavel Pisa --- hw/net/can/xlnx-versal-canfd.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c index 1704b558d0..47631917ab 100644 --- a/hw/net/can/xlnx-versal-canfd.c +++ b/hw/net/can/xlnx-versal-canfd.c @@ -872,6 +872,8 @@ static void regs2frame(XlnxVersalCANFDState *s, qemu_can_frame *frame, uint32_t id_reg_val = 0; bool is_rtr = false; + frame->flags = 0; + /* Check that reg_num should be within TX register space. */ assert(reg_num <= R_TB_ID_REGISTER + (NUM_REGS_PER_MSG_SPACE * s->cfg.tx_fifo)); @@ -913,7 +915,7 @@ static void regs2frame(XlnxVersalCANFDState *s, qemu_can_frame *frame, * 15 49 - 64 */ - frame->flags = QEMU_CAN_FRMF_TYPE_FD; + frame->flags |= QEMU_CAN_FRMF_TYPE_FD; if (dlc_value < 8) { frame->can_dlc = dlc_value; @@ -921,6 +923,10 @@ static void regs2frame(XlnxVersalCANFDState *s, qemu_can_frame *frame, 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. @@ -1058,6 +1064,13 @@ static void store_rx_sequential(XlnxVersalCANFDState *s, dlc_reg_val = FIELD_DP32(0, RB_DLC_REGISTER, DLC, 8 + i); } } + + if (frame->flags & QEMU_CAN_FRMF_BRS) { + dlc_reg_val |= FIELD_DP32(0, RB_DLC_REGISTER, BRS, 1); + } + if (frame->flags & QEMU_CAN_FRMF_ESI) { + dlc_reg_val |= FIELD_DP32(0, RB_DLC_REGISTER, ESI, 1); + } } else { is_canfd_frame = false; From patchwork Tue Aug 27 03:49:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13778813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 969ADC5320E for ; Tue, 27 Aug 2024 03:52:18 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sinET-0005K2-0H; Mon, 26 Aug 2024 23:51:01 -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 1sinEN-00055j-Vj for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:57 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sinEL-0003qs-LW for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:55 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-7bb75419123so3264053a12.3 for ; Mon, 26 Aug 2024 20:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1724730651; x=1725335451; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JnP3Mz0YCYvkvuQOeow8f8X6KYRPaGRZd1rCOK6MrJs=; b=ezn6Jw5yIk/p1LxOfuLXUfwN2RNBV1E5lO5T4x/exItkNiWPnpWTeOiKue205tDyAS t/WSe3abnQJYnUNlf+BDU1lWz+WhODlMp/6eNvjY+ZzzuiyExYhqZoG7McIZdrz+cMoA oyXA+8jtShnR870yNeGLGphSbxHT1a1a2qvLc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724730651; x=1725335451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JnP3Mz0YCYvkvuQOeow8f8X6KYRPaGRZd1rCOK6MrJs=; b=S4wFOiqZXhudGhyn07Ja53JG0+R5ZqNSce5+bAaCBkLFSEMBifAu2ZGtWXO3chSNGo m5a+5nsmlQ+7lDHEgG4FoB6njih91pUM97uTn+TPOXqt5ddk4H9vbUBN7K2Kifi4bx4Z xL4L4CQwiL6F6bq7wkjlkxkHUl1qAKtBw2xZlG2xCzDHKhVbe81nHM4DnaMWBxBQ7xRs pakM826h7o3csM6ehfhxf+/QXImiE58VbXWYflwxaO8bZyFt4h4ONJvZn9smc3Mub7I0 82kQ/tfzUkPfN7dRbHGcjymYn9UmCABK96Kka5DKbso8b7f9DV6yD75tqmLt64MmTJhm VeBQ== X-Forwarded-Encrypted: i=1; AJvYcCUtnXuYyzB2o8WTrpaZmePQYsN2FZ40WHoIXpOxKFoU8e6tFE/APxuMgyQk6ZD37KrDND+VRfYat8Nl@nongnu.org X-Gm-Message-State: AOJu0YyceIiirmmae5XyWTa/ztir6vri3TOC0afoYcuX/r6Uqoj5Rp31 25YlmGypbNq718cHcJgSzjiex0bwt/8rcqMn0YCC3edVgSAqhTRfnntv0B5yifk= X-Google-Smtp-Source: AGHT+IGe3PUZEYCSgJsKiA6gmmK50hNyHr7QOk853mSIwidN4JmobSoIwlgaGyUk6yU8I4xAs38q6w== X-Received: by 2002:a17:902:d2c6:b0:202:2cd5:2085 with SMTP id d9443c01a7336-2039e4b4b90mr96999355ad.32.1724730651632; Mon, 26 Aug 2024 20:50:51 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd269sm74503625ad.135.2024.08.26.20.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 20:50:51 -0700 (PDT) From: Doug Brown To: Francisco Iglesias , Pavel Pisa Cc: Jason Wang , Paolo Bonzini , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH v2 5/7] hw/net/can/xlnx-versal-canfd: Fix byte ordering Date: Mon, 26 Aug 2024 20:49:25 -0700 Message-Id: <20240827034927.66659-6-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827034927.66659-1-doug@schmorgal.com> References: <20240827034927.66659-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=doug@schmorgal.com; helo=mail-pg1-x52f.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The endianness of the CAN data was backwards in each group of 4 bytes. For example, the following data: 00 11 22 33 44 55 66 77 was showing up like this: 33 22 11 00 77 66 55 44 Fix both the TX and RX code to put the data in the correct order. Signed-off-by: Doug Brown Reviewed-by: Francisco Iglesias Acked-by: Pavel Pisa --- hw/net/can/xlnx-versal-canfd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c index 47631917ab..5d7adf8740 100644 --- a/hw/net/can/xlnx-versal-canfd.c +++ b/hw/net/can/xlnx-versal-canfd.c @@ -951,7 +951,7 @@ static void regs2frame(XlnxVersalCANFDState *s, qemu_can_frame *frame, } for (j = 0; j < frame->can_dlc; j++) { - val = 8 * i; + val = 8 * (3 - i); frame->data[j] = extract32(s->regs[reg_num + 2 + (j / 4)], val, 8); i++; @@ -1093,19 +1093,19 @@ static void store_rx_sequential(XlnxVersalCANFDState *s, case 0: rx_reg_num = i / 4; - data_reg_val = FIELD_DP32(0, RB_DW0_REGISTER, DATA_BYTES3, + data_reg_val = FIELD_DP32(0, RB_DW0_REGISTER, DATA_BYTES0, frame->data[i]); break; case 1: - data_reg_val |= FIELD_DP32(0, RB_DW0_REGISTER, DATA_BYTES2, + data_reg_val |= FIELD_DP32(0, RB_DW0_REGISTER, DATA_BYTES1, frame->data[i]); break; case 2: - data_reg_val |= FIELD_DP32(0, RB_DW0_REGISTER, DATA_BYTES1, + data_reg_val |= FIELD_DP32(0, RB_DW0_REGISTER, DATA_BYTES2, frame->data[i]); break; case 3: - data_reg_val |= FIELD_DP32(0, RB_DW0_REGISTER, DATA_BYTES0, + data_reg_val |= FIELD_DP32(0, RB_DW0_REGISTER, DATA_BYTES3, frame->data[i]); /* * Last Bytes data which means we have all 4 bytes ready to From patchwork Tue Aug 27 03:49:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13778811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D61F3C5472F for ; Tue, 27 Aug 2024 03:52:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sinET-0005NM-R2; Mon, 26 Aug 2024 23:51:01 -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 1sinEP-00057M-P0 for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:58 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sinEN-0003rC-Hb for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:56 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-7163489149eso3078957a12.1 for ; Mon, 26 Aug 2024 20:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1724730653; x=1725335453; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Awp0ytvcQ56tnn09fPAbSHHgINoCasgEEQF1NRSqcwA=; b=EFZvROAMuShF9+vW7CZxycQSaKHRXIK0Etlgw2NXhx28ONZr1bvj46GBCIzHM8nKx9 eZZ9Iw8Ip1Ys1U9hzfpkQ3EF+SbicOl1lfHV7uIW7iMD4xkZ3oOP+Y0XvgaHu6JNaTzA 00wUNod9KiIqViauhrBAzEx4lQnRpX8W8WVr8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724730653; x=1725335453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Awp0ytvcQ56tnn09fPAbSHHgINoCasgEEQF1NRSqcwA=; b=KPZ6XpN/K/9J6O1aI2MpHzWzAPKvAN3bnL8o5RcYS5n+85qqSfWs21Y553L8zh/url U49DUJ/I3zGeoJmBBNamPDuYG0M7qwxcZF2BxxzR4hn25YYhytaYLwCM+0JdM61DkEi5 AH2TdZOfVf+C1POOjmxXwAaqd8jo6w/3yJ4u5R56AvJC9jtFCM+kzFdcPo3CIMfBhGXj fCNgsjhMP0qJgzkc8Y2OI5jHzkr2NT1ACeennzUr5C4UGYCJnBJh3cICinNBfBxeufsI bRSn2+2ycSaIAE3tQmT53LMKn0X4sTLP7upqX7sCwux3dij7dtP/KGwBdn617EakODxM mvhg== X-Forwarded-Encrypted: i=1; AJvYcCVEz5+3FmklyZ/cZesjNMNU6sChKMdIbdkRxV1WlKuvT+I4NBvWcPsWEkOsz+CfNI/zTIvItV6YEvgY@nongnu.org X-Gm-Message-State: AOJu0Yw47GqrMWzwBpTX57ywb+on03JKsm2vHRgr0g7bmDbbt3ppWz6Q UNdHaPzmNFofNX8hTJeStWuVli0KjEZYPczZQRYMuVFb/9tsq1DcHGhy3qtZqz0= X-Google-Smtp-Source: AGHT+IEMwa0uTkA57YVq8QyRnfzAPIK03A5xb3nbdhcI//ULSPBM6r28Im8OSZxxgno1CdVcpS6wTg== X-Received: by 2002:a05:6a20:e687:b0:1c8:b10d:eadb with SMTP id adf61e73a8af0-1cc8b4855b3mr14515630637.17.1724730653261; Mon, 26 Aug 2024 20:50:53 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd269sm74503625ad.135.2024.08.26.20.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 20:50:52 -0700 (PDT) From: Doug Brown To: Francisco Iglesias , Pavel Pisa Cc: Jason Wang , Paolo Bonzini , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH v2 6/7] hw/net/can/xlnx-versal-canfd: Simplify DLC conversions Date: Mon, 26 Aug 2024 20:49:26 -0700 Message-Id: <20240827034927.66659-7-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827034927.66659-1-doug@schmorgal.com> References: <20240827034927.66659-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=doug@schmorgal.com; helo=mail-pg1-x529.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 --- 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 5d7adf8740..589c21db69 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); From patchwork Tue Aug 27 03:49:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13778809 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5F5BC52D6F for ; Tue, 27 Aug 2024 03:51:41 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sinES-0005Hu-EY; Mon, 26 Aug 2024 23:51:00 -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 1sinEQ-0005Be-SU for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:58 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sinEO-0003rb-6E for qemu-devel@nongnu.org; Mon, 26 Aug 2024 23:50:57 -0400 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-7d1fa104851so1296907a12.3 for ; Mon, 26 Aug 2024 20:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1724730655; x=1725335455; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/zRMYEmVpTZe+R3MyadGyIt4py5ThMYbf+0okcx+mC0=; b=QpA5tWvCkSXOg27uO5imHcmghXAVKSvRVvpzBuU0J4t4163gJG1G7z1LCm0QRO2tZG IONY35LECB8YO6q5VEyI3I/K4jyCypKV+0qAI8zqoMmUn0/xNGfvZ+NA/bwGnXr3E3h8 kV47F5dy9v/HUAq/bJz2x83PHwNfRrABLnng8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724730655; x=1725335455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/zRMYEmVpTZe+R3MyadGyIt4py5ThMYbf+0okcx+mC0=; b=W1XKHrJxrURFqpGH9tfDF6YLGnNLZwepGjUpamJXU7rOgCo1LLSz7ZbLW5riz07gVZ jxPLfBOQAgy9Ur+HzcKGzo66/N1EGkKng4F36drtAyu+yYIMTB3CJpM/rXUCqwrXZOYh FOi7BLM4jBKraaYnEoTzMCXBkLBKUj5VHM+0s5PW3F+q3+n14Zls0nN45ktG115ZIuUl fungJ85ZFdfQUYRiRDRAJhkAm08FoV9GPHekJFU90uU9qf6VCdEQANvtxcphMxXnur6S 1m58FFNOaqa+wfnHjySDUsQZfZmKxfTcz+oZDtCh3Zhgc5uWiyQvIaZnroyJgvRA1s7D WI8A== X-Forwarded-Encrypted: i=1; AJvYcCUUAG1RF+brc+MQoyXEOXDq0mvLVwHQVJjzRpwqKSExalNR1LZpJRkhJWcC3re4XydqoazPuFO7a0fm@nongnu.org X-Gm-Message-State: AOJu0YxC35z33y2NTGlLKW4Di2BVYoXUMT2fqCSPj/vzNoUya5fL1kBK CIi80NUqtgl5RhRc4LY4egkVxNLcFGRbSjrZ70DXllPMcTh7rcr6GLy5vChEiLs= X-Google-Smtp-Source: AGHT+IGCevETHQsx4Ox8kx8Mvkuq5YUp3/5bmIZZFBi8ZndXG3W00PUxyF2V0DzCIYvEnnx9BwUS9A== X-Received: by 2002:a17:902:cf4f:b0:202:1db8:d9b0 with SMTP id d9443c01a7336-204df4803e0mr15259535ad.34.1724730654755; Mon, 26 Aug 2024 20:50:54 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855dd269sm74503625ad.135.2024.08.26.20.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 20:50:54 -0700 (PDT) From: Doug Brown To: Francisco Iglesias , Pavel Pisa Cc: Jason Wang , Paolo Bonzini , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH v2 7/7] hw/net/can/xlnx-versal-canfd: Fix FIFO issues Date: Mon, 26 Aug 2024 20:49:27 -0700 Message-Id: <20240827034927.66659-8-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240827034927.66659-1-doug@schmorgal.com> References: <20240827034927.66659-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=doug@schmorgal.com; helo=mail-pg1-x531.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, T_SCC_BODY_TEXT_LINE=-0.01 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The read index should not be changed when storing a new message into the RX or TX FIFO. Changing it at this point will cause the reader to get out of sync. The wrapping of the read index is already handled by the pre-write functions for the FIFO status registers anyway. Additionally, the calculation for wrapping the store index was off by one, which caused new messages to be written to the wrong location in the FIFO. This caused incorrect messages to be delivered. Signed-off-by: Doug Brown Reviewed-by: Francisco Iglesias --- hw/net/can/xlnx-versal-canfd.c | 36 +++------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c index 589c21db69..c291a0272b 100644 --- a/hw/net/can/xlnx-versal-canfd.c +++ b/hw/net/can/xlnx-versal-canfd.c @@ -1144,18 +1144,8 @@ static void update_rx_sequential(XlnxVersalCANFDState *s, read_index = ARRAY_FIELD_EX32(s->regs, RX_FIFO_STATUS_REGISTER, RI); store_index = read_index + fill_level; - if (read_index == s->cfg.rx0_fifo - 1) { - /* - * When ri is s->cfg.rx0_fifo - 1 i.e. max, it goes cyclic that - * means we reset the ri to 0x0. - */ - read_index = 0; - ARRAY_FIELD_DP32(s->regs, RX_FIFO_STATUS_REGISTER, RI, - read_index); - } - if (store_index > s->cfg.rx0_fifo - 1) { - store_index -= s->cfg.rx0_fifo - 1; + store_index -= s->cfg.rx0_fifo; } store_location = R_RB_ID_REGISTER + @@ -1172,18 +1162,8 @@ static void update_rx_sequential(XlnxVersalCANFDState *s, RI_1); store_index = read_index + fill_level; - if (read_index == s->cfg.rx1_fifo - 1) { - /* - * When ri is s->cfg.rx1_fifo - 1 i.e. max, it goes cyclic that - * means we reset the ri to 0x0. - */ - read_index = 0; - ARRAY_FIELD_DP32(s->regs, RX_FIFO_STATUS_REGISTER, RI_1, - read_index); - } - if (store_index > s->cfg.rx1_fifo - 1) { - store_index -= s->cfg.rx1_fifo - 1; + store_index -= s->cfg.rx1_fifo; } store_location = R_RB_ID_REGISTER_1 + @@ -1265,18 +1245,8 @@ static void tx_fifo_stamp(XlnxVersalCANFDState *s, uint32_t tb0_regid) " Discarding the message\n"); ARRAY_FIELD_DP32(s->regs, INTERRUPT_STATUS_REGISTER, TXEOFLW, 1); } else { - if (read_index == s->cfg.tx_fifo - 1) { - /* - * When ri is s->cfg.tx_fifo - 1 i.e. max, it goes cyclic that - * means we reset the ri to 0x0. - */ - read_index = 0; - ARRAY_FIELD_DP32(s->regs, TX_EVENT_FIFO_STATUS_REGISTER, TXE_RI, - read_index); - } - if (store_index > s->cfg.tx_fifo - 1) { - store_index -= s->cfg.tx_fifo - 1; + store_index -= s->cfg.tx_fifo; } assert(store_index < s->cfg.tx_fifo);