Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1032280pxb; Tue, 14 Sep 2021 14:38:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz++2lxGth/D0VGu3wpA9Vi6OYlvbIn9ozb8TJd7DFh3VjIVM/JGn3GR28NONk0n3zrVEni X-Received: by 2002:a5e:c609:: with SMTP id f9mr15908014iok.127.1631655481553; Tue, 14 Sep 2021 14:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631655481; cv=none; d=google.com; s=arc-20160816; b=dMnKpOCP8CU8tMUqJzOwbjDT9/r1/DrA40Ow6agC3njhqnKWDkRXQpjnlrWyy38Ii+ q7VyL+HUTrbkNtNtM5NeF6nY2iwfsYO4UmF+UFzS4n1X0b+iVjPBgHSqSVWKRnKPRFXv o23g+5+pW1jOzWvcxQN6cEWA8VI47rgcD8g+hulnFJHjqU8V4UnIUMo0RIkzCc8NugE7 7M+NRD5De5Rmb3+laVxWWWSsK/jQD7QnwJDTsfqBgN9n2QifM3amqWreeLEc19lH35H0 sbgeCGsVS3L47kEFMdAXv/RhMT0UupcJ/mORmPJhEiuR/ivKrxMwEDFmUoFCbYNHH5/L 9EXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dGH53sxifYoEVoAJVL7uZWNIIwKbbbyk03C+3/3+mao=; b=lKNKuLj8i+092wMaQJlbj9JOrK95KWhP4N0oZojlokqSIB5IgON3n+r1dt6IKL62yK FUJOFG0R14kQLOtYbSNu66Asd07PucOrl72FgNKSCpBlZGF1vsS+tjjUqPQ5vMF0z4qx FZ55GQESCHFbxEOiGu9ZwWqGw6u85plrB6DROydlcWtTuCjX8Cj8jQiHXYPxXDqaoMub JogZ/ACQ/XPwE69ZHO/Gw06pQjBnEhxpF9VFbBWiq5sN+yn1NuYfUFkBOwiGoxJu8LIY sHHP6S44uiHK1tw0jBPJpbdAcBIsWVE+pCs7PLdKU0Gc5wJL7SIQ/EQqrM4VNb5Xyju/ sJMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Sp6Dm9s7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o29si11268629jac.75.2021.09.14.14.37.50; Tue, 14 Sep 2021 14:38:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Sp6Dm9s7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234833AbhINVhp (ORCPT + 99 others); Tue, 14 Sep 2021 17:37:45 -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 Content-Transfer-Encoding: 8bit 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-kernel@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; } -- 2.27.0