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 6F0C3C433F5 for ; Thu, 31 Mar 2022 10:10:37 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7F142841FB; Thu, 31 Mar 2022 12:10:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.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=google.com header.i=@google.com header.b="pTLJELFR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CD8CC841F0; Thu, 31 Mar 2022 12:10:09 +0200 (CEST) Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) (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 A4438841F2 for ; Thu, 31 Mar 2022 12:10:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3-n1FYgYKBiUBTDVMMHPPHMF.DPNV-CPPUMJTUT.EFOY.EF@flex--ascull.bounces.google.com Received: by mail-wm1-x34a.google.com with SMTP id 84-20020a1c0257000000b0038124c99ebcso9218809wmc.9 for ; Thu, 31 Mar 2022 03:10:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=RU+FgWmWk1Pq78WTLjNZR84wsVZUV0At3Zj/BIgDuAE=; b=pTLJELFRF53Huh/2qhDfPzv2J44dUgs4bQPXQ0DJjpcs9h+JEs4kHDjS2Q/wIKTefO diyzKSwkZISHWIsUgh/E1VyUmfGdhHYo7w8+putZAUrSyo/wa+G3oP+P4Rw0hQ9ZkNJt TZkmKOmI9B+lD+0IweC7/8SjvcKunLrz8lT4hBNXuGpPDiA0mBy8XEyLjgex1Q+AwnVi uJguOFB+4hZo5gfEa1cDn/Ey5XCwNTV92bx+iJXeKEB6p4mQg5zvLYYB3/YxJa3P1AyT NQywbTJLDaAuVISduGds6qS5R6P5UdKUlSCAu3EqgvjAYrMdAeSqzTHf+8+GGoEtpx4l 4kGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=RU+FgWmWk1Pq78WTLjNZR84wsVZUV0At3Zj/BIgDuAE=; b=kFxCMX30Xyh3DeT/514kK4lQz+5uM3d0L1Rbq+KQyyzv8FL2Y0uODBs/JYAJwVAYzU /FwINppMSZ2ia6Aqvg8dtRNIqVZzkwxfipT+B7efL/mpdAEr7TCYYggCZs9b/JNv+9VY I46MjDsVlVUfS4wuhNVX4WSQjop+vVA+hxdaf3iUjwOAABPyTG5Z1HvuqfuJKof/cx0I dSTfvRCn36cFKwFxniCJy0G55WFd4JNQFTb+TVHBVy+smGoLm8/fm4m+MjqEMUAhYtBd ewjttGh9Mz4g3yyvN3xAKuyAvlaFs9E/hnjj/Xxvnc8ZLQgETG2uqP4R2Tm+d/U8l+fJ mM3w== X-Gm-Message-State: AOAM532TatrFgnQX+FYwDdJyXyJp8a2accjWd7MyY2DD7iMNkm9fu4m3 +vV1ErYCkrhR4qVHa/eXL59Wp6Ws3KvAODb3zJ46zkxgMUQBBfk11P8KUQqxG9Wh77BHuTYzxWt 7RABu4Et/L4Xs/lAZPnA3vSU12MczDx7otLC3JCczQSGn8630Xn7+M52n9sg= X-Google-Smtp-Source: ABdhPJzwO3MpEFLLuHTZMS2CJEL3rm0NFOhN7hJ8cHMjMyj3ITaRpX2EwsrGogrHDHpVoN1Zgu3wfMMNUCs= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:a45:b0:346:5e67:cd54 with SMTP id c5-20020a05600c0a4500b003465e67cd54mr4198582wmq.127.1648721402166; Thu, 31 Mar 2022 03:10:02 -0700 (PDT) Date: Thu, 31 Mar 2022 10:09:40 +0000 In-Reply-To: <20220331100949.3637425-1-ascull@google.com> Message-Id: <20220331100949.3637425-3-ascull@google.com> Mime-Version: 1.0 References: <20220331100949.3637425-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH 02/11] virtio_ring: Add helper to attach vring descriptor From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, bmeng.cn@gmail.com, adelva@google.com, keirf@google.com, ptosi@google.com, Andrew Scull 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 Move the logic for attaching a descriptor to its own function. Signed-off-by: Andrew Scull --- 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); } /* Last one doesn't continue */ desc[prev].flags &= cpu_to_virtio16(vq->vdev, ~VRING_DESC_F_NEXT); -- 2.35.1.1094.g7c7d902a7c-goog