2 * Copyright (c) 2013-2015, 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 <dev/mlx5/driver.h>
29 #include <linux/module.h>
30 #include "mlx5_core.h"
32 static int mlx5_cmd_query_adapter(struct mlx5_core_dev *dev, u32 *out,
35 u32 in[MLX5_ST_SZ_DW(query_adapter_in)];
38 memset(in, 0, sizeof(in));
40 MLX5_SET(query_adapter_in, in, opcode, MLX5_CMD_OP_QUERY_ADAPTER);
42 err = mlx5_cmd_exec(dev, in, sizeof(in), out, outlen);
46 int mlx5_query_board_id(struct mlx5_core_dev *dev)
49 int outlen = MLX5_ST_SZ_BYTES(query_adapter_out);
52 out = kzalloc(outlen, GFP_KERNEL);
54 err = mlx5_cmd_query_adapter(dev, out, outlen);
59 MLX5_ADDR_OF(query_adapter_out, out,
60 query_adapter_struct.vsd_contd_psid),
61 MLX5_FLD_SZ_BYTES(query_adapter_out,
62 query_adapter_struct.vsd_contd_psid));
70 int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id)
73 int outlen = MLX5_ST_SZ_BYTES(query_adapter_out);
76 out = kzalloc(outlen, GFP_KERNEL);
78 err = mlx5_cmd_query_adapter(mdev, out, outlen);
82 *vendor_id = MLX5_GET(query_adapter_out, out,
83 query_adapter_struct.ieee_vendor_id);
90 EXPORT_SYMBOL(mlx5_core_query_vendor_id);
92 static int mlx5_core_query_special_contexts(struct mlx5_core_dev *dev)
94 u32 in[MLX5_ST_SZ_DW(query_special_contexts_in)];
95 u32 out[MLX5_ST_SZ_DW(query_special_contexts_out)];
98 memset(in, 0, sizeof(in));
99 memset(out, 0, sizeof(out));
101 MLX5_SET(query_special_contexts_in, in, opcode,
102 MLX5_CMD_OP_QUERY_SPECIAL_CONTEXTS);
103 err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
107 dev->special_contexts.resd_lkey = MLX5_GET(query_special_contexts_out,
113 int mlx5_query_hca_caps(struct mlx5_core_dev *dev)
117 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL);
121 if (MLX5_CAP_GEN(dev, eth_net_offloads)) {
122 err = mlx5_core_get_caps(dev, MLX5_CAP_ETHERNET_OFFLOADS);
127 if (MLX5_CAP_GEN(dev, pg)) {
128 err = mlx5_core_get_caps(dev, MLX5_CAP_ODP);
133 if (MLX5_CAP_GEN(dev, atomic)) {
134 err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC);
139 if (MLX5_CAP_GEN(dev, roce)) {
140 err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE);
145 if ((MLX5_CAP_GEN(dev, port_type) ==
146 MLX5_CMD_HCA_CAP_PORT_TYPE_ETHERNET &&
147 MLX5_CAP_GEN(dev, nic_flow_table)) ||
148 (MLX5_CAP_GEN(dev, port_type) == MLX5_CMD_HCA_CAP_PORT_TYPE_IB &&
149 MLX5_CAP_GEN(dev, ipoib_enhanced_offloads))) {
150 err = mlx5_core_get_caps(dev, MLX5_CAP_FLOW_TABLE);
156 MLX5_CAP_GEN(dev, eswitch_flow_table)) {
157 err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH_FLOW_TABLE);
162 if (MLX5_CAP_GEN(dev, vport_group_manager)) {
163 err = mlx5_core_get_caps(dev, MLX5_CAP_ESWITCH);
168 if (MLX5_CAP_GEN(dev, snapshot)) {
169 err = mlx5_core_get_caps(dev, MLX5_CAP_SNAPSHOT);
174 if (MLX5_CAP_GEN(dev, ipoib_enhanced_offloads)) {
175 err = mlx5_core_get_caps(dev, MLX5_CAP_EOIB_OFFLOADS);
180 if (MLX5_CAP_GEN(dev, debug)) {
181 err = mlx5_core_get_caps(dev, MLX5_CAP_DEBUG);
186 if (MLX5_CAP_GEN(dev, qos)) {
187 err = mlx5_core_get_caps(dev, MLX5_CAP_QOS);
192 err = mlx5_core_query_special_contexts(dev);
199 int mlx5_cmd_init_hca(struct mlx5_core_dev *dev)
201 u32 in[MLX5_ST_SZ_DW(init_hca_in)];
202 u32 out[MLX5_ST_SZ_DW(init_hca_out)];
204 memset(in, 0, sizeof(in));
206 MLX5_SET(init_hca_in, in, opcode, MLX5_CMD_OP_INIT_HCA);
208 memset(out, 0, sizeof(out));
209 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
212 int mlx5_cmd_teardown_hca(struct mlx5_core_dev *dev)
214 u32 in[MLX5_ST_SZ_DW(teardown_hca_in)] = {0};
215 u32 out[MLX5_ST_SZ_DW(teardown_hca_out)] = {0};
217 MLX5_SET(teardown_hca_in, in, opcode, MLX5_CMD_OP_TEARDOWN_HCA);
218 return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
221 int mlx5_cmd_force_teardown_hca(struct mlx5_core_dev *dev)
223 u32 out[MLX5_ST_SZ_DW(teardown_hca_out)] = {0};
224 u32 in[MLX5_ST_SZ_DW(teardown_hca_in)] = {0};
228 if (!MLX5_CAP_GEN(dev, force_teardown)) {
229 mlx5_core_dbg(dev, "force teardown is not supported in the firmware\n");
233 MLX5_SET(teardown_hca_in, in, opcode, MLX5_CMD_OP_TEARDOWN_HCA);
234 MLX5_SET(teardown_hca_in, in, profile, MLX5_TEARDOWN_HCA_IN_PROFILE_FORCE_CLOSE);
236 ret = mlx5_cmd_exec_polling(dev, in, sizeof(in), out, sizeof(out));
240 force_state = MLX5_GET(teardown_hca_out, out, force_state);
241 if (force_state == MLX5_TEARDOWN_HCA_OUT_FORCE_STATE_FAIL) {
242 mlx5_core_err(dev, "teardown with force mode failed\n");
249 int mlx5_core_set_dc_cnak_trace(struct mlx5_core_dev *dev, int enable,
252 u32 in[MLX5_ST_SZ_DW(set_dc_cnak_trace_in)] = {0};
253 u32 out[MLX5_ST_SZ_DW(set_dc_cnak_trace_out)] = {0};
257 MLX5_SET(set_dc_cnak_trace_in, in, opcode, MLX5_CMD_OP_SET_DC_CNAK_TRACE);
258 MLX5_SET(set_dc_cnak_trace_in, in, enable, enable);
259 pas = MLX5_ADDR_OF(set_dc_cnak_trace_in, in, pas);
260 be_addr = cpu_to_be64(addr);
261 memcpy(MLX5_ADDR_OF(cmd_pas, pas, pa_h), &be_addr, sizeof(be_addr));
263 return mlx5_cmd_exec(dev, &in, sizeof(in), &out, sizeof(out));