Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3328936rwa; Tue, 23 Aug 2022 02:58:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR4z1yreYSw/8xRcAItSxLVRzCzu7k6TJMGHBojS1SGElmuKy8u8lgbYChlYNnL3CS3WSrzH X-Received: by 2002:a17:907:2da6:b0:730:8b30:e517 with SMTP id gt38-20020a1709072da600b007308b30e517mr15934368ejc.291.1661248719224; Tue, 23 Aug 2022 02:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248719; cv=none; d=google.com; s=arc-20160816; b=UfDR7Taw2q7gk9BN/zgX8jCKWar+y5jbmJnEKALm8XqN892D6f7VwtQw7H9SGK/L7x KWvWd53YLwHs3RgihHEN9ls4FEMZ6CixOJnbNiRSg5v98pNDIitaKWlyNRBOni6dQx/i InWA3tLOCIwbkhdVVBxyQ+NTvUt5yZAZgTYMGBiXBDfpqg7KqrwZ3XL8qFV35FcOev63 bjyCC4AScz3Uz5sPWSjZewbKIa28876Lwny+JIQ4vQTEE3Lsaku7/GLAZeqvczl2JhSL GFJzTaetaZw2F5QUyjkqWouNDbikMzkjSlthsEZUbk/+8LNSIBX/dM5JoramDAtO6nNn We0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=IC7JOGzQ5bSfE4hm5u1U5+6t0XUtDUmoLjxT3XW/jHU=; b=hKrPMOiMWmqyh5LRa2yxZNBJrM/5oZQQ032fVLmnRXkIvnaJypIG++TDofdsHkqwZh va9hfuvHsdYxtO8VOhyNe1TXiyCy34lBAxd54pgpirSiUMfAhVfKlo+tRw2LiRp6DJwV tGCwOPJRXf4BR3i4RWqfT6Gs9dFOErWeUDmC3e+EKlIrjMAZRVg1xYeYZPXwSSaAmexl VfUkaAteLopho6BxYlBso6ueSRjSOerSbeAuvkgbsz6bg+7zbO7w9F5KKQ6ejAxAyfWR dEgvIepQvo8fMRYwVZ72ekylFFC3rjGBF4S5iLrh2jrp0uYROPEOXM8mQXL6mXg0QDLF ZkuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=GGpm6cPT; 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=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a056402520300b0044202417985si712791edd.108.2022.08.23.02.58.12; Tue, 23 Aug 2022 02:58: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=@collabora.com header.s=mail header.b=GGpm6cPT; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241817AbiHWJmC (ORCPT + 99 others); Tue, 23 Aug 2022 05:42:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351651AbiHWJj6 (ORCPT ); Tue, 23 Aug 2022 05:39:58 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EC6C42AE7; Tue, 23 Aug 2022 01:41:23 -0700 (PDT) Received: from [10.3.2.13] (zone.collabora.co.uk [167.235.23.81]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 9A9CB660035D; Tue, 23 Aug 2022 09:40:01 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1661244002; bh=ZlOOvApFGOMbPEfDLhpmrwlUuzkzliB2kc8cG9m2hAg=; h=Date:Subject:To:References:From:In-Reply-To:From; b=GGpm6cPToGVjt2TGPzDVJggwpmq33yQmIW/tSS7VUXeTRxiX7iAGnXdAP7p8t7v2k AU1lXN3llCeQoREhm59iyYyL25HiRUsz1EUv3K/0/1DkHpgIrG+qvOZkIYpLv7u16F NcbfYIiuU/Y+oGUiEGPLqoM5bgT1IaHbczVevsOvMyh1in620AwNkB2FXKOHaI7T2W VY073ruGl62M7bSH/m1bgLwpxeFDX8y1/CFpO+zczh0adSWeGSMVaGlmBu4hCabqrw oBzARqDj9ActJfLP1p0A+K7+A6avRKpOytE6V6k9/3WA8R4nhJ5C6g/0IPEYGkXDPh 3J8NJFPvjGj1w== Message-ID: Date: Tue, 23 Aug 2022 11:39:56 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH RESEND 1/2] i2c: tegra: Add GPCDMA support Content-Language: en-US To: Akhil R , Dmitry Osipenko , "robh+dt@kernel.org" , "devicetree@vger.kernel.org" , "christian.koenig@amd.com" , Jonathan Hunter , Laxman Dewangan , "linux-i2c@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-tegra@vger.kernel.org" , "sumit.semwal@linaro.org" , "thierry.reding@gmail.com" , "wsa@kernel.org" References: <20220819122313.40445-1-akhilrajeev@nvidia.com> <20220819122313.40445-2-akhilrajeev@nvidia.com> <20281ca7-e597-7030-4861-5f9a3594726d@gmail.com> <89a746fd-a98e-3147-7811-33c5051c2b6d@gmail.com> From: Dmitry Osipenko In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 8/23/22 08:17, Akhil R wrote: >> 22.08.2022 23:33, Dmitry Osipenko пишет: >>> 22.08.2022 13:29, Akhil R пишет: >>>>> On 8/22/22 09:56, Akhil R wrote: >>>>>>> 19.08.2022 18:15, Dmitry Osipenko пишет: >>>>>>>> 19.08.2022 15:23, Akhil R пишет: >>>>>>>>> if (of_device_is_compatible(np, "nvidia,tegra210-i2c-vi")) >>>>>>>>> i2c_dev->is_vi = true; >>>>>>>>> + else >>>>>>>>> + i2c_dev->dma_support = !!(of_find_property(np, "dmas", >>>>>>>>> + NULL)); >>>>>>>> >>>>>>>> 1. You leak the np returned by of_find_property(). >>>>>>>> >>>>>>>> 2. There is device_property_read_bool() for this kind of >>>>>>>> property-exists checks. >>>>>> Okay. I went by the implementation in of_dma_request_slave_channel() to >>>>>> check 'dmas'. >>>>>> >>>>>>>> >>>>>>>> 3. If "dmas" is missing in DT, then dma_request_chan() should return >>>>>>>> NULL and everything will work fine. I suppose you haven't tried to >>>>>>>> test this code. >>>>>>> >>>>>>> Although, no. It should return ERR_PTR(-ENODEV) and then you should >> check >>>>>>> the return code. >>>>>> Yes. Agree that it is more agnostic to check for ERR_PTR(-ENODEV). But >> since I >>>>>> call tegra_init_dma() for every large transfer until DMA is initialized, >> wouldn't >>>>>> it be better to have a flag inside the driver so that we do not have to go >>>>> through >>>>>> so many functions for every attempted DMA transaction to find out that >> the >>>>> DT >>>>>> properties don't exist? >>>>>> >>>>>> Shall I just put i2c_dev->dma_support = true here since DMA is supported >> by >>>>>> hardware? It would turn false if dma_request_chan() returns something >> other >>>>>> than -EPROBE_DEFER. >>>>>> >>>>>> if (of_device_is_compatible(np, "nvidia,tegra210-i2c-vi")) >>>>>> i2c_dev->is_vi = true; >>>>>> + else >>>>>> + i2c_dev->dma_support = true; >>>>> >>>>> The code already has dma_mode for that. I don't see why another variable >>>>> is needed. >>>>> >>>>> Either add new generic dma_request_chan_optional() that will return NULL >>>>> if channel is not available and make Tegra I2C driver to use it, or >>>>> handle the error code returned by dma_request_chan(). >>>> >>>> Let me elaborate my thoughts. >>>> >>>> The function tegra_i2c_init_dma() is also called inside tegra_i2c_xfer_msg() if >>>> DMA is not initialized before, i.e. if (!i2c_dev->dma_buf). >>> >>> This is not true >>> >>> i2c_dev->dma_mode=false if !i2c_dev->dma_buf and that's it >>> >>> https://elixir.bootlin.com/linux/v6.0-rc2/source/drivers/i2c/busses/i2c- >> tegra.c#L1253 >>> >>> tegra_i2c_init_dma() is invoked only during probe >>> >>>> So, if suppose there is no DT entry for dmas, the driver would have to go take >> the >>>> path tegra_i2c_init_dma() -> dma_request_chan() -> of_*() apis -> ... and >> then figure >>>> out that DMA is not supported. This would happen for each transfer of size >> larger than >>>> I2C_PIO_MODE_PREFERRED_LEN. >>>> >>>> To avoid this, I am looking for a variable/flag which can indicate if the driver >> should attempt >>>> to configure DMA or not. I didn't quite get the idea if dma_mode can be >> extended to support >>>> this, because it is updated based on xfer_size on each transfer. My idea of >> i2c_dev->dma_support >>>> is that it will be constant after the probe(). >> >> I see now that it's you added tegra_i2c_init_dma() to >> tegra_i2c_xfer_msg(). And tegra_i2c_init_dma() already falls back to PIO >> if DMA is unavailable. >> >> I don't remember why !IS_ENABLED(CONFIG_TEGRA20_APB_DMA) was added >> to >> tegra_i2c_init_dma(), but if dma_request_chan() returns -EPROBE_DEFER >> when there is no DMA channel available at all, then you should fix it. >> >> Trying to initialize DMA during transfer if it failed to initialize >> during probe is a wrong approach. DMA must be initialized only once >> during probe. Please make the probe to work properly. > > What I am trying for is to have a mechanism that doesn't halt the i2c transfers > till DMA is available. Also, I do not want to drop DMA because it was unavailable > during probe(). Why is it unavailable? Sounds like you're not packaging kernel properly. > This situation is sure to hit if we have I2C driver as built in and DMA driver as a > module. In such cases, I2C will never be able to use the DMA. For Tegra I2C built-in + DMA driver module you should add the dma.ko to initramfs and then it will work. This is a common practice for many kernel drivers. It's also similar to a problem with firmware files that must be available to drivers during boot, > Another option I thought about was to request and free DMA channel for each > transfer, which many serial drivers already do. But I am a bit anxious if that will > increase the latency of transfer. Perhaps all you need to do is to add MODULE_SOFTDEP to Tegra I2C driver like we did it for the EMC driver [1]. [1] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=14b43c20c283de36131da0cb44f3170b9ffa7630 -- Best regards, Dmitry