[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <5DD6E0A4F173D3D3+20240804124841.71177-9-mengyuanlou@net-swift.com>
Date: Sun, 4 Aug 2024 20:48:39 +0800
From: Mengyuan Lou <mengyuanlou@...-swift.com>
To: netdev@...r.kernel.org
Cc: Mengyuan Lou <mengyuanlou@...-swift.com>
Subject: [PATCH net-next v5 08/10] net: libwx: add eswitch switch api for devlink ops
Signed-off-by: Mengyuan Lou <mengyuanlou@...-swift.com>
---
drivers/net/ethernet/wangxun/libwx/Makefile | 3 +-
.../net/ethernet/wangxun/libwx/wx_devlink.c | 3 ++
.../net/ethernet/wangxun/libwx/wx_eswitch.c | 53 +++++++++++++++++++
.../net/ethernet/wangxun/libwx/wx_eswitch.h | 13 +++++
drivers/net/ethernet/wangxun/libwx/wx_type.h | 1 +
5 files changed, 72 insertions(+), 1 deletion(-)
create mode 100644 drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
create mode 100644 drivers/net/ethernet/wangxun/libwx/wx_eswitch.h
diff --git a/drivers/net/ethernet/wangxun/libwx/Makefile b/drivers/net/ethernet/wangxun/libwx/Makefile
index 643a5e947ba9..a7065ad924d1 100644
--- a/drivers/net/ethernet/wangxun/libwx/Makefile
+++ b/drivers/net/ethernet/wangxun/libwx/Makefile
@@ -4,4 +4,5 @@
obj-$(CONFIG_LIBWX) += libwx.o
-libwx-objs := wx_hw.o wx_lib.o wx_ethtool.o wx_mbx.o wx_sriov.o wx_devlink.o
+libwx-objs := wx_hw.o wx_lib.o wx_ethtool.o wx_mbx.o wx_sriov.o wx_devlink.o \
+ wx_eswitch.o
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_devlink.c b/drivers/net/ethernet/wangxun/libwx/wx_devlink.c
index b39da37c0842..f37362af1449 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_devlink.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_devlink.c
@@ -6,9 +6,12 @@
#include "wx_type.h"
#include "wx_sriov.h"
+#include "wx_eswitch.h"
#include "wx_devlink.h"
static const struct devlink_ops wx_pf_devlink_ops = {
+ .eswitch_mode_get = wx_eswitch_mode_get,
+ .eswitch_mode_set = wx_eswitch_mode_set,
};
static void wx_devlink_free(void *devlink_ptr)
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
new file mode 100644
index 000000000000..a426a352bf96
--- /dev/null
+++ b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2019-2021, Intel Corporation. */
+
+#include <linux/pci.h>
+
+#include "wx_type.h"
+#include "wx_eswitch.h"
+#include "wx_devlink.h"
+
+int wx_eswitch_mode_set(struct devlink *devlink, u16 mode,
+ struct netlink_ext_ack *extack)
+{
+ struct wx_dl_priv *dl_priv = devlink_priv(devlink);
+ struct wx *wx = dl_priv->priv_wx;
+
+ if (wx->eswitch_mode == mode)
+ return 0;
+
+ if (wx->num_vfs) {
+ dev_info(&(wx)->pdev->dev,
+ "Change eswitch mode is allowed if there is no VFs.");
+ return -EOPNOTSUPP;
+ }
+
+ switch (mode) {
+ case DEVLINK_ESWITCH_MODE_LEGACY:
+ dev_info(&(wx)->pdev->dev,
+ "PF%d changed eswitch mode to legacy",
+ wx->bus.func);
+ NL_SET_ERR_MSG_MOD(extack, "Changed eswitch mode to legacy");
+ break;
+ case DEVLINK_ESWITCH_MODE_SWITCHDEV:
+ dev_info(&(wx)->pdev->dev,
+ "Do not support switchdev in eswitch mode.");
+ NL_SET_ERR_MSG_MOD(extack, "Do not support switchdev mode.");
+ return -EINVAL;
+ default:
+ NL_SET_ERR_MSG_MOD(extack, "Unknown eswitch mode");
+ return -EINVAL;
+ }
+
+ wx->eswitch_mode = mode;
+ return 0;
+}
+
+int wx_eswitch_mode_get(struct devlink *devlink, u16 *mode)
+{
+ struct wx_dl_priv *dl_priv = devlink_priv(devlink);
+ struct wx *wx = dl_priv->priv_wx;
+
+ *mode = wx->eswitch_mode;
+ return 0;
+}
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_eswitch.h b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.h
new file mode 100644
index 000000000000..0323931e7df1
--- /dev/null
+++ b/drivers/net/ethernet/wangxun/libwx/wx_eswitch.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2019-2021, Intel Corporation. */
+
+#ifndef _WX_ESWITCH_H_
+#define _WX_ESWITCH_H_
+
+#include <net/devlink.h>
+
+int wx_eswitch_mode_get(struct devlink *devlink, u16 *mode);
+int wx_eswitch_mode_set(struct devlink *devlink, u16 mode,
+ struct netlink_ext_ack *extack);
+
+#endif /* _WX_ESWITCH_H_ */
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_type.h b/drivers/net/ethernet/wangxun/libwx/wx_type.h
index a8722f69cebb..a3e103e0c365 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_type.h
+++ b/drivers/net/ethernet/wangxun/libwx/wx_type.h
@@ -1141,6 +1141,7 @@ struct wx {
/* devlink port data */
struct devlink_port devlink_port;
struct wx_dl_priv *dl_priv;
+ u16 eswitch_mode; /* current mode of eswitch */
struct wx_bus_info bus;
struct wx_mbx_info mbx;
--
2.45.2
Powered by blists - more mailing lists