From patchwork Wed Mar 13 23:28:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 2266811 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id AF6EE3FD8C for ; Wed, 13 Mar 2013 23:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934428Ab3CMXe6 (ORCPT ); Wed, 13 Mar 2013 19:34:58 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:17537 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934441Ab3CMX2b (ORCPT ); Wed, 13 Mar 2013 19:28:31 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r2DNSQN1015250 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 13 Mar 2013 23:28:26 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r2DNSPou019199 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 13 Mar 2013 23:28:25 GMT Received: from abhmt103.oracle.com (abhmt103.oracle.com [141.146.116.55]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r2DNSP3s030465; Wed, 13 Mar 2013 18:28:25 -0500 Received: from linux-siqj.site (/10.132.126.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 Mar 2013 16:28:25 -0700 From: Yinghai Lu To: Bjorn Helgaas , Ram Pai Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v3 08/27] PCI: Use for_each_pci_resource() with IOV releated functions Date: Wed, 13 Mar 2013 16:28:03 -0700 Message-Id: <1363217302-14383-9-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1363217302-14383-1-git-send-email-yinghai@kernel.org> References: <1363217302-14383-1-git-send-email-yinghai@kernel.org> X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Signed-off-by: Yinghai Lu --- drivers/pci/iov.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index ee599f2..baf6c80 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -93,17 +93,20 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset) pci_setup_device(virtfn); virtfn->dev.parent = dev->dev.parent; - for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = dev->resource + PCI_IOV_RESOURCES + i; + for_each_pci_resource(dev, res, i, PCI_IOV_RES) { + struct resource *virtfn_res; + if (!res->parent) continue; - virtfn->resource[i].name = pci_name(virtfn); - virtfn->resource[i].flags = res->flags; + + virtfn_res = pci_dev_resource_n(virtfn, i - PCI_IOV_RESOURCES); + virtfn_res->name = pci_name(virtfn); + virtfn_res->flags = res->flags; size = resource_size(res); do_div(size, iov->total_VFs); - virtfn->resource[i].start = res->start + size * id; - virtfn->resource[i].end = virtfn->resource[i].start + size - 1; - rc = request_resource(res, &virtfn->resource[i]); + virtfn_res->start = res->start + size * id; + virtfn_res->end = virtfn_res->start + size - 1; + rc = request_resource(res, virtfn_res); BUG_ON(rc); } @@ -305,9 +308,8 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) return -EIO; nres = 0; - for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - bars |= (1 << (i + PCI_IOV_RESOURCES)); - res = dev->resource + PCI_IOV_RESOURCES + i; + for_each_pci_resource(dev, res, i, PCI_IOV_RES) { + bars |= 1 << i; if (res->parent) nres++; } @@ -465,10 +467,9 @@ found: pci_write_config_dword(dev, pos + PCI_SRIOV_SYS_PGSIZE, pgsz); nres = 0; - for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = dev->resource + PCI_IOV_RESOURCES + i; + for_each_pci_resource(dev, res, i, PCI_IOV_RES) { i += __pci_read_base(dev, pci_bar_unknown, res, - pos + PCI_SRIOV_BAR + i * 4); + pos + PCI_SRIOV_BAR + (i - PCI_IOV_RESOURCES) * 4); if (!res->flags) continue; if (resource_size(res) & (PAGE_SIZE - 1)) { @@ -511,10 +512,8 @@ found: return 0; failed: - for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { - res = dev->resource + PCI_IOV_RESOURCES + i; + for_each_pci_resource(dev, res, i, PCI_IOV_RES) res->flags = 0; - } return rc; }