Skip to content

Commit 7725657

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5: E-Switch, Introduce Vport administration functions
Implement set VF mac/link state and query VF config to be used later in nedev VF ndos or any other management API. Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: Or Gerlitz <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8184873 commit 7725657

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,3 +1022,64 @@ void mlx5_eswitch_vport_event(struct mlx5_eswitch *esw, struct mlx5_eqe *eqe)
10221022
queue_work(esw->work_queue, &vport->vport_change_handler);
10231023
spin_unlock(&vport->lock);
10241024
}
1025+
1026+
/* Vport Administration */
1027+
#define ESW_ALLOWED(esw) \
1028+
(esw && MLX5_CAP_GEN(esw->dev, vport_group_manager) && mlx5_core_is_pf(esw->dev))
1029+
#define LEGAL_VPORT(esw, vport) (vport >= 0 && vport < esw->total_vports)
1030+
1031+
int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
1032+
int vport, u8 mac[ETH_ALEN])
1033+
{
1034+
int err = 0;
1035+
1036+
if (!ESW_ALLOWED(esw))
1037+
return -EPERM;
1038+
if (!LEGAL_VPORT(esw, vport))
1039+
return -EINVAL;
1040+
1041+
err = mlx5_modify_nic_vport_mac_address(esw->dev, vport, mac);
1042+
if (err) {
1043+
mlx5_core_warn(esw->dev,
1044+
"Failed to mlx5_modify_nic_vport_mac vport(%d) err=(%d)\n",
1045+
vport, err);
1046+
return err;
1047+
}
1048+
1049+
return err;
1050+
}
1051+
1052+
int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
1053+
int vport, int link_state)
1054+
{
1055+
if (!ESW_ALLOWED(esw))
1056+
return -EPERM;
1057+
if (!LEGAL_VPORT(esw, vport))
1058+
return -EINVAL;
1059+
1060+
return mlx5_modify_vport_admin_state(esw->dev,
1061+
MLX5_QUERY_VPORT_STATE_IN_OP_MOD_ESW_VPORT,
1062+
vport, link_state);
1063+
}
1064+
1065+
int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
1066+
int vport, struct ifla_vf_info *ivi)
1067+
{
1068+
if (!ESW_ALLOWED(esw))
1069+
return -EPERM;
1070+
if (!LEGAL_VPORT(esw, vport))
1071+
return -EINVAL;
1072+
1073+
memset(ivi, 0, sizeof(*ivi));
1074+
ivi->vf = vport - 1;
1075+
1076+
mlx5_query_nic_vport_mac_address(esw->dev, vport, ivi->mac);
1077+
ivi->linkstate = mlx5_query_vport_admin_state(esw->dev,
1078+
MLX5_QUERY_VPORT_STATE_IN_OP_MOD_ESW_VPORT,
1079+
vport);
1080+
ivi->vlan = 0;
1081+
ivi->qos = 0;
1082+
ivi->spoofchk = 0;
1083+
1084+
return 0;
1085+
}

drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#ifndef __MLX5_ESWITCH_H__
3434
#define __MLX5_ESWITCH_H__
3535

36+
#include <linux/if_ether.h>
37+
#include <linux/if_link.h>
3638
#include <linux/mlx5/device.h>
3739

3840
#define MLX5_MAX_UC_PER_VPORT(dev) \
@@ -143,5 +145,11 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw);
143145
void mlx5_eswitch_vport_event(struct mlx5_eswitch *esw, struct mlx5_eqe *eqe);
144146
int mlx5_eswitch_enable_sriov(struct mlx5_eswitch *esw, int nvfs);
145147
void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw);
148+
int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
149+
int vport, u8 mac[ETH_ALEN]);
150+
int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
151+
int vport, int link_state);
152+
int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
153+
int vport, struct ifla_vf_info *ivi);
146154

147155
#endif /* __MLX5_ESWITCH_H__ */

0 commit comments

Comments
 (0)