Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4584769ybg; Mon, 8 Jun 2020 11:31:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7JqqFEPrup9KVRAMKm2mUfjIqRWNNHAZYcUmVdPmes1uFOfPAovChxqRVJ2aMOJp35rzx X-Received: by 2002:a17:906:1088:: with SMTP id u8mr15624961eju.428.1591641060541; Mon, 08 Jun 2020 11:31:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591641060; cv=none; d=google.com; s=arc-20160816; b=I0/XsUdSTilR5Ua3aHUisPgitpix0EPaYavgaxLNzDtBDbHJREFOFmdcObCLKKRG0q r0RfXChu8f73qgdzuBi5PiDbaHQ7OK0qIQLhcoI68H03PiC5qhkC1KkcLw7vSTyTqw7N 8gfJ5PST1pu7hCGLu7Vnwl1DqJ9gqRh3PTDHWqLeUEOih9Ba0svVIYPm4lOUOmG7/pvb QRGSMs4VlFTBk+emu6ow80hiBOj1FCD6l2N0sNLueSeBriBwvAszNmgrsnevrQ5Adnup Vn0+OWK+mFnfREf6MJIHXYsR7sCUdenMsZOKA4Lg4+QqNJvEbuAsZRm93TjFo2ZObcIH 40cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=R7jXQTiwNbdbx++CCng3unnrFCOel7FKX095xysUOZw=; b=V787caydIg0CRAcZQNoClasZ2tjUcbCFWyOve5LQesXQswX3FF/8/U7R3HyIC+ALl3 KiEEjhyvmVdF+7gLLjxlf3jBtQeZSfadV6RmwJcDc49PUk7R/TKBSAQmGdu97d+t9Xt2 Dh9EIw6yKO4fRLq76IYD9ppnSzYy8lZyuIOCWVyCWRajCUjqRwQVIyYiwp0MFhmcIXqJ QyfHkXf8V5Ey1VzWnDTL7gyhIzOa4ftsy7Y/Ru+lXrEZMoW4w9JUaiGC1QTlCTIt8Pkp xic3JfDHPkjsJ3+KuH6oPowtqRmS4mJRClok9sLZqSMxKh5p/Rt1XJyjHkwbFlQtD6sc xZUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z3si103186eja.429.2020.06.08.11.30.37; Mon, 08 Jun 2020 11:31:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730635AbgFHQod (ORCPT + 99 others); Mon, 8 Jun 2020 12:44:33 -0400 Received: from foss.arm.com ([217.140.110.172]:55066 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730583AbgFHQob (ORCPT ); Mon, 8 Jun 2020 12:44:31 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8326A1FB; Mon, 8 Jun 2020 09:44:30 -0700 (PDT) Received: from [10.57.9.113] (unknown [10.57.9.113]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A3CB63F73D; Mon, 8 Jun 2020 09:44:25 -0700 (PDT) Subject: Re: [PATCH v9 RESEND 01/13] spi: imx: add dma_sync_sg_for_device after fallback from dma To: Mark Brown , Robin Gong Cc: "mark.rutland@arm.com" , "devicetree@vger.kernel.org" , "matthias.schiffer@ew.tq-group.com" , "martin.fuzzey@flowbird.group" , "catalin.marinas@arm.com" , "s.hauer@pengutronix.de" , "will.deacon@arm.com" , "linux-kernel@vger.kernel.org" , "linux-spi@vger.kernel.org" , "vkoul@kernel.org" , "robh+dt@kernel.org" , dl-linux-imx , "festevam@gmail.com" , "u.kleine-koenig@pengutronix.de" , "dmaengine@vger.kernel.org" , "dan.j.williams@intel.com" , "shawnguo@kernel.org" , "kernel@pengutronix.de" , "linux-arm-kernel@lists.infradead.org" References: <1591485677-20533-1-git-send-email-yibin.gong@nxp.com> <1591485677-20533-2-git-send-email-yibin.gong@nxp.com> <20200608143458.GH4593@sirena.org.uk> <20200608153139.GI4593@sirena.org.uk> From: Robin Murphy Message-ID: <59ce3620-00b9-bac1-30e1-011a29583642@arm.com> Date: Mon, 8 Jun 2020 17:44:21 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200608153139.GI4593@sirena.org.uk> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-08 16:31, Mark Brown wrote: > On Mon, Jun 08, 2020 at 03:08:45PM +0000, Robin Gong wrote: > >>>> + if (transfer->rx_sg.sgl) { >>>> + struct device *rx_dev = spi->controller->dma_rx->device->dev; >>>> + >>>> + dma_sync_sg_for_device(rx_dev, transfer->rx_sg.sgl, >>>> + transfer->rx_sg.nents, DMA_TO_DEVICE); >>>> + } >>>> + > >>> This is confusing - why are we DMA mapping to the device after doing a PIO >>> transfer? > >> 'transfer->rx_sg.sgl' condition check that's the case fallback PIO after DMA transfer >> failed. But the spi core still think the buffer should be in 'device' while spi driver >> touch it by PIO(CPU), so sync it back to device to ensure all received data flush to DDR. > > So we sync it back to the device so that we can then do another sync to > CPU? TBH I'm a bit surprised that there's a requirement that we > explicitly undo a sync and that a redundant double sync in the same > direction might be an issue but I've not had a need to care so I'm > perfectly prepared to believe there is. > > At the very least this needs a comment. Yeah, something's off here - at the very least, syncing with DMA_TO_DEVICE on the Rx buffer that was mapped with DMA_FROM_DEVICE is clearly wrong. CONFIG_DMA_API_DEBUG should scream about that. If the device has written to the buffer at all since dma_map_sg() was called then you do need a dma_sync_sg_for_cpu() call before touching it from a CPU fallback path, but if nobody's going to touch it from that point until it's unmapped then there's no point syncing it again. The my_card_interrupt_handler() example in DMA-API_HOWTO.txt demonstrates this. Robin.