From: Wenjun Wu <wenjun1.wu@intel.com>
To: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org
Cc: xuejun.zhang@intel.com, madhu.chittim@intel.com,
qi.z.zhang@intel.com, anthony.l.nguyen@intel.com
Subject: [PATCH iwl-next v2 3/5] iavf: Add devlink and devlink port support
Date: Tue, 8 Aug 2023 09:57:32 +0800 [thread overview]
Message-ID: <20230808015734.1060525-4-wenjun1.wu@intel.com> (raw)
In-Reply-To: <20230808015734.1060525-1-wenjun1.wu@intel.com>
From: Jun Zhang <xuejun.zhang@intel.com>
To allow user to configure queue bandwidth, devlink port support
is added to support devlink port rate API.
Add devlink framework registration/unregistration on iavf driver
initialization and remove, and devlink port of DEVLINK_PORT_FLAVOUR_VIRTUAL
is created to be associated iavf net device.
Signed-off-by: Jun Zhang <xuejun.zhang@intel.com>
---
drivers/net/ethernet/intel/Kconfig | 1 +
drivers/net/ethernet/intel/iavf/Makefile | 2 +-
drivers/net/ethernet/intel/iavf/iavf.h | 6 ++
.../net/ethernet/intel/iavf/iavf_devlink.c | 93 +++++++++++++++++++
.../net/ethernet/intel/iavf/iavf_devlink.h | 17 ++++
drivers/net/ethernet/intel/iavf/iavf_main.c | 14 +++
6 files changed, 132 insertions(+), 1 deletion(-)
create mode 100644 drivers/net/ethernet/intel/iavf/iavf_devlink.c
create mode 100644 drivers/net/ethernet/intel/iavf/iavf_devlink.h
diff --git a/drivers/net/ethernet/intel/Kconfig b/drivers/net/ethernet/intel/Kconfig
index 9bc0a9519899..f916b8ef6acb 100644
--- a/drivers/net/ethernet/intel/Kconfig
+++ b/drivers/net/ethernet/intel/Kconfig
@@ -256,6 +256,7 @@ config I40EVF
tristate "Intel(R) Ethernet Adaptive Virtual Function support"
select IAVF
depends on PCI_MSI
+ select NET_DEVLINK
help
This driver supports virtual functions for Intel XL710,
X710, X722, XXV710, and all devices advertising support for
diff --git a/drivers/net/ethernet/intel/iavf/Makefile b/drivers/net/ethernet/intel/iavf/Makefile
index 9c3e45c54d01..b5d7db97ab8b 100644
--- a/drivers/net/ethernet/intel/iavf/Makefile
+++ b/drivers/net/ethernet/intel/iavf/Makefile
@@ -12,5 +12,5 @@ subdir-ccflags-y += -I$(src)
obj-$(CONFIG_IAVF) += iavf.o
iavf-objs := iavf_main.o iavf_ethtool.o iavf_virtchnl.o iavf_fdir.o \
- iavf_adv_rss.o \
+ iavf_adv_rss.o iavf_devlink.o \
iavf_txrx.o iavf_common.o iavf_adminq.o iavf_client.o
diff --git a/drivers/net/ethernet/intel/iavf/iavf.h b/drivers/net/ethernet/intel/iavf/iavf.h
index 8cbdebc5b698..519aeaec793c 100644
--- a/drivers/net/ethernet/intel/iavf/iavf.h
+++ b/drivers/net/ethernet/intel/iavf/iavf.h
@@ -33,9 +33,11 @@
#include <net/udp.h>
#include <net/tc_act/tc_gact.h>
#include <net/tc_act/tc_mirred.h>
+#include <net/devlink.h>
#include "iavf_type.h"
#include <linux/avf/virtchnl.h>
+#include "iavf_devlink.h"
#include "iavf_txrx.h"
#include "iavf_fdir.h"
#include "iavf_adv_rss.h"
@@ -369,6 +371,10 @@ struct iavf_adapter {
struct net_device *netdev;
struct pci_dev *pdev;
+ /* devlink & port data */
+ struct devlink *devlink;
+ struct devlink_port devlink_port;
+
struct iavf_hw hw; /* defined in iavf_type.h */
enum iavf_state_t state;
diff --git a/drivers/net/ethernet/intel/iavf/iavf_devlink.c b/drivers/net/ethernet/intel/iavf/iavf_devlink.c
new file mode 100644
index 000000000000..991d041e5922
--- /dev/null
+++ b/drivers/net/ethernet/intel/iavf/iavf_devlink.c
@@ -0,0 +1,93 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2023 Intel Corporation */
+
+#include "iavf.h"
+#include "iavf_devlink.h"
+
+static const struct devlink_ops iavf_devlink_ops = {};
+
+/**
+ * iavf_devlink_register - Register allocated devlink instance for iavf adapter
+ * @adapter: the iavf adapter to register the devlink for.
+ *
+ * Register the devlink instance associated with this iavf adapter
+ *
+ * Return: zero on success or an error code on failure.
+ */
+int iavf_devlink_register(struct iavf_adapter *adapter)
+{
+ struct device *dev = &adapter->pdev->dev;
+ struct iavf_devlink *ref;
+ struct devlink *devlink;
+
+ /* Allocate devlink instance */
+ devlink = devlink_alloc(&iavf_devlink_ops, sizeof(struct iavf_devlink),
+ dev);
+ if (!devlink)
+ return -ENOMEM;
+
+ /* Init iavf adapter devlink */
+ adapter->devlink = devlink;
+ ref = devlink_priv(devlink);
+ ref->devlink_ref = adapter;
+
+ devlink_register(devlink);
+
+ return 0;
+}
+
+/**
+ * iavf_devlink_unregister - Unregister devlink resources for iavf adapter.
+ * @adapter: the iavf adapter structure
+ *
+ * Releases resources used by devlink and cleans up associated memory.
+ */
+void iavf_devlink_unregister(struct iavf_adapter *adapter)
+{
+ devlink_unregister(adapter->devlink);
+ devlink_free(adapter->devlink);
+}
+
+/**
+ * iavf_devlink_port_register - Register devlink port for iavf adapter
+ * @adapter: the iavf adapter to register the devlink port for.
+ *
+ * Register the devlink port instance associated with this iavf adapter
+ * before iavf adapter registers with netdevice
+ *
+ * Return: zero on success or an error code on failure.
+ */
+int iavf_devlink_port_register(struct iavf_adapter *adapter)
+{
+ struct device *dev = &adapter->pdev->dev;
+ struct devlink_port_attrs attrs = {};
+ int err;
+
+ /* Create devlink port: attr/port flavour, port index */
+ SET_NETDEV_DEVLINK_PORT(adapter->netdev, &adapter->devlink_port);
+ attrs.flavour = DEVLINK_PORT_FLAVOUR_VIRTUAL;
+ memset(&adapter->devlink_port, 0, sizeof(adapter->devlink_port));
+ devlink_port_attrs_set(&adapter->devlink_port, &attrs);
+
+ /* Register with driver specific index (device id) */
+ err = devlink_port_register(adapter->devlink, &adapter->devlink_port,
+ adapter->hw.bus.device);
+ if (err)
+ dev_err(dev, "devlink port registration failed: %d\n", err);
+
+ return err;
+}
+
+/**
+ * iavf_devlink_port_unregister - Unregister devlink port for iavf adapter.
+ * @adapter: the iavf adapter structure
+ *
+ * Releases resources used by devlink port and registration with devlink.
+ */
+void iavf_devlink_port_unregister(struct iavf_adapter *adapter)
+{
+ if (!adapter->devlink_port.registered)
+ return;
+
+ devlink_port_unregister(&adapter->devlink_port);
+}
diff --git a/drivers/net/ethernet/intel/iavf/iavf_devlink.h b/drivers/net/ethernet/intel/iavf/iavf_devlink.h
new file mode 100644
index 000000000000..5c122278611a
--- /dev/null
+++ b/drivers/net/ethernet/intel/iavf/iavf_devlink.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/* Copyright (C) 2023 Intel Corporation */
+
+#ifndef _IAVF_DEVLINK_H_
+#define _IAVF_DEVLINK_H_
+
+/* iavf devlink structure pointing to iavf adapter */
+struct iavf_devlink {
+ struct iavf_adapter *devlink_ref; /* ref to iavf adapter */
+};
+
+int iavf_devlink_register(struct iavf_adapter *adapter);
+void iavf_devlink_unregister(struct iavf_adapter *adapter);
+int iavf_devlink_port_register(struct iavf_adapter *adapter);
+void iavf_devlink_port_unregister(struct iavf_adapter *adapter);
+
+#endif /* _IAVF_DEVLINK_H_ */
diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index 7b300c86ceda..db010e68d5d2 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -2037,6 +2037,7 @@ static void iavf_finish_config(struct work_struct *work)
iavf_free_rss(adapter);
iavf_free_misc_irq(adapter);
iavf_reset_interrupt_capability(adapter);
+ iavf_devlink_port_unregister(adapter);
iavf_change_state(adapter,
__IAVF_INIT_CONFIG_ADAPTER);
goto out;
@@ -2708,6 +2709,9 @@ static void iavf_init_config_adapter(struct iavf_adapter *adapter)
if (err)
goto err_sw_init;
+ if (!adapter->netdev_registered)
+ iavf_devlink_port_register(adapter);
+
netif_carrier_off(netdev);
adapter->link_up = false;
netif_tx_stop_all_queues(netdev);
@@ -2749,6 +2753,7 @@ static void iavf_init_config_adapter(struct iavf_adapter *adapter)
err_mem:
iavf_free_rss(adapter);
iavf_free_misc_irq(adapter);
+ iavf_devlink_port_unregister(adapter);
err_sw_init:
iavf_reset_interrupt_capability(adapter);
err:
@@ -4995,6 +5000,12 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
/* Setup the wait queue for indicating virtchannel events */
init_waitqueue_head(&adapter->vc_waitqueue);
+ /* Register iavf adapter with devlink */
+ err = iavf_devlink_register(adapter);
+ if (err)
+ dev_err(&pdev->dev, "devlink registration failed: %d\n", err);
+
+ /* Keep driver interface even on devlink registration failure */
return 0;
err_ioremap:
@@ -5139,6 +5150,9 @@ static void iavf_remove(struct pci_dev *pdev)
err);
}
+ iavf_devlink_port_unregister(adapter);
+ iavf_devlink_unregister(adapter);
+
mutex_lock(&adapter->crit_lock);
dev_info(&adapter->pdev->dev, "Removing device\n");
iavf_change_state(adapter, __IAVF_REMOVE);
--
2.34.1
next prev parent reply other threads:[~2023-08-08 1:54 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230727021021.961119-1-wenjun1.wu@intel.com>
2023-08-08 1:57 ` [PATCH iwl-next v2 0/5] iavf: Add devlink and devlink rate support Wenjun Wu
2023-08-08 1:57 ` [PATCH iwl-next v2 1/5] virtchnl: support queue rate limit and quanta size configuration Wenjun Wu
2023-08-08 1:57 ` [PATCH iwl-next v2 2/5] ice: Support VF " Wenjun Wu
2023-08-16 16:54 ` Brett Creeley
2023-08-08 1:57 ` Wenjun Wu [this message]
2023-08-16 17:11 ` [PATCH iwl-next v2 3/5] iavf: Add devlink and devlink port support Brett Creeley
2023-08-08 1:57 ` [PATCH iwl-next v2 4/5] iavf: Add devlink port function rate API support Wenjun Wu
2023-08-08 20:49 ` Simon Horman
2023-08-09 18:43 ` Zhang, Xuejun
2023-08-16 17:27 ` Brett Creeley
2023-08-08 1:57 ` [PATCH iwl-next v2 5/5] iavf: Add VIRTCHNL Opcodes Support for Queue bw Setting Wenjun Wu
2023-08-08 20:54 ` Simon Horman
2023-08-09 18:44 ` Zhang, Xuejun
2023-08-16 17:32 ` Brett Creeley
2023-08-16 3:33 ` [PATCH iwl-next v3 0/5] iavf: Add devlink and devlink rate support Wenjun Wu
2023-08-16 3:33 ` [PATCH iwl-next v3 1/5] virtchnl: support queue rate limit and quanta size configuration Wenjun Wu
2023-08-16 3:33 ` [PATCH iwl-next v3 2/5] ice: Support VF " Wenjun Wu
2023-08-16 3:33 ` [PATCH iwl-next v3 3/5] iavf: Add devlink and devlink port support Wenjun Wu
2023-08-16 3:33 ` [PATCH iwl-next v3 4/5] iavf: Add devlink port function rate API support Wenjun Wu
2023-08-16 3:33 ` [PATCH iwl-next v3 5/5] iavf: Add VIRTCHNL Opcodes Support for Queue bw Setting Wenjun Wu
2023-08-16 9:14 ` Simon Horman
2023-08-22 3:39 ` [PATCH iwl-next v4 0/5] iavf: Add devlink and devlink rate support Wenjun Wu
2023-08-22 3:39 ` [PATCH iwl-next v4 1/5] virtchnl: support queue rate limit and quanta size configuration Wenjun Wu
2023-08-22 3:40 ` [PATCH iwl-next v4 2/5] ice: Support VF " Wenjun Wu
2023-08-22 3:40 ` [PATCH iwl-next v4 3/5] iavf: Add devlink and devlink port support Wenjun Wu
2023-08-22 3:40 ` [PATCH iwl-next v4 4/5] iavf: Add devlink port function rate API support Wenjun Wu
2023-08-22 3:40 ` [PATCH iwl-next v4 5/5] iavf: Add VIRTCHNL Opcodes Support for Queue bw Setting Wenjun Wu
2023-08-22 6:12 ` [PATCH iwl-next v4 0/5] iavf: Add devlink and devlink rate support Jiri Pirko
2023-08-22 15:12 ` Jakub Kicinski
2023-08-22 15:34 ` [PATCH iwl-next v4 0/5] iavf: Add devlink and devlink rate support' Jiri Pirko
2023-08-23 21:39 ` Zhang, Xuejun
[not found] ` <0893327b-1c84-7c25-d10c-1cc93595825a@intel.com>
2023-08-24 7:04 ` Jiri Pirko
2023-08-28 22:46 ` Zhang, Xuejun
2023-11-17 5:52 ` [Intel-wired-lan] " Zhang, Xuejun
2023-11-17 11:21 ` Jiri Pirko
2023-11-21 9:04 ` Paolo Abeni
2023-11-18 16:48 ` Jakub Kicinski
2023-11-22 22:19 ` Zhang, Xuejun
2023-11-23 3:22 ` Jakub Kicinski
2023-11-28 0:15 ` Zhang, Xuejun
2023-11-28 1:43 ` Jakub Kicinski
2023-12-14 20:29 ` Paolo Abeni
2023-12-15 1:46 ` Jakub Kicinski
2023-12-15 11:06 ` Paolo Abeni
2023-12-15 11:47 ` Paolo Abeni
2023-12-15 12:30 ` Jiri Pirko
2023-12-15 22:41 ` Jakub Kicinski
2023-12-18 20:12 ` Paolo Abeni
2023-12-18 21:33 ` Jakub Kicinski
2023-12-15 12:22 ` Jiri Pirko
2023-10-18 9:05 ` Paolo Abeni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230808015734.1060525-4-wenjun1.wu@intel.com \
--to=wenjun1.wu@intel.com \
--cc=anthony.l.nguyen@intel.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=madhu.chittim@intel.com \
--cc=netdev@vger.kernel.org \
--cc=qi.z.zhang@intel.com \
--cc=xuejun.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).