Skip to content

Commit e16aea2

Browse files
Saeed Mahameeddavem330
authored andcommitted
net/mlx5: Introduce access functions to modify/query vport mac lists
Those functions are needed to notify the upcoming L2 table and SR-IOV E-Switch(FDB) manager(PF), of the NIC vport (vf) UC/MC mac lists 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 e1d7d34 commit e16aea2

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

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

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,125 @@ int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *mdev,
150150
}
151151
EXPORT_SYMBOL(mlx5_modify_nic_vport_mac_address);
152152

153+
int mlx5_query_nic_vport_mac_list(struct mlx5_core_dev *dev,
154+
u32 vport,
155+
enum mlx5_list_type list_type,
156+
u8 addr_list[][ETH_ALEN],
157+
int *list_size)
158+
{
159+
u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)];
160+
void *nic_vport_ctx;
161+
int max_list_size;
162+
int req_list_size;
163+
int out_sz;
164+
void *out;
165+
int err;
166+
int i;
167+
168+
req_list_size = *list_size;
169+
170+
max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
171+
1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
172+
1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
173+
174+
if (req_list_size > max_list_size) {
175+
mlx5_core_warn(dev, "Requested list size (%d) > (%d) max_list_size\n",
176+
req_list_size, max_list_size);
177+
req_list_size = max_list_size;
178+
}
179+
180+
out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
181+
req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
182+
183+
memset(in, 0, sizeof(in));
184+
out = kzalloc(out_sz, GFP_KERNEL);
185+
if (!out)
186+
return -ENOMEM;
187+
188+
MLX5_SET(query_nic_vport_context_in, in, opcode,
189+
MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
190+
MLX5_SET(query_nic_vport_context_in, in, allowed_list_type, list_type);
191+
MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
192+
193+
if (vport)
194+
MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
195+
196+
err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, out_sz);
197+
if (err)
198+
goto out;
199+
200+
nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
201+
nic_vport_context);
202+
req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
203+
allowed_list_size);
204+
205+
*list_size = req_list_size;
206+
for (i = 0; i < req_list_size; i++) {
207+
u8 *mac_addr = MLX5_ADDR_OF(nic_vport_context,
208+
nic_vport_ctx,
209+
current_uc_mac_address[i]) + 2;
210+
ether_addr_copy(addr_list[i], mac_addr);
211+
}
212+
out:
213+
kfree(out);
214+
return err;
215+
}
216+
EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_list);
217+
218+
int mlx5_modify_nic_vport_mac_list(struct mlx5_core_dev *dev,
219+
enum mlx5_list_type list_type,
220+
u8 addr_list[][ETH_ALEN],
221+
int list_size)
222+
{
223+
u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
224+
void *nic_vport_ctx;
225+
int max_list_size;
226+
int in_sz;
227+
void *in;
228+
int err;
229+
int i;
230+
231+
max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
232+
1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
233+
1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
234+
235+
if (list_size > max_list_size)
236+
return -ENOSPC;
237+
238+
in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
239+
list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
240+
241+
memset(out, 0, sizeof(out));
242+
in = kzalloc(in_sz, GFP_KERNEL);
243+
if (!in)
244+
return -ENOMEM;
245+
246+
MLX5_SET(modify_nic_vport_context_in, in, opcode,
247+
MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
248+
MLX5_SET(modify_nic_vport_context_in, in,
249+
field_select.addresses_list, 1);
250+
251+
nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
252+
nic_vport_context);
253+
254+
MLX5_SET(nic_vport_context, nic_vport_ctx,
255+
allowed_list_type, list_type);
256+
MLX5_SET(nic_vport_context, nic_vport_ctx,
257+
allowed_list_size, list_size);
258+
259+
for (i = 0; i < list_size; i++) {
260+
u8 *curr_mac = MLX5_ADDR_OF(nic_vport_context,
261+
nic_vport_ctx,
262+
current_uc_mac_address[i]) + 2;
263+
ether_addr_copy(curr_mac, addr_list[i]);
264+
}
265+
266+
err = mlx5_cmd_exec_check_status(dev, in, in_sz, out, sizeof(out));
267+
kfree(in);
268+
return err;
269+
}
270+
EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_list);
271+
153272
int mlx5_query_hca_vport_gid(struct mlx5_core_dev *dev, u8 other_vport,
154273
u8 port_num, u16 vf_num, u16 gid_index,
155274
union ib_gid *gid)

include/linux/mlx5/device.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,12 @@ enum {
11021102
MLX5_FLOW_CONTEXT_DEST_TYPE_TIR = 2,
11031103
};
11041104

1105+
enum mlx5_list_type {
1106+
MLX5_NVPRT_LIST_TYPE_UC = 0x0,
1107+
MLX5_NVPRT_LIST_TYPE_MC = 0x1,
1108+
MLX5_NVPRT_LIST_TYPE_VLAN = 0x2,
1109+
};
1110+
11051111
enum {
11061112
MLX5_RQC_RQ_TYPE_MEMORY_RQ_INLINE = 0x0,
11071113
MLX5_RQC_RQ_TYPE_MEMORY_RQ_RPM = 0x1,

include/linux/mlx5/vport.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define __MLX5_VPORT_H__
3535

3636
#include <linux/mlx5/driver.h>
37+
#include <linux/mlx5/device.h>
3738

3839
u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod);
3940
int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
@@ -54,5 +55,14 @@ int mlx5_query_hca_vport_system_image_guid(struct mlx5_core_dev *dev,
5455
u64 *sys_image_guid);
5556
int mlx5_query_hca_vport_node_guid(struct mlx5_core_dev *dev,
5657
u64 *node_guid);
58+
int mlx5_query_nic_vport_mac_list(struct mlx5_core_dev *dev,
59+
u32 vport,
60+
enum mlx5_list_type list_type,
61+
u8 addr_list[][ETH_ALEN],
62+
int *list_size);
63+
int mlx5_modify_nic_vport_mac_list(struct mlx5_core_dev *dev,
64+
enum mlx5_list_type list_type,
65+
u8 addr_list[][ETH_ALEN],
66+
int list_size);
5767

5868
#endif /* __MLX5_VPORT_H__ */

0 commit comments

Comments
 (0)