From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB8133E714A for ; Fri, 15 May 2026 16:26:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862401; cv=none; b=fCBm8V6KnfpzujkEBL0Z+fXVGvsMHpqqdehmocQ+S0gaw31VcZWxQx2r7SPIZsGWXSCp4nER21Mi9zVGvrYQ7UipuuuU+d4wTjaBOhwj3vzgqV1K4KPZZIk5lrirL1qdGoBrM8UNmlkZv9Yj8oCebIAWRpIFenAI6/+9UB9Z1Xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862401; c=relaxed/simple; bh=MqUQxPJtRMYyoi1ZCQXB70GwPNJeUef867jmLmOks/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BwZeNXo3ljebwffLB7Y3ZGFriuxQJKqF/E4sE2KxZq3G6wNV6X8Lb0eBlZmZhXcK4zi2B1wugeEqQYgdAx41ds3t4nYwZV/d8l73zuEs6MyFDGQfITHHtwGJIqJR9VQmMsEv/pRg9aDK3CwORyVSvJmYHYJWGQKnmEXY4MAQ4VQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dfUgLfaY; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dfUgLfaY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862400; x=1810398400; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MqUQxPJtRMYyoi1ZCQXB70GwPNJeUef867jmLmOks/U=; b=dfUgLfaYtCdQr1ZgW1TgUEhP3SXDSqlHptizsMJfGY6QIn3rZ5pwi0TV qtIYldezmQHtraxivGB65xJYlc5oU2dSAzrJ14QCu/HqBc5KUykjjxBZf S/jFeb6ai+9M+v7mYz84FBP2qplxqw+aG1hLqJ6HLYC5FVMdrA8TiWs6S OSPFT+BIO62wbNqvJ49ysuVo0YbXoGxJK8lgBXrEK7kqq50V4nZm1AC8q SyckO6rp9lPIOL92aAbQuATJsRIACjlQESOuvuX7mOCC1owZsgj/3DuAG I/bPHReCzvn7th6O8CFcayMqnVY0xlcF3dDNOEMF2wuRGPN236rb6gVhg A==; X-CSE-ConnectionGUID: tWIsZwqkRpyR535jA80lZw== X-CSE-MsgGUID: gPNQrVPwS++S5WLFS+kz4A== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785223" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785223" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:38 -0700 X-CSE-ConnectionGUID: eeoBwHfTRRygzhT6+8r9bA== X-CSE-MsgGUID: b1wIOrVET8ivUnZR3VNi0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857129" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:34 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 01/17] i3c: mipi-i3c-hci: Fix suspend behavior when bus disable falls back to software reset Date: Fri, 15 May 2026 19:26:05 +0300 Message-ID: <20260515162621.57719-2-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Software reset was introduced as a fallback if bus disable failed. The change was made in 2 places: the cleanup path and the suspend path. For the cleanup path (i3c_hci_bus_cleanup()), after software reset the function continues to do cleanup for the current I/O mode. For the suspend path (i3c_hci_rpm_suspend()), after software reset the function returns early. However software reset does not reset any Ring Headers in the Host Controller, so returning early is not the right thing to do. Instead, continue to call suspend for the current I/O mode, which for DMA mode will reset any Ring Headers. Note, although Ring Headers should not be active at this stage, performing this reset follows the procedure defined by the specification and keeps the suspend path consistent with the cleanup path. Note also, i3c_hci_sync_irq_inactive() is still called via the PIO and DMA hci->io->suspend() callbacks. Always return 0 because the device is quiesced as much as possible and returning a negative error code would unnecessarily prevent system suspend. Fixes: 9a258d1336f7 ("i3c: mipi-i3c-hci: Fallback to software reset when bu= s disable fails") Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V4: None Changes in V3: Add Frank's rev'd-by Changes in V2: Always return 0 from suspend callback Amend commit message drivers/i3c/master/mipi-i3c-hci/core.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index b781dbed2165..afb0764b5e1f 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -762,15 +762,10 @@ static int i3c_hci_reset_and_init(struct i3c_hci *hci) int i3c_hci_rpm_suspend(struct device *dev) { struct i3c_hci *hci =3D dev_get_drvdata(dev); - int ret; =20 - ret =3D i3c_hci_bus_disable(hci); - if (ret) { - /* Fall back to software reset to disable the bus */ - ret =3D i3c_hci_software_reset(hci); - i3c_hci_sync_irq_inactive(hci); - return ret; - } + /* Fall back to software reset to disable the bus */ + if (i3c_hci_bus_disable(hci)) + i3c_hci_software_reset(hci); =20 hci->io->suspend(hci); =20 --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8E4B3F58CD for ; Fri, 15 May 2026 16:26:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862401; cv=none; b=GkukEpz6Vse8FwNlRvIM2DaULyb6u6yPyHwrDN1CA3ui33aSDX6lWudBEeL/thxsp3XogtTRchHyIv76tY3cCfXgUhnqffGXWUtlSYfbVTmCq55iLWc9RUsM6n+w6cqivjSvM44smywkQcwf1aecdVYGW9h4GnJm4WyLx75C9fg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862401; c=relaxed/simple; bh=ObbOkCE44+r/FKwgeTpdAODaGKkmUlmyYBoR8+AOZxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rutrg/1T8QyrHpe6Jej8ra3zmILa93OVz6+odR7M6FVNLyRN2ABBit+5RKM4qrqsS/xU8tBQwT0bYFOIRXUFKPTkrHTm/t6mVaq0g3kbAn5DtVaJ6q/SWpPK/s0aBMEIvTVAO1kSBEPz1pzq/wIJ9LrwmCKaB5gjDJStK7CPB00= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JvXU+LvF; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JvXU+LvF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862400; x=1810398400; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ObbOkCE44+r/FKwgeTpdAODaGKkmUlmyYBoR8+AOZxc=; b=JvXU+LvFEVzUl02rlbrK6dRf8ymGkTP/NmVzFPi4N5CYIhTkHNBrGavx Wdd1k4QhWqwft0yorqCFMvRtydJktO/KofpyNq8VsXltflTwwI8IlyHLa 9cZIm3slV4nYnSalgZ6D7pv9cf+n/Hew236tZVOq4l9hJyfLtv018mr5p R1D5toQdMktsRtuUrlm0Ys0Vt/uQ612oeiBdrgANcrdkGFPghhp2gxJUE ue/Yh47g8OXpXB9MIcTyw1mgPwJ5Yp7QhJjEgknvEwqMtk1bxUYe1dYuY 8KOJttFxl75ux8oHImpADPjZFNYxhxoYLuRk9qIzkvMQSRS4DU7sj+0WU A==; X-CSE-ConnectionGUID: ADgzPdWvRw25fD3GZtMoIA== X-CSE-MsgGUID: wZDDy8cYSBStvvihynnmgg== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785227" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785227" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:38 -0700 X-CSE-ConnectionGUID: SdgyzqifTAuRnXcUrmaF3A== X-CSE-MsgGUID: O/1n+4/zSsq1QcCfWUlxmw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857133" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:36 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 02/17] i3c: mipi-i3c-hci: Preserve RUN bit when aborting DMA ring Date: Fri, 15 May 2026 19:26:06 +0300 Message-ID: <20260515162621.57719-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The MIPI I3C HCI specification does not require the DMA ring RUN bit (RUN_STOP) to be cleared when issuing an ABORT. That allows the DMA ring to continue to receive IBIs, although an IBI is anyway not lost because it can be received once the ring restarts if the I3C device has not given up. Note, currently ABORT is only used on a timeout error path so the change has very little effect in practice. In the more common case of a transfer error, the ring (bundle) operation is halted by the controller anyway. Adjust the RING_CONTROL handling to set ABORT without clearing RUN_STOP, bringing the driver into alignment with the specification. Fixes: b795e68bf3073 ("i3c: mipi-i3c-hci: Correct RING_CTRL_ABORT handling = in DMA dequeue") Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V4: None Changes in V3: Add Frank's rev'd-by Changes in V2: Improve commit message drivers/i3c/master/mipi-i3c-hci/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index e4daaa612055..bdffdd8b8923 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -554,7 +554,7 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, if (ring_status & RING_STATUS_RUNNING) { /* stop the ring */ reinit_completion(&rh->op_done); - rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE | RING_CTRL_ABORT); + rh_reg_write(RING_CONTROL, rh_reg_read(RING_CONTROL) | RING_CTRL_ABORT); wait_for_completion_timeout(&rh->op_done, HZ); ring_status =3D rh_reg_read(RING_STATUS); if (ring_status & RING_STATUS_RUNNING) { --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48BE13FD950 for ; Fri, 15 May 2026 16:26:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862403; cv=none; b=CBqGhrkSwOiUR0xQ4eBEmmC5Rq1xIStv+gEtAf5C7tKaKRJ/k56DblsIlF+d4kxh79hUXJnrJ9WC2+4Vs/MktqL8xlKKa4NaH0nV0nxk982IWNqJvPT/eLJ6tKpHCzLrmFEtwBTG02hnBUfS3Ow1ZpH1oBjKP/M8pXQP8fxeFEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862403; c=relaxed/simple; bh=p14xCUTELcWuRMCXox69iS/zsIC4SjMMl8Z1ckiUQeQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VeO5o90XzbJUnZnSBe0+Yt7y42yyLWG29tn0JTa2tnJ37uRICjvruEVrDgNHBwcvfzycrOB63wK0TML0YniUoYCfPvU/6/RgyDM1XmFvO0bR5MI0BdzUT9ZzwyQAZkAh9zI1JtwXiIC6sYFkVfMqU8hR3BT03MJQMZt8abhp8AQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=augsJYkh; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="augsJYkh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862402; x=1810398402; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p14xCUTELcWuRMCXox69iS/zsIC4SjMMl8Z1ckiUQeQ=; b=augsJYkhIlChxPNWbdQKA5Y/a/LdpMZjOpiZnLpi68zsQTnHFiBktkgN 1l4I+pX6IEByN+4bpZInBUKzjgZ0uQJK44fPce3otMEO0/RoGOfhnbzzi kkmdvDMxWPrfZnzLtxeJjtuwgMG3Bl+dLslWo2rOGxkCuHBGqNWYI+ji3 R+458PGl39k+aU3p122JJEZMQSz46K9KwlFJ09EuBbxr11O8IxKhFp485 v+1Gok8ZAZsEs4G66ERYqs3jjdtIVf04587Cw06tFrCMBwI+8c95FYmjJ oqRx2whH/OsYTzD7h+1F7Gd/j6sgte0OBYj4sKvnmBsdDY6xP1ACOflpp A==; X-CSE-ConnectionGUID: 7vQDL7RpQGidhYQxXu0LIQ== X-CSE-MsgGUID: dr/i+Ig5Sq6ZAlg5gos/sQ== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785230" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785230" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:40 -0700 X-CSE-ConnectionGUID: Ezo+T/V3T9SkpwJQY3JicQ== X-CSE-MsgGUID: FfdLkxCrQrmSmr3gqoKZOw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857148" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:38 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 03/17] i3c: mipi-i3c-hci: Prevent DMA enqueue while ring is aborting or in error Date: Fri, 15 May 2026 19:26:07 +0300 Message-ID: <20260515162621.57719-4-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Block the DMA enqueue path while a Ring abort is in progress or after an error condition has been detected. Previously, new transfers could be enqueued while the DMA Ring was being aborted or while error handling was underway. This allowed enqueue and error-recovery paths to run concurrently, potentially interfering with each other and corrupting Ring state. Introduce explicit enqueue blocking and a wait queue to serialize access: enqueue operations now wait until abort or error handling has completed before proceeding. Enqueue is unblocked once the Ring is safely restarted. Note, there is only 1 ring bundle configured, and a transfer error causes the controller to halt ring (bundle) operation, so there is only ever 1 outstanding error at a time. Furthermore, a later patch ensures that only the currently active transfer list can time out. Consequently, the DMA queue will not be unblocked while there are outstanding transfer errors or timeouts. Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V4: Add Frank's Rev'd-by Changes in V3: None Changes in V2: Improve commit message drivers/i3c/master/mipi-i3c-hci/core.c | 1 + drivers/i3c/master/mipi-i3c-hci/dma.c | 25 +++++++++++++++++++++++-- drivers/i3c/master/mipi-i3c-hci/hci.h | 2 ++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index afb0764b5e1f..44617eb3a3f1 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -973,6 +973,7 @@ static int i3c_hci_probe(struct platform_device *pdev) =20 spin_lock_init(&hci->lock); mutex_init(&hci->control_mutex); + init_waitqueue_head(&hci->enqueue_wait_queue); =20 /* * Multi-bus instances share the same MMIO address range, but not diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index bdffdd8b8923..c3da6eab8eae 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -484,6 +484,12 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, =20 spin_lock_irq(&hci->lock); =20 + while (unlikely(hci->enqueue_blocked)) { + spin_unlock_irq(&hci->lock); + wait_event(hci->enqueue_wait_queue, !READ_ONCE(hci->enqueue_blocked)); + spin_lock_irq(&hci->lock); + } + if (n > rh->xfer_space) { spin_unlock_irq(&hci->lock); hci_dma_unmap_xfer(hci, xfer_list, n); @@ -539,6 +545,14 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, return 0; } =20 +static void hci_dma_unblock_enqueue(struct i3c_hci *hci) +{ + if (hci->enqueue_blocked) { + hci->enqueue_blocked =3D false; + wake_up_all(&hci->enqueue_wait_queue); + } +} + static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, struct hci_xfer *xfer_list, int n) { @@ -550,12 +564,17 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, =20 guard(mutex)(&hci->control_mutex); =20 + spin_lock_irq(&hci->lock); + ring_status =3D rh_reg_read(RING_STATUS); if (ring_status & RING_STATUS_RUNNING) { + hci->enqueue_blocked =3D true; + spin_unlock_irq(&hci->lock); /* stop the ring */ reinit_completion(&rh->op_done); rh_reg_write(RING_CONTROL, rh_reg_read(RING_CONTROL) | RING_CTRL_ABORT); wait_for_completion_timeout(&rh->op_done, HZ); + spin_lock_irq(&hci->lock); ring_status =3D rh_reg_read(RING_STATUS); if (ring_status & RING_STATUS_RUNNING) { /* @@ -567,8 +586,6 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, } } =20 - spin_lock_irq(&hci->lock); - for (i =3D 0; i < n; i++) { struct hci_xfer *xfer =3D xfer_list + i; int idx =3D xfer->ring_entry; @@ -604,6 +621,8 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE); rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE | RING_CTRL_RUN_STOP); =20 + hci_dma_unblock_enqueue(hci); + spin_unlock_irq(&hci->lock); =20 return did_unqueue; @@ -647,6 +666,8 @@ static void hci_dma_xfer_done(struct i3c_hci *hci, stru= ct hci_rh_data *rh) } if (xfer->completion) complete(xfer->completion); + if (RESP_STATUS(resp)) + hci->enqueue_blocked =3D true; } =20 done_ptr =3D (done_ptr + 1) % rh->xfer_entries; diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mip= i-i3c-hci/hci.h index f17f43494c1b..d630400ec945 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -54,6 +54,8 @@ struct i3c_hci { struct mutex control_mutex; atomic_t next_cmd_tid; bool irq_inactive; + bool enqueue_blocked; + wait_queue_head_t enqueue_wait_queue; u32 caps; unsigned int quirks; unsigned int DAT_entries; --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BB6B3FD95B for ; Fri, 15 May 2026 16:26:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862402; cv=none; b=FFOMwpy1JagHJQSVxaU/Ys+5kMWdNwmOojW94bi4n5vHGziSjlP0QUjGXg+t4hhAZqOas0AjNWNLoEa4TmY+wkCsledEhItWhom00ftC1eQuyF8+FLu8NSPQu8pL9InoZEry7XhOdgh+4GMFJcIRZZDlQ59JfPF1z/7GAi8F1Pk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862402; c=relaxed/simple; bh=dVCJ05IA2LC6vrTUR77jZ+SF61lBLGgMfwXzmINuLFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hc1VJZPJc9cTZmJAag0Zqx7/cEvhS2nkIAVIdKg6GLvwy91D1Yjk+RbDlcqP3mdMpnIHF15Jwp/BIUCRdET3Od/OJ0CRCPtP5Dh4pcU5fyRUoyssvAX4NqIL/ZuXe/1CoNpFQxhu6MGzyhCw4UmOwxxDFdl1u6yNS3X7t/J59RQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=J6tf+4U/; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="J6tf+4U/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862402; x=1810398402; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dVCJ05IA2LC6vrTUR77jZ+SF61lBLGgMfwXzmINuLFk=; b=J6tf+4U/u4tiZgoU9t1j158+lVEUrJrqhDlssA0NG4PLA7Fg0WKCaaE8 yOwgikEFgw231WUM5Y7WfHB4dKiWdS4deydthrO36EnJ77bVBI6SouUzH kOkTlFzEFaP61lwl+AI1bevgg6DJ7GgUrNK9ho7/gTY8bRn344azI/j6z 7IdVvyZLMvrxq72io46aQXMkt0SRto+dJ9lUWuZf2hc19ONbr/v8co4k+ 1f3qI2V4r0C+SIphhJoUhB4hTiQnI4j9k/QUJRvG9I5VTJQ6LapQFa8ZP c2C1gUzO+2jZuEaIp6CUuHgwY8oPVOOAdVxyxzHh3eUIdZLaG+1P7CTXL Q==; X-CSE-ConnectionGUID: cVmvgAFdRqCOQDUqBhmEHQ== X-CSE-MsgGUID: hv9QAnD3TDSwvUu/A7wbnw== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785236" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785236" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:42 -0700 X-CSE-ConnectionGUID: oHWmFItpSp6mp+xABDAUWw== X-CSE-MsgGUID: 1IJrWLIbT+up4aUd90OynA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857167" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:40 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 04/17] i3c: mipi-i3c-hci: Wait for DMA ring restart to complete Date: Fri, 15 May 2026 19:26:08 +0300 Message-ID: <20260515162621.57719-5-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Although hci_dma_dequeue_xfer() is serialized against itself via control_mutex, this does not guarantee that a DMA ring restart triggered by a previous invocation has fully completed. When the function is called again in rapid succession, the DMA ring may still be transitioning back to the running state, which may confound or disrupt further state changes. Address this by waiting for the DMA ring restart to complete before continuing. Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V4: Add Frank's Rev'd-by Changes in V2 and V3: None drivers/i3c/master/mipi-i3c-hci/dma.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index c3da6eab8eae..3b14bc87bdf6 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -617,6 +617,7 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, } =20 /* restart the ring */ + reinit_completion(&rh->op_done); mipi_i3c_hci_resume(hci); rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE); rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE | RING_CTRL_RUN_STOP); @@ -625,6 +626,8 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, =20 spin_unlock_irq(&hci->lock); =20 + wait_for_completion_timeout(&rh->op_done, HZ); + return did_unqueue; } =20 --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B92524BC032 for ; Fri, 15 May 2026 16:26:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862405; cv=none; b=ONkBr4jEXwH5/eOU3/xivk093Z36ZwVSSrdL9pw8Uuf1R2tmZpm68tXXC9AQP/Dod+KCWIIv1IjBjTUV57FxzpNWfbfyFObyqnWAVSm2HOBtU9pD2Y71hIKyzo/KJyGk8jmSroR9eBRK+UcztCJ+ngsNIG3m396MBuBVA33C6mc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862405; c=relaxed/simple; bh=211AEh4Pq5WMRP3XSH8i3Q0DXrtefLFwgHUDVvOKiQo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EUu/Mm5AK+FJDc0uR2XK5CLms4OSJCw/X3he9rzhYkAKmTrJYQipTqPM1IRKAnDRgaDNPWbutUVKkCqU0BYT3xmWizGMGT3521Xn/ZMrOGMh5D+sMOjTO3xoax7M1FXEOb7DzCmhkugKwrcGu85lkwtqtXk0vqQLOQoHQEfakhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QAdViaYv; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QAdViaYv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862404; x=1810398404; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=211AEh4Pq5WMRP3XSH8i3Q0DXrtefLFwgHUDVvOKiQo=; b=QAdViaYvksBGdMhqYvuATxqewaQ+yWNBT3/5MJkKdLO8VgS70+Va83tl bG2nX62dMXr9ZrUOHIwTZ8XGYiktyIeWEBV4Q9VMzDlCaqKZByW/Lq9L7 JBu7UW5Urif8AsSf13VNdmI4nq3mTZXXIm3O+4MJJeK0pthDaIJq16lBv W7UVdNhbOjNO4xcHedmrfLgaM6ximjMHvb76jnXvDCm364CBcRvuPiHqa ugCHO/kh1GgQf47hM134F/b4h8N7MAMjSQ4LpNuUPVjuQLmNOwf/VbJN9 3lZku8SrQqJhzPDhDnWr593Oq3PO7Vxe8ccFyhHFWc6xhe7devqhMUNJQ A==; X-CSE-ConnectionGUID: Kn/DpRtgQtiloeGt4IFhbw== X-CSE-MsgGUID: Qzpn9EV5QoG+BLC/BEOJQQ== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785240" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785240" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:44 -0700 X-CSE-ConnectionGUID: LHOzoov2QkW0QUT73aIGvg== X-CSE-MsgGUID: fJf2opkWQnG7RLTYuOu6Wg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857186" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:42 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 05/17] i3c: mipi-i3c-hci: Move hci_dma_xfer_done() definition Date: Fri, 15 May 2026 19:26:09 +0300 Message-ID: <20260515162621.57719-6-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move hci_dma_xfer_done() earlier in the file to avoid a forward declaration needed by a subsequent change. No functional change. Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V3 and V4: None Changes in V2: Added Frank's Rev'd-by drivers/i3c/master/mipi-i3c-hci/dma.c | 98 +++++++++++++-------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index 3b14bc87bdf6..ad47bb2890d6 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -545,6 +545,55 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, return 0; } =20 +static void hci_dma_xfer_done(struct i3c_hci *hci, struct hci_rh_data *rh) +{ + u32 op1_val, op2_val, resp, *ring_resp; + unsigned int tid, done_ptr =3D rh->done_ptr; + unsigned int done_cnt =3D 0; + struct hci_xfer *xfer; + + for (;;) { + op2_val =3D rh_reg_read(RING_OPERATION2); + if (done_ptr =3D=3D FIELD_GET(RING_OP2_CR_DEQ_PTR, op2_val)) + break; + + ring_resp =3D rh->resp + rh->resp_struct_sz * done_ptr; + resp =3D *ring_resp; + tid =3D RESP_TID(resp); + dev_dbg(&hci->master.dev, "resp =3D 0x%08x", resp); + + xfer =3D rh->src_xfers[done_ptr]; + if (!xfer) { + dev_dbg(&hci->master.dev, "orphaned ring entry"); + } else { + hci_dma_unmap_xfer(hci, xfer, 1); + rh->src_xfers[done_ptr] =3D NULL; + xfer->ring_entry =3D -1; + xfer->response =3D resp; + if (tid !=3D xfer->cmd_tid) { + dev_err(&hci->master.dev, + "response tid=3D%d when expecting %d\n", + tid, xfer->cmd_tid); + /* TODO: do something about it? */ + } + if (xfer->completion) + complete(xfer->completion); + if (RESP_STATUS(resp)) + hci->enqueue_blocked =3D true; + } + + done_ptr =3D (done_ptr + 1) % rh->xfer_entries; + rh->done_ptr =3D done_ptr; + done_cnt +=3D 1; + } + + rh->xfer_space +=3D done_cnt; + op1_val =3D rh_reg_read(RING_OPERATION1); + op1_val &=3D ~RING_OP1_CR_SW_DEQ_PTR; + op1_val |=3D FIELD_PREP(RING_OP1_CR_SW_DEQ_PTR, done_ptr); + rh_reg_write(RING_OPERATION1, op1_val); +} + static void hci_dma_unblock_enqueue(struct i3c_hci *hci) { if (hci->enqueue_blocked) { @@ -636,55 +685,6 @@ static int hci_dma_handle_error(struct i3c_hci *hci, s= truct hci_xfer *xfer_list, return hci_dma_dequeue_xfer(hci, xfer_list, n) ? -EIO : 0; } =20 -static void hci_dma_xfer_done(struct i3c_hci *hci, struct hci_rh_data *rh) -{ - u32 op1_val, op2_val, resp, *ring_resp; - unsigned int tid, done_ptr =3D rh->done_ptr; - unsigned int done_cnt =3D 0; - struct hci_xfer *xfer; - - for (;;) { - op2_val =3D rh_reg_read(RING_OPERATION2); - if (done_ptr =3D=3D FIELD_GET(RING_OP2_CR_DEQ_PTR, op2_val)) - break; - - ring_resp =3D rh->resp + rh->resp_struct_sz * done_ptr; - resp =3D *ring_resp; - tid =3D RESP_TID(resp); - dev_dbg(&hci->master.dev, "resp =3D 0x%08x", resp); - - xfer =3D rh->src_xfers[done_ptr]; - if (!xfer) { - dev_dbg(&hci->master.dev, "orphaned ring entry"); - } else { - hci_dma_unmap_xfer(hci, xfer, 1); - rh->src_xfers[done_ptr] =3D NULL; - xfer->ring_entry =3D -1; - xfer->response =3D resp; - if (tid !=3D xfer->cmd_tid) { - dev_err(&hci->master.dev, - "response tid=3D%d when expecting %d\n", - tid, xfer->cmd_tid); - /* TODO: do something about it? */ - } - if (xfer->completion) - complete(xfer->completion); - if (RESP_STATUS(resp)) - hci->enqueue_blocked =3D true; - } - - done_ptr =3D (done_ptr + 1) % rh->xfer_entries; - rh->done_ptr =3D done_ptr; - done_cnt +=3D 1; - } - - rh->xfer_space +=3D done_cnt; - op1_val =3D rh_reg_read(RING_OPERATION1); - op1_val &=3D ~RING_OP1_CR_SW_DEQ_PTR; - op1_val |=3D FIELD_PREP(RING_OP1_CR_SW_DEQ_PTR, done_ptr); - rh_reg_write(RING_OPERATION1, op1_val); -} - static int hci_dma_request_ibi(struct i3c_hci *hci, struct i3c_dev_desc *d= ev, const struct i3c_ibi_setup *req) { --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63DE63FD95B for ; Fri, 15 May 2026 16:26:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862406; cv=none; b=G+PNEdJbOaEioOf4rkve4QCVBvw3LpAErZc70VHHubhKa5VDJrVTnxuqf9fUf/IZyiV1ixfc412LkiSjYX8/jlqMT75SYb/e9ASGRJRIN6aBdME1BKNI8UZh7GK/Ycie8/+5cxC1no66jpc97zy3gdTlkIFcqp+c5zr4cLC1WJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862406; c=relaxed/simple; bh=RXfFB7UJVDGcBk6zbniffn/NJbT+BI67ap0XTvRMXCE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RlAzbYEwBegD2YypdlaJkIKnQM72D4ahX1CEQrdjp4zfnWZDvXPfORtTty+wz9nCrYnoS8PTzZ699PFBQtj8FuqAvaxTM1ln6hUB059m6nP4yRi5TRT27rgd8zoTeGGkg6pLdjb8Yplt5lZs9k0SfL0suINMW027QokZnPXEdSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZbWNwyNk; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZbWNwyNk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862406; x=1810398406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RXfFB7UJVDGcBk6zbniffn/NJbT+BI67ap0XTvRMXCE=; b=ZbWNwyNkzSyq/lIiAq04mVBFGoyTtZWVMO0UqTp7vNHqUieRUacMGw02 OgaV3s7nF/F3pcK6zNcgVBZTWm3WDRYSP7F9pnLi42/br4KH8NWB9Rk1H y9Pmk6U81VJkVsSC3MS8wcoETna+Ud4jTnldPKHnuJkuCn2o7QthVs12D hilgnbGpYZkfcvwUE8/GjrKjA2BS4erwRhfDvd+gEzreW2ZOBCrn8uEif VR9YjaC1Qf37HtIjcr2LPLFRgdgMt9RFSU0c/0Vj+BfE4oIVk6DvVa1xp YjpKunkop33r8OejJ73+bLKJR+405ki9rOcMKec+bnp9njyYQhVmaKCj0 Q==; X-CSE-ConnectionGUID: W6x7eHyqRUScYbq+R29kOw== X-CSE-MsgGUID: pIwa3e7XRxKf3itHyG6sWg== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785249" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785249" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:46 -0700 X-CSE-ConnectionGUID: dcBzboy5RomFr2iIVMRUxw== X-CSE-MsgGUID: DpizpCdUTRma0NRsOBln+A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857197" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:44 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 06/17] i3c: mipi-i3c-hci: Call hci_dma_xfer_done() from dequeue path Date: Fri, 15 May 2026 19:26:10 +0300 Message-ID: <20260515162621.57719-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" hci_dma_dequeue_xfer() relies on state normally updated by the DMA interrupt handler. Ensure that state is current by explicitly invoking hci_dma_xfer_done() from the dequeue path. This handles cases where the interrupt handler has not (yet) run. Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V3 and V4: None Changes in V2: Added Frank's Rev'd-by drivers/i3c/master/mipi-i3c-hci/dma.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index ad47bb2890d6..de0f17706ac8 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -635,6 +635,8 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, } } =20 + hci_dma_xfer_done(hci, rh); + for (i =3D 0; i < n; i++) { struct hci_xfer *xfer =3D xfer_list + i; int idx =3D xfer->ring_entry; --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BB034C77BC for ; Fri, 15 May 2026 16:26:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862409; cv=none; b=o5Res7qwdMU4v3swp8N3mscN2CxlX6eeKz9RTrx0wvRBgdgEUI3CZPulf9bcVOIHReOOh2rPzXDZ2dVr3FnLennp+v0EqqUoTbzt46MtLaxd0eu6ub/bpzXx7s4a3Zp3D1pyT3tgAeBs5y6i2vvjv/IkmX6pS0iHyWyKhuK4E/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862409; c=relaxed/simple; bh=rmo72hvT7oVdD8KLIA0ACavIj7twlGv7h7oHGIOnbQE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U7Lu8Ly/nVsvwcrdVAVW58a5MvMxkTWeXvikQ8G+ZXgveqz/lnJ1kZemjnf5JPdjw7+568/yk3Eh9hGz2zU8FEI9Om/0cDz7DACsw6iCnPt0JvD8AB9ih0rVTbEdgH4+xl343yeI6QdAqV6RtzoZ2E99htTNo5bovXUna+erMNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=KqBFQuWb; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KqBFQuWb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862408; x=1810398408; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rmo72hvT7oVdD8KLIA0ACavIj7twlGv7h7oHGIOnbQE=; b=KqBFQuWbQobDW8rvstpIaBEZc4j3m9BmN3owmPB1gYx/SIbAR6ShtRQr H4hANPgW2Qkg5FLEIZ4BIiFNpITCgwXqH8TvO38IP6COGRaK6RM20F3wJ zLhBpMbbXtzSXfRJRcEE2XCK6eFwH3dni2mC7XVQL/kax6EvRBz1ARhg6 vhWlN0YPJ2MALs2xbWFFYC2yV5+q6rah48zsKhc6kwbaqm/9JyScVXjKz 2Py3XvzLfTBlY/sAE68Y/kzbKzmPou0SDL2gTwqS9ccLRs/NaxOU/oHS2 aBoMAqXyEMkD7TUwHW/LBNRgWSqoEe767sEbTSIXKkoxGE5IWH2FWC5N4 w==; X-CSE-ConnectionGUID: 5krxq9e0TruFjIHZi/ygIw== X-CSE-MsgGUID: AfVzDcrtRFKctZWnFDA0ig== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785255" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785255" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:48 -0700 X-CSE-ConnectionGUID: HmCIGNQ1QUORZf5EOLj3eA== X-CSE-MsgGUID: O41tTOXuRninxzeWxc6ErQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857207" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:46 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 07/17] i3c: mipi-i3c-hci: Complete transfer lists immediately on error Date: Fri, 15 May 2026 19:26:11 +0300 Message-ID: <20260515162621.57719-8-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In DMA mode, transfer lists are currently completed only when the final transfer in the list completes. If an earlier transfer fails, the list is left incomplete and callers wait until timeout. There is no need to wait for a timeout, as the completion path in i3c_hci_process_xfer() already checks for error status. Complete the transfer list as soon as any transfer in the list reports an error. This avoids unnecessary delays and spurious timeouts on error. Complete a transfer list completion immediately there is an error. Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V4: Add Frank's Rev'd-by Changes in V3: None Changes in V2: Renamed completing_xfer to final_xfer drivers/i3c/master/mipi-i3c-hci/dma.c | 6 ++++-- drivers/i3c/master/mipi-i3c-hci/hci.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index de0f17706ac8..83b553e1ab0b 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -502,6 +502,8 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, struct hci_xfer *xfer =3D xfer_list + i; u32 *ring_data =3D rh->xfer + rh->xfer_struct_sz * enqueue_ptr; =20 + xfer->final_xfer =3D xfer_list + n - 1; + /* store cmd descriptor */ *ring_data++ =3D xfer->cmd_desc[0]; *ring_data++ =3D xfer->cmd_desc[1]; @@ -576,8 +578,8 @@ static void hci_dma_xfer_done(struct i3c_hci *hci, stru= ct hci_rh_data *rh) tid, xfer->cmd_tid); /* TODO: do something about it? */ } - if (xfer->completion) - complete(xfer->completion); + if (xfer =3D=3D xfer->final_xfer || RESP_STATUS(resp)) + complete(xfer->final_xfer->completion); if (RESP_STATUS(resp)) hci->enqueue_blocked =3D true; } diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mip= i-i3c-hci/hci.h index d630400ec945..f07fc627d4d2 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -104,6 +104,7 @@ struct hci_xfer { struct { /* DMA specific */ struct i3c_dma *dma; + struct hci_xfer *final_xfer; int ring_number; int ring_entry; }; --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 561A64CA26E for ; Fri, 15 May 2026 16:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862410; cv=none; b=LhONyYWaw5hgSP8iRPOG0CS8UKlyRbfrXPWc09AO+EnJFEFbge4734cn3udtsp7DokUD593qDsMmZYv7Q7J7kt6KSXwSAsdhRYamgeuRNmE5bZHa/O9QSQ4oYYIQ9dW5CtUsfhk+gujCx0m2tRsRzX8NWR3/Ukm39dep/MBk5Ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862410; c=relaxed/simple; bh=Cy9JCgl78HKFpC/wm/5a98l6Dzm9pXxRhKkJ8NoUOu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nXCWK6dHGKWaV13il6FIKeNVZ1v5yKzznvEm+hu3SliXMMGeQMZfEaCSHxRlYIlE+pVAHxQqvSwKiV5BTOuPDgcxtoO6QuFfvLv2dxH8RtmLNXJ4uEWToVpdziiAS49HyNgA0kFaohtbU3E2fXh2Y1tzwgr5tXBovOanGC6ha+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Slh9PBoC; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Slh9PBoC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862410; x=1810398410; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Cy9JCgl78HKFpC/wm/5a98l6Dzm9pXxRhKkJ8NoUOu0=; b=Slh9PBoCW6HmbCmeW155aoMWyyURqfXYePxWO8CsG3fQRPZcGir2PWjd GGIyRtCseL+j/zr1yauZfRcvpoFDiLX8CuYXCTbMOnstDsSL+YdrsjVZi HfO2syRl/aWei+jtYVSfYACNj+HXGNhjrIntqfcBIH40z/DSGQcTvNHB5 FcEy0DNmZEM1qfOxIqwXOSEz2P8nhwVLX0jCVjlPbh6H2jQrN74kVu6RY Rf+DKscLUFun6bo17vU3hM7I2T8TD3Tat6R5er23PbUXpKUHSttVuAzSP 36oxh1Qh1Qk3r4HuN0XnwIHk/FFlJAD2P16tPBqVRaWjc6ezj9nErwOD1 g==; X-CSE-ConnectionGUID: 8GzSwS30Sl+hwy86b5aIvQ== X-CSE-MsgGUID: s2p9d46TTS6E2p3tLt/f5Q== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785260" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785260" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:50 -0700 X-CSE-ConnectionGUID: +rk9Hd1mTgWkKeOB9pC7KA== X-CSE-MsgGUID: 1v5jWdO8QKGtKaLRqICEng== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857220" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:48 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 08/17] i3c: mipi-i3c-hci: Avoid restarting DMA ring after aborting wrong transfer Date: Fri, 15 May 2026 19:26:12 +0300 Message-ID: <20260515162621.57719-9-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Software ABORT of the DMA ring is used to recover from transfer list timeouts, but it is inherently racy. The intended transfer list may complete just before the ABORT takes effect, causing the subsequent transfer list to be aborted instead. In this case, an incomplete transfer list may remain in the ring and has not yet been processed by hci_dma_dequeue_xfer(). Restarting the DMA ring at that point can lead to unpredictable results. Detect when the next queued transfer is not the first entry of a transfer list and does not belong to the list currently being dequeued. In that case, skip restarting the DMA ring and defer recovery until a subsequent call to hci_dma_dequeue_xfer(), which will safely restart the ring once the incomplete list is handled. Signed-off-by: Adrian Hunter --- Changes in V3 and V4: None Changes in V2: Renamed completing_xfer to final_xfer drivers/i3c/master/mipi-i3c-hci/dma.c | 15 +++++++++++++++ drivers/i3c/master/mipi-i3c-hci/hci.h | 1 + 2 files changed, 16 insertions(+) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index 83b553e1ab0b..8e27fb6f18f5 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -503,6 +503,7 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, u32 *ring_data =3D rh->xfer + rh->xfer_struct_sz * enqueue_ptr; =20 xfer->final_xfer =3D xfer_list + n - 1; + xfer->xfer_list_pos =3D i; =20 /* store cmd descriptor */ *ring_data++ =3D xfer->cmd_desc[0]; @@ -669,6 +670,20 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, } } =20 + /* + * A software ABORT may race with transfer completion and abort the next + * transfer list instead. Detect that case, and do not restart the ring. + * It will be handled by a subsequent dequeue. + */ + if (!did_unqueue) { + struct hci_xfer *xfer =3D rh->src_xfers[rh->done_ptr]; + + if (xfer && xfer->xfer_list_pos && xfer->final_xfer !=3D xfer_list->fina= l_xfer) { + spin_unlock_irq(&hci->lock); + return false; + } + } + /* restart the ring */ reinit_completion(&rh->op_done); mipi_i3c_hci_resume(hci); diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mip= i-i3c-hci/hci.h index f07fc627d4d2..83d4f13a68a3 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -107,6 +107,7 @@ struct hci_xfer { struct hci_xfer *final_xfer; int ring_number; int ring_entry; + int xfer_list_pos; }; }; }; --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 443A54D2EF2 for ; Fri, 15 May 2026 16:26:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862412; cv=none; b=UY2kPTCDr6uQ8QsLYZc98lJPZeByNXin9YFCOVlcPEBdDOMPYu5YZwt2zcKpfS1U1dlovyRYLAtj/tSBqw5jkTc/iHlduISbcseIlJe72yEvIt9isANz+WppsMDFl9yGcKU9fLlMGpSQbxmgJAq4aP+Xy9trLnH/NHZVX51fmoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862412; c=relaxed/simple; bh=hG9wfkwAaz+u19uqN8A9JPhHYm6btu6rZ1Ynz0/WCXM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QJQ3zJ/g8IDWUAG8jxi7zcV8bGxzjnbA0WsAFlrHBi3t/BliYlV67ow/w+KH3m3OiOo3MMneFIizOSK0gXZhzKdHHwk5yKAE3Pk2RJNKtUPCcM94TxgNfRJUG6EkDzwzqM9hN4RnNMnG5M6MxUbcvUYhwzLpc4fijkgjJ8idHD4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=dOOIGcFA; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="dOOIGcFA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862412; x=1810398412; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hG9wfkwAaz+u19uqN8A9JPhHYm6btu6rZ1Ynz0/WCXM=; b=dOOIGcFA57QAv0wbFjmtGkSmStkn9NonedOMcmwrbWFuL5mx25jRrAgU hT/i7p++5PU/d1SN0ZcyJB/NyDqHO2sLCqYFnNaQTAzDztvmcG4qrG1uF 5xDeijqRwvaVCZP65zxUZ1yZ7Syq5mEqy7XX2yTTCOEY17PbQ/g7A8Q79 iI7Ox6oQ1LTWDWqbbH4Me/clQJPQhRez+PSNz77cC+2BRteJY/ZKTme83 Y62zR+voEAdom/1wnrEOmhSECChokZ1ZjmaEx87OgnuwyZPImVaqE+QAS TCbIt6XKyap8YW10Xy/zRKV6hVg+gDrActdhAgy6KYA5dYH3fQd4SboYj w==; X-CSE-ConnectionGUID: 0j070MHlQJCyf4uyrpN5Tg== X-CSE-MsgGUID: ZwuXGGTNRDuXooarCx21yg== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785268" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785268" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:51 -0700 X-CSE-ConnectionGUID: 9Ka0mOSHRpq2bBc/GVzjTA== X-CSE-MsgGUID: IzC0DjdXShiPFaUIjcZASg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857232" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:50 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 09/17] i3c: mipi-i3c-hci: Add DMA ring abort/reset quirk for Intel controllers Date: Fri, 15 May 2026 19:26:13 +0300 Message-ID: <20260515162621.57719-10-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some Intel I3C HCI controllers cannot reliably restart a DMA ring after an ABORT. Additional queue resets are required to recover, and must be performed using PIO reset bits even while operating in DMA mode. This behavior is non-standard. Introduce a controller quirk to opt into the required PIO queue resets after a DMA ring abort, and enable it for Intel LPSS I3C controllers. Signed-off-by: Adrian Hunter --- Changes in V4: Inline HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET check at call site instead of using a helper function Changes in V2 and V3: None drivers/i3c/master/mipi-i3c-hci/core.c | 15 ++++++++++++++- drivers/i3c/master/mipi-i3c-hci/dma.c | 4 ++++ drivers/i3c/master/mipi-i3c-hci/hci.h | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index 44617eb3a3f1..770235ad6b25 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -240,6 +240,18 @@ void mipi_i3c_hci_pio_reset(struct i3c_hci *hci) reg_write(RESET_CONTROL, RX_FIFO_RST | TX_FIFO_RST | RESP_QUEUE_RST); } =20 +#define ALL_QUEUES_RST (CMD_QUEUE_RST | RESP_QUEUE_RST | RX_FIFO_RST | TX_= FIFO_RST | IBI_QUEUE_RST) + +void mipi_i3c_hci_pio_reset_all_queues(struct i3c_hci *hci) +{ + u32 regval; + + reg_write(RESET_CONTROL, ALL_QUEUES_RST); + if (readx_poll_timeout_atomic(reg_read, RESET_CONTROL, regval, + !(regval & ALL_QUEUES_RST), 0, 20)) + dev_err(&hci->master.dev, "%s: Reset queues failed\n", __func__); +} + /* located here rather than dct.c because needed bits are in core reg spac= e */ void mipi_i3c_hci_dct_index_reset(struct i3c_hci *hci) { @@ -1040,7 +1052,8 @@ MODULE_DEVICE_TABLE(acpi, i3c_hci_acpi_match); static const struct platform_device_id i3c_hci_driver_ids[] =3D { { .name =3D "intel-lpss-i3c", HCI_QUIRK_RPM_ALLOWED | HCI_QUIRK_RPM_IBI_ALLOWED | - HCI_QUIRK_RPM_PARENT_MANAGED }, + HCI_QUIRK_RPM_PARENT_MANAGED | + HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(platform, i3c_hci_driver_ids); diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index 8e27fb6f18f5..906de7dbfdb5 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -638,6 +638,10 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, } } =20 + if ((hci->quirks & HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET) && + (rh_reg_read(RING_STATUS) & RING_STATUS_ABORTED)) + mipi_i3c_hci_pio_reset_all_queues(hci); + hci_dma_xfer_done(hci, rh); =20 for (i =3D 0; i < n; i++) { diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mip= i-i3c-hci/hci.h index 83d4f13a68a3..01237b12d32e 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -156,10 +156,12 @@ struct i3c_hci_dev_data { #define HCI_QUIRK_RPM_ALLOWED BIT(5) /* Runtime PM allowed */ #define HCI_QUIRK_RPM_IBI_ALLOWED BIT(6) /* IBI and Hot-Join allowed whil= e runtime suspended */ #define HCI_QUIRK_RPM_PARENT_MANAGED BIT(7) /* Runtime PM managed by pare= nt device */ +#define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET BIT(8) /* Do PIO queue SW = resets after DMA abort */ =20 /* global functions */ void mipi_i3c_hci_resume(struct i3c_hci *hci); void mipi_i3c_hci_pio_reset(struct i3c_hci *hci); +void mipi_i3c_hci_pio_reset_all_queues(struct i3c_hci *hci); void mipi_i3c_hci_dct_index_reset(struct i3c_hci *hci); void amd_set_od_pp_timing(struct i3c_hci *hci); void amd_set_resp_buf_thld(struct i3c_hci *hci); --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 379B64D990C for ; Fri, 15 May 2026 16:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862414; cv=none; b=ERIQr/jBq8oy/edSYfoPydAFloxYQl8jqywBReBd9/iGhCHg0OHVpsF6uWa+B8CjqgqqVI7wsajpsA2RGxVN5QD/OEZ1uMYON9aw1eQxUjAdhKVAVaZiT795/ZHrMqG3hsv/UOR6pXqsL00soH9kWzrQxXJDEsz9LIIFFdBzlc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862414; c=relaxed/simple; bh=FSUUfb0G+Gxwh81FaCHidOvdNJ83lqm7ZkEkFCNbAyg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p57Du/NC9wrluLquXbZf61w3m9ypiqeClW2aw7cFiPrCcrBOAIcjLMQOIuMi/2V+uot8Le95bGXGxK3pkCfZXDH0pJETMFZTnNQ1qhK6lc1RXBnsjAUSGa1K10svpqt3arWqw+DpgoRXWw6XrERJQOC3Pl/EFg6wrT3OjQDJpbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZeMKGfaY; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZeMKGfaY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862414; x=1810398414; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FSUUfb0G+Gxwh81FaCHidOvdNJ83lqm7ZkEkFCNbAyg=; b=ZeMKGfaYcvqmSP05gqkyLCCG839XwNZIpBpfswFTUUIdC606qKwdhHdy YfbI7xp8q2BBZw4LtSeI3ouwk8VW9fu/M/f/2xBoDbvdLthY0LMNPerhc fd7hYQWrvFdffiSk9+EJiIo9ZjAYWHI9JLs7asgUqDlmSsGiZk8k2x+ux rZWM2ljoarUg5aDW1v8HpfoRMllDC9Wp4Wd1ruJjW1BU4LHuECIDw+tGk 6kzfXj4Fs6zkfze62ia8jOjpTBBVQN41RSLKjH55oS10iZJhuguMvDFeZ q/6ygJt4vXptesto+pG9gRbJ2Suu60IXxriX9Su986kyOKsyZ05N0FHRW g==; X-CSE-ConnectionGUID: trkUgWbcQOOHvlCl28gpWg== X-CSE-MsgGUID: 0S6CZhGVRlS3o0RAXWR4qQ== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785276" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785276" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:53 -0700 X-CSE-ConnectionGUID: H6K3jIM7SwGuwslSecwHOw== X-CSE-MsgGUID: zdIyBGnpSk+xXlsXw3CqrQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857244" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:52 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 10/17] i3c: mipi-i3c-hci: Factor out hci_dma_abort() Date: Fri, 15 May 2026 19:26:14 +0300 Message-ID: <20260515162621.57719-11-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out hci_dma_abort() from hci_dma_dequeue_xfer() in preparation for further changes. Signed-off-by: Adrian Hunter --- Changes in V4: New patch drivers/i3c/master/mipi-i3c-hci/dma.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index 906de7dbfdb5..f2d33068b8df 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -597,6 +597,13 @@ static void hci_dma_xfer_done(struct i3c_hci *hci, str= uct hci_rh_data *rh) rh_reg_write(RING_OPERATION1, op1_val); } =20 +static void hci_dma_abort(struct hci_rh_data *rh) +{ + reinit_completion(&rh->op_done); + rh_reg_write(RING_CONTROL, rh_reg_read(RING_CONTROL) | RING_CTRL_ABORT); + wait_for_completion_timeout(&rh->op_done, HZ); +} + static void hci_dma_unblock_enqueue(struct i3c_hci *hci) { if (hci->enqueue_blocked) { @@ -623,9 +630,7 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, hci->enqueue_blocked =3D true; spin_unlock_irq(&hci->lock); /* stop the ring */ - reinit_completion(&rh->op_done); - rh_reg_write(RING_CONTROL, rh_reg_read(RING_CONTROL) | RING_CTRL_ABORT); - wait_for_completion_timeout(&rh->op_done, HZ); + hci_dma_abort(rh); spin_lock_irq(&hci->lock); ring_status =3D rh_reg_read(RING_STATUS); if (ring_status & RING_STATUS_RUNNING) { --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F1604D990D for ; Fri, 15 May 2026 16:26:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862416; cv=none; b=XTz3CADrOrmIWvc3ZnY/v30Uh38LW29RcdrojZGYyYFbk0WVWcdwx5BxaWiO6T5s4lxFZbioNSK/PgajKM/S/F77e2//yIIVk0v2aedxjCD+iZfrW7cWb7n+ur/hlVLincDM4neHaDShjNUZAj7OdpaTg+RmmnPZOm0TJtdbIS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862416; c=relaxed/simple; bh=CXtKYMmKwEbkIY3ho/VVIr8S1aiko+WAbN4B3AgFKK8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h7F4zGsThYWtTL191oCx3ktv/n3x3ZEZRUczFZjyLPe2P6EqVu1kxA9gm3X5pDy+jRXYMtXKOVq2Su53dqw/NmAn9jmDjd4XsWoeywc4KujjLm+Qfr9DHyb+xOacWlxtkXUQL1alNrRv+PvJRwZ/yJbkAO89pjfa/ua/8l/VGz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=i8kVpuHH; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="i8kVpuHH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862416; x=1810398416; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CXtKYMmKwEbkIY3ho/VVIr8S1aiko+WAbN4B3AgFKK8=; b=i8kVpuHHxGXlGNiNFnUDCr8cAMUntmNICSfpUh/AA1nkDzwaL4cv1hUS bWIAluicLbVdpSSon/Dz/K5j7UR55Zr7dht+H9AxQqqVYltTP2TygvLsF So8Fk+uiZpDBoZru0/ROxC4ACnhpDFDwqmtFsk8QmxTbKw5mqCfc/mLVg oJAKmM3G+cuUKTxaEW3KN9lJA6KAjSyjOrAkz4j9tsxA0SXUAAijtA2yP i/kLNFzF6Hai4G9GvyysFBirWCCih3YTfBOiVjI3DtzGgnyxsbmxZ47TD YdqVjZzBCWi4h3zwjGVdQ7UIthWXKOvcwMyXW0kkU9RvuYoPQdP87iJv6 w==; X-CSE-ConnectionGUID: 3I5jkVxaT1SKl5PDfro1cA== X-CSE-MsgGUID: N4VeGsQDRt6ZbFGWDW2bhg== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785281" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785281" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:55 -0700 X-CSE-ConnectionGUID: IJ7FUVXESmqpu9GzVplgYA== X-CSE-MsgGUID: 0aes11l6RRWebuu6NBYNrA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857255" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:54 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 11/17] i3c: mipi-i3c-hci: Add DMA ring abort quirk for Intel controllers Date: Fri, 15 May 2026 19:26:15 +0300 Message-ID: <20260515162621.57719-12-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DMA rings can be aborted either per-ring via RING_CONTROL or globally via HC_CONTROL_ABORT. The driver currently relies on the per-ring mechanism. Some Intel I3C HCI controllers require HC_CONTROL_ABORT to be asserted before a DMA ring abort is effective. This behavior is non-standard. Introduce a controller quirk to select the required abort method and enable it for Intel LPSS I3C controllers. Signed-off-by: Adrian Hunter --- Changes in V4: Factor out hci_dma_abort() into a preceding patch Make hci_dma_requires_hc_abort_quirk() return void and move quirk check to caller Changes in V2 and V3: None drivers/i3c/master/mipi-i3c-hci/core.c | 18 ++++++++++++++++-- drivers/i3c/master/mipi-i3c-hci/dma.c | 17 +++++++++++++++-- drivers/i3c/master/mipi-i3c-hci/hci.h | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index 770235ad6b25..8274c84b16be 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -231,7 +231,20 @@ static void i3c_hci_bus_cleanup(struct i3c_master_cont= roller *m) =20 void mipi_i3c_hci_resume(struct i3c_hci *hci) { - reg_set(HC_CONTROL, HC_CONTROL_RESUME); + u32 reg =3D reg_read(HC_CONTROL); + + reg |=3D HC_CONTROL_RESUME; + reg &=3D ~HC_CONTROL_ABORT; + reg_write(HC_CONTROL, reg); +} + +void mipi_i3c_hci_abort(struct i3c_hci *hci) +{ + u32 reg =3D reg_read(HC_CONTROL); + + reg &=3D ~HC_CONTROL_RESUME; /* Do not set resume */ + reg |=3D HC_CONTROL_ABORT; + reg_write(HC_CONTROL, reg); } =20 /* located here rather than pio.c because needed bits are in core reg spac= e */ @@ -1053,7 +1066,8 @@ static const struct platform_device_id i3c_hci_driver= _ids[] =3D { { .name =3D "intel-lpss-i3c", HCI_QUIRK_RPM_ALLOWED | HCI_QUIRK_RPM_IBI_ALLOWED | HCI_QUIRK_RPM_PARENT_MANAGED | - HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET }, + HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET | + HCI_QUIRK_DMA_REQUIRES_HC_ABORT }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(platform, i3c_hci_driver_ids); diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index f2d33068b8df..f9023cb3c5a2 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -597,8 +597,21 @@ static void hci_dma_xfer_done(struct i3c_hci *hci, str= uct hci_rh_data *rh) rh_reg_write(RING_OPERATION1, op1_val); } =20 -static void hci_dma_abort(struct hci_rh_data *rh) +static void hci_dma_requires_hc_abort_quirk(struct i3c_hci *hci, struct hc= i_rh_data *rh) { + reinit_completion(&rh->op_done); + mipi_i3c_hci_abort(hci); + wait_for_completion_timeout(&rh->op_done, HZ); + rh_reg_write(RING_CONTROL, rh_reg_read(RING_CONTROL) | RING_CTRL_ABORT); +} + +static void hci_dma_abort(struct i3c_hci *hci, struct hci_rh_data *rh) +{ + if (hci->quirks & HCI_QUIRK_DMA_REQUIRES_HC_ABORT) { + hci_dma_requires_hc_abort_quirk(hci, rh); + return; + } + reinit_completion(&rh->op_done); rh_reg_write(RING_CONTROL, rh_reg_read(RING_CONTROL) | RING_CTRL_ABORT); wait_for_completion_timeout(&rh->op_done, HZ); @@ -630,7 +643,7 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, hci->enqueue_blocked =3D true; spin_unlock_irq(&hci->lock); /* stop the ring */ - hci_dma_abort(rh); + hci_dma_abort(hci, rh); spin_lock_irq(&hci->lock); ring_status =3D rh_reg_read(RING_STATUS); if (ring_status & RING_STATUS_RUNNING) { diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mip= i-i3c-hci/hci.h index 01237b12d32e..97c31a315a6e 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -157,9 +157,11 @@ struct i3c_hci_dev_data { #define HCI_QUIRK_RPM_IBI_ALLOWED BIT(6) /* IBI and Hot-Join allowed whil= e runtime suspended */ #define HCI_QUIRK_RPM_PARENT_MANAGED BIT(7) /* Runtime PM managed by pare= nt device */ #define HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET BIT(8) /* Do PIO queue SW = resets after DMA abort */ +#define HCI_QUIRK_DMA_REQUIRES_HC_ABORT BIT(9) /* Use HC_CONTROL ABORT t= o abort DMA */ =20 /* global functions */ void mipi_i3c_hci_resume(struct i3c_hci *hci); +void mipi_i3c_hci_abort(struct i3c_hci *hci); void mipi_i3c_hci_pio_reset(struct i3c_hci *hci); void mipi_i3c_hci_pio_reset_all_queues(struct i3c_hci *hci); void mipi_i3c_hci_dct_index_reset(struct i3c_hci *hci); --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24BC94DB54F for ; Fri, 15 May 2026 16:26:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862418; cv=none; b=Cg3TpkMSRL1JJOMTKr4HVDKKkcJGHctPHf5edtz6tk/7OyhyibA7pOBWigkrdGwz1UVhixbamRYcmhDjyjNNOGN9SLx0QMQb5uuxt7hVTxH+dV2rgeuKua2L9gHOwIp70dAZplQjYFM0OOr6xcckF0K/OfrxUglbtGkyel6ESQQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862418; c=relaxed/simple; bh=KtEA1mk6JfjgPW/BabL7nch+gDd3Wsxjpv4iDjidqho=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nRloW816X/XFE6Iius5kyh+RLMotgZVjGTKILRICs+GvQpJeBn/dqYf0bmTDwY7+f5cO29SX32t5GaB9RBJp1L8ZXpdwP3WqrIXmBd+DQXe54kFGrD3iCMwkYDYOyHZHaU/zk7M4ictb5hJbpjiaROLLwhGPLWZ/DW5F6xMQYHY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Dyvu8tZi; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Dyvu8tZi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862417; x=1810398417; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KtEA1mk6JfjgPW/BabL7nch+gDd3Wsxjpv4iDjidqho=; b=Dyvu8tZiIlckuHJxgNJECCW1woN3O2KKMI/1jeY4XRTIHuqcmJnXtEfe wGIYynbzrYHzNE9b6xwnZny9+4DMTtucJ2R0QvBh2zRX3gbc9wmIYGHu9 QEU67/RTaNIAbmgE5ENSpVTjz5imKyHysX1lz2YX0FZw5AKMc+XRt8X4m vfwwr0VQ7dabuzoWieyTg5Sh92IX7K+2+DUSC5RfMB7Gror5ZLxyZHK+R LXTjbGEKVp4+/njYUP9ZKdchyJ23348ZNSVtFhGQgb7uBfxHt76q7+ZRF Iu72PJN7GT1xKONJRjSj+ub/2o1fZLVT3FPE7p6PghZktrJUcunkUBhdd g==; X-CSE-ConnectionGUID: wJEs/oDnRlmxv/3jrTGOug== X-CSE-MsgGUID: U3w86+aTTZiJCPXTlXM0/w== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785286" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785286" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:57 -0700 X-CSE-ConnectionGUID: OjvOzWpmTd+aN5pSph3dCw== X-CSE-MsgGUID: F92zqIqqRGemsu42CBT1WA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857261" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:56 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 12/17] i3c: mipi-i3c-hci: Factor out reset-and-restore helper Date: Fri, 15 May 2026 19:26:16 +0300 Message-ID: <20260515162621.57719-13-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor the reset-and-restore sequence out of i3c_hci_rpm_resume() into a separate helper. This allows the same logic to be reused for recovery paths in subsequent changes without duplicating suspend/resume handling. No functional change. Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V4: Add Frank's Rev'd by Changes in V3: None Changes in V2: Drop redundant i3c_hci_sync_irq_inactive(hci) from i3c_hci_reset_and_restore() because it is called by hci->io->suspend() anyway drivers/i3c/master/mipi-i3c-hci/core.c | 19 +++++++++++++++++-- drivers/i3c/master/mipi-i3c-hci/hci.h | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index 8274c84b16be..12a0122fb709 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -798,9 +798,8 @@ int i3c_hci_rpm_suspend(struct device *dev) } EXPORT_SYMBOL_GPL(i3c_hci_rpm_suspend); =20 -int i3c_hci_rpm_resume(struct device *dev) +static int i3c_hci_do_reset_and_restore(struct i3c_hci *hci) { - struct i3c_hci *hci =3D dev_get_drvdata(dev); int ret; =20 ret =3D i3c_hci_reset_and_init(hci); @@ -821,6 +820,22 @@ int i3c_hci_rpm_resume(struct device *dev) =20 return 0; } + +int i3c_hci_reset_and_restore(struct i3c_hci *hci) +{ + i3c_hci_bus_disable(hci); + + hci->io->suspend(hci); + + return i3c_hci_do_reset_and_restore(hci); +} + +int i3c_hci_rpm_resume(struct device *dev) +{ + struct i3c_hci *hci =3D dev_get_drvdata(dev); + + return i3c_hci_do_reset_and_restore(hci); +} EXPORT_SYMBOL_GPL(i3c_hci_rpm_resume); =20 static int i3c_hci_runtime_suspend(struct device *dev) diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mip= i-i3c-hci/hci.h index 97c31a315a6e..a3151c26827e 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -175,4 +175,6 @@ int i3c_hci_process_xfer(struct i3c_hci *hci, struct hc= i_xfer *xfer, int n); int i3c_hci_rpm_suspend(struct device *dev); int i3c_hci_rpm_resume(struct device *dev); =20 +int i3c_hci_reset_and_restore(struct i3c_hci *hci); + #endif --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19EE54DB572 for ; Fri, 15 May 2026 16:26:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862420; cv=none; b=TQ4Zgco1iaGeFOPuQEfvWOyp8PW35vWgI7V5v70pMF8Qgi6Dzkex0bKueR942Xq1HKKL6U8jPK2Jt4gUay953AkSB7d3kRNu9W+X2Fk9axNhN3pgeLFYjx+IMUaVT0DdrlGSSi4LQaO/37c61/5UFrHW0eKk9uRzzhlNyYjFUy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862420; c=relaxed/simple; bh=D5oBESzPNx+cLrbnJ1M6pVbNyC/gDptaQOG6kHbyyL4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W2eart5+MGLu6Jq9I0p2KFEtOGQKB9IENBd71QAcPlXgycT5fue/5popU21AxFREl1R69RI1MOBIfdPECC6YN89nZxxroWHnKtURjTNCgNul8VB44CW3vw9WyIXj6JB3//r52Rj7qKy50ugnCy1kiHTpzjibem44PlBcCNeC2/w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=b5Ya9iCN; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="b5Ya9iCN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862419; x=1810398419; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D5oBESzPNx+cLrbnJ1M6pVbNyC/gDptaQOG6kHbyyL4=; b=b5Ya9iCNS4xNapwdHCp+QKHBkC3JEfm0Ia+7c9Ei1GbGnuxa9WWLJKB7 3evC96YuQyxF5DPch2fD9NpkuSPljn77oP2MY1mSh12RO+gqtvCo+55cn FGYM5qDs9a/5Z8JhgYbsOvbj9zmz6mMEqS16mHVpkanGFDhkDZSZazf7y X6KkWgEgjFLQkKfNBWiXDMDhEtWUQfkNdBxHXyLrzv0UKUCCQ7TMpEVLv sEo0LlDDcWokL8T7O+tM4oe3K0ndm0lYugS/2tVpzvYJ+FeIC6lE6tD51 0mMA2Vd9inCQEWG4CwGgeu/8Veqap4bhh+T9GxKSdLWUY7AWzbhc8MwHm Q==; X-CSE-ConnectionGUID: jAeOhOz2S4uZCnGup7h8kw== X-CSE-MsgGUID: EA4lRGj6T9mMddWYNoZzAQ== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785293" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785293" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:59 -0700 X-CSE-ConnectionGUID: y63FIfgnSJWwp47td8GiQw== X-CSE-MsgGUID: VXvD5CYTR5mgeJR/rbB60w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857272" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:26:58 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 13/17] i3c: mipi-i3c-hci: Add DMA-mode recovery for internal controller errors Date: Fri, 15 May 2026 19:26:17 +0300 Message-ID: <20260515162621.57719-14-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Handle internal I3C HCI errors when operating in DMA mode by adding a simple recovery mechanism. On detection of an internal controller error, mark recovery as needed and attempt to restore operation by performing a software reset followed by state restore. To keep recovery straightforward on this unlikely error path, all currently queued transfers are terminated and completed with an error. This allows the controller to resume operation after internal failures rather than remaining permanently stuck. Note, internal errors indicated by INTR_HC_INTERNAL_ERR, cause the controller to stop. Signed-off-by: Adrian Hunter --- Changes in V4: None Changes in V3: When erroring out transfers, ensure the final transfer of a transfer list is processed last Changes in V2: Rename completing_xfer to final_xfer Add hci_dma_xfer_done() before checking for an already complete transfer Improve commit message drivers/i3c/master/mipi-i3c-hci/cmd.h | 6 ++ drivers/i3c/master/mipi-i3c-hci/core.c | 1 + drivers/i3c/master/mipi-i3c-hci/dma.c | 93 +++++++++++++++++++++++--- drivers/i3c/master/mipi-i3c-hci/hci.h | 1 + 4 files changed, 92 insertions(+), 9 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/cmd.h b/drivers/i3c/master/mip= i-i3c-hci/cmd.h index b1bf87daa651..7bada7b4b2de 100644 --- a/drivers/i3c/master/mipi-i3c-hci/cmd.h +++ b/drivers/i3c/master/mipi-i3c-hci/cmd.h @@ -65,4 +65,10 @@ struct hci_cmd_ops { extern const struct hci_cmd_ops mipi_i3c_hci_cmd_v1; extern const struct hci_cmd_ops mipi_i3c_hci_cmd_v2; =20 +static inline void hci_cmd_set_resp_err(u32 *response, int resp_err) +{ + *response &=3D ~RESP_ERR_FIELD; + *response |=3D FIELD_PREP(RESP_ERR_FIELD, resp_err); +} + #endif diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index 12a0122fb709..69dcf5dad3a5 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -668,6 +668,7 @@ static irqreturn_t i3c_hci_irq_handler(int irq, void *d= ev_id) if (val & INTR_HC_INTERNAL_ERR) { dev_err(&hci->master.dev, "Host Controller Internal Error\n"); val &=3D ~INTR_HC_INTERNAL_ERR; + hci->recovery_needed =3D true; } =20 if (val) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index f9023cb3c5a2..f39a6ce2aad5 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -9,6 +9,7 @@ */ =20 #include +#include #include #include #include @@ -258,6 +259,10 @@ static void hci_dma_init_rh(struct i3c_hci *hci, struc= t hci_rh_data *rh, int i) rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE); rh_reg_write(RING_CONTROL, RING_CTRL_ENABLE | RING_CTRL_RUN_STOP); =20 + /* + * Do not clear the entries of rh->src_xfers because the recovery uses + * them. In other cases they should be NULL anyway. + */ rh->done_ptr =3D 0; rh->ibi_chunk_ptr =3D 0; rh->xfer_space =3D rh->xfer_entries; @@ -362,7 +367,7 @@ static int hci_dma_init(struct i3c_hci *hci) rh->resp =3D dma_alloc_coherent(rings->sysdev, resps_sz, &rh->resp_dma, GFP_KERNEL); rh->src_xfers =3D - kmalloc_objs(*rh->src_xfers, rh->xfer_entries); + kzalloc_objs(*rh->src_xfers, rh->xfer_entries); ret =3D -ENOMEM; if (!rh->xfer || !rh->resp || !rh->src_xfers) goto err_out; @@ -572,13 +577,15 @@ static void hci_dma_xfer_done(struct i3c_hci *hci, st= ruct hci_rh_data *rh) hci_dma_unmap_xfer(hci, xfer, 1); rh->src_xfers[done_ptr] =3D NULL; xfer->ring_entry =3D -1; - xfer->response =3D resp; if (tid !=3D xfer->cmd_tid) { dev_err(&hci->master.dev, "response tid=3D%d when expecting %d\n", tid, xfer->cmd_tid); - /* TODO: do something about it? */ + hci->recovery_needed =3D true; + if (!RESP_STATUS(resp)) + hci_cmd_set_resp_err(&resp, RESP_ERR_HC_TERMINATED); } + xfer->response =3D resp; if (xfer =3D=3D xfer->final_xfer || RESP_STATUS(resp)) complete(xfer->final_xfer->completion); if (RESP_STATUS(resp)) @@ -625,6 +632,60 @@ static void hci_dma_unblock_enqueue(struct i3c_hci *hc= i) } } =20 +static void hci_dma_error_out_rh(struct i3c_hci *hci, struct hci_rh_data *= rh) +{ + /* + * The entries of rh->src_xfers are not cleared by + * i3c_hci_reset_and_restore(), so can be used here. Do 2 passes so + * that the final_xfer of an xfer list is always processed last. + */ + for (int pass =3D 0; pass < 2; pass++) + for (int i =3D 0; i < rh->xfer_entries; i++) { + struct hci_xfer *xfer =3D rh->src_xfers[i]; + + if (!xfer || (!pass && xfer =3D=3D xfer->final_xfer)) + continue; + hci_dma_unmap_xfer(hci, xfer, 1); + rh->src_xfers[i] =3D NULL; + xfer->ring_entry =3D -1; + hci_cmd_set_resp_err(&xfer->response, RESP_ERR_HC_TERMINATED); + if (xfer =3D=3D xfer->final_xfer) + complete(xfer->final_xfer->completion); + } +} + +static void hci_dma_error_out_all(struct i3c_hci *hci) +{ + struct hci_rings_data *rings =3D hci->io_data; + + for (int i =3D 0; i < rings->total; i++) + hci_dma_error_out_rh(hci, &rings->headers[i]); +} + +static void hci_dma_recovery(struct i3c_hci *hci) +{ + int ret; + + dev_err(&hci->master.dev, "Attempting to recover from internal errors\n"); + + for (int i =3D 0; i < 3; i++) { + ret =3D i3c_hci_reset_and_restore(hci); + if (!ret) + break; + dev_err(&hci->master.dev, "Reset and restore failed, error %d\n", ret); + /* Just in case the controller is busy, give it some time */ + msleep(1000); + } + + spin_lock_irq(&hci->lock); + hci_dma_error_out_all(hci); + hci_dma_unblock_enqueue(hci); + hci->recovery_needed =3D false; + spin_unlock_irq(&hci->lock); + + dev_err(&hci->master.dev, "Recovery %s\n", ret ? "failed!" : "done"); +} + static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, struct hci_xfer *xfer_list, int n) { @@ -640,6 +701,17 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, =20 ring_status =3D rh_reg_read(RING_STATUS); if (ring_status & RING_STATUS_RUNNING) { + /* + * The transfer may have already completed, especially + * if recovery has just run. Do nothing in that case. + */ + hci_dma_xfer_done(hci, rh); + if (xfer_list->final_xfer->ring_entry < 0 && + !hci->recovery_needed && !hci->enqueue_blocked && + ring_status =3D=3D (RING_STATUS_ENABLED | RING_STATUS_RUNNING)) { + spin_unlock_irq(&hci->lock); + return false; + } hci->enqueue_blocked =3D true; spin_unlock_irq(&hci->lock); /* stop the ring */ @@ -647,12 +719,8 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, spin_lock_irq(&hci->lock); ring_status =3D rh_reg_read(RING_STATUS); if (ring_status & RING_STATUS_RUNNING) { - /* - * We're deep in it if ever this condition is ever met. - * Hardware might still be writing to memory, etc. - */ - dev_crit(&hci->master.dev, "unable to abort the ring\n"); - WARN_ON(1); + dev_err(&hci->master.dev, "Unable to abort the DMA ring\n"); + hci->recovery_needed =3D true; } } =20 @@ -662,6 +730,13 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, =20 hci_dma_xfer_done(hci, rh); =20 + if (hci->recovery_needed) { + hci->enqueue_blocked =3D true; + spin_unlock_irq(&hci->lock); + hci_dma_recovery(hci); + return true; + } + for (i =3D 0; i < n; i++) { struct hci_xfer *xfer =3D xfer_list + i; int idx =3D xfer->ring_entry; diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mip= i-i3c-hci/hci.h index a3151c26827e..4bf2c66c97b4 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -55,6 +55,7 @@ struct i3c_hci { atomic_t next_cmd_tid; bool irq_inactive; bool enqueue_blocked; + bool recovery_needed; wait_queue_head_t enqueue_wait_queue; u32 caps; unsigned int quirks; --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09BE239C63E for ; Fri, 15 May 2026 16:27:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862422; cv=none; b=a7yUxb9gBBYw7RMG3e4T3c6Iw89tuk/ZqcRoUqRept/+qFTgxhPzRuZfYIz8RWOb6IzPjs0YnHwDN4ivP7Xv+Y/0Uz4f8O/SitC9ZC6UwfsWypHD32iDelSsY4Ff9JVW0q+IFizE3bZcMu+mqPvdW9xogDrhubg/chaeSJGIoT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862422; c=relaxed/simple; bh=K0FaceN76BW9oMyI5NTtJOg+RiTxX8/HuQ0RxbmIDM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IB+Ort/B77Z9LL/liQhY0WL49aP0HJOgau8euzRb8RPGVaiZV+y00boMENWVUZYIQWd85mIgq6a+svsuMjiuMBTw8xPihNkRbbBh5VKd+K7vvy04Ocev/u+ajqyKTAFkNHonIy1FBS6D+okp6R3Lh9kURtEOXGPI6txeY0wyDek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GU5pTZCn; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GU5pTZCn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862421; x=1810398421; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K0FaceN76BW9oMyI5NTtJOg+RiTxX8/HuQ0RxbmIDM4=; b=GU5pTZCnowGrfMCrWngvR4Y2OfzICzM7Q9H0iWb+wsPjTw5jZAmEjW6s DsgtuKrWAM7cL57n8zhgzfaIpZDjqZU0KVVQiWU1O8R+LSaiiOdY0g589 wCv5tfYSooQmRcuHMki/ExWfiI9T//O0aTbk8Vm5mJTHQ47aOzjpJijhy RRkB+1EcfpOL76hTKJTJeK/Kd9MRTmA2B2dS5bXghU9eB6pKSBTvuIZK6 mCmZM/s+MdV0ox6lG9AOla55PPiMqCSLEEEzF1n6AudQVEdCfQKTV78vb FmkB91A5wF5hxD/ccTyVh4qWuSL/2lJ8dMjPvZrtiCNjjlx8ocEbfyKoZ Q==; X-CSE-ConnectionGUID: 8fSm3idPTw2+5HhAv/Vldg== X-CSE-MsgGUID: 6JZgx6G5S0yf7Pe3j0c4uw== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785297" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785297" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:27:01 -0700 X-CSE-ConnectionGUID: 3eRbHB/8TO+zMHQOtQztAQ== X-CSE-MsgGUID: +uyVVrBTRNKrDjaGaUpQog== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857283" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:27:00 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 14/17] i3c: mipi-i3c-hci: Wait for NoOp commands to complete Date: Fri, 15 May 2026 19:26:18 +0300 Message-ID: <20260515162621.57719-15-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a transfer list is only partially completed due to an error, hci_dma_dequeue_xfer() overwrites the remaining DMA ring entries with NoOp commands and restarts the ring to flush them out. While NoOp commands are expected to complete successfully, they may still fail to complete if the DMA ring is stuck. Explicitly wait for the NoOp commands to finish, and trigger controller recovery if they do not complete or report an error. This ensures that partially completed transfer lists are reliably resolved and that a stuck ring is recovered promptly. Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V4: Add Frank's Rev'd-by Changes in V3: None Changes in V2: Rename completing_xfer to final_xfer Add missing reinit_completion() drivers/i3c/master/mipi-i3c-hci/dma.c | 39 ++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index f39a6ce2aad5..0fd56bbb84ef 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -686,11 +686,33 @@ static void hci_dma_recovery(struct i3c_hci *hci) dev_err(&hci->master.dev, "Recovery %s\n", ret ? "failed!" : "done"); } =20 +static bool hci_dma_wait_for_noop(struct i3c_hci *hci, struct hci_xfer *xf= er_list, int n, + int noop_pos) +{ + struct completion *done =3D xfer_list->final_xfer->completion; + bool timeout =3D !wait_for_completion_timeout(done, HZ); + u32 error =3D timeout; + + for (int i =3D noop_pos; i < n && !error; i++) + error =3D RESP_STATUS(xfer_list[i].response); + + if (!error) + return true; + + if (timeout) + dev_err(&hci->master.dev, "NoOp timeout error\n"); + else + dev_err(&hci->master.dev, "NoOp error %u\n", error); + + return false; +} + static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, struct hci_xfer *xfer_list, int n) { struct hci_rings_data *rings =3D hci->io_data; struct hci_rh_data *rh =3D &rings->headers[xfer_list[0].ring_number]; + int noop_pos =3D -1; unsigned int i; bool did_unqueue =3D false; u32 ring_status; @@ -698,7 +720,7 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, guard(mutex)(&hci->control_mutex); =20 spin_lock_irq(&hci->lock); - +restart: ring_status =3D rh_reg_read(RING_STATUS); if (ring_status & RING_STATUS_RUNNING) { /* @@ -757,11 +779,10 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, *ring_data++ =3D 0; } =20 - /* disassociate this xfer struct */ - rh->src_xfers[idx] =3D NULL; - - /* and unmap it */ - hci_dma_unmap_xfer(hci, xfer, 1); + if (noop_pos < 0) { + reinit_completion(xfer->final_xfer->completion); + noop_pos =3D i; + } =20 did_unqueue =3D true; } @@ -793,6 +814,12 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, =20 wait_for_completion_timeout(&rh->op_done, HZ); =20 + if (did_unqueue && !hci_dma_wait_for_noop(hci, xfer_list, n, noop_pos)) { + spin_lock_irq(&hci->lock); + hci->recovery_needed =3D true; + goto restart; + } + return did_unqueue; } =20 --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0D864DBD9C for ; Fri, 15 May 2026 16:27:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862424; cv=none; b=UVN4yJQ9Ro8R9t35YYNKErDiafhUNkOSpLcCFNTcp7uw1+MwrMTbFlCip9hq9WES2VKsR0MoXMoIlpsobuQGCG/DWc6Q2/y7kjuJrf1ycSB2//Qd10eWDMnbjbFHA/lCuNPeDU9sPBUOHQIaS6B+YfaoidCd7zw1Abdfx4ruVdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862424; c=relaxed/simple; bh=6fXwyeduDin/S6au+6ZNs/9x+JnffSJL5W3KcM4GM4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZvvY25GjGRUiAGy0Cfmmi5Y4wWzkWgn9uvSFvwaQ98Wd0v28Dyo9q7EGQdFiz/fUi/QpYwTQPRB6Yck6IEJd8WiTSUnIqyQPEHjd0oi94RDxaZLsSMSdyJnHwv49BfcUV1s0n9oECYvZ8dLfrIAZ/POrEvO2iBmztJrAlP8v4iU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UbGY3Dqq; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UbGY3Dqq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862423; x=1810398423; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6fXwyeduDin/S6au+6ZNs/9x+JnffSJL5W3KcM4GM4A=; b=UbGY3DqqbFwjc+ZcL4d4hjLcr46vS81TbsNwv4e9gODwbSQBnqJN2qc+ ESB4zUohfuh/z1C1iBmMG/MSy153jrcjkMWvs/mW8JrMlb5J0g3zETqyh NRQq8dOMn4IX1JXaWL0vc+83cCIHqhvHhvaZH3cgKVWVWhsUNpP7egkLg D/Cs8MMc2N4FRrEvX361xItJHZ5LegwgXMae9nvH1fnu8WxNOwNhhO2CR C/FlwIjjryt7X3xOUjmIZqpVwky1KSiynoAK0xXTL/o1wo+JL40xsHIHA x0/fgfxFxNYNA0B2YjMuzY9mQcaPW7ImqJ+HDFm0CRGhfTf2GJDda4u9W g==; X-CSE-ConnectionGUID: Kg3UbaEyRDCPlCosK4Vcmw== X-CSE-MsgGUID: dHa4TfDcS3OkzD9aszDiRg== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785302" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785302" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:27:03 -0700 X-CSE-ConnectionGUID: sGMNAS9fQTyvrOsKCXSl+A== X-CSE-MsgGUID: /1/MNj7zQjG1WbM831eWvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857293" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:27:02 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 15/17] i3c: mipi-i3c-hci: Base timeouts on actual transfer start time Date: Fri, 15 May 2026 19:26:19 +0300 Message-ID: <20260515162621.57719-16-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Transfer timeouts are currently measured from the point where a transfer list is queued to the controller. This can cause transfers to time out before they have actually started, if earlier queued transfers consume the timeout interval. Fix this by recording when a transfer reaches the head of the queue and adjusting the timeout calculation to start from that point. The existing low-overhead completion-based timeout mechanism is preserved, but care is taken to ensure the transfer start time is consistently recorded for both PIO and DMA paths. This prevents premature timeouts while retaining efficient timeout handling. Signed-off-by: Adrian Hunter --- Changes in V4: Rename start_time to start_jiffies Changes in V3: None Changes in V2: Do not flag the next transfer as started when there is an error which halts the controller Instead flag it started at the end of hci_dma_dequeue_xfer() Use hci_start_xfer() in pio.c drivers/i3c/master/mipi-i3c-hci/core.c | 19 ++++++++++++++++++- drivers/i3c/master/mipi-i3c-hci/dma.c | 19 ++++++++++++++++++- drivers/i3c/master/mipi-i3c-hci/hci.h | 11 +++++++++++ drivers/i3c/master/mipi-i3c-hci/pio.c | 1 + 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index 69dcf5dad3a5..c6edbbedfdd7 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -275,13 +275,30 @@ int i3c_hci_process_xfer(struct i3c_hci *hci, struct = hci_xfer *xfer, int n) { struct completion *done =3D xfer[n - 1].completion; unsigned long timeout =3D xfer[n - 1].timeout; + unsigned long remaining_timeout =3D timeout; + long time_taken; + bool started; int ret; =20 + xfer[0].started =3D false; + ret =3D hci->io->queue_xfer(hci, xfer, n); if (ret) return ret; =20 - if (!wait_for_completion_timeout(done, timeout)) { + while (!wait_for_completion_timeout(done, remaining_timeout)) { + scoped_guard(spinlock_irqsave, &hci->lock) { + started =3D xfer[0].started; + time_taken =3D jiffies - xfer[0].start_jiffies; + } + /* Keep waiting if xfer has not started */ + if (!started) + continue; + /* Recalculate timeout based on actual start time */ + if (time_taken < timeout) { + remaining_timeout =3D timeout - time_taken; + continue; + } if (hci->io->dequeue_xfer(hci, xfer, n)) { dev_err(&hci->master.dev, "%s: timeout error\n", __func__); return -ETIMEDOUT; diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index 0fd56bbb84ef..9a01c740760f 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -543,6 +543,9 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, enqueue_ptr =3D (enqueue_ptr + 1) % rh->xfer_entries; } =20 + if (rh->xfer_space =3D=3D rh->xfer_entries) + hci_start_xfer(xfer_list); + rh->xfer_space -=3D n; =20 op1_val &=3D ~RING_OP1_CR_ENQ_PTR; @@ -558,6 +561,7 @@ static void hci_dma_xfer_done(struct i3c_hci *hci, stru= ct hci_rh_data *rh) u32 op1_val, op2_val, resp, *ring_resp; unsigned int tid, done_ptr =3D rh->done_ptr; unsigned int done_cnt =3D 0; + bool start_next =3D false; struct hci_xfer *xfer; =20 for (;;) { @@ -588,8 +592,14 @@ static void hci_dma_xfer_done(struct i3c_hci *hci, str= uct hci_rh_data *rh) xfer->response =3D resp; if (xfer =3D=3D xfer->final_xfer || RESP_STATUS(resp)) complete(xfer->final_xfer->completion); - if (RESP_STATUS(resp)) + else + hci_start_xfer(xfer); + if (RESP_STATUS(resp)) { hci->enqueue_blocked =3D true; + start_next =3D false; + } else { + start_next =3D true; + } } =20 done_ptr =3D (done_ptr + 1) % rh->xfer_entries; @@ -598,6 +608,10 @@ static void hci_dma_xfer_done(struct i3c_hci *hci, str= uct hci_rh_data *rh) } =20 rh->xfer_space +=3D done_cnt; + if (start_next && rh->xfer_space < rh->xfer_entries) { + xfer =3D rh->src_xfers[done_ptr]; + hci_start_xfer(xfer); + } op1_val =3D rh_reg_read(RING_OPERATION1); op1_val &=3D ~RING_OP1_CR_SW_DEQ_PTR; op1_val |=3D FIELD_PREP(RING_OP1_CR_SW_DEQ_PTR, done_ptr); @@ -810,6 +824,9 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, =20 hci_dma_unblock_enqueue(hci); =20 + if (rh->xfer_space < rh->xfer_entries) + hci_start_xfer(rh->src_xfers[rh->done_ptr]); + spin_unlock_irq(&hci->lock); =20 wait_for_completion_timeout(&rh->op_done, HZ); diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mip= i-i3c-hci/hci.h index 4bf2c66c97b4..30297823ca85 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -11,6 +11,7 @@ #define HCI_H =20 #include +#include =20 /* 32-bit word aware bit and mask macros */ #define W0_MASK(h, l) GENMASK((h) - 0, (l) - 0) @@ -88,11 +89,13 @@ struct hci_xfer { u32 cmd_desc[4]; u32 response; bool rnw; + bool started; void *data; unsigned int data_len; unsigned int cmd_tid; struct completion *completion; unsigned long timeout; + unsigned long start_jiffies; union { struct { /* PIO specific */ @@ -123,6 +126,14 @@ static inline void hci_free_xfer(struct hci_xfer *xfer= , unsigned int n) kfree(xfer); } =20 +static inline void hci_start_xfer(struct hci_xfer *xfer) +{ + if (!xfer->started) { + xfer->started =3D true; + xfer->start_jiffies =3D jiffies; + } +} + /* This abstracts PIO vs DMA operations */ struct hci_io_ops { bool (*irq_handler)(struct i3c_hci *hci); diff --git a/drivers/i3c/master/mipi-i3c-hci/pio.c b/drivers/i3c/master/mip= i-i3c-hci/pio.c index 8f48a81e65ab..6b8cc5f2b4d2 100644 --- a/drivers/i3c/master/mipi-i3c-hci/pio.c +++ b/drivers/i3c/master/mipi-i3c-hci/pio.c @@ -605,6 +605,7 @@ static bool hci_pio_process_cmd(struct i3c_hci *hci, st= ruct hci_pio_data *pio) * Finally send the command. */ hci_pio_write_cmd(hci, pio->curr_xfer); + hci_start_xfer(pio->curr_xfer); /* * And move on. */ --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E047B4DC547 for ; Fri, 15 May 2026 16:27:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862426; cv=none; b=WWsl9Bbr4KLqv2R4C6yLfk5UCzzCcUQRoeGnLw3Ypv7NcVh3CWax+052eYHfSNT7J3uGaBnkyy3BV+XNx/PdJE2JA3UXsTi7E1geLZO1kXxQ2jpBFnmPPk4ZvoNoeQaDFonvag7R1U6BlHIYV9H0uW8Q6oAGLX+PPAD9luvtBCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862426; c=relaxed/simple; bh=kUVjrL0lqKCpnst7yNWoomTv/ezfLwAtTMQwfCRoTd0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eTygqrsaPMtRD+x0yZt61Tm2n+AKmoTNh5dvwdmqF3WmrrXQetI4L1OlVU2YDBMR1u7AwlD2G8+6gOc3+ppp0ol3FDb+1ACSn9Z3EY7aJsrHA7xPoxBX45T+dcgx5Y4A51ETTQV8P0Xjl/DnQ8ltEHwGr0U2uUfqXWKQ3gu+Cgo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=emYZxqZS; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="emYZxqZS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862425; x=1810398425; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kUVjrL0lqKCpnst7yNWoomTv/ezfLwAtTMQwfCRoTd0=; b=emYZxqZSvcYltHVsQgYyUbPBaLUGX65QkQ4hD+V36+XxB6SDvK0XZztI MZceZ7lYsCiE9im/HcRVXY1+FwCSAUt3TLQvQI1a4HKggHKApzJBVAlR0 dn+4VcSnHxmDEoKSRC51pJ18jmKHo2bI39uuAECp6oZ3pjbgdDjdROIUN sN6nperkFgtktlZJQYSkm/KNgVHj19TN+3eb1f85f92MYbY7T0D+T3a3W TT7tpPp2RB4fyirwnJzsGpXtnFMMCk6MR8gjQ1Sg/rIj86iiBj1D9MrPS FdxwGpnG99P2nFODuEVBsbo9hrlbae18toeKCBG5AQtjJkwKsfTKrOacS g==; X-CSE-ConnectionGUID: oqdwiIh7QDWk8CVq4knQlg== X-CSE-MsgGUID: Ohex3jsnRK+x0redMc3D/A== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785307" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785307" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:27:05 -0700 X-CSE-ConnectionGUID: ANF83kFASlyto7lyTmZbHg== X-CSE-MsgGUID: QBC3Trb0T4aXGxQRquU1WQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857298" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:27:03 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 16/17] i3c: mipi-i3c-hci: Consolidate DMA ring allocation Date: Fri, 15 May 2026 19:26:20 +0300 Message-ID: <20260515162621.57719-17-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" dma_alloc_coherent() allocates memory in whole pages, which can waste space when command and response queues are allocated separately. Allocate the DMA command and response queues from a single coherent allocation instead, while preserving the required 4-byte alignment. This reduces memory overhead without changing behavior. Signed-off-by: Adrian Hunter --- Changes in V4: Cache allocation size in rh->xfer_alloc_sz to avoid recomputing in hci_dma_free() Changes in V3: None Changes in V2: Check for failed allocation before assignments to avoid doing arithmetic with NULL pointers drivers/i3c/master/mipi-i3c-hci/dma.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index 9a01c740760f..0136f3064ada 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -130,7 +130,7 @@ struct hci_rh_data { dma_addr_t xfer_dma, resp_dma, ibi_status_dma, ibi_data_dma; unsigned int xfer_entries, ibi_status_entries, ibi_chunks_total; unsigned int xfer_struct_sz, resp_struct_sz, ibi_status_sz, ibi_chunk_sz; - unsigned int done_ptr, ibi_chunk_ptr, xfer_space; + unsigned int xfer_alloc_sz, done_ptr, ibi_chunk_ptr, xfer_space; struct hci_xfer **src_xfers; struct completion op_done; }; @@ -187,13 +187,7 @@ static void hci_dma_free(void *data) rh =3D &rings->headers[i]; =20 if (rh->xfer) - dma_free_coherent(rings->sysdev, - rh->xfer_struct_sz * rh->xfer_entries, - rh->xfer, rh->xfer_dma); - if (rh->resp) - dma_free_coherent(rings->sysdev, - rh->resp_struct_sz * rh->xfer_entries, - rh->resp, rh->resp_dma); + dma_free_coherent(rings->sysdev, rh->xfer_alloc_sz, rh->xfer, rh->xfer_= dma); kfree(rh->src_xfers); if (rh->ibi_status) dma_free_coherent(rings->sysdev, @@ -359,18 +353,19 @@ static int hci_dma_init(struct i3c_hci *hci) dev_dbg(&hci->master.dev, "xfer_struct_sz =3D %d, resp_struct_sz =3D %d", rh->xfer_struct_sz, rh->resp_struct_sz); - xfers_sz =3D rh->xfer_struct_sz * rh->xfer_entries; + xfers_sz =3D round_up(rh->xfer_struct_sz * rh->xfer_entries, 4); resps_sz =3D rh->resp_struct_sz * rh->xfer_entries; + rh->xfer_alloc_sz =3D xfers_sz + resps_sz; =20 - rh->xfer =3D dma_alloc_coherent(rings->sysdev, xfers_sz, + rh->xfer =3D dma_alloc_coherent(rings->sysdev, rh->xfer_alloc_sz, &rh->xfer_dma, GFP_KERNEL); - rh->resp =3D dma_alloc_coherent(rings->sysdev, resps_sz, - &rh->resp_dma, GFP_KERNEL); rh->src_xfers =3D kzalloc_objs(*rh->src_xfers, rh->xfer_entries); ret =3D -ENOMEM; - if (!rh->xfer || !rh->resp || !rh->src_xfers) + if (!rh->xfer || !rh->src_xfers) goto err_out; + rh->resp =3D rh->xfer + xfers_sz; + rh->resp_dma =3D rh->xfer_dma + xfers_sz; =20 /* IBIs */ =20 --=20 2.51.0 From nobody Mon May 25 08:10:49 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D90FE4DD6CB for ; Fri, 15 May 2026 16:27:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862428; cv=none; b=NXVqX8TApgwBe0jzLe2lFW8j26T4ATCecNTIW+Ri447rMma0aFbeMmTSlnwauqVm0oduPguP97AgpCqVcZOQSEEVo82aLQv+JU2cVwkHtiylbFf5Jybpqch8StQGN9Qj6jFhG15K388ok6Tgx0V2n3/nsOBlVersp7nQTjxb5L8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862428; c=relaxed/simple; bh=nToMwuW9z9iC87oDlmlW2x/HtDiZ1V7hTueP90c3kwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JrhhqxGLvnFIDuTY7Fpg52VmIDLrcQXuR13+xWsntZmYHcNEEeEagfStl5jSG9fpNNf8WcNy4n4YxGa1WtM6rLREDEY2NhgueDFTfWhyXr1r6GZP36aadH1aC8CcIuIK9YnTZZspuH675hW58Qg/G0VYBPQois3mR1cBTdcz7LI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CqDRd99o; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CqDRd99o" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1778862427; x=1810398427; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nToMwuW9z9iC87oDlmlW2x/HtDiZ1V7hTueP90c3kwg=; b=CqDRd99o0xO7RU8U1v81xH5MI2KQLB+xb+mPdT+/tRHeqZ6jHvj5uwsu 2zQJHZ59oCUeSU7YHtSOnVk2LRm4A02Tp0QwcpyOu0NL76zuNK8s95UQ6 PIfmX3n0MmEhI9wE0LkxsP+iNRUmY+ppU+VNvwH9uth3FQk5f8H/tGk7u vt28alOvh7PB8ShYqSsXIiFTmghZGvI9YsavMzVM4O0L/eiPiad703vkB 7bqkabSObDcYiyB6d+HKS8bMmNwmVEHSOq/5mnqSeYrpvsxAgmy/hHb/v aQzhuX5GKJvusB8O6u3/fgHGq+23mDyMqD4UlCIUws3BVKFRzTiNpMwwa Q==; X-CSE-ConnectionGUID: PGv7k1vTReC0/42ExJSp/w== X-CSE-MsgGUID: P3M2XDLBS7+ZeiEi042ocQ== X-IronPort-AV: E=McAfee;i="6800,10657,11787"; a="79785313" X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="79785313" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:27:07 -0700 X-CSE-ConnectionGUID: lhf+66zoS8eDkq99WLvdLg== X-CSE-MsgGUID: DSHfI1QoQYC5tON6cqrTyQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,236,1770624000"; d="scan'208";a="238857310" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.28]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2026 09:27:05 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 17/17] i3c: mipi-i3c-hci: Increase DMA transfer ring size to maximum Date: Fri, 15 May 2026 19:26:21 +0300 Message-ID: <20260515162621.57719-18-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260515162621.57719-1-adrian.hunter@intel.com> References: <20260515162621.57719-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The DMA transfer ring is currently limited to 16 entries, despite the MIPI I3C HCI supporting up to 32 devices. When the ring lacks space for a new transfer list, the driver returns -EBUSY, which can be unexpected for clients. Increase the DMA transfer ring size to the maximum supported value of 255 entries. This effectively eliminates ring-space exhaustion in practice and avoids the complexity of adding secondary queuing mechanisms. Even at the maximum size, the memory overhead remains small (approximately 24 bytes per entry by default). Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V4: Add Frank's Rev'd-by Changes in V2 and V3: None drivers/i3c/master/mipi-i3c-hci/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index 0136f3064ada..5c6ae2055618 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -27,7 +27,7 @@ */ =20 #define XFER_RINGS 1 /* max: 8 */ -#define XFER_RING_ENTRIES 16 /* max: 255 */ +#define XFER_RING_ENTRIES 255 /* max: 255 */ =20 #define IBI_RINGS 1 /* max: 8 */ #define IBI_STATUS_RING_ENTRIES 32 /* max: 255 */ --=20 2.51.0