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_alloc_pd(struct mlx5_core_dev *dev, u32 *pdn) 34290650Shselasky{ 35290650Shselasky u32 in[MLX5_ST_SZ_DW(alloc_pd_in)]; 36290650Shselasky u32 out[MLX5_ST_SZ_DW(alloc_pd_out)]; 37290650Shselasky int err; 38290650Shselasky 39290650Shselasky memset(in, 0, sizeof(in)); 40290650Shselasky 41290650Shselasky MLX5_SET(alloc_pd_in, in, opcode, MLX5_CMD_OP_ALLOC_PD); 42290650Shselasky 43290650Shselasky memset(out, 0, sizeof(out)); 44290650Shselasky err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out)); 45290650Shselasky if (err) 46290650Shselasky return err; 47290650Shselasky 48290650Shselasky *pdn = MLX5_GET(alloc_pd_out, out, pd); 49290650Shselasky return 0; 50290650Shselasky} 51290650ShselaskyEXPORT_SYMBOL(mlx5_core_alloc_pd); 52290650Shselasky 53290650Shselaskyint mlx5_core_dealloc_pd(struct mlx5_core_dev *dev, u32 pdn) 54290650Shselasky{ 55290650Shselasky u32 in[MLX5_ST_SZ_DW(dealloc_pd_in)]; 56290650Shselasky u32 out[MLX5_ST_SZ_DW(dealloc_pd_out)]; 57290650Shselasky 58290650Shselasky memset(in, 0, sizeof(in)); 59290650Shselasky 60290650Shselasky MLX5_SET(dealloc_pd_in, in, opcode, MLX5_CMD_OP_DEALLOC_PD); 61290650Shselasky MLX5_SET(dealloc_pd_in, in, pd, pdn); 62290650Shselasky 63290650Shselasky memset(out, 0, sizeof(out)); 64290650Shselasky return mlx5_cmd_exec_check_status(dev, in, sizeof(in), 65290650Shselasky out, sizeof(out)); 66290650Shselasky} 67290650ShselaskyEXPORT_SYMBOL(mlx5_core_dealloc_pd); 68