Message ID | 1705669223-5655-4-git-send-email-quic_msarkar@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-31160-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp988795dyb; Fri, 19 Jan 2024 05:02:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IG7/KJaU+1xm5IfKQ9IDjCn1ADDbKm5DBfmf8P9UPEjrO8xbbWGuLxK9siGymvDgorgv/et X-Received: by 2002:ac8:5755:0:b0:42a:153c:af5d with SMTP id 21-20020ac85755000000b0042a153caf5dmr1466346qtx.34.1705669372509; Fri, 19 Jan 2024 05:02:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705669372; cv=pass; d=google.com; s=arc-20160816; b=EZNiibR+hs3S0spRwEVxjlRnAMcHSQOya6XgtT4ZGfXCYNPReL7ZaZ0j0Hx92lfRV7 Y4Zlua+JX7+SZ3iDbpsMxD3ML3l9njeGIDNtvmBLO/rnLvLjWY/EetFkH+Ws0b/JuYIZ 22WBH3jZNf6aDKQuO290ARLpPOP2a/z56O5ge0hu+3Iwti86Zp7D3cJ8oDuZdsmFoc5J Y+wJeRXz8qv1cRREwTjyc4HvoLspJv4cadkCoGihTRVusyhhWPap/fxFgwqz5AhcguIK L0luDunqdA0aFq1Ga8nYePzgVKA2rskRAEJDdCBae0sVYpnXdchjufWW0ytSi7I6bkHw uUxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=J5N0eH+XorUHi+CvGk/WwzsrjWyuz4FCQ2eZXs4R5nY=; fh=A9BXgcrlMZ5z9wYoTmuXIwTqeYf3DKZIOMrQtykU1fI=; b=Mv/nwyapdR3XWVlO3iIJXJSmQghxrmhAi/gmJqHS2GLC2uBKfQAdL9pq2giA092FUb 0nXs1a09wBb9SL+WH4A4LK44yM0cejFnBY0keG9dxVKtdagxK23ghoqPrLuVLvxXlpAJ 91gfyv8HCdrxaA63RUBPTrOI8XviFjUs6yv6c3Pfa50J4Frp8qQQbNuiV9CAORO2Zcox 1YC94vGxbSnD2cIbIr62011TbGV1wnLDfpM3Uuu4SeCKIOxACAYMQgkiLkO6+CsrGpaD vM1iHdanlt96vNgntEp9IoNxgwgosuKWUvalQ84uzvEQpEoriI8Wt1cZ+jw0XhYPUFa0 eniw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=chlwqT5n; arc=pass (i=1 spf=pass spfdomain=qualcomm.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-31160-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31160-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z4-20020ac87f84000000b0042a1b115a01si3465884qtj.92.2024.01.19.05.02.52 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 05:02:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31160-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=chlwqT5n; arc=pass (i=1 spf=pass spfdomain=qualcomm.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-31160-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31160-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 43BB71C2211B for <ouuuleilei@gmail.com>; Fri, 19 Jan 2024 13:02:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDDD054BCA; Fri, 19 Jan 2024 13:01:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="chlwqT5n" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2046A52F86; Fri, 19 Jan 2024 13:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705669260; cv=none; b=iB2nmH0SSZ0pwZBPcZSJiStmvwEThanOLpJy6d4x9c1cSWuOnKDMD/3x4Fozs/DrSRqgncgfAJu6l67TB0jNq3l1GRBFuCZJYFQ31dTZ6t9ByaE6smpX9glnMbvAU72+ZKqJmyyNDZ8t20ukepONkPI+6sYh3LxElYgY6wg6nSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705669260; c=relaxed/simple; bh=EerfizSXmr8ySSTQG3Ek8cTyqeYJTbG6H8QUFJ+dUbc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=dwpLCOz/f7dLawmjcu/GJHbnaMaMKdniV4eNpJ52H8rkV8eN34hswRKpMyeW6RvoNm5WRA7raFXMDGsEgU/2ft2sq1pF6v+L69tK5+BxC/Il9Fp+6/6rTAwnys2MIUcUBhtWPVB2Bs9J80C3OZYWhqnhun/L8Xjb/JgGdaj0WU0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=qualcomm.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=chlwqT5n; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=qualcomm.com Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40JCRWRX021492; Fri, 19 Jan 2024 13:00:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references; s= qcppdkim1; bh=J5N0eH+XorUHi+CvGk/WwzsrjWyuz4FCQ2eZXs4R5nY=; b=ch lwqT5nOSWEWRJwPAFnbuTrHhaRl7l9q+E5zsdLBei1bYES4dpzq0is7VpLxwOiwc fVeaPlli/Ix157Tc0v/tvnr9baWTAN7N1uhzUt4HC07lc5Ru2YCRUdrAhzV62m+H 5gxKk7AHTMfGm9WudeqFPsadude9nT1xV4pEr9lFF4nVPL2tn2eYnDcDdxdtMQyo dvJFe0+cWlptKAhAxhE9nzoe1zOytYvB2FuzW4GrRUrwtOha9l9Qw6l4OOZTtziy WM5FKtijvB1vhn5Wjr+5V2SnE3mwq1T/6Kpfm7xNHnhKmqbaO8yr0kshUXrOM3CR LJJKmBw5tL+TYPD30C5A== Received: from apblrppmta01.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vqh2k90tv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2024 13:00:43 +0000 (GMT) Received: from pps.filterd (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 40JD0eMr023790; Fri, 19 Jan 2024 13:00:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTPS id 3vkkkmtgrw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 19 Jan 2024 13:00:40 +0000 Received: from APBLRPPMTA01.qualcomm.com (APBLRPPMTA01.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40JD0dLE023785; Fri, 19 Jan 2024 13:00:39 GMT Received: from hu-sgudaval-hyd.qualcomm.com (hu-msarkar-hyd.qualcomm.com [10.213.111.194]) by APBLRPPMTA01.qualcomm.com (PPS) with ESMTP id 40JD0dlN023784; Fri, 19 Jan 2024 13:00:39 +0000 Received: by hu-sgudaval-hyd.qualcomm.com (Postfix, from userid 3891782) id 3BC35273A; Fri, 19 Jan 2024 18:30:38 +0530 (+0530) From: Mrinmay Sarkar <quic_msarkar@quicinc.com> To: vkoul@kernel.org, jingoohan1@gmail.com, conor+dt@kernel.org, konrad.dybcio@linaro.org, manivannan.sadhasivam@linaro.org, robh+dt@kernel.org Cc: quic_shazhuss@quicinc.com, quic_nitegupt@quicinc.com, quic_ramkri@quicinc.com, quic_nayiluri@quicinc.com, dmitry.baryshkov@linaro.org, quic_krichai@quicinc.com, quic_vbadigan@quicinc.com, quic_parass@quicinc.com, quic_schintav@quicinc.com, quic_shijjose@quicinc.com, Mrinmay Sarkar <quic_msarkar@quicinc.com>, Gustavo Pimentel <gustavo.pimentel@synopsys.com>, Serge Semin <fancer.lancer@gmail.com>, Lorenzo Pieralisi <lpieralisi@kernel.org>, =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= <kw@linux.com>, Rob Herring <robh@kernel.org>, Bjorn Helgaas <bhelgaas@google.com>, Kishon Vijay Abraham I <kishon@kernel.org>, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, mhi@lists.linux.dev Subject: [PATCH v1 3/6] PCI: dwc: Add HDMA support Date: Fri, 19 Jan 2024 18:30:19 +0530 Message-Id: <1705669223-5655-4-git-send-email-quic_msarkar@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1705669223-5655-1-git-send-email-quic_msarkar@quicinc.com> References: <1705669223-5655-1-git-send-email-quic_msarkar@quicinc.com> X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: z69Q7pBn-mgOoTOjfxot1-qCLdMS5U1p X-Proofpoint-ORIG-GUID: z69Q7pBn-mgOoTOjfxot1-qCLdMS5U1p X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_07,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 clxscore=1015 impostorscore=0 phishscore=0 mlxlogscore=803 mlxscore=0 suspectscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401190066 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788523968305530292 X-GMAIL-MSGID: 1788523968305530292 |
Series |
Add Change to integrate HDMA with dwc ep driver
|
|
Commit Message
Mrinmay Sarkar
Jan. 19, 2024, 1 p.m. UTC
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Hyper DMA (HDMA) is already supported by the dw-edma dmaengine driver. Unlike it's predecessor Embedded DMA (eDMA), HDMA supports only the unrolled mapping format. So the platform drivers need to provide a valid base address of the CSRs. Also, there is no standard way to auto detect the number of available read/write channels in a platform. So the platform drivers has to provide that information as well. For adding HDMA support, the mapping format set by the platform drivers is used to detect whether eDMA or HDMA is being used, since we cannot auto detect it in a sane way. Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Signed-off-by: Mrinmay Sarkar <quic_msarkar@quicinc.com> --- drivers/pci/controller/dwc/pcie-designware.c | 55 ++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 8 deletions(-)
Comments
On Sat, Feb 03, 2024 at 12:40:39AM +0300, Serge Semin wrote: > On Fri, Jan 19, 2024 at 06:30:19PM +0530, Mrinmay Sarkar wrote: > > From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> > > > > Hyper DMA (HDMA) is already supported by the dw-edma dmaengine driver. > > Unlike it's predecessor Embedded DMA (eDMA), HDMA supports only the > > unrolled mapping format. So the platform drivers need to provide a valid > > base address of the CSRs. Also, there is no standard way to auto detect > > the number of available read/write channels in a platform. So the platform > > drivers has to provide that information as well. > > > > For adding HDMA support, the mapping format set by the platform drivers is > > used to detect whether eDMA or HDMA is being used, since we cannot auto > > detect it in a sane way. > > > > Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> > > Signed-off-by: Mrinmay Sarkar <quic_msarkar@quicinc.com> > > --- > > drivers/pci/controller/dwc/pcie-designware.c | 55 ++++++++++++++++++++++++---- > > 1 file changed, 47 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > > index 96575b8..07a1f2d 100644 > > --- a/drivers/pci/controller/dwc/pcie-designware.c > > +++ b/drivers/pci/controller/dwc/pcie-designware.c > > @@ -880,7 +880,29 @@ static struct dw_edma_plat_ops dw_pcie_edma_ops = { > > .irq_vector = dw_pcie_edma_irq_vector, > > }; > > > > -static int dw_pcie_edma_find_chip(struct dw_pcie *pci) > > +static int dw_pcie_find_hdma(struct dw_pcie *pci) > > +{ > > + /* > > + * Since HDMA supports only unrolled mapping, platform drivers need to > > + * provide a valid base address. > > + */ > > + if (!pci->edma.reg_base) > > + return -ENODEV; > > + > > + /* > > + * Since there is no standard way to detect the number of read/write > > + * HDMA channels, platform drivers are expected to provide the channel > > + * count. Let's also do a sanity check of them to make sure that the > > + * counts are within the limit specified by the spec. > > + */ > > + if (!pci->edma.ll_wr_cnt || pci->edma.ll_wr_cnt > dw_edma_get_max_wr_ch(pci->edma.mf) || > > + !pci->edma.ll_rd_cnt || pci->edma.ll_rd_cnt > dw_edma_get_max_rd_ch(pci->edma.mf)) > > + return -EINVAL; > > + > > + return 0; > > +} > > + > > +static int dw_pcie_find_edma(struct dw_pcie *pci) > > { > > u32 val; > > > > @@ -912,13 +934,6 @@ static int dw_pcie_edma_find_chip(struct dw_pcie *pci) > > return -ENODEV; > > } > > > > - pci->edma.dev = pci->dev; > > - > > - if (!pci->edma.ops) > > - pci->edma.ops = &dw_pcie_edma_ops; > > - > > - pci->edma.flags |= DW_EDMA_CHIP_LOCAL; > > - > > 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); > > > > @@ -930,6 +945,30 @@ static int dw_pcie_edma_find_chip(struct dw_pcie *pci) > > return 0; > > } > > > > +static int dw_pcie_edma_find_chip(struct dw_pcie *pci) > > +{ > > + int ret; > > + > > > + if (pci->edma.mf == EDMA_MF_HDMA_NATIVE) { > > + ret = dw_pcie_find_hdma(pci); > > + if (ret) > > + return ret; > > + } else { > > + ret = dw_pcie_find_edma(pci); > > + if (ret) > > + return ret; > > + } > > Basically this change defines two versions of the eDMA info > initialization procedure: > 1. use pre-defined CSRs mapping format and amount of channels, > 2. auto-detect CSRs mapping and the amount of channels. > The second version also supports the optional CSRs mapping format > detection procedure by means of the DW_PCIE_CAP_EDMA_UNROLL flag > semantics. Thus should this patch is accepted there will be the > functionality duplication. I suggest to make things a bit more > flexible than that. Instead of creating the two types of the > init-methods selectable based on the mapping format, let's split up > the already available DW eDMA engine detection procedure into the next > three stages: > 1. initialize DW eDMA data, > 2. auto-detect the CSRs mapping format, > 3. auto-detect the amount of channels. > and convert the later two to being optional. They will be skipped in case > if the mapping format or the amount of channels have been pre-defined > by the platform drivers. Thus we can keep the eDMA data init procedure > more linear thus easier to read, drop redundant DW_PCIE_CAP_EDMA_UNROLL flag > and use the new functionality for the Renesas R-Car S4-8's PCIe > controller (for which the auto-detection didn't work), for HDMA with compat > and _native_ CSRs mapping. See the attached patches for details: > Above approach sounds good to me, thanks! Mrinmay, please integrate Sergey's patches and drop this one. I'll do a review in v2. - Mani > 0001-PCI-dwc-Fix-eDMA-mapping-info-string.patch > +- Just the eDMA log-message fix which will be useful in any case. > > 0002-PCI-dwc-Split-up-eDMA-parameters-auto-detection-proc.patch > +-> Split up the dw_pcie_edma_find_chip() method into three ones > described above. > > 0003-PCI-dwc-Convert-eDMA-mapping-detection-to-being-full.patch > +-> Skip the second stage the mapping format has been specified. > > 0004-PCI-dwc-Convert-eDMA-channels-detection-to-being-opt.patch > +-> Skip the amount of channels auto-detection if the amount has > already been specified. > > 0005-PCI-dwc-Drop-DW_PCIE_CAP_EDMA_UNROLL-flag.patch > +-> Drop the no longer needed DW_PCIE_CAP_EDMA_UNROLL flag. > > After these patches are applied AFAICS the patches 5/6 and 6/6 of this > series shall work with no additional modification. > > * Note I only build-tested the attached patches. So even though they > * aren't that much invasive please be read for a bit debugging. > > -Serge(y) > > > + > > + pci->edma.dev = pci->dev; > > + > > + if (!pci->edma.ops) > > + pci->edma.ops = &dw_pcie_edma_ops; > > + > > + pci->edma.flags |= DW_EDMA_CHIP_LOCAL; > > + > > + return 0; > > +} > > + > > static int dw_pcie_edma_irq_verify(struct dw_pcie *pci) > > { > > struct platform_device *pdev = to_platform_device(pci->dev); > > -- > > 2.7.4 > > > From 9b600c17aa56b3949a040055cf82222c48b60bf3 Mon Sep 17 00:00:00 2001 > From: Serge Semin <fancer.lancer@gmail.com> > Date: Fri, 2 Feb 2024 18:01:31 +0300 > Subject: [PATCH 1/5] PCI: dwc: Fix eDMA mapping info string > > DW PCIe controller can be equipped with the next types of DMA controllers: > 1. eDMA controller with viewport-based CSRs access (so called legacy), > 2. eDMA controller with unrolled CSRs mapping, > 3. HDMA controller compatible with the eDMA unrolled CSRs mapping, > 4. HDMA controller with native CSRs mapping. > The later three types imply having the DMA-engine CSRs _unrolled_ mapping. > Let's fix the info-message printed in the DW PCIe eDMA controller > detection procedure to comply with that. > > Signed-off-by: Serge Semin <fancer.lancer@gmail.com> > --- > drivers/pci/controller/dwc/pcie-designware.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > index 7551e0fea5e9..454ea32ee70b 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.c > +++ b/drivers/pci/controller/dwc/pcie-designware.c > @@ -1018,7 +1018,7 @@ int dw_pcie_edma_detect(struct dw_pcie *pci) > } > > dev_info(pci->dev, "eDMA: unroll %s, %hu wr, %hu rd\n", > - pci->edma.mf == EDMA_MF_EDMA_UNROLL ? "T" : "F", > + pci->edma.mf != EDMA_MF_EDMA_LEGACY ? "T" : "F", > pci->edma.ll_wr_cnt, pci->edma.ll_rd_cnt); > > return 0; > -- > 2.43.0 > > From ca70e7dd9b84c9dd01124a13f624441c01f7c09d Mon Sep 17 00:00:00 2001 > From: Serge Semin <fancer.lancer@gmail.com> > Date: Fri, 2 Feb 2024 18:18:39 +0300 > Subject: [PATCH 2/5] PCI: dwc: Split up eDMA parameters auto-detection > procedure > > It turns out the DW HDMA controller parameters can't be auto-detected in > the same way as it's done for DW eDMA: HDMA has only the unrolled CSRs > mapping and has no way to find out the amount of the channels. For that > case the best choice would be to have the HDMA controller parameters > pre-defined by the platform drivers and to convert the implemented > auto-detection procedure to being optionally executed if no DMA-controller > parameters specified. As a preparation step before that let's split the > eDMA auto-detection into three stages: > 1. initialize DW eDMA data, > 2. auto-detect the CSRs mapping format, > 3. auto-detect the amount of channels. > > Note this commit doesn't imply the eDMA detection procedure semantics > change. > > Signed-off-by: Serge Semin <fancer.lancer@gmail.com> > --- > drivers/pci/controller/dwc/pcie-designware.c | 33 +++++++++++++++----- > 1 file changed, 25 insertions(+), 8 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > index 454ea32ee70b..149c7a2a12f2 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.c > +++ b/drivers/pci/controller/dwc/pcie-designware.c > @@ -878,7 +878,17 @@ static struct dw_edma_plat_ops dw_pcie_edma_ops = { > .irq_vector = dw_pcie_edma_irq_vector, > }; > > -static int dw_pcie_edma_find_chip(struct dw_pcie *pci) > +static void dw_pcie_edma_init_data(struct dw_pcie *pci) > +{ > + pci->edma.dev = pci->dev; > + > + if (!pci->edma.ops) > + pci->edma.ops = &dw_pcie_edma_ops; > + > + pci->edma.flags |= DW_EDMA_CHIP_LOCAL; > +} > + > +static int dw_pcie_edma_find_mf(struct dw_pcie *pci) > { > u32 val; > > @@ -900,8 +910,6 @@ static int dw_pcie_edma_find_chip(struct dw_pcie *pci) > > if (val == 0xFFFFFFFF && pci->edma.reg_base) { > pci->edma.mf = EDMA_MF_EDMA_UNROLL; > - > - val = dw_pcie_readl_dma(pci, PCIE_DMA_CTRL); > } else if (val != 0xFFFFFFFF) { > pci->edma.mf = EDMA_MF_EDMA_LEGACY; > > @@ -910,12 +918,14 @@ static int dw_pcie_edma_find_chip(struct dw_pcie *pci) > return -ENODEV; > } > > - pci->edma.dev = pci->dev; > + return 0; > +} > > - if (!pci->edma.ops) > - pci->edma.ops = &dw_pcie_edma_ops; > +static int dw_pcie_edma_find_chan(struct dw_pcie *pci) > +{ > + u32 val; > > - pci->edma.flags |= DW_EDMA_CHIP_LOCAL; > + 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); > @@ -992,8 +1002,15 @@ int dw_pcie_edma_detect(struct dw_pcie *pci) > { > int ret; > > + dw_pcie_edma_init_data(pci); > + > /* Don't fail if no eDMA was found (for the backward compatibility) */ > - ret = dw_pcie_edma_find_chip(pci); > + ret = dw_pcie_edma_find_mf(pci); > + if (ret) > + return 0; > + > + /* Don't fail if no valid channels detected (for the backward compatibility) */ > + ret = dw_pcie_edma_find_chan(pci); > if (ret) > return 0; > > -- > 2.43.0 > > From f5149d0827d9d8b0ccaaaeb6309b1a86832cdddc Mon Sep 17 00:00:00 2001 > From: Serge Semin <fancer.lancer@gmail.com> > Date: Fri, 2 Feb 2024 19:02:35 +0300 > Subject: [PATCH 3/5] PCI: dwc: Convert eDMA mapping detection to being fully > optional > > The DW eDMA CSRs mapping detection procedure doesn't work for the DW HDMA > controller. Moreover it isn't that easy to distinguish HDMA from eDMA if > the former controller available in place of the later one. Thus seeing DW > HDMA controller has the unrolled CSRs mapping only there is no better > choice but to rely on the HDMA-capable platform drivers having the > DMA-engine mapping format specified. In order to permit that let's convert > the eDMA mapping format auto-detection to being fully optional: execute > the DMA Ctrl-based CSRs mapping auto-detection only if no mapping format > was specific. > > Note the DW_PCIE_CAP_EDMA_UNROLL flag semantics also imply the mapping > auto-detection optionality. But it doesn't indicate the type of the > controller. It's merely a fixup for the DW PCIe eDMA controllers which for > some reason don't support the DMA Ctrl-based CSRs mapping auto-detection > procedure (see note regarding the Renesas R-Car S4-8's PCIe). So it can't > be utilized for DW HDMA auto-detection. But after this change is applied > the flag will get to be redundant and will be subject for removal in one > of the subsequent commit. > > Signed-off-by: Serge Semin <fancer.lancer@gmail.com> > --- > drivers/pci/controller/dwc/pcie-designware.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > index 149c7a2a12f2..2243ffeb95b5 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.c > +++ b/drivers/pci/controller/dwc/pcie-designware.c > @@ -892,6 +892,14 @@ static int dw_pcie_edma_find_mf(struct dw_pcie *pci) > { > u32 val; > > + /* > + * The platform drivers can pre-define the DMA controller mapping > + * format especially if the auto-detection procedure doesn't work for > + * them. In that case the CSRs base must be specified too. > + */ > + if (pci->edma.mf != EDMA_MF_EDMA_LEGACY) > + return pci->edma.reg_base ? 0 : -EINVAL; > + > /* > * Indirect eDMA CSRs access has been completely removed since v5.40a > * thus no space is now reserved for the eDMA channels viewport and > -- > 2.43.0 > > From 4f9668ad9e741b501476cd4457cf9ca9013ee6e3 Mon Sep 17 00:00:00 2001 > From: Serge Semin <fancer.lancer@gmail.com> > Date: Fri, 2 Feb 2024 20:12:46 +0300 > Subject: [PATCH 4/5] PCI: dwc: Convert eDMA channels detection to being > optional > > DW HDMA controller channels can't be auto-detected. Thus there is no way > but to rely on the HDMA-capable platform drivers having the number of > channels specified. In order to permit that convert the > dw_pcie_edma_find_chan() method to executing the DMA Ctrl CSR-based number > of channels detection procedure only if no channels amount was specified, > otherwise just sanity check the specified values. > > Signed-off-by: Serge Semin <fancer.lancer@gmail.com> > --- > drivers/pci/controller/dwc/pcie-designware.c | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > index 2243ffeb95b5..4d53a71ab1b4 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.c > +++ b/drivers/pci/controller/dwc/pcie-designware.c > @@ -933,12 +933,20 @@ static int dw_pcie_edma_find_chan(struct dw_pcie *pci) > { > u32 val; > > - val = dw_pcie_readl_dma(pci, PCIE_DMA_CTRL); > + if (!pci->edma.ll_wr_cnt && !pci->edma.ll_rd_cnt) { > + if (pci->edma.mf == EDMA_MF_HDMA_NATIVE) > + return -EINVAL; > + > + 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); > + 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 */ > + /* > + * Sanity check the channels count in case if the mapping was > + * incorrectly detected/specified by the glue-driver. > + */ > if (!pci->edma.ll_wr_cnt || pci->edma.ll_wr_cnt > EDMA_MAX_WR_CH || > !pci->edma.ll_rd_cnt || pci->edma.ll_rd_cnt > EDMA_MAX_RD_CH) > return -EINVAL; > -- > 2.43.0 > > From 9590af6f5114b07e4073083ecde9e563cc920410 Mon Sep 17 00:00:00 2001 > From: Serge Semin <fancer.lancer@gmail.com> > Date: Fri, 2 Feb 2024 23:45:00 +0300 > Subject: [PATCH 5/5] PCI: dwc: Drop DW_PCIE_CAP_EDMA_UNROLL flag > > That flag was introduced in order to bypass the DW eDMA mapping format > auto-detection procedure and force the unrolled eDMA CSRs mapping > procedure. Since the same can be now reached just by pre-defining the > required mapping format, drop the flag and convert the Renesas R-Car S4-8 > glue-driver to using the new approach. > > Signed-off-by: Serge Semin <fancer.lancer@gmail.com> > --- > drivers/pci/controller/dwc/pcie-designware.c | 13 +++++-------- > drivers/pci/controller/dwc/pcie-designware.h | 5 ++--- > drivers/pci/controller/dwc/pcie-rcar-gen4.c | 2 +- > 3 files changed, 8 insertions(+), 12 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c > index 4d53a71ab1b4..a49de18c9836 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.c > +++ b/drivers/pci/controller/dwc/pcie-designware.c > @@ -895,7 +895,10 @@ static int dw_pcie_edma_find_mf(struct dw_pcie *pci) > /* > * The platform drivers can pre-define the DMA controller mapping > * format especially if the auto-detection procedure doesn't work for > - * them. In that case the CSRs base must be specified too. > + * them (e.g. Renesas R-Car S4-8's PCIe controllers for unknown reason > + * have zeros in the eDMA CTRL register even though the HW-manual > + * explicitly states there must be FFs if the unrolled mapping is > + * enabled). In that case the CSRs base must be specified too. > */ > if (pci->edma.mf != EDMA_MF_EDMA_LEGACY) > return pci->edma.reg_base ? 0 : -EINVAL; > @@ -904,14 +907,8 @@ static int dw_pcie_edma_find_mf(struct dw_pcie *pci) > * Indirect eDMA CSRs access has been completely removed since v5.40a > * thus no space is now reserved for the eDMA channels viewport and > * former DMA CTRL register is no longer fixed to FFs. > - * > - * Note that Renesas R-Car S4-8's PCIe controllers for unknown reason > - * have zeros in the eDMA CTRL register even though the HW-manual > - * explicitly states there must FFs if the unrolled mapping is enabled. > - * For such cases the low-level drivers are supposed to manually > - * activate the unrolled mapping to bypass the auto-detection procedure. > */ > - if (dw_pcie_ver_is_ge(pci, 540A) || dw_pcie_cap_is(pci, EDMA_UNROLL)) > + if (dw_pcie_ver_is_ge(pci, 540A)) > val = 0xFFFFFFFF; > else > val = dw_pcie_readl_dbi(pci, PCIE_DMA_VIEWPORT_BASE + PCIE_DMA_CTRL); > diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h > index 035df6bc7606..a666190e8b1b 100644 > --- a/drivers/pci/controller/dwc/pcie-designware.h > +++ b/drivers/pci/controller/dwc/pcie-designware.h > @@ -54,9 +54,8 @@ > > /* DWC PCIe controller capabilities */ > #define DW_PCIE_CAP_REQ_RES 0 > -#define DW_PCIE_CAP_EDMA_UNROLL 1 > -#define DW_PCIE_CAP_IATU_UNROLL 2 > -#define DW_PCIE_CAP_CDM_CHECK 3 > +#define DW_PCIE_CAP_IATU_UNROLL 1 > +#define DW_PCIE_CAP_CDM_CHECK 2 > > #define dw_pcie_cap_is(_pci, _cap) \ > test_bit(DW_PCIE_CAP_ ## _cap, &(_pci)->caps) > diff --git a/drivers/pci/controller/dwc/pcie-rcar-gen4.c b/drivers/pci/controller/dwc/pcie-rcar-gen4.c > index 3bc45e513b3d..5678d69c413a 100644 > --- a/drivers/pci/controller/dwc/pcie-rcar-gen4.c > +++ b/drivers/pci/controller/dwc/pcie-rcar-gen4.c > @@ -255,7 +255,7 @@ static struct rcar_gen4_pcie *rcar_gen4_pcie_alloc(struct platform_device *pdev) > rcar->dw.ops = &dw_pcie_ops; > rcar->dw.dev = dev; > rcar->pdev = pdev; > - dw_pcie_cap_set(&rcar->dw, EDMA_UNROLL); > + rcar->dw.edma.mf = EDMA_MF_EDMA_UNROLL; > dw_pcie_cap_set(&rcar->dw, REQ_RES); > platform_set_drvdata(pdev, rcar); > > -- > 2.43.0 >
diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c index 96575b8..07a1f2d 100644 --- a/drivers/pci/controller/dwc/pcie-designware.c +++ b/drivers/pci/controller/dwc/pcie-designware.c @@ -880,7 +880,29 @@ static struct dw_edma_plat_ops dw_pcie_edma_ops = { .irq_vector = dw_pcie_edma_irq_vector, }; -static int dw_pcie_edma_find_chip(struct dw_pcie *pci) +static int dw_pcie_find_hdma(struct dw_pcie *pci) +{ + /* + * Since HDMA supports only unrolled mapping, platform drivers need to + * provide a valid base address. + */ + if (!pci->edma.reg_base) + return -ENODEV; + + /* + * Since there is no standard way to detect the number of read/write + * HDMA channels, platform drivers are expected to provide the channel + * count. Let's also do a sanity check of them to make sure that the + * counts are within the limit specified by the spec. + */ + if (!pci->edma.ll_wr_cnt || pci->edma.ll_wr_cnt > dw_edma_get_max_wr_ch(pci->edma.mf) || + !pci->edma.ll_rd_cnt || pci->edma.ll_rd_cnt > dw_edma_get_max_rd_ch(pci->edma.mf)) + return -EINVAL; + + return 0; +} + +static int dw_pcie_find_edma(struct dw_pcie *pci) { u32 val; @@ -912,13 +934,6 @@ static int dw_pcie_edma_find_chip(struct dw_pcie *pci) return -ENODEV; } - pci->edma.dev = pci->dev; - - if (!pci->edma.ops) - pci->edma.ops = &dw_pcie_edma_ops; - - pci->edma.flags |= DW_EDMA_CHIP_LOCAL; - 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); @@ -930,6 +945,30 @@ static int dw_pcie_edma_find_chip(struct dw_pcie *pci) return 0; } +static int dw_pcie_edma_find_chip(struct dw_pcie *pci) +{ + int ret; + + if (pci->edma.mf == EDMA_MF_HDMA_NATIVE) { + ret = dw_pcie_find_hdma(pci); + if (ret) + return ret; + } else { + ret = dw_pcie_find_edma(pci); + if (ret) + return ret; + } + + pci->edma.dev = pci->dev; + + if (!pci->edma.ops) + pci->edma.ops = &dw_pcie_edma_ops; + + pci->edma.flags |= DW_EDMA_CHIP_LOCAL; + + return 0; +} + static int dw_pcie_edma_irq_verify(struct dw_pcie *pci) { struct platform_device *pdev = to_platform_device(pci->dev);