33 #include <linux/kernel.h>
34 #include <linux/random.h>
35 #include <linux/slab.h>
38 #include <linux/errno.h>
42 static struct kfifo rhdl_fifo;
45 #define RANDOM_SIZE 16
47 static int __cxio_init_resource_fifo(
struct kfifo *
fifo,
61 for (i = 0; i < skip_low + skip_high; i++)
62 kfifo_in(fifo, (
unsigned char *) &entry,
sizeof(
u32));
67 rarray[i] = i + skip_low;
68 for (i = skip_low + RANDOM_SIZE; i < nr - skip_high; i++) {
69 if (j >= RANDOM_SIZE) {
73 idx = (random_bytes >> (j * 2)) & 0xF;
75 (
unsigned char *) &rarray[
idx],
82 (
unsigned char *) &rarray[i],
85 for (i = skip_low; i < nr - skip_high; i++)
88 for (i = 0; i < skip_low + skip_high; i++)
90 sizeof(
u32), fifo_lock) !=
sizeof(
u32))
95 static int cxio_init_resource_fifo(
struct kfifo *
fifo,
spinlock_t * fifo_lock,
98 return (__cxio_init_resource_fifo(fifo, fifo_lock, nr, skip_low,
102 static int cxio_init_resource_fifo_random(
struct kfifo *fifo,
107 return (__cxio_init_resource_fifo(fifo, fifo_lock, nr, skip_low,
111 static int cxio_init_qpid_fifo(
struct cxio_rdev *rdev_p)
122 if (!(i & rdev_p->
qpmask))
124 (
unsigned char *) &i,
sizeof(
u32));
130 return cxio_init_resource_fifo(&rhdl_fifo, &rhdl_fifo_lock, nr_rhdl, 1,
151 err = cxio_init_resource_fifo_random(&rscp->
tpt_fifo,
156 err = cxio_init_qpid_fifo(rdev_p);
181 static u32 cxio_hal_get_resource(
struct kfifo *fifo,
spinlock_t * lock)
190 static void cxio_hal_put_resource(
struct kfifo *fifo,
spinlock_t * lock,
212 PDBG(
"%s qpid 0x%x\n", __func__, qpid);
218 PDBG(
"%s qpid 0x%x\n", __func__, qpid);
255 #define MIN_PBL_SHIFT 8
260 PDBG(
"%s addr 0x%x size %d\n", __func__, (
u32)addr, size);
266 PDBG(
"%s addr 0x%x size %d\n", __func__, addr, size);
272 unsigned pbl_start, pbl_chunk;
279 pbl_chunk = rdev_p->
rnic_info.pbl_top - pbl_start + 1;
281 while (pbl_start < rdev_p->rnic_info.pbl_top) {
282 pbl_chunk =
min(rdev_p->
rnic_info.pbl_top - pbl_start + 1,
284 if (gen_pool_add(rdev_p->
pbl_pool, pbl_start, pbl_chunk, -1)) {
285 PDBG(
"%s failed to add PBL chunk (%x/%x)\n",
286 __func__, pbl_start, pbl_chunk);
289 __func__, pbl_start, rdev_p->
rnic_info.pbl_top - pbl_start);
294 PDBG(
"%s added PBL chunk (%x/%x)\n",
295 __func__, pbl_start, pbl_chunk);
296 pbl_start += pbl_chunk;
312 #define MIN_RQT_SHIFT 10
313 #define RQT_CHUNK 2*1024*1024
318 PDBG(
"%s addr 0x%x size %d\n", __func__, (
u32)addr, size << 6);
324 PDBG(
"%s addr 0x%x size %d\n", __func__, addr, size << 6);
334 i <= rdev_p->rnic_info.rqt_top -
RQT_CHUNK + 1;