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: 4326401 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E5B9C9F466 for ; Tue, 10 Jun 2014 01:57:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0000C20148 for ; Tue, 10 Jun 2014 01:57:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6799920176 for ; Tue, 10 Jun 2014 01:57:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934003AbaFJB5V (ORCPT ); Mon, 9 Jun 2014 21:57:21 -0400 Received: from e28smtp02.in.ibm.com ([122.248.162.2]:50170 "EHLO e28smtp02.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933943AbaFJB5U (ORCPT ); Mon, 9 Jun 2014 21:57:20 -0400 Received: from /spool/local by e28smtp02.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 10 Jun 2014 07:27:18 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp02.in.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 10 Jun 2014 07:27:17 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 929A8E004B for ; Tue, 10 Jun 2014 07:28:15 +0530 (IST) Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5A1w7FD7274760 for ; Tue, 10 Jun 2014 07:28:07 +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 s5A1vGZ1029693 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 Cc: linuxppc-dev@lists.ozlabs.org, bhelgaas@google.com, linux-pci@vger.kernel.org, gwshan@linux.vnet.ibm.com, yan@linux.vnet.ibm.com, qiudayu@linux.vnet.ibm.com, Wei Yang 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-5816-0000-0000-00000E82AA2F Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)