aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSjur Braendeland <sjur.brandeland@stericsson.com>2010-04-28 04:54:36 -0400
committerDavid S. Miller <davem@davemloft.net>2010-04-28 15:55:12 -0400
commit5b2086567503f9b55136642031ec0067319f58e0 (patch)
tree00c4264ed7a8a989b398166c2c5f98175f5c28a5
parente539d83cc8a4fa581cbf8ed288fdadb19a692cb0 (diff)
caif: Add reference counting to service layer
Changes: o Added functions cfsrvl_get and cfsrvl_put. o Added support release_client to use by socket and net device. o Increase reference counting for in-flight packets from cfmuxl Signed-off-by: Sjur Braendeland <sjur.brandeland@stericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/caif/caif_dev.h11
-rw-r--r--include/net/caif/cfcnfg.h7
-rw-r--r--include/net/caif/cfsrvl.h22
-rw-r--r--net/caif/caif_dev.c6
-rw-r--r--net/caif/cfcnfg.c7
-rw-r--r--net/caif/cfmuxl.c7
-rw-r--r--net/caif/cfsrvl.c7
7 files changed, 66 insertions, 1 deletions
diff --git a/include/net/caif/caif_dev.h b/include/net/caif/caif_dev.h
index 3aa1ff642323..318ab9478a44 100644
--- a/include/net/caif/caif_dev.h
+++ b/include/net/caif/caif_dev.h
@@ -70,6 +70,17 @@ int caif_connect_client(struct caif_connect_request *config,
70int caif_disconnect_client(struct cflayer *client_layer); 70int caif_disconnect_client(struct cflayer *client_layer);
71 71
72/** 72/**
73 * caif_release_client - Release adaptation layer reference to client.
74 *
75 * @client_layer: Client layer.
76 *
77 * Releases a client/adaptation layer use of the caif stack.
78 * This function must be used after caif_disconnect_client to
79 * decrease the reference count of the service layer.
80 */
81void caif_release_client(struct cflayer *client_layer);
82
83/**
73 * connect_req_to_link_param - Translate configuration parameters 84 * connect_req_to_link_param - Translate configuration parameters
74 * from socket format to internal format. 85 * from socket format to internal format.
75 * @cnfg: Pointer to configuration handler 86 * @cnfg: Pointer to configuration handler
diff --git a/include/net/caif/cfcnfg.h b/include/net/caif/cfcnfg.h
index f16b875acc48..9fc2fc20b884 100644
--- a/include/net/caif/cfcnfg.h
+++ b/include/net/caif/cfcnfg.h
@@ -97,6 +97,13 @@ int cfcnfg_disconn_adapt_layer(struct cfcnfg *cnfg,
97 struct cflayer *adap_layer); 97 struct cflayer *adap_layer);
98 98
99/** 99/**
100 * cfcnfg_release_adap_layer - Used by client to release the adaptation layer.
101 *
102 * @adap_layer: Adaptation layer.
103 */
104void cfcnfg_release_adap_layer(struct cflayer *adap_layer);
105
106/**
100 * cfcnfg_add_adaptation_layer - Add an adaptation layer to the CAIF stack. 107 * cfcnfg_add_adaptation_layer - Add an adaptation layer to the CAIF stack.
101 * 108 *
102 * The adaptation Layer is where the interface to application or higher-level 109 * The adaptation Layer is where the interface to application or higher-level
diff --git a/include/net/caif/cfsrvl.h b/include/net/caif/cfsrvl.h
index b2a12db20cd2..2dc9eb193ecf 100644
--- a/include/net/caif/cfsrvl.h
+++ b/include/net/caif/cfsrvl.h
@@ -9,14 +9,18 @@
9#include <linux/list.h> 9#include <linux/list.h>
10#include <linux/stddef.h> 10#include <linux/stddef.h>
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/kref.h>
13
12struct cfsrvl { 14struct cfsrvl {
13 struct cflayer layer; 15 struct cflayer layer;
14 bool open; 16 bool open;
15 bool phy_flow_on; 17 bool phy_flow_on;
16 bool modem_flow_on; 18 bool modem_flow_on;
17 struct dev_info dev_info; 19 struct dev_info dev_info;
20 struct kref ref;
18}; 21};
19 22
23void cfsrvl_release(struct kref *kref);
20struct cflayer *cfvei_create(u8 linkid, struct dev_info *dev_info); 24struct cflayer *cfvei_create(u8 linkid, struct dev_info *dev_info);
21struct cflayer *cfdgml_create(u8 linkid, struct dev_info *dev_info); 25struct cflayer *cfdgml_create(u8 linkid, struct dev_info *dev_info);
22struct cflayer *cfutill_create(u8 linkid, struct dev_info *dev_info); 26struct cflayer *cfutill_create(u8 linkid, struct dev_info *dev_info);
@@ -31,4 +35,22 @@ void cfsrvl_init(struct cfsrvl *service,
31bool cfsrvl_ready(struct cfsrvl *service, int *err); 35bool cfsrvl_ready(struct cfsrvl *service, int *err);
32u8 cfsrvl_getphyid(struct cflayer *layer); 36u8 cfsrvl_getphyid(struct cflayer *layer);
33 37
38static inline void cfsrvl_get(struct cflayer *layr)
39{
40 struct cfsrvl *s;
41 if (layr == NULL)
42 return;
43 s = container_of(layr, struct cfsrvl, layer);
44 kref_get(&s->ref);
45}
46
47static inline void cfsrvl_put(struct cflayer *layr)
48{
49 struct cfsrvl *s;
50 if (layr == NULL)
51 return;
52 s = container_of(layr, struct cfsrvl, layer);
53 kref_put(&s->ref, cfsrvl_release);
54}
55
34#endif /* CFSRVL_H_ */ 56#endif /* CFSRVL_H_ */
diff --git a/net/caif/caif_dev.c b/net/caif/caif_dev.c
index be1f674a3b67..0145bae0274f 100644
--- a/net/caif/caif_dev.c
+++ b/net/caif/caif_dev.c
@@ -346,6 +346,12 @@ int caif_disconnect_client(struct cflayer *adap_layer)
346} 346}
347EXPORT_SYMBOL(caif_disconnect_client); 347EXPORT_SYMBOL(caif_disconnect_client);
348 348
349void caif_release_client(struct cflayer *adap_layer)
350{
351 cfcnfg_release_adap_layer(adap_layer);
352}
353EXPORT_SYMBOL(caif_release_client);
354
349/* Per-namespace Caif devices handling */ 355/* Per-namespace Caif devices handling */
350static int caif_init_net(struct net *net) 356static int caif_init_net(struct net *net)
351{ 357{
diff --git a/net/caif/cfcnfg.c b/net/caif/cfcnfg.c
index d52f2566916e..f94f3dfe85c1 100644
--- a/net/caif/cfcnfg.c
+++ b/net/caif/cfcnfg.c
@@ -247,6 +247,13 @@ end:
247} 247}
248EXPORT_SYMBOL(cfcnfg_disconn_adapt_layer); 248EXPORT_SYMBOL(cfcnfg_disconn_adapt_layer);
249 249
250void cfcnfg_release_adap_layer(struct cflayer *adap_layer)
251{
252 if (adap_layer->dn)
253 cfsrvl_put(adap_layer->dn);
254}
255EXPORT_SYMBOL(cfcnfg_release_adap_layer);
256
250static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id, 257static void cfcnfg_linkdestroy_rsp(struct cflayer *layer, u8 channel_id,
251 struct cflayer *client_layer) 258 struct cflayer *client_layer)
252{ 259{
diff --git a/net/caif/cfmuxl.c b/net/caif/cfmuxl.c
index 6fb9f9e96cf8..7372f27f1d32 100644
--- a/net/caif/cfmuxl.c
+++ b/net/caif/cfmuxl.c
@@ -62,6 +62,7 @@ int cfmuxl_set_uplayer(struct cflayer *layr, struct cflayer *up, u8 linkid)
62{ 62{
63 struct cfmuxl *muxl = container_obj(layr); 63 struct cfmuxl *muxl = container_obj(layr);
64 spin_lock(&muxl->receive_lock); 64 spin_lock(&muxl->receive_lock);
65 cfsrvl_get(up);
65 list_add(&up->node, &muxl->srvl_list); 66 list_add(&up->node, &muxl->srvl_list);
66 spin_unlock(&muxl->receive_lock); 67 spin_unlock(&muxl->receive_lock);
67 return 0; 68 return 0;
@@ -172,8 +173,11 @@ struct cflayer *cfmuxl_remove_uplayer(struct cflayer *layr, u8 id)
172 struct cfmuxl *muxl = container_obj(layr); 173 struct cfmuxl *muxl = container_obj(layr);
173 spin_lock(&muxl->receive_lock); 174 spin_lock(&muxl->receive_lock);
174 up = get_up(muxl, id); 175 up = get_up(muxl, id);
176 if (up == NULL)
177 return NULL;
175 memset(muxl->up_cache, 0, sizeof(muxl->up_cache)); 178 memset(muxl->up_cache, 0, sizeof(muxl->up_cache));
176 list_del(&up->node); 179 list_del(&up->node);
180 cfsrvl_put(up);
177 spin_unlock(&muxl->receive_lock); 181 spin_unlock(&muxl->receive_lock);
178 return up; 182 return up;
179} 183}
@@ -203,8 +207,9 @@ static int cfmuxl_receive(struct cflayer *layr, struct cfpkt *pkt)
203 */ 207 */
204 return /* CFGLU_EPROT; */ 0; 208 return /* CFGLU_EPROT; */ 0;
205 } 209 }
206 210 cfsrvl_get(up);
207 ret = up->receive(up, pkt); 211 ret = up->receive(up, pkt);
212 cfsrvl_put(up);
208 return ret; 213 return ret;
209} 214}
210 215
diff --git a/net/caif/cfsrvl.c b/net/caif/cfsrvl.c
index d470c51c6431..aff31f34528f 100644
--- a/net/caif/cfsrvl.c
+++ b/net/caif/cfsrvl.c
@@ -158,6 +158,13 @@ void cfsrvl_init(struct cfsrvl *service,
158 service->layer.ctrlcmd = cfservl_ctrlcmd; 158 service->layer.ctrlcmd = cfservl_ctrlcmd;
159 service->layer.modemcmd = cfservl_modemcmd; 159 service->layer.modemcmd = cfservl_modemcmd;
160 service->dev_info = *dev_info; 160 service->dev_info = *dev_info;
161 kref_init(&service->ref);
162}
163
164void cfsrvl_release(struct kref *kref)
165{
166 struct cfsrvl *service = container_of(kref, struct cfsrvl, ref);
167 kfree(service);
161} 168}
162 169
163bool cfsrvl_ready(struct cfsrvl *service, int *err) 170bool cfsrvl_ready(struct cfsrvl *service, int *err)