Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp644989rwl; Wed, 29 Mar 2023 06:49:21 -0700 (PDT) X-Google-Smtp-Source: AKy350b8FLyG1vldWTT1rFTdg96uCV/zFBV3jUrKeo7GL+6aYZUXxSjoxU9hpol4ryoaDE4BQnxX X-Received: by 2002:a17:90a:4bca:b0:23d:2d91:ab71 with SMTP id u10-20020a17090a4bca00b0023d2d91ab71mr20716161pjl.6.1680097761216; Wed, 29 Mar 2023 06:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680097761; cv=none; d=google.com; s=arc-20160816; b=wFybufuackjJl2/MT+EKH6mos0nKPkd4QVWZAAvg5lPvmMNms4xEOgJJk5UVBQ1/Xj zYe4AxN/ogebKsC2U4RR6EPWx24bS4J9JeHmDJlGv7MTEpVESx+wCWUkwI/AjV4UCN9Z 1e5+OTuMFUj/Bs6lBmzfNdCoP9Axmc1v3zHQDJuxKBvuKWqas4Tsg7rfeoMf03kSeHIX HIlzy5/xcInN7biXu5m12f8gUj2P/smjd5jI0vEiW3P7Hu3A/Tk+Bw/nCBw6trjjw7dQ R7dVaSdo/jx4lO7r57CCk6OD1Nf04z+eVExpsjkW8dmvG2ucx6zAE5vwa22U/hIWC3ya lYCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xs3l8xHeQN0QhWBPHkIY5Muif5eQvC6Mk/I7Rd6Zf28=; b=s+IxrYwyeQArVwJ8pz9o1MpE3PqVWNcAt0p1JwanlD6yMdkBOlGj4TbrRCWgeRGNVZ /e0Z/4nWxrrfFOkg0tDnjcxfw6JxPCpJ6iTcO3yuvtSEpnf/1dc9VsSEt3ubqy5KNbPz PtFtmR9/h9rEIo+jeDrTtrHSgWnoaLFBafXbNDH9hXWweSA+k8pPuuRyBTFVR5urA9AV hnimCxylojt9xfCKgeLfK7AMuzcgBeHFPyJPMEkUdPT0XGd9iERaRiz03f8DufDdEHqM HOq8m02y/5FeSqmY25iY5DPretxdD4AZDp1BqlSHhDidl2Kh1Hq2xjAxI1z6ZEEah1lM UZVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jZw+rW3Y; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx2-20020a17090b4b0200b0023d2847e355si1634456pjb.0.2023.03.29.06.49.09; Wed, 29 Mar 2023 06:49:21 -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=@gmail.com header.s=20210112 header.b=jZw+rW3Y; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbjC2Nfm (ORCPT + 99 others); Wed, 29 Mar 2023 09:35:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbjC2Nfk (ORCPT ); Wed, 29 Mar 2023 09:35:40 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16C094EEF; Wed, 29 Mar 2023 06:35:32 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id 20so16183658lju.0; Wed, 29 Mar 2023 06:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680096930; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=xs3l8xHeQN0QhWBPHkIY5Muif5eQvC6Mk/I7Rd6Zf28=; b=jZw+rW3YMHX6RRst6QgAfrweHt+DdeVRxGSxoB82qXyjy4Hulym29aWz22gRN4ZMKN YmHKZiy+nHrylSZi8w8FYIy8kUWoR6UNHj/V2iFKvZxuf3xY421uTHK5asEWkrOqC9Qq 7Febh7ITJOt92exuBphLlmBlk/6wL9L2E0Uyoaf26ETtFVouypjfCh/Gnvy69BhT0RLv bsqbZvuNAjiQ1JvwxTTCEDMCMd66zJnDLc4BZ9UuXJM6daKHnFANxbzWChBZ/5bv73MA 8z6m27+VskjVmjoIaGf/itTfdnNYkH0qkEfqq5Dfb0gfCYPwH1c4+n1QEqLeO9yKFfRS hLHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680096930; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xs3l8xHeQN0QhWBPHkIY5Muif5eQvC6Mk/I7Rd6Zf28=; b=OzAulT3ultrw54pA7DCp7LD0la201oVubLqNVVJdjJyeUl3epnaH6YdYE9IUcx2SvS oRsTHMS9AVy8ccEtDrKCxf205I3ZAqNCvHHEYnHBXCTFroB6TRQv5Y+Hv7Hq7RewKK7A E9jXCmDnUKYBAxbTh6TbYRpNabq3RHOymesesaan+5VK33HcoJsEvRJj4wGYsv7Y0qw0 /7bCJKF6LXvlXMLBjNxWLeeywpojX4MvKFNIdiZVazSPIJL380yUyJ6vgCx/w8hCNTqj Voe8UmgqpbPojHDsCbcjdNlfluTwA8lg4ausQodnNsLrbfInOj4I5YLuW8tKUKwpoV7r sDMA== X-Gm-Message-State: AAQBX9dZVR5KN2z+aAN6vUI1o/m/qgIEO6RC/YowQYRRK6gk/g0tLSS6 3CpkzOPVf9rrN6+74jAB1ZU= X-Received: by 2002:a2e:9593:0:b0:29e:8a51:35d4 with SMTP id w19-20020a2e9593000000b0029e8a5135d4mr5748774ljh.12.1680096930164; Wed, 29 Mar 2023 06:35:30 -0700 (PDT) Received: from mobilestation ([95.79.133.202]) by smtp.gmail.com with ESMTPSA id v18-20020a2e9252000000b002934abfb109sm5520370ljg.45.2023.03.29.06.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 06:35:29 -0700 (PDT) Date: Wed, 29 Mar 2023 16:35:27 +0300 From: Serge Semin To: Joy Chakraborty Cc: Mark Brown , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, manugautam@google.com, rohitner@google.com Subject: Re: [PATCH v4 2/2] spi: dw: Add dma controller capability checks Message-ID: <20230329133527.wa7u3osht7tfl47x@mobilestation> References: <20230327043405.881645-1-joychakr@google.com> <20230327043405.881645-3-joychakr@google.com> <20230328180338.bpxvjwx4tn4ter3f@mobilestation> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, 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 On Wed, Mar 29, 2023 at 09:26:47AM +0530, Joy Chakraborty wrote: > Hi Serge(y), > > On Tue, Mar 28, 2023 at 11:33 PM Serge Semin wrote: > > > > On Mon, Mar 27, 2023 at 04:34:05AM +0000, Joy Chakraborty wrote: > > > Check capabilities of DMA controller during init to make sure it is > > > capable of handling MEM2DEV for tx channel, DEV2MEM for rx channel > > > and store addr_width capabilities to check per transfer to make sure the > > > bits/word requirement can be met for that transfer. > > > > > > Signed-off-by: Joy Chakraborty > > > --- > > > drivers/spi/spi-dw-dma.c | 54 ++++++++++++++++++++++++++++++++-------- > > > drivers/spi/spi-dw.h | 1 + > > > 2 files changed, 44 insertions(+), 11 deletions(-) > > > > > > diff --git a/drivers/spi/spi-dw-dma.c b/drivers/spi/spi-dw-dma.c > > > index b3a88bb75907..f47483ec369f 100644 > > > --- a/drivers/spi/spi-dw-dma.c > > > +++ b/drivers/spi/spi-dw-dma.c > > > @@ -23,6 +23,8 @@ > > > #define DW_SPI_TX_BUSY 1 > > > #define DW_SPI_TX_BURST_LEVEL 16 > > > > > > +static enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes); > > > + > > > static bool dw_spi_dma_chan_filter(struct dma_chan *chan, void *param) > > > { > > > struct dw_dma_slave *s = param; > > > @@ -72,12 +74,15 @@ 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) > > > { > > > > > + int ret; > > > struct dma_slave_caps tx = {0}, rx = {0}; > > > > 1. Preserve the reverse xmas tree order please (driver local convention). > > 2. The zero-initialization can be dropped since the function will halt > > on further procedures if any of the dma_get_slave_caps() calls fail. > > Meanwhile if all of them are successfully executed the capability > > structures will be sanely initialized. > > > > Sure, will update > > > > > > > - dma_get_slave_caps(dws->txchan, &tx); > > > - dma_get_slave_caps(dws->rxchan, &rx); > > > > > + ret = dma_get_slave_caps(dws->txchan, &tx); > > if (ret) > > return ret; > > < newline > > > + ret |= dma_get_slave_caps(dws->rxchan, &rx); > > > + if (ret) > > > + return ret; > > > > No OR-ing the errnos please. They aren't bitfields. > > Sure, I will update this. > In this case do you think we need an error print here to differentiate > which slave caps failed ? No. dw_spi_add_host() will inform (dev_warn()) about the DMA-initialization failures. Printing something besides of that won't help much since in any case an additional debugging would be necessary. > > > > > > > > > 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 +92,18 @@ 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; > > > + > > > + /* > > > + * Assuming both channels belong to the same DMA controller hence the > > > + * address width capabilities most likely would be the same. > > > + */ > > > + dws->dma_addr_widths = tx.dst_addr_widths & rx.src_addr_widths; > > > + > > > > > + if (!(tx.directions & BIT(DMA_MEM_TO_DEV) && > > > + rx.directions & BIT(DMA_DEV_TO_MEM))) > > > + return -ENXIO; > > > > Please move this to be right after the capabilities are retrieved. > > There is no point in the SG-burst and addr-width data initializations > > if a DMA-controller isn't suitable for the Tx/Rx DMAs. > > On second thought I see that dma_get_slave_caps already checks if > direction exists in dmaengine.c: > ... > int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps) > ... > if (!device->directions) > return -ENXIO; > ... > But it does not check the capability w.r.t the type of channel i.e. > tx/rx , so we can keep this check as well. Right. dma_get_slave_caps() doesn't check the particular channel dir capability which is essential for us in this case. So please keep the directions check here. > Either Way, in case we keep it I shall move this as you suggested. Ok. Thanks. -Serge(y) > > > > > -Serge(y) > > > > > + > > > + return 0; > > > } > > > > > > static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) > > > @@ -95,6 +112,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 +142,24 @@ 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 +185,16 @@ 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; > > > @@ -202,8 +228,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 enum dma_slave_buswidth dw_spi_dma_convert_width(u8 n_bytes) > > > 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; > > > -- > > > 2.40.0.348.gf938b09366-goog > > > > > Thanks > Joy