From patchwork Tue Dec 12 23:58:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 10108479 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CD540602B3 for ; Wed, 13 Dec 2017 00:01:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF2A228904 for ; Wed, 13 Dec 2017 00:01:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3BB228B1A; Wed, 13 Dec 2017 00:01:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56F4528904 for ; Wed, 13 Dec 2017 00:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753127AbdLMAAh (ORCPT ); Tue, 12 Dec 2017 19:00:37 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:42470 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752819AbdLLX7C (ORCPT ); Tue, 12 Dec 2017 18:59:02 -0500 Received: by mail-pf0-f194.google.com with SMTP id d23so484099pfe.9 for ; Tue, 12 Dec 2017 15:59:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Hu6BsG1JTKNbTp7QNPwW5B/ymudxfxLU+z44D53QaMI=; b=fxhuJf+C9nPyMzJiU8YLwlnmX5HEA8xy7f/GqeIVQVqJT10pYSKzmrQbu5KOc+gne/ HVLhmfO9C2eY+pHk4A4lBZQZPzW+gOauKE4whHIBh1z6knW+OturQkqMLDSjbC8Bd9Ql jLYu7HVUk6l2+kUEYuyDLU7PnC8CDqPYYepPA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Hu6BsG1JTKNbTp7QNPwW5B/ymudxfxLU+z44D53QaMI=; b=gy/8T95xRatgBWhViLCHlpSx/UHUG3rOw4CZcW1PirK0TdYSAtj5hp9r6B2b6eiTj0 32oo+rr3+r0Ab8e35A4U52PxVKVuzvcnx60w1TPg8jpt8SbHwN4Negu3nlHkegPeM2tl uWhr68X+a0Ekv2JtBMz/8ElO71rBO+ggReFlXmL2B0Df7ry/ayueNqlK8zv00jP8Eshc 2+p11/nznEjsajd5dTN7fqrq53EONKBwf8UfT9dWCsn/KURFb68iuzsLu9i5WW/4hdv3 QCC07+PEUIigpkFuubpoqw5/g+PvZM7BRjpWQA1beymsvEAj3Dcvz0WvFpokd1eX90Hd +ycQ== X-Gm-Message-State: AKGB3mJ7RItZcPhboFaR2TuPStQ2EZ8GYQvzIFM/7BIp9cFbjBi+6Miu ofmP0I/+O3UW6ylLXQpbfaxuxQ== X-Google-Smtp-Source: ACJfBovjdmV601bS4txAhJWCTtFxPPlzG5TpiOZrl4jtIhOTNbRHzlwTxrbak5dD1/+mMIIAS0/0Ng== X-Received: by 10.84.128.36 with SMTP id 33mr4027181pla.329.1513123141704; Tue, 12 Dec 2017 15:59:01 -0800 (PST) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id t202sm270317pgb.75.2017.12.12.15.59.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 15:59:01 -0800 (PST) From: Bjorn Andersson To: Ohad Ben-Cohen , Bjorn Andersson , Jeremy McNicoll , Will Newton Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Chris Lew Subject: [PATCH 1/5] rpmsg: smd: Perform handshake during open Date: Tue, 12 Dec 2017 15:58:53 -0800 Message-Id: <20171212235857.10432-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171212235857.10432-1-bjorn.andersson@linaro.org> References: <20171212235857.10432-1-bjorn.andersson@linaro.org> Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Validate the the remote side is opening the channel that we've found by performing a handshake when opening the channel. Signed-off-by: Bjorn Andersson --- drivers/rpmsg/qcom_smd.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c index b01774e9fac0..58dd44493420 100644 --- a/drivers/rpmsg/qcom_smd.c +++ b/drivers/rpmsg/qcom_smd.c @@ -200,6 +200,7 @@ struct qcom_smd_channel { char *name; enum smd_channel_state state; enum smd_channel_state remote_state; + wait_queue_head_t state_change_event; struct smd_channel_info_pair *info; struct smd_channel_info_word_pair *info_word; @@ -570,6 +571,8 @@ static bool qcom_smd_channel_intr(struct qcom_smd_channel *channel) if (remote_state != channel->remote_state) { channel->remote_state = remote_state; need_state_scan = true; + + wake_up_interruptible_all(&channel->state_change_event); } /* Indicate that we have seen any state change */ SET_RX_CHANNEL_FLAG(channel, fSTATE, 0); @@ -786,7 +789,9 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data, static int qcom_smd_channel_open(struct qcom_smd_channel *channel, rpmsg_rx_cb_t cb) { + struct qcom_smd_edge *edge = channel->edge; size_t bb_size; + int ret; /* * Packets are maximum 4k, but reduce if the fifo is smaller @@ -798,9 +803,33 @@ static int qcom_smd_channel_open(struct qcom_smd_channel *channel, qcom_smd_channel_set_callback(channel, cb); qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENING); + + /* Wait for remote to enter opening or opened */ + ret = wait_event_interruptible_timeout(channel->state_change_event, + channel->remote_state == SMD_CHANNEL_OPENING || + channel->remote_state == SMD_CHANNEL_OPENED, + HZ); + if (!ret) { + dev_err(&edge->dev, "remote side did not enter opening state\n"); + goto out_close_timeout; + } + qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENED); + /* Wait for remote to enter opened */ + ret = wait_event_interruptible_timeout(channel->state_change_event, + channel->remote_state == SMD_CHANNEL_OPENED, + HZ); + if (!ret) { + dev_err(&edge->dev, "remote side did not enter open state\n"); + goto out_close_timeout; + } + return 0; + +out_close_timeout: + qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED); + return -ETIMEDOUT; } /* @@ -1055,6 +1084,7 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed mutex_init(&channel->tx_lock); spin_lock_init(&channel->recv_lock); init_waitqueue_head(&channel->fblockread_event); + init_waitqueue_head(&channel->state_change_event); info = qcom_smem_get(edge->remote_pid, smem_info_item, &info_size); if (IS_ERR(info)) {