Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp200522pxj; Tue, 1 Jun 2021 19:16:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqZyg33qwTTAKa2Yn8IVcLi9Eh/PB3zhX4zOMEP8svpzXDj7oAZ4Gr81rLTavPEidGHG46 X-Received: by 2002:a05:6e02:14a:: with SMTP id j10mr4938454ilr.250.1622600195275; Tue, 01 Jun 2021 19:16:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622600195; cv=none; d=google.com; s=arc-20160816; b=kUZ86wF05/FzcbcqEIbv+ps5TuX/vewLsJFs5RMwcIURQmE2bQBwv759CQ4D/4temJ bNwE6h0C913H1VTO1QOyDPA1p7il23M+XcM5lgEc5BhkjXnIa2HHbVR/q+krsN4kdwHB cQaIfZx/magbU68sxPNU6XFBo+wKaS783p6qBd7EILaG3iSSHq2b3qExTGB4AyMO4qx6 jp4EbFUDzk7ii2MUaKz3ERJDt3rx3g0rgWnuiTpDOpq6IF7lXWQlHTl68zH1iCAxb80B 9iSkiykk8nUIFE1Io8PUfeq0ESRFeMX6jGJdlkr+WX3dHxHNiQqzDLfpvxnlPePYnlzT sG9w== 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=HkilwBwFhJtLCkWc/s8f79yGTq+PN2d+n/O8mKBEbHc=; b=Nl4Ca29ALBKtm8ZEhmr0qa4eclPxK20jAALtPIkAW2dGG/+9K507BFeBY9cj4hMd2X 1CNgRrkC/rokp9+DpFXdGiMrEnjn2oc7vVBpE12O3C1XnCgZwVQGe5fIuW1PTdGZokE+ xKO/QOWDsq+fL2gAuZiWhEvDGpJ1yHmDd/z7WeUd6leeaG06+q92T/sAFxH3527FbugY 8jg+RbzG0twlKqdvTAnBW38igo1iHGJI2otGFSzbs/Cl5ZZ1hWBi7wUXlraSULbBcouM IHX9GeV1owS15yJ7n63za81dy8VNMge+HuqEWyb2GvbLGnkNy3fR1msp+Zo/o5bHW6lS N33g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dV0mr90d; 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 k7si14214058ilh.42.2021.06.01.19.16.22; Tue, 01 Jun 2021 19:16:35 -0700 (PDT) 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=dV0mr90d; 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 S230320AbhFBCMn (ORCPT + 99 others); Tue, 1 Jun 2021 22:12:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:51321 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230261AbhFBCMl (ORCPT ); Tue, 1 Jun 2021 22:12:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622599858; 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=HkilwBwFhJtLCkWc/s8f79yGTq+PN2d+n/O8mKBEbHc=; b=dV0mr90d7qcDR3kpYbVDlQvrL+Sw0dFfjjz/5/fo4rSFIbbG5hy5UCk9qLX2K9mKpUqPrL giRVKbLU6uWlF1zlBlu1r8EOpK6ML8G5sFiMg7RaD62eadPoKSEf7wbuODIg0myn3oUDPA ktNt8DiBbiX8He726Q9iDaPkMARM+rk= 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-336-n-HHfwKoPI2rvJFXXLlhRA-1; Tue, 01 Jun 2021 22:10:57 -0400 X-MC-Unique: n-HHfwKoPI2rvJFXXLlhRA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35BA08015F8; Wed, 2 Jun 2021 02:10:56 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-99.pek2.redhat.com [10.72.12.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id C056D5D6CF; Wed, 2 Jun 2021 02:10:53 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, netdev@vger.kernel.org Cc: eli@mellanox.com Subject: [PATCH V2 1/4] vdpa: support packed virtqueue for set/get_vq_state() Date: Wed, 2 Jun 2021 10:10:40 +0800 Message-Id: <20210602021043.39201-2-jasowang@redhat.com> In-Reply-To: <20210602021043.39201-1-jasowang@redhat.com> References: <20210602021043.39201-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch extends the vdpa_vq_state to support packed virtqueue state which is basically the device/driver ring wrap counters and the avail and used index. This will be used for the virito-vdpa support for the packed virtqueue and the future vhost/vhost-vdpa support for the packed virtqueue. Signed-off-by: Jason Wang --- drivers/vdpa/ifcvf/ifcvf_main.c | 4 ++-- drivers/vdpa/mlx5/net/mlx5_vnet.c | 8 ++++---- drivers/vdpa/vdpa_sim/vdpa_sim.c | 4 ++-- drivers/vhost/vdpa.c | 4 ++-- include/linux/vdpa.h | 25 +++++++++++++++++++++++-- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c index ab0ab5cf0f6e..5d3891b1ca28 100644 --- a/drivers/vdpa/ifcvf/ifcvf_main.c +++ b/drivers/vdpa/ifcvf/ifcvf_main.c @@ -264,7 +264,7 @@ static int ifcvf_vdpa_get_vq_state(struct vdpa_device *vdpa_dev, u16 qid, { struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); - state->avail_index = ifcvf_get_vq_state(vf, qid); + state->split.avail_index = ifcvf_get_vq_state(vf, qid); return 0; } @@ -273,7 +273,7 @@ static int ifcvf_vdpa_set_vq_state(struct vdpa_device *vdpa_dev, u16 qid, { struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); - return ifcvf_set_vq_state(vf, qid, state->avail_index); + return ifcvf_set_vq_state(vf, qid, state->split.avail_index); } static void ifcvf_vdpa_set_vq_cb(struct vdpa_device *vdpa_dev, u16 qid, diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c index 189e4385df40..e5505d760bca 100644 --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c @@ -1427,8 +1427,8 @@ static int mlx5_vdpa_set_vq_state(struct vdpa_device *vdev, u16 idx, return -EINVAL; } - mvq->used_idx = state->avail_index; - mvq->avail_idx = state->avail_index; + mvq->used_idx = state->split.avail_index; + mvq->avail_idx = state->split.avail_index; return 0; } @@ -1449,7 +1449,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device *vdev, u16 idx, struct vdpa * Since both values should be identical, we take the value of * used_idx which is reported correctly. */ - state->avail_index = mvq->used_idx; + state->split.avail_index = mvq->used_idx; return 0; } @@ -1458,7 +1458,7 @@ static int mlx5_vdpa_get_vq_state(struct vdpa_device *vdev, u16 idx, struct vdpa mlx5_vdpa_warn(mvdev, "failed to query virtqueue\n"); return err; } - state->avail_index = attr.used_index; + state->split.avail_index = attr.used_index; return 0; } diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 98f793bc9376..14e024de5cbf 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -374,7 +374,7 @@ static int vdpasim_set_vq_state(struct vdpa_device *vdpa, u16 idx, struct vringh *vrh = &vq->vring; spin_lock(&vdpasim->lock); - vrh->last_avail_idx = state->avail_index; + vrh->last_avail_idx = state->split.avail_index; spin_unlock(&vdpasim->lock); return 0; @@ -387,7 +387,7 @@ static int vdpasim_get_vq_state(struct vdpa_device *vdpa, u16 idx, struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx]; struct vringh *vrh = &vq->vring; - state->avail_index = vrh->last_avail_idx; + state->split.avail_index = vrh->last_avail_idx; return 0; } diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index fb41db3da611..210ab35a7ebf 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -383,7 +383,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, if (r) return r; - vq->last_avail_idx = vq_state.avail_index; + vq->last_avail_idx = vq_state.split.avail_index; break; } @@ -401,7 +401,7 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd, break; case VHOST_SET_VRING_BASE: - vq_state.avail_index = vq->last_avail_idx; + vq_state.split.avail_index = vq->last_avail_idx; if (ops->set_vq_state(vdpa, idx, &vq_state)) r = -EINVAL; break; diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h index f311d227aa1b..3357ac98878d 100644 --- a/include/linux/vdpa.h +++ b/include/linux/vdpa.h @@ -28,13 +28,34 @@ struct vdpa_notification_area { }; /** - * struct vdpa_vq_state - vDPA vq_state definition + * struct vdpa_vq_state_split - vDPA split virtqueue state * @avail_index: available index */ -struct vdpa_vq_state { +struct vdpa_vq_state_split { u16 avail_index; }; +/** + * struct vdpa_vq_state_packed - vDPA packed virtqueue state + * @last_avail_counter: last driver ring wrap counter observed by device + * @last_avail_idx: device available index + * @last_used_counter: device ring wrap counter + * @last_used_idx: used index + */ +struct vdpa_vq_state_packed { + u16 last_avail_counter:1; + u16 last_avail_idx:15; + u16 last_used_counter:1; + u16 last_used_idx:15; +}; + +struct vdpa_vq_state { + union { + struct vdpa_vq_state_split split; + struct vdpa_vq_state_packed packed; + }; +}; + struct vdpa_mgmt_dev; /** -- 2.25.1