From patchwork Tue Sep 14 21:35:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 12494917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32208C433EF for ; Tue, 14 Sep 2021 21:36:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B73061213 for ; Tue, 14 Sep 2021 21:36:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235074AbhINVhf (ORCPT ); Tue, 14 Sep 2021 17:37:35 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:2920 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234925AbhINVhc (ORCPT ); Tue, 14 Sep 2021 17:37:32 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 18EKxjHS031888; Tue, 14 Sep 2021 17:35:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=5Gh8S5FvyeFMEokeXe/PXEHPNy8luH1zsbM4fj9ZU3A=; b=DnlGIc9ko8xL234QqmcMaiHWsFGp7wOFKc1m4X7ij7UwtVjze7yOWjc8e8u4x8IOyTJm qFE8sAyKVczuUhB6/K/t84Ocme0yaldllBygY2lB9RBm2ZNpyQoceV4L5QgyhnxHf1qR cS1THxxd+Z2y313FYRnbupYFZq2eAEfsxElsRpwhKylGS/lAG+fl7NIohii8KuL0f861 RgVZ80u/wCgU+yHAEqqSz8lbSxQw+7kKRb2ouD/tWc+pl8mnr+nwEq7o04CCcv15Ujy9 lgBoAkUKXGF6rU5+18JmUr9yOig1KijF9iKnfOuRdDymxmNBbq5tbv3LYbozYPOjjOlV yw== Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com with ESMTP id 3b31gqu8ym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Sep 2021 17:35:47 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 18ELRrc7009216; Tue, 14 Sep 2021 21:35:46 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma01wdc.us.ibm.com with ESMTP id 3b0m39u5bd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Sep 2021 21:35:46 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 18ELZjc053346582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Sep 2021 21:35:45 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 19D04136055; Tue, 14 Sep 2021 21:35:45 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A0629136066; Tue, 14 Sep 2021 21:35:44 +0000 (GMT) Received: from v0005c16.aus.stglabs.ibm.com (unknown [9.211.154.14]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 14 Sep 2021 21:35:44 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, joel@jms.id.au, linux@roeck-us.net, jdelvare@suse.com, alistair@popple.id.au, jk@ozlabs.org, eajames@linux.ibm.com Subject: [PATCH 1/3] fsi: occ: Use a large buffer for responses Date: Tue, 14 Sep 2021 16:35:41 -0500 Message-Id: <20210914213543.73351-2-eajames@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210914213543.73351-1-eajames@linux.ibm.com> References: <20210914213543.73351-1-eajames@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: hhDr9h_lhj4ZP24QFKNzkl7dr4RoXEj- X-Proofpoint-ORIG-GUID: hhDr9h_lhj4ZP24QFKNzkl7dr4RoXEj- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1011 spamscore=0 bulkscore=0 impostorscore=0 malwarescore=0 suspectscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109140100 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Allocate a large buffer for each OCC to handle response data. This removes memory allocation during an operation, and also allows for the maximum amount of SBE FFDC. Signed-off-by: Eddie James --- drivers/fsi/fsi-occ.c | 109 ++++++++++++++++------------------------ include/linux/fsi-occ.h | 2 + 2 files changed, 45 insertions(+), 66 deletions(-) diff --git a/drivers/fsi/fsi-occ.c b/drivers/fsi/fsi-occ.c index b0c9322078a1..ace3ec7767e5 100644 --- a/drivers/fsi/fsi-occ.c +++ b/drivers/fsi/fsi-occ.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -42,13 +43,6 @@ #define OCC_P10_SRAM_MODE 0x58 /* Normal mode, OCB channel 2 */ -/* - * Assume we don't have much FFDC, if we do we'll overflow and - * fail the command. This needs to be big enough for simple - * commands as well. - */ -#define OCC_SBE_STATUS_WORDS 32 - #define OCC_TIMEOUT_MS 1000 #define OCC_CMD_IN_PRG_WAIT_MS 50 @@ -60,6 +54,7 @@ struct occ { char name[32]; int idx; u8 sequence_number; + void *buffer; enum versions version; struct miscdevice mdev; struct mutex occ_lock; @@ -250,8 +245,10 @@ static int occ_verify_checksum(struct occ *occ, struct occ_response *resp, static int occ_getsram(struct occ *occ, u32 offset, void *data, ssize_t len) { u32 data_len = ((len + 7) / 8) * 8; /* must be multiples of 8 B */ - size_t cmd_len, resp_len, resp_data_len; - __be32 *resp, cmd[6]; + size_t cmd_len, resp_data_len; + size_t resp_len = OCC_MAX_RESP_WORDS; + __be32 *resp = occ->buffer; + __be32 cmd[6]; int idx = 0, rc; /* @@ -278,19 +275,19 @@ static int occ_getsram(struct occ *occ, u32 offset, void *data, ssize_t len) cmd[1] = cpu_to_be32(SBEFIFO_CMD_GET_OCC_SRAM); cmd[4 + idx] = cpu_to_be32(data_len); - resp_len = (data_len >> 2) + OCC_SBE_STATUS_WORDS; - resp = kzalloc(resp_len << 2, GFP_KERNEL); - if (!resp) - return -ENOMEM; - rc = sbefifo_submit(occ->sbefifo, cmd, cmd_len, resp, &resp_len); if (rc) - goto free; + return rc; rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_GET_OCC_SRAM, resp, resp_len, &resp_len); - if (rc) - goto free; + if (rc > 0) { + dev_err(occ->dev, "SRAM read returned failure status: %08x\n", + rc); + return -EBADMSG; + } else if (rc) { + return rc; + } resp_data_len = be32_to_cpu(resp[resp_len - 1]); if (resp_data_len != data_len) { @@ -301,39 +298,21 @@ static int occ_getsram(struct occ *occ, u32 offset, void *data, ssize_t len) memcpy(data, resp, len); } -free: - /* Convert positive SBEI status */ - if (rc > 0) { - dev_err(occ->dev, "SRAM read returned failure status: %08x\n", - rc); - rc = -EBADMSG; - } - - kfree(resp); return rc; } static int occ_putsram(struct occ *occ, const void *data, ssize_t len, u8 seq_no, u16 checksum) { - size_t cmd_len, buf_len, resp_len, resp_data_len; u32 data_len = ((len + 7) / 8) * 8; /* must be multiples of 8 B */ - __be32 *buf; + size_t cmd_len, resp_data_len; + size_t resp_len = OCC_MAX_RESP_WORDS; + __be32 *buf = occ->buffer; u8 *byte_buf; int idx = 0, rc; cmd_len = (occ->version == occ_p10) ? 6 : 5; - - /* - * We use the same buffer for command and response, make - * sure it's big enough - */ - resp_len = OCC_SBE_STATUS_WORDS; cmd_len += data_len >> 2; - buf_len = max(cmd_len, resp_len); - buf = kzalloc(buf_len << 2, GFP_KERNEL); - if (!buf) - return -ENOMEM; /* * Magic sequence to do SBE putsram command. SBE will transfer @@ -384,12 +363,17 @@ static int occ_putsram(struct occ *occ, const void *data, ssize_t len, rc = sbefifo_submit(occ->sbefifo, buf, cmd_len, buf, &resp_len); if (rc) - goto free; + return rc; rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_PUT_OCC_SRAM, buf, resp_len, &resp_len); - if (rc) - goto free; + if (rc > 0) { + dev_err(occ->dev, "SRAM write returned failure status: %08x\n", + rc); + return -EBADMSG; + } else if (rc) { + return rc; + } if (resp_len != 1) { dev_err(occ->dev, "SRAM write response length invalid: %zd\n", @@ -405,27 +389,16 @@ static int occ_putsram(struct occ *occ, const void *data, ssize_t len, } } -free: - /* Convert positive SBEI status */ - if (rc > 0) { - dev_err(occ->dev, "SRAM write returned failure status: %08x\n", - rc); - rc = -EBADMSG; - } - - kfree(buf); return rc; } static int occ_trigger_attn(struct occ *occ) { - __be32 buf[OCC_SBE_STATUS_WORDS]; - size_t cmd_len, resp_len, resp_data_len; + __be32 *buf = occ->buffer; + size_t cmd_len, resp_data_len; + size_t resp_len = OCC_MAX_RESP_WORDS; int idx = 0, rc; - BUILD_BUG_ON(OCC_SBE_STATUS_WORDS < 8); - resp_len = OCC_SBE_STATUS_WORDS; - switch (occ->version) { default: case occ_p9: @@ -450,12 +423,17 @@ static int occ_trigger_attn(struct occ *occ) rc = sbefifo_submit(occ->sbefifo, buf, cmd_len, buf, &resp_len); if (rc) - goto error; + return rc; rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_PUT_OCC_SRAM, buf, resp_len, &resp_len); - if (rc) - goto error; + if (rc > 0) { + dev_err(occ->dev, "SRAM attn returned failure status: %08x\n", + rc); + return -EBADMSG; + } else if (rc) { + return rc; + } if (resp_len != 1) { dev_err(occ->dev, "SRAM attn response length invalid: %zd\n", @@ -471,14 +449,6 @@ static int occ_trigger_attn(struct occ *occ) } } - error: - /* Convert positive SBEI status */ - if (rc > 0) { - dev_err(occ->dev, "SRAM attn returned failure status: %08x\n", - rc); - rc = -EBADMSG; - } - return rc; } @@ -635,6 +605,10 @@ static int occ_probe(struct platform_device *pdev) if (!occ) return -ENOMEM; + occ->buffer = kvmalloc(OCC_MAX_RESP_WORDS * 4, GFP_KERNEL); + if (!occ->buffer) + return -ENOMEM; + occ->version = (enum versions)md; occ->dev = dev; occ->sbefifo = dev->parent; @@ -670,6 +644,7 @@ static int occ_probe(struct platform_device *pdev) if (rc) { dev_err(dev, "failed to register miscdevice: %d\n", rc); ida_simple_remove(&occ_ida, occ->idx); + kvfree(occ->buffer); return rc; } @@ -685,6 +660,8 @@ static int occ_remove(struct platform_device *pdev) { struct occ *occ = platform_get_drvdata(pdev); + kvfree(occ->buffer); + misc_deregister(&occ->mdev); device_for_each_child(&pdev->dev, NULL, occ_unregister_child); diff --git a/include/linux/fsi-occ.h b/include/linux/fsi-occ.h index d4cdc2aa6e33..7ee3dbd7f4b3 100644 --- a/include/linux/fsi-occ.h +++ b/include/linux/fsi-occ.h @@ -19,6 +19,8 @@ struct device; #define OCC_RESP_CRIT_OCB 0xE3 #define OCC_RESP_CRIT_HW 0xE4 +#define OCC_MAX_RESP_WORDS 2048 + int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, void *response, size_t *resp_len); From patchwork Tue Sep 14 21:35:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 12494913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B184BC433FE for ; Tue, 14 Sep 2021 21:36:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 910CB61213 for ; Tue, 14 Sep 2021 21:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233680AbhINVhf (ORCPT ); Tue, 14 Sep 2021 17:37:35 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39144 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234911AbhINVhc (ORCPT ); Tue, 14 Sep 2021 17:37:32 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 18EL0d4Q026895; Tue, 14 Sep 2021 17:35:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=IE3gxtKmIb8raCWDJMJkGEi0VuJ0w9PNCyVhB+iI1/g=; b=ronLSG035hWlW1+yZjNEc64lBd6ZptUNAl84mLXypGoECTJMCwmcH+QhqQ2wWOtIraPf QXKoShH5OnK47pA5QyewffeEtaw087k5xxg262R1RnlrvFBsnU26yTAZMNsQSkXeGnUw XEkBULwcDaeho4fcg454AW7M+/M+6y9M9mo4l+h5mdgPt/4iIKv7BT4dlpueGoEK9D8z UidqlKCq4aKlK+mNs4s2Ed8UJuaJEpVOtIlO/e6kwm1A6KESOHOsymfdBr6mqwmAgg9/ hiznEuLLVCZWG6gBIh20nABOEt5c3OGGMyC8XS1INdp7qIGmM/6+ieE2YfEZADzLK75Q ew== Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 3b3394rmyp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Sep 2021 17:35:48 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 18ELRoHM010933; Tue, 14 Sep 2021 21:35:46 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma03dal.us.ibm.com with ESMTP id 3b0m3bb97q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Sep 2021 21:35:46 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 18ELZjF052625714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Sep 2021 21:35:45 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D58D136055; Tue, 14 Sep 2021 21:35:45 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2C53113605D; Tue, 14 Sep 2021 21:35:45 +0000 (GMT) Received: from v0005c16.aus.stglabs.ibm.com (unknown [9.211.154.14]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 14 Sep 2021 21:35:45 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, joel@jms.id.au, linux@roeck-us.net, jdelvare@suse.com, alistair@popple.id.au, jk@ozlabs.org, eajames@linux.ibm.com Subject: [PATCH 2/3] fsi: occ: Store the SBEFIFO FFDC in the user response buffer Date: Tue, 14 Sep 2021 16:35:42 -0500 Message-Id: <20210914213543.73351-3-eajames@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210914213543.73351-1-eajames@linux.ibm.com> References: <20210914213543.73351-1-eajames@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Ltn8aGy8VnmXWBUFzZPT1sSiq8QfeDUk X-Proofpoint-ORIG-GUID: Ltn8aGy8VnmXWBUFzZPT1sSiq8QfeDUk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 malwarescore=0 spamscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109140111 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org If the SBEFIFO response indicates an error, store the response in the user buffer and return an error. Previously, the user had no way of obtaining the SBEFIFO FFDC. In case of an error with the SBE or SBEFIFO itself, in which case there is no FFDC, set the FFDC data to a magic value to indicate this kind of error. Signed-off-by: Eddie James --- drivers/fsi/fsi-occ.c | 87 ++++++++++++++++++++++++++++++----------- include/linux/fsi-occ.h | 1 + 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/drivers/fsi/fsi-occ.c b/drivers/fsi/fsi-occ.c index ace3ec7767e5..e4ef96e41747 100644 --- a/drivers/fsi/fsi-occ.c +++ b/drivers/fsi/fsi-occ.c @@ -55,6 +55,9 @@ struct occ { int idx; u8 sequence_number; void *buffer; + void *client_buffer; + size_t client_buffer_size; + size_t client_response_size; enum versions version; struct miscdevice mdev; struct mutex occ_lock; @@ -217,6 +220,28 @@ static const struct file_operations occ_fops = { .release = occ_release, }; +static void occ_save_ffdc(struct occ *occ, __be32 *resp, size_t parsed_len, + size_t resp_len) +{ + size_t dh = resp_len - parsed_len; + size_t ffdc_len = (dh - 1) * 4; + __be32 *ffdc = &resp[resp_len - dh]; + + if (ffdc_len > occ->client_buffer_size) + ffdc_len = occ->client_buffer_size; + + memcpy(occ->client_buffer, ffdc, ffdc_len); + occ->client_response_size = ffdc_len; +} + +static void occ_save_sbefifo_error(struct occ *occ) +{ + u32 no_ffdc_magic = OCC_NO_FFDC_MAGIC; + + memcpy(occ->client_buffer, &no_ffdc_magic, sizeof(u32)); + occ->client_response_size = sizeof(u32); +} + static int occ_verify_checksum(struct occ *occ, struct occ_response *resp, u16 data_length) { @@ -245,7 +270,7 @@ static int occ_verify_checksum(struct occ *occ, struct occ_response *resp, static int occ_getsram(struct occ *occ, u32 offset, void *data, ssize_t len) { u32 data_len = ((len + 7) / 8) * 8; /* must be multiples of 8 B */ - size_t cmd_len, resp_data_len; + size_t cmd_len, parsed_len, resp_data_len; size_t resp_len = OCC_MAX_RESP_WORDS; __be32 *resp = occ->buffer; __be32 cmd[6]; @@ -276,20 +301,23 @@ static int occ_getsram(struct occ *occ, u32 offset, void *data, ssize_t len) cmd[4 + idx] = cpu_to_be32(data_len); rc = sbefifo_submit(occ->sbefifo, cmd, cmd_len, resp, &resp_len); - if (rc) + if (rc) { + occ_save_sbefifo_error(occ); return rc; + } rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_GET_OCC_SRAM, - resp, resp_len, &resp_len); + resp, resp_len, &parsed_len); if (rc > 0) { dev_err(occ->dev, "SRAM read returned failure status: %08x\n", rc); - return -EBADMSG; + occ_save_ffdc(occ, resp, parsed_len, resp_len); + return -ECOMM; } else if (rc) { return rc; } - resp_data_len = be32_to_cpu(resp[resp_len - 1]); + resp_data_len = be32_to_cpu(resp[parsed_len - 1]); if (resp_data_len != data_len) { dev_err(occ->dev, "SRAM read expected %d bytes got %zd\n", data_len, resp_data_len); @@ -305,7 +333,7 @@ static int occ_putsram(struct occ *occ, const void *data, ssize_t len, u8 seq_no, u16 checksum) { u32 data_len = ((len + 7) / 8) * 8; /* must be multiples of 8 B */ - size_t cmd_len, resp_data_len; + size_t cmd_len, parsed_len, resp_data_len; size_t resp_len = OCC_MAX_RESP_WORDS; __be32 *buf = occ->buffer; u8 *byte_buf; @@ -362,22 +390,25 @@ static int occ_putsram(struct occ *occ, const void *data, ssize_t len, } rc = sbefifo_submit(occ->sbefifo, buf, cmd_len, buf, &resp_len); - if (rc) + if (rc) { + occ_save_sbefifo_error(occ); return rc; + } rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_PUT_OCC_SRAM, - buf, resp_len, &resp_len); + buf, resp_len, &parsed_len); if (rc > 0) { dev_err(occ->dev, "SRAM write returned failure status: %08x\n", rc); - return -EBADMSG; + occ_save_ffdc(occ, buf, parsed_len, resp_len); + return -ECOMM; } else if (rc) { return rc; } - if (resp_len != 1) { + if (parsed_len != 1) { dev_err(occ->dev, "SRAM write response length invalid: %zd\n", - resp_len); + parsed_len); rc = -EBADMSG; } else { resp_data_len = be32_to_cpu(buf[0]); @@ -395,7 +426,7 @@ static int occ_putsram(struct occ *occ, const void *data, ssize_t len, static int occ_trigger_attn(struct occ *occ) { __be32 *buf = occ->buffer; - size_t cmd_len, resp_data_len; + size_t cmd_len, parsed_len, resp_data_len; size_t resp_len = OCC_MAX_RESP_WORDS; int idx = 0, rc; @@ -422,22 +453,25 @@ static int occ_trigger_attn(struct occ *occ) buf[6 + idx] = 0; rc = sbefifo_submit(occ->sbefifo, buf, cmd_len, buf, &resp_len); - if (rc) + if (rc) { + occ_save_sbefifo_error(occ); return rc; + } rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_PUT_OCC_SRAM, - buf, resp_len, &resp_len); + buf, resp_len, &parsed_len); if (rc > 0) { dev_err(occ->dev, "SRAM attn returned failure status: %08x\n", rc); - return -EBADMSG; + occ_save_ffdc(occ, buf, parsed_len, resp_len); + return -ECOMM; } else if (rc) { return rc; } - if (resp_len != 1) { + if (parsed_len != 1) { dev_err(occ->dev, "SRAM attn response length invalid: %zd\n", - resp_len); + parsed_len); rc = -EBADMSG; } else { resp_data_len = be32_to_cpu(buf[0]); @@ -460,6 +494,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, msecs_to_jiffies(OCC_CMD_IN_PRG_WAIT_MS); struct occ *occ = dev_get_drvdata(dev); struct occ_response *resp = response; + size_t user_resp_len = *resp_len; u8 seq_no; u16 checksum = 0; u16 resp_data_length; @@ -468,11 +503,13 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, int rc; size_t i; + *resp_len = 0; + if (!occ) return -ENODEV; - if (*resp_len < 7) { - dev_dbg(dev, "Bad resplen %zd\n", *resp_len); + if (user_resp_len < 7) { + dev_dbg(dev, "Bad resplen %zd\n", user_resp_len); return -EINVAL; } @@ -482,6 +519,11 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, mutex_lock(&occ->occ_lock); + occ->client_buffer = response; + occ->client_buffer_size = user_resp_len; + occ->client_response_size = 0; + memset(occ->client_buffer, 0, 8); + /* * Get a sequence number and update the counter. Avoid a sequence * number of 0 which would pass the response check below even if the @@ -532,7 +574,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, resp_data_length = get_unaligned_be16(&resp->data_length); /* Message size is data length + 5 bytes header + 2 bytes checksum */ - if ((resp_data_length + 7) > *resp_len) { + if ((resp_data_length + 7) > user_resp_len) { rc = -EMSGSIZE; goto done; } @@ -548,7 +590,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, goto done; } - *resp_len = resp_data_length + 7; + occ->client_response_size = resp_data_length + 7; { DEFINE_DYNAMIC_DEBUG_METADATA(ddm_occ_rsp, @@ -560,7 +602,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, DYNAMIC_DEBUG_BRANCH(ddm_occ_rsp)) { char prefix[64]; size_t l = DYNAMIC_DEBUG_BRANCH(ddm_occ_full_rsp) ? - *resp_len : 16; + occ->client_response_size : 16; snprintf(prefix, sizeof(prefix), "%s %s: rsp ", dev_driver_string(occ->dev), @@ -573,6 +615,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, rc = occ_verify_checksum(occ, resp, resp_data_length); done: + *resp_len = occ->client_response_size; mutex_unlock(&occ->occ_lock); return rc; diff --git a/include/linux/fsi-occ.h b/include/linux/fsi-occ.h index 7ee3dbd7f4b3..1d584b2acba5 100644 --- a/include/linux/fsi-occ.h +++ b/include/linux/fsi-occ.h @@ -20,6 +20,7 @@ struct device; #define OCC_RESP_CRIT_HW 0xE4 #define OCC_MAX_RESP_WORDS 2048 +#define OCC_NO_FFDC_MAGIC 0x4f434346 /* "OCCF" */ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len, void *response, size_t *resp_len); From patchwork Tue Sep 14 21:35:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 12494915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64DC1C4332F for ; Tue, 14 Sep 2021 21:36:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4AB5A61213 for ; Tue, 14 Sep 2021 21:36:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235077AbhINVhg (ORCPT ); Tue, 14 Sep 2021 17:37:36 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:2826 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234883AbhINVhc (ORCPT ); Tue, 14 Sep 2021 17:37:32 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 18EL0RhP026217; Tue, 14 Sep 2021 17:35:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=dGH53sxifYoEVoAJVL7uZWNIIwKbbbyk03C+3/3+mao=; b=Sp6Dm9s7uGw6AOoxbpQ+rUpFcYQHleD7lcw80zaxxphKSvUOgG71lalnGn4aYdwknPjh T2SjTXzACGI93w3nl0+H9FuloeUl6v/tNNV1ZnzQ6xXhlJ1S53MCRzp2CYhPv81Ud6J1 OeLC5la50hqyK+an2sAmqf5Ny3aGXJxOZl/TpGX1uPskALP77SYSrWNuBGcmVVsQltDY GpDRUvSqhbd9RHWdbBetu53ltpXR0bHRmA9D9SxsZlpzWX/h34G4PeSZ6B92epeNkGsL DFpQRdt7wPkRu37D+nI2T7mRZrFeUR5tW/XPZHnJ032BW0Ljs5LopYxvtjZDvKKGaqJu lA== Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 3b3394rmyt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Sep 2021 17:35:48 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 18ELRTwW021462; Tue, 14 Sep 2021 21:35:47 GMT Received: from b03cxnp07027.gho.boulder.ibm.com (b03cxnp07027.gho.boulder.ibm.com [9.17.130.14]) by ppma05wdc.us.ibm.com with ESMTP id 3b0m3b3233-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 14 Sep 2021 21:35:47 +0000 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp07027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 18ELZkNU32112932 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 14 Sep 2021 21:35:46 GMT Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2159113604F; Tue, 14 Sep 2021 21:35:46 +0000 (GMT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B1543136066; Tue, 14 Sep 2021 21:35:45 +0000 (GMT) Received: from v0005c16.aus.stglabs.ibm.com (unknown [9.211.154.14]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 14 Sep 2021 21:35:45 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, joel@jms.id.au, linux@roeck-us.net, jdelvare@suse.com, alistair@popple.id.au, jk@ozlabs.org, eajames@linux.ibm.com Subject: [PATCH 3/3] hwmon: (occ) Provide the SBEFIFO FFDC in binary sysfs Date: Tue, 14 Sep 2021 16:35:43 -0500 Message-Id: <20210914213543.73351-4-eajames@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210914213543.73351-1-eajames@linux.ibm.com> References: <20210914213543.73351-1-eajames@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: F2hK56a0NTRZCsFGBhcnPyn3E37B7xWk X-Proofpoint-ORIG-GUID: F2hK56a0NTRZCsFGBhcnPyn3E37B7xWk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 malwarescore=0 spamscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109140111 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org Save any FFDC provided by the OCC driver, and provide it to userspace through a binary sysfs entry. Do some basic state management to ensure that userspace can always collect the data if there was an error. Notify polling userspace when there is an error too. Signed-off-by: Eddie James --- drivers/hwmon/occ/p9_sbe.c | 98 +++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/occ/p9_sbe.c b/drivers/hwmon/occ/p9_sbe.c index 9709f2b9c052..505f489832a4 100644 --- a/drivers/hwmon/occ/p9_sbe.c +++ b/drivers/hwmon/occ/p9_sbe.c @@ -4,18 +4,54 @@ #include #include #include +#include #include +#include #include +#include +#include #include "common.h" +enum sbe_error_state { + SBE_ERROR_NONE = 0, + SBE_ERROR_PENDING, + SBE_ERROR_COLLECTED +}; + struct p9_sbe_occ { struct occ occ; + int sbe_error; + void *ffdc; + size_t ffdc_len; + size_t ffdc_size; + struct mutex sbe_error_lock; /* lock access to ffdc data */ + u32 no_ffdc_magic; struct device *sbe; }; #define to_p9_sbe_occ(x) container_of((x), struct p9_sbe_occ, occ) +static ssize_t sbe_error_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *battr, char *buf, + loff_t pos, size_t count) +{ + ssize_t rc = 0; + struct occ *occ = dev_get_drvdata(kobj_to_dev(kobj)); + struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ); + + mutex_lock(&ctx->sbe_error_lock); + if (ctx->sbe_error == SBE_ERROR_PENDING) { + rc = memory_read_from_buffer(buf, count, &pos, ctx->ffdc, + ctx->ffdc_len); + ctx->sbe_error = SBE_ERROR_COLLECTED; + } + mutex_unlock(&ctx->sbe_error_lock); + + return rc; +} +static BIN_ATTR_RO(sbe_error, OCC_MAX_RESP_WORDS * 4); + static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) { struct occ_response *resp = &occ->resp; @@ -24,8 +60,47 @@ static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len) int rc; rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len); - if (rc < 0) + if (rc < 0) { + if (resp_len) { + bool notify = false; + + mutex_lock(&ctx->sbe_error_lock); + if (ctx->sbe_error != SBE_ERROR_PENDING) + notify = true; + ctx->sbe_error = SBE_ERROR_PENDING; + + if (resp_len > ctx->ffdc_size) { + if (ctx->ffdc_size) + kvfree(ctx->ffdc); + ctx->ffdc = kvmalloc(resp_len, GFP_KERNEL); + if (!ctx->ffdc) { + ctx->ffdc_size = 0; + ctx->ffdc_len = sizeof(u32); + ctx->ffdc = &ctx->no_ffdc_magic; + goto unlock; + } + + ctx->ffdc_size = resp_len; + } + + ctx->ffdc_len = resp_len; + memcpy(ctx->ffdc, resp, resp_len); + +unlock: + mutex_unlock(&ctx->sbe_error_lock); + + if (notify) + sysfs_notify(&occ->bus_dev->kobj, NULL, + bin_attr_sbe_error.attr.name); + } + return rc; + } + + mutex_lock(&ctx->sbe_error_lock); + if (ctx->sbe_error == SBE_ERROR_COLLECTED) + ctx->sbe_error = SBE_ERROR_NONE; + mutex_unlock(&ctx->sbe_error_lock); switch (resp->return_status) { case OCC_RESP_CMD_IN_PRG: @@ -65,6 +140,13 @@ static int p9_sbe_occ_probe(struct platform_device *pdev) if (!ctx) return -ENOMEM; + ctx->no_ffdc_magic = OCC_NO_FFDC_MAGIC; + ctx->sbe_error = SBE_ERROR_NONE; + ctx->ffdc = &ctx->no_ffdc_magic; + ctx->ffdc_len = sizeof(u32); + ctx->ffdc_size = 0; + mutex_init(&ctx->sbe_error_lock); + ctx->sbe = pdev->dev.parent; occ = &ctx->occ; occ->bus_dev = &pdev->dev; @@ -78,6 +160,15 @@ static int p9_sbe_occ_probe(struct platform_device *pdev) if (rc == -ESHUTDOWN) rc = -ENODEV; /* Host is shutdown, don't spew errors */ + if (!rc) { + rc = device_create_bin_file(occ->bus_dev, &bin_attr_sbe_error); + if (rc) { + dev_warn(occ->bus_dev, + "failed to create SBE error ffdc file\n"); + rc = 0; + } + } + return rc; } @@ -86,9 +177,14 @@ static int p9_sbe_occ_remove(struct platform_device *pdev) struct occ *occ = platform_get_drvdata(pdev); struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ); + device_remove_bin_file(occ->bus_dev, &bin_attr_sbe_error); + ctx->sbe = NULL; occ_shutdown(occ); + if (ctx->ffdc_size) + kvfree(ctx->ffdc); + return 0; }