From patchwork Tue Dec 5 01:01:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 844515 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 3yrNl116zlz9s7g for ; Tue, 5 Dec 2017 12:02:37 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yrNl04wqLzDrqJ for ; Tue, 5 Dec 2017 12:02:36 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=au1.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=cyril.bur@au1.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 3yrNk00WVMzDrqV for ; Tue, 5 Dec 2017 12:01:43 +1100 (AEDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB50wxom070745 for ; Mon, 4 Dec 2017 20:01:41 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2endqryfme-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 04 Dec 2017 20:01:41 -0500 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Dec 2017 01:01:39 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 5 Dec 2017 01:01:36 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vB511aL926148974; Tue, 5 Dec 2017 01:01:36 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B970B4C044; Tue, 5 Dec 2017 00:56:28 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2034D4C046; Tue, 5 Dec 2017 00:56:28 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 5 Dec 2017 00:56:28 +0000 (GMT) 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 8BD68A023F; Tue, 5 Dec 2017 12:01:34 +1100 (AEDT) From: Cyril Bur To: skiboot@lists.ozlabs.org Date: Tue, 5 Dec 2017 12:01:06 +1100 X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171205010113.23263-1-cyril.bur@au1.ibm.com> References: <20171205010113.23263-1-cyril.bur@au1.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17120501-0016-0000-0000-000005095A64 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17120501-0017-0000-0000-0000284552D7 Message-Id: <20171205010113.23263-5-cyril.bur@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-04_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712050012 Subject: [Skiboot] [PATCH v3 04/11] libflash/mbox-flash: Allow mbox-flash to tell the driver msg timeouts X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair@popple.id.au MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Currently when mbox-flash decides that a message times out the driver has no way of knowing to drop the message and will continue waiting for a response indefinitely preventing more messages from ever being sent. This is a problem if the BMC crashes or has some other issue where it won't ever respond to our outstanding message. This patch provides a method for mbox-flash to tell the driver how long it should wait before it no longer needs to care about the response. Signed-off-by: Cyril Bur --- hw/lpc-mbox.c | 12 +++++++++--- include/lpc-mbox.h | 2 +- libflash/mbox-flash.c | 17 +++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/hw/lpc-mbox.c b/hw/lpc-mbox.c index 74214938..f303f4d5 100644 --- a/hw/lpc-mbox.c +++ b/hw/lpc-mbox.c @@ -64,6 +64,7 @@ struct mbox { struct lock lock; /* Protect in_flight */ struct bmc_mbox_msg *in_flight; uint8_t sequence; + unsigned long timeout; }; static struct mbox mbox; @@ -115,7 +116,7 @@ static void bmc_mbox_send_message(struct bmc_mbox_msg *msg) bmc_mbox_outb(MBOX_CTRL_INT_SEND, MBOX_HOST_CTRL); } -int bmc_mbox_enqueue(struct bmc_mbox_msg *msg) +int bmc_mbox_enqueue(struct bmc_mbox_msg *msg, unsigned int timeout_sec) { if (!mbox.base) { prlog(PR_CRIT, "Using MBOX without init!\n"); @@ -125,10 +126,15 @@ int bmc_mbox_enqueue(struct bmc_mbox_msg *msg) lock(&mbox.lock); if (mbox.in_flight) { prlog(PR_DEBUG, "MBOX message already in flight\n"); - unlock(&mbox.lock); - return OPAL_BUSY; + if (mftb() > mbox.timeout) { + prlog(PR_ERR, "In flight message dropped on the floor\n"); + } else { + unlock(&mbox.lock); + return OPAL_BUSY; + } } + mbox.timeout = mftb() + secs_to_tb(timeout_sec); mbox.in_flight = msg; unlock(&mbox.lock); msg->seq = ++mbox.sequence; diff --git a/include/lpc-mbox.h b/include/lpc-mbox.h index c4b1015b..569f1f72 100644 --- a/include/lpc-mbox.h +++ b/include/lpc-mbox.h @@ -63,7 +63,7 @@ struct bmc_mbox_msg { uint8_t bmc; }; -int bmc_mbox_enqueue(struct bmc_mbox_msg *msg); +int bmc_mbox_enqueue(struct bmc_mbox_msg *msg, unsigned int timeout_sec); int bmc_mbox_register_callback(void (*callback)(struct bmc_mbox_msg *msg, void *priv), void *drv_data); int bmc_mbox_register_attn(void (*callback)(uint8_t bits, void *priv), diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c index 3615df78..7fd2e119 100644 --- a/libflash/mbox-flash.c +++ b/libflash/mbox-flash.c @@ -252,13 +252,14 @@ static bool is_reboot(struct mbox_flash_data *mbox_flash) return mbox_flash->reboot; } -static int msg_send(struct mbox_flash_data *mbox_flash, struct bmc_mbox_msg *msg) +static int msg_send(struct mbox_flash_data *mbox_flash, struct bmc_mbox_msg *msg, + unsigned int timeout_sec) { if (is_reboot(mbox_flash)) return FLASH_ERR_AGAIN; mbox_flash->busy = true; mbox_flash->rc = 0; - return bmc_mbox_enqueue(msg); + return bmc_mbox_enqueue(msg, timeout_sec); } static int wait_for_bmc(struct mbox_flash_data *mbox_flash, unsigned int timeout_sec) @@ -307,7 +308,7 @@ static int mbox_flash_ack(struct mbox_flash_data *mbox_flash, uint8_t reg) /* Clear this first so msg_send() doesn't freak out */ mbox_flash->reboot = false; - rc = msg_send(mbox_flash, msg); + 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; @@ -499,7 +500,7 @@ static int mbox_flash_mark_write(struct mbox_flash_data *mbox_flash, msg_put_u16(msg, 2, end - start); /* Total Length */ } - rc = msg_send(mbox_flash, msg); + rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); goto out; @@ -554,7 +555,7 @@ static int mbox_flash_flush(struct mbox_flash_data *mbox_flash) if (!msg) return FLASH_ERR_MALLOC_FAILED; - rc = msg_send(mbox_flash, msg); + rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); goto out; @@ -609,7 +610,7 @@ static int mbox_window_move(struct mbox_flash_data *mbox_flash, return FLASH_ERR_MALLOC_FAILED; msg_put_u16(msg, 0, bytes_to_blocks(mbox_flash, pos)); - rc = msg_send(mbox_flash, msg); + rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); goto out; @@ -772,7 +773,7 @@ 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); + rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); goto out; @@ -965,7 +966,7 @@ static int protocol_init(struct mbox_flash_data *mbox_flash) return FLASH_ERR_MALLOC_FAILED; msg_put_u8(msg, 0, mbox_flash->version); - rc = msg_send(mbox_flash, msg); + rc = msg_send(mbox_flash, msg, MBOX_DEFAULT_TIMEOUT); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); goto out;