From patchwork Wed Nov 29 21:05:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deb McLemore X-Patchwork-Id: 842767 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@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 3ynCls4tgcz9s03 for ; Thu, 30 Nov 2017 08:07:21 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3ynCls3T8WzDrpg for ; Thu, 30 Nov 2017 08:07:21 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=debmc@linux.vnet.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 3ynCkN0y0TzDqs4 for ; Thu, 30 Nov 2017 08:06:03 +1100 (AEDT) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vATL4XU6150105 for ; Wed, 29 Nov 2017 16:06:01 -0500 Received: from e18.ny.us.ibm.com (e18.ny.us.ibm.com [129.33.205.208]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ej1pbqdg7-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 29 Nov 2017 16:06:01 -0500 Received: from localhost by e18.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 29 Nov 2017 16:06:00 -0500 Received: from b01cxnp22034.gho.pok.ibm.com (9.57.198.24) by e18.ny.us.ibm.com (146.89.104.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 29 Nov 2017 16:05:58 -0500 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vATL5wwI52494566; Wed, 29 Nov 2017 21:05:58 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38527B205A; Wed, 29 Nov 2017 16:03:06 -0500 (EST) Received: from debmc-P50.localdomain (unknown [9.85.170.20]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP id E9C28B2054; Wed, 29 Nov 2017 16:03:05 -0500 (EST) Received: by debmc-P50.localdomain (Postfix, from userid 1000) id 6F232D014A4; Wed, 29 Nov 2017 15:05:55 -0600 (CST) From: Deb McLemore To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v2] powerpc/powernv: Add queue mechanism for early messages Date: Wed, 29 Nov 2017 15:05:53 -0600 X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-TM-AS-GCONF: 00 x-cbid: 17112921-0044-0000-0000-000003B7226B X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008123; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000242; SDB=6.00953064; UDB=6.00481524; IPR=6.00733144; BA=6.00005721; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018256; XFM=3.00000015; UTC=2017-11-29 21:05:59 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112921-0045-0000-0000-000007E64F92 Message-Id: <1511989553-16198-1-git-send-email-debmc@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-29_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=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711290272 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Deb McLemore , jk@ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Problem being solved is when issuing a BMC soft poweroff during IPL, the poweroff was being lost so the machine would not poweroff. Opal messages were being received before the opal-power code registered its notifiers. Alternatives discussed (option #3 was chosen): 1 - Have opal_message_init() explicitly call opal_power_control_init() before it dequeues any OPAL messages (i.e. before we register the opal-msg IRQ handler). 2 - Introduce concept of critical message types and when we register handlers we track which message types have a registered handler, then defer the opal-msg IRQ registration until we have a handler registered for all the critical types. 3 - Buffering messages, if we receive a message and do not yet have a handler for that type, store the message and replay when a handler for that type is registered. Signed-off-by: Deb McLemore --- arch/powerpc/platforms/powernv/opal.c | 83 ++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c index 65c79ec..46d7604 100644 --- a/arch/powerpc/platforms/powernv/opal.c +++ b/arch/powerpc/platforms/powernv/opal.c @@ -40,6 +40,16 @@ #include "powernv.h" +#define OPAL_MSG_QUEUE_MAX 16 + +struct opal_msg_node { + struct list_head list; + struct opal_msg msg; +}; + +static DEFINE_SPINLOCK(msg_list_lock); +static LIST_HEAD(msg_list); + /* /sys/firmware/opal */ struct kobject *opal_kobj; @@ -55,6 +65,8 @@ struct mcheck_recoverable_range { u64 recover_addr; }; +static int msg_list_size; + static struct mcheck_recoverable_range *mc_recoverable_range; static int mc_recoverable_range_len; @@ -231,6 +243,44 @@ static int __init opal_register_exception_handlers(void) } machine_early_initcall(powernv, opal_register_exception_handlers); +static void queue_replay_msg(void *msg) +{ + struct opal_msg_node *msg_node; + + if (msg_list_size < OPAL_MSG_QUEUE_MAX) { + msg_node = kzalloc(sizeof(*msg_node), GFP_ATOMIC); + if (msg_node) { + INIT_LIST_HEAD(&msg_node->list); + memcpy(&msg_node->msg, msg, sizeof(struct opal_msg)); + list_add_tail(&msg_node->list, &msg_list); + msg_list_size++; + } else + pr_warn_once("message queue no memory\n"); + + if (msg_list_size >= OPAL_MSG_QUEUE_MAX) + pr_warn_once("message queue full\n"); + } +} + +static void dequeue_replay_msg(enum opal_msg_type msg_type) +{ + struct opal_msg_node *msg_node, *tmp; + unsigned long flags; + + spin_lock_irqsave(&msg_list_lock, flags); + list_for_each_entry_safe(msg_node, tmp, &msg_list, list) { + if (be32_to_cpu(msg_node->msg.msg_type) != msg_type) + continue; + atomic_notifier_call_chain(&opal_msg_notifier_head[msg_type], + msg_type, + &msg_node->msg); + list_del(&msg_node->list); + kfree(msg_node); + msg_list_size--; + } + spin_unlock_irqrestore(&msg_list_lock, flags); +} + /* * Opal message notifier based on message type. Allow subscribers to get * notified for specific messgae type. @@ -238,14 +288,25 @@ machine_early_initcall(powernv, opal_register_exception_handlers); int opal_message_notifier_register(enum opal_msg_type msg_type, struct notifier_block *nb) { + int ret; + if (!nb || msg_type >= OPAL_MSG_TYPE_MAX) { pr_warning("%s: Invalid arguments, msg_type:%d\n", __func__, msg_type); return -EINVAL; } - return atomic_notifier_chain_register( - &opal_msg_notifier_head[msg_type], nb); + ret = atomic_notifier_chain_register( + &opal_msg_notifier_head[msg_type], nb); + + if (ret) + return ret; + + /* Replay any queued messages that came in */ + /* prior to the notifier chain registration */ + dequeue_replay_msg(msg_type); + + return 0; } EXPORT_SYMBOL_GPL(opal_message_notifier_register); @@ -259,9 +320,21 @@ EXPORT_SYMBOL_GPL(opal_message_notifier_unregister); static void opal_message_do_notify(uint32_t msg_type, void *msg) { - /* notify subscribers */ - atomic_notifier_call_chain(&opal_msg_notifier_head[msg_type], - msg_type, msg); + unsigned long flags; + + spin_lock_irqsave(&msg_list_lock, flags); + + if (opal_msg_notifier_head[msg_type].head != NULL) { + /* notify subscribers */ + atomic_notifier_call_chain(&opal_msg_notifier_head[msg_type], + msg_type, msg); + } else { + /* Queue up the msg since no notifiers have */ + /* registered yet for this msg_type */ + queue_replay_msg(msg); + } + + spin_unlock_irqrestore(&msg_list_lock, flags); } static void opal_handle_message(void)