From nobody Mon Nov 23 04:36:06 2026 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; arc=pass (i=1 dmarc=pass fromdomain=gmail.com); dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=2; a=rsa-sha256; t=1794834332; cv=pass; d=zohomail.com; s=zohoarc; b=iU6rsodMOXN2KTHDZsU+qQfPEyZG4PReAKXyn/cpOOjUwCUUdKUIlTw9JtOiXTFiEWQCbM98dMw6pm4QZoxNEzJVYzb3aEOZD8uOEOAazyQk7NXeklPPndPx1uPvjpWNGKIfzEefJV8B0kwXhzKsgztzIk3Ut2tX92ZupIvFVos= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794834332; h=Content-Type:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/teIbFDfFMVmxQje9kp2hS399UAI+EGdwUcW/53j7Yg=; b=XfVpiRb5qaJ3n/Xe3qhEyKL8ds3A2lX6cuI4M4zWyJkE432IyZO34Hj3UFkBVqu/PmCHoGo911LfpbJUyH8Nj2hcYlfHYCI4mn9gtIH4pQB4wDiKfnPrupALovC5L1Pfcf9utlOtf1Fk455HW3cfSLvejyDwyM9n7v9m2yjohIo= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=gmail.com); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794834332843918.0759218595576; Mon, 16 Nov 2026 05:05:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xSwOL-0002zU-UU; Mon, 16 Nov 2026 08:05:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xSntX-0008JJ-NF for qemu-devel@nongnu.org; Sun, 15 Nov 2026 23:00:42 -0500 Received: from mail-ej1-x629.google.com ([2a00:1450: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 1xSntU-0001fT-AW for qemu-devel@nongnu.org; Sun, 15 Nov 2026 23:00:38 -0500 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-c4322d310e7so560485266b.0 for ; Sun, 15 Nov 2026 20:00:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794801634; cv=none; d=google.com; s=arc-20260327; b=rFz5oiYbqL/9YVCM0LV+bxwuUKlwl0Kp0Kh+xtAdauvSDhajit9zZIxPWL/4DRwpLi CyqPW3zkmByS6lWCKZPD3Gw0UNAI+FrIrEmYx4p8Z9fbzfZHleyDdP1stXoBa/IJ+wMA Y7wfDqvE/CmeXTrhtYFu9uJMOq8TUNObGrdG+tPa8GAEFINrH2w2TAAIWFQjwSlF839f XH/OcszhSpld8nB+R4+/yJH6CJhsKgjNfYjQ3xQ0apLcO6D8pRovIHNzj1nXDpNkEoMH LOBkhmY3QFpcCgMpGKH317CdETDBGlEIUx4P4CBgtPZRI3XWjIT1t3UcWV01EMEnDnvu MvuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:mime-version:dkim-signature; bh=/teIbFDfFMVmxQje9kp2hS399UAI+EGdwUcW/53j7Yg=; fh=+1s+9yvYs7Nh3GwsadYf3eNpEFzOi0Ny4bdYxASykYA=; b=efmypcQrNPiCviwoop/egFYWShcJFcCN4CPRRB5hqGY48d327G9VWEeCzs3i09qh8Y /SAbikQL0OgNqzfhj+nwGg6a6STYrXtOdxH6uPPBbovSosth0+ZjIwzYYTaVW0fVWkQp JIb+1pyyWq7UJqGk4WYc+T9yQ27a2kc75ZXFWNqhI1w+E835tt+cGGZFe7aYliCYwpbj NW7TD4r1YsUMzIYm/BrHP5YUkjBuijSgAMweB03eJiuukb8nCUd6wRrmvRac9U+EOd/s 7dxX1lY2SpzggHYlar4GVneeTIEju0PST5uceRwqbniQIkXV5LFofL52zZ4OPNZRJQo/ fhuw==; darn=nongnu.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794801634; x=1795406434; darn=nongnu.org; h=content-type:cc:to:subject:message-id:date:from:mime-version:from :to:cc:subject:date:message-id:reply-to:content-type; bh=/teIbFDfFMVmxQje9kp2hS399UAI+EGdwUcW/53j7Yg=; b=HVNRQx1hQdmpQ9Ew7PHCuNWKRYltH8y/IekdgPr3SMWzNuhTvXR68U0ZHc3WC3bzxW kg3k1Qzii41UQDCHLFzfno52Hsn1GebqIfcAeHXQnK99xCY0vAB5WARCK5pbbN92p5/x yyrNVjEeulRA//ttrEE2ztAy8xrtG4YarXQUtuxiV1Z502dViNgV5gfvJI2h7WCoD+BE 0L/SJaNJCM9dj5hUPwf0yhc03B4dEXfXCCycCA9r0kVH6G/K5HWxT7KoFDQcbOQCmiaB M07N67hFyfqpfJsCMgPTKTlbSxOKvlEC+k+qYk6tn7mg7r8FjDGlvWb3U3bPfyW6nkGL bSJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794801634; x=1795406434; h=content-type:cc:to:subject:message-id:date:from:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-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SNKOileT8EhyHiEzSOC7CdUOG4CLs/U63qMBgtSLxPA2FtkJOH61tyfQoUk/Mp ZZlp/vSbCYU X-Received: by 2002:a17:906:f596:b0:c42:3a77:80e5 with SMTP id a640c23a62f3a-c5096349305mr762081166b.29.1794801634080; Sun, 15 Nov 2026 20:00:34 -0800 (PST) MIME-Version: 1.0 From: Dzulfikar Ats Tsauri Date: Mon, 16 Nov 2026 11:00:22 +0700 X-Gm-Features: AclHuK9RJYo_Pf7sTorHpSbFMZB9nO2LqDVHOtnTTe8jFUF5wZzdy4pbaSZRSXE Message-ID: Subject: [PATCH] hw/net/can/ctucan: report fault confinement state, raise FCSI on enable To: qemu-devel@nongnu.org Cc: Pavel Pisa , Francisco Iglesias , Vikram Garhwal , Jason Wang 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=dzulfikar.at@gmail.com; helo=mail-ej1-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, FREEMAIL_FROM=0.001, 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-Mailman-Approved-At: Mon, 16 Nov 2026 08:05:00 -0500 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @gmail.com) X-ZM-MESSAGEID: 1794834334841158501 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The CTU CAN FD model never leaves its reset fault confinement state: INT_STAT[FCSI] is never set, and reads of the EWL/ERP/FAULT_STATE (0x2c) and REC/TEC (0x30) words are not handled, so they return 0. The CTU CAN FD datasheet (v2.7.0, section 2.5 "Operating modes") describes what happens when software sets SETTINGS[ENA]: the core integrates to the bus while it is bus-off, then becomes error-active, and "the moment when CTU CAN FD joined CAN bus communication can be determined by FCS interrupt, and subsequent probing of FAULT_STATE". Section 2.12.2 adds that FCSI is set "upon any Fault confinement state change (even bus-off to error-active)", and the COMMAND[ERCRST] description that a disabled core (SETTINGS[ENA] =3D 0) is bus-off. The RTL matches: fault_confinement_fsm.vhd resets to bus-off, the CAN core is held in reset while ENA is 0, and protocol_control_fsm.vhd sets the node error-active, clearing REC/TEC, at the end of integration. The Linux ctucanfd driver relies on exactly this. ctucan_chip_start() sets the interface state to CAN_STATE_STOPPED ("Controller enters ERROR_ACTIVE on initial FCSI") and enables the core; the error interrupt handler then reads FAULT_STATE to find the new state. With the model, the interface stays STOPPED ("ip -details link show can0" reports "state STOPPED") although frames are sent and received, and raising FCSI alone would not be enough: FAULT_STATE reads as 0, which the driver treats as an invalid state (WARN in ctucan_read_fault_state()). Model the documented behaviour: - Reset (MODE[RST]) sets the register reset values: EW_LIMIT 96, ERP_LIMIT 128, FAULT_STATE bus-off, REC and TEC 0. - Clearing SETTINGS[ENA] returns the node to bus-off with cleared error counters. - Setting SETTINGS[ENA] makes the node error-active and raises FCSI. The model has no bit timing, so integration completes at once. - EWL/ERP/FAULT_STATE and REC/TEC are readable. The model does not produce bus errors, so the node then stays error-active until it is disabled or reset. Writes to EWL/ERP are still ignored (Linux never writes them). Both registers were already part of the migration state, so no VMState change is needed. Datasheet (v2.7.0): https://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/doc/Datasheet.pdf RTL: src/can_core/fault_confinement_fsm.vhd at commit b76a8888ecd1 of https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core Driver: drivers/net/can/ctucanfd/ctucanfd_base.c in Linux Signed-off-by: Dzulfikar Ats Tsauri --- Tested on master 29760efaf9 (v11.2.0-rc0) with qemu-system-aarch64 -M virt (--target-list=3Daarch64-softmmu), booting a Linux 6.18.59 (arm64) image wi= th -device ctucan_pci bridged to a host vcan interface (can-host-socketcan): - With the patch: the driver logs "ctucan_err_interrupt: ISR =3D 0x00000010" and "state changes from CAN_STATE_STOPPED to CAN_STATE_ERROR_ACTIVE"; "ip -details link show can0" reports ERROR-ACTIVE; after "ip link set can0 down" it reports STOPPED and the next "up" raises FCSI again; classic and CAN FD (64 bytes, BRS) frames pass in both directions. - Without the patch, same image and setup: frames pass, but the state stays STOPPED. - tests/qtest/xlnx-can-test (5/5) and xlnx-canfd-test (3/3) still pass. There is no qtest for the CTU CAN FD model yet; I can write one (enable the core, check FAULT_STATE and INT_STAT.FCSI) if that is wanted. The same change on QEMU 10.2.0 has been in use in a Yocto build since 2026-11-11. hw/net/can/ctucan_core.c | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/hw/net/can/ctucan_core.c b/hw/net/can/ctucan_core.c index f6ff4ad..d2bb747 100644 --- a/hw/net/can/ctucan_core.c +++ b/hw/net/can/ctucan_core.c @@ -188,6 +188,36 @@ s->status.s.txnf =3D txnf; } +/* + * Fault confinement. While SETTINGS[ENA] is 0 the CAN core is held in res= et: + * the node is bus-off and both error counters are zero. After the core is + * enabled it integrates to the bus and, coming from bus-off, becomes + * error-active, clears REC and TEC and raises FCSI. The model has no bit + * timing, so integration completes at once, and it never sees bus errors, + * so the node stays error-active until it is disabled or reset. + */ +static void ctucan_fault_confinement_reset(CtuCanCoreState *s) +{ + s->ewl_erp_fault_state.s.era =3D 0; + s->ewl_erp_fault_state.s.erp =3D 0; + s->ewl_erp_fault_state.s.bof =3D 1; + s->rec_tec.u32 =3D 0; +} + +static void ctucan_set_err_active(CtuCanCoreState *s) +{ + union ctu_can_fd_int_stat int_stat; + + s->ewl_erp_fault_state.s.era =3D 1; + s->ewl_erp_fault_state.s.erp =3D 0; + s->ewl_erp_fault_state.s.bof =3D 0; + s->rec_tec.u32 =3D 0; + + int_stat.u32 =3D 0; + int_stat.s.fcsi =3D 1; + s->int_stat.u32 |=3D int_stat.u32 & ~s->int_mask.u32; +} + void ctucan_hardware_reset(CtuCanCoreState *s) { DPRINTF("Hardware reset in progress!!!\n"); @@ -230,6 +260,11 @@ s->rx_fr_ctr.u32 =3D 0; s->tx_fr_ctr.u32 =3D 0; + s->ewl_erp_fault_state.u32 =3D 0; + s->ewl_erp_fault_state.s.ew_limit =3D 96; + s->ewl_erp_fault_state.s.erp_limit =3D 128; + ctucan_fault_confinement_reset(s); + s->yolo_reg.s.yolo_val =3D 3735928559; qemu_irq_lower(s->irq); @@ -311,12 +346,21 @@ } else { switch (addr & ~3) { case CTU_CAN_FD_MODE: + { + bool was_enabled =3D s->mode_settings.s.ena; + s->mode_settings.u32 =3D (uint32_t)val; if (s->mode_settings.s.rst) { ctucan_hardware_reset(s); s->mode_settings.s.rst =3D 0; } + if (!was_enabled && s->mode_settings.s.ena) { + ctucan_set_err_active(s); + } else if (was_enabled && !s->mode_settings.s.ena) { + ctucan_fault_confinement_reset(s); + } break; + } case CTU_CAN_FD_COMMAND: { union ctu_can_fd_command command; @@ -494,6 +538,12 @@ val =3D 0; } break; + case CTU_CAN_FD_EWL: + val =3D s->ewl_erp_fault_state.u32; + break; + case CTU_CAN_FD_REC: + val =3D s->rec_tec.u32; + break; case CTU_CAN_FD_TX_STATUS: val =3D s->tx_status.u32; break; --=20 2.56.0