From patchwork Thu Jun 29 12:39:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 782228 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 ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wz00g5Dm8z9s3T for ; Thu, 29 Jun 2017 22:51:47 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wz00g2lbQzDrBZ for ; Thu, 29 Jun 2017 22:51:47 +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 3wyzlR1Jf0zDrH4 for ; Thu, 29 Jun 2017 22:40:19 +1000 (AEST) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v5TCd1fT086305 for ; Thu, 29 Jun 2017 08:40:17 -0400 Received: from e23smtp02.au.ibm.com (e23smtp02.au.ibm.com [202.81.31.144]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bcpx5093e-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 29 Jun 2017 08:40:16 -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:08 +1000 Received: from d23relay07.au.ibm.com (202.81.31.226) 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:04 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v5TCe3As48693304 for ; Thu, 29 Jun 2017 22:40:03 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v5TCe15b030491 for ; Thu, 29 Jun 2017 22:40:01 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v5TCe0qT030450; Thu, 29 Jun 2017 22:40:00 +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 1B5ECA037F; 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:22 +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-0000022119A6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17062912-0005-0000-0000-00005E05195A Message-Id: <20170629123925.28243-9-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=0 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 08/11] libflash/mbox-flash: Use static arrays of function pointers 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" Signed-off-by: Cyril Bur --- libflash/mbox-flash.c | 113 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 81 insertions(+), 32 deletions(-) diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c index 2a7321f4..bbb54c51 100644 --- a/libflash/mbox-flash.c +++ b/libflash/mbox-flash.c @@ -41,6 +41,9 @@ #define MSG_CREATE(init_command) { .command = init_command } +struct mbox_flash_data; +typedef void (mbox_handler)(struct mbox_flash_data *, struct bmc_mbox_msg *); + struct lpc_window { uint32_t lpc_addr; /* Offset into LPC space */ uint32_t cur_pos; /* Current position of the window in the flash */ @@ -62,10 +65,63 @@ struct mbox_flash_data { bool pause; bool busy; bool ack; - /* Plus one, commands start at 1 */ - void (*handlers[MBOX_COMMAND_COUNT + 1])(struct mbox_flash_data *, struct bmc_mbox_msg*); + mbox_handler **handlers; +}; + +static mbox_handler mbox_flash_do_nop; +static mbox_handler mbox_flash_do_illegal; + +/* Version 1 and Version 2 compatible */ +static mbox_handler mbox_flash_do_get_mbox_info; + +static mbox_handler mbox_flash_do_get_flash_info_v2; +static mbox_handler mbox_flash_do_get_flash_info_v1; + +static mbox_handler mbox_flash_do_create_read_window_v2; +static mbox_handler mbox_flash_do_create_read_window_v1; + +static mbox_handler mbox_flash_do_create_write_window_v2; +static mbox_handler mbox_flash_do_create_write_window_v1; + +/* Version 1 and Version 2 compatible */ +static mbox_handler mbox_flash_do_close_window; + +/* Plus one, commands start at 1 */ +static mbox_handler *handlers_v2[MBOX_COMMAND_COUNT + 1] = { + NULL, + &mbox_flash_do_nop, + &mbox_flash_do_get_mbox_info, + &mbox_flash_do_get_flash_info_v2, + &mbox_flash_do_create_read_window_v2, + &mbox_flash_do_close_window, + &mbox_flash_do_create_write_window_v2, + &mbox_flash_do_nop, + &mbox_flash_do_nop, + &mbox_flash_do_nop, + &mbox_flash_do_nop }; +/* + * Plus one, commands start at 1. + * V2 adds a command so there should never be a response for the last + * command. + * Ensure we print an error message with mbox_flash_do_illegal(). + */ +static mbox_handler *handlers_v1[MBOX_COMMAND_COUNT + 1] = { + NULL, + &mbox_flash_do_nop, + &mbox_flash_do_get_mbox_info, + &mbox_flash_do_get_flash_info_v1, + &mbox_flash_do_create_read_window_v1, + &mbox_flash_do_close_window, + &mbox_flash_do_create_write_window_v1, + &mbox_flash_do_nop, + &mbox_flash_do_nop, + &mbox_flash_do_nop, + &mbox_flash_do_illegal +}; + + static void mbox_flash_callback(struct bmc_mbox_msg *msg, void *priv); static void mbox_flash_attn(uint8_t attn, void *priv); @@ -333,6 +389,12 @@ static void mbox_flash_do_nop(struct mbox_flash_data *mbox_flash __unused, { } +static void mbox_flash_do_illegal(struct mbox_flash_data *mbox_flash __unused, + struct bmc_mbox_msg *msg __unused) +{ + prlog(PR_CRIT, "Got response to unknown message type\n"); +} + /* Version 1 and Version 2 compatible */ static void mbox_flash_do_get_mbox_info(struct mbox_flash_data *mbox_flash, struct bmc_mbox_msg *msg) @@ -891,18 +953,7 @@ static int protocol_init(struct mbox_flash_data *mbox_flash) mbox_flash->bl.get_info = &mbox_flash_get_info; /* Assume V2 */ - mbox_flash->handlers[0] = NULL; - mbox_flash->handlers[MBOX_C_RESET_STATE] = &mbox_flash_do_nop; - mbox_flash->handlers[MBOX_C_GET_MBOX_INFO] = &mbox_flash_do_get_mbox_info; - mbox_flash->handlers[MBOX_C_GET_FLASH_INFO] = &mbox_flash_do_get_flash_info_v2; - mbox_flash->handlers[MBOX_C_CREATE_READ_WINDOW] = &mbox_flash_do_create_read_window_v2; - mbox_flash->handlers[MBOX_C_CLOSE_WINDOW] = &mbox_flash_do_close_window; - mbox_flash->handlers[MBOX_C_CREATE_WRITE_WINDOW] = &mbox_flash_do_create_write_window_v2; - mbox_flash->handlers[MBOX_C_MARK_WRITE_DIRTY] = &mbox_flash_do_nop; - mbox_flash->handlers[MBOX_C_WRITE_FLUSH] = &mbox_flash_do_nop; - mbox_flash->handlers[MBOX_C_BMC_EVENT_ACK] = &mbox_flash_do_nop; - mbox_flash->handlers[MBOX_C_MARK_WRITE_ERASED] = &mbox_flash_do_nop; - + mbox_flash->handlers = handlers_v2; bmc_mbox_register_callback(&mbox_flash_callback, mbox_flash); bmc_mbox_register_attn(&mbox_flash_attn, mbox_flash); @@ -922,7 +973,8 @@ static int protocol_init(struct mbox_flash_data *mbox_flash) /* * Always attempt init with V2. * The GET_MBOX_INFO response will confirm that the other side can - * talk V2, we'll update this variable then if V2 is not supported + * talk the highest version, we'll update this variable then if + * our highest version is not supported */ mbox_flash->version = 2; @@ -940,23 +992,20 @@ static int protocol_init(struct mbox_flash_data *mbox_flash) } 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; - /* Not all handlers differ, update those which do */ - mbox_flash->handlers[MBOX_C_GET_FLASH_INFO] = &mbox_flash_do_get_flash_info_v1; - mbox_flash->handlers[MBOX_C_CREATE_READ_WINDOW] = - &mbox_flash_do_create_read_window_v1; - mbox_flash->handlers[MBOX_C_CREATE_WRITE_WINDOW] = - &mbox_flash_do_create_write_window_v1; - mbox_flash->handlers[MBOX_C_MARK_WRITE_ERASED] = NULL; /* Not in V1 */ - } else if (mbox_flash->version > 2) { - /* - * Uh, we requested version 2... The BMC is can only lower the - * requested version not do anything else. FWIW there is no - * verion 0 - */ - prlog(PR_CRIT, "Bad version: %u\n", mbox_flash->version); - rc = FLASH_ERR_PARM_ERROR; + switch (mbox_flash->version) { + case 1: + mbox_flash->bl.erase = &mbox_flash_erase_v1; + mbox_flash->handlers = handlers_v1; + break; + case 2: + break; + default: + /* + * The BMC is can only lower the requested version not do + * anything else. FWIW there is no verion 0. + */ + prlog(PR_CRIT, "Bad version: %u\n", mbox_flash->version); + rc = FLASH_ERR_PARM_ERROR; } return rc;