Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13624563pxu; Sun, 3 Jan 2021 23:01:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRDX6JymoY5FQo5NOei971s0eAIGE5+DBQEv6zL0Jy9KlkXYdi7nlJMZOsjU4Ibgdc7v3y X-Received: by 2002:a17:906:56ca:: with SMTP id an10mr65742836ejc.498.1609743693248; Sun, 03 Jan 2021 23:01:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609743693; cv=none; d=google.com; s=arc-20160816; b=0ypDLlVNkW1scrylvIOT0r+XSeUtjE+X5U3hxaPOryC70YZ4yezmENZWPJFJ+vR88K ojjYh37kezGIR+78MwQGGsNT4AGkRFve6mDSSQVrc4fWDFQzz35TYfoN0SPoezr0J0/Z cLu1cgKwUF8tC/4qQfeeH5ERjInsCdLw6nPrGCbIEQBkewqm5qq4Zn4yy/x24Nc6pPh0 EM/maSUjMkGr9Fc0+mPbxm4EiPFCKPisihUkdS3uu/lwiRV0+iBfEwGUsbgkvJVzeAx4 J9krnpyvROYkf5d6rpog6pQ8bSOrS0mTErLOAGVURS1ZnrZokqjKXqyRxBKXErcF2MYo XUTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z64b5COMNLfzQJNVeb0d9/TazIFH39UCgArmmEFKpMo=; b=cKKfdUAD1wcAf0EWSxqZMLoX8dyMbz88OR0Pd9Q9RX+X2sn/1bZ/Hgrmp6ul92tt1X SRSEE7s/H4grJ1iuVZxUhpJUqGEIJD1T9HAW5x9eyoQqAkHFCvu4vN+O3RGI6IzoJWeu CgQYWg7JI8UeewcVAqSQ7SAMciwqXNrS8ujDau3937Q1dxgMU9ZseaZR6YUwvPlZ94bB ZELwxeQfACw7inkB6Fa15WMr3u5/KL0/KrBMNQ7A4U8R3PBWuZpCK2yfamvMr4CB6O7g Yyt+8KPMt7TJCwsBnT6dIXfd+qsUCrgd2ZT3Hj4xbAYbYo0OLlesUN0HaCM3fghWhSlG izeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Voi80hIs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ca26si28217819ejb.622.2021.01.03.23.01.10; Sun, 03 Jan 2021 23:01:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Voi80hIs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728230AbhADG5X (ORCPT + 99 others); Mon, 4 Jan 2021 01:57:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43087 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728180AbhADG5X (ORCPT ); Mon, 4 Jan 2021 01:57:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609743356; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z64b5COMNLfzQJNVeb0d9/TazIFH39UCgArmmEFKpMo=; b=Voi80hIsgzLikx/W8u7PxPof0HS5+h01ZggzhCKQ9xwGdnTOmNw/jix7ZwoHcL2pnwkN1g k7fewT3gfJ/rECUxdkgbr/834Kk0GYWh1FrwTqfI0GxxGlztVj+ndr9SeuXg/dBVgocfRF mpZ9H5U/M7QnLzoDNBKE12H76JWGqDk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-nBaavWo7Pu6Z_nsYskvdxw-1; Mon, 04 Jan 2021 01:55:55 -0500 X-MC-Unique: nBaavWo7Pu6Z_nsYskvdxw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0B603180A087; Mon, 4 Jan 2021 06:55:54 +0000 (UTC) Received: from jason-ThinkPad-X1-Carbon-6th.redhat.com (ovpn-13-91.pek2.redhat.com [10.72.13.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DE931002388; Mon, 4 Jan 2021 06:55:51 +0000 (UTC) From: Jason Wang To: mst@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: shahafs@mellanox.com, lulu@redhat.com, sgarzare@redhat.com, rdunlap@infradead.org, Jason Wang Subject: [PATCH V3 11/19] virtio-pci-modern: introduce helper to set/get queue_enable Date: Mon, 4 Jan 2021 14:54:55 +0800 Message-Id: <20210104065503.199631-12-jasowang@redhat.com> In-Reply-To: <20210104065503.199631-1-jasowang@redhat.com> References: <20210104065503.199631-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces a helper to set/get queue_enable for modern device. Signed-off-by: Jason Wang --- drivers/virtio/virtio_pci_modern.c | 37 +++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c index 05b21e18f46c..0e62820b83ff 100644 --- a/drivers/virtio/virtio_pci_modern.c +++ b/drivers/virtio/virtio_pci_modern.c @@ -234,6 +234,34 @@ static void vp_modern_queue_address(struct virtio_pci_modern_device *mdev, &cfg->queue_used_hi); } +/* + * vp_modern_set_queue_enable - enable a virtqueue + * @mdev: the modern virtio-pci device + * @index: the queue index + * @enable: whether the virtqueue is enable or not + */ +static void vp_modern_set_queue_enable(struct virtio_pci_modern_device *mdev, + u16 index, bool enable) +{ + vp_iowrite16(index, &mdev->common->queue_select); + vp_iowrite16(enable, &mdev->common->queue_enable); +} + +/* + * vp_modern_get_queue_enable - enable a virtqueue + * @mdev: the modern virtio-pci device + * @index: the queue index + * + * Returns whether a virtqueue is enabled or not + */ +static bool vp_modern_get_queue_enable(struct virtio_pci_modern_device *mdev, + u16 index) +{ + vp_iowrite16(index, &mdev->common->queue_select); + + return vp_ioread16(&mdev->common->queue_enable); +} + /* virtio config->finalize_features() implementation */ static int vp_finalize_features(struct virtio_device *vdev) { @@ -460,7 +488,7 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, /* Check if queue is either not available or already active. */ num = vp_ioread16(&cfg->queue_size); - if (!num || vp_ioread16(&cfg->queue_enable)) + if (!num || vp_modern_get_queue_enable(mdev, index)) return ERR_PTR(-ENOENT); if (num & (num - 1)) { @@ -538,7 +566,6 @@ static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned nvqs, struct irq_affinity *desc) { struct virtio_pci_device *vp_dev = to_vp_device(vdev); - struct virtio_pci_common_cfg __iomem *cfg = vp_dev->mdev.common; struct virtqueue *vq; int rc = vp_find_vqs(vdev, nvqs, vqs, callbacks, names, ctx, desc); @@ -548,10 +575,8 @@ static int vp_modern_find_vqs(struct virtio_device *vdev, unsigned nvqs, /* Select and activate all queues. Has to be done last: once we do * this, there's no way to go back except reset. */ - list_for_each_entry(vq, &vdev->vqs, list) { - vp_iowrite16(vq->index, &cfg->queue_select); - vp_iowrite16(1, &cfg->queue_enable); - } + list_for_each_entry(vq, &vdev->vqs, list) + vp_modern_set_queue_enable(&vp_dev->mdev, vq->index, true); return 0; } -- 2.25.1