Commit 43e36921 authored by sjur.brandeland@stericsson.com's avatar sjur.brandeland@stericsson.com Committed by David S. Miller

caif: Move refcount from service layer to sock and dev.

Instead of having reference counts in caif service layers,
we hook into existing refcount handling in socket layer and netdevice.
Signed-off-by: default avatarSjur Brændeland <sjur.brandeland@stericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cb3cb423
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/stddef.h> #include <linux/stddef.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/rculist.h>
struct cfsrvl { struct cfsrvl {
struct cflayer layer; struct cflayer layer;
...@@ -17,9 +18,11 @@ struct cfsrvl { ...@@ -17,9 +18,11 @@ struct cfsrvl {
bool phy_flow_on; bool phy_flow_on;
bool modem_flow_on; bool modem_flow_on;
bool supports_flowctrl; bool supports_flowctrl;
void (*release)(struct kref *); void (*release)(struct cflayer *layer);
struct dev_info dev_info; struct dev_info dev_info;
struct kref ref; void (*hold)(struct cflayer *lyr);
void (*put)(struct cflayer *lyr);
struct rcu_head rcu;
}; };
struct cflayer *cfvei_create(u8 linkid, struct dev_info *dev_info); struct cflayer *cfvei_create(u8 linkid, struct dev_info *dev_info);
...@@ -29,6 +32,10 @@ struct cflayer *cfvidl_create(u8 linkid, struct dev_info *dev_info); ...@@ -29,6 +32,10 @@ struct cflayer *cfvidl_create(u8 linkid, struct dev_info *dev_info);
struct cflayer *cfrfml_create(u8 linkid, struct dev_info *dev_info, struct cflayer *cfrfml_create(u8 linkid, struct dev_info *dev_info,
int mtu_size); int mtu_size);
struct cflayer *cfdbgl_create(u8 linkid, struct dev_info *dev_info); struct cflayer *cfdbgl_create(u8 linkid, struct dev_info *dev_info);
void cfsrvl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl,
int phyid);
bool cfsrvl_phyid_match(struct cflayer *layer, int phyid); bool cfsrvl_phyid_match(struct cflayer *layer, int phyid);
void cfsrvl_init(struct cfsrvl *service, void cfsrvl_init(struct cfsrvl *service,
...@@ -40,23 +47,19 @@ u8 cfsrvl_getphyid(struct cflayer *layer); ...@@ -40,23 +47,19 @@ u8 cfsrvl_getphyid(struct cflayer *layer);
static inline void cfsrvl_get(struct cflayer *layr) static inline void cfsrvl_get(struct cflayer *layr)
{ {
struct cfsrvl *s; struct cfsrvl *s = container_of(layr, struct cfsrvl, layer);
if (layr == NULL) if (layr == NULL || layr->up == NULL || s->hold == NULL)
return; return;
s = container_of(layr, struct cfsrvl, layer);
kref_get(&s->ref); s->hold(layr->up);
} }
static inline void cfsrvl_put(struct cflayer *layr) static inline void cfsrvl_put(struct cflayer *layr)
{ {
struct cfsrvl *s; struct cfsrvl *s = container_of(layr, struct cfsrvl, layer);
if (layr == NULL) if (layr == NULL || layr->up == NULL || s->hold == NULL)
return; return;
s = container_of(layr, struct cfsrvl, layer);
WARN_ON(!s->release); s->put(layr->up);
if (s->release)
kref_put(&s->ref, s->release);
} }
#endif /* CFSRVL_H_ */ #endif /* CFSRVL_H_ */
...@@ -31,9 +31,9 @@ struct cfrfml { ...@@ -31,9 +31,9 @@ struct cfrfml {
spinlock_t sync; spinlock_t sync;
}; };
static void cfrfml_release(struct kref *kref) static void cfrfml_release(struct cflayer *layer)
{ {
struct cfsrvl *srvl = container_of(kref, struct cfsrvl, ref); struct cfsrvl *srvl = container_of(layer, struct cfsrvl, layer);
struct cfrfml *rfml = container_obj(&srvl->layer); struct cfrfml *rfml = container_obj(&srvl->layer);
if (rfml->incomplete_frm) if (rfml->incomplete_frm)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/module.h>
#include <net/caif/caif_layer.h> #include <net/caif/caif_layer.h>
#include <net/caif/cfsrvl.h> #include <net/caif/cfsrvl.h>
#include <net/caif/cfpkt.h> #include <net/caif/cfpkt.h>
...@@ -27,8 +28,8 @@ static void cfservl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, ...@@ -27,8 +28,8 @@ static void cfservl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl,
{ {
struct cfsrvl *service = container_obj(layr); struct cfsrvl *service = container_obj(layr);
caif_assert(layr->up != NULL); if (layr->up == NULL || layr->up->ctrlcmd == NULL)
caif_assert(layr->up->ctrlcmd != NULL); return;
switch (ctrl) { switch (ctrl) {
case CAIF_CTRLCMD_INIT_RSP: case CAIF_CTRLCMD_INIT_RSP:
...@@ -151,9 +152,9 @@ static int cfservl_modemcmd(struct cflayer *layr, enum caif_modemcmd ctrl) ...@@ -151,9 +152,9 @@ static int cfservl_modemcmd(struct cflayer *layr, enum caif_modemcmd ctrl)
return -EINVAL; return -EINVAL;
} }
static void cfsrvl_release(struct kref *kref) static void cfsrvl_release(struct cflayer *layer)
{ {
struct cfsrvl *service = container_of(kref, struct cfsrvl, ref); struct cfsrvl *service = container_of(layer, struct cfsrvl, layer);
kfree(service); kfree(service);
} }
...@@ -173,10 +174,8 @@ void cfsrvl_init(struct cfsrvl *service, ...@@ -173,10 +174,8 @@ void cfsrvl_init(struct cfsrvl *service,
service->dev_info = *dev_info; service->dev_info = *dev_info;
service->supports_flowctrl = supports_flowctrl; service->supports_flowctrl = supports_flowctrl;
service->release = cfsrvl_release; service->release = cfsrvl_release;
kref_init(&service->ref);
} }
bool cfsrvl_ready(struct cfsrvl *service, int *err) bool cfsrvl_ready(struct cfsrvl *service, int *err)
{ {
if (service->open && service->modem_flow_on && service->phy_flow_on) if (service->open && service->modem_flow_on && service->phy_flow_on)
...@@ -189,6 +188,7 @@ bool cfsrvl_ready(struct cfsrvl *service, int *err) ...@@ -189,6 +188,7 @@ bool cfsrvl_ready(struct cfsrvl *service, int *err)
*err = -EAGAIN; *err = -EAGAIN;
return false; return false;
} }
u8 cfsrvl_getphyid(struct cflayer *layer) u8 cfsrvl_getphyid(struct cflayer *layer)
{ {
struct cfsrvl *servl = container_obj(layer); struct cfsrvl *servl = container_obj(layer);
...@@ -200,3 +200,26 @@ bool cfsrvl_phyid_match(struct cflayer *layer, int phyid) ...@@ -200,3 +200,26 @@ bool cfsrvl_phyid_match(struct cflayer *layer, int phyid)
struct cfsrvl *servl = container_obj(layer); struct cfsrvl *servl = container_obj(layer);
return servl->dev_info.id == phyid; return servl->dev_info.id == phyid;
} }
void caif_free_client(struct cflayer *adap_layer)
{
struct cfsrvl *servl;
if (adap_layer == NULL || adap_layer->dn == NULL)
return;
servl = container_obj(adap_layer->dn);
servl->release(&servl->layer);
}
EXPORT_SYMBOL(caif_free_client);
void caif_client_register_refcnt(struct cflayer *adapt_layer,
void (*hold)(struct cflayer *lyr),
void (*put)(struct cflayer *lyr))
{
struct cfsrvl *service;
service = container_of(adapt_layer->dn, struct cfsrvl, layer);
WARN_ON(adapt_layer == NULL || adapt_layer->dn == NULL);
service->hold = hold;
service->put = put;
}
EXPORT_SYMBOL(caif_client_register_refcnt);
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