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 static int _mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod,
40 u16 vport, u32 *out, int outlen)
42 u32 in[MLX5_ST_SZ_DW(query_vport_state_in)] = {0};
44 MLX5_SET(query_vport_state_in, in, opcode,
45 MLX5_CMD_OP_QUERY_VPORT_STATE);
46 MLX5_SET(query_vport_state_in, in, op_mod, opmod);
47 MLX5_SET(query_vport_state_in, in, vport_number, vport);
49 MLX5_SET(query_vport_state_in, in, other_vport, 1);
51 return mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
54 u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport)
56 u32 out[MLX5_ST_SZ_DW(query_vport_state_out)] = {0};
58 _mlx5_query_vport_state(mdev, opmod, vport, out, sizeof(out));
60 return MLX5_GET(query_vport_state_out, out, state);
62 EXPORT_SYMBOL_GPL(mlx5_query_vport_state);
64 u8 mlx5_query_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport)
66 u32 out[MLX5_ST_SZ_DW(query_vport_state_out)] = {0};
68 _mlx5_query_vport_state(mdev, opmod, vport, out, sizeof(out));
70 return MLX5_GET(query_vport_state_out, out, admin_state);
72 EXPORT_SYMBOL_GPL(mlx5_query_vport_admin_state);
74 int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
77 u32 in[MLX5_ST_SZ_DW(modify_vport_state_in)] = {0};
78 u32 out[MLX5_ST_SZ_DW(modify_vport_state_out)] = {0};
80 MLX5_SET(modify_vport_state_in, in, opcode,
81 MLX5_CMD_OP_MODIFY_VPORT_STATE);
82 MLX5_SET(modify_vport_state_in, in, op_mod, opmod);
83 MLX5_SET(modify_vport_state_in, in, vport_number, vport);
85 MLX5_SET(modify_vport_state_in, in, other_vport, 1);
86 MLX5_SET(modify_vport_state_in, in, admin_state, state);
88 return mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
90 EXPORT_SYMBOL_GPL(mlx5_modify_vport_admin_state);
92 static int mlx5_query_nic_vport_context(struct mlx5_core_dev *mdev, u16 vport,
95 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
97 MLX5_SET(query_nic_vport_context_in, in, opcode,
98 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
99 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
101 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
103 return mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
106 static int mlx5_modify_nic_vport_context(struct mlx5_core_dev *mdev, void *in,
109 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)] = {0};
111 MLX5_SET(modify_nic_vport_context_in, in, opcode,
112 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
113 return mlx5_cmd_exec(mdev, in, inlen, out, sizeof(out));
116 int mlx5_query_nic_vport_min_inline(struct mlx5_core_dev *mdev,
117 u16 vport, u8 *min_inline)
119 u32 out[MLX5_ST_SZ_DW(query_nic_vport_context_out)] = {0};
122 err = mlx5_query_nic_vport_context(mdev, vport, out, sizeof(out));
124 *min_inline = MLX5_GET(query_nic_vport_context_out, out,
125 nic_vport_context.min_wqe_inline_mode);
128 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_min_inline);
130 void mlx5_query_min_inline(struct mlx5_core_dev *mdev,
133 switch (MLX5_CAP_ETH(mdev, wqe_inline_mode)) {
134 case MLX5_CAP_INLINE_MODE_L2:
135 *min_inline_mode = MLX5_INLINE_MODE_L2;
137 case MLX5_CAP_INLINE_MODE_VPORT_CONTEXT:
138 mlx5_query_nic_vport_min_inline(mdev, 0, min_inline_mode);
140 case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
141 *min_inline_mode = MLX5_INLINE_MODE_NONE;
145 EXPORT_SYMBOL_GPL(mlx5_query_min_inline);
147 int mlx5_modify_nic_vport_min_inline(struct mlx5_core_dev *mdev,
148 u16 vport, u8 min_inline)
150 u32 in[MLX5_ST_SZ_DW(modify_nic_vport_context_in)] = {0};
151 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
154 MLX5_SET(modify_nic_vport_context_in, in,
155 field_select.min_inline, 1);
156 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
157 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
159 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
160 in, nic_vport_context);
161 MLX5_SET(nic_vport_context, nic_vport_ctx,
162 min_wqe_inline_mode, min_inline);
164 return mlx5_modify_nic_vport_context(mdev, in, inlen);
167 int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
171 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
175 out = kvzalloc(outlen, GFP_KERNEL);
179 out_addr = MLX5_ADDR_OF(query_nic_vport_context_out, out,
180 nic_vport_context.permanent_address);
182 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
184 ether_addr_copy(addr, &out_addr[2]);
189 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_address);
191 int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *mdev,
195 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
200 in = kvzalloc(inlen, GFP_KERNEL);
204 MLX5_SET(modify_nic_vport_context_in, in,
205 field_select.permanent_address, 1);
206 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
209 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
211 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
212 in, nic_vport_context);
213 perm_mac = MLX5_ADDR_OF(nic_vport_context, nic_vport_ctx,
216 ether_addr_copy(&perm_mac[2], addr);
218 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
224 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_address);
226 int mlx5_query_nic_vport_mtu(struct mlx5_core_dev *mdev, u16 *mtu)
228 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
232 out = kvzalloc(outlen, GFP_KERNEL);
236 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
238 *mtu = MLX5_GET(query_nic_vport_context_out, out,
239 nic_vport_context.mtu);
244 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mtu);
246 int mlx5_modify_nic_vport_mtu(struct mlx5_core_dev *mdev, u16 mtu)
248 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
252 in = kvzalloc(inlen, GFP_KERNEL);
256 MLX5_SET(modify_nic_vport_context_in, in, field_select.mtu, 1);
257 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.mtu, mtu);
259 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
264 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mtu);
266 int mlx5_query_nic_vport_mac_list(struct mlx5_core_dev *dev,
268 enum mlx5_list_type list_type,
269 u8 addr_list[][ETH_ALEN],
272 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
281 req_list_size = *list_size;
283 max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
284 1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
285 1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
287 if (req_list_size > max_list_size) {
288 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max_list_size\n",
289 req_list_size, max_list_size);
290 req_list_size = max_list_size;
293 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
294 req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
296 out = kzalloc(out_sz, GFP_KERNEL);
300 MLX5_SET(query_nic_vport_context_in, in, opcode,
301 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
302 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type, list_type);
303 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
306 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
308 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
312 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
314 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
317 *list_size = req_list_size;
318 for (i = 0; i < req_list_size; i++) {
319 u8 *mac_addr = MLX5_ADDR_OF(nic_vport_context,
321 current_uc_mac_address[i]) + 2;
322 ether_addr_copy(addr_list[i], mac_addr);
328 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_list);
330 int mlx5_modify_nic_vport_mac_list(struct mlx5_core_dev *dev,
331 enum mlx5_list_type list_type,
332 u8 addr_list[][ETH_ALEN],
335 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
343 max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
344 1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
345 1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
347 if (list_size > max_list_size)
350 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
351 list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
353 memset(out, 0, sizeof(out));
354 in = kzalloc(in_sz, GFP_KERNEL);
358 MLX5_SET(modify_nic_vport_context_in, in, opcode,
359 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
360 MLX5_SET(modify_nic_vport_context_in, in,
361 field_select.addresses_list, 1);
363 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
366 MLX5_SET(nic_vport_context, nic_vport_ctx,
367 allowed_list_type, list_type);
368 MLX5_SET(nic_vport_context, nic_vport_ctx,
369 allowed_list_size, list_size);
371 for (i = 0; i < list_size; i++) {
372 u8 *curr_mac = MLX5_ADDR_OF(nic_vport_context,
374 current_uc_mac_address[i]) + 2;
375 ether_addr_copy(curr_mac, addr_list[i]);
378 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
382 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_list);
384 int mlx5_query_nic_vport_vlans(struct mlx5_core_dev *dev,
389 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)];
398 req_list_size = *size;
399 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
400 if (req_list_size > max_list_size) {
401 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max list size\n",
402 req_list_size, max_list_size);
403 req_list_size = max_list_size;
406 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
407 req_list_size * MLX5_ST_SZ_BYTES(vlan_layout);
409 memset(in, 0, sizeof(in));
410 out = kzalloc(out_sz, GFP_KERNEL);
414 MLX5_SET(query_nic_vport_context_in, in, opcode,
415 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
416 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type,
417 MLX5_NVPRT_LIST_TYPE_VLAN);
418 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
421 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
423 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
427 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
429 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
432 *size = req_list_size;
433 for (i = 0; i < req_list_size; i++) {
434 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
436 current_uc_mac_address[i]);
437 vlans[i] = MLX5_GET(vlan_layout, vlan_addr, vlan);
443 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_vlans);
445 int mlx5_modify_nic_vport_vlans(struct mlx5_core_dev *dev,
449 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
457 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
459 if (list_size > max_list_size)
462 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
463 list_size * MLX5_ST_SZ_BYTES(vlan_layout);
465 memset(out, 0, sizeof(out));
466 in = kzalloc(in_sz, GFP_KERNEL);
470 MLX5_SET(modify_nic_vport_context_in, in, opcode,
471 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
472 MLX5_SET(modify_nic_vport_context_in, in,
473 field_select.addresses_list, 1);
475 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
478 MLX5_SET(nic_vport_context, nic_vport_ctx,
479 allowed_list_type, MLX5_NVPRT_LIST_TYPE_VLAN);
480 MLX5_SET(nic_vport_context, nic_vport_ctx,
481 allowed_list_size, list_size);
483 for (i = 0; i < list_size; i++) {
484 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
486 current_uc_mac_address[i]);
487 MLX5_SET(vlan_layout, vlan_addr, vlan, vlans[i]);
490 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
494 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_vlans);
496 int mlx5_query_nic_vport_system_image_guid(struct mlx5_core_dev *mdev,
497 u64 *system_image_guid)
500 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
502 out = kvzalloc(outlen, GFP_KERNEL);
506 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
508 *system_image_guid = MLX5_GET64(query_nic_vport_context_out, out,
509 nic_vport_context.system_image_guid);
515 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_system_image_guid);
517 int mlx5_query_nic_vport_node_guid(struct mlx5_core_dev *mdev, u64 *node_guid)
520 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
522 out = kvzalloc(outlen, GFP_KERNEL);
526 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
528 *node_guid = MLX5_GET64(query_nic_vport_context_out, out,
529 nic_vport_context.node_guid);
535 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_node_guid);
537 int mlx5_modify_nic_vport_node_guid(struct mlx5_core_dev *mdev,
538 u32 vport, u64 node_guid)
540 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
541 void *nic_vport_context;
547 if (!MLX5_CAP_GEN(mdev, vport_group_manager))
549 if (!MLX5_CAP_ESW(mdev, nic_vport_node_guid_modify))
552 in = kvzalloc(inlen, GFP_KERNEL);
556 MLX5_SET(modify_nic_vport_context_in, in,
557 field_select.node_guid, 1);
558 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
559 MLX5_SET(modify_nic_vport_context_in, in, other_vport, !!vport);
561 nic_vport_context = MLX5_ADDR_OF(modify_nic_vport_context_in,
562 in, nic_vport_context);
563 MLX5_SET64(nic_vport_context, nic_vport_context, node_guid, node_guid);
565 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
572 int mlx5_query_nic_vport_qkey_viol_cntr(struct mlx5_core_dev *mdev,
576 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
578 out = kvzalloc(outlen, GFP_KERNEL);
582 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
584 *qkey_viol_cntr = MLX5_GET(query_nic_vport_context_out, out,
585 nic_vport_context.qkey_violation_counter);
591 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_qkey_viol_cntr);
593 int mlx5_query_hca_vport_gid(struct mlx5_core_dev *dev, u8 other_vport,
594 u8 port_num, u16 vf_num, u16 gid_index,
597 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_in);
598 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_out);
599 int is_group_manager;
607 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
608 tbsz = mlx5_get_gid_table_len(MLX5_CAP_GEN(dev, gid_table_size));
609 mlx5_core_dbg(dev, "vf_num %d, index %d, gid_table_size %d\n",
610 vf_num, gid_index, tbsz);
612 if (gid_index > tbsz && gid_index != 0xffff)
615 if (gid_index == 0xffff)
620 out_sz += nout * sizeof(*gid);
622 in = kzalloc(in_sz, GFP_KERNEL);
623 out = kzalloc(out_sz, GFP_KERNEL);
629 MLX5_SET(query_hca_vport_gid_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_GID);
631 if (is_group_manager) {
632 MLX5_SET(query_hca_vport_gid_in, in, vport_number, vf_num);
633 MLX5_SET(query_hca_vport_gid_in, in, other_vport, 1);
639 MLX5_SET(query_hca_vport_gid_in, in, gid_index, gid_index);
641 if (MLX5_CAP_GEN(dev, num_ports) == 2)
642 MLX5_SET(query_hca_vport_gid_in, in, port_num, port_num);
644 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
648 tmp = out + MLX5_ST_SZ_BYTES(query_hca_vport_gid_out);
649 gid->global.subnet_prefix = tmp->global.subnet_prefix;
650 gid->global.interface_id = tmp->global.interface_id;
657 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_gid);
659 int mlx5_query_hca_vport_pkey(struct mlx5_core_dev *dev, u8 other_vport,
660 u8 port_num, u16 vf_num, u16 pkey_index,
663 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_in);
664 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_out);
665 int is_group_manager;
674 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
676 tbsz = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(dev, pkey_table_size));
677 if (pkey_index > tbsz && pkey_index != 0xffff)
680 if (pkey_index == 0xffff)
685 out_sz += nout * MLX5_ST_SZ_BYTES(pkey);
687 in = kzalloc(in_sz, GFP_KERNEL);
688 out = kzalloc(out_sz, GFP_KERNEL);
694 MLX5_SET(query_hca_vport_pkey_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_PKEY);
696 if (is_group_manager) {
697 MLX5_SET(query_hca_vport_pkey_in, in, vport_number, vf_num);
698 MLX5_SET(query_hca_vport_pkey_in, in, other_vport, 1);
704 MLX5_SET(query_hca_vport_pkey_in, in, pkey_index, pkey_index);
706 if (MLX5_CAP_GEN(dev, num_ports) == 2)
707 MLX5_SET(query_hca_vport_pkey_in, in, port_num, port_num);
709 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
713 pkarr = MLX5_ADDR_OF(query_hca_vport_pkey_out, out, pkey);
714 for (i = 0; i < nout; i++, pkey++, pkarr += MLX5_ST_SZ_BYTES(pkey))
715 *pkey = MLX5_GET_PR(pkey, pkarr, pkey);
722 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_pkey);
724 int mlx5_query_hca_vport_context(struct mlx5_core_dev *dev,
725 u8 other_vport, u8 port_num,
727 struct mlx5_hca_vport_context *rep)
729 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_context_out);
730 int in[MLX5_ST_SZ_DW(query_hca_vport_context_in)] = {0};
731 int is_group_manager;
736 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
738 out = kzalloc(out_sz, GFP_KERNEL);
742 MLX5_SET(query_hca_vport_context_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_CONTEXT);
745 if (is_group_manager) {
746 MLX5_SET(query_hca_vport_context_in, in, other_vport, 1);
747 MLX5_SET(query_hca_vport_context_in, in, vport_number, vf_num);
754 if (MLX5_CAP_GEN(dev, num_ports) == 2)
755 MLX5_SET(query_hca_vport_context_in, in, port_num, port_num);
757 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
761 ctx = MLX5_ADDR_OF(query_hca_vport_context_out, out, hca_vport_context);
762 rep->field_select = MLX5_GET_PR(hca_vport_context, ctx, field_select);
763 rep->sm_virt_aware = MLX5_GET_PR(hca_vport_context, ctx, sm_virt_aware);
764 rep->has_smi = MLX5_GET_PR(hca_vport_context, ctx, has_smi);
765 rep->has_raw = MLX5_GET_PR(hca_vport_context, ctx, has_raw);
766 rep->policy = MLX5_GET_PR(hca_vport_context, ctx, vport_state_policy);
767 rep->phys_state = MLX5_GET_PR(hca_vport_context, ctx,
768 port_physical_state);
769 rep->vport_state = MLX5_GET_PR(hca_vport_context, ctx, vport_state);
770 rep->port_physical_state = MLX5_GET_PR(hca_vport_context, ctx,
771 port_physical_state);
772 rep->port_guid = MLX5_GET64_PR(hca_vport_context, ctx, port_guid);
773 rep->node_guid = MLX5_GET64_PR(hca_vport_context, ctx, node_guid);
774 rep->cap_mask1 = MLX5_GET_PR(hca_vport_context, ctx, cap_mask1);
775 rep->cap_mask1_perm = MLX5_GET_PR(hca_vport_context, ctx,
776 cap_mask1_field_select);
777 rep->cap_mask2 = MLX5_GET_PR(hca_vport_context, ctx, cap_mask2);
778 rep->cap_mask2_perm = MLX5_GET_PR(hca_vport_context, ctx,
779 cap_mask2_field_select);
780 rep->lid = MLX5_GET_PR(hca_vport_context, ctx, lid);
781 rep->init_type_reply = MLX5_GET_PR(hca_vport_context, ctx,
783 rep->lmc = MLX5_GET_PR(hca_vport_context, ctx, lmc);
784 rep->subnet_timeout = MLX5_GET_PR(hca_vport_context, ctx,
786 rep->sm_lid = MLX5_GET_PR(hca_vport_context, ctx, sm_lid);
787 rep->sm_sl = MLX5_GET_PR(hca_vport_context, ctx, sm_sl);
788 rep->qkey_violation_counter = MLX5_GET_PR(hca_vport_context, ctx,
789 qkey_violation_counter);
790 rep->pkey_violation_counter = MLX5_GET_PR(hca_vport_context, ctx,
791 pkey_violation_counter);
792 rep->grh_required = MLX5_GET_PR(hca_vport_context, ctx, grh_required);
793 rep->sys_image_guid = MLX5_GET64_PR(hca_vport_context, ctx,
800 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_context);
802 int mlx5_query_hca_vport_system_image_guid(struct mlx5_core_dev *dev,
805 struct mlx5_hca_vport_context *rep;
808 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
812 err = mlx5_query_hca_vport_context(dev, 0, 1, 0, rep);
814 *sys_image_guid = rep->sys_image_guid;
819 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_system_image_guid);
821 int mlx5_query_hca_vport_node_guid(struct mlx5_core_dev *dev,
824 struct mlx5_hca_vport_context *rep;
827 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
831 err = mlx5_query_hca_vport_context(dev, 0, 1, 0, rep);
833 *node_guid = rep->node_guid;
838 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_node_guid);
840 int mlx5_query_nic_vport_promisc(struct mlx5_core_dev *mdev,
847 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
850 out = kzalloc(outlen, GFP_KERNEL);
854 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
858 *promisc_uc = MLX5_GET(query_nic_vport_context_out, out,
859 nic_vport_context.promisc_uc);
860 *promisc_mc = MLX5_GET(query_nic_vport_context_out, out,
861 nic_vport_context.promisc_mc);
862 *promisc_all = MLX5_GET(query_nic_vport_context_out, out,
863 nic_vport_context.promisc_all);
869 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_promisc);
871 int mlx5_modify_nic_vport_promisc(struct mlx5_core_dev *mdev,
877 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
880 in = kvzalloc(inlen, GFP_KERNEL);
884 MLX5_SET(modify_nic_vport_context_in, in, field_select.promisc, 1);
885 MLX5_SET(modify_nic_vport_context_in, in,
886 nic_vport_context.promisc_uc, promisc_uc);
887 MLX5_SET(modify_nic_vport_context_in, in,
888 nic_vport_context.promisc_mc, promisc_mc);
889 MLX5_SET(modify_nic_vport_context_in, in,
890 nic_vport_context.promisc_all, promisc_all);
892 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
898 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_promisc);
905 int mlx5_nic_vport_update_local_lb(struct mlx5_core_dev *mdev, bool enable)
907 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
911 mlx5_core_dbg(mdev, "%s local_lb\n", enable ? "enable" : "disable");
912 in = kvzalloc(inlen, GFP_KERNEL);
916 MLX5_SET(modify_nic_vport_context_in, in,
917 field_select.disable_mc_local_lb, 1);
918 MLX5_SET(modify_nic_vport_context_in, in,
919 nic_vport_context.disable_mc_local_lb, !enable);
921 MLX5_SET(modify_nic_vport_context_in, in,
922 field_select.disable_uc_local_lb, 1);
923 MLX5_SET(modify_nic_vport_context_in, in,
924 nic_vport_context.disable_uc_local_lb, !enable);
926 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
931 EXPORT_SYMBOL_GPL(mlx5_nic_vport_update_local_lb);
933 int mlx5_nic_vport_query_local_lb(struct mlx5_core_dev *mdev, bool *status)
935 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
940 out = kzalloc(outlen, GFP_KERNEL);
944 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
948 value = MLX5_GET(query_nic_vport_context_out, out,
949 nic_vport_context.disable_mc_local_lb) << MC_LOCAL_LB;
951 value |= MLX5_GET(query_nic_vport_context_out, out,
952 nic_vport_context.disable_uc_local_lb) << UC_LOCAL_LB;
960 EXPORT_SYMBOL_GPL(mlx5_nic_vport_query_local_lb);
962 enum mlx5_vport_roce_state {
963 MLX5_VPORT_ROCE_DISABLED = 0,
964 MLX5_VPORT_ROCE_ENABLED = 1,
967 static int mlx5_nic_vport_update_roce_state(struct mlx5_core_dev *mdev,
968 enum mlx5_vport_roce_state state)
971 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
974 in = kvzalloc(inlen, GFP_KERNEL);
978 MLX5_SET(modify_nic_vport_context_in, in, field_select.roce_en, 1);
979 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.roce_en,
982 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
989 int mlx5_nic_vport_enable_roce(struct mlx5_core_dev *mdev)
991 if (atomic_inc_return(&mdev->roce.roce_en) != 1)
993 return mlx5_nic_vport_update_roce_state(mdev, MLX5_VPORT_ROCE_ENABLED);
995 EXPORT_SYMBOL_GPL(mlx5_nic_vport_enable_roce);
997 int mlx5_nic_vport_disable_roce(struct mlx5_core_dev *mdev)
999 if (atomic_dec_return(&mdev->roce.roce_en) != 0)
1001 return mlx5_nic_vport_update_roce_state(mdev, MLX5_VPORT_ROCE_DISABLED);
1003 EXPORT_SYMBOL_GPL(mlx5_nic_vport_disable_roce);
1005 int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport,
1006 int vf, u8 port_num, void *out,
1009 int in_sz = MLX5_ST_SZ_BYTES(query_vport_counter_in);
1010 int is_group_manager;
1014 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1015 in = kvzalloc(in_sz, GFP_KERNEL);
1021 MLX5_SET(query_vport_counter_in, in, opcode,
1022 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
1024 if (is_group_manager) {
1025 MLX5_SET(query_vport_counter_in, in, other_vport, 1);
1026 MLX5_SET(query_vport_counter_in, in, vport_number, vf + 1);
1032 if (MLX5_CAP_GEN(dev, num_ports) == 2)
1033 MLX5_SET(query_vport_counter_in, in, port_num, port_num);
1035 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
1040 EXPORT_SYMBOL_GPL(mlx5_core_query_vport_counter);
1042 int mlx5_core_modify_hca_vport_context(struct mlx5_core_dev *dev,
1043 u8 other_vport, u8 port_num,
1045 struct mlx5_hca_vport_context *req)
1047 int in_sz = MLX5_ST_SZ_BYTES(modify_hca_vport_context_in);
1048 u8 out[MLX5_ST_SZ_BYTES(modify_hca_vport_context_out)];
1049 int is_group_manager;
1054 mlx5_core_dbg(dev, "vf %d\n", vf);
1055 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1056 in = kzalloc(in_sz, GFP_KERNEL);
1060 memset(out, 0, sizeof(out));
1061 MLX5_SET(modify_hca_vport_context_in, in, opcode, MLX5_CMD_OP_MODIFY_HCA_VPORT_CONTEXT);
1063 if (is_group_manager) {
1064 MLX5_SET(modify_hca_vport_context_in, in, other_vport, 1);
1065 MLX5_SET(modify_hca_vport_context_in, in, vport_number, vf);
1072 if (MLX5_CAP_GEN(dev, num_ports) > 1)
1073 MLX5_SET(modify_hca_vport_context_in, in, port_num, port_num);
1075 ctx = MLX5_ADDR_OF(modify_hca_vport_context_in, in, hca_vport_context);
1076 MLX5_SET(hca_vport_context, ctx, field_select, req->field_select);
1077 MLX5_SET(hca_vport_context, ctx, sm_virt_aware, req->sm_virt_aware);
1078 MLX5_SET(hca_vport_context, ctx, has_smi, req->has_smi);
1079 MLX5_SET(hca_vport_context, ctx, has_raw, req->has_raw);
1080 MLX5_SET(hca_vport_context, ctx, vport_state_policy, req->policy);
1081 MLX5_SET(hca_vport_context, ctx, port_physical_state, req->phys_state);
1082 MLX5_SET(hca_vport_context, ctx, vport_state, req->vport_state);
1083 MLX5_SET64(hca_vport_context, ctx, port_guid, req->port_guid);
1084 MLX5_SET64(hca_vport_context, ctx, node_guid, req->node_guid);
1085 MLX5_SET(hca_vport_context, ctx, cap_mask1, req->cap_mask1);
1086 MLX5_SET(hca_vport_context, ctx, cap_mask1_field_select, req->cap_mask1_perm);
1087 MLX5_SET(hca_vport_context, ctx, cap_mask2, req->cap_mask2);
1088 MLX5_SET(hca_vport_context, ctx, cap_mask2_field_select, req->cap_mask2_perm);
1089 MLX5_SET(hca_vport_context, ctx, lid, req->lid);
1090 MLX5_SET(hca_vport_context, ctx, init_type_reply, req->init_type_reply);
1091 MLX5_SET(hca_vport_context, ctx, lmc, req->lmc);
1092 MLX5_SET(hca_vport_context, ctx, subnet_timeout, req->subnet_timeout);
1093 MLX5_SET(hca_vport_context, ctx, sm_lid, req->sm_lid);
1094 MLX5_SET(hca_vport_context, ctx, sm_sl, req->sm_sl);
1095 MLX5_SET(hca_vport_context, ctx, qkey_violation_counter, req->qkey_violation_counter);
1096 MLX5_SET(hca_vport_context, ctx, pkey_violation_counter, req->pkey_violation_counter);
1097 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
1102 EXPORT_SYMBOL_GPL(mlx5_core_modify_hca_vport_context);