2 * Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/export.h>
34 #include <linux/etherdevice.h>
35 #include <linux/mlx5/driver.h>
36 #include <linux/mlx5/vport.h>
37 #include "mlx5_core.h"
39 /* Mutex to hold while enabling or disabling RoCE */
40 static DEFINE_MUTEX(mlx5_roce_en_lock);
42 static int _mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod,
43 u16 vport, u32 *out, int outlen)
45 u32 in[MLX5_ST_SZ_DW(query_vport_state_in)] = {0};
47 MLX5_SET(query_vport_state_in, in, opcode,
48 MLX5_CMD_OP_QUERY_VPORT_STATE);
49 MLX5_SET(query_vport_state_in, in, op_mod, opmod);
50 MLX5_SET(query_vport_state_in, in, vport_number, vport);
52 MLX5_SET(query_vport_state_in, in, other_vport, 1);
54 return mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
57 u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport)
59 u32 out[MLX5_ST_SZ_DW(query_vport_state_out)] = {0};
61 _mlx5_query_vport_state(mdev, opmod, vport, out, sizeof(out));
63 return MLX5_GET(query_vport_state_out, out, state);
66 int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
69 u32 in[MLX5_ST_SZ_DW(modify_vport_state_in)] = {0};
70 u32 out[MLX5_ST_SZ_DW(modify_vport_state_out)] = {0};
72 MLX5_SET(modify_vport_state_in, in, opcode,
73 MLX5_CMD_OP_MODIFY_VPORT_STATE);
74 MLX5_SET(modify_vport_state_in, in, op_mod, opmod);
75 MLX5_SET(modify_vport_state_in, in, vport_number, vport);
77 MLX5_SET(modify_vport_state_in, in, other_vport, 1);
78 MLX5_SET(modify_vport_state_in, in, admin_state, state);
80 return mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
83 static int mlx5_query_nic_vport_context(struct mlx5_core_dev *mdev, u16 vport,
86 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
88 MLX5_SET(query_nic_vport_context_in, in, opcode,
89 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
90 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
92 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
94 return mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
97 static int mlx5_modify_nic_vport_context(struct mlx5_core_dev *mdev, void *in,
100 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)] = {0};
102 MLX5_SET(modify_nic_vport_context_in, in, opcode,
103 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
104 return mlx5_cmd_exec(mdev, in, inlen, out, sizeof(out));
107 int mlx5_query_nic_vport_min_inline(struct mlx5_core_dev *mdev,
108 u16 vport, u8 *min_inline)
110 u32 out[MLX5_ST_SZ_DW(query_nic_vport_context_out)] = {0};
113 err = mlx5_query_nic_vport_context(mdev, vport, out, sizeof(out));
115 *min_inline = MLX5_GET(query_nic_vport_context_out, out,
116 nic_vport_context.min_wqe_inline_mode);
119 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_min_inline);
121 void mlx5_query_min_inline(struct mlx5_core_dev *mdev,
124 switch (MLX5_CAP_ETH(mdev, wqe_inline_mode)) {
125 case MLX5_CAP_INLINE_MODE_L2:
126 *min_inline_mode = MLX5_INLINE_MODE_L2;
128 case MLX5_CAP_INLINE_MODE_VPORT_CONTEXT:
129 mlx5_query_nic_vport_min_inline(mdev, 0, min_inline_mode);
131 case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
132 *min_inline_mode = MLX5_INLINE_MODE_NONE;
136 EXPORT_SYMBOL_GPL(mlx5_query_min_inline);
138 int mlx5_modify_nic_vport_min_inline(struct mlx5_core_dev *mdev,
139 u16 vport, u8 min_inline)
141 u32 in[MLX5_ST_SZ_DW(modify_nic_vport_context_in)] = {0};
142 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
145 MLX5_SET(modify_nic_vport_context_in, in,
146 field_select.min_inline, 1);
147 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
148 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
150 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
151 in, nic_vport_context);
152 MLX5_SET(nic_vport_context, nic_vport_ctx,
153 min_wqe_inline_mode, min_inline);
155 return mlx5_modify_nic_vport_context(mdev, in, inlen);
158 int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
162 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
166 out = kvzalloc(outlen, GFP_KERNEL);
170 out_addr = MLX5_ADDR_OF(query_nic_vport_context_out, out,
171 nic_vport_context.permanent_address);
173 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
175 ether_addr_copy(addr, &out_addr[2]);
180 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_address);
182 int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *mdev,
186 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
191 in = kvzalloc(inlen, GFP_KERNEL);
195 MLX5_SET(modify_nic_vport_context_in, in,
196 field_select.permanent_address, 1);
197 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
200 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
202 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
203 in, nic_vport_context);
204 perm_mac = MLX5_ADDR_OF(nic_vport_context, nic_vport_ctx,
207 ether_addr_copy(&perm_mac[2], addr);
209 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
215 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_address);
217 int mlx5_query_nic_vport_mtu(struct mlx5_core_dev *mdev, u16 *mtu)
219 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
223 out = kvzalloc(outlen, GFP_KERNEL);
227 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
229 *mtu = MLX5_GET(query_nic_vport_context_out, out,
230 nic_vport_context.mtu);
235 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mtu);
237 int mlx5_modify_nic_vport_mtu(struct mlx5_core_dev *mdev, u16 mtu)
239 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
243 in = kvzalloc(inlen, GFP_KERNEL);
247 MLX5_SET(modify_nic_vport_context_in, in, field_select.mtu, 1);
248 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.mtu, mtu);
250 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
255 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mtu);
257 int mlx5_query_nic_vport_mac_list(struct mlx5_core_dev *dev,
259 enum mlx5_list_type list_type,
260 u8 addr_list[][ETH_ALEN],
263 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
272 req_list_size = *list_size;
274 max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
275 1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
276 1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
278 if (req_list_size > max_list_size) {
279 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max_list_size\n",
280 req_list_size, max_list_size);
281 req_list_size = max_list_size;
284 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
285 req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
287 out = kzalloc(out_sz, GFP_KERNEL);
291 MLX5_SET(query_nic_vport_context_in, in, opcode,
292 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
293 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type, list_type);
294 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
297 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
299 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
303 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
305 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
308 *list_size = req_list_size;
309 for (i = 0; i < req_list_size; i++) {
310 u8 *mac_addr = MLX5_ADDR_OF(nic_vport_context,
312 current_uc_mac_address[i]) + 2;
313 ether_addr_copy(addr_list[i], mac_addr);
319 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_list);
321 int mlx5_modify_nic_vport_mac_list(struct mlx5_core_dev *dev,
322 enum mlx5_list_type list_type,
323 u8 addr_list[][ETH_ALEN],
326 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
334 max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
335 1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
336 1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
338 if (list_size > max_list_size)
341 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
342 list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
344 memset(out, 0, sizeof(out));
345 in = kzalloc(in_sz, GFP_KERNEL);
349 MLX5_SET(modify_nic_vport_context_in, in, opcode,
350 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
351 MLX5_SET(modify_nic_vport_context_in, in,
352 field_select.addresses_list, 1);
354 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
357 MLX5_SET(nic_vport_context, nic_vport_ctx,
358 allowed_list_type, list_type);
359 MLX5_SET(nic_vport_context, nic_vport_ctx,
360 allowed_list_size, list_size);
362 for (i = 0; i < list_size; i++) {
363 u8 *curr_mac = MLX5_ADDR_OF(nic_vport_context,
365 current_uc_mac_address[i]) + 2;
366 ether_addr_copy(curr_mac, addr_list[i]);
369 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
373 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_list);
375 int mlx5_query_nic_vport_vlans(struct mlx5_core_dev *dev,
380 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)];
389 req_list_size = *size;
390 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
391 if (req_list_size > max_list_size) {
392 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max list size\n",
393 req_list_size, max_list_size);
394 req_list_size = max_list_size;
397 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
398 req_list_size * MLX5_ST_SZ_BYTES(vlan_layout);
400 memset(in, 0, sizeof(in));
401 out = kzalloc(out_sz, GFP_KERNEL);
405 MLX5_SET(query_nic_vport_context_in, in, opcode,
406 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
407 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type,
408 MLX5_NVPRT_LIST_TYPE_VLAN);
409 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
412 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
414 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
418 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
420 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
423 *size = req_list_size;
424 for (i = 0; i < req_list_size; i++) {
425 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
427 current_uc_mac_address[i]);
428 vlans[i] = MLX5_GET(vlan_layout, vlan_addr, vlan);
434 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_vlans);
436 int mlx5_modify_nic_vport_vlans(struct mlx5_core_dev *dev,
440 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
448 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
450 if (list_size > max_list_size)
453 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
454 list_size * MLX5_ST_SZ_BYTES(vlan_layout);
456 memset(out, 0, sizeof(out));
457 in = kzalloc(in_sz, GFP_KERNEL);
461 MLX5_SET(modify_nic_vport_context_in, in, opcode,
462 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
463 MLX5_SET(modify_nic_vport_context_in, in,
464 field_select.addresses_list, 1);
466 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
469 MLX5_SET(nic_vport_context, nic_vport_ctx,
470 allowed_list_type, MLX5_NVPRT_LIST_TYPE_VLAN);
471 MLX5_SET(nic_vport_context, nic_vport_ctx,
472 allowed_list_size, list_size);
474 for (i = 0; i < list_size; i++) {
475 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
477 current_uc_mac_address[i]);
478 MLX5_SET(vlan_layout, vlan_addr, vlan, vlans[i]);
481 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
485 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_vlans);
487 int mlx5_query_nic_vport_system_image_guid(struct mlx5_core_dev *mdev,
488 u64 *system_image_guid)
491 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
493 out = kvzalloc(outlen, GFP_KERNEL);
497 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
499 *system_image_guid = MLX5_GET64(query_nic_vport_context_out, out,
500 nic_vport_context.system_image_guid);
506 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_system_image_guid);
508 int mlx5_query_nic_vport_node_guid(struct mlx5_core_dev *mdev, u64 *node_guid)
511 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
513 out = kvzalloc(outlen, GFP_KERNEL);
517 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
519 *node_guid = MLX5_GET64(query_nic_vport_context_out, out,
520 nic_vport_context.node_guid);
526 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_node_guid);
528 int mlx5_modify_nic_vport_node_guid(struct mlx5_core_dev *mdev,
529 u32 vport, u64 node_guid)
531 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
532 void *nic_vport_context;
538 if (!MLX5_CAP_GEN(mdev, vport_group_manager))
541 in = kvzalloc(inlen, GFP_KERNEL);
545 MLX5_SET(modify_nic_vport_context_in, in,
546 field_select.node_guid, 1);
547 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
548 MLX5_SET(modify_nic_vport_context_in, in, other_vport, !!vport);
550 nic_vport_context = MLX5_ADDR_OF(modify_nic_vport_context_in,
551 in, nic_vport_context);
552 MLX5_SET64(nic_vport_context, nic_vport_context, node_guid, node_guid);
554 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
561 int mlx5_query_nic_vport_qkey_viol_cntr(struct mlx5_core_dev *mdev,
565 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
567 out = kvzalloc(outlen, GFP_KERNEL);
571 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
573 *qkey_viol_cntr = MLX5_GET(query_nic_vport_context_out, out,
574 nic_vport_context.qkey_violation_counter);
580 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_qkey_viol_cntr);
582 int mlx5_query_hca_vport_gid(struct mlx5_core_dev *dev, u8 other_vport,
583 u8 port_num, u16 vf_num, u16 gid_index,
586 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_in);
587 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_out);
588 int is_group_manager;
596 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
597 tbsz = mlx5_get_gid_table_len(MLX5_CAP_GEN(dev, gid_table_size));
598 mlx5_core_dbg(dev, "vf_num %d, index %d, gid_table_size %d\n",
599 vf_num, gid_index, tbsz);
601 if (gid_index > tbsz && gid_index != 0xffff)
604 if (gid_index == 0xffff)
609 out_sz += nout * sizeof(*gid);
611 in = kzalloc(in_sz, GFP_KERNEL);
612 out = kzalloc(out_sz, GFP_KERNEL);
618 MLX5_SET(query_hca_vport_gid_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_GID);
620 if (is_group_manager) {
621 MLX5_SET(query_hca_vport_gid_in, in, vport_number, vf_num);
622 MLX5_SET(query_hca_vport_gid_in, in, other_vport, 1);
628 MLX5_SET(query_hca_vport_gid_in, in, gid_index, gid_index);
630 if (MLX5_CAP_GEN(dev, num_ports) == 2)
631 MLX5_SET(query_hca_vport_gid_in, in, port_num, port_num);
633 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
637 tmp = out + MLX5_ST_SZ_BYTES(query_hca_vport_gid_out);
638 gid->global.subnet_prefix = tmp->global.subnet_prefix;
639 gid->global.interface_id = tmp->global.interface_id;
646 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_gid);
648 int mlx5_query_hca_vport_pkey(struct mlx5_core_dev *dev, u8 other_vport,
649 u8 port_num, u16 vf_num, u16 pkey_index,
652 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_in);
653 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_out);
654 int is_group_manager;
663 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
665 tbsz = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(dev, pkey_table_size));
666 if (pkey_index > tbsz && pkey_index != 0xffff)
669 if (pkey_index == 0xffff)
674 out_sz += nout * MLX5_ST_SZ_BYTES(pkey);
676 in = kzalloc(in_sz, GFP_KERNEL);
677 out = kzalloc(out_sz, GFP_KERNEL);
683 MLX5_SET(query_hca_vport_pkey_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_PKEY);
685 if (is_group_manager) {
686 MLX5_SET(query_hca_vport_pkey_in, in, vport_number, vf_num);
687 MLX5_SET(query_hca_vport_pkey_in, in, other_vport, 1);
693 MLX5_SET(query_hca_vport_pkey_in, in, pkey_index, pkey_index);
695 if (MLX5_CAP_GEN(dev, num_ports) == 2)
696 MLX5_SET(query_hca_vport_pkey_in, in, port_num, port_num);
698 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
702 pkarr = MLX5_ADDR_OF(query_hca_vport_pkey_out, out, pkey);
703 for (i = 0; i < nout; i++, pkey++, pkarr += MLX5_ST_SZ_BYTES(pkey))
704 *pkey = MLX5_GET_PR(pkey, pkarr, pkey);
711 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_pkey);
713 int mlx5_query_hca_vport_context(struct mlx5_core_dev *dev,
714 u8 other_vport, u8 port_num,
716 struct mlx5_hca_vport_context *rep)
718 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_context_out);
719 int in[MLX5_ST_SZ_DW(query_hca_vport_context_in)] = {0};
720 int is_group_manager;
725 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
727 out = kzalloc(out_sz, GFP_KERNEL);
731 MLX5_SET(query_hca_vport_context_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_CONTEXT);
734 if (is_group_manager) {
735 MLX5_SET(query_hca_vport_context_in, in, other_vport, 1);
736 MLX5_SET(query_hca_vport_context_in, in, vport_number, vf_num);
743 if (MLX5_CAP_GEN(dev, num_ports) == 2)
744 MLX5_SET(query_hca_vport_context_in, in, port_num, port_num);
746 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
750 ctx = MLX5_ADDR_OF(query_hca_vport_context_out, out, hca_vport_context);
751 rep->field_select = MLX5_GET_PR(hca_vport_context, ctx, field_select);
752 rep->sm_virt_aware = MLX5_GET_PR(hca_vport_context, ctx, sm_virt_aware);
753 rep->has_smi = MLX5_GET_PR(hca_vport_context, ctx, has_smi);
754 rep->has_raw = MLX5_GET_PR(hca_vport_context, ctx, has_raw);
755 rep->policy = MLX5_GET_PR(hca_vport_context, ctx, vport_state_policy);
756 rep->phys_state = MLX5_GET_PR(hca_vport_context, ctx,
757 port_physical_state);
758 rep->vport_state = MLX5_GET_PR(hca_vport_context, ctx, vport_state);
759 rep->port_physical_state = MLX5_GET_PR(hca_vport_context, ctx,
760 port_physical_state);
761 rep->port_guid = MLX5_GET64_PR(hca_vport_context, ctx, port_guid);
762 rep->node_guid = MLX5_GET64_PR(hca_vport_context, ctx, node_guid);
763 rep->cap_mask1 = MLX5_GET_PR(hca_vport_context, ctx, cap_mask1);
764 rep->cap_mask1_perm = MLX5_GET_PR(hca_vport_context, ctx,
765 cap_mask1_field_select);
766 rep->cap_mask2 = MLX5_GET_PR(hca_vport_context, ctx, cap_mask2);
767 rep->cap_mask2_perm = MLX5_GET_PR(hca_vport_context, ctx,
768 cap_mask2_field_select);
769 rep->lid = MLX5_GET_PR(hca_vport_context, ctx, lid);
770 rep->init_type_reply = MLX5_GET_PR(hca_vport_context, ctx,
772 rep->lmc = MLX5_GET_PR(hca_vport_context, ctx, lmc);
773 rep->subnet_timeout = MLX5_GET_PR(hca_vport_context, ctx,
775 rep->sm_lid = MLX5_GET_PR(hca_vport_context, ctx, sm_lid);
776 rep->sm_sl = MLX5_GET_PR(hca_vport_context, ctx, sm_sl);
777 rep->qkey_violation_counter = MLX5_GET_PR(hca_vport_context, ctx,
778 qkey_violation_counter);
779 rep->pkey_violation_counter = MLX5_GET_PR(hca_vport_context, ctx,
780 pkey_violation_counter);
781 rep->grh_required = MLX5_GET_PR(hca_vport_context, ctx, grh_required);
782 rep->sys_image_guid = MLX5_GET64_PR(hca_vport_context, ctx,
789 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_context);
791 int mlx5_query_hca_vport_system_image_guid(struct mlx5_core_dev *dev,
794 struct mlx5_hca_vport_context *rep;
797 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
801 err = mlx5_query_hca_vport_context(dev, 0, 1, 0, rep);
803 *sys_image_guid = rep->sys_image_guid;
808 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_system_image_guid);
810 int mlx5_query_hca_vport_node_guid(struct mlx5_core_dev *dev,
813 struct mlx5_hca_vport_context *rep;
816 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
820 err = mlx5_query_hca_vport_context(dev, 0, 1, 0, rep);
822 *node_guid = rep->node_guid;
827 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_node_guid);
829 int mlx5_query_nic_vport_promisc(struct mlx5_core_dev *mdev,
836 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
839 out = kzalloc(outlen, GFP_KERNEL);
843 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
847 *promisc_uc = MLX5_GET(query_nic_vport_context_out, out,
848 nic_vport_context.promisc_uc);
849 *promisc_mc = MLX5_GET(query_nic_vport_context_out, out,
850 nic_vport_context.promisc_mc);
851 *promisc_all = MLX5_GET(query_nic_vport_context_out, out,
852 nic_vport_context.promisc_all);
858 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_promisc);
860 int mlx5_modify_nic_vport_promisc(struct mlx5_core_dev *mdev,
866 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
869 in = kvzalloc(inlen, GFP_KERNEL);
873 MLX5_SET(modify_nic_vport_context_in, in, field_select.promisc, 1);
874 MLX5_SET(modify_nic_vport_context_in, in,
875 nic_vport_context.promisc_uc, promisc_uc);
876 MLX5_SET(modify_nic_vport_context_in, in,
877 nic_vport_context.promisc_mc, promisc_mc);
878 MLX5_SET(modify_nic_vport_context_in, in,
879 nic_vport_context.promisc_all, promisc_all);
881 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
887 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_promisc);
894 int mlx5_nic_vport_update_local_lb(struct mlx5_core_dev *mdev, bool enable)
896 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
900 if (!MLX5_CAP_GEN(mdev, disable_local_lb_mc) &&
901 !MLX5_CAP_GEN(mdev, disable_local_lb_uc))
904 in = kvzalloc(inlen, GFP_KERNEL);
908 MLX5_SET(modify_nic_vport_context_in, in,
909 nic_vport_context.disable_mc_local_lb, !enable);
910 MLX5_SET(modify_nic_vport_context_in, in,
911 nic_vport_context.disable_uc_local_lb, !enable);
913 if (MLX5_CAP_GEN(mdev, disable_local_lb_mc))
914 MLX5_SET(modify_nic_vport_context_in, in,
915 field_select.disable_mc_local_lb, 1);
917 if (MLX5_CAP_GEN(mdev, disable_local_lb_uc))
918 MLX5_SET(modify_nic_vport_context_in, in,
919 field_select.disable_uc_local_lb, 1);
921 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
924 mlx5_core_dbg(mdev, "%s local_lb\n",
925 enable ? "enable" : "disable");
930 EXPORT_SYMBOL_GPL(mlx5_nic_vport_update_local_lb);
932 int mlx5_nic_vport_query_local_lb(struct mlx5_core_dev *mdev, bool *status)
934 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
939 out = kzalloc(outlen, GFP_KERNEL);
943 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
947 value = MLX5_GET(query_nic_vport_context_out, out,
948 nic_vport_context.disable_mc_local_lb) << MC_LOCAL_LB;
950 value |= MLX5_GET(query_nic_vport_context_out, out,
951 nic_vport_context.disable_uc_local_lb) << UC_LOCAL_LB;
959 EXPORT_SYMBOL_GPL(mlx5_nic_vport_query_local_lb);
961 enum mlx5_vport_roce_state {
962 MLX5_VPORT_ROCE_DISABLED = 0,
963 MLX5_VPORT_ROCE_ENABLED = 1,
966 static int mlx5_nic_vport_update_roce_state(struct mlx5_core_dev *mdev,
967 enum mlx5_vport_roce_state state)
970 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
973 in = kvzalloc(inlen, GFP_KERNEL);
977 MLX5_SET(modify_nic_vport_context_in, in, field_select.roce_en, 1);
978 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.roce_en,
981 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
988 int mlx5_nic_vport_enable_roce(struct mlx5_core_dev *mdev)
992 mutex_lock(&mlx5_roce_en_lock);
993 if (!mdev->roce.roce_en)
994 err = mlx5_nic_vport_update_roce_state(mdev, MLX5_VPORT_ROCE_ENABLED);
997 mdev->roce.roce_en++;
998 mutex_unlock(&mlx5_roce_en_lock);
1002 EXPORT_SYMBOL_GPL(mlx5_nic_vport_enable_roce);
1004 int mlx5_nic_vport_disable_roce(struct mlx5_core_dev *mdev)
1008 mutex_lock(&mlx5_roce_en_lock);
1009 if (mdev->roce.roce_en) {
1010 mdev->roce.roce_en--;
1011 if (mdev->roce.roce_en == 0)
1012 err = mlx5_nic_vport_update_roce_state(mdev, MLX5_VPORT_ROCE_DISABLED);
1015 mdev->roce.roce_en++;
1017 mutex_unlock(&mlx5_roce_en_lock);
1020 EXPORT_SYMBOL_GPL(mlx5_nic_vport_disable_roce);
1022 int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport,
1023 int vf, u8 port_num, void *out,
1026 int in_sz = MLX5_ST_SZ_BYTES(query_vport_counter_in);
1027 int is_group_manager;
1031 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1032 in = kvzalloc(in_sz, GFP_KERNEL);
1038 MLX5_SET(query_vport_counter_in, in, opcode,
1039 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
1041 if (is_group_manager) {
1042 MLX5_SET(query_vport_counter_in, in, other_vport, 1);
1043 MLX5_SET(query_vport_counter_in, in, vport_number, vf + 1);
1049 if (MLX5_CAP_GEN(dev, num_ports) == 2)
1050 MLX5_SET(query_vport_counter_in, in, port_num, port_num);
1052 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
1057 EXPORT_SYMBOL_GPL(mlx5_core_query_vport_counter);
1059 int mlx5_query_vport_down_stats(struct mlx5_core_dev *mdev, u16 vport,
1060 u64 *rx_discard_vport_down,
1061 u64 *tx_discard_vport_down)
1063 u32 out[MLX5_ST_SZ_DW(query_vnic_env_out)] = {0};
1064 u32 in[MLX5_ST_SZ_DW(query_vnic_env_in)] = {0};
1067 MLX5_SET(query_vnic_env_in, in, opcode,
1068 MLX5_CMD_OP_QUERY_VNIC_ENV);
1069 MLX5_SET(query_vnic_env_in, in, op_mod, 0);
1070 MLX5_SET(query_vnic_env_in, in, vport_number, vport);
1072 MLX5_SET(query_vnic_env_in, in, other_vport, 1);
1074 err = mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
1078 *rx_discard_vport_down = MLX5_GET64(query_vnic_env_out, out,
1079 vport_env.receive_discard_vport_down);
1080 *tx_discard_vport_down = MLX5_GET64(query_vnic_env_out, out,
1081 vport_env.transmit_discard_vport_down);
1085 int mlx5_core_modify_hca_vport_context(struct mlx5_core_dev *dev,
1086 u8 other_vport, u8 port_num,
1088 struct mlx5_hca_vport_context *req)
1090 int in_sz = MLX5_ST_SZ_BYTES(modify_hca_vport_context_in);
1091 u8 out[MLX5_ST_SZ_BYTES(modify_hca_vport_context_out)];
1092 int is_group_manager;
1097 mlx5_core_dbg(dev, "vf %d\n", vf);
1098 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1099 in = kzalloc(in_sz, GFP_KERNEL);
1103 memset(out, 0, sizeof(out));
1104 MLX5_SET(modify_hca_vport_context_in, in, opcode, MLX5_CMD_OP_MODIFY_HCA_VPORT_CONTEXT);
1106 if (is_group_manager) {
1107 MLX5_SET(modify_hca_vport_context_in, in, other_vport, 1);
1108 MLX5_SET(modify_hca_vport_context_in, in, vport_number, vf);
1115 if (MLX5_CAP_GEN(dev, num_ports) > 1)
1116 MLX5_SET(modify_hca_vport_context_in, in, port_num, port_num);
1118 ctx = MLX5_ADDR_OF(modify_hca_vport_context_in, in, hca_vport_context);
1119 MLX5_SET(hca_vport_context, ctx, field_select, req->field_select);
1120 MLX5_SET(hca_vport_context, ctx, sm_virt_aware, req->sm_virt_aware);
1121 MLX5_SET(hca_vport_context, ctx, has_smi, req->has_smi);
1122 MLX5_SET(hca_vport_context, ctx, has_raw, req->has_raw);
1123 MLX5_SET(hca_vport_context, ctx, vport_state_policy, req->policy);
1124 MLX5_SET(hca_vport_context, ctx, port_physical_state, req->phys_state);
1125 MLX5_SET(hca_vport_context, ctx, vport_state, req->vport_state);
1126 MLX5_SET64(hca_vport_context, ctx, port_guid, req->port_guid);
1127 MLX5_SET64(hca_vport_context, ctx, node_guid, req->node_guid);
1128 MLX5_SET(hca_vport_context, ctx, cap_mask1, req->cap_mask1);
1129 MLX5_SET(hca_vport_context, ctx, cap_mask1_field_select, req->cap_mask1_perm);
1130 MLX5_SET(hca_vport_context, ctx, cap_mask2, req->cap_mask2);
1131 MLX5_SET(hca_vport_context, ctx, cap_mask2_field_select, req->cap_mask2_perm);
1132 MLX5_SET(hca_vport_context, ctx, lid, req->lid);
1133 MLX5_SET(hca_vport_context, ctx, init_type_reply, req->init_type_reply);
1134 MLX5_SET(hca_vport_context, ctx, lmc, req->lmc);
1135 MLX5_SET(hca_vport_context, ctx, subnet_timeout, req->subnet_timeout);
1136 MLX5_SET(hca_vport_context, ctx, sm_lid, req->sm_lid);
1137 MLX5_SET(hca_vport_context, ctx, sm_sl, req->sm_sl);
1138 MLX5_SET(hca_vport_context, ctx, qkey_violation_counter, req->qkey_violation_counter);
1139 MLX5_SET(hca_vport_context, ctx, pkey_violation_counter, req->pkey_violation_counter);
1140 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
1145 EXPORT_SYMBOL_GPL(mlx5_core_modify_hca_vport_context);
1147 int mlx5_nic_vport_affiliate_multiport(struct mlx5_core_dev *master_mdev,
1148 struct mlx5_core_dev *port_mdev)
1150 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
1154 in = kvzalloc(inlen, GFP_KERNEL);
1158 err = mlx5_nic_vport_enable_roce(port_mdev);
1162 MLX5_SET(modify_nic_vport_context_in, in, field_select.affiliation, 1);
1163 MLX5_SET(modify_nic_vport_context_in, in,
1164 nic_vport_context.affiliated_vhca_id,
1165 MLX5_CAP_GEN(master_mdev, vhca_id));
1166 MLX5_SET(modify_nic_vport_context_in, in,
1167 nic_vport_context.affiliation_criteria,
1168 MLX5_CAP_GEN(port_mdev, affiliate_nic_vport_criteria));
1170 err = mlx5_modify_nic_vport_context(port_mdev, in, inlen);
1172 mlx5_nic_vport_disable_roce(port_mdev);
1178 EXPORT_SYMBOL_GPL(mlx5_nic_vport_affiliate_multiport);
1180 int mlx5_nic_vport_unaffiliate_multiport(struct mlx5_core_dev *port_mdev)
1182 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
1186 in = kvzalloc(inlen, GFP_KERNEL);
1190 MLX5_SET(modify_nic_vport_context_in, in, field_select.affiliation, 1);
1191 MLX5_SET(modify_nic_vport_context_in, in,
1192 nic_vport_context.affiliated_vhca_id, 0);
1193 MLX5_SET(modify_nic_vport_context_in, in,
1194 nic_vport_context.affiliation_criteria, 0);
1196 err = mlx5_modify_nic_vport_context(port_mdev, in, inlen);
1198 mlx5_nic_vport_disable_roce(port_mdev);
1203 EXPORT_SYMBOL_GPL(mlx5_nic_vport_unaffiliate_multiport);