2019-01-29 00:23:23 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
// Copyright IBM Corp 2019
|
2018-11-09 05:05:24 +08:00
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/errno.h>
|
2021-11-06 04:35:07 +08:00
|
|
|
#include <linux/slab.h>
|
2018-11-09 05:05:25 +08:00
|
|
|
#include <linux/fsi-occ.h>
|
2021-10-20 04:53:07 +08:00
|
|
|
#include <linux/mm.h>
|
2018-11-09 05:05:24 +08:00
|
|
|
#include <linux/module.h>
|
2021-10-20 04:53:07 +08:00
|
|
|
#include <linux/mutex.h>
|
2018-11-09 05:05:24 +08:00
|
|
|
#include <linux/platform_device.h>
|
2021-10-20 04:53:07 +08:00
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/sysfs.h>
|
2018-11-09 05:05:24 +08:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
struct p9_sbe_occ {
|
|
|
|
struct occ occ;
|
2021-10-20 04:53:07 +08:00
|
|
|
bool sbe_error;
|
|
|
|
void *ffdc;
|
|
|
|
size_t ffdc_len;
|
|
|
|
size_t ffdc_size;
|
|
|
|
struct mutex sbe_error_lock; /* lock access to ffdc data */
|
2018-11-09 05:05:24 +08:00
|
|
|
struct device *sbe;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_p9_sbe_occ(x) container_of((x), struct p9_sbe_occ, occ)
|
|
|
|
|
2021-10-20 04:53:07 +08:00
|
|
|
static ssize_t ffdc_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) {
|
|
|
|
rc = memory_read_from_buffer(buf, count, &pos, ctx->ffdc,
|
|
|
|
ctx->ffdc_len);
|
|
|
|
if (pos >= ctx->ffdc_len)
|
|
|
|
ctx->sbe_error = false;
|
|
|
|
}
|
|
|
|
mutex_unlock(&ctx->sbe_error_lock);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
static BIN_ATTR_RO(ffdc, OCC_MAX_RESP_WORDS * 4);
|
|
|
|
|
|
|
|
static bool p9_sbe_occ_save_ffdc(struct p9_sbe_occ *ctx, const void *resp,
|
|
|
|
size_t resp_len)
|
|
|
|
{
|
|
|
|
bool notify = false;
|
|
|
|
|
|
|
|
mutex_lock(&ctx->sbe_error_lock);
|
|
|
|
if (!ctx->sbe_error) {
|
|
|
|
if (resp_len > ctx->ffdc_size) {
|
2022-06-06 21:14:01 +08:00
|
|
|
kvfree(ctx->ffdc);
|
2021-10-20 04:53:07 +08:00
|
|
|
ctx->ffdc = kvmalloc(resp_len, GFP_KERNEL);
|
|
|
|
if (!ctx->ffdc) {
|
|
|
|
ctx->ffdc_len = 0;
|
|
|
|
ctx->ffdc_size = 0;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->ffdc_size = resp_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
notify = true;
|
|
|
|
ctx->sbe_error = true;
|
|
|
|
ctx->ffdc_len = resp_len;
|
|
|
|
memcpy(ctx->ffdc, resp, resp_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
mutex_unlock(&ctx->sbe_error_lock);
|
|
|
|
return notify;
|
|
|
|
}
|
|
|
|
|
2022-06-29 04:30:29 +08:00
|
|
|
static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len,
|
|
|
|
void *resp, size_t resp_len)
|
2018-11-09 05:05:24 +08:00
|
|
|
{
|
2018-11-09 05:05:25 +08:00
|
|
|
struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
|
|
|
|
int rc;
|
|
|
|
|
2021-07-22 03:02:30 +08:00
|
|
|
rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
|
2021-10-20 04:53:07 +08:00
|
|
|
if (rc < 0) {
|
|
|
|
if (resp_len) {
|
|
|
|
if (p9_sbe_occ_save_ffdc(ctx, resp, resp_len))
|
|
|
|
sysfs_notify(&occ->bus_dev->kobj, NULL,
|
|
|
|
bin_attr_ffdc.attr.name);
|
|
|
|
}
|
|
|
|
|
2018-11-09 05:05:25 +08:00
|
|
|
return rc;
|
2021-10-20 04:53:07 +08:00
|
|
|
}
|
2018-11-09 05:05:25 +08:00
|
|
|
|
2022-06-29 04:30:29 +08:00
|
|
|
switch (((struct occ_response *)resp)->return_status) {
|
2018-11-09 05:05:25 +08:00
|
|
|
case OCC_RESP_CMD_IN_PRG:
|
|
|
|
rc = -ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
case OCC_RESP_SUCCESS:
|
|
|
|
rc = 0;
|
|
|
|
break;
|
|
|
|
case OCC_RESP_CMD_INVAL:
|
|
|
|
case OCC_RESP_CMD_LEN_INVAL:
|
|
|
|
case OCC_RESP_DATA_INVAL:
|
|
|
|
case OCC_RESP_CHKSUM_ERR:
|
|
|
|
rc = -EINVAL;
|
|
|
|
break;
|
|
|
|
case OCC_RESP_INT_ERR:
|
|
|
|
case OCC_RESP_BAD_STATE:
|
|
|
|
case OCC_RESP_CRIT_EXCEPT:
|
|
|
|
case OCC_RESP_CRIT_INIT:
|
|
|
|
case OCC_RESP_CRIT_WATCHDOG:
|
|
|
|
case OCC_RESP_CRIT_OCB:
|
|
|
|
case OCC_RESP_CRIT_HW:
|
|
|
|
rc = -EREMOTEIO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = -EPROTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
2018-11-09 05:05:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int p9_sbe_occ_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct occ *occ;
|
|
|
|
struct p9_sbe_occ *ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!ctx)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2021-10-20 04:53:07 +08:00
|
|
|
mutex_init(&ctx->sbe_error_lock);
|
|
|
|
|
2018-11-09 05:05:24 +08:00
|
|
|
ctx->sbe = pdev->dev.parent;
|
|
|
|
occ = &ctx->occ;
|
|
|
|
occ->bus_dev = &pdev->dev;
|
|
|
|
platform_set_drvdata(pdev, occ);
|
|
|
|
|
2018-11-09 05:05:27 +08:00
|
|
|
occ->powr_sample_time_us = 500;
|
2018-11-09 05:05:24 +08:00
|
|
|
occ->poll_cmd_data = 0x20; /* P9 OCC poll data */
|
|
|
|
occ->send_cmd = p9_sbe_occ_send_cmd;
|
|
|
|
|
2022-04-27 22:04:43 +08:00
|
|
|
rc = occ_setup(occ);
|
2018-11-09 05:05:24 +08:00
|
|
|
if (rc == -ESHUTDOWN)
|
|
|
|
rc = -ENODEV; /* Host is shutdown, don't spew errors */
|
|
|
|
|
2021-10-20 04:53:07 +08:00
|
|
|
if (!rc) {
|
|
|
|
rc = device_create_bin_file(occ->bus_dev, &bin_attr_ffdc);
|
|
|
|
if (rc) {
|
|
|
|
dev_warn(occ->bus_dev,
|
|
|
|
"failed to create SBE error ffdc file\n");
|
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 05:05:24 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-10-20 04:53:07 +08:00
|
|
|
device_remove_bin_file(occ->bus_dev, &bin_attr_ffdc);
|
|
|
|
|
2018-11-09 05:05:24 +08:00
|
|
|
ctx->sbe = NULL;
|
2018-11-09 05:05:29 +08:00
|
|
|
occ_shutdown(occ);
|
2018-11-09 05:05:24 +08:00
|
|
|
|
2022-06-06 21:14:01 +08:00
|
|
|
kvfree(ctx->ffdc);
|
2021-10-20 04:53:07 +08:00
|
|
|
|
2018-11-09 05:05:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver p9_sbe_occ_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "occ-hwmon",
|
|
|
|
},
|
|
|
|
.probe = p9_sbe_occ_probe,
|
|
|
|
.remove = p9_sbe_occ_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(p9_sbe_occ_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Eddie James <eajames@linux.ibm.com>");
|
|
|
|
MODULE_DESCRIPTION("BMC P9 OCC hwmon driver");
|
|
|
|
MODULE_LICENSE("GPL");
|