From patchwork Fri May 20 08:29:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7BE3C433EF for ; Fri, 20 May 2022 08:31:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239017AbiETIbN (ORCPT ); Fri, 20 May 2022 04:31:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347105AbiETIap (ORCPT ); Fri, 20 May 2022 04:30:45 -0400 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBAC7140845; Fri, 20 May 2022 01:30:17 -0700 (PDT) Received: from pps.filterd (m0288072.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K7BpO1004845; Fri, 20 May 2022 10:29:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=2oUCJKuYX/NY/iBtWA66txdrB/9BfeAv1MvQ2qwk1ys=; b=c2+WEpseMSKCE9cXbU455BUQcyQfLs4tVxR8ZCuMZ0BRq5uMGqhBKCV3n6M5Ol6CFe7l JmZaYN7m4aB5xuz5RI4ol4j9SuXOcI52pDrCD/2a4EeesFrrWJzKZ9SPKl8hSoKZYo7P BPTi9Tfbx6RZfGUIY3h32P1lhcKN23Xf3YPpTsLBCUaqQiAD+NnzOqBAskKV/dRVUzdb vPtqSVWJ9EXSBqBv6sx08B1pnr0qax9wEzPcg5QIH/WwqrvzTGi/P5S+SgX6Wf805HJ3 f1zQmZ52iC98mSRM8A2s61+s2fISuWSDbkX+8q58vPKRR4JJqKSFdxTVlFwJoeoJnhRC 5Q== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g21umb988-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:29:59 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 789CA100034; Fri, 20 May 2022 10:29:56 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 6C049214D28; Fri, 20 May 2022 10:29:56 +0200 (CEST) Received: from localhost (10.75.127.46) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:29:55 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 01/10] rpmsg: core: Add signal API support Date: Fri, 20 May 2022 10:29:31 +0200 Message-ID: <20220520082940.2984914-2-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_02,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Deepak Kumar Singh Some transports like Glink support the state notifications between clients using signals similar to serial protocol signals. Local glink client drivers can send and receive signals to glink clients running on remote processors. Add APIs to support sending and receiving of signals by rpmsg clients. Signed-off-by: Deepak Kumar Singh --- drivers/rpmsg/rpmsg_core.c | 21 +++++++++++++++++++++ drivers/rpmsg/rpmsg_internal.h | 2 ++ include/linux/rpmsg.h | 15 +++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 79368a957d89..8de8aadd9b27 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -330,6 +330,24 @@ int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, } EXPORT_SYMBOL(rpmsg_trysend_offchannel); +/** + * rpmsg_set_flow_control() - sets/clears serial flow control signals + * @ept: the rpmsg endpoint + * @enable: enable or disable serial flow control + * + * Return: 0 on success and an appropriate error value on failure. + */ +int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable) +{ + if (WARN_ON(!ept)) + return -EINVAL; + if (!ept->ops->set_flow_control) + return -ENXIO; + + return ept->ops->set_flow_control(ept, enable); +} +EXPORT_SYMBOL(rpmsg_set_flow_control); + /** * rpmsg_get_mtu() - get maximum transmission buffer size for sending message. * @ept: the rpmsg endpoint @@ -538,6 +556,9 @@ static int rpmsg_dev_probe(struct device *dev) rpdev->ept = ept; rpdev->src = ept->addr; + + if (rpdrv->signals) + ept->sig_cb = rpdrv->signals; } err = rpdrv->probe(rpdev); diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index d4b23fd019a8..4ce58e68af30 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -55,6 +55,7 @@ struct rpmsg_device_ops { * @trysendto: see @rpmsg_trysendto(), optional * @trysend_offchannel: see @rpmsg_trysend_offchannel(), optional * @poll: see @rpmsg_poll(), optional + * @set_flow_control: see @rpmsg_set_flow_control(), optional * @get_mtu: see @rpmsg_get_mtu(), optional * * Indirection table for the operations that a rpmsg backend should implement. @@ -75,6 +76,7 @@ struct rpmsg_endpoint_ops { void *data, int len); __poll_t (*poll)(struct rpmsg_endpoint *ept, struct file *filp, poll_table *wait); + int (*set_flow_control)(struct rpmsg_endpoint *ept, bool enable); ssize_t (*get_mtu)(struct rpmsg_endpoint *ept); }; diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 02fa9116cd60..dbd0c591bb85 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -62,12 +62,14 @@ struct rpmsg_device { }; typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); +typedef int (*rpmsg_rx_sig_t)(struct rpmsg_device *, void *, u32); /** * struct rpmsg_endpoint - binds a local rpmsg address to its user * @rpdev: rpmsg channel device * @refcount: when this drops to zero, the ept is deallocated * @cb: rx callback handler + * @sig_cb: rx serial signal handler * @cb_lock: must be taken before accessing/changing @cb * @addr: local rpmsg address * @priv: private data for the driver's use @@ -90,6 +92,7 @@ struct rpmsg_endpoint { struct rpmsg_device *rpdev; struct kref refcount; rpmsg_rx_cb_t cb; + rpmsg_rx_sig_t sig_cb; struct mutex cb_lock; u32 addr; void *priv; @@ -104,6 +107,7 @@ struct rpmsg_endpoint { * @probe: invoked when a matching rpmsg channel (i.e. device) is found * @remove: invoked when the rpmsg channel is removed * @callback: invoked when an inbound message is received on the channel + * @signal: invoked to received remote flow control signaling. */ struct rpmsg_driver { struct device_driver drv; @@ -111,6 +115,7 @@ struct rpmsg_driver { int (*probe)(struct rpmsg_device *dev); void (*remove)(struct rpmsg_device *dev); int (*callback)(struct rpmsg_device *, void *, int, void *, u32); + int (*signals)(struct rpmsg_device *rpdev, void *priv, u32 state); }; static inline u16 rpmsg16_to_cpu(struct rpmsg_device *rpdev, __rpmsg16 val) @@ -188,6 +193,8 @@ __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp, ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept); +int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable); + #else static inline int rpmsg_register_device(struct rpmsg_device *rpdev) @@ -306,6 +313,14 @@ static inline ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept) return -ENXIO; } +static inline int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return -ENXIO; +} + #endif /* IS_ENABLED(CONFIG_RPMSG) */ /* use a macro to avoid include chaining to get THIS_MODULE */ From patchwork Fri May 20 08:29:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A91AC433EF for ; Fri, 20 May 2022 08:30:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347083AbiETIa4 (ORCPT ); Fri, 20 May 2022 04:30:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347156AbiETIao (ORCPT ); Fri, 20 May 2022 04:30:44 -0400 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FBF2140840; Fri, 20 May 2022 01:30:20 -0700 (PDT) Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K4a0tN005786; Fri, 20 May 2022 10:30:01 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=fIYcdPhrP+UAIOWW4991D3j8xdtottmzpGrRfJZWd1o=; b=sCDduPYQDYLoRBEwoS+Uup3p4ey+PAWnDkWEfXYCSd5PQcwQIlMmPUzB3q49N4wrGZAk 27QX0XcLO1WSDBtF7T4wMKwCm5fRIS2ku/8FmMocM4Qc83/Ze8yQfqxqIwNs4geMUlw1 OQwVadXI3afvi9HmPiMhd0wzPUMdD5QXLfmm9RU4Go2qtAc5SlVK3SwrLNqjq4rr7Yab PjZZ+XK+UR9DSsYUant3Ew5bZuJZHdIiBus2ytqEQVivrJKgvmXQ2hY1fNMPU49YRMBk 4Pmhw8bm2qsWaR7lMIq+fPe4rC8Aw0o63YSF5aACgfOrGzHCajfZuGeGFspInsuoG/71 LQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g21j9f79t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:30:01 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3D643100039; Fri, 20 May 2022 10:29:59 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 37397215127; Fri, 20 May 2022 10:29:59 +0200 (CEST) Received: from localhost (10.75.127.44) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:29:56 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 02/10] rpmsg: char: Add TIOCMGET/TIOCMSET ioctl support Date: Fri, 20 May 2022 10:29:32 +0200 Message-ID: <20220520082940.2984914-3-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_03,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Deepak Kumar Singh Add TICOMGET and TIOCMSET ioctl support for rpmsg char device nodes to get/set the low level transport signals. Signed-off-by: Chris Lew Signed-off-by: Deepak Kumar Singh Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_char.c | 56 +++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c index b6183d4f62a2..904e7c67b356 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -52,6 +53,8 @@ static DEFINE_IDA(rpmsg_minor_ida); * @readq: wait object for incoming queue * @default_ept: set to channel default endpoint if the default endpoint should be re-used * on device open to prevent endpoint address update. + * @rsigs: remote flow control state + * @sig_pending: inform that flow control information has been received from remote but not treated */ struct rpmsg_eptdev { struct device dev; @@ -68,6 +71,8 @@ struct rpmsg_eptdev { struct sk_buff_head queue; wait_queue_head_t readq; + u32 rsigs; + bool sig_pending; }; int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data) @@ -107,7 +112,18 @@ static int rpmsg_ept_cb(struct rpmsg_device *rpdev, void *buf, int len, skb_queue_tail(&eptdev->queue, skb); spin_unlock(&eptdev->queue_lock); - /* wake up any blocking processes, waiting for new data */ + wake_up_interruptible(&eptdev->readq); + + return 0; +} + +static int rpmsg_sigs_cb(struct rpmsg_device *rpdev, void *priv, u32 sigs) +{ + struct rpmsg_eptdev *eptdev = priv; + + eptdev->rsigs = sigs; + eptdev->sig_pending = true; + wake_up_interruptible(&eptdev->readq); return 0; @@ -140,6 +156,7 @@ static int rpmsg_eptdev_open(struct inode *inode, struct file *filp) return -EINVAL; } + ept->sig_cb = rpmsg_sigs_cb; eptdev->ept = ept; filp->private_data = eptdev; @@ -159,6 +176,7 @@ static int rpmsg_eptdev_release(struct inode *inode, struct file *filp) eptdev->ept = NULL; } mutex_unlock(&eptdev->ept_lock); + eptdev->sig_pending = false; /* Discard all SKBs */ skb_queue_purge(&eptdev->queue); @@ -272,6 +290,9 @@ static __poll_t rpmsg_eptdev_poll(struct file *filp, poll_table *wait) if (!skb_queue_empty(&eptdev->queue)) mask |= EPOLLIN | EPOLLRDNORM; + if (eptdev->sig_pending) + mask |= EPOLLPRI; + mask |= rpmsg_poll(eptdev->ept, filp, wait); return mask; @@ -281,15 +302,36 @@ static long rpmsg_eptdev_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) { struct rpmsg_eptdev *eptdev = fp->private_data; + bool set; + u32 val; + int ret; - if (cmd != RPMSG_DESTROY_EPT_IOCTL) - return -EINVAL; + switch (cmd) { + case TIOCMGET: + eptdev->sig_pending = false; + ret = put_user(eptdev->rsigs, (int __user *)arg); + break; + case TIOCMSET: + ret = get_user(val, (int __user *)arg); + if (ret) + break; + set = (val & TIOCM_DTR) ? true : false; + ret = rpmsg_set_flow_control(eptdev->ept, set); + break; + case RPMSG_DESTROY_EPT_IOCTL: + /* Don't allow to destroy a default endpoint. */ + if (eptdev->default_ept) { + ret = -EINVAL; + break; + } + ret = rpmsg_chrdev_eptdev_destroy(&eptdev->dev, NULL); + break; + default: + ret = -EINVAL; + } - /* Don't allow to destroy a default endpoint. */ - if (eptdev->default_ept) - return -EINVAL; - return rpmsg_chrdev_eptdev_destroy(&eptdev->dev, NULL); + return ret; } static const struct file_operations rpmsg_eptdev_fops = { From patchwork Fri May 20 08:29:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FDDAC433F5 for ; Fri, 20 May 2022 08:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234699AbiETIat (ORCPT ); Fri, 20 May 2022 04:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347091AbiETIaf (ORCPT ); Fri, 20 May 2022 04:30:35 -0400 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE17C14B676; Fri, 20 May 2022 01:30:06 -0700 (PDT) Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K3tLia028145; Fri, 20 May 2022 10:30:00 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=ELzzZyzi9IIRB85sZHLytKa0QsJoVdFk2Y4D4aQAVAo=; b=1t9eTyznf9T4JFHDbh8VG8RC/ucYGYT01BYBBxUFQCAdBPo3LbaZpEV3B0VpJOlPT47Y z9zBj2dM1dBRFdWAKxNLiHvNgu2tqnfeo6SqIquE7wsdTU1ZFwIsUzIQ/xMisK5c2B5n owV16Vfe8v0KtNgQ0ppzZNoadAu4XGr8NoqQxR7SHzA+8ZOQ4lLB1dIiTo0b317M9TwU eK38LqNtlkCidS2ncVH6CKOomVWti61EjxKWPwyaqR0qaBUy8nb1U4j0iNiOJUTtdjFK Nogumxsx5vUwU+JbmP9AZP9PqeAddSsL/nGYJtdFTdgqVgf373Y4df/WcZUDuzIqZZwx zw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g23s22tk1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:30:00 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3C61A10003A; Fri, 20 May 2022 10:29:58 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 3572A214D3E; Fri, 20 May 2022 10:29:58 +0200 (CEST) Received: from localhost (10.75.127.44) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:29:57 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 03/10] rpmsg: core: Add rpmsg device remote flow control announcement ops Date: Fri, 20 May 2022 10:29:33 +0200 Message-ID: <20220520082940.2984914-4-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_03,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org This ops is called by the rpmsg flow control service to inform a rpmsg local device of a remote endpoint flow control state. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_core.c | 24 ++++++++++++++++++++++++ drivers/rpmsg/rpmsg_internal.h | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 8de8aadd9b27..6bbc3b3ace50 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -67,6 +67,30 @@ int rpmsg_release_channel(struct rpmsg_device *rpdev, } EXPORT_SYMBOL(rpmsg_release_channel); +/** + * rpmsg_channel_remote_fc() - announce remote endpoint flow control state + * using source and destination endpoint address info. + * @rpdev: rpmsg device + * @chinfo: channel_info + * @enable: state of the remote endpoint + * + * Return: 0 on success or an appropriate error value. + */ +int rpmsg_channel_remote_fc(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo, + bool enable) +{ + if (WARN_ON(!rpdev)) + return -EINVAL; + if (!rpdev->ops || !rpdev->ops->announce_remote_fc) { + dev_err(&rpdev->dev, "no flow control ops found\n"); + return -ENXIO; + } + + return rpdev->ops->announce_remote_fc(rpdev, chinfo, enable); +} +EXPORT_SYMBOL(rpmsg_channel_remote_fc); + /** * rpmsg_create_ept() - create a new rpmsg_endpoint * @rpdev: rpmsg channel device diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index 4ce58e68af30..44e2c0f2f5ea 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -43,6 +43,9 @@ struct rpmsg_device_ops { int (*announce_create)(struct rpmsg_device *ept); int (*announce_destroy)(struct rpmsg_device *ept); + int (*announce_remote_fc)(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo, + bool enable); }; /** @@ -87,6 +90,10 @@ struct rpmsg_device *rpmsg_create_channel(struct rpmsg_device *rpdev, struct rpmsg_channel_info *chinfo); int rpmsg_release_channel(struct rpmsg_device *rpdev, struct rpmsg_channel_info *chinfo); + +int rpmsg_channel_remote_fc(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo, + bool enable); /** * rpmsg_ctrldev_register_device() - register a char device for control based on rpdev * @rpdev: prepared rpdev to be used for creating endpoints From patchwork Fri May 20 08:29:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36379C433EF for ; Fri, 20 May 2022 08:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244345AbiETIas (ORCPT ); Fri, 20 May 2022 04:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347002AbiETIah (ORCPT ); Fri, 20 May 2022 04:30:37 -0400 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0473714E2DB; Fri, 20 May 2022 01:30:06 -0700 (PDT) Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K4Uw9T017719; Fri, 20 May 2022 10:30:01 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=YHFIJxRiiXd7Hm4A9fpzYXfeaDCgITQVThJATlJXER4=; b=z5qsmjMr8pw8Svt/HbQH0xtotQE8l+Mn3cYrlhh8Aa+OcfRZMJ96KSVKVtnyThp4wn8D 7UoKzxRDp6SXMvlraZ7mU77s4UDpmRwoS6UG6u4AmUf1IbbFvdmm5MT1VjbrEaT/ddSh YtEglG8n+mlG3zYngJg8lZVApY8bXGxo6bfkaUDd7eRjQDIGCWTj+V06VMZ1hKBmH1eM 8hU1xKUMKj75ojomsOERYK0BwcEgchjM4F5vhmgsslbwMtUkSSJsmlA4doW+yUXQ5VeE ecuSuCvuJZd3LXETD5aMG7W64cUAWwdw/pjlqQ3wX1Jc1xE9zEXuoczk6A9wWvopYfeT aA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g21j9f79s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:30:01 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8966210003B; Fri, 20 May 2022 10:29:58 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 7F1C7215122; Fri, 20 May 2022 10:29:58 +0200 (CEST) Received: from localhost (10.75.127.46) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:29:58 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 04/10] rpmsg: virtio: Implement the announce_remote_fc ops Date: Fri, 20 May 2022 10:29:34 +0200 Message-ID: <20220520082940.2984914-5-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_03,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add the capability for a rpmsg local endpoint to receive information of a remote endpoint state using the flow control channel. The virtio_rpmsg_remote_flowctrl function calls the endpoint which matches with the chinfo. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/virtio_rpmsg_bus.c | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 0db8043e6c49..785fda77984e 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -305,6 +305,7 @@ __rpmsg_destroy_ept(struct virtproc_info *vrp, struct rpmsg_endpoint *ept) /* make sure in-flight inbound messages won't invoke cb anymore */ mutex_lock(&ept->cb_lock); ept->cb = NULL; + ept->sig_cb = NULL; mutex_unlock(&ept->cb_lock); kref_put(&ept->refcount, __ept_release); @@ -365,12 +366,49 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) return err; } +static int virtio_rpmsg_remote_flowctrl(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo, + bool enable) +{ + struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); + struct virtproc_info *vrp = vch->vrp; + struct rpmsg_endpoint *ept; + + /* Use the dst addr to fetch the callback of the appropriate user */ + mutex_lock(&vrp->endpoints_lock); + + ept = idr_find(&vrp->endpoints, chinfo->dst); + + /* Let's make sure no one deallocates ept while we use it */ + if (ept) + kref_get(&ept->refcount); + + mutex_unlock(&vrp->endpoints_lock); + + if (!ept) + return -EINVAL; + + /* Make sure ept->sig_cb doesn't go away while we use it */ + mutex_lock(&ept->cb_lock); + + if (ept->sig_cb) + ept->sig_cb(ept->rpdev, ept->priv, enable); + + mutex_unlock(&ept->cb_lock); + + /* Farewell, ept, we don't need you anymore */ + kref_put(&ept->refcount, __ept_release); + + return 0; +} + static const struct rpmsg_device_ops virtio_rpmsg_ops = { .create_channel = virtio_rpmsg_create_channel, .release_channel = virtio_rpmsg_release_channel, .create_ept = virtio_rpmsg_create_ept, .announce_create = virtio_rpmsg_announce_create, .announce_destroy = virtio_rpmsg_announce_destroy, + .announce_remote_fc = virtio_rpmsg_remote_flowctrl, }; static void virtio_rpmsg_release_device(struct device *dev) From patchwork Fri May 20 08:29:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856493 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9072FC433F5 for ; Fri, 20 May 2022 08:32:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347119AbiETIcb (ORCPT ); Fri, 20 May 2022 04:32:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347172AbiETIcT (ORCPT ); Fri, 20 May 2022 04:32:19 -0400 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B34326A40E; Fri, 20 May 2022 01:31:30 -0700 (PDT) Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K1fHuU021302; Fri, 20 May 2022 10:31:12 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=CdJLGIQGVB3QH47VC81jXK7okrgL52nTShMQiG+y/eI=; b=pyWNmPkUKV7bLK7LEt6AOPvIr540TQpwFm3VA24hUouFyUk7T4ny2ixzjb9vpRC1W2IM 89Mm+qqPajmIKndjBJpfmlbop0iqyBuHWadOm5mr8BjhIeSUFM8tWD+Ab+IxM3g2UyGL 2xnXy+1uFLXxzbspNFa2Q4z9QpUCjE1co/Sawork0lWwxTM9yLdxVMjfgko918bKC03F fOocU2oKEM0gBFF2oIdw2dStKObF5Wk3JQDtoVXRWV2eR3aqGocUEdMDGupTD3X/NRJV bve2oMjeUGvOkWRKi8+XUNHnT1v4D+waretm2gIaP9vk5IBQ70VwxbZks2yoHbKjz9i9 DA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g23aj6vtn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:31:12 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E8F9810002A; Fri, 20 May 2022 10:31:09 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id E178921512E; Fri, 20 May 2022 10:31:09 +0200 (CEST) Received: from localhost (10.75.127.47) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:31:09 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 05/10] rpmsg: Introduce flow control channel driver Date: Fri, 20 May 2022 10:29:35 +0200 Message-ID: <20220520082940.2984914-6-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_03,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Register the channel 54 to manage flow control between endpoints. the aim of this service is. - to inform the local endpoint of the state of the associated remote endpoints. - to inform remote endpoint about the state of the local endpoint. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/Kconfig | 10 ++++ drivers/rpmsg/Makefile | 1 + drivers/rpmsg/rpmsg_fc.c | 113 +++++++++++++++++++++++++++++++++++++++ include/linux/rpmsg/fc.h | 51 ++++++++++++++++++ 4 files changed, 175 insertions(+) create mode 100644 drivers/rpmsg/rpmsg_fc.c create mode 100644 include/linux/rpmsg/fc.h diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig index d3795860f5c0..c6659f27c617 100644 --- a/drivers/rpmsg/Kconfig +++ b/drivers/rpmsg/Kconfig @@ -31,6 +31,16 @@ config RPMSG_NS channel that probes the associated RPMsg device on remote endpoint service announcement. +config RPMSG_FC + tristate "RPMSG endpoint flow control management" + depends on RPMSG + help + Say Y here to enable the support of the flow control management + for the rpmsg endpoints. + + To compile this driver as a module, choose M here: the module will be + called rpmsg_fc. + config RPMSG_MTK_SCP tristate "MediaTek SCP" depends on MTK_SCP diff --git a/drivers/rpmsg/Makefile b/drivers/rpmsg/Makefile index 58e3b382e316..c70b9864231f 100644 --- a/drivers/rpmsg/Makefile +++ b/drivers/rpmsg/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_RPMSG) += rpmsg_core.o obj-$(CONFIG_RPMSG_CHAR) += rpmsg_char.o obj-$(CONFIG_RPMSG_CTRL) += rpmsg_ctrl.o obj-$(CONFIG_RPMSG_NS) += rpmsg_ns.o +obj-$(CONFIG_RPMSG_FC) += rpmsg_fc.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_fc.c b/drivers/rpmsg/rpmsg_fc.c new file mode 100644 index 000000000000..d7e17c8cffb0 --- /dev/null +++ b/drivers/rpmsg/rpmsg_fc.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) STMicroelectronics 2022 - All Rights Reserved + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include + +#include "rpmsg_internal.h" + +/** + * rpmsg_fc_register_device() - register name service device based on rpdev + * @rpdev: prepared rpdev to be used catfor creating endpoints + * + * This function wraps rpmsg_register_device() preparing the rpdev for use as + * basis for the rpmsg name service device. + */ +int rpmsg_fc_register_device(struct rpmsg_device *rpdev) +{ + strcpy(rpdev->id.name, "rpmsg_fc"); + rpdev->driver_override = KBUILD_MODNAME; + rpdev->src = RPMSG_FC_ADDR; + rpdev->dst = RPMSG_FC_ADDR; + + return rpmsg_register_device(rpdev); +} +EXPORT_SYMBOL(rpmsg_fc_register_device); + +/* Invoked when a name service announcement arrives */ +static int rpmsg_fc_cb(struct rpmsg_device *rpdev, void *data, int len, + void *priv, u32 src) +{ + struct rpmsg_ept_msg *msg = data; + struct rpmsg_channel_info chinfo; + struct device *dev = rpdev->dev.parent; + bool enable; + int ret; + + if (len != sizeof(*msg)) { + dev_err(dev, "malformed fc msg (%d)\n", len); + return -EINVAL; + } + + chinfo.src = rpmsg32_to_cpu(rpdev, msg->src); + chinfo.dst = rpmsg32_to_cpu(rpdev, msg->dst); + enable = rpmsg32_to_cpu(rpdev, msg->flags) & RPMSG_EPT_FC_ON; + + dev_dbg(dev, "remote endpoint 0x%x in state %sable\n", chinfo.src, enable ? "en" : "dis"); + + ret = rpmsg_channel_remote_fc(rpdev, &chinfo, enable); + if (ret) + dev_err(dev, "rpmsg_annouce_flow_ctrl failed: %d\n", ret); + + return ret; +} + +static int rpmsg_fc_probe(struct rpmsg_device *rpdev) +{ + struct rpmsg_endpoint *fc_ept; + struct rpmsg_channel_info fc_chinfo = { + .src = RPMSG_FC_ADDR, + .dst = RPMSG_FC_ADDR, + .name = "flow_control_service", + }; + + /* + * Create the Flow control (FC) service endpoint associated to the RPMsg + * device. The endpoint will be automatically destroyed when the RPMsg + * device will be deleted. + */ + fc_ept = rpmsg_create_ept(rpdev, rpmsg_fc_cb, NULL, fc_chinfo); + if (!fc_ept) { + dev_err(&rpdev->dev, "failed to create the FC ept\n"); + return -ENOMEM; + } + rpdev->ept = fc_ept; + + return 0; +} + +static struct rpmsg_driver rpmsg_fc_driver = { + .drv.name = KBUILD_MODNAME, + .probe = rpmsg_fc_probe, +}; + +static int rpmsg_fc_init(void) +{ + int ret; + + ret = register_rpmsg_driver(&rpmsg_fc_driver); + if (ret < 0) + pr_err("%s: Failed to register FC rpmsg driver\n", __func__); + + return ret; +} +postcore_initcall(rpmsg_fc_init); + +static void rpmsg_fc_exit(void) +{ + unregister_rpmsg_driver(&rpmsg_fc_driver); +} +module_exit(rpmsg_fc_exit); + +MODULE_DESCRIPTION("Flow control service rpmsg driver"); +MODULE_AUTHOR("Arnaud Pouliquen "); +MODULE_ALIAS("rpmsg:" KBUILD_MODNAME); +MODULE_LICENSE("GPL"); diff --git a/include/linux/rpmsg/fc.h b/include/linux/rpmsg/fc.h new file mode 100644 index 000000000000..5284ea410673 --- /dev/null +++ b/include/linux/rpmsg/fc.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_RPMSG_FC_H +#define _LINUX_RPMSG_FC_H + +#include +#include +#include +#include + +/* The feature bitmap for the endpoint flow control flags */ +#define RPMSG_EPT_FC_ON BIT(0) /* Set when endpoint is ready to communicate */ + +/** + * struct rpmsg_ept_msg - dynamic endpoint announcement message + * @src: address of the endpoint that sends the message + * @dest: address of the destination endpoint. + * @flags: indicates the state of the endpoint based on @rpmsg_ept_flags enum. + * + * This message is sent across to inform the remote about the state of a local + * endpoint associated with a remote endpoint: + * - a RPMSG_EPT_OFF can be sent to inform that a local endpoint is suspended. + * - a RPMSG_EPT_ON can be sent to inform that a local endpoint is ready to communicate. + * + * When we receive these messages, the appropriate endpoint is informed. + */ +struct rpmsg_ept_msg { + __rpmsg32 src; + __rpmsg32 dst; + __rpmsg32 flags; +} __packed; + +/* Address 54 is reserved for flow control advertising */ +#define RPMSG_FC_ADDR (54) + +#if IS_ENABLED(CONFIG_RPMSG_FC) + +int rpmsg_fc_register_device(struct rpmsg_device *rpdev); + +#else + +static inline int rpmsg_fc_register_device(struct rpmsg_device *rpdev) +{ + /* This shouldn't be possible */ + WARN_ON(1); + + return -ENXIO; +} +#endif /* IS_ENABLED(CONFIG_RPMSG_FC)*/ + +#endif From patchwork Fri May 20 08:29:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88769C433EF for ; Fri, 20 May 2022 08:32:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233557AbiETIcQ (ORCPT ); Fri, 20 May 2022 04:32:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347041AbiETIbT (ORCPT ); Fri, 20 May 2022 04:31:19 -0400 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AC7347540; Fri, 20 May 2022 01:31:17 -0700 (PDT) Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K8N4uh009064; Fri, 20 May 2022 10:31:12 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=jJqFYr/2kSFBBvwcNFQzdXYzRLTYOhwzMWQZ47+U0eM=; b=1XaD9oxWSDAZuwmh7yhFRShcHlu+fvFhvXpJz/oo8hD3a7v0J2mq6Rm/eV8txz8T+SwR rAj65pGe6ERCgwXiOHVIakgmCZ3qSPqQFCgVqVtyqUN/VQTZU78WNHue9ztxxVfBnKxH Ys1MphcL0EHDWTTZNTOVLL2ez7qTrE60UYYa/a8squWkyRDajojYWw4k11WkAz995zkp hLPdjQZaceAQlDUj9cSbPUMjDlK0UURBD5obFgLBXD3l6Deo8F8kNEEumF2TgGCxbfIt 2JIEhWP+Fl10LB7/PptxBxoSuzSQOfDks4mTEBepYeqFOi0pjMu/aOOZFyWQbONYUyUl zA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g21j9f7h4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:31:12 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 52836100038; Fri, 20 May 2022 10:31:10 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 49418215131; Fri, 20 May 2022 10:31:10 +0200 (CEST) Received: from localhost (10.75.127.47) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:31:09 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 06/10] rpmsg: virtio: Add support of the VIRTIO_RPMSG_F_FC feature Date: Fri, 20 May 2022 10:29:36 +0200 Message-ID: <20220520082940.2984914-7-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_03,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Introduce the VIRTIO_RPMSG_F_FC feature in charge of the end point flow control management. The virtio feature is negotiated. If the remote side supports it, the rpmsg_fc device is probed. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/Kconfig | 1 + drivers/rpmsg/virtio_rpmsg_bus.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig index c6659f27c617..e39cf32483de 100644 --- a/drivers/rpmsg/Kconfig +++ b/drivers/rpmsg/Kconfig @@ -89,6 +89,7 @@ config RPMSG_VIRTIO depends on HAS_DMA select RPMSG select RPMSG_NS + select RPMSG_FC select VIRTIO endmenu diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 785fda77984e..40d2ab86b395 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,7 @@ struct virtproc_info { /* The feature bitmap for virtio rpmsg */ #define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ +#define VIRTIO_RPMSG_F_FC 1 /* RP supports endpoint flow control notifications */ /** * struct rpmsg_hdr - common header for all rpmsg messages @@ -909,7 +911,7 @@ static int rpmsg_probe(struct virtio_device *vdev) struct virtqueue *vqs[2]; struct virtproc_info *vrp; struct virtio_rpmsg_channel *vch = NULL; - struct rpmsg_device *rpdev_ns, *rpdev_ctrl; + struct rpmsg_device *rpdev_ns = NULL, *rpdev_ctrl, *rpdev_fc; void *bufs_va; int err = 0, i; size_t total_buf_space; @@ -1013,6 +1015,30 @@ static int rpmsg_probe(struct virtio_device *vdev) goto free_ctrldev; } + /* If supported by the remote processor, enable the flow control service */ + if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_FC)) { + vch = kzalloc(sizeof(*vch), GFP_KERNEL); + if (!vch) { + err = -ENOMEM; + goto free_ns; + } + + /* Link the channel to our vrp */ + vch->vrp = vrp; + + /* Assign public information to the rpmsg_device */ + rpdev_fc = &vch->rpdev; + rpdev_fc->ops = &virtio_rpmsg_ops; + rpdev_fc->little_endian = virtio_is_little_endian(vrp->vdev); + + rpdev_fc->dev.parent = &vrp->vdev->dev; + rpdev_fc->dev.release = virtio_rpmsg_release_device; + + err = rpmsg_fc_register_device(rpdev_fc); + if (err) + goto free_ns; + } + /* * Prepare to kick but don't notify yet - we can't do this before * device is ready. @@ -1034,6 +1060,9 @@ static int rpmsg_probe(struct virtio_device *vdev) return 0; +free_ns: + if (rpdev_ns) + device_unregister(&rpdev_ns->dev); free_ctrldev: rpmsg_virtio_del_ctrl_dev(rpdev_ctrl); free_coherent: @@ -1082,6 +1111,7 @@ static struct virtio_device_id id_table[] = { static unsigned int features[] = { VIRTIO_RPMSG_F_NS, + VIRTIO_RPMSG_F_FC, }; static struct virtio_driver virtio_ipc_driver = { From patchwork Fri May 20 08:29:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46E66C433EF for ; Fri, 20 May 2022 08:32:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347128AbiETIcW (ORCPT ); Fri, 20 May 2022 04:32:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347125AbiETIcR (ORCPT ); Fri, 20 May 2022 04:32:17 -0400 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04EBE5253A; Fri, 20 May 2022 01:31:19 -0700 (PDT) Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K1fHuV021302; Fri, 20 May 2022 10:31:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=t94o4VLq7z8yU2gSvGyjpvMAkLvBovU9E/HfTz+KTSA=; b=n7qkXL8KJw/5QDLTaSC5lU3wZ09WfVAWDR3kXtXL4qiBfKf0/cPDYonDtCB4NVlaW6AV 8GYUyNqz6IXsGKGxcYRN0fKtRD7ptyzIKy6rXULMHOm1fP+0+xHZFmveGZgVHLlAGFxI DVcvXF0SkWWoVAUhSdOuJWRlhX1eOlDXyqdzzoYOyouY+YfUhy+je/8lZDC+0ysJEei+ T0nnx3gg5pARasCcdN/Fddlvf2j47OKN41qz2AterXBjjIZxDPbrGdA03Mj4mrW77GIf 9Ya4swTaP/FhjkKEQl11iMoTuHPqoz+tGBpHhK6YP9ma6MFOokarB9eF4Ptg/nuvLH6B qQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g23aj6vtx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:31:14 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 32926100038; Fri, 20 May 2022 10:31:14 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 9437720E6D1; Fri, 20 May 2022 10:31:13 +0200 (CEST) Received: from localhost (10.75.127.44) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:31:10 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 07/10] rpmsg: virtio: Implement the set_flow_control ops Date: Fri, 20 May 2022 10:29:37 +0200 Message-ID: <20220520082940.2984914-8-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_03,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add the capability for a rpmsg local endpoint to informs the remote of its state using the flow control channel. If the feature is not supported by the remote processor, no message is sent. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/virtio_rpmsg_bus.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 40d2ab86b395..96bd12095c8c 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -154,6 +154,8 @@ static ssize_t virtio_rpmsg_get_mtu(struct rpmsg_endpoint *ept); static struct rpmsg_device *__rpmsg_create_channel(struct virtproc_info *vrp, struct rpmsg_channel_info *chinfo); +static int virtio_rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable); + static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { .destroy_ept = virtio_rpmsg_destroy_ept, .send = virtio_rpmsg_send, @@ -163,6 +165,7 @@ static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { .trysendto = virtio_rpmsg_trysendto, .trysend_offchannel = virtio_rpmsg_trysend_offchannel, .get_mtu = virtio_rpmsg_get_mtu, + .set_flow_control = virtio_rpmsg_set_flow_control, }; /** @@ -745,6 +748,34 @@ static ssize_t virtio_rpmsg_get_mtu(struct rpmsg_endpoint *ept) return vch->vrp->buf_size - sizeof(struct rpmsg_hdr); } +static int virtio_rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable) +{ + struct rpmsg_device *rpdev; + struct virtio_rpmsg_channel *vch; + int err = 0; + + if (!ept) + return -EINVAL; + + rpdev = ept->rpdev; + vch = to_virtio_rpmsg_channel(rpdev); + + if (virtio_has_feature(vch->vrp->vdev, VIRTIO_RPMSG_F_FC)) { + struct rpmsg_ept_msg msg; + + msg.src = cpu_to_rpmsg32(rpdev, ept->addr); + msg.dst = cpu_to_rpmsg32(rpdev, rpdev->dst); + msg.flags = cpu_to_rpmsg32(rpdev, enable ? RPMSG_EPT_FC_ON : 0); + + err = rpmsg_sendto(ept, &msg, sizeof(msg), RPMSG_FC_ADDR); + if (err) + dev_err(&rpdev->dev, "Failed to set endpoint 0x%x state %sable (%d)\n", + ept->addr, enable ? "en" : "dis", err); + } + + return err; +} + static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, struct rpmsg_hdr *msg, unsigned int len) { From patchwork Fri May 20 08:29:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 442B2C433EF for ; Fri, 20 May 2022 08:32:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345608AbiETIc0 (ORCPT ); Fri, 20 May 2022 04:32:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347047AbiETIcT (ORCPT ); Fri, 20 May 2022 04:32:19 -0400 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C8325DA0D; Fri, 20 May 2022 01:31:24 -0700 (PDT) Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K6PmIU022160; Fri, 20 May 2022 10:31:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=XxRyzDT/cjEKJwSautfebKnSTO2wQfu9PaCTzwbxsbM=; b=Zdg1hkZ3aCNwkHBaM7enUlBp96KdBa0rPExa/JTWIYi9YYP15mg8TpHlCyd+IrD0wGCQ fMtNqD7PireqCqnQEzFcQaaP78po6wTugsmEZQA7mpziw8xwHobRhXYL7zdq1weloqtK SvZ4nsoV8cT6wAipVG3LAlBsUUm7qJXJZCJi2GMCK/7h+DVcuuy1B4clZHQSONq4vrPA 41GqOEt1bGg0ctwSco9FN6gQcGQ6nsAiy82bAH0cH2EC+aamUkwLjEX3PugzoDItv23x tyTNcMhwM0y0r8K7qKloli8lEKVudfTobWfPHQRDm/pkBRaPEnso90T4ceoKlwGwxTtR ew== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g23aj6vtu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:31:14 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C021E100039; Fri, 20 May 2022 10:31:11 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id B9A7B215132; Fri, 20 May 2022 10:31:11 +0200 (CEST) Received: from localhost (10.75.127.44) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:31:11 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 08/10] rpmsg: Add the destination address in rpmsg_set_flow_control Date: Fri, 20 May 2022 10:29:38 +0200 Message-ID: <20220520082940.2984914-9-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_03,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The destination address is not part of the rpmsg_endpoint structure. For static endpoint without channel, we need to specify the destination address for backend such as the rpmsg virtio. It is also needed for endpoint to multi endpoint communication. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_char.c | 2 +- drivers/rpmsg/rpmsg_core.c | 6 ++++-- drivers/rpmsg/rpmsg_internal.h | 2 +- drivers/rpmsg/virtio_rpmsg_bus.c | 6 +++--- include/linux/rpmsg.h | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c index 904e7c67b356..f44747e64b5b 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -316,7 +316,7 @@ static long rpmsg_eptdev_ioctl(struct file *fp, unsigned int cmd, if (ret) break; set = (val & TIOCM_DTR) ? true : false; - ret = rpmsg_set_flow_control(eptdev->ept, set); + ret = rpmsg_set_flow_control(eptdev->ept, eptdev->chinfo.dst, set); break; case RPMSG_DESTROY_EPT_IOCTL: /* Don't allow to destroy a default endpoint. */ diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 6bbc3b3ace50..ab9a170ffa93 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -357,18 +357,20 @@ EXPORT_SYMBOL(rpmsg_trysend_offchannel); /** * rpmsg_set_flow_control() - sets/clears serial flow control signals * @ept: the rpmsg endpoint + * @dst: the remote endpoint destination addr, set to RPMSG_ADDR_ANY to send to the default + * remote endpoint associated to the rpmsg device. * @enable: enable or disable serial flow control * * Return: 0 on success and an appropriate error value on failure. */ -int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable) +int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, u32 dst, bool enable) { if (WARN_ON(!ept)) return -EINVAL; if (!ept->ops->set_flow_control) return -ENXIO; - return ept->ops->set_flow_control(ept, enable); + return ept->ops->set_flow_control(ept, dst, enable); } EXPORT_SYMBOL(rpmsg_set_flow_control); diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index 44e2c0f2f5ea..c34175f5093c 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -79,7 +79,7 @@ struct rpmsg_endpoint_ops { void *data, int len); __poll_t (*poll)(struct rpmsg_endpoint *ept, struct file *filp, poll_table *wait); - int (*set_flow_control)(struct rpmsg_endpoint *ept, bool enable); + int (*set_flow_control)(struct rpmsg_endpoint *ept, u32 dst, bool enable); ssize_t (*get_mtu)(struct rpmsg_endpoint *ept); }; diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 96bd12095c8c..a8e60ca4cd08 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -154,7 +154,7 @@ static ssize_t virtio_rpmsg_get_mtu(struct rpmsg_endpoint *ept); static struct rpmsg_device *__rpmsg_create_channel(struct virtproc_info *vrp, struct rpmsg_channel_info *chinfo); -static int virtio_rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable); +static int virtio_rpmsg_set_flow_control(struct rpmsg_endpoint *ept, u32 dst, bool enable); static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { .destroy_ept = virtio_rpmsg_destroy_ept, @@ -748,7 +748,7 @@ static ssize_t virtio_rpmsg_get_mtu(struct rpmsg_endpoint *ept) return vch->vrp->buf_size - sizeof(struct rpmsg_hdr); } -static int virtio_rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable) +static int virtio_rpmsg_set_flow_control(struct rpmsg_endpoint *ept, u32 dst, bool enable) { struct rpmsg_device *rpdev; struct virtio_rpmsg_channel *vch; @@ -764,7 +764,7 @@ static int virtio_rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable struct rpmsg_ept_msg msg; msg.src = cpu_to_rpmsg32(rpdev, ept->addr); - msg.dst = cpu_to_rpmsg32(rpdev, rpdev->dst); + msg.dst = cpu_to_rpmsg32(rpdev, dst == RPMSG_ADDR_ANY ? rpdev->dst : dst); msg.flags = cpu_to_rpmsg32(rpdev, enable ? RPMSG_EPT_FC_ON : 0); err = rpmsg_sendto(ept, &msg, sizeof(msg), RPMSG_FC_ADDR); diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index dbd0c591bb85..9b321e1554e3 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -193,7 +193,7 @@ __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp, ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept); -int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable); +int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, u32 dst, bool enable); #else @@ -313,7 +313,7 @@ static inline ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept) return -ENXIO; } -static inline int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool enable) +static inline int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, u32 dst, bool enable) { /* This shouldn't be possible */ WARN_ON(1); From patchwork Fri May 20 08:29:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856494 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 980CBC433EF for ; Fri, 20 May 2022 08:32:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347013AbiETIcd (ORCPT ); Fri, 20 May 2022 04:32:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347126AbiETIcR (ORCPT ); Fri, 20 May 2022 04:32:17 -0400 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65E1253A75; Fri, 20 May 2022 01:31:19 -0700 (PDT) Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K6OsWj029143; Fri, 20 May 2022 10:31:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=Tqs+xiYCFI/8hHPXJbtrZX5TEbiaS90HqfCz+Xzn8qU=; b=GhiDIvS3rGfr2I1AJ0Yyd08HBT/vGRKwQWuxQpg1FOLRh+ClBHMAkcmFKoENL2uVVvJj bUL+gX8TSyV8bY0Ox53NEBldyWC5DqmYvxsCH+aNSRQuJS88qvWGz0j2NJImerSTu6Fp EOvsGLZUOFHLLTJ4rVzQ8NyMCn5khnnfo94FMIjasmRCn+6orjFWTyvwg3HRjO1D0kj/ pNHS0ltq+Ce5PqUArGPSZjc7+1KfvKX/Tm4+IJQL5fkku9Mk+WsiuIOOW6zW5M9HOH5E VNafwc6GzxlPKHUc/7dzVhVykr6KwETotSUq+zGWTYgjuFjDTT0p4CXPsy5ISel1MAVc 7A== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g21j9f7ha-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:31:14 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 22F2D100034; Fri, 20 May 2022 10:31:13 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 1789221512E; Fri, 20 May 2022 10:31:13 +0200 (CEST) Received: from localhost (10.75.127.46) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:31:12 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 09/10] rpmsg: tty : Add the support of the flow control Date: Fri, 20 May 2022 10:29:39 +0200 Message-ID: <20220520082940.2984914-10-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_03,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add Software flow control support based on the RPMsg flow control channel. Signed-off-by: Arnaud Pouliquen --- drivers/tty/rpmsg_tty.c | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/tty/rpmsg_tty.c b/drivers/tty/rpmsg_tty.c index 29db413bbc03..fc1dc4a5ca9d 100644 --- a/drivers/tty/rpmsg_tty.c +++ b/drivers/tty/rpmsg_tty.c @@ -30,6 +30,7 @@ struct rpmsg_tty_port { struct tty_port port; /* TTY port data */ int id; /* TTY rpmsg index */ struct rpmsg_device *rpdev; /* rpmsg device */ + bool flow_stopped; /* remote device flow control */ }; static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src) @@ -106,6 +107,9 @@ static unsigned int rpmsg_tty_write_room(struct tty_struct *tty) struct rpmsg_tty_port *cport = tty->driver_data; int size; + if (cport->flow_stopped) + return 0; + size = rpmsg_get_mtu(cport->rpdev->ept); if (size < 0) return 0; @@ -118,6 +122,28 @@ static void rpmsg_tty_hangup(struct tty_struct *tty) tty_port_hangup(tty->port); } +static void rpmsg_tty_throttle(struct tty_struct *tty) +{ + struct rpmsg_tty_port *cport = tty->driver_data; + int ret; + + /* Disable remote transmission */ + ret = rpmsg_set_flow_control(cport->rpdev->ept, RPMSG_ADDR_ANY, 0); + if (ret && ret != ENXIO) + dev_err(tty->dev, "cannot send control (%d)\n", ret); +}; + +static void rpmsg_tty_unthrottle(struct tty_struct *tty) +{ + struct rpmsg_tty_port *cport = tty->driver_data; + int ret; + + /* Enable remote transmission */ + ret = rpmsg_set_flow_control(cport->rpdev->ept, RPMSG_ADDR_ANY, 1); + if (ret && ret != ENXIO) + dev_err(tty->dev, "cannot send control (%d)\n", ret); +}; + static const struct tty_operations rpmsg_tty_ops = { .install = rpmsg_tty_install, .open = rpmsg_tty_open, @@ -126,6 +152,8 @@ static const struct tty_operations rpmsg_tty_ops = { .write_room = rpmsg_tty_write_room, .hangup = rpmsg_tty_hangup, .cleanup = rpmsg_tty_cleanup, + .throttle = rpmsg_tty_throttle, + .unthrottle = rpmsg_tty_unthrottle, }; static struct rpmsg_tty_port *rpmsg_tty_alloc_cport(void) @@ -162,11 +190,32 @@ static void rpmsg_tty_destruct_port(struct tty_port *port) kfree(cport); } +static void rpmsg_tty_dtr_rts(struct tty_port *port, int raise) +{ + if (!port->tty) + return; + + if (raise) + rpmsg_tty_unthrottle(port->tty); + else + rpmsg_tty_throttle(port->tty); +} + static const struct tty_port_operations rpmsg_tty_port_ops = { .destruct = rpmsg_tty_destruct_port, + .dtr_rts = rpmsg_tty_dtr_rts, }; +static int rpmsg_tty_dsr_cts(struct rpmsg_device *rpdev, void *priv, u32 state) +{ + struct rpmsg_tty_port *cport = dev_get_drvdata(&rpdev->dev); + + cport->flow_stopped = !state; + + return 0; +} + static int rpmsg_tty_probe(struct rpmsg_device *rpdev) { struct rpmsg_tty_port *cport; @@ -225,6 +274,7 @@ static struct rpmsg_driver rpmsg_tty_rpmsg_drv = { .probe = rpmsg_tty_probe, .callback = rpmsg_tty_cb, .remove = rpmsg_tty_remove, + .signals = rpmsg_tty_dsr_cts, }; static int __init rpmsg_tty_init(void) From patchwork Fri May 20 08:29:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 12856500 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAA68C433EF for ; Fri, 20 May 2022 08:33:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344452AbiETId5 (ORCPT ); Fri, 20 May 2022 04:33:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347160AbiETIdd (ORCPT ); Fri, 20 May 2022 04:33:33 -0400 Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [185.132.182.106]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAA5F15F6C8; Fri, 20 May 2022 01:32:34 -0700 (PDT) Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24K3tLjB028145; Fri, 20 May 2022 10:32:26 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=c/Lq0oy39Sxj5Cf7Ma+CafFIl6MIsyg+0GLBTzXk1No=; b=zRkUXEdtfH8syzUhy3lFopRF1TbdtxZIywyejyCWnUNX26LEVEDLybDrMkuoTAYKQ8/T 653omNVZBb68VWCRg6tGVim8HxtRfYW+cfDoRuVn2Sqo8OaMnlj2cPgA3AKvcIZSiXBC 6/AE7bTSMalsCjyAOEfpcwpgzRTC/XkHo5GGGlPl4XbktN3MYbSGCj/a8KW522zhqPuQ Z1W3/YkC2Si2Ggign9MmSNMJFqNypEXhp4qIQKQfeXOIAijYbuOfpcHDfIVuLUTevTeL X4o+jwGgm252pY5zmExI9C7gL6jCye1DWsZ5i0ovj1h4qPGGYH6ho8dFue9JgrTRLLG9 sQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g23s22u1e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 20 May 2022 10:32:26 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D9A8010002A; Fri, 20 May 2022 10:32:23 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node2.st.com [10.75.129.70]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id D11EB215124; Fri, 20 May 2022 10:32:23 +0200 (CEST) Received: from localhost (10.75.127.46) by SHFDAG1NODE2.st.com (10.75.129.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Fri, 20 May 2022 10:32:22 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Mathieu Poirier CC: , , , Deepak Kumar Singh , Chris Lew , Subject: [RFC PATCH 10/10] rpmsg: virtio: Set default dst address on flow control Date: Fri, 20 May 2022 10:29:40 +0200 Message-ID: <20220520082940.2984914-11-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> References: <20220520082940.2984914-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE2.st.com (10.75.129.70) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-20_03,2022-05-19_03,2022-02-23_01 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org When a rpmsg channel has been created locally with a destination address set to RPMSG_ADDR_ANY, a name service announcement message is sent to the remote side. Then the destination address is never updated, making it impossible to send messages to the remote. An example of kernel trace observed: rpmsg_tty virtio0.rpmsg-tty.29.-1: invalid addr (src 0x1d, dst 0xffffffff) The flow control can be used to set the rpmsg device address. If the destination address is RPMSG_ADDR_ANY, then set it to address of the remote endpoint that send the message. Signed-off-by: Arnaud Pouliquen --- This patch is an alternative of the fix proposed in patch [1] [1] https://lore.kernel.org/lkml/20220316153001.662422-1-arnaud.pouliquen@foss.st.com/ --- drivers/rpmsg/virtio_rpmsg_bus.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index a8e60ca4cd08..0337a07e278c 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -393,6 +393,16 @@ static int virtio_rpmsg_remote_flowctrl(struct rpmsg_device *rpdev, if (!ept) return -EINVAL; + /* + * If the endpoint is the rpmsg device default one, then it can not be yet associated + * to the remote endpoint. This can occur if a ns announcement message has been + * previously sent to the remote side. + * Update the rpmsg device destination address in such case to store the remote + * address as default remote endpoint. + */ + if (rpdev->ept == ept && rpdev->dst == RPMSG_ADDR_ANY) + rpdev->dst = __rpmsg32_to_cpu(virtio_is_little_endian(vrp->vdev), chinfo->src); + /* Make sure ept->sig_cb doesn't go away while we use it */ mutex_lock(&ept->cb_lock);