Skip to content

Commit 9e7ea35

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5: E-Switch, Introduce set vport vlan (VST mode)
Add query and modify functions to control client vlan and qos striping or insertion, in E-Switch vports contexts. Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: Or Gerlitz <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d666675 commit 9e7ea35

File tree

2 files changed

+134
-2
lines changed

2 files changed

+134
-2
lines changed

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

Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,116 @@ static int arm_vport_context_events_cmd(struct mlx5_core_dev *dev, u16 vport,
128128
return err;
129129
}
130130

131+
/* E-Switch vport context HW commands */
132+
static int query_esw_vport_context_cmd(struct mlx5_core_dev *mdev, u32 vport,
133+
u32 *out, int outlen)
134+
{
135+
u32 in[MLX5_ST_SZ_DW(query_esw_vport_context_in)];
136+
137+
memset(in, 0, sizeof(in));
138+
139+
MLX5_SET(query_nic_vport_context_in, in, opcode,
140+
MLX5_CMD_OP_QUERY_ESW_VPORT_CONTEXT);
141+
142+
MLX5_SET(query_esw_vport_context_in, in, vport_number, vport);
143+
if (vport)
144+
MLX5_SET(query_esw_vport_context_in, in, other_vport, 1);
145+
146+
return mlx5_cmd_exec_check_status(mdev, in, sizeof(in), out, outlen);
147+
}
148+
149+
static int query_esw_vport_cvlan(struct mlx5_core_dev *dev, u32 vport,
150+
u16 *vlan, u8 *qos)
151+
{
152+
u32 out[MLX5_ST_SZ_DW(query_esw_vport_context_out)];
153+
int err;
154+
bool cvlan_strip;
155+
bool cvlan_insert;
156+
157+
memset(out, 0, sizeof(out));
158+
159+
*vlan = 0;
160+
*qos = 0;
161+
162+
if (!MLX5_CAP_ESW(dev, vport_cvlan_strip) ||
163+
!MLX5_CAP_ESW(dev, vport_cvlan_insert_if_not_exist))
164+
return -ENOTSUPP;
165+
166+
err = query_esw_vport_context_cmd(dev, vport, out, sizeof(out));
167+
if (err)
168+
goto out;
169+
170+
cvlan_strip = MLX5_GET(query_esw_vport_context_out, out,
171+
esw_vport_context.vport_cvlan_strip);
172+
173+
cvlan_insert = MLX5_GET(query_esw_vport_context_out, out,
174+
esw_vport_context.vport_cvlan_insert);
175+
176+
if (cvlan_strip || cvlan_insert) {
177+
*vlan = MLX5_GET(query_esw_vport_context_out, out,
178+
esw_vport_context.cvlan_id);
179+
*qos = MLX5_GET(query_esw_vport_context_out, out,
180+
esw_vport_context.cvlan_pcp);
181+
}
182+
183+
esw_debug(dev, "Query Vport[%d] cvlan: VLAN %d qos=%d\n",
184+
vport, *vlan, *qos);
185+
out:
186+
return err;
187+
}
188+
189+
static int modify_esw_vport_context_cmd(struct mlx5_core_dev *dev, u16 vport,
190+
void *in, int inlen)
191+
{
192+
u32 out[MLX5_ST_SZ_DW(modify_esw_vport_context_out)];
193+
194+
memset(out, 0, sizeof(out));
195+
196+
MLX5_SET(modify_esw_vport_context_in, in, vport_number, vport);
197+
if (vport)
198+
MLX5_SET(modify_esw_vport_context_in, in, other_vport, 1);
199+
200+
MLX5_SET(modify_esw_vport_context_in, in, opcode,
201+
MLX5_CMD_OP_MODIFY_ESW_VPORT_CONTEXT);
202+
203+
return mlx5_cmd_exec_check_status(dev, in, inlen,
204+
out, sizeof(out));
205+
}
206+
207+
static int modify_esw_vport_cvlan(struct mlx5_core_dev *dev, u32 vport,
208+
u16 vlan, u8 qos, bool set)
209+
{
210+
u32 in[MLX5_ST_SZ_DW(modify_esw_vport_context_in)];
211+
212+
memset(in, 0, sizeof(in));
213+
214+
if (!MLX5_CAP_ESW(dev, vport_cvlan_strip) ||
215+
!MLX5_CAP_ESW(dev, vport_cvlan_insert_if_not_exist))
216+
return -ENOTSUPP;
217+
218+
esw_debug(dev, "Set Vport[%d] VLAN %d qos %d set=%d\n",
219+
vport, vlan, qos, set);
220+
221+
if (set) {
222+
MLX5_SET(modify_esw_vport_context_in, in,
223+
esw_vport_context.vport_cvlan_strip, 1);
224+
/* insert only if no vlan in packet */
225+
MLX5_SET(modify_esw_vport_context_in, in,
226+
esw_vport_context.vport_cvlan_insert, 1);
227+
MLX5_SET(modify_esw_vport_context_in, in,
228+
esw_vport_context.cvlan_pcp, qos);
229+
MLX5_SET(modify_esw_vport_context_in, in,
230+
esw_vport_context.cvlan_id, vlan);
231+
}
232+
233+
MLX5_SET(modify_esw_vport_context_in, in,
234+
field_select.vport_cvlan_strip, 1);
235+
MLX5_SET(modify_esw_vport_context_in, in,
236+
field_select.vport_cvlan_insert, 1);
237+
238+
return modify_esw_vport_context_cmd(dev, vport, in, sizeof(in));
239+
}
240+
131241
/* HW L2 Table (MPFS) management */
132242
static int set_l2_table_entry_cmd(struct mlx5_core_dev *dev, u32 index,
133243
u8 *mac, u8 vlan_valid, u16 vlan)
@@ -1065,6 +1175,9 @@ int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
10651175
int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
10661176
int vport, struct ifla_vf_info *ivi)
10671177
{
1178+
u16 vlan;
1179+
u8 qos;
1180+
10681181
if (!ESW_ALLOWED(esw))
10691182
return -EPERM;
10701183
if (!LEGAL_VPORT(esw, vport))
@@ -1077,9 +1190,26 @@ int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
10771190
ivi->linkstate = mlx5_query_vport_admin_state(esw->dev,
10781191
MLX5_QUERY_VPORT_STATE_IN_OP_MOD_ESW_VPORT,
10791192
vport);
1080-
ivi->vlan = 0;
1081-
ivi->qos = 0;
1193+
query_esw_vport_cvlan(esw->dev, vport, &vlan, &qos);
1194+
ivi->vlan = vlan;
1195+
ivi->qos = qos;
10821196
ivi->spoofchk = 0;
10831197

10841198
return 0;
10851199
}
1200+
1201+
int mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
1202+
int vport, u16 vlan, u8 qos)
1203+
{
1204+
int set = 0;
1205+
1206+
if (!ESW_ALLOWED(esw))
1207+
return -EPERM;
1208+
if (!LEGAL_VPORT(esw, vport) || (vlan > 4095) || (qos > 7))
1209+
return -EINVAL;
1210+
1211+
if (vlan || qos)
1212+
set = 1;
1213+
1214+
return modify_esw_vport_cvlan(esw->dev, vport, vlan, qos, set);
1215+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
149149
int vport, u8 mac[ETH_ALEN]);
150150
int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
151151
int vport, int link_state);
152+
int mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
153+
int vport, u16 vlan, u8 qos);
152154
int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
153155
int vport, struct ifla_vf_info *ivi);
154156

0 commit comments

Comments
 (0)