On 04-Dec-18 18:03, Jason Gunthorpe wrote: > On Tue, Dec 04, 2018 at 02:04:26PM +0200, Gal Pressman wrote: >> Bitmap allocation service is currently used for assigning >> Protection Domain (PD) numbers. >> >> Signed-off-by: Gal Pressman <galpress@xxxxxxxxxx> >> drivers/infiniband/hw/efa/efa_bitmap.c | 76 ++++++++++++++++++++++++++++++++++ >> 1 file changed, 76 insertions(+) >> create mode 100644 drivers/infiniband/hw/efa/efa_bitmap.c >> >> diff --git a/drivers/infiniband/hw/efa/efa_bitmap.c b/drivers/infiniband/hw/efa/efa_bitmap.c >> new file mode 100644 >> index 000000000000..251cc68d25f5 >> +++ b/drivers/infiniband/hw/efa/efa_bitmap.c >> @@ -0,0 +1,76 @@ >> +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB >> +/* >> + * Copyright 2006, 2007 Cisco Systems, Inc. All rights reserved. >> + * Copyright 2007, 2008 Mellanox Technologies. All rights reserved. >> + * Copyright 2018 Amazon.com, Inc. or its affiliates. >> + */ >> + >> +#include <linux/bitmap.h> >> + >> +#include "efa.h" >> + >> +u32 efa_bitmap_alloc(struct efa_bitmap *bitmap) >> +{ >> + u32 obj; >> + >> + spin_lock(&bitmap->lock); >> + >> + obj = find_next_zero_bit(bitmap->table, bitmap->max, bitmap->last); >> + if (obj >= bitmap->max) >> + obj = find_first_zero_bit(bitmap->table, bitmap->max); >> + >> + if (obj < bitmap->max) { >> + set_bit(obj, bitmap->table); >> + bitmap->last = obj + 1; >> + if (bitmap->last == bitmap->max) >> + bitmap->last = 0; >> + } else { >> + obj = EFA_BITMAP_INVAL; >> + } >> + >> + if (obj != EFA_BITMAP_INVAL) >> + --bitmap->avail; >> + >> + spin_unlock(&bitmap->lock); >> + >> + return obj; >> +} > > Isn't this just an ida? > > Jason > Will examine.