Skip to content

Commit c0046cf

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5: Introduce access functions to modify/query vport vlans
Those functions are needed to notify the upcoming L2 table and SR-IOV E-Switch(FDB) manager(PF), of the NIC vport (vf) vlan table changes. preperation for ethernet sriov and l2 table management. Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: Or Gerlitz <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d82b731 commit c0046cf

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,118 @@ int mlx5_modify_nic_vport_mac_list(struct mlx5_core_dev *dev,
318318
}
319319
EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_list);
320320

321+
int mlx5_query_nic_vport_vlans(struct mlx5_core_dev *dev,
322+
u32 vport,
323+
u16 vlans[],
324+
int *size)
325+
{
326+
u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)];
327+
void *nic_vport_ctx;
328+
int req_list_size;
329+
int max_list_size;
330+
int out_sz;
331+
void *out;
332+
int err;
333+
int i;
334+
335+
req_list_size = *size;
336+
max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
337+
if (req_list_size > max_list_size) {
338+
mlx5_core_warn(dev, "Requested list size (%d) > (%d) max list size\n",
339+
req_list_size, max_list_size);
340+
req_list_size = max_list_size;
341+
}
342+
343+
out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
344+
req_list_size * MLX5_ST_SZ_BYTES(vlan_layout);
345+
346+
memset(in, 0, sizeof(in));
347+
out = kzalloc(out_sz, GFP_KERNEL);
348+
if (!out)
349+
return -ENOMEM;
350+
351+
MLX5_SET(query_nic_vport_context_in, in, opcode,
352+
MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
353+
MLX5_SET(query_nic_vport_context_in, in, allowed_list_type,
354+
MLX5_NVPRT_LIST_TYPE_VLAN);
355+
MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
356+
357+
if (vport)
358+
MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
359+
360+
err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, out_sz);
361+
if (err)
362+
goto out;
363+
364+
nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
365+
nic_vport_context);
366+
req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
367+
allowed_list_size);
368+
369+
*size = req_list_size;
370+
for (i = 0; i < req_list_size; i++) {
371+
void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
372+
nic_vport_ctx,
373+
current_uc_mac_address[i]);
374+
vlans[i] = MLX5_GET(vlan_layout, vlan_addr, vlan);
375+
}
376+
out:
377+
kfree(out);
378+
return err;
379+
}
380+
EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_vlans);
381+
382+
int mlx5_modify_nic_vport_vlans(struct mlx5_core_dev *dev,
383+
u16 vlans[],
384+
int list_size)
385+
{
386+
u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
387+
void *nic_vport_ctx;
388+
int max_list_size;
389+
int in_sz;
390+
void *in;
391+
int err;
392+
int i;
393+
394+
max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
395+
396+
if (list_size > max_list_size)
397+
return -ENOSPC;
398+
399+
in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
400+
list_size * MLX5_ST_SZ_BYTES(vlan_layout);
401+
402+
memset(out, 0, sizeof(out));
403+
in = kzalloc(in_sz, GFP_KERNEL);
404+
if (!in)
405+
return -ENOMEM;
406+
407+
MLX5_SET(modify_nic_vport_context_in, in, opcode,
408+
MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
409+
MLX5_SET(modify_nic_vport_context_in, in,
410+
field_select.addresses_list, 1);
411+
412+
nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
413+
nic_vport_context);
414+
415+
MLX5_SET(nic_vport_context, nic_vport_ctx,
416+
allowed_list_type, MLX5_NVPRT_LIST_TYPE_VLAN);
417+
MLX5_SET(nic_vport_context, nic_vport_ctx,
418+
allowed_list_size, list_size);
419+
420+
for (i = 0; i < list_size; i++) {
421+
void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
422+
nic_vport_ctx,
423+
current_uc_mac_address[i]);
424+
MLX5_SET(vlan_layout, vlan_addr, vlan, vlans[i]);
425+
}
426+
427+
err = mlx5_cmd_exec_check_status(dev, in, in_sz, out, sizeof(out));
428+
kfree(in);
429+
return err;
430+
}
431+
EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_vlans);
432+
321433
int mlx5_query_hca_vport_gid(struct mlx5_core_dev *dev, u8 other_vport,
322434
u8 port_num, u16 vf_num, u16 gid_index,
323435
union ib_gid *gid)

include/linux/mlx5/mlx5_ifc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,13 @@ struct mlx5_ifc_mac_address_layout_bits {
910910
u8 mac_addr_31_0[0x20];
911911
};
912912

913+
struct mlx5_ifc_vlan_layout_bits {
914+
u8 reserved_0[0x14];
915+
u8 vlan[0x0c];
916+
917+
u8 reserved_1[0x20];
918+
};
919+
913920
struct mlx5_ifc_cong_control_r_roce_ecn_np_bits {
914921
u8 reserved_0[0xa0];
915922

include/linux/mlx5/vport.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,12 @@ int mlx5_modify_nic_vport_promisc(struct mlx5_core_dev *mdev,
7777
int promisc_uc,
7878
int promisc_mc,
7979
int promisc_all);
80+
int mlx5_query_nic_vport_vlans(struct mlx5_core_dev *dev,
81+
u32 vport,
82+
u16 vlans[],
83+
int *size);
84+
int mlx5_modify_nic_vport_vlans(struct mlx5_core_dev *dev,
85+
u16 vlans[],
86+
int list_size);
8087

8188
#endif /* __MLX5_VPORT_H__ */

0 commit comments

Comments
 (0)