Commit 4ed134be authored by Alexandre Bounine's avatar Alexandre Bounine Committed by Linus Torvalds

rapidio: update for destination ID allocation

Address comments provided by Andrew Morton:
https://lkml.org/lkml/2012/10/3/550

 - Keeps consistent kerneldoc compatible comments style for new static
   functions.
 - Removes unnecessary complexity from destination ID allocation
   routine.
 - Uses kcalloc() for code clarity.
Signed-off-by: default avatarAlexandre Bounine <alexandre.bounine@idt.com>
Cc: Matt Porter <mporter@kernel.crashing.org>
Cc: Li Yang <leoli@freescale.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2574740d
...@@ -55,9 +55,9 @@ static int rio_mport_phys_table[] = { ...@@ -55,9 +55,9 @@ static int rio_mport_phys_table[] = {
}; };
/* /**
* rio_destid_alloc - Allocate next available destID for given network * rio_destid_alloc - Allocate next available destID for given network
* net: RIO network * @net: RIO network
* *
* Returns next available device destination ID for the specified RIO network. * Returns next available device destination ID for the specified RIO network.
* Marks allocated ID as one in use. * Marks allocated ID as one in use.
...@@ -69,14 +69,9 @@ static u16 rio_destid_alloc(struct rio_net *net) ...@@ -69,14 +69,9 @@ static u16 rio_destid_alloc(struct rio_net *net)
struct rio_id_table *idtab = &net->destid_table; struct rio_id_table *idtab = &net->destid_table;
spin_lock(&idtab->lock); spin_lock(&idtab->lock);
destid = find_next_zero_bit(idtab->table, idtab->max, idtab->next); destid = find_first_zero_bit(idtab->table, idtab->max);
if (destid >= idtab->max)
destid = find_first_zero_bit(idtab->table, idtab->max);
if (destid < idtab->max) { if (destid < idtab->max) {
idtab->next = destid + 1;
if (idtab->next >= idtab->max)
idtab->next = 0;
set_bit(destid, idtab->table); set_bit(destid, idtab->table);
destid += idtab->start; destid += idtab->start;
} else } else
...@@ -86,10 +81,10 @@ static u16 rio_destid_alloc(struct rio_net *net) ...@@ -86,10 +81,10 @@ static u16 rio_destid_alloc(struct rio_net *net)
return (u16)destid; return (u16)destid;
} }
/* /**
* rio_destid_reserve - Reserve the specivied destID * rio_destid_reserve - Reserve the specivied destID
* net: RIO network * @net: RIO network
* destid: destID to reserve * @destid: destID to reserve
* *
* Tries to reserve the specified destID. * Tries to reserve the specified destID.
* Returns 0 if successfull. * Returns 0 if successfull.
...@@ -106,10 +101,10 @@ static int rio_destid_reserve(struct rio_net *net, u16 destid) ...@@ -106,10 +101,10 @@ static int rio_destid_reserve(struct rio_net *net, u16 destid)
return oldbit; return oldbit;
} }
/* /**
* rio_destid_free - free a previously allocated destID * rio_destid_free - free a previously allocated destID
* net: RIO network * @net: RIO network
* destid: destID to free * @destid: destID to free
* *
* Makes the specified destID available for use. * Makes the specified destID available for use.
*/ */
...@@ -123,9 +118,9 @@ static void rio_destid_free(struct rio_net *net, u16 destid) ...@@ -123,9 +118,9 @@ static void rio_destid_free(struct rio_net *net, u16 destid)
spin_unlock(&idtab->lock); spin_unlock(&idtab->lock);
} }
/* /**
* rio_destid_first - return first destID in use * rio_destid_first - return first destID in use
* net: RIO network * @net: RIO network
*/ */
static u16 rio_destid_first(struct rio_net *net) static u16 rio_destid_first(struct rio_net *net)
{ {
...@@ -142,10 +137,10 @@ static u16 rio_destid_first(struct rio_net *net) ...@@ -142,10 +137,10 @@ static u16 rio_destid_first(struct rio_net *net)
return (u16)destid; return (u16)destid;
} }
/* /**
* rio_destid_next - return next destID in use * rio_destid_next - return next destID in use
* net: RIO network * @net: RIO network
* from: destination ID from which search shall continue * @from: destination ID from which search shall continue
*/ */
static u16 rio_destid_next(struct rio_net *net, u16 from) static u16 rio_destid_next(struct rio_net *net, u16 from)
{ {
...@@ -1163,8 +1158,8 @@ static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port, ...@@ -1163,8 +1158,8 @@ static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port,
net = kzalloc(sizeof(struct rio_net), GFP_KERNEL); net = kzalloc(sizeof(struct rio_net), GFP_KERNEL);
if (net && do_enum) { if (net && do_enum) {
net->destid_table.table = kzalloc( net->destid_table.table = kcalloc(
BITS_TO_LONGS(RIO_MAX_ROUTE_ENTRIES(port->sys_size)) * BITS_TO_LONGS(RIO_MAX_ROUTE_ENTRIES(port->sys_size)),
sizeof(long), sizeof(long),
GFP_KERNEL); GFP_KERNEL);
...@@ -1174,7 +1169,6 @@ static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port, ...@@ -1174,7 +1169,6 @@ static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port,
net = NULL; net = NULL;
} else { } else {
net->destid_table.start = start; net->destid_table.start = start;
net->destid_table.next = 0;
net->destid_table.max = net->destid_table.max =
RIO_MAX_ROUTE_ENTRIES(port->sys_size); RIO_MAX_ROUTE_ENTRIES(port->sys_size);
spin_lock_init(&net->destid_table.lock); spin_lock_init(&net->destid_table.lock);
......
...@@ -266,7 +266,6 @@ struct rio_mport { ...@@ -266,7 +266,6 @@ struct rio_mport {
struct rio_id_table { struct rio_id_table {
u16 start; /* logical minimal id */ u16 start; /* logical minimal id */
u16 next; /* hint for find */
u32 max; /* max number of IDs in table */ u32 max; /* max number of IDs in table */
spinlock_t lock; spinlock_t lock;
unsigned long *table; unsigned long *table;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment