* [PATCH] net/gve: Check whether the driver is compatible with the device presented.
@ 2023-04-14 5:14 Rushil Gupta
2023-04-14 9:05 ` Guo, Junfeng
` (2 more replies)
0 siblings, 3 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-04-14 5:14 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
This patch is dependent on https://patchwork.dpdk.org/project/dpdk/list/?series=27687&state=*
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
drivers/net/gve/base/gve.h | 3 --
drivers/net/gve/base/gve_adminq.c | 19 +++++++++
drivers/net/gve/base/gve_adminq.h | 49 ++++++++++++++++++++++-
drivers/net/gve/base/gve_osdep.h | 36 +++++++++++++++++
drivers/net/gve/gve_ethdev.c | 65 +++++++++++++++++++++++++------
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 14 +++++++
drivers/net/gve/gve_version.h | 25 ++++++++++++
drivers/net/gve/meson.build | 1 +
9 files changed, 198 insertions(+), 16 deletions(-)
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2dc4507acb..89f9654a72 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -8,9 +8,6 @@
#include "gve_desc.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e745b709b2..2e5099a5b0 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..edac32f031 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,47 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+#define GVE_CAP2(a) BIT(((int)a) - 64)
+#define GVE_CAP3(a) BIT(((int)a) - 128)
+#define GVE_CAP4(a) BIT(((int)a) - 192)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +387,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +422,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index 7cb73002f4..a5efa8543e 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -79,6 +90,12 @@ typedef rte_iova_t dma_addr_t;
#define GVE_CHECK_UNION_LEN(n, X) enum gve_static_asset_enum_##X \
{ gve_static_assert_##X = (n) / ((sizeof(union X) == (n)) ? 1 : 0) }
+#ifndef LINUX_VERSION_MAJOR
+#define LINUX_VERSION_MAJOR (((LINUX_VERSION_CODE) >> 16) & 0xff)
+#define LINUX_VERSION_SUBLEVEL (((LINUX_VERSION_CODE) >> 8) & 0xff)
+#define LINUX_VERSION_PATCHLEVEL ((LINUX_VERSION_CODE) & 0xff)
+#endif
+
static __rte_always_inline u8
readb(volatile void *addr)
{
@@ -156,4 +173,23 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(struct os_version_string *os_version_str)
+{
+#ifdef __linux__
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(os_version_str->os_version_str1, uts.release,
+ sizeof(os_version_str->os_version_str1));
+ /* version */
+ rte_strscpy(os_version_str->os_version_str2, uts.version,
+ sizeof(os_version_str->os_version_str2));
+ }
+#else
+ /* gVNIC is currently not supported on OS like FreeBSD */
+ RTE_SET_USED(os_version_str);
+#endif
+}
+
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index cf28a4a3b7..1d6e134fff 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -265,6 +257,52 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ const struct rte_memzone *driver_info_bus;
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info_bus = rte_memzone_reserve_aligned("verify_driver_compatibility",
+ sizeof(struct gve_driver_info),
+ rte_socket_id(),
+ RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
+ if (driver_info_bus == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc memzone for driver compatibility");
+ return -ENOMEM;
+ }
+ driver_info = (struct gve_driver_info *)driver_info_bus->addr;
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((struct os_version_string *)&driver_info->os_version_str1);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info_bus);
+
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_memzone_free(driver_info_bus);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -672,6 +710,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index 42a02cf5d4..23ccff37d3 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -222,7 +222,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..7eaa689d90
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: MIT
+ * Google Virtual Ethernet (gve) driver
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[10];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..9af6a00568
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: MIT
+ * Google Virtual Ethernet (gve) driver
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index af0010c01c..a37c4bafa2 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -12,5 +12,6 @@ sources = files(
'gve_rx.c',
'gve_tx.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.0.634.g4ca3ef3211-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* RE: [PATCH] net/gve: Check whether the driver is compatible with the device presented.
2023-04-14 5:14 [PATCH] net/gve: Check whether the driver is compatible with the device presented Rushil Gupta
@ 2023-04-14 9:05 ` Guo, Junfeng
2023-04-14 15:40 ` Ferruh Yigit
2023-04-26 21:37 ` Rushil Gupta
2023-05-08 19:14 ` [v2] " Rushil Gupta
2 siblings, 1 reply; 32+ messages in thread
From: Guo, Junfeng @ 2023-04-14 9:05 UTC (permalink / raw)
To: Rushil Gupta, ferruh.yigit, Zhang, Qi Z, Wu, Jingjing
Cc: joshwash, dev, Jeroen de Borst
Hi Ferruh,
Here is the summary of the dependency of related patches:
P1: necessary headers update
https://patchwork.dpdk.org/project/dpdk/list/?series=27647&state=*
P2: minor update for base code
https://patchwork.dpdk.org/project/dpdk/list/?series=27653&state=*
P3: gve PMD enhancement
https://patchwork.dpdk.org/project/dpdk/list/?series=27687&state=*
P4: add new AdminQ cmd to verify drv cap
https://patchwork.dpdk.org/project/dpdk/list/?series=27703&state=*
The merging order could be: P1 > P2 > P3 > P4, due to the dependency.
Just to inform you about this here. Thanks for the review!
Regards,
Junfeng
> -----Original Message-----
> From: Rushil Gupta <rushilg@google.com>
> Sent: Friday, April 14, 2023 13:15
> To: ferruh.yigit@amd.com; Zhang, Qi Z <qi.z.zhang@intel.com>; Wu,
> Jingjing <jingjing.wu@intel.com>
> Cc: Guo, Junfeng <junfeng.guo@intel.com>; joshwash@google.com;
> dev@dpdk.org; Rushil Gupta <rushilg@google.com>; Jeroen de Borst
> <jeroendb@google.com>
> Subject: [PATCH] net/gve: Check whether the driver is compatible with
> the device presented.
>
> Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
> version as OS version, reserving driver_version fields for GVE driver
> version based on features.
>
> This patch is dependent on
> https://patchwork.dpdk.org/project/dpdk/list/?series=27687&state=*
>
> Signed-off-by: Rushil Gupta <rushilg@google.com>
> Signed-off-by: Joshua Washington <joshwash@google.com>
> Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
> Signed-off-by: Jeroen de Borst <jeroendb@google.com>
> ---
> drivers/net/gve/base/gve.h | 3 --
> drivers/net/gve/base/gve_adminq.c | 19 +++++++++
> drivers/net/gve/base/gve_adminq.h | 49 ++++++++++++++++++++++-
> drivers/net/gve/base/gve_osdep.h | 36 +++++++++++++++++
> drivers/net/gve/gve_ethdev.c | 65 +++++++++++++++++++++++++-----
> -
> drivers/net/gve/gve_ethdev.h | 2 +-
> drivers/net/gve/gve_version.c | 14 +++++++
> drivers/net/gve/gve_version.h | 25 ++++++++++++
> drivers/net/gve/meson.build | 1 +
> 9 files changed, 198 insertions(+), 16 deletions(-)
> create mode 100644 drivers/net/gve/gve_version.c
> create mode 100644 drivers/net/gve/gve_version.h
>
> diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
> index 2dc4507acb..89f9654a72 100644
> --- a/drivers/net/gve/base/gve.h
> +++ b/drivers/net/gve/base/gve.h
> @@ -8,9 +8,6 @@
>
> #include "gve_desc.h"
>
> -#define GVE_VERSION "1.3.0"
> -#define GVE_VERSION_PREFIX "GVE-"
> -
> #ifndef GOOGLE_VENDOR_ID
> #define GOOGLE_VENDOR_ID 0x1ae0
> #endif
> diff --git a/drivers/net/gve/base/gve_adminq.c
> b/drivers/net/gve/base/gve_adminq.c
> index e745b709b2..2e5099a5b0 100644
> --- a/drivers/net/gve/base/gve_adminq.c
> +++ b/drivers/net/gve/base/gve_adminq.c
> @@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv
> *priv,
> case GVE_ADMINQ_GET_PTYPE_MAP:
> priv->adminq_get_ptype_map_cnt++;
> break;
> + case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
> + priv->adminq_verify_driver_compatibility_cnt++;
> + break;
> default:
> PMD_DRV_LOG(ERR, "unknown AQ command
> opcode %d", opcode);
> }
> @@ -465,6 +468,22 @@ int
> gve_adminq_configure_device_resources(struct gve_priv *priv,
> return gve_adminq_execute_cmd(priv, &cmd);
> }
>
> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> + u64 driver_info_len,
> + dma_addr_t driver_info_addr)
> +{
> + union gve_adminq_command cmd;
> +
> + memset(&cmd, 0, sizeof(cmd));
> + cmd.opcode =
> cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
> + cmd.verify_driver_compatibility = (struct
> gve_adminq_verify_driver_compatibility) {
> + .driver_info_len = cpu_to_be64(driver_info_len),
> + .driver_info_addr = cpu_to_be64(driver_info_addr),
> + };
> +
> + return gve_adminq_execute_cmd(priv, &cmd);
> +}
> +
> int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
> {
> union gve_adminq_command cmd;
> diff --git a/drivers/net/gve/base/gve_adminq.h
> b/drivers/net/gve/base/gve_adminq.h
> index 05550119de..edac32f031 100644
> --- a/drivers/net/gve/base/gve_adminq.h
> +++ b/drivers/net/gve/base/gve_adminq.h
> @@ -1,6 +1,6 @@
> /* SPDX-License-Identifier: MIT
> * Google Virtual Ethernet (gve) driver
> - * Copyright (C) 2015-2022 Google, Inc.
> + * Copyright (C) 2015-2023 Google, Inc.
> */
>
> #ifndef _GVE_ADMINQ_H
> @@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
> GVE_ADMINQ_REPORT_STATS = 0xC,
> GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
> GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
> + GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
> };
>
> /* Admin queue status codes */
> @@ -145,6 +146,47 @@ enum gve_sup_feature_mask {
> };
>
> #define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
> +enum gve_driver_capbility {
> + gve_driver_capability_gqi_qpl = 0,
> + gve_driver_capability_gqi_rda = 1,
> + gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
> + gve_driver_capability_dqo_rda = 3,
> +};
> +
> +#define GVE_CAP1(a) BIT((int)a)
> +#define GVE_CAP2(a) BIT(((int)a) - 64)
> +#define GVE_CAP3(a) BIT(((int)a) - 128)
> +#define GVE_CAP4(a) BIT(((int)a) - 192)
> +
> +#define GVE_DRIVER_CAPABILITY_FLAGS1 \
> + (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
> + GVE_CAP1(gve_driver_capability_gqi_rda) | \
> + GVE_CAP1(gve_driver_capability_dqo_rda))
> +
> +#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
> +#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
> +#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
> +
> +struct gve_driver_info {
> + u8 os_type; /* 0x05 = DPDK */
> + u8 driver_major;
> + u8 driver_minor;
> + u8 driver_sub;
> + __be32 os_version_major;
> + __be32 os_version_minor;
> + __be32 os_version_sub;
> + __be64 driver_capability_flags[4];
> + u8 os_version_str1[OS_VERSION_STRLEN];
> + u8 os_version_str2[OS_VERSION_STRLEN];
> +};
> +
> +struct gve_adminq_verify_driver_compatibility {
> + __be64 driver_info_len;
> + __be64 driver_info_addr;
> +};
> +
> +GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
> +
>
> struct gve_adminq_configure_device_resources {
> __be64 counter_array;
> @@ -345,6 +387,8 @@ union gve_adminq_command {
> struct gve_adminq_report_stats report_stats;
> struct gve_adminq_report_link_speed
> report_link_speed;
> struct gve_adminq_get_ptype_map
> get_ptype_map;
> + struct gve_adminq_verify_driver_compatibility
> + verify_driver_compatibility;
> };
> };
> u8 reserved[64];
> @@ -378,4 +422,7 @@ struct gve_ptype_lut;
> int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
> struct gve_ptype_lut *ptype_lut);
>
> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> + u64 driver_info_len,
> + dma_addr_t driver_info_addr);
> #endif /* _GVE_ADMINQ_H */
> diff --git a/drivers/net/gve/base/gve_osdep.h
> b/drivers/net/gve/base/gve_osdep.h
> index 7cb73002f4..a5efa8543e 100644
> --- a/drivers/net/gve/base/gve_osdep.h
> +++ b/drivers/net/gve/base/gve_osdep.h
> @@ -21,9 +21,14 @@
> #include <rte_malloc.h>
> #include <rte_memcpy.h>
> #include <rte_memzone.h>
> +#include <rte_version.h>
>
> #include "../gve_logs.h"
>
> +#ifdef __linux__
> +#include <sys/utsname.h>
> +#endif
> +
> typedef uint8_t u8;
> typedef uint16_t u16;
> typedef uint32_t u32;
> @@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
>
> #define msleep(ms) rte_delay_ms(ms)
>
> +#define OS_VERSION_STRLEN 128
> +struct os_version_string {
> + char os_version_str1[OS_VERSION_STRLEN];
> + char os_version_str2[OS_VERSION_STRLEN];
> +};
> +
> /* These macros are used to generate compilation errors if a
> struct/union
> * is not exactly the correct length. It gives a divide by zero error if
> * the struct/union is not of the correct size, otherwise it creates an
> @@ -79,6 +90,12 @@ typedef rte_iova_t dma_addr_t;
> #define GVE_CHECK_UNION_LEN(n, X) enum
> gve_static_asset_enum_##X \
> { gve_static_assert_##X = (n) / ((sizeof(union X) == (n)) ? 1 : 0) }
>
> +#ifndef LINUX_VERSION_MAJOR
> +#define LINUX_VERSION_MAJOR (((LINUX_VERSION_CODE) >> 16) &
> 0xff)
> +#define LINUX_VERSION_SUBLEVEL (((LINUX_VERSION_CODE) >> 8) &
> 0xff)
> +#define LINUX_VERSION_PATCHLEVEL ((LINUX_VERSION_CODE) & 0xff)
> +#endif
> +
> static __rte_always_inline u8
> readb(volatile void *addr)
> {
> @@ -156,4 +173,23 @@ gve_free_dma_mem(struct gve_dma_mem
> *mem)
> mem->pa = 0;
> }
>
> +static inline void
> +populate_driver_version_strings(struct os_version_string
> *os_version_str)
> +{
> +#ifdef __linux__
> + struct utsname uts;
> + if (uname(&uts) >= 0) {
> + /* release */
> + rte_strscpy(os_version_str->os_version_str1, uts.release,
> + sizeof(os_version_str->os_version_str1));
> + /* version */
> + rte_strscpy(os_version_str->os_version_str2, uts.version,
> + sizeof(os_version_str->os_version_str2));
> + }
> +#else
> + /* gVNIC is currently not supported on OS like FreeBSD */
> + RTE_SET_USED(os_version_str);
> +#endif
> +}
> +
> #endif /* _GVE_OSDEP_H_ */
> diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
> index cf28a4a3b7..1d6e134fff 100644
> --- a/drivers/net/gve/gve_ethdev.c
> +++ b/drivers/net/gve/gve_ethdev.c
> @@ -5,21 +5,13 @@
> #include "gve_ethdev.h"
> #include "base/gve_adminq.h"
> #include "base/gve_register.h"
> -
> -const char gve_version_str[] = GVE_VERSION;
> -static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
> +#include "base/gve_osdep.h"
> +#include "gve_version.h"
>
> static void
> gve_write_version(uint8_t *driver_version_register)
> {
> - const char *c = gve_version_prefix;
> -
> - while (*c) {
> - writeb(*c, driver_version_register);
> - c++;
> - }
> -
> - c = gve_version_str;
> + const char *c = gve_version_string();
> while (*c) {
> writeb(*c, driver_version_register);
> c++;
> @@ -265,6 +257,52 @@ gve_dev_close(struct rte_eth_dev *dev)
> return err;
> }
>
> +static int
> +gve_verify_driver_compatibility(struct gve_priv *priv)
> +{
> + const struct rte_memzone *driver_info_bus;
> + struct gve_driver_info *driver_info;
> + int err;
> +
> + driver_info_bus =
> rte_memzone_reserve_aligned("verify_driver_compatibility",
> + sizeof(struct
> gve_driver_info),
> + rte_socket_id(),
> +
> RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
> + if (driver_info_bus == NULL) {
> + PMD_DRV_LOG(ERR,
> + "Could not alloc memzone for driver
> compatibility");
> + return -ENOMEM;
> + }
> + driver_info = (struct gve_driver_info *)driver_info_bus->addr;
> + *driver_info = (struct gve_driver_info) {
> + .os_type = 5, /* DPDK */
> + .driver_major = GVE_VERSION_MAJOR,
> + .driver_minor = GVE_VERSION_MINOR,
> + .driver_sub = GVE_VERSION_SUB,
> + .os_version_major =
> cpu_to_be32(DPDK_VERSION_MAJOR),
> + .os_version_minor =
> cpu_to_be32(DPDK_VERSION_MINOR),
> + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> + .driver_capability_flags = {
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> + },
> + };
> +
> + populate_driver_version_strings((struct os_version_string
> *)&driver_info->os_version_str1);
> +
> + err = gve_adminq_verify_driver_compatibility(priv,
> + sizeof(struct gve_driver_info),
> (dma_addr_t)driver_info_bus);
> +
> + /* It's ok if the device doesn't support this */
> + if (err == -EOPNOTSUPP)
> + err = 0;
> +
> + rte_memzone_free(driver_info_bus);
> + return err;
> +}
> +
> static int
> gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info
> *dev_info)
> {
> @@ -672,6 +710,11 @@ gve_init_priv(struct gve_priv *priv, bool
> skip_describe_device)
> PMD_DRV_LOG(ERR, "Failed to alloc admin queue:
> err=%d", err);
> return err;
> }
> + err = gve_verify_driver_compatibility(priv);
> + if (err) {
> + PMD_DRV_LOG(ERR, "Could not verify driver
> compatibility: err=%d", err);
> + goto free_adminq;
> + }
>
> if (skip_describe_device)
> goto setup_device;
> diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
> index 42a02cf5d4..23ccff37d3 100644
> --- a/drivers/net/gve/gve_ethdev.h
> +++ b/drivers/net/gve/gve_ethdev.h
> @@ -222,7 +222,7 @@ struct gve_priv {
> uint32_t adminq_report_stats_cnt;
> uint32_t adminq_report_link_speed_cnt;
> uint32_t adminq_get_ptype_map_cnt;
> -
> + uint32_t adminq_verify_driver_compatibility_cnt;
> volatile uint32_t state_flags;
>
> /* Gvnic device link speed from hypervisor. */
> diff --git a/drivers/net/gve/gve_version.c
> b/drivers/net/gve/gve_version.c
> new file mode 100644
> index 0000000000..7eaa689d90
> --- /dev/null
> +++ b/drivers/net/gve/gve_version.c
> @@ -0,0 +1,14 @@
> +/* SPDX-License-Identifier: MIT
> + * Google Virtual Ethernet (gve) driver
> + * Copyright (C) 2015-2023 Google, Inc.
> + */
> +#include "gve_version.h"
> +
> +const char *gve_version_string(void)
> +{
> + static char gve_version[10];
> + snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
> + GVE_VERSION_PREFIX, GVE_VERSION_MAJOR,
> GVE_VERSION_MINOR,
> + GVE_VERSION_SUB);
> + return gve_version;
> +}
> diff --git a/drivers/net/gve/gve_version.h
> b/drivers/net/gve/gve_version.h
> new file mode 100644
> index 0000000000..9af6a00568
> --- /dev/null
> +++ b/drivers/net/gve/gve_version.h
> @@ -0,0 +1,25 @@
> +/* SPDX-License-Identifier: MIT
> + * Google Virtual Ethernet (gve) driver
> + * Copyright (C) 2015-2023 Google, Inc.
> + */
> +
> +#ifndef _GVE_VERSION_H_
> +#define _GVE_VERSION_H_
> +
> +#include <rte_version.h>
> +
> +#define GVE_VERSION_PREFIX "DPDK-"
> +#define GVE_VERSION_MAJOR 1
> +#define GVE_VERSION_MINOR 0
> +#define GVE_VERSION_SUB 0
> +
> +#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR +
> RTE_VER_MONTH)
> +#define DPDK_VERSION_MINOR RTE_VER_MINOR
> +#define DPDK_VERSION_SUB RTE_VER_RELEASE
> +
> +
> +const char *
> +gve_version_string(void);
> +
> +
> +#endif /* GVE_VERSION_H */
> diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
> index af0010c01c..a37c4bafa2 100644
> --- a/drivers/net/gve/meson.build
> +++ b/drivers/net/gve/meson.build
> @@ -12,5 +12,6 @@ sources = files(
> 'gve_rx.c',
> 'gve_tx.c',
> 'gve_ethdev.c',
> + 'gve_version.c',
> )
> includes += include_directories('base')
> --
> 2.40.0.634.g4ca3ef3211-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH] net/gve: Check whether the driver is compatible with the device presented.
2023-04-14 9:05 ` Guo, Junfeng
@ 2023-04-14 15:40 ` Ferruh Yigit
2023-04-18 5:30 ` Guo, Junfeng
0 siblings, 1 reply; 32+ messages in thread
From: Ferruh Yigit @ 2023-04-14 15:40 UTC (permalink / raw)
To: Guo, Junfeng, Rushil Gupta, Zhang, Qi Z, Wu, Jingjing
Cc: joshwash, dev, Jeroen de Borst, Aaron Conole, dpdklab
On 4/14/2023 10:05 AM, Guo, Junfeng wrote:
> Hi Ferruh,
>
> Here is the summary of the dependency of related patches:
>
> P1: necessary headers update
> https://patchwork.dpdk.org/project/dpdk/list/?series=27647&state=*
> P2: minor update for base code
> https://patchwork.dpdk.org/project/dpdk/list/?series=27653&state=*
> P3: gve PMD enhancement
> https://patchwork.dpdk.org/project/dpdk/list/?series=27687&state=*
> P4: add new AdminQ cmd to verify drv cap
> https://patchwork.dpdk.org/project/dpdk/list/?series=27703&state=*
>
> The merging order could be: P1 > P2 > P3 > P4, due to the dependency.
> Just to inform you about this here. Thanks for the review!
>
Thanks Junfeng, this is useful.
Btw, we have a defined syntax for this [1], having it in commit log may
help automated CI to parse it and apply in correct order (when it is
fully supported in CI :) )
[1]
https://doc.dpdk.org/guides/contributing/patches.html#patch-dependencies
Depends-on: series-NNNNN ("Title of the series")
or
Depends-on: patch-NNNNN ("Title of the patch")
And I just recognized that syntax is not clear for multiple dependency
case, we should define it better.
^ permalink raw reply [flat|nested] 32+ messages in thread
* RE: [PATCH] net/gve: Check whether the driver is compatible with the device presented.
2023-04-14 15:40 ` Ferruh Yigit
@ 2023-04-18 5:30 ` Guo, Junfeng
0 siblings, 0 replies; 32+ messages in thread
From: Guo, Junfeng @ 2023-04-18 5:30 UTC (permalink / raw)
To: Ferruh Yigit, Rushil Gupta, Zhang, Qi Z, Wu, Jingjing
Cc: joshwash, dev, Jeroen de Borst, Aaron Conole, dpdklab
> -----Original Message-----
> From: Ferruh Yigit <ferruh.yigit@amd.com>
> Sent: Friday, April 14, 2023 23:40
> To: Guo, Junfeng <junfeng.guo@intel.com>; Rushil Gupta
> <rushilg@google.com>; Zhang, Qi Z <qi.z.zhang@intel.com>; Wu, Jingjing
> <jingjing.wu@intel.com>
> Cc: joshwash@google.com; dev@dpdk.org; Jeroen de Borst
> <jeroendb@google.com>; Aaron Conole <aconole@redhat.com>;
> dpdklab <dpdklab@iol.unh.edu>
> Subject: Re: [PATCH] net/gve: Check whether the driver is compatible
> with the device presented.
>
> On 4/14/2023 10:05 AM, Guo, Junfeng wrote:
> > Hi Ferruh,
> >
> > Here is the summary of the dependency of related patches:
> >
> > P1: necessary headers update
> > https://patchwork.dpdk.org/project/dpdk/list/?series=27647&state=*
> > P2: minor update for base code
> > https://patchwork.dpdk.org/project/dpdk/list/?series=27653&state=*
> > P3: gve PMD enhancement
> > https://patchwork.dpdk.org/project/dpdk/list/?series=27687&state=*
> > P4: add new AdminQ cmd to verify drv cap
> > https://patchwork.dpdk.org/project/dpdk/list/?series=27703&state=*
> >
> > The merging order could be: P1 > P2 > P3 > P4, due to the dependency.
> > Just to inform you about this here. Thanks for the review!
> >
>
> Thanks Junfeng, this is useful.
>
> Btw, we have a defined syntax for this [1], having it in commit log may
> help automated CI to parse it and apply in correct order (when it is
> fully supported in CI :) )
>
>
> [1]
> https://doc.dpdk.org/guides/contributing/patches.html#patch-
> dependencies
>
> Depends-on: series-NNNNN ("Title of the series")
> or
> Depends-on: patch-NNNNN ("Title of the patch")
>
> And I just recognized that syntax is not clear for multiple dependency
> case, we should define it better.
Sure, we will try this in the coming version patches.
Really a good solution for the patch dependencies!
Thanks for the enhancement!
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH] net/gve: Check whether the driver is compatible with the device presented.
2023-04-14 5:14 [PATCH] net/gve: Check whether the driver is compatible with the device presented Rushil Gupta
2023-04-14 9:05 ` Guo, Junfeng
@ 2023-04-26 21:37 ` Rushil Gupta
2023-05-04 15:06 ` Ferruh Yigit
` (2 more replies)
2023-05-08 19:14 ` [v2] " Rushil Gupta
2 siblings, 3 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-04-26 21:37 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Depends-on: series-27687
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
drivers/net/gve/base/gve.h | 3 --
drivers/net/gve/base/gve_adminq.c | 19 +++++++++
drivers/net/gve/base/gve_adminq.h | 49 ++++++++++++++++++++++-
drivers/net/gve/base/gve_osdep.h | 36 +++++++++++++++++
drivers/net/gve/gve_ethdev.c | 65 +++++++++++++++++++++++++------
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 14 +++++++
drivers/net/gve/gve_version.h | 25 ++++++++++++
drivers/net/gve/meson.build | 1 +
9 files changed, 198 insertions(+), 16 deletions(-)
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2dc4507acb..89f9654a72 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -8,9 +8,6 @@
#include "gve_desc.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e745b709b2..2e5099a5b0 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..edac32f031 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,47 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+#define GVE_CAP2(a) BIT(((int)a) - 64)
+#define GVE_CAP3(a) BIT(((int)a) - 128)
+#define GVE_CAP4(a) BIT(((int)a) - 192)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +387,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +422,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index 7cb73002f4..a5efa8543e 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -79,6 +90,12 @@ typedef rte_iova_t dma_addr_t;
#define GVE_CHECK_UNION_LEN(n, X) enum gve_static_asset_enum_##X \
{ gve_static_assert_##X = (n) / ((sizeof(union X) == (n)) ? 1 : 0) }
+#ifndef LINUX_VERSION_MAJOR
+#define LINUX_VERSION_MAJOR (((LINUX_VERSION_CODE) >> 16) & 0xff)
+#define LINUX_VERSION_SUBLEVEL (((LINUX_VERSION_CODE) >> 8) & 0xff)
+#define LINUX_VERSION_PATCHLEVEL ((LINUX_VERSION_CODE) & 0xff)
+#endif
+
static __rte_always_inline u8
readb(volatile void *addr)
{
@@ -156,4 +173,23 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(struct os_version_string *os_version_str)
+{
+#ifdef __linux__
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(os_version_str->os_version_str1, uts.release,
+ sizeof(os_version_str->os_version_str1));
+ /* version */
+ rte_strscpy(os_version_str->os_version_str2, uts.version,
+ sizeof(os_version_str->os_version_str2));
+ }
+#else
+ /* gVNIC is currently not supported on OS like FreeBSD */
+ RTE_SET_USED(os_version_str);
+#endif
+}
+
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index cf28a4a3b7..1d6e134fff 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -265,6 +257,52 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ const struct rte_memzone *driver_info_bus;
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info_bus = rte_memzone_reserve_aligned("verify_driver_compatibility",
+ sizeof(struct gve_driver_info),
+ rte_socket_id(),
+ RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
+ if (driver_info_bus == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc memzone for driver compatibility");
+ return -ENOMEM;
+ }
+ driver_info = (struct gve_driver_info *)driver_info_bus->addr;
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((struct os_version_string *)&driver_info->os_version_str1);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info_bus);
+
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_memzone_free(driver_info_bus);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -672,6 +710,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index 42a02cf5d4..23ccff37d3 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -222,7 +222,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..7eaa689d90
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: MIT
+ * Google Virtual Ethernet (gve) driver
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[10];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..9af6a00568
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: MIT
+ * Google Virtual Ethernet (gve) driver
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index af0010c01c..a37c4bafa2 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -12,5 +12,6 @@ sources = files(
'gve_rx.c',
'gve_tx.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.0.634.g4ca3ef3211-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH] net/gve: Check whether the driver is compatible with the device presented.
2023-04-26 21:37 ` Rushil Gupta
@ 2023-05-04 15:06 ` Ferruh Yigit
2023-05-08 6:23 ` Rushil Gupta
2023-05-08 19:15 ` [v2] net/gve: check driver compatibility Rushil Gupta
2023-05-18 17:40 ` [v3] " Rushil Gupta
2 siblings, 1 reply; 32+ messages in thread
From: Ferruh Yigit @ 2023-05-04 15:06 UTC (permalink / raw)
To: Rushil Gupta, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Jeroen de Borst
On 4/26/2023 10:37 PM, Rushil Gupta wrote:
> Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
> version as OS version, reserving driver_version fields for GVE driver
> version based on features.
>
'./devtools/check-git-log.sh' is giving some warnings, can you please
check them?
Contribution guide documentation may help to fix reported issues:
https://doc.dpdk.org/guides/contributing/patches.html#commit-messages-subject-line
> Depends-on: series-27687
>
> Signed-off-by: Rushil Gupta <rushilg@google.com>
> Signed-off-by: Joshua Washington <joshwash@google.com>
> Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
> Signed-off-by: Jeroen de Borst <jeroendb@google.com>
> ---
> drivers/net/gve/base/gve.h | 3 --
> drivers/net/gve/base/gve_adminq.c | 19 +++++++++
> drivers/net/gve/base/gve_adminq.h | 49 ++++++++++++++++++++++-
> drivers/net/gve/base/gve_osdep.h | 36 +++++++++++++++++
> drivers/net/gve/gve_ethdev.c | 65 +++++++++++++++++++++++++------
> drivers/net/gve/gve_ethdev.h | 2 +-
> drivers/net/gve/gve_version.c | 14 +++++++
> drivers/net/gve/gve_version.h | 25 ++++++++++++
> drivers/net/gve/meson.build | 1 +
> 9 files changed, 198 insertions(+), 16 deletions(-)
> create mode 100644 drivers/net/gve/gve_version.c
> create mode 100644 drivers/net/gve/gve_version.h
>
> diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
> index 2dc4507acb..89f9654a72 100644
> --- a/drivers/net/gve/base/gve.h
> +++ b/drivers/net/gve/base/gve.h
> @@ -8,9 +8,6 @@
>
> #include "gve_desc.h"
>
> -#define GVE_VERSION "1.3.0"
> -#define GVE_VERSION_PREFIX "GVE-"
> -
> #ifndef GOOGLE_VENDOR_ID
> #define GOOGLE_VENDOR_ID 0x1ae0
> #endif
> diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
> index e745b709b2..2e5099a5b0 100644
> --- a/drivers/net/gve/base/gve_adminq.c
> +++ b/drivers/net/gve/base/gve_adminq.c
> @@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
> case GVE_ADMINQ_GET_PTYPE_MAP:
> priv->adminq_get_ptype_map_cnt++;
> break;
> + case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
> + priv->adminq_verify_driver_compatibility_cnt++;
> + break;
> default:
> PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
> }
> @@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
> return gve_adminq_execute_cmd(priv, &cmd);
> }
>
> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> + u64 driver_info_len,
> + dma_addr_t driver_info_addr)
> +{
> + union gve_adminq_command cmd;
> +
> + memset(&cmd, 0, sizeof(cmd));
> + cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
> + cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
> + .driver_info_len = cpu_to_be64(driver_info_len),
> + .driver_info_addr = cpu_to_be64(driver_info_addr),
> + };
> +
> + return gve_adminq_execute_cmd(priv, &cmd);
> +}
> +
> int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
> {
> union gve_adminq_command cmd;
> diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
> index 05550119de..edac32f031 100644
> --- a/drivers/net/gve/base/gve_adminq.h
> +++ b/drivers/net/gve/base/gve_adminq.h
> @@ -1,6 +1,6 @@
> /* SPDX-License-Identifier: MIT
> * Google Virtual Ethernet (gve) driver
> - * Copyright (C) 2015-2022 Google, Inc.
> + * Copyright (C) 2015-2023 Google, Inc.
> */
>
> #ifndef _GVE_ADMINQ_H
> @@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
> GVE_ADMINQ_REPORT_STATS = 0xC,
> GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
> GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
> + GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
> };
>
> /* Admin queue status codes */
> @@ -145,6 +146,47 @@ enum gve_sup_feature_mask {
> };
>
> #define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
> +enum gve_driver_capbility {
> + gve_driver_capability_gqi_qpl = 0,
> + gve_driver_capability_gqi_rda = 1,
> + gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
> + gve_driver_capability_dqo_rda = 3,
> +};
> +
> +#define GVE_CAP1(a) BIT((int)a)
> +#define GVE_CAP2(a) BIT(((int)a) - 64)
> +#define GVE_CAP3(a) BIT(((int)a) - 128)
> +#define GVE_CAP3(a) BIT(((int)a) - 192)
GVE_CAP2, GVE_CAP3 & GVE_CAP4 seems not used, do we need to add them now?
And I guess '(((int)a) - 64)' usage is to unset some bits, will it be
better to '(a & ~(1 << 6))' ?
> +
> +#define GVE_DRIVER_CAPABILITY_FLAGS1 \
> + (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
> + GVE_CAP1(gve_driver_capability_gqi_rda) | \
> + GVE_CAP1(gve_driver_capability_dqo_rda))
> +
> +#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
> +#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
> +#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
> +
> +struct gve_driver_info {
> + u8 os_type; /* 0x05 = DPDK */
> + u8 driver_major;
> + u8 driver_minor;
> + u8 driver_sub;
> + __be32 os_version_major;
> + __be32 os_version_minor;
> + __be32 os_version_sub;
> + __be64 driver_capability_flags[4];
> + u8 os_version_str1[OS_VERSION_STRLEN];
> + u8 os_version_str2[OS_VERSION_STRLEN];
> +};
> +
> +struct gve_adminq_verify_driver_compatibility {
> + __be64 driver_info_len;
> + __be64 driver_info_addr;
> +};
> +
> +GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
> +
It looks like we need a static assert helper for DPDK, I will try to
send something.
>
> struct gve_adminq_configure_device_resources {
> __be64 counter_array;
> @@ -345,6 +387,8 @@ union gve_adminq_command {
> struct gve_adminq_report_stats report_stats;
> struct gve_adminq_report_link_speed report_link_speed;
> struct gve_adminq_get_ptype_map get_ptype_map;
> + struct gve_adminq_verify_driver_compatibility
> + verify_driver_compatibility;
> };
> };
> u8 reserved[64];
> @@ -378,4 +422,7 @@ struct gve_ptype_lut;
> int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
> struct gve_ptype_lut *ptype_lut);
>
> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> + u64 driver_info_len,
> + dma_addr_t driver_info_addr);
> #endif /* _GVE_ADMINQ_H */
> diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
> index 7cb73002f4..a5efa8543e 100644
> --- a/drivers/net/gve/base/gve_osdep.h
> +++ b/drivers/net/gve/base/gve_osdep.h
> @@ -21,9 +21,14 @@
> #include <rte_malloc.h>
> #include <rte_memcpy.h>
> #include <rte_memzone.h>
> +#include <rte_version.h>
>
> #include "../gve_logs.h"
>
> +#ifdef __linux__
> +#include <sys/utsname.h>
> +#endif
> +
> typedef uint8_t u8;
> typedef uint16_t u16;
> typedef uint32_t u32;
> @@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
>
> #define msleep(ms) rte_delay_ms(ms)
>
> +#define OS_VERSION_STRLEN 128
> +struct os_version_string {
> + char os_version_str1[OS_VERSION_STRLEN];
> + char os_version_str2[OS_VERSION_STRLEN];
> +};
> +
> /* These macros are used to generate compilation errors if a struct/union
> * is not exactly the correct length. It gives a divide by zero error if
> * the struct/union is not of the correct size, otherwise it creates an
> @@ -79,6 +90,12 @@ typedef rte_iova_t dma_addr_t;
> #define GVE_CHECK_UNION_LEN(n, X) enum gve_static_asset_enum_##X \
> { gve_static_assert_##X = (n) / ((sizeof(union X) == (n)) ? 1 : 0) }
>
> +#ifndef LINUX_VERSION_MAJOR
> +#define LINUX_VERSION_MAJOR (((LINUX_VERSION_CODE) >> 16) & 0xff)
> +#define LINUX_VERSION_SUBLEVEL (((LINUX_VERSION_CODE) >> 8) & 0xff)
> +#define LINUX_VERSION_PATCHLEVEL ((LINUX_VERSION_CODE) & 0xff)
> +#endif
> +
Do we need Linux version macros in DPDK? They are not used at all.
> static __rte_always_inline u8
> readb(volatile void *addr)
> {
> @@ -156,4 +173,23 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
> mem->pa = 0;
> }
>
> +static inline void
> +populate_driver_version_strings(struct os_version_string *os_version_str)
> +{
> +#ifdef __linux__
> + struct utsname uts;
> + if (uname(&uts) >= 0) {
> + /* release */
> + rte_strscpy(os_version_str->os_version_str1, uts.release,
> + sizeof(os_version_str->os_version_str1));
> + /* version */
> + rte_strscpy(os_version_str->os_version_str2, uts.version,
> + sizeof(os_version_str->os_version_str2));
> + }
Since OS type is reported as DPDK, do we need underlying Linux release
information to the FW?
If not we can remove #ifdef and 'uname()' to reduce platform specific code.
> +#else
> + /* gVNIC is currently not supported on OS like FreeBSD */
meson file only disable for Windows, for FreeBSD driver is compiled.
If driver is only supported on Linux, can you change the meson file to
reflec this?
> + RTE_SET_USED(os_version_str);
> +#endif
> +}
> +
> #endif /* _GVE_OSDEP_H_ */
> diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
> index cf28a4a3b7..1d6e134fff 100644
> --- a/drivers/net/gve/gve_ethdev.c
> +++ b/drivers/net/gve/gve_ethdev.c
> @@ -5,21 +5,13 @@
> #include "gve_ethdev.h"
> #include "base/gve_adminq.h"
> #include "base/gve_register.h"
> -
> -const char gve_version_str[] = GVE_VERSION;
> -static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
> +#include "base/gve_osdep.h"
> +#include "gve_version.h"
>
> static void
> gve_write_version(uint8_t *driver_version_register)
> {
> - const char *c = gve_version_prefix;
> -
> - while (*c) {
> - writeb(*c, driver_version_register);
> - c++;
> - }
> -
> - c = gve_version_str;
> + const char *c = gve_version_string();
> while (*c) {
> writeb(*c, driver_version_register);
> c++;
> @@ -265,6 +257,52 @@ gve_dev_close(struct rte_eth_dev *dev)
> return err;
> }
>
> +static int
> +gve_verify_driver_compatibility(struct gve_priv *priv)
> +{
> + const struct rte_memzone *driver_info_bus;
What does '_bus' indicates in the variable name?
> + struct gve_driver_info *driver_info;
> + int err;
> +
> + driver_info_bus = rte_memzone_reserve_aligned("verify_driver_compatibility",
> + sizeof(struct gve_driver_info),
> + rte_socket_id(),
> + RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
There is no benefit to use DPDK memory APIs for this usage, a 'malloc()'
will do the work, and maybe better as compilers/static analyzers
recognizes it more.
> + if (driver_info_bus == NULL) {
> + PMD_DRV_LOG(ERR,
> + "Could not alloc memzone for driver compatibility");
> + return -ENOMEM;
> + }
> + driver_info = (struct gve_driver_info *)driver_info_bus->addr;
> + *driver_info = (struct gve_driver_info) {
> + .os_type = 5, /* DPDK */
> + .driver_major = GVE_VERSION_MAJOR,
> + .driver_minor = GVE_VERSION_MINOR,
> + .driver_sub = GVE_VERSION_SUB,
> + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
> + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
> + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> + .driver_capability_flags = {
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> + },
> + };
> +
> + populate_driver_version_strings((struct os_version_string *)&driver_info->os_version_str1);
> +
If you pass two strings as parameter to
'populate_driver_version_strings()' can you get rid of interim type
"struct os_version_string" and above casting?
> + err = gve_adminq_verify_driver_compatibility(priv,
> + sizeof(struct gve_driver_info), (dma_addr_t)driver_info_bus);
> +
> + /* It's ok if the device doesn't support this */
> + if (err == -EOPNOTSUPP)
> + err = 0;
Is this error saying DPDK version is not supported?
Where a change should go to be able to identify and verify DPDK platform
in GVE? Does it require continious update as DPDK get updated?
> +
> + rte_memzone_free(driver_info_bus);
> + return err;
> +}
> +
> static int
> gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
> {
> @@ -672,6 +710,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
> PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
> return err;
> }
> + err = gve_verify_driver_compatibility(priv);
> + if (err) {
> + PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
> + goto free_adminq;
> + }
>
> if (skip_describe_device)
> goto setup_device;
> diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
> index 42a02cf5d4..23ccff37d3 100644
> --- a/drivers/net/gve/gve_ethdev.h
> +++ b/drivers/net/gve/gve_ethdev.h
> @@ -222,7 +222,7 @@ struct gve_priv {
> uint32_t adminq_report_stats_cnt;
> uint32_t adminq_report_link_speed_cnt;
> uint32_t adminq_get_ptype_map_cnt;
> -
> + uint32_t adminq_verify_driver_compatibility_cnt;
> volatile uint32_t state_flags;
>
> /* Gvnic device link speed from hypervisor. */
> diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
> new file mode 100644
> index 0000000000..7eaa689d90
> --- /dev/null
> +++ b/drivers/net/gve/gve_version.c
> @@ -0,0 +1,14 @@
> +/* SPDX-License-Identifier: MIT
> + * Google Virtual Ethernet (gve) driver
> + * Copyright (C) 2015-2023 Google, Inc.
> + */
This is not base code, but DPDK layer, license should be BSD-3.
> +#include "gve_version.h"
> +
> +const char *gve_version_string(void)
> +{
> + static char gve_version[10];
> + snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
> + GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
> + GVE_VERSION_SUB);
> + return gve_version;
> +}
> diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
> new file mode 100644
> index 0000000000..9af6a00568
> --- /dev/null
> +++ b/drivers/net/gve/gve_version.h
> @@ -0,0 +1,25 @@
> +/* SPDX-License-Identifier: MIT
> + * Google Virtual Ethernet (gve) driver
> + * Copyright (C) 2015-2023 Google, Inc.
> + */
> +
This is not base code, but DPDK layer, license should be BSD-3.
> +#ifndef _GVE_VERSION_H_
> +#define _GVE_VERSION_H_
> +
> +#include <rte_version.h>
> +
> +#define GVE_VERSION_PREFIX "DPDK-"
> +#define GVE_VERSION_MAJOR 1
> +#define GVE_VERSION_MINOR 0
> +#define GVE_VERSION_SUB 0
> +
Is this GVE base version, or DPDK gve version?
Previous version information was "GVE-1.3.0", now it is becoming
"DPDK-1.0.0",
is this breaking the version link with GVE base version and creating a
new versioning scheme for DPDK GVE driver?
Btw, documentation still has "v1.3.0. GVE base code", should it be
updated as well?
> +#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
> +#define DPDK_VERSION_MINOR RTE_VER_MINOR
> +#define DPDK_VERSION_SUB RTE_VER_RELEASE
> +
RTE_VER_RELEASE is 1 (-rc1), 2 (-rc2), etc... And if it is not release
candidate it is always 99, so it may not be very usefull for the
official releases and changes frequently for the development tree, are
you sure to use this value?
> +
> +const char *
> +gve_version_string(void);
> +
> +
> +#endif /* GVE_VERSION_H */
> diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
> index af0010c01c..a37c4bafa2 100644
> --- a/drivers/net/gve/meson.build
> +++ b/drivers/net/gve/meson.build
> @@ -12,5 +12,6 @@ sources = files(
> 'gve_rx.c',
> 'gve_tx.c',
> 'gve_ethdev.c',
> + 'gve_version.c',
> )
> includes += include_directories('base')
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH] net/gve: Check whether the driver is compatible with the device presented.
2023-05-04 15:06 ` Ferruh Yigit
@ 2023-05-08 6:23 ` Rushil Gupta
2023-05-08 16:00 ` Ferruh Yigit
0 siblings, 1 reply; 32+ messages in thread
From: Rushil Gupta @ 2023-05-08 6:23 UTC (permalink / raw)
To: Ferruh Yigit
Cc: qi.z.zhang, jingjing.wu, junfeng.guo, joshwash, dev, Jeroen de Borst
Thanks for reviewing Ferruh Yigit! I wanted to answer your queries
before sending the next patch.
Please find answers below:
On Thu, May 4, 2023 at 8:06 AM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>
> On 4/26/2023 10:37 PM, Rushil Gupta wrote:
> > Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
> > version as OS version, reserving driver_version fields for GVE driver
> > version based on features.
> >
>
> './devtools/check-git-log.sh' is giving some warnings, can you please
> check them?
>
> Contribution guide documentation may help to fix reported issues:
> https://doc.dpdk.org/guides/contributing/patches.html#commit-messages-subject-line
>
I did run ./devtools/checkpatches.sh but not
./devtools/check-git-log.sh. I will run both before sending the next
patch.
> > Depends-on: series-27687
> >
> > Signed-off-by: Rushil Gupta <rushilg@google.com>
> > Signed-off-by: Joshua Washington <joshwash@google.com>
> > Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
> > Signed-off-by: Jeroen de Borst <jeroendb@google.com>
> > ---
> > drivers/net/gve/base/gve.h | 3 --
> > drivers/net/gve/base/gve_adminq.c | 19 +++++++++
> > drivers/net/gve/base/gve_adminq.h | 49 ++++++++++++++++++++++-
> > drivers/net/gve/base/gve_osdep.h | 36 +++++++++++++++++
> > drivers/net/gve/gve_ethdev.c | 65 +++++++++++++++++++++++++------
> > drivers/net/gve/gve_ethdev.h | 2 +-
> > drivers/net/gve/gve_version.c | 14 +++++++
> > drivers/net/gve/gve_version.h | 25 ++++++++++++
> > drivers/net/gve/meson.build | 1 +
> > 9 files changed, 198 insertions(+), 16 deletions(-)
> > create mode 100644 drivers/net/gve/gve_version.c
> > create mode 100644 drivers/net/gve/gve_version.h
> >
> > diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
> > index 2dc4507acb..89f9654a72 100644
> > --- a/drivers/net/gve/base/gve.h
> > +++ b/drivers/net/gve/base/gve.h
> > @@ -8,9 +8,6 @@
> >
> > #include "gve_desc.h"
> >
> > -#define GVE_VERSION "1.3.0"
> > -#define GVE_VERSION_PREFIX "GVE-"
> > -
> > #ifndef GOOGLE_VENDOR_ID
> > #define GOOGLE_VENDOR_ID 0x1ae0
> > #endif
> > diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
> > index e745b709b2..2e5099a5b0 100644
> > --- a/drivers/net/gve/base/gve_adminq.c
> > +++ b/drivers/net/gve/base/gve_adminq.c
> > @@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
> > case GVE_ADMINQ_GET_PTYPE_MAP:
> > priv->adminq_get_ptype_map_cnt++;
> > break;
> > + case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
> > + priv->adminq_verify_driver_compatibility_cnt++;
> > + break;
> > default:
> > PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
> > }
> > @@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
> > return gve_adminq_execute_cmd(priv, &cmd);
> > }
> >
> > +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> > + u64 driver_info_len,
> > + dma_addr_t driver_info_addr)
> > +{
> > + union gve_adminq_command cmd;
> > +
> > + memset(&cmd, 0, sizeof(cmd));
> > + cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
> > + cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
> > + .driver_info_len = cpu_to_be64(driver_info_len),
> > + .driver_info_addr = cpu_to_be64(driver_info_addr),
> > + };
> > +
> > + return gve_adminq_execute_cmd(priv, &cmd);
> > +}
> > +
> > int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
> > {
> > union gve_adminq_command cmd;
> > diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
> > index 05550119de..edac32f031 100644
> > --- a/drivers/net/gve/base/gve_adminq.h
> > +++ b/drivers/net/gve/base/gve_adminq.h
> > @@ -1,6 +1,6 @@
> > /* SPDX-License-Identifier: MIT
> > * Google Virtual Ethernet (gve) driver
> > - * Copyright (C) 2015-2022 Google, Inc.
> > + * Copyright (C) 2015-2023 Google, Inc.
> > */
> >
> > #ifndef _GVE_ADMINQ_H
> > @@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
> > GVE_ADMINQ_REPORT_STATS = 0xC,
> > GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
> > GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
> > + GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
> > };
> >
> > /* Admin queue status codes */
> > @@ -145,6 +146,47 @@ enum gve_sup_feature_mask {
> > };
> >
> > #define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
> > +enum gve_driver_capbility {
> > + gve_driver_capability_gqi_qpl = 0,
> > + gve_driver_capability_gqi_rda = 1,
> > + gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
> > + gve_driver_capability_dqo_rda = 3,
> > +};
> > +
> > +#define GVE_CAP1(a) BIT((int)a)
> > +#define GVE_CAP2(a) BIT(((int)a) - 64)
> > +#define GVE_CAP3(a) BIT(((int)a) - 128)
> > +#define GVE_CAP3(a) BIT(((int)a) - 192)
>
> GVE_CAP2, GVE_CAP3 & GVE_CAP4 seems not used, do we need to add them now?
> And I guess '(((int)a) - 64)' usage is to unset some bits, will it be
> better to '(a & ~(1 << 6))' ?
Sure; I will remove GVE_CAP2, GVE_CAP3 & GVE_CAP4.
>
> > +
> > +#define GVE_DRIVER_CAPABILITY_FLAGS1 \
> > + (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
> > + GVE_CAP1(gve_driver_capability_gqi_rda) | \
> > + GVE_CAP1(gve_driver_capability_dqo_rda))
> > +
> > +#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
> > +#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
> > +#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
> > +
> > +struct gve_driver_info {
> > + u8 os_type; /* 0x05 = DPDK */
> > + u8 driver_major;
> > + u8 driver_minor;
> > + u8 driver_sub;
> > + __be32 os_version_major;
> > + __be32 os_version_minor;
> > + __be32 os_version_sub;
> > + __be64 driver_capability_flags[4];
> > + u8 os_version_str1[OS_VERSION_STRLEN];
> > + u8 os_version_str2[OS_VERSION_STRLEN];
> > +};
> > +
> > +struct gve_adminq_verify_driver_compatibility {
> > + __be64 driver_info_len;
> > + __be64 driver_info_addr;
> > +};
> > +
> > +GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
> > +
>
> It looks like we need a static assert helper for DPDK, I will try to
> send something.
>
> >
> > struct gve_adminq_configure_device_resources {
> > __be64 counter_array;
> > @@ -345,6 +387,8 @@ union gve_adminq_command {
> > struct gve_adminq_report_stats report_stats;
> > struct gve_adminq_report_link_speed report_link_speed;
> > struct gve_adminq_get_ptype_map get_ptype_map;
> > + struct gve_adminq_verify_driver_compatibility
> > + verify_driver_compatibility;
> > };
> > };
> > u8 reserved[64];
> > @@ -378,4 +422,7 @@ struct gve_ptype_lut;
> > int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
> > struct gve_ptype_lut *ptype_lut);
> >
> > +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> > + u64 driver_info_len,
> > + dma_addr_t driver_info_addr);
> > #endif /* _GVE_ADMINQ_H */
> > diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
> > index 7cb73002f4..a5efa8543e 100644
> > --- a/drivers/net/gve/base/gve_osdep.h
> > +++ b/drivers/net/gve/base/gve_osdep.h
> > @@ -21,9 +21,14 @@
> > #include <rte_malloc.h>
> > #include <rte_memcpy.h>
> > #include <rte_memzone.h>
> > +#include <rte_version.h>
> >
> > #include "../gve_logs.h"
> >
> > +#ifdef __linux__
> > +#include <sys/utsname.h>
> > +#endif
> > +
> > typedef uint8_t u8;
> > typedef uint16_t u16;
> > typedef uint32_t u32;
> > @@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
> >
> > #define msleep(ms) rte_delay_ms(ms)
> >
> > +#define OS_VERSION_STRLEN 128
> > +struct os_version_string {
> > + char os_version_str1[OS_VERSION_STRLEN];
> > + char os_version_str2[OS_VERSION_STRLEN];
> > +};
> > +
> > /* These macros are used to generate compilation errors if a struct/union
> > * is not exactly the correct length. It gives a divide by zero error if
> > * the struct/union is not of the correct size, otherwise it creates an
> > @@ -79,6 +90,12 @@ typedef rte_iova_t dma_addr_t;
> > #define GVE_CHECK_UNION_LEN(n, X) enum gve_static_asset_enum_##X \
> > { gve_static_assert_##X = (n) / ((sizeof(union X) == (n)) ? 1 : 0) }
> >
> > +#ifndef LINUX_VERSION_MAJOR
> > +#define LINUX_VERSION_MAJOR (((LINUX_VERSION_CODE) >> 16) & 0xff)
> > +#define LINUX_VERSION_SUBLEVEL (((LINUX_VERSION_CODE) >> 8) & 0xff)
> > +#define LINUX_VERSION_PATCHLEVEL ((LINUX_VERSION_CODE) & 0xff)
> > +#endif
> > +
>
> Do we need Linux version macros in DPDK? They are not used at all.
You are right. Will remove.
>
> > static __rte_always_inline u8
> > readb(volatile void *addr)
> > {
> > @@ -156,4 +173,23 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
> > mem->pa = 0;
> > }
> >
> > +static inline void
> > +populate_driver_version_strings(struct os_version_string *os_version_str)
> > +{
> > +#ifdef __linux__
> > + struct utsname uts;
> > + if (uname(&uts) >= 0) {
> > + /* release */
> > + rte_strscpy(os_version_str->os_version_str1, uts.release,
> > + sizeof(os_version_str->os_version_str1));
> > + /* version */
> > + rte_strscpy(os_version_str->os_version_str2, uts.version,
> > + sizeof(os_version_str->os_version_str2));
> > + }
>
> Since OS type is reported as DPDK, do we need underlying Linux release
> information to the FW?
>
> If not we can remove #ifdef and 'uname()' to reduce platform specific code.
Yes it is a GCE business requirement (to look at DPDK usage by linux
kernel version).
>
> > +#else
> > + /* gVNIC is currently not supported on OS like FreeBSD */
>
> meson file only disable for Windows, for FreeBSD driver is compiled.
> If driver is only supported on Linux, can you change the meson file to
> reflec this?
>
Ok will do.
> > + RTE_SET_USED(os_version_str);
> > +#endif
> > +}
> > +
> > #endif /* _GVE_OSDEP_H_ */
> > diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
> > index cf28a4a3b7..1d6e134fff 100644
> > --- a/drivers/net/gve/gve_ethdev.c
> > +++ b/drivers/net/gve/gve_ethdev.c
> > @@ -5,21 +5,13 @@
> > #include "gve_ethdev.h"
> > #include "base/gve_adminq.h"
> > #include "base/gve_register.h"
> > -
> > -const char gve_version_str[] = GVE_VERSION;
> > -static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
> > +#include "base/gve_osdep.h"
> > +#include "gve_version.h"
> >
> > static void
> > gve_write_version(uint8_t *driver_version_register)
> > {
> > - const char *c = gve_version_prefix;
> > -
> > - while (*c) {
> > - writeb(*c, driver_version_register);
> > - c++;
> > - }
> > -
> > - c = gve_version_str;
> > + const char *c = gve_version_string();
> > while (*c) {
> > writeb(*c, driver_version_register);
> > c++;
> > @@ -265,6 +257,52 @@ gve_dev_close(struct rte_eth_dev *dev)
> > return err;
> > }
> >
> > +static int
> > +gve_verify_driver_compatibility(struct gve_priv *priv)
> > +{
> > + const struct rte_memzone *driver_info_bus;
>
> What does '_bus' indicates in the variable name?
This seems like a typo. Will correct.
>
> > + struct gve_driver_info *driver_info;
> > + int err;
> > +
> > + driver_info_bus = rte_memzone_reserve_aligned("verify_driver_compatibility",
> > + sizeof(struct gve_driver_info),
> > + rte_socket_id(),
> > + RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
>
> There is no benefit to use DPDK memory APIs for this usage, a 'malloc()'
> will do the work, and maybe better as compilers/static analyzers
> recognizes it more.
Makes sense.
>
> > + if (driver_info_bus == NULL) {
> > + PMD_DRV_LOG(ERR,
> > + "Could not alloc memzone for driver compatibility");
> > + return -ENOMEM;
> > + }
> > + driver_info = (struct gve_driver_info *)driver_info_bus->addr;
> > + *driver_info = (struct gve_driver_info) {
> > + .os_type = 5, /* DPDK */
> > + .driver_major = GVE_VERSION_MAJOR,
> > + .driver_minor = GVE_VERSION_MINOR,
> > + .driver_sub = GVE_VERSION_SUB,
> > + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
> > + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
> > + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> > + .driver_capability_flags = {
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> > + },
> > + };
> > +
> > + populate_driver_version_strings((struct os_version_string *)&driver_info->os_version_str1);
> > +
>
> If you pass two strings as parameter to
> 'populate_driver_version_strings()' can you get rid of interim type
> "struct os_version_string" and above casting?
Ok.
>
> > + err = gve_adminq_verify_driver_compatibility(priv,
> > + sizeof(struct gve_driver_info), (dma_addr_t)driver_info_bus);
> > +
> > + /* It's ok if the device doesn't support this */
> > + if (err == -EOPNOTSUPP)
> > + err = 0;
>
> Is this error saying DPDK version is not supported?
> Where a change should go to be able to identify and verify DPDK platform
> in GVE? Does it require continious update as DPDK get updated?
>
This means vNIC doesn't support verify and log adminq information
(because of older hypervisor).
Does it require continuous update : No. This is to make sure we return
proper error code for older vNIC.
> > +
> > + rte_memzone_free(driver_info_bus);
> > + return err;
> > +}
> > +
> > static int
> > gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
> > {
> > @@ -672,6 +710,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
> > PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
> > return err;
> > }
> > + err = gve_verify_driver_compatibility(priv);
> > + if (err) {
> > + PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
> > + goto free_adminq;
> > + }
> >
> > if (skip_describe_device)
> > goto setup_device;
> > diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
> > index 42a02cf5d4..23ccff37d3 100644
> > --- a/drivers/net/gve/gve_ethdev.h
> > +++ b/drivers/net/gve/gve_ethdev.h
> > @@ -222,7 +222,7 @@ struct gve_priv {
> > uint32_t adminq_report_stats_cnt;
> > uint32_t adminq_report_link_speed_cnt;
> > uint32_t adminq_get_ptype_map_cnt;
> > -
> > + uint32_t adminq_verify_driver_compatibility_cnt;
> > volatile uint32_t state_flags;
> >
> > /* Gvnic device link speed from hypervisor. */
> > diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
> > new file mode 100644
> > index 0000000000..7eaa689d90
> > --- /dev/null
> > +++ b/drivers/net/gve/gve_version.c
> > @@ -0,0 +1,14 @@
> > +/* SPDX-License-Identifier: MIT
> > + * Google Virtual Ethernet (gve) driver
> > + * Copyright (C) 2015-2023 Google, Inc.
> > + */
>
> This is not base code, but DPDK layer, license should be BSD-3.
>
Ok
> > +#include "gve_version.h"
> > +
> > +const char *gve_version_string(void)
> > +{
> > + static char gve_version[10];
> > + snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
> > + GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
> > + GVE_VERSION_SUB);
> > + return gve_version;
> > +}
> > diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
> > new file mode 100644
> > index 0000000000..9af6a00568
> > --- /dev/null
> > +++ b/drivers/net/gve/gve_version.h
> > @@ -0,0 +1,25 @@
> > +/* SPDX-License-Identifier: MIT
> > + * Google Virtual Ethernet (gve) driver
> > + * Copyright (C) 2015-2023 Google, Inc.
> > + */
> > +
>
> This is not base code, but DPDK layer, license should be BSD-3.
>
Ok
> > +#ifndef _GVE_VERSION_H_
> > +#define _GVE_VERSION_H_
> > +
> > +#include <rte_version.h>
> > +
> > +#define GVE_VERSION_PREFIX "DPDK-"
> > +#define GVE_VERSION_MAJOR 1
> > +#define GVE_VERSION_MINOR 0
> > +#define GVE_VERSION_SUB 0
> > +
>
> Is this GVE base version, or DPDK gve version?
> Previous version information was "GVE-1.3.0", now it is becoming
> "DPDK-1.0.0",
> is this breaking the version link with GVE base version and creating a
> new versioning scheme for DPDK GVE driver?
>
> Btw, documentation still has "v1.3.0. GVE base code", should it be
> updated as well?
>
DPDK-1.0.0 is the DPDK driver version. GVE driver versioning only
applies for linux kernel Gvnic driver.
Similarly Windows Gvnic driver has different versioning system.
>
> > +#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
> > +#define DPDK_VERSION_MINOR RTE_VER_MINOR
> > +#define DPDK_VERSION_SUB RTE_VER_RELEASE
> > +
>
> RTE_VER_RELEASE is 1 (-rc1), 2 (-rc2), etc... And if it is not release
> candidate it is always 99, so it may not be very usefull for the
> official releases and changes frequently for the development tree, are
> you sure to use this value?
>
It is ok for our usecase.
>
> > +
> > +const char *
> > +gve_version_string(void);
> > +
> > +
> > +#endif /* GVE_VERSION_H */
> > diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
> > index af0010c01c..a37c4bafa2 100644
> > --- a/drivers/net/gve/meson.build
> > +++ b/drivers/net/gve/meson.build
> > @@ -12,5 +12,6 @@ sources = files(
> > 'gve_rx.c',
> > 'gve_tx.c',
> > 'gve_ethdev.c',
> > + 'gve_version.c',
> > )
> > includes += include_directories('base')
>
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH] net/gve: Check whether the driver is compatible with the device presented.
2023-05-08 6:23 ` Rushil Gupta
@ 2023-05-08 16:00 ` Ferruh Yigit
2023-05-08 19:22 ` Rushil Gupta
0 siblings, 1 reply; 32+ messages in thread
From: Ferruh Yigit @ 2023-05-08 16:00 UTC (permalink / raw)
To: Rushil Gupta
Cc: qi.z.zhang, jingjing.wu, junfeng.guo, joshwash, dev, Jeroen de Borst
On 5/8/2023 7:23 AM, Rushil Gupta wrote:
>>> +#ifndef _GVE_VERSION_H_
>>> +#define _GVE_VERSION_H_
>>> +
>>> +#include <rte_version.h>
>>> +
>>> +#define GVE_VERSION_PREFIX "DPDK-"
>>> +#define GVE_VERSION_MAJOR 1
>>> +#define GVE_VERSION_MINOR 0
>>> +#define GVE_VERSION_SUB 0
>>> +
>> Is this GVE base version, or DPDK gve version?
>> Previous version information was "GVE-1.3.0", now it is becoming
>> "DPDK-1.0.0",
>> is this breaking the version link with GVE base version and creating a
>> new versioning scheme for DPDK GVE driver?
>>
>> Btw, documentation still has "v1.3.0. GVE base code", should it be
>> updated as well?
>>
> DPDK-1.0.0 is the DPDK driver version. GVE driver versioning only
> applies for linux kernel Gvnic driver.
> Similarly Windows Gvnic driver has different versioning system.
So creating a new versioning scheme for DPDK driver, I guess that is OK.
Since there is a new version, is it clear how to manage the versioning,
like when to update major version and when to update minor etc? If so
can you please document this?
And base code is still coming from the Linux kernel driver, I wonder if
a mapping between versions of these two is required.
As mentioned "v1.3.0" is still in the documentation, what happens if
base code updated and some relevant update is required in the dpdk
driver code? How to record/manage this?
Some drivers records the base code version in a readme file in the base
folder, maybe same can be done.
^ permalink raw reply [flat|nested] 32+ messages in thread
* [v2] net/gve: check driver compatibility
2023-04-14 5:14 [PATCH] net/gve: Check whether the driver is compatible with the device presented Rushil Gupta
2023-04-14 9:05 ` Guo, Junfeng
2023-04-26 21:37 ` Rushil Gupta
@ 2023-05-08 19:14 ` Rushil Gupta
2 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-08 19:14 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
drivers/net/gve/base/gve.h | 3 --
drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 14 +++++++
drivers/net/gve/gve_version.h | 25 +++++++++++++
drivers/net/gve/meson.build | 7 ++++
9 files changed, 185 insertions(+), 16 deletions(-)
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2dc4507acb..89f9654a72 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -8,9 +8,6 @@
#include "gve_desc.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e745b709b2..2e5099a5b0 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..e30b184913 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +384,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +419,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index 7cb73002f4..43081ec2a9 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -156,4 +167,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(char *str1, char *str2)
+{
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(str1, uts.release,
+ OS_VERSION_STRLEN);
+ /* version */
+ rte_strscpy(str2, uts.version,
+ OS_VERSION_STRLEN);
+ }
+}
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index cf28a4a3b7..12a4d07252 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -265,6 +257,48 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info = rte_zmalloc("driver info", sizeof(struct gve_driver_info), 0);
+ if (driver_info == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc for driver compatibility");
+ return -ENOMEM;
+ }
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((char *)driver_info->os_version_str1,
+ (char *)driver_info->os_version_str2);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
+
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_free(driver_info);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -672,6 +706,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index 42a02cf5d4..23ccff37d3 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -222,7 +222,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..f02b4f696f
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Google Virtual Ethernet (gve) driver
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[10];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..eca717d64b
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Google Virtual Ethernet (gve) driver
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index af0010c01c..62ab02d0dc 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -7,10 +7,17 @@ if is_windows
subdir_done()
endif
+if is_freebsd
+ build = false
+ reason = 'not supported on FreeBSD'
+ subdir_done()
+endif
+
sources = files(
'base/gve_adminq.c',
'gve_rx.c',
'gve_tx.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.1.521.gf1e218fcd8-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* [v2] net/gve: check driver compatibility
2023-04-26 21:37 ` Rushil Gupta
2023-05-04 15:06 ` Ferruh Yigit
@ 2023-05-08 19:15 ` Rushil Gupta
2023-05-17 16:58 ` Ferruh Yigit
` (3 more replies)
2023-05-18 17:40 ` [v3] " Rushil Gupta
2 siblings, 4 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-08 19:15 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
drivers/net/gve/base/gve.h | 3 --
drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 14 +++++++
drivers/net/gve/gve_version.h | 25 +++++++++++++
drivers/net/gve/meson.build | 7 ++++
9 files changed, 185 insertions(+), 16 deletions(-)
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2dc4507acb..89f9654a72 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -8,9 +8,6 @@
#include "gve_desc.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e745b709b2..2e5099a5b0 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..e30b184913 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +384,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +419,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index 7cb73002f4..43081ec2a9 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -156,4 +167,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(char *str1, char *str2)
+{
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(str1, uts.release,
+ OS_VERSION_STRLEN);
+ /* version */
+ rte_strscpy(str2, uts.version,
+ OS_VERSION_STRLEN);
+ }
+}
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index cf28a4a3b7..12a4d07252 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -265,6 +257,48 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info = rte_zmalloc("driver info", sizeof(struct gve_driver_info), 0);
+ if (driver_info == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc for driver compatibility");
+ return -ENOMEM;
+ }
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((char *)driver_info->os_version_str1,
+ (char *)driver_info->os_version_str2);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
+
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_free(driver_info);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -672,6 +706,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index 42a02cf5d4..23ccff37d3 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -222,7 +222,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..f02b4f696f
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Google Virtual Ethernet (gve) driver
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[10];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..eca717d64b
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Google Virtual Ethernet (gve) driver
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index af0010c01c..62ab02d0dc 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -7,10 +7,17 @@ if is_windows
subdir_done()
endif
+if is_freebsd
+ build = false
+ reason = 'not supported on FreeBSD'
+ subdir_done()
+endif
+
sources = files(
'base/gve_adminq.c',
'gve_rx.c',
'gve_tx.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.1.521.gf1e218fcd8-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH] net/gve: Check whether the driver is compatible with the device presented.
2023-05-08 16:00 ` Ferruh Yigit
@ 2023-05-08 19:22 ` Rushil Gupta
0 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-08 19:22 UTC (permalink / raw)
To: Ferruh Yigit
Cc: qi.z.zhang, jingjing.wu, junfeng.guo, joshwash, dev, Jeroen de Borst
Sounds good. I will document the versioning in a separate patch. For
now, the DPDK driver with DQO changes is reported as 1.0.0.
I think there is some confusion here. The base code is not coming from
the linux kernel driver.
Linux kernel driver is in a different repository and it has nothing to
do with the dpdk driver version. Ideally, we'd want the base code of
both drivers to be the same but there are several higher priority
projects that are taking precedence.
Btw I have addressed your comments:
http://patchwork.dpdk.org/project/dpdk/patch/20230508191552.104540-1-rushilg@google.com/
On Mon, May 8, 2023 at 9:00 AM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>
> On 5/8/2023 7:23 AM, Rushil Gupta wrote:
> >>> +#ifndef _GVE_VERSION_H_
> >>> +#define _GVE_VERSION_H_
> >>> +
> >>> +#include <rte_version.h>
> >>> +
> >>> +#define GVE_VERSION_PREFIX "DPDK-"
> >>> +#define GVE_VERSION_MAJOR 1
> >>> +#define GVE_VERSION_MINOR 0
> >>> +#define GVE_VERSION_SUB 0
> >>> +
> >> Is this GVE base version, or DPDK gve version?
> >> Previous version information was "GVE-1.3.0", now it is becoming
> >> "DPDK-1.0.0",
> >> is this breaking the version link with GVE base version and creating a
> >> new versioning scheme for DPDK GVE driver?
> >>
> >> Btw, documentation still has "v1.3.0. GVE base code", should it be
> >> updated as well?
> >>
> > DPDK-1.0.0 is the DPDK driver version. GVE driver versioning only
> > applies for linux kernel Gvnic driver.
> > Similarly Windows Gvnic driver has different versioning system.
>
> So creating a new versioning scheme for DPDK driver, I guess that is OK.
> Since there is a new version, is it clear how to manage the versioning,
> like when to update major version and when to update minor etc? If so
> can you please document this?
>
> And base code is still coming from the Linux kernel driver, I wonder if
> a mapping between versions of these two is required.
> As mentioned "v1.3.0" is still in the documentation, what happens if
> base code updated and some relevant update is required in the dpdk
> driver code? How to record/manage this?
> Some drivers records the base code version in a readme file in the base
> folder, maybe same can be done.
>
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v2] net/gve: check driver compatibility
2023-05-08 19:15 ` [v2] net/gve: check driver compatibility Rushil Gupta
@ 2023-05-17 16:58 ` Ferruh Yigit
2023-05-18 17:41 ` Rushil Gupta
2023-05-19 7:15 ` [v3] " Rushil Gupta
` (2 subsequent siblings)
3 siblings, 1 reply; 32+ messages in thread
From: Ferruh Yigit @ 2023-05-17 16:58 UTC (permalink / raw)
To: Rushil Gupta, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Jeroen de Borst
On 5/8/2023 8:15 PM, Rushil Gupta wrote:
> Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
> version as OS version, reserving driver_version fields for GVE driver
> version based on features.
>
> Signed-off-by: Rushil Gupta <rushilg@google.com>
> Signed-off-by: Joshua Washington <joshwash@google.com>
> Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
> Signed-off-by: Jeroen de Borst <jeroendb@google.com>
> ---
> drivers/net/gve/base/gve.h | 3 --
> drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
> drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
> drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
> drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
> drivers/net/gve/gve_ethdev.h | 2 +-
> drivers/net/gve/gve_version.c | 14 +++++++
> drivers/net/gve/gve_version.h | 25 +++++++++++++
> drivers/net/gve/meson.build | 7 ++++
> 9 files changed, 185 insertions(+), 16 deletions(-)
> create mode 100644 drivers/net/gve/gve_version.c
> create mode 100644 drivers/net/gve/gve_version.h
>
'doc/guides/nics/gve.rst' has following reference to Linux kernel version:
"
The base code is under MIT license and based on GVE kernel driver v1.3.0.
"
Previously you mentioned that Linux kernel code has nothing to do with
DPDK version, should above note removed or updated?
<...>
> +static int
> +gve_verify_driver_compatibility(struct gve_priv *priv)
> +{
> + struct gve_driver_info *driver_info;
> + int err;
> +
> + driver_info = rte_zmalloc("driver info", sizeof(struct gve_driver_info), 0);
Can use calloc(), no need to use DPDK memory APIs.
This memory is not for datapath, and only used for short time.
> + if (driver_info == NULL) {
> + PMD_DRV_LOG(ERR,
> + "Could not alloc for driver compatibility");
Message can be misleading, adding 'verify' may help.
> + return -ENOMEM;
> + }
> + *driver_info = (struct gve_driver_info) {
> + .os_type = 5, /* DPDK */
> + .driver_major = GVE_VERSION_MAJOR,
> + .driver_minor = GVE_VERSION_MINOR,
> + .driver_sub = GVE_VERSION_SUB,
> + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
> + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
> + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> + .driver_capability_flags = {
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> + },
> + };
> +
> + populate_driver_version_strings((char *)driver_info->os_version_str1,
> + (char *)driver_info->os_version_str2);
> +
Is it accepted by adminq_verify if 'os_version_str1' & 'os_version_str2'
is not set? If not 'populate_driver_version_strings()' should return
success/error value.
> + err = gve_adminq_verify_driver_compatibility(priv,
> + sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
> +
> + /* It's ok if the device doesn't support this */
> + if (err == -EOPNOTSUPP)
> + err = 0;
> +
> + rte_free(driver_info);
> + return err;
> +}
> +
> static int
> gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
> {
> @@ -672,6 +706,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
> PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
> return err;
> }
> + err = gve_verify_driver_compatibility(priv);
> + if (err) {
> + PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
> + goto free_adminq;
> + }
>
> if (skip_describe_device)
> goto setup_device;
> diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
> index 42a02cf5d4..23ccff37d3 100644
> --- a/drivers/net/gve/gve_ethdev.h
> +++ b/drivers/net/gve/gve_ethdev.h
> @@ -222,7 +222,7 @@ struct gve_priv {
> uint32_t adminq_report_stats_cnt;
> uint32_t adminq_report_link_speed_cnt;
> uint32_t adminq_get_ptype_map_cnt;
> -
> + uint32_t adminq_verify_driver_compatibility_cnt;
> volatile uint32_t state_flags;
>
> /* Gvnic device link speed from hypervisor. */
> diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
> new file mode 100644
> index 0000000000..f02b4f696f
> --- /dev/null
> +++ b/drivers/net/gve/gve_version.c
> @@ -0,0 +1,14 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Google Virtual Ethernet (gve) driver
Is above line added intentionally?
Normally SPDX tag only contains license and copyright information,
please check 'gve_ethdev.c' for sample tag.
> + * Copyright (C) 2015-2023 Google, Inc.
> + */
> +#include "gve_version.h"
> +
> +const char *gve_version_string(void)
> +{
> + static char gve_version[10];
DPDK-1.0.0 => 10 chars, it doesn't left room for terminating NULL, but
at least 'gve_write_version()' seems expecting to have one.
> + snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
> + GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
> + GVE_VERSION_SUB);
'snprintf()' adds terminating NULL, truncating version string, need more
space in the 'gve_version' array.
> + return gve_version;
> +}
> diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
> new file mode 100644
> index 0000000000..eca717d64b
> --- /dev/null
> +++ b/drivers/net/gve/gve_version.h
> @@ -0,0 +1,25 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Google Virtual Ethernet (gve) driver
Ditto
> + * Copyright (C) 2015-2023 Google, Inc.
> + */
> +
> +#ifndef _GVE_VERSION_H_
> +#define _GVE_VERSION_H_
> +
> +#include <rte_version.h>
> +
> +#define GVE_VERSION_PREFIX "DPDK-"
> +#define GVE_VERSION_MAJOR 1
> +#define GVE_VERSION_MINOR 0
> +#define GVE_VERSION_SUB 0
> +
> +#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
> +#define DPDK_VERSION_MINOR RTE_VER_MINOR
> +#define DPDK_VERSION_SUB RTE_VER_RELEASE
> +
> +
> +const char *
> +gve_version_string(void);
> +
> +
> +#endif /* GVE_VERSION_H */
> diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
> index af0010c01c..62ab02d0dc 100644
> --- a/drivers/net/gve/meson.build
> +++ b/drivers/net/gve/meson.build
> @@ -7,10 +7,17 @@ if is_windows
> subdir_done()
> endif
>
> +if is_freebsd
> + build = false
> + reason = 'not supported on FreeBSD'
> + subdir_done()
> +endif
> +
instead of both 'is_windows' & 'is_freebsd' checks,
can check as "not is_linux":
if not is_linux
build = false
reason = 'only supported on Linux'
endif
^ permalink raw reply [flat|nested] 32+ messages in thread
* [v3] net/gve: check driver compatibility
2023-04-26 21:37 ` Rushil Gupta
2023-05-04 15:06 ` Ferruh Yigit
2023-05-08 19:15 ` [v2] net/gve: check driver compatibility Rushil Gupta
@ 2023-05-18 17:40 ` Rushil Gupta
2 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-18 17:40 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
drivers/net/gve/base/gve.h | 3 --
drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 13 +++++++
drivers/net/gve/gve_version.h | 24 ++++++++++++
drivers/net/gve/meson.build | 5 ++-
9 files changed, 179 insertions(+), 18 deletions(-)
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2dc4507acb..89f9654a72 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -8,9 +8,6 @@
#include "gve_desc.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e745b709b2..2e5099a5b0 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..e30b184913 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +384,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +419,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index 7cb73002f4..43081ec2a9 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -156,4 +167,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(char *str1, char *str2)
+{
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(str1, uts.release,
+ OS_VERSION_STRLEN);
+ /* version */
+ rte_strscpy(str2, uts.version,
+ OS_VERSION_STRLEN);
+ }
+}
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index cf28a4a3b7..2766ca0d3b 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -265,6 +257,48 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info = calloc(sizeof(struct gve_driver_info), 0);
+ if (driver_info == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc for verify driver compatibility");
+ return -ENOMEM;
+ }
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((char *)driver_info->os_version_str1,
+ (char *)driver_info->os_version_str2);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
+
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ free(driver_info);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -672,6 +706,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index 42a02cf5d4..23ccff37d3 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -222,7 +222,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..5fe34dc179
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[20];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..4dd998dca1
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index af0010c01c..365b7ffdaa 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(C) 2022 Intel Corporation
-if is_windows
+if not is_linux
build = false
- reason = 'not supported on Windows'
+ reason = 'only supported on Linux'
subdir_done()
endif
@@ -12,5 +12,6 @@ sources = files(
'gve_rx.c',
'gve_tx.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.1.698.g37aff9b760-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v2] net/gve: check driver compatibility
2023-05-17 16:58 ` Ferruh Yigit
@ 2023-05-18 17:41 ` Rushil Gupta
0 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-18 17:41 UTC (permalink / raw)
To: Ferruh Yigit
Cc: qi.z.zhang, jingjing.wu, junfeng.guo, joshwash, dev, Jeroen de Borst
[-- Attachment #1: Type: text/plain, Size: 8116 bytes --]
Thanks for reviewing. Here is v3:
http://patchwork.dpdk.org/project/dpdk/patch/20230518174005.1377467-1-rushilg@google.com/
On Wed, May 17, 2023 at 9:59 AM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> On 5/8/2023 8:15 PM, Rushil Gupta wrote:
> > Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
> > version as OS version, reserving driver_version fields for GVE driver
> > version based on features.
> >
> > Signed-off-by: Rushil Gupta <rushilg@google.com>
> > Signed-off-by: Joshua Washington <joshwash@google.com>
> > Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
> > Signed-off-by: Jeroen de Borst <jeroendb@google.com>
> > ---
> > drivers/net/gve/base/gve.h | 3 --
> > drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
> > drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
> > drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
> > drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
> > drivers/net/gve/gve_ethdev.h | 2 +-
> > drivers/net/gve/gve_version.c | 14 +++++++
> > drivers/net/gve/gve_version.h | 25 +++++++++++++
> > drivers/net/gve/meson.build | 7 ++++
> > 9 files changed, 185 insertions(+), 16 deletions(-)
> > create mode 100644 drivers/net/gve/gve_version.c
> > create mode 100644 drivers/net/gve/gve_version.h
> >
>
> 'doc/guides/nics/gve.rst' has following reference to Linux kernel version:
>
> "
> The base code is under MIT license and based on GVE kernel driver v1.3.0.
> "
>
> Previously you mentioned that Linux kernel code has nothing to do with
> DPDK version, should above note removed or updated?
>
> I will address this in the license patch 23.11. We will port all of our
MIT licenses to BSD.
http://patchwork.dpdk.org/project/dpdk/patch/20230411045908.844901-2-rushilg@google.com/
For now let's keep this change separate from license update/removal.
> <...>
>
> > +static int
> > +gve_verify_driver_compatibility(struct gve_priv *priv)
> > +{
> > + struct gve_driver_info *driver_info;
> > + int err;
> > +
> > + driver_info = rte_zmalloc("driver info", sizeof(struct
> gve_driver_info), 0);
>
> Can use calloc(), no need to use DPDK memory APIs.
> This memory is not for datapath, and only used for short time.
>
Done
>
> > + if (driver_info == NULL) {
> > + PMD_DRV_LOG(ERR,
> > + "Could not alloc for driver compatibility");
>
> Message can be misleading, adding 'verify' may help.
>
Done
>
> > + return -ENOMEM;
> > + }
> > + *driver_info = (struct gve_driver_info) {
> > + .os_type = 5, /* DPDK */
> > + .driver_major = GVE_VERSION_MAJOR,
> > + .driver_minor = GVE_VERSION_MINOR,
> > + .driver_sub = GVE_VERSION_SUB,
> > + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
> > + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
> > + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> > + .driver_capability_flags = {
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> > + },
> > + };
> > +
> > + populate_driver_version_strings((char
> *)driver_info->os_version_str1,
> > + (char *)driver_info->os_version_str2);
> > +
>
> Is it accepted by adminq_verify if 'os_version_str1' & 'os_version_str2'
> is not set? If not 'populate_driver_version_strings()' should return
> success/error value.
>
It is acceptable if 'os_version_str1' & 'os_version_str2' are not set.
>
> > + err = gve_adminq_verify_driver_compatibility(priv,
> > + sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
> > +
> > + /* It's ok if the device doesn't support this */
> > + if (err == -EOPNOTSUPP)
> > + err = 0;
> > +
> > + rte_free(driver_info);
> > + return err;
> > +}
> > +
> > static int
> > gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info
> *dev_info)
> > {
> > @@ -672,6 +706,11 @@ gve_init_priv(struct gve_priv *priv, bool
> skip_describe_device)
> > PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d",
> err);
> > return err;
> > }
> > + err = gve_verify_driver_compatibility(priv);
> > + if (err) {
> > + PMD_DRV_LOG(ERR, "Could not verify driver compatibility:
> err=%d", err);
> > + goto free_adminq;
> > + }
> >
> > if (skip_describe_device)
> > goto setup_device;
> > diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
> > index 42a02cf5d4..23ccff37d3 100644
> > --- a/drivers/net/gve/gve_ethdev.h
> > +++ b/drivers/net/gve/gve_ethdev.h
> > @@ -222,7 +222,7 @@ struct gve_priv {
> > uint32_t adminq_report_stats_cnt;
> > uint32_t adminq_report_link_speed_cnt;
> > uint32_t adminq_get_ptype_map_cnt;
> > -
> > + uint32_t adminq_verify_driver_compatibility_cnt;
> > volatile uint32_t state_flags;
> >
> > /* Gvnic device link speed from hypervisor. */
> > diff --git a/drivers/net/gve/gve_version.c
> b/drivers/net/gve/gve_version.c
> > new file mode 100644
> > index 0000000000..f02b4f696f
> > --- /dev/null
> > +++ b/drivers/net/gve/gve_version.c
> > @@ -0,0 +1,14 @@
> > +/* SPDX-License-Identifier: BSD-3-Clause
> > + * Google Virtual Ethernet (gve) driver
>
> Is above line added intentionally?
> Normally SPDX tag only contains license and copyright information,
> please check 'gve_ethdev.c' for sample tag.
>
Fixed.
>
> > + * Copyright (C) 2015-2023 Google, Inc.
> > + */
> > +#include "gve_version.h"
> > +
> > +const char *gve_version_string(void)
> > +{
> > + static char gve_version[10];
>
> DPDK-1.0.0 => 10 chars, it doesn't left room for terminating NULL, but
> at least 'gve_write_version()' seems expecting to have one.
>
Great catch! Fixed.
>
> > + snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
> > + GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
> > + GVE_VERSION_SUB);
>
> 'snprintf()' adds terminating NULL, truncating version string, need more
> space in the 'gve_version' array.
>
> > + return gve_version;
> > +}
> > diff --git a/drivers/net/gve/gve_version.h
> b/drivers/net/gve/gve_version.h
> > new file mode 100644
> > index 0000000000..eca717d64b
> > --- /dev/null
> > +++ b/drivers/net/gve/gve_version.h
> > @@ -0,0 +1,25 @@
> > +/* SPDX-License-Identifier: BSD-3-Clause
> > + * Google Virtual Ethernet (gve) driver
>
> Ditto
>
Fixed.
>
> > + * Copyright (C) 2015-2023 Google, Inc.
> > + */
> > +
> > +#ifndef _GVE_VERSION_H_
> > +#define _GVE_VERSION_H_
> > +
> > +#include <rte_version.h>
> > +
> > +#define GVE_VERSION_PREFIX "DPDK-"
> > +#define GVE_VERSION_MAJOR 1
> > +#define GVE_VERSION_MINOR 0
> > +#define GVE_VERSION_SUB 0
> > +
> > +#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
> > +#define DPDK_VERSION_MINOR RTE_VER_MINOR
> > +#define DPDK_VERSION_SUB RTE_VER_RELEASE
> > +
> > +
> > +const char *
> > +gve_version_string(void);
> > +
> > +
> > +#endif /* GVE_VERSION_H */
> > diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
> > index af0010c01c..62ab02d0dc 100644
> > --- a/drivers/net/gve/meson.build
> > +++ b/drivers/net/gve/meson.build
> > @@ -7,10 +7,17 @@ if is_windows
> > subdir_done()
> > endif
> >
> > +if is_freebsd
> > + build = false
> > + reason = 'not supported on FreeBSD'
> > + subdir_done()
> > +endif
> > +
>
> instead of both 'is_windows' & 'is_freebsd' checks,
> can check as "not is_linux":
>
> if not is_linux
> build = false
> reason = 'only supported on Linux'
> endif
>
Fixed.
[-- Attachment #2: Type: text/html, Size: 11398 bytes --]
^ permalink raw reply [flat|nested] 32+ messages in thread
* [v3] net/gve: check driver compatibility
2023-05-08 19:15 ` [v2] net/gve: check driver compatibility Rushil Gupta
2023-05-17 16:58 ` Ferruh Yigit
@ 2023-05-19 7:15 ` Rushil Gupta
2023-05-19 7:23 ` [PATCH] " Rushil Gupta
2023-05-19 7:26 ` Rushil Gupta
3 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-19 7:15 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
0001-net-gve-check-driver-compatibility.patch | 388 ++++++++++++++++++
drivers/net/gve/base/gve.h | 3 -
drivers/net/gve/base/gve_adminq.c | 19 +
drivers/net/gve/base/gve_adminq.h | 46 ++-
drivers/net/gve/base/gve_osdep.h | 24 ++
drivers/net/gve/gve_ethdev.c | 60 ++-
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 13 +
drivers/net/gve/gve_version.h | 24 ++
drivers/net/gve/meson.build | 5 +-
10 files changed, 566 insertions(+), 18 deletions(-)
create mode 100644 0001-net-gve-check-driver-compatibility.patch
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/0001-net-gve-check-driver-compatibility.patch b/0001-net-gve-check-driver-compatibility.patch
new file mode 100644
index 0000000000..0187db7dc2
--- /dev/null
+++ b/0001-net-gve-check-driver-compatibility.patch
@@ -0,0 +1,388 @@
+From 1624a08eaa94242286da930b92b227759f906bd9 Mon Sep 17 00:00:00 2001
+From: Rushil Gupta <rushilg@google.com>
+Date: Thu, 13 Apr 2023 22:06:20 -0700
+Subject: [v3] net/gve: check driver compatibility
+
+Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
+version as OS version, reserving driver_version fields for GVE driver
+version based on features.
+
+Signed-off-by: Rushil Gupta <rushilg@google.com>
+Signed-off-by: Joshua Washington <joshwash@google.com>
+Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
+Signed-off-by: Jeroen de Borst <jeroendb@google.com>
+---
+ drivers/net/gve/base/gve.h | 3 --
+ drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
+ drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
+ drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
+ drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
+ drivers/net/gve/gve_ethdev.h | 2 +-
+ drivers/net/gve/gve_version.c | 13 +++++++
+ drivers/net/gve/gve_version.h | 24 ++++++++++++
+ drivers/net/gve/meson.build | 5 ++-
+ 9 files changed, 179 insertions(+), 18 deletions(-)
+ create mode 100644 drivers/net/gve/gve_version.c
+ create mode 100644 drivers/net/gve/gve_version.h
+
+diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
+index 2dc4507acb..89f9654a72 100644
+--- a/drivers/net/gve/base/gve.h
++++ b/drivers/net/gve/base/gve.h
+@@ -8,9 +8,6 @@
+
+ #include "gve_desc.h"
+
+-#define GVE_VERSION "1.3.0"
+-#define GVE_VERSION_PREFIX "GVE-"
+-
+ #ifndef GOOGLE_VENDOR_ID
+ #define GOOGLE_VENDOR_ID 0x1ae0
+ #endif
+diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
+index e745b709b2..2e5099a5b0 100644
+--- a/drivers/net/gve/base/gve_adminq.c
++++ b/drivers/net/gve/base/gve_adminq.c
+@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
+ case GVE_ADMINQ_GET_PTYPE_MAP:
+ priv->adminq_get_ptype_map_cnt++;
+ break;
++ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
++ priv->adminq_verify_driver_compatibility_cnt++;
++ break;
+ default:
+ PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
+ }
+@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
+ return gve_adminq_execute_cmd(priv, &cmd);
+ }
+
++int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
++ u64 driver_info_len,
++ dma_addr_t driver_info_addr)
++{
++ union gve_adminq_command cmd;
++
++ memset(&cmd, 0, sizeof(cmd));
++ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
++ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
++ .driver_info_len = cpu_to_be64(driver_info_len),
++ .driver_info_addr = cpu_to_be64(driver_info_addr),
++ };
++
++ return gve_adminq_execute_cmd(priv, &cmd);
++}
++
+ int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
+ {
+ union gve_adminq_command cmd;
+diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
+index 05550119de..e30b184913 100644
+--- a/drivers/net/gve/base/gve_adminq.h
++++ b/drivers/net/gve/base/gve_adminq.h
+@@ -1,6 +1,6 @@
+ /* SPDX-License-Identifier: MIT
+ * Google Virtual Ethernet (gve) driver
+- * Copyright (C) 2015-2022 Google, Inc.
++ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+ #ifndef _GVE_ADMINQ_H
+@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
+ GVE_ADMINQ_REPORT_STATS = 0xC,
+ GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
+ GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
++ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
+ };
+
+ /* Admin queue status codes */
+@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
+ };
+
+ #define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
++enum gve_driver_capbility {
++ gve_driver_capability_gqi_qpl = 0,
++ gve_driver_capability_gqi_rda = 1,
++ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
++ gve_driver_capability_dqo_rda = 3,
++};
++
++#define GVE_CAP1(a) BIT((int)a)
++
++#define GVE_DRIVER_CAPABILITY_FLAGS1 \
++ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
++ GVE_CAP1(gve_driver_capability_gqi_rda) | \
++ GVE_CAP1(gve_driver_capability_dqo_rda))
++
++#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
++#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
++#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
++
++struct gve_driver_info {
++ u8 os_type; /* 0x05 = DPDK */
++ u8 driver_major;
++ u8 driver_minor;
++ u8 driver_sub;
++ __be32 os_version_major;
++ __be32 os_version_minor;
++ __be32 os_version_sub;
++ __be64 driver_capability_flags[4];
++ u8 os_version_str1[OS_VERSION_STRLEN];
++ u8 os_version_str2[OS_VERSION_STRLEN];
++};
++
++struct gve_adminq_verify_driver_compatibility {
++ __be64 driver_info_len;
++ __be64 driver_info_addr;
++};
++
++GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
++
+
+ struct gve_adminq_configure_device_resources {
+ __be64 counter_array;
+@@ -345,6 +384,8 @@ union gve_adminq_command {
+ struct gve_adminq_report_stats report_stats;
+ struct gve_adminq_report_link_speed report_link_speed;
+ struct gve_adminq_get_ptype_map get_ptype_map;
++ struct gve_adminq_verify_driver_compatibility
++ verify_driver_compatibility;
+ };
+ };
+ u8 reserved[64];
+@@ -378,4 +419,7 @@ struct gve_ptype_lut;
+ int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
+ struct gve_ptype_lut *ptype_lut);
+
++int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
++ u64 driver_info_len,
++ dma_addr_t driver_info_addr);
+ #endif /* _GVE_ADMINQ_H */
+diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
+index 7cb73002f4..43081ec2a9 100644
+--- a/drivers/net/gve/base/gve_osdep.h
++++ b/drivers/net/gve/base/gve_osdep.h
+@@ -21,9 +21,14 @@
+ #include <rte_malloc.h>
+ #include <rte_memcpy.h>
+ #include <rte_memzone.h>
++#include <rte_version.h>
+
+ #include "../gve_logs.h"
+
++#ifdef __linux__
++#include <sys/utsname.h>
++#endif
++
+ typedef uint8_t u8;
+ typedef uint16_t u16;
+ typedef uint32_t u32;
+@@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
+
+ #define msleep(ms) rte_delay_ms(ms)
+
++#define OS_VERSION_STRLEN 128
++struct os_version_string {
++ char os_version_str1[OS_VERSION_STRLEN];
++ char os_version_str2[OS_VERSION_STRLEN];
++};
++
+ /* These macros are used to generate compilation errors if a struct/union
+ * is not exactly the correct length. It gives a divide by zero error if
+ * the struct/union is not of the correct size, otherwise it creates an
+@@ -156,4 +167,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
+ mem->pa = 0;
+ }
+
++static inline void
++populate_driver_version_strings(char *str1, char *str2)
++{
++ struct utsname uts;
++ if (uname(&uts) >= 0) {
++ /* release */
++ rte_strscpy(str1, uts.release,
++ OS_VERSION_STRLEN);
++ /* version */
++ rte_strscpy(str2, uts.version,
++ OS_VERSION_STRLEN);
++ }
++}
+ #endif /* _GVE_OSDEP_H_ */
+diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
+index cf28a4a3b7..2766ca0d3b 100644
+--- a/drivers/net/gve/gve_ethdev.c
++++ b/drivers/net/gve/gve_ethdev.c
+@@ -5,21 +5,13 @@
+ #include "gve_ethdev.h"
+ #include "base/gve_adminq.h"
+ #include "base/gve_register.h"
+-
+-const char gve_version_str[] = GVE_VERSION;
+-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
++#include "base/gve_osdep.h"
++#include "gve_version.h"
+
+ static void
+ gve_write_version(uint8_t *driver_version_register)
+ {
+- const char *c = gve_version_prefix;
+-
+- while (*c) {
+- writeb(*c, driver_version_register);
+- c++;
+- }
+-
+- c = gve_version_str;
++ const char *c = gve_version_string();
+ while (*c) {
+ writeb(*c, driver_version_register);
+ c++;
+@@ -265,6 +257,48 @@ gve_dev_close(struct rte_eth_dev *dev)
+ return err;
+ }
+
++static int
++gve_verify_driver_compatibility(struct gve_priv *priv)
++{
++ struct gve_driver_info *driver_info;
++ int err;
++
++ driver_info = calloc(sizeof(struct gve_driver_info), 0);
++ if (driver_info == NULL) {
++ PMD_DRV_LOG(ERR,
++ "Could not alloc for verify driver compatibility");
++ return -ENOMEM;
++ }
++ *driver_info = (struct gve_driver_info) {
++ .os_type = 5, /* DPDK */
++ .driver_major = GVE_VERSION_MAJOR,
++ .driver_minor = GVE_VERSION_MINOR,
++ .driver_sub = GVE_VERSION_SUB,
++ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
++ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
++ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
++ .driver_capability_flags = {
++ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
++ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
++ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
++ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
++ },
++ };
++
++ populate_driver_version_strings((char *)driver_info->os_version_str1,
++ (char *)driver_info->os_version_str2);
++
++ err = gve_adminq_verify_driver_compatibility(priv,
++ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
++
++ /* It's ok if the device doesn't support this */
++ if (err == -EOPNOTSUPP)
++ err = 0;
++
++ free(driver_info);
++ return err;
++}
++
+ static int
+ gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
+ {
+@@ -672,6 +706,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
+ PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
+ return err;
+ }
++ err = gve_verify_driver_compatibility(priv);
++ if (err) {
++ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
++ goto free_adminq;
++ }
+
+ if (skip_describe_device)
+ goto setup_device;
+diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
+index 42a02cf5d4..23ccff37d3 100644
+--- a/drivers/net/gve/gve_ethdev.h
++++ b/drivers/net/gve/gve_ethdev.h
+@@ -222,7 +222,7 @@ struct gve_priv {
+ uint32_t adminq_report_stats_cnt;
+ uint32_t adminq_report_link_speed_cnt;
+ uint32_t adminq_get_ptype_map_cnt;
+-
++ uint32_t adminq_verify_driver_compatibility_cnt;
+ volatile uint32_t state_flags;
+
+ /* Gvnic device link speed from hypervisor. */
+diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
+new file mode 100644
+index 0000000000..5fe34dc179
+--- /dev/null
++++ b/drivers/net/gve/gve_version.c
+@@ -0,0 +1,13 @@
++/* SPDX-License-Identifier: BSD-3-Clause
++ * Copyright (C) 2015-2023 Google, Inc.
++ */
++#include "gve_version.h"
++
++const char *gve_version_string(void)
++{
++ static char gve_version[20];
++ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
++ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
++ GVE_VERSION_SUB);
++ return gve_version;
++}
+diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
+new file mode 100644
+index 0000000000..4dd998dca1
+--- /dev/null
++++ b/drivers/net/gve/gve_version.h
+@@ -0,0 +1,24 @@
++/* SPDX-License-Identifier: BSD-3-Clause
++ * Copyright (C) 2015-2023 Google, Inc.
++ */
++
++#ifndef _GVE_VERSION_H_
++#define _GVE_VERSION_H_
++
++#include <rte_version.h>
++
++#define GVE_VERSION_PREFIX "DPDK-"
++#define GVE_VERSION_MAJOR 1
++#define GVE_VERSION_MINOR 0
++#define GVE_VERSION_SUB 0
++
++#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
++#define DPDK_VERSION_MINOR RTE_VER_MINOR
++#define DPDK_VERSION_SUB RTE_VER_RELEASE
++
++
++const char *
++gve_version_string(void);
++
++
++#endif /* GVE_VERSION_H */
+diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
+index af0010c01c..365b7ffdaa 100644
+--- a/drivers/net/gve/meson.build
++++ b/drivers/net/gve/meson.build
+@@ -1,9 +1,9 @@
+ # SPDX-License-Identifier: BSD-3-Clause
+ # Copyright(C) 2022 Intel Corporation
+
+-if is_windows
++if not is_linux
+ build = false
+- reason = 'not supported on Windows'
++ reason = 'only supported on Linux'
+ subdir_done()
+ endif
+
+@@ -12,5 +12,6 @@ sources = files(
+ 'gve_rx.c',
+ 'gve_tx.c',
+ 'gve_ethdev.c',
++ 'gve_version.c',
+ )
+ includes += include_directories('base')
+--
+2.40.1.698.g37aff9b760-goog
+
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2b7cf7d99b..f7b297e759 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -9,9 +9,6 @@
#include "gve_desc.h"
#include "gve_desc_dqo.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e963f910a0..41202725e6 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..e30b184913 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +384,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +419,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index abf3d379ae..5e8ae1eac6 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -160,4 +171,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(char *str1, char *str2)
+{
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(str1, uts.release,
+ OS_VERSION_STRLEN);
+ /* version */
+ rte_strscpy(str2, uts.version,
+ OS_VERSION_STRLEN);
+ }
+}
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index 1dcb3b3a01..342eb2d2fa 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -245,6 +237,47 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info = rte_zmalloc("driver info", sizeof(struct gve_driver_info), 0);
+ if (driver_info == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc for verify driver compatibility");
+ return -ENOMEM;
+ }
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((char *)driver_info->os_version_str1,
+ (char *)driver_info->os_version_str2);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_free(driver_info);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -679,6 +712,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index cd62debd22..c9bcfa553c 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -268,7 +268,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..5fe34dc179
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[20];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..4dd998dca1
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index c9d87903f9..61d195009c 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(C) 2022 Intel Corporation
-if is_windows
+if not is_linux
build = false
- reason = 'not supported on Windows'
+ reason = 'only supported on Linux'
subdir_done()
endif
@@ -14,5 +14,6 @@ sources = files(
'gve_rx_dqo.c',
'gve_tx_dqo.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.1.698.g37aff9b760-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH] net/gve: check driver compatibility
2023-05-08 19:15 ` [v2] net/gve: check driver compatibility Rushil Gupta
2023-05-17 16:58 ` Ferruh Yigit
2023-05-19 7:15 ` [v3] " Rushil Gupta
@ 2023-05-19 7:23 ` Rushil Gupta
2023-05-19 7:26 ` Rushil Gupta
3 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-19 7:23 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
0001-net-gve-check-driver-compatibility.patch | 388 ++++++++++++++++++
drivers/net/gve/base/gve.h | 3 -
drivers/net/gve/base/gve_adminq.c | 19 +
drivers/net/gve/base/gve_adminq.h | 46 ++-
drivers/net/gve/base/gve_osdep.h | 24 ++
drivers/net/gve/gve_ethdev.c | 60 ++-
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 13 +
drivers/net/gve/gve_version.h | 24 ++
drivers/net/gve/meson.build | 5 +-
10 files changed, 566 insertions(+), 18 deletions(-)
create mode 100644 0001-net-gve-check-driver-compatibility.patch
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/0001-net-gve-check-driver-compatibility.patch b/0001-net-gve-check-driver-compatibility.patch
new file mode 100644
index 0000000000..0187db7dc2
--- /dev/null
+++ b/0001-net-gve-check-driver-compatibility.patch
@@ -0,0 +1,388 @@
+From 1624a08eaa94242286da930b92b227759f906bd9 Mon Sep 17 00:00:00 2001
+From: Rushil Gupta <rushilg@google.com>
+Date: Thu, 13 Apr 2023 22:06:20 -0700
+Subject: [v3] net/gve: check driver compatibility
+
+Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
+version as OS version, reserving driver_version fields for GVE driver
+version based on features.
+
+Signed-off-by: Rushil Gupta <rushilg@google.com>
+Signed-off-by: Joshua Washington <joshwash@google.com>
+Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
+Signed-off-by: Jeroen de Borst <jeroendb@google.com>
+---
+ drivers/net/gve/base/gve.h | 3 --
+ drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
+ drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
+ drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
+ drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
+ drivers/net/gve/gve_ethdev.h | 2 +-
+ drivers/net/gve/gve_version.c | 13 +++++++
+ drivers/net/gve/gve_version.h | 24 ++++++++++++
+ drivers/net/gve/meson.build | 5 ++-
+ 9 files changed, 179 insertions(+), 18 deletions(-)
+ create mode 100644 drivers/net/gve/gve_version.c
+ create mode 100644 drivers/net/gve/gve_version.h
+
+diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
+index 2dc4507acb..89f9654a72 100644
+--- a/drivers/net/gve/base/gve.h
++++ b/drivers/net/gve/base/gve.h
+@@ -8,9 +8,6 @@
+
+ #include "gve_desc.h"
+
+-#define GVE_VERSION "1.3.0"
+-#define GVE_VERSION_PREFIX "GVE-"
+-
+ #ifndef GOOGLE_VENDOR_ID
+ #define GOOGLE_VENDOR_ID 0x1ae0
+ #endif
+diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
+index e745b709b2..2e5099a5b0 100644
+--- a/drivers/net/gve/base/gve_adminq.c
++++ b/drivers/net/gve/base/gve_adminq.c
+@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
+ case GVE_ADMINQ_GET_PTYPE_MAP:
+ priv->adminq_get_ptype_map_cnt++;
+ break;
++ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
++ priv->adminq_verify_driver_compatibility_cnt++;
++ break;
+ default:
+ PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
+ }
+@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
+ return gve_adminq_execute_cmd(priv, &cmd);
+ }
+
++int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
++ u64 driver_info_len,
++ dma_addr_t driver_info_addr)
++{
++ union gve_adminq_command cmd;
++
++ memset(&cmd, 0, sizeof(cmd));
++ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
++ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
++ .driver_info_len = cpu_to_be64(driver_info_len),
++ .driver_info_addr = cpu_to_be64(driver_info_addr),
++ };
++
++ return gve_adminq_execute_cmd(priv, &cmd);
++}
++
+ int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
+ {
+ union gve_adminq_command cmd;
+diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
+index 05550119de..e30b184913 100644
+--- a/drivers/net/gve/base/gve_adminq.h
++++ b/drivers/net/gve/base/gve_adminq.h
+@@ -1,6 +1,6 @@
+ /* SPDX-License-Identifier: MIT
+ * Google Virtual Ethernet (gve) driver
+- * Copyright (C) 2015-2022 Google, Inc.
++ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+ #ifndef _GVE_ADMINQ_H
+@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
+ GVE_ADMINQ_REPORT_STATS = 0xC,
+ GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
+ GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
++ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
+ };
+
+ /* Admin queue status codes */
+@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
+ };
+
+ #define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
++enum gve_driver_capbility {
++ gve_driver_capability_gqi_qpl = 0,
++ gve_driver_capability_gqi_rda = 1,
++ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
++ gve_driver_capability_dqo_rda = 3,
++};
++
++#define GVE_CAP1(a) BIT((int)a)
++
++#define GVE_DRIVER_CAPABILITY_FLAGS1 \
++ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
++ GVE_CAP1(gve_driver_capability_gqi_rda) | \
++ GVE_CAP1(gve_driver_capability_dqo_rda))
++
++#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
++#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
++#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
++
++struct gve_driver_info {
++ u8 os_type; /* 0x05 = DPDK */
++ u8 driver_major;
++ u8 driver_minor;
++ u8 driver_sub;
++ __be32 os_version_major;
++ __be32 os_version_minor;
++ __be32 os_version_sub;
++ __be64 driver_capability_flags[4];
++ u8 os_version_str1[OS_VERSION_STRLEN];
++ u8 os_version_str2[OS_VERSION_STRLEN];
++};
++
++struct gve_adminq_verify_driver_compatibility {
++ __be64 driver_info_len;
++ __be64 driver_info_addr;
++};
++
++GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
++
+
+ struct gve_adminq_configure_device_resources {
+ __be64 counter_array;
+@@ -345,6 +384,8 @@ union gve_adminq_command {
+ struct gve_adminq_report_stats report_stats;
+ struct gve_adminq_report_link_speed report_link_speed;
+ struct gve_adminq_get_ptype_map get_ptype_map;
++ struct gve_adminq_verify_driver_compatibility
++ verify_driver_compatibility;
+ };
+ };
+ u8 reserved[64];
+@@ -378,4 +419,7 @@ struct gve_ptype_lut;
+ int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
+ struct gve_ptype_lut *ptype_lut);
+
++int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
++ u64 driver_info_len,
++ dma_addr_t driver_info_addr);
+ #endif /* _GVE_ADMINQ_H */
+diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
+index 7cb73002f4..43081ec2a9 100644
+--- a/drivers/net/gve/base/gve_osdep.h
++++ b/drivers/net/gve/base/gve_osdep.h
+@@ -21,9 +21,14 @@
+ #include <rte_malloc.h>
+ #include <rte_memcpy.h>
+ #include <rte_memzone.h>
++#include <rte_version.h>
+
+ #include "../gve_logs.h"
+
++#ifdef __linux__
++#include <sys/utsname.h>
++#endif
++
+ typedef uint8_t u8;
+ typedef uint16_t u16;
+ typedef uint32_t u32;
+@@ -69,6 +74,12 @@ typedef rte_iova_t dma_addr_t;
+
+ #define msleep(ms) rte_delay_ms(ms)
+
++#define OS_VERSION_STRLEN 128
++struct os_version_string {
++ char os_version_str1[OS_VERSION_STRLEN];
++ char os_version_str2[OS_VERSION_STRLEN];
++};
++
+ /* These macros are used to generate compilation errors if a struct/union
+ * is not exactly the correct length. It gives a divide by zero error if
+ * the struct/union is not of the correct size, otherwise it creates an
+@@ -156,4 +167,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
+ mem->pa = 0;
+ }
+
++static inline void
++populate_driver_version_strings(char *str1, char *str2)
++{
++ struct utsname uts;
++ if (uname(&uts) >= 0) {
++ /* release */
++ rte_strscpy(str1, uts.release,
++ OS_VERSION_STRLEN);
++ /* version */
++ rte_strscpy(str2, uts.version,
++ OS_VERSION_STRLEN);
++ }
++}
+ #endif /* _GVE_OSDEP_H_ */
+diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
+index cf28a4a3b7..2766ca0d3b 100644
+--- a/drivers/net/gve/gve_ethdev.c
++++ b/drivers/net/gve/gve_ethdev.c
+@@ -5,21 +5,13 @@
+ #include "gve_ethdev.h"
+ #include "base/gve_adminq.h"
+ #include "base/gve_register.h"
+-
+-const char gve_version_str[] = GVE_VERSION;
+-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
++#include "base/gve_osdep.h"
++#include "gve_version.h"
+
+ static void
+ gve_write_version(uint8_t *driver_version_register)
+ {
+- const char *c = gve_version_prefix;
+-
+- while (*c) {
+- writeb(*c, driver_version_register);
+- c++;
+- }
+-
+- c = gve_version_str;
++ const char *c = gve_version_string();
+ while (*c) {
+ writeb(*c, driver_version_register);
+ c++;
+@@ -265,6 +257,48 @@ gve_dev_close(struct rte_eth_dev *dev)
+ return err;
+ }
+
++static int
++gve_verify_driver_compatibility(struct gve_priv *priv)
++{
++ struct gve_driver_info *driver_info;
++ int err;
++
++ driver_info = calloc(sizeof(struct gve_driver_info), 0);
++ if (driver_info == NULL) {
++ PMD_DRV_LOG(ERR,
++ "Could not alloc for verify driver compatibility");
++ return -ENOMEM;
++ }
++ *driver_info = (struct gve_driver_info) {
++ .os_type = 5, /* DPDK */
++ .driver_major = GVE_VERSION_MAJOR,
++ .driver_minor = GVE_VERSION_MINOR,
++ .driver_sub = GVE_VERSION_SUB,
++ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
++ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
++ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
++ .driver_capability_flags = {
++ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
++ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
++ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
++ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
++ },
++ };
++
++ populate_driver_version_strings((char *)driver_info->os_version_str1,
++ (char *)driver_info->os_version_str2);
++
++ err = gve_adminq_verify_driver_compatibility(priv,
++ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
++
++ /* It's ok if the device doesn't support this */
++ if (err == -EOPNOTSUPP)
++ err = 0;
++
++ free(driver_info);
++ return err;
++}
++
+ static int
+ gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
+ {
+@@ -672,6 +706,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
+ PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
+ return err;
+ }
++ err = gve_verify_driver_compatibility(priv);
++ if (err) {
++ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
++ goto free_adminq;
++ }
+
+ if (skip_describe_device)
+ goto setup_device;
+diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
+index 42a02cf5d4..23ccff37d3 100644
+--- a/drivers/net/gve/gve_ethdev.h
++++ b/drivers/net/gve/gve_ethdev.h
+@@ -222,7 +222,7 @@ struct gve_priv {
+ uint32_t adminq_report_stats_cnt;
+ uint32_t adminq_report_link_speed_cnt;
+ uint32_t adminq_get_ptype_map_cnt;
+-
++ uint32_t adminq_verify_driver_compatibility_cnt;
+ volatile uint32_t state_flags;
+
+ /* Gvnic device link speed from hypervisor. */
+diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
+new file mode 100644
+index 0000000000..5fe34dc179
+--- /dev/null
++++ b/drivers/net/gve/gve_version.c
+@@ -0,0 +1,13 @@
++/* SPDX-License-Identifier: BSD-3-Clause
++ * Copyright (C) 2015-2023 Google, Inc.
++ */
++#include "gve_version.h"
++
++const char *gve_version_string(void)
++{
++ static char gve_version[20];
++ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
++ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
++ GVE_VERSION_SUB);
++ return gve_version;
++}
+diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
+new file mode 100644
+index 0000000000..4dd998dca1
+--- /dev/null
++++ b/drivers/net/gve/gve_version.h
+@@ -0,0 +1,24 @@
++/* SPDX-License-Identifier: BSD-3-Clause
++ * Copyright (C) 2015-2023 Google, Inc.
++ */
++
++#ifndef _GVE_VERSION_H_
++#define _GVE_VERSION_H_
++
++#include <rte_version.h>
++
++#define GVE_VERSION_PREFIX "DPDK-"
++#define GVE_VERSION_MAJOR 1
++#define GVE_VERSION_MINOR 0
++#define GVE_VERSION_SUB 0
++
++#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
++#define DPDK_VERSION_MINOR RTE_VER_MINOR
++#define DPDK_VERSION_SUB RTE_VER_RELEASE
++
++
++const char *
++gve_version_string(void);
++
++
++#endif /* GVE_VERSION_H */
+diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
+index af0010c01c..365b7ffdaa 100644
+--- a/drivers/net/gve/meson.build
++++ b/drivers/net/gve/meson.build
+@@ -1,9 +1,9 @@
+ # SPDX-License-Identifier: BSD-3-Clause
+ # Copyright(C) 2022 Intel Corporation
+
+-if is_windows
++if not is_linux
+ build = false
+- reason = 'not supported on Windows'
++ reason = 'only supported on Linux'
+ subdir_done()
+ endif
+
+@@ -12,5 +12,6 @@ sources = files(
+ 'gve_rx.c',
+ 'gve_tx.c',
+ 'gve_ethdev.c',
++ 'gve_version.c',
+ )
+ includes += include_directories('base')
+--
+2.40.1.698.g37aff9b760-goog
+
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2b7cf7d99b..f7b297e759 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -9,9 +9,6 @@
#include "gve_desc.h"
#include "gve_desc_dqo.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e963f910a0..41202725e6 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..e30b184913 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +384,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +419,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index abf3d379ae..5e8ae1eac6 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -160,4 +171,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(char *str1, char *str2)
+{
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(str1, uts.release,
+ OS_VERSION_STRLEN);
+ /* version */
+ rte_strscpy(str2, uts.version,
+ OS_VERSION_STRLEN);
+ }
+}
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index 1dcb3b3a01..342eb2d2fa 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -245,6 +237,47 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info = rte_zmalloc("driver info", sizeof(struct gve_driver_info), 0);
+ if (driver_info == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc for verify driver compatibility");
+ return -ENOMEM;
+ }
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((char *)driver_info->os_version_str1,
+ (char *)driver_info->os_version_str2);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_free(driver_info);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -679,6 +712,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index cd62debd22..c9bcfa553c 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -268,7 +268,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..5fe34dc179
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[20];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..4dd998dca1
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index c9d87903f9..61d195009c 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(C) 2022 Intel Corporation
-if is_windows
+if not is_linux
build = false
- reason = 'not supported on Windows'
+ reason = 'only supported on Linux'
subdir_done()
endif
@@ -14,5 +14,6 @@ sources = files(
'gve_rx_dqo.c',
'gve_tx_dqo.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.1.698.g37aff9b760-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH] net/gve: check driver compatibility
2023-05-08 19:15 ` [v2] net/gve: check driver compatibility Rushil Gupta
` (2 preceding siblings ...)
2023-05-19 7:23 ` [PATCH] " Rushil Gupta
@ 2023-05-19 7:26 ` Rushil Gupta
2023-05-19 7:41 ` Rushil Gupta
` (2 more replies)
3 siblings, 3 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-19 7:26 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
drivers/net/gve/base/gve.h | 3 --
drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 13 +++++++
drivers/net/gve/gve_version.h | 24 ++++++++++++
drivers/net/gve/meson.build | 5 ++-
9 files changed, 179 insertions(+), 18 deletions(-)
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2b7cf7d99b..f7b297e759 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -9,9 +9,6 @@
#include "gve_desc.h"
#include "gve_desc_dqo.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e963f910a0..41202725e6 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..e30b184913 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +384,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +419,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index abf3d379ae..5e8ae1eac6 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -160,4 +171,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(char *str1, char *str2)
+{
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(str1, uts.release,
+ OS_VERSION_STRLEN);
+ /* version */
+ rte_strscpy(str2, uts.version,
+ OS_VERSION_STRLEN);
+ }
+}
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index 1dcb3b3a01..71d131fb41 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -245,6 +237,48 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info = rte_zmalloc("driver info",
+ sizeof(struct gve_driver_info), 0);
+ if (driver_info == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc for verify driver compatibility");
+ return -ENOMEM;
+ }
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((char *)driver_info->os_version_str1,
+ (char *)driver_info->os_version_str2);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_free(driver_info);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -679,6 +713,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index cd62debd22..c9bcfa553c 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -268,7 +268,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..5fe34dc179
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[20];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..4dd998dca1
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index c9d87903f9..61d195009c 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(C) 2022 Intel Corporation
-if is_windows
+if not is_linux
build = false
- reason = 'not supported on Windows'
+ reason = 'only supported on Linux'
subdir_done()
endif
@@ -14,5 +14,6 @@ sources = files(
'gve_rx_dqo.c',
'gve_tx_dqo.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.1.698.g37aff9b760-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH] net/gve: check driver compatibility
2023-05-19 7:26 ` Rushil Gupta
@ 2023-05-19 7:41 ` Rushil Gupta
2023-05-19 10:04 ` Ferruh Yigit
2023-05-19 19:54 ` [v4] " Rushil Gupta
2023-05-19 20:46 ` Rushil Gupta
2 siblings, 1 reply; 32+ messages in thread
From: Rushil Gupta @ 2023-05-19 7:41 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Jeroen de Borst
Hi Ferruh
I have updated the latest patch here:
http://patchwork.dpdk.org/project/dpdk/patch/20230519072600.1444309-1-rushilg@google.com/
However, using calloc causes issue while executing verify-compatibility command.
sudo dpdk-testpmd -a 00:04.0 -l 0-32 -- --forward-mode=rxonly --txq=16
--rxq=16 --nb-cores=16 --stats-period 5
...
EAL: Using IOMMU type 8 (No-IOMMU)
EAL: Probe PCI driver: net_gve (1ae0:42) device: 0000:00:04.0 (socket -1)
gve_adminq_parse_err(): AQ command failed with status -9
gve_init_priv(): Could not verify driver compatibility: err=-22
EAL: Releasing PCI mapped resource for 0000:00:04.0
...
EAL: Error - exiting with code: 1
This is probably because the adminq command is sharing memory to
report driver-info to the gvnic device and that needs to be in dpdk
memory.
On Fri, May 19, 2023 at 12:26 AM Rushil Gupta <rushilg@google.com> wrote:
>
> Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
> version as OS version, reserving driver_version fields for GVE driver
> version based on features.
>
> Signed-off-by: Rushil Gupta <rushilg@google.com>
> Signed-off-by: Joshua Washington <joshwash@google.com>
> Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
> Signed-off-by: Jeroen de Borst <jeroendb@google.com>
> ---
> drivers/net/gve/base/gve.h | 3 --
> drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
> drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
> drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
> drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
> drivers/net/gve/gve_ethdev.h | 2 +-
> drivers/net/gve/gve_version.c | 13 +++++++
> drivers/net/gve/gve_version.h | 24 ++++++++++++
> drivers/net/gve/meson.build | 5 ++-
> 9 files changed, 179 insertions(+), 18 deletions(-)
> create mode 100644 drivers/net/gve/gve_version.c
> create mode 100644 drivers/net/gve/gve_version.h
>
> diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
> index 2b7cf7d99b..f7b297e759 100644
> --- a/drivers/net/gve/base/gve.h
> +++ b/drivers/net/gve/base/gve.h
> @@ -9,9 +9,6 @@
> #include "gve_desc.h"
> #include "gve_desc_dqo.h"
>
> -#define GVE_VERSION "1.3.0"
> -#define GVE_VERSION_PREFIX "GVE-"
> -
> #ifndef GOOGLE_VENDOR_ID
> #define GOOGLE_VENDOR_ID 0x1ae0
> #endif
> diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
> index e963f910a0..41202725e6 100644
> --- a/drivers/net/gve/base/gve_adminq.c
> +++ b/drivers/net/gve/base/gve_adminq.c
> @@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
> case GVE_ADMINQ_GET_PTYPE_MAP:
> priv->adminq_get_ptype_map_cnt++;
> break;
> + case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
> + priv->adminq_verify_driver_compatibility_cnt++;
> + break;
> default:
> PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
> }
> @@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
> return gve_adminq_execute_cmd(priv, &cmd);
> }
>
> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> + u64 driver_info_len,
> + dma_addr_t driver_info_addr)
> +{
> + union gve_adminq_command cmd;
> +
> + memset(&cmd, 0, sizeof(cmd));
> + cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
> + cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
> + .driver_info_len = cpu_to_be64(driver_info_len),
> + .driver_info_addr = cpu_to_be64(driver_info_addr),
> + };
> +
> + return gve_adminq_execute_cmd(priv, &cmd);
> +}
> +
> int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
> {
> union gve_adminq_command cmd;
> diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
> index 05550119de..e30b184913 100644
> --- a/drivers/net/gve/base/gve_adminq.h
> +++ b/drivers/net/gve/base/gve_adminq.h
> @@ -1,6 +1,6 @@
> /* SPDX-License-Identifier: MIT
> * Google Virtual Ethernet (gve) driver
> - * Copyright (C) 2015-2022 Google, Inc.
> + * Copyright (C) 2015-2023 Google, Inc.
> */
>
> #ifndef _GVE_ADMINQ_H
> @@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
> GVE_ADMINQ_REPORT_STATS = 0xC,
> GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
> GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
> + GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
> };
>
> /* Admin queue status codes */
> @@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
> };
>
> #define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
> +enum gve_driver_capbility {
> + gve_driver_capability_gqi_qpl = 0,
> + gve_driver_capability_gqi_rda = 1,
> + gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
> + gve_driver_capability_dqo_rda = 3,
> +};
> +
> +#define GVE_CAP1(a) BIT((int)a)
> +
> +#define GVE_DRIVER_CAPABILITY_FLAGS1 \
> + (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
> + GVE_CAP1(gve_driver_capability_gqi_rda) | \
> + GVE_CAP1(gve_driver_capability_dqo_rda))
> +
> +#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
> +#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
> +#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
> +
> +struct gve_driver_info {
> + u8 os_type; /* 0x05 = DPDK */
> + u8 driver_major;
> + u8 driver_minor;
> + u8 driver_sub;
> + __be32 os_version_major;
> + __be32 os_version_minor;
> + __be32 os_version_sub;
> + __be64 driver_capability_flags[4];
> + u8 os_version_str1[OS_VERSION_STRLEN];
> + u8 os_version_str2[OS_VERSION_STRLEN];
> +};
> +
> +struct gve_adminq_verify_driver_compatibility {
> + __be64 driver_info_len;
> + __be64 driver_info_addr;
> +};
> +
> +GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
> +
>
> struct gve_adminq_configure_device_resources {
> __be64 counter_array;
> @@ -345,6 +384,8 @@ union gve_adminq_command {
> struct gve_adminq_report_stats report_stats;
> struct gve_adminq_report_link_speed report_link_speed;
> struct gve_adminq_get_ptype_map get_ptype_map;
> + struct gve_adminq_verify_driver_compatibility
> + verify_driver_compatibility;
> };
> };
> u8 reserved[64];
> @@ -378,4 +419,7 @@ struct gve_ptype_lut;
> int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
> struct gve_ptype_lut *ptype_lut);
>
> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> + u64 driver_info_len,
> + dma_addr_t driver_info_addr);
> #endif /* _GVE_ADMINQ_H */
> diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
> index abf3d379ae..5e8ae1eac6 100644
> --- a/drivers/net/gve/base/gve_osdep.h
> +++ b/drivers/net/gve/base/gve_osdep.h
> @@ -21,9 +21,14 @@
> #include <rte_malloc.h>
> #include <rte_memcpy.h>
> #include <rte_memzone.h>
> +#include <rte_version.h>
>
> #include "../gve_logs.h"
>
> +#ifdef __linux__
> +#include <sys/utsname.h>
> +#endif
> +
> typedef uint8_t u8;
> typedef uint16_t u16;
> typedef uint32_t u32;
> @@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
>
> #define msleep(ms) rte_delay_ms(ms)
>
> +#define OS_VERSION_STRLEN 128
> +struct os_version_string {
> + char os_version_str1[OS_VERSION_STRLEN];
> + char os_version_str2[OS_VERSION_STRLEN];
> +};
> +
> /* These macros are used to generate compilation errors if a struct/union
> * is not exactly the correct length. It gives a divide by zero error if
> * the struct/union is not of the correct size, otherwise it creates an
> @@ -160,4 +171,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
> mem->pa = 0;
> }
>
> +static inline void
> +populate_driver_version_strings(char *str1, char *str2)
> +{
> + struct utsname uts;
> + if (uname(&uts) >= 0) {
> + /* release */
> + rte_strscpy(str1, uts.release,
> + OS_VERSION_STRLEN);
> + /* version */
> + rte_strscpy(str2, uts.version,
> + OS_VERSION_STRLEN);
> + }
> +}
> #endif /* _GVE_OSDEP_H_ */
> diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
> index 1dcb3b3a01..71d131fb41 100644
> --- a/drivers/net/gve/gve_ethdev.c
> +++ b/drivers/net/gve/gve_ethdev.c
> @@ -5,21 +5,13 @@
> #include "gve_ethdev.h"
> #include "base/gve_adminq.h"
> #include "base/gve_register.h"
> -
> -const char gve_version_str[] = GVE_VERSION;
> -static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
> +#include "base/gve_osdep.h"
> +#include "gve_version.h"
>
> static void
> gve_write_version(uint8_t *driver_version_register)
> {
> - const char *c = gve_version_prefix;
> -
> - while (*c) {
> - writeb(*c, driver_version_register);
> - c++;
> - }
> -
> - c = gve_version_str;
> + const char *c = gve_version_string();
> while (*c) {
> writeb(*c, driver_version_register);
> c++;
> @@ -245,6 +237,48 @@ gve_dev_close(struct rte_eth_dev *dev)
> return err;
> }
>
> +static int
> +gve_verify_driver_compatibility(struct gve_priv *priv)
> +{
> + struct gve_driver_info *driver_info;
> + int err;
> +
> + driver_info = rte_zmalloc("driver info",
> + sizeof(struct gve_driver_info), 0);
> + if (driver_info == NULL) {
> + PMD_DRV_LOG(ERR,
> + "Could not alloc for verify driver compatibility");
> + return -ENOMEM;
> + }
> + *driver_info = (struct gve_driver_info) {
> + .os_type = 5, /* DPDK */
> + .driver_major = GVE_VERSION_MAJOR,
> + .driver_minor = GVE_VERSION_MINOR,
> + .driver_sub = GVE_VERSION_SUB,
> + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
> + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
> + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> + .driver_capability_flags = {
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> + },
> + };
> +
> + populate_driver_version_strings((char *)driver_info->os_version_str1,
> + (char *)driver_info->os_version_str2);
> +
> + err = gve_adminq_verify_driver_compatibility(priv,
> + sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
> + /* It's ok if the device doesn't support this */
> + if (err == -EOPNOTSUPP)
> + err = 0;
> +
> + rte_free(driver_info);
> + return err;
> +}
> +
> static int
> gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
> {
> @@ -679,6 +713,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
> PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
> return err;
> }
> + err = gve_verify_driver_compatibility(priv);
> + if (err) {
> + PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
> + goto free_adminq;
> + }
>
> if (skip_describe_device)
> goto setup_device;
> diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
> index cd62debd22..c9bcfa553c 100644
> --- a/drivers/net/gve/gve_ethdev.h
> +++ b/drivers/net/gve/gve_ethdev.h
> @@ -268,7 +268,7 @@ struct gve_priv {
> uint32_t adminq_report_stats_cnt;
> uint32_t adminq_report_link_speed_cnt;
> uint32_t adminq_get_ptype_map_cnt;
> -
> + uint32_t adminq_verify_driver_compatibility_cnt;
> volatile uint32_t state_flags;
>
> /* Gvnic device link speed from hypervisor. */
> diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
> new file mode 100644
> index 0000000000..5fe34dc179
> --- /dev/null
> +++ b/drivers/net/gve/gve_version.c
> @@ -0,0 +1,13 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright (C) 2015-2023 Google, Inc.
> + */
> +#include "gve_version.h"
> +
> +const char *gve_version_string(void)
> +{
> + static char gve_version[20];
> + snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
> + GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
> + GVE_VERSION_SUB);
> + return gve_version;
> +}
> diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
> new file mode 100644
> index 0000000000..4dd998dca1
> --- /dev/null
> +++ b/drivers/net/gve/gve_version.h
> @@ -0,0 +1,24 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright (C) 2015-2023 Google, Inc.
> + */
> +
> +#ifndef _GVE_VERSION_H_
> +#define _GVE_VERSION_H_
> +
> +#include <rte_version.h>
> +
> +#define GVE_VERSION_PREFIX "DPDK-"
> +#define GVE_VERSION_MAJOR 1
> +#define GVE_VERSION_MINOR 0
> +#define GVE_VERSION_SUB 0
> +
> +#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
> +#define DPDK_VERSION_MINOR RTE_VER_MINOR
> +#define DPDK_VERSION_SUB RTE_VER_RELEASE
> +
> +
> +const char *
> +gve_version_string(void);
> +
> +
> +#endif /* GVE_VERSION_H */
> diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
> index c9d87903f9..61d195009c 100644
> --- a/drivers/net/gve/meson.build
> +++ b/drivers/net/gve/meson.build
> @@ -1,9 +1,9 @@
> # SPDX-License-Identifier: BSD-3-Clause
> # Copyright(C) 2022 Intel Corporation
>
> -if is_windows
> +if not is_linux
> build = false
> - reason = 'not supported on Windows'
> + reason = 'only supported on Linux'
> subdir_done()
> endif
>
> @@ -14,5 +14,6 @@ sources = files(
> 'gve_rx_dqo.c',
> 'gve_tx_dqo.c',
> 'gve_ethdev.c',
> + 'gve_version.c',
> )
> includes += include_directories('base')
> --
> 2.40.1.698.g37aff9b760-goog
>
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH] net/gve: check driver compatibility
2023-05-19 7:41 ` Rushil Gupta
@ 2023-05-19 10:04 ` Ferruh Yigit
2023-05-19 16:15 ` Rushil Gupta
0 siblings, 1 reply; 32+ messages in thread
From: Ferruh Yigit @ 2023-05-19 10:04 UTC (permalink / raw)
To: Rushil Gupta, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Jeroen de Borst
On 5/19/2023 8:41 AM, Rushil Gupta wrote:
> Hi Ferruh
> I have updated the latest patch here:
> http://patchwork.dpdk.org/project/dpdk/patch/20230519072600.1444309-1-rushilg@google.com/
> However, using calloc causes issue while executing verify-compatibility command.
>
> sudo dpdk-testpmd -a 00:04.0 -l 0-32 -- --forward-mode=rxonly --txq=16
> --rxq=16 --nb-cores=16 --stats-period 5
> ...
> EAL: Using IOMMU type 8 (No-IOMMU)
> EAL: Probe PCI driver: net_gve (1ae0:42) device: 0000:00:04.0 (socket -1)
> gve_adminq_parse_err(): AQ command failed with status -9
> gve_init_priv(): Could not verify driver compatibility: err=-22
> EAL: Releasing PCI mapped resource for 0000:00:04.0
> ...
> EAL: Error - exiting with code: 1
>
>
> This is probably because the adminq command is sharing memory to
> report driver-info to the gvnic device and that needs to be in dpdk
> memory.
>
>
Hi Rushil,
That is OK, I missed this requirement.
Admin command passes pointers for device to process, what is the address
type requirement here?
Some other commands pass pysical address (iova address) via the command.
Both 'calloc()' and 'rte_zmalloc()' returns (guest) virtual address, why
one doesn't work but other does?
Initial version was passing 'rte_memzone' pointer, are you updating the
hyperviser side based on changes on dpdk side?
And perhaps better to switch to 'rte_memzone_reserve_aligned()' as done
initial version and pass (guest) pysical address via adminq, if that is
the requirement?
>
> On Fri, May 19, 2023 at 12:26 AM Rushil Gupta <rushilg@google.com> wrote:
>>
>> Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
>> version as OS version, reserving driver_version fields for GVE driver
>> version based on features.
>>
>> Signed-off-by: Rushil Gupta <rushilg@google.com>
>> Signed-off-by: Joshua Washington <joshwash@google.com>
>> Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
>> Signed-off-by: Jeroen de Borst <jeroendb@google.com>
>> ---
>> drivers/net/gve/base/gve.h | 3 --
>> drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
>> drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
>> drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
>> drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
>> drivers/net/gve/gve_ethdev.h | 2 +-
>> drivers/net/gve/gve_version.c | 13 +++++++
>> drivers/net/gve/gve_version.h | 24 ++++++++++++
>> drivers/net/gve/meson.build | 5 ++-
>> 9 files changed, 179 insertions(+), 18 deletions(-)
>> create mode 100644 drivers/net/gve/gve_version.c
>> create mode 100644 drivers/net/gve/gve_version.h
>>
>> diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
>> index 2b7cf7d99b..f7b297e759 100644
>> --- a/drivers/net/gve/base/gve.h
>> +++ b/drivers/net/gve/base/gve.h
>> @@ -9,9 +9,6 @@
>> #include "gve_desc.h"
>> #include "gve_desc_dqo.h"
>>
>> -#define GVE_VERSION "1.3.0"
>> -#define GVE_VERSION_PREFIX "GVE-"
>> -
>> #ifndef GOOGLE_VENDOR_ID
>> #define GOOGLE_VENDOR_ID 0x1ae0
>> #endif
>> diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
>> index e963f910a0..41202725e6 100644
>> --- a/drivers/net/gve/base/gve_adminq.c
>> +++ b/drivers/net/gve/base/gve_adminq.c
>> @@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
>> case GVE_ADMINQ_GET_PTYPE_MAP:
>> priv->adminq_get_ptype_map_cnt++;
>> break;
>> + case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
>> + priv->adminq_verify_driver_compatibility_cnt++;
>> + break;
>> default:
>> PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
>> }
>> @@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
>> return gve_adminq_execute_cmd(priv, &cmd);
>> }
>>
>> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
>> + u64 driver_info_len,
>> + dma_addr_t driver_info_addr)
>> +{
>> + union gve_adminq_command cmd;
>> +
>> + memset(&cmd, 0, sizeof(cmd));
>> + cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
>> + cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
>> + .driver_info_len = cpu_to_be64(driver_info_len),
>> + .driver_info_addr = cpu_to_be64(driver_info_addr),
>> + };
>> +
>> + return gve_adminq_execute_cmd(priv, &cmd);
>> +}
>> +
>> int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
>> {
>> union gve_adminq_command cmd;
>> diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
>> index 05550119de..e30b184913 100644
>> --- a/drivers/net/gve/base/gve_adminq.h
>> +++ b/drivers/net/gve/base/gve_adminq.h
>> @@ -1,6 +1,6 @@
>> /* SPDX-License-Identifier: MIT
>> * Google Virtual Ethernet (gve) driver
>> - * Copyright (C) 2015-2022 Google, Inc.
>> + * Copyright (C) 2015-2023 Google, Inc.
>> */
>>
>> #ifndef _GVE_ADMINQ_H
>> @@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
>> GVE_ADMINQ_REPORT_STATS = 0xC,
>> GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
>> GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
>> + GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
>> };
>>
>> /* Admin queue status codes */
>> @@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
>> };
>>
>> #define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
>> +enum gve_driver_capbility {
>> + gve_driver_capability_gqi_qpl = 0,
>> + gve_driver_capability_gqi_rda = 1,
>> + gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
>> + gve_driver_capability_dqo_rda = 3,
>> +};
>> +
>> +#define GVE_CAP1(a) BIT((int)a)
>> +
>> +#define GVE_DRIVER_CAPABILITY_FLAGS1 \
>> + (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
>> + GVE_CAP1(gve_driver_capability_gqi_rda) | \
>> + GVE_CAP1(gve_driver_capability_dqo_rda))
>> +
>> +#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
>> +#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
>> +#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
>> +
>> +struct gve_driver_info {
>> + u8 os_type; /* 0x05 = DPDK */
>> + u8 driver_major;
>> + u8 driver_minor;
>> + u8 driver_sub;
>> + __be32 os_version_major;
>> + __be32 os_version_minor;
>> + __be32 os_version_sub;
>> + __be64 driver_capability_flags[4];
>> + u8 os_version_str1[OS_VERSION_STRLEN];
>> + u8 os_version_str2[OS_VERSION_STRLEN];
>> +};
>> +
>> +struct gve_adminq_verify_driver_compatibility {
>> + __be64 driver_info_len;
>> + __be64 driver_info_addr;
>> +};
>> +
>> +GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
>> +
>>
>> struct gve_adminq_configure_device_resources {
>> __be64 counter_array;
>> @@ -345,6 +384,8 @@ union gve_adminq_command {
>> struct gve_adminq_report_stats report_stats;
>> struct gve_adminq_report_link_speed report_link_speed;
>> struct gve_adminq_get_ptype_map get_ptype_map;
>> + struct gve_adminq_verify_driver_compatibility
>> + verify_driver_compatibility;
>> };
>> };
>> u8 reserved[64];
>> @@ -378,4 +419,7 @@ struct gve_ptype_lut;
>> int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
>> struct gve_ptype_lut *ptype_lut);
>>
>> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
>> + u64 driver_info_len,
>> + dma_addr_t driver_info_addr);
>> #endif /* _GVE_ADMINQ_H */
>> diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
>> index abf3d379ae..5e8ae1eac6 100644
>> --- a/drivers/net/gve/base/gve_osdep.h
>> +++ b/drivers/net/gve/base/gve_osdep.h
>> @@ -21,9 +21,14 @@
>> #include <rte_malloc.h>
>> #include <rte_memcpy.h>
>> #include <rte_memzone.h>
>> +#include <rte_version.h>
>>
>> #include "../gve_logs.h"
>>
>> +#ifdef __linux__
>> +#include <sys/utsname.h>
>> +#endif
>> +
>> typedef uint8_t u8;
>> typedef uint16_t u16;
>> typedef uint32_t u32;
>> @@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
>>
>> #define msleep(ms) rte_delay_ms(ms)
>>
>> +#define OS_VERSION_STRLEN 128
>> +struct os_version_string {
>> + char os_version_str1[OS_VERSION_STRLEN];
>> + char os_version_str2[OS_VERSION_STRLEN];
>> +};
>> +
>> /* These macros are used to generate compilation errors if a struct/union
>> * is not exactly the correct length. It gives a divide by zero error if
>> * the struct/union is not of the correct size, otherwise it creates an
>> @@ -160,4 +171,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
>> mem->pa = 0;
>> }
>>
>> +static inline void
>> +populate_driver_version_strings(char *str1, char *str2)
>> +{
>> + struct utsname uts;
>> + if (uname(&uts) >= 0) {
>> + /* release */
>> + rte_strscpy(str1, uts.release,
>> + OS_VERSION_STRLEN);
>> + /* version */
>> + rte_strscpy(str2, uts.version,
>> + OS_VERSION_STRLEN);
>> + }
>> +}
>> #endif /* _GVE_OSDEP_H_ */
>> diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
>> index 1dcb3b3a01..71d131fb41 100644
>> --- a/drivers/net/gve/gve_ethdev.c
>> +++ b/drivers/net/gve/gve_ethdev.c
>> @@ -5,21 +5,13 @@
>> #include "gve_ethdev.h"
>> #include "base/gve_adminq.h"
>> #include "base/gve_register.h"
>> -
>> -const char gve_version_str[] = GVE_VERSION;
>> -static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
>> +#include "base/gve_osdep.h"
>> +#include "gve_version.h"
>>
>> static void
>> gve_write_version(uint8_t *driver_version_register)
>> {
>> - const char *c = gve_version_prefix;
>> -
>> - while (*c) {
>> - writeb(*c, driver_version_register);
>> - c++;
>> - }
>> -
>> - c = gve_version_str;
>> + const char *c = gve_version_string();
>> while (*c) {
>> writeb(*c, driver_version_register);
>> c++;
>> @@ -245,6 +237,48 @@ gve_dev_close(struct rte_eth_dev *dev)
>> return err;
>> }
>>
>> +static int
>> +gve_verify_driver_compatibility(struct gve_priv *priv)
>> +{
>> + struct gve_driver_info *driver_info;
>> + int err;
>> +
>> + driver_info = rte_zmalloc("driver info",
>> + sizeof(struct gve_driver_info), 0);
>> + if (driver_info == NULL) {
>> + PMD_DRV_LOG(ERR,
>> + "Could not alloc for verify driver compatibility");
>> + return -ENOMEM;
>> + }
>> + *driver_info = (struct gve_driver_info) {
>> + .os_type = 5, /* DPDK */
>> + .driver_major = GVE_VERSION_MAJOR,
>> + .driver_minor = GVE_VERSION_MINOR,
>> + .driver_sub = GVE_VERSION_SUB,
>> + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
>> + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
>> + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
>> + .driver_capability_flags = {
>> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
>> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
>> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
>> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
>> + },
>> + };
>> +
>> + populate_driver_version_strings((char *)driver_info->os_version_str1,
>> + (char *)driver_info->os_version_str2);
>> +
>> + err = gve_adminq_verify_driver_compatibility(priv,
>> + sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
>> + /* It's ok if the device doesn't support this */
>> + if (err == -EOPNOTSUPP)
>> + err = 0;
>> +
>> + rte_free(driver_info);
>> + return err;
>> +}
>> +
>> static int
>> gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
>> {
>> @@ -679,6 +713,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
>> PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
>> return err;
>> }
>> + err = gve_verify_driver_compatibility(priv);
>> + if (err) {
>> + PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
>> + goto free_adminq;
>> + }
>>
>> if (skip_describe_device)
>> goto setup_device;
>> diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
>> index cd62debd22..c9bcfa553c 100644
>> --- a/drivers/net/gve/gve_ethdev.h
>> +++ b/drivers/net/gve/gve_ethdev.h
>> @@ -268,7 +268,7 @@ struct gve_priv {
>> uint32_t adminq_report_stats_cnt;
>> uint32_t adminq_report_link_speed_cnt;
>> uint32_t adminq_get_ptype_map_cnt;
>> -
>> + uint32_t adminq_verify_driver_compatibility_cnt;
>> volatile uint32_t state_flags;
>>
>> /* Gvnic device link speed from hypervisor. */
>> diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
>> new file mode 100644
>> index 0000000000..5fe34dc179
>> --- /dev/null
>> +++ b/drivers/net/gve/gve_version.c
>> @@ -0,0 +1,13 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause
>> + * Copyright (C) 2015-2023 Google, Inc.
>> + */
>> +#include "gve_version.h"
>> +
>> +const char *gve_version_string(void)
>> +{
>> + static char gve_version[20];
>> + snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
>> + GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
>> + GVE_VERSION_SUB);
>> + return gve_version;
>> +}
>> diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
>> new file mode 100644
>> index 0000000000..4dd998dca1
>> --- /dev/null
>> +++ b/drivers/net/gve/gve_version.h
>> @@ -0,0 +1,24 @@
>> +/* SPDX-License-Identifier: BSD-3-Clause
>> + * Copyright (C) 2015-2023 Google, Inc.
>> + */
>> +
>> +#ifndef _GVE_VERSION_H_
>> +#define _GVE_VERSION_H_
>> +
>> +#include <rte_version.h>
>> +
>> +#define GVE_VERSION_PREFIX "DPDK-"
>> +#define GVE_VERSION_MAJOR 1
>> +#define GVE_VERSION_MINOR 0
>> +#define GVE_VERSION_SUB 0
>> +
>> +#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
>> +#define DPDK_VERSION_MINOR RTE_VER_MINOR
>> +#define DPDK_VERSION_SUB RTE_VER_RELEASE
>> +
>> +
>> +const char *
>> +gve_version_string(void);
>> +
>> +
>> +#endif /* GVE_VERSION_H */
>> diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
>> index c9d87903f9..61d195009c 100644
>> --- a/drivers/net/gve/meson.build
>> +++ b/drivers/net/gve/meson.build
>> @@ -1,9 +1,9 @@
>> # SPDX-License-Identifier: BSD-3-Clause
>> # Copyright(C) 2022 Intel Corporation
>>
>> -if is_windows
>> +if not is_linux
>> build = false
>> - reason = 'not supported on Windows'
>> + reason = 'only supported on Linux'
>> subdir_done()
>> endif
>>
>> @@ -14,5 +14,6 @@ sources = files(
>> 'gve_rx_dqo.c',
>> 'gve_tx_dqo.c',
>> 'gve_ethdev.c',
>> + 'gve_version.c',
>> )
>> includes += include_directories('base')
>> --
>> 2.40.1.698.g37aff9b760-goog
>>
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH] net/gve: check driver compatibility
2023-05-19 10:04 ` Ferruh Yigit
@ 2023-05-19 16:15 ` Rushil Gupta
0 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-19 16:15 UTC (permalink / raw)
To: Ferruh Yigit
Cc: qi.z.zhang, jingjing.wu, junfeng.guo, joshwash, dev, Jeroen de Borst
I agree. Other adminq commands like gve_adminq_report_link_speed use
gve_alloc_dma_mem and gve_free_dma_mem (which use
rte_memzone_reserve_aligned under the hood)
so let's stick to that.
On Fri, May 19, 2023 at 3:04 AM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>
> On 5/19/2023 8:41 AM, Rushil Gupta wrote:
> > Hi Ferruh
> > I have updated the latest patch here:
> > http://patchwork.dpdk.org/project/dpdk/patch/20230519072600.1444309-1-rushilg@google.com/
> > However, using calloc causes issue while executing verify-compatibility command.
> >
> > sudo dpdk-testpmd -a 00:04.0 -l 0-32 -- --forward-mode=rxonly --txq=16
> > --rxq=16 --nb-cores=16 --stats-period 5
> > ...
> > EAL: Using IOMMU type 8 (No-IOMMU)
> > EAL: Probe PCI driver: net_gve (1ae0:42) device: 0000:00:04.0 (socket -1)
> > gve_adminq_parse_err(): AQ command failed with status -9
> > gve_init_priv(): Could not verify driver compatibility: err=-22
> > EAL: Releasing PCI mapped resource for 0000:00:04.0
> > ...
> > EAL: Error - exiting with code: 1
> >
> >
> > This is probably because the adminq command is sharing memory to
> > report driver-info to the gvnic device and that needs to be in dpdk
> > memory.
> >
> >
>
> Hi Rushil,
>
> That is OK, I missed this requirement.
>
> Admin command passes pointers for device to process, what is the address
> type requirement here?
> Some other commands pass pysical address (iova address) via the command.
>
> Both 'calloc()' and 'rte_zmalloc()' returns (guest) virtual address, why
> one doesn't work but other does?
>
> Initial version was passing 'rte_memzone' pointer, are you updating the
> hyperviser side based on changes on dpdk side?
>
>
> And perhaps better to switch to 'rte_memzone_reserve_aligned()' as done
> initial version and pass (guest) pysical address via adminq, if that is
> the requirement?
>
>
> >
> > On Fri, May 19, 2023 at 12:26 AM Rushil Gupta <rushilg@google.com> wrote:
> >>
> >> Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
> >> version as OS version, reserving driver_version fields for GVE driver
> >> version based on features.
> >>
> >> Signed-off-by: Rushil Gupta <rushilg@google.com>
> >> Signed-off-by: Joshua Washington <joshwash@google.com>
> >> Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
> >> Signed-off-by: Jeroen de Borst <jeroendb@google.com>
> >> ---
> >> drivers/net/gve/base/gve.h | 3 --
> >> drivers/net/gve/base/gve_adminq.c | 19 ++++++++++
> >> drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++++-
> >> drivers/net/gve/base/gve_osdep.h | 24 ++++++++++++
> >> drivers/net/gve/gve_ethdev.c | 61 +++++++++++++++++++++++++------
> >> drivers/net/gve/gve_ethdev.h | 2 +-
> >> drivers/net/gve/gve_version.c | 13 +++++++
> >> drivers/net/gve/gve_version.h | 24 ++++++++++++
> >> drivers/net/gve/meson.build | 5 ++-
> >> 9 files changed, 179 insertions(+), 18 deletions(-)
> >> create mode 100644 drivers/net/gve/gve_version.c
> >> create mode 100644 drivers/net/gve/gve_version.h
> >>
> >> diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
> >> index 2b7cf7d99b..f7b297e759 100644
> >> --- a/drivers/net/gve/base/gve.h
> >> +++ b/drivers/net/gve/base/gve.h
> >> @@ -9,9 +9,6 @@
> >> #include "gve_desc.h"
> >> #include "gve_desc_dqo.h"
> >>
> >> -#define GVE_VERSION "1.3.0"
> >> -#define GVE_VERSION_PREFIX "GVE-"
> >> -
> >> #ifndef GOOGLE_VENDOR_ID
> >> #define GOOGLE_VENDOR_ID 0x1ae0
> >> #endif
> >> diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
> >> index e963f910a0..41202725e6 100644
> >> --- a/drivers/net/gve/base/gve_adminq.c
> >> +++ b/drivers/net/gve/base/gve_adminq.c
> >> @@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
> >> case GVE_ADMINQ_GET_PTYPE_MAP:
> >> priv->adminq_get_ptype_map_cnt++;
> >> break;
> >> + case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
> >> + priv->adminq_verify_driver_compatibility_cnt++;
> >> + break;
> >> default:
> >> PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
> >> }
> >> @@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
> >> return gve_adminq_execute_cmd(priv, &cmd);
> >> }
> >>
> >> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> >> + u64 driver_info_len,
> >> + dma_addr_t driver_info_addr)
> >> +{
> >> + union gve_adminq_command cmd;
> >> +
> >> + memset(&cmd, 0, sizeof(cmd));
> >> + cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
> >> + cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
> >> + .driver_info_len = cpu_to_be64(driver_info_len),
> >> + .driver_info_addr = cpu_to_be64(driver_info_addr),
> >> + };
> >> +
> >> + return gve_adminq_execute_cmd(priv, &cmd);
> >> +}
> >> +
> >> int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
> >> {
> >> union gve_adminq_command cmd;
> >> diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
> >> index 05550119de..e30b184913 100644
> >> --- a/drivers/net/gve/base/gve_adminq.h
> >> +++ b/drivers/net/gve/base/gve_adminq.h
> >> @@ -1,6 +1,6 @@
> >> /* SPDX-License-Identifier: MIT
> >> * Google Virtual Ethernet (gve) driver
> >> - * Copyright (C) 2015-2022 Google, Inc.
> >> + * Copyright (C) 2015-2023 Google, Inc.
> >> */
> >>
> >> #ifndef _GVE_ADMINQ_H
> >> @@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
> >> GVE_ADMINQ_REPORT_STATS = 0xC,
> >> GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
> >> GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
> >> + GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
> >> };
> >>
> >> /* Admin queue status codes */
> >> @@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
> >> };
> >>
> >> #define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
> >> +enum gve_driver_capbility {
> >> + gve_driver_capability_gqi_qpl = 0,
> >> + gve_driver_capability_gqi_rda = 1,
> >> + gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
> >> + gve_driver_capability_dqo_rda = 3,
> >> +};
> >> +
> >> +#define GVE_CAP1(a) BIT((int)a)
> >> +
> >> +#define GVE_DRIVER_CAPABILITY_FLAGS1 \
> >> + (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
> >> + GVE_CAP1(gve_driver_capability_gqi_rda) | \
> >> + GVE_CAP1(gve_driver_capability_dqo_rda))
> >> +
> >> +#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
> >> +#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
> >> +#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
> >> +
> >> +struct gve_driver_info {
> >> + u8 os_type; /* 0x05 = DPDK */
> >> + u8 driver_major;
> >> + u8 driver_minor;
> >> + u8 driver_sub;
> >> + __be32 os_version_major;
> >> + __be32 os_version_minor;
> >> + __be32 os_version_sub;
> >> + __be64 driver_capability_flags[4];
> >> + u8 os_version_str1[OS_VERSION_STRLEN];
> >> + u8 os_version_str2[OS_VERSION_STRLEN];
> >> +};
> >> +
> >> +struct gve_adminq_verify_driver_compatibility {
> >> + __be64 driver_info_len;
> >> + __be64 driver_info_addr;
> >> +};
> >> +
> >> +GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
> >> +
> >>
> >> struct gve_adminq_configure_device_resources {
> >> __be64 counter_array;
> >> @@ -345,6 +384,8 @@ union gve_adminq_command {
> >> struct gve_adminq_report_stats report_stats;
> >> struct gve_adminq_report_link_speed report_link_speed;
> >> struct gve_adminq_get_ptype_map get_ptype_map;
> >> + struct gve_adminq_verify_driver_compatibility
> >> + verify_driver_compatibility;
> >> };
> >> };
> >> u8 reserved[64];
> >> @@ -378,4 +419,7 @@ struct gve_ptype_lut;
> >> int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
> >> struct gve_ptype_lut *ptype_lut);
> >>
> >> +int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
> >> + u64 driver_info_len,
> >> + dma_addr_t driver_info_addr);
> >> #endif /* _GVE_ADMINQ_H */
> >> diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
> >> index abf3d379ae..5e8ae1eac6 100644
> >> --- a/drivers/net/gve/base/gve_osdep.h
> >> +++ b/drivers/net/gve/base/gve_osdep.h
> >> @@ -21,9 +21,14 @@
> >> #include <rte_malloc.h>
> >> #include <rte_memcpy.h>
> >> #include <rte_memzone.h>
> >> +#include <rte_version.h>
> >>
> >> #include "../gve_logs.h"
> >>
> >> +#ifdef __linux__
> >> +#include <sys/utsname.h>
> >> +#endif
> >> +
> >> typedef uint8_t u8;
> >> typedef uint16_t u16;
> >> typedef uint32_t u32;
> >> @@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
> >>
> >> #define msleep(ms) rte_delay_ms(ms)
> >>
> >> +#define OS_VERSION_STRLEN 128
> >> +struct os_version_string {
> >> + char os_version_str1[OS_VERSION_STRLEN];
> >> + char os_version_str2[OS_VERSION_STRLEN];
> >> +};
> >> +
> >> /* These macros are used to generate compilation errors if a struct/union
> >> * is not exactly the correct length. It gives a divide by zero error if
> >> * the struct/union is not of the correct size, otherwise it creates an
> >> @@ -160,4 +171,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
> >> mem->pa = 0;
> >> }
> >>
> >> +static inline void
> >> +populate_driver_version_strings(char *str1, char *str2)
> >> +{
> >> + struct utsname uts;
> >> + if (uname(&uts) >= 0) {
> >> + /* release */
> >> + rte_strscpy(str1, uts.release,
> >> + OS_VERSION_STRLEN);
> >> + /* version */
> >> + rte_strscpy(str2, uts.version,
> >> + OS_VERSION_STRLEN);
> >> + }
> >> +}
> >> #endif /* _GVE_OSDEP_H_ */
> >> diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
> >> index 1dcb3b3a01..71d131fb41 100644
> >> --- a/drivers/net/gve/gve_ethdev.c
> >> +++ b/drivers/net/gve/gve_ethdev.c
> >> @@ -5,21 +5,13 @@
> >> #include "gve_ethdev.h"
> >> #include "base/gve_adminq.h"
> >> #include "base/gve_register.h"
> >> -
> >> -const char gve_version_str[] = GVE_VERSION;
> >> -static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
> >> +#include "base/gve_osdep.h"
> >> +#include "gve_version.h"
> >>
> >> static void
> >> gve_write_version(uint8_t *driver_version_register)
> >> {
> >> - const char *c = gve_version_prefix;
> >> -
> >> - while (*c) {
> >> - writeb(*c, driver_version_register);
> >> - c++;
> >> - }
> >> -
> >> - c = gve_version_str;
> >> + const char *c = gve_version_string();
> >> while (*c) {
> >> writeb(*c, driver_version_register);
> >> c++;
> >> @@ -245,6 +237,48 @@ gve_dev_close(struct rte_eth_dev *dev)
> >> return err;
> >> }
> >>
> >> +static int
> >> +gve_verify_driver_compatibility(struct gve_priv *priv)
> >> +{
> >> + struct gve_driver_info *driver_info;
> >> + int err;
> >> +
> >> + driver_info = rte_zmalloc("driver info",
> >> + sizeof(struct gve_driver_info), 0);
> >> + if (driver_info == NULL) {
> >> + PMD_DRV_LOG(ERR,
> >> + "Could not alloc for verify driver compatibility");
> >> + return -ENOMEM;
> >> + }
> >> + *driver_info = (struct gve_driver_info) {
> >> + .os_type = 5, /* DPDK */
> >> + .driver_major = GVE_VERSION_MAJOR,
> >> + .driver_minor = GVE_VERSION_MINOR,
> >> + .driver_sub = GVE_VERSION_SUB,
> >> + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
> >> + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
> >> + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> >> + .driver_capability_flags = {
> >> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> >> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> >> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> >> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> >> + },
> >> + };
> >> +
> >> + populate_driver_version_strings((char *)driver_info->os_version_str1,
> >> + (char *)driver_info->os_version_str2);
> >> +
> >> + err = gve_adminq_verify_driver_compatibility(priv,
> >> + sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
> >> + /* It's ok if the device doesn't support this */
> >> + if (err == -EOPNOTSUPP)
> >> + err = 0;
> >> +
> >> + rte_free(driver_info);
> >> + return err;
> >> +}
> >> +
> >> static int
> >> gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
> >> {
> >> @@ -679,6 +713,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
> >> PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
> >> return err;
> >> }
> >> + err = gve_verify_driver_compatibility(priv);
> >> + if (err) {
> >> + PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
> >> + goto free_adminq;
> >> + }
> >>
> >> if (skip_describe_device)
> >> goto setup_device;
> >> diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
> >> index cd62debd22..c9bcfa553c 100644
> >> --- a/drivers/net/gve/gve_ethdev.h
> >> +++ b/drivers/net/gve/gve_ethdev.h
> >> @@ -268,7 +268,7 @@ struct gve_priv {
> >> uint32_t adminq_report_stats_cnt;
> >> uint32_t adminq_report_link_speed_cnt;
> >> uint32_t adminq_get_ptype_map_cnt;
> >> -
> >> + uint32_t adminq_verify_driver_compatibility_cnt;
> >> volatile uint32_t state_flags;
> >>
> >> /* Gvnic device link speed from hypervisor. */
> >> diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
> >> new file mode 100644
> >> index 0000000000..5fe34dc179
> >> --- /dev/null
> >> +++ b/drivers/net/gve/gve_version.c
> >> @@ -0,0 +1,13 @@
> >> +/* SPDX-License-Identifier: BSD-3-Clause
> >> + * Copyright (C) 2015-2023 Google, Inc.
> >> + */
> >> +#include "gve_version.h"
> >> +
> >> +const char *gve_version_string(void)
> >> +{
> >> + static char gve_version[20];
> >> + snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
> >> + GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
> >> + GVE_VERSION_SUB);
> >> + return gve_version;
> >> +}
> >> diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
> >> new file mode 100644
> >> index 0000000000..4dd998dca1
> >> --- /dev/null
> >> +++ b/drivers/net/gve/gve_version.h
> >> @@ -0,0 +1,24 @@
> >> +/* SPDX-License-Identifier: BSD-3-Clause
> >> + * Copyright (C) 2015-2023 Google, Inc.
> >> + */
> >> +
> >> +#ifndef _GVE_VERSION_H_
> >> +#define _GVE_VERSION_H_
> >> +
> >> +#include <rte_version.h>
> >> +
> >> +#define GVE_VERSION_PREFIX "DPDK-"
> >> +#define GVE_VERSION_MAJOR 1
> >> +#define GVE_VERSION_MINOR 0
> >> +#define GVE_VERSION_SUB 0
> >> +
> >> +#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
> >> +#define DPDK_VERSION_MINOR RTE_VER_MINOR
> >> +#define DPDK_VERSION_SUB RTE_VER_RELEASE
> >> +
> >> +
> >> +const char *
> >> +gve_version_string(void);
> >> +
> >> +
> >> +#endif /* GVE_VERSION_H */
> >> diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
> >> index c9d87903f9..61d195009c 100644
> >> --- a/drivers/net/gve/meson.build
> >> +++ b/drivers/net/gve/meson.build
> >> @@ -1,9 +1,9 @@
> >> # SPDX-License-Identifier: BSD-3-Clause
> >> # Copyright(C) 2022 Intel Corporation
> >>
> >> -if is_windows
> >> +if not is_linux
> >> build = false
> >> - reason = 'not supported on Windows'
> >> + reason = 'only supported on Linux'
> >> subdir_done()
> >> endif
> >>
> >> @@ -14,5 +14,6 @@ sources = files(
> >> 'gve_rx_dqo.c',
> >> 'gve_tx_dqo.c',
> >> 'gve_ethdev.c',
> >> + 'gve_version.c',
> >> )
> >> includes += include_directories('base')
> >> --
> >> 2.40.1.698.g37aff9b760-goog
> >>
>
^ permalink raw reply [flat|nested] 32+ messages in thread
* [v4] net/gve: check driver compatibility
2023-05-19 7:26 ` Rushil Gupta
2023-05-19 7:41 ` Rushil Gupta
@ 2023-05-19 19:54 ` Rushil Gupta
2023-05-19 20:46 ` Rushil Gupta
2 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-19 19:54 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
drivers/net/gve/base/gve.h | 3 --
drivers/net/gve/base/gve_adminq.c | 19 +++++++++
drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++-
drivers/net/gve/base/gve_osdep.h | 24 +++++++++++
drivers/net/gve/gve_ethdev.c | 68 ++++++++++++++++++++++++++-----
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 13 ++++++
drivers/net/gve/gve_version.h | 24 +++++++++++
drivers/net/gve/meson.build | 5 ++-
9 files changed, 186 insertions(+), 18 deletions(-)
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2b7cf7d99b..f7b297e759 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -9,9 +9,6 @@
#include "gve_desc.h"
#include "gve_desc_dqo.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e963f910a0..41202725e6 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..e30b184913 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +384,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +419,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index abf3d379ae..5e8ae1eac6 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -160,4 +171,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(char *str1, char *str2)
+{
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(str1, uts.release,
+ OS_VERSION_STRLEN);
+ /* version */
+ rte_strscpy(str2, uts.version,
+ OS_VERSION_STRLEN);
+ }
+}
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index 1dcb3b3a01..e963b52c37 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -245,6 +237,55 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ const struct rte_memzone *driver_info_mem;
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info_mem = rte_memzone_reserve_aligned(
+ "verify_driver_compatibility",
+ sizeof(struct gve_driver_info),
+ rte_socket_id(),
+ RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
+
+ if (driver_info_mem == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc memzone for driver compatibility");
+ return -ENOMEM;
+ }
+ driver_info = (struct gve_driver_info *)driver_info_mem->addr;
+
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((char *)driver_info->os_version_str1,
+ (char *)driver_info->os_version_str2);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_memzone_free(driver_info_mem);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -679,6 +720,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index cd62debd22..c9bcfa553c 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -268,7 +268,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..5fe34dc179
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[20];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..4dd998dca1
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index c9d87903f9..61d195009c 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(C) 2022 Intel Corporation
-if is_windows
+if not is_linux
build = false
- reason = 'not supported on Windows'
+ reason = 'only supported on Linux'
subdir_done()
endif
@@ -14,5 +14,6 @@ sources = files(
'gve_rx_dqo.c',
'gve_tx_dqo.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.1.698.g37aff9b760-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* [v4] net/gve: check driver compatibility
2023-05-19 7:26 ` Rushil Gupta
2023-05-19 7:41 ` Rushil Gupta
2023-05-19 19:54 ` [v4] " Rushil Gupta
@ 2023-05-19 20:46 ` Rushil Gupta
2023-05-19 20:56 ` Stephen Hemminger
` (3 more replies)
2 siblings, 4 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-19 20:46 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
drivers/net/gve/base/gve.h | 3 --
drivers/net/gve/base/gve_adminq.c | 19 +++++++++
drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++-
drivers/net/gve/base/gve_osdep.h | 24 +++++++++++
drivers/net/gve/gve_ethdev.c | 67 ++++++++++++++++++++++++++-----
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 13 ++++++
drivers/net/gve/gve_version.h | 24 +++++++++++
drivers/net/gve/meson.build | 5 ++-
9 files changed, 185 insertions(+), 18 deletions(-)
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2b7cf7d99b..f7b297e759 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -9,9 +9,6 @@
#include "gve_desc.h"
#include "gve_desc_dqo.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e963f910a0..41202725e6 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..e30b184913 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +384,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +419,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index abf3d379ae..5e8ae1eac6 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -160,4 +171,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(char *str1, char *str2)
+{
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(str1, uts.release,
+ OS_VERSION_STRLEN);
+ /* version */
+ rte_strscpy(str2, uts.version,
+ OS_VERSION_STRLEN);
+ }
+}
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index 1dcb3b3a01..56109aee35 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -245,6 +237,54 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ const struct rte_memzone *driver_info_mem;
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info_mem = rte_memzone_reserve_aligned("verify_driver_compatibility",
+ sizeof(struct gve_driver_info),
+ rte_socket_id(),
+ RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
+
+ if (driver_info_mem == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc memzone for driver compatibility");
+ return -ENOMEM;
+ }
+ driver_info = (struct gve_driver_info *)driver_info_mem->addr;
+
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((char *)driver_info->os_version_str1,
+ (char *)driver_info->os_version_str2);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_memzone_free(driver_info_mem);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -679,6 +719,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index cd62debd22..c9bcfa553c 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -268,7 +268,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..5fe34dc179
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[20];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..4dd998dca1
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index c9d87903f9..61d195009c 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(C) 2022 Intel Corporation
-if is_windows
+if not is_linux
build = false
- reason = 'not supported on Windows'
+ reason = 'only supported on Linux'
subdir_done()
endif
@@ -14,5 +14,6 @@ sources = files(
'gve_rx_dqo.c',
'gve_tx_dqo.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.40.1.698.g37aff9b760-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v4] net/gve: check driver compatibility
2023-05-19 20:46 ` Rushil Gupta
@ 2023-05-19 20:56 ` Stephen Hemminger
2023-05-20 16:44 ` Rushil Gupta
2023-05-22 8:52 ` Ferruh Yigit
` (2 subsequent siblings)
3 siblings, 1 reply; 32+ messages in thread
From: Stephen Hemminger @ 2023-05-19 20:56 UTC (permalink / raw)
To: Rushil Gupta
Cc: ferruh.yigit, qi.z.zhang, jingjing.wu, junfeng.guo, joshwash,
dev, Jeroen de Borst
On Fri, 19 May 2023 13:46:18 -0700
Rushil Gupta <rushilg@google.com> wrote:
> +#include <rte_version.h>
>
> #include "../gve_logs.h"
>
> +#ifdef __linux__
> +#include <sys/utsname.h>
> +#endif
> +
> typedef uint8_t u8;
> typedef uint16_t u16;
> typedef uint32_t u32;
> @@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
>
> #define msleep(ms) rte_delay_ms(ms)
>
> +#define OS_VERSION_STRLEN 128
> +struct os_version_string {
> + char os_version_str1[OS_VERSION_STRLEN];
> + char os_version_str2[OS_VERSION_STRLEN];
> +};
> +
Not sure this a good idea. Are you having the host validate
against DPDK versions. This is a bad idea.
Better to use feature bits like virtio and not be creating
and validating strings about versions. For example, ever minor
stable release changes this.
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v4] net/gve: check driver compatibility
2023-05-19 20:56 ` Stephen Hemminger
@ 2023-05-20 16:44 ` Rushil Gupta
0 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-20 16:44 UTC (permalink / raw)
To: Stephen Hemminger
Cc: ferruh.yigit, qi.z.zhang, jingjing.wu, junfeng.guo, joshwash,
dev, Jeroen de Borst
[-- Attachment #1: Type: text/plain, Size: 1087 bytes --]
We are not validating anything.
This is for our internal analysis and product requirements.
On Fri, May 19, 2023 at 1:56 PM Stephen Hemminger <
stephen@networkplumber.org> wrote:
> On Fri, 19 May 2023 13:46:18 -0700
> Rushil Gupta <rushilg@google.com> wrote:
>
> > +#include <rte_version.h>
> >
> > #include "../gve_logs.h"
> >
> > +#ifdef __linux__
> > +#include <sys/utsname.h>
> > +#endif
> > +
> > typedef uint8_t u8;
> > typedef uint16_t u16;
> > typedef uint32_t u32;
> > @@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
> >
> > #define msleep(ms) rte_delay_ms(ms)
> >
> > +#define OS_VERSION_STRLEN 128
> > +struct os_version_string {
> > + char os_version_str1[OS_VERSION_STRLEN];
> > + char os_version_str2[OS_VERSION_STRLEN];
> > +};
> > +
>
> Not sure this a good idea. Are you having the host validate
> against DPDK versions. This is a bad idea.
>
> Better to use feature bits like virtio and not be creating
> and validating strings about versions. For example, ever minor
> stable release changes this.
>
[-- Attachment #2: Type: text/html, Size: 1615 bytes --]
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v4] net/gve: check driver compatibility
2023-05-19 20:46 ` Rushil Gupta
2023-05-19 20:56 ` Stephen Hemminger
@ 2023-05-22 8:52 ` Ferruh Yigit
2023-05-22 15:45 ` Rushil Gupta
2023-05-23 10:21 ` Ferruh Yigit
2023-05-24 17:13 ` [v5] " Rushil Gupta
3 siblings, 1 reply; 32+ messages in thread
From: Ferruh Yigit @ 2023-05-22 8:52 UTC (permalink / raw)
To: Rushil Gupta, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Jeroen de Borst
On 5/19/2023 9:46 PM, Rushil Gupta wrote:
> +static int
> +gve_verify_driver_compatibility(struct gve_priv *priv)
> +{
> + const struct rte_memzone *driver_info_mem;
> + struct gve_driver_info *driver_info;
> + int err;
> +
> + driver_info_mem = rte_memzone_reserve_aligned("verify_driver_compatibility",
> + sizeof(struct gve_driver_info),
> + rte_socket_id(),
> + RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
> +
> + if (driver_info_mem == NULL) {
> + PMD_DRV_LOG(ERR,
> + "Could not alloc memzone for driver compatibility");
> + return -ENOMEM;
> + }
> + driver_info = (struct gve_driver_info *)driver_info_mem->addr;
> +
> + *driver_info = (struct gve_driver_info) {
> + .os_type = 5, /* DPDK */
> + .driver_major = GVE_VERSION_MAJOR,
> + .driver_minor = GVE_VERSION_MINOR,
> + .driver_sub = GVE_VERSION_SUB,
> + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
> + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
> + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> + .driver_capability_flags = {
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> + },
> + };
> +
> + populate_driver_version_strings((char *)driver_info->os_version_str1,
> + (char *)driver_info->os_version_str2);
> +
> + err = gve_adminq_verify_driver_compatibility(priv,
> + sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
Back to previous discussion, other commands pass physical address to the
admin command, but this pass virtual address.
To follow the same semantic, shouldn't above be 'driver_info_mem.iova'?
I asked before but not able to get an answer, what is the memory type
requirement for device?
Why virtual address obtained via 'calloc()' is not working, but virtual
address from hugepages are working?
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v4] net/gve: check driver compatibility
2023-05-22 8:52 ` Ferruh Yigit
@ 2023-05-22 15:45 ` Rushil Gupta
2023-05-23 10:20 ` Ferruh Yigit
0 siblings, 1 reply; 32+ messages in thread
From: Rushil Gupta @ 2023-05-22 15:45 UTC (permalink / raw)
To: Ferruh Yigit
Cc: qi.z.zhang, jingjing.wu, junfeng.guo, joshwash, dev, Jeroen de Borst
[-- Attachment #1: Type: text/plain, Size: 3716 bytes --]
1. This is the excerpt from the google's virtual nic spec:
"In addition to the device-owned register file, vector table, and
doorbells, the gVNIC device uses *DMA* (which in most cases amounts to
ordinary memory access by host software since we're dealing with a virtual
device, but guests must assume the device could be backed by actual
hardware) to access physical memory. The following are all located in
physical memory: Admin queue - 4096-byte command queue used for configuring
gVNIC.
Some commands require an additional dma memory region to be passed to the
device. These memory regions are allocated to execute the command and freed
when the command completes."
The calloc by default doesn't allow memory to be shared between the dpdk
process and hypervisor (where virtual device lives); so that's the reason
it doesn't work.
2. I also have a query: RHEL8 compilation in ci/Intel-compilation context
fails due to; is this because of if `not is_linux`
meson.build:67:0: ERROR: Include dir lib/eal/linux/include does not exist.
Passes: http://patchwork.dpdk.org/project/dpdk/patch/20230508191552.104540-1-rushilg@google.com/
Fails: http://patchwork.dpdk.org/project/dpdk/patch/20230519204618.1507956-1-rushilg@google.com/
On Mon, May 22, 2023 at 1:52 AM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> On 5/19/2023 9:46 PM, Rushil Gupta wrote:
> > +static int
> > +gve_verify_driver_compatibility(struct gve_priv *priv)
> > +{
> > + const struct rte_memzone *driver_info_mem;
> > + struct gve_driver_info *driver_info;
> > + int err;
> > +
> > + driver_info_mem =
> rte_memzone_reserve_aligned("verify_driver_compatibility",
> > + sizeof(struct gve_driver_info),
> > + rte_socket_id(),
> > + RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
> > +
> > + if (driver_info_mem == NULL) {
> > + PMD_DRV_LOG(ERR,
> > + "Could not alloc memzone for driver
> compatibility");
> > + return -ENOMEM;
> > + }
> > + driver_info = (struct gve_driver_info *)driver_info_mem->addr;
> > +
> > + *driver_info = (struct gve_driver_info) {
> > + .os_type = 5, /* DPDK */
> > + .driver_major = GVE_VERSION_MAJOR,
> > + .driver_minor = GVE_VERSION_MINOR,
> > + .driver_sub = GVE_VERSION_SUB,
> > + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
> > + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
> > + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> > + .driver_capability_flags = {
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> > + },
> > + };
> > +
> > + populate_driver_version_strings((char
> *)driver_info->os_version_str1,
> > + (char *)driver_info->os_version_str2);
> > +
> > + err = gve_adminq_verify_driver_compatibility(priv,
> > + sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
>
> Back to previous discussion, other commands pass physical address to the
> admin command, but this pass virtual address.
> To follow the same semantic, shouldn't above be 'driver_info_mem.iova'?
>
> I asked before but not able to get an answer, what is the memory type
> requirement for device?
> Why virtual address obtained via 'calloc()' is not working, but virtual
> address from hugepages are working?
>
[-- Attachment #2: Type: text/html, Size: 5038 bytes --]
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v4] net/gve: check driver compatibility
2023-05-22 15:45 ` Rushil Gupta
@ 2023-05-23 10:20 ` Ferruh Yigit
0 siblings, 0 replies; 32+ messages in thread
From: Ferruh Yigit @ 2023-05-23 10:20 UTC (permalink / raw)
To: Rushil Gupta
Cc: qi.z.zhang, jingjing.wu, junfeng.guo, joshwash, dev, Jeroen de Borst
On 5/22/2023 4:45 PM, Rushil Gupta wrote:
> 1. This is the excerpt from the google's virtual nic spec:
> "In addition to the device-owned register file, vector table, and
> doorbells, the gVNIC device uses *DMA* (which in most cases amounts to
> ordinary memory access by host software since we're dealing with a
> virtual device, but guests must assume the device could be backed by
> actual hardware) to access physical memory. The following are all
> located in physical memory: Admin queue - 4096-byte command queue used
> for configuring gVNIC.
> Some commands require an additional dma memory region to be passed to
> the device. These memory regions are allocated to execute the command
> and freed when the command completes."
> The calloc by default doesn't allow memory to be shared between the dpdk
> process and hypervisor (where virtual device lives); so that's the
> reason it doesn't work.
>
Thanks Rushil for the info.
So, I expect gVNIC requires physical address to be passed in the admin
command, as 'driver_info_mem.iova'.
What confuses me is, latest version passes another virtual address
'driver_info' ('driver_info_mem->addr').
> 2. I also have a query: RHEL8 compilation in ci/Intel-compilation
> context fails due to; is this because of if `not is_linux`
>
> meson.build:67:0: ERROR: Include dir lib/eal/linux/include does not exist.
>
This error shouldn't be related with `not is_linux`, but I am not sure
about its root case, if it still exists in next version we can
communicate with CI team for details. For now I assume this is an
infrastructure issue.
> Passes:
> http://patchwork.dpdk.org/project/dpdk/patch/20230508191552.104540-1-rushilg@google.com/ <http://patchwork.dpdk.org/project/dpdk/patch/20230508191552.104540-1-rushilg@google.com/>
>
> Fails:
> http://patchwork.dpdk.org/project/dpdk/patch/20230519204618.1507956-1-rushilg@google.com/ <http://patchwork.dpdk.org/project/dpdk/patch/20230519204618.1507956-1-rushilg@google.com/>
>
>
> On Mon, May 22, 2023 at 1:52 AM Ferruh Yigit <ferruh.yigit@amd.com
> <mailto:ferruh.yigit@amd.com>> wrote:
>
> On 5/19/2023 9:46 PM, Rushil Gupta wrote:
> > +static int
> > +gve_verify_driver_compatibility(struct gve_priv *priv)
> > +{
> > + const struct rte_memzone *driver_info_mem;
> > + struct gve_driver_info *driver_info;
> > + int err;
> > +
> > + driver_info_mem =
> rte_memzone_reserve_aligned("verify_driver_compatibility",
> > + sizeof(struct gve_driver_info),
> > + rte_socket_id(),
> > + RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
> > +
> > + if (driver_info_mem == NULL) {
> > + PMD_DRV_LOG(ERR,
> > + "Could not alloc memzone for driver
> compatibility");
> > + return -ENOMEM;
> > + }
> > + driver_info = (struct gve_driver_info *)driver_info_mem->addr;
> > +
> > + *driver_info = (struct gve_driver_info) {
> > + .os_type = 5, /* DPDK */
> > + .driver_major = GVE_VERSION_MAJOR,
> > + .driver_minor = GVE_VERSION_MINOR,
> > + .driver_sub = GVE_VERSION_SUB,
> > + .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
> > + .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
> > + .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
> > + .driver_capability_flags = {
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
> > + cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
> > + },
> > + };
> > +
> > + populate_driver_version_strings((char
> *)driver_info->os_version_str1,
> > + (char *)driver_info->os_version_str2);
> > +
> > + err = gve_adminq_verify_driver_compatibility(priv,
> > + sizeof(struct gve_driver_info),
> (dma_addr_t)driver_info);
>
> Back to previous discussion, other commands pass physical address to the
> admin command, but this pass virtual address.
> To follow the same semantic, shouldn't above be 'driver_info_mem.iova'?
>
> I asked before but not able to get an answer, what is the memory type
> requirement for device?
> Why virtual address obtained via 'calloc()' is not working, but virtual
> address from hugepages are working?
>
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v4] net/gve: check driver compatibility
2023-05-19 20:46 ` Rushil Gupta
2023-05-19 20:56 ` Stephen Hemminger
2023-05-22 8:52 ` Ferruh Yigit
@ 2023-05-23 10:21 ` Ferruh Yigit
2023-05-24 17:14 ` Rushil Gupta
2023-05-24 17:13 ` [v5] " Rushil Gupta
3 siblings, 1 reply; 32+ messages in thread
From: Ferruh Yigit @ 2023-05-23 10:21 UTC (permalink / raw)
To: Rushil Gupta, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Jeroen de Borst
On 5/19/2023 9:46 PM, Rushil Gupta wrote:
> diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
> index abf3d379ae..5e8ae1eac6 100644
> --- a/drivers/net/gve/base/gve_osdep.h
> +++ b/drivers/net/gve/base/gve_osdep.h
> @@ -21,9 +21,14 @@
> #include <rte_malloc.h>
> #include <rte_memcpy.h>
> #include <rte_memzone.h>
> +#include <rte_version.h>
>
> #include "../gve_logs.h"
>
> +#ifdef __linux__
> +#include <sys/utsname.h>
> +#endif
> +
Can you please use 'RTE_EXEC_ENV_LINUX' macro instead of '__linux__'?
^ permalink raw reply [flat|nested] 32+ messages in thread
* [v5] net/gve: check driver compatibility
2023-05-19 20:46 ` Rushil Gupta
` (2 preceding siblings ...)
2023-05-23 10:21 ` Ferruh Yigit
@ 2023-05-24 17:13 ` Rushil Gupta
2023-05-31 17:04 ` Ferruh Yigit
3 siblings, 1 reply; 32+ messages in thread
From: Rushil Gupta @ 2023-05-24 17:13 UTC (permalink / raw)
To: ferruh.yigit, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Rushil Gupta, Jeroen de Borst
Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
version as OS version, reserving driver_version fields for GVE driver
version based on features.
Signed-off-by: Rushil Gupta <rushilg@google.com>
Signed-off-by: Joshua Washington <joshwash@google.com>
Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
Signed-off-by: Jeroen de Borst <jeroendb@google.com>
---
drivers/net/gve/base/gve.h | 3 --
drivers/net/gve/base/gve_adminq.c | 19 +++++++++
drivers/net/gve/base/gve_adminq.h | 46 ++++++++++++++++++++-
drivers/net/gve/base/gve_osdep.h | 24 +++++++++++
drivers/net/gve/gve_ethdev.c | 67 ++++++++++++++++++++++++++-----
drivers/net/gve/gve_ethdev.h | 2 +-
drivers/net/gve/gve_version.c | 13 ++++++
drivers/net/gve/gve_version.h | 24 +++++++++++
drivers/net/gve/meson.build | 5 ++-
9 files changed, 185 insertions(+), 18 deletions(-)
create mode 100644 drivers/net/gve/gve_version.c
create mode 100644 drivers/net/gve/gve_version.h
diff --git a/drivers/net/gve/base/gve.h b/drivers/net/gve/base/gve.h
index 2b7cf7d99b..f7b297e759 100644
--- a/drivers/net/gve/base/gve.h
+++ b/drivers/net/gve/base/gve.h
@@ -9,9 +9,6 @@
#include "gve_desc.h"
#include "gve_desc_dqo.h"
-#define GVE_VERSION "1.3.0"
-#define GVE_VERSION_PREFIX "GVE-"
-
#ifndef GOOGLE_VENDOR_ID
#define GOOGLE_VENDOR_ID 0x1ae0
#endif
diff --git a/drivers/net/gve/base/gve_adminq.c b/drivers/net/gve/base/gve_adminq.c
index e963f910a0..41202725e6 100644
--- a/drivers/net/gve/base/gve_adminq.c
+++ b/drivers/net/gve/base/gve_adminq.c
@@ -401,6 +401,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
case GVE_ADMINQ_GET_PTYPE_MAP:
priv->adminq_get_ptype_map_cnt++;
break;
+ case GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY:
+ priv->adminq_verify_driver_compatibility_cnt++;
+ break;
default:
PMD_DRV_LOG(ERR, "unknown AQ command opcode %d", opcode);
}
@@ -465,6 +468,22 @@ int gve_adminq_configure_device_resources(struct gve_priv *priv,
return gve_adminq_execute_cmd(priv, &cmd);
}
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr)
+{
+ union gve_adminq_command cmd;
+
+ memset(&cmd, 0, sizeof(cmd));
+ cmd.opcode = cpu_to_be32(GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY);
+ cmd.verify_driver_compatibility = (struct gve_adminq_verify_driver_compatibility) {
+ .driver_info_len = cpu_to_be64(driver_info_len),
+ .driver_info_addr = cpu_to_be64(driver_info_addr),
+ };
+
+ return gve_adminq_execute_cmd(priv, &cmd);
+}
+
int gve_adminq_deconfigure_device_resources(struct gve_priv *priv)
{
union gve_adminq_command cmd;
diff --git a/drivers/net/gve/base/gve_adminq.h b/drivers/net/gve/base/gve_adminq.h
index 05550119de..e30b184913 100644
--- a/drivers/net/gve/base/gve_adminq.h
+++ b/drivers/net/gve/base/gve_adminq.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
* Google Virtual Ethernet (gve) driver
- * Copyright (C) 2015-2022 Google, Inc.
+ * Copyright (C) 2015-2023 Google, Inc.
*/
#ifndef _GVE_ADMINQ_H
@@ -23,6 +23,7 @@ enum gve_adminq_opcodes {
GVE_ADMINQ_REPORT_STATS = 0xC,
GVE_ADMINQ_REPORT_LINK_SPEED = 0xD,
GVE_ADMINQ_GET_PTYPE_MAP = 0xE,
+ GVE_ADMINQ_VERIFY_DRIVER_COMPATIBILITY = 0xF,
};
/* Admin queue status codes */
@@ -145,6 +146,44 @@ enum gve_sup_feature_mask {
};
#define GVE_DEV_OPT_LEN_GQI_RAW_ADDRESSING 0x0
+enum gve_driver_capbility {
+ gve_driver_capability_gqi_qpl = 0,
+ gve_driver_capability_gqi_rda = 1,
+ gve_driver_capability_dqo_qpl = 2, /* reserved for future use */
+ gve_driver_capability_dqo_rda = 3,
+};
+
+#define GVE_CAP1(a) BIT((int)a)
+
+#define GVE_DRIVER_CAPABILITY_FLAGS1 \
+ (GVE_CAP1(gve_driver_capability_gqi_qpl) | \
+ GVE_CAP1(gve_driver_capability_gqi_rda) | \
+ GVE_CAP1(gve_driver_capability_dqo_rda))
+
+#define GVE_DRIVER_CAPABILITY_FLAGS2 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS3 0x0
+#define GVE_DRIVER_CAPABILITY_FLAGS4 0x0
+
+struct gve_driver_info {
+ u8 os_type; /* 0x05 = DPDK */
+ u8 driver_major;
+ u8 driver_minor;
+ u8 driver_sub;
+ __be32 os_version_major;
+ __be32 os_version_minor;
+ __be32 os_version_sub;
+ __be64 driver_capability_flags[4];
+ u8 os_version_str1[OS_VERSION_STRLEN];
+ u8 os_version_str2[OS_VERSION_STRLEN];
+};
+
+struct gve_adminq_verify_driver_compatibility {
+ __be64 driver_info_len;
+ __be64 driver_info_addr;
+};
+
+GVE_CHECK_STRUCT_LEN(16, gve_adminq_verify_driver_compatibility);
+
struct gve_adminq_configure_device_resources {
__be64 counter_array;
@@ -345,6 +384,8 @@ union gve_adminq_command {
struct gve_adminq_report_stats report_stats;
struct gve_adminq_report_link_speed report_link_speed;
struct gve_adminq_get_ptype_map get_ptype_map;
+ struct gve_adminq_verify_driver_compatibility
+ verify_driver_compatibility;
};
};
u8 reserved[64];
@@ -378,4 +419,7 @@ struct gve_ptype_lut;
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
struct gve_ptype_lut *ptype_lut);
+int gve_adminq_verify_driver_compatibility(struct gve_priv *priv,
+ u64 driver_info_len,
+ dma_addr_t driver_info_addr);
#endif /* _GVE_ADMINQ_H */
diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
index abf3d379ae..a3702f4b8c 100644
--- a/drivers/net/gve/base/gve_osdep.h
+++ b/drivers/net/gve/base/gve_osdep.h
@@ -21,9 +21,14 @@
#include <rte_malloc.h>
#include <rte_memcpy.h>
#include <rte_memzone.h>
+#include <rte_version.h>
#include "../gve_logs.h"
+#ifdef RTE_EXEC_ENV_LINUX
+#include <sys/utsname.h>
+#endif
+
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
@@ -73,6 +78,12 @@ typedef rte_iova_t dma_addr_t;
#define msleep(ms) rte_delay_ms(ms)
+#define OS_VERSION_STRLEN 128
+struct os_version_string {
+ char os_version_str1[OS_VERSION_STRLEN];
+ char os_version_str2[OS_VERSION_STRLEN];
+};
+
/* These macros are used to generate compilation errors if a struct/union
* is not exactly the correct length. It gives a divide by zero error if
* the struct/union is not of the correct size, otherwise it creates an
@@ -160,4 +171,17 @@ gve_free_dma_mem(struct gve_dma_mem *mem)
mem->pa = 0;
}
+static inline void
+populate_driver_version_strings(char *str1, char *str2)
+{
+ struct utsname uts;
+ if (uname(&uts) >= 0) {
+ /* release */
+ rte_strscpy(str1, uts.release,
+ OS_VERSION_STRLEN);
+ /* version */
+ rte_strscpy(str2, uts.version,
+ OS_VERSION_STRLEN);
+ }
+}
#endif /* _GVE_OSDEP_H_ */
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index 1dcb3b3a01..2c1e73d07a 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -5,21 +5,13 @@
#include "gve_ethdev.h"
#include "base/gve_adminq.h"
#include "base/gve_register.h"
-
-const char gve_version_str[] = GVE_VERSION;
-static const char gve_version_prefix[] = GVE_VERSION_PREFIX;
+#include "base/gve_osdep.h"
+#include "gve_version.h"
static void
gve_write_version(uint8_t *driver_version_register)
{
- const char *c = gve_version_prefix;
-
- while (*c) {
- writeb(*c, driver_version_register);
- c++;
- }
-
- c = gve_version_str;
+ const char *c = gve_version_string();
while (*c) {
writeb(*c, driver_version_register);
c++;
@@ -245,6 +237,54 @@ gve_dev_close(struct rte_eth_dev *dev)
return err;
}
+static int
+gve_verify_driver_compatibility(struct gve_priv *priv)
+{
+ const struct rte_memzone *driver_info_mem;
+ struct gve_driver_info *driver_info;
+ int err;
+
+ driver_info_mem = rte_memzone_reserve_aligned("verify_driver_compatibility",
+ sizeof(struct gve_driver_info),
+ rte_socket_id(),
+ RTE_MEMZONE_IOVA_CONTIG, PAGE_SIZE);
+
+ if (driver_info_mem == NULL) {
+ PMD_DRV_LOG(ERR,
+ "Could not alloc memzone for driver compatibility");
+ return -ENOMEM;
+ }
+ driver_info = (struct gve_driver_info *)driver_info_mem->addr;
+
+ *driver_info = (struct gve_driver_info) {
+ .os_type = 5, /* DPDK */
+ .driver_major = GVE_VERSION_MAJOR,
+ .driver_minor = GVE_VERSION_MINOR,
+ .driver_sub = GVE_VERSION_SUB,
+ .os_version_major = cpu_to_be32(DPDK_VERSION_MAJOR),
+ .os_version_minor = cpu_to_be32(DPDK_VERSION_MINOR),
+ .os_version_sub = cpu_to_be32(DPDK_VERSION_SUB),
+ .driver_capability_flags = {
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS1),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS2),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS3),
+ cpu_to_be64(GVE_DRIVER_CAPABILITY_FLAGS4),
+ },
+ };
+
+ populate_driver_version_strings((char *)driver_info->os_version_str1,
+ (char *)driver_info->os_version_str2);
+
+ err = gve_adminq_verify_driver_compatibility(priv,
+ sizeof(struct gve_driver_info), (dma_addr_t)driver_info);
+ /* It's ok if the device doesn't support this */
+ if (err == -EOPNOTSUPP)
+ err = 0;
+
+ rte_memzone_free(driver_info_mem);
+ return err;
+}
+
static int
gve_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
{
@@ -679,6 +719,11 @@ gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
PMD_DRV_LOG(ERR, "Failed to alloc admin queue: err=%d", err);
return err;
}
+ err = gve_verify_driver_compatibility(priv);
+ if (err) {
+ PMD_DRV_LOG(ERR, "Could not verify driver compatibility: err=%d", err);
+ goto free_adminq;
+ }
if (skip_describe_device)
goto setup_device;
diff --git a/drivers/net/gve/gve_ethdev.h b/drivers/net/gve/gve_ethdev.h
index cd62debd22..c9bcfa553c 100644
--- a/drivers/net/gve/gve_ethdev.h
+++ b/drivers/net/gve/gve_ethdev.h
@@ -268,7 +268,7 @@ struct gve_priv {
uint32_t adminq_report_stats_cnt;
uint32_t adminq_report_link_speed_cnt;
uint32_t adminq_get_ptype_map_cnt;
-
+ uint32_t adminq_verify_driver_compatibility_cnt;
volatile uint32_t state_flags;
/* Gvnic device link speed from hypervisor. */
diff --git a/drivers/net/gve/gve_version.c b/drivers/net/gve/gve_version.c
new file mode 100644
index 0000000000..5fe34dc179
--- /dev/null
+++ b/drivers/net/gve/gve_version.c
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+#include "gve_version.h"
+
+const char *gve_version_string(void)
+{
+ static char gve_version[20];
+ snprintf(gve_version, sizeof(gve_version), "%s%d.%d.%d",
+ GVE_VERSION_PREFIX, GVE_VERSION_MAJOR, GVE_VERSION_MINOR,
+ GVE_VERSION_SUB);
+ return gve_version;
+}
diff --git a/drivers/net/gve/gve_version.h b/drivers/net/gve/gve_version.h
new file mode 100644
index 0000000000..4dd998dca1
--- /dev/null
+++ b/drivers/net/gve/gve_version.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) 2015-2023 Google, Inc.
+ */
+
+#ifndef _GVE_VERSION_H_
+#define _GVE_VERSION_H_
+
+#include <rte_version.h>
+
+#define GVE_VERSION_PREFIX "DPDK-"
+#define GVE_VERSION_MAJOR 1
+#define GVE_VERSION_MINOR 0
+#define GVE_VERSION_SUB 0
+
+#define DPDK_VERSION_MAJOR (100 * RTE_VER_YEAR + RTE_VER_MONTH)
+#define DPDK_VERSION_MINOR RTE_VER_MINOR
+#define DPDK_VERSION_SUB RTE_VER_RELEASE
+
+
+const char *
+gve_version_string(void);
+
+
+#endif /* GVE_VERSION_H */
diff --git a/drivers/net/gve/meson.build b/drivers/net/gve/meson.build
index c9d87903f9..61d195009c 100644
--- a/drivers/net/gve/meson.build
+++ b/drivers/net/gve/meson.build
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(C) 2022 Intel Corporation
-if is_windows
+if not is_linux
build = false
- reason = 'not supported on Windows'
+ reason = 'only supported on Linux'
subdir_done()
endif
@@ -14,5 +14,6 @@ sources = files(
'gve_rx_dqo.c',
'gve_tx_dqo.c',
'gve_ethdev.c',
+ 'gve_version.c',
)
includes += include_directories('base')
--
2.41.0.rc0.172.g3f132b7071-goog
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v4] net/gve: check driver compatibility
2023-05-23 10:21 ` Ferruh Yigit
@ 2023-05-24 17:14 ` Rushil Gupta
2023-05-31 16:40 ` Rushil Gupta
0 siblings, 1 reply; 32+ messages in thread
From: Rushil Gupta @ 2023-05-24 17:14 UTC (permalink / raw)
To: Ferruh Yigit
Cc: qi.z.zhang, jingjing.wu, junfeng.guo, joshwash, dev, Jeroen de Borst
As noted from spec: "Some commands require an additional dma memory
region to be passed to the device"
We are passing virtual addresses to devices (please look at link-speed
and describe-device adminq commands):
describe device:
https://github.com/DPDK/dpdk/blob/main/drivers/net/gve/base/gve_adminq.c#L704
link-speed: https://github.com/DPDK/dpdk/blob/main/drivers/net/gve/base/gve_adminq.c#L869
These adminq commands rely on gve_dma_alloc which presents mz->addr
and not iova as memory region:
https://github.com/DPDK/dpdk/blob/main/drivers/net/gve/base/gve_osdep.h#L139
Here is the new patch:
http://patchwork.dpdk.org/project/dpdk/patch/20230524171324.2072742-1-rushilg@google.com/
On Tue, May 23, 2023 at 3:22 AM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
>
> On 5/19/2023 9:46 PM, Rushil Gupta wrote:
> > diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
> > index abf3d379ae..5e8ae1eac6 100644
> > --- a/drivers/net/gve/base/gve_osdep.h
> > +++ b/drivers/net/gve/base/gve_osdep.h
> > @@ -21,9 +21,14 @@
> > #include <rte_malloc.h>
> > #include <rte_memcpy.h>
> > #include <rte_memzone.h>
> > +#include <rte_version.h>
> >
> > #include "../gve_logs.h"
> >
> > +#ifdef __linux__
> > +#include <sys/utsname.h>
> > +#endif
> > +
>
> Can you please use 'RTE_EXEC_ENV_LINUX' macro instead of '__linux__'?
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v4] net/gve: check driver compatibility
2023-05-24 17:14 ` Rushil Gupta
@ 2023-05-31 16:40 ` Rushil Gupta
0 siblings, 0 replies; 32+ messages in thread
From: Rushil Gupta @ 2023-05-31 16:40 UTC (permalink / raw)
To: Ferruh Yigit
Cc: qi.z.zhang, jingjing.wu, junfeng.guo, joshwash, dev, Jeroen de Borst
http://patchwork.dpdk.org/project/dpdk/patch/20230524171324.2072742-1-rushilg@google.com/
Does this look good to you?
On Wed, May 24, 2023 at 10:14 AM Rushil Gupta <rushilg@google.com> wrote:
>
> As noted from spec: "Some commands require an additional dma memory
> region to be passed to the device"
> We are passing virtual addresses to devices (please look at link-speed
> and describe-device adminq commands):
> describe device:
> https://github.com/DPDK/dpdk/blob/main/drivers/net/gve/base/gve_adminq.c#L704
> link-speed: https://github.com/DPDK/dpdk/blob/main/drivers/net/gve/base/gve_adminq.c#L869
>
> These adminq commands rely on gve_dma_alloc which presents mz->addr
> and not iova as memory region:
> https://github.com/DPDK/dpdk/blob/main/drivers/net/gve/base/gve_osdep.h#L139
>
> Here is the new patch:
> http://patchwork.dpdk.org/project/dpdk/patch/20230524171324.2072742-1-rushilg@google.com/
>
>
>
> On Tue, May 23, 2023 at 3:22 AM Ferruh Yigit <ferruh.yigit@amd.com> wrote:
> >
> > On 5/19/2023 9:46 PM, Rushil Gupta wrote:
> > > diff --git a/drivers/net/gve/base/gve_osdep.h b/drivers/net/gve/base/gve_osdep.h
> > > index abf3d379ae..5e8ae1eac6 100644
> > > --- a/drivers/net/gve/base/gve_osdep.h
> > > +++ b/drivers/net/gve/base/gve_osdep.h
> > > @@ -21,9 +21,14 @@
> > > #include <rte_malloc.h>
> > > #include <rte_memcpy.h>
> > > #include <rte_memzone.h>
> > > +#include <rte_version.h>
> > >
> > > #include "../gve_logs.h"
> > >
> > > +#ifdef __linux__
> > > +#include <sys/utsname.h>
> > > +#endif
> > > +
> >
> > Can you please use 'RTE_EXEC_ENV_LINUX' macro instead of '__linux__'?
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [v5] net/gve: check driver compatibility
2023-05-24 17:13 ` [v5] " Rushil Gupta
@ 2023-05-31 17:04 ` Ferruh Yigit
0 siblings, 0 replies; 32+ messages in thread
From: Ferruh Yigit @ 2023-05-31 17:04 UTC (permalink / raw)
To: Rushil Gupta, qi.z.zhang, jingjing.wu
Cc: junfeng.guo, joshwash, dev, Jeroen de Borst
On 5/24/2023 6:13 PM, Rushil Gupta wrote:
> Change gve_driver_info fields to report DPDK as OS type and DPDK RTE
> version as OS version, reserving driver_version fields for GVE driver
> version based on features.
>
> Signed-off-by: Rushil Gupta <rushilg@google.com>
> Signed-off-by: Joshua Washington <joshwash@google.com>
> Signed-off-by: Junfeng Guo <junfeng.guo@intel.com>
>
Reviewed-by: Ferruh Yigit <ferruh.yigit@amd.com>
Applied to dpdk-next-net/main, thanks.
^ permalink raw reply [flat|nested] 32+ messages in thread
end of thread, other threads:[~2023-05-31 17:05 UTC | newest]
Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-14 5:14 [PATCH] net/gve: Check whether the driver is compatible with the device presented Rushil Gupta
2023-04-14 9:05 ` Guo, Junfeng
2023-04-14 15:40 ` Ferruh Yigit
2023-04-18 5:30 ` Guo, Junfeng
2023-04-26 21:37 ` Rushil Gupta
2023-05-04 15:06 ` Ferruh Yigit
2023-05-08 6:23 ` Rushil Gupta
2023-05-08 16:00 ` Ferruh Yigit
2023-05-08 19:22 ` Rushil Gupta
2023-05-08 19:15 ` [v2] net/gve: check driver compatibility Rushil Gupta
2023-05-17 16:58 ` Ferruh Yigit
2023-05-18 17:41 ` Rushil Gupta
2023-05-19 7:15 ` [v3] " Rushil Gupta
2023-05-19 7:23 ` [PATCH] " Rushil Gupta
2023-05-19 7:26 ` Rushil Gupta
2023-05-19 7:41 ` Rushil Gupta
2023-05-19 10:04 ` Ferruh Yigit
2023-05-19 16:15 ` Rushil Gupta
2023-05-19 19:54 ` [v4] " Rushil Gupta
2023-05-19 20:46 ` Rushil Gupta
2023-05-19 20:56 ` Stephen Hemminger
2023-05-20 16:44 ` Rushil Gupta
2023-05-22 8:52 ` Ferruh Yigit
2023-05-22 15:45 ` Rushil Gupta
2023-05-23 10:20 ` Ferruh Yigit
2023-05-23 10:21 ` Ferruh Yigit
2023-05-24 17:14 ` Rushil Gupta
2023-05-31 16:40 ` Rushil Gupta
2023-05-24 17:13 ` [v5] " Rushil Gupta
2023-05-31 17:04 ` Ferruh Yigit
2023-05-18 17:40 ` [v3] " Rushil Gupta
2023-05-08 19:14 ` [v2] " Rushil Gupta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).