Skip to content

Commit bffaa91

Browse files
roidayandavem330
authored andcommitted
net/mlx5: E-Switch, Add control for inline mode
Implement devlink show and set of HW inline-mode. The supported modes: none, link, network, transport. We currently support one mode for all vports so set is done on all vports. When eswitch is first initialized the inline-mode is queried from the FW. Signed-off-by: Roi Dayan <roid@mellanox.com> Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 34e4e99 commit bffaa91

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,7 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)
17981798
esw->total_vports = total_vports;
17991799
esw->enabled_vports = 0;
18001800
esw->mode = SRIOV_NONE;
1801+
esw->offloads.inline_mode = MLX5_INLINE_MODE_NONE;
18011802

18021803
dev->priv.eswitch = esw;
18031804
return 0;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct mlx5_esw_offload {
200200
struct mlx5_flow_group *vport_rx_group;
201201
struct mlx5_eswitch_rep *vport_reps;
202202
DECLARE_HASHTABLE(encap_tbl, 8);
203+
u8 inline_mode;
203204
};
204205

205206
struct mlx5_eswitch {
@@ -309,6 +310,9 @@ void mlx5_eswitch_sqs2vport_stop(struct mlx5_eswitch *esw,
309310

310311
int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode);
311312
int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode);
313+
int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode);
314+
int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode);
315+
int mlx5_eswitch_inline_mode_get(struct mlx5_eswitch *esw, int nvfs, u8 *mode);
312316
void mlx5_eswitch_register_vport_rep(struct mlx5_eswitch *esw,
313317
int vport_index,
314318
struct mlx5_eswitch_rep *rep);

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

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,14 @@ static int esw_offloads_start(struct mlx5_eswitch *esw)
657657
if (err1)
658658
esw_warn(esw->dev, "Failed setting eswitch back to legacy, err %d\n", err);
659659
}
660+
if (esw->offloads.inline_mode == MLX5_INLINE_MODE_NONE) {
661+
if (mlx5_eswitch_inline_mode_get(esw,
662+
num_vfs,
663+
&esw->offloads.inline_mode)) {
664+
esw->offloads.inline_mode = MLX5_INLINE_MODE_L2;
665+
esw_warn(esw->dev, "Inline mode is different between vports\n");
666+
}
667+
}
660668
return err;
661669
}
662670

@@ -771,6 +779,50 @@ static int esw_mode_to_devlink(u16 mlx5_mode, u16 *mode)
771779
return 0;
772780
}
773781

782+
static int esw_inline_mode_from_devlink(u8 mode, u8 *mlx5_mode)
783+
{
784+
switch (mode) {
785+
case DEVLINK_ESWITCH_INLINE_MODE_NONE:
786+
*mlx5_mode = MLX5_INLINE_MODE_NONE;
787+
break;
788+
case DEVLINK_ESWITCH_INLINE_MODE_LINK:
789+
*mlx5_mode = MLX5_INLINE_MODE_L2;
790+
break;
791+
case DEVLINK_ESWITCH_INLINE_MODE_NETWORK:
792+
*mlx5_mode = MLX5_INLINE_MODE_IP;
793+
break;
794+
case DEVLINK_ESWITCH_INLINE_MODE_TRANSPORT:
795+
*mlx5_mode = MLX5_INLINE_MODE_TCP_UDP;
796+
break;
797+
default:
798+
return -EINVAL;
799+
}
800+
801+
return 0;
802+
}
803+
804+
static int esw_inline_mode_to_devlink(u8 mlx5_mode, u8 *mode)
805+
{
806+
switch (mlx5_mode) {
807+
case MLX5_INLINE_MODE_NONE:
808+
*mode = DEVLINK_ESWITCH_INLINE_MODE_NONE;
809+
break;
810+
case MLX5_INLINE_MODE_L2:
811+
*mode = DEVLINK_ESWITCH_INLINE_MODE_LINK;
812+
break;
813+
case MLX5_INLINE_MODE_IP:
814+
*mode = DEVLINK_ESWITCH_INLINE_MODE_NETWORK;
815+
break;
816+
case MLX5_INLINE_MODE_TCP_UDP:
817+
*mode = DEVLINK_ESWITCH_INLINE_MODE_TRANSPORT;
818+
break;
819+
default:
820+
return -EINVAL;
821+
}
822+
823+
return 0;
824+
}
825+
774826
int mlx5_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode)
775827
{
776828
struct mlx5_core_dev *dev;
@@ -815,6 +867,95 @@ int mlx5_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode)
815867
return esw_mode_to_devlink(dev->priv.eswitch->mode, mode);
816868
}
817869

870+
int mlx5_devlink_eswitch_inline_mode_set(struct devlink *devlink, u8 mode)
871+
{
872+
struct mlx5_core_dev *dev = devlink_priv(devlink);
873+
struct mlx5_eswitch *esw = dev->priv.eswitch;
874+
int num_vports = esw->enabled_vports;
875+
int err;
876+
int vport;
877+
u8 mlx5_mode;
878+
879+
if (!MLX5_CAP_GEN(dev, vport_group_manager))
880+
return -EOPNOTSUPP;
881+
882+
if (esw->mode == SRIOV_NONE)
883+
return -EOPNOTSUPP;
884+
885+
if (MLX5_CAP_ETH(dev, wqe_inline_mode) !=
886+
MLX5_CAP_INLINE_MODE_VPORT_CONTEXT)
887+
return -EOPNOTSUPP;
888+
889+
err = esw_inline_mode_from_devlink(mode, &mlx5_mode);
890+
if (err)
891+
goto out;
892+
893+
for (vport = 1; vport < num_vports; vport++) {
894+
err = mlx5_modify_nic_vport_min_inline(dev, vport, mlx5_mode);
895+
if (err) {
896+
esw_warn(dev, "Failed to set min inline on vport %d\n",
897+
vport);
898+
goto revert_inline_mode;
899+
}
900+
}
901+
902+
esw->offloads.inline_mode = mlx5_mode;
903+
return 0;
904+
905+
revert_inline_mode:
906+
while (--vport > 0)
907+
mlx5_modify_nic_vport_min_inline(dev,
908+
vport,
909+
esw->offloads.inline_mode);
910+
out:
911+
return err;
912+
}
913+
914+
int mlx5_devlink_eswitch_inline_mode_get(struct devlink *devlink, u8 *mode)
915+
{
916+
struct mlx5_core_dev *dev = devlink_priv(devlink);
917+
struct mlx5_eswitch *esw = dev->priv.eswitch;
918+
919+
if (!MLX5_CAP_GEN(dev, vport_group_manager))
920+
return -EOPNOTSUPP;
921+
922+
if (esw->mode == SRIOV_NONE)
923+
return -EOPNOTSUPP;
924+
925+
if (MLX5_CAP_ETH(dev, wqe_inline_mode) !=
926+
MLX5_CAP_INLINE_MODE_VPORT_CONTEXT)
927+
return -EOPNOTSUPP;
928+
929+
return esw_inline_mode_to_devlink(esw->offloads.inline_mode, mode);
930+
}
931+
932+
int mlx5_eswitch_inline_mode_get(struct mlx5_eswitch *esw, int nvfs, u8 *mode)
933+
{
934+
struct mlx5_core_dev *dev = esw->dev;
935+
int vport;
936+
u8 prev_mlx5_mode, mlx5_mode = MLX5_INLINE_MODE_L2;
937+
938+
if (!MLX5_CAP_GEN(dev, vport_group_manager))
939+
return -EOPNOTSUPP;
940+
941+
if (esw->mode == SRIOV_NONE)
942+
return -EOPNOTSUPP;
943+
944+
if (MLX5_CAP_ETH(dev, wqe_inline_mode) !=
945+
MLX5_CAP_INLINE_MODE_VPORT_CONTEXT)
946+
return -EOPNOTSUPP;
947+
948+
for (vport = 1; vport <= nvfs; vport++) {
949+
mlx5_query_nic_vport_min_inline(dev, vport, &mlx5_mode);
950+
if (vport > 1 && prev_mlx5_mode != mlx5_mode)
951+
return -EINVAL;
952+
prev_mlx5_mode = mlx5_mode;
953+
}
954+
955+
*mode = mlx5_mode;
956+
return 0;
957+
}
958+
818959
void mlx5_eswitch_register_vport_rep(struct mlx5_eswitch *esw,
819960
int vport_index,
820961
struct mlx5_eswitch_rep *__rep)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,8 @@ static const struct devlink_ops mlx5_devlink_ops = {
12391239
#ifdef CONFIG_MLX5_CORE_EN
12401240
.eswitch_mode_set = mlx5_devlink_eswitch_mode_set,
12411241
.eswitch_mode_get = mlx5_devlink_eswitch_mode_get,
1242+
.eswitch_inline_mode_set = mlx5_devlink_eswitch_inline_mode_set,
1243+
.eswitch_inline_mode_get = mlx5_devlink_eswitch_inline_mode_get,
12421244
#endif
12431245
};
12441246

0 commit comments

Comments
 (0)