Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1563537rbb; Mon, 26 Feb 2024 13:33:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCURzpFlx/ltYK3MJ6yQUA/yT20HPA8ll66buiG+5qTgHw1B11M5ePLQ/oAi1aKcjMLKewHrqIT1CpAMcgkxF3y2tBtt78lUORgYEqTBdg== X-Google-Smtp-Source: AGHT+IGaQ8yHyeo5dh/2V6BUZGu/XwQ10VK0dzjFh0s6AGl1SQBphnG+VadzFDUPqLGoi4Va9+76 X-Received: by 2002:a9d:4b14:0:b0:6e4:7cd3:b3f5 with SMTP id q20-20020a9d4b14000000b006e47cd3b3f5mr8826925otf.22.1708983211971; Mon, 26 Feb 2024 13:33:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708983211; cv=pass; d=google.com; s=arc-20160816; b=iYdcBUokbXkJc54OivzSZb1Jha31uHYDzs9PP9LnvRvrobfWTot5lkrrynkxrJEKAk mFu7QVcgh8MR3ezeHLgOWe+Vp20mkgkaMZjccL7nuHfSJiWcZCJoY6kDdJ8lT3xwiwXH z+Y8qsGttFA/genpyg84MOiA5Dm+NM8GOxJy2cpQRHxcuQbVHg+YDYcA9NLlwLYdDSJb Fm8f/ApzILU3dLKfDrBnTp9T/3lP8ZJc5MawoFHrCZFEeNRDw/TycL9gsBb3XhS3mEB+ auLuRMNkOKHDAK0gEjtrhC7qMP8SMLqaRwW03oLftLh+x3aB6NorhlWqfjrmC9ZOMiDr YeGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=i8xzxpmRfOYpMJXfjSv2//ub/SLcVqWsue/aaIwJmAc=; fh=hABCJIAEPCoMLcpouWT1rO5IBTfIlCIiPHjYHaMaISo=; b=ww/mZuuFcQ26AzKX+SHP6e0l9hBpbjf+CxN0jyi+G5qctfkGimtuShxUkbPUoOO81T EknI426rG0BHTvwNnQYuAJprrMrqxjROG22HMkZ6xEnRGR0ToCHWKvfYvBrHci9pimvG kxdH9ulV9Eia/EwlShpZ0qUUO9d70PSMuN+ZWMxuAvFtEZKem70cmDH30AR0TYnxYypk DW3nVYnrhJtJB1GHlQ830CYe0PR6675WcXvz3nFFv3BRSyZu7wUH7uxYcY7/OziX13a2 y0qspKRlsT9YUkjBk6xDYZIDAjpc7cRvJND8qUjKVpEyQUDksyfu9Ni5dzq7GjX0mPpq Ji+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FQKriiat; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-82352-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82352-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l7-20020a635707000000b005cfda2f9e48si4338843pgb.860.2024.02.26.13.33.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:33:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82352-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FQKriiat; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-82352-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82352-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9FCA028E84A for ; Mon, 26 Feb 2024 21:33:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6298132C02; Mon, 26 Feb 2024 21:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FQKriiat" Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3566131E40; Mon, 26 Feb 2024 21:32:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983170; cv=none; b=TynX7SBOASm6GdBPMvDrryImELP4+KOxyRbCCRPKNa1jr8lgvw4bDimDngKLGXXOAhAdWMRPiHjoBUQs9F2Z5a/9E9G6EbApxqPcz8lvWTI48k4RyydxVlGu8P17iTE1yBtZtLlBF5CHgga2F41cSHlcvw6I7GVi8JQIcjH7co0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708983170; c=relaxed/simple; bh=6jYoQspdkHGJLK0YUMFQ1JcVi1hhQ8mEQbVyui8iIj4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uuBGmZFFQ4m2tv2ybp4zpGt8FPYBAeStjgov52RByFit3JwbbM1mqGPYiQg6gYhUGdzzP3ZSzAzAjDBTdA5B8cqj7Wn06imQMsqphli/xmPYYXNlmmsuw1HFz1kebwOf7HzfrWESGYEgKyWic4/N2TTRw8BL2TO7Y1YB9r4TUCs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FQKriiat; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d288bac3caso19989131fa.2; Mon, 26 Feb 2024 13:32:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708983167; x=1709587967; darn=vger.kernel.org; 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=i8xzxpmRfOYpMJXfjSv2//ub/SLcVqWsue/aaIwJmAc=; b=FQKriiatg5mPDf+7Hm1fjqdku4zkV3kSinOQR8YYoUXLDN6QpH9HzaAwM6YsEAXkJR HfjU+n2XhECA2EQmRtDvT8nnYoBA/jt1+C2Qv8hweGc4rg9BDc9AnpCGAyLy1m2o5gJi yHzs3N5FbLULRMOkAGSy4gC1azcoOXUOyJP4nI2S7t03yQRxmOPsCj2AITOgsdu0fgqU Jw9glDmEdd62aU3ky9Yc7zVnz3qIiSB4StJTm1J//DB37X14dYAu3dUSjcEhMwNooSVR UAO8L1ULlD08UE1Rvv6MzEvwHQpuhsrR/5ZoDg6fHc0lmd1Mz/auYXjvBO/OLRQ9lvvV opGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708983167; x=1709587967; 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=i8xzxpmRfOYpMJXfjSv2//ub/SLcVqWsue/aaIwJmAc=; b=Sr9ak38erG8tMe6Mpliwt9AfIayc7q60f99nDAzu9pEU2yH0gXv7dhoF5WItVeEB8M MH/Qta1tn+k0U3xiyp/IAn/pEQIkkkSDMp9fHwCx1lKJAtJoaH+FchtCh5qGvrcP61F9 DhG0/fvBuvr7y9gVhoPgRNXT8dsrJv/BQ6HCWiARc6dTiCqQxrrL4ruU2lSScs8G1PA0 1SeEgexKcd/FcTnCVX6tEDXk75Rglb/h62ErF+KBNNpt3m/Spjxxt4n6uUWNeodaSG9v SbY0oB4WaYPGM/OhbO4wzYKAbtYXBQhy/lWnW41tGnvZLvouKdDR07R0cU10/KjetgSC ixZw== X-Forwarded-Encrypted: i=1; AJvYcCWt5gzWTl86x0vMTqFUGl0E7D+OPSqLAxiNBSa3/aXiL4JyTblGEPHP8ktnIqTzDFKK4jOHs6YaZb2LRDwdSGm/l9F4w14EbTFwCB0CfFk6N+UKocqU5jQ+LroEhYT/Ny0fe1TNY5QCidxUvehLC53qE9NjK0ojJGnRsB7SuoAHdiBQrIfMPBlkTPKOD/uQ9oIudb5X0pLDynmI2NvPd8FijTgxPc8q81ql X-Gm-Message-State: AOJu0YyF7jsDkPn7qDIjHXBaUCxsCooSoG13TG3DMAPW144S+hyTTEyM UrMn798obEqyzOdgmcxU4PDRmnqtCktfux//Foa0IjWYjuCra6QJ X-Received: by 2002:a2e:a495:0:b0:2d2:7d73:7b3b with SMTP id h21-20020a2ea495000000b002d27d737b3bmr4157845lji.3.1708983166865; Mon, 26 Feb 2024 13:32:46 -0800 (PST) Received: from mobilestation ([95.79.226.168]) by smtp.gmail.com with ESMTPSA id y5-20020a2e7d05000000b002d2474fdecesm997285ljc.35.2024.02.26.13.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 13:32:46 -0800 (PST) Date: Tue, 27 Feb 2024 00:32:44 +0300 From: Serge Semin To: Manivannan Sadhasivam Cc: Jingoo Han , Gustavo Pimentel , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Marek Vasut , Yoshihiro Shimoda , Kishon Vijay Abraham I , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-msm@vger.kernel.org, mhi@lists.linux.dev, Siddharth Vadapalli Subject: Re: [PATCH v3 2/5] PCI: dwc: Skip finding eDMA channels count if glue drivers have passed them Message-ID: <4p4z5eyhpdhxzi36drhrmz6z7krupszddudg6c2baypkbnnj7t@nqcmk2wdntts> References: <20240226-dw-hdma-v3-0-cfcb8171fc24@linaro.org> <20240226-dw-hdma-v3-2-cfcb8171fc24@linaro.org> <5gzkxdpx6u3jhw5twbncjhtozgekmlzxrpj3m6is3ijadm2svb@f6ng4owyakup> <20240226153014.GG8422@thinkpad> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240226153014.GG8422@thinkpad> On Mon, Feb 26, 2024 at 09:00:14PM +0530, Manivannan Sadhasivam wrote: > On Mon, Feb 26, 2024 at 03:53:20PM +0300, Serge Semin wrote: > > On Mon, Feb 26, 2024 at 05:07:27PM +0530, Manivannan Sadhasivam wrote: > > > In the case of Hyper DMA (HDMA) present in DWC controllers, there is no way > > > the drivers can auto detect the number of read/write channels as like its > > > predecessor embedded DMA (eDMA). So the glue drivers making use of HDMA > > > have to pass the channels count during probe. > > > > > > To accommodate that, let's skip finding the channels if the channels count > > > were already passed by glue drivers. If the channels count passed were > > > wrong in any form, then the existing sanity check will catch it. > > > > > > Suggested-by: Serge Semin > > > Reviewed-by: Siddharth Vadapalli > > > Signed-off-by: Manivannan Sadhasivam > > > --- > > > drivers/pci/controller/dwc/pcie-designware.c | 16 +++++++++------- > > > 1 file changed, 9 insertions(+), 7 deletions(-) > > > > > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > > > index 193fcd86cf93..ce273c3c5421 100644 > > > --- a/drivers/pci/controller/dwc/pcie-designware.c > > > +++ b/drivers/pci/controller/dwc/pcie-designware.c > > > @@ -927,13 +927,15 @@ static int dw_pcie_edma_find_channels(struct dw_pcie *pci) > > > { > > > u32 val; > > > > > > - if (pci->edma.mf == EDMA_MF_EDMA_LEGACY) > > > - val = dw_pcie_readl_dbi(pci, PCIE_DMA_VIEWPORT_BASE + PCIE_DMA_CTRL); > > > - else > > > - val = dw_pcie_readl_dma(pci, PCIE_DMA_CTRL); > > > - > > > - pci->edma.ll_wr_cnt = FIELD_GET(PCIE_DMA_NUM_WR_CHAN, val); > > > - pci->edma.ll_rd_cnt = FIELD_GET(PCIE_DMA_NUM_RD_CHAN, val); > > > > > + if (!pci->edma.ll_wr_cnt || !pci->edma.ll_rd_cnt) { > > > > Are you sure that the partly initialized case should be considered as > > a request for the auto-detection? IMO &&-ing here and letting the > > sanity check to fail further would be more correct since thus the > > developer would know about improper initialized data. > > > > We already have the check below. So the partly initialized case will fail > anyway. Not really. If the partly initialized case activates the auto-detection procedure it will override both non-initialized and _initialized_ number of channels with the values retrieved from the hardware, which the glue driver has been willing not to use. This prone to undefined behavior depending on the reasons of skipping the auto-detection procedure. For instance, assume the DMA_CTRL register reports an invalid number of read channels. A glue driver by mistake or willingly overwrites the pci->edma.ll_rd_cnt field only. This won't solve the problem since the auto-detection will be proceeded due to the pci->edma.ll_wr_cnt field being left uninitialized. So to speak it would be better to implement a strictly determined case for activating the auto-detection procedure: both number of channels aren't initialized; if only one field is initialized then report an error. Alternatively we can have the auto-detection executed on the per-channel basis: + if (pci->edma.mf != EDMA_MF_HDMA_NATIVE) { + val = dw_pcie_readl_dma(pci, PCIE_DMA_CTRL); + + if (!pci->edma.ll_wr_cnt) + pci->edma.ll_wr_cnt = FIELD_GET(PCIE_DMA_NUM_WR_CHAN, val); + + if (!pci->edma.ll_rd_cnt) + pci->edma.ll_rd_cnt = FIELD_GET(PCIE_DMA_NUM_RD_CHAN, val); + } -Serge(y) > > - Mani > > > -Serge(y) > > > > > + if (pci->edma.mf == EDMA_MF_EDMA_LEGACY) > > > + val = dw_pcie_readl_dbi(pci, PCIE_DMA_VIEWPORT_BASE + PCIE_DMA_CTRL); > > > + else > > > + val = dw_pcie_readl_dma(pci, PCIE_DMA_CTRL); > > > + > > > + pci->edma.ll_wr_cnt = FIELD_GET(PCIE_DMA_NUM_WR_CHAN, val); > > > + pci->edma.ll_rd_cnt = FIELD_GET(PCIE_DMA_NUM_RD_CHAN, val); > > > + } > > > > > > /* Sanity check the channels count if the mapping was incorrect */ > > > if (!pci->edma.ll_wr_cnt || pci->edma.ll_wr_cnt > EDMA_MAX_WR_CH || > > > > > > -- > > > 2.25.1 > > > > > -- > மணிவண்ணன் சதாசிவம்