@@ -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
@@ -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)
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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_ */
@@ -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;
Signed-off-by: Mengyuan Lou <mengyuanlou@net-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