From patchwork Thu Nov 9 13:37:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Nikula X-Patchwork-Id: 13451036 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C487DC4167D for ; Thu, 9 Nov 2023 13:38:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=w3SNTAdzRcKufsVLF6PqWiGeSKHiXMwPI+yWk07mx+o=; b=0bhV/kHL0ag42E LKD6H0hiZIKsJti5zZdAwXJ46RUBeVFAE1r751Vy0v5hOuaiP5v5aX5dgbud1RsX8ngjpB1Is4Q/e ZF7072L6BHpWIze9sTjP1RplaPTcArkQ/guStK2bUG8wDAAIAdIOe4VvWZikXDDaLfNYlsTVoW8zn Zuy7UO78Z+NiPSbtRp1DINBzveu7MfFTbL3zx444+ssrjymMKOvzVTEYDUHXL8dz6tcTVWkeg/XrS LsRu2RolrJDdSZpw5SQVEU4O/fz35I+Es1mVVR/nOttK26VdHV/Z9st/Se4pH6RAy1p7uuLSJD8Gt I6TypmC3QbXYm0/NV/gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r15Eu-006Oua-14; Thu, 09 Nov 2023 13:38:32 +0000 Received: from mgamail.intel.com ([192.198.163.8]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r15Eq-006OsE-02 for linux-i3c@lists.infradead.org; Thu, 09 Nov 2023 13:38:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699537108; x=1731073108; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/FZZtJ6+Hdv0BA3obePg6w7dckLey/G2RfAjB2DjZeg=; b=TXww1X3417ak89CwmS8Rk+8dSYNBg8sBu7PhLQQKvQGVtF16ixR9yzPZ gGjFi2nKBHkKNDZWFpbM0zaxCK0LPnT4IQGLg9H39GL12FUU490bBD2+j sVvpYztiIbJTzAPNIGWkhSJsyTfnmrlYS1jkpqh+uhrYA9FR4wyTlBUDH LrLFTXIlfe1OtfFc/jpkG303liYwr2hwUMhmAtEGi1YG+KzzcReSiQCUU 7jgtwJsnzZ2j8KxvW8OweTT/fN7MnJBmlWg2daY7DvSHgBYpSn5FSna/U rSS5zXaOyUS+QuKeagEFCNl6cVz7w7iLi/IP8Mp2tggmpn4l/BVmrt5HD w==; X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="2949353" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="2949353" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 05:38:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="907127730" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="907127730" Received: from display-mtlp-1.fi.intel.com (HELO mylly.fi.intel.com.) ([10.237.72.68]) by fmsmga001.fm.intel.com with ESMTP; 09 Nov 2023 05:38:22 -0800 From: Jarkko Nikula To: linux-i3c@lists.infradead.org Cc: Alexandre Belloni , Jarkko Nikula Subject: [PATCH 1/4] i3c: mipi-i3c-hci: Report NACK response from CCC command to core Date: Thu, 9 Nov 2023 15:37:05 +0200 Message-ID: <20231109133708.653950-2-jarkko.nikula@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109133708.653950-1-jarkko.nikula@linux.intel.com> References: <20231109133708.653950-1-jarkko.nikula@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231109_053828_060414_8327C6AE X-CRM114-Status: GOOD ( 13.17 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Currently probe of mipi-i3c-hci will fail if bus doesn't have any I3C devices connected. This happens when CCC commands that are sent during i3c_master_bus_init() are not ACKed by any device and controller responds with an error status set. The controller can detect NACK both during I3C address header transmission (broadcast address 0x7e is not ACKed) and when target device address or dynamic address assignment is NACKed. Former as error status 0x4: Address Header Error and latter as 0x5: NACK. Difference between those two NACK statuses were not described explicitly until MIPI I3C HCI Specification v1.1. Earlier versions share the same error status code though. Report both of those as I3C_ERROR_M2 to I3C core code. Signed-off-by: Jarkko Nikula --- drivers/i3c/master/mipi-i3c-hci/core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c index 1ae56a5699c6..8471a1fe1dad 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -245,7 +245,14 @@ static int i3c_hci_send_ccc_cmd(struct i3c_master_controller *m, if (ccc->rnw) ccc->dests[i - prefixed].payload.len = RESP_DATA_LENGTH(xfer[i].response); - if (RESP_STATUS(xfer[i].response) != RESP_SUCCESS) { + switch (RESP_STATUS(xfer[i].response)) { + case RESP_SUCCESS: + continue; + case RESP_ERR_ADDR_HEADER: + case RESP_ERR_NACK: + ccc->err = I3C_ERROR_M2; + fallthrough; + default: ret = -EIO; goto out; } From patchwork Thu Nov 9 13:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Nikula X-Patchwork-Id: 13451035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84417C4332F for ; Thu, 9 Nov 2023 13:38:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6Vp47sTGV99JHSTJPZZ07vMuw8ClisyWovBBIt60uTc=; b=s1dtgGm0B0zPFb tMazl4R4F1g+voOSYrh+fNXhS0P9fuo4xwCXVx1+faUQduTkn4anMer4QqVMXmb81zcZUuW+N5yHh cSUWtl0hk2YCKthG6Go42obyeb48wiqwjwpf+LxN7utjlIrdnU61MgulGDBA90okBuLqye4XCFg0c /lB0nAIKe7Q1znYGOJIj/v2nl56KybbcXWXwC5BYuUYV+VFwOfELUZUmnsb/Rd3Uh9y+IGf+zT0kR P08GgaUL8zBN3IrUxQGeCHsvgIAhkBez/I3EjTCesgjWesi7Nbw6XIydUvHHzlWt+K1uMM33m5DwN sOS5ZaJhvSFC2oZdok8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r15Er-006OtV-2y; Thu, 09 Nov 2023 13:38:29 +0000 Received: from mgamail.intel.com ([192.198.163.8]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r15Ep-006OsH-3B for linux-i3c@lists.infradead.org; Thu, 09 Nov 2023 13:38:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699537108; x=1731073108; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9SeSn39vA3HNnGtEdoNJbsGLYDoNtG8on5nyHfleAws=; b=AcTfxeyVsT5nnZaZm7VrAQiwTPhDwJjqOirfpeI2hizAQHDMKvRe4Bm0 1+WOY9fbPg/iz3utCQAnnAcOY5KmMxvURxOPVC3uiHR7khzXL/4frAQQj LBBlDM1TCLwVvCORNanVwwU4rtL/18iYBfSDxnJm2kuEI9kxlk367E89v /DiLOZ9ZzzoOQ++7W9p4Bkb12pKGvkqwa/LXL/AqD+usWSiU+T1zzNMNp OLyuRfphgHAXLD9zTKUOwnVxe0mn27Y0b1YicfP4e0u+Ik+cPK2Rfaocl H0bZUaWS9xWu+DnX5evp1XognftOKahIjKyksHdfnZVclepJwzGfa6fBl g==; X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="2949357" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="2949357" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 05:38:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="907127733" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="907127733" Received: from display-mtlp-1.fi.intel.com (HELO mylly.fi.intel.com.) ([10.237.72.68]) by fmsmga001.fm.intel.com with ESMTP; 09 Nov 2023 05:38:23 -0800 From: Jarkko Nikula To: linux-i3c@lists.infradead.org Cc: Alexandre Belloni , Jarkko Nikula Subject: [PATCH 2/4] i3c: mipi-i3c-hci: Do not overallocate transfers in hci_cmd_v1_daa() Date: Thu, 9 Nov 2023 15:37:06 +0200 Message-ID: <20231109133708.653950-3-jarkko.nikula@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109133708.653950-1-jarkko.nikula@linux.intel.com> References: <20231109133708.653950-1-jarkko.nikula@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231109_053828_043679_BBC34A7B X-CRM114-Status: GOOD ( 12.82 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Function hci_cmd_v1_daa() uses only single transfer at a time so no need to allocate two transfers and access can be simplified. Signed-off-by: Jarkko Nikula --- drivers/i3c/master/mipi-i3c-hci/cmd_v1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c b/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c index 2b2323aa6714..31f03cb22489 100644 --- a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c +++ b/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c @@ -298,7 +298,7 @@ static int hci_cmd_v1_daa(struct i3c_hci *hci) unsigned int dcr, bcr; DECLARE_COMPLETION_ONSTACK(done); - xfer = hci_alloc_xfer(2); + xfer = hci_alloc_xfer(1); if (!xfer) return -ENOMEM; @@ -339,12 +339,12 @@ static int hci_cmd_v1_daa(struct i3c_hci *hci) ret = -ETIME; break; } - if (RESP_STATUS(xfer[0].response) == RESP_ERR_NACK && + if (RESP_STATUS(xfer->response) == RESP_ERR_NACK && RESP_DATA_LENGTH(xfer->response) == 1) { ret = 0; /* no more devices to be assigned */ break; } - if (RESP_STATUS(xfer[0].response) != RESP_SUCCESS) { + if (RESP_STATUS(xfer->response) != RESP_SUCCESS) { ret = -EIO; break; } From patchwork Thu Nov 9 13:37:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Nikula X-Patchwork-Id: 13451037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A302C0018C for ; Thu, 9 Nov 2023 13:38:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Hd0D1u64rq0VptueV7VtFhd4jpWut5ZsbF1b+QJ5Fm8=; b=xF2zx6MNwvinc+ HcN6H0EcjB6rRk2w0WdmlafNzvyQp6SGCpMcd2GLfIRgDIpmNMbsXngPYirRw9yPSkhvkQw4dUwjQ rXpnK+N0wyeGCYu+Clgjykg6ZII0FQF+aMKZ23ehJNUAQA+o33sWe1Rb0r1LSM1Nl5n5yM/aPZxLB 1ABwrLajY5SUd43+qaaeM0Jn1LdirEiefO5Nd49DrjL0Eq5wD5zlyodX/Z3Esw4adVDi9qcyzndqy Ww/Pkf0UnkBs7YmyfPRY443+3gehkBWOiKbMZkwYZ5xajJzqjBX/E8gieTpjIu/BjRfIrSn8RYokh sRAjUb59gnCZjf7bm0hQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r15Eu-006Oux-32; Thu, 09 Nov 2023 13:38:32 +0000 Received: from mgamail.intel.com ([192.198.163.8]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r15Er-006OsH-1m for linux-i3c@lists.infradead.org; Thu, 09 Nov 2023 13:38:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699537109; x=1731073109; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c9eNuTC8Py04Wkg89wL/NdP4ycI2loadrD7to1ZGSZM=; b=EofJ3pvYvR2NKy47MIUb1UY1/qhoXiAJq8pqbu8NNGgRnGNs04GvxJdR 7lB9EWPI3yk3sjsmC5aMbTCdEYBqgVEOAFd6KlIMxV1H49B6KR6Eq0l7S f48nXPOl0XMA5YpB/Z7zXyqE51WWvrRRliWj5rIfQQ6Gvq7yppWbdSOAQ q9V8VJWtNk59XbVjDw1KNsgEAsZcMMUaKwhWZl/drFVnxcx0L3RdbCUw9 JHquVR+DaNTANHeEXbCDDXO40Izm2tpbVeEopjNnyebazUQHcGdx+XBrD bnALhOBNCfgIdJbiGGTWSUZiK48cSIMIUClkEdrtkWxXnfx1hKJcJZvfr A==; X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="2949363" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="2949363" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 05:38:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="907127737" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="907127737" Received: from display-mtlp-1.fi.intel.com (HELO mylly.fi.intel.com.) ([10.237.72.68]) by fmsmga001.fm.intel.com with ESMTP; 09 Nov 2023 05:38:25 -0800 From: Jarkko Nikula To: linux-i3c@lists.infradead.org Cc: Alexandre Belloni , Jarkko Nikula Subject: [PATCH 3/4] i3c: mipi-i3c-hci: Handle I3C address header error in hci_cmd_v1_daa() Date: Thu, 9 Nov 2023 15:37:07 +0200 Message-ID: <20231109133708.653950-4-jarkko.nikula@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109133708.653950-1-jarkko.nikula@linux.intel.com> References: <20231109133708.653950-1-jarkko.nikula@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231109_053829_601045_B96757DF X-CRM114-Status: GOOD ( 13.92 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Handle also I3C address header error response status as the end of DAA process in hci_cmd_v1_daa(). According to MIPI I3C HCI Specification v1.1 the NACK error during DAA process comes when the device does not accept the dynamic address. Currently code uses it for successful exit from the process and fails with any other error response. I'm unsure is this MIPI I3C HCI version specific difference or specification misunderstanding but on an early MIPI I3C HCI version compatible controller responds always with I3C address header error and not with NACK error when there is no device on the bus or no more devices participating to DAA process. Handle now both response statuses as the end of DAA. Signed-off-by: Jarkko Nikula --- drivers/i3c/master/mipi-i3c-hci/cmd_v1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c b/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c index 31f03cb22489..638b054d6c92 100644 --- a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c +++ b/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c @@ -339,7 +339,8 @@ static int hci_cmd_v1_daa(struct i3c_hci *hci) ret = -ETIME; break; } - if (RESP_STATUS(xfer->response) == RESP_ERR_NACK && + if ((RESP_STATUS(xfer->response) == RESP_ERR_ADDR_HEADER || + RESP_STATUS(xfer->response) == RESP_ERR_NACK) && RESP_DATA_LENGTH(xfer->response) == 1) { ret = 0; /* no more devices to be assigned */ break; From patchwork Thu Nov 9 13:37:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Nikula X-Patchwork-Id: 13451039 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8419EC04A92 for ; Thu, 9 Nov 2023 13:38:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zOuRAv2IeZwQW4ASMk1/75kM22+Kxwk6UG5G0sWlsAU=; b=2sj+WAxyOTSuV2 flI0EJygfUozvhEln+taFj10GnzQsamJNimP52yLA1Ts6b8S+8AyXoTSDYF5gewAcrKyQrm8+NHUk ao9ieLT3q2/Si2AnmOXlG9dON/Y+g3YBnmaqyEtWltJWtfp42y8OSLoPVESfadmMeafQmK5i3njTM sZr24mZulk8TIZK2QZ5NHOxfPXAc4OAUUaDWXDzP6jDxASovwJygExWkYB5HXdMzXd6iRYA3FFITP xNMf3sWxAHUH6KOH+uLreO2UP5YNmuc3sE3c3lA0sed0HyVoh+37rHAoI+mK3zb+FXU59y61THegb CSuj9G7fE/SBDpu8KrEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r15Ev-006OvB-0s; Thu, 09 Nov 2023 13:38:33 +0000 Received: from mgamail.intel.com ([192.198.163.8]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r15Es-006OsE-1m for linux-i3c@lists.infradead.org; Thu, 09 Nov 2023 13:38:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699537110; x=1731073110; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E8QBdLq/wWB6tcm1H21keeUBmqGI2K83omwnqarsYbc=; b=kxe1cRXVtKsY/Pe12CfQjcFnj/4HpbrSHWce38hQqJfz6ydsOT7FKzPC qskFsBCsKasKObi+VSrfVX9unkU9f0o2r24SSq2L066sp/Acj/ENKRRN6 ILVbRTqW7qNJnPSyukfJFOGk3E7V6iwAFv3u4a20MN8aLYkXhxnM5hexR zBPJWazi3TLdU9yarAdlT3t+629wHKlB+aTT+DbpNBIqhQg3OGp8ZoU0l DTelchM82ikVQTtGWoF9gqi3gv0fPKqmINB4EhPMrBrNOByDB9aCal5qm PheZnRTVPew6cVevU2fiWCOZWbdbmkWi4df8N5g5MQJWSZQv09lAoNHYX Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="2949367" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="2949367" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 05:38:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="907127740" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="907127740" Received: from display-mtlp-1.fi.intel.com (HELO mylly.fi.intel.com.) ([10.237.72.68]) by fmsmga001.fm.intel.com with ESMTP; 09 Nov 2023 05:38:26 -0800 From: Jarkko Nikula To: linux-i3c@lists.infradead.org Cc: Alexandre Belloni , Jarkko Nikula Subject: [PATCH 4/4] i3c: mipi-i3c-hci: Add DMA bounce buffer for private transfers Date: Thu, 9 Nov 2023 15:37:08 +0200 Message-ID: <20231109133708.653950-5-jarkko.nikula@linux.intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109133708.653950-1-jarkko.nikula@linux.intel.com> References: <20231109133708.653950-1-jarkko.nikula@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231109_053830_606371_4E903D88 X-CRM114-Status: GOOD ( 21.10 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Implement a local bounce buffer for private I3C SDR and I2C transfers when using DMA and the buffer attached to the transfer is not DMA safe. Otherwise the DMA transfer will fail and with following warning: [ 11.411059] i3c mipi-i3c-hci.0: rejecting DMA map of vmalloc memory [ 11.417313] WARNING: CPU: 3 PID: 357 at include/linux/dma-mapping.h:332 hci_dma_queue_xfer+0x2e2/0x300 [mipi_i3c_hci] Strictly speaking private I3C SDR transfers are expected to pass a DMA-able buffer. However I fear this requirement may easily be slipped or go unnoticed when I3C interface support is added into a existing device driver that use regmap API to read/write stack variables. For example this is the case with the commit 2660b0080bb2 ("iio: imu: st_lsm6dsx: add i3c basic support for LSM6DSO and LSM6DSR"). Buffer of an I2C message is not required to be DMA safe and the I2C core provides i2c_(get|put)_dma_safe_msg_buf() helpers for the host controllers that do DMA and that is also recommendation for the i2c_xfers() callback from the I3C core. However due to above I3C private transfers reason I decided to implement a bounce buffer for them and reuse the same code for the I2C transfers too. Since this driver is currently the only I3C host controller driver that can do DMA the implementation is done here and not in I3C core. Signed-off-by: Jarkko Nikula --- drivers/i3c/master/mipi-i3c-hci/core.c | 40 ++++++++++++++++++++++++++ drivers/i3c/master/mipi-i3c-hci/dma.c | 4 ++- drivers/i3c/master/mipi-i3c-hci/hci.h | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c index 8471a1fe1dad..d7e966a25583 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -276,6 +276,34 @@ static int i3c_hci_daa(struct i3c_master_controller *m) return hci->cmd->perform_daa(hci); } +static int i3c_hci_alloc_safe_xfer_buf(struct i3c_hci *hci, + struct hci_xfer *xfer) +{ + if (hci->io != &mipi_i3c_hci_dma || + xfer->data == NULL || !is_vmalloc_addr(xfer->data)) + return 0; + + if (xfer->rnw) + xfer->bounce_buf = kzalloc(xfer->data_len, GFP_KERNEL); + else + xfer->bounce_buf = kmemdup(xfer->data, + xfer->data_len, GFP_KERNEL); + + return xfer->bounce_buf == NULL ? -ENOMEM : 0; +} + +static void i3c_hci_free_safe_xfer_buf(struct i3c_hci *hci, + struct hci_xfer *xfer) +{ + if (hci->io != &mipi_i3c_hci_dma || xfer->bounce_buf == NULL) + return; + + if (xfer->rnw) + memcpy(xfer->data, xfer->bounce_buf, xfer->data_len); + + kfree(xfer->bounce_buf); +} + static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev, struct i3c_priv_xfer *i3c_xfers, int nxfers) @@ -309,6 +337,9 @@ static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev, } hci->cmd->prep_i3c_xfer(hci, dev, &xfer[i]); xfer[i].cmd_desc[0] |= CMD_0_ROC; + ret = i3c_hci_alloc_safe_xfer_buf(hci, &xfer[i]); + if (ret) + goto out; } last = i - 1; xfer[last].cmd_desc[0] |= CMD_0_TOC; @@ -332,6 +363,9 @@ static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev, } out: + for (i = 0; i < nxfers; i++) + i3c_hci_free_safe_xfer_buf(hci, &xfer[i]); + hci_free_xfer(xfer, nxfers); return ret; } @@ -357,6 +391,9 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev, xfer[i].rnw = i2c_xfers[i].flags & I2C_M_RD; hci->cmd->prep_i2c_xfer(hci, dev, &xfer[i]); xfer[i].cmd_desc[0] |= CMD_0_ROC; + ret = i3c_hci_alloc_safe_xfer_buf(hci, &xfer[i]); + if (ret) + goto out; } last = i - 1; xfer[last].cmd_desc[0] |= CMD_0_TOC; @@ -378,6 +415,9 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev, } out: + for (i = 0; i < nxfers; i++) + i3c_hci_free_safe_xfer_buf(hci, &xfer[i]); + hci_free_xfer(xfer, nxfers); return ret; } diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c index c805a8497319..4e01a95cc4d0 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -362,6 +362,7 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, struct hci_rh_data *rh; unsigned int i, ring, enqueue_ptr; u32 op1_val, op2_val; + void *buf; /* For now we only use ring 0 */ ring = 0; @@ -390,9 +391,10 @@ static int hci_dma_queue_xfer(struct i3c_hci *hci, /* 2nd and 3rd words of Data Buffer Descriptor Structure */ if (xfer->data) { + buf = xfer->bounce_buf ? xfer->bounce_buf : xfer->data; xfer->data_dma = dma_map_single(&hci->master.dev, - xfer->data, + buf, xfer->data_len, xfer->rnw ? DMA_FROM_DEVICE : diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mipi-i3c-hci/hci.h index f109923f6c3f..f94d95e024be 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -90,6 +90,7 @@ struct hci_xfer { struct { /* DMA specific */ dma_addr_t data_dma; + void *bounce_buf; int ring_number; int ring_entry; };