Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp719643ybz; Wed, 15 Apr 2020 17:27:32 -0700 (PDT) X-Google-Smtp-Source: APiQypJ/zZG59NqeRFt1aj4JJr2bb+T2HXPe1CoYDDTmQUgj/8kfjKs3PIreF2hl07OI1fSlS4gZ X-Received: by 2002:a17:906:7e19:: with SMTP id e25mr7689890ejr.358.1586996852377; Wed, 15 Apr 2020 17:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586996852; cv=none; d=google.com; s=arc-20160816; b=EoL6x1wfLASqZ8qeFfEU0bL9Rv7ITSTeySli0hcWX9cpGRxtudHa6RryGiBUeMWJ6k yZ2rWXwwXjzvjUt0OVuf2K/dXHRCABiwaVfJoK+5vBK+ycIaR11okauXpRATHdD18wUb ipSlHgLwEm7j0xeFNhIC+MVTpVu/c6FApqdtYe9q8P8I5nYm09Q3GrZcw60o2oF5XA6m Dt9J1znaFX8WsrkszmIwx/+I64YikoS82dttThmPeqgMjrlUDzIEM57JivK4ZvDrWTuE raJH/L4wo2ALQwVLAbE3dmKeh6QBzYefmDVBZXIV81qb/y39Wx72Kf5EdSfJxR5x059k KgTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=nY+69lch1Z1eEPsftYngAsdf1DrodOInXT0dD8s9W9c=; b=sDwPJDTULI8hQhaCJTau7pLSSu5KZP65sN4CxXsCqi5VWfE2HVstXaFxj9ldqF92Fi i9CdTJmz6I6DT+oZcorp9ES3T4TBa+ms/pSGlaQ+yDS5+AQsa5HxTcTeKg2Kq660zVEj TvTEOr33r57P6p44axQ2dWjKFxR2mnAuBhyetV9p7Ad5w7gEFHtw5X342b8vCsG/IhYT pXVtS7kXPhMa/O39QBrMPQ8HiO0BbXz7huAqMLyQuuirHnGt+bWhkHEpwrYY00d+ey1z TojtD0l7leIK2td6hWS/WK1gRhq/S6I83S3Uv397OQFitZpazGJcuOzfJN7gPHnqtW7t gwgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=aTrc5dlc; 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 7si10673319edv.167.2020.04.15.17.27.00; Wed, 15 Apr 2020 17:27:32 -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=@sifive.com header.s=google header.b=aTrc5dlc; 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 S2410972AbgDOR1X (ORCPT + 99 others); Wed, 15 Apr 2020 13:27:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2410844AbgDOR1V (ORCPT ); Wed, 15 Apr 2020 13:27:21 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26021C061A0C for ; Wed, 15 Apr 2020 10:27:21 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id o1so136929pjs.4 for ; Wed, 15 Apr 2020 10:27:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=nY+69lch1Z1eEPsftYngAsdf1DrodOInXT0dD8s9W9c=; b=aTrc5dlcIr5Ec1JUMT00OHAtdS1DFD55M4o5HR4FrmM1TrFAZwNiv1oXURyyBNI504 c4AHjTusPxJMk+Y/TcYfuWbhAnkaYpXYSQcvng0B+6ZkEHKHQqW0mNBQvOYT3adUhrsz 8FXC3Zoe7wen3sq2Amxl1G9uqE0Pkokfy6qfaw0cyoPYamtvNBrc3XeUhGcUK0EBEjk8 /h8yRYT+DwivZKTkRyljziAVQM9lA5FG2GWAGQZVhkiuLclUKvgb0O1Hv8xxJcgfaE/7 5Vkhn4UZL/sYV84G9k+qu3vq/FtPwfpSEKxwIBgcwNKZAFyJ8y6AtAUoi8PkVFi384JU sd/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=nY+69lch1Z1eEPsftYngAsdf1DrodOInXT0dD8s9W9c=; b=qpU5IWvljZtHsDHw7K8Qyfr4Ek9gMq6Q9QQuEBeMKUKIl3fM9ymKzhuRuynv1+AiPz a0jnMBPDwZQNnkevujZVttIxETYO6usz1cdtsAgiK8LXfesWpweLjD4n5Dl6zvzdP/Dy 4KphfhtNDx9Ew77B5onXm7Sy1Hqip3oaFOlHwxX5+O+p6VsWi4iFN1qsjDog2AsPPaCe mAp0lCN+NiRqhHGR9D6SFbWjIFnz+zVWKuy6bFyhg1FUvjO6O0YpqnYQdraFg5LknfTL s66MvgAvnmbM7ZHXRe/BbQHsdSalz8M1eJbJHZpsPnfflAK7gSuHwHIVkoIYLTymOqve ylDw== X-Gm-Message-State: AGi0Pua/HsDf07r7FgLKE3bO0XUj1u9W16u3PFwLgscfVhlZ3ly69P/v 9NV2xF3Y7TWNLKzfIwnYbZZ2gQ== X-Received: by 2002:a17:90a:5d02:: with SMTP id s2mr326816pji.148.1586971640606; Wed, 15 Apr 2020 10:27:20 -0700 (PDT) Received: from nuc7.sifive.com (c-24-5-48-146.hsd1.ca.comcast.net. [24.5.48.146]) by smtp.gmail.com with ESMTPSA id e66sm10784808pfa.69.2020.04.15.10.27.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Apr 2020 10:27:19 -0700 (PDT) From: Alan Mikhak X-Google-Original-From: Alan Mikhak < alan.mikhak@sifive.com > To: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, gustavo.pimentel@synopsys.com, dan.j.williams@intel.com, vkoul@kernel.org, kishon@ti.com, paul.walmsley@sifive.com Cc: Alan Mikhak Subject: [PATCH v2] dmaengine: dw-edma: Decouple dw-edma-core.c from struct pci_dev Date: Wed, 15 Apr 2020 10:27:09 -0700 Message-Id: <1586971629-30196-1-git-send-email-alan.mikhak@sifive.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Mikhak Decouple dw-edma-core.c from struct pci_dev as a step toward integration of dw-edma with pci-epf-test so the latter can initiate dma operations locally from the endpoint side. A barrier to such integration is the dependency of dw_edma_probe() and other functions in dw-edma-core.c on struct pci_dev. The Synopsys DesignWare dw-edma driver was designed to run on host side of PCIe link to initiate DMA operations remotely using eDMA channels of PCIe controller on the endpoint side. This can be inferred from seeing that dw-edma uses struct pci_dev and accesses hardware registers of dma channels across the bus using BAR0 and BAR2. The ops field of struct dw_edma in dw-edma-core.h is currenty undefined: const struct dw_edma_core_ops *ops; However, the kernel builds without failure even when dw-edma driver is enabled. Instead of removing the currently undefined and usued ops field, define struct dw_edma_core_ops and use the ops field to decouple dw-edma-core.c from struct pci_dev. Signed-off-by: Alan Mikhak --- drivers/dma/dw-edma/dw-edma-core.c | 29 ++++++++++++++++++++--------- drivers/dma/dw-edma/dw-edma-core.h | 4 ++++ drivers/dma/dw-edma/dw-edma-pcie.c | 10 ++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index ff392c01bad1..db401eb11322 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "dw-edma-core.h" #include "dw-edma-v0-core.h" @@ -781,7 +781,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, if (dw->nr_irqs == 1) { /* Common IRQ shared among all channels */ - err = request_irq(pci_irq_vector(to_pci_dev(dev), 0), + err = request_irq(dw->ops->irq_vector(dev, 0), dw_edma_interrupt_common, IRQF_SHARED, dw->name, &dw->irq[0]); if (err) { @@ -789,7 +789,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, return err; } - get_cached_msi_msg(pci_irq_vector(to_pci_dev(dev), 0), + get_cached_msi_msg(dw->ops->irq_vector(dev, 0), &dw->irq[0].msi); } else { /* Distribute IRQs equally among all channels */ @@ -804,7 +804,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, dw_edma_add_irq_mask(&rd_mask, *rd_alloc, dw->rd_ch_cnt); for (i = 0; i < (*wr_alloc + *rd_alloc); i++) { - err = request_irq(pci_irq_vector(to_pci_dev(dev), i), + err = request_irq(dw->ops->irq_vector(dev, i), i < *wr_alloc ? dw_edma_interrupt_write : dw_edma_interrupt_read, @@ -815,7 +815,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, return err; } - get_cached_msi_msg(pci_irq_vector(to_pci_dev(dev), i), + get_cached_msi_msg(dw->ops->irq_vector(dev, i), &dw->irq[i].msi); } @@ -827,12 +827,23 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, int dw_edma_probe(struct dw_edma_chip *chip) { - struct device *dev = chip->dev; - struct dw_edma *dw = chip->dw; + struct device *dev; + struct dw_edma *dw; u32 wr_alloc = 0; u32 rd_alloc = 0; int i, err; + if (!chip) + return -EINVAL; + + dev = chip->dev; + if (!dev) + return -EINVAL; + + dw = chip->dw; + if (!dw || !dw->irq || !dw->ops || !dw->ops->irq_vector) + return -EINVAL; + raw_spin_lock_init(&dw->lock); /* Find out how many write channels are supported by hardware */ @@ -884,7 +895,7 @@ int dw_edma_probe(struct dw_edma_chip *chip) err_irq_free: for (i = (dw->nr_irqs - 1); i >= 0; i--) - free_irq(pci_irq_vector(to_pci_dev(dev), i), &dw->irq[i]); + free_irq(dw->ops->irq_vector(dev, i), &dw->irq[i]); dw->nr_irqs = 0; @@ -904,7 +915,7 @@ int dw_edma_remove(struct dw_edma_chip *chip) /* Free irqs */ for (i = (dw->nr_irqs - 1); i >= 0; i--) - free_irq(pci_irq_vector(to_pci_dev(dev), i), &dw->irq[i]); + free_irq(dw->ops->irq_vector(dev, i), &dw->irq[i]); /* Power management */ pm_runtime_disable(dev); diff --git a/drivers/dma/dw-edma/dw-edma-core.h b/drivers/dma/dw-edma/dw-edma-core.h index 4e5f9f6e901b..31fc50d31792 100644 --- a/drivers/dma/dw-edma/dw-edma-core.h +++ b/drivers/dma/dw-edma/dw-edma-core.h @@ -103,6 +103,10 @@ struct dw_edma_irq { struct dw_edma *dw; }; +struct dw_edma_core_ops { + int (*irq_vector)(struct device *dev, unsigned int nr); +}; + struct dw_edma { char name[20]; diff --git a/drivers/dma/dw-edma/dw-edma-pcie.c b/drivers/dma/dw-edma/dw-edma-pcie.c index dc85f55e1bb8..1eafc602e17e 100644 --- a/drivers/dma/dw-edma/dw-edma-pcie.c +++ b/drivers/dma/dw-edma/dw-edma-pcie.c @@ -54,6 +54,15 @@ static const struct dw_edma_pcie_data snps_edda_data = { .irqs = 1, }; +static int dw_edma_pcie_irq_vector(struct device *dev, unsigned int nr) +{ + return pci_irq_vector(to_pci_dev(dev), nr); +} + +static const struct dw_edma_core_ops dw_edma_pcie_core_ops = { + .irq_vector = dw_edma_pcie_irq_vector, +}; + static int dw_edma_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *pid) { @@ -151,6 +160,7 @@ static int dw_edma_pcie_probe(struct pci_dev *pdev, dw->version = pdata->version; dw->mode = pdata->mode; dw->nr_irqs = nr_irqs; + dw->ops = &dw_edma_pcie_core_ops; /* Debug info */ pci_dbg(pdev, "Version:\t%u\n", dw->version); -- 2.7.4