From patchwork Thu Jun 29 12:39:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 782222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wyzzQ3wjsz9s3T for ; Thu, 29 Jun 2017 22:50:42 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wyzzQ2q05zDrJJ for ; Thu, 29 Jun 2017 22:50:42 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wyzlL6cFTzDrGr for ; Thu, 29 Jun 2017 22:40:14 +1000 (AEST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5TCd5Bw109627 for ; Thu, 29 Jun 2017 08:40:13 -0400 Received: from e23smtp02.au.ibm.com (e23smtp02.au.ibm.com [202.81.31.144]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bd1npr6ae-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 29 Jun 2017 08:40:12 -0400 Received: from localhost by e23smtp02.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 29 Jun 2017 22:40:06 +1000 Received: from d23relay09.au.ibm.com (202.81.31.228) by e23smtp02.au.ibm.com (202.81.31.208) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 29 Jun 2017 22:40:06 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5TCe2mP66978000 for ; Thu, 29 Jun 2017 22:40:02 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v5TCe2KZ007374 for ; Thu, 29 Jun 2017 22:40:02 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v5TCe2QL007363; Thu, 29 Jun 2017 22:40:02 +1000 Received: from camb691.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 07E8CA02C5; Thu, 29 Jun 2017 22:40:02 +1000 (AEST) From: Cyril Bur To: skiboot@lists.ozlabs.org, sjitindarsingh@gmail.com Date: Thu, 29 Jun 2017 22:39:20 +1000 X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170629123925.28243-1-cyril.bur@au1.ibm.com> References: <20170629123925.28243-1-cyril.bur@au1.ibm.com> X-TM-AS-MML: disable x-cbid: 17062912-0004-0000-0000-0000022119A9 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062912-0005-0000-0000-00005E05195C Message-Id: <20170629123925.28243-7-cyril.bur@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-29_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1706290207 Subject: [Skiboot] [PATCH 06/11] libflash/mbox-flash: Simplify message sending X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair@popple.id.au, sam@mendozajonas.com MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" hw/lpc-mbox no longer requires that the memory associated with commands exist for the lifetime of the message, simply long enough for the sending function and for the receving callback. Remove all code to deal with allocating messages. Signed-off-by: Cyril Bur --- libflash/mbox-flash.c | 123 +++++++++++++------------------------------------- 1 file changed, 31 insertions(+), 92 deletions(-) diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c index 2914901e..999f663c 100644 --- a/libflash/mbox-flash.c +++ b/libflash/mbox-flash.c @@ -39,6 +39,8 @@ #define MBOX_DEFAULT_TIMEOUT 30 +#define MSG_CREATE(init_command) { .command = init_command } + struct lpc_window { uint32_t lpc_addr; /* Offset into LPC space */ uint32_t cur_pos; /* Current position of the window in the flash */ @@ -61,7 +63,6 @@ struct mbox_flash_data { bool ack; /* Plus one, commands start at 1 */ void (*handlers[MBOX_COMMAND_COUNT + 1])(struct mbox_flash_data *, struct bmc_mbox_msg*); - struct bmc_mbox_msg msg_mem; }; static void mbox_flash_callback(struct bmc_mbox_msg *msg, void *priv); @@ -188,25 +189,6 @@ static uint16_t bytes_to_blocks(struct mbox_flash_data *mbox_flash, return bytes >> mbox_flash->shift; } -static struct bmc_mbox_msg *msg_alloc(struct mbox_flash_data *mbox_flash, - uint8_t command) -{ - /* - * Yes this causes *slow*. - * This file and lpc-mbox have far greater slow points, zeroed - * data regs are VERY useful for debugging. Think twice if this is - * really the performance optimisation you want to make. - */ - memset(&mbox_flash->msg_mem, 0, sizeof(mbox_flash->msg_mem)); - mbox_flash->msg_mem.command = command; - return &mbox_flash->msg_mem; -} - -static void msg_free_memory(struct bmc_mbox_msg *mem __unused) -{ - /* Allocation is so simple this isn't required */ -} - /* * The BMC may send is an out of band message to say that it doesn't * own the flash anymore. @@ -296,26 +278,22 @@ static int wait_for_bmc(struct mbox_flash_data *mbox_flash, unsigned int timeout static int mbox_flash_ack(struct mbox_flash_data *mbox_flash, uint8_t reg) { - struct bmc_mbox_msg *msg; + struct bmc_mbox_msg msg = MSG_CREATE(MBOX_C_BMC_EVENT_ACK); int rc; - msg = msg_alloc(mbox_flash, MBOX_C_BMC_EVENT_ACK); - if (!msg) - return FLASH_ERR_MALLOC_FAILED; - - msg_put_u8(msg, 0, reg); + msg_put_u8(&msg, 0, reg); /* Clear this first so msg_send() doesn't freak out */ mbox_flash->reboot = false; - rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); + rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT); /* Still need to deal with it, we've only acked it now. */ mbox_flash->reboot = true; if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); - goto out; + return rc; } /* @@ -327,8 +305,6 @@ static int mbox_flash_ack(struct mbox_flash_data *mbox_flash, uint8_t reg) if (rc) prlog(PR_ERR, "Error waiting for BMC\n"); -out: - msg_free_memory(msg); return rc; } @@ -474,21 +450,17 @@ static bool do_delayed_work(struct mbox_flash_data *mbox_flash) static int mbox_flash_mark_write(struct mbox_flash_data *mbox_flash, uint64_t pos, uint64_t len, int type) { - struct bmc_mbox_msg *msg; + struct bmc_mbox_msg msg = MSG_CREATE(type); int rc; - msg = msg_alloc(mbox_flash, type); - if (!msg) - return FLASH_ERR_MALLOC_FAILED; - if (mbox_flash->version == 1) { uint32_t start = ALIGN_DOWN(pos, 1 << mbox_flash->shift); - msg_put_u16(msg, 0, bytes_to_blocks(mbox_flash, pos)); + msg_put_u16(&msg, 0, bytes_to_blocks(mbox_flash, pos)); /* * We need to make sure that we mark dirty until up to atleast * pos + len. */ - msg_put_u32(msg, 2, pos + len - start); + msg_put_u32(&msg, 2, pos + len - start); } else { uint64_t window_pos = pos - mbox_flash->write.cur_pos; uint16_t start = bytes_to_blocks(mbox_flash, window_pos); @@ -496,24 +468,20 @@ static int mbox_flash_mark_write(struct mbox_flash_data *mbox_flash, ALIGN_UP(window_pos + len, 1 << mbox_flash->shift)); - msg_put_u16(msg, 0, start); - msg_put_u16(msg, 2, end - start); /* Total Length */ + msg_put_u16(&msg, 0, start); + msg_put_u16(&msg, 2, end - start); /* Total Length */ } - rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); + rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); - goto out; + return rc; } rc = wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT); - if (rc) { + if (rc) prlog(PR_ERR, "Error waiting for BMC\n"); - goto out; - } -out: - msg_free_memory(msg); return rc; } @@ -543,7 +511,7 @@ static int mbox_flash_erase(struct mbox_flash_data *mbox_flash, uint64_t pos, static int mbox_flash_flush(struct mbox_flash_data *mbox_flash) { - struct bmc_mbox_msg *msg; + struct bmc_mbox_msg msg = MSG_CREATE(MBOX_C_WRITE_FLUSH); int rc; if (!mbox_flash->write.open) { @@ -551,22 +519,16 @@ static int mbox_flash_flush(struct mbox_flash_data *mbox_flash) return FLASH_ERR_DEVICE_GONE; } - msg = msg_alloc(mbox_flash, MBOX_C_WRITE_FLUSH); - if (!msg) - return FLASH_ERR_MALLOC_FAILED; - - rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); + rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); - goto out; + return rc; } rc = wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT); if (rc) prlog(PR_ERR, "Error waiting for BMC\n"); -out: - msg_free_memory(msg); return rc; } @@ -587,7 +549,7 @@ static int mbox_window_move(struct mbox_flash_data *mbox_flash, struct lpc_window *win, uint8_t command, uint64_t pos, uint64_t len, uint64_t *size) { - struct bmc_mbox_msg *msg; + struct bmc_mbox_msg msg = MSG_CREATE(command); int rc; /* Is the window currently open valid */ @@ -605,15 +567,11 @@ static int mbox_window_move(struct mbox_flash_data *mbox_flash, */ win->cur_pos = pos & ~mbox_flash_mask(mbox_flash); - msg = msg_alloc(mbox_flash, command); - if (!msg) - return FLASH_ERR_MALLOC_FAILED; - - msg_put_u16(msg, 0, bytes_to_blocks(mbox_flash, pos)); - rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); + msg_put_u16(&msg, 0, bytes_to_blocks(mbox_flash, pos)); + rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); - goto out; + return rc; } mbox_flash->read.open = false; @@ -622,7 +580,7 @@ static int mbox_window_move(struct mbox_flash_data *mbox_flash, rc = wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Error waiting for BMC\n"); - goto out; + return rc; } *size = len; @@ -645,8 +603,6 @@ static int mbox_window_move(struct mbox_flash_data *mbox_flash, prlog(PR_ERR, "win pos: 0x%08x win size: 0x%08x\n", win->cur_pos, win->size); } -out: - msg_free_memory(msg); return rc; } @@ -750,8 +706,8 @@ static int mbox_flash_read(struct blocklevel_device *bl, uint64_t pos, static int mbox_flash_get_info(struct blocklevel_device *bl, const char **name, uint64_t *total_size, uint32_t *erase_granule) { + struct bmc_mbox_msg msg = MSG_CREATE(MBOX_C_GET_FLASH_INFO); struct mbox_flash_data *mbox_flash; - struct bmc_mbox_msg *msg; int rc; mbox_flash = container_of(bl, struct mbox_flash_data, bl); @@ -759,10 +715,6 @@ static int mbox_flash_get_info(struct blocklevel_device *bl, const char **name, if (do_delayed_work(mbox_flash)) return FLASH_ERR_AGAIN; - msg = msg_alloc(mbox_flash, MBOX_C_GET_FLASH_INFO); - if (!msg) - return FLASH_ERR_MALLOC_FAILED; - /* * We want to avoid runtime mallocs in skiboot. The expected * behavour to uses of libflash is that one can free() the memory @@ -773,15 +725,15 @@ static int mbox_flash_get_info(struct blocklevel_device *bl, const char **name, *name = NULL; mbox_flash->busy = true; - rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); + rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); - goto out; + return rc; } if (wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT)) { prlog(PR_ERR, "Error waiting for BMC\n"); - goto out; + return rc; } mbox_flash->bl.erase_mask = mbox_flash->erase_granule - 1; @@ -791,8 +743,6 @@ static int mbox_flash_get_info(struct blocklevel_device *bl, const char **name, if (erase_granule) *erase_granule = mbox_flash->erase_granule; -out: - msg_free_memory(msg); return rc; } @@ -922,7 +872,7 @@ out: static int protocol_init(struct mbox_flash_data *mbox_flash) { - struct bmc_mbox_msg *msg; + struct bmc_mbox_msg msg = MSG_CREATE(MBOX_C_GET_MBOX_INFO); int rc; /* Assume V2 */ @@ -961,25 +911,19 @@ static int protocol_init(struct mbox_flash_data *mbox_flash) */ mbox_flash->version = 2; - msg = msg_alloc(mbox_flash, MBOX_C_GET_MBOX_INFO); - if (!msg) - return FLASH_ERR_MALLOC_FAILED; - - msg_put_u8(msg, 0, mbox_flash->version); - rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); + msg_put_u8(&msg, 0, mbox_flash->version); + rc = msg_send(mbox_flash, &msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); - goto out; + return rc; } rc = wait_for_bmc(mbox_flash, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Error waiting for BMC\n"); - goto out; + return rc; } - msg_free_memory(msg); - prlog(PR_INFO, "Detected mbox protocol version %d\n", mbox_flash->version); if (mbox_flash->version == 1) { mbox_flash->bl.erase = &mbox_flash_erase_v1; @@ -998,13 +942,8 @@ static int protocol_init(struct mbox_flash_data *mbox_flash) */ prlog(PR_CRIT, "Bad version: %u\n", mbox_flash->version); rc = FLASH_ERR_PARM_ERROR; - goto out; } - - return 0; -out: - msg_free_memory(msg); return rc; }