1290650Shselasky/*-
2290650Shselasky * Copyright (c) 2013-2015, Mellanox Technologies, Ltd.  All rights reserved.
3290650Shselasky *
4290650Shselasky * Redistribution and use in source and binary forms, with or without
5290650Shselasky * modification, are permitted provided that the following conditions
6290650Shselasky * are met:
7290650Shselasky * 1. Redistributions of source code must retain the above copyright
8290650Shselasky *    notice, this list of conditions and the following disclaimer.
9290650Shselasky * 2. Redistributions in binary form must reproduce the above copyright
10290650Shselasky *    notice, this list of conditions and the following disclaimer in the
11290650Shselasky *    documentation and/or other materials provided with the distribution.
12290650Shselasky *
13290650Shselasky * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14290650Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15290650Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16290650Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17290650Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18290650Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19290650Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20290650Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21290650Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22290650Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23290650Shselasky * SUCH DAMAGE.
24290650Shselasky *
25290650Shselasky * $FreeBSD$
26290650Shselasky */
27290650Shselasky
28290650Shselasky#include <linux/kernel.h>
29290650Shselasky#include <linux/module.h>
30290650Shselasky#include <dev/mlx5/driver.h>
31290650Shselasky#include "mlx5_core.h"
32290650Shselasky
33290650Shselaskyint mlx5_core_mad_ifc(struct mlx5_core_dev *dev, void *inb, void *outb,
34290650Shselasky		      u16 opmod, u8 port)
35290650Shselasky{
36290650Shselasky	struct mlx5_mad_ifc_mbox_in *in = NULL;
37290650Shselasky	struct mlx5_mad_ifc_mbox_out *out = NULL;
38290650Shselasky	int err;
39290650Shselasky
40290650Shselasky	in = kzalloc(sizeof(*in), GFP_KERNEL);
41290650Shselasky
42290650Shselasky	out = kzalloc(sizeof(*out), GFP_KERNEL);
43290650Shselasky
44290650Shselasky	in->hdr.opcode = cpu_to_be16(MLX5_CMD_OP_MAD_IFC);
45290650Shselasky	in->hdr.opmod = cpu_to_be16(opmod);
46290650Shselasky	in->port = port;
47290650Shselasky
48290650Shselasky	memcpy(in->data, inb, sizeof(in->data));
49290650Shselasky
50290650Shselasky	err = mlx5_cmd_exec(dev, in, sizeof(*in), out, sizeof(*out));
51290650Shselasky	if (err)
52290650Shselasky		goto out;
53290650Shselasky
54290650Shselasky	if (out->hdr.status) {
55290650Shselasky		err = mlx5_cmd_status_to_err(&out->hdr);
56290650Shselasky		goto out;
57290650Shselasky	}
58290650Shselasky
59290650Shselasky	memcpy(outb, out->data, sizeof(out->data));
60290650Shselasky
61290650Shselaskyout:
62290650Shselasky	kfree(out);
63290650Shselasky	kfree(in);
64290650Shselasky	return err;
65290650Shselasky}
66290650ShselaskyEXPORT_SYMBOL_GPL(mlx5_core_mad_ifc);
67