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 <rdma/ib_verbs.h>
32290650Shselasky#include "mlx5_core.h"
33290650Shselasky
34290650Shselaskyint mlx5_core_attach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn)
35290650Shselasky{
36290650Shselasky	u32 in[MLX5_ST_SZ_DW(attach_to_mcg_in)];
37290650Shselasky	u32 out[MLX5_ST_SZ_DW(attach_to_mcg_out)];
38290650Shselasky
39290650Shselasky	memset(in, 0, sizeof(in));
40290650Shselasky
41290650Shselasky	MLX5_SET(attach_to_mcg_in, in, opcode, MLX5_CMD_OP_ATTACH_TO_MCG);
42290650Shselasky	MLX5_SET(attach_to_mcg_in, in, qpn, qpn);
43290650Shselasky	memcpy(MLX5_ADDR_OF(attach_to_mcg_in, in, multicast_gid), mgid,
44290650Shselasky	       sizeof(*mgid));
45290650Shselasky
46290650Shselasky	memset(out, 0, sizeof(out));
47290650Shselasky	return mlx5_cmd_exec_check_status(dev, in,  sizeof(in),
48290650Shselasky					       out, sizeof(out));
49290650Shselasky}
50290650ShselaskyEXPORT_SYMBOL(mlx5_core_attach_mcg);
51290650Shselasky
52290650Shselaskyint mlx5_core_detach_mcg(struct mlx5_core_dev *dev, union ib_gid *mgid, u32 qpn)
53290650Shselasky{
54290650Shselasky	u32 in[MLX5_ST_SZ_DW(detach_from_mcg_in)];
55290650Shselasky	u32 out[MLX5_ST_SZ_DW(detach_from_mcg_out)];
56290650Shselasky
57290650Shselasky	memset(in, 0, sizeof(in));
58290650Shselasky
59290650Shselasky	MLX5_SET(detach_from_mcg_in, in, opcode, MLX5_CMD_OP_DETACH_FROM_MCG);
60290650Shselasky	MLX5_SET(detach_from_mcg_in, in, qpn, qpn);
61290650Shselasky	memcpy(MLX5_ADDR_OF(detach_from_mcg_in, in, multicast_gid), mgid,
62290650Shselasky	       sizeof(*mgid));
63290650Shselasky
64290650Shselasky	memset(out, 0, sizeof(out));
65290650Shselasky	return mlx5_cmd_exec_check_status(dev, in,  sizeof(in),
66290650Shselasky					       out, sizeof(out));
67290650Shselasky}
68290650ShselaskyEXPORT_SYMBOL(mlx5_core_detach_mcg);
69