[zaptel-commits] kpfleming: branch mogorman/zaptel-1.2-transcoder r2003 - /team/mogorman/zapte...

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Mon Jan 29 13:51:25 MST 2007


Author: kpfleming
Date: Mon Jan 29 14:51:24 2007
New Revision: 2003

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2003
Log:
various cleanups
don't use cmdq during processor booting, since it is unnecessary (reduces size of cmdq array by 80%)

Modified:
    team/mogorman/zaptel-1.2-transcoder/wctc4xxp/base.c

Modified: team/mogorman/zaptel-1.2-transcoder/wctc4xxp/base.c
URL: http://svn.digium.com/view/zaptel/team/mogorman/zaptel-1.2-transcoder/wctc4xxp/base.c?view=diff&rev=2003&r1=2002&r2=2003
==============================================================================
--- team/mogorman/zaptel-1.2-transcoder/wctc4xxp/base.c (original)
+++ team/mogorman/zaptel-1.2-transcoder/wctc4xxp/base.c Mon Jan 29 14:51:24 2007
@@ -40,23 +40,15 @@
 #include <asm/semaphore.h>
 #include <linux/jiffies.h>
 #include <linux/workqueue.h>
-#ifdef CONFIG_DEVFS_FS
-#include <linux/devfs_fs_kernel.h>
-#endif
+#include <linux/moduleparam.h>
+#include <linux/firmware.h>
+
 #ifdef STANDALONE_ZAPATA
 #include "zaptel.h"
 #else
 #include <linux/zaptel.h>
 #endif
-#include <linux/moduleparam.h>
-#if defined(LINUX26)
-#include <linux/firmware.h>
-#else
-ostruct firmware {
-	size_t size;
-	u8 *data;
-};
-#endif
+
 #if defined(HOTPLUG_FIRMWARE)
 static const char *tc400m_firmware = "tc400m-firmware.bin";
 #else
@@ -97,15 +89,10 @@
 #define MAX_COMMANDS (NUM_CHANNELS + ACK_SPACE)
 #define MAX_RCV_COMMANDS 16
 
-/* 1432 for boot, 274 for 30ms ulaw, 194 for 20ms ulaw */
-#define BOOT_CMD_LEN 1500
+/* 274 for 30ms ulaw, 194 for 20ms ulaw */
 #define OTHER_CMD_LEN 300
 
-#if BOOT_CMD_LEN > OTHER_CMD_LEN
-#define MAX_COMMAND_LEN BOOT_CMD_LEN
-#else
 #define MAX_COMMAND_LEN OTHER_CMD_LEN
-#endif
 
 #define ERING_SIZE (NUM_CHANNELS / 2)		/* Maximum ring size */
 
@@ -265,22 +252,19 @@
 	({ \
 		int ret = 0; \
 		do { \
-	 		if (ret == 2) \
-	 		{ \
+	 		if (ret == 2) { \
 				wc->ztsnd_rtx++; \
 	 			if (hex == 0x0010) \
 					wc->ztsnd_0010_rtx++; \
 			} \
 			down(&wc->cmdqsem); \
 	 		wc->last_command_sent = hex; \
-			if ( (((wc->cmdq_wndx + 1) % MAX_COMMANDS) == wc->cmdq_rndx) && debug ) \
-				module_printk("cmdq is full\n"); \
-			else { \
+			if ((((wc->cmdq_wndx + 1) % MAX_COMMANDS) == wc->cmdq_rndx)) {\
+				debug_printk(1, "cmdq is full\n"); \
+			} else { \
 				u8 fifo[OTHER_CMD_LEN] = command; \
-				u32 i; \
 				wc->cmdq[wc->cmdq_wndx].cmdlen = length; \
-				for (i = 0; i < length; i++) \
-					wc->cmdq[wc->cmdq_wndx].cmd[i] = fifo[i]; \
+				memcpy(wc->cmdq[wc->cmdq_wndx].cmd, fifo, length); \
 				wc->cmdq_wndx = (wc->cmdq_wndx + 1) % MAX_COMMANDS; \
 			} \
 			__transmit_demand(wc); \
@@ -381,23 +365,18 @@
 static struct dte_state *decoders;
 static int debug = 0;
 static char *mode;
-int debug_packets = 0;
-int debug_cmd_packets = 0;
+u32 debug_packets = 0;
+u32 debug_cmd_packets = 0;
 
 static int create_channel(struct wcdte *wc, int simple, int complicated, int part1_id, int part2_id, unsigned int *dte_chan1, unsigned int *dte_chan2);
 static int destroy_channel(struct wcdte *wc, unsigned int chan1, unsigned int chan2);
 
 static void dte_init_state(struct dte_state *state_ptr, int encoder, unsigned int channel, struct wcdte *wc)
 {
+	memset(state_ptr, 0, sizeof(*state_ptr));
+
 	state_ptr->encoder = encoder;
 	state_ptr->wc = wc;
-	state_ptr->timestamp = 0;
-	state_ptr->seqno = 0;
-
-	state_ptr->packets_sent = 0;
-	state_ptr->packets_received = 0;
-	state_ptr->last_dte_seqno = 0;
-	state_ptr->dte_seqno_rcv = 0;
 
 	state_ptr->chan_in_num = 999;
 	state_ptr->chan_out_num = 999;
@@ -410,7 +389,6 @@
 		state_ptr->timeslot_out_num = channel * 2;
 	}
 }
-
 
 static inline unsigned int zapfmt_to_dtefmt(unsigned int fmt)
 {
@@ -447,6 +425,18 @@
 	spin_unlock_irqrestore(&wc->reglock, flags);
 }
 
+static inline unsigned int getctl(struct wcdte *wc, unsigned int addr)
+{
+	unsigned long flags;
+	unsigned int val;
+
+	spin_lock_irqsave(&wc->reglock, flags);
+	val = __getctl(wc, addr);
+	spin_unlock_irqrestore(&wc->reglock, flags);
+
+	return val;
+}
+
 static inline void reinit_descriptor(struct wcdte *wc, int tx, int dbl, char *s)
 {
 	unsigned int o2;
@@ -460,39 +450,13 @@
 	setctl(wc, 0x0008, 0x00000000);
 }
 
-static inline unsigned int getctl(struct wcdte *wc, unsigned int addr)
-{
-	unsigned long flags;
-	unsigned int val;
-
-	spin_lock_irqsave(&wc->reglock, flags);
-	val = __getctl(wc, addr);
-	spin_unlock_irqrestore(&wc->reglock, flags);
-
-	return val;
-}
-
-static inline int __transmit_demand(struct wcdte *wc)
+static inline void __transmit_one(struct wcdte *wc, u8 *data, u32 length)
 {
 	volatile u8 *writechunk;
-	int o2, i, j;
-	unsigned int reg, xmt_length;
-
-	reg = getctl(wc, 0x0028) & 0x00700000;
-	
-	/* Already transmitting, no need to demand another */
-	if (!((reg == 0) || (reg = 6)))
-		return 1;
-
-	/* Nothing to transmit */
-	if (wc->cmdq_rndx == wc->cmdq_wndx)
-		return 1;
-
-	/* Nothing to transmit */
-	if (!wc->cmdq[wc->cmdq_rndx].cmdlen)
-		return 1;
-
-	writechunk = (volatile u8 *)(wc->writechunk);
+	u32 o2;
+	u32 xmt_length;
+
+	writechunk = (volatile u8 *) (wc->writechunk);
 
 	writechunk += wc->tdbl * SFRAME_SIZE;
 
@@ -504,35 +468,61 @@
 	*/
 	do {} while ((le32_to_cpu(wc->descripchunk[o2]) & 0x80000000));
 
-	xmt_length = max(wc->cmdq[wc->cmdq_rndx].cmdlen, 64U);
+	xmt_length = max(length, 64U);
 
 	wc->descripchunk[o2 + 1] = cpu_to_le32((le32_to_cpu(wc->descripchunk[o2 + 1]) & 0xFBFFF800) | xmt_length);
 				
-	for (i = 0; i < wc->cmdq[wc->cmdq_rndx].cmdlen; i++)
-		writechunk[i] = wc->cmdq[wc->cmdq_rndx].cmd[i];
-	for (j = i; j < xmt_length; j++)
-		writechunk[j] = 0;
-
-	if (debug_packets) {
-		module_printk("TX: ");
-		for (i = 0; i < debug_packets; i++)
-			printk("%02X ", writechunk[i]);
-		printk("\n");
-	}
-
-	if (debug_cmd_packets && (writechunk[12] == 0x88) && (writechunk[13] == 0x9B)) {
-		module_printk("wcdte debug: TX: ");
-		for (i = 0; i < debug_cmd_packets; i++)
-			printk("%02X ", writechunk[i]);
-		printk("\n");
-	}
-
-	wc->cmdq[wc->cmdq_rndx].cmdlen = 0;
+	memcpy((u8 *) writechunk, data, length);
+	if (length < xmt_length)
+		memset((u8 *) writechunk + length, 0, xmt_length - length);
 
 	wc->descripchunk[o2] = cpu_to_le32(0x80000000);
 	setctl(wc, 0x0008, 0x00000000);			/* Transmit Poll Demand */
 	
 	wc->tdbl = (wc->tdbl + 1) % ERING_SIZE;
+}
+
+static inline int __transmit_demand(struct wcdte *wc)
+{
+	int i;
+	unsigned int reg;
+	struct cmdq *cmdq;
+
+	reg = getctl(wc, 0x0028) & 0x00700000;
+	
+	/* Already transmitting, no need to demand another */
+	if (!((reg == 0) || (reg = 6)))
+		return 1;
+
+	/* Nothing to transmit */
+	if (wc->cmdq_rndx == wc->cmdq_wndx)
+		return 1;
+
+	cmdq = &wc->cmdq[wc->cmdq_rndx];
+
+	/* Nothing to transmit */
+	if (!cmdq->cmdlen)
+		return 1;
+
+	__transmit_one(wc, cmdq->cmd, cmdq->cmdlen);
+
+	if (debug_packets) {
+		debug_printk(1, "TX: ");
+		for (i = 0; i < min(debug_packets, cmdq->cmdlen); i++)
+			printk("%02X ", cmdq->cmd[i]);
+		printk("\n");
+	}
+
+	if (debug_cmd_packets &&
+	    (cmdq->cmd[12] == 0x88) &&
+	    (cmdq->cmd[13] == 0x9B)) {
+		debug_printk(1, "TX: ");
+		for (i = 0; i < min(debug_cmd_packets, cmdq->cmdlen); i++)
+			printk("%02X ", cmdq->cmd[i]);
+		printk("\n");
+	}
+
+	cmdq->cmdlen = 0;
 
 	wc->cmdq_rndx = (wc->cmdq_rndx + 1) % MAX_COMMANDS;
 
@@ -1178,7 +1168,7 @@
 
 static int boot_processor(struct wcdte *wc, const struct firmware *firmware)
 {
-	int i, j, byteloc, last_byteloc, length, delay_count;
+	int byteloc, last_byteloc, length, delay_count;
 	unsigned int reg, ret;
 
 #if !defined(USE_TEST_HW)
@@ -1218,39 +1208,17 @@
 		debug_printk(1, "LINK STATUS: reg(0xfc) = %X\n", reg);
 	}
 
-	/* TODO: what is this for? we don't refer to the read value anywhere */
-	reg = getctl(wc, 0x00A0);
-
-	byteloc = 17;
-	j = 0;
-
-	do {
-		last_byteloc = byteloc;
-		
-		length = (firmware->data[byteloc] << 8) |firmware->data[byteloc+1];
+	for (ret = 0, last_byteloc = byteloc = 17; byteloc < (firmware->size - 20); last_byteloc = byteloc) {
+		length = (firmware->data[byteloc] << 8) | firmware->data[byteloc];
 		byteloc += 2;
-		
-		down(&wc->cmdqsem);
-		if (((wc->cmdq_wndx + 1) % MAX_COMMANDS) == wc->cmdq_rndx) {
-			debug_printk(1, "wcdte error: cmdq is full.\n");
-		} else {
-			wc->cmdq[wc->cmdq_wndx].cmdlen = length;
-			for (i = 0; i < length; i++)
-				wc->cmdq[wc->cmdq_wndx].cmd[i] = firmware->data[byteloc++];
-			wc->cmdq_wndx = (wc->cmdq_wndx + 1) % MAX_COMMANDS;
-		}
-		
-		__transmit_demand(wc);
-		up(&wc->cmdqsem);
-		
+		__transmit_one(wc, firmware->data + byteloc, length);
+		byteloc += length;
 		ret = waitfor_csmencaps(wc, RCV_CSMENCAPS_ACK, 1);
 		if (ret == 1)
 			return 1;
-		else if (ret == 2)		/* Retransmit if dte processor times out */
+		else if (ret == 2)		/* Retransmit if processor times out */
 			byteloc = last_byteloc;
-		j++;
-		
-	} while (byteloc < firmware->size-20);
+	}
 
 	wc->timeout = 10 * HZ;
 	if (waitfor_csmencaps(wc, RCV_CSMENCAPS, 1))
@@ -1258,6 +1226,7 @@
 	
 	/* Turn on booted LED */
 	setctl(wc, 0x00A0, 0x04080000);
+
 	debug_printk(1, "Successfully booted DTE processor.\n");
 
 	return 0;



More information about the zaptel-commits mailing list