devlink.c (2017B)
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 void 8mlx5e_devlink_get_port_parent_id(struct mlx5_core_dev *dev, struct netdev_phys_item_id *ppid) 9{ 10 u64 parent_id; 11 12 parent_id = mlx5_query_nic_system_image_guid(dev); 13 ppid->id_len = sizeof(parent_id); 14 memcpy(ppid->id, &parent_id, sizeof(parent_id)); 15} 16 17int mlx5e_devlink_port_register(struct mlx5e_priv *priv) 18{ 19 struct devlink *devlink = priv_to_devlink(priv->mdev); 20 struct devlink_port_attrs attrs = {}; 21 struct netdev_phys_item_id ppid = {}; 22 struct devlink_port *dl_port; 23 unsigned int dl_port_index; 24 25 if (mlx5_core_is_pf(priv->mdev)) { 26 attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; 27 attrs.phys.port_number = mlx5_get_dev_index(priv->mdev); 28 if (MLX5_ESWITCH_MANAGER(priv->mdev)) { 29 mlx5e_devlink_get_port_parent_id(priv->mdev, &ppid); 30 memcpy(attrs.switch_id.id, ppid.id, ppid.id_len); 31 attrs.switch_id.id_len = ppid.id_len; 32 } 33 dl_port_index = mlx5_esw_vport_to_devlink_port_index(priv->mdev, 34 MLX5_VPORT_UPLINK); 35 } else { 36 attrs.flavour = DEVLINK_PORT_FLAVOUR_VIRTUAL; 37 dl_port_index = mlx5_esw_vport_to_devlink_port_index(priv->mdev, 0); 38 } 39 40 dl_port = mlx5e_devlink_get_dl_port(priv); 41 memset(dl_port, 0, sizeof(*dl_port)); 42 devlink_port_attrs_set(dl_port, &attrs); 43 44 return devlink_port_register(devlink, dl_port, dl_port_index); 45} 46 47void mlx5e_devlink_port_type_eth_set(struct mlx5e_priv *priv) 48{ 49 struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv); 50 51 devlink_port_type_eth_set(dl_port, priv->netdev); 52} 53 54void mlx5e_devlink_port_unregister(struct mlx5e_priv *priv) 55{ 56 struct devlink_port *dl_port = mlx5e_devlink_get_dl_port(priv); 57 58 devlink_port_unregister(dl_port); 59} 60 61struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev) 62{ 63 struct mlx5e_priv *priv = netdev_priv(dev); 64 65 if (!netif_device_present(dev)) 66 return NULL; 67 68 return mlx5e_devlink_get_dl_port(priv); 69}