From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C60BDA04C0; Fri, 25 Sep 2020 14:32:05 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 90EDF1E95B; Fri, 25 Sep 2020 14:31:39 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by dpdk.org (Postfix) with ESMTP id 880E61E92A for ; Fri, 25 Sep 2020 14:31:34 +0200 (CEST) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601037094; 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=QG9jH8n9xj3YeXOSvK5pKQeyMF0mQQKtGFV+3WIca/c=; b=G1rh7U8lKfjtq/jEjrdELI9t33/w+zJo/yU+scHLHMPzrL++cl8z7JIqBgs4qe0wEIF/Sy Hb/llYHleIHI5F2Dyk9otfoEltb8CrRn5gEONA0PM3awdFsL3AqoQAJKcasSDE0ksKv2v8 0IN3RDLYYPq1zF3uSDVkhDf+sfi9bP8= 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-518-KwVUo9MSN1ykqIgmSap0xw-1; Fri, 25 Sep 2020 08:31:32 -0400 X-MC-Unique: KwVUo9MSN1ykqIgmSap0xw-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 60126186DD2C; Fri, 25 Sep 2020 12:31:31 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7660978810; Fri, 25 Sep 2020 12:31:29 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, patrick.fu@intel.com, amorenoz@redhat.com Cc: Maxime Coquelin Date: Fri, 25 Sep 2020 14:31:09 +0200 Message-Id: <20200925123113.68916-5-maxime.coquelin@redhat.com> In-Reply-To: <20200925123113.68916-1-maxime.coquelin@redhat.com> References: <20200925123113.68916-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH v2 4/8] net/virtio: introduce Vhost-vDPA backend type 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" Backend type is determined by checking char-device major numbers Signed-off-by: Maxime Coquelin Signed-off-by: Adrian Moreno --- .../net/virtio/virtio_user/virtio_user_dev.h | 1 + drivers/net/virtio/virtio_user_ethdev.c | 48 +++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h index 575bf430c0..1c8c98b1cd 100644 --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h @@ -14,6 +14,7 @@ enum virtio_user_backend_type { VIRTIO_USER_BACKEND_UNKNOWN, VIRTIO_USER_BACKEND_VHOST_USER, VIRTIO_USER_BACKEND_VHOST_KERNEL, + VIRTIO_USER_BACKEND_VHOST_VDPA, }; struct virtio_user_queue { diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 7bf065f34b..3a51afd711 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -6,7 +6,9 @@ #include #include #include +#include #include +#include #include #include @@ -519,17 +521,55 @@ get_integer_arg(const char *key __rte_unused, return -errno; } +static uint32_t +vdpa_dynamic_major_num(void) +{ + FILE *fp; + char *line = NULL; + size_t size; + char name[11]; + bool found = false; + uint32_t num; + + fp = fopen("/proc/devices", "r"); + if (fp == NULL) { + PMD_INIT_LOG(ERR, "Cannot open /proc/devices: %s", + strerror(errno)); + return UNNAMED_MAJOR; + } + + while (getline(&line, &size, fp) > 0) { + char *stripped = line + strspn(line, " "); + if ((sscanf(stripped, "%u %10s", &num, name) == 2) && + (strncmp(name, "vhost-vdpa", 10) == 0)) { + found = true; + break; + } + } + fclose(fp); + return found ? num : UNNAMED_MAJOR; +} + static enum virtio_user_backend_type virtio_user_backend_type(const char *path) { struct stat sb; - if (stat(path, &sb) == -1) + if (stat(path, &sb) == -1) { + PMD_INIT_LOG(ERR, "Stat fails: %s (%s)\n", path, + strerror(errno)); return VIRTIO_USER_BACKEND_UNKNOWN; + } - return S_ISSOCK(sb.st_mode)? - VIRTIO_USER_BACKEND_VHOST_USER : - VIRTIO_USER_BACKEND_VHOST_KERNEL; + if (S_ISSOCK(sb.st_mode)) { + return VIRTIO_USER_BACKEND_VHOST_USER; + } else if (S_ISCHR(sb.st_mode)) { + if (major(sb.st_rdev) == MISC_MAJOR) + return VIRTIO_USER_BACKEND_VHOST_KERNEL; + if (major(sb.st_rdev) == vdpa_dynamic_major_num()) + return VIRTIO_USER_BACKEND_VHOST_VDPA; + } + return VIRTIO_USER_BACKEND_UNKNOWN; } static struct rte_eth_dev * -- 2.26.2