From patchwork Sun Nov 26 14:30:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deb McLemore X-Patchwork-Id: 841408 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 3ylC6Z0yPnz9s5L for ; Mon, 27 Nov 2017 01:31:34 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3ylC6Y74mFzDrpR for ; Mon, 27 Nov 2017 01:31:33 +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.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=debmc@linux.vnet.ibm.com; receiver=) 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 3ylC5F5Gz9zDrMj for ; Mon, 27 Nov 2017 01:30:24 +1100 (AEDT) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAQETbUG029433 for ; Sun, 26 Nov 2017 09:30:22 -0500 Received: from e18.ny.us.ibm.com (e18.ny.us.ibm.com [129.33.205.208]) by mx0a-001b2d01.pphosted.com with ESMTP id 2efpxawbr2-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 26 Nov 2017 09:30:21 -0500 Received: from localhost by e18.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 26 Nov 2017 09:30:20 -0500 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e18.ny.us.ibm.com (146.89.104.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 26 Nov 2017 09:30:19 -0500 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAQEUIYJ41812016; Sun, 26 Nov 2017 14:30:19 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D99A2AE034; Sun, 26 Nov 2017 09:31:13 -0500 (EST) Received: from debmc-P50.localdomain (unknown [9.85.176.171]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id 99791AE052; Sun, 26 Nov 2017 09:31:13 -0500 (EST) Received: by debmc-P50.localdomain (Postfix, from userid 1000) id C84FCD04A75; Sun, 26 Nov 2017 08:30:16 -0600 (CST) From: Deb McLemore To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH] powerpc/powernv: Add queue mechanism for early messages Date: Sun, 26 Nov 2017 08:30:15 -0600 X-Mailer: git-send-email 2.7.4 X-TM-AS-GCONF: 00 x-cbid: 17112614-0044-0000-0000-000003B57AC3 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008121; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000241; SDB=6.00951494; UDB=6.00480582; IPR=6.00731577; BA=6.00005715; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018194; XFM=3.00000015; UTC=2017-11-26 14:30:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112614-0045-0000-0000-000007E4A47B Message-Id: <1511706615-7126-1-git-send-email-debmc@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-26_09:, , 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-1711260204 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" Add a check for do_notify to confirm that a message handler has been registered before an attempt is made to call notifier call chain. If the message handler has not been registered queue up the message to be replayed when the proper registration is called. Signed-off-by: Deb McLemore --- arch/powerpc/platforms/powernv/opal.c | 88 +++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c index 65c79ec..0e3b464 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 OpalMsgNode { + struct list_head opal_queue_list_node; + struct opal_msg msg; + uint32_t queue_msg_type; +}; + +static LIST_HEAD(opal_msg_queue_pending); + /* /sys/firmware/opal */ struct kobject *opal_kobj; @@ -55,11 +65,15 @@ struct mcheck_recoverable_range { u64 recover_addr; }; +static unsigned long opal_msg_notify_reg_mask; +static int opal_active_queue_elements; + static struct mcheck_recoverable_range *mc_recoverable_range; static int mc_recoverable_range_len; struct device_node *opal_node; static DEFINE_SPINLOCK(opal_write_lock); +static DEFINE_SPINLOCK(opal_msg_lock); static struct atomic_notifier_head opal_msg_notifier_head[OPAL_MSG_TYPE_MAX]; static uint32_t opal_heartbeat; static struct task_struct *kopald_tsk; @@ -238,14 +252,47 @@ machine_early_initcall(powernv, opal_register_exception_handlers); int opal_message_notifier_register(enum opal_msg_type msg_type, struct notifier_block *nb) { + struct OpalMsgNode *msg_node, *tmp; + int ret; + unsigned long flags; + + spin_lock_irqsave(&opal_msg_lock, flags); + + opal_msg_notify_reg_mask |= 1 << msg_type; + + spin_unlock_irqrestore(&opal_msg_lock, flags); + 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; + + spin_lock_irqsave(&opal_msg_lock, flags); + list_for_each_entry_safe(msg_node, + tmp, + &opal_msg_queue_pending, + opal_queue_list_node) { + if (msg_node->queue_msg_type == msg_type) { + atomic_notifier_call_chain( + &opal_msg_notifier_head[msg_type], + msg_type, + &msg_node->msg); + list_del(&msg_node->opal_queue_list_node); + kfree(msg_node); + opal_active_queue_elements--; + } + } + spin_unlock_irqrestore(&opal_msg_lock, flags); + + return ret; + } EXPORT_SYMBOL_GPL(opal_message_notifier_register); @@ -259,9 +306,40 @@ 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); + struct OpalMsgNode *msg_node; + + unsigned long flags; + + spin_lock_irqsave(&opal_msg_lock, flags); + + if (opal_msg_notify_reg_mask & (1 << msg_type)) { + /* notify subscribers */ + atomic_notifier_call_chain(&opal_msg_notifier_head[msg_type], + msg_type, msg); + } else { + if (opal_active_queue_elements < OPAL_MSG_QUEUE_MAX) { + msg_node = kzalloc(sizeof(*msg_node), GFP_ATOMIC); + if (msg_node) { + INIT_LIST_HEAD(&msg_node->opal_queue_list_node); + memcpy(&msg_node->msg, + msg, + sizeof(struct opal_msg)); + msg_node->queue_msg_type = msg_type; + list_add_tail(&msg_node->opal_queue_list_node, + &opal_msg_queue_pending); + opal_active_queue_elements++; + } + } + + if (opal_active_queue_elements >= OPAL_MSG_QUEUE_MAX) { + pr_warn_once("%s: Notifier Register Queue full at %i\n", + __func__, + opal_active_queue_elements); + } + } + + spin_unlock_irqrestore(&opal_msg_lock, flags); + } static void opal_handle_message(void)