From patchwork Mon Jun 19 06:46:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 777593 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wrhNf4N8Vz9s76 for ; Mon, 19 Jun 2017 16:47:14 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wrhNf3XTDzDqh3 for ; Mon, 19 Jun 2017 16:47:14 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wrhNN4QQczDq7c for ; Mon, 19 Jun 2017 16:47:00 +1000 (AEST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5J6iu7D123363 for ; Mon, 19 Jun 2017 02:46:59 -0400 Received: from e23smtp04.au.ibm.com (e23smtp04.au.ibm.com [202.81.31.146]) by mx0a-001b2d01.pphosted.com with ESMTP id 2b64mrabjj-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 19 Jun 2017 02:46:58 -0400 Received: from localhost by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 19 Jun 2017 16:46:56 +1000 Received: from d23relay08.au.ibm.com (202.81.31.227) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 19 Jun 2017 16:46:53 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5J6kqCm63635592 for ; Mon, 19 Jun 2017 16:46:52 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v5J6kpuR015911 for ; Mon, 19 Jun 2017 16:46:51 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v5J6kp2Q015887; Mon, 19 Jun 2017 16:46:51 +1000 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id B3203A0281; Mon, 19 Jun 2017 16:46:51 +1000 (AEST) Received: from gwshan.ozlabs.ibm.com (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id A7421E3C84; Mon, 19 Jun 2017 16:46:51 +1000 (AEST) Received: by gwshan.ozlabs.ibm.com (Postfix, from userid 1000) id 9E3A0AC0DF8; Mon, 19 Jun 2017 16:46:51 +1000 (AEST) From: Gavin Shan To: skiboot@lists.ozlabs.org Date: Mon, 19 Jun 2017 16:46:48 +1000 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497854809-26032-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1497854809-26032-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17061906-0012-0000-0000-000002491CB5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17061906-0013-0000-0000-0000076176FF Message-Id: <1497854809-26032-4-git-send-email-gwshan@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-19_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706190114 Subject: [Skiboot] [PATCH v2 3/4] core/pci: Release IOV capability on removing device X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This introduces helper function pci_release_dev(), release the specified PCI device, to be shared in fast-reboot and PCI hot remove path. From there, pci_release_capabilities() and pci_release_iov_cap() is called to free memory allocated for IOV capability and VFs. Signed-off-by: Gavin Shan --- core/pci-iov.c | 14 ++++++++++++++ core/pci.c | 52 +++++++++++++++++++++++++++++++++------------------- include/pci-iov.h | 2 +- 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/core/pci-iov.c b/core/pci-iov.c index 627f300..9866b22 100644 --- a/core/pci-iov.c +++ b/core/pci-iov.c @@ -256,3 +256,17 @@ void pci_init_iov_cap(struct phb *phb, struct pci_device *pd) pci_iov_update_parameters(iov); pci_set_cap(pd, PCIECAP_ID_SRIOV, pos, true); } + +void pci_release_iov_cap(struct pci_device *pd) +{ + if (!pd->iov) + return; + + if (pd->iov->VFs) { + free(pd->iov->VFs); + pd->iov->VFs = NULL; + } + + free(pd->iov); + pd->iov = NULL; +} diff --git a/core/pci.c b/core/pci.c index 1aa906a..684c054 100644 --- a/core/pci.c +++ b/core/pci.c @@ -218,6 +218,11 @@ void pci_init_capabilities(struct phb *phb, struct pci_device *pd) pci_init_pm_cap(phb, pd); } +static void pci_release_capabilities(struct pci_device *pd) +{ + pci_release_iov_cap(pd); +} + static struct pci_device *pci_scan_one(struct phb *phb, struct pci_device *parent, uint16_t bdfn) { @@ -673,6 +678,26 @@ static void pci_cleanup_bridge(struct phb *phb, struct pci_device *pd) pci_cfg_write16(phb, pd->bdfn, PCI_CFG_CMD, cmd); } +static void pci_release_dev(struct phb *phb, struct pci_device *pd) +{ + if (phb->ops->device_remove) + phb->ops->device_remove(phb, pd); + + pci_release_capabilities(pd); + if (pd->dn) { + dt_free(pd->dn); + pd->dn = NULL; + } + + if (pd->slot) { + free(pd->slot); + pd->slot = NULL; + } + + list_del(&pd->link); + free(pd); +} + /* Remove all subordinate PCI devices leading from the indicated * PCI bus. It's used to remove all PCI devices behind one PCI * slot at unplugging time @@ -684,18 +709,7 @@ void pci_remove_bus(struct phb *phb, struct list_head *list) list_for_each_safe(list, pd, tmp, link) { pci_remove_bus(phb, &pd->children); - if (phb->ops->device_remove) - phb->ops->device_remove(phb, pd); - - /* Release device node and PCI slot */ - if (pd->dn) - dt_free(pd->dn); - if (pd->slot) - free(pd->slot); - - /* Remove from parent list and release itself */ - list_del(&pd->link); - free(pd); + pci_release_dev(phb, pd); } } @@ -1631,14 +1645,14 @@ void pci_add_device_nodes(struct phb *phb, } } -static void __pci_reset(struct list_head *list) +static void __pci_reset(struct phb *phb, struct list_head *list) { - struct pci_device *pd; + struct pci_device *pd, *tmp; - while ((pd = list_pop(list, struct pci_device, link)) != NULL) { - __pci_reset(&pd->children); - dt_free(pd->dn); - free(pd); + list_for_each_safe(list, pd, tmp, link) { + __pci_reset(phb, &pd->children); + + pci_release_dev(phb, pd); } } @@ -1657,7 +1671,7 @@ void pci_reset(void) struct phb *phb = phbs[i]; if (!phb) continue; - __pci_reset(&phb->devices); + __pci_reset(phb, &phb->devices); slot = phb->slot; if (!slot || !slot->ops.creset) { diff --git a/include/pci-iov.h b/include/pci-iov.h index 787b2cd..18da320 100644 --- a/include/pci-iov.h +++ b/include/pci-iov.h @@ -33,5 +33,5 @@ struct pci_iov { }; extern void pci_init_iov_cap(struct phb *phb, struct pci_device *pd); - +extern void pci_release_iov_cap(struct pci_device *pd); #endif