From patchwork Mon May 15 14:07:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 94169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6966750vqo; Mon, 15 May 2023 07:32:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7xlpW+wJG01MTNvo4skdR6kY+g90U7NMXLyy/8XMU/VRJCM3s4HMYY3IXMYIsvaXUWAUDJ X-Received: by 2002:a9d:6f11:0:b0:6ad:cf63:a83e with SMTP id n17-20020a9d6f11000000b006adcf63a83emr1861405otq.6.1684161137993; Mon, 15 May 2023 07:32:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684161137; cv=none; d=google.com; s=arc-20160816; b=wkU1/yIzpkbIrZBTUS1jwNksuGK8HslOEqReVQn4kKW+b9Krgkrl1lcbe1FGwd8UKv HsJY7zisvIwFdyzqtr3+szHtdRYhMOc7VHj608jiPS/c8qVz9lDZTjhbGvQDXX9orhiS Z/YdymHGPzz095Xil+dSE9IG6bw5OAEkbq3HyQ+Pqrf2gUJz70gxtqHgkMCq8NSff+3p fbx/8japoWFESYmqW24V4GW4I5BiOxnJ+cohiT2iOpRL1TqOUXh/2FnE+oz+ZBYnjlEi CWEXyJ1MPVC7y8CU5DO+egJ0g8+1I62z+MGU1d0yvY2QXs9MuCyTJ/LJYQREhfrtE/Nv GZxg== 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=Z4IOkzhfU/wOULsj49Qc05G09PFpD6G07jXBib6+vlM=; b=jNDbS5Hus87EFINCIwHW4TDUL8imlAk8sU34cQDPOkhypRWadv0nwGf9x0dbDPNCwn uTQYg41kB0hbJFJYnCK7MyQAjjI3hoHfiRSYiYWHjIidkpYGcjhRlKqKXH3uadzoSjPm qAo9thzScYCT0EzHfR7X2Id9TTCTtUvy9q7STe/Gm9VAV3r+XcnMN2eWLpPZqmkfPR0h PtjsYhpRn37zOg8cTqPO2GtgDvfzgCkDEF736prFzBxcqm20qDZoMuy2Z6L7mI1LuIa4 LChi6hbRAptq7cYAJn1CIFxiBCAHkXeyvVyVLxvs4tA4ZeBcjEDHIqsbnI+4PcTwXQu2 H9mA== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cp15-20020a056830660f00b006ac9b7fa271si4600077otb.34.2023.05.15.07.32.03; Mon, 15 May 2023 07:32:17 -0700 (PDT) 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240343AbjEOOUp (ORCPT + 99 others); Mon, 15 May 2023 10:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240239AbjEOOUj (ORCPT ); Mon, 15 May 2023 10:20:39 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D79DA2685; Mon, 15 May 2023 07:20:35 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4QKh695P20z9sfM; Mon, 15 May 2023 16:08:01 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n7iBsVw3BR-u; Mon, 15 May 2023 16:08:01 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4QKh662g1Wz9sfH; Mon, 15 May 2023 16:07:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4A0618B770; Mon, 15 May 2023 16:07:58 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id alq4ozSJz5kR; Mon, 15 May 2023 16:07:58 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.232.36]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 08C2C8B763; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 34FE7OO1583495 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 May 2023 16:07:24 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 34FE7OhM583494; Mon, 15 May 2023 16:07:24 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Rasmus Villemoes , Mark Brown Subject: [PATCH 1/3][For 4.19/4.14] spi: spi-fsl-spi: automatically adapt bits-per-word in cpu mode Date: Mon, 15 May 2023 16:07:13 +0200 Message-Id: <674d9af640acf4aa04abd642cc81de926d3271ed.1684158520.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1684159634; l=1846; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=OWc7X3nzzTeipDvjQyYBRZZJhdcswKxTsmbPVSf0T6w=; b=wRJPE7NaTac/3r834KzwijlYzcX1UtMJJV6UAtQ0MOaDVhKWMSQWCsCpEmOR2Pg6Me5ICd3gb epA+e6RJDvEC4MrkUpuXfOyzZwIndITdnQ1g0xp6vMnK7u8+nSVwxEa X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1765970949353170945?= X-GMAIL-MSGID: =?utf-8?q?1765970949353170945?= From: Rasmus Villemoes (cherry picked from upstream af0e6242909c3c4297392ca3e94eff1b4db71a97) Taking one interrupt for every byte is rather slow. Since the controller is perfectly capable of transmitting 32 bits at a time, change t->bits_per-word to 32 when the length is divisible by 4 and large enough that the reduced number of interrupts easily compensates for the one or two extra fsl_spi_setup_transfer() calls this causes. Signed-off-by: Rasmus Villemoes Signed-off-by: Mark Brown Signed-off-by: Christophe Leroy --- drivers/spi/spi-fsl-spi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 479d10dc6cb8..946b417f2d1c 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -357,12 +357,28 @@ static int fsl_spi_bufs(struct spi_device *spi, struct spi_transfer *t, static int fsl_spi_do_one_msg(struct spi_master *master, struct spi_message *m) { + struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master); struct spi_device *spi = m->spi; struct spi_transfer *t, *first; unsigned int cs_change; const int nsecs = 50; int status; + /* + * In CPU mode, optimize large byte transfers to use larger + * bits_per_word values to reduce number of interrupts taken. + */ + if (!(mpc8xxx_spi->flags & SPI_CPM_MODE)) { + list_for_each_entry(t, &m->transfers, transfer_list) { + if (t->len < 256 || t->bits_per_word != 8) + continue; + if ((t->len & 3) == 0) + t->bits_per_word = 32; + else if ((t->len & 1) == 0) + t->bits_per_word = 16; + } + } + /* Don't allow changes if CS is active */ first = list_first_entry(&m->transfers, struct spi_transfer, transfer_list); From patchwork Mon May 15 14:07:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 94166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6964210vqo; Mon, 15 May 2023 07:28:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4mqHWRwywXxFkt0mFG/VgKsyEg06lW3om2rfu187QVv9jS2pocsm6EYa4ZnVsCqIlebXo/ X-Received: by 2002:a05:6a21:7891:b0:101:209e:bc57 with SMTP id bf17-20020a056a21789100b00101209ebc57mr29631789pzc.50.1684160931123; Mon, 15 May 2023 07:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684160931; cv=none; d=google.com; s=arc-20160816; b=fBpqHobpl67HMEbikS3BoenN2WHhMz3YY5WEBcIiNnWU2k/5Rh58y3+Y5dH+aXH62u tRt/wf3sm8WBkPeguow6RDRxvTnw0i0cn7O1eg065aqYmQns3hx4qe3v/ODuJaHrJADR m3UNEQypu/QxfhvKWWTviwrvG+4CDgdV3Dt5lWDqAyJXCfawhxpDi9PFPT7BQAanbl32 KlfmDM3Wc/Qch+Oy+u+ceQ2eRu126L4ukVAp3NSTw3QL0krDh2x848yTV5CdZySKnQsN xqEoWVz1CcPN+1HtBtNHUQl7iSg0E4oe1ShR0SSqi7tcKZq2gpxCh4md59Zl9czCgcnO IqpQ== 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=ay22Rxr7bW85gsA9TjwTVcy2Dx61cCxV+Fj70XkPcsU=; b=XaIRaqA7WeOAkOSvRMIOMknnDfNwFTYNWaHWSFRD2Oakp3Ay0pql/6AHaZA3pM/rrP R5XJ4R8r009Xm4JL4efEvnbbc3qiExt1idjzeDaowl+7Fb2F1EmNlVbVb4ziAAaJG903 nYHiClpVM2EUBvBNcg28cXg1ybNxJGbz8HcR6NMX5KXijsJ8Ls/Fhed8dA5E/6sjQFkc YxPel1BNO8SiWbg4iLrvIU8a2EaO5YZBwUNYBO8QZfFbJXch3d/ClGnw+7va4STCxWQd d/z0PBT/mt6yV6oMBygFKYq0lomyIUFsyWBB+3tlHSzlvuT4HO6zZkiLhyKF80A6hg83 U4Jg== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k12-20020aa7998c000000b0063b843131b1si16474140pfh.324.2023.05.15.07.28.35; Mon, 15 May 2023 07:28:51 -0700 (PDT) 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240191AbjEOOUi (ORCPT + 99 others); Mon, 15 May 2023 10:20:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239849AbjEOOUd (ORCPT ); Mon, 15 May 2023 10:20:33 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3E7D2118; Mon, 15 May 2023 07:20:31 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4QKh671bhbz9sfT; Mon, 15 May 2023 16:07:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nsFmj3CNAqph; Mon, 15 May 2023 16:07:59 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4QKh655PpNz9sfL; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A8E298B770; Mon, 15 May 2023 16:07:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 8Xl6TUU0YdU8; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.232.36]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 697CD8B763; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 34FE7PJm583501 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 May 2023 16:07:25 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 34FE7Po1583500; Mon, 15 May 2023 16:07:25 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Mark Brown Subject: [PATCH 2/3][For 4.19/4.14] spi: fsl-spi: Re-organise transfer bits_per_word adaptation Date: Mon, 15 May 2023 16:07:14 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: <674d9af640acf4aa04abd642cc81de926d3271ed.1684158520.git.christophe.leroy@csgroup.eu> References: <674d9af640acf4aa04abd642cc81de926d3271ed.1684158520.git.christophe.leroy@csgroup.eu> MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1684159634; l=4014; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=hx7h1I+YEnCP3HczYbWaCBjvenpopKKrD57hpgFewfY=; b=DWdjwylIRwQxmu/KOehp0AezNhX2zHk0wasyuiVpThPz7AuGtCKF9YiMBWgMF6H5oD2yWuCSE ziueG7jLpx8AYHCE2n3YoL0qOKb9pc3+5ewbGJUmmXvMxOgboXf0Vxn X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1765970732274227117?= X-GMAIL-MSGID: =?utf-8?q?1765970732274227117?= (backported from upstream 8a5299a1278eadf1e08a598a5345c376206f171e) For different reasons, fsl-spi driver performs bits_per_word modifications for different reasons: - On CPU mode, to minimise amount of interrupts - On CPM/QE mode to work around controller byte order For CPU mode that's done in fsl_spi_prepare_message() while for CPM mode that's done in fsl_spi_setup_transfer(). Reunify all of it in fsl_spi_prepare_message(), and catch impossible cases early through master's bits_per_word_mask instead of returning EINVAL later. Signed-off-by: Christophe Leroy Link: https://lore.kernel.org/r/0ce96fe96e8b07cba0613e4097cfd94d09b8919a.1680371809.git.christophe.leroy@csgroup.eu Signed-off-by: Mark Brown --- drivers/spi/spi-fsl-spi.c | 50 ++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 946b417f2d1c..e08a11070c5c 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -201,26 +201,6 @@ static int mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs, return bits_per_word; } -static int mspi_apply_qe_mode_quirks(struct spi_mpc8xxx_cs *cs, - struct spi_device *spi, - int bits_per_word) -{ - /* CPM/QE uses Little Endian for words > 8 - * so transform 16 and 32 bits words into 8 bits - * Unfortnatly that doesn't work for LSB so - * reject these for now */ - /* Note: 32 bits word, LSB works iff - * tfcr/rfcr is set to CPMFCR_GBL */ - if (spi->mode & SPI_LSB_FIRST && - bits_per_word > 8) - return -EINVAL; - if (bits_per_word <= 8) - return bits_per_word; - if (bits_per_word == 16 || bits_per_word == 32) - return 8; /* pretend its 8 bits */ - return -EINVAL; -} - static int fsl_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) { @@ -248,9 +228,6 @@ static int fsl_spi_setup_transfer(struct spi_device *spi, bits_per_word = mspi_apply_cpu_mode_quirks(cs, spi, mpc8xxx_spi, bits_per_word); - else - bits_per_word = mspi_apply_qe_mode_quirks(cs, spi, - bits_per_word); if (bits_per_word < 0) return bits_per_word; @@ -368,14 +345,27 @@ static int fsl_spi_do_one_msg(struct spi_master *master, * In CPU mode, optimize large byte transfers to use larger * bits_per_word values to reduce number of interrupts taken. */ - if (!(mpc8xxx_spi->flags & SPI_CPM_MODE)) { - list_for_each_entry(t, &m->transfers, transfer_list) { + list_for_each_entry(t, &m->transfers, transfer_list) { + if (!(mpc8xxx_spi->flags & SPI_CPM_MODE)) { if (t->len < 256 || t->bits_per_word != 8) continue; if ((t->len & 3) == 0) t->bits_per_word = 32; else if ((t->len & 1) == 0) t->bits_per_word = 16; + } else { + /* + * CPM/QE uses Little Endian for words > 8 + * so transform 16 and 32 bits words into 8 bits + * Unfortnatly that doesn't work for LSB so + * reject these for now + * Note: 32 bits word, LSB works iff + * tfcr/rfcr is set to CPMFCR_GBL + */ + if (m->spi->mode & SPI_LSB_FIRST && t->bits_per_word > 8) + return -EINVAL; + if (t->bits_per_word == 16 || t->bits_per_word == 32) + t->bits_per_word = 8; /* pretend its 8 bits */ } } @@ -658,8 +648,14 @@ static struct spi_master * fsl_spi_probe(struct device *dev, if (mpc8xxx_spi->type == TYPE_GRLIB) fsl_spi_grlib_probe(dev); - master->bits_per_word_mask = - (SPI_BPW_RANGE_MASK(4, 16) | SPI_BPW_MASK(32)) & + if (mpc8xxx_spi->flags & SPI_CPM_MODE) + master->bits_per_word_mask = + (SPI_BPW_RANGE_MASK(4, 8) | SPI_BPW_MASK(16) | SPI_BPW_MASK(32)); + else + master->bits_per_word_mask = + (SPI_BPW_RANGE_MASK(4, 16) | SPI_BPW_MASK(32)); + + master->bits_per_word_mask &= SPI_BPW_RANGE_MASK(1, mpc8xxx_spi->max_bits_per_word); if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) From patchwork Mon May 15 14:07:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 94165 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6959994vqo; Mon, 15 May 2023 07:22:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nMPKcdhkeVtr94XBByfQaVrBLz19MPhTM00ZAvIyKVHkEGxpVeo7FwHRQLt5M1CRveYBT X-Received: by 2002:a17:90b:3910:b0:250:2ad4:b459 with SMTP id ob16-20020a17090b391000b002502ad4b459mr34038846pjb.39.1684160546713; Mon, 15 May 2023 07:22:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684160546; cv=none; d=google.com; s=arc-20160816; b=F1tiAaMccEOvI3olO+i5qwWNmt5i7WLgY5tRQEH//nuuRFQo+kaHgjjayzznSLgsuF Z0gXoGCrNguos9vQAUsrLn93VXQF1FwrNmB+ohTuBx69ZERRbiZQ/o9xZT6YuttlRP24 HWB7bDko1bsflb7/R2w5G4sOaxPbdD0MO4a2dLXcqeE9fFmRv2F78Hmv6CYP53d8G9Sy 8df6+8PHza7yquxVeU9h/wR23v6iYeIT/GfXzY5TSKkGpw7O18Osq5ZHwYRKvReeuyP8 VaC/j5LM9D2GjJAkW3jxglxmzXMyn/GrQtc4r0JaihPKB2mL5fkmqAd6a5VVSZmf/tAH 2a5w== 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=3AzDBBJfEOzzzKOiUNJPYvKgvewXdcsfzLn3G1HfpKs=; b=nuqVT6kLCKifaXQWGMLiyndn8/5CBkQ2lSX/jRjnfE3r9jYbbDllaOzwlX9nKrvtMU Ur+WtusF+FYK7cm+mIdoW8Xg/qAU+n7jpmjCpfV7TK5DGqYrDBdkDqWQmjECR0vYp2eU U9ja9c8EVXKpoILpwGtLNocuLw0lOLIQhpNTJAp3YrL0teu5cvufCv9inuvFFEIWIuPr jkP82/JBC20uwmecXdK9PjZFj9l8Ew7TmqtkiOpnzt0vyFyqHN61RR2GxBhnj8CC0Ydp WX0BnoptXxtjkiVR1H13C2id2wv1emGMHGap/2JUNrfTV0OI/43VrXr2xS1mYotNjjH4 UvCQ== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020a639d08000000b0051ba2ec8320si16117563pgd.353.2023.05.15.07.21.49; Mon, 15 May 2023 07:22:26 -0700 (PDT) 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=csgroup.eu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239817AbjEOOUd (ORCPT + 99 others); Mon, 15 May 2023 10:20:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237208AbjEOOUa (ORCPT ); Mon, 15 May 2023 10:20:30 -0400 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A589C1BFB; Mon, 15 May 2023 07:20:28 -0700 (PDT) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4QKh652927z9sfK; Mon, 15 May 2023 16:07:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TIq3ECWBFt4Z; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4QKh650yV1z9sfH; Mon, 15 May 2023 16:07:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0EF2A8B770; Mon, 15 May 2023 16:07:57 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id DVnxLdnlrnuA; Mon, 15 May 2023 16:07:56 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.232.36]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C5EED8B763; Mon, 15 May 2023 16:07:55 +0200 (CEST) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 34FE7PGS583505 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 15 May 2023 16:07:25 +0200 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 34FE7P4L583504; Mon, 15 May 2023 16:07:25 +0200 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Mark Brown Subject: [PATCH 3/3][For 4.19/4.14] spi: fsl-cpm: Use 16 bit mode for large transfers with even size Date: Mon, 15 May 2023 16:07:15 +0200 Message-Id: <9363da33f54e9862b4b59c0ed97924ca7265f7a4.1684158520.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.40.1 In-Reply-To: <674d9af640acf4aa04abd642cc81de926d3271ed.1684158520.git.christophe.leroy@csgroup.eu> References: <674d9af640acf4aa04abd642cc81de926d3271ed.1684158520.git.christophe.leroy@csgroup.eu> MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1684159635; l=3126; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=l7gMBo+J9VneTb7HZST7+pC/HbETdxgOtrQIZaFHdik=; b=Q+cyRKRh9x9rIqyUk77SliaUcnE7JGKafPsMuKOhte+TWtTI/IvZ6MpVBCvlnBAip35wo7Y/5 8g0bvpE1SCsB8AbCr0TZN5mJfLL1MXw54ZPV2ETMxbVJPptxeCXlk4V X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1765970329317981001?= X-GMAIL-MSGID: =?utf-8?q?1765970329317981001?= (cherry picked from upstream fc96ec826bced75cc6b9c07a4ac44bbf651337ab) On CPM, the RISC core is a lot more efficiant when doing transfers in 16-bits chunks than in 8-bits chunks, but unfortunately the words need to be byte swapped as seen in a previous commit. So, for large tranfers with an even size, allocate a temporary tx buffer and byte-swap data before and after transfer. This change allows setting higher speed for transfer. For instance on an MPC 8xx (CPM1 comms RISC processor), the documentation tells that transfer in byte mode at 1 kbit/s uses 0.200% of CPM load at 25 MHz while a word transfer at the same speed uses 0.032% of CPM load. This means the speed can be 6 times higher in word mode for the same CPM load. For the time being, only do it on CPM1 as there must be a trade-off between the CPM load reduction and the CPU load required to byte swap the data. Signed-off-by: Christophe Leroy Link: https://lore.kernel.org/r/f2e981f20f92dd28983c3949702a09248c23845c.1680371809.git.christophe.leroy@csgroup.eu Signed-off-by: Mark Brown --- drivers/spi/spi-fsl-cpm.c | 23 +++++++++++++++++++++++ drivers/spi/spi-fsl-spi.c | 3 +++ 2 files changed, 26 insertions(+) diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c index 8f7b26ec181e..0485593dc2f5 100644 --- a/drivers/spi/spi-fsl-cpm.c +++ b/drivers/spi/spi-fsl-cpm.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "spi-fsl-cpm.h" #include "spi-fsl-lib.h" @@ -124,6 +125,21 @@ int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, mspi->rx_dma = mspi->dma_dummy_rx; mspi->map_rx_dma = 0; } + if (t->bits_per_word == 16 && t->tx_buf) { + const u16 *src = t->tx_buf; + u16 *dst; + int i; + + dst = kmalloc(t->len, GFP_KERNEL); + if (!dst) + return -ENOMEM; + + for (i = 0; i < t->len >> 1; i++) + dst[i] = cpu_to_le16p(src + i); + + mspi->tx = dst; + mspi->map_tx_dma = 1; + } if (mspi->map_tx_dma) { void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */ @@ -177,6 +193,13 @@ void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi) if (mspi->map_rx_dma) dma_unmap_single(dev, mspi->rx_dma, t->len, DMA_FROM_DEVICE); mspi->xfer_in_progress = NULL; + + if (t->bits_per_word == 16 && t->rx_buf) { + int i; + + for (i = 0; i < t->len; i += 2) + le16_to_cpus(t->rx_buf + i); + } } EXPORT_SYMBOL_GPL(fsl_spi_cpm_bufs_complete); diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index e08a11070c5c..5e49fed487f8 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c @@ -366,6 +366,9 @@ static int fsl_spi_do_one_msg(struct spi_master *master, return -EINVAL; if (t->bits_per_word == 16 || t->bits_per_word == 32) t->bits_per_word = 8; /* pretend its 8 bits */ + if (t->bits_per_word == 8 && t->len >= 256 && + (mpc8xxx_spi->flags & SPI_CPM1)) + t->bits_per_word = 16; } }