From patchwork Fri May 12 10:47:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 93136 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5020618vqo; Fri, 12 May 2023 04:21:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7WLnCzl3xNDfZxZKpcwG3XPJ4mtj3f5dU8h7SJA3Pns+WDAn2io8VookuwDg1DMR/afXkY X-Received: by 2002:a05:6a20:7492:b0:100:b137:3563 with SMTP id p18-20020a056a20749200b00100b1373563mr18324397pzd.32.1683890489155; Fri, 12 May 2023 04:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683890489; cv=none; d=google.com; s=arc-20160816; b=BadAACazEJ6FDxfBVJzEQh/iU1hXEfepovh/a8mHbPnqSfDTWiOmffsFAGAZW360+h nWK2TDUGKjzSZG+508WPEcC9MJ4iM2dvzkoLuiRFCNDq/QIPnSmqr3cXcVMbHSkThCkc PHLLhqwAS3TWkRpCvYPzgxa603XPP6BnCqnJrrYZCLVC30BRqdUK4SCTLdbm8oEbxOwa ApnIuV00wKsvDtUx9TeLxqr7K8rWbBYFOqTLNAeagAhn+/hUMHQc1y2Z+VrkpKF5zxi3 A5rDR2jaQJfFzvWUWjoIXjrlrVWbkl/twlyp2zSTyJ+yh+cCrvFbhZoPDfqlSTqUXSSr Smng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=VXKFUpKr0w+nTlVz7d6efsfYj1wpJ5Pn5dWHxsHWrQ4=; b=tUMp2Xp3cVS8Dh3oJ7wktxTVrjnuqSTk0G0kBhcieoKJCbp7wD62SAolagbpTtj3L+ UmDc7tesHqxHA7tb3egv/FYHGzGGX1ILkW0le4fGgLLQMQxYihWQCK3EtDuz3m7Dh8id zjbwv1R7I+3oIzNS3Yz37f1dQP1N+t0Y3eNbvyRvrtx2tVwgwRXX1f///H+WOEZYpgIw lDbHEwUZfemP+w9GLSjAZFXurz22BG8y/gIn2me8lomCNgXToNoTrl5kriQOzJpmLuCV CtyAZsk7HS3LqBUF9Fo5Ba9QPxsfxDNXKNClIsPzrdi2Vutsqkg+ByckDvaKfnrPweQl 5kTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=2tPLx5Jn; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c10-20020a056a00008a00b0063b21db5973si9987497pfj.358.2023.05.12.04.21.14; Fri, 12 May 2023 04:21:29 -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; dkim=pass header.i=@google.com header.s=20221208 header.b=2tPLx5Jn; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240898AbjELKsr (ORCPT + 99 others); Fri, 12 May 2023 06:48:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240864AbjELKsd (ORCPT ); Fri, 12 May 2023 06:48:33 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D917C13844 for ; Fri, 12 May 2023 03:47:57 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-b9a7d92d0f7so17816599276.1 for ; Fri, 12 May 2023 03:47:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683888477; x=1686480477; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VXKFUpKr0w+nTlVz7d6efsfYj1wpJ5Pn5dWHxsHWrQ4=; b=2tPLx5Jn2d88GYhqypiMnQ2nPJnhEzg90y22Gv4K0TcTBV8rNgHMc1a3U1sXfd+LQq z5Ls5cmFRvVt8gwQeReN/GPkZo9/vhpQww15PjmkoGyKQkOtwM9X6Yji4b1aKSNfknb5 h5EZHVF+d38m6iFRutc14n+dwx4SoJGiNz8XQNSlk86gC+ngVKNWMVECUejkDTX62zli FI1QqMk74Caf6djSkSfO0TKw3LQTheAW1oBhvdMi0pc/0PU/x1jSN+AhuFmXebl06JlE LjBcSLbVr6aAAGuacOuvV6IDEGDvq6V/2IcwV5/cczyY0xoEbLuD7rAf/ZTW4bZrZ3sJ iRcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683888477; x=1686480477; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VXKFUpKr0w+nTlVz7d6efsfYj1wpJ5Pn5dWHxsHWrQ4=; b=ebF0MbdC9vu/pHAKjpBd5GgiS0yrPz/Cxp99K1MISGPF1C/OCxJK0erKq5Q54t1Sb/ MfrlyqCl+9HG6UlzJPjfytOf+GwRj7fRBQ/04zK6x0ssVxax/LuNqbH3Ur21YNgyk1LH 9EgR3oR1f6P3MyEzioJ6Cd9v60nNti8296jyzwRoG8/9E05Pf7MvvQb18Z3Eo/UIp1fb 935QACtyET05RmxIO+0wHxSWpqFGudPLxY8n5aY8pYqW7Xr/YLjUNSsQ965XiP/pDCIH FcReyBg4rPiXV10rrtDEFRP/vHoU5vNKXi+gSmZGfjqXwjydwEB7oLmnr5ojYGAQLfYR Z8nA== X-Gm-Message-State: AC+VfDxMdtzqpZg7h1nRsuWocu2TyApMZFU0dXANGshSmmephgcVVfDO iY0iqewdONuDi6z3ZYeuR939+p6wanaHkQ== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:5454:0:b0:ba2:1a28:c852 with SMTP id i81-20020a255454000000b00ba21a28c852mr9966526ybb.7.1683888477042; Fri, 12 May 2023 03:47:57 -0700 (PDT) Date: Fri, 12 May 2023 10:47:43 +0000 In-Reply-To: <20230512104746.1797865-1-joychakr@google.com> Mime-Version: 1.0 References: <20230512104746.1797865-1-joychakr@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230512104746.1797865-2-joychakr@google.com> Subject: [PATCH v11 1/3] spi: dw: Add DMA directional capability check From: Joy Chakraborty To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, Joy Chakraborty , Serge Semin X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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?1765687153249768217?= X-GMAIL-MSGID: =?utf-8?q?1765687153249768217?= Check capabilities of DMA controller during init to make sure it is capable of handling MEM2DEV for tx channel, DEV2MEM for rx channel. Current DW DMA driver requires both tx and rx channel to be configured and functional for any kind of transfers to take effect including half duplex. Hence, check for both tx and rx direction and fail on unavailbility of either. Signed-off-by: Joy Chakraborty Reviewed-by: Serge Semin Tested-by: Serge Semin * tested on Baikal-T1 based system with DW SPI-looped back interface transferring a chunk of data with DFS:8,12,16. --- drivers/spi/spi-dw-dma.c | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index f19c092920a1..2363317a0dca 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -72,12 +72,22 @@ static void dw_spi_dma_maxburst_init(struct dw_spi *dws) dw_writel(dws, DW_SPI_DMATDLR, dws->txburst); } -static void dw_spi_dma_sg_burst_init(struct dw_spi *dws) +static int dw_spi_dma_caps_init(struct dw_spi *dws) { - struct dma_slave_caps tx = {0}, rx = {0}; + struct dma_slave_caps tx, rx; + int ret; + + ret = dma_get_slave_caps(dws->txchan, &tx); + if (ret) + return ret; - dma_get_slave_caps(dws->txchan, &tx); - dma_get_slave_caps(dws->rxchan, &rx); + ret = dma_get_slave_caps(dws->rxchan, &rx); + if (ret) + return ret; + + if (!(tx.directions & BIT(DMA_MEM_TO_DEV) && + rx.directions & BIT(DMA_DEV_TO_MEM))) + return -ENXIO; if (tx.max_sg_burst > 0 && rx.max_sg_burst > 0) dws->dma_sg_burst = min(tx.max_sg_burst, rx.max_sg_burst); @@ -87,6 +97,8 @@ static void dw_spi_dma_sg_burst_init(struct dw_spi *dws) dws->dma_sg_burst = rx.max_sg_burst; else dws->dma_sg_burst = 0; + + return 0; } static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) @@ -95,6 +107,7 @@ static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) struct dw_dma_slave dma_rx = { .src_id = 0 }, *rx = &dma_rx; struct pci_dev *dma_dev; dma_cap_mask_t mask; + int ret = -EBUSY; /* * Get pci device for DMA controller, currently it could only @@ -124,20 +137,25 @@ static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) init_completion(&dws->dma_completion); - dw_spi_dma_maxburst_init(dws); + ret = dw_spi_dma_caps_init(dws); + if (ret) + goto free_txchan; - dw_spi_dma_sg_burst_init(dws); + dw_spi_dma_maxburst_init(dws); pci_dev_put(dma_dev); return 0; +free_txchan: + dma_release_channel(dws->txchan); + dws->txchan = NULL; free_rxchan: dma_release_channel(dws->rxchan); dws->rxchan = NULL; err_exit: pci_dev_put(dma_dev); - return -EBUSY; + return ret; } static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws) @@ -163,12 +181,17 @@ static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws) init_completion(&dws->dma_completion); - dw_spi_dma_maxburst_init(dws); + ret = dw_spi_dma_caps_init(dws); + if (ret) + goto free_txchan; - dw_spi_dma_sg_burst_init(dws); + dw_spi_dma_maxburst_init(dws); return 0; +free_txchan: + dma_release_channel(dws->txchan); + dws->txchan = NULL; free_rxchan: dma_release_channel(dws->rxchan); dws->rxchan = NULL; From patchwork Fri May 12 10:47:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 93139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5024560vqo; Fri, 12 May 2023 04:29:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7WSlBcWGW8nIufNdo+F3EOJyfzY+3QIs11pKsDKA0kDjnNI7sHYM3YfySE4g12VYrU5QfK X-Received: by 2002:a05:6a21:3391:b0:101:5f33:94ad with SMTP id yy17-20020a056a21339100b001015f3394admr16558215pzb.52.1683890939649; Fri, 12 May 2023 04:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683890939; cv=none; d=google.com; s=arc-20160816; b=i9rMm8FkvPET/Jlafq5HF+ITe3x2ffSsSnd5ixW/Wzvy5FJ9vmxAjUAZN+lY7WoQc4 1T5D+4JM5ZxB85fS917MIgCLCzPmOgfD6NFikvCvpdch+UvQW8Z5NdC/j/Oa9icc+CDV c/jRBEhurYi0WwF5KykYDjlTrgqFK+b9R/Zk7eTQv+bm8I8OYrnZQ8QV+mu4o91rkZB6 +jsefBoEGsjCEuN1FDq30H0FFYFIldI+W/86g6+GSly7A2ynB3MuJoddtNAqWfXMRtDh omoeFAnphoV2rOqrNIrW+kntHI50G3pBYISFm1kSXiVqQucuRFE+rGFsoSZLwTWKjhQu CzBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=jAZjFxFUrm9OtcOgH4xOlH5bZ5I2tEQhGA86p1DuNqo=; b=bdZvDgMJpVki49+X1Na1TXuyhMAfpFz3ZNhiYZRT4nCXZAzDibnyZ/YI+9I9n5/Juo JL2VU1muBgEAunKF06sSAA3XBXMaUyYAmHkqaP4a3bqne+j6cH5cxI0vEnJDro8s3lQ1 yZag+BwLiiVnDoycaiI5XjAvwU7RmDJIdqpLh69lIGyW1cLil4A0wYS3us96XrZcjiy0 AARoKfw0uoHh3Hy4MsJhrCqTMtC5HUhzJ+5sHFGppJ3lfoRv49YdxXZkWq/1m5TaVwI3 Sin4Ra/bkDPKtZQxvVL9J0gz2XmsuZxpSdaWITeuNoSQg6BWz7H8LR95DkZ+VQEg+SXd qHXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ioq3uuIc; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v15-20020a63b64f000000b00524eefa6d61si9025226pgt.736.2023.05.12.04.28.45; Fri, 12 May 2023 04:28:59 -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; dkim=pass header.i=@google.com header.s=20221208 header.b=ioq3uuIc; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240684AbjELKs7 (ORCPT + 99 others); Fri, 12 May 2023 06:48:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240332AbjELKsm (ORCPT ); Fri, 12 May 2023 06:48:42 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 793AD13861 for ; Fri, 12 May 2023 03:48:02 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-ba22ced2e95so8771711276.1 for ; Fri, 12 May 2023 03:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683888481; x=1686480481; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=jAZjFxFUrm9OtcOgH4xOlH5bZ5I2tEQhGA86p1DuNqo=; b=ioq3uuIcfu+Q081SaVe+zrdtTTXwoa94fq3eQbzWahm+lfuDG6BcmyqPBMHVij789J QHsE56ld/XaGkM4n4LlkhLdpezbh1IrDwmq89Kez5Xv5409xZ1/G5x4B0pL1q6hne7MM ZXSClIb0um0b+Rz6jCRTdY1EOzpDML4kB5tXpaLgsQKfpsMhzOdmM26MXKrHi5Wk9bgT uuYXbZFUSAgsackXoWkOJxzn39jr+QFXSSGt6Zj39lB9erac3MPp32m3DeleSzKTazBj 5PFfc39a7Q4H45LWvibSjwOCteIlRj9a/QxvxftuXk7dVtM/a9iPEJ+vGPQYu8KZQtzN gPJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683888481; x=1686480481; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jAZjFxFUrm9OtcOgH4xOlH5bZ5I2tEQhGA86p1DuNqo=; b=YoZNUwB3YcLy1pcp2+4sa0646Uh8ks8TGdFnZ33n5y2SYCeZVfcmmBr521S16PlLfI KNbZv/Lrg7KACJ0d53CPuILC/EfPSiFdsnAmYju1XrG7jXL17LN7U/dz7mmJaPhHW20P yZq6+92WRh1Hvw70VFKSkvg2W4/JxDZg6yEnaiJWdnsrN6eLvSXv621NJgt6W7GqluoR HmMKoldLV39QgmRrMQxC8VcXwYG5KkscY26tm/yhLoUasLYyUVrDb9D9ZDLSqCylgrSu gUknUEsCtpWZ9KhVMpoHqqs5NKXMvh12dm/yyLP1QfinRc/XZzKVrkY9q8DHh/OCJUgB kzpQ== X-Gm-Message-State: AC+VfDweusg0TLbLYx4iHyXzt5mz3/PEAvkLSJINLR9X9PNtbVpOEm7X qdALvJmWxaTFbU//aeaYxwnAQqs7a6XbLQ== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a25:9ac5:0:b0:ba7:1499:e202 with SMTP id t5-20020a259ac5000000b00ba71499e202mr830400ybo.7.1683888481591; Fri, 12 May 2023 03:48:01 -0700 (PDT) Date: Fri, 12 May 2023 10:47:44 +0000 In-Reply-To: <20230512104746.1797865-1-joychakr@google.com> Mime-Version: 1.0 References: <20230512104746.1797865-1-joychakr@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230512104746.1797865-3-joychakr@google.com> Subject: [PATCH v11 2/3] spi: dw: Add DMA address widths capability check From: Joy Chakraborty To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, Joy Chakraborty , Serge Semin X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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?1765687625800013997?= X-GMAIL-MSGID: =?utf-8?q?1765687625800013997?= Store address width capabilities of DMA controller during init and check the same per transfer to make sure the bits/word requirement can be met. Current DW DMA driver requires both tx and rx channel to be configured and functional hence a subset of both tx and rx channel address width capability is checked with the width requirement(n_bytes) for a transfer. Signed-off-by: Joy Chakraborty Reviewed-by: Serge Semin Tested-by: Serge Semin * tested on Baikal-T1 based system with DW SPI-looped back interface transferring a chunk of data with DFS:8,12,16. --- drivers/spi/spi-dw-dma.c | 15 ++++++++++++++- drivers/spi/spi-dw.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c index 2363317a0dca..df819652901a 100644 --- a/drivers/spi/spi-dw-dma.c +++ b/drivers/spi/spi-dw-dma.c @@ -98,6 +98,13 @@ static int dw_spi_dma_caps_init(struct dw_spi *dws) else dws->dma_sg_burst = 0; + /* + * Assuming both channels belong to the same DMA controller hence the + * peripheral side address width capabilities most likely would be + * the same. + */ + dws->dma_addr_widths = tx.dst_addr_widths & rx.src_addr_widths; + return 0; } @@ -239,8 +246,14 @@ static bool dw_spi_can_dma(struct spi_controller *master, struct spi_device *spi, struct spi_transfer *xfer) { struct dw_spi *dws = spi_controller_get_devdata(master); + enum dma_slave_buswidth dma_bus_width; + + if (xfer->len <= dws->fifo_len) + return false; + + dma_bus_width = dw_spi_dma_convert_width(dws->n_bytes); - return xfer->len > dws->fifo_len; + return dws->dma_addr_widths & BIT(dma_bus_width); } static int dw_spi_dma_wait(struct dw_spi *dws, unsigned int len, u32 speed) diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h index 9e8eb2b52d5c..3962e6dcf880 100644 --- a/drivers/spi/spi-dw.h +++ b/drivers/spi/spi-dw.h @@ -190,6 +190,7 @@ struct dw_spi { struct dma_chan *rxchan; u32 rxburst; u32 dma_sg_burst; + u32 dma_addr_widths; unsigned long dma_chan_busy; dma_addr_t dma_addr; /* phy address of the Data register */ const struct dw_spi_dma_ops *dma_ops; From patchwork Fri May 12 10:47:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joy Chakraborty X-Patchwork-Id: 93135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5018108vqo; Fri, 12 May 2023 04:17:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ63xhDvRJEraMR+5PYbDluu1jzNktgNq6OG0i8V44n7fGKohHKwTDSolrnle3NQau3Y7GGb X-Received: by 2002:a05:6a00:1396:b0:646:7bc9:c480 with SMTP id t22-20020a056a00139600b006467bc9c480mr21616126pfg.10.1683890219948; Fri, 12 May 2023 04:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683890219; cv=none; d=google.com; s=arc-20160816; b=Y3fug/eg8IoTblQSUsLMIvMrHM+5UFH6bH17Am3OP1gCwzS2I/3MFLUWuqzXjGPR9P GHiDFpUogHIXDJ5SGmdqYnqOFdfJIz2z9beP/X2B14Oy6DJe2ebcuTPUW+gZCOxtnB/2 22MuVA1G6/81xTth+EPKgOOGLBrwE50BSjpAMEicxbGwyxo9sf1XSTNbkos17r9J97dY Kp+0O+cXkkOk7A2peDnhZukzbOL4sGE7yipBJYX8U/civFNsUaYp3cWBEYPumJqxk5as EyoG/dAn9apbsKXb9JUcG7lLc3ArGzdw6oopC2ZhrA+MhIOu4A7CYT9YqSqmlVRGwrWY 15bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=y049PmC5C0PnSAgiyWvWPHzKRIJST3guVG5ES+MeGns=; b=Y4EDejRIM/bC6bNuZZ6a/qLCkH2qNN6uwdJq0T73hRBL96ulYf198Qp0BtRAGeQ/1m 4/AF7OP85XqFrvFLuWY4KUo1xtT2Ai3aAeoDUkABSrzxx9JZMNcGtbZHrA23tdNoMnVD rWlYhMcrj4aq7vjshM785H0BRqQmbzAqbqJ19KLkdk5cjcP0R2aYhdOVfffHvXr0z5nb 9uwvOG+9Vj0NzvY9lCvAB3eHxx9muIwTfPcRbcyOeWGjOn8yFDKwxXNtoYQpW8MBVjCQ ZBmIiTl5uA+oIGqYgLT6r2qvBlJQ47H1QwDw5cVhaBsFxhY8yTynTwZLcmPUwyvLd+l6 740w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=vzvkdCR8; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u190-20020a6385c7000000b00525037a363asi9232503pgd.328.2023.05.12.04.16.45; Fri, 12 May 2023 04:16:59 -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; dkim=pass header.i=@google.com header.s=20221208 header.b=vzvkdCR8; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240915AbjELKsz (ORCPT + 99 others); Fri, 12 May 2023 06:48:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240907AbjELKso (ORCPT ); Fri, 12 May 2023 06:48:44 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C15C512EB4 for ; Fri, 12 May 2023 03:48:06 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b9a7c58ec19so11706023276.2 for ; Fri, 12 May 2023 03:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683888486; x=1686480486; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=y049PmC5C0PnSAgiyWvWPHzKRIJST3guVG5ES+MeGns=; b=vzvkdCR8kM136SsZBU8U6eQlSFq1oB+ZzglgeMJUx1D0MI+o/WQSVOCyw//1P3LZVw npUlZM10hPgXVQ2Cbmr3lZeebUN8Dq/7w4re/xNNrVEEkLgVTQanyAPt3J/qxl47Phag wuurc+OhIsCI3v0IoO8V0okHUzfS0FGRIzDdTTWooGPJwGl8oIsmiPAtSaFkLnDb42V9 b8DR3HLqasuktNv8yBUjuMR4SLdhfbr+/9pa2ApIj/0mcwTdK1LP7S1arT74S1rq/Nxs IQFoe2LN/ptkKD5ZFlVg1wDRkKW4VPHyVVaVC05WFrmDOaBiRbdwfPUroOXRCZ4Wl2Jy J3+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683888486; x=1686480486; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y049PmC5C0PnSAgiyWvWPHzKRIJST3guVG5ES+MeGns=; b=KBj4gKlpwXVhLkHIsZX+StmhTeYHPHzVW+fM0l3a9yKDnie4VwGfsKtgJn7CS/2Dk0 zFpK1eOqn3rfguZsoDqN7x/TIKrNaO3WijDn0DFDTuvUew3L0/OCixCKr3AjgpQl74Gb ra/Jg1j8iFETKrW7Eiht4A+fl2neAx7zocMf4SED26Y7I8C8FbwNWYChap0xeCxYPjID G4qjbZ/Q6nGXVivLhnroVzK/T3ikhPOxEqioOS5ULuDtxa4OmSLcFf4Ny0vh5l1DKCxY Asmn7WEZpyEAwTYbgZ2wh7WxNJIv44Ru6efWV3mSqxWap2w1EKxV6muRG0GjhmOBMTbm OU+Q== X-Gm-Message-State: AC+VfDwQUZkws6+KAJuMcbz+bpg3luCp1AMJfyk5wcMn+/vdtwO3t6/t CvWW6mYp5uqf2ArKP9Syxg1Nlz1FHmYg4A== X-Received: from joychakr.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:6ea]) (user=joychakr job=sendgmr) by 2002:a05:6902:1890:b0:b96:7676:db4a with SMTP id cj16-20020a056902189000b00b967676db4amr15756188ybb.0.1683888485998; Fri, 12 May 2023 03:48:05 -0700 (PDT) Date: Fri, 12 May 2023 10:47:45 +0000 In-Reply-To: <20230512104746.1797865-1-joychakr@google.com> Mime-Version: 1.0 References: <20230512104746.1797865-1-joychakr@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230512104746.1797865-4-joychakr@google.com> Subject: [PATCH v11 3/3] spi: dw: Round of n_bytes to power of 2 From: Joy Chakraborty To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, Joy Chakraborty , Andy Shevchenko , Serge Semin X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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?1765686871260380336?= X-GMAIL-MSGID: =?utf-8?q?1765686871260380336?= n_bytes variable in the driver represents the number of bytes per word that needs to be sent/copied to fifo. Bits/word can be between 8 and 32 bits from the client but in memory they are a power of 2, same is mentioned in spi.h header: " * @bits_per_word: Data transfers involve one or more words; word sizes * like eight or 12 bits are common. In-memory wordsizes are * powers of two bytes (e.g. 20 bit samples use 32 bits). * This may be changed by the device's driver, or left at the * default (0) indicating protocol words are eight bit bytes. * The spi_transfer.bits_per_word can override this for each transfer. " Hence, round of n_bytes to a power of 2 to avoid values like 3 which would generate unalligned/odd accesses to memory/fifo. Fixes: a51acc2400d4 ("spi: dw: Add support for 32-bits max xfer size") Suggested-by: Andy Shevchenko Signed-off-by: Joy Chakraborty Reviewed-by: Serge Semin Tested-by: Serge Semin * tested on Baikal-T1 based system with DW SPI-looped back interface transferring a chunk of data with DFS:8,12,16. --- drivers/spi/spi-dw-core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c index ae3108c70f50..7778b19bcb6c 100644 --- a/drivers/spi/spi-dw-core.c +++ b/drivers/spi/spi-dw-core.c @@ -426,7 +426,10 @@ static int dw_spi_transfer_one(struct spi_controller *master, int ret; dws->dma_mapped = 0; - dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); + dws->n_bytes = + roundup_pow_of_two(DIV_ROUND_UP(transfer->bits_per_word, + BITS_PER_BYTE)); + dws->tx = (void *)transfer->tx_buf; dws->tx_len = transfer->len / dws->n_bytes; dws->rx = transfer->rx_buf;