mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 07:12:09 +00:00
caif: prepare support for namespaces
Use struct net to reference CAIF configuration object instead of static variables. Refactor functions caif_connect_client, caif_disconnect_client and squach files cfcnfg.c and caif_config_utils. Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
b3ccfbe409
commit
bee925db9a
8 changed files with 176 additions and 261 deletions
|
@ -21,7 +21,6 @@
|
|||
#include <net/net_namespace.h>
|
||||
#include <net/pkt_sched.h>
|
||||
#include <net/caif/caif_device.h>
|
||||
#include <net/caif/caif_dev.h>
|
||||
#include <net/caif/caif_layer.h>
|
||||
#include <net/caif/cfpkt.h>
|
||||
#include <net/caif/cfcnfg.h>
|
||||
|
@ -43,11 +42,21 @@ struct caif_device_entry_list {
|
|||
};
|
||||
|
||||
struct caif_net {
|
||||
struct cfcnfg *cfg;
|
||||
struct caif_device_entry_list caifdevs;
|
||||
};
|
||||
|
||||
static int caif_net_id;
|
||||
static struct cfcnfg *cfg;
|
||||
|
||||
struct cfcnfg *get_cfcnfg(struct net *net)
|
||||
{
|
||||
struct caif_net *caifn;
|
||||
BUG_ON(!net);
|
||||
caifn = net_generic(net, caif_net_id);
|
||||
BUG_ON(!caifn);
|
||||
return caifn->cfg;
|
||||
}
|
||||
EXPORT_SYMBOL(get_cfcnfg);
|
||||
|
||||
static struct caif_device_entry_list *caif_device_list(struct net *net)
|
||||
{
|
||||
|
@ -191,12 +200,17 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what,
|
|||
struct caif_dev_common *caifdev;
|
||||
enum cfcnfg_phy_preference pref;
|
||||
enum cfcnfg_phy_type phy_type;
|
||||
struct cfcnfg *cfg;
|
||||
struct caif_device_entry_list *caifdevs =
|
||||
caif_device_list(dev_net(dev));
|
||||
|
||||
if (dev->type != ARPHRD_CAIF)
|
||||
return 0;
|
||||
|
||||
cfg = get_cfcnfg(dev_net(dev));
|
||||
if (cfg == NULL)
|
||||
return 0;
|
||||
|
||||
switch (what) {
|
||||
case NETDEV_REGISTER:
|
||||
caifd = caif_device_alloc(dev);
|
||||
|
@ -235,7 +249,6 @@ static int caif_device_notify(struct notifier_block *me, unsigned long what,
|
|||
phy_type,
|
||||
dev,
|
||||
&caifd->layer,
|
||||
0,
|
||||
pref,
|
||||
caifdev->use_fcs,
|
||||
caifdev->use_stx);
|
||||
|
@ -323,35 +336,20 @@ static struct notifier_block caif_device_notifier = {
|
|||
.priority = 0,
|
||||
};
|
||||
|
||||
int caif_connect_client(struct caif_connect_request *conn_req,
|
||||
struct cflayer *client_layer, int *ifindex,
|
||||
int *headroom, int *tailroom)
|
||||
{
|
||||
struct cfctrl_link_param param;
|
||||
int ret;
|
||||
|
||||
ret = caif_connect_req_to_link_param(cfg, conn_req, ¶m);
|
||||
if (ret)
|
||||
return ret;
|
||||
/* Hook up the adaptation layer. */
|
||||
return cfcnfg_add_adaptation_layer(cfg, ¶m,
|
||||
client_layer, ifindex,
|
||||
headroom, tailroom);
|
||||
}
|
||||
EXPORT_SYMBOL(caif_connect_client);
|
||||
|
||||
int caif_disconnect_client(struct cflayer *adap_layer)
|
||||
{
|
||||
return cfcnfg_disconn_adapt_layer(cfg, adap_layer);
|
||||
}
|
||||
EXPORT_SYMBOL(caif_disconnect_client);
|
||||
|
||||
/* Per-namespace Caif devices handling */
|
||||
static int caif_init_net(struct net *net)
|
||||
{
|
||||
struct caif_net *caifn = net_generic(net, caif_net_id);
|
||||
BUG_ON(!caifn);
|
||||
INIT_LIST_HEAD(&caifn->caifdevs.list);
|
||||
mutex_init(&caifn->caifdevs.lock);
|
||||
|
||||
caifn->cfg = cfcnfg_create();
|
||||
if (!caifn->cfg) {
|
||||
pr_warn("can't create cfcnfg\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -360,10 +358,17 @@ static void caif_exit_net(struct net *net)
|
|||
struct caif_device_entry *caifd, *tmp;
|
||||
struct caif_device_entry_list *caifdevs =
|
||||
caif_device_list(net);
|
||||
struct cfcnfg *cfg;
|
||||
|
||||
rtnl_lock();
|
||||
mutex_lock(&caifdevs->lock);
|
||||
|
||||
cfg = get_cfcnfg(net);
|
||||
if (cfg == NULL) {
|
||||
mutex_unlock(&caifdevs->lock);
|
||||
return;
|
||||
}
|
||||
|
||||
list_for_each_entry_safe(caifd, tmp, &caifdevs->list, list) {
|
||||
int i = 0;
|
||||
list_del_rcu(&caifd->list);
|
||||
|
@ -382,7 +387,7 @@ static void caif_exit_net(struct net *net)
|
|||
free_percpu(caifd->pcpu_refcnt);
|
||||
kfree(caifd);
|
||||
}
|
||||
|
||||
cfcnfg_remove(cfg);
|
||||
|
||||
mutex_unlock(&caifdevs->lock);
|
||||
rtnl_unlock();
|
||||
|
@ -400,32 +405,22 @@ static int __init caif_device_init(void)
|
|||
{
|
||||
int result;
|
||||
|
||||
cfg = cfcnfg_create();
|
||||
if (!cfg) {
|
||||
pr_warn("can't create cfcnfg\n");
|
||||
goto err_cfcnfg_create_failed;
|
||||
}
|
||||
result = register_pernet_device(&caif_net_ops);
|
||||
|
||||
if (result) {
|
||||
kfree(cfg);
|
||||
cfg = NULL;
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
dev_add_pack(&caif_packet_type);
|
||||
|
||||
register_netdevice_notifier(&caif_device_notifier);
|
||||
dev_add_pack(&caif_packet_type);
|
||||
|
||||
return result;
|
||||
err_cfcnfg_create_failed:
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
static void __exit caif_device_exit(void)
|
||||
{
|
||||
dev_remove_pack(&caif_packet_type);
|
||||
unregister_pernet_device(&caif_net_ops);
|
||||
unregister_netdevice_notifier(&caif_device_notifier);
|
||||
cfcnfg_remove(cfg);
|
||||
dev_remove_pack(&caif_packet_type);
|
||||
}
|
||||
|
||||
module_init(caif_device_init);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue