summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>2010-07-13 19:38:13 +0000
committerTzafrir Cohen <tzafrir.cohen@xorcom.com>2010-07-13 19:38:13 +0000
commit4be5101ff455df8ed4097977587cf2f34addb7cc (patch)
tree35f5fcc4ddc405988864af7a80fcffb2271db1b6 /drivers
parentce0d2d4620f49e6ac0ec697733c786369ad8c822 (diff)
start migrating from xbus_num() to get_xbus()/put_xbus()
* Now get_xbus() receive and xbus number (not poiner) and uses xbus_num() internally to map it to an xbus pointer + refcount increment. (this is atomic) * Migrate all obvious places that used xbus_num() to map bus number into a pointer, so now they use get_xbus() + put_xbus() to aquire and release an xbus. git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@8913 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'drivers')
-rw-r--r--drivers/dahdi/xpp/xbus-core.c55
-rw-r--r--drivers/dahdi/xpp/xbus-core.h8
-rw-r--r--drivers/dahdi/xpp/xbus-pcm.c26
-rw-r--r--drivers/dahdi/xpp/xpp_dahdi.c4
4 files changed, 55 insertions, 38 deletions
diff --git a/drivers/dahdi/xpp/xbus-core.c b/drivers/dahdi/xpp/xbus-core.c
index 6b331e0..144d565 100644
--- a/drivers/dahdi/xpp/xbus-core.c
+++ b/drivers/dahdi/xpp/xbus-core.c
@@ -189,11 +189,19 @@ static void xbus_destroy(struct kref *kref)
xbus_sysfs_remove(xbus);
}
-xbus_t *get_xbus(const char *msg, xbus_t *xbus)
+xbus_t *get_xbus(const char *msg, uint num)
{
- XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n",
- msg, refcount_xbus(xbus));
- kref_get(&xbus->kref);
+ unsigned long flags;
+ xbus_t *xbus;
+
+ spin_lock_irqsave(&xbuses_lock, flags);
+ xbus = xbus_num(num);
+ if (xbus != NULL) {
+ kref_get(&xbus->kref);
+ XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n",
+ msg, refcount_xbus(xbus));
+ }
+ spin_unlock_irqrestore(&xbuses_lock, flags);
return xbus;
}
@@ -999,7 +1007,7 @@ void xbus_populate(void *data)
int ret = 0;
xbus = container_of(worker, xbus_t, worker);
- xbus = get_xbus(__func__, xbus); /* return in function end */
+ xbus = get_xbus(__func__, xbus->num); /* return in function end */
XBUS_DBG(DEVICES, xbus, "Entering %s\n", __FUNCTION__);
spin_lock_irqsave(&worker->worker_lock, flags);
list_for_each_safe(card, next_card, &worker->card_list) {
@@ -1169,7 +1177,7 @@ static int worker_run(xbus_t *xbus)
{
struct xbus_workqueue *worker;
- xbus = get_xbus(__func__, xbus); /* return in worker_destroy() */
+ xbus = get_xbus(__func__, xbus->num); /* return in worker_destroy() */
BUG_ON(!xbus);
BUG_ON(xbus->busname[0] == '\0'); /* No name? */
worker = &xbus->worker;
@@ -1337,6 +1345,7 @@ void xbus_deactivate(xbus_t *xbus)
if(!xbus_setstate(xbus, XBUS_STATE_DEACTIVATING))
return;
xbus_request_sync(xbus, SYNC_MODE_NONE); /* no more ticks */
+ elect_syncer("deactivate");
xbus_request_removal(xbus);
XBUS_DBG(DEVICES, xbus, "[%s] Waiting for queues\n", xbus->label);
xbus_command_queue_clean(xbus);
@@ -1344,7 +1353,6 @@ void xbus_deactivate(xbus_t *xbus)
xbus_setstate(xbus, XBUS_STATE_DEACTIVATED);
worker_reset(xbus);
xbus_release_xpds(xbus); /* taken in xpd_alloc() [kref_init] */
- elect_syncer("deactivate");
}
void xbus_disconnect(xbus_t *xbus)
@@ -1585,7 +1593,8 @@ int waitfor_xpds(xbus_t *xbus, char *buf)
* FIXME: worker is created before ?????
* So by now it exists and initialized.
*/
- xbus = get_xbus(__func__, xbus); /* until end of waitfor_xpds_show() */
+ /* until end of waitfor_xpds_show(): */
+ xbus = get_xbus(__func__, xbus->num);
if (!xbus)
return -ENODEV;
worker = &xbus->worker;
@@ -1663,10 +1672,9 @@ static int xbus_read_proc(char *page, char **start, off_t off, int count, int *e
int len = 0;
int i = (int)((unsigned long)data);
- xbus = xbus_num(i);
+ xbus = get_xbus(__func__, i); /* until end of xbus_read_proc */
if(!xbus)
goto out;
- xbus = get_xbus(__FUNCTION__, xbus); /* until end of xbus_read_proc */
spin_lock_irqsave(&xbus->lock, flags);
worker = &xbus->worker;
@@ -1734,17 +1742,18 @@ out:
static int xbus_read_waitfor_xpds(char *page, char **start, off_t off, int count, int *eof, void *data)
{
int len = 0;
- xbus_t *xbus = data;
+ int i = (int)((unsigned long)data);
+ xbus_t *xbus;
- if(!xbus)
- goto out;
- XBUS_NOTICE(xbus, "%s: DEPRECATED: %s[%d] read from /proc interface instead of /sys\n",
- __FUNCTION__, current->comm, current->tgid);
- /* first handle special cases */
- if(!count || off)
- goto out;
- len = waitfor_xpds(xbus, page);
-out:
+ xbus = get_xbus(__func__, i);
+ if (xbus != NULL) {
+ XBUS_NOTICE(xbus, "%s: DEPRECATED: %s[%d] read from /proc interface instead of /sys\n",
+ __func__, current->comm, current->tgid);
+ /* first handle special cases */
+ if (count && !off)
+ len = waitfor_xpds(xbus, page);
+ put_xbus(__func__, xbus);
+ }
if (len <= off+count)
*eof = 1;
*start = page + off;
@@ -1841,12 +1850,10 @@ out:
static int read_proc_xbuses(char *page, char **start, off_t off, int count, int *eof, void *data)
{
int len = 0;
- unsigned long flags;
int i;
- spin_lock_irqsave(&xbuses_lock, flags);
for(i = 0; i < MAX_BUSES; i++) {
- xbus_t *xbus = xbus_num(i);
+ xbus_t *xbus = get_xbus(__func__, i);
if(xbus) {
len += sprintf(page + len, "%s: CONNECTOR=%s LABEL=[%s] STATUS=%s\n",
@@ -1855,12 +1862,12 @@ static int read_proc_xbuses(char *page, char **start, off_t off, int count, int
xbus->label,
(XBUS_FLAGS(xbus, CONNECTED)) ? "connected" : "missing"
);
+ put_xbus(__func__, xbus);
}
}
#if 0
len += sprintf(page + len, "<-- len=%d\n", len);
#endif
- spin_unlock_irqrestore(&xbuses_lock, flags);
if (len <= off+count)
*eof = 1;
*start = page + off;
diff --git a/drivers/dahdi/xpp/xbus-core.h b/drivers/dahdi/xpp/xbus-core.h
index 4fbc57b..536acaf 100644
--- a/drivers/dahdi/xpp/xbus-core.h
+++ b/drivers/dahdi/xpp/xbus-core.h
@@ -158,10 +158,10 @@ void put_xframe(struct xframe_queue *q, xframe_t *xframe);
#define FREE_SEND_XFRAME(xbus, xframe) put_xframe(&(xbus)->send_pool, (xframe))
#define FREE_RECV_XFRAME(xbus, xframe) put_xframe(&(xbus)->receive_pool, (xframe))
-xbus_t *xbus_num(uint num);
-xbus_t *get_xbus(const char *msg, xbus_t *xbus);
-void put_xbus(const char *msg, xbus_t *xbus);
-int refcount_xbus(xbus_t *xbus);
+xbus_t *xbus_num(uint num);
+xbus_t *get_xbus(const char *msg, uint num);
+void put_xbus(const char *msg, xbus_t *xbus);
+int refcount_xbus(xbus_t *xbus);
/*
* An xbus is a transport layer for Xorcom Protocol commands
diff --git a/drivers/dahdi/xpp/xbus-pcm.c b/drivers/dahdi/xpp/xbus-pcm.c
index ca722cf..ce5c0fa 100644
--- a/drivers/dahdi/xpp/xbus-pcm.c
+++ b/drivers/dahdi/xpp/xbus-pcm.c
@@ -440,9 +440,9 @@ static void reset_sync_counters(void)
//DBG(SYNC, "%d\n", atomic_read(&xpp_tick_counter));
for(i = 0; i < MAX_BUSES; i++) {
- xbus_t *xbus = xbus_num(i);
+ xbus_t *xbus = get_xbus(__func__, i);
- if(!xbus)
+ if (xbus == NULL)
continue;
/*
* Don't send to non self_ticking Astribanks:
@@ -459,6 +459,7 @@ static void reset_sync_counters(void)
CALL_PROTO(GLOBAL, RESET_SYNC_COUNTERS, xbus, NULL);
}
}
+ put_xbus(__func__, xbus);
}
}
@@ -589,8 +590,8 @@ static void update_sync_master(xbus_t *new_syncer, bool force_dahdi)
DBG(SYNC, "stop unwanted syncers\n");
/* Shut all down except the wanted sync master */
for(i = 0; i < MAX_BUSES; i++) {
- xbus_t *xbus = xbus_num(i);
- if(!xbus)
+ xbus_t *xbus = get_xbus(__func__, i);
+ if (xbus == NULL)
continue;
if(XBUS_FLAGS(xbus, CONNECTED) && xbus != new_syncer) {
if(xbus->self_ticking)
@@ -599,6 +600,7 @@ static void update_sync_master(xbus_t *new_syncer, bool force_dahdi)
else
XBUS_DBG(SYNC, xbus, "Not self_ticking yet. Ignore\n");
}
+ put_xbus(__func__, xbus);
}
}
@@ -612,9 +614,12 @@ void elect_syncer(const char *msg)
unsigned long flags;
spin_lock_irqsave(&elect_syncer_lock, flags);
+ DBG(SYNC, "%s: %s syncer=%s\n", __func__, msg,
+ (syncer) ? syncer->busname : "NULL");
for(i = 0; i < MAX_BUSES; i++) {
- xbus_t *xbus = xbus_num(i);
- if(!xbus)
+ xbus_t *xbus = get_xbus(__func__, i);
+
+ if (xbus == NULL)
continue;
if(XBUS_IS(xbus, READY)) {
if(!the_xbus)
@@ -638,6 +643,7 @@ void elect_syncer(const char *msg)
}
}
}
+ put_xbus(__func__, xbus);
}
if(best_xpd) {
the_xbus = best_xpd->xbus;
@@ -1177,18 +1183,22 @@ int exec_sync_command(const char *buf, size_t count)
update_sync_master(NULL, 1);
} else if(sscanf(buf, "SYNC=%d", &xbusno) == 1) {
DBG(SYNC, "SYNC=%d\n", xbusno);
- if((xbus = xbus_num(xbusno)) == NULL) {
+ xbus = get_xbus(__func__, xbusno);
+ if (xbus == NULL) {
ERR("No bus %d exists\n", xbusno);
return -ENXIO;
}
update_sync_master(xbus, 0);
+ put_xbus(__func__, xbus);
} else if(sscanf(buf, "QUERY=%d", &xbusno) == 1) {
DBG(SYNC, "QUERY=%d\n", xbusno);
- if((xbus = xbus_num(xbusno)) == NULL) {
+ xbus = get_xbus(__func__, xbusno);
+ if (xbus == NULL) {
ERR("No bus %d exists\n", xbusno);
return -ENXIO;
}
CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_QUERY, 0);
+ put_xbus(__func__, xbus);
} else {
ERR("%s: cannot parse '%s'\n", __FUNCTION__, buf);
ret = -EINVAL;
diff --git a/drivers/dahdi/xpp/xpp_dahdi.c b/drivers/dahdi/xpp/xpp_dahdi.c
index cc92710..72b514e 100644
--- a/drivers/dahdi/xpp/xpp_dahdi.c
+++ b/drivers/dahdi/xpp/xpp_dahdi.c
@@ -571,8 +571,8 @@ __must_check xpd_t *xpd_alloc(xbus_t *xbus,
* This makes sure the xbus cannot be removed before this xpd
* is removed in xpd_free()
*/
- xbus = get_xbus(__FUNCTION__, xbus); /* returned in xpd_free() */
- xproto_get(type); /* will be returned in xpd_free() */
+ xbus = get_xbus(__func__, xbus->num); /* returned in xpd_free() */
+ xproto_get(type); /* will be returned in xpd_free() */
return xpd;
err:
if(xpd) {