2 * Copyright (c) 2013-2017, Mellanox Technologies, Ltd. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <linux/etherdevice.h>
29 #include <dev/mlx5/driver.h>
30 #include <dev/mlx5/vport.h>
31 #include "mlx5_core.h"
33 static int mlx5_modify_nic_vport_context(struct mlx5_core_dev *mdev, void *in,
36 static int _mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod,
37 u16 vport, u32 *out, int outlen)
40 u32 in[MLX5_ST_SZ_DW(query_vport_state_in)] = {0};
42 MLX5_SET(query_vport_state_in, in, opcode,
43 MLX5_CMD_OP_QUERY_VPORT_STATE);
44 MLX5_SET(query_vport_state_in, in, op_mod, opmod);
45 MLX5_SET(query_vport_state_in, in, vport_number, vport);
47 MLX5_SET(query_vport_state_in, in, other_vport, 1);
49 err = mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
51 mlx5_core_warn(mdev, "MLX5_CMD_OP_QUERY_VPORT_STATE failed\n");
56 u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport)
58 u32 out[MLX5_ST_SZ_DW(query_vport_state_out)] = {0};
60 _mlx5_query_vport_state(mdev, opmod, vport, out, sizeof(out));
62 return MLX5_GET(query_vport_state_out, out, state);
64 EXPORT_SYMBOL_GPL(mlx5_query_vport_state);
66 u8 mlx5_query_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport)
68 u32 out[MLX5_ST_SZ_DW(query_vport_state_out)] = {0};
70 _mlx5_query_vport_state(mdev, opmod, vport, out, sizeof(out));
72 return MLX5_GET(query_vport_state_out, out, admin_state);
74 EXPORT_SYMBOL(mlx5_query_vport_admin_state);
76 int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
79 u32 in[MLX5_ST_SZ_DW(modify_vport_state_in)] = {0};
80 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);
89 MLX5_SET(modify_vport_state_in, in, other_vport, 1);
91 MLX5_SET(modify_vport_state_in, in, admin_state, state);
93 err = mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
95 mlx5_core_warn(mdev, "MLX5_CMD_OP_MODIFY_VPORT_STATE failed\n");
99 EXPORT_SYMBOL(mlx5_modify_vport_admin_state);
101 static int mlx5_query_nic_vport_context(struct mlx5_core_dev *mdev, u16 vport,
102 u32 *out, int outlen)
104 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
106 MLX5_SET(query_nic_vport_context_in, in, opcode,
107 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
109 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
111 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
113 return mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
116 static u32 mlx5_vport_max_q_counter_allocator(struct mlx5_core_dev *mdev,
120 case MLX5_INTERFACE_PROTOCOL_IB:
121 return (MLX5_CAP_GEN(mdev, max_qp_cnt) -
122 MLX5_QCOUNTER_SETS_NETDEV);
123 case MLX5_INTERFACE_PROTOCOL_ETH:
124 return MLX5_QCOUNTER_SETS_NETDEV;
126 mlx5_core_warn(mdev, "Unknown Client: %d\n", client_id);
131 int mlx5_vport_alloc_q_counter(struct mlx5_core_dev *mdev,
132 int client_id, u16 *counter_set_id)
134 u32 in[MLX5_ST_SZ_DW(alloc_q_counter_in)] = {0};
135 u32 out[MLX5_ST_SZ_DW(alloc_q_counter_out)] = {0};
138 if (mdev->num_q_counter_allocated[client_id] >
139 mlx5_vport_max_q_counter_allocator(mdev, client_id))
142 MLX5_SET(alloc_q_counter_in, in, opcode,
143 MLX5_CMD_OP_ALLOC_Q_COUNTER);
145 err = mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
148 *counter_set_id = MLX5_GET(alloc_q_counter_out, out,
151 mdev->num_q_counter_allocated[client_id]++;
156 int mlx5_vport_dealloc_q_counter(struct mlx5_core_dev *mdev,
157 int client_id, u16 counter_set_id)
159 u32 in[MLX5_ST_SZ_DW(dealloc_q_counter_in)] = {0};
160 u32 out[MLX5_ST_SZ_DW(dealloc_q_counter_out)] = {0};
163 if (mdev->num_q_counter_allocated[client_id] <= 0)
166 MLX5_SET(dealloc_q_counter_in, in, opcode,
167 MLX5_CMD_OP_DEALLOC_Q_COUNTER);
168 MLX5_SET(dealloc_q_counter_in, in, counter_set_id,
171 err = mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out));
173 mdev->num_q_counter_allocated[client_id]--;
178 int mlx5_vport_query_q_counter(struct mlx5_core_dev *mdev,
184 u32 in[MLX5_ST_SZ_DW(query_q_counter_in)] = {0};
186 MLX5_SET(query_q_counter_in, in, opcode, MLX5_CMD_OP_QUERY_Q_COUNTER);
187 MLX5_SET(query_q_counter_in, in, clear, reset);
188 MLX5_SET(query_q_counter_in, in, counter_set_id, counter_set_id);
190 return mlx5_cmd_exec(mdev, in, sizeof(in), out, out_size);
193 int mlx5_vport_query_out_of_rx_buffer(struct mlx5_core_dev *mdev,
195 u32 *out_of_rx_buffer)
197 u32 out[MLX5_ST_SZ_DW(query_q_counter_out)] = {0};
200 err = mlx5_vport_query_q_counter(mdev, counter_set_id, 0, out,
206 *out_of_rx_buffer = MLX5_GET(query_q_counter_out, out,
211 int mlx5_query_nic_vport_min_inline(struct mlx5_core_dev *mdev,
212 u16 vport, u8 *min_inline)
214 u32 out[MLX5_ST_SZ_DW(query_nic_vport_context_out)] = {0};
217 err = mlx5_query_nic_vport_context(mdev, vport, out, sizeof(out));
219 *min_inline = MLX5_GET(query_nic_vport_context_out, out,
220 nic_vport_context.min_wqe_inline_mode);
223 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_min_inline);
225 void mlx5_query_min_inline(struct mlx5_core_dev *mdev,
228 switch (MLX5_CAP_ETH(mdev, wqe_inline_mode)) {
229 case MLX5_CAP_INLINE_MODE_L2:
230 *min_inline_mode = MLX5_INLINE_MODE_L2;
232 case MLX5_CAP_INLINE_MODE_VPORT_CONTEXT:
233 mlx5_query_nic_vport_min_inline(mdev, 0, min_inline_mode);
235 case MLX5_CAP_INLINE_MODE_NOT_REQUIRED:
236 *min_inline_mode = MLX5_INLINE_MODE_NONE;
240 EXPORT_SYMBOL_GPL(mlx5_query_min_inline);
242 int mlx5_modify_nic_vport_min_inline(struct mlx5_core_dev *mdev,
243 u16 vport, u8 min_inline)
245 u32 in[MLX5_ST_SZ_DW(modify_nic_vport_context_in)] = {0};
246 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
249 MLX5_SET(modify_nic_vport_context_in, in,
250 field_select.min_wqe_inline_mode, 1);
251 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
252 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
254 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
255 in, nic_vport_context);
256 MLX5_SET(nic_vport_context, nic_vport_ctx,
257 min_wqe_inline_mode, min_inline);
259 return mlx5_modify_nic_vport_context(mdev, in, inlen);
261 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_min_inline);
263 int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
267 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
271 out = mlx5_vzalloc(outlen);
275 out_addr = MLX5_ADDR_OF(query_nic_vport_context_out, out,
276 nic_vport_context.permanent_address);
278 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
282 ether_addr_copy(addr, &out_addr[2]);
288 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_address);
290 int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *mdev,
294 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
299 in = mlx5_vzalloc(inlen);
301 mlx5_core_warn(mdev, "failed to allocate inbox\n");
305 MLX5_SET(modify_nic_vport_context_in, in,
306 field_select.permanent_address, 1);
307 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
310 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
312 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
313 in, nic_vport_context);
314 perm_mac = MLX5_ADDR_OF(nic_vport_context, nic_vport_ctx,
317 ether_addr_copy(&perm_mac[2], addr);
319 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
325 EXPORT_SYMBOL(mlx5_modify_nic_vport_mac_address);
327 int mlx5_query_nic_vport_system_image_guid(struct mlx5_core_dev *mdev,
328 u64 *system_image_guid)
331 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
334 out = mlx5_vzalloc(outlen);
338 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
342 *system_image_guid = MLX5_GET64(query_nic_vport_context_out, out,
343 nic_vport_context.system_image_guid);
348 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_system_image_guid);
350 int mlx5_query_nic_vport_node_guid(struct mlx5_core_dev *mdev, u64 *node_guid)
353 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
356 out = mlx5_vzalloc(outlen);
360 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
364 *node_guid = MLX5_GET64(query_nic_vport_context_out, out,
365 nic_vport_context.node_guid);
371 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_node_guid);
373 static int mlx5_query_nic_vport_port_guid(struct mlx5_core_dev *mdev,
377 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
380 out = mlx5_vzalloc(outlen);
384 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
388 *port_guid = MLX5_GET64(query_nic_vport_context_out, out,
389 nic_vport_context.port_guid);
396 int mlx5_query_nic_vport_qkey_viol_cntr(struct mlx5_core_dev *mdev,
400 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
403 out = mlx5_vzalloc(outlen);
407 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
411 *qkey_viol_cntr = MLX5_GET(query_nic_vport_context_out, out,
412 nic_vport_context.qkey_violation_counter);
418 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_qkey_viol_cntr);
420 static int mlx5_modify_nic_vport_context(struct mlx5_core_dev *mdev, void *in,
423 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)] = {0};
425 MLX5_SET(modify_nic_vport_context_in, in, opcode,
426 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
428 return mlx5_cmd_exec(mdev, in, inlen, out, sizeof(out));
431 static int mlx5_nic_vport_enable_disable_roce(struct mlx5_core_dev *mdev,
435 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
438 in = mlx5_vzalloc(inlen);
440 mlx5_core_warn(mdev, "failed to allocate inbox\n");
444 MLX5_SET(modify_nic_vport_context_in, in, field_select.roce_en, 1);
445 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.roce_en,
448 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
455 int mlx5_set_nic_vport_current_mac(struct mlx5_core_dev *mdev, int vport,
456 bool other_vport, u8 *addr)
459 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in)
460 + MLX5_ST_SZ_BYTES(mac_address_layout);
465 in = mlx5_vzalloc(inlen);
467 mlx5_core_warn(mdev, "failed to allocate inbox\n");
471 MLX5_SET(modify_nic_vport_context_in, in,
472 opcode, MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
473 MLX5_SET(modify_nic_vport_context_in, in,
474 vport_number, vport);
475 MLX5_SET(modify_nic_vport_context_in, in,
476 other_vport, other_vport);
477 MLX5_SET(modify_nic_vport_context_in, in,
478 field_select.addresses_list, 1);
479 MLX5_SET(modify_nic_vport_context_in, in,
480 nic_vport_context.allowed_list_type,
481 MLX5_NIC_VPORT_LIST_TYPE_UC);
482 MLX5_SET(modify_nic_vport_context_in, in,
483 nic_vport_context.allowed_list_size, 1);
485 mac_layout = (u8 *)MLX5_ADDR_OF(modify_nic_vport_context_in, in,
486 nic_vport_context.current_uc_mac_address);
487 mac_ptr = (u8 *)MLX5_ADDR_OF(mac_address_layout, mac_layout,
489 ether_addr_copy(mac_ptr, addr);
491 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
497 EXPORT_SYMBOL_GPL(mlx5_set_nic_vport_current_mac);
499 int mlx5_modify_nic_vport_node_guid(struct mlx5_core_dev *mdev,
500 u32 vport, u64 node_guid)
503 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
505 void *nic_vport_context;
509 if (!MLX5_CAP_GEN(mdev, vport_group_manager))
511 if (!MLX5_CAP_ESW(mdev, nic_vport_node_guid_modify))
514 in = mlx5_vzalloc(inlen);
516 mlx5_core_warn(mdev, "failed to allocate inbox\n");
520 MLX5_SET(modify_nic_vport_context_in, in,
521 field_select.node_guid, 1);
522 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
524 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
526 nic_vport_context = MLX5_ADDR_OF(modify_nic_vport_context_in,
527 in, nic_vport_context);
528 MLX5_SET64(nic_vport_context, nic_vport_context, node_guid, node_guid);
530 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
536 EXPORT_SYMBOL(mlx5_modify_nic_vport_node_guid);
538 int mlx5_modify_nic_vport_port_guid(struct mlx5_core_dev *mdev,
539 u32 vport, u64 port_guid)
542 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
544 void *nic_vport_context;
548 if (!MLX5_CAP_GEN(mdev, vport_group_manager))
550 if (!MLX5_CAP_ESW(mdev, nic_vport_port_guid_modify))
553 in = mlx5_vzalloc(inlen);
555 mlx5_core_warn(mdev, "failed to allocate inbox\n");
559 MLX5_SET(modify_nic_vport_context_in, in,
560 field_select.port_guid, 1);
561 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
563 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
565 nic_vport_context = MLX5_ADDR_OF(modify_nic_vport_context_in,
566 in, nic_vport_context);
567 MLX5_SET64(nic_vport_context, nic_vport_context, port_guid, port_guid);
569 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
575 EXPORT_SYMBOL(mlx5_modify_nic_vport_port_guid);
577 int mlx5_set_nic_vport_vlan_list(struct mlx5_core_dev *dev, u16 vport,
578 u16 *vlan_list, int list_len)
582 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in)
583 + MLX5_ST_SZ_BYTES(vlan_layout) * (int)list_len;
585 int max_list_size = 1 << MLX5_CAP_GEN_MAX(dev, log_max_vlan_list);
587 if (list_len > max_list_size) {
588 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max_list_size\n",
589 list_len, max_list_size);
593 in = mlx5_vzalloc(inlen);
595 mlx5_core_warn(dev, "failed to allocate inbox\n");
599 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
601 MLX5_SET(modify_nic_vport_context_in, in,
603 MLX5_SET(modify_nic_vport_context_in, in,
604 field_select.addresses_list, 1);
606 ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in, nic_vport_context);
608 MLX5_SET(nic_vport_context, ctx, allowed_list_type,
609 MLX5_NIC_VPORT_LIST_TYPE_VLAN);
610 MLX5_SET(nic_vport_context, ctx, allowed_list_size, list_len);
612 for (i = 0; i < list_len; i++) {
613 u8 *vlan_lout = MLX5_ADDR_OF(nic_vport_context, ctx,
614 current_uc_mac_address[i]);
615 MLX5_SET(vlan_layout, vlan_lout, vlan, vlan_list[i]);
618 err = mlx5_modify_nic_vport_context(dev, in, inlen);
623 EXPORT_SYMBOL_GPL(mlx5_set_nic_vport_vlan_list);
625 int mlx5_set_nic_vport_mc_list(struct mlx5_core_dev *mdev, int vport,
626 u64 *addr_list, size_t addr_list_len)
629 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in)
630 + MLX5_ST_SZ_BYTES(mac_address_layout) * (int)addr_list_len;
633 int max_list_sz = 1 << MLX5_CAP_GEN_MAX(mdev, log_max_current_mc_list);
635 if ((int)addr_list_len > max_list_sz) {
636 mlx5_core_warn(mdev, "Requested list size (%d) > (%d) max_list_size\n",
637 (int)addr_list_len, max_list_sz);
641 in = mlx5_vzalloc(inlen);
643 mlx5_core_warn(mdev, "failed to allocate inbox\n");
647 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
649 MLX5_SET(modify_nic_vport_context_in, in,
651 MLX5_SET(modify_nic_vport_context_in, in,
652 field_select.addresses_list, 1);
654 ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in, nic_vport_context);
656 MLX5_SET(nic_vport_context, ctx, allowed_list_type,
657 MLX5_NIC_VPORT_LIST_TYPE_MC);
658 MLX5_SET(nic_vport_context, ctx, allowed_list_size, addr_list_len);
660 for (i = 0; i < addr_list_len; i++) {
661 u8 *mac_lout = (u8 *)MLX5_ADDR_OF(nic_vport_context, ctx,
662 current_uc_mac_address[i]);
663 u8 *mac_ptr = (u8 *)MLX5_ADDR_OF(mac_address_layout, mac_lout,
665 ether_addr_copy(mac_ptr, (u8 *)&addr_list[i]);
668 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
674 EXPORT_SYMBOL_GPL(mlx5_set_nic_vport_mc_list);
676 int mlx5_set_nic_vport_promisc(struct mlx5_core_dev *mdev, int vport,
677 bool promisc_mc, bool promisc_uc,
680 u8 in[MLX5_ST_SZ_BYTES(modify_nic_vport_context_in)];
681 u8 *ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
684 memset(in, 0, MLX5_ST_SZ_BYTES(modify_nic_vport_context_in));
686 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
688 MLX5_SET(modify_nic_vport_context_in, in,
690 MLX5_SET(modify_nic_vport_context_in, in, field_select.promisc, 1);
692 MLX5_SET(nic_vport_context, ctx, promisc_mc, 1);
694 MLX5_SET(nic_vport_context, ctx, promisc_uc, 1);
696 MLX5_SET(nic_vport_context, ctx, promisc_all, 1);
698 return mlx5_modify_nic_vport_context(mdev, in, sizeof(in));
700 EXPORT_SYMBOL_GPL(mlx5_set_nic_vport_promisc);
702 int mlx5_query_nic_vport_mac_list(struct mlx5_core_dev *dev,
704 enum mlx5_list_type list_type,
705 u8 addr_list[][ETH_ALEN],
708 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
717 req_list_size = *list_size;
719 max_list_size = (list_type == MLX5_NIC_VPORT_LIST_TYPE_UC) ?
720 1 << MLX5_CAP_GEN_MAX(dev, log_max_current_uc_list) :
721 1 << MLX5_CAP_GEN_MAX(dev, log_max_current_mc_list);
723 if (req_list_size > max_list_size) {
724 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max_list_size\n",
725 req_list_size, max_list_size);
726 req_list_size = max_list_size;
729 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
730 req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
732 out = kzalloc(out_sz, GFP_KERNEL);
736 MLX5_SET(query_nic_vport_context_in, in, opcode,
737 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
738 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type, list_type);
739 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
742 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
744 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
748 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
750 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
753 *list_size = req_list_size;
754 for (i = 0; i < req_list_size; i++) {
755 u8 *mac_addr = MLX5_ADDR_OF(nic_vport_context,
757 current_uc_mac_address[i]) + 2;
758 ether_addr_copy(addr_list[i], mac_addr);
764 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_list);
766 int mlx5_modify_nic_vport_mac_list(struct mlx5_core_dev *dev,
767 enum mlx5_list_type list_type,
768 u8 addr_list[][ETH_ALEN],
771 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)] = {0};
779 max_list_size = list_type == MLX5_NIC_VPORT_LIST_TYPE_UC ?
780 1 << MLX5_CAP_GEN(dev, log_max_current_uc_list) :
781 1 << MLX5_CAP_GEN(dev, log_max_current_mc_list);
783 if (list_size > max_list_size)
786 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
787 list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
789 in = kzalloc(in_sz, GFP_KERNEL);
793 MLX5_SET(modify_nic_vport_context_in, in, opcode,
794 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
795 MLX5_SET(modify_nic_vport_context_in, in,
796 field_select.addresses_list, 1);
798 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
801 MLX5_SET(nic_vport_context, nic_vport_ctx,
802 allowed_list_type, list_type);
803 MLX5_SET(nic_vport_context, nic_vport_ctx,
804 allowed_list_size, list_size);
806 for (i = 0; i < list_size; i++) {
807 u8 *curr_mac = MLX5_ADDR_OF(nic_vport_context,
809 current_uc_mac_address[i]) + 2;
810 ether_addr_copy(curr_mac, addr_list[i]);
813 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
817 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_mac_list);
819 int mlx5_query_nic_vport_vlans(struct mlx5_core_dev *dev,
824 u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
833 req_list_size = *size;
834 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
835 if (req_list_size > max_list_size) {
836 mlx5_core_warn(dev, "Requested list size (%d) > (%d) max list size\n",
837 req_list_size, max_list_size);
838 req_list_size = max_list_size;
841 out_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
842 req_list_size * MLX5_ST_SZ_BYTES(vlan_layout);
844 out = kzalloc(out_sz, GFP_KERNEL);
848 MLX5_SET(query_nic_vport_context_in, in, opcode,
849 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
850 MLX5_SET(query_nic_vport_context_in, in, allowed_list_type,
851 MLX5_NIC_VPORT_CONTEXT_ALLOWED_LIST_TYPE_VLAN_LIST);
852 MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
855 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
857 err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
861 nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
863 req_list_size = MLX5_GET(nic_vport_context, nic_vport_ctx,
866 *size = req_list_size;
867 for (i = 0; i < req_list_size; i++) {
868 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
870 current_uc_mac_address[i]);
871 vlans[i] = MLX5_GET(vlan_layout, vlan_addr, vlan);
877 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_vlans);
879 int mlx5_modify_nic_vport_vlans(struct mlx5_core_dev *dev,
883 u32 out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)] = {0};
891 max_list_size = 1 << MLX5_CAP_GEN(dev, log_max_vlan_list);
893 if (list_size > max_list_size)
896 in_sz = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in) +
897 list_size * MLX5_ST_SZ_BYTES(vlan_layout);
899 in = kzalloc(in_sz, GFP_KERNEL);
903 MLX5_SET(modify_nic_vport_context_in, in, opcode,
904 MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
905 MLX5_SET(modify_nic_vport_context_in, in,
906 field_select.addresses_list, 1);
908 nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in, in,
911 MLX5_SET(nic_vport_context, nic_vport_ctx,
912 allowed_list_type, MLX5_NIC_VPORT_LIST_TYPE_VLAN);
913 MLX5_SET(nic_vport_context, nic_vport_ctx,
914 allowed_list_size, list_size);
916 for (i = 0; i < list_size; i++) {
917 void *vlan_addr = MLX5_ADDR_OF(nic_vport_context,
919 current_uc_mac_address[i]);
920 MLX5_SET(vlan_layout, vlan_addr, vlan, vlans[i]);
923 err = mlx5_cmd_exec(dev, in, in_sz, out, sizeof(out));
927 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_vlans);
929 int mlx5_query_nic_vport_roce_en(struct mlx5_core_dev *mdev, u8 *enable)
932 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
935 out = kzalloc(outlen, GFP_KERNEL);
939 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
943 *enable = MLX5_GET(query_nic_vport_context_out, out,
944 nic_vport_context.roce_en);
950 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_roce_en);
952 int mlx5_set_nic_vport_permanent_mac(struct mlx5_core_dev *mdev, int vport,
956 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
960 in = mlx5_vzalloc(inlen);
962 mlx5_core_warn(mdev, "failed to allocate inbox\n");
966 MLX5_SET(modify_nic_vport_context_in, in,
967 opcode, MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
968 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
969 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
970 MLX5_SET(modify_nic_vport_context_in, in,
971 field_select.permanent_address, 1);
972 mac_ptr = (u8 *)MLX5_ADDR_OF(modify_nic_vport_context_in, in,
973 nic_vport_context.permanent_address.mac_addr_47_32);
974 ether_addr_copy(mac_ptr, addr);
976 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
982 EXPORT_SYMBOL_GPL(mlx5_set_nic_vport_permanent_mac);
984 int mlx5_nic_vport_enable_roce(struct mlx5_core_dev *mdev)
986 return mlx5_nic_vport_enable_disable_roce(mdev, 1);
988 EXPORT_SYMBOL_GPL(mlx5_nic_vport_enable_roce);
990 int mlx5_nic_vport_disable_roce(struct mlx5_core_dev *mdev)
992 return mlx5_nic_vport_enable_disable_roce(mdev, 0);
994 EXPORT_SYMBOL_GPL(mlx5_nic_vport_disable_roce);
996 int mlx5_core_query_vport_counter(struct mlx5_core_dev *dev, u8 other_vport,
997 int vf, u8 port_num, void *out,
1000 int in_sz = MLX5_ST_SZ_BYTES(query_vport_counter_in);
1001 int is_group_manager;
1005 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1006 in = mlx5_vzalloc(in_sz);
1012 MLX5_SET(query_vport_counter_in, in, opcode,
1013 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
1015 if (is_group_manager) {
1016 MLX5_SET(query_vport_counter_in, in, other_vport, 1);
1017 MLX5_SET(query_vport_counter_in, in, vport_number, vf + 1);
1023 if (MLX5_CAP_GEN(dev, num_ports) == 2)
1024 MLX5_SET(query_vport_counter_in, in, port_num, port_num);
1026 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
1031 EXPORT_SYMBOL_GPL(mlx5_core_query_vport_counter);
1033 int mlx5_query_hca_vport_context(struct mlx5_core_dev *mdev,
1034 u8 port_num, u8 vport_num, u32 *out,
1037 u32 in[MLX5_ST_SZ_DW(query_hca_vport_context_in)] = {0};
1038 int is_group_manager;
1040 is_group_manager = MLX5_CAP_GEN(mdev, vport_group_manager);
1042 MLX5_SET(query_hca_vport_context_in, in, opcode,
1043 MLX5_CMD_OP_QUERY_HCA_VPORT_CONTEXT);
1046 if (is_group_manager) {
1047 MLX5_SET(query_hca_vport_context_in, in, other_vport,
1049 MLX5_SET(query_hca_vport_context_in, in, vport_number,
1056 if (MLX5_CAP_GEN(mdev, num_ports) == 2)
1057 MLX5_SET(query_hca_vport_context_in, in, port_num, port_num);
1059 return mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
1062 int mlx5_query_hca_vport_system_image_guid(struct mlx5_core_dev *mdev,
1063 u64 *system_image_guid)
1066 int outlen = MLX5_ST_SZ_BYTES(query_hca_vport_context_out);
1069 out = mlx5_vzalloc(outlen);
1073 err = mlx5_query_hca_vport_context(mdev, 1, 0, out, outlen);
1077 *system_image_guid = MLX5_GET64(query_hca_vport_context_out, out,
1078 hca_vport_context.system_image_guid);
1084 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_system_image_guid);
1086 int mlx5_query_hca_vport_node_guid(struct mlx5_core_dev *mdev, u64 *node_guid)
1089 int outlen = MLX5_ST_SZ_BYTES(query_hca_vport_context_out);
1092 out = mlx5_vzalloc(outlen);
1096 err = mlx5_query_hca_vport_context(mdev, 1, 0, out, outlen);
1100 *node_guid = MLX5_GET64(query_hca_vport_context_out, out,
1101 hca_vport_context.node_guid);
1107 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_node_guid);
1109 static int mlx5_query_hca_vport_port_guid(struct mlx5_core_dev *mdev,
1113 int outlen = MLX5_ST_SZ_BYTES(query_hca_vport_context_out);
1116 out = mlx5_vzalloc(outlen);
1120 err = mlx5_query_hca_vport_context(mdev, 1, 0, out, outlen);
1124 *port_guid = MLX5_GET64(query_hca_vport_context_out, out,
1125 hca_vport_context.port_guid);
1132 int mlx5_query_hca_vport_gid(struct mlx5_core_dev *dev, u8 port_num,
1133 u16 vport_num, u16 gid_index, union ib_gid *gid)
1135 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_in);
1136 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_gid_out);
1137 int is_group_manager;
1145 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1146 tbsz = mlx5_get_gid_table_len(MLX5_CAP_GEN(dev, gid_table_size));
1148 if (gid_index > tbsz && gid_index != 0xffff)
1151 if (gid_index == 0xffff)
1156 out_sz += nout * sizeof(*gid);
1158 in = mlx5_vzalloc(in_sz);
1159 out = mlx5_vzalloc(out_sz);
1165 MLX5_SET(query_hca_vport_gid_in, in, opcode,
1166 MLX5_CMD_OP_QUERY_HCA_VPORT_GID);
1168 if (is_group_manager) {
1169 MLX5_SET(query_hca_vport_gid_in, in, vport_number,
1171 MLX5_SET(query_hca_vport_gid_in, in, other_vport, 1);
1178 MLX5_SET(query_hca_vport_gid_in, in, gid_index, gid_index);
1180 if (MLX5_CAP_GEN(dev, num_ports) == 2)
1181 MLX5_SET(query_hca_vport_gid_in, in, port_num, port_num);
1183 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
1187 tmp = (union ib_gid *)MLX5_ADDR_OF(query_hca_vport_gid_out, out, gid);
1188 gid->global.subnet_prefix = tmp->global.subnet_prefix;
1189 gid->global.interface_id = tmp->global.interface_id;
1196 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_gid);
1198 int mlx5_query_hca_vport_pkey(struct mlx5_core_dev *dev, u8 other_vport,
1199 u8 port_num, u16 vf_num, u16 pkey_index,
1202 int in_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_in);
1203 int out_sz = MLX5_ST_SZ_BYTES(query_hca_vport_pkey_out);
1204 int is_group_manager;
1213 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1215 tbsz = mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(dev, pkey_table_size));
1216 if (pkey_index > tbsz && pkey_index != 0xffff)
1219 if (pkey_index == 0xffff)
1224 out_sz += nout * MLX5_ST_SZ_BYTES(pkey);
1226 in = kzalloc(in_sz, GFP_KERNEL);
1227 out = kzalloc(out_sz, GFP_KERNEL);
1229 MLX5_SET(query_hca_vport_pkey_in, in, opcode,
1230 MLX5_CMD_OP_QUERY_HCA_VPORT_PKEY);
1232 if (is_group_manager) {
1233 MLX5_SET(query_hca_vport_pkey_in, in, vport_number,
1235 MLX5_SET(query_hca_vport_pkey_in, in, other_vport, 1);
1241 MLX5_SET(query_hca_vport_pkey_in, in, pkey_index, pkey_index);
1243 if (MLX5_CAP_GEN(dev, num_ports) == 2)
1244 MLX5_SET(query_hca_vport_pkey_in, in, port_num, port_num);
1246 err = mlx5_cmd_exec(dev, in, in_sz, out, out_sz);
1250 pkarr = MLX5_ADDR_OF(query_hca_vport_pkey_out, out, pkey);
1251 for (i = 0; i < nout; i++, pkey++,
1252 pkarr += MLX5_ST_SZ_BYTES(pkey))
1253 *pkey = MLX5_GET_PR(pkey, pkarr, pkey);
1260 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_pkey);
1262 static int mlx5_query_hca_min_wqe_header(struct mlx5_core_dev *mdev,
1266 u32 outlen = MLX5_ST_SZ_BYTES(query_hca_vport_context_out);
1269 out = mlx5_vzalloc(outlen);
1273 err = mlx5_query_hca_vport_context(mdev, 1, 0, out, outlen);
1277 *min_header = MLX5_GET(query_hca_vport_context_out, out,
1278 hca_vport_context.min_wqe_inline_mode);
1285 static int mlx5_modify_eswitch_vport_context(struct mlx5_core_dev *mdev,
1286 u16 vport, void *in, int inlen)
1288 u32 out[MLX5_ST_SZ_DW(modify_esw_vport_context_out)] = {0};
1291 MLX5_SET(modify_esw_vport_context_in, in, vport_number, vport);
1293 MLX5_SET(modify_esw_vport_context_in, in, other_vport, 1);
1295 MLX5_SET(modify_esw_vport_context_in, in, opcode,
1296 MLX5_CMD_OP_MODIFY_ESW_VPORT_CONTEXT);
1298 err = mlx5_cmd_exec(mdev, in, inlen, out, sizeof(out));
1300 mlx5_core_warn(mdev, "MLX5_CMD_OP_MODIFY_ESW_VPORT_CONTEXT failed\n");
1305 int mlx5_set_eswitch_cvlan_info(struct mlx5_core_dev *mdev, u8 vport,
1306 u8 insert_mode, u8 strip_mode,
1307 u16 vlan, u8 cfi, u8 pcp)
1309 u32 in[MLX5_ST_SZ_DW(modify_esw_vport_context_in)];
1311 memset(in, 0, sizeof(in));
1313 if (insert_mode != MLX5_MODIFY_ESW_VPORT_CONTEXT_CVLAN_INSERT_NONE) {
1314 MLX5_SET(modify_esw_vport_context_in, in,
1315 esw_vport_context.cvlan_cfi, cfi);
1316 MLX5_SET(modify_esw_vport_context_in, in,
1317 esw_vport_context.cvlan_pcp, pcp);
1318 MLX5_SET(modify_esw_vport_context_in, in,
1319 esw_vport_context.cvlan_id, vlan);
1322 MLX5_SET(modify_esw_vport_context_in, in,
1323 esw_vport_context.vport_cvlan_insert, insert_mode);
1325 MLX5_SET(modify_esw_vport_context_in, in,
1326 esw_vport_context.vport_cvlan_strip, strip_mode);
1328 MLX5_SET(modify_esw_vport_context_in, in, field_select,
1329 MLX5_MODIFY_ESW_VPORT_CONTEXT_FIELD_SELECT_CVLAN_STRIP |
1330 MLX5_MODIFY_ESW_VPORT_CONTEXT_FIELD_SELECT_CVLAN_INSERT);
1332 return mlx5_modify_eswitch_vport_context(mdev, vport, in, sizeof(in));
1334 EXPORT_SYMBOL_GPL(mlx5_set_eswitch_cvlan_info);
1336 int mlx5_query_vport_mtu(struct mlx5_core_dev *mdev, int *mtu)
1339 u32 outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
1342 out = mlx5_vzalloc(outlen);
1346 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
1350 *mtu = MLX5_GET(query_nic_vport_context_out, out,
1351 nic_vport_context.mtu);
1357 EXPORT_SYMBOL_GPL(mlx5_query_vport_mtu);
1359 int mlx5_set_vport_mtu(struct mlx5_core_dev *mdev, int mtu)
1362 u32 inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
1365 in = mlx5_vzalloc(inlen);
1369 MLX5_SET(modify_nic_vport_context_in, in, field_select.mtu, 1);
1370 MLX5_SET(modify_nic_vport_context_in, in, nic_vport_context.mtu, mtu);
1372 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
1377 EXPORT_SYMBOL_GPL(mlx5_set_vport_mtu);
1379 static int mlx5_query_vport_min_wqe_header(struct mlx5_core_dev *mdev,
1383 u32 outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
1386 out = mlx5_vzalloc(outlen);
1390 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
1394 *min_header = MLX5_GET(query_nic_vport_context_out, out,
1395 nic_vport_context.min_wqe_inline_mode);
1402 int mlx5_set_vport_min_wqe_header(struct mlx5_core_dev *mdev,
1403 u8 vport, int min_header)
1406 u32 inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
1409 in = mlx5_vzalloc(inlen);
1413 MLX5_SET(modify_nic_vport_context_in, in,
1414 field_select.min_wqe_inline_mode, 1);
1415 MLX5_SET(modify_nic_vport_context_in, in,
1416 nic_vport_context.min_wqe_inline_mode, min_header);
1417 MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
1418 MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
1420 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
1425 EXPORT_SYMBOL_GPL(mlx5_set_vport_min_wqe_header);
1427 int mlx5_query_min_wqe_header(struct mlx5_core_dev *dev, int *min_header)
1429 switch (MLX5_CAP_GEN(dev, port_type)) {
1430 case MLX5_CMD_HCA_CAP_PORT_TYPE_IB:
1431 return mlx5_query_hca_min_wqe_header(dev, min_header);
1433 case MLX5_CMD_HCA_CAP_PORT_TYPE_ETHERNET:
1434 return mlx5_query_vport_min_wqe_header(dev, min_header);
1440 EXPORT_SYMBOL_GPL(mlx5_query_min_wqe_header);
1442 int mlx5_query_nic_vport_promisc(struct mlx5_core_dev *mdev,
1449 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
1452 out = kzalloc(outlen, GFP_KERNEL);
1456 err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
1460 *promisc_uc = MLX5_GET(query_nic_vport_context_out, out,
1461 nic_vport_context.promisc_uc);
1462 *promisc_mc = MLX5_GET(query_nic_vport_context_out, out,
1463 nic_vport_context.promisc_mc);
1464 *promisc_all = MLX5_GET(query_nic_vport_context_out, out,
1465 nic_vport_context.promisc_all);
1471 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_promisc);
1473 int mlx5_modify_nic_vport_promisc(struct mlx5_core_dev *mdev,
1479 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
1482 in = mlx5_vzalloc(inlen);
1484 mlx5_core_err(mdev, "failed to allocate inbox\n");
1488 MLX5_SET(modify_nic_vport_context_in, in, field_select.promisc, 1);
1489 MLX5_SET(modify_nic_vport_context_in, in,
1490 nic_vport_context.promisc_uc, promisc_uc);
1491 MLX5_SET(modify_nic_vport_context_in, in,
1492 nic_vport_context.promisc_mc, promisc_mc);
1493 MLX5_SET(modify_nic_vport_context_in, in,
1494 nic_vport_context.promisc_all, promisc_all);
1496 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
1500 EXPORT_SYMBOL_GPL(mlx5_modify_nic_vport_promisc);
1502 int mlx5_nic_vport_modify_local_lb(struct mlx5_core_dev *mdev,
1503 enum mlx5_local_lb_selection selection,
1507 int inlen = MLX5_ST_SZ_BYTES(modify_nic_vport_context_in);
1510 in = mlx5_vzalloc(inlen);
1512 mlx5_core_warn(mdev, "failed to allocate inbox\n");
1516 MLX5_SET(modify_nic_vport_context_in, in, vport_number, 0);
1518 if (selection == MLX5_LOCAL_MC_LB) {
1519 MLX5_SET(modify_nic_vport_context_in, in,
1520 field_select.disable_mc_local_lb, 1);
1521 MLX5_SET(modify_nic_vport_context_in, in,
1522 nic_vport_context.disable_mc_local_lb,
1525 MLX5_SET(modify_nic_vport_context_in, in,
1526 field_select.disable_uc_local_lb, 1);
1527 MLX5_SET(modify_nic_vport_context_in, in,
1528 nic_vport_context.disable_uc_local_lb,
1532 err = mlx5_modify_nic_vport_context(mdev, in, inlen);
1537 EXPORT_SYMBOL_GPL(mlx5_nic_vport_modify_local_lb);
1539 int mlx5_nic_vport_query_local_lb(struct mlx5_core_dev *mdev,
1540 enum mlx5_local_lb_selection selection,
1544 int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
1547 out = kzalloc(outlen, GFP_KERNEL);
1551 err = mlx5_query_nic_vport_context(mdev, 0, out, outlen);
1555 if (selection == MLX5_LOCAL_MC_LB)
1556 *value = MLX5_GET(query_nic_vport_context_out, out,
1557 nic_vport_context.disable_mc_local_lb);
1559 *value = MLX5_GET(query_nic_vport_context_out, out,
1560 nic_vport_context.disable_uc_local_lb);
1566 EXPORT_SYMBOL_GPL(mlx5_nic_vport_query_local_lb);
1568 int mlx5_query_vport_counter(struct mlx5_core_dev *dev,
1569 u8 port_num, u16 vport_num,
1570 void *out, int out_size)
1572 int in_sz = MLX5_ST_SZ_BYTES(query_vport_counter_in);
1573 int is_group_manager;
1577 is_group_manager = MLX5_CAP_GEN(dev, vport_group_manager);
1579 in = mlx5_vzalloc(in_sz);
1583 MLX5_SET(query_vport_counter_in, in, opcode,
1584 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
1586 if (is_group_manager) {
1587 MLX5_SET(query_vport_counter_in, in, other_vport, 1);
1588 MLX5_SET(query_vport_counter_in, in, vport_number,
1595 if (MLX5_CAP_GEN(dev, num_ports) == 2)
1596 MLX5_SET(query_vport_counter_in, in, port_num, port_num);
1598 err = mlx5_cmd_exec(dev, in, in_sz, out, out_size);
1604 EXPORT_SYMBOL_GPL(mlx5_query_vport_counter);
1606 int mlx5_get_vport_counters(struct mlx5_core_dev *dev, u8 port_num,
1607 struct mlx5_vport_counters *vc)
1609 int out_sz = MLX5_ST_SZ_BYTES(query_vport_counter_out);
1613 out = mlx5_vzalloc(out_sz);
1617 err = mlx5_query_vport_counter(dev, port_num, 0, out, out_sz);
1621 vc->received_errors.packets =
1622 MLX5_GET64(query_vport_counter_out,
1623 out, received_errors.packets);
1624 vc->received_errors.octets =
1625 MLX5_GET64(query_vport_counter_out,
1626 out, received_errors.octets);
1627 vc->transmit_errors.packets =
1628 MLX5_GET64(query_vport_counter_out,
1629 out, transmit_errors.packets);
1630 vc->transmit_errors.octets =
1631 MLX5_GET64(query_vport_counter_out,
1632 out, transmit_errors.octets);
1633 vc->received_ib_unicast.packets =
1634 MLX5_GET64(query_vport_counter_out,
1635 out, received_ib_unicast.packets);
1636 vc->received_ib_unicast.octets =
1637 MLX5_GET64(query_vport_counter_out,
1638 out, received_ib_unicast.octets);
1639 vc->transmitted_ib_unicast.packets =
1640 MLX5_GET64(query_vport_counter_out,
1641 out, transmitted_ib_unicast.packets);
1642 vc->transmitted_ib_unicast.octets =
1643 MLX5_GET64(query_vport_counter_out,
1644 out, transmitted_ib_unicast.octets);
1645 vc->received_ib_multicast.packets =
1646 MLX5_GET64(query_vport_counter_out,
1647 out, received_ib_multicast.packets);
1648 vc->received_ib_multicast.octets =
1649 MLX5_GET64(query_vport_counter_out,
1650 out, received_ib_multicast.octets);
1651 vc->transmitted_ib_multicast.packets =
1652 MLX5_GET64(query_vport_counter_out,
1653 out, transmitted_ib_multicast.packets);
1654 vc->transmitted_ib_multicast.octets =
1655 MLX5_GET64(query_vport_counter_out,
1656 out, transmitted_ib_multicast.octets);
1657 vc->received_eth_broadcast.packets =
1658 MLX5_GET64(query_vport_counter_out,
1659 out, received_eth_broadcast.packets);
1660 vc->received_eth_broadcast.octets =
1661 MLX5_GET64(query_vport_counter_out,
1662 out, received_eth_broadcast.octets);
1663 vc->transmitted_eth_broadcast.packets =
1664 MLX5_GET64(query_vport_counter_out,
1665 out, transmitted_eth_broadcast.packets);
1666 vc->transmitted_eth_broadcast.octets =
1667 MLX5_GET64(query_vport_counter_out,
1668 out, transmitted_eth_broadcast.octets);
1669 vc->received_eth_unicast.octets =
1670 MLX5_GET64(query_vport_counter_out,
1671 out, received_eth_unicast.octets);
1672 vc->received_eth_unicast.packets =
1673 MLX5_GET64(query_vport_counter_out,
1674 out, received_eth_unicast.packets);
1675 vc->transmitted_eth_unicast.octets =
1676 MLX5_GET64(query_vport_counter_out,
1677 out, transmitted_eth_unicast.octets);
1678 vc->transmitted_eth_unicast.packets =
1679 MLX5_GET64(query_vport_counter_out,
1680 out, transmitted_eth_unicast.packets);
1681 vc->received_eth_multicast.octets =
1682 MLX5_GET64(query_vport_counter_out,
1683 out, received_eth_multicast.octets);
1684 vc->received_eth_multicast.packets =
1685 MLX5_GET64(query_vport_counter_out,
1686 out, received_eth_multicast.packets);
1687 vc->transmitted_eth_multicast.octets =
1688 MLX5_GET64(query_vport_counter_out,
1689 out, transmitted_eth_multicast.octets);
1690 vc->transmitted_eth_multicast.packets =
1691 MLX5_GET64(query_vport_counter_out,
1692 out, transmitted_eth_multicast.packets);
1699 int mlx5_query_vport_system_image_guid(struct mlx5_core_dev *dev,
1700 u64 *sys_image_guid)
1702 switch (MLX5_CAP_GEN(dev, port_type)) {
1703 case MLX5_CMD_HCA_CAP_PORT_TYPE_IB:
1704 return mlx5_query_hca_vport_system_image_guid(dev,
1707 case MLX5_CMD_HCA_CAP_PORT_TYPE_ETHERNET:
1708 return mlx5_query_nic_vport_system_image_guid(dev,
1715 EXPORT_SYMBOL_GPL(mlx5_query_vport_system_image_guid);
1717 int mlx5_query_vport_node_guid(struct mlx5_core_dev *dev, u64 *node_guid)
1719 switch (MLX5_CAP_GEN(dev, port_type)) {
1720 case MLX5_CMD_HCA_CAP_PORT_TYPE_IB:
1721 return mlx5_query_hca_vport_node_guid(dev, node_guid);
1723 case MLX5_CMD_HCA_CAP_PORT_TYPE_ETHERNET:
1724 return mlx5_query_nic_vport_node_guid(dev, node_guid);
1730 EXPORT_SYMBOL_GPL(mlx5_query_vport_node_guid);
1732 int mlx5_query_vport_port_guid(struct mlx5_core_dev *dev, u64 *port_guid)
1734 switch (MLX5_CAP_GEN(dev, port_type)) {
1735 case MLX5_CMD_HCA_CAP_PORT_TYPE_IB:
1736 return mlx5_query_hca_vport_port_guid(dev, port_guid);
1738 case MLX5_CMD_HCA_CAP_PORT_TYPE_ETHERNET:
1739 return mlx5_query_nic_vport_port_guid(dev, port_guid);
1745 EXPORT_SYMBOL_GPL(mlx5_query_vport_port_guid);
1747 int mlx5_query_hca_vport_state(struct mlx5_core_dev *dev, u8 *vport_state)
1750 int outlen = MLX5_ST_SZ_BYTES(query_hca_vport_context_out);
1753 out = mlx5_vzalloc(outlen);
1757 err = mlx5_query_hca_vport_context(dev, 1, 0, out, outlen);
1761 *vport_state = MLX5_GET(query_hca_vport_context_out, out,
1762 hca_vport_context.vport_state);
1768 EXPORT_SYMBOL_GPL(mlx5_query_hca_vport_state);
1770 int mlx5_core_query_ib_ppcnt(struct mlx5_core_dev *dev,
1771 u8 port_num, void *out, size_t sz)
1776 in = mlx5_vzalloc(sz);
1782 MLX5_SET(ppcnt_reg, in, local_port, port_num);
1784 MLX5_SET(ppcnt_reg, in, grp, MLX5_INFINIBAND_PORT_COUNTERS_GROUP);
1785 err = mlx5_core_access_reg(dev, in, sz, out,
1786 sz, MLX5_REG_PPCNT, 0, 0);