FSI changes for v5.16

- SBEFIFO usersapce interfaces to perform FFDC (First Failure
    Data Capture) and detect timeouts
 
  - A fix to handle multiple messages in flight
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEE+nHMAt9PCBDH63wBa3ZZB4FHcJ4FAmFx+ZIACgkQa3ZZB4FH
 cJ7WHhAAn840J0zZS5mUMq7oJC6oWsSwEtKoBqoEwJq0nGGTDY7KX5r5umH1uEdR
 SlIjZ8WoNgZVpZEXXOXZyKWU8yzEckVjEYMWNWZGuabuAXMzTDyB/J376vn9IYQO
 ZkGYbu4B9CZssn0sDC671R/FHfPFk7L5jJ0sJgi5I3nDOApw+uvcGqw9r0AWmUfp
 7BHNLZvvUNO/Z3yqF+YaeDhOIXHRbN0kq7fwi+lp4s5UUhPZDmNrrbVu+6HqJe9E
 ghUST309zWUdtBToyzxkRb2U8rK8QDtkZppRPf+e/64RP8Fz1yNDPHG6HQX7cyYS
 1VyMbA5AzzbUE2XORmfbPGrJ9WmQSX8JOJX1bxq/eu15VJAeDVYuMVHm0ekNhi3u
 gwBvPXeyCwMCn0rQBGxbqoM9bHHj07vJ1FVaSWpWYjbTWo343itjVi54nYxgQxIA
 12TW8xRI1H7IHkgKtaCvrINxHgyXinfZuWrNXVKHsiT02Y+F08eXp0xotaMg0bmj
 nhvTw4wRZa0rHIFNFqj/yEKpIaaoDuPo1ZxT81NOAK4kxgzuFB/z2IsUXf+xJI4r
 2UAWyryth5wFbfu0BBq95onGOI+MgZwpksVNekcS1P2pByox+pKKvUsqXeSBRHnx
 DmiSZVME2zRUb+9jZHVfEVHBZBrMVzDn1pb9Fm1OId8cjeFupdA=
 =ug/2
 -----END PGP SIGNATURE-----

Merge tag 'fsi-for-v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/joel/fsi into char-misc-next

Joel writes:

FSI changes for v5.16

 - SBEFIFO usersapce interfaces to perform FFDC (First Failure
   Data Capture) and detect timeouts

 - A fix to handle multiple messages in flight

* tag 'fsi-for-v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/joel/fsi:
  fsi: sbefifo: Use interruptible mutex locking
  fsi: sbefifo: Add sysfs file indicating a timeout error
  docs: ABI: testing: Document the SBEFIFO timeout interface
  hwmon: (occ) Provide the SBEFIFO FFDC in binary sysfs
  docs: ABI: testing: Document the OCC hwmon FFDC binary interface
  fsi: occ: Store the SBEFIFO FFDC in the user response buffer
  fsi: occ: Use a large buffer for responses
  hwmon: (occ) Remove sequence numbering and checksum calculation
  fsi: occ: Force sequence numbering per OCC
This commit is contained in:
Greg Kroah-Hartman 2021-10-22 09:45:59 +02:00
commit b1f4c00e41
9 changed files with 282 additions and 127 deletions

View File

@ -0,0 +1,10 @@
What: /sys/bus/fsi/devices/XX.XX.00:06/sbefifoX/timeout
KernelVersion: 5.15
Contact: eajames@linux.ibm.com
Description:
Indicates whether or not this SBE device has experienced a
timeout; i.e. the SBE did not respond within the time allotted
by the driver. A value of 1 indicates that a timeout has
ocurred and no transfers have completed since the timeout. A
value of 0 indicates that no timeout has ocurred, or if one
has, more recent transfers have completed successful.

View File

@ -0,0 +1,13 @@
What: /sys/bus/platform/devices/occ-hwmon.X/ffdc
KernelVersion: 5.15
Contact: eajames@linux.ibm.com
Description:
Contains the First Failure Data Capture from the SBEFIFO
hardware, if there is any from a previous transfer. Otherwise,
the file is empty. The data is cleared when it's been
completely read by a user. As the name suggests, only the data
from the first error is saved, until it's cleared upon read. The OCC hwmon driver, running on
a Baseboard Management Controller (BMC), communicates with
POWER9 and up processors over the Self-Boot Engine (SBE) FIFO.
In many error conditions, the SBEFIFO will return error data
indicating the type of error and system state, etc.

View File

@ -10,6 +10,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/mm.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/fsi-occ.h> #include <linux/fsi-occ.h>
@ -33,13 +34,6 @@
#define OCC_P10_SRAM_MODE 0x58 /* Normal mode, OCB channel 2 */ #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_TIMEOUT_MS 1000
#define OCC_CMD_IN_PRG_WAIT_MS 50 #define OCC_CMD_IN_PRG_WAIT_MS 50
@ -50,6 +44,11 @@ struct occ {
struct device *sbefifo; struct device *sbefifo;
char name[32]; char name[32];
int idx; int idx;
u8 sequence_number;
void *buffer;
void *client_buffer;
size_t client_buffer_size;
size_t client_response_size;
enum versions version; enum versions version;
struct miscdevice mdev; struct miscdevice mdev;
struct mutex occ_lock; struct mutex occ_lock;
@ -141,8 +140,7 @@ static ssize_t occ_write(struct file *file, const char __user *buf,
{ {
struct occ_client *client = file->private_data; struct occ_client *client = file->private_data;
size_t rlen, data_length; size_t rlen, data_length;
u16 checksum = 0; ssize_t rc;
ssize_t rc, i;
u8 *cmd; u8 *cmd;
if (!client) if (!client)
@ -156,9 +154,6 @@ static ssize_t occ_write(struct file *file, const char __user *buf,
/* Construct the command */ /* Construct the command */
cmd = client->buffer; cmd = client->buffer;
/* Sequence number (we could increment and compare with response) */
cmd[0] = 1;
/* /*
* Copy the user command (assume user data follows the occ command * Copy the user command (assume user data follows the occ command
* format) * format)
@ -178,14 +173,7 @@ static ssize_t occ_write(struct file *file, const char __user *buf,
goto done; goto done;
} }
/* Calculate checksum */ /* Submit command; 4 bytes before the data and 2 bytes after */
for (i = 0; i < data_length + 4; ++i)
checksum += cmd[i];
cmd[data_length + 4] = checksum >> 8;
cmd[data_length + 5] = checksum & 0xFF;
/* Submit command */
rlen = PAGE_SIZE; rlen = PAGE_SIZE;
rc = fsi_occ_submit(client->occ->dev, cmd, data_length + 6, cmd, rc = fsi_occ_submit(client->occ->dev, cmd, data_length + 6, cmd,
&rlen); &rlen);
@ -223,6 +211,22 @@ static const struct file_operations occ_fops = {
.release = occ_release, .release = occ_release,
}; };
static void occ_save_ffdc(struct occ *occ, __be32 *resp, size_t parsed_len,
size_t resp_len)
{
if (resp_len > parsed_len) {
size_t dh = resp_len - parsed_len;
size_t ffdc_len = (dh - 1) * 4; /* SBE words are four bytes */
__be32 *ffdc = &resp[parsed_len];
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 int occ_verify_checksum(struct occ *occ, struct occ_response *resp, static int occ_verify_checksum(struct occ *occ, struct occ_response *resp,
u16 data_length) u16 data_length)
{ {
@ -251,8 +255,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) 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 */ u32 data_len = ((len + 7) / 8) * 8; /* must be multiples of 8 B */
size_t cmd_len, resp_len, resp_data_len; size_t cmd_len, parsed_len, resp_data_len;
__be32 *resp, cmd[6]; size_t resp_len = OCC_MAX_RESP_WORDS;
__be32 *resp = occ->buffer;
__be32 cmd[6];
int idx = 0, rc; int idx = 0, rc;
/* /*
@ -279,21 +285,22 @@ 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[1] = cpu_to_be32(SBEFIFO_CMD_GET_OCC_SRAM);
cmd[4 + idx] = cpu_to_be32(data_len); 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); rc = sbefifo_submit(occ->sbefifo, cmd, cmd_len, resp, &resp_len);
if (rc) if (rc)
goto free; return rc;
rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_GET_OCC_SRAM, rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_GET_OCC_SRAM,
resp, resp_len, &resp_len); resp, resp_len, &parsed_len);
if (rc) if (rc > 0) {
goto free; dev_err(occ->dev, "SRAM read returned failure status: %08x\n",
rc);
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) { if (resp_data_len != data_len) {
dev_err(occ->dev, "SRAM read expected %d bytes got %zd\n", dev_err(occ->dev, "SRAM read expected %d bytes got %zd\n",
data_len, resp_data_len); data_len, resp_data_len);
@ -302,37 +309,21 @@ static int occ_getsram(struct occ *occ, u32 offset, void *data, ssize_t len)
memcpy(data, resp, 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; return rc;
} }
static int occ_putsram(struct occ *occ, const void *data, ssize_t len) 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 */ u32 data_len = ((len + 7) / 8) * 8; /* must be multiples of 8 B */
__be32 *buf; size_t cmd_len, parsed_len, resp_data_len;
size_t resp_len = OCC_MAX_RESP_WORDS;
__be32 *buf = occ->buffer;
u8 *byte_buf;
int idx = 0, rc; int idx = 0, rc;
cmd_len = (occ->version == occ_p10) ? 6 : 5; 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; 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 * Magic sequence to do SBE putsram command. SBE will transfer
@ -358,18 +349,33 @@ static int occ_putsram(struct occ *occ, const void *data, ssize_t len)
buf[4 + idx] = cpu_to_be32(data_len); buf[4 + idx] = cpu_to_be32(data_len);
memcpy(&buf[5 + idx], data, len); memcpy(&buf[5 + idx], data, len);
byte_buf = (u8 *)&buf[5 + idx];
/*
* Overwrite the first byte with our sequence number and the last two
* bytes with the checksum.
*/
byte_buf[0] = seq_no;
byte_buf[len - 2] = checksum >> 8;
byte_buf[len - 1] = checksum & 0xff;
rc = sbefifo_submit(occ->sbefifo, buf, cmd_len, buf, &resp_len); rc = sbefifo_submit(occ->sbefifo, buf, cmd_len, buf, &resp_len);
if (rc) if (rc)
goto free; return rc;
rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_PUT_OCC_SRAM, rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_PUT_OCC_SRAM,
buf, resp_len, &resp_len); buf, resp_len, &parsed_len);
if (rc) if (rc > 0) {
goto free; dev_err(occ->dev, "SRAM write returned failure status: %08x\n",
rc);
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", dev_err(occ->dev, "SRAM write response length invalid: %zd\n",
resp_len); parsed_len);
rc = -EBADMSG; rc = -EBADMSG;
} else { } else {
resp_data_len = be32_to_cpu(buf[0]); resp_data_len = be32_to_cpu(buf[0]);
@ -381,27 +387,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; return rc;
} }
static int occ_trigger_attn(struct occ *occ) static int occ_trigger_attn(struct occ *occ)
{ {
__be32 buf[OCC_SBE_STATUS_WORDS]; __be32 *buf = occ->buffer;
size_t cmd_len, resp_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; int idx = 0, rc;
BUILD_BUG_ON(OCC_SBE_STATUS_WORDS < 8);
resp_len = OCC_SBE_STATUS_WORDS;
switch (occ->version) { switch (occ->version) {
default: default:
case occ_p9: case occ_p9:
@ -426,16 +421,22 @@ static int occ_trigger_attn(struct occ *occ)
rc = sbefifo_submit(occ->sbefifo, buf, cmd_len, buf, &resp_len); rc = sbefifo_submit(occ->sbefifo, buf, cmd_len, buf, &resp_len);
if (rc) if (rc)
goto error; return rc;
rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_PUT_OCC_SRAM, rc = sbefifo_parse_status(occ->sbefifo, SBEFIFO_CMD_PUT_OCC_SRAM,
buf, resp_len, &resp_len); buf, resp_len, &parsed_len);
if (rc) if (rc > 0) {
goto error; dev_err(occ->dev, "SRAM attn returned failure status: %08x\n",
rc);
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", dev_err(occ->dev, "SRAM attn response length invalid: %zd\n",
resp_len); parsed_len);
rc = -EBADMSG; rc = -EBADMSG;
} else { } else {
resp_data_len = be32_to_cpu(buf[0]); resp_data_len = be32_to_cpu(buf[0]);
@ -447,14 +448,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; return rc;
} }
@ -466,24 +459,49 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len,
msecs_to_jiffies(OCC_CMD_IN_PRG_WAIT_MS); msecs_to_jiffies(OCC_CMD_IN_PRG_WAIT_MS);
struct occ *occ = dev_get_drvdata(dev); struct occ *occ = dev_get_drvdata(dev);
struct occ_response *resp = response; struct occ_response *resp = response;
size_t user_resp_len = *resp_len;
u8 seq_no; u8 seq_no;
u16 checksum = 0;
u16 resp_data_length; u16 resp_data_length;
const u8 *byte_request = (const u8 *)request;
unsigned long start; unsigned long start;
int rc; int rc;
size_t i;
*resp_len = 0;
if (!occ) if (!occ)
return -ENODEV; return -ENODEV;
if (*resp_len < 7) { if (user_resp_len < 7) {
dev_dbg(dev, "Bad resplen %zd\n", *resp_len); dev_dbg(dev, "Bad resplen %zd\n", user_resp_len);
return -EINVAL; return -EINVAL;
} }
/* Checksum the request, ignoring first byte (sequence number). */
for (i = 1; i < req_len - 2; ++i)
checksum += byte_request[i];
mutex_lock(&occ->occ_lock); mutex_lock(&occ->occ_lock);
/* Extract the seq_no from the command (first byte) */ occ->client_buffer = response;
seq_no = *(const u8 *)request; occ->client_buffer_size = user_resp_len;
rc = occ_putsram(occ, request, req_len); occ->client_response_size = 0;
/*
* Get a sequence number and update the counter. Avoid a sequence
* number of 0 which would pass the response check below even if the
* OCC response is uninitialized. Any sequence number the user is
* trying to send is overwritten since this function is the only common
* interface to the OCC and therefore the only place we can guarantee
* unique sequence numbers.
*/
seq_no = occ->sequence_number++;
if (!occ->sequence_number)
occ->sequence_number = 1;
checksum += seq_no;
rc = occ_putsram(occ, request, req_len, seq_no, checksum);
if (rc) if (rc)
goto done; goto done;
@ -520,7 +538,7 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len,
resp_data_length = get_unaligned_be16(&resp->data_length); resp_data_length = get_unaligned_be16(&resp->data_length);
/* Message size is data length + 5 bytes header + 2 bytes checksum */ /* 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; rc = -EMSGSIZE;
goto done; goto done;
} }
@ -536,10 +554,11 @@ int fsi_occ_submit(struct device *dev, const void *request, size_t req_len,
goto done; goto done;
} }
*resp_len = resp_data_length + 7; occ->client_response_size = resp_data_length + 7;
rc = occ_verify_checksum(occ, resp, resp_data_length); rc = occ_verify_checksum(occ, resp, resp_data_length);
done: done:
*resp_len = occ->client_response_size;
mutex_unlock(&occ->occ_lock); mutex_unlock(&occ->occ_lock);
return rc; return rc;
@ -571,9 +590,15 @@ static int occ_probe(struct platform_device *pdev)
if (!occ) if (!occ)
return -ENOMEM; return -ENOMEM;
/* SBE words are always four bytes */
occ->buffer = kvmalloc(OCC_MAX_RESP_WORDS * 4, GFP_KERNEL);
if (!occ->buffer)
return -ENOMEM;
occ->version = (uintptr_t)of_device_get_match_data(dev); occ->version = (uintptr_t)of_device_get_match_data(dev);
occ->dev = dev; occ->dev = dev;
occ->sbefifo = dev->parent; occ->sbefifo = dev->parent;
occ->sequence_number = 1;
mutex_init(&occ->occ_lock); mutex_init(&occ->occ_lock);
if (dev->of_node) { if (dev->of_node) {
@ -605,6 +630,7 @@ static int occ_probe(struct platform_device *pdev)
if (rc) { if (rc) {
dev_err(dev, "failed to register miscdevice: %d\n", rc); dev_err(dev, "failed to register miscdevice: %d\n", rc);
ida_simple_remove(&occ_ida, occ->idx); ida_simple_remove(&occ_ida, occ->idx);
kvfree(occ->buffer);
return rc; return rc;
} }
@ -620,6 +646,8 @@ static int occ_remove(struct platform_device *pdev)
{ {
struct occ *occ = platform_get_drvdata(pdev); struct occ *occ = platform_get_drvdata(pdev);
kvfree(occ->buffer);
misc_deregister(&occ->mdev); misc_deregister(&occ->mdev);
device_for_each_child(&pdev->dev, NULL, occ_unregister_child); device_for_each_child(&pdev->dev, NULL, occ_unregister_child);

View File

@ -124,6 +124,7 @@ struct sbefifo {
bool broken; bool broken;
bool dead; bool dead;
bool async_ffdc; bool async_ffdc;
bool timed_out;
}; };
struct sbefifo_user { struct sbefifo_user {
@ -136,6 +137,14 @@ struct sbefifo_user {
static DEFINE_MUTEX(sbefifo_ffdc_mutex); static DEFINE_MUTEX(sbefifo_ffdc_mutex);
static ssize_t timeout_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct sbefifo *sbefifo = container_of(dev, struct sbefifo, dev);
return sysfs_emit(buf, "%d\n", sbefifo->timed_out ? 1 : 0);
}
static DEVICE_ATTR_RO(timeout);
static void __sbefifo_dump_ffdc(struct device *dev, const __be32 *ffdc, static void __sbefifo_dump_ffdc(struct device *dev, const __be32 *ffdc,
size_t ffdc_sz, bool internal) size_t ffdc_sz, bool internal)
@ -462,11 +471,14 @@ static int sbefifo_wait(struct sbefifo *sbefifo, bool up,
break; break;
} }
if (!ready) { if (!ready) {
sysfs_notify(&sbefifo->dev.kobj, NULL, dev_attr_timeout.attr.name);
sbefifo->timed_out = true;
dev_err(dev, "%s FIFO Timeout ! status=%08x\n", up ? "UP" : "DOWN", sts); dev_err(dev, "%s FIFO Timeout ! status=%08x\n", up ? "UP" : "DOWN", sts);
return -ETIMEDOUT; return -ETIMEDOUT;
} }
dev_vdbg(dev, "End of wait status: %08x\n", sts); dev_vdbg(dev, "End of wait status: %08x\n", sts);
sbefifo->timed_out = false;
*status = sts; *status = sts;
return 0; return 0;
@ -740,7 +752,9 @@ int sbefifo_submit(struct device *dev, const __be32 *command, size_t cmd_len,
iov_iter_kvec(&resp_iter, WRITE, &resp_iov, 1, rbytes); iov_iter_kvec(&resp_iter, WRITE, &resp_iov, 1, rbytes);
/* Perform the command */ /* Perform the command */
mutex_lock(&sbefifo->lock); rc = mutex_lock_interruptible(&sbefifo->lock);
if (rc)
return rc;
rc = __sbefifo_submit(sbefifo, command, cmd_len, &resp_iter); rc = __sbefifo_submit(sbefifo, command, cmd_len, &resp_iter);
mutex_unlock(&sbefifo->lock); mutex_unlock(&sbefifo->lock);
@ -820,7 +834,9 @@ static ssize_t sbefifo_user_read(struct file *file, char __user *buf,
iov_iter_init(&resp_iter, WRITE, &resp_iov, 1, len); iov_iter_init(&resp_iter, WRITE, &resp_iov, 1, len);
/* Perform the command */ /* Perform the command */
mutex_lock(&sbefifo->lock); rc = mutex_lock_interruptible(&sbefifo->lock);
if (rc)
goto bail;
rc = __sbefifo_submit(sbefifo, user->pending_cmd, cmd_len, &resp_iter); rc = __sbefifo_submit(sbefifo, user->pending_cmd, cmd_len, &resp_iter);
mutex_unlock(&sbefifo->lock); mutex_unlock(&sbefifo->lock);
if (rc < 0) if (rc < 0)
@ -875,7 +891,9 @@ static ssize_t sbefifo_user_write(struct file *file, const char __user *buf,
user->pending_len = 0; user->pending_len = 0;
/* Trigger reset request */ /* Trigger reset request */
mutex_lock(&sbefifo->lock); rc = mutex_lock_interruptible(&sbefifo->lock);
if (rc)
goto bail;
rc = sbefifo_request_reset(user->sbefifo); rc = sbefifo_request_reset(user->sbefifo);
mutex_unlock(&sbefifo->lock); mutex_unlock(&sbefifo->lock);
if (rc == 0) if (rc == 0)
@ -993,6 +1011,8 @@ static int sbefifo_probe(struct device *dev)
child_name); child_name);
} }
device_create_file(&sbefifo->dev, &dev_attr_timeout);
return 0; return 0;
err_free_minor: err_free_minor:
fsi_free_minor(sbefifo->dev.devt); fsi_free_minor(sbefifo->dev.devt);
@ -1018,6 +1038,8 @@ static int sbefifo_remove(struct device *dev)
dev_dbg(dev, "Removing sbefifo device...\n"); dev_dbg(dev, "Removing sbefifo device...\n");
device_remove_file(&sbefifo->dev, &dev_attr_timeout);
mutex_lock(&sbefifo->lock); mutex_lock(&sbefifo->lock);
sbefifo->dead = true; sbefifo->dead = true;
mutex_unlock(&sbefifo->lock); mutex_unlock(&sbefifo->lock);

View File

@ -132,22 +132,20 @@ struct extended_sensor {
static int occ_poll(struct occ *occ) static int occ_poll(struct occ *occ)
{ {
int rc; int rc;
u16 checksum = occ->poll_cmd_data + occ->seq_no + 1; u8 cmd[7];
u8 cmd[8];
struct occ_poll_response_header *header; struct occ_poll_response_header *header;
/* big endian */ /* big endian */
cmd[0] = occ->seq_no++; /* sequence number */ cmd[0] = 0; /* sequence number */
cmd[1] = 0; /* cmd type */ cmd[1] = 0; /* cmd type */
cmd[2] = 0; /* data length msb */ cmd[2] = 0; /* data length msb */
cmd[3] = 1; /* data length lsb */ cmd[3] = 1; /* data length lsb */
cmd[4] = occ->poll_cmd_data; /* data */ cmd[4] = occ->poll_cmd_data; /* data */
cmd[5] = checksum >> 8; /* checksum msb */ cmd[5] = 0; /* checksum msb */
cmd[6] = checksum & 0xFF; /* checksum lsb */ cmd[6] = 0; /* checksum lsb */
cmd[7] = 0;
/* mutex should already be locked if necessary */ /* mutex should already be locked if necessary */
rc = occ->send_cmd(occ, cmd); rc = occ->send_cmd(occ, cmd, sizeof(cmd));
if (rc) { if (rc) {
occ->last_error = rc; occ->last_error = rc;
if (occ->error_count++ > OCC_ERROR_COUNT_THRESHOLD) if (occ->error_count++ > OCC_ERROR_COUNT_THRESHOLD)
@ -184,25 +182,23 @@ static int occ_set_user_power_cap(struct occ *occ, u16 user_power_cap)
{ {
int rc; int rc;
u8 cmd[8]; u8 cmd[8];
u16 checksum = 0x24;
__be16 user_power_cap_be = cpu_to_be16(user_power_cap); __be16 user_power_cap_be = cpu_to_be16(user_power_cap);
cmd[0] = 0; cmd[0] = 0; /* sequence number */
cmd[1] = 0x22; cmd[1] = 0x22; /* cmd type */
cmd[2] = 0; cmd[2] = 0; /* data length msb */
cmd[3] = 2; cmd[3] = 2; /* data length lsb */
memcpy(&cmd[4], &user_power_cap_be, 2); memcpy(&cmd[4], &user_power_cap_be, 2);
checksum += cmd[4] + cmd[5]; cmd[6] = 0; /* checksum msb */
cmd[6] = checksum >> 8; cmd[7] = 0; /* checksum lsb */
cmd[7] = checksum & 0xFF;
rc = mutex_lock_interruptible(&occ->lock); rc = mutex_lock_interruptible(&occ->lock);
if (rc) if (rc)
return rc; return rc;
rc = occ->send_cmd(occ, cmd); rc = occ->send_cmd(occ, cmd, sizeof(cmd));
mutex_unlock(&occ->lock); mutex_unlock(&occ->lock);
@ -1144,8 +1140,6 @@ int occ_setup(struct occ *occ, const char *name)
{ {
int rc; int rc;
/* start with 1 to avoid false match with zero-initialized SRAM buffer */
occ->seq_no = 1;
mutex_init(&occ->lock); mutex_init(&occ->lock);
occ->groups[0] = &occ->group; occ->groups[0] = &occ->group;

View File

@ -95,9 +95,8 @@ struct occ {
struct occ_sensors sensors; struct occ_sensors sensors;
int powr_sample_time_us; /* average power sample time */ int powr_sample_time_us; /* average power sample time */
u8 seq_no;
u8 poll_cmd_data; /* to perform OCC poll command */ u8 poll_cmd_data; /* to perform OCC poll command */
int (*send_cmd)(struct occ *occ, u8 *cmd); int (*send_cmd)(struct occ *occ, u8 *cmd, size_t len);
unsigned long next_update; unsigned long next_update;
struct mutex lock; /* lock OCC access */ struct mutex lock; /* lock OCC access */

View File

@ -97,18 +97,21 @@ static int p8_i2c_occ_putscom_u32(struct i2c_client *client, u32 address,
} }
static int p8_i2c_occ_putscom_be(struct i2c_client *client, u32 address, static int p8_i2c_occ_putscom_be(struct i2c_client *client, u32 address,
u8 *data) u8 *data, size_t len)
{ {
__be32 data0, data1; __be32 data0 = 0, data1 = 0;
memcpy(&data0, data, 4); memcpy(&data0, data, min_t(size_t, len, 4));
memcpy(&data1, data + 4, 4); if (len > 4) {
len -= 4;
memcpy(&data1, data + 4, min_t(size_t, len, 4));
}
return p8_i2c_occ_putscom_u32(client, address, be32_to_cpu(data0), return p8_i2c_occ_putscom_u32(client, address, be32_to_cpu(data0),
be32_to_cpu(data1)); be32_to_cpu(data1));
} }
static int p8_i2c_occ_send_cmd(struct occ *occ, u8 *cmd) static int p8_i2c_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len)
{ {
int i, rc; int i, rc;
unsigned long start; unsigned long start;
@ -127,7 +130,7 @@ static int p8_i2c_occ_send_cmd(struct occ *occ, u8 *cmd)
return rc; return rc;
/* write command (expected to already be BE), we need bus-endian... */ /* write command (expected to already be BE), we need bus-endian... */
rc = p8_i2c_occ_putscom_be(client, OCB_DATA3, cmd); rc = p8_i2c_occ_putscom_be(client, OCB_DATA3, cmd, len);
if (rc) if (rc)
return rc; return rc;

View File

@ -4,28 +4,96 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/fsi-occ.h> #include <linux/fsi-occ.h>
#include <linux/mm.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mutex.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include "common.h" #include "common.h"
struct p9_sbe_occ { struct p9_sbe_occ {
struct occ occ; struct occ occ;
bool sbe_error;
void *ffdc;
size_t ffdc_len;
size_t ffdc_size;
struct mutex sbe_error_lock; /* lock access to ffdc data */
struct device *sbe; struct device *sbe;
}; };
#define to_p9_sbe_occ(x) container_of((x), struct p9_sbe_occ, occ) #define to_p9_sbe_occ(x) container_of((x), struct p9_sbe_occ, occ)
static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd) 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) {
if (ctx->ffdc)
kvfree(ctx->ffdc);
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;
}
static int p9_sbe_occ_send_cmd(struct occ *occ, u8 *cmd, size_t len)
{ {
struct occ_response *resp = &occ->resp; struct occ_response *resp = &occ->resp;
struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ); struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
size_t resp_len = sizeof(*resp); size_t resp_len = sizeof(*resp);
int rc; int rc;
rc = fsi_occ_submit(ctx->sbe, cmd, 8, resp, &resp_len); rc = fsi_occ_submit(ctx->sbe, cmd, len, resp, &resp_len);
if (rc < 0) 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);
}
return rc; return rc;
}
switch (resp->return_status) { switch (resp->return_status) {
case OCC_RESP_CMD_IN_PRG: case OCC_RESP_CMD_IN_PRG:
@ -65,6 +133,8 @@ static int p9_sbe_occ_probe(struct platform_device *pdev)
if (!ctx) if (!ctx)
return -ENOMEM; return -ENOMEM;
mutex_init(&ctx->sbe_error_lock);
ctx->sbe = pdev->dev.parent; ctx->sbe = pdev->dev.parent;
occ = &ctx->occ; occ = &ctx->occ;
occ->bus_dev = &pdev->dev; occ->bus_dev = &pdev->dev;
@ -78,6 +148,15 @@ static int p9_sbe_occ_probe(struct platform_device *pdev)
if (rc == -ESHUTDOWN) if (rc == -ESHUTDOWN)
rc = -ENODEV; /* Host is shutdown, don't spew errors */ rc = -ENODEV; /* Host is shutdown, don't spew errors */
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;
}
}
return rc; return rc;
} }
@ -86,9 +165,14 @@ static int p9_sbe_occ_remove(struct platform_device *pdev)
struct occ *occ = platform_get_drvdata(pdev); struct occ *occ = platform_get_drvdata(pdev);
struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ); struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);
device_remove_bin_file(occ->bus_dev, &bin_attr_ffdc);
ctx->sbe = NULL; ctx->sbe = NULL;
occ_shutdown(occ); occ_shutdown(occ);
if (ctx->ffdc)
kvfree(ctx->ffdc);
return 0; return 0;
} }

View File

@ -19,6 +19,8 @@ struct device;
#define OCC_RESP_CRIT_OCB 0xE3 #define OCC_RESP_CRIT_OCB 0xE3
#define OCC_RESP_CRIT_HW 0xE4 #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, int fsi_occ_submit(struct device *dev, const void *request, size_t req_len,
void *response, size_t *resp_len); void *response, size_t *resp_len);