From patchwork Thu Aug 11 04:55:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 658003 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 AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s8wgy2qDkz9sR9 for ; Thu, 11 Aug 2016 14:55:42 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3s8wgy1nNjzDr12 for ; Thu, 11 Aug 2016 14:55:42 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 3s8wgj48LTzDqfj for ; Thu, 11 Aug 2016 14:55:29 +1000 (AEST) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7B4sN6Y044793 for ; Thu, 11 Aug 2016 00:55:26 -0400 Received: from e23smtp02.au.ibm.com (e23smtp02.au.ibm.com [202.81.31.144]) by mx0b-001b2d01.pphosted.com with ESMTP id 24qm9sv2ss-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 11 Aug 2016 00:55:26 -0400 Received: from localhost by e23smtp02.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 11 Aug 2016 14:55:23 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp02.au.ibm.com (202.81.31.208) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 11 Aug 2016 14:55:22 +1000 X-IBM-Helo: d23dlp03.au.ibm.com X-IBM-MailFrom: gwshan@linux.vnet.ibm.com X-IBM-RcptTo: skiboot@lists.ozlabs.org Received: from d23relay07.au.ibm.com (d23relay07.au.ibm.com [9.190.26.37]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 693743578053 for ; Thu, 11 Aug 2016 14:55:22 +1000 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u7B4tM2o26673300 for ; Thu, 11 Aug 2016 14:55:22 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u7B4tL2d024354 for ; Thu, 11 Aug 2016 14:55:22 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u7B4tL3Q024333; Thu, 11 Aug 2016 14:55:21 +1000 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 39011A013E; Thu, 11 Aug 2016 14:55:21 +1000 (AEST) Received: from gwshan (shangw.ozlabs.ibm.com [10.61.2.199]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id 27227E3BD5; Thu, 11 Aug 2016 14:55:21 +1000 (AEST) Received: by gwshan (Postfix, from userid 1000) id ED4E5941D9A; Thu, 11 Aug 2016 14:55:20 +1000 (AEST) From: Gavin Shan To: skiboot@lists.ozlabs.org Date: Thu, 11 Aug 2016 14:55:15 +1000 X-Mailer: git-send-email 2.1.0 In-Reply-To: <1470891318-23046-1-git-send-email-gwshan@linux.vnet.ibm.com> References: <1470891318-23046-1-git-send-email-gwshan@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16081104-0004-0000-0000-00000185148E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16081104-0005-0000-0000-00000870FDEF Message-Id: <1470891318-23046-5-git-send-email-gwshan@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-08-11_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608110057 Subject: [Skiboot] [PATCH 4/7] core/pci: Fix initial PCIe slot power state X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: shlimeng@cn.ibm.com, jiangyu@cn.ibm.com MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The initial PCIe slot power state should be retrieved from the PCIe Slot Control register (offset: +0x18), instead of having the fixed state (power-off) wrongly. Otherwise, we possibly have mismatched states by software and hardware. One side-effect is PCIe slot can not be powered off from hardware for the first time. This fixes above issue by fetching the initial PCIe slot power state from hardware (PCIe Slot Control register) if the power control is supported on the slot. Otherwise, it doesn't matter on what we have for the initial PCIe slot power state. Signed-off-by: Gavin Shan --- core/pcie-slot.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/pcie-slot.c b/core/pcie-slot.c index 62933a4..358e61a 100644 --- a/core/pcie-slot.c +++ b/core/pcie-slot.c @@ -404,6 +404,7 @@ struct pci_slot *pcie_slot_create(struct phb *phb, struct pci_device *pd) { struct pci_slot *slot; uint32_t ecap; + uint16_t slot_ctl; /* Allocate PCI slot */ slot = pci_slot_alloc(phb, pd); @@ -422,8 +423,20 @@ struct pci_slot *pcie_slot_create(struct phb *phb, struct pci_device *pd) if ((slot->slot_cap & PCICAP_EXP_SLOTCAP_HPLUG_SURP) && (slot->slot_cap & PCICAP_EXP_SLOTCAP_HPLUG_CAP)) slot->pluggable = 1; - if (slot->slot_cap & PCICAP_EXP_SLOTCAP_PWCTRL) + + if (slot->slot_cap & PCICAP_EXP_SLOTCAP_PWCTRL) { slot->power_ctl = 1; + + /* The power is on by default */ + slot->power_state = 1; + if (pd && ecap) { + pci_cfg_read16(phb, pd->bdfn, + ecap + PCICAP_EXP_SLOTCTL, &slot_ctl); + if (slot_ctl & PCICAP_EXP_SLOTCTL_PWRCTLR) + slot->power_state = 0; + } + } + if (slot->slot_cap & PCICAP_EXP_SLOTCAP_PWRI) slot->power_led_ctl = PCI_SLOT_PWR_LED_CTL_KERNEL; if (slot->slot_cap & PCICAP_EXP_SLOTCAP_ATTNI)