2 * Copyright (c) 2000, 2011 Mellanox Technology Inc. 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
40 #include <sys/types.h>
47 /* Only ia64 requires this */
49 #define MLX5_SHM_ADDR ((void *)0x8000000000000000UL)
50 #define MLX5_SHMAT_FLAGS (SHM_RND)
52 #define MLX5_SHM_ADDR NULL
53 #define MLX5_SHMAT_FLAGS 0
56 #define BITS_PER_LONG (8 * sizeof(long))
57 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_LONG)
60 #define HPAGE_SIZE (2UL * 1024 * 1024)
63 #define MLX5_SHM_LENGTH HPAGE_SIZE
64 #define MLX5_Q_CHUNK_SIZE 32768
65 #define MLX5_SHM_NUM_REGION 64
67 static inline unsigned long mlx5_ffz(uint32_t word)
69 return __builtin_ffs(~word) - 1;
72 static inline uint32_t mlx5_find_first_zero_bit(const unsigned long *addr,
75 const unsigned long *p = addr;
79 while (size & ~(BITS_PER_LONG - 1)) {
83 result += BITS_PER_LONG;
84 size -= BITS_PER_LONG;
89 tmp = (*p) | (~0UL << size);
90 if (tmp == (uint32_t)~0UL) /* Are any bits zero? */
91 return result + size; /* Nope. */
93 return result + mlx5_ffz(tmp);
96 static inline void mlx5_set_bit(unsigned int nr, unsigned long *addr)
98 addr[(nr / BITS_PER_LONG)] |= (1 << (nr % BITS_PER_LONG));
101 static inline void mlx5_clear_bit(unsigned int nr, unsigned long *addr)
103 addr[(nr / BITS_PER_LONG)] &= ~(1 << (nr % BITS_PER_LONG));
106 static inline int mlx5_test_bit(unsigned int nr, const unsigned long *addr)
108 return !!(addr[(nr / BITS_PER_LONG)] & (1 << (nr % BITS_PER_LONG)));