Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp238322ybg; Mon, 8 Jun 2020 22:23:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2JajqkMm8vrvJwOWn644Mm97QJIzZUFuL77wV+/aNd0OGvAjl8F5i49naatIc2+OwORH0 X-Received: by 2002:a17:906:4310:: with SMTP id j16mr22911146ejm.511.1591680227555; Mon, 08 Jun 2020 22:23:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1591680227; cv=pass; d=google.com; s=arc-20160816; b=seT1Tk0/VJtzsHQn0/sMj1gqsCNQWNUC670TjzXETTVqcIN6I+95KbGJ9GUSlURzw5 aWa90/68rSGYOIas6xBiCoIzfAxYkV3MO8AShToJkptH1tKyKDVA0Y4sgvP0lso3vEM2 QXCY46hQnCjW/lH05t2KK7DiQ/Z14mGscKfpXhtRHTnHJc8LoONhD2m+kNkaYsf54l6F IFXxuFPyXbmiLfNSJacKZ3Q2P0RICEDtgfykg0K9wSiGoAzR0GLuZmLn5xLbv5JhbbL5 Zcuongf8vV4ANEHmEQAfwIEyLGcRvBPkcMHu1qIDVR8Xuc1/UbrrOU8q8DxW6cGn3L99 DZTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=yHkBw0HPxc+prr1W8elbO/t6RVzRCdRlO9wi82ahmio=; b=swy5uZ1MkwlNX+LvgFezWUIKgs2s2k1iXEeCatrBCc92DUjLsIAymUMC+dFQJMicaJ U+7jROtWMR2j0ZkARRBZPITc1DfBl7eb/tryoM/ArmngKuUSklRut4A0qkFi7fHmFct9 e1XrzEXS4UbAgDHve2u0f4E5O9NTVeZ9fpy32HIb8czX2MZy/9rmKEoRHSiNhNLTE2mY O9s1E+eESOxEAPELPTcz5szc1Ax/yLGywy23knJwZjsLOqTVPpOoDgGdyKvBYQVr25FR VnxhW6GpBftn3VOn+I+678mJUd/lLZgVszc/sY39GCVGRrVhr3HmlkDwTGQ883xFNVW7 dNNg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=ou2M7RFy; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si10497084edo.509.2020.06.08.22.23.24; Mon, 08 Jun 2020 22:23:47 -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; dkim=pass header.i=@nxp.com header.s=selector2 header.b=ou2M7RFy; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726924AbgFIFVL (ORCPT + 99 others); Tue, 9 Jun 2020 01:21:11 -0400 Received: from mail-eopbgr60048.outbound.protection.outlook.com ([40.107.6.48]:39953 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725770AbgFIFVK (ORCPT ); Tue, 9 Jun 2020 01:21:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JP7rUtXQfxCyot87oW+5qXkXhyWY16+Jke3B0MJbe3Rfpc3BBPUPiuvYaqWMoNjnHH4HtbFtQLqFx1d3gitQdTI3axZLWDHQMoiPF8DQ9oUP1n9hHnYbTjD1tK2WdbaAJkgOX4qbxcdt3NtajLpm/u4sOse1nnXRBhdqred8tNoh8zqu60tyB6gfCGrk4x6z/WWGn1LjDZWLEJka+K+NZHbpQ3odqP8j67OllUsK9zCD2715I8BYINqkZA8S5ocW1+ILGRFIqOI+dCbUw0ufCTyDMZ3n3VBPCb+MDW37s+0ZvkEU4lSpdOS8HY7VD4E8FC0V1urX5yMrvnFKYbCwIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yHkBw0HPxc+prr1W8elbO/t6RVzRCdRlO9wi82ahmio=; b=bUICbCJ4k6Kk30gR5QEKPgBWNAkGUs5mg+rhw73MBzLGsZgKmoanHje7WQIS161lxt6bxILhlvvdeBOc8kOfIYBz4fAUk7cPEvC1bOLYT0XCHG9bOW/FCK0HXKjIHFhypo8d0BVzx/6qBRIyWSjIyq9Jesbf3lBosL5M1mtTOHMuGcZ/wT4iptMTxcjeCGcsx16ONwRI0D3CwpiVr+7Yt7njKarBjo6rGi/oA7V9T/zCvHeAhI0gxLl59irPmFgoUA2JYYzFsoNIcP2HDvqwnU05PVtwswdx2jSMfhpX3rjbhxJ6rs5LhV/EcsX/Ejr4aDexjkOrGyP89EOOTBig7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yHkBw0HPxc+prr1W8elbO/t6RVzRCdRlO9wi82ahmio=; b=ou2M7RFyYpOHdh+p6qHmmHysqyiQZIdpNpUt+4O5AxIKisLflGHuOvVnXMCxIUdGP+43wgblMSi/O5Pab62C9OerXekcBw7ZoG6RE8GxO58E3Bh+6FkYxcLYddYg2UqDYu8bo6W3fkJTVKfHFVP0gOPDHfobMAgKbf3nvDbP7J0= Received: from VE1PR04MB6638.eurprd04.prod.outlook.com (2603:10a6:803:119::15) by VE1PR04MB6685.eurprd04.prod.outlook.com (2603:10a6:803:120::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Tue, 9 Jun 2020 05:21:04 +0000 Received: from VE1PR04MB6638.eurprd04.prod.outlook.com ([fe80::5cc4:23a5:ca17:da7d]) by VE1PR04MB6638.eurprd04.prod.outlook.com ([fe80::5cc4:23a5:ca17:da7d%6]) with mapi id 15.20.3066.023; Tue, 9 Jun 2020 05:21:04 +0000 From: Robin Gong To: Robin Murphy , Mark Brown 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" Subject: RE: [PATCH v9 RESEND 01/13] spi: imx: add dma_sync_sg_for_device after fallback from dma Thread-Topic: [PATCH v9 RESEND 01/13] spi: imx: add dma_sync_sg_for_device after fallback from dma Thread-Index: AQHWPBYcMy4ZpJEEjkym0JBjSJknZajOy8sAgAABToCAAA6IgIAAFFCAgACn/7A= Date: Tue, 9 Jun 2020 05:21:04 +0000 Message-ID: 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> <59ce3620-00b9-bac1-30e1-011a29583642@arm.com> In-Reply-To: <59ce3620-00b9-bac1-30e1-011a29583642@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=nxp.com; x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 4b0ad395-6309-44de-8f10-08d80c34e846 x-ms-traffictypediagnostic: VE1PR04MB6685: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 042957ACD7 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 2/lNHVr7dIMiPtQ8ub7DLLkN2z2SHr0IbK8WqUsUwy+s+hVtBgkLOZ4rn+Pp5wheI8RlVLx2THWpvLFRjINOtwpS7ibJNG0umcTyCK/ekV1eVwqpNfK/WysrusfKdilptJyHmOfSua8aWaUspqUiZdGBsGGsErhjPmqo6OtRcSSFb+Jd+qktUsAH79lKVj0Gwr+t5qsPmp2uIILQzYruhJM12udeAWzsnH7Uf7F+sljMFUlNXnJyL4TcftWeYC0FMBw2GElck543W6WOnxO9PQVAwwQ7SKc+NLCe+VW3dwLkKWDBm05sxt3Mx2/VMbyCOifrQ+mKesYl4/xPw3C2gA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR04MB6638.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(39860400002)(136003)(396003)(376002)(346002)(53546011)(76116006)(8676002)(2906002)(83380400001)(8936002)(71200400001)(55016002)(478600001)(33656002)(9686003)(5660300002)(66556008)(86362001)(186003)(26005)(54906003)(6506007)(7696005)(316002)(7416002)(110136005)(66476007)(4326008)(66946007)(66446008)(64756008)(52536014);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata: Q4lfBzB9Q21BwKqHejUWnW1aU2D8WxZuJwTpbEaGSsgUFZjD3VS1nEGPsn3DraJalKpyqHyMqU+jAvGIwjdmz2GXVGbp2Yc31hiJPzr9vVAvRogDQISFFiyTsvoXdDsX04NenInSynyFFmbNdSHRwpSHBa/3cTETHGP8BeLPklewFbLSfrLA9Mz2WFEWwxakfZhC0PUJg9Fklry7DlKcThmRdukzove/JJIUkFjC/N6MJXRYWwrKrshaGk7TW2hXxZgD3mGWV11BS5f1EvN7NEwrTC6SVksdCbI2Dm/tvp5cdLf7m/kDjquCPFs4eGhhZhevYxO2dZlZp0a9F4SZjqpvHsUCnYRTrYAa/Kq3/kQNe3y2lqeEhlGWw6AEP95C4+j22TzEZCTkDEdGph3OMLK9zLmQrWqxyAG+DMuyOPzRPFpUfAxirbneJvFer9LXoF8Q705PoQRez7kQWzZg5tYhkFJZ4PbVIo98Ssyz31Y= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b0ad395-6309-44de-8f10-08d80c34e846 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Jun 2020 05:21:04.6746 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: K0zgAiXkt4M9D8HiTrgFRM5+reDiPPdbu3QQvzHuVPZMC9iY7HndPduCbGYMPRO/LtqJlyfibDCQf8q3zM6WXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6685 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/06/09 0:44 Robin Murphy wrote: > 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 =3D 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 i= t 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. >=20 > Yeah, something's off here - at the very least, syncing with DMA_TO_DEVIC= E on > the Rx buffer that was mapped with DMA_FROM_DEVICE is clearly wrong. > CONFIG_DMA_API_DEBUG should scream about that. >=20 > If the device has written to the buffer at all since dma_map_sg() was cal= led > then you do need a dma_sync_sg_for_cpu() call before touching it from a C= PU > 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. Thanks for you post, but sorry, that's not spi-imx case now, because the rx= data in device memory is not truly updated from 'device'/DMA, but from PIO= , so that dma_sync_sg_for_cpu with DMA_FROM_DEVICE can't be used, otherwise= the fresh data in cache will be invalidated. But you're right, kernel warning comes out if CONFIG_DMA_API_DEBUG enabled.= ..=20