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 void mlx5_query_nic_vport_min_inline(struct mlx5_core_dev *mdev,
119 u32 out[MLX5_ST_SZ_DW(query_nic_vport_context_out)] = {0};
121 mlx5_query_nic_vport_context(mdev, 0, out, sizeof(out));
123 *min_inline_mode = MLX5_GET(query_nic_vport_context_out, out,
124 nic_vport_context.min_wqe_inline_mode);
126 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_min_inline);
128 int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
132 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
136 out = mlx5_vzalloc(outlen);
140 out_addr = MLX5_ADDR_OF(query_nic_vport_context_out, out,
141 nic_vport_context.permanent_address);
143 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
145 ether_addr_copy(addr, &out_addr[2]);
150 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_address);
152 int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *mdev,
156 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
161 in = mlx5_vzalloc(inlen);
163 mlx5_core_warn(mdev, "failed to allocate inbox\n");
167 MLX5_SET(modify_nic_vport_context_in, in,
168 field_select.permanent_address, 1);
169 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
172 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
174 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
175 in, nic_vport_context);
176 perm_mac = MLX5_ADDR_OF(nic_vport_context, nic_vport_ctx,
179 ether_addr_copy(&perm_mac[2], addr);
181 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
187 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_address);
189 int mlx5_query_nic_vport_mtu(struct mlx5_core_dev *mdev, u16 *mtu)
191 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
195 out = mlx5_vzalloc(outlen);
199 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
201 *mtu = MLX5_GET(query_nic_vport_context_out, out,
202 nic_vport_context.mtu);
207 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mtu);
209 int mlx5_modify_nic_vport_mtu(struct mlx5_core_dev *mdev, u16 mtu)
211 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
215 in = mlx5_vzalloc(inlen);
219 MLX5_SET(modify_nic_vport_context_in, in, field_select.mtu, 1);
220 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.mtu, mtu);
222 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
227 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mtu);
229 int mlx5_query_nic_vport_mac_list(struct mlx5_core_dev *dev,
231 enum mlx5_list_type list_type,
232 u8 addr_list[][ETH_ALEN],
235 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
244 req_list_size = *list_size;
246 max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
247 1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
248 1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
250 if (req_list_size > max_list_size) {
251 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max_list_size\n",
252 req_list_size, max_list_size);
253 req_list_size = max_list_size;
256 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
257 req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
259 out = kzalloc(out_sz, GFP_KERNEL);
263 MLX5_SET(query_nic_vport_context_in, in, opcode,
264 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
265 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type, list_type);
266 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
269 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
271 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
275 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
277 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
280 *list_size = req_list_size;
281 for (i = 0; i < req_list_size; i++) {
282 u8 *mac_addr = MLX5_ADDR_OF(nic_vport_context,
284 current_uc_mac_address[i]) + 2;
285 ether_addr_copy(addr_list[i], mac_addr);
291 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_list);
293 int mlx5_modify_nic_vport_mac_list(struct mlx5_core_dev *dev,
294 enum mlx5_list_type list_type,
295 u8 addr_list[][ETH_ALEN],
298 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
306 max_list_size = list_type == MLX5_NVPRT_LIST_TYPE_UC ?
307 1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
308 1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
310 if (list_size > max_list_size)
313 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
314 list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
316 memset(out, 0, sizeof(out));
317 in = kzalloc(in_sz, GFP_KERNEL);
321 MLX5_SET(modify_nic_vport_context_in, in, opcode,
322 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
323 MLX5_SET(modify_nic_vport_context_in, in,
324 field_select.addresses_list, 1);
326 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
329 MLX5_SET(nic_vport_context, nic_vport_ctx,
330 allowed_list_type, list_type);
331 MLX5_SET(nic_vport_context, nic_vport_ctx,
332 allowed_list_size, list_size);
334 for (i = 0; i < list_size; i++) {
335 u8 *curr_mac = MLX5_ADDR_OF(nic_vport_context,
337 current_uc_mac_address[i]) + 2;
338 ether_addr_copy(curr_mac, addr_list[i]);
341 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
345 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_list);
347 int mlx5_query_nic_vport_vlans(struct mlx5_core_dev *dev,
352 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)];
361 req_list_size = *size;
362 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
363 if (req_list_size > max_list_size) {
364 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max list size\n",
365 req_list_size, max_list_size);
366 req_list_size = max_list_size;
369 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
370 req_list_size * MLX5_ST_SZ_BYTES(vlan_layout);
372 memset(in, 0, sizeof(in));
373 out = kzalloc(out_sz, GFP_KERNEL);
377 MLX5_SET(query_nic_vport_context_in, in, opcode,
378 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
379 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type,
380 MLX5_NVPRT_LIST_TYPE_VLAN);
381 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
384 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
386 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
390 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
392 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
395 *size = req_list_size;
396 for (i = 0; i < req_list_size; i++) {
397 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
399 current_uc_mac_address[i]);
400 vlans[i] = MLX5_GET(vlan_layout, vlan_addr, vlan);
406 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_vlans);
408 int mlx5_modify_nic_vport_vlans(struct mlx5_core_dev *dev,
412 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
420 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
422 if (list_size > max_list_size)
425 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
426 list_size * MLX5_ST_SZ_BYTES(vlan_layout);
428 memset(out, 0, sizeof(out));
429 in = kzalloc(in_sz, GFP_KERNEL);
433 MLX5_SET(modify_nic_vport_context_in, in, opcode,
434 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
435 MLX5_SET(modify_nic_vport_context_in, in,
436 field_select.addresses_list, 1);
438 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
441 MLX5_SET(nic_vport_context, nic_vport_ctx,
442 allowed_list_type, MLX5_NVPRT_LIST_TYPE_VLAN);
443 MLX5_SET(nic_vport_context, nic_vport_ctx,
444 allowed_list_size, list_size);
446 for (i = 0; i < list_size; i++) {
447 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
449 current_uc_mac_address[i]);
450 MLX5_SET(vlan_layout, vlan_addr, vlan, vlans[i]);
453 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
457 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_vlans);
459 int mlx5_query_nic_vport_system_image_guid(struct mlx5_core_dev *mdev,
460 u64 *system_image_guid)
463 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
465 out = mlx5_vzalloc(outlen);
469 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
471 *system_image_guid = MLX5_GET64(query_nic_vport_context_out, out,
472 nic_vport_context.system_image_guid);
478 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_system_image_guid);
480 int mlx5_query_nic_vport_node_guid(struct mlx5_core_dev *mdev, u64 *node_guid)
483 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
485 out = mlx5_vzalloc(outlen);
489 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
491 *node_guid = MLX5_GET64(query_nic_vport_context_out, out,
492 nic_vport_context.node_guid);
498 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_node_guid);
500 int mlx5_modify_nic_vport_node_guid(struct mlx5_core_dev *mdev,
501 u32 vport, u64 node_guid)
503 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
504 void *nic_vport_context;
510 if (!MLX5_CAP_GEN(mdev, vport_group_manager))
512 if (!MLX5_CAP_ESW(mdev, nic_vport_node_guid_modify))
515 in = mlx5_vzalloc(inlen);
519 MLX5_SET(modify_nic_vport_context_in, in,
520 field_select.node_guid, 1);
521 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
522 MLX5_SET(modify_nic_vport_context_in, in, other_vport, !!vport);
524 nic_vport_context = MLX5_ADDR_OF(modify_nic_vport_context_in,
525 in, nic_vport_context);
526 MLX5_SET64(nic_vport_context, nic_vport_context, node_guid, node_guid);
528 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
535 int mlx5_query_nic_vport_qkey_viol_cntr(struct mlx5_core_dev *mdev,
539 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
541 out = mlx5_vzalloc(outlen);
545 mlx5_query_nic_vport_context(mdev, 0, out, outlen);
547 *qkey_viol_cntr = MLX5_GET(query_nic_vport_context_out, out,
548 nic_vport_context.qkey_violation_counter);
554 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_qkey_viol_cntr);
556 int mlx5_query_hca_vport_gid(struct mlx5_core_dev *dev, u8 other_vport,
557 u8 port_num, u16 vf_num, u16 gid_index,
560 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_in);
561 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_out);
562 int is_group_manager;
570 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
571 tbsz = mlx5_get_gid_table_len(MLX5_CAP_GEN(dev, gid_table_size));
572 mlx5_core_dbg(dev, "vf_num %d, index %d, gid_table_size %d\n",
573 vf_num, gid_index, tbsz);
575 if (gid_index > tbsz && gid_index != 0xffff)
578 if (gid_index == 0xffff)
583 out_sz += nout * sizeof(*gid);
585 in = kzalloc(in_sz, GFP_KERNEL);
586 out = kzalloc(out_sz, GFP_KERNEL);
592 MLX5_SET(query_hca_vport_gid_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_GID);
594 if (is_group_manager) {
595 MLX5_SET(query_hca_vport_gid_in, in, vport_number, vf_num);
596 MLX5_SET(query_hca_vport_gid_in, in, other_vport, 1);
602 MLX5_SET(query_hca_vport_gid_in, in, gid_index, gid_index);
604 if (MLX5_CAP_GEN(dev, num_ports) == 2)
605 MLX5_SET(query_hca_vport_gid_in, in, port_num, port_num);
607 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
611 tmp = out + MLX5_ST_SZ_BYTES(query_hca_vport_gid_out);
612 gid->global.subnet_prefix = tmp->global.subnet_prefix;
613 gid->global.interface_id = tmp->global.interface_id;
620 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_gid);
622 int mlx5_query_hca_vport_pkey(struct mlx5_core_dev *dev, u8 other_vport,
623 u8 port_num, u16 vf_num, u16 pkey_index,
626 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_in);
627 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_out);
628 int is_group_manager;
637 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
639 tbsz = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(dev, pkey_table_size));
640 if (pkey_index > tbsz && pkey_index != 0xffff)
643 if (pkey_index == 0xffff)
648 out_sz += nout * MLX5_ST_SZ_BYTES(pkey);
650 in = kzalloc(in_sz, GFP_KERNEL);
651 out = kzalloc(out_sz, GFP_KERNEL);
657 MLX5_SET(query_hca_vport_pkey_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_PKEY);
659 if (is_group_manager) {
660 MLX5_SET(query_hca_vport_pkey_in, in, vport_number, vf_num);
661 MLX5_SET(query_hca_vport_pkey_in, in, other_vport, 1);
667 MLX5_SET(query_hca_vport_pkey_in, in, pkey_index, pkey_index);
669 if (MLX5_CAP_GEN(dev, num_ports) == 2)
670 MLX5_SET(query_hca_vport_pkey_in, in, port_num, port_num);
672 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
676 pkarr = MLX5_ADDR_OF(query_hca_vport_pkey_out, out, pkey);
677 for (i = 0; i < nout; i++, pkey++, pkarr += MLX5_ST_SZ_BYTES(pkey))
678 *pkey = MLX5_GET_PR(pkey, pkarr, pkey);
685 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_pkey);
687 int mlx5_query_hca_vport_context(struct mlx5_core_dev *dev,
688 u8 other_vport, u8 port_num,
690 struct mlx5_hca_vport_context *rep)
692 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_context_out);
693 int in[MLX5_ST_SZ_DW(query_hca_vport_context_in)] = {0};
694 int is_group_manager;
699 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
701 out = kzalloc(out_sz, GFP_KERNEL);
705 MLX5_SET(query_hca_vport_context_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_VPORT_CONTEXT);
708 if (is_group_manager) {
709 MLX5_SET(query_hca_vport_context_in, in, other_vport, 1);
710 MLX5_SET(query_hca_vport_context_in, in, vport_number, vf_num);
717 if (MLX5_CAP_GEN(dev, num_ports) == 2)
718 MLX5_SET(query_hca_vport_context_in, in, port_num, port_num);
720 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
724 ctx = MLX5_ADDR_OF(query_hca_vport_context_out, out, hca_vport_context);
725 rep->field_select = MLX5_GET_PR(hca_vport_context, ctx, field_select);
726 rep->sm_virt_aware = MLX5_GET_PR(hca_vport_context, ctx, sm_virt_aware);
727 rep->has_smi = MLX5_GET_PR(hca_vport_context, ctx, has_smi);
728 rep->has_raw = MLX5_GET_PR(hca_vport_context, ctx, has_raw);
729 rep->policy = MLX5_GET_PR(hca_vport_context, ctx, vport_state_policy);
730 rep->phys_state = MLX5_GET_PR(hca_vport_context, ctx,
731 port_physical_state);
732 rep->vport_state = MLX5_GET_PR(hca_vport_context, ctx, vport_state);
733 rep->port_physical_state = MLX5_GET_PR(hca_vport_context, ctx,
734 port_physical_state);
735 rep->port_guid = MLX5_GET64_PR(hca_vport_context, ctx, port_guid);
736 rep->node_guid = MLX5_GET64_PR(hca_vport_context, ctx, node_guid);
737 rep->cap_mask1 = MLX5_GET_PR(hca_vport_context, ctx, cap_mask1);
738 rep->cap_mask1_perm = MLX5_GET_PR(hca_vport_context, ctx,
739 cap_mask1_field_select);
740 rep->cap_mask2 = MLX5_GET_PR(hca_vport_context, ctx, cap_mask2);
741 rep->cap_mask2_perm = MLX5_GET_PR(hca_vport_context, ctx,
742 cap_mask2_field_select);
743 rep->lid = MLX5_GET_PR(hca_vport_context, ctx, lid);
744 rep->init_type_reply = MLX5_GET_PR(hca_vport_context, ctx,
746 rep->lmc = MLX5_GET_PR(hca_vport_context, ctx, lmc);
747 rep->subnet_timeout = MLX5_GET_PR(hca_vport_context, ctx,
749 rep->sm_lid = MLX5_GET_PR(hca_vport_context, ctx, sm_lid);
750 rep->sm_sl = MLX5_GET_PR(hca_vport_context, ctx, sm_sl);
751 rep->qkey_violation_counter = MLX5_GET_PR(hca_vport_context, ctx,
752 qkey_violation_counter);
753 rep->pkey_violation_counter = MLX5_GET_PR(hca_vport_context, ctx,
754 pkey_violation_counter);
755 rep->grh_required = MLX5_GET_PR(hca_vport_context, ctx, grh_required);
756 rep->sys_image_guid = MLX5_GET64_PR(hca_vport_context, ctx,
763 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_context);
765 int mlx5_query_hca_vport_system_image_guid(struct mlx5_core_dev *dev,
768 struct mlx5_hca_vport_context *rep;
771 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
775 err = mlx5_query_hca_vport_context(dev, 0, 1, 0, rep);
777 *sys_image_guid = rep->sys_image_guid;
782 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_system_image_guid);
784 int mlx5_query_hca_vport_node_guid(struct mlx5_core_dev *dev,
787 struct mlx5_hca_vport_context *rep;
790 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
794 err = mlx5_query_hca_vport_context(dev, 0, 1, 0, rep);
796 *node_guid = rep->node_guid;
801 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_node_guid);
803 int mlx5_query_nic_vport_promisc(struct mlx5_core_dev *mdev,
810 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
813 out = kzalloc(outlen, GFP_KERNEL);
817 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
821 *promisc_uc = MLX5_GET(query_nic_vport_context_out, out,
822 nic_vport_context.promisc_uc);
823 *promisc_mc = MLX5_GET(query_nic_vport_context_out, out,
824 nic_vport_context.promisc_mc);
825 *promisc_all = MLX5_GET(query_nic_vport_context_out, out,
826 nic_vport_context.promisc_all);
832 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_promisc);
834 int mlx5_modify_nic_vport_promisc(struct mlx5_core_dev *mdev,
840 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
843 in = mlx5_vzalloc(inlen);
845 mlx5_core_err(mdev, "failed to allocate inbox\n");
849 MLX5_SET(modify_nic_vport_context_in, in, field_select.promisc, 1);
850 MLX5_SET(modify_nic_vport_context_in, in,
851 nic_vport_context.promisc_uc, promisc_uc);
852 MLX5_SET(modify_nic_vport_context_in, in,
853 nic_vport_context.promisc_mc, promisc_mc);
854 MLX5_SET(modify_nic_vport_context_in, in,
855 nic_vport_context.promisc_all, promisc_all);
857 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
863 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_promisc);
865 enum mlx5_vport_roce_state {
866 MLX5_VPORT_ROCE_DISABLED = 0,
867 MLX5_VPORT_ROCE_ENABLED = 1,
870 static int mlx5_nic_vport_update_roce_state(struct mlx5_core_dev *mdev,
871 enum mlx5_vport_roce_state state)
874 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
877 in = mlx5_vzalloc(inlen);
879 mlx5_core_warn(mdev, "failed to allocate inbox\n");
883 MLX5_SET(modify_nic_vport_context_in, in, field_select.roce_en, 1);
884 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.roce_en,
887 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
894 int mlx5_nic_vport_enable_roce(struct mlx5_core_dev *mdev)
896 return mlx5_nic_vport_update_roce_state(mdev, MLX5_VPORT_ROCE_ENABLED);
898 EXPORT_SYMBOL_GPL(mlx5_nic_vport_enable_roce);
900 int mlx5_nic_vport_disable_roce(struct mlx5_core_dev *mdev)
902 return mlx5_nic_vport_update_roce_state(mdev, MLX5_VPORT_ROCE_DISABLED);
904 EXPORT_SYMBOL_GPL(mlx5_nic_vport_disable_roce);
906 int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport,
907 int vf, u8 port_num, void *out,
910 int in_sz = MLX5_ST_SZ_BYTES(query_vport_counter_in);
911 int is_group_manager;
915 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
916 in = mlx5_vzalloc(in_sz);
922 MLX5_SET(query_vport_counter_in, in, opcode,
923 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
925 if (is_group_manager) {
926 MLX5_SET(query_vport_counter_in, in, other_vport, 1);
927 MLX5_SET(query_vport_counter_in, in, vport_number, vf + 1);
933 if (MLX5_CAP_GEN(dev, num_ports) == 2)
934 MLX5_SET(query_vport_counter_in, in, port_num, port_num);
936 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
941 EXPORT_SYMBOL_GPL(mlx5_core_query_vport_counter);
943 int mlx5_core_modify_hca_vport_context(struct mlx5_core_dev *dev,
944 u8 other_vport, u8 port_num,
946 struct mlx5_hca_vport_context *req)
948 int in_sz = MLX5_ST_SZ_BYTES(modify_hca_vport_context_in);
949 u8 out[MLX5_ST_SZ_BYTES(modify_hca_vport_context_out)];
950 int is_group_manager;
955 mlx5_core_dbg(dev, "vf %d\n", vf);
956 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
957 in = kzalloc(in_sz, GFP_KERNEL);
961 memset(out, 0, sizeof(out));
962 MLX5_SET(modify_hca_vport_context_in, in, opcode, MLX5_CMD_OP_MODIFY_HCA_VPORT_CONTEXT);
964 if (is_group_manager) {
965 MLX5_SET(modify_hca_vport_context_in, in, other_vport, 1);
966 MLX5_SET(modify_hca_vport_context_in, in, vport_number, vf);
973 if (MLX5_CAP_GEN(dev, num_ports) > 1)
974 MLX5_SET(modify_hca_vport_context_in, in, port_num, port_num);
976 ctx = MLX5_ADDR_OF(modify_hca_vport_context_in, in, hca_vport_context);
977 MLX5_SET(hca_vport_context, ctx, field_select, req->field_select);
978 MLX5_SET(hca_vport_context, ctx, sm_virt_aware, req->sm_virt_aware);
979 MLX5_SET(hca_vport_context, ctx, has_smi, req->has_smi);
980 MLX5_SET(hca_vport_context, ctx, has_raw, req->has_raw);
981 MLX5_SET(hca_vport_context, ctx, vport_state_policy, req->policy);
982 MLX5_SET(hca_vport_context, ctx, port_physical_state, req->phys_state);
983 MLX5_SET(hca_vport_context, ctx, vport_state, req->vport_state);
984 MLX5_SET64(hca_vport_context, ctx, port_guid, req->port_guid);
985 MLX5_SET64(hca_vport_context, ctx, node_guid, req->node_guid);
986 MLX5_SET(hca_vport_context, ctx, cap_mask1, req->cap_mask1);
987 MLX5_SET(hca_vport_context, ctx, cap_mask1_field_select, req->cap_mask1_perm);
988 MLX5_SET(hca_vport_context, ctx, cap_mask2, req->cap_mask2);
989 MLX5_SET(hca_vport_context, ctx, cap_mask2_field_select, req->cap_mask2_perm);
990 MLX5_SET(hca_vport_context, ctx, lid, req->lid);
991 MLX5_SET(hca_vport_context, ctx, init_type_reply, req->init_type_reply);
992 MLX5_SET(hca_vport_context, ctx, lmc, req->lmc);
993 MLX5_SET(hca_vport_context, ctx, subnet_timeout, req->subnet_timeout);
994 MLX5_SET(hca_vport_context, ctx, sm_lid, req->sm_lid);
995 MLX5_SET(hca_vport_context, ctx, sm_sl, req->sm_sl);
996 MLX5_SET(hca_vport_context, ctx, qkey_violation_counter, req->qkey_violation_counter);
997 MLX5_SET(hca_vport_context, ctx, pkey_violation_counter, req->pkey_violation_counter);
998 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
1003 EXPORT_SYMBOL_GPL(mlx5_core_modify_hca_vport_context);