Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp5355873rwi; Sun, 23 Oct 2022 04:51:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WrKRxgn9E03Hr8VS/UEDu38BKf3E8kGKdDWvxGOxOiETNeKCaZccc0d9N9kU8oH+Bv/6J X-Received: by 2002:a17:907:97c2:b0:78d:accc:c0a9 with SMTP id js2-20020a17090797c200b0078dacccc0a9mr22840510ejc.312.1666525899576; Sun, 23 Oct 2022 04:51:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666525899; cv=none; d=google.com; s=arc-20160816; b=DdNdGWXh3YerMtRFBB2cfxJBP2pPkzU0zeyuBXhg+FklVTCD4p1i2GNBfF/Sfor+EI tMBselKNyaGbb/bX1O0G612skpgXhS5MwPZkprfyTQEl468jS9ZhJiJdDtCaSK3YxaOJ KGxvhRwf90ZHX2dICCKD22B4mPVg+eztuOETF5rR9cZosw7v5hl1YX7uNmW0+zUEGQah zWB/uFlugf+tdMwP2vUUOqpSHoh8dP/AYhM+AwhifaFVgO8GKZjjFUT3+p0dem25ePU8 gxyy6kLRwCst3nRONVSJ1GgdsaxwJXizZval7k7Q12s+roqbq1Flm+YAXd/lnwlFVcQE 49zw== 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:subject:cc:to:from:date :dkim-signature; bh=Bx9gJ4PIjzpylfjUm9iFpMaKu5IokgCR+nI5Le4GaUY=; b=lv/DZQD0jg/yho+Xs3tkbtlfTh9UrVQixBS9rwtgRjqJ+UdVdV8JjN8tVHNDAvtubk Hj5hOFpUCt7cAiqFL6RroA74LuFE7tuv/7JmJub1vfcyBQVUhdU1/U/LcxFp3njRzIQm Mx8nDYg5cNwrXMlKRyUBV3aocy72q6PlVGRsUeM3JA9X16SNm0h6Y6Lsx4NpjusCl1Zy WJfBc1CBlGpMH1RFbDZEZR8lqvduF6MGBD2gEZmZUQITdI2+p3IWuzexYiztNkuwOYsG ALjrGCkn7C7+F2RpJfYwR2KiDjK5rPeep+u3Ht/T8c+xTDqO3IYcZE5wov16npSnButG xi2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NYPN8VkG; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g11-20020a1709065d0b00b007a4feae7adesi1691964ejt.837.2022.10.23.04.51.12; Sun, 23 Oct 2022 04:51:39 -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=@kernel.org header.s=k20201202 header.b=NYPN8VkG; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230322AbiJWK4j (ORCPT + 99 others); Sun, 23 Oct 2022 06:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbiJWK4h (ORCPT ); Sun, 23 Oct 2022 06:56:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37B635A8DB; Sun, 23 Oct 2022 03:56:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A888B60B61; Sun, 23 Oct 2022 10:56:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D14D3C433C1; Sun, 23 Oct 2022 10:56:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666522596; bh=lyTdIKeZjwi6PoGVvjTDLmW7YJbAZtMOfj7JmOF6Gmw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NYPN8VkGrvo19tKNOorOnl8MKQZvblC5h8iXLPadyri41aTPyDui7E+JY5laKk+DL HLXoCzTDhLStJFiOsTWS7Ncr1r0Q1BZF8UMrxr8FSNQw10fyEnSJvTK9KVZipqgMvu Pm06NM/KwM3bDnwN6EgJ5sg+pW6tCqZcRnCOZ3HBg5qOnzkoejcMbW072nABaLReYu mx60T4xZD0Lx1O0iMQEHmgnQ0Pbc4lwiMYYdl2OZ0wlBlNfEKSUk3/FlhgO4qHfiUT gdTCJn9FaCuXP6NgrgH/Q35es00kmSD38ewz/SOd9ZOWo/MCEdOnPw5IlbI+dJeBFy MqZCizIzCf3Tg== Date: Sat, 25 Jun 2022 14:32:53 +0100 From: Jonathan Cameron To: Andy Shevchenko Cc: Cosmin Tanislav , Rob Herring , Linus Walleij , linux-iio , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , devicetree , Cosmin Tanislav Subject: Re: [PATCH v5 2/2] iio: adc: ad4130: add AD4130 driver Message-ID: <20220625143253.0c022fcd@jic23-huawei> In-Reply-To: References: <20220620162059.1097264-1-cosmin.tanislav@analog.com> <20220620162059.1097264-3-cosmin.tanislav@analog.com> <2aa93eab-de6d-866b-a829-36b47ff00982@gmail.com> <54bfff70-938f-16e1-198d-47ed9ba95db4@gmail.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DATE_IN_PAST_96_XX, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 On Thu, 23 Jun 2022 19:33:45 +0200 Andy Shevchenko wrote: > On Thu, Jun 23, 2022 at 6:14 PM Cosmin Tanislav wrote: > > On 6/23/22 18:39, Andy Shevchenko wrote: > > > On Thu, Jun 23, 2022 at 5:27 PM Cosmin Tanislav wrote: > > >> On 6/20/22 21:29, Andy Shevchenko wrote: > > >>> On Mon, Jun 20, 2022 at 6:27 PM Cosmin Tanislav wrote: > > ... > > > >>>> + /* > > >>>> + * DMA (thus cache coherency maintenance) requires the > > >>>> + * transfer buffers to live in their own cache lines. > > >>>> + */ > > >>> > > >>> This is a good comment, but what fields does it apply to? > > >> > > >> Whatever is below it, grouped together. This is not hard to > > >> understand. > > > > > > It's hard to understand what exactly is DMA-aware here. I see only one > > > buffer that is aligned properly for DMA, the rest are not, except the > > > case if all of them are going in one DMA transaction. Is this the case > > > here? > > > > > >>>> + u8 reset_buf[AD4130_RESET_BUF_SIZE] __aligned(IIO_DMA_MINALIGN); > > > > > > This is aligned. > > > > > >>>> + u8 reg_write_tx_buf[4]; > > > > > > This one is aligned + offset (== AD4130_RESET_BUF_SIZE + 0). > > > > > >>>> + u8 reg_read_tx_buf[1]; > > > > > > This one is aligned + offset (== AD4130_RESET_BUF_SIZE + 0 + 4). > > > > > >>>> + u8 reg_read_rx_buf[3]; > > > > > > This one is aligned + offset (== AD4130_RESET_BUF_SIZE + 0 + 4 + 1). > > > And this is Rx. > > > > > >>>> + u8 fifo_tx_buf[2]; > > > > > > Here is Tx again which is most likely is not aligned... > > > > > >>>> + u8 fifo_rx_buf[AD4130_FIFO_SIZE * > > >>>> + AD4130_FIFO_MAX_SAMPLE_SIZE]; > > >>>> +}; > > > > > > > This has been mentioned before by Jonathan as a reply to V6 of my > > AD74413R driver. > > > > > I'm surprised I didn't mention this before but you only need to > > ensure > that any memory used for DMA is not in a cacheline with memory > > used > > > for other things that might change concurrently. > > > > To my understanding, as long as the DMA buffers will all be accessed by > > the same DMA-compatible SPI controller, you only need to align them so > > they're not in the same cacheline with memory that will not be accessed > > by the SPI controller. > > SPI is synchronous by nature, what will happen if the Tx and Rx > buffers are sharing the same cache line? Anybody to shed a light here? > > (I.o.w. I'm not sure that we don't need to split the Rx and Tx buffers > of the same transfer.) My understanding is that any device that stamps on itself is considered broken and needs to do it's own bounce buffering. We just need to ensure no CPU writes hit stuff in the same cacheline whilst DMA is in progress. A clarification to the comment to say that it covers all the buffers at the end of the structure would be a good addition. Jonathan