From: Chris Lew <quic_clew@quicinc.com>
To: <bjorn.andersson@linaro.org>, <mathieu.poirier@linaro.org>
Cc: <linux-remoteproc@vger.kernel.org>,
<linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<quic_clew@quicinc.com>
Subject: [PATCH 2/4] rpmsg: char: Add support to use rpmsg_rx_done
Date: Tue, 7 Jun 2022 18:16:43 -0700 [thread overview]
Message-ID: <1654651005-15475-3-git-send-email-quic_clew@quicinc.com> (raw)
In-Reply-To: <1654651005-15475-1-git-send-email-quic_clew@quicinc.com>
Add support into the rpmsg char driver to skip copying the data into an
skb if the endpoint supports rpmsg_rx_done. If the endpoint supports
the rx_done operation, allocate a zero sized skb and set the data to
the buffer returned in the rx callback. When the packet is read from
the character device, release the memory by calling rpmsg_rx_done().
Signed-off-by: Chris Lew <quic_clew@quicinc.com>
---
drivers/rpmsg/rpmsg_char.c | 50 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c
index b6183d4f62a2..be62ddcf356c 100644
--- a/drivers/rpmsg/rpmsg_char.c
+++ b/drivers/rpmsg/rpmsg_char.c
@@ -91,8 +91,8 @@ int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data)
}
EXPORT_SYMBOL(rpmsg_chrdev_eptdev_destroy);
-static int rpmsg_ept_cb(struct rpmsg_device *rpdev, void *buf, int len,
- void *priv, u32 addr)
+static int rpmsg_ept_copy_cb(struct rpmsg_device *rpdev, void *buf, int len,
+ void *priv, u32 addr)
{
struct rpmsg_eptdev *eptdev = priv;
struct sk_buff *skb;
@@ -113,6 +113,43 @@ static int rpmsg_ept_cb(struct rpmsg_device *rpdev, void *buf, int len,
return 0;
}
+static int rpmsg_ept_no_copy_cb(struct rpmsg_device *rpdev, void *buf, int len,
+ void *priv, u32 addr)
+{
+ struct rpmsg_eptdev *eptdev = priv;
+ struct sk_buff *skb;
+
+ skb = alloc_skb(0, GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+
+ skb->head = buf;
+ skb->data = buf;
+ skb_reset_tail_pointer(skb);
+ skb_set_end_offset(skb, len);
+ skb_put(skb, len);
+
+ spin_lock(&eptdev->queue_lock);
+ 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 RPMSG_DEFER;
+}
+
+static int rpmsg_ept_cb(struct rpmsg_device *rpdev, void *buf, int len,
+ void *priv, u32 addr)
+{
+ struct rpmsg_eptdev *eptdev = priv;
+ rpmsg_rx_cb_t cb;
+
+ cb = (eptdev->ept->rx_done) ? rpmsg_ept_no_copy_cb : rpmsg_ept_copy_cb;
+
+ return cb(rpdev, buf, len, priv, addr);
+}
+
static int rpmsg_eptdev_open(struct inode *inode, struct file *filp)
{
struct rpmsg_eptdev *eptdev = cdev_to_eptdev(inode->i_cdev);
@@ -210,6 +247,15 @@ static ssize_t rpmsg_eptdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (copy_to_iter(skb->data, use, to) != use)
use = -EFAULT;
+ if (eptdev->ept->rx_done) {
+ rpmsg_rx_done(eptdev->ept, skb->data);
+ /*
+ * Data memory is freed by rpmsg_rx_done(), reset the skb data
+ * pointers so kfree_skb() does not try to free a second time.
+ */
+ skb->head = NULL;
+ skb->data = NULL;
+ }
kfree_skb(skb);
return use;
--
2.7.4
next prev parent reply other threads:[~2022-06-08 4:52 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-08 1:16 [PATCH 0/4] Introduction of rpmsg_rx_done Chris Lew
2022-06-08 1:16 ` [PATCH 1/4] rpmsg: core: Add rx done hooks Chris Lew
2022-07-18 8:31 ` Arnaud POULIQUEN
2022-07-27 17:16 ` Mathieu Poirier
2022-06-08 1:16 ` Chris Lew [this message]
2022-07-27 17:18 ` [PATCH 2/4] rpmsg: char: Add support to use rpmsg_rx_done Mathieu Poirier
2022-06-08 1:16 ` [PATCH 3/4] rpmsg: glink: Try to send rx done in irq Chris Lew
2022-06-08 1:16 ` [PATCH 4/4] rpmsg: glink: Add support for rpmsg_rx_done Chris Lew
2022-07-27 17:21 ` Mathieu Poirier
2022-07-18 8:26 ` [PATCH 0/4] Introduction of rpmsg_rx_done Arnaud POULIQUEN
2022-07-18 16:54 ` Mathieu Poirier
2022-07-27 17:25 ` Mathieu Poirier
2022-07-26 17:51 ` Mathieu Poirier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1654651005-15475-3-git-send-email-quic_clew@quicinc.com \
--to=quic_clew@quicinc.com \
--cc=bjorn.andersson@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox