Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp607338ybz; Wed, 15 Apr 2020 15:03:07 -0700 (PDT) X-Google-Smtp-Source: APiQypLRWzguV4tzsce5JGNOPy6pD8cmtrsYpHE6bmSdupp0ypsKQJiUOBWQK9Z8P3Py/U8uZsl4 X-Received: by 2002:a17:906:4714:: with SMTP id y20mr2871891ejq.5.1586988187799; Wed, 15 Apr 2020 15:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586988187; cv=none; d=google.com; s=arc-20160816; b=tFGQnLUizMHJpv90Jv2FOd7uobAMRQyxc5VEp19+/3GQP52r97Qml03kHrV4SLus1q /AKTOeYhEFk6RFQo9+d4QLOw8soitmtOSjqhFqcg/r/dbEMNsVw6diRT/UzBR3iR5t08 5CQuZMOSTylxVesce+MJejGWCtcvyXi3wmQKcQcIf92OklPoDpI7haxqImV4L6DhwVKP VZMmIHr0lkCshpqQYrSFoOQxNvrGrbBXEm8j6QuUJ0p4VLXpJ8/RjN5Ho8LYJdichUIH SlToWi9BYSv+8NPRl3ZYR6qGXllW2L9v1HozLdNMrhlGr9UECxfhFQezUeM4y76UgaiT OnVw== 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=u2+cGS1cRmAclSEhKu1ZjnWLakz4YOOfQzuWAv57OAM=; b=stKt8NByHDVJupJX4oSswwXgQ+kWh/e2hvlQIrxJPz7MKa1ZNjy51XKk2o8SrV2csl f/VMvzDctemcDMA1HmKH9/Qwa2ZMqlZY2xE+/46SuIQtqOuQDTlMVm8D0DCo0E875sO2 Y3nwFBskrf0Wp+TzXhK1dNxW3IVgJ7U4nd4gU0DOoxTgXYFLzShYsaQ1YqnYYkWH2G/x crQB2iOj1G2SR2Vgg1jGCReUM5s+CXeLe8tKdi70spwalgvHVUa5QcxYDkSm/oRA3mCp gaBk2mQnVjFU0OQesvWjQ6ucTStlc1FcoA4vlDxmo5y+VQmpA0zg9AKDvWU4hPKherjx lo+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=XCsJXqiL; 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 i13si13093719edt.174.2020.04.15.15.02.41; Wed, 15 Apr 2020 15:03:07 -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=XCsJXqiL; 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 S2392789AbgDOCH7 (ORCPT + 99 others); Tue, 14 Apr 2020 22:07:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392842AbgDOCH4 (ORCPT ); Tue, 14 Apr 2020 22:07:56 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72285C061A0E for ; Tue, 14 Apr 2020 19:07:55 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id a22so1664411pjk.5 for ; Tue, 14 Apr 2020 19:07:55 -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=u2+cGS1cRmAclSEhKu1ZjnWLakz4YOOfQzuWAv57OAM=; b=XCsJXqiLpCpNyksP4j7p6/CF+p6B1Z/TWHZg7DYLvgKLnFfZq6jrVa0Ro2XOLyq05O Mr2GOMBFAVcJ8mb9nIaT/cRwsrBdMOmCPZiD4j4d4XM0LBomAJuXe9CBFklYjV6y6OqR fi9MYbiUUFCczPMZtvUkoM0WNzpjX6SaWp5aI43UP3oJEz8Dd7gmaO/EW1ki3BqssLRt xhfQWS0+otSmtaf3zBU9higbiMsGbWY5+ZnKVPzaMJ4MisDEr0FJCZGddqcnNcXvjz4v 8K+WD/WTG+iCjEUSYbmflqi4H2UTd1n0MUtnG5iOpJ95qIE4wnAyDWCwCv4sqth7tgwY pvbQ== 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=u2+cGS1cRmAclSEhKu1ZjnWLakz4YOOfQzuWAv57OAM=; b=ZVBL6g49LHfPcr3aN34Ww7khX0GmMLTXTahKkJTN7G9tCqzwSIpgiHMhae4lYxInEJ sQkjR29kHuM0BZuK5u4LCQCn50urk45q+ZrRlCnk1AllYnMD6c4bvspUFuN7iNJTtXIC M7dX9WKUqp/eRK/8UoghaZ47FDNoYA6HD5kFMuoJMf3pYy5iLwq9GftE4LZM8tOm6res uKe2HIRr6CkZW68UO1+S+DD4StPMuNmISQiVldlSc5eb9V87wMFaHMFe1P9uNTDzNv8B b/SYK7ciFzgXomJCHGJOU2/f7j1K8nNj37nP0y+QDZdmmR2Tot4fUO/C9wSksRrKByfK 72xA== X-Gm-Message-State: AGi0Pub4LLoy9+2WhAjnA2/6AH/ijii9F1rAQS6kPNZrE/qLus3wvgZr QMYawNhyK4cYlqNrXcuokIZNIg== X-Received: by 2002:a17:902:a503:: with SMTP id s3mr2821309plq.303.1586916474702; Tue, 14 Apr 2020 19:07:54 -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 v67sm8362776pfb.83.2020.04.14.19.07.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Apr 2020 19:07:53 -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 RFC] dmaengine: dw-edma: Decouple dw-edma-core.c from struct pci_dev Date: Tue, 14 Apr 2020 19:07:44 -0700 Message-Id: <1586916464-27727-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 While reviewing the Synopsys Designware eDMA PCIe driver, I came across the following field of struct dw_edma in dw-edma-core.h: const struct dw_edma_core_ops *ops; I was unable to find a definition for struct dw_edma_core_ops. It was surprising that the kernel would build without failure even though the dw-edma driver was enabled with what seems to be an undefined struct. The reason I was reviewing the dw-edma driver was to see if I could integrate it with pcitest to initiate dma operations from endpoint side. As I understand from reviewing the dw-edma code, it is designed to run on the host side of PCIe link to initiate DMA operations remotely using eDMA channels of PCIe controller on the endpoint side. I am not sure if my understanding is correct. I infer this from seeing that dw-edma uses struct pci_dev and accesses hardware registers of dma channels across the bus using BAR0 and BAR2. I was exploring what would need to change in dw-edma to integrate it with pci-epf-test to initiate dma operations locally from the endpoint side. One barrier I see is dw_edma_probe() and other functions in dw-edma-core.c depend on struct pci_dev. Hence, instead of posting a patch to remove the undefined and unused ops field, I would like to define the struct and use it to decouple dw-edma-core.c from struct pci_dev. To my surprise, the kernel still builds without error even after defining struct dw_edma_core_ops in dw-edma-core.h and using it as in this patch. I would appreciate any comments on my observations about the 'ops' field, decoupling dw-edma-core.c from struct pci_dev, and how best to use dw-edma with pcitest. Signed-off-by: Alan Mikhak --- drivers/dma/dw-edma/dw-edma-core.c | 17 ++++++++++------- drivers/dma/dw-edma/dw-edma-core.h | 4 ++++ drivers/dma/dw-edma/dw-edma-pcie.c | 10 ++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index ff392c01bad1..9417a5feabbf 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); } @@ -833,6 +833,9 @@ int dw_edma_probe(struct dw_edma_chip *chip) u32 rd_alloc = 0; int i, err; + if (!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 +887,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 +907,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