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);
65 EXPORT_SYMBOL_GPL(mlx5_query_vport_state);
67 u8 mlx5_query_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport)
69 u32 out[MLX5_ST_SZ_DW(query_vport_state_out)] = {0};
71 _mlx5_query_vport_state(mdev, opmod, vport, out, sizeof(out));
73 return MLX5_GET(query_vport_state_out, out, admin_state);
75 EXPORT_SYMBOL_GPL(mlx5_query_vport_admin_state);
77 int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
80 u32 in[MLX5_ST_SZ_DW(modify_vport_state_in)] = {0};
81 u32 out[MLX5_ST_SZ_DW(modify_vport_state_out)] = {0};
83 MLX5_SET(modify_vport_state_in, in, opcode,
84 MLX5_CMD_OP_MODIFY_VPORT_STATE);
85 MLX5_SET(modify_vport_state_in, in, op_mod, opmod);
86 MLX5_SET(modify_vport_state_in, in, vport_number, vport);
88 MLX5_SET(modify_vport_state_in, in, other_vport, 1);
89 MLX5_SET(modify_vport_state_in, in, admin_state, state);
91 return mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
93 EXPORT_SYMBOL_GPL(mlx5_modify_vport_admin_state);
95 static int mlx5_query_nic_vport_context(struct mlx5_core_dev *mdev, u16 vport,
98 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
100 MLX5_SET(query_nic_vport_context_in, in, opcode,
101 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
102 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
104 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
106 return mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
109 static int mlx5_modify_nic_vport_context(struct mlx5_core_dev *mdev, void *in,
112 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)] = {0};
114 MLX5_SET(modify_nic_vport_context_in, in, opcode,
115 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
116 return mlx5_cmd_exec(mdev, in, inlen, out, sizeof(out));
119 int mlx5_query_nic_vport_min_inline(struct mlx5_core_dev *mdev,
120 u16 vport, u8 *min_inline)
122 u32 out[MLX5_ST_SZ_DW(query_nic_vport_context_out)] = {0};
125 err = mlx5_query_nic_vport_context(mdev, vport, out, sizeof(out));
127 *min_inline = MLX5_GET(query_nic_vport_context_out, out,
128 nic_vport_context.min_wqe_inline_mode);
131 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_min_inline);
133 void mlx5_query_min_inline(struct mlx5_core_dev *mdev,
136 switch (MLX5_CAP_ETH(mdev, wqe_inline_mode)) {
137 case MLX5_CAP_INLINE_MODE_L2:
138 *min_inline_mode = MLX5_INLINE_MODE_L2;
140 case MLX5_CAP_INLINE_MODE_VPORT_CONTEXT:
141 mlx5_query_nic_vport_min_inline(mdev, 0, min_inline_mode);
143 case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
144 *min_inline_mode = MLX5_INLINE_MODE_NONE;
148 EXPORT_SYMBOL_GPL(mlx5_query_min_inline);
150 int mlx5_modify_nic_vport_min_inline(struct mlx5_core_dev *mdev,
151 u16 vport, u8 min_inline)
153 u32 in[MLX5_ST_SZ_DW(modify_nic_vport_context_in)] = {0};
154 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
157 MLX5_SET(modify_nic_vport_context_in, in,
158 field_select.min_inline, 1);
159 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
160 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
162 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
163 in, nic_vport_context);
164 MLX5_SET(nic_vport_context, nic_vport_ctx,
165 min_wqe_inline_mode, min_inline);
167 return mlx5_modify_nic_vport_context(mdev, in, inlen);
170 int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
174 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
178 out = kvzalloc(outlen, GFP_KERNEL);
182 out_addr = MLX5_ADDR_OF(query_nic_vport_context_out, out,
183 nic_vport_context.permanent_address);
185 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
187 ether_addr_copy(addr, &out_addr[2]);
192 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_address);
194 int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *mdev,
198 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
203 in = kvzalloc(inlen, GFP_KERNEL);
207 MLX5_SET(modify_nic_vport_context_in, in,
208 field_select.permanent_address, 1);
209 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
212 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
214 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
215 in, nic_vport_context);
216 perm_mac = MLX5_ADDR_OF(nic_vport_context, nic_vport_ctx,
219 ether_addr_copy(&perm_mac[2], addr);
221 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
227 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_address);
229 int mlx5_query_nic_vport_mtu(struct mlx5_core_dev *mdev, u16 *mtu)
231 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
235 out = kvzalloc(outlen, GFP_KERNEL);
239 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
241 *mtu = MLX5_GET(query_nic_vport_context_out, out,
242 nic_vport_context.mtu);
247 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mtu);
249 int mlx5_modify_nic_vport_mtu(struct mlx5_core_dev *mdev, u16 mtu)
251 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
255 in = kvzalloc(inlen, GFP_KERNEL);
259 MLX5_SET(modify_nic_vport_context_in, in, field_select.mtu, 1);
260 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.mtu, mtu);
262 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
267 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mtu);
269 int mlx5_query_nic_vport_mac_list(struct mlx5_core_dev *dev,
271 enum mlx5_list_type list_type,
272 u8 addr_list[][ETH_ALEN],
275 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
284 req_list_size = *list_size;
286 max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
287 1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
288 1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
290 if (req_list_size > max_list_size) {
291 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max_list_size\n",
292 req_list_size, max_list_size);
293 req_list_size = max_list_size;
296 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
297 req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
299 out = kzalloc(out_sz, GFP_KERNEL);
303 MLX5_SET(query_nic_vport_context_in, in, opcode,
304 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
305 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type, list_type);
306 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
309 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
311 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
315 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
317 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
320 *list_size = req_list_size;
321 for (i = 0; i < req_list_size; i++) {
322 u8 *mac_addr = MLX5_ADDR_OF(nic_vport_context,
324 current_uc_mac_address[i]) + 2;
325 ether_addr_copy(addr_list[i], mac_addr);
331 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_list);
333 int mlx5_modify_nic_vport_mac_list(struct mlx5_core_dev *dev,
334 enum mlx5_list_type list_type,
335 u8 addr_list[][ETH_ALEN],
338 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
346 max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
347 1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
348 1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
350 if (list_size > max_list_size)
353 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
354 list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
356 memset(out, 0, sizeof(out));
357 in = kzalloc(in_sz, GFP_KERNEL);
361 MLX5_SET(modify_nic_vport_context_in, in, opcode,
362 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
363 MLX5_SET(modify_nic_vport_context_in, in,
364 field_select.addresses_list, 1);
366 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
369 MLX5_SET(nic_vport_context, nic_vport_ctx,
370 allowed_list_type, list_type);
371 MLX5_SET(nic_vport_context, nic_vport_ctx,
372 allowed_list_size, list_size);
374 for (i = 0; i < list_size; i++) {
375 u8 *curr_mac = MLX5_ADDR_OF(nic_vport_context,
377 current_uc_mac_address[i]) + 2;
378 ether_addr_copy(curr_mac, addr_list[i]);
381 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
385 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_list);
387 int mlx5_query_nic_vport_vlans(struct mlx5_core_dev *dev,
392 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)];
401 req_list_size = *size;
402 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
403 if (req_list_size > max_list_size) {
404 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max list size\n",
405 req_list_size, max_list_size);
406 req_list_size = max_list_size;
409 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
410 req_list_size * MLX5_ST_SZ_BYTES(vlan_layout);
412 memset(in, 0, sizeof(in));
413 out = kzalloc(out_sz, GFP_KERNEL);
417 MLX5_SET(query_nic_vport_context_in, in, opcode,
418 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
419 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type,
420 MLX5_NVPRT_LIST_TYPE_VLAN);
421 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
424 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
426 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
430 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
432 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
435 *size = req_list_size;
436 for (i = 0; i < req_list_size; i++) {
437 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
439 current_uc_mac_address[i]);
440 vlans[i] = MLX5_GET(vlan_layout, vlan_addr, vlan);
446 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_vlans);
448 int mlx5_modify_nic_vport_vlans(struct mlx5_core_dev *dev,
452 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
460 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
462 if (list_size > max_list_size)
465 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
466 list_size * MLX5_ST_SZ_BYTES(vlan_layout);
468 memset(out, 0, sizeof(out));
469 in = kzalloc(in_sz, GFP_KERNEL);
473 MLX5_SET(modify_nic_vport_context_in, in, opcode,
474 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
475 MLX5_SET(modify_nic_vport_context_in, in,
476 field_select.addresses_list, 1);
478 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
481 MLX5_SET(nic_vport_context, nic_vport_ctx,
482 allowed_list_type, MLX5_NVPRT_LIST_TYPE_VLAN);
483 MLX5_SET(nic_vport_context, nic_vport_ctx,
484 allowed_list_size, list_size);
486 for (i = 0; i < list_size; i++) {
487 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
489 current_uc_mac_address[i]);
490 MLX5_SET(vlan_layout, vlan_addr, vlan, vlans[i]);
493 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
497 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_vlans);
499 int mlx5_query_nic_vport_system_image_guid(struct mlx5_core_dev *mdev,
500 u64 *system_image_guid)
503 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
505 out = kvzalloc(outlen, GFP_KERNEL);
509 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
511 *system_image_guid = MLX5_GET64(query_nic_vport_context_out, out,
512 nic_vport_context.system_image_guid);
518 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_system_image_guid);
520 int mlx5_query_nic_vport_node_guid(struct mlx5_core_dev *mdev, u64 *node_guid)
523 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
525 out = kvzalloc(outlen, GFP_KERNEL);
529 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
531 *node_guid = MLX5_GET64(query_nic_vport_context_out, out,
532 nic_vport_context.node_guid);
538 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_node_guid);
540 int mlx5_modify_nic_vport_node_guid(struct mlx5_core_dev *mdev,
541 u32 vport, u64 node_guid)
543 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
544 void *nic_vport_context;
550 if (!MLX5_CAP_GEN(mdev, vport_group_manager))
553 in = kvzalloc(inlen, GFP_KERNEL);
557 MLX5_SET(modify_nic_vport_context_in, in,
558 field_select.node_guid, 1);
559 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
560 MLX5_SET(modify_nic_vport_context_in, in, other_vport, !!vport);
562 nic_vport_context = MLX5_ADDR_OF(modify_nic_vport_context_in,
563 in, nic_vport_context);
564 MLX5_SET64(nic_vport_context, nic_vport_context, node_guid, node_guid);
566 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
573 int mlx5_query_nic_vport_qkey_viol_cntr(struct mlx5_core_dev *mdev,
577 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
579 out = kvzalloc(outlen, GFP_KERNEL);
583 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
585 *qkey_viol_cntr = MLX5_GET(query_nic_vport_context_out, out,
586 nic_vport_context.qkey_violation_counter);
592 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_qkey_viol_cntr);
594 int mlx5_query_hca_vport_gid(struct mlx5_core_dev *dev, u8 other_vport,
595 u8 port_num, u16 vf_num, u16 gid_index,
598 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_in);
599 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_out);
600 int is_group_manager;
608 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
609 tbsz = mlx5_get_gid_table_len(MLX5_CAP_GEN(dev, gid_table_size));
610 mlx5_core_dbg(dev, "vf_num %d, index %d, gid_table_size %d\n",
611 vf_num, gid_index, tbsz);
613 if (gid_index > tbsz && gid_index != 0xffff)
616 if (gid_index == 0xffff)
621 out_sz += nout * sizeof(*gid);
623 in = kzalloc(in_sz, GFP_KERNEL);
624 out = kzalloc(out_sz, GFP_KERNEL);
630 MLX5_SET(query_hca_vport_gid_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_GID);
632 if (is_group_manager) {
633 MLX5_SET(query_hca_vport_gid_in, in, vport_number, vf_num);
634 MLX5_SET(query_hca_vport_gid_in, in, other_vport, 1);
640 MLX5_SET(query_hca_vport_gid_in, in, gid_index, gid_index);
642 if (MLX5_CAP_GEN(dev, num_ports) == 2)
643 MLX5_SET(query_hca_vport_gid_in, in, port_num, port_num);
645 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
649 tmp = out + MLX5_ST_SZ_BYTES(query_hca_vport_gid_out);
650 gid->global.subnet_prefix = tmp->global.subnet_prefix;
651 gid->global.interface_id = tmp->global.interface_id;
658 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_gid);
660 int mlx5_query_hca_vport_pkey(struct mlx5_core_dev *dev, u8 other_vport,
661 u8 port_num, u16 vf_num, u16 pkey_index,
664 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_in);
665 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_out);
666 int is_group_manager;
675 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
677 tbsz = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(dev, pkey_table_size));
678 if (pkey_index > tbsz && pkey_index != 0xffff)
681 if (pkey_index == 0xffff)
686 out_sz += nout * MLX5_ST_SZ_BYTES(pkey);
688 in = kzalloc(in_sz, GFP_KERNEL);
689 out = kzalloc(out_sz, GFP_KERNEL);
695 MLX5_SET(query_hca_vport_pkey_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_PKEY);
697 if (is_group_manager) {
698 MLX5_SET(query_hca_vport_pkey_in, in, vport_number, vf_num);
699 MLX5_SET(query_hca_vport_pkey_in, in, other_vport, 1);
705 MLX5_SET(query_hca_vport_pkey_in, in, pkey_index, pkey_index);
707 if (MLX5_CAP_GEN(dev, num_ports) == 2)
708 MLX5_SET(query_hca_vport_pkey_in, in, port_num, port_num);
710 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
714 pkarr = MLX5_ADDR_OF(query_hca_vport_pkey_out, out, pkey);
715 for (i = 0; i < nout; i++, pkey++, pkarr += MLX5_ST_SZ_BYTES(pkey))
716 *pkey = MLX5_GET_PR(pkey, pkarr, pkey);
723 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_pkey);
725 int mlx5_query_hca_vport_context(struct mlx5_core_dev *dev,
726 u8 other_vport, u8 port_num,
728 struct mlx5_hca_vport_context *rep)
730 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_context_out);
731 int in[MLX5_ST_SZ_DW(query_hca_vport_context_in)] = {0};
732 int is_group_manager;
737 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
739 out = kzalloc(out_sz, GFP_KERNEL);
743 MLX5_SET(query_hca_vport_context_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_CONTEXT);
746 if (is_group_manager) {
747 MLX5_SET(query_hca_vport_context_in, in, other_vport, 1);
748 MLX5_SET(query_hca_vport_context_in, in, vport_number, vf_num);
755 if (MLX5_CAP_GEN(dev, num_ports) == 2)
756 MLX5_SET(query_hca_vport_context_in, in, port_num, port_num);
758 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
762 ctx = MLX5_ADDR_OF(query_hca_vport_context_out, out, hca_vport_context);
763 rep->field_select = MLX5_GET_PR(hca_vport_context, ctx, field_select);
764 rep->sm_virt_aware = MLX5_GET_PR(hca_vport_context, ctx, sm_virt_aware);
765 rep->has_smi = MLX5_GET_PR(hca_vport_context, ctx, has_smi);
766 rep->has_raw = MLX5_GET_PR(hca_vport_context, ctx, has_raw);
767 rep->policy = MLX5_GET_PR(hca_vport_context, ctx, vport_state_policy);
768 rep->phys_state = MLX5_GET_PR(hca_vport_context, ctx,
769 port_physical_state);
770 rep->vport_state = MLX5_GET_PR(hca_vport_context, ctx, vport_state);
771 rep->port_physical_state = MLX5_GET_PR(hca_vport_context, ctx,
772 port_physical_state);
773 rep->port_guid = MLX5_GET64_PR(hca_vport_context, ctx, port_guid);
774 rep->node_guid = MLX5_GET64_PR(hca_vport_context, ctx, node_guid);
775 rep->cap_mask1 = MLX5_GET_PR(hca_vport_context, ctx, cap_mask1);
776 rep->cap_mask1_perm = MLX5_GET_PR(hca_vport_context, ctx,
777 cap_mask1_field_select);
778 rep->cap_mask2 = MLX5_GET_PR(hca_vport_context, ctx, cap_mask2);
779 rep->cap_mask2_perm = MLX5_GET_PR(hca_vport_context, ctx,
780 cap_mask2_field_select);
781 rep->lid = MLX5_GET_PR(hca_vport_context, ctx, lid);
782 rep->init_type_reply = MLX5_GET_PR(hca_vport_context, ctx,
784 rep->lmc = MLX5_GET_PR(hca_vport_context, ctx, lmc);
785 rep->subnet_timeout = MLX5_GET_PR(hca_vport_context, ctx,
787 rep->sm_lid = MLX5_GET_PR(hca_vport_context, ctx, sm_lid);
788 rep->sm_sl = MLX5_GET_PR(hca_vport_context, ctx, sm_sl);
789 rep->qkey_violation_counter = MLX5_GET_PR(hca_vport_context, ctx,
790 qkey_violation_counter);
791 rep->pkey_violation_counter = MLX5_GET_PR(hca_vport_context, ctx,
792 pkey_violation_counter);
793 rep->grh_required = MLX5_GET_PR(hca_vport_context, ctx, grh_required);
794 rep->sys_image_guid = MLX5_GET64_PR(hca_vport_context, ctx,
801 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_context);
803 int mlx5_query_hca_vport_system_image_guid(struct mlx5_core_dev *dev,
806 struct mlx5_hca_vport_context *rep;
809 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
813 err = mlx5_query_hca_vport_context(dev, 0, 1, 0, rep);
815 *sys_image_guid = rep->sys_image_guid;
820 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_system_image_guid);
822 int mlx5_query_hca_vport_node_guid(struct mlx5_core_dev *dev,
825 struct mlx5_hca_vport_context *rep;
828 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
832 err = mlx5_query_hca_vport_context(dev, 0, 1, 0, rep);
834 *node_guid = rep->node_guid;
839 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_node_guid);
841 int mlx5_query_nic_vport_promisc(struct mlx5_core_dev *mdev,
848 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
851 out = kzalloc(outlen, GFP_KERNEL);
855 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
859 *promisc_uc = MLX5_GET(query_nic_vport_context_out, out,
860 nic_vport_context.promisc_uc);
861 *promisc_mc = MLX5_GET(query_nic_vport_context_out, out,
862 nic_vport_context.promisc_mc);
863 *promisc_all = MLX5_GET(query_nic_vport_context_out, out,
864 nic_vport_context.promisc_all);
870 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_promisc);
872 int mlx5_modify_nic_vport_promisc(struct mlx5_core_dev *mdev,
878 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
881 in = kvzalloc(inlen, GFP_KERNEL);
885 MLX5_SET(modify_nic_vport_context_in, in, field_select.promisc, 1);
886 MLX5_SET(modify_nic_vport_context_in, in,
887 nic_vport_context.promisc_uc, promisc_uc);
888 MLX5_SET(modify_nic_vport_context_in, in,
889 nic_vport_context.promisc_mc, promisc_mc);
890 MLX5_SET(modify_nic_vport_context_in, in,
891 nic_vport_context.promisc_all, promisc_all);
893 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
899 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_promisc);
906 int mlx5_nic_vport_update_local_lb(struct mlx5_core_dev *mdev, bool enable)
908 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
912 if (!MLX5_CAP_GEN(mdev, disable_local_lb_mc) &&
913 !MLX5_CAP_GEN(mdev, disable_local_lb_uc))
916 in = kvzalloc(inlen, GFP_KERNEL);
920 MLX5_SET(modify_nic_vport_context_in, in,
921 nic_vport_context.disable_mc_local_lb, !enable);
922 MLX5_SET(modify_nic_vport_context_in, in,
923 nic_vport_context.disable_uc_local_lb, !enable);
925 if (MLX5_CAP_GEN(mdev, disable_local_lb_mc))
926 MLX5_SET(modify_nic_vport_context_in, in,
927 field_select.disable_mc_local_lb, 1);
929 if (MLX5_CAP_GEN(mdev, disable_local_lb_uc))
930 MLX5_SET(modify_nic_vport_context_in, in,
931 field_select.disable_uc_local_lb, 1);
933 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
936 mlx5_core_dbg(mdev, "%s local_lb\n",
937 enable ? "enable" : "disable");
942 EXPORT_SYMBOL_GPL(mlx5_nic_vport_update_local_lb);
944 int mlx5_nic_vport_query_local_lb(struct mlx5_core_dev *mdev, bool *status)
946 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
951 out = kzalloc(outlen, GFP_KERNEL);
955 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
959 value = MLX5_GET(query_nic_vport_context_out, out,
960 nic_vport_context.disable_mc_local_lb) << MC_LOCAL_LB;
962 value |= MLX5_GET(query_nic_vport_context_out, out,
963 nic_vport_context.disable_uc_local_lb) << UC_LOCAL_LB;
971 EXPORT_SYMBOL_GPL(mlx5_nic_vport_query_local_lb);
973 enum mlx5_vport_roce_state {
974 MLX5_VPORT_ROCE_DISABLED = 0,
975 MLX5_VPORT_ROCE_ENABLED = 1,
978 static int mlx5_nic_vport_update_roce_state(struct mlx5_core_dev *mdev,
979 enum mlx5_vport_roce_state state)
982 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
985 in = kvzalloc(inlen, GFP_KERNEL);
989 MLX5_SET(modify_nic_vport_context_in, in, field_select.roce_en, 1);
990 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.roce_en,
993 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
1000 int mlx5_nic_vport_enable_roce(struct mlx5_core_dev *mdev)
1004 mutex_lock(&mlx5_roce_en_lock);
1005 if (!mdev->roce.roce_en)
1006 err = mlx5_nic_vport_update_roce_state(mdev, MLX5_VPORT_ROCE_ENABLED);
1009 mdev->roce.roce_en++;
1010 mutex_unlock(&mlx5_roce_en_lock);
1014 EXPORT_SYMBOL_GPL(mlx5_nic_vport_enable_roce);
1016 int mlx5_nic_vport_disable_roce(struct mlx5_core_dev *mdev)
1020 mutex_lock(&mlx5_roce_en_lock);
1021 if (mdev->roce.roce_en) {
1022 mdev->roce.roce_en--;
1023 if (mdev->roce.roce_en == 0)
1024 err = mlx5_nic_vport_update_roce_state(mdev, MLX5_VPORT_ROCE_DISABLED);
1027 mdev->roce.roce_en++;
1029 mutex_unlock(&mlx5_roce_en_lock);
1032 EXPORT_SYMBOL_GPL(mlx5_nic_vport_disable_roce);
1034 int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport,
1035 int vf, u8 port_num, void *out,
1038 int in_sz = MLX5_ST_SZ_BYTES(query_vport_counter_in);
1039 int is_group_manager;
1043 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1044 in = kvzalloc(in_sz, GFP_KERNEL);
1050 MLX5_SET(query_vport_counter_in, in, opcode,
1051 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
1053 if (is_group_manager) {
1054 MLX5_SET(query_vport_counter_in, in, other_vport, 1);
1055 MLX5_SET(query_vport_counter_in, in, vport_number, vf + 1);
1061 if (MLX5_CAP_GEN(dev, num_ports) == 2)
1062 MLX5_SET(query_vport_counter_in, in, port_num, port_num);
1064 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
1069 EXPORT_SYMBOL_GPL(mlx5_core_query_vport_counter);
1071 int mlx5_query_vport_down_stats(struct mlx5_core_dev *mdev, u16 vport,
1072 u64 *rx_discard_vport_down,
1073 u64 *tx_discard_vport_down)
1075 u32 out[MLX5_ST_SZ_DW(query_vnic_env_out)] = {0};
1076 u32 in[MLX5_ST_SZ_DW(query_vnic_env_in)] = {0};
1079 MLX5_SET(query_vnic_env_in, in, opcode,
1080 MLX5_CMD_OP_QUERY_VNIC_ENV);
1081 MLX5_SET(query_vnic_env_in, in, op_mod, 0);
1082 MLX5_SET(query_vnic_env_in, in, vport_number, vport);
1084 MLX5_SET(query_vnic_env_in, in, other_vport, 1);
1086 err = mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
1090 *rx_discard_vport_down = MLX5_GET64(query_vnic_env_out, out,
1091 vport_env.receive_discard_vport_down);
1092 *tx_discard_vport_down = MLX5_GET64(query_vnic_env_out, out,
1093 vport_env.transmit_discard_vport_down);
1097 int mlx5_core_modify_hca_vport_context(struct mlx5_core_dev *dev,
1098 u8 other_vport, u8 port_num,
1100 struct mlx5_hca_vport_context *req)
1102 int in_sz = MLX5_ST_SZ_BYTES(modify_hca_vport_context_in);
1103 u8 out[MLX5_ST_SZ_BYTES(modify_hca_vport_context_out)];
1104 int is_group_manager;
1109 mlx5_core_dbg(dev, "vf %d\n", vf);
1110 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1111 in = kzalloc(in_sz, GFP_KERNEL);
1115 memset(out, 0, sizeof(out));
1116 MLX5_SET(modify_hca_vport_context_in, in, opcode, MLX5_CMD_OP_MODIFY_HCA_VPORT_CONTEXT);
1118 if (is_group_manager) {
1119 MLX5_SET(modify_hca_vport_context_in, in, other_vport, 1);
1120 MLX5_SET(modify_hca_vport_context_in, in, vport_number, vf);
1127 if (MLX5_CAP_GEN(dev, num_ports) > 1)
1128 MLX5_SET(modify_hca_vport_context_in, in, port_num, port_num);
1130 ctx = MLX5_ADDR_OF(modify_hca_vport_context_in, in, hca_vport_context);
1131 MLX5_SET(hca_vport_context, ctx, field_select, req->field_select);
1132 MLX5_SET(hca_vport_context, ctx, sm_virt_aware, req->sm_virt_aware);
1133 MLX5_SET(hca_vport_context, ctx, has_smi, req->has_smi);
1134 MLX5_SET(hca_vport_context, ctx, has_raw, req->has_raw);
1135 MLX5_SET(hca_vport_context, ctx, vport_state_policy, req->policy);
1136 MLX5_SET(hca_vport_context, ctx, port_physical_state, req->phys_state);
1137 MLX5_SET(hca_vport_context, ctx, vport_state, req->vport_state);
1138 MLX5_SET64(hca_vport_context, ctx, port_guid, req->port_guid);
1139 MLX5_SET64(hca_vport_context, ctx, node_guid, req->node_guid);
1140 MLX5_SET(hca_vport_context, ctx, cap_mask1, req->cap_mask1);
1141 MLX5_SET(hca_vport_context, ctx, cap_mask1_field_select, req->cap_mask1_perm);
1142 MLX5_SET(hca_vport_context, ctx, cap_mask2, req->cap_mask2);
1143 MLX5_SET(hca_vport_context, ctx, cap_mask2_field_select, req->cap_mask2_perm);
1144 MLX5_SET(hca_vport_context, ctx, lid, req->lid);
1145 MLX5_SET(hca_vport_context, ctx, init_type_reply, req->init_type_reply);
1146 MLX5_SET(hca_vport_context, ctx, lmc, req->lmc);
1147 MLX5_SET(hca_vport_context, ctx, subnet_timeout, req->subnet_timeout);
1148 MLX5_SET(hca_vport_context, ctx, sm_lid, req->sm_lid);
1149 MLX5_SET(hca_vport_context, ctx, sm_sl, req->sm_sl);
1150 MLX5_SET(hca_vport_context, ctx, qkey_violation_counter, req->qkey_violation_counter);
1151 MLX5_SET(hca_vport_context, ctx, pkey_violation_counter, req->pkey_violation_counter);
1152 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
1157 EXPORT_SYMBOL_GPL(mlx5_core_modify_hca_vport_context);
1159 int mlx5_nic_vport_affiliate_multiport(struct mlx5_core_dev *master_mdev,
1160 struct mlx5_core_dev *port_mdev)
1162 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
1166 in = kvzalloc(inlen, GFP_KERNEL);
1170 err = mlx5_nic_vport_enable_roce(port_mdev);
1174 MLX5_SET(modify_nic_vport_context_in, in, field_select.affiliation, 1);
1175 MLX5_SET(modify_nic_vport_context_in, in,
1176 nic_vport_context.affiliated_vhca_id,
1177 MLX5_CAP_GEN(master_mdev, vhca_id));
1178 MLX5_SET(modify_nic_vport_context_in, in,
1179 nic_vport_context.affiliation_criteria,
1180 MLX5_CAP_GEN(port_mdev, affiliate_nic_vport_criteria));
1182 err = mlx5_modify_nic_vport_context(port_mdev, in, inlen);
1184 mlx5_nic_vport_disable_roce(port_mdev);
1190 EXPORT_SYMBOL_GPL(mlx5_nic_vport_affiliate_multiport);
1192 int mlx5_nic_vport_unaffiliate_multiport(struct mlx5_core_dev *port_mdev)
1194 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
1198 in = kvzalloc(inlen, GFP_KERNEL);
1202 MLX5_SET(modify_nic_vport_context_in, in, field_select.affiliation, 1);
1203 MLX5_SET(modify_nic_vport_context_in, in,
1204 nic_vport_context.affiliated_vhca_id, 0);
1205 MLX5_SET(modify_nic_vport_context_in, in,
1206 nic_vport_context.affiliation_criteria, 0);
1208 err = mlx5_modify_nic_vport_context(port_mdev, in, inlen);
1210 mlx5_nic_vport_disable_roce(port_mdev);
1215 EXPORT_SYMBOL_GPL(mlx5_nic_vport_unaffiliate_multiport);