From patchwork Tue Jun 10 01:56:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 357701 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DE7F51400AF for ; Tue, 10 Jun 2014 12:07:49 +1000 (EST) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id C59081A17FF for ; Tue, 10 Jun 2014 12:07:49 +1000 (EST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from e28smtp04.in.ibm.com (e28smtp04.in.ibm.com [122.248.162.4]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 1DA801A02CA for ; Tue, 10 Jun 2014 11:57:20 +1000 (EST) Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 10 Jun 2014 07:27:19 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp04.in.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 10 Jun 2014 07:27:17 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 91BB31258053 for ; Tue, 10 Jun 2014 07:26:38 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5A1w85u55377978 for ; Tue, 10 Jun 2014 07:28:08 +0530 Received: from d28av01.in.ibm.com (localhost [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5A1vGYx029693 for ; Tue, 10 Jun 2014 07:27:16 +0530 Received: from localhost (richard.cn.ibm.com [9.111.17.78]) by d28av01.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s5A1vFrF029647; Tue, 10 Jun 2014 07:27:15 +0530 From: Wei Yang To: benh@au1.ibm.com Subject: [RFC PATCH V3 14/17] ppc/pci: create/release dev-tree node for VFs Date: Tue, 10 Jun 2014 09:56:36 +0800 Message-Id: <1402365399-5121-15-git-send-email-weiyang@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1402365399-5121-1-git-send-email-weiyang@linux.vnet.ibm.com> References: <1402365399-5121-1-git-send-email-weiyang@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14061001-5564-0000-0000-00000E3898F3 Cc: Wei Yang , linux-pci@vger.kernel.org, gwshan@linux.vnet.ibm.com, qiudayu@linux.vnet.ibm.com, bhelgaas@google.com, yan@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Currently, powernv platform is not aware of VFs. This means no dev-node represents a VF. Also, VF PCI device is created when PF driver want to enable it. This leads to the pdn->pdev and pdn->pe_number an invalid value. This patch create/release dev-node for VF and fixs this when a VF's pci_dev is created. Signed-off-by: Wei Yang --- arch/powerpc/platforms/powernv/Kconfig | 1 + arch/powerpc/platforms/powernv/pci-ioda.c | 103 +++++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/pci.c | 20 ++++++ 3 files changed, 124 insertions(+) diff --git a/arch/powerpc/platforms/powernv/Kconfig b/arch/powerpc/platforms/powernv/Kconfig index 895e8a2..0dd331b 100644 --- a/arch/powerpc/platforms/powernv/Kconfig +++ b/arch/powerpc/platforms/powernv/Kconfig @@ -11,6 +11,7 @@ config PPC_POWERNV select PPC_UDBG_16550 select PPC_SCOM select ARCH_RANDOM + select OF_DYNAMIC default y config PPC_POWERNV_RTAS diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c index e46c5bf..9ace027 100644 --- a/arch/powerpc/platforms/powernv/pci-ioda.c +++ b/arch/powerpc/platforms/powernv/pci-ioda.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -771,6 +772,108 @@ static void pnv_pci_ioda_setup_PEs(void) } } +#ifdef CONFIG_PCI_IOV +static void pnv_pci_create_vf_node(struct pci_dev *dev, u16 vf_num) +{ + struct device_node *dn, *p_dn; + struct pci_dn *pdn; + struct pci_controller *hose; + struct property *pp; + void* value; + u16 id; + + hose = pci_bus_to_host(dev->bus); + + /* Create dev-tree node for VFs if this is a PF */ + p_dn = pci_bus_to_OF_node(dev->bus); + if (p_dn == NULL) { + dev_err(&dev->dev, "SRIOV: VF bus NULL device node\n"); + return; + } + + for (id = 0; id < vf_num; id++) { + dn = kzalloc(sizeof(*dn), GFP_KERNEL); + pdn = kzalloc(sizeof(*pdn), GFP_KERNEL); + pp = kzalloc(sizeof(*pp), GFP_KERNEL); + value = kzalloc(sizeof(u32), GFP_KERNEL); + + if (!dn || !pdn || !pp || !value) { + kfree(dn); + kfree(pdn); + kfree(pp); + kfree(value); + dev_warn(&dev->dev, "%s: failed to create" + "dev-tree node for idx(%d)\n", + __func__, id); + + break; + } + + pp->value = value; + pdn->node = dn; + pdn->devfn = pci_iov_virtfn_devfn(dev, id); + pdn->busno = dev->bus->number; + pdn->pe_number = IODA_INVALID_PE; + pdn->phb = hose; + + dn->data = pdn; + kref_init(&dn->kref); + dn->full_name = dn->name = + kasprintf(GFP_KERNEL, "%s/vf%d", + p_dn->full_name, pdn->devfn); + dn->parent = p_dn; + + pp->name = kasprintf(GFP_KERNEL, "reg"); + pp->length = 5 * sizeof(__be32); + *(u32*)pp->value = cpu_to_be32(pdn->devfn) << 8; + dn->properties = pp; + + of_attach_node(dn); + } +} + +static void pnv_pci_release_vf_node(struct pci_dev *dev, u16 vf_num) +{ + struct device_node *dn; + struct property *pp; + u16 id; + + for (id = 0; id < vf_num; id++) { + dn = of_pci_find_child_device(dev->bus->dev.of_node, + pci_iov_virtfn_devfn(dev, id)); + if (!dn) + continue; + + of_detach_node(dn); + pp = dn->properties; + kfree(pp->name); + kfree(pp->value); + kfree(pp); + kfree(dn->data); + kfree(dn); + } +} + +int pcibios_sriov_disable(struct pci_dev *pdev) +{ + struct pci_sriov *iov; + u16 vf_num; + + iov = pdev->sriov; + vf_num = iov->num_VFs; + pnv_pci_release_vf_node(pdev, vf_num); + + return 0; +} + +int pcibios_sriov_enable(struct pci_dev *pdev, u16 vf_num) +{ + pnv_pci_create_vf_node(pdev, vf_num); + + return 0; +} +#endif /* CONFIG_PCI_IOV */ + static void pnv_pci_ioda_dma_dev_setup(struct pnv_phb *phb, struct pci_dev *pdev) { struct pci_dn *pdn = pci_get_pdn(pdev); diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c index 687a068..43fcc73 100644 --- a/arch/powerpc/platforms/powernv/pci.c +++ b/arch/powerpc/platforms/powernv/pci.c @@ -654,6 +654,26 @@ static void pnv_pci_dma_dev_setup(struct pci_dev *pdev) { struct pci_controller *hose = pci_bus_to_host(pdev->bus); struct pnv_phb *phb = hose->private_data; +#ifdef CONFIG_PCI_IOV + struct pnv_ioda_pe *pe; + struct pci_dn *pdn; + + /* Fix the VF pdn PE number */ + if (pdev->is_virtfn) { + pdn = pci_get_pdn(pdev); + if (pdn->pcidev == NULL || pdn->pe_number == IODA_INVALID_PE) { + list_for_each_entry(pe, &phb->ioda.pe_list, list) { + if (pe->rid == + ((pdev->bus->number << 8) | (pdev->devfn & 0xff))) { + pdn->pcidev = pdev; + pdn->pe_number = pe->pe_number; + pe->pdev = pdev; + break; + } + } + } + } +#endif /* CONFIG_PCI_IOV */ /* If we have no phb structure, try to setup a fallback based on * the device-tree (RTAS PCI for example)