aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlistair Popple <alistair@popple.id.au>2015-02-04 16:07:43 +1100
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-02-09 13:55:25 +1100
commit91b9a6f43ab16a66c4fe792a5d2615eea8a5620c (patch)
tree2efe60ff6f3d2f8777c3504134fff0f43bf5008a
parent38bb327d1ad3d5971dc7ddab4ad6d2386e5f6036 (diff)
downloadskiboot-91b9a6f43ab16a66c4fe792a5d2615eea8a5620c.zip
skiboot-91b9a6f43ab16a66c4fe792a5d2615eea8a5620c.tar.gz
skiboot-91b9a6f43ab16a66c4fe792a5d2615eea8a5620c.tar.bz2
ipmi: Add a function to (re)initialise a message without allocation
Currently the only functions we have for initialising ipmi messages with the correct values also allocate memory for the message. In some cases we want to reuse previously allocated messages to avoid continually freeing/allocating memory. This patch introduces a function which (re)initialises a previously allocated message and converts existing instances of this behaviour over to the new function. Signed-off-by: Alistair Popple <alistair@popple.id.au> Reviewed-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r--core/ipmi.c28
-rw-r--r--hw/ipmi/ipmi-fru.c7
-rw-r--r--hw/ipmi/ipmi-sel.c24
-rw-r--r--hw/ipmi/test/run-fru.c8
-rw-r--r--include/ipmi.h7
5 files changed, 48 insertions, 26 deletions
diff --git a/core/ipmi.c b/core/ipmi.c
index 76b9a33..5caf057 100644
--- a/core/ipmi.c
+++ b/core/ipmi.c
@@ -30,6 +30,22 @@ void ipmi_free_msg(struct ipmi_msg *msg)
msg->backend->free_msg(msg);
}
+void ipmi_init_msg(struct ipmi_msg *msg, int interface,
+ uint32_t code, void (*complete)(struct ipmi_msg *),
+ void *user_data, size_t req_size, size_t resp_size)
+{
+ /* We don't actually support multiple interfaces at the moment. */
+ assert(interface == IPMI_DEFAULT_INTERFACE);
+
+ msg->backend = ipmi_backend;
+ msg->cmd = IPMI_CMD(code);
+ msg->netfn = IPMI_NETFN(code) << 2;
+ msg->req_size = req_size;
+ msg->resp_size = resp_size;
+ msg->complete = complete;
+ msg->user_data = user_data;
+}
+
struct ipmi_msg *ipmi_mkmsg_simple(uint32_t code, void *req_data, size_t req_size)
{
return ipmi_mkmsg(IPMI_DEFAULT_INTERFACE, code, ipmi_free_msg, NULL,
@@ -43,20 +59,12 @@ struct ipmi_msg *ipmi_mkmsg(int interface, uint32_t code,
{
struct ipmi_msg *msg;
- /* We don't actually support multiple interfaces at the moment. */
- assert(interface == IPMI_DEFAULT_INTERFACE);
-
msg = ipmi_backend->alloc_msg(req_size, resp_size);
if (!msg)
return NULL;
- msg->backend = ipmi_backend;
- msg->cmd = IPMI_CMD(code);
- msg->netfn = IPMI_NETFN(code) << 2;
- msg->req_size = req_size;
- msg->resp_size = resp_size;
- msg->complete = complete;
- msg->user_data = user_data;
+ ipmi_init_msg(msg, interface, code, complete, user_data, req_size,
+ resp_size);
/* Commands are free to over ride this if they want to handle errors */
msg->error = ipmi_free_msg;
diff --git a/hw/ipmi/ipmi-fru.c b/hw/ipmi/ipmi-fru.c
index 8728e33..be3ca90 100644
--- a/hw/ipmi/ipmi-fru.c
+++ b/hw/ipmi/ipmi-fru.c
@@ -183,10 +183,9 @@ static void fru_write_complete(struct ipmi_msg *msg)
goto out;
offset = msg->data[WRITE_INDEX];
- msg->req_size = MIN(msg->data[REMAINING] + 3, IPMI_MAX_REQ_SIZE);
- msg->cmd = IPMI_CMD(IPMI_WRITE_FRU);
- msg->netfn = IPMI_NETFN(IPMI_WRITE_FRU) << 2;
- msg->resp_size = 2;
+ ipmi_init_msg(msg, IPMI_DEFAULT_INTERFACE, IPMI_WRITE_FRU,
+ fru_write_complete, NULL,
+ MIN(msg->data[REMAINING] + 3, IPMI_MAX_REQ_SIZE), 2);
memmove(&msg->data[3], &msg->data[offset + 3], msg->req_size - 3);
diff --git a/hw/ipmi/ipmi-sel.c b/hw/ipmi/ipmi-sel.c
index 3f9462a..5832228 100644
--- a/hw/ipmi/ipmi-sel.c
+++ b/hw/ipmi/ipmi-sel.c
@@ -69,6 +69,7 @@ static void ipmi_elog_poll(struct ipmi_msg *msg)
static unsigned int reservation_id = 0;
static unsigned int record_id = 0;
struct errorlog *elog_buf = (struct errorlog *) msg->user_data;
+ size_t req_size;
if (msg->cmd == IPMI_CMD(IPMI_RESERVE_SEL)) {
reservation_id = msg->data[0];
@@ -103,9 +104,17 @@ static void ipmi_elog_poll(struct ipmi_msg *msg)
return;
}
- msg->cmd = IPMI_CMD(IPMI_PARTIAL_ADD_ESEL);
- msg->netfn = IPMI_NETFN(IPMI_PARTIAL_ADD_ESEL) << 2;
- msg->resp_size = 2;
+ if ((pel_size - index) < (IPMI_MAX_REQ_SIZE - ESEL_HDR_SIZE)) {
+ /* Last data to send */
+ msg->data[6] = 1;
+ req_size = pel_size - index + ESEL_HDR_SIZE;
+ } else {
+ msg->data[6] = 0;
+ req_size = IPMI_MAX_REQ_SIZE;
+ }
+
+ ipmi_init_msg(msg, IPMI_DEFAULT_INTERFACE, IPMI_PARTIAL_ADD_ESEL,
+ ipmi_elog_poll, elog_buf, req_size, 2);
msg->data[0] = reservation_id & 0xff;
msg->data[1] = (reservation_id >> 8) & 0xff;
@@ -114,15 +123,6 @@ static void ipmi_elog_poll(struct ipmi_msg *msg)
msg->data[4] = index & 0xff;
msg->data[5] = (index >> 8) & 0xff;
- if ((pel_size - index) < (IPMI_MAX_REQ_SIZE - ESEL_HDR_SIZE)) {
- /* Last data to send */
- msg->data[6] = 1;
- msg->req_size = pel_size - index + ESEL_HDR_SIZE;
- } else {
- msg->data[6] = 0;
- msg->req_size = IPMI_MAX_REQ_SIZE;
- }
-
memcpy(&msg->data[ESEL_HDR_SIZE], &pel_buf[index], msg->req_size - ESEL_HDR_SIZE);
index += msg->req_size - ESEL_HDR_SIZE;
diff --git a/hw/ipmi/test/run-fru.c b/hw/ipmi/test/run-fru.c
index f147a28..0c70e2d 100644
--- a/hw/ipmi/test/run-fru.c
+++ b/hw/ipmi/test/run-fru.c
@@ -27,6 +27,14 @@ void ipmi_free_msg(struct ipmi_msg __unused *msg)
{
}
+void ipmi_init_msg(struct ipmi_msg __unused *msg, int __unused interface,
+ uint32_t __unused code,
+ void __unused (*complete)(struct ipmi_msg *),
+ void __unused *user_data, size_t __unused req_size,
+ size_t __unused resp_size)
+{
+}
+
struct ipmi_msg *ipmi_mkmsg(int __unused interface, uint32_t __unused code,
void __unused (*complete)(struct ipmi_msg *),
void __unused *user_data, void __unused *req_data, size_t __unused req_size,
diff --git a/include/ipmi.h b/include/ipmi.h
index 50de293..bbeae5a 100644
--- a/include/ipmi.h
+++ b/include/ipmi.h
@@ -163,6 +163,13 @@ struct ipmi_msg *ipmi_mkmsg(int interface, uint32_t code,
void *user_data, void *req_data, size_t req_size,
size_t resp_size);
+/* Initialise a previously allocated message with the required
+fields. The caller must ensure the message is large enough to hold the
+request and response data. */
+void ipmi_init_msg(struct ipmi_msg *msg, int interface,
+ uint32_t code, void (*complete)(struct ipmi_msg *),
+ void *user_data, size_t req_size, size_t resp_size);
+
/* Add an ipmi message to the queue */
int ipmi_queue_msg(struct ipmi_msg *msg);