From patchwork Fri Mar 29 01:41:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tivy, Robert" X-Patchwork-Id: 2360091 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from arroyo.ext.ti.com (arroyo.ext.ti.com [192.94.94.40]) by patchwork1.kernel.org (Postfix) with ESMTP id 1438B3FDDA for ; Fri, 29 Mar 2013 01:47:28 +0000 (UTC) Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id r2T1hOJ9011179; Thu, 28 Mar 2013 20:43:24 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id r2T1hODB017154; Thu, 28 Mar 2013 20:43:24 -0500 Received: from dlelxv23.itg.ti.com (172.17.1.198) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.2.342.3; Thu, 28 Mar 2013 20:43:24 -0500 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dlelxv23.itg.ti.com (8.13.8/8.13.8) with ESMTP id r2T1hOQl006888; Thu, 28 Mar 2013 20:43:24 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 012E68062A; Thu, 28 Mar 2013 19:43:24 -0600 (CST) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dlelxv30.itg.ti.com (dlelxv30.itg.ti.com [172.17.2.17]) by linux.omap.com (Postfix) with ESMTP id 2F0B28062C for ; Thu, 28 Mar 2013 19:42:17 -0600 (CST) Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id r2T1gHS7014264; Thu, 28 Mar 2013 20:42:17 -0500 Received: from dlelxv24.itg.ti.com (172.17.1.199) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.2.342.3; Thu, 28 Mar 2013 20:42:16 -0500 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dlelxv24.itg.ti.com (8.13.8/8.13.8) with ESMTP id r2T1gGNv005954; Thu, 28 Mar 2013 20:42:16 -0500 Received: from sanblnx02.sanb.design.ti.com (sanblnx02.sanb.design.ti.com [146.252.160.81]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id r2T1gFV09989; Thu, 28 Mar 2013 20:42:15 -0500 (CDT) Received: from sanblnx02.sanb.design.ti.com (localhost [127.0.0.1]) by sanblnx02.sanb.design.ti.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id r2T1gEsH001387; Thu, 28 Mar 2013 18:42:14 -0700 Received: (from a0783933@localhost) by sanblnx02.sanb.design.ti.com (8.13.6/8.13.6/Submit) id r2T1gErH001384; Thu, 28 Mar 2013 18:42:14 -0700 From: Robert Tivy To: , , , , , , Subject: [PATCH v9 1/6] rpmsg: Process all available messages in virtqueue callback Date: Thu, 28 Mar 2013 18:41:42 -0700 Message-ID: <1364521307-1219-2-git-send-email-rtivy@ti.com> X-Mailer: git-send-email 1.7.9.4 In-Reply-To: <1364521307-1219-1-git-send-email-rtivy@ti.com> References: <1364521307-1219-1-git-send-email-rtivy@ti.com> MIME-Version: 1.0 X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com Change virtqueue callback function rpmsg_recv_done() to process all available messages instead of just one message. Signed-off-by: Robert Tivy --- drivers/rpmsg/virtio_rpmsg_bus.c | 97 +++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 39 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index a59684b..6e54f6a 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -776,7 +776,7 @@ out: } EXPORT_SYMBOL(rpmsg_send_offchannel_raw); -/* called when an rx buffer is used, and it's time to digest a message */ +/* called when an rx buffer is used, and it's time to digest a message(s) */ static void rpmsg_recv_done(struct virtqueue *rvq) { struct rpmsg_hdr *msg; @@ -785,6 +785,7 @@ static void rpmsg_recv_done(struct virtqueue *rvq) struct scatterlist sg; struct virtproc_info *vrp = rvq->vdev->priv; struct device *dev = &rvq->vdev->dev; + int added_buf = 0; int err; msg = virtqueue_get_buf(rvq, &len); @@ -793,60 +794,78 @@ static void rpmsg_recv_done(struct virtqueue *rvq) return; } - dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n", + while (msg) { + dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n", msg->src, msg->dst, msg->len, msg->flags, msg->reserved); - print_hex_dump(KERN_DEBUG, "rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1, +#ifdef DEBUG_VERBOSE + print_hex_dump(KERN_DEBUG, "rpmsg_virtio RX: ", + DUMP_PREFIX_NONE, 16, 1, msg, sizeof(*msg) + msg->len, true); +#endif - /* - * We currently use fixed-sized buffers, so trivially sanitize - * the reported payload length. - */ - if (len > RPMSG_BUF_SIZE || - msg->len > (len - sizeof(struct rpmsg_hdr))) { - dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len); - return; - } + /* + * We currently use fixed-sized buffers, so trivially sanitize + * the reported payload length. + */ + if (len > RPMSG_BUF_SIZE || + msg->len > (len - sizeof(struct rpmsg_hdr))) { + dev_warn(dev, "inbound msg too big: (%d, %d)\n", + len, msg->len); + break; + } - /* use the dst addr to fetch the callback of the appropriate user */ - mutex_lock(&vrp->endpoints_lock); + /* + * Use the dst addr to fetch the callback of the appropriate + * user. + */ + mutex_lock(&vrp->endpoints_lock); - ept = idr_find(&vrp->endpoints, msg->dst); + ept = idr_find(&vrp->endpoints, msg->dst); - /* let's make sure no one deallocates ept while we use it */ - if (ept) - kref_get(&ept->refcount); + /* let's make sure no one deallocates ept while we use it */ + if (ept) + kref_get(&ept->refcount); - mutex_unlock(&vrp->endpoints_lock); + mutex_unlock(&vrp->endpoints_lock); - if (ept) { - /* make sure ept->cb doesn't go away while we use it */ - mutex_lock(&ept->cb_lock); + if (ept) { + /* make sure ept->cb doesn't go away while we use it */ + mutex_lock(&ept->cb_lock); - if (ept->cb) - ept->cb(ept->rpdev, msg->data, msg->len, ept->priv, - msg->src); + if (ept->cb) + ept->cb(ept->rpdev, msg->data, msg->len, + ept->priv, msg->src); - mutex_unlock(&ept->cb_lock); + mutex_unlock(&ept->cb_lock); - /* farewell, ept, we don't need you anymore */ - kref_put(&ept->refcount, __ept_release); - } else - dev_warn(dev, "msg received with no recipient\n"); + /* farewell, ept, we don't need you anymore */ + kref_put(&ept->refcount, __ept_release); + } else + dev_warn(dev, "msg received with no recipient\n"); - /* publish the real size of the buffer */ - sg_init_one(&sg, msg, RPMSG_BUF_SIZE); + /* publish the real size of the buffer */ + sg_init_one(&sg, msg, RPMSG_BUF_SIZE); - /* add the buffer back to the remote processor's virtqueue */ - err = virtqueue_add_buf(vrp->rvq, &sg, 0, 1, msg, GFP_KERNEL); - if (err < 0) { - dev_err(dev, "failed to add a virtqueue buffer: %d\n", err); - return; + /* add the buffer back to the remote processor's virtqueue */ + err = virtqueue_add_buf(vrp->rvq, &sg, 0, 1, msg, GFP_KERNEL); + if (err < 0) { + dev_err(dev, "failed to add a virtqueue buffer: %d\n", + err); + break; + } + + added_buf = 1; + + msg = virtqueue_get_buf(rvq, &len); } - /* tell the remote processor we added another available rx buffer */ - virtqueue_kick(vrp->rvq); + if (added_buf) + /* + * Tell the remote processor we added another available rx + * buffer. + */ + virtqueue_kick(vrp->rvq); } /*