From patchwork Tue Apr 9 08:25:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ohad Ben Cohen X-Patchwork-Id: 2413411 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) by patchwork2.kernel.org (Postfix) with ESMTP id 935E1DF25A for ; Tue, 9 Apr 2013 08:30:12 +0000 (UTC) Received: from dlelxv30.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id r398QFVc015340; Tue, 9 Apr 2013 03:26:15 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv30.itg.ti.com (8.13.8/8.13.8) with ESMTP id r398QFIZ001030; Tue, 9 Apr 2013 03:26:15 -0500 Received: from dlelxv23.itg.ti.com (172.17.1.198) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.2.342.3; Tue, 9 Apr 2013 03:26:15 -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 r398QFBf002090; Tue, 9 Apr 2013 03:26:15 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 4E3AB80627; Tue, 9 Apr 2013 03:26:15 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp53.itg.ti.com (dflp53.itg.ti.com [128.247.5.6]) by linux.omap.com (Postfix) with ESMTP id 318B380626 for ; Tue, 9 Apr 2013 03:26:13 -0500 (CDT) Received: from red.ext.ti.com (red.ext.ti.com [192.94.93.37]) by dflp53.itg.ti.com (8.13.8/8.13.8) with ESMTP id r398QDrD005177 for ; Tue, 9 Apr 2013 03:26:13 -0500 (CDT) Received: from mail6.bemta7.messagelabs.com (mail6.bemta7.messagelabs.com [216.82.255.55]) by red.ext.ti.com (8.13.7/8.13.7) with ESMTP id r398QCtS020557 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Apr 2013 03:26:12 -0500 Received: from [216.82.253.147:52300] by server-13.bemta-7.messagelabs.com id C7/8B-22723-4A0D3615; Tue, 09 Apr 2013 08:26:12 +0000 X-Env-Sender: ohad@wizery.com X-Msg-Ref: server-6.tower-165.messagelabs.com!1365495969!10790035!1 X-Originating-IP: [209.85.215.47] X-SpamReason: No, hits=0.3 required=7.0 tests=RCVD_BY_IP X-StarScan-Received: X-StarScan-Version: 6.8.6.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23085 invoked from network); 9 Apr 2013 08:26:11 -0000 Received: from mail-la0-f47.google.com (HELO mail-la0-f47.google.com) (209.85.215.47) by server-6.tower-165.messagelabs.com with RC4-SHA encrypted SMTP; 9 Apr 2013 08:26:11 -0000 Received: by mail-la0-f47.google.com with SMTP id fj20so6216220lab.34 for ; Tue, 09 Apr 2013 01:26:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-originating-ip:in-reply-to:references :from:date:message-id:subject:to:cc:content-type:x-gm-message-state; bh=thZ7iUzRRntzkiL79IvWijueq/bl/gR1DvsYkv+j1wk=; b=h+Citt3/Yli67y6ZpJtcXsFhiHUmWX+ZXp1oW/qT+h8byr6qhw87D/mzs4zl6Q271n lMybaJIJv60cLxhPTqR9mi6Dkqnf6SLU8fL5hTPiaAwrHuGp9PSTsTOVvkAC9wQU4GFA /LK1YMi80Vl6NqFRaHGXo9o162EKok3KXbQMneRGg3vZmMdmnZdgPhdKfYrlQVQcjo2I j4R729NBTeVHDWxUzyJgJto2BgOfu/0QgnqrMKzX6SHX2Vm9kv/wKM7jdxRvd6eLADGk BWuD7tpKCxNzamUdTwuT9yKiPibefRxt89YC7trNJ9WHsbwJ8+/jTGVYli2q+CTwBfGT nJIQ== X-Received: by 10.112.150.34 with SMTP id uf2mr11361566lbb.1.1365495966735; Tue, 09 Apr 2013 01:26:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.100.39 with HTTP; Tue, 9 Apr 2013 01:25:46 -0700 (PDT) X-Originating-IP: [85.250.125.78] In-Reply-To: <13514BD7FAEBA745BBD7D8A672905C1431230345@DFLE12.ent.ti.com> References: <1364521307-1219-1-git-send-email-rtivy@ti.com> <1364521307-1219-2-git-send-email-rtivy@ti.com> <13514BD7FAEBA745BBD7D8A672905C1431230345@DFLE12.ent.ti.com> From: Ohad Ben-Cohen Date: Tue, 9 Apr 2013 11:25:46 +0300 Message-ID: Subject: Re: [PATCH v9 1/6] rpmsg: Process all available messages in virtqueue callback To: "Tivy, Robert" X-Gm-Message-State: ALoCoQmNcDQXiXb4FBuYDQ3u2Wjg6IYRnLwyYjXHLJ2tM/sDPv03PYUBO6X9DCnPM6tEM/69CmCN CC: davinci-linux-open-source , linux-arm 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 On Tue, Apr 9, 2013 at 1:56 AM, Tivy, Robert wrote: > Shouldn't the virtqueue_kick() be called only when we successfully added a buffer with virtqueue_add_buf()? Definitely, thanks for noticing! Take 2: > Thanks for the rewrite, looks better. I'll give it a try and let you know how it goes. Thanks! Ohad. Acked-by: Robert Tivy diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index a59684b..4ade672 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -776,22 +776,11 @@ out: } EXPORT_SYMBOL(rpmsg_send_offchannel_raw); -/* called when an rx buffer is used, and it's time to digest a message */ -static void rpmsg_recv_done(struct virtqueue *rvq) +static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, + struct rpmsg_hdr *msg, unsigned int len) { - struct rpmsg_hdr *msg; - unsigned int len; struct rpmsg_endpoint *ept; struct scatterlist sg; - struct virtproc_info *vrp = rvq->vdev->priv; - struct device *dev = &rvq->vdev->dev; - int err; - - msg = virtqueue_get_buf(rvq, &len); - if (!msg) { - dev_err(dev, "uhm, incoming signal, but no used buffer ?\n"); - return; - } dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n", msg->src, msg->dst, msg->len, @@ -806,7 +795,7 @@ static void rpmsg_recv_done(struct virtqueue *rvq) 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; + return -EINVAL; } /* use the dst addr to fetch the callback of the appropriate user */ @@ -842,11 +831,42 @@ static void rpmsg_recv_done(struct virtqueue *rvq) 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 err; + } + + return 0; +} + +/* called when an rx buffer is used, and it's time to digest a message */ +static void rpmsg_recv_done(struct virtqueue *rvq) +{ + struct virtproc_info *vrp = rvq->vdev->priv; + struct device *dev = &rvq->vdev->dev; + struct rpmsg_hdr *msg; + unsigned int len, msgs_received = 0; + int err; + + msg = virtqueue_get_buf(rvq, &len); + if (!msg) { + dev_err(dev, "uhm, incoming signal, but no used buffer ?\n"); return; } + while (msg) { + err = rpmsg_recv_single(vrp, dev, msg, len); + if (err) + break; + + msgs_received++; + + msg = virtqueue_get_buf(rvq, &len); + }; + + dev_dbg(dev, "Received %u messages\n", msgs_received); + /* tell the remote processor we added another available rx buffer */ - virtqueue_kick(vrp->rvq); + if (msgs_received) + virtqueue_kick(vrp->rvq); } /*