File Index
Files and directories
Sign in
FILE

devlink.c

File preview with syntax highlighting.

linux-6.19.14/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c C
 1// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
 2/* Copyright (c) 2020, Mellanox Technologies inc.  All rights reserved. */
 3
 4#include "en/devlink.h"
 5#include "eswitch.h"
 6
 7static const struct devlink_ops mlx5e_devlink_ops = {
 8};
 9
10struct mlx5e_dev *mlx5e_create_devlink(struct device *dev,
11				       struct mlx5_core_dev *mdev)
12{
13	struct mlx5e_dev *mlx5e_dev;
14	struct devlink *devlink;
15	int err;
16
17	devlink = devlink_alloc_ns(&mlx5e_devlink_ops, sizeof(*mlx5e_dev),
18				   devlink_net(priv_to_devlink(mdev)), dev);
19	if (!devlink)
20		return ERR_PTR(-ENOMEM);
21
22	err = devl_nested_devlink_set(priv_to_devlink(mdev), devlink);
23	if (err) {
24		devlink_free(devlink);
25		return ERR_PTR(err);
26	}
27
28	devlink_register(devlink);
29	return devlink_priv(devlink);
30}
31
32void mlx5e_destroy_devlink(struct mlx5e_dev *mlx5e_dev)
33{
34	struct devlink *devlink = priv_to_devlink(mlx5e_dev);
35
36	devlink_unregister(devlink);
37	devlink_free(devlink);
38}
39
40static void
41mlx5e_devlink_get_port_parent_id(struct mlx5_core_dev *dev, struct netdev_phys_item_id *ppid)
42{
43	BUILD_BUG_ON(MLX5_SW_IMAGE_GUID_MAX_BYTES > MAX_PHYS_ITEM_ID_LEN);
44	mlx5_query_nic_sw_system_image_guid(dev, ppid->id, &ppid->id_len);
45}
46
47int mlx5e_devlink_port_register(struct mlx5e_dev *mlx5e_dev,
48				struct mlx5_core_dev *mdev)
49{
50	struct devlink *devlink = priv_to_devlink(mlx5e_dev);
51	struct devlink_port_attrs attrs = {};
52	struct netdev_phys_item_id ppid = {};
53	unsigned int dl_port_index;
54
55	if (mlx5_core_is_pf(mdev)) {
56		attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL;
57		attrs.phys.port_number = mlx5_get_dev_index(mdev);
58		if (MLX5_ESWITCH_MANAGER(mdev)) {
59			mlx5e_devlink_get_port_parent_id(mdev, &ppid);
60			memcpy(attrs.switch_id.id, ppid.id, ppid.id_len);
61			attrs.switch_id.id_len = ppid.id_len;
62		}
63		dl_port_index = mlx5_esw_vport_to_devlink_port_index(mdev,
64								     MLX5_VPORT_UPLINK);
65	} else {
66		attrs.flavour = DEVLINK_PORT_FLAVOUR_VIRTUAL;
67		dl_port_index = mlx5_esw_vport_to_devlink_port_index(mdev, 0);
68	}
69
70	devlink_port_attrs_set(&mlx5e_dev->dl_port, &attrs);
71
72	return devlink_port_register(devlink, &mlx5e_dev->dl_port,
73				     dl_port_index);
74}
75
76void mlx5e_devlink_port_unregister(struct mlx5e_dev *mlx5e_dev)
77{
78	devlink_port_unregister(&mlx5e_dev->dl_port);
79}
~/ Read-only file preview.