From: Jimmy Assarsson <extja@kvaser.com>
To: linux-can@vger.kernel.org
Cc: Jimmy Assarsson <jimmyassarsson@gmail.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
netdev@vger.kernel.org
Subject: [PATCH v3 07/10] can: kvaser_pciefd: Add devlink support
Date: Thu, 24 Jul 2025 09:30:18 +0200 [thread overview]
Message-ID: <20250724073021.8-8-extja@kvaser.com> (raw)
In-Reply-To: <20250724073021.8-1-extja@kvaser.com>
Add devlink support at device level.
Example output:
$ devlink dev
pci/0000:07:00.0
pci/0000:08:00.0
pci/0000:09:00.0
$ devlink dev info
pci/0000:07:00.0:
driver kvaser_pciefd
pci/0000:08:00.0:
driver kvaser_pciefd
pci/0000:09:00.0:
driver kvaser_pciefd
Signed-off-by: Jimmy Assarsson <extja@kvaser.com>
---
Changes in v2:
- Add two space indentation to terminal output.
Suggested by Vincent Mailhol [1]
[1] https://lore.kernel.org/linux-can/20250723083236.9-1-extja@kvaser.com/T/#m31ee4aad13ee29d5559b56fdce842609ae4f67c5
drivers/net/can/Kconfig | 1 +
drivers/net/can/kvaser_pciefd/Makefile | 2 +-
drivers/net/can/kvaser_pciefd/kvaser_pciefd.h | 2 ++
.../net/can/kvaser_pciefd/kvaser_pciefd_core.c | 15 ++++++++++++---
.../net/can/kvaser_pciefd/kvaser_pciefd_devlink.c | 10 ++++++++++
5 files changed, 26 insertions(+), 4 deletions(-)
create mode 100644 drivers/net/can/kvaser_pciefd/kvaser_pciefd_devlink.c
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index cf989bea9aa3..b37d80bf7270 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -154,6 +154,7 @@ config CAN_JANZ_ICAN3
config CAN_KVASER_PCIEFD
depends on PCI
tristate "Kvaser PCIe FD cards"
+ select NET_DEVLINK
help
This is a driver for the Kvaser PCI Express CAN FD family.
diff --git a/drivers/net/can/kvaser_pciefd/Makefile b/drivers/net/can/kvaser_pciefd/Makefile
index ea1bf1000760..8c5b8cdc6b5f 100644
--- a/drivers/net/can/kvaser_pciefd/Makefile
+++ b/drivers/net/can/kvaser_pciefd/Makefile
@@ -1,3 +1,3 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_CAN_KVASER_PCIEFD) += kvaser_pciefd.o
-kvaser_pciefd-y = kvaser_pciefd_core.o
+kvaser_pciefd-y = kvaser_pciefd_core.o kvaser_pciefd_devlink.o
diff --git a/drivers/net/can/kvaser_pciefd/kvaser_pciefd.h b/drivers/net/can/kvaser_pciefd/kvaser_pciefd.h
index 55bb7e078340..34ba393d6093 100644
--- a/drivers/net/can/kvaser_pciefd/kvaser_pciefd.h
+++ b/drivers/net/can/kvaser_pciefd/kvaser_pciefd.h
@@ -13,6 +13,7 @@
#include <linux/spinlock.h>
#include <linux/timer.h>
#include <linux/types.h>
+#include <net/devlink.h>
#define KVASER_PCIEFD_MAX_CAN_CHANNELS 8UL
#define KVASER_PCIEFD_DMA_COUNT 2U
@@ -87,4 +88,5 @@ struct kvaser_pciefd {
struct kvaser_pciefd_fw_version fw_version;
};
+extern const struct devlink_ops kvaser_pciefd_devlink_ops;
#endif /* _KVASER_PCIEFD_H */
diff --git a/drivers/net/can/kvaser_pciefd/kvaser_pciefd_core.c b/drivers/net/can/kvaser_pciefd/kvaser_pciefd_core.c
index 97cbe07c4ee3..60c72ab0a5d8 100644
--- a/drivers/net/can/kvaser_pciefd/kvaser_pciefd_core.c
+++ b/drivers/net/can/kvaser_pciefd/kvaser_pciefd_core.c
@@ -1751,14 +1751,16 @@ static int kvaser_pciefd_probe(struct pci_dev *pdev,
const struct pci_device_id *id)
{
int ret;
+ struct devlink *devlink;
struct device *dev = &pdev->dev;
struct kvaser_pciefd *pcie;
const struct kvaser_pciefd_irq_mask *irq_mask;
- pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
- if (!pcie)
+ devlink = devlink_alloc(&kvaser_pciefd_devlink_ops, sizeof(*pcie), dev);
+ if (!devlink)
return -ENOMEM;
+ pcie = devlink_priv(devlink);
pci_set_drvdata(pdev, pcie);
pcie->pci = pdev;
pcie->driver_data = (const struct kvaser_pciefd_driver_data *)id->driver_data;
@@ -1766,7 +1768,7 @@ static int kvaser_pciefd_probe(struct pci_dev *pdev,
ret = pci_enable_device(pdev);
if (ret)
- return ret;
+ goto err_free_devlink;
ret = pci_request_regions(pdev, KVASER_PCIEFD_DRV_NAME);
if (ret)
@@ -1830,6 +1832,8 @@ static int kvaser_pciefd_probe(struct pci_dev *pdev,
if (ret)
goto err_free_irq;
+ devlink_register(devlink);
+
return 0;
err_free_irq:
@@ -1853,6 +1857,9 @@ static int kvaser_pciefd_probe(struct pci_dev *pdev,
err_disable_pci:
pci_disable_device(pdev);
+err_free_devlink:
+ devlink_free(devlink);
+
return ret;
}
@@ -1876,6 +1883,8 @@ static void kvaser_pciefd_remove(struct pci_dev *pdev)
for (i = 0; i < pcie->nr_channels; ++i)
free_candev(pcie->can[i]->can.dev);
+ devlink_unregister(priv_to_devlink(pcie));
+ devlink_free(priv_to_devlink(pcie));
pci_iounmap(pdev, pcie->reg_base);
pci_release_regions(pdev);
pci_disable_device(pdev);
diff --git a/drivers/net/can/kvaser_pciefd/kvaser_pciefd_devlink.c b/drivers/net/can/kvaser_pciefd/kvaser_pciefd_devlink.c
new file mode 100644
index 000000000000..8145d25943de
--- /dev/null
+++ b/drivers/net/can/kvaser_pciefd/kvaser_pciefd_devlink.c
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+/* kvaser_pciefd devlink functions
+ *
+ * Copyright (C) 2025 KVASER AB, Sweden. All rights reserved.
+ */
+
+#include <net/devlink.h>
+
+const struct devlink_ops kvaser_pciefd_devlink_ops = {
+};
--
2.49.0
next prev parent reply other threads:[~2025-07-24 7:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-24 7:30 [PATCH v3 00/10] can: kvaser_pciefd: Simplify identification of physical CAN interfaces Jimmy Assarsson
2025-07-24 7:30 ` [PATCH v3 01/10] can: kvaser_pciefd: Add support to control CAN LEDs on device Jimmy Assarsson
2025-07-24 7:30 ` [PATCH v3 02/10] can: kvaser_pciefd: Add support for ethtool set_phys_id() Jimmy Assarsson
2025-07-24 7:30 ` [PATCH v3 03/10] can: kvaser_pciefd: Add intermediate variable for device struct in probe() Jimmy Assarsson
2025-07-24 7:30 ` [PATCH v3 04/10] can: kvaser_pciefd: Store the different firmware version components in a struct Jimmy Assarsson
2025-07-24 7:30 ` [PATCH v3 05/10] can: kvaser_pciefd: Store device channel index Jimmy Assarsson
2025-07-24 7:30 ` [PATCH v3 06/10] can: kvaser_pciefd: Split driver into C-file and header-file Jimmy Assarsson
2025-07-24 7:30 ` Jimmy Assarsson [this message]
2025-07-24 7:30 ` [PATCH v3 08/10] can: kvaser_pciefd: Expose device firmware version via devlink info_get() Jimmy Assarsson
2025-07-24 13:52 ` Simon Horman
2025-07-25 12:39 ` Jimmy Assarsson
2025-07-24 7:30 ` [PATCH v3 09/10] can: kvaser_pciefd: Add devlink port support Jimmy Assarsson
2025-07-24 7:30 ` [PATCH v3 10/10] Documentation: devlink: add devlink documentation for the kvaser_pciefd driver Jimmy Assarsson
2025-07-24 11:10 ` [PATCH v3 00/10] can: kvaser_pciefd: Simplify identification of physical CAN interfaces Paolo Abeni
2025-07-25 3:05 ` Vincent Mailhol
2025-07-25 8:51 ` Marc Kleine-Budde
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=20250724073021.8-8-extja@kvaser.com \
--to=extja@kvaser.com \
--cc=jimmyassarsson@gmail.com \
--cc=linux-can@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.