2 * Copyright (c) 2013-2015, Mellanox Technologies. 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/mlx5/cmd.h>
34 #include <rdma/ib_mad.h>
35 #include <rdma/ib_smi.h>
39 MLX5_IB_VENDOR_CLASS1
= 0x9,
40 MLX5_IB_VENDOR_CLASS2
= 0xa
43 int mlx5_MAD_IFC(struct mlx5_ib_dev
*dev
, int ignore_mkey
, int ignore_bkey
,
44 u8 port
, const struct ib_wc
*in_wc
, const struct ib_grh
*in_grh
,
45 const void *in_mad
, void *response_mad
)
49 /* Key check traps can't be generated unless we have in_wc to
50 * tell us where to send the trap.
52 if (ignore_mkey
|| !in_wc
)
54 if (ignore_bkey
|| !in_wc
)
57 return mlx5_core_mad_ifc(dev
->mdev
, in_mad
, response_mad
, op_modifier
, port
);
60 int mlx5_ib_process_mad(struct ib_device
*ibdev
, int mad_flags
, u8 port_num
,
61 const struct ib_wc
*in_wc
, const struct ib_grh
*in_grh
,
62 const struct ib_mad_hdr
*in
, size_t in_mad_size
,
63 struct ib_mad_hdr
*out
, size_t *out_mad_size
,
64 u16
*out_mad_pkey_index
)
68 const struct ib_mad
*in_mad
= (const struct ib_mad
*)in
;
69 struct ib_mad
*out_mad
= (struct ib_mad
*)out
;
71 if (WARN_ON_ONCE(in_mad_size
!= sizeof(*in_mad
) ||
72 *out_mad_size
!= sizeof(*out_mad
)))
73 return IB_MAD_RESULT_FAILURE
;
75 slid
= in_wc
? in_wc
->slid
: be16_to_cpu(IB_LID_PERMISSIVE
);
77 if (in_mad
->mad_hdr
.method
== IB_MGMT_METHOD_TRAP
&& slid
== 0)
78 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_CONSUMED
;
80 if (in_mad
->mad_hdr
.mgmt_class
== IB_MGMT_CLASS_SUBN_LID_ROUTED
||
81 in_mad
->mad_hdr
.mgmt_class
== IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
) {
82 if (in_mad
->mad_hdr
.method
!= IB_MGMT_METHOD_GET
&&
83 in_mad
->mad_hdr
.method
!= IB_MGMT_METHOD_SET
&&
84 in_mad
->mad_hdr
.method
!= IB_MGMT_METHOD_TRAP_REPRESS
)
85 return IB_MAD_RESULT_SUCCESS
;
87 /* Don't process SMInfo queries -- the SMA can't handle them.
89 if (in_mad
->mad_hdr
.attr_id
== IB_SMP_ATTR_SM_INFO
)
90 return IB_MAD_RESULT_SUCCESS
;
91 } else if (in_mad
->mad_hdr
.mgmt_class
== IB_MGMT_CLASS_PERF_MGMT
||
92 in_mad
->mad_hdr
.mgmt_class
== MLX5_IB_VENDOR_CLASS1
||
93 in_mad
->mad_hdr
.mgmt_class
== MLX5_IB_VENDOR_CLASS2
||
94 in_mad
->mad_hdr
.mgmt_class
== IB_MGMT_CLASS_CONG_MGMT
) {
95 if (in_mad
->mad_hdr
.method
!= IB_MGMT_METHOD_GET
&&
96 in_mad
->mad_hdr
.method
!= IB_MGMT_METHOD_SET
)
97 return IB_MAD_RESULT_SUCCESS
;
99 return IB_MAD_RESULT_SUCCESS
;
102 err
= mlx5_MAD_IFC(to_mdev(ibdev
),
103 mad_flags
& IB_MAD_IGNORE_MKEY
,
104 mad_flags
& IB_MAD_IGNORE_BKEY
,
105 port_num
, in_wc
, in_grh
, in_mad
, out_mad
);
107 return IB_MAD_RESULT_FAILURE
;
109 /* set return bit in status of directed route responses */
110 if (in_mad
->mad_hdr
.mgmt_class
== IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
)
111 out_mad
->mad_hdr
.status
|= cpu_to_be16(1 << 15);
113 if (in_mad
->mad_hdr
.method
== IB_MGMT_METHOD_TRAP_REPRESS
)
114 /* no response for trap repress */
115 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_CONSUMED
;
117 return IB_MAD_RESULT_SUCCESS
| IB_MAD_RESULT_REPLY
;
120 int mlx5_query_ext_port_caps(struct mlx5_ib_dev
*dev
, u8 port
)
122 struct ib_smp
*in_mad
= NULL
;
123 struct ib_smp
*out_mad
= NULL
;
127 in_mad
= kzalloc(sizeof(*in_mad
), GFP_KERNEL
);
128 out_mad
= kmalloc(sizeof(*out_mad
), GFP_KERNEL
);
129 if (!in_mad
|| !out_mad
)
132 init_query_mad(in_mad
);
133 in_mad
->attr_id
= MLX5_ATTR_EXTENDED_PORT_INFO
;
134 in_mad
->attr_mod
= cpu_to_be32(port
);
136 err
= mlx5_MAD_IFC(dev
, 1, 1, 1, NULL
, NULL
, in_mad
, out_mad
);
138 packet_error
= be16_to_cpu(out_mad
->status
);
140 dev
->mdev
->port_caps
[port
- 1].ext_port_cap
= (!err
&& !packet_error
) ?
141 MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO
: 0;
149 int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device
*ibdev
,
150 struct ib_smp
*out_mad
)
152 struct ib_smp
*in_mad
= NULL
;
155 in_mad
= kzalloc(sizeof(*in_mad
), GFP_KERNEL
);
159 init_query_mad(in_mad
);
160 in_mad
->attr_id
= IB_SMP_ATTR_NODE_INFO
;
162 err
= mlx5_MAD_IFC(to_mdev(ibdev
), 1, 1, 1, NULL
, NULL
, in_mad
,
169 int mlx5_query_mad_ifc_system_image_guid(struct ib_device
*ibdev
,
170 __be64
*sys_image_guid
)
172 struct ib_smp
*out_mad
= NULL
;
175 out_mad
= kmalloc(sizeof(*out_mad
), GFP_KERNEL
);
179 err
= mlx5_query_mad_ifc_smp_attr_node_info(ibdev
, out_mad
);
183 memcpy(sys_image_guid
, out_mad
->data
+ 4, 8);
191 int mlx5_query_mad_ifc_max_pkeys(struct ib_device
*ibdev
,
194 struct ib_smp
*out_mad
= NULL
;
197 out_mad
= kmalloc(sizeof(*out_mad
), GFP_KERNEL
);
201 err
= mlx5_query_mad_ifc_smp_attr_node_info(ibdev
, out_mad
);
205 *max_pkeys
= be16_to_cpup((__be16
*)(out_mad
->data
+ 28));
213 int mlx5_query_mad_ifc_vendor_id(struct ib_device
*ibdev
,
216 struct ib_smp
*out_mad
= NULL
;
219 out_mad
= kmalloc(sizeof(*out_mad
), GFP_KERNEL
);
223 err
= mlx5_query_mad_ifc_smp_attr_node_info(ibdev
, out_mad
);
227 *vendor_id
= be32_to_cpup((__be32
*)(out_mad
->data
+ 36)) & 0xffff;
235 int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev
*dev
, char *node_desc
)
237 struct ib_smp
*in_mad
= NULL
;
238 struct ib_smp
*out_mad
= NULL
;
241 in_mad
= kzalloc(sizeof(*in_mad
), GFP_KERNEL
);
242 out_mad
= kmalloc(sizeof(*out_mad
), GFP_KERNEL
);
243 if (!in_mad
|| !out_mad
)
246 init_query_mad(in_mad
);
247 in_mad
->attr_id
= IB_SMP_ATTR_NODE_DESC
;
249 err
= mlx5_MAD_IFC(dev
, 1, 1, 1, NULL
, NULL
, in_mad
, out_mad
);
253 memcpy(node_desc
, out_mad
->data
, 64);
260 int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev
*dev
, __be64
*node_guid
)
262 struct ib_smp
*in_mad
= NULL
;
263 struct ib_smp
*out_mad
= NULL
;
266 in_mad
= kzalloc(sizeof(*in_mad
), GFP_KERNEL
);
267 out_mad
= kmalloc(sizeof(*out_mad
), GFP_KERNEL
);
268 if (!in_mad
|| !out_mad
)
271 init_query_mad(in_mad
);
272 in_mad
->attr_id
= IB_SMP_ATTR_NODE_INFO
;
274 err
= mlx5_MAD_IFC(dev
, 1, 1, 1, NULL
, NULL
, in_mad
, out_mad
);
278 memcpy(node_guid
, out_mad
->data
+ 12, 8);
285 int mlx5_query_mad_ifc_pkey(struct ib_device
*ibdev
, u8 port
, u16 index
,
288 struct ib_smp
*in_mad
= NULL
;
289 struct ib_smp
*out_mad
= NULL
;
292 in_mad
= kzalloc(sizeof(*in_mad
), GFP_KERNEL
);
293 out_mad
= kmalloc(sizeof(*out_mad
), GFP_KERNEL
);
294 if (!in_mad
|| !out_mad
)
297 init_query_mad(in_mad
);
298 in_mad
->attr_id
= IB_SMP_ATTR_PKEY_TABLE
;
299 in_mad
->attr_mod
= cpu_to_be32(index
/ 32);
301 err
= mlx5_MAD_IFC(to_mdev(ibdev
), 1, 1, port
, NULL
, NULL
, in_mad
,
306 *pkey
= be16_to_cpu(((__be16
*)out_mad
->data
)[index
% 32]);
314 int mlx5_query_mad_ifc_gids(struct ib_device
*ibdev
, u8 port
, int index
,
317 struct ib_smp
*in_mad
= NULL
;
318 struct ib_smp
*out_mad
= NULL
;
321 in_mad
= kzalloc(sizeof(*in_mad
), GFP_KERNEL
);
322 out_mad
= kmalloc(sizeof(*out_mad
), GFP_KERNEL
);
323 if (!in_mad
|| !out_mad
)
326 init_query_mad(in_mad
);
327 in_mad
->attr_id
= IB_SMP_ATTR_PORT_INFO
;
328 in_mad
->attr_mod
= cpu_to_be32(port
);
330 err
= mlx5_MAD_IFC(to_mdev(ibdev
), 1, 1, port
, NULL
, NULL
, in_mad
,
335 memcpy(gid
->raw
, out_mad
->data
+ 8, 8);
337 init_query_mad(in_mad
);
338 in_mad
->attr_id
= IB_SMP_ATTR_GUID_INFO
;
339 in_mad
->attr_mod
= cpu_to_be32(index
/ 8);
341 err
= mlx5_MAD_IFC(to_mdev(ibdev
), 1, 1, port
, NULL
, NULL
, in_mad
,
346 memcpy(gid
->raw
+ 8, out_mad
->data
+ (index
% 8) * 8, 8);
354 int mlx5_query_mad_ifc_port(struct ib_device
*ibdev
, u8 port
,
355 struct ib_port_attr
*props
)
357 struct mlx5_ib_dev
*dev
= to_mdev(ibdev
);
358 struct mlx5_core_dev
*mdev
= dev
->mdev
;
359 struct ib_smp
*in_mad
= NULL
;
360 struct ib_smp
*out_mad
= NULL
;
361 int ext_active_speed
;
364 if (port
< 1 || port
> MLX5_CAP_GEN(mdev
, num_ports
)) {
365 mlx5_ib_warn(dev
, "invalid port number %d\n", port
);
369 in_mad
= kzalloc(sizeof(*in_mad
), GFP_KERNEL
);
370 out_mad
= kmalloc(sizeof(*out_mad
), GFP_KERNEL
);
371 if (!in_mad
|| !out_mad
)
374 memset(props
, 0, sizeof(*props
));
376 init_query_mad(in_mad
);
377 in_mad
->attr_id
= IB_SMP_ATTR_PORT_INFO
;
378 in_mad
->attr_mod
= cpu_to_be32(port
);
380 err
= mlx5_MAD_IFC(dev
, 1, 1, port
, NULL
, NULL
, in_mad
, out_mad
);
382 mlx5_ib_warn(dev
, "err %d\n", err
);
386 props
->lid
= be16_to_cpup((__be16
*)(out_mad
->data
+ 16));
387 props
->lmc
= out_mad
->data
[34] & 0x7;
388 props
->sm_lid
= be16_to_cpup((__be16
*)(out_mad
->data
+ 18));
389 props
->sm_sl
= out_mad
->data
[36] & 0xf;
390 props
->state
= out_mad
->data
[32] & 0xf;
391 props
->phys_state
= out_mad
->data
[33] >> 4;
392 props
->port_cap_flags
= be32_to_cpup((__be32
*)(out_mad
->data
+ 20));
393 props
->gid_tbl_len
= out_mad
->data
[50];
394 props
->max_msg_sz
= 1 << MLX5_CAP_GEN(mdev
, log_max_msg
);
395 props
->pkey_tbl_len
= mdev
->port_caps
[port
- 1].pkey_table_len
;
396 props
->bad_pkey_cntr
= be16_to_cpup((__be16
*)(out_mad
->data
+ 46));
397 props
->qkey_viol_cntr
= be16_to_cpup((__be16
*)(out_mad
->data
+ 48));
398 props
->active_width
= out_mad
->data
[31] & 0xf;
399 props
->active_speed
= out_mad
->data
[35] >> 4;
400 props
->max_mtu
= out_mad
->data
[41] & 0xf;
401 props
->active_mtu
= out_mad
->data
[36] >> 4;
402 props
->subnet_timeout
= out_mad
->data
[51] & 0x1f;
403 props
->max_vl_num
= out_mad
->data
[37] >> 4;
404 props
->init_type_reply
= out_mad
->data
[41] >> 4;
406 /* Check if extended speeds (EDR/FDR/...) are supported */
407 if (props
->port_cap_flags
& IB_PORT_EXTENDED_SPEEDS_SUP
) {
408 ext_active_speed
= out_mad
->data
[62] >> 4;
410 switch (ext_active_speed
) {
412 props
->active_speed
= 16; /* FDR */
415 props
->active_speed
= 32; /* EDR */
420 /* If reported active speed is QDR, check if is FDR-10 */
421 if (props
->active_speed
== 4) {
422 if (mdev
->port_caps
[port
- 1].ext_port_cap
&
423 MLX_EXT_PORT_CAP_FLAG_EXTENDED_PORT_INFO
) {
424 init_query_mad(in_mad
);
425 in_mad
->attr_id
= MLX5_ATTR_EXTENDED_PORT_INFO
;
426 in_mad
->attr_mod
= cpu_to_be32(port
);
428 err
= mlx5_MAD_IFC(dev
, 1, 1, port
,
429 NULL
, NULL
, in_mad
, out_mad
);
433 /* Checking LinkSpeedActive for FDR-10 */
434 if (out_mad
->data
[15] & 0x1)
435 props
->active_speed
= 8;