[svn-commits] sruffell: branch linux/sruffell/dahdi-linux-cmdqueue r6339 - /linux/team/sruf...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Apr 7 13:38:40 CDT 2009


Author: sruffell
Date: Tue Apr  7 13:38:37 2009
New Revision: 6339

URL: http://svn.digium.com/svn-view/dahdi?view=rev&rev=6339
Log:
Cleanup any outstanding queued commands on unload / restart.

Modified:
    linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c
    linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/vpmadt032.c
    linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h

Modified: linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c
URL: http://svn.digium.com/svn-view/dahdi/linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c?view=diff&rev=6339&r1=6338&r2=6339
==============================================================================
--- linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c (original)
+++ linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/base.c Tue Apr  7 13:38:37 2009
@@ -83,10 +83,16 @@
 static struct t1_desc te122 = { "Wildcard TE122", 0 };
 static struct t1_desc te121 = { "Wildcard TE121", 0 };
 
-static struct command * get_free_cmd(struct t1 *wc)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
+static kmem_cache_t *cmd_cache;
+#else
+static struct kmem_cache *cmd_cache;
+#endif
+
+static struct command *get_free_cmd(struct t1 *wc)
 {
 	struct command *cmd;
-	cmd = kmem_cache_alloc(wc->cmd_cache, GFP_ATOMIC);
+	cmd = kmem_cache_alloc(cmd_cache, GFP_ATOMIC);
 	if (cmd) {
 		memset(cmd, 0, sizeof(*cmd));
 		INIT_LIST_HEAD(&cmd->node);
@@ -96,7 +102,7 @@
 
 static void free_cmd(struct t1 *wc, struct command *cmd)
 {
-	kmem_cache_free(wc->cmd_cache, cmd);
+	kmem_cache_free(cmd_cache, cmd);
 }
 
 static struct command * get_pending_cmd(struct t1 *wc)
@@ -307,29 +313,33 @@
 	}
 }
 
-static void t1_release(struct t1 *wc)
+static void free_wc(struct t1 *wc)
 {
 	unsigned int x;
 	unsigned long flags;
 	struct command *cmd;
 	LIST_HEAD(list);
 
-	dahdi_unregister(&wc->span);
-	for (x = 0; x < (wc->spantype == TYPE_E1 ? 31 : 24); x++) {
+	for (x = 0; x < (wc->spantype == TYPE_E1 ? 31 : 24); x++)
 		kfree(wc->chans[x]);
-	}
+
 	spin_lock_irqsave(&wc->cmd_list_lock, flags);
-	list_move_tail(&wc->active_cmds, &list);
-	list_move_tail(&wc->pending_cmds, &list);
+	list_splice_init(&wc->active_cmds, &list);
+	list_splice_init(&wc->pending_cmds, &list);
 	spin_unlock_irqrestore(&wc->cmd_list_lock, flags);
 	while (!list_empty(&list)) {
 		cmd = list_entry(list.next, struct command, node);
 		list_del(&cmd->node);
 		free_cmd(wc, cmd);
 	}
-	kmem_cache_destroy(wc->cmd_cache);
 	kfree(wc);
-	printk(KERN_INFO "Freed a Wildcard TE12xP\n");
+}
+
+static void t1_release(struct t1 *wc)
+{
+	dahdi_unregister(&wc->span);
+	printk(KERN_INFO "Freed a Wildcard TE12xP.\n");
+	free_wc(wc);
 }
 
 static void t4_serial_setup(struct t1 *wc)
@@ -974,7 +984,8 @@
 		module_printk("Unable to register span with DAHDI\n");
 		return -1;
 	}
-	atomic_set(&wc->initialized, 1);
+
+	set_bit(INITIALIZED, &wc->bit_flags);
 
 	return 0;
 }
@@ -1195,12 +1206,10 @@
 
 static void t1_do_counters(struct t1 *wc)
 {
-	if (wc->alarmtimer) {
-		if (time_after(jiffies, wc->alarmtimer)) {
-			wc->span.alarms &= ~(DAHDI_ALARM_RECOVER);
-			wc->alarmtimer = 0;
-			dahdi_alarm_notify(&wc->span);
-		}
+	if (wc->alarmtimer && time_after(jiffies, wc->alarmtimer)) {
+		wc->span.alarms &= ~(DAHDI_ALARM_RECOVER);
+		wc->alarmtimer = 0;
+		dahdi_alarm_notify(&wc->span);
 	}
 }
 
@@ -1211,12 +1220,12 @@
 	int chan;
 
 	/* Calculate Transmission */
-	if (likely(atomic_read(&wc->initialized))) {
+	if (likely(test_bit(INITIALIZED, &wc->bit_flags))) {
 		dahdi_transmit(&wc->span);
 	}
 
 	for (x = 0; x < DAHDI_CHUNKSIZE; x++) {
-		if (likely(atomic_read(&wc->initialized))) {
+		if (likely(test_bit(INITIALIZED, &wc->bit_flags))) {
 			for (chan = 0; chan < wc->span.channels; chan++)
 				writechunk[(chan+1)*2] = wc->chans[chan]->writechunk[x];	
 		}
@@ -1247,7 +1256,7 @@
 	unsigned char expected;
 
 	for (x = 0; x < DAHDI_CHUNKSIZE; x++) {
-		if (likely(atomic_read(&wc->initialized))) {
+		if (likely(test_bit(INITIALIZED, &wc->bit_flags))) {
 			for (chan = 0; chan < wc->span.channels; chan++) {
 				wc->chans[chan]->readchunk[x]= readchunk[(chan+1)*2];
 			}
@@ -1259,7 +1268,7 @@
 			if (wc->rxident != expected) {
 				wc->span.irqmisses++;
 				resend_cmds(wc);
-				if (unlikely(debug && atomic_read(&wc->initialized)))
+				if (unlikely(debug && test_bit(INITIALIZED, &wc->bit_flags)))
 					module_printk("oops: rxident=%d expected=%d x=%d\n", wc->rxident, expected, x);
 			}
 		}
@@ -1275,7 +1284,7 @@
 	}
 	
 	/* echo cancel */
-	if (likely(atomic_read(&wc->initialized))) {
+	if (likely(test_bit(INITIALIZED, &wc->bit_flags))) {
 		for (x = 0; x < wc->span.channels; x++) {
 			dahdi_ec_chunk(wc->chans[x], wc->chans[x]->readchunk, wc->ec_chunk2[x]);
 			memcpy(wc->ec_chunk2[x],wc->ec_chunk1[x],DAHDI_CHUNKSIZE);
@@ -1313,7 +1322,7 @@
 	struct t1 *wc = container_of(work, struct t1, timer_work);
 #endif
 	/* Called once every 100ms */
-	if (unlikely(!atomic_read(&wc->initialized))) return;
+	if (unlikely(!test_bit(INITIALIZED, &wc->bit_flags))) return;
 	t1_do_counters(wc);
 	t1_check_alarms(wc);
 	t1_check_sigbits(wc);
@@ -1363,17 +1372,6 @@
 	INIT_LIST_HEAD(&wc->active_cmds);
 	INIT_LIST_HEAD(&wc->pending_cmds);
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
-	wc->cmd_cache = kmem_cache_create(THIS_MODULE->name, sizeof(struct command), 0, 
-#if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 22)
-				SLAB_HWCACHE_ALIGN | SLAB_STORE_USER, NULL, NULL);
-#else
-				SLAB_HWCACHE_ALIGN, NULL, NULL);
-#endif
-#else
-	wc->cmd_cache = kmem_cache_create(THIS_MODULE->name, sizeof(struct command), 0, 
-				SLAB_HWCACHE_ALIGN, NULL);
-#endif
 	wc->variety = d->name;
 	wc->txident = 1;
 
@@ -1396,7 +1394,7 @@
 				 t1_handle_receive, t1_handle_transmit, wc,
 				 debug, &wc->vb))) {
 		WARN_ON(1);
-		kfree(wc);
+		free_wc(wc);
 		ifaces[index] = NULL;
 		return res;
 	}
@@ -1412,11 +1410,7 @@
 
 	for (x = 0; x < (wc->spantype == TYPE_E1 ? 31 : 24); x++) {
 		if (!(wc->chans[x] = kmalloc(sizeof(*wc->chans[x]), GFP_KERNEL))) {
-			while (x) {
-				kfree(wc->chans[--x]);
-			}
-
-			kfree(wc);
+			free_wc(wc);
 			ifaces[index] = NULL;
 			return -ENOMEM;
 		}
@@ -1437,7 +1431,7 @@
 		dahdi_unregister(&wc->span);
 		voicebus_release(wc->vb);
 		wc->vb = NULL;
-		kfree(wc);
+		free_wc(wc);
 		wc = NULL;
 		goto retry;
 	}
@@ -1457,6 +1451,7 @@
 	if (!wc)
 		return;
 
+	clear_bit(INITIALIZED, &wc->bit_flags);
 	del_timer_sync(&wc->timer);
 	flush_scheduled_work();
 	del_timer_sync(&wc->timer);
@@ -1505,15 +1500,34 @@
 {
 	int res;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
+	cmd_cache = kmem_cache_create(THIS_MODULE->name, sizeof(struct command), 0, 
+#if LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 22)
+				SLAB_HWCACHE_ALIGN | SLAB_STORE_USER, NULL, NULL);
+#else
+				SLAB_HWCACHE_ALIGN, NULL, NULL);
+#endif
+#else
+	cmd_cache = kmem_cache_create(THIS_MODULE->name, sizeof(struct command), 0, 
+				SLAB_HWCACHE_ALIGN, NULL);
+#endif
+	if (!cmd_cache)
+		return -ENOMEM;
+
 	res = dahdi_pci_module(&te12xp_driver);
-
-	return res ? -ENODEV : 0;
+	if (res) {
+		kmem_cache_destroy(cmd_cache);
+		return -ENODEV;
+	}
+
+	return 0;
 }
 
 
 static void __exit te12xp_cleanup(void)
 {
 	pci_unregister_driver(&te12xp_driver);
+	kmem_cache_destroy(cmd_cache);
 }
 
 module_param(debug, int, S_IRUGO | S_IWUSR);

Modified: linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/vpmadt032.c
URL: http://svn.digium.com/svn-view/dahdi/linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/vpmadt032.c?view=diff&rev=6339&r1=6338&r2=6339
==============================================================================
--- linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/vpmadt032.c (original)
+++ linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/vpmadt032.c Tue Apr  7 13:38:37 2009
@@ -498,16 +498,21 @@
 	struct vpm150m *vpm150m = container_of(data, struct vpm150m, work_echocan);
 #endif
 	struct t1 *wc = vpm150m->wc;
-	struct list_head *task;
-	struct list_head *next_task;
 	unsigned long flags;
-
-	list_for_each_safe(task, next_task, &vpm150m->worklist) {
-		struct vpm150m_workentry *we = list_entry(task, struct vpm150m_workentry, list);
-		struct dahdi_chan *chan = we->chan;
-		int deflaw;
-		int res;
-		GPAK_AlgControlStat_t pstatus;
+	struct vpm150m_workentry *we;
+	struct dahdi_chan *chan;
+	int deflaw;
+	int res;
+	GPAK_AlgControlStat_t pstatus;
+
+	while (!list_empty(&vpm150m->worklist)) {
+		we = list_entry(vpm150m->worklist.next, struct vpm150m_workentry, list);
+
+		spin_lock_irqsave(&vpm150m->lock, flags);
+		list_del(&we->list);
+		spin_unlock_irqrestore(&vpm150m->lock, flags);
+
+		chan = we->chan;
 
 		if (we->params.tap_length) {
 			/* configure channel for the ulaw/alaw */
@@ -550,9 +555,6 @@
 			module_printk("Unable to toggle echo cancellation on channel %d (reason %d)\n", chan->chanpos, res);
 		}
 
-		spin_lock_irqsave(&vpm150m->lock, flags);
-		list_del(task);
-		spin_unlock_irqrestore(&vpm150m->lock, flags);
 		kfree(we);
 	}
 }

Modified: linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h
URL: http://svn.digium.com/svn-view/dahdi/linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h?view=diff&rev=6339&r1=6338&r2=6339
==============================================================================
--- linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h (original)
+++ linux/team/sruffell/dahdi-linux-cmdqueue/drivers/dahdi/wcte12xp/wcte12xp.h Tue Apr  7 13:38:37 2009
@@ -118,7 +118,9 @@
 	unsigned long blinktimer;
 	int loopupcnt;
 	int loopdowncnt;
-	atomic_t initialized;
+#define INITIALIZED 1
+#define SHUTDOWN    2
+	unsigned long bit_flags;
 	unsigned long alarmtimer;
 	unsigned char ledstate;
 	unsigned char ec_chunk1[32][DAHDI_CHUNKSIZE];
@@ -136,11 +138,6 @@
 	unsigned long dtmfmutemask;
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
-	kmem_cache_t *cmd_cache;
-#else
-	struct kmem_cache *cmd_cache;
-#endif
 	spinlock_t cmd_list_lock;
 	struct list_head pending_cmds;
 	struct list_head active_cmds;




More information about the svn-commits mailing list