From patchwork Tue Jul 25 05:56:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 108614 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp178946qge; Mon, 24 Jul 2017 22:56:59 -0700 (PDT) X-Received: by 10.99.122.20 with SMTP id v20mr18495721pgc.342.1500962219683; Mon, 24 Jul 2017 22:56:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500962219; cv=none; d=google.com; s=arc-20160816; b=GC1GEjKgepClJ19yleHisjVXOPzFo7x6XbxFERUllJXcQprMMUC0IQd6qr/OFBLYnp igXxU0yJxz0+AZGYoqu3kbVcsrSj8xQkLfxZjKYMbGTuFHNANiF8MijuqPLHCvmMzsMw cSnJqfSa0md7ihNPdz1X3KEqNvFHS4p5sNTfgLoU/YXLub3Af4gcC0mlKr7jJM1DfC7k kQp2DBHMfupzKOGUlhmlaTxlZp2k7Uatsxir58F6cq/yJgiKcXAbv8d1O8jpHv657Yk1 93lIhuUdMC/5EVzSTdJr6hctcMhtHdKZeTC7C5jPufwszAV0ZclBx8DwctC7X4T+WLcm xd3Q== 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=qli5HVu2XBzZK0yYeRv4XUzl1/c6FqSBRrL0Z+0zfKA=; b=HdRiFk309Niu05xlefvpsDQI56TredicFun+0je1dXFVIa2qFu5YfhshCOt0us4KA2 U0N2zaYgCCxlfgpdI+Ea/73M+ms1+WKLfHKXhIK/i73dSqM6KUVUzRkVI2Ts1HpwFggq CEj2SXFTM8qXXcPvsvOztmLcMz1RYwWSkLAg0X6xmCoEYayFCS2ouLgl9t/hJmGN9U9f EAW6xeKOCn2C2b4Pggo89UrhOIdOSHD4wNBNwf/0BFyBEMO15ich2JxVOXVJHeReh9pC 7D6a56UcawiNKIQ1oKxnzzj37xGkHIGhYJgJxg+MUlpl426JesdGKCABn2ao9ShFkB3k fzlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=NLmyPhFz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 t69si7837429pgd.95.2017.07.24.22.56.59; Mon, 24 Jul 2017 22:56:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=NLmyPhFz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750968AbdGYF45 (ORCPT + 26 others); Tue, 25 Jul 2017 01:56:57 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:36536 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750880AbdGYF4v (ORCPT ); Tue, 25 Jul 2017 01:56:51 -0400 Received: by mail-pg0-f43.google.com with SMTP id 125so66294834pgi.3 for ; Mon, 24 Jul 2017 22:56:51 -0700 (PDT) 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=qli5HVu2XBzZK0yYeRv4XUzl1/c6FqSBRrL0Z+0zfKA=; b=NLmyPhFzvX/d4up6jQzWKauhvFFF4NfaYXTY5r3DKij/yImDiLtIC5n8qq4zqC09ff 6iNnhRdEFGV/bSmIec+EqWqeQihw+4ZYKNgBLhkazdyqTf4xXAJhIMfoRnXH9lwtp1HU 9W9+VVShGIGHAkCeXEAkQrkaVliU5qxp6tBi4= 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=qli5HVu2XBzZK0yYeRv4XUzl1/c6FqSBRrL0Z+0zfKA=; b=spfNgGWZcjVNczG808Cq4B8o53/5f1O42pZuWuPTJdW/wn5D3lvv8Pats2WnHfR03o X+gon/YFwXFkN83LZLHrWiWTs3ilFtKBdsyMeKK7/hNwXa+wKgeYE0X0AKKZt0xVLfb/ ia70AaA5rEhFNK2yIycRfsCx0O5LbrHcbT/Tqcf05XTDcHQDkyK8km30mIXC1eAqcsMZ KvF74kE1EAXf3U9dXtbqfm/PTMR3GxH6MYces55iCIobiVnxK0aRXHH4MRsHIxt+ytGo N/8OmFJUUfMZ/vtoL4QPQjtvaFs92PdHvvCFIbnAg5lLWVZ9GZfSsivsqVjzJdTr06VI rCCg== X-Gm-Message-State: AIVw112sPRgAMfhNT80K7tj5w/Jxmml5RBrLDh6svg5ta/vtUP3J92yE WuS4ARb6TfKqACgO X-Received: by 10.84.137.129 with SMTP id 1mr20260715pln.251.1500962210942; Mon, 24 Jul 2017 22:56:50 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id a6sm25323438pfj.136.2017.07.24.22.56.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Jul 2017 22:56:50 -0700 (PDT) From: Bjorn Andersson To: Andy Gross , David Brown , Bjorn Andersson Cc: Ohad Ben-Cohen , linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org Subject: [PATCH 2/2] soc: qcom: GLINK SSR notifier Date: Mon, 24 Jul 2017 22:56:44 -0700 Message-Id: <20170725055644.20947-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170725055644.20947-1-bjorn.andersson@linaro.org> References: <20170725055644.20947-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This driver register as a subsystem restart notifier and will send out notifications to remote processors that has opened the "glink_ssr" GLINK channel. This mechanism is used to signal any GLINK participants that a 3rd party is gone and that the communication state has to be reset; i.e. that read and write pointers of the GLINK FIFOs are stale. Signed-off-by: Bjorn Andersson --- drivers/soc/qcom/Kconfig | 9 +++ drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/glink_ssr.c | 164 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+) create mode 100644 drivers/soc/qcom/glink_ssr.c -- 2.12.0 diff --git a/drivers/soc/qcom/Kconfig b/drivers/soc/qcom/Kconfig index 9fca977ef18d..d0fc331972d2 100644 --- a/drivers/soc/qcom/Kconfig +++ b/drivers/soc/qcom/Kconfig @@ -1,6 +1,15 @@ # # QCOM Soc drivers # +config QCOM_GLINK_SSR + tristate "Qualcomm Glink SSR driver" + depends on RPMSG + depends on QCOM_RPROC_COMMON + help + Say y here to enable GLINK SSR support. The GLINK SSR driver + implements the SSR protocol for notifying the remote processor about + neighboring subsystems going up or down. + config QCOM_GSBI tristate "QCOM General Serial Bus Interface" depends on ARCH_QCOM diff --git a/drivers/soc/qcom/Makefile b/drivers/soc/qcom/Makefile index 414f0de274fa..f151de41eb93 100644 --- a/drivers/soc/qcom/Makefile +++ b/drivers/soc/qcom/Makefile @@ -1,3 +1,4 @@ +obj-$(CONFIG_QCOM_GLINK_SSR) += glink_ssr.o obj-$(CONFIG_QCOM_GSBI) += qcom_gsbi.o obj-$(CONFIG_QCOM_MDT_LOADER) += mdt_loader.o obj-$(CONFIG_QCOM_PM) += spm.o diff --git a/drivers/soc/qcom/glink_ssr.c b/drivers/soc/qcom/glink_ssr.c new file mode 100644 index 000000000000..19c7399eddb5 --- /dev/null +++ b/drivers/soc/qcom/glink_ssr.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2017, Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +/** + * struct do_cleanup_msg - The data structure for an SSR do_cleanup message + * version: The G-Link SSR protocol version + * command: The G-Link SSR command - do_cleanup + * seq_num: Sequence number + * name_len: Length of the name of the subsystem being restarted + * name: G-Link edge name of the subsystem being restarted + */ +struct do_cleanup_msg { + __le32 version; + __le32 command; + __le32 seq_num; + __le32 name_len; + char name[32]; +}; + +/** + * struct cleanup_done_msg - The data structure for an SSR cleanup_done message + * version: The G-Link SSR protocol version + * response: The G-Link SSR response to a do_cleanup command, cleanup_done + * seq_num: Sequence number + */ +struct cleanup_done_msg { + __le32 version; + __le32 response; + __le32 seq_num; +}; + +/** + * G-Link SSR protocol commands + */ +#define GLINK_SSR_DO_CLEANUP 0 +#define GLINK_SSR_CLEANUP_DONE 1 + +struct glink_ssr { + struct device *dev; + struct rpmsg_endpoint *ept; + + struct notifier_block nb; + + u32 seq_num; + struct completion completion; +}; + +static int qcom_glink_ssr_callback(struct rpmsg_device *rpdev, + void *data, int len, void *priv, u32 addr) +{ + struct cleanup_done_msg *msg = data; + struct glink_ssr *ssr = dev_get_drvdata(&rpdev->dev); + + if (len < sizeof(*msg)) { + dev_err(ssr->dev, "message too short\n"); + return -EINVAL; + } + + if (le32_to_cpu(msg->version) != 0) + return -EINVAL; + + if (le32_to_cpu(msg->response) != GLINK_SSR_CLEANUP_DONE) + return 0; + + if (le32_to_cpu(msg->seq_num) != ssr->seq_num) { + dev_err(ssr->dev, "invalid sequence number of response\n"); + return -EINVAL; + } + + complete(&ssr->completion); + + return 0; +} + +static int qcom_glink_ssr_notify(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct glink_ssr *ssr = container_of(nb, struct glink_ssr, nb); + struct do_cleanup_msg msg; + char *ssr_name = data; + int ret; + + ssr->seq_num++; + reinit_completion(&ssr->completion); + + memset(&msg, 0, sizeof(msg)); + msg.command = cpu_to_le32(GLINK_SSR_DO_CLEANUP); + msg.seq_num = cpu_to_le32(ssr->seq_num); + msg.name_len = cpu_to_le32(strlen(ssr_name)); + strlcpy(msg.name, ssr_name, sizeof(msg.name)); + + ret = rpmsg_send(ssr->ept, &msg, sizeof(msg)); + if (ret < 0) + dev_err(ssr->dev, "failed to send cleanup message\n"); + + ret = wait_for_completion_timeout(&ssr->completion, HZ); + if (!ret) + dev_err(ssr->dev, "timeout waiting for cleanup done message\n"); + + return NOTIFY_DONE; +} + +static int qcom_glink_ssr_probe(struct rpmsg_device *rpdev) +{ + struct glink_ssr *ssr; + + ssr = devm_kzalloc(&rpdev->dev, sizeof(*ssr), GFP_KERNEL); + if (!ssr) + return -ENOMEM; + + init_completion(&ssr->completion); + + ssr->dev = &rpdev->dev; + ssr->ept = rpdev->ept; + ssr->nb.notifier_call = qcom_glink_ssr_notify; + + dev_set_drvdata(&rpdev->dev, ssr); + + return qcom_register_ssr_notifier(&ssr->nb); +} + +static void qcom_glink_ssr_remove(struct rpmsg_device *rpdev) +{ + struct glink_ssr *ssr = dev_get_drvdata(&rpdev->dev); + + qcom_unregister_ssr_notifier(&ssr->nb); +} + +static const struct rpmsg_device_id qcom_glink_ssr_match[] = { + { "glink_ssr" }, + {} +}; + +static struct rpmsg_driver qcom_glink_ssr_driver = { + .probe = qcom_glink_ssr_probe, + .remove = qcom_glink_ssr_remove, + .callback = qcom_glink_ssr_callback, + .id_table = qcom_glink_ssr_match, + .drv = { + .name = "qcom_glink_ssr", + }, +}; +module_rpmsg_driver(qcom_glink_ssr_driver); + +MODULE_ALIAS("rpmsg:glink_ssr"); +MODULE_DESCRIPTION("Qualcomm GLINK SSR notifier"); +MODULE_LICENSE("GPL v2");