Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2483025pxa; Mon, 24 Aug 2020 15:51:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwftwFVTnmLN/FY7p3/Il4mAVfwXt26NVoXUnGM8459FIBr/WhGIFKd4iWd1NoKPhQlwLfV X-Received: by 2002:a17:907:426e:: with SMTP id nx22mr3073684ejb.340.1598309502467; Mon, 24 Aug 2020 15:51:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598309502; cv=none; d=google.com; s=arc-20160816; b=JapD5wFxYg5Kb104Apgc87GR1nHOZwC97WFIh0QO5rhiVwFabzIL7zEwo7KEF7Uhbz zxDdnIVSVl0ehToRPyMhizhKP8QYp5XZ6Jckz0ZNFlsjmHmPaFX1W1Gdg8zY1l45gBFX KkiMTuFO1qT5mtTAoMtZ0sZ4iRvAdy64EgOGLN2UUT3Jkou1aQihvlCcvu3btsq30Lga oI0xtFE4Gf/D5KxEY9jE9tKNW41nlg4WuZXTkENMba09xEYq0ZjTVNRqlTmnKtlgU4O7 WbhLWYglWum5w0RqMT6fne05f4OkRa3Plei3qOGy0+UnDIh4KiNW+zUo8QdHKDS2s/k/ 5lMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Jsz3EcPSYk1NTYtfG4XIBQNhz0VHZo3gfk38PJMQ9JQ=; b=Bw5C0GIGexC8PIqSH6XyQqO9KTBAtmNoZmU7TNkEZuMUBAkKX1R0giWo0AfJYpYsRz vSfkmb11IwZLue/Zs+R7VzqStJtO+/N6fHfRM0///Vc6JqfyHQwPVS2heBjX4kptAd0z grRxIZnEpgqiPJCE/sKDWVtcG5ryET87fpBl73xrwXhQLezTja5Yaq2DijdfNXBjfFb3 YJ9jI0B45bbXarPHfyyeJ9pAPZ38AZoO28yx+frsjWzEIR2uOET2vXCxJQ70DbHZc2+H JzXNT2UPWOQfHxcknJ4SDbUCOEcFpWe0Amkrc/vTzFrIwdhYm0C3zFA7p6+35JAwRJXu bBwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sk9CVTXi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id e20si4117267ejq.136.2020.08.24.15.51.18; Mon, 24 Aug 2020 15:51:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sk9CVTXi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728109AbgHXWrm (ORCPT + 99 others); Mon, 24 Aug 2020 18:47:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726531AbgHXWrj (ORCPT ); Mon, 24 Aug 2020 18:47:39 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D942C061574 for ; Mon, 24 Aug 2020 15:47:39 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id o13so5411029pgf.0 for ; Mon, 24 Aug 2020 15:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Jsz3EcPSYk1NTYtfG4XIBQNhz0VHZo3gfk38PJMQ9JQ=; b=sk9CVTXi7u2zLFcmorqKkpdWB2zVcKDBAJmn9eHKjBvKl17Ohwl13YoEt9cim+BDNB QsTa+Pd+8NKMUO5lfUyVpHaOhARg2lE/3fhrJYj+x7pYARYPsiwbStL0BuaqMdcz1ERR 6TswnxzltWhyedJyjWQY/V3OReQqHvVT/Mn2R25h1l0rX+woJ4W7Of6QKC31vbWgwn00 LcRgDRMkwLAs+OBY83pwZE8VlTNsMMCFpW1Ji+4HO0IlcmpQNP1aUzoEglefpkoRXlEf ZvEwfFta4mXFyfE+MJdeJGplpf8LXLRZwVzb2aRujCfsVR5MzuGhRGhnAl7ITHHVeYK8 SOZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Jsz3EcPSYk1NTYtfG4XIBQNhz0VHZo3gfk38PJMQ9JQ=; b=e7QWvRTuiFmD4snxnhh4twulC0GYTiY4TnYvQ5s1mCM8+fXRzXeTOkb1nJAGR37zhf 0LWC0rIJrncpovMtpgCNBLDsZgIOT0vKXIyUp+L+hNhbqrR7RmvbEN1M15lZzkXf9OU9 qJOhQMdSdIKU9n3+4sdFpeEHKL0Kznkz7v6dSpOuSUUAox+dtjmWKWZw/kUiOMTifmfH u0IMGDzcAgTriJxY72pIn6lwAaWSgYi/PU1pxRDrQy4qDaJ2DKmYZqUJYdfVOaFmKiZ0 tI3QIMZKEWs2skFze7cyG25ptg3BpSvcZR8F/ffoLV9CzvM6Qz7uWrapVjMBxp/X1PFQ SUvw== X-Gm-Message-State: AOAM533hpyUQmfUcvUSWSOvmothWIlXbpHcumxGOpZ46LDiHQNHCw9yo mNnarSnathzxC3Fmk5l1cUv1BQ== X-Received: by 2002:a17:902:d903:: with SMTP id c3mr5503708plz.145.1598309258711; Mon, 24 Aug 2020 15:47:38 -0700 (PDT) Received: from xps15 (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id s68sm12117973pfb.91.2020.08.24.15.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2020 15:47:38 -0700 (PDT) Date: Mon, 24 Aug 2020 16:47:36 -0600 From: Mathieu Poirier To: Arnaud Pouliquen Cc: Bjorn Andersson , Ohad Ben-Cohen , linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: Re: [PATCH 5/9] rpmsg: introduce reserved rpmsg driver for ns announcement Message-ID: <20200824224736.GD3938186@xps15> References: <20200731114732.12815-1-arnaud.pouliquen@st.com> <20200731114732.12815-6-arnaud.pouliquen@st.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200731114732.12815-6-arnaud.pouliquen@st.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 31, 2020 at 01:47:28PM +0200, Arnaud Pouliquen wrote: > The name service announcement should not be linked to the RPMsg virtio bus > but to the RPMsg protocol itself. > > This patch proposes to break the dependency with the RPmsg virtio bus by > the introduction of the reserved RPMsg name service driver which will be in > charge of managing the RPMsg name service announcement. > > This first patch only implements the probe and the RPMsg endpoint to > manage create and release channels remote requests. > > Signed-off-by: Arnaud Pouliquen > --- > drivers/rpmsg/Kconfig | 8 ++ > drivers/rpmsg/Makefile | 1 + > drivers/rpmsg/rpmsg_internal.h | 17 +++++ > drivers/rpmsg/rpmsg_ns.c | 135 +++++++++++++++++++++++++++++++++ > 4 files changed, 161 insertions(+) > create mode 100644 drivers/rpmsg/rpmsg_ns.c > > diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig > index f96716893c2a..140faa975ea1 100644 > --- a/drivers/rpmsg/Kconfig > +++ b/drivers/rpmsg/Kconfig > @@ -15,6 +15,14 @@ config RPMSG_CHAR > in /dev. They make it possible for user-space programs to send and > receive rpmsg packets. > > +config RPMSG_NS > + tristate "RPMSG name service announcement" > + depends on RPMSG > + help > + Say Y here to enable the support of the name service announcement > + channel that probes the associate RPMsg device on remote endpoint s/associate/associated > + service announcement. > + > config RPMSG_MTK_SCP > tristate "MediaTek SCP" > depends on MTK_SCP > diff --git a/drivers/rpmsg/Makefile b/drivers/rpmsg/Makefile > index ffe932ef6050..8d452656f0ee 100644 > --- a/drivers/rpmsg/Makefile > +++ b/drivers/rpmsg/Makefile > @@ -1,6 +1,7 @@ > # SPDX-License-Identifier: GPL-2.0 > obj-$(CONFIG_RPMSG) += rpmsg_core.o > obj-$(CONFIG_RPMSG_CHAR) += rpmsg_char.o > +obj-$(CONFIG_RPMSG_NS) += rpmsg_ns.o > obj-$(CONFIG_RPMSG_MTK_SCP) += mtk_rpmsg.o > qcom_glink-objs := qcom_glink_native.o qcom_glink_ssr.o > obj-$(CONFIG_RPMSG_QCOM_GLINK) += qcom_glink.o > diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h > index d5ab286d0e5e..641b48f6bf2a 100644 > --- a/drivers/rpmsg/rpmsg_internal.h > +++ b/drivers/rpmsg/rpmsg_internal.h > @@ -102,4 +102,21 @@ static inline int rpmsg_chrdev_register_device(struct rpmsg_device *rpdev) > return rpmsg_register_device(rpdev); > } > > +/** > + * rpmsg_ns_register_device() - register name service device based on rpdev > + * @rpdev: prepared rpdev to be used for creating endpoints > + * > + * This function wraps rpmsg_register_device() preparing the rpdev for use as > + * basis for the rpmsg name service device. > + */ > +static inline int rpmsg_ns_register_device(struct rpmsg_device *rpdev) > +{ > + strcpy(rpdev->id.name, "rpmsg_ns"); > + rpdev->driver_override = "rpmsg_ns"; > + rpdev->src = RPMSG_NS_ADDR; > + rpdev->dst = RPMSG_NS_ADDR; > + > + return rpmsg_register_device(rpdev); > +} > + > #endif > diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c > new file mode 100644 > index 000000000000..fe7713e737c2 > --- /dev/null > +++ b/drivers/rpmsg/rpmsg_ns.c > @@ -0,0 +1,135 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) STMicroelectronics 2020 - All Rights Reserved > + */ > +#include > +#include > +#include > +#include > +#include "rpmsg_internal.h" > + > +/** > + * enum rpmsg_ns_flags - dynamic name service announcement flags > + * > + * @RPMSG_NS_CREATE: a new remote service was just created > + * @RPMSG_NS_DESTROY: a known remote service was just destroyed > + */ > +enum rpmsg_ns_flags { > + RPMSG_NS_CREATE = 0, > + RPMSG_NS_DESTROY = 1, > +}; > + > +/** > + * struct rpmsg_ns_msg - dynamic name service announcement message > + * @name: name of remote service that is published > + * @addr: address of remote service that is published > + * @flags: indicates whether service is created or destroyed > + * > + * This message is sent across to publish a new service, or announce > + * about its removal. When we receive these messages, an appropriate > + * rpmsg channel (i.e device) is created/destroyed. In turn, the ->probe() > + * or ->remove() handler of the appropriate rpmsg driver will be invoked > + * (if/as-soon-as one is registered). > + */ > +struct rpmsg_ns_msg { > + char name[RPMSG_NAME_SIZE]; > + u32 addr; > + u32 flags; > +} __packed; > + > +/* invoked when a name service announcement arrives */ > +static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, > + void *priv, u32 src) > +{ > + struct rpmsg_ns_msg *msg = data; > + struct rpmsg_device *newch; > + struct rpmsg_channel_info chinfo; > + struct device *dev = &rpdev->dev; > + int ret; > + > +#if defined(CONFIG_DYNAMIC_DEBUG) > + dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1, > + data, len, true); > +#endif > + > + if (len != sizeof(*msg)) { > + dev_err(dev, "malformed ns msg (%d)\n", len); > + return -EINVAL; > + } > + > + /* don't trust the remote processor for null terminating the name */ > + msg->name[RPMSG_NAME_SIZE - 1] = '\0'; > + > + strncpy(chinfo.name, msg->name, sizeof(chinfo.name)); > + chinfo.src = RPMSG_ADDR_ANY; > + chinfo.dst = msg->addr; > + > + dev_info(dev, "%sing channel %s addr 0x%x\n", > + msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat", > + msg->name, msg->addr); > + > + if (msg->flags & RPMSG_NS_DESTROY) { > + ret = rpmsg_release_channel(rpdev, &chinfo); > + if (ret) > + dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret); > + } else { > + newch = rpmsg_create_channel(rpdev, &chinfo); > + if (!newch) > + dev_err(dev, "rpmsg_create_channel failed\n"); > + } > + > + return 0; > +} > + > +static int rpmsg_ns_probe(struct rpmsg_device *rpdev) > +{ > + struct rpmsg_channel_info ns_chinfo; > + struct rpmsg_endpoint *ns_ept; > + > + ns_chinfo.src = RPMSG_NS_ADDR; > + ns_chinfo.dst = RPMSG_NS_ADDR; > + strcpy(ns_chinfo.name, "name_service"); > + > + /* > + * create and attach the endpoint to the rpmsg device that it would be > + * destroy when the rpmsg device will be deleted > + */ This comment doesn't work, please revise. > + ns_ept = rpmsg_create_ept(rpdev, rpmsg_ns_cb, NULL, ns_chinfo); > + if (!ns_ept) { > + dev_err(&rpdev->dev, "failed to create the ns ept\n"); > + return -ENOMEM; > + } > + rpdev->ept = ns_ept; > + > + rpdev->src = RPMSG_NS_ADDR; I think this is already done in rpmsg_ns_register_device(). > + > + return 0; > +} > + > +static struct rpmsg_driver rpmsg_ns_driver = { > + .drv.name = "rpmsg_ns", > + .probe = rpmsg_ns_probe, > +}; > + > +static int rpmsg_ns_init(void) > +{ > + int ret; > + > + ret = register_rpmsg_driver(&rpmsg_ns_driver); > + if (ret < 0) > + pr_err("%s: Failed to register rpmsg driver\n", __func__); > + > + return ret; > +} > +postcore_initcall(rpmsg_ns_init); > + > +static void rpmsg_ns_exit(void) > +{ > + unregister_rpmsg_driver(&rpmsg_ns_driver); > +} > +module_exit(rpmsg_ns_exit); > + > +MODULE_DESCRIPTION("Name service announcement rpmsg Driver"); > +MODULE_AUTHOR("Arnaud Pouliquen "); > +MODULE_ALIAS("rpmsg_ns"); > +MODULE_LICENSE("GPL v2"); > -- > 2.17.1 >