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 093D4C433EF for ; Mon, 16 May 2022 10:42:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 41F89841A5; Mon, 16 May 2022 12:42:26 +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="X/r/2XPL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 99C9584077; Mon, 16 May 2022 12:42:00 +0200 (CEST) Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) (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 08479832C3 for ; Mon, 16 May 2022 12:41:56 +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=3cyqCYgYKBuoMeOgXXSaaSXQ.OaYg-NaafXUefe.PQZj.PQ@flex--ascull.bounces.google.com Received: by mail-wm1-x349.google.com with SMTP id bi5-20020a05600c3d8500b0039489e1d18dso10144004wmb.5 for ; Mon, 16 May 2022 03:41:56 -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=Piqlz19BEt/W+spE9LlIRsDf0EYzGvCVhwKZ7cETzbM=; b=X/r/2XPLvMKA2fhvZCC6Jg8TN8dGh4iRuQbMeSKErFRFpLHRKLpAyfgoZOG8VDiklB xj7ZXzKOd29ylHZ7Hsjc0lelv+NFt1Whj+IvIfCc/Kk1nLRYuknOm9PIbHnlgqfejBc4 1CElRF6KrMFglT0XG3cUJCZ8Exi9wWGwuJwx+CiCpB3+S9LBlpFOQhNR8rECpKakFMNt bVoHBzUV0FlnPkHFeQe8lSF1UblmDkqQtD3ti9DwuEmreFWfmeFtbBlQQ9At7TAloOeK /sBwtGOpLdXvoIoW5nbxgJR/h9cIm/roPvv2EufStNgBB+4xDT9Mv7X+HRr2hlf2iGf4 0t5A== 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=Piqlz19BEt/W+spE9LlIRsDf0EYzGvCVhwKZ7cETzbM=; b=wVz30oQbm9opJjrvikrcB5EIvNX3VqencZ1FNVnWS07JeX5cMbth9cth/kgTRzs/hm O5W15Kw8kFQ76+FcSWgviX5tR5dKK0Rgkzq0gJNFarGWjjKvX7oiBXLiGJYPhrne5T+F 9FNpm4IRdBjyMpC/+EZx034CfH4acuJG/bnkdt4Ht/WgeDOPeLMGt5ICCDbQ4WEzQVvy C++6GUNcjRZ9IijpeU9mTA3mOJReXx6XmPTvAwBWWo7ogQDCYBPSIuqJPFXjjxiMskyF amWZwydS8CimBuQMLkYWuw7RQp6FkCSSGs8kawEW3t/AgY8G+SYxUs6ceEdDAFsYts0S RZXg== X-Gm-Message-State: AOAM532pdLFazs1/MzLG8qR8xsZ5LHuAfthVv3dc6zopuDWcWEegBOFi h0ObCqIamg1sxshIPrGFaxafZWoH1zW1HdzaqKhPuSbowZTTGQ7VetqUz0D+dKeOM3sND8+0v/z w69M5HhbkJLBMXqJHwaI+Gf0japFOpRIG5/etbRrrU5MvqGrYqh2kl4bdJh8= X-Google-Smtp-Source: ABdhPJzhts3qAy4Dh22g9+SWczH1XireXoVQoSTaXaWx2xCNK7uVrkY1fv8keMrBXf5hXZrBVxFKA6zSEFU= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:35c1:b0:394:8621:a1d5 with SMTP id r1-20020a05600c35c100b003948621a1d5mr26337775wmq.196.1652697715571; Mon, 16 May 2022 03:41:55 -0700 (PDT) Date: Mon, 16 May 2022 10:41:30 +0000 In-Reply-To: <20220516104140.1047229-1-ascull@google.com> Message-Id: <20220516104140.1047229-3-ascull@google.com> Mime-Version: 1.0 References: <20220516104140.1047229-1-ascull@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [PATCH v3 02/12] virtio_ring: Add helper to attach vring descriptor From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, trini@konsulko.com, bmeng.cn@gmail.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 Reviewed-by: Simon Glass --- drivers/virtio/virtio_ring.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index a6922ce1b8..d3fc842f30 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) { @@ -44,27 +56,13 @@ int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[], return -ENOSPC; } - 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); - } - 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); + for (n = 0; n < descs_used; n++) { + u16 flags = VRING_DESC_F_NEXT; + if (n >= out_sgs) + flags |= 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.36.0.550.gb090851708-goog