From nobody Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 666A13A6B6A for ; Mon, 4 May 2026 11:34:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894447; cv=none; b=XaFwouUeCMFwl2kyXxuA4LDywFlsyjZQSH0nIBaZ97ICVrErCM0WfGyd+lwq7exTIpIBD52ewVa4TUBFltu8TYKFlIQ+mcd3+Az+J4k3N0KF+jVIA2NogvsP5G0xHlwagwuy0KSZaHYqiAUdqeK7kozwBktGgHPQNb1tBz8ZALo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894447; c=relaxed/simple; bh=teWJz0OV8eS9QHdCuehQXJXiHZ/gJsf/+8wEIwLhtIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XsXy/iahwo/XD0kR7MCN97vuB2MDnYHBu3QTg8AytDbQfjX/kxidNhP+2mJypDzq1kPcbcS/QtpegeZvISUK8dEg2yF6xlbile2Y7frQDd5jLEh+eTCvFuwUkwvt00glYn7p9kaO64HViLo6uH7T9H0dJ/8B+KNgEcmwlRYPcps= 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=SYdgNkd5; arc=none smtp.client-ip=192.198.163.13 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="SYdgNkd5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894445; x=1809430445; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=teWJz0OV8eS9QHdCuehQXJXiHZ/gJsf/+8wEIwLhtIE=; b=SYdgNkd5qNhGU4igFceX1AbBzqN9foqZ8+BxqsNdRjMoDqSGJdJ5sx6C SK38LR2x6IVw08G02hwru7krlN5x57B+rqRlGAwdTF+2bRNbXXieUIU3H ul0aZWKD5NulrcXspOVkp2S2cafuaUSK9YdpQArtE+kY8sbq1P46VHymW Ukc5Lt8dEeh9OjkFnd81PTu1Xj7lDOUiP3IGQwWg/Re3wPXRdNWfefect Lh+QKmL5hWtfbfzlFR2w91ghyAkl1FfDs4OrTXmo6yFX2GUT9ZDbFOnlu NY2Q1uxNsiMS9wGBD6xlHMvHvnFaOF9mxWQPj67hy5e3AYH7IWJ5xbuMr A==; X-CSE-ConnectionGUID: a6damoHFQoSAjMNBhDMw4g== X-CSE-MsgGUID: 3K5JVuvIRjag8gKAoyNgdg== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315138" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315138" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:05 -0700 X-CSE-ConnectionGUID: HUKmFH1vTRSpfOIvS0ncJQ== X-CSE-MsgGUID: HasUU7NGROKR5FngHOQvNA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478189" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34: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 V3 01/16] i3c: mipi-i3c-hci: Fix suspend behavior when bus disable falls back to software reset Date: Mon, 4 May 2026 14:33:37 +0300 Message-ID: <20260504113352.38490-2-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 DC8DC3BE627 for ; Mon, 4 May 2026 11:34:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894448; cv=none; b=kPCtkDfXYGIZkCEHPaMf93d6Bg62Pfoio/+nb8udvRlqhjUFf43QZrQX1eA0Hd4g4MeWDxJqaV3BH3uqlFsEaNjPSBTtQm/9Cupp8FdZTnt7KoGX+gUrcGeeD7LRB0MoKkWWhLT3fkf0C9kmcNrnUmyDu+NMxNx6D0lT93/58ko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894448; c=relaxed/simple; bh=tBQeJbD6frPT216scr5vXTjp7lJDChruCq8wEw3Bl4k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DrygG8szkbm8eSY3ilTZ+GhSxJUCR7m4iwd6yqjfhXqvLJEvHi5jsrBV32m17Y5WcvAonfvacFoH9djCU4awloLUsVyIKLhnaMPR8cZRasSchHlvLI/bB/DRi9EN9QFCkprXEE/lcnygTbjYuuOxADK0Xj4eba3zqMBP+VyOGWM= 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=VLfhIKGS; arc=none smtp.client-ip=192.198.163.13 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="VLfhIKGS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894447; x=1809430447; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tBQeJbD6frPT216scr5vXTjp7lJDChruCq8wEw3Bl4k=; b=VLfhIKGScuyvBC2HLRq32XTgJKk7y4SpMBIgiyQwWVBvdDPYBPGowEpH i+9X9YBDnu4cBfIIjY+2Xj4pDU3+oHtv0dbn3U3RCGydIK+1TQrbgs7Oq 6g6+c66cR9U8a0ZKvkCqB2wXUr5HngXXNEnH7B1+eESeY9TEz7d7S/uMH 1JYjJOtXAvSVFMRQl1STKSU66jtAI5KIhStm8SS5B/99Bui62lVjt0tdS DRU2ZhzQeRTg7TJlGq/RNrXGhp8o7FKvyi/r6oNCb3DKiFkJeZSSOVTu3 MXvRTshGkcZQab62LLzkksAlwdlk08TYCr3e/9S1AZDSgaAl86THRRNmL g==; X-CSE-ConnectionGUID: 0XprgtEiRCem2j308WLvnw== X-CSE-MsgGUID: PKwSikXqRTyqzneI0h38ag== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315145" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315145" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:07 -0700 X-CSE-ConnectionGUID: pkkDYiE6S7C6x9EkmxHqUg== X-CSE-MsgGUID: gSL30k/bTvmv+R55amxWbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478194" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34: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 V3 02/16] i3c: mipi-i3c-hci: Preserve RUN bit when aborting DMA ring Date: Mon, 4 May 2026 14:33:38 +0300 Message-ID: <20260504113352.38490-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 e487ef52f6b4..4cd32e3afa7b 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 055623BE156 for ; Mon, 4 May 2026 11:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894450; cv=none; b=e0cv74NUZtO4cnkwKEL5+I8KlSctEYyagnnLJnOpISyCwnUxZ+A/S1489NwV6yb8gcbuJ+25DvbG9cOpf95XNIVKMvn09P7ui9hoTRJ/5GguJbrTR/Cqai5y/8CdewzHmwPesiUFR7lS9ul33qIDmv6E8whpuLpYT12DDA0dJx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894450; c=relaxed/simple; bh=Whce9V9RaI6dgCU5/FM6GNfIrFeQa/gRLMY4ctqLAnU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I70KeUBtJ2zxGJdNz7F9RwAH0d30s6aooevtII4HZiG2B1phq1brY/nxa3alEj3ys3mkDGIcKcSWEU3C6QOV29HgE2VncygrzwesTSZKnBVixHUyKP3+Albf7YqcALvdyH5AAFsho11n70k/Ki7FEr+ArfvWlikMV17O5oILP3A= 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=kDi8AV2i; arc=none smtp.client-ip=192.198.163.13 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="kDi8AV2i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894449; x=1809430449; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Whce9V9RaI6dgCU5/FM6GNfIrFeQa/gRLMY4ctqLAnU=; b=kDi8AV2iQ50/3xxz6MZCdmPcVTQpLttNLnnVYbNIm7qOzVT57rNXdHOt kG6DU6iFIBX0cIrz19GjDiBpb9LGY8QOsIBdlgSm7UZTeQzSdHzoIJrYA xD7FUaaRf8KTW3Wl0w2rrkvYF2jhBmxZ/1cn59Si+m4QaCwtE8IxRMuuX 0dnPzQsi0pQcl+5DTZQx4hBWWZEo7ay3zgnrv/+5pQ9plMWFmm8Wf6gN4 I9txvdIrPx0QnXYN73lwEtWCsq6bnLBRp7RzXfyVKm+hi/Ce+fZVx8g/D NhiKVb4Kl7In7aCi9ckx1jIos943xuQBjxhMev+vdgrhU99Sqo0x+Ezg9 w==; X-CSE-ConnectionGUID: Qncynjs3Q4GRzAdswZJZIQ== X-CSE-MsgGUID: 5PPmzsBRQTi2p2ePtivbew== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315149" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315149" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:09 -0700 X-CSE-ConnectionGUID: hX45CL3DQRakdC0bjKpBRw== X-CSE-MsgGUID: 3STxsx5vQ1Kov0bs7Efkqg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478203" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:07 -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 V3 03/16] i3c: mipi-i3c-hci: Prevent DMA enqueue while ring is aborting or in error Date: Mon, 4 May 2026 14:33:39 +0300 Message-ID: <20260504113352.38490-4-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 4cd32e3afa7b..314635e6e190 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 9CE813BE623 for ; Mon, 4 May 2026 11:34:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894454; cv=none; b=qELpR8OaBU3Yzs3uRR72YlvxqemYa50RkA97ksDvlhmcP/Atfk7Du6iY+HJ48FswiwEfqO+lHszFLPWH1vGeBLVW/MRAg5fcyOdwSv9Oi5gnRyfS5VOrikIcXQw+dvHJj/7QQNs/fN5J0HVWZUyBr6Qn8alQH5jxyOwwrstiGLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894454; c=relaxed/simple; bh=rOnIi5Au/er0JAR2gXsjbHXOLsZxgafGwGrpu94iBhA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DtBKKsEbkQ1qpSVRKB8tYNWLibQHbuVmDLlU4l7cE46+uZ7kq82Rw8svl6jPLhjo/6h+l130dR+cp9kQ7v2ua4pilM6crFcScQ3ZHv16QhQ7YIEFOPa5mh52vhl/+X9q7SV3L05I7SZ8KYISdi10EvsNAeMQlFl3e5CumLFng5A= 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=jzLk1PLS; arc=none smtp.client-ip=192.198.163.13 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="jzLk1PLS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894451; x=1809430451; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rOnIi5Au/er0JAR2gXsjbHXOLsZxgafGwGrpu94iBhA=; b=jzLk1PLSOIMdfTuSCjHMbFdV8zP3aRlSdBrBTFpogadduFQVbXpY3BWd 8VVCJHDT7Ki0SbFPUHPIaA3gQ5vVRLlapXi5LEw7k72p1sH9RLvJ4ahID jlh2kGcST50gtDdMWwqBnWeZpMcLKg+lxi7/RRROS6dsXkdXtvAIYvsu6 VPM2+wH0uKYgt2PCafvAhJcbxOLlLi7SG1y/AJURjIdw3pghG+Cane6YU v5sSa3Qa9CSKmK6pA24VICfAKgo/PRW+Y+/oC1T0oVEin+nsIqRuhOCMp dIwkMH/1VH/tq4+ZMLtBt5EUURlh0LS3nXAyjdfmr5N9qe6GEWftbiq/u g==; X-CSE-ConnectionGUID: zNt/Lmv9QWypV80gK5noRw== X-CSE-MsgGUID: SagiPQhgQr+LA17/Z9Ji8Q== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315153" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315153" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:10 -0700 X-CSE-ConnectionGUID: hkqgU0VLSiGFTF+qCKBpGg== X-CSE-MsgGUID: ty15N4aNQCKe3IojAWGpWg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478211" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:09 -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 V3 04/16] i3c: mipi-i3c-hci: Wait for DMA ring restart to complete Date: Mon, 4 May 2026 14:33:40 +0300 Message-ID: <20260504113352.38490-5-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 314635e6e190..28614fdbf558 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 76B523B8D7E for ; Mon, 4 May 2026 11:34:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894454; cv=none; b=Sd0LZrGNKG3BXXgQkc2+ZqHYmTZagS/rs6rmwLQx3cbmZWtPLXPP4RQhaW5M3X5jMJprG/z6dEU5gnCk02IieSbszYuz6rnGC3PgK1pv7Ea8igDLFWoBKekAa0GjeQVX0raXZv/idLR3/lywEaTkaWvbOYL3p2Fd++hD+AaHqHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894454; c=relaxed/simple; bh=iN2shRNkaK73UGBWmJekGQhMx/1LLB+5eDkZTDYKB9E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=he5L1jmT22P8V9QDjSdyd3IiemikoyQiglUeop372cGIXONibcv1s9ffgeJeSV5KvmA2f6MYbEj2jEXa4p/wUfNL6OAFH/sXvIPNm0bvr7psJE1GxftILB1z4irWhcunkMOTGXN5zNErP6lMsEu8gzLJ18y9IxYLqLdYdXRJ3X0= 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=arWQYVCv; arc=none smtp.client-ip=192.198.163.13 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="arWQYVCv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894452; x=1809430452; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iN2shRNkaK73UGBWmJekGQhMx/1LLB+5eDkZTDYKB9E=; b=arWQYVCv1agSxQrpI7qLFQe5mGK5Uq9U7upVji1CxfCoG5QfSzEwI3ua g7oR6VrUkwMtLYdG44XF0c2S321AMT5lf2kZXnzVhv4WeMhUVaMdgCBac OB+wkgj9xHbhkXBRINxYpBBKyKmdlpNjp78vqcMomZleeytflqNkp96bZ fP4IkhnNY7iiW0Xs8hRcmmnlN6imQ5g35tiAILze9YaB5/8VVvtK/JHsk nkBPZ6KuHIgcoRqBZidiLg53qlxdDyInPuEd8D9o4sfMsdttOO5Cs2gP5 vCileT5aKL2quY4SsMUx5lnQ7NKxTjwpw4chbfZgIa09+5k9NfLOVc6T+ g==; X-CSE-ConnectionGUID: Cxi61ACET0yR0aCsjlc75w== X-CSE-MsgGUID: L5Bhi7omQ8SFntgvaWRbsg== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315162" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315162" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:12 -0700 X-CSE-ConnectionGUID: F65BLUX5TNuHr+OZwqy18A== X-CSE-MsgGUID: wHuAfmDmShmVfb+YCEU3+A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478222" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:10 -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 V3 05/16] i3c: mipi-i3c-hci: Move hci_dma_xfer_done() definition Date: Mon, 4 May 2026 14:33:41 +0300 Message-ID: <20260504113352.38490-6-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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: 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 28614fdbf558..c9852b85d6b0 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 6BE6A3B9600 for ; Mon, 4 May 2026 11:34:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894455; cv=none; b=qHWVVdE1WScGnl22dhyTKmUXD5XuBKK362unsdeGQzx6Jvu4W902P3roUQCyC7aHGwkgNN/UP8wPE8nkg3v/EjzTaK7axxuXZCaf3xyu0+hvyhHKAsxgLTvHzgcQrLNoTA9a3us28R6f/oe/bR4N0h4kdsBmlbGlC7As54RlRUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894455; c=relaxed/simple; bh=IzW18hxU6ryJbCtoN9ZyjWymDMsq+JGKhx2UL831gxk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZNN4lzjZ6To/nNNTH7DNHElrCKSQcdZ8b2KsDfZf95ejWg5J22U2dnWGmGE3TXCYy3bPlyjw9WLwlthybN1kPtAjzUNT0dyw4dE18QQaXHAlagD6A0xesdnASl6knyLFVTOEYgIC206lldGMVXmv6l1PecRtxCPbs+HmFndrSVs= 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=EM1gb7gs; arc=none smtp.client-ip=192.198.163.13 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="EM1gb7gs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894454; x=1809430454; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IzW18hxU6ryJbCtoN9ZyjWymDMsq+JGKhx2UL831gxk=; b=EM1gb7gsz4fHNMFrGB5kuITee/CCl6u4IAMsTCleoXF7ktNXemHZ0gNz xvX+/0TJSTF+K/45u0WQkmf+IrrApbU8UGlcE523F2th2j/5BFQzCRPq9 U/GhF4RBBhC8mawq3HVLeu4RwcjzFRNhe5V1OfiF3E9AnqiLqegh0KhiE ZcxBSv0MqGt/upUSePNpr9aMyz4YgMRgxLD2xYeQMTUzw9Dz2qXWK7XpB Jhk5ugKYavOzYBaIt9AUrEDGjVA0AZHnTgt/P2R73gIoNijswyRYLfKlZ 2rN08mLFlvH8/m7SzEgmiUghMds5llCw1eI0LxGa6j88zLCh7MhkLiSFh A==; X-CSE-ConnectionGUID: zCzDqg12TlmlZrZWMfEXwg== X-CSE-MsgGUID: q9qgQLFPREOtRgsMai/PZw== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315166" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315166" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:14 -0700 X-CSE-ConnectionGUID: cye4dEbVQ7iZxk2l5vvWng== X-CSE-MsgGUID: +YaKoq6jReKxuoi+Z62SUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478237" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:12 -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 V3 06/16] i3c: mipi-i3c-hci: Call hci_dma_xfer_done() from dequeue path Date: Mon, 4 May 2026 14:33:42 +0300 Message-ID: <20260504113352.38490-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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: 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 c9852b85d6b0..28e4d38f55d3 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 F34003BED5F for ; Mon, 4 May 2026 11:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894460; cv=none; b=C2HmL07fcHWtT++RmP6LACxUVaHOgllPkmE1AkvHxzTdk/vm9JE8tp45N3JQXuAQX4MWG38jCzwygFP6NhapAWGfgd9NPLlrASPHOtMWJ/7yKuLPH3yAHdgH2giigXRO3xf2OZn0D9X5Vu7tVdvgHerb8QYzzskLDN1re71cTzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894460; c=relaxed/simple; bh=ziNVxdUbaASwghi8AIhL9hLaXeTgfUuYFZaqap0QkWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QNXoNhnQAeKh+U2ipX73bvPXmbZvn8mAOtNtzK/dJaTwoTENJzB/kzosioyfOnkVCgyVVOA0JLRqUhAypO8r9N9740nK8td6TXLmM9hu76puqHNpF9ushntFQJD8rf1AF40Bqcuj2PdNDj+cd5CQEMJ1IUH6Jwpbqm4FKspgkj4= 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=Hop2bztS; arc=none smtp.client-ip=192.198.163.13 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="Hop2bztS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894456; x=1809430456; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ziNVxdUbaASwghi8AIhL9hLaXeTgfUuYFZaqap0QkWg=; b=Hop2bztSH/NwbqDEPEUfYaRzgiKB7nOcS+IgFFohrBwDvzZ3Hk1zotIl lTkxOlg7Yxbpndb98JsxiDacstclcmo+yvE3uKd5xSR6j/LRGB1BSICIx mC08p1rm2l2/+5ePhrcc6bkUwRWM1mEsvobFDzKU4rcsFe3v+qhwSRPna S3rwoe4vkszxoCVKW4t2gg4dB69QTkNFhkmZ3P63Db8mKjmuaoBBY2Qmf /dMqpvRzC9iMWbhUlvoKyHuFNUjL5LpkRHFE7HE8/I2bzKRNauJwoM1AI hxvTwRg6Xa6gmahQYwuwVNrwfRK3BuIrxhXrfCI0KfoxP29qwijAjuOsJ A==; X-CSE-ConnectionGUID: dUOoiIrmTGGhAxV3dTvJ7g== X-CSE-MsgGUID: Ht5xqsG3QO+eJynioVfUqg== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315171" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315171" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:16 -0700 X-CSE-ConnectionGUID: w0vSKyivQFiKopr4EXu1PA== X-CSE-MsgGUID: W2aXWlvIRcCmruNiEujnoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478249" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:14 -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 V3 07/16] i3c: mipi-i3c-hci: Complete transfer lists immediately on error Date: Mon, 4 May 2026 14:33:43 +0300 Message-ID: <20260504113352.38490-8-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 28e4d38f55d3..899fdf6555a8 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 AD5F73BED6E for ; Mon, 4 May 2026 11:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894461; cv=none; b=s8zi8lNcWoGm8zsyaV/nniS3aa/9LVfXVHW92KmCTv7wrZkZdEQac6fFGlZNBXdo+sz9wiYC0vXGIY6SStYfzvn1Ees3+C6PJg3j2xGgcWZiGyAdbU7THNt5mYVlV3qRd0ziE1pAfmlDACGszKnmcpgmmjGVncVJYYz1XzcbPdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894461; c=relaxed/simple; bh=mTzeDX/vaawzq5dQWkCtrOafbvlVzBe74prFohLgREk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MHE/sYVmQX1Xm3witA3iCEikmyrDQwd3he19XCIO0Zp2MpoH6whRE6J/CY9IQzOGoBjixxX1Leji2TfpQ7TOzmFiSRTQwWH1R3+v38L+syWBbeC62ZDQvrTRPANnxMflHqK9Qm9EgioiydmgAKDQhG4bi7UetX21Dogvwx6zbDQ= 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=jefatEtC; arc=none smtp.client-ip=192.198.163.13 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="jefatEtC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894458; x=1809430458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mTzeDX/vaawzq5dQWkCtrOafbvlVzBe74prFohLgREk=; b=jefatEtCZl4vTOE0UI/8miIWYBXRJWkMcm+iJB56Rxg+Eft8zQ9cfOUX aE1G9Lpr7vjqgw0/uIqbokC0XMHPKJTcgj1h6zQAeEICB7xyQl4CghPS3 veaTl4lvYFjk3BzUUH3ixBJX1m3N//pNhBXKVGJ97r0ZeGGlGiIJvxw5c o5rW1CDZrdIHWODgh4OtnfrnATc1wEcQDAH3fM9A0Y4KaEv8wBKSQu2Lb Jd7fgBXIgZob06jEcyDGOvy0ZQck7GQ1z8i8IQgrqesiXLqNBnSlaDYgR lAaElZ1oEajwCBqXYQuVUOr1lQ0smBfFzL+3cjND86yHON57C+6JfqKWa A==; X-CSE-ConnectionGUID: rETJCwZESCuz2oGEkebB7w== X-CSE-MsgGUID: e7KhqzYnRJmLAgr70B2lbA== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315185" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315185" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:18 -0700 X-CSE-ConnectionGUID: yIEtuRmFS+OV9eskvkts7w== X-CSE-MsgGUID: jl9eTMPKTnitPjBmhL1hEg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478257" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:16 -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 V3 08/16] i3c: mipi-i3c-hci: Avoid restarting DMA ring after aborting wrong transfer Date: Mon, 4 May 2026 14:33:44 +0300 Message-ID: <20260504113352.38490-9-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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: 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 899fdf6555a8..268f54b32101 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 B36E13BE627 for ; Mon, 4 May 2026 11:34:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894462; cv=none; b=c0QdY7xFQjQErGvqiyWRJKM+V7azNBgIgfnQru1Za0xTLEJxJLzBuIBqG/+mGPMdoyxVAA6vZ0/SFV30FkqvdziNqOV9qjQ2OR0WPATF6TiAKGqoGpefpwqlf1ABbEZaM3Ll0svbOJ1RT2HRybwqIddQ5i1K3kF/VWz8O0wR8F8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894462; c=relaxed/simple; bh=wGhnE9vCekc+VegggAQI+J8l9oPFvKZCRqMb1M0F6Aw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NNNB9kfsl8po+IVyrCrPyP/vL/Qeet0B1iD1kpV0wVym6WXzNytHazETgwUe8XfV+IAb6vKYes90bM5dzvFVxICtudd6BgHPz0mtBED5R0Nt5C+2adBQsgCml2dDdJ8BDvnl+dvDaplgWQGj8cocV/6x59vYxnHia/zg6gryZ0g= 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=hZc7rRbW; arc=none smtp.client-ip=192.198.163.13 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="hZc7rRbW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894460; x=1809430460; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wGhnE9vCekc+VegggAQI+J8l9oPFvKZCRqMb1M0F6Aw=; b=hZc7rRbW2dbrMMY/frk5a5rS31qqLB3kAjHUJQRdbBP2QJESQKjGjOkk l1Fwz8n8tNz59/MCE04K/nD512RzK3d13LxJnAoLBQ/ggY8WyrpIRLKbz QUnzrNlxOpr67j7IVwrMv4+toFWWufEwlqJHANVfAH4ttemaBUS8ah0mz lAx01+G7s+f9TWTlVFKezM5RfiQPmqIl8lzDszcy6cU6eQTsPA8kyQXlG PbUIANP7ZZZ5MpjuOUkUU3/FI8yYhABA11zLzG7Bgfna7tFc5lHn1gcDz FdVwZiWGd2NTU6S+4K8jYaWC8yOga3quj3Ya5+0ug7+IoBPdLiba5piSB w==; X-CSE-ConnectionGUID: /r20wJ1dTx+ABsd6hKtXwQ== X-CSE-MsgGUID: Pe7OJnBSTHiys+THSnSPeA== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315210" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315210" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:19 -0700 X-CSE-ConnectionGUID: bo+0hXPwRl+O81SqtKv/Pw== X-CSE-MsgGUID: XOW0gjZYQiOptIfd1KL3gA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478266" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:18 -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 V3 09/16] i3c: mipi-i3c-hci: Add DMA ring abort/reset quirk for Intel controllers Date: Mon, 4 May 2026 14:33:45 +0300 Message-ID: <20260504113352.38490-10-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 V2 and V3: None drivers/i3c/master/mipi-i3c-hci/core.c | 15 ++++++++++++++- drivers/i3c/master/mipi-i3c-hci/dma.c | 9 +++++++++ drivers/i3c/master/mipi-i3c-hci/hci.h | 2 ++ 3 files changed, 25 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 268f54b32101..699c6d523eed 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_requires_pio_reset_quirk(struct i3c_hci *hci, st= ruct hci_rh_data *rh) +{ + 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); +} + static void hci_dma_unblock_enqueue(struct i3c_hci *hci) { if (hci->enqueue_blocked) { @@ -638,6 +645,8 @@ static bool hci_dma_dequeue_xfer(struct i3c_hci *hci, } } =20 + hci_dma_abort_requires_pio_reset_quirk(hci, rh); + 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 483133B9600 for ; Mon, 4 May 2026 11:34:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894463; cv=none; b=Dk4vT4Jq4hJw/lcI1Nm047drxxX1xJdrtlmo+3tHkcsLdWsuulBLK+V++W/U+jbXw7EK+phqUfe6phgAdsXstcf3DxjZSTCVTPCQnLs0wdUbnkC2DYP5QyEPMe2lhgaSihDUwKbkLAkFBjJcWNNowgE4gRx399np41JLmT9zqmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894463; c=relaxed/simple; bh=f86i4XDsGlrKjm0Br2d3/oiMsI6uFn13A5Ha901yOGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NbS/14UNnS4laX+tZ1x+a8KTqvD8JKCjzrzoQhukH7MHWvJ1T5d656EihJ36xAbdTrB/W9HSaRXZWKYTsAXYtllLC0XfZS25CtjZ9o4vJLHNx7hrKZByKg80sbxkU9iz8GzUTYNUl/hWA9iy1dG2hxmu9Zqgq9YW9hZ0SrmZfNE= 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=hl+1tkJn; arc=none smtp.client-ip=192.198.163.13 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="hl+1tkJn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894461; x=1809430461; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f86i4XDsGlrKjm0Br2d3/oiMsI6uFn13A5Ha901yOGw=; b=hl+1tkJn5Vvo6IXvU7sAQ49Lc3lwr66G8cQNug20QWYLmesQy7QDzeyR XnCGZdhdGBlsZLSMUHojZnOFfCxMLupG9umMJLOd09CqKjHIk6vb22j2p OBzt3/YFzQ2eWz+RHbcTQTTPDG5kMnFSrEuCbyblJguQWm2Y7qQDOfcvQ /arAil/q6lR2i7Vp3JaBdiuq52IKQu9bbBfeuJGq2x9s+M9WQV5m8SuMb ezPU/7hxHS7m+nwPQzFRbyTSsg1A2CwqBHQDG/ZLUapZG8o5+IHU20f6G sLLUAhf3RocFuUgDakHPdu5/QHt5V1LZLvLnoi5hxo1Crd1opV837JF2k A==; X-CSE-ConnectionGUID: 3NQkPgv8QN2yMjVg9Gsmww== X-CSE-MsgGUID: LdEXf+YoR8O6sMMFpH8g2Q== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315215" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315215" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:21 -0700 X-CSE-ConnectionGUID: /MlSrEC4SAGno5/F0ihhAA== X-CSE-MsgGUID: lxqSgeOAQSyJ7R23HxMF5w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478277" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:19 -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 V3 10/16] i3c: mipi-i3c-hci: Add DMA ring abort quirk for Intel controllers Date: Mon, 4 May 2026 14:33:46 +0300 Message-ID: <20260504113352.38490-11-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 V2 and V3: None drivers/i3c/master/mipi-i3c-hci/core.c | 18 +++++++++++++++-- drivers/i3c/master/mipi-i3c-hci/dma.c | 27 +++++++++++++++++++++++--- drivers/i3c/master/mipi-i3c-hci/hci.h | 2 ++ 3 files changed, 42 insertions(+), 5 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 699c6d523eed..41bbd912df7f 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -597,6 +597,29 @@ 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 bool hci_dma_requires_hc_abort_quirk(struct i3c_hci *hci, struct hc= i_rh_data *rh) +{ + if (!(hci->quirks & HCI_QUIRK_DMA_REQUIRES_HC_ABORT)) + return false; + + 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); + + return true; +} + +static void hci_dma_abort(struct i3c_hci *hci, struct hci_rh_data *rh) +{ + if (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); +} + static void hci_dma_abort_requires_pio_reset_quirk(struct i3c_hci *hci, st= ruct hci_rh_data *rh) { if ((hci->quirks & HCI_QUIRK_DMA_ABORT_REQUIRES_PIO_RESET) && @@ -630,9 +653,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(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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 8DB683B8D7E for ; Mon, 4 May 2026 11:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894465; cv=none; b=I9ot6ctfpVfYreLXhU9YLsc1z6NBjonTj35AMbnv+nUwQ5DuTrvfT3IBWcztY1BGfttXlhZp+MPnDLYqRchu9oGmvOJ884aaRG4J9tkFB/TCGVXdfZDfpSeotw5HpZj+yWEc0SgGSDHJCDrZe8jMwuWAehuOuOjFxjdp5zRc1ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894465; c=relaxed/simple; bh=dVsKZXcxZ5BtGeLdH16h9e8zvXX13Alg2ikK2Z0Ln8M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y0LtIX8JUnykgzhLioVxnsQHp9O/3vQba6VwumMbrTLxlUOP9Zgkz/UdsCuQL33F0YYaC0COf6tuPaRyuYn+uRMTjScjP5Y2zKMXobKthIBWJSMYmTto2YaXEyucexrDvu/NBtARt33tPCuX3EfFfGMY534I7zJlTBXknkbXUbk= 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=YcNmJuJi; arc=none smtp.client-ip=192.198.163.13 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="YcNmJuJi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894464; x=1809430464; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dVsKZXcxZ5BtGeLdH16h9e8zvXX13Alg2ikK2Z0Ln8M=; b=YcNmJuJinBMqbMaR0fvvsyWGqSdVXRpSa02J+zqcJlVECWZmJTpdKhNh bRjSVKVLITNiP0kcKgiKr0eZpn/j7XIMy2/wEurVTJDTEUevHxUEBQoAK Q3MU3/F+4oDB6XgSRRDv9BHVDjk0FI+ZGuv5AW2+pKakF5qu70raIupgE XmI1WKgpzW7Bijzwwdna5C6sMtl6css6HF9tfCbknkMiy38RdmWIz5k1A bB8JQwlBzT/CIRJ2Enc5MWkPemFNiJmqnpdt7OgZCGqG/8SQqLvoR/Hzm dVYfsS+ir9i2fLiiaI5wzWD3KkydGrB/Fg9Z+bVwVu27i0CZK3Dj811Bn g==; X-CSE-ConnectionGUID: kbDKJXThT26EynEN0Yt5Ag== X-CSE-MsgGUID: 4FlJim5USlq352/uwXMfqQ== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315220" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315220" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:23 -0700 X-CSE-ConnectionGUID: KebiJ14yQiOgqiZV/kA60w== X-CSE-MsgGUID: 6vc9fWzsTrm9BG98BaH8Kw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478284" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:21 -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 V3 11/16] i3c: mipi-i3c-hci: Factor out reset-and-restore helper Date: Mon, 4 May 2026 14:33:47 +0300 Message-ID: <20260504113352.38490-12-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 048463BE156 for ; Mon, 4 May 2026 11:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894469; cv=none; b=oYF6emyXQrOiu3RZIoGlzXExQWHU8LIYtKOGDIjPuInXFLxvIkf3qvITmZ5nkIXmBkb4IX0BT9VQODrUY/ork0P4O21lfDiWohVpMIPLtjQyt+d78x/IbDsSOb96apJN9QK8FTMLqQvAczZZVvPvMljROe1eEFPcDBIhnPyak14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894469; c=relaxed/simple; bh=ZZSZuEZZIkYK5l+87E82HMycK6FJWco0QGBxgxkqM28=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jHr3Vqcin+efEX8+6VPxHSXCV08U4/XLp45dbuyE9Iml54SYArUJaoj/vHeInwEonRCOdS3oCFkRfb4cTht5iIws49uW+H3b/6K15296s5nlZPMeOuzktslK+IN08gorHkO681buVo/gn3IY8EcBGvUdPEKzV+8jdz8vzWuZaKw= 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=EmYPHQYR; arc=none smtp.client-ip=192.198.163.13 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="EmYPHQYR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894465; x=1809430465; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZZSZuEZZIkYK5l+87E82HMycK6FJWco0QGBxgxkqM28=; b=EmYPHQYR7w4KQm/LJcUFbParzaLWodNCLPgUvencTZ8gi4eSE4F/94wG qiclYlOAVPS4RKO6B5mduYiBW38CnxWYcILUAIKkmUDTFYvM8/+tcZWYy atSbxXwFkStzbC1YXboVQ6UBRnzsTilRtP3vFEXX0F/Dfq3NQ16ufExyw 3NUSHaSBpBJINoj4/T6QZP5yf8sqnguOxCbUDaTGqz/XpwqQB7WzaolEg pbWRCUTe6NZ17dxzzkftKSBzDyFftweEugEBgxf5kEyrjDznI6P4I4OFd REdT9Q/Dpb2Yf4ioyCK/9k6Xxl6Z34iypEdf82o86gOMPWLyLwqybA73u w==; X-CSE-ConnectionGUID: yWoowjMzSlCecQhtZES8BQ== X-CSE-MsgGUID: 4vJcc1e9QcSBCkdHB/0JVQ== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315224" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315224" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:25 -0700 X-CSE-ConnectionGUID: 47or7PDnSGmbgvlCA4zaLg== X-CSE-MsgGUID: oOun2pbnTX+fwzVgR7f/tw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478296" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:23 -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 V3 12/16] i3c: mipi-i3c-hci: Add DMA-mode recovery for internal controller errors Date: Mon, 4 May 2026 14:33:48 +0300 Message-ID: <20260504113352.38490-13-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 41bbd912df7f..376062c0fcbf 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)) @@ -635,6 +642,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) { @@ -650,6 +711,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 */ @@ -657,12 +729,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 @@ -670,6 +738,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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 1A3A13C0621 for ; Mon, 4 May 2026 11:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894471; cv=none; b=lH5r1zosIEr9W+I1Pq6Dqq5rjzrQgjWo9cF19ZKP9XwPPqMb1utmQYQuIWymw4hqSLP/zEq9KyQNLwTa4Hc5rRiTT2U81NClr/Xo79y0ijFgByAJA0/lM2VNydu7LFdNu/f6H7vQofzPATmZwx6lB3wULYdQJkslYy3gBs5qDhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894471; c=relaxed/simple; bh=dSs/OjFxjj0Jz+Gc4GvWeID34N7C3MTiYL0AhV70tf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UFbZ9v//uvdh5EQKORt0HrxHK5CouQRibF9RMRFbzRMORYbsiHoTA8lr+o1hRnjiIZuDHMZANDrzSbbLp/wfmVGrE10xlAfLGTAS/ObNAjb8M/Ok9xktzHLiPSm5uYO+hwFr1aiw4D9Kz2rVefkNuoYyNSVtMzfF+BW4o1TMpwc= 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=mC+shWsg; arc=none smtp.client-ip=192.198.163.13 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="mC+shWsg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894467; x=1809430467; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dSs/OjFxjj0Jz+Gc4GvWeID34N7C3MTiYL0AhV70tf0=; b=mC+shWsgX2IGktunatKXJyNm8bUeVXEDXrcTo4fGnGHIBPFtRjrQpYae 1xYbUs3X9qFgbs6f7AsUWIzEsXTkh72LaDER0YmZT5NUBbwL2CAYHLlAn tIoLpOSXgOfYhcAozShpvAoaBHw+qDG99nC3oljpe1d4/YOkdThwhIigf +Gu2SEDe8cz+eXdN1g6/tbBJ33UacKXXz8QGtdvgH9IcXjTV/h7T+RgtM xXVDXQbJefGyEJyn+tL0n2PqKt/ifXUfVcQOtl5EZ3XA14RaT4u/OZcZE NCO0UubCg5EbXd6MZE4WgpomrkMxfcij6WQclqsk2h28QNKNbxQBCSY86 w==; X-CSE-ConnectionGUID: qJzII3cZQLyl5k7sZ3Pnkw== X-CSE-MsgGUID: A6hvbhuzT+qYZGt3FOKbTQ== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315256" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315256" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:26 -0700 X-CSE-ConnectionGUID: NN/uMxxgS3CPdUWcI9XPpA== X-CSE-MsgGUID: OjZylFnrTk+9T7wjTk4sRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478306" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:25 -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 V3 13/16] i3c: mipi-i3c-hci: Wait for NoOp commands to complete Date: Mon, 4 May 2026 14:33:49 +0300 Message-ID: <20260504113352.38490-14-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 376062c0fcbf..90fa621c9d56 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -696,11 +696,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; @@ -708,7 +730,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) { /* @@ -765,11 +787,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; } @@ -801,6 +822,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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 AE05B3BF66E for ; Mon, 4 May 2026 11:34:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894473; cv=none; b=HFeGwri66UwHvxGaTS34KUfdIzQwwFlutxbCDVBq8R6P2M6t3P4yAJuRfqtAwrjXgRSKuBOTbt5seziD0huc5j/nlSMSSfUpYf285PHVV699hVAnu8qQOF7jr+/EWoe1JOGo/yKDc2auZYjuY05pPe0du1PnXIX96gRaxSiNx2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894473; c=relaxed/simple; bh=mHhmQ3j/Sr7TdwoSpfXodUmINy6WgkAlXwFNdu1DWk4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N62/ngs/b12tt9toJ5Z/Z5yjTMyJWOXqP35dTdk012JIYmHD33ALJ40CYFKtDTO13pQEEYOnq3oiI9575jUCAiPMW1SwkbR9ftMSyagNKbByDCHyzAhQYjurDcauPVBhWrP4vxeWHNMnTH34QsgNEm2DRBflvn5LXDzUUuzIeKQ= 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=PIrrMVDX; arc=none smtp.client-ip=192.198.163.13 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="PIrrMVDX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894470; x=1809430470; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mHhmQ3j/Sr7TdwoSpfXodUmINy6WgkAlXwFNdu1DWk4=; b=PIrrMVDXCLYnZRQA8BJIOz31w6Je9xiYV3Qu/5WbsagA0Betuc4PFuX8 shsAyIdQDH4f7i8BClv5PKdxPRqujwuWSRnHfH2hEWCreXOAqBsTJQw5a ztWZAqBJl3rLR03gnyrg5CDZohBxIQbHLVRCcynl30IJnNHSV2LQX+ek1 YFQyGjd51OITQgFaMMeAS+eTBbBrjdawk8zLH24YLnKuMRKmZT9gZt7uq Z7clJq0/OdiBOkHzKdVSJLeurmxErd1FYIDh8EsOvXP3j23MqXMi5PmHI Ge+KEmZ3C9tPtVjjtEJzpAoIUdjFzzs5z6234RrlrFyJFLWNq4Xkckcrm w==; X-CSE-ConnectionGUID: KJyMSaJ4RaCv5qJy69hClw== X-CSE-MsgGUID: lpeW0ORDTsyu6q4ywR9v5w== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315288" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315288" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:28 -0700 X-CSE-ConnectionGUID: ImkaXy50Q4WBzAJcjFRcuQ== X-CSE-MsgGUID: eYnDCwwySt2zi9ngmxElxw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478318" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:27 -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 V3 14/16] i3c: mipi-i3c-hci: Base timeouts on actual transfer start time Date: Mon, 4 May 2026 14:33:50 +0300 Message-ID: <20260504113352.38490-15-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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..2866d599612a 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_time; + } + /* 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 90fa621c9d56..6440302c63ca 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); @@ -818,6 +832,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..243d7a67f6f6 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_time; 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_time =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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 586B03BF679 for ; Mon, 4 May 2026 11:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894473; cv=none; b=g3svXzBxXu59QA/tFq+t3AHbt8O3qDbqBxPreS12JV9zqSXefn+hs+ZPCXDeqCVv0Z5EBU7FagAW36ImG3z+uRcz/V9evS27DFO1cplulahx+e/UZej8HhDsrk0+8HNmy4cSklySjPUU8/D9EIrcMGaJo5kxId4IKYI7yV3gSXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894473; c=relaxed/simple; bh=3fhwoOwBkgIJmMxuUMApk0MQ0at4iJ07yU50SQdd6PY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T97XRqE7joc0fSIFLCF2Qj+ocnimnzP7QStw0Q3q8ms63645Ebiq8ATpzl+o/xPqgadJE7zwHB/uZnDVnBDkyIQHtABPLlpapTrTn0gtP/UYj1fjGpZm7tusLbvq09hPtyVFA5nNoOEhkQFN0ErbRpe8UJlTqhCVFLwpe64V/8U= 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=kodGWBVd; arc=none smtp.client-ip=192.198.163.13 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="kodGWBVd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894470; x=1809430470; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3fhwoOwBkgIJmMxuUMApk0MQ0at4iJ07yU50SQdd6PY=; b=kodGWBVdhI8Kzg6N+i968lfpuW+yLiZM9Zl+g1ligW93cXE9W2ixGDUI 51J+G1gOoMHp3YHtbl21o/5VXN4VSQkJpxei2e/3wV1/kujHOwrCiXO22 I9GMWixiugiQsT/JBqVyCddEN7KVtAgNdVTNBvnpy0atgzPdkHnSMjTVf OWkz78YIXFJzWCivxAPuvP5aCQA+7SF/EkSY8WsD63u9Kwsu+Y0il6qDD +1ns4nGmmu3L8wmvbkHAvDLitqqQdPQoRU4kySU5g1/Rq42FwZdrQMfXd 7tT+IPwgZDiNWcG3QyHmP0+/lA0aQKZgZSsESBHReRcHJkmPjImEMON/W A==; X-CSE-ConnectionGUID: zTmXXNzwS6Om8kvJRCek6w== X-CSE-MsgGUID: q3neOTlFSmuK3b3k8QXQFw== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315293" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315293" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:30 -0700 X-CSE-ConnectionGUID: QFkkCzqZTjOVvrEnd9oyOA== X-CSE-MsgGUID: NTX9ODEtSc6kU3UQ4acWVQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478333" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:28 -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 V3 15/16] i3c: mipi-i3c-hci: Consolidate DMA ring allocation Date: Mon, 4 May 2026 14:33:51 +0300 Message-ID: <20260504113352.38490-16-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 | 24 +++++++++++------------- 1 file changed, 11 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 6440302c63ca..4029d4d9e784 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -186,14 +186,12 @@ static void hci_dma_free(void *data) for (int i =3D 0; i < rings->total; i++) { 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); + if (rh->xfer) { + size_t sz =3D round_up(rh->xfer_struct_sz * rh->xfer_entries, 4); + + sz +=3D rh->resp_struct_sz * rh->xfer_entries; + dma_free_coherent(rings->sysdev, sz, rh->xfer, rh->xfer_dma); + } kfree(rh->src_xfers); if (rh->ibi_status) dma_free_coherent(rings->sysdev, @@ -359,18 +357,18 @@ 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; =20 - rh->xfer =3D dma_alloc_coherent(rings->sysdev, xfers_sz, + rh->xfer =3D dma_alloc_coherent(rings->sysdev, xfers_sz + resps_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 Sun Jun 14 02:31:54 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 2B9EF3C140F for ; Mon, 4 May 2026 11:34:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894474; cv=none; b=DNZlG2B4j8i9rjfFbp0Dy5jFPxdKgdje07k3YDzIxxGmayJ91u2dQo1QH2TFKVq5GlweV/guzopBrxeXpnIqp1Oi7MS0HhEJg/04S16SPXP6niL2VHRBVB7gQbAkwyWtyBhZTGzbPf2NyLw1x3QbpyV+ifbk1E4NrirS82H8s14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777894474; c=relaxed/simple; bh=prMcaVJdpa2v2ahCOleV4GJ+fFGnc0wB+iTPX8a7A8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ucb2Ew7MAOASvQKuGckjXgXK+9xW0hAc2I5wcnm5SO75EpLzmhx/AiJFaNdLrnV+p8nMGF6VoWeysx72BAwne6xhy9/6wZFYq1ECZ8Sb62H/OskI87YC5N4gv4GBJ+MhilDClS/6gTYGzyVNLzQVS5YhEsJsJaZCSalFuwy2pDw= 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=Evx0V2Ok; arc=none smtp.client-ip=192.198.163.13 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="Evx0V2Ok" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777894472; x=1809430472; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=prMcaVJdpa2v2ahCOleV4GJ+fFGnc0wB+iTPX8a7A8I=; b=Evx0V2OkUC1Y6q3SuSotGyL6LUrNd6jp4faR0GvymTc9RGwK6dn6TuJj TgO2dlo7Ldc9a81SZoxD2gaBgqaoajOPADI6lbJgiF1R4EWDH3IYpqW5w PZKSL7SCFMw9catcpWffGH3LrrbuPezuOaI6kyo8ppUbzQfwzKwh5qzSg 8SWhIdqFFUG8HjLZbQPdlRxm+P/wm0mYlf3YaBnnE3avpdvO1TmnAshQL KIq/EhZ073vTW8BrRt3WEp4WTLxf55bHoLytyoF67EqNCCwtWkhDX2TDh sUD7WHbHpeJ4fpPWvag3fSYgneDi4EEzzUgE2g9CkKIZpJKhKgeZbb+Aw g==; X-CSE-ConnectionGUID: 87FtAAraQme1amv9lGHL7g== X-CSE-MsgGUID: haXth0pHSNiJ0lEcNxCSIw== X-IronPort-AV: E=McAfee;i="6800,10657,11775"; a="81315300" X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="81315300" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:32 -0700 X-CSE-ConnectionGUID: AI7RNkFtSre2SpVr7YgpYQ== X-CSE-MsgGUID: IPelCT5UTDKpHaBJKegKpw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,215,1770624000"; d="scan'208";a="240478345" Received: from hrotuna-mobl2.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.92]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2026 04:34:30 -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 V3 16/16] i3c: mipi-i3c-hci: Increase DMA transfer ring size to maximum Date: Mon, 4 May 2026 14:33:52 +0300 Message-ID: <20260504113352.38490-17-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260504113352.38490-1-adrian.hunter@intel.com> References: <20260504113352.38490-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 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 4029d4d9e784..9549d98add4b 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