1219820Sjeff/*
2219820Sjeff * Copyright (c) 2006, 2007 Cisco Systems, Inc.  All rights reserved.
3219820Sjeff * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
4219820Sjeff *
5219820Sjeff * This software is available to you under a choice of one of two
6219820Sjeff * licenses.  You may choose to be licensed under the terms of the GNU
7219820Sjeff * General Public License (GPL) Version 2, available from the file
8219820Sjeff * COPYING in the main directory of this source tree, or the
9219820Sjeff * OpenIB.org BSD license below:
10219820Sjeff *
11219820Sjeff *     Redistribution and use in source and binary forms, with or
12219820Sjeff *     without modification, are permitted provided that the following
13219820Sjeff *     conditions are met:
14219820Sjeff *
15219820Sjeff *      - Redistributions of source code must retain the above
16219820Sjeff *        copyright notice, this list of conditions and the following
17219820Sjeff *        disclaimer.
18219820Sjeff *
19219820Sjeff *      - Redistributions in binary form must reproduce the above
20219820Sjeff *        copyright notice, this list of conditions and the following
21219820Sjeff *        disclaimer in the documentation and/or other materials
22219820Sjeff *        provided with the distribution.
23219820Sjeff *
24219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31219820Sjeff * SOFTWARE.
32219820Sjeff */
33219820Sjeff
34219820Sjeff#include <linux/init.h>
35219820Sjeff#include <linux/errno.h>
36219820Sjeff
37219820Sjeff#include "mlx4.h"
38219820Sjeff
39219820Sjeffint mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn)
40219820Sjeff{
41219820Sjeff	struct mlx4_priv *priv = mlx4_priv(dev);
42219820Sjeff
43219820Sjeff	*xrcdn = mlx4_bitmap_alloc(&priv->xrcd_bitmap);
44219820Sjeff	if (*xrcdn == -1)
45219820Sjeff		return -ENOMEM;
46219820Sjeff
47219820Sjeff	return 0;
48219820Sjeff}
49219820SjeffEXPORT_SYMBOL_GPL(mlx4_xrcd_alloc);
50219820Sjeff
51219820Sjeffvoid mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn)
52219820Sjeff{
53219820Sjeff	mlx4_bitmap_free(&mlx4_priv(dev)->xrcd_bitmap, xrcdn);
54219820Sjeff}
55219820SjeffEXPORT_SYMBOL_GPL(mlx4_xrcd_free);
56219820Sjeff
57219820Sjeffint __devinit mlx4_init_xrcd_table(struct mlx4_dev *dev)
58219820Sjeff{
59219820Sjeff	struct mlx4_priv *priv = mlx4_priv(dev);
60219820Sjeff
61219820Sjeff	return mlx4_bitmap_init(&priv->xrcd_bitmap, (1 << 16),
62219820Sjeff				(1 << 16) - 1, dev->caps.reserved_xrcds + 1, 0);
63219820Sjeff}
64219820Sjeff
65219820Sjeffvoid mlx4_cleanup_xrcd_table(struct mlx4_dev *dev)
66219820Sjeff{
67219820Sjeff	mlx4_bitmap_cleanup(&mlx4_priv(dev)->xrcd_bitmap);
68219820Sjeff}
69219820Sjeff
70219820Sjeff
71