rapidio: move net allocation into core code

Make net allocation/release routines available to all components of
RapidIO subsystem by moving code from rio-scan enumerator.

Make destination ID allocation method private to existing enumerator
because other enumeration methods can use their own algorithm.

Setup net device object as a parent of all RapidIO devices residing in
it and register net as a child of active mport device.

Signed-off-by: Alexandre Bounine <alexandre.bounine@idt.com>
Cc: Matt Porter <mporter@kernel.crashing.org>
Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
Cc: Andre van Herk <andre.van.herk@prodrive-technologies.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Alexandre Bounine
2016-03-22 14:26:17 -07:00
committed by Linus Torvalds
parent b74ec56e8a
commit e6b585ca6e
4 changed files with 133 additions and 49 deletions

View File

@@ -42,6 +42,7 @@ MODULE_PARM_DESC(hdid,
"Destination ID assignment to local RapidIO controllers");
static LIST_HEAD(rio_devices);
static LIST_HEAD(rio_nets);
static DEFINE_SPINLOCK(rio_global_list_lock);
static LIST_HEAD(rio_mports);
@@ -84,6 +85,58 @@ int rio_query_mport(struct rio_mport *port,
}
EXPORT_SYMBOL(rio_query_mport);
/**
* rio_alloc_net- Allocate and initialize a new RIO network data structure
* @mport: Master port associated with the RIO network
*
* Allocates a RIO network structure, initializes per-network
* list heads, and adds the associated master port to the
* network list of associated master ports. Returns a
* RIO network pointer on success or %NULL on failure.
*/
struct rio_net *rio_alloc_net(struct rio_mport *mport)
{
struct rio_net *net;
net = kzalloc(sizeof(struct rio_net), GFP_KERNEL);
if (net) {
INIT_LIST_HEAD(&net->node);
INIT_LIST_HEAD(&net->devices);
INIT_LIST_HEAD(&net->switches);
INIT_LIST_HEAD(&net->mports);
mport->net = net;
}
return net;
}
EXPORT_SYMBOL_GPL(rio_alloc_net);
int rio_add_net(struct rio_net *net)
{
int err;
err = device_register(&net->dev);
if (err)
return err;
spin_lock(&rio_global_list_lock);
list_add_tail(&net->node, &rio_nets);
spin_unlock(&rio_global_list_lock);
return 0;
}
EXPORT_SYMBOL_GPL(rio_add_net);
void rio_free_net(struct rio_net *net)
{
spin_lock(&rio_global_list_lock);
if (!list_empty(&net->node))
list_del(&net->node);
spin_unlock(&rio_global_list_lock);
if (net->release)
net->release(net);
device_unregister(&net->dev);
}
EXPORT_SYMBOL_GPL(rio_free_net);
/**
* rio_add_device- Adds a RIO device to the device model
* @rdev: RIO device