[dahdi-commits] mattf: linux/trunk r4817 - in /linux/trunk: drivers/dahdi/ include/dahdi/

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Sun Aug 24 00:53:32 CDT 2008


Author: mattf
Date: Sun Aug 24 00:53:32 2008
New Revision: 4817

URL: http://svn.digium.com/view/dahdi?view=rev&rev=4817
Log:
Add support for 56 KB HDLC as well as selectable rate via ioctl

Modified:
    linux/trunk/drivers/dahdi/dahdi-base.c
    linux/trunk/include/dahdi/fasthdlc.h
    linux/trunk/include/dahdi/kernel.h
    linux/trunk/include/dahdi/user.h

Modified: linux/trunk/drivers/dahdi/dahdi-base.c
URL: http://svn.digium.com/view/dahdi/linux/trunk/drivers/dahdi/dahdi-base.c?view=diff&rev=4817&r1=4816&r2=4817
==============================================================================
--- linux/trunk/drivers/dahdi/dahdi-base.c (original)
+++ linux/trunk/drivers/dahdi/dahdi-base.c Sun Aug 24 00:53:32 2008
@@ -1515,8 +1515,8 @@
 	if (res)
 		return res;
 
-	fasthdlc_init(&ms->rxhdlc);
-	fasthdlc_init(&ms->txhdlc);
+	fasthdlc_init(&ms->rxhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
+	fasthdlc_init(&ms->txhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
 	ms->infcs = PPP_INITFCS;
 
 	netif_start_queue(ztchan_to_dev(ms));
@@ -2373,8 +2373,8 @@
 	chan->firstcadencepos = 0; /* By default loop back to first cadence position */
 
 	/* HDLC & FCS stuff */
-	fasthdlc_init(&chan->rxhdlc);
-	fasthdlc_init(&chan->txhdlc);
+	fasthdlc_init(&chan->rxhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
+	fasthdlc_init(&chan->txhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
 	chan->infcs = PPP_INITFCS;
 
 	/* Timings for RBS */
@@ -5012,8 +5012,8 @@
 		chan->flags &= ~(DAHDI_FLAG_AUDIO | DAHDI_FLAG_HDLC | DAHDI_FLAG_FCS);
 		if (j) {
 			chan->flags |= DAHDI_FLAG_HDLC;
-			fasthdlc_init(&chan->rxhdlc);
-			fasthdlc_init(&chan->txhdlc);
+			fasthdlc_init(&chan->rxhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
+			fasthdlc_init(&chan->txhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
 		}
 		break;
 	case DAHDI_HDLCFCSMODE:
@@ -5022,9 +5022,20 @@
 		chan->flags &= ~(DAHDI_FLAG_AUDIO | DAHDI_FLAG_HDLC | DAHDI_FLAG_FCS);
 		if (j) {
 			chan->flags |= DAHDI_FLAG_HDLC | DAHDI_FLAG_FCS;
-			fasthdlc_init(&chan->rxhdlc);
-			fasthdlc_init(&chan->txhdlc);
-		}
+			fasthdlc_init(&chan->rxhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
+			fasthdlc_init(&chan->txhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
+		}
+		break;
+	case DAHDI_HDLC_RATE:
+		get_user(j, (int *) data);
+		if (j == 56) {
+			chan->flags |= DAHDI_FLAG_HDLC56;
+		} else {
+			chan->flags &= ~DAHDI_FLAG_HDLC56;
+		}
+
+		fasthdlc_init(&chan->rxhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
+		fasthdlc_init(&chan->txhdlc, (chan->flags & DAHDI_FLAG_HDLC56) ? FASTHDLC_MODE_56 : FASTHDLC_MODE_64);
 		break;
 	case DAHDI_ECHOCANCEL_PARAMS:
 	{
@@ -5860,7 +5871,7 @@
 				/* If this is an HDLC channel we only send a byte of
 				   HDLC. */
 				for(x=0;x<left;x++) {
-					if (ms->txhdlc.bits < 8)
+					if (fasthdlc_tx_need_data(&ms->txhdlc))
 						/* Load a byte of data only if needed */
 						fasthdlc_tx_load_nocheck(&ms->txhdlc, buf[ms->writeidx[ms->outwritebuf]++]);
 					*(txb++) = fasthdlc_tx_run_nocheck(&ms->txhdlc);
@@ -5971,7 +5982,7 @@
 		} else if (ms->flags & DAHDI_FLAG_HDLC) {
 			for (x=0;x<bytes;x++) {
 				/* Okay, if we're HDLC, then transmit a flag by default */
-				if (ms->txhdlc.bits < 8)
+				if (fasthdlc_tx_need_data(&ms->txhdlc))
 					fasthdlc_tx_frame_nocheck(&ms->txhdlc);
 				*(txb++) = fasthdlc_tx_run_nocheck(&ms->txhdlc);
 			}

Modified: linux/trunk/include/dahdi/fasthdlc.h
URL: http://svn.digium.com/view/dahdi/linux/trunk/include/dahdi/fasthdlc.h?view=diff&rev=4817&r1=4816&r2=4817
==============================================================================
--- linux/trunk/include/dahdi/fasthdlc.h (original)
+++ linux/trunk/include/dahdi/fasthdlc.h Sun Aug 24 00:53:32 2008
@@ -32,11 +32,17 @@
 #ifndef _FASTHDLC_H
 #define _FASTHDLC_H
 
+enum fasthdlc_mode {
+	FASTHDLC_MODE_64 = 0,
+	FASTHDLC_MODE_56,
+};
+
 struct fasthdlc_state {
 	int state;		/* What state we are in */
 	unsigned int data;	/* Our current data queue */
 	int bits;		/* Number of bits in our data queue */
 	int ones;		/* Number of ones */
+	enum fasthdlc_mode mode;
 };
 
 #ifdef FAST_HDLC_NEED_TABLES
@@ -343,9 +349,10 @@
 }
 
 
-static inline void fasthdlc_init(struct fasthdlc_state *h)
+static inline void fasthdlc_init(struct fasthdlc_state *h, enum fasthdlc_mode mode)
 {
 	/* Initializes all states appropriately */
+	h->mode = mode;
 	h->state = 0;
 	h->bits = 0;
 	h->data = 0;
@@ -386,13 +393,36 @@
 	return fasthdlc_tx_frame_nocheck(h);
 }
 
+static inline int fasthdlc_tx_need_data(struct fasthdlc_state *h)
+{
+	if (h->mode == FASTHDLC_MODE_56) {
+		if (h->bits < 7)
+			return 1;
+	} else {
+		if (h->bits < 8)
+			return 1;
+	}
+
+	return 0;
+}
+
 static inline int fasthdlc_tx_run_nocheck(struct fasthdlc_state *h)
 {
 	unsigned char b;
-	b = h->data >> 24;
-	h->bits -= 8;
-	h->data <<= 8;
-	return b;
+	if (h->mode == FASTHDLC_MODE_56) {
+		b = h->data >> 25;
+		h->bits -= 7;
+		h->data <<= 7;
+
+		return b << 1;
+	} else {
+		b = h->data >> 24;
+		h->bits -= 8;
+		h->data <<= 8;
+
+		return b;
+	}
+
 }
 
 static inline int fasthdlc_tx_run(struct fasthdlc_state *h)
@@ -404,9 +434,14 @@
 
 static inline int fasthdlc_rx_load_nocheck(struct fasthdlc_state *h, unsigned char b)
 {
-	/* Put the new byte in the data stream */
-	h->data |= b << (24-h->bits);
-	h->bits += 8;
+	if (h->mode == FASTHDLC_MODE_56) {
+		h->data |= (b >> 1) << (25-h->bits);
+		h->bits += 7;
+	} else {
+		/* Put the new byte in the data stream */
+		h->data |= b << (24-h->bits);
+		h->bits += 8;
+	}
 	return 0;
 }
 

Modified: linux/trunk/include/dahdi/kernel.h
URL: http://svn.digium.com/view/dahdi/linux/trunk/include/dahdi/kernel.h?view=diff&rev=4817&r1=4816&r2=4817
==============================================================================
--- linux/trunk/include/dahdi/kernel.h (original)
+++ linux/trunk/include/dahdi/kernel.h Sun Aug 24 00:53:32 2008
@@ -462,6 +462,7 @@
 #define DAHDI_FLAG_NOSTDTXRX		(1 << 17)	/*!< Do NOT do standard transmit and receive on every interrupt */
 #define DAHDI_FLAG_LOOPED			(1 << 18)	/*!< Loopback the receive data from the channel to the transmit */
 #define DAHDI_FLAG_MTP2			(1 << 19)	/*!< Repeats last message in buffer and also discards repeating messages sent to us */
+#define DAHDI_FLAG_HDLC56			(1 << 20)	/*!< Sets the given channel (if in HDLC mode) to use 56K HDLC instead of 64K  */
 
 /*! This is a redefinition of the flags from above to allow use of the kernel atomic bit testing and changing routines.
  * See the above descriptions for DAHDI_FLAG_....  for documentation about function. */
@@ -486,6 +487,7 @@
 	DAHDI_FLAGBIT_NOSTDTXRX  = 17,
 	DAHDI_FLAGBIT_LOOPED     = 18,
 	DAHDI_FLAGBIT_MTP2       = 19,
+	DAHDI_FLAGBIT_HDLC56       = 20,
 };
 
 struct dahdi_span {

Modified: linux/trunk/include/dahdi/user.h
URL: http://svn.digium.com/view/dahdi/linux/trunk/include/dahdi/user.h?view=diff&rev=4817&r1=4816&r2=4817
==============================================================================
--- linux/trunk/include/dahdi/user.h (original)
+++ linux/trunk/include/dahdi/user.h Sun Aug 24 00:53:32 2008
@@ -976,6 +976,9 @@
 #define DAHDI_STARTUP			_IOW(DAHDI_CODE, 99, int)
 #define DAHDI_SHUTDOWN			_IOW(DAHDI_CODE, 100, int)
 
+
+#define DAHDI_HDLC_RATE			_IOW(DAHDI_CODE, 101, int)
+
 struct torisa_debug {
 	unsigned int txerrors;
 	unsigned int irqcount;




More information about the dahdi-commits mailing list