[svn-commits] mattf: branch linux/sruffell/improved_ecreference r8385 - in /linux/team/sruf...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Mar 22 12:27:17 CDT 2010


Author: mattf
Date: Mon Mar 22 12:27:13 2010
New Revision: 8385

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8385
Log:
Commit simple fifo mechanism for EC data buffering.  Still needs to have a flush mechanism to handle hard underrun and similar situations.

Modified:
    linux/team/sruffell/improved_ecreference/drivers/dahdi/dahdi-base.c
    linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/base.c
    linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/wctdm24xxp.h
    linux/team/sruffell/improved_ecreference/include/dahdi/kernel.h

Modified: linux/team/sruffell/improved_ecreference/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/linux/team/sruffell/improved_ecreference/drivers/dahdi/dahdi-base.c?view=diff&rev=8385&r1=8384&r2=8385
==============================================================================
--- linux/team/sruffell/improved_ecreference/drivers/dahdi/dahdi-base.c (original)
+++ linux/team/sruffell/improved_ecreference/drivers/dahdi/dahdi-base.c Mon Mar 22 12:27:13 2010
@@ -145,6 +145,11 @@
 
 EXPORT_SYMBOL(dahdi_set_hpec_ioctl);
 
+EXPORT_SYMBOL(__dahdi_fifo_put);
+EXPORT_SYMBOL(__dahdi_fifo_get);
+EXPORT_SYMBOL(dahdi_fifo_free);
+EXPORT_SYMBOL(dahdi_fifo_alloc);
+
 #ifdef CONFIG_PROC_FS
 static struct proc_dir_entry *proc_entries[DAHDI_MAX_SPANS];
 #endif
@@ -492,6 +497,103 @@
 
 	write_unlock(&ecfactory_list_lock);
 }
+
+struct dahdi_fifo {
+	unsigned int total_size;
+	unsigned int start;
+	unsigned int end;
+	unsigned char data[0];
+};
+
+unsigned int dahdi_fifo_used_space(struct dahdi_fifo *fifo)
+{
+	if (fifo->end >= fifo->start) {
+		return fifo->end - fifo->start;
+	} else {
+		return fifo->total_size - fifo->start + fifo->end;
+	}
+}
+
+unsigned int __dahdi_fifo_put(struct dahdi_fifo *fifo, unsigned char *data, unsigned int size)
+{
+	int newinsertposition;
+	int cpy_one_len, cpy_two_len;
+	
+	if ((size + dahdi_fifo_used_space(fifo)) > (fifo->total_size - 1)) {
+		return -1;
+	}
+	
+	if ((fifo->end + size) >= fifo->total_size) {
+		cpy_one_len = fifo->total_size - fifo->end;
+		cpy_two_len = fifo->end + size - fifo->total_size;
+		newinsertposition = cpy_two_len;
+	} else {
+		cpy_one_len = size;
+		cpy_two_len = 0;
+		newinsertposition = fifo->end + size;
+	}
+
+	memcpy(&fifo->data[fifo->end], data, cpy_one_len);
+	
+	if (cpy_two_len) {
+		memcpy(&fifo->data[0], &data[cpy_one_len], cpy_two_len);
+	}
+	
+	fifo->end = newinsertposition;
+
+	return size;
+}
+
+unsigned int __dahdi_fifo_get(struct dahdi_fifo *fifo, unsigned char *data, unsigned int size)
+{
+	int newbegin;
+	int cpy_one_len, cpy_two_len;
+	
+	if (size > dahdi_fifo_used_space(fifo)) {
+		return 0;
+	}
+	
+	if ((fifo->start + size) >= fifo->total_size) {
+		cpy_one_len = fifo->total_size - fifo->start;
+		cpy_two_len = fifo->start + size - fifo->total_size;
+		newbegin = cpy_two_len;
+	} else {
+		cpy_one_len = size;
+		cpy_two_len = 0;
+		newbegin = fifo->start + size;
+	}
+	
+	memcpy(&data[0], &fifo->data[fifo->start], cpy_one_len);
+	
+	if (cpy_two_len) {
+		memcpy(&data[cpy_one_len], &fifo->data[0], cpy_two_len);
+	}
+	
+	fifo->start = newbegin;
+
+	return size;
+}
+
+void dahdi_fifo_free(struct dahdi_fifo *fifo)
+{
+	kfree(fifo);
+}
+
+struct dahdi_fifo * dahdi_fifo_alloc(unsigned int maxsize, int alloc_flags)
+{
+	struct dahdi_fifo *fifo;
+
+	fifo = kmalloc(maxsize + sizeof(*fifo) + 1, alloc_flags);
+
+	if (!fifo)
+		return NULL;
+
+	fifo->start = fifo->end = 0;
+	fifo->total_size = maxsize + 1;
+
+	return fifo;
+}
+
 
 static inline void rotate_sums(void)
 {

Modified: linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/base.c
URL: http://svnview.digium.com/svn/dahdi/linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/base.c?view=diff&rev=8385&r1=8384&r2=8385
==============================================================================
--- linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/base.c (original)
+++ linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/base.c Mon Mar 22 12:27:13 2010
@@ -46,7 +46,6 @@
 #include <linux/workqueue.h>
 #include <linux/delay.h>
 #include <linux/moduleparam.h>
-#include <linux/kfifo.h>
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
 #include <linux/semaphore.h>
 #else
@@ -838,7 +837,7 @@
 		dahdi_transmit(&wc->span);
 		for (x = 0; x < wc->desc->ports; x++) {
 			if (wc->cardflag & (1 << x)) {
-				__kfifo_put(wc->ec_reference[x],
+				__dahdi_fifo_put(wc->ec_reference[x],
 					    wc->chans[x]->writechunk, DAHDI_CHUNKSIZE);
 			}
 		}
@@ -1052,7 +1051,7 @@
 		unsigned char buffer[DAHDI_CHUNKSIZE];
 		for (x = 0; x < wc->desc->ports; x++) {
 			if (wc->cardflag & (1 << x)) {
-				__kfifo_get(wc->ec_reference[x], buffer,
+				__dahdi_fifo_get(wc->ec_reference[x], buffer,
 					    ARRAY_SIZE(buffer));
 				dahdi_ec_chunk(wc->chans[x],
 					       wc->chans[x]->readchunk,
@@ -3736,7 +3735,7 @@
 
 	for (x = 0; x < ARRAY_SIZE(wc->ec_reference); ++x) {
 		if (wc->ec_reference[x])
-			kfifo_free(wc->ec_reference[x]);
+			dahdi_fifo_free(wc->ec_reference[x]);
 	}
 
 	kfree(wc);
@@ -3795,9 +3794,9 @@
 	init_waitqueue_head(&wc->regq);
 
 	for (i = 0; i < ARRAY_SIZE(wc->ec_reference); ++i) {
-		wc->ec_reference[i] = kfifo_alloc(DAHDI_CHUNKSIZE *
+		wc->ec_reference[i] = dahdi_fifo_alloc(DAHDI_CHUNKSIZE *
 						  VOICEBUS_MAX_LATENCY,
-						  GFP_KERNEL, &wc->reglock);
+						  GFP_KERNEL);
 
 		if (IS_ERR(wc->ec_reference[i])) {
 			ret = PTR_ERR(wc->ec_reference[i]);

Modified: linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/wctdm24xxp.h
URL: http://svnview.digium.com/svn/dahdi/linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/wctdm24xxp.h?view=diff&rev=8385&r1=8384&r2=8385
==============================================================================
--- linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/wctdm24xxp.h (original)
+++ linux/team/sruffell/improved_ecreference/drivers/dahdi/wctdm24xxp/wctdm24xxp.h Mon Mar 22 12:27:13 2010
@@ -230,7 +230,7 @@
 	struct voicebus *vb;
 	struct dahdi_chan *chans[NUM_CARDS];
 	struct dahdi_echocan_state *ec[NUM_CARDS];
-	struct kfifo *ec_reference[NUM_CARDS];
+	struct dahdi_fifo *ec_reference[NUM_CARDS];
 	int initialized;
 };
 

Modified: linux/team/sruffell/improved_ecreference/include/dahdi/kernel.h
URL: http://svnview.digium.com/svn/dahdi/linux/team/sruffell/improved_ecreference/include/dahdi/kernel.h?view=diff&rev=8385&r1=8384&r2=8385
==============================================================================
--- linux/team/sruffell/improved_ecreference/include/dahdi/kernel.h (original)
+++ linux/team/sruffell/improved_ecreference/include/dahdi/kernel.h Mon Mar 22 12:27:13 2010
@@ -1061,6 +1061,16 @@
 extern u_char __dahdi_lin2mu[16384];
 extern u_char __dahdi_lin2a[16384];
 #endif
+
+struct dahdi_fifo;
+
+unsigned int __dahdi_fifo_put(struct dahdi_fifo *fifo, unsigned char *data, unsigned int size);
+
+unsigned int __dahdi_fifo_get(struct dahdi_fifo *fifo, unsigned char *data, unsigned int size);
+
+void dahdi_fifo_free(struct dahdi_fifo *fifo);
+
+struct dahdi_fifo * dahdi_fifo_alloc(unsigned int maxsize, int alloc_flags);
 
 /*! \brief Used by dynamic DAHDI -- don't use directly */
 void dahdi_set_dynamic_ioctl(int (*func)(unsigned int cmd, unsigned long data));




More information about the svn-commits mailing list