From patchwork Fri Aug 16 16:35:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13766755 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 683B8C531DC for ; Fri, 16 Aug 2024 18:18:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sf1X2-0004LI-TI; Fri, 16 Aug 2024 14:18:36 -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 1sezwe-0003GX-FR for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:56 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sezwZ-0002KG-7h for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:56 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-2d3ed48c748so159303a91.3 for ; Fri, 16 Aug 2024 09:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1723826210; x=1724431010; 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=Hpykp3v3nUS3no6XDt2FDZxaHDZOI6A5wRB8LlJUTdQ=; b=VqjC/92pQ54Pj0Mzn0kzAxfEQ8vMZgqMoxKEGM8NHas1Te9LJ782Jc26Iit+mpCJlw NZXlzFdsEu9FZBxeLWOC67oHdI/Hc9N/it/e45W/oEC5OyfN9qzbHio+55WheMWVo5og IU6eJu6OTJbcn+S0/0+brYUdc8Pl9vMNnwbYA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723826210; x=1724431010; 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=Hpykp3v3nUS3no6XDt2FDZxaHDZOI6A5wRB8LlJUTdQ=; b=NgiopPYQOz4Y1EutX65XKzKXwP7hSD/gqVecXZrC6ehQMo9ck334vleFacT2VCc4np I663NNIefw8hrr8SUNWLVgSrxfVFip/U09jd5Ee3ZaQ8wBlkyW8iTmmozpWRgSIOqJgb rVv5a9HPoJ8fbvxkgX4ty6U8CeL4qxNLp5AvOSJexuTHSTWIGnPFgDuYOLKoM2O80Cm/ BSueFj2DwUwqYtCT/3Bjw9uy4Z+9YtrhvF/Ccjy2RJSf3xniDGC3WVclvaueFmzs3Qzj Ct//S6DGdIZN94CB4Zs5woz5m0BHkd7nVGWHz6yLLzXvdMEYfg05SDDHhAUsIUGp5QxE UMHA== X-Forwarded-Encrypted: i=1; AJvYcCWRAc+mgtRjqTKiMzyvnx1SKwdv15StKeT13t4L9Ny5ZdDUsffsjLpbJC6ZSpiZiKWs6jpT8uWWkVxL@nongnu.org X-Gm-Message-State: AOJu0YzrcMhB7JZCTsJiIPhhkSZChZFaULzVC9csD7XCFd5QmWvAevVI TfUWiy/GAhjm4D+NZGrPeZDfe/VOUE7XNWsjnCXDMxugtWfzPXdfm8f0CmGg1UE= X-Google-Smtp-Source: AGHT+IHtue1ofcS5v4Hx4+pAt9Dw9ZXebnre/TFnx2PeOqt8lj0qBsytmNORWwtiXFPBgWyZLAcGKg== X-Received: by 2002:a17:90a:ad83:b0:2cd:1e0d:a4c8 with SMTP id 98e67ed59e1d1-2d3e02ebd87mr2208763a91.3.1723826209538; Fri, 16 Aug 2024 09:36:49 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2e6b201sm2134285a91.15.2024.08.16.09.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 09:36:49 -0700 (PDT) From: Doug Brown To: Vikram Garhwal , Francisco Iglesias , Pavel Pisa Cc: Jason Wang , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH 1/5] hw/net/can/xlnx-versal-canfd: Fix interrupt level Date: Fri, 16 Aug 2024 09:35:01 -0700 Message-Id: <20240816163504.789393-2-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816163504.789393-1-doug@schmorgal.com> References: <20240816163504.789393-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=doug@schmorgal.com; helo=mail-pj1-x1030.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-Mailman-Approved-At: Fri, 16 Aug 2024 14:18:34 -0400 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 --- 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 Fri Aug 16 16:35:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13766757 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 C7DEBC531DC for ; Fri, 16 Aug 2024 18:19:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sf1X0-0004B8-A9; Fri, 16 Aug 2024 14:18:34 -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 1sezwc-0003D9-JN for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:54 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sezwb-0002KV-2I for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:54 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2d3d486d8bdso251140a91.3 for ; Fri, 16 Aug 2024 09:36:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1723826212; x=1724431012; 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=dXryEFEA7lHJuOcvJ0eJXPDARQuNMSDNxcV14dvqN78=; b=d0GqBKRtoaTCNLivq0lRpT4CCGMYk7DRCsew2uhH2tgS5PLWx6qdZutkEAB7+H5K/b AL/K87ntTi/UWEpBwIJnE4ueA0A2E6jnAuIma2NKn65AamgPn0DJTOkSEuckv7lBJC7q aePjlDQepZVe79g+dM+JtZZTZ4ha9eD7ThNqw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723826212; x=1724431012; 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=dXryEFEA7lHJuOcvJ0eJXPDARQuNMSDNxcV14dvqN78=; b=uhtVLT0/0JstRtU4wz15bIA6KYPOOcH5WoeAFGuBeC8EEAwOx0/5gFVerxkQFaTvH+ 8HeEnvWFEm+RVURKaiPKC/ZUMovNAWa0At+8xpx7OkdVxrojMN085mg30dWDQySLHMJa sIywBr45b1S+RB1DDdI5DdsOYnDfieRH9hKhlb+zRJXaMuZFMo26R8Ld1flMYPi5yq7t eh8tjGCWdJhs49/PW4w1tVzK6uTi3OYlCxr9E3W4ClbBRweL/7qkomJpYUIdPsfKHhP9 LIB5yLPOiEh03cwF4g/ikAzs2jp+PTCQKrP83+JknE5bdTyA9TlB+B0IOrdPi3UTUypU 4DNw== X-Forwarded-Encrypted: i=1; AJvYcCWbnd7IGyrx5XMgPv711+emrdM+Y7AsIzvRVh7mpevOePBxDYxvDISd38wEx3FuBpLPTsLwzMIGDYx2niP1D1iJh908B6w= X-Gm-Message-State: AOJu0YzixDAt/J+r1GJJ2O3zHn6SgnELFOMyX07QAz18bKBfulmqLhfo ueCaRvZiNr32sI8xdXV0V2uw0pIxc4Yai1wakZxW1WFE4PE0cZT/26LehXmNU+s= X-Google-Smtp-Source: AGHT+IG1xMWqUlrBaBAM2Ig1Zy3oH2zeBxbPZinOUbKwoliYaJUy1oxjBTWzR1J+iAELeEsTT6ugXQ== X-Received: by 2002:a17:90a:9a9:b0:2c4:cd15:3e4b with SMTP id 98e67ed59e1d1-2d3e086417amr2226352a91.4.1723826211670; Fri, 16 Aug 2024 09:36:51 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2e6b201sm2134285a91.15.2024.08.16.09.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 09:36:51 -0700 (PDT) From: Doug Brown To: Vikram Garhwal , Francisco Iglesias , Pavel Pisa Cc: Jason Wang , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH 2/5] hw/net/can/xlnx-versal-canfd: Fix CAN FD flag check Date: Fri, 16 Aug 2024 09:35:02 -0700 Message-Id: <20240816163504.789393-3-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816163504.789393-1-doug@schmorgal.com> References: <20240816163504.789393-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=doug@schmorgal.com; helo=mail-pj1-x102d.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-Mailman-Approved-At: Fri, 16 Aug 2024 14:18:29 -0400 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 --- 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 Fri Aug 16 16:35:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13766758 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 91899C3DA4A for ; Fri, 16 Aug 2024 18:19:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sf1X3-0004O4-Ii; Fri, 16 Aug 2024 14:18:37 -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 1sezwe-0003GZ-Iq for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:56 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sezwc-0002KZ-Qf for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:56 -0400 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2d3e6fd744fso140153a91.3 for ; Fri, 16 Aug 2024 09:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1723826213; x=1724431013; 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=arg2TvA2GPM8gZ2q2s2JlR3QumG7iRuQQq7xe/+qsBo=; b=WFK6eqnZwsB/413xoHiWSa8YYHDM1Y5xomg9GPY7DdtysBkYxJH5RVVQqkmcesUkF+ Z8qajv/8glpmlgy7h4tUOns3jsu2zm7dSDmj1sDHtJez1Bw74xD21XCRbts858uZnbVe QeG8La9+KREf62bXjVxZ7wPfG3DuT6u0y++kw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723826213; x=1724431013; 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=arg2TvA2GPM8gZ2q2s2JlR3QumG7iRuQQq7xe/+qsBo=; b=Dw20SEGgSh2KpIg/iFZcc/PjixVpkByn7F0T0CmSCmoNpF5hECAHASRYnLLyerPDSu cr5FuDvuGGklnl5J5CvrmiaueLyiUVy3Dxq9gtm1F1PzKrY+tEmgsKotQ5tivyRrRbQq CJDAvfxlXSwn91SoywcRD4f7bn8qYbLhNvLmg2hleTWwYqOzT4NaUvGiYVy7Ex69b3FT rXR1E/VPqGfMQTdlInIWQN7TH0rE4pCEN86NrGlrIY4MnoN95G8hA8MI1qAFVz41ZbeZ ZIPRUag8MH9lfR9p8ZfH+3S4KNGu0eryIGSVf4CXcBbBgDdgMTVPwW7YCn3Q2TQwXya4 F5Dw== X-Forwarded-Encrypted: i=1; AJvYcCWAB6dnajPMuHNOjqjAR+u7ThjIVz2/d5zAwaiIWaqdDKcbGcYuLe7chlVV4FlrStj+ac4bOXLngovR@nongnu.org X-Gm-Message-State: AOJu0YzoN8fV+H9dUB/LxBr7+VYGQo74/BUkgq7t/8dY6nOiAP1nZHDW ItuoTnPT70shd7Gk2+YxEKoy6AjqTfw2+uJAAYLdXz/txIo+pBfrSbTuXsu/it50ceWAij1ngGY I96r/2A== X-Google-Smtp-Source: AGHT+IH6FsrYq3xYeN+0mTYBT1bY3l8I2ngn3RLvNXgzVs0mUr5pGTzRQ5xEVSmhszfhfAmPXNReqQ== X-Received: by 2002:a05:6a20:394a:b0:1c2:9009:f6f with SMTP id adf61e73a8af0-1c9a1e9bb9amr2043871637.4.1723826213350; Fri, 16 Aug 2024 09:36:53 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2e6b201sm2134285a91.15.2024.08.16.09.36.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 09:36:52 -0700 (PDT) From: Doug Brown To: Vikram Garhwal , Francisco Iglesias , Pavel Pisa Cc: Jason Wang , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH 3/5] hw/net/can/xlnx-versal-canfd: Translate CAN ID registers Date: Fri, 16 Aug 2024 09:35:03 -0700 Message-Id: <20240816163504.789393-4-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816163504.789393-1-doug@schmorgal.com> References: <20240816163504.789393-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=doug@schmorgal.com; helo=mail-pj1-x1034.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-Mailman-Approved-At: Fri, 16 Aug 2024 14:18:35 -0400 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 --- 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 Fri Aug 16 16:35:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13766756 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 A141AC3DA4A for ; Fri, 16 Aug 2024 18:19:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sf1X9-0004nW-4x; Fri, 16 Aug 2024 14:18:43 -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 1sezwf-0003Hy-Tm for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:57 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sezwe-0002Kj-8t for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:57 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-2d3d4862712so231738a91.2 for ; Fri, 16 Aug 2024 09:36:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1723826215; x=1724431015; 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=gF5wQtBRwS5BcKCR1fatsaBhyKFb2ABe75XUBpYoZfQ=; b=bOOgpPU47DHLJqCgRPm+hiL9bFX8BjxbHJ3FjbLoSfqQsK4q8iqwZP1QQ6GmO/Jl3v 2taBKBJSwsphcpZV3+Jcp92azg7E2TQd0Il8HVs4umrcXsBKder5PDM7hCm6WVzbLns0 KCQfDVo8yYtFOaW314OJCQcI9L0OSkx3eKxcE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723826215; x=1724431015; 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=gF5wQtBRwS5BcKCR1fatsaBhyKFb2ABe75XUBpYoZfQ=; b=ZrAJprBw1Wng+M1ZtHWYx4rDLrp1GWKfQsQ19XjhvpueA/0eyiJGRmuwN7lAUXvwtJ GDfRta+sjeh2phJHhAjpPVC7RSn6UQyRyYF5MYpAw2ZYBr/MAwOv6C6dpbCuuIrzb4dN /40sEBp+OaYJx7YweIyy8fcToStkFT7KsnzKS6ej96gej1Qblm9Ic753hs629M3kjVVf IZwQ6Pb1/ZoCK6Mh46YUy2zJRA1bVf69MD1J0TjaduOmEb4BP2/n7NGe07G4kqAR7lge Oj9Y4kTYVi008ndxOHPHoGTeB4oBuPqp6EachtV2A+I4M3f74IpaTcY5WAmMGTpL3c4N Nmag== X-Forwarded-Encrypted: i=1; AJvYcCW9Jj7WTbkBqMQEEM7b5WNSq2bfo4I3zEHhY7kO8AiGf9PdAtx3Mb72vgVINeR1gj5p5pIMt8HX8Y2MJUQ8R6kJggnBsfY= X-Gm-Message-State: AOJu0YwbjI5+NvZOhbl9NryCdElAK2GT/tVVOJ6zNrbKFIXHZSDqED7r /JMPDnC1QK9CBbnwBxUq2fVMbnH3mZkkYBnI9Ac7AQbdThKXRiBypzvmjfqXTBQ= X-Google-Smtp-Source: AGHT+IGzW99cJKbppBdD/yEWS+jyMZaQEUXcPyTXolnJe480/RZ09i+Lp2aJkXpbluZDqh6DlRxVSQ== X-Received: by 2002:a17:90b:124a:b0:2cb:4382:99f1 with SMTP id 98e67ed59e1d1-2d3e1e10102mr2129671a91.6.1723826214781; Fri, 16 Aug 2024 09:36:54 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2e6b201sm2134285a91.15.2024.08.16.09.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 09:36:54 -0700 (PDT) From: Doug Brown To: Vikram Garhwal , Francisco Iglesias , Pavel Pisa Cc: Jason Wang , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH 4/5] hw/net/can/xlnx-versal-canfd: Fix byte ordering Date: Fri, 16 Aug 2024 09:35:04 -0700 Message-Id: <20240816163504.789393-5-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816163504.789393-1-doug@schmorgal.com> References: <20240816163504.789393-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=doug@schmorgal.com; helo=mail-pj1-x102c.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-Mailman-Approved-At: Fri, 16 Aug 2024 14:18:42 -0400 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 --- 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 1704b558d0..fda1e7016a 100644 --- a/hw/net/can/xlnx-versal-canfd.c +++ b/hw/net/can/xlnx-versal-canfd.c @@ -945,7 +945,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++; @@ -1080,19 +1080,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 Fri Aug 16 16:35:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Brown X-Patchwork-Id: 13766760 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 D5B3CC3DA4A for ; Fri, 16 Aug 2024 18:20:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sf1XA-0004tr-O8; Fri, 16 Aug 2024 14:18:44 -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 1sezwh-0003J0-IR for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:59 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sezwg-0002L0-0Z for qemu-devel@nongnu.org; Fri, 16 Aug 2024 12:36:59 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2d3c99c5d69so303064a91.1 for ; Fri, 16 Aug 2024 09:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; t=1723826216; x=1724431016; 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=kFdvC6MeP6yP93X/5WA8Lf++mX0YuQiplIojlGAQD34=; b=BNoD6jCCWFMYRbCRO8qxJSpdiRlkmwOBmm3cYQjiZkgsufwZlUCOzcpZGTz+aAGfQ7 1z9Gmg8lblU95EZMWq1fDSEucw7+F7Xkg202L/E6sen9390wNdbCBAOO/QsgVIMWJXQn ZKQLwjEsNgPR08m8NZozOFdmj1/nEFz2dmLSE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723826216; x=1724431016; 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=kFdvC6MeP6yP93X/5WA8Lf++mX0YuQiplIojlGAQD34=; b=us6QK2DtE0eJWG6aoCA5tXbGu9T4mTBZQYtryMkTraZjrKAZPi0hMEdKFb9t+YBWe/ zcVjlYAq+uwWJF3oxMQeZ2kGpM6T9IrsYE6AeT1hDZWY2OLFJ+0om8RXlvTXwkhXdsZu WeTQXvfiLBBnHQRhaYSHg4bxguQh/Z0RTGCpV/K+/3R7to8weQqDi6GmHTAhWdzCKTjA sd1R4QTQd49/QA7gF/7b3H1UaCy4BQTE09USYa7UU2BZVudl5wP2SWfVWPEVtis5x3mB ozLScp4ZZ7nbThxiJ84gLwGU1Cvk2YMwWYVnUOOYf23Yc/Zc8dzj/ggkSDf7PBoqJr95 Ft4g== X-Forwarded-Encrypted: i=1; AJvYcCWRjCs5fYAL3nlNxq7wpoGfW0jy4Hd+8988kaeYRyaA/jdv2nOgCtg2RT+QWC0hy7e7S9MGzWQFUIvZkc4MkbnteWFDnzc= X-Gm-Message-State: AOJu0YzF/uCX+hmzAqbBmXhUnDBBDiFh8JIPGIFtbDTxb188m9vNgacf NE2BxEh0heLrcC/9A+LzjtRMw4AQW1ZJ2VEFuQzZFome1bNXXg8CvTP3zNJqv9I= X-Google-Smtp-Source: AGHT+IHmWA36aomK2A2/el1m/B1FdBylg7BZTz/BhCM5RRLZiXvw7jp6k+m5SlwCquHKZfBrsGDVMA== X-Received: by 2002:a05:6a21:788e:b0:1c4:c007:51b7 with SMTP id adf61e73a8af0-1c9a2a456f3mr2103118637.6.1723826216349; Fri, 16 Aug 2024 09:36:56 -0700 (PDT) Received: from doug-ryzen-5700G.. ([50.37.200.153]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3e2e6b201sm2134285a91.15.2024.08.16.09.36.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 09:36:55 -0700 (PDT) From: Doug Brown To: Vikram Garhwal , Francisco Iglesias , Pavel Pisa Cc: Jason Wang , qemu-devel@nongnu.org, Doug Brown Subject: [PATCH 5/5] hw/net/can/xlnx-versal-canfd: Handle RX of short FD frames Date: Fri, 16 Aug 2024 09:35:05 -0700 Message-Id: <20240816163504.789393-6-doug@schmorgal.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816163504.789393-1-doug@schmorgal.com> References: <20240816163504.789393-1-doug@schmorgal.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=doug@schmorgal.com; helo=mail-pj1-x102b.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-Mailman-Approved-At: Fri, 16 Aug 2024 14:18:43 -0400 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 There was no case for handling received CAN FD frames with a DLC of 0-8. This was already handled properly with TX. Add similar code for RX. Signed-off-by: Doug Brown Reviewed-by: Francisco Iglesias --- hw/net/can/xlnx-versal-canfd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hw/net/can/xlnx-versal-canfd.c b/hw/net/can/xlnx-versal-canfd.c index fda1e7016a..ce68dab46a 100644 --- a/hw/net/can/xlnx-versal-canfd.c +++ b/hw/net/can/xlnx-versal-canfd.c @@ -1052,10 +1052,15 @@ static void store_rx_sequential(XlnxVersalCANFDState *s, 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); + if (dlc <= 8) { + dlc_reg_val = FIELD_DP32(0, RB_DLC_REGISTER, DLC, dlc); + } else { + /* 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); + } } } } else {