From mboxrd@z Thu Jan 1 00:00:00 1970 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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5DA96C433F5 for ; Fri, 22 Apr 2022 09:07:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0EBDA82DD7; Fri, 22 Apr 2022 11:07:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="I7v/IOPX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B3D4983D39; Fri, 22 Apr 2022 11:07:53 +0200 (CEST) Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C958981DD3 for ; Fri, 22 Apr 2022 11:07:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bmeng.cn@gmail.com Received: by mail-yb1-xb30.google.com with SMTP id w20so7151898ybi.8 for ; Fri, 22 Apr 2022 02:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EuzrIlSfpF5pEsQr6bIz6BoTTCnPj9b2UPs9DLYm4wg=; b=I7v/IOPXCYD8j+XQIaMR0RcC7mtVdsyQHniiKH3Qypbznn6f+7oWtSbWhjXiokotgf VFcGBKKadSjtWAYS/V931R850zCRkdE4QY9Mvt3pN6QpDxNV0nse2JOdpa7zh8pu2UAs lZiwedhPGebuiZzGLWLu6GMHnRKAeVJNi1sZI2irJd0ZlmrcsIkaa4Q3eqLzStPrC1b6 9PUxwTYThkTvslw6y+IA9H7MYvRA/OnE0t45c0Oft1sIL9LD5WXT1QMXWIkkLboDDdmF gm6py6hLQ4hUhxRXiOX2k73xH9lz7fZ4GGaT1YP3aPs35GFs0JpXqg6uJH9mR8TU+IHZ 8nBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EuzrIlSfpF5pEsQr6bIz6BoTTCnPj9b2UPs9DLYm4wg=; b=v6e/Aenq+b0mLYCPsWR/lHVbNd1C4fn/an3GDKfZrhjIzlFC7vUNdmLLYNu0tgUQVW HrYtXyipZI9S6B3QkizpMKr2jcyHKHCq94QxPSpWWPHssEivOZ6kmJYtJ0Lt3YTFT1KE oWJQBQb0iN2uDtHW9pzT4er4dX29xt3mqLgph91mujddF2iv+PL9s/HitAQydtLB6FUX 4BJeWTt/Y4iNBsm069rvXjVu+2n71amKa37CVLV3SVZxSIcDKTSGcJytGW2psglQyrB+ QXW0L8SrJtGUTLhJFV4ne2samX57ovK9QO43aiB99EBNXpV8XqsGKrpK2MQBmYxpkjxF M2WQ== X-Gm-Message-State: AOAM532dqZzfMCDk8grPWTkuFksoeIWTa+N/jLm7+jDdo8rn03XVzpEV iBNimh6EhknrGNvxa0OY43sDw62ZshBXMhS2fwI= X-Google-Smtp-Source: ABdhPJwPKV6ssft9EDP4/1+Zyj3jKAxpXkMSQINGgAD3yDXcQ5vMCBDuzNjes1JpszUgi9US/PZLT64SiB30mQ6dCJw= X-Received: by 2002:a05:6902:10c1:b0:63c:d3bf:59d2 with SMTP id w1-20020a05690210c100b0063cd3bf59d2mr3379785ybu.99.1650618469710; Fri, 22 Apr 2022 02:07:49 -0700 (PDT) MIME-Version: 1.0 References: <20220413142137.560987-1-ascull@google.com> <20220413142137.560987-3-ascull@google.com> In-Reply-To: <20220413142137.560987-3-ascull@google.com> From: Bin Meng Date: Fri, 22 Apr 2022 17:07:38 +0800 Message-ID: Subject: Re: [PATCH v2 02/12] virtio_ring: Add helper to attach vring descriptor To: Andrew Scull Cc: U-Boot Mailing List , Simon Glass , Tom Rini Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On Wed, Apr 13, 2022 at 10:22 PM Andrew Scull wrote: > > Move the logic for attaching a descriptor to its own function. > > Signed-off-by: Andrew Scull > Reviewed-by: Simon Glass > --- > drivers/virtio/virtio_ring.c | 30 +++++++++++++++--------------- > 1 file changed, 15 insertions(+), 15 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index a6922ce1b8..8e0cb3d666 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -16,6 +16,18 @@ > #include > #include > > +static unsigned int virtqueue_attach_desc(struct virtqueue *vq, unsigned int i, > + struct virtio_sg *sg, u16 flags) > +{ > + struct vring_desc *desc = &vq->vring.desc[i]; > + > + desc->addr = cpu_to_virtio64(vq->vdev, (u64)(uintptr_t)sg->addr); > + desc->len = cpu_to_virtio32(vq->vdev, sg->length); > + desc->flags = cpu_to_virtio16(vq->vdev, flags); > + > + return virtio16_to_cpu(vq->vdev, desc->next); > +} > + > int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[], > unsigned int out_sgs, unsigned int in_sgs) > { > @@ -45,26 +57,14 @@ int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[], > } > > for (n = 0; n < out_sgs; n++) { > - struct virtio_sg *sg = sgs[n]; > - > - desc[i].flags = cpu_to_virtio16(vq->vdev, VRING_DESC_F_NEXT); > - desc[i].addr = cpu_to_virtio64(vq->vdev, (u64)(size_t)sg->addr); > - desc[i].len = cpu_to_virtio32(vq->vdev, sg->length); > - > prev = i; > - i = virtio16_to_cpu(vq->vdev, desc[i].next); > + i = virtqueue_attach_desc(vq, i, sgs[n], VRING_DESC_F_NEXT); > } > for (; n < (out_sgs + in_sgs); n++) { > - struct virtio_sg *sg = sgs[n]; > - > - desc[i].flags = cpu_to_virtio16(vq->vdev, VRING_DESC_F_NEXT | > - VRING_DESC_F_WRITE); > - desc[i].addr = cpu_to_virtio64(vq->vdev, > - (u64)(uintptr_t)sg->addr); > - desc[i].len = cpu_to_virtio32(vq->vdev, sg->length); > + u16 flags = VRING_DESC_F_NEXT | VRING_DESC_F_WRITE; > > prev = i; > - i = virtio16_to_cpu(vq->vdev, desc[i].next); > + i = virtqueue_attach_desc(vq, i, sgs[n], flags); The above 2 for loops can be further merged into one loop: u16 flags = VRING_DESC_F_NEXT; for (n = 0; n < (out_sgs + in_sgs); n++) { if (n >= out_sgs) flags |= VRING_DESC_F_WRITE; prev = i; i = virtqueue_attach_desc(vq, i, sgs[n], flags); } > } > /* Last one doesn't continue */ > desc[prev].flags &= cpu_to_virtio16(vq->vdev, ~VRING_DESC_F_NEXT); Regards, Bin