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: 121688 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4785696qgn; Tue, 12 Dec 2017 16:00:36 -0800 (PST) X-Google-Smtp-Source: ACJfBougybTxJDD0LmeVMxC+M1CptJov1KD9psj5WU506AoExNzKSXfrqDVA4YXEOQ235eyY54J6 X-Received: by 10.84.234.135 with SMTP id n7mr3785686plk.298.1513123236497; Tue, 12 Dec 2017 16:00:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513123236; cv=none; d=google.com; s=arc-20160816; b=HB1ScNaRGp3n6lpszQQyNlYvNeTy/b9uHj0Hl2EEDzdMkQGnpVoyaYKnYLjPhXhd7x vLH8CwouKaIvUwdLglAhoOLtzCDtX3Zpw1sReJwuS6Oke+YBStYQjcSjUmUDZgVLHBjc 9mKIUGPE27MhM8XQXiSJPicvxGH46qgl4Vq1ee1ExiqsgTrFHzsJXsCva1lbzJt2Jn/c 2ATbaduTVrWm/vZ6rKyY46w5Qm1e6RRXQUFwYS+ZLu/E0+Ll2Jm2D2ta5PYZS66c3Wh7 rl5t/UsLr3gDX0Tnm43pnApMftl+xTJRVFz1V7bpWLe3zDC5UJ9vHnDZi87bnqSzpdB8 qkHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=YXR+Zj6Z1qfQPkK/HMLffsyX/njqlb19NyAECCzfFcs=; b=l4zgHDbfZ4w3nYm0BoAHliu0wVLkL3BkvAa6paO0GqfXFMSnu6yAONeWz97yL4pZ6y HU2biq/0rd8BPCuA+vrxFTzpgoDplefwuckUGulILPRV9d0/obdfSDsLvRBwjft1lp8j K9xYKinx0SCVg1RlfVIE7bJsiguZufGts65PTLSy5oE68wwqmptlw5jrY1L658wT++3B giR2NbAKJ6NqdMxeYtthMFhBSjlqh3GY0ndY7jShvOquZbQEg/y3V4bCcCGHBOovVhGW aQPVExOO9b49gEcdO1LCeax5xymmN5FzdEnWXEA8kK0qXrvL7N7Lflz8n8cjA0VWAJh5 P4XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fxhuJf+C; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ba12si247680plb.784.2017.12.12.16.00.36; Tue, 12 Dec 2017 16:00:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fxhuJf+C; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752875AbdLMAAf (ORCPT + 10 others); Tue, 12 Dec 2017 19:00:35 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:43633 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752822AbdLLX7C (ORCPT ); Tue, 12 Dec 2017 18:59:02 -0500 Received: by mail-pf0-f196.google.com with SMTP id e3so482559pfi.10 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=elLxMTz01sGEVclPLtAbeZUcN1hNklK+pYfnObJx9W9HpAW/kMoAU5KWKrZOpKypC/ tozeH5mSD8TE+AqYXJBh7qRvPbRxCAmvrzUyuBAO4WSxIIVSs95gi2jdbA+CpZYozDlG tf1b3XfW1Be8YPIi5U1h1iVi9cmPPaX3Sh+xvv1aWskxxmlCm6emnes40YwH8jQymM9p 3iPxP5u1p39TNXnx1NTP94Rm24NRfmTJw+aNejR/SQ4BQFuSIu3xJKqJz527QNKGtlf0 G6mK22CbsC7P2PrvLxHtTfivxvlbCFqqDtTilC/iPsVHMuVndff+X8lWjfbhhiK4lRFV KHFg== X-Gm-Message-State: AKGB3mLHTdZY0eW7LpN/EMpMZOp3zjGa4QGewD0K5gCa6sHK+o5NizTy P5dRonDfvSTYViEmMtpJQQrXQernY9Y= 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-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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(+) -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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)) {