From patchwork Tue Aug 4 07:24:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Moreno X-Patchwork-Id: 75171 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C4C9EA053A; Tue, 4 Aug 2020 09:25:19 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8D2091C033; Tue, 4 Aug 2020 09:24:55 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 79E5C1C020 for ; Tue, 4 Aug 2020 09:24:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596525893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FoblptbJdpQYQVYThfQgTL3YNEIpS+fcbevTayrYMl8=; b=GHzc4zfJFrBcHo+ittSZtbNeBXElVxN+4eGxK+bqAjDkdPnC9WU+xKJhlIEPjo9wYsKfE1 9zcLO9orLOzMB9+2EQAKrLscyBxdDr2UHQ5k7wUg3ZZ2SaSMKQ/iDKB31tjqcmEz5rJaP/ ROO7GbupPXiBRNrPOPzSNnr8MUKyExc= 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-484-AQ-BBadxOrezor3Epumwow-1; Tue, 04 Aug 2020 03:24:51 -0400 X-MC-Unique: AQ-BBadxOrezor3Epumwow-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 706AC8015F4; Tue, 4 Aug 2020 07:24:50 +0000 (UTC) Received: from amorenoz.users.ipa.redhat.com (ovpn-113-91.ams2.redhat.com [10.36.113.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C9D87852C; Tue, 4 Aug 2020 07:24:48 +0000 (UTC) From: Adrian Moreno To: dev@dpdk.org Cc: zhihong.wang@intel.com, chenbo.xia@intel.com, maxime.coquelin@redhat.com, Adrian Moreno Date: Tue, 4 Aug 2020 09:24:30 +0200 Message-Id: <20200804072431.86441-4-amorenoz@redhat.com> In-Reply-To: <20200804072431.86441-1-amorenoz@redhat.com> References: <20200804072431.86441-1-amorenoz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 3/4] net/virtio: add GET_STATUS support to virtio-user X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds support for VHOST_USER_GET_STATUS request. Only vhost-user backed is supported for now Signed-off-by: Adrian Moreno --- drivers/net/virtio/virtio_user/vhost_user.c | 2 + .../net/virtio/virtio_user/virtio_user_dev.c | 42 +++++++++++++++++++ .../net/virtio/virtio_user/virtio_user_dev.h | 1 + drivers/net/virtio/virtio_user_ethdev.c | 2 + 4 files changed, 47 insertions(+) diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c index 337e51199..12b6c7dbc 100644 --- a/drivers/net/virtio/virtio_user/vhost_user.c +++ b/drivers/net/virtio/virtio_user/vhost_user.c @@ -279,6 +279,7 @@ vhost_user_sock(struct virtio_user_dev *dev, switch (req) { case VHOST_USER_GET_FEATURES: case VHOST_USER_GET_PROTOCOL_FEATURES: + case VHOST_USER_GET_STATUS: need_reply = 1; break; @@ -373,6 +374,7 @@ vhost_user_sock(struct virtio_user_dev *dev, switch (req) { case VHOST_USER_GET_FEATURES: + case VHOST_USER_GET_STATUS: case VHOST_USER_GET_PROTOCOL_FEATURES: if (msg.size != sizeof(m.payload.u64)) { PMD_DRV_LOG(ERR, "Received bad msg size"); diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c index 670fc9d40..a5b2d7057 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c @@ -807,3 +807,45 @@ virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status) return 0; } + +int +virtio_user_update_status(struct virtio_user_dev *dev) +{ + uint64_t ret; + int err; + + /* Vhost-user only for now */ + if (!is_vhost_user_by_type(dev->path)) + return 0; + + if (!(dev->protocol_features & (1UL << VHOST_USER_PROTOCOL_F_STATUS))) + return 0; + + err = dev->ops->send_request(dev, VHOST_USER_GET_STATUS, &ret); + if (err) { + PMD_INIT_LOG(ERR, "VHOST_USER_GET_STATUS failed (%d): %s", err, + strerror(errno)); + return -1; + } + if (ret > UINT8_MAX) { + PMD_INIT_LOG(ERR, "Invalid VHOST_USER_GET_STATUS response 0x%" PRIx64 "\n", ret); + return -1; + } + + dev->status = ret; + PMD_INIT_LOG(DEBUG, "Updated Device Status(0x%08x):\n" + "\t-ACKNOWLEDGE: %u\n" + "\t-DRIVER: %u\n" + "\t-DRIVER_OK: %u\n" + "\t-FEATURES_OK: %u\n" + "\t-DEVICE_NEED_RESET: %u\n" + "\t-FAILED: %u\n", + dev->status, + !!(dev->status & VIRTIO_CONFIG_STATUS_ACK), + !!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER), + !!(dev->status & VIRTIO_CONFIG_STATUS_DRIVER_OK), + !!(dev->status & VIRTIO_CONFIG_STATUS_FEATURES_OK), + !!(dev->status & VIRTIO_CONFIG_STATUS_DEV_NEED_RESET), + !!(dev->status & VIRTIO_CONFIG_STATUS_FAILED)); + return 0; +} diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 835ab64ae..9377d5ba6 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -73,4 +73,5 @@ void virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx); uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs); int virtio_user_send_status_update(struct virtio_user_dev *dev, uint8_t status); +int virtio_user_update_status(struct virtio_user_dev *dev); #endif diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 785882e06..87f6cb695 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -280,6 +280,8 @@ virtio_user_get_status(struct virtio_hw *hw) { struct virtio_user_dev *dev = virtio_user_get_dev(hw); + virtio_user_update_status(dev); + return dev->status; }