From patchwork Mon Oct 18 12:37:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Barrat X-Patchwork-Id: 1542581 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=loD+jePD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HXxHM5pcnz9sPf for ; Mon, 18 Oct 2021 23:38:07 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HXxHL6BNFz2yw2 for ; Mon, 18 Oct 2021 23:38:06 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=loD+jePD; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=fbarrat@linux.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=loD+jePD; dkim-atps=neutral Received: from mx0b-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 4HXxHC715Jz2xtF for ; Mon, 18 Oct 2021 23:37:59 +1100 (AEDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19I9uru5005316 for ; Mon, 18 Oct 2021 08:37:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=QSEEYO0nTWofHcWotzKQ7m9ruy1b9ZiNOgMO7uceGmg=; b=loD+jePDhNmVSSVAehwO/LOGc3vNkwVPrwpRNXZHOp5cXdvw7IcO75oCbVcxfdV0i5FL rd8Q3XJiE9yR4RVxC0AUMhY77tDchDk3aTIiv/pWNsZ0dXNpYBwxFzIbYUBYmFTgaHfI ER6zR9YSmcETDYBc7vXWD5igaJPHuv+R6LGYSGk26/0f66ESme+VH0TFuYM7WQ3kqMLB nDIRyMHEhrPlVh8vIAojKPslqplNTGcFjSv4BggIBh+MTsCn3n3VnpI+xPcRorpzyGYq WCDEafzINSdLt09bVPm8PL7pKIiPoIovt7M+KqXV06805+GqMAzgsr5T5CVeJkr6N7QV lw== Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3bs1u59e4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 18 Oct 2021 08:37:57 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 19ICbTdf021867 for ; Mon, 18 Oct 2021 12:37:55 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 3bqp0je81n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 18 Oct 2021 12:37:55 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 19ICbrZG2818696 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 18 Oct 2021 12:37:53 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D6D414C044 for ; Mon, 18 Oct 2021 12:37:52 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B6E164C066 for ; Mon, 18 Oct 2021 12:37:52 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.170.57]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Mon, 18 Oct 2021 12:37:52 +0000 (GMT) From: Frederic Barrat To: skiboot@lists.ozlabs.org Date: Mon, 18 Oct 2021 14:37:49 +0200 Message-Id: <20211018123751.72794-5-fbarrat@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018123751.72794-1-fbarrat@linux.ibm.com> References: <20211018123751.72794-1-fbarrat@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: y55Dqzz8h7ue_sGLtfCZnNKAcawEW0VN X-Proofpoint-ORIG-GUID: y55Dqzz8h7ue_sGLtfCZnNKAcawEW0VN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-10-18_03,2021-10-14_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 spamscore=0 clxscore=1015 adultscore=0 suspectscore=0 mlxscore=0 phishscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110180075 Subject: [Skiboot] [PATCH 4/6] rainier: Define PCI slot table X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Define the table of PCI slots for Rainier, reusing the existing slot table infrastructure. For each slot, add the information useful to control power through the hotplug controller. This patch also redefines the slot power management callbacks to route them to the previously introduced hotplug controller interfaces. Signed-off-by: Frederic Barrat --- platforms/astbmc/rainier.c | 159 ++++++++++++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 2 deletions(-) diff --git a/platforms/astbmc/rainier.c b/platforms/astbmc/rainier.c index 467e6d5a..baa93254 100644 --- a/platforms/astbmc/rainier.c +++ b/platforms/astbmc/rainier.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "astbmc.h" @@ -46,6 +47,61 @@ struct slot_hp_data { uint8_t slot_index; }; +#define RAINIER_HP_DATA(st_name, controller, n) \ + static const struct slot_hp_data st_name = { \ + .hp_controller = &(controller), \ + .slot_index = n, \ + } + +#define RAINIER_SLOT_DEF(st_name, slot_name, hp_data) \ + static const struct slot_table_entry st_name[] = { \ + { \ + .etype = st_pluggable_slot, \ + .name = slot_name, \ + .platform_data = &(hp_data), \ + }, \ + { .etype = st_end }, \ + } + +RAINIER_HP_DATA(c7_data, hp_controller_dcm0, 0); +RAINIER_HP_DATA(c8_data, hp_controller_dcm0, 1); +RAINIER_HP_DATA(c9_data, hp_controller_dcm0, 2); +RAINIER_HP_DATA(c10_data, hp_controller_dcm0, 3); +RAINIER_HP_DATA(c11_data, hp_controller_dcm0, 4); +RAINIER_SLOT_DEF(p1phb3_slot, "C7", c7_data); +RAINIER_SLOT_DEF(p1phb1_slot, "C8", c8_data); +RAINIER_SLOT_DEF(p1phb0_slot, "C9", c9_data); +RAINIER_SLOT_DEF(p0phb3_slot, "C10", c10_data); +RAINIER_SLOT_DEF(p0phb0_slot, "C11", c11_data); + +RAINIER_HP_DATA(c0_data, hp_controller_dcm1, 0); +RAINIER_HP_DATA(c1_data, hp_controller_dcm1, 1); +RAINIER_HP_DATA(c2_data, hp_controller_dcm1, 2); +RAINIER_HP_DATA(c3_data, hp_controller_dcm1, 3); +RAINIER_HP_DATA(c4_data, hp_controller_dcm1, 4); +RAINIER_SLOT_DEF(p3phb3_slot, "C0", c0_data); +RAINIER_SLOT_DEF(p3phb1_slot, "C1", c1_data); +RAINIER_SLOT_DEF(p3phb0_slot, "C2", c2_data); +RAINIER_SLOT_DEF(p2phb3_slot, "C3", c3_data); +RAINIER_SLOT_DEF(p2phb0_slot, "C4", c4_data); + +static const struct slot_table_entry rainier_phb_table[] = { + ST_PHB_ENTRY(0, 0, p0phb0_slot), + ST_PHB_ENTRY(0, 3, p0phb3_slot), + + ST_PHB_ENTRY(2, 0, p1phb0_slot), + ST_PHB_ENTRY(2, 1, p1phb1_slot), + ST_PHB_ENTRY(2, 3, p1phb3_slot), + + ST_PHB_ENTRY(4, 0, p2phb0_slot), + ST_PHB_ENTRY(4, 3, p2phb3_slot), + + ST_PHB_ENTRY(6, 0, p3phb0_slot), + ST_PHB_ENTRY(6, 1, p3phb1_slot), + ST_PHB_ENTRY(6, 3, p3phb3_slot), + { .etype = st_end }, +}; + static int64_t hp_controller_i2c_read(struct hp_controller *hpc, uint32_t *data) { @@ -127,7 +183,7 @@ unlock: return rc; } -static void __unused timer_check_enable(struct timer *t __unused, void *data, +static void timer_check_enable(struct timer *t __unused, void *data, uint64_t now __unused) { struct pci_slot *slot = data; @@ -176,7 +232,7 @@ unlock: return rc; } -static int64_t __unused hp_controller_disable(struct hp_controller *hpc, int slot_index) +static int64_t hp_controller_disable(struct hp_controller *hpc, int slot_index) { uint32_t state, en_mask, ctl_mask, pg_mask; uint64_t rc = OPAL_SUCCESS; @@ -227,11 +283,108 @@ static void hp_controller_init(struct hp_controller *hpc, uint32_t chip_id) } } +static int64_t rainier_pci_slot_get_power_state(struct pci_slot *slot, + uint8_t *val) +{ + uint32_t state, en_mask, ctl_mask, pg_mask; + struct slot_table_entry *ent = slot->data; + const struct slot_hp_data *hp_data; + struct hp_controller *hpc; + uint32_t slot_index; + + if (!ent || !ent->platform_data) + return OPAL_PARAMETER; + + hp_data = ent->platform_data; + slot_index = hp_data->slot_index; + hpc = hp_data->hp_controller; + + hp_get_masks(slot_index, &en_mask, &pg_mask, &ctl_mask); + + lock(&hpc->lock); + hp_controller_i2c_read(hpc, &state); + unlock(&hpc->lock); + + *val = (state & en_mask) && (state & pg_mask); + return 0; +} + +static int64_t rainier_pci_slot_set_power_state(struct pci_slot *slot, + uint8_t val) +{ + struct slot_table_entry *ent = slot->data; + const struct slot_hp_data *hp_data; + struct hp_controller *hpc; + uint32_t slot_index; + int64_t rc; + + if (!ent || !ent->platform_data) + return OPAL_PARAMETER; + if (val != PCI_SLOT_POWER_OFF && val != PCI_SLOT_POWER_ON) + return OPAL_PARAMETER; + + hp_data = ent->platform_data; + slot_index = hp_data->slot_index; + hpc = hp_data->hp_controller; + + slot->power_state = val; + if (val == PCI_SLOT_POWER_ON) { + rc = hp_controller_enable(hpc, slot_index); + if (!rc) { + /* schedule to check state of PGOOD after 2s */ + init_timer(&hpc->slot_timer[slot_index], + timer_check_enable, slot); + schedule_timer(&hpc->slot_timer[slot_index], + msecs_to_tb(PGOOD_QUERY_WINDOW)); + pci_slot_set_state(slot, PCI_SLOT_STATE_SPOWER_START); + rc = OPAL_ASYNC_COMPLETION; + } + } else { + rc = hp_controller_disable(hpc, slot_index); + } + return rc; +} + +static void rainier_get_slot_info(struct phb *phb, struct pci_device *pd) +{ + struct pci_slot *slot; + + if (!pd || pd->slot) + return; + + slot_table_get_slot_info(phb, pd); + if (!pd->slot) + return; + + slot = pd->slot; + if (!pd->parent && phb->slot) { + void (*tmp)(struct pci_slot *slot, struct dt_node *np); + /* + * For PHB slots, keep the ops of the PHB, except for + * add_properties, which was defined by the slot table + * framework and takes care of things like slot label, + * location, ... + */ + tmp = slot->ops.add_properties; + memcpy(&slot->ops, &phb->slot->ops, + sizeof(struct pci_slot_ops)); + slot->ops.add_properties = tmp; + } + + if (slot->data) { + /* slots defined in our slot table support power management */ + slot->ops.get_power_state = rainier_pci_slot_get_power_state; + slot->ops.set_power_state = rainier_pci_slot_set_power_state; + } +} + static void rainier_pci_probe_complete(void) { prlog(PR_DEBUG, "PLAT: checking power of PCI slots\n"); hp_controller_check_enable(&hp_controller_dcm0, -1); hp_controller_check_enable(&hp_controller_dcm1, -1); + + check_all_slot_table(); } static void rainier_init_slot_power(void) @@ -246,6 +399,7 @@ static void rainier_init_slot_power(void) static void rainier_init(void) { astbmc_init(); + slot_table_init(rainier_phb_table); rainier_init_slot_power(); } @@ -274,6 +428,7 @@ DECLARE_PLATFORM(rainier) = { .bmc = &bmc_plat_ast2600_openbmc, .cec_power_down = astbmc_ipmi_power_down, .cec_reboot = astbmc_ipmi_reboot, + .pci_get_slot_info = rainier_get_slot_info, .pci_probe_complete = rainier_pci_probe_complete, .elog_commit = ipmi_elog_commit, .exit = astbmc_exit,