From patchwork Fri Mar 10 09:20:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Leonard_G=C3=B6hrs?= X-Patchwork-Id: 67303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp770577wrd; Fri, 10 Mar 2023 01:28:44 -0800 (PST) X-Google-Smtp-Source: AK7set/v7RZ/ZL3fBnFQFK3wW0QcKgP6uA8pDb/xO542U7qTxFi9Hbp08t1ELu4TlY+UbRoqlWWX X-Received: by 2002:a17:902:e842:b0:19e:4173:38b3 with SMTP id t2-20020a170902e84200b0019e417338b3mr32830217plg.46.1678440524567; Fri, 10 Mar 2023 01:28:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678440524; cv=none; d=google.com; s=arc-20160816; b=jEKSjvIBHHRc4i1f9cg2Tu/gSyBHGKLIV3rfHaOFpsvetgzIh/s2ptEt1XxM/5BNRg cyehn6K8JvJoj4ecRPmzy1pxfq/RQwV4mUAgzYRkdrSr1nYz6gqn6cmKwtBy3zM5gsTz Yz99lS/sWRUXSBJNxeUF/dl8vRQKu1eWGQjSEj8TUO7vbHJdiGpxQ+lwOzO7YQkphMuh IuhOXT7L9RtPYWHdzl82YCC3LEhB5zRlnmyE6Lp1MDXio0XyK+DM0Ode7+8SXo/C7uUF qBB19bhzewCxm4RlkYpOjzp//HM7+QRme4HwWOQmBIzU6yjjeC0mFVL7BwMhGWuvNrO2 DSSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0PKYsCWYuJYsCyJIt3HdC9izYFVwo/GG3EC1RaNXECk=; b=TEus6pPrMUBNLPkjNGrMJXHPUKV+M2w+rAgp215vnw3hYZl/NO+13BJu5zhoEGuYlI 5a6SewueeOAWurnCt8JIZNCfOE/mXqcpPB3hHLvFBTIgq/fLQ3XixDL34ILMKaRw4zyP S4uhLT2prSu36TUmlXjmOxzyCsucU3IYDQL0ZVDucXoH/FlGXjcZYUVTDS1zx+uZgssY SSjg49QlLdZrcTMCoeSLEqgcVJQxEt8qjnZnUhv7m8Hp7JyzlcDvpLc9+CM/5CG9bkmT AUMnC8GSrsba/7egpmRwgBKQ868VCVtkCr623R6bIRMc94mNrMlNu44Sce3TRTXyp9pM HO9Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p4-20020a170902e74400b0019e29ce6975si1863082plf.202.2023.03.10.01.28.32; Fri, 10 Mar 2023 01:28:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230287AbjCJJ0S (ORCPT + 99 others); Fri, 10 Mar 2023 04:26:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230206AbjCJJ0C (ORCPT ); Fri, 10 Mar 2023 04:26:02 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1F3711567E for ; Fri, 10 Mar 2023 01:21:57 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1paYwH-0002ig-3D; Fri, 10 Mar 2023 10:21:25 +0100 Received: from [2a0a:edc0:0:1101:1d::39] (helo=dude03.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1paYwG-0038yg-Bj; Fri, 10 Mar 2023 10:21:24 +0100 Received: from lgo by dude03.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1paYwF-004DqG-G4; Fri, 10 Mar 2023 10:21:23 +0100 From: =?utf-8?q?Leonard_G=C3=B6hrs?= To: Mark Brown Cc: kernel@pengutronix.de, =?utf-8?q?Leonard_G=C3=B6hrs?= , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/2] spi: core: add spi_split_transfers_maxwords Date: Fri, 10 Mar 2023 10:20:52 +0100 Message-Id: <20230310092053.1006459-1-l.goehrs@pengutronix.de> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: lgo@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759972451562095877?= X-GMAIL-MSGID: =?utf-8?q?1759972451562095877?= Add spi_split_transfers_maxwords() function that splits spi_transfers transparently into multiple transfers that are below a given number of SPI words. This function reuses most of its code from spi_split_transfers_maxsize() and for transfers with eight or less bits per word actually behaves the same. Signed-off-by: Leonard Göhrs --- drivers/spi/spi.c | 49 +++++++++++++++++++++++++++++++++++++++++ include/linux/spi/spi.h | 4 ++++ 2 files changed, 53 insertions(+) base-commit: fe15c26ee26efa11741a7b632e9f23b01aca4cc6 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 44b85a8d47f1..165e4a286080 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -3621,6 +3621,55 @@ int spi_split_transfers_maxsize(struct spi_controller *ctlr, } EXPORT_SYMBOL_GPL(spi_split_transfers_maxsize); + +/** + * spi_split_transfers_maxwords - split spi transfers into multiple transfers + * when an individual transfer exceeds a + * certain number of SPI words + * @ctlr: the @spi_controller for this transfer + * @msg: the @spi_message to transform + * @maxwords: the number of words to limit each transfer to + * @gfp: GFP allocation flags + * + * Return: status of transformation + */ +int spi_split_transfers_maxwords(struct spi_controller *ctlr, + struct spi_message *msg, + size_t maxwords, + gfp_t gfp) +{ + struct spi_transfer *xfer; + + /* + * Iterate over the transfer_list, + * but note that xfer is advanced to the last transfer inserted + * to avoid checking sizes again unnecessarily (also xfer does + * potentially belong to a different list by the time the + * replacement has happened). + */ + list_for_each_entry(xfer, &msg->transfers, transfer_list) { + size_t maxsize; + int ret; + + if (xfer->bits_per_word <= 8) + maxsize = maxwords; + else if (xfer->bits_per_word <= 16) + maxsize = 2 * maxwords; + else + maxsize = 4 * maxwords; + + if (xfer->len > maxsize) { + ret = __spi_split_transfer_maxsize(ctlr, msg, &xfer, + maxsize, gfp); + if (ret) + return ret; + } + } + + return 0; +} +EXPORT_SYMBOL_GPL(spi_split_transfers_maxwords); + /*-------------------------------------------------------------------------*/ /* Core methods for SPI controller protocol drivers. Some of the diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 4fa26b9a3572..f8dff44d77e5 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -1295,6 +1295,10 @@ extern int spi_split_transfers_maxsize(struct spi_controller *ctlr, struct spi_message *msg, size_t maxsize, gfp_t gfp); +extern int spi_split_transfers_maxwords(struct spi_controller *ctlr, + struct spi_message *msg, + size_t maxwords, + gfp_t gfp); /*---------------------------------------------------------------------------*/ From patchwork Fri Mar 10 09:20:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Leonard_G=C3=B6hrs?= X-Patchwork-Id: 67304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp770658wrd; Fri, 10 Mar 2023 01:28:57 -0800 (PST) X-Google-Smtp-Source: AK7set8Bk+2a4OCtBP5g3iG8MlNP/hn3s55taO64CclCfkv4GXkf0f6aCB4qJmW+vl7KQN/kdirU X-Received: by 2002:a17:902:c412:b0:19c:be03:d18b with SMTP id k18-20020a170902c41200b0019cbe03d18bmr34524518plk.22.1678440537036; Fri, 10 Mar 2023 01:28:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678440537; cv=none; d=google.com; s=arc-20160816; b=HZVGVYVCdMgJN6ItmNxbkuX1I9eJt0HFWpFRYhw7i2yU8Oj0sHMFsaN+csx7HvXkRK b23rqm2fq8W/21KwSCmyuoaQhDUY3UclI7wJAHuMKDLt7DoyVAkg/mMk1/MAdPFgEyOK N/kEA0ibXWA8G2wZxap5UYjri1OaNAdtyC+NyRmYLmd8mylM5kcCt3Oj7RXl7giFL+p2 bGJqPAzW15tibQpyc0z/KNonAI6pA8t5SpKvmyKiMVFaGYVNpuX7eNtQbkLhtAfSjK8M viTm1k1scw0oiOyzgZxmuh8aNtMjthptSowV6izMGT9bwOzjtQcRpCeu35ItAfPNvtHZ urAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=kkvka3ljkNEwudugiSTC8eq9/w3nf/9l1tS0UI/CfFA=; b=eAqH9P1ue32qM4GYlWsyCpxp8aH+06Ahl07OsEMLIWn+wDqi855m+kjFZ60SU+Qg8j gn1ELY7FLz/NZT7sZCf1M5J8N1l56uuOgzg401y9xDfiFVygTqhp85SkH7S9oygBs8PW sR9dGOQGJyhYtg4XKxU9bmBlIE7SxyXGlVNBRQb8hGHuPsnkXl3CyKu7s8yyKUmmvCSw ty73uiPe1rleIqiCQuxNkZj+aaAXNyaBKjrMfmHVbF6JhuCmoXWfFZVlaxbmORZQPja0 REk1uxffcqdvvA5VTkuBI06Bw4zUgyrfF3cayYP4K5OVdpkPWA1NIpVlmkF6RXyVraSt X9jw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ko13-20020a17090307cd00b0019cf1bde932si1638091plb.35.2023.03.10.01.28.44; Fri, 10 Mar 2023 01:28:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230447AbjCJJ0j (ORCPT + 99 others); Fri, 10 Mar 2023 04:26:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230430AbjCJJ0H (ORCPT ); Fri, 10 Mar 2023 04:26:07 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A746610A2B0 for ; Fri, 10 Mar 2023 01:22:05 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1paYwN-0002lF-P7; Fri, 10 Mar 2023 10:21:31 +0100 Received: from [2a0a:edc0:0:1101:1d::39] (helo=dude03.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1paYwM-0038yl-36; Fri, 10 Mar 2023 10:21:30 +0100 Received: from lgo by dude03.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1paYwL-004Dqb-De; Fri, 10 Mar 2023 10:21:29 +0100 From: =?utf-8?q?Leonard_G=C3=B6hrs?= To: Alain Volmat , Mark Brown , Maxime Coquelin , Alexandre Torgue Cc: kernel@pengutronix.de, =?utf-8?q?Leonard_G=C3=B6hrs?= , linux-spi@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] spi: stm32: split large transfers based on word size instead of bytes Date: Fri, 10 Mar 2023 10:20:53 +0100 Message-Id: <20230310092053.1006459-2-l.goehrs@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230310092053.1006459-1-l.goehrs@pengutronix.de> References: <20230310092053.1006459-1-l.goehrs@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: lgo@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759972464370089723?= X-GMAIL-MSGID: =?utf-8?q?1759972464370089723?= The TSIZE register in CR2, to which the number of words to transfer is written, is only 16 Bit. This limits transfers to 65535 SPI _words_ at a time. The existing code uses spi_split_transfers_maxsize to limit transfers to 65535 _bytes_ at a time. This breaks large transfers with bits_per_word > 8, as they are split inside of a word boundary by the odd size limit. Split transfers based on the number of words instead. This has the added benefit of not artificially limiting the maximum length of bpw > 8 transfers to half or a quarter of the actual limit. The combination of very large transfers and bits_per_word = 16 is triggered e.g. by MIPI DBI displays when updating large parts of the screen. Signed-off-by: Leonard Göhrs Acked-by: Alain Volmat --- drivers/spi/spi-stm32.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index def09cf0dc14..d2e16f16fae6 100644 --- a/drivers/spi/spi-stm32.c +++ b/drivers/spi/spi-stm32.c @@ -984,9 +984,9 @@ static int stm32_spi_prepare_msg(struct spi_master *master, if (spi->cfg->set_number_of_data) { int ret; - ret = spi_split_transfers_maxsize(master, msg, - STM32H7_SPI_TSIZE_MAX, - GFP_KERNEL | GFP_DMA); + ret = spi_split_transfers_maxwords(master, msg, + STM32H7_SPI_TSIZE_MAX, + GFP_KERNEL | GFP_DMA); if (ret) return ret; }