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 4F7F0C433F5 for ; Wed, 13 Apr 2022 14:22:07 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1D1F383C97; Wed, 13 Apr 2022 16:21:54 +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="AsHCeVrU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5DC4B83D62; Wed, 13 Apr 2022 16:21:51 +0200 (CEST) Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) (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 DBF6083D44 for ; Wed, 13 Apr 2022 16:21:48 +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=3fNxWYgYKBqkJbLdUUPXXPUN.LXVd-KXXcURbcb.MNWg.MN@flex--ascull.bounces.google.com Received: by mail-wr1-x44a.google.com with SMTP id c17-20020a5d6cd1000000b00207a6974951so419242wrc.1 for ; Wed, 13 Apr 2022 07:21:48 -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=8TseOqwB4+NqzhtoORXTLYSiEuKf3zCsMRmnn7r8vN8=; b=AsHCeVrU50T8Utx/oDtZGkOn+tSy8OMKzoqAgCvbrxiDPGK5ua2KOZupUrI/2wX/qg uGgHLsZwiydb2GIy3UWvhiuIreyPeBaPrJ2C8/S/PH1HhDU7qWsXTcWtUHnLctP43avj oIg9305rBXQOG/+zUDl/qA723e8HzoFr9r4Yj2zwo39xsdbcwkORr7qtG9zZzxiekB3w Jie0cVdkfMOP6VzeBjHNqqYGDMZxFyTyxWfuf4zzZoqBMa7/OmvcVYMbQ0l5K4Dk/F/u OE/IeJvbyL2Ec0oy8Lj/6HXIC91k/PknMlpvkhOlyOHuPGvLBvV+BZZFNX3gXkb9WTTH 3AyQ== 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=8TseOqwB4+NqzhtoORXTLYSiEuKf3zCsMRmnn7r8vN8=; b=4IBQQLyLBi+v8+PCdQp35y8kXN36KpPR8P8xOniZkSRwW2kXeyKjwuQg/ssFaCzqul mMho0VlQwCJ34J9TEvR7k2tGwaB+wzUFjAm2Cwl2AA/IW2trLmP1OYjkPwTJcuRsCkNu s9VLc34IrtnUDBoH9vHt+A/t2XKjzJa8MuKp2SCraw49LNLqynXEGN9eJZqHVpzfTb0G eSGsgcJ1cHd+sqS6QgtdQDAzP9UoEHt1wVE6b1AVzbmZcOevQ4XVuakNBS45XF5PmLXD FOW1RYX31tkLH4CARU480EWFHUmNqDlZbp/jCOGpQRZphckaS2jiC6x7G6HOFOhY+1x1 +zNg== X-Gm-Message-State: AOAM5324ySySK3xFe6wyteJlnD3zUDYYV/J5UhxnVZwVvp0fIfdlYc/C IiRx/pwuhUoEMHopHQObF+kXJV7gXINCzFFrYZW68z7HhUwUtgVMRKewsGmi1JUeQo512u3sP4E E0/jaDfuA5RXaLAqbdN7Omgol4ReA+MLN87qbsXLXHpAQTIhka1VzeJUPfsg= X-Google-Smtp-Source: ABdhPJwUQTpP/MhGkMdC7TLjvWUbCTlWmIOzVV814S4K7XwD9FzLMpl4ZQ2AReEq+iomnJAwUD0O6noEjPU= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:3492:b0:38e:d3ea:9ae3 with SMTP id a18-20020a05600c349200b0038ed3ea9ae3mr3708455wmq.174.1649859708440; Wed, 13 Apr 2022 07:21:48 -0700 (PDT) Date: Wed, 13 Apr 2022 14:21:27 +0000 In-Reply-To: <20220413142137.560987-1-ascull@google.com> Message-Id: <20220413142137.560987-3-ascull@google.com> Mime-Version: 1.0 References: <20220413142137.560987-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH v2 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, 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 | 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.1178.g4f1659d476-goog