From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id BE374A0C4B; Sat, 14 Aug 2021 05:36:29 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 466034068F; Sat, 14 Aug 2021 05:36:29 +0200 (CEST) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mails.dpdk.org (Postfix) with ESMTP id 2E5584013F for ; Sat, 14 Aug 2021 05:36:28 +0200 (CEST) Received: by mail-pl1-f179.google.com with SMTP id k2so14442734plk.13 for ; Fri, 13 Aug 2021 20:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uKOujq7TTwTqoheh0g5fz/Og3I3TieCoD5jPtLXmUDs=; b=rEnRhZgsB18OzEuSpVtTWURlkGsS/ZvdY4e+rMD7upKYHNueJ88pbZDZKq+Onv6VUb DDfBi8pZOMb+hNF2u2NGs7pY5SV6SDFsqsCer7Jb5BS82EGjMCVwDSNnTqBFlqUkxTti k87dB+lW7jz6uwafkDi+d8iL5DhcC7mFHL+k9hl/ky8CjvSujRdgIy3sUYKTkfLI6N5O 89Hh+9OuuEBi0cq4orS1pBxbI1D7eAk0f83RKpwmUWPWA9R1ZHM7NYIHm51zHTDtuU/w IYWg+Z4/OyHTbghB31vjli1ESbdaFzZtmkRU4p4kD2k40O2Ozi9JCvlh7nB1DwC8S40S CtPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uKOujq7TTwTqoheh0g5fz/Og3I3TieCoD5jPtLXmUDs=; b=gTgZxowZf2GFRfEIBCVHAdIUmRQILBT7f7X+/9kJjOtGYk8Z7gSPeDaiT4RxEr8cra HEHf7NX/AHWPovhCa6wb+gQsJ1IpFjccWxEk0BxVOo74b8CNs1cThvNjfweBxG9/myy/ PjrJEqN0kk4YfE6jjaCPm7FZR9/BYZ3PtUOBF8Z3JhjmspXsSOShg0+BS2jmsg5l5Ly7 rwF1m+HT/cjUBymO4FBnCI96shKsCXuZfKocpXxjgqGTsaZOyuTw2dxpO8nEymhf4X2w 7aIOtSPVyIUjlUB8DDY9BvwmLFjqA+DuWNxYUieXo1Da2eemW7V+DTdhRytvLyicqRei hBnQ== X-Gm-Message-State: AOAM532znPCusZJEQ3pKAqE5HP8NKBhWwDX7/hZOPxLAcjDZCi+JKqfy J5DF8WwIfJjD6rfmqRneE5QyrUMjr0biCg== X-Google-Smtp-Source: ABdhPJxEy4h19SRCsMVjMlwjlfab9x5b/2p3jzOOfrklLFhn5w6Bn619DieYWHeynXdlgKQp/IDCnQ== X-Received: by 2002:a17:90a:9b13:: with SMTP id f19mr5478714pjp.224.1628912186718; Fri, 13 Aug 2021 20:36:26 -0700 (PDT) Received: from localhost.localdomain (c-67-185-44-206.hsd1.wa.comcast.net. [67.185.44.206]) by smtp.gmail.com with ESMTPSA id n185sm4050359pfn.171.2021.08.13.20.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Aug 2021 20:36:26 -0700 (PDT) From: William Tu To: dev@dpdk.org Cc: Dmitry.Kozliuk@gmail.com Date: Sat, 14 Aug 2021 03:36:09 +0000 Message-Id: <20210814033609.58553-1-u9012063@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH RFC] net/ena: Add Windows support. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" I don't have a physical Windows testbed so I want to see if I can get virtual nic working, in this case ENA driver on AWS. The patch passes build on Windows, but I haven't tested loading the ena driver. I want to know if this is the right direction, or whether I also need to change other places in ENA driver? I copy some of the pthread code from https://nachtimwald.com/2019/04/05/cross-platform-thread-wrapper/ https://stackoverflow.com/questions/10905892/equivalent-of-gettimeday-for-windows Thanks. Signed-off-by: William Tu --- drivers/net/ena/base/ena_com.c | 4 +- drivers/net/ena/base/ena_plat.h | 2 +- drivers/net/ena/base/ena_plat_dpdk.h | 14 +++- drivers/net/ena/meson.build | 5 -- lib/eal/version.map | 2 +- lib/eal/windows/include/pthread.h | 105 ++++++++++++++++++++++++++ lib/eal/windows/include/rte_windows.h | 1 + 7 files changed, 120 insertions(+), 13 deletions(-) diff --git a/drivers/net/ena/base/ena_com.c b/drivers/net/ena/base/ena_com.c index 5ca36ab6d9..587e7b6ed1 100644 --- a/drivers/net/ena/base/ena_com.c +++ b/drivers/net/ena/base/ena_com.c @@ -1375,11 +1375,11 @@ int ena_com_execute_admin_command(struct ena_com_admin_queue *admin_queue, if (IS_ERR(comp_ctx)) { if (comp_ctx == ERR_PTR(ENA_COM_NO_DEVICE)) ena_trc_dbg(admin_queue->ena_dev, - "Failed to submit command [%ld]\n", + "Failed to submit command [%" PRIu64 "]\n", PTR_ERR(comp_ctx)); else ena_trc_err(admin_queue->ena_dev, - "Failed to submit command [%ld]\n", + "Failed to submit command [%" PRIu64 "]\n", PTR_ERR(comp_ctx)); return (int)PTR_ERR(comp_ctx); diff --git a/drivers/net/ena/base/ena_plat.h b/drivers/net/ena/base/ena_plat.h index 2583823080..555cf23e5e 100644 --- a/drivers/net/ena/base/ena_plat.h +++ b/drivers/net/ena/base/ena_plat.h @@ -21,7 +21,7 @@ #include #endif #elif defined(_WIN32) -#include +#include #else #error "Invalid platform" #endif diff --git a/drivers/net/ena/base/ena_plat_dpdk.h b/drivers/net/ena/base/ena_plat_dpdk.h index 4e7f52881a..bba61d7180 100644 --- a/drivers/net/ena/base/ena_plat_dpdk.h +++ b/drivers/net/ena/base/ena_plat_dpdk.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -24,7 +25,12 @@ #include #include +#if defined(_WIN32) +#include +#include +#else #include +#endif #include typedef uint64_t u64; @@ -293,9 +299,9 @@ extern rte_atomic64_t ena_alloc_cnt; #define dma_rmb() rmb() #define MAX_ERRNO 4095 -#define IS_ERR(x) (((unsigned long)x) >= (unsigned long)-MAX_ERRNO) -#define ERR_PTR(error) ((void *)(long)error) -#define PTR_ERR(error) ((long)(void *)error) +#define IS_ERR(x) (((uintptr_t)x) >= (uintptr_t)-MAX_ERRNO) +#define ERR_PTR(error) ((void *)(uintptr_t)error) +#define PTR_ERR(error) ((uintptr_t)(void *)error) #define might_sleep() #define prefetch(x) rte_prefetch0(x) @@ -322,7 +328,7 @@ extern rte_atomic64_t ena_alloc_cnt; #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) -#define ENA_FFS(x) ffs(x) +#define ENA_FFS(x) __builtin_ffs(x) void ena_rss_key_fill(void *key, size_t size); diff --git a/drivers/net/ena/meson.build b/drivers/net/ena/meson.build index d02ed3f64f..57f8050ccb 100644 --- a/drivers/net/ena/meson.build +++ b/drivers/net/ena/meson.build @@ -1,11 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Intel Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif sources = files( 'ena_ethdev.c', diff --git a/lib/eal/version.map b/lib/eal/version.map index 887012d02a..3de59910cd 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -198,7 +198,7 @@ DPDK_21 { rte_uuid_is_null; # WINDOWS_NO_EXPORT rte_uuid_parse; # WINDOWS_NO_EXPORT rte_uuid_unparse; # WINDOWS_NO_EXPORT - rte_version; # WINDOWS_NO_EXPORT + rte_version; rte_vfio_clear_group; # WINDOWS_NO_EXPORT rte_vfio_container_create; # WINDOWS_NO_EXPORT rte_vfio_container_destroy; # WINDOWS_NO_EXPORT diff --git a/lib/eal/windows/include/pthread.h b/lib/eal/windows/include/pthread.h index 27fd2cca52..4dc39b9a60 100644 --- a/lib/eal/windows/include/pthread.h +++ b/lib/eal/windows/include/pthread.h @@ -7,6 +7,7 @@ #include #include +#include /** * This file is required to support the common code in eal_common_proc.c, @@ -34,6 +35,10 @@ typedef CRITICAL_SECTION pthread_mutex_t; typedef SYNCHRONIZATION_BARRIER pthread_barrier_t; +typedef CONDITION_VARIABLE pthread_cond_t; + +typedef void pthread_condattr_t; + #define pthread_barrier_init(barrier, attr, count) \ !InitializeSynchronizationBarrier(barrier, count, -1) #define pthread_barrier_wait(barrier) EnterSynchronizationBarrier(barrier, \ @@ -185,6 +190,106 @@ pthread_mutex_destroy(pthread_mutex_t *mutex) return 0; } +static inline DWORD +timespec_to_ms(const struct timespec *abstime) +{ + DWORD t; + + if (abstime == NULL) + return INFINITE; + + t = ((abstime->tv_sec - time(NULL)) * 1000) + + (abstime->tv_nsec / 1000000); + if (t < 0) + t = 1; + return t; +} + +static inline int +pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr) +{ + (void)attr; + if (cond == NULL) + return 1; + InitializeConditionVariable(cond); + return 0; +} + +static inline int +pthread_cond_destroy(pthread_cond_t *cond) +{ + /* Windows does not have a destroy for conditionals */ + (void)cond; + return 0; +} + +static inline int +pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, + const struct timespec *abstime) +{ + if (cond == NULL || mutex == NULL) + return 1; + if (!SleepConditionVariableCS(cond, mutex, timespec_to_ms(abstime))) + return 1; + return 0; +} + +static inline int +pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) +{ + if (cond == NULL || mutex == NULL) + return 1; + return pthread_cond_timedwait(cond, mutex, NULL); +} + +static inline int +pthread_cond_signal(pthread_cond_t *cond) +{ + if (cond == NULL) + return 1; + WakeConditionVariable(cond); + return 0; +} + +static inline int +pthread_cond_broadcast(pthread_cond_t *cond) +{ + if (cond == NULL) + return 1; + WakeAllConditionVariable(cond); + return 0; +} + +struct timezone { + int tz_minuteswest; + int tz_dsttime; +}; + +static inline int +gettimeofday(struct timeval *tv, struct timezone *tz) +{ + if (tv) { + FILETIME filetime; + ULARGE_INTEGER x; + ULONGLONG usec; + static const ULONGLONG epoch_ofs_us = 11644473600000000ULL; + + GetSystemTimePreciseAsFileTime(&filetime); + x.LowPart = filetime.dwLowDateTime; + x.HighPart = filetime.dwHighDateTime; + usec = x.QuadPart / 10 - epoch_ofs_us; + tv->tv_sec = (time_t)(usec / 1000000ULL); + tv->tv_usec = (long)(usec % 1000000ULL); + } + if (tz) { + TIME_ZONE_INFORMATION timezone; + GetTimeZoneInformation(&timezone); + tz->tz_minuteswest = timezone.Bias; + tz->tz_dsttime = 0; + } + return 0; +} + #ifdef __cplusplus } #endif diff --git a/lib/eal/windows/include/rte_windows.h b/lib/eal/windows/include/rte_windows.h index 0063b5d78c..3240970ab7 100644 --- a/lib/eal/windows/include/rte_windows.h +++ b/lib/eal/windows/include/rte_windows.h @@ -31,6 +31,7 @@ #include #include #include +#include /* Have GUIDs defined. */ #ifndef INITGUID -- 2.30.2