From patchwork Wed Nov 28 11:02:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasant Hegde X-Patchwork-Id: 1004434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 434dDX03NRz9ryk for ; Wed, 28 Nov 2018 22:08:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 434dDW5WlQzDqhs for ; Wed, 28 Nov 2018 22:08:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=hegdevasant@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com 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 434d7J0KY2zDqgL for ; Wed, 28 Nov 2018 22:03:39 +1100 (AEDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wASB0d0l098033 for ; Wed, 28 Nov 2018 06:03:38 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p1ps2qhqk-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 28 Nov 2018 06:03:38 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 28 Nov 2018 11:03:35 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 28 Nov 2018 11:03:32 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wASB3VYX51118180 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 28 Nov 2018 11:03:31 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9ACF0A404D; Wed, 28 Nov 2018 11:03:31 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 12C9AA4040; Wed, 28 Nov 2018 11:03:30 +0000 (GMT) Received: from hegdevasant.in.ibm.com (unknown [9.109.198.143]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 28 Nov 2018 11:03:29 +0000 (GMT) From: Vasant Hegde To: skiboot@lists.ozlabs.org Date: Wed, 28 Nov 2018 16:32:36 +0530 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181128110244.17664-1-hegdevasant@linux.vnet.ibm.com> References: <20181128110244.17664-1-hegdevasant@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18112811-0012-0000-0000-000002D16D76 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112811-0013-0000-0000-00002106B1F2 Message-Id: <20181128110244.17664-15-hegdevasant@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-11-28_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811280100 Subject: [Skiboot] [PATCH v6 14/22] fadump: Add OPAL API to register for fadump 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: , Cc: stewart@linux.vnet.ibm.com, hbathini@linux.vnet.ibm.com MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This patch adds new API for fadump. int64_t opal_fadump_manage(uint64_t cmd, void *data, uint64_t dsize) cmd : 0x01 -> Register for fadump 0x02 -> Unregister fadump 0x03 -> Invalidate existing dump data : For cmd = 0x01, data contains payload section reservation details (uses fadump structure format to send data). For other cmd values, data will be NULL. dsize: Size of data Return values: OPAL_SUCCESS : Operation success OPAL_PARAMETER : Payload passed invalid data OPAL_RESOURCE : Ran out of MDST, MDDT table size OPAL_PERMISSION: Already registered OPAL_HARDWARE : Fadump not supported Signed-off-by: Vasant Hegde --- core/opal-mpipl.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/opal-api.h | 13 +++- 2 files changed, 195 insertions(+), 1 deletion(-) diff --git a/core/opal-mpipl.c b/core/opal-mpipl.c index 2a4d13a52..1779bc56f 100644 --- a/core/opal-mpipl.c +++ b/core/opal-mpipl.c @@ -37,6 +37,186 @@ static struct spira_ntuple *ntuple_mdst; static struct spira_ntuple *ntuple_mddt; static struct spira_ntuple *ntuple_mdrt; +/* Clear MDRT memory */ +static inline void opal_fadump_invalidate(void) +{ + struct mdrt_table *mdrt = (void *)(MDRT_TABLE_BASE); + + memset(mdrt, 0, MDRT_TABLE_SIZE); + /* Reset MDRT count */ + ntuple_mdrt->act_cnt = + cpu_to_be16(MDRT_TABLE_SIZE / sizeof(struct mdrt_table)); + ntuple_mdrt->alloc_cnt = + cpu_to_be16(MDRT_TABLE_SIZE / sizeof(struct mdrt_table)); +} + +static void opal_fadump_unregister(void) +{ + int i, j; + struct mdst_table *mdst, *tmp_mdst; + struct mddt_table *mddt, *tmp_mddt; + + mdst = (void *)(MDST_TABLE_BASE); + for (i = 0; i < ntuple_mdst->act_cnt; ) { + if (mdst->dump_type != DUMP_TYPE_FADUMP || + mdst->data_region < FADUMP_REGION_HOST_START) { + mdst++; + i++; + continue; + } + + tmp_mdst = mdst; + memset(tmp_mdst, 0, sizeof(struct mdst_table)); + for (j = i; j < ntuple_mdst->act_cnt - 1; j++) { + memcpy((void *)tmp_mdst, + (void *)(tmp_mdst + 1), sizeof(struct mdst_table)); + tmp_mdst++; + memset(tmp_mdst, 0, sizeof(struct mdst_table)); + } + ntuple_mdst->act_cnt--; + } + + mddt = (void *)(MDDT_TABLE_BASE); + for (i = 0; i < ntuple_mddt->act_cnt; ) { + if (mddt->data_region < FADUMP_REGION_HOST_START) { + mddt++; + i++; + continue; + } + + tmp_mddt = mddt; + memset(tmp_mddt, 0, sizeof(struct mddt_table)); + for (j = i; j < ntuple_mddt->act_cnt - 1; j++) { + memcpy((void *)tmp_mddt, + (void *)(tmp_mddt + 1), sizeof(struct mddt_table)); + tmp_mddt++; + memset(tmp_mddt, 0, sizeof(struct mddt_table)); + } + ntuple_mddt->act_cnt--; + } +} + +static int opal_fadump_register(void *data, uint64_t dsize) +{ + int i, sec_cnt, max_mdst_entry, max_mddt_entry; + struct fadump_section *section; + struct fadump *fadump = (void *)data; + struct mdst_table *mdst = (void *)(MDST_TABLE_BASE); + struct mddt_table *mddt = (void *)(MDDT_TABLE_BASE); + + if (dsize < sizeof(struct fadump)) { + prlog(PR_DEBUG, "data size is less than minimum size " + "[dsize = 0x%llx]\n", dsize); + return OPAL_PARAMETER; + } + + sec_cnt = be16_to_cpu(fadump->section_count); + if (sec_cnt <= 0) { + prlog(PR_DEBUG, "Invalid section count = 0x%x\n", sec_cnt); + return OPAL_PARAMETER; + } + + max_mdst_entry = MDST_TABLE_SIZE / sizeof(struct mdst_table); + if (ntuple_mdst->act_cnt >= (max_mdst_entry + sec_cnt)) { + prlog(PR_DEBUG, "MDST table is full\n"); + return OPAL_RESOURCE; + } + + max_mddt_entry = MDDT_TABLE_SIZE / sizeof(struct mddt_table); + if (ntuple_mddt->act_cnt >= (max_mddt_entry + sec_cnt)) { + prlog(PR_DEBUG, "MDDT table is full\n"); + return OPAL_RESOURCE; + } + + /* Already registered ? */ + for (i = 0; i < ntuple_mdst->act_cnt; i++) { + if (mdst->dump_type == DUMP_TYPE_FADUMP && + mdst->data_region >= FADUMP_REGION_HOST_START) { + prlog(PR_DEBUG, "Already registered\n"); + return OPAL_PERMISSION; + } + + mdst++; + } + + mdst = (struct mdst_table *)(MDST_TABLE_BASE + + ntuple_mdst->act_cnt * sizeof(struct mdst_table)); + mddt = (struct mddt_table *)(MDDT_TABLE_BASE + + ntuple_mddt->act_cnt * sizeof(struct mddt_table)); + for (i = 0; i < sec_cnt; i++) { + section = &(fadump->section[i]); + + if (section->source_type < FADUMP_REGION_HOST_START) { + prlog(PR_DEBUG, "Invalid source type : 0x%x\n", + section->source_type); + goto clr_entry; + } + + if (!opal_addr_valid((void *)section->source_addr)) { + prlog(PR_DEBUG, "Invalid source address " + "[addr = 0x%llx]\n", section->source_addr); + goto clr_entry; + } + + mdst->dump_type = DUMP_TYPE_FADUMP; + mdst->data_region = section->source_type; + mdst->addr = section->source_addr | HRMOR_BIT; + mdst->size = section->source_size; + mdst++; + ntuple_mdst->act_cnt++; + + if (!opal_addr_valid((void *)section->dest_addr)) { + prlog(PR_DEBUG, "Invalid destination address " + "[addr = 0x%llx]\n", section->dest_addr); + goto clr_entry; + } + + mddt->data_region = section->source_type; + mddt->addr = section->dest_addr | HRMOR_BIT; + mddt->size = section->dest_size; + mddt++; + ntuple_mddt->act_cnt++; + + prlog(PR_NOTICE, "Registered new entry : src - 0x%llx, " + "dst - 0x%llx, size - 0x%llx\n", section->source_addr, + section->dest_addr, section->source_size); + } + + return OPAL_SUCCESS; + +clr_entry: + opal_fadump_unregister(); + return OPAL_PARAMETER; +} + +static int64_t opal_fadump_manage(uint64_t cmd, void *data, uint64_t dsize) +{ + int rc = OPAL_SUCCESS; + + prlog(PR_TRACE, "opal_fadump_manage : cmd - 0x%llx\n", cmd); + + switch (cmd) { + case OPAL_FADUMP_REGISTER: + rc = opal_fadump_register(data, dsize); + if (rc == OPAL_SUCCESS) + prlog(PR_NOTICE, "Payload registered for MPIPL\n"); + break; + case OPAL_FADUMP_UNREGISTER: + opal_fadump_unregister(); + prlog(PR_NOTICE, "Payload unregistered for MPIPL\n"); + break; + case OPAL_FADUMP_INVALIDATE: + opal_fadump_invalidate(); + prlog(PR_NOTICE, "Payload invalidated dump\n"); + break; + default: + prlog(PR_DEBUG, "Unsupported command : 0x%llx\n", cmd); + rc = OPAL_PARAMETER; + break; + } + + return rc; +} /* Reserve OPAL dump destination memory */ static void add_fadump_reserve_node(struct dt_node *dump_node) @@ -169,4 +349,7 @@ void opal_fadump_init(void) ntuple_mdrt = &(spirah.ntuples.mdump_res); adjust_opal_dump_size(dump_node); + + /* OPAL interface */ + opal_register(OPAL_FADUMP_MANAGE, opal_fadump_manage, 3); } diff --git a/include/opal-api.h b/include/opal-api.h index 9cb952e43..d66295304 100644 --- a/include/opal-api.h +++ b/include/opal-api.h @@ -226,7 +226,8 @@ #define OPAL_NX_COPROC_INIT 167 #define OPAL_NPU_SET_RELAXED_ORDER 168 #define OPAL_NPU_GET_RELAXED_ORDER 169 -#define OPAL_LAST 169 +#define OPAL_FADUMP_MANAGE 170 +#define OPAL_LAST 170 #define QUIESCE_HOLD 1 /* Spin all calls at entry */ #define QUIESCE_REJECT 2 /* Fail all calls with OPAL_BUSY */ @@ -1345,6 +1346,16 @@ struct fadump { struct fadump_section section[]; }; +/* + * Command option argument for fadump manage API (OPAL_FADUMP_MANAGE) + * - for registration payload should pass memory reservation details + * - Unregister option removes all entries from payload + * - Invalidate option invalidatates existing fadump + * */ +#define OPAL_FADUMP_REGISTER 0x01 +#define OPAL_FADUMP_UNREGISTER 0x02 +#define OPAL_FADUMP_INVALIDATE 0x03 + #endif /* __ASSEMBLY__ */ #endif /* __OPAL_API_H */