From patchwork Tue Jan 13 04:21:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 428254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1416514017C for ; Tue, 13 Jan 2015 15:21:28 +1100 (AEDT) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id D095E1A0C29 for ; Tue, 13 Jan 2015 15:21:27 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id F32EA1A0749 for ; Tue, 13 Jan 2015 15:21:20 +1100 (AEDT) Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Jan 2015 14:21:19 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 13 Jan 2015 14:21:17 +1000 Received: from d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 523353578023 for ; Tue, 13 Jan 2015 15:21:16 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t0D4LFK639977028 for ; Tue, 13 Jan 2015 15:21:16 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t0D4LFEM019751 for ; Tue, 13 Jan 2015 15:21:15 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t0D4LFHH019748 for ; Tue, 13 Jan 2015 15:21:15 +1100 Received: from localhost (haven.au.ibm.com [9.192.253.15]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 630AAA01A5 for ; Tue, 13 Jan 2015 15:21:15 +1100 (AEDT) From: Alistair Popple To: skiboot@lists.ozlabs.org Date: Tue, 13 Jan 2015 15:21:13 +1100 Message-Id: <1421122875-2963-1-git-send-email-alistair@popple.id.au> X-Mailer: git-send-email 1.8.3.2 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15011304-0009-0000-0000-000000CA6122 Subject: [Skiboot] [PATCH 1/3] ipmi: Add a function to (re)initialise a message without allocation X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" 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 --- core/ipmi.c | 28 ++++++++++++++++++---------- hw/ipmi/ipmi-fru.c | 7 +++---- hw/ipmi/ipmi-sel.c | 24 ++++++++++++------------ include/ipmi.h | 7 +++++++ 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/core/ipmi.c b/core/ipmi.c index 14c35f3..a8d99e1 100644 --- a/core/ipmi.c +++ b/core/ipmi.c @@ -27,6 +27,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, @@ -40,20 +56,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 49a7e0f..77b23e6 100644 --- a/hw/ipmi/ipmi-fru.c +++ b/hw/ipmi/ipmi-fru.c @@ -181,10 +181,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 d6f7f47..22d48fd 100644 --- a/hw/ipmi/ipmi-sel.c +++ b/hw/ipmi/ipmi-sel.c @@ -67,6 +67,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]; @@ -101,9 +102,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; @@ -112,15 +121,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/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);