mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Register each CAN channel of the device as an devlink physical port. This makes it easier to get device information for a given network interface (i.e. can2). Example output: $ devlink dev pci/0000:07:00.0 pci/0000:08:00.0 pci/0000:09:00.0 $ devlink port pci/0000:07:00.0/0: type eth netdev can0 flavour physical port 0 splittable false pci/0000:07:00.0/1: type eth netdev can1 flavour physical port 1 splittable false pci/0000:07:00.0/2: type eth netdev can2 flavour physical port 2 splittable false pci/0000:07:00.0/3: type eth netdev can3 flavour physical port 3 splittable false pci/0000:08:00.0/0: type eth netdev can4 flavour physical port 0 splittable false pci/0000:08:00.0/1: type eth netdev can5 flavour physical port 1 splittable false pci/0000:09:00.0/0: type eth netdev can6 flavour physical port 0 splittable false pci/0000:09:00.0/1: type eth netdev can7 flavour physical port 1 splittable false pci/0000:09:00.0/2: type eth netdev can8 flavour physical port 2 splittable false pci/0000:09:00.0/3: type eth netdev can9 flavour physical port 3 splittable false $ devlink port show can2 pci/0000:07:00.0/2: type eth netdev can2 flavour physical port 2 splittable false $ devlink dev info pci/0000:07:00.0: driver kvaser_pciefd versions: running: fw 1.3.75 pci/0000:08:00.0: driver kvaser_pciefd versions: running: fw 2.4.29 pci/0000:09:00.0: driver kvaser_pciefd versions: running: fw 1.3.72 $ sudo ethtool -i can2 driver: kvaser_pciefd version: 6.8.0-40-generic firmware-version: 1.3.75 expansion-rom-version: bus-info: 0000:07:00.0 supports-statistics: no supports-test: no supports-eeprom-access: no supports-register-dump: no supports-priv-flags: no Reviewed-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Jimmy Assarsson <extja@kvaser.com> Link: https://patch.msgid.link/20250725123230.8-10-extja@kvaser.com Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
|
|
/* kvaser_pciefd devlink functions
|
|
*
|
|
* Copyright (C) 2025 KVASER AB, Sweden. All rights reserved.
|
|
*/
|
|
#include "kvaser_pciefd.h"
|
|
|
|
#include <linux/netdevice.h>
|
|
#include <net/devlink.h>
|
|
|
|
static int kvaser_pciefd_devlink_info_get(struct devlink *devlink,
|
|
struct devlink_info_req *req,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct kvaser_pciefd *pcie = devlink_priv(devlink);
|
|
char buf[] = "xxx.xxx.xxxxx";
|
|
int ret;
|
|
|
|
if (pcie->fw_version.major) {
|
|
snprintf(buf, sizeof(buf), "%u.%u.%u",
|
|
pcie->fw_version.major,
|
|
pcie->fw_version.minor,
|
|
pcie->fw_version.build);
|
|
ret = devlink_info_version_running_put(req,
|
|
DEVLINK_INFO_VERSION_GENERIC_FW,
|
|
buf);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
const struct devlink_ops kvaser_pciefd_devlink_ops = {
|
|
.info_get = kvaser_pciefd_devlink_info_get,
|
|
};
|
|
|
|
int kvaser_pciefd_devlink_port_register(struct kvaser_pciefd_can *can)
|
|
{
|
|
int ret;
|
|
struct devlink_port_attrs attrs = {
|
|
.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL,
|
|
.phys.port_number = can->can.dev->dev_port,
|
|
};
|
|
devlink_port_attrs_set(&can->devlink_port, &attrs);
|
|
|
|
ret = devlink_port_register(priv_to_devlink(can->kv_pcie),
|
|
&can->devlink_port, can->can.dev->dev_port);
|
|
if (ret)
|
|
return ret;
|
|
|
|
SET_NETDEV_DEVLINK_PORT(can->can.dev, &can->devlink_port);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void kvaser_pciefd_devlink_port_unregister(struct kvaser_pciefd_can *can)
|
|
{
|
|
devlink_port_unregister(&can->devlink_port);
|
|
}
|