[zaptel-commits] sruffell: branch sruffell/zaptel-1.4-transcoder r4256 - /team/sruffell/zaptel...

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Mon May 12 14:09:05 CDT 2008


Author: sruffell
Date: Mon May 12 14:09:03 2008
New Revision: 4256

URL: http://svn.digium.com/view/zaptel?view=rev&rev=4256
Log:
Added an early trace option for debugging.

Modified:
    team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/Kbuild
    team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/base.c
    team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.c
    team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.h
    team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wctc4xxp.h

Modified: team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/Kbuild
URL: http://svn.digium.com/view/zaptel/team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/Kbuild?view=diff&rev=4256&r1=4255&r2=4256
==============================================================================
--- team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/Kbuild (original)
+++ team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/Kbuild Mon May 12 14:09:03 2008
@@ -8,7 +8,8 @@
   EXTRA_CFLAGS+=-DHOTPLUG_FIRMWARE
 endif
 
-wctc4xxp-objs := base.o wcdte_net.o
+wctc4xxp-objs := base.o
+wctc4xxp-objs += wcdte_net.o
 
 ifneq ($(HOTPLUG_FIRMWARE),yes)
 wctc4xxp-objs += $(FIRM_DIR)/zaptel-fw-tc400m.o

Modified: team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/base.c
URL: http://svn.digium.com/view/zaptel/team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/base.c?view=diff&rev=4256&r1=4255&r2=4256
==============================================================================
--- team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/base.c (original)
+++ team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/base.c Mon May 12 14:09:03 2008
@@ -475,15 +475,6 @@
 	return c;
 }
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
-/*! Used to allocate commands to submit to the dte. */
-kmem_cache_t *cmd_cache;
-#else
-/*! Used to allocate commands to submit to the dte. */
-struct kmem_cache *cmd_cache;
-#endif
-
-
 static inline void __wcdte_setctl(struct wcdte *wc, unsigned int addr, unsigned int val)
 {
 	outl(val, wc->iobase + addr);
@@ -524,38 +515,6 @@
 	spin_unlock_irqrestore(&wc->reglock, flags);
 }
 
-static void initialize_cmd(struct dte_cmd *cmd, unsigned long cmd_flags) 
-{
-	memset(cmd, 0, sizeof(*cmd));
-	INIT_LIST_HEAD(&cmd->node);
-	init_completion(&cmd->complete);
-	cmd->flags = cmd_flags;
-}
-
-static inline struct dte_cmd *
-__alloc_cmd(unsigned alloc_flags, unsigned long cmd_flags)
-{
-	struct dte_cmd *cmd;
-
-	cmd = kmem_cache_alloc(cmd_cache, alloc_flags);
-	if (likely(cmd)) {
-		initialize_cmd(cmd, cmd_flags);
-	}
-	return cmd;
-}
-static inline struct dte_cmd *
-alloc_cmd(void)
-{
-	return __alloc_cmd(GFP_KERNEL, 0);
-}
-
-static inline void 
-free_cmd(struct dte_cmd *cmd)
-{
-	kmem_cache_free(cmd_cache, cmd);
-	return;
-}
-
 static void
 wcdte_cleanup_descriptor_ring(struct dte_descriptor_ring *dr) 
 {
@@ -622,54 +581,7 @@
 
 static void wcdte_capture_packet(struct wcdte *wc, const struct dte_cmd *cmd)
 {
-
-#if 0
-	struct dte_cmd *new;
-	unsigned long flags;
-	unsigned long alloc_flags;
-
-	if (0 == debug_packets) {
-		/* We're not capturing packets */
-		return;
-	}
-
-	alloc_flags = (in_interrupt()) ? GFP_ATOMIC : GFP_KERNEL;
-	if (!(new = __alloc_cmd(alloc_flags, 0))) {
-		DTE_DEBUG(DTE_DEBUG_GENERAL, "Cannot capture packet.\n");
-		return;
-	}
-	memcpy(new->cmd, cmd->cmd, sizeof(cmd->cmd));
-	spin_lock_irqsave(&wc->captured_list_lock, flags);
-	if (++wc->captured_list_length > debug_packets) {
-		/* Remove the oldest item from the captured list to limit the
-		 * amount of memory consumed by packet capture.
-		 */
-		struct dte_cmd *old;
-		old = list_entry(wc->captured_packets.next, struct dte_cmd, node); 
-		list_del(&old->node);
-		free_cmd(old);
-		--wc->captured_list_length;
-	}
-	list_add_tail(&new->node, &wc->captured_packets);
-	spin_unlock_irqrestore(&wc->captured_list_lock, flags);
-#else
-
 	wcdte_net_capture_cmd(wc, cmd);
-#endif
-}
-
-static void wcdte_cleanup_captured_packets(struct wcdte *wc)
-{
-	unsigned long flags;
-	struct dte_cmd *cmd;
-	struct dte_cmd *temp;
-	spin_lock_irqsave(&wc->captured_list_lock, flags);
-	list_for_each_entry_safe(cmd, temp, &wc->captured_packets, node) {
-		list_del(&cmd->node);
-		free_cmd(cmd);
-	}
-	WARN_ON(!list_empty(&wc->cmd_list));
-	spin_unlock_irqrestore(&wc->captured_list_lock, flags);
 }
 
 /**
@@ -693,6 +605,9 @@
 	if (cmd->cmdlen < MIN_PACKET_LEN) {
 		memset(&cmd->cmd[cmd->cmdlen],0,MIN_PACKET_LEN-cmd->cmdlen);
 		cmd->cmdlen = MIN_PACKET_LEN;
+	} else if (cmd->cmdlen > SFRAME_SIZE) {
+		DTE_PRINTK(WARNING, "Packet of size %d passed to dte_transmit_cmd.\n", cmd->cmdlen);
+		cmd->cmdlen = SFRAME_SIZE;
 	}
 	wcdte_capture_packet(wc, cmd);
 	if (unlikely((res=dte_submit(wc->txd, cmd)))) {
@@ -1152,8 +1067,8 @@
 			 * transcode. 
 			 */
 			ret = wait_event_interruptible_timeout(cpvt->waitq, 
-			       (!list_empty(&cpvt->rx_queue)), HZ/326);
-		if (-ERESTARTSYS == ret) {
+			       (!list_empty(&cpvt->rx_queue)), HZ/32);
+			if (-ERESTARTSYS == ret) {
 				/* Signal interrupted the wait */
 				return -EINTR;
 			} else if (ret) {
@@ -1407,8 +1322,8 @@
 	
 	/* Just for debugging purposes. */
 	rlen = (cmd->cmd[39] | (cmd->cmd[38] << 8)) - 20;
-	DTE_DEBUG(DTE_DEBUG_RTP_RX, "Adding RTP packet of length %d to channel: %p\n", 
-	          rlen, ztc);
+	DTE_DEBUG(DTE_DEBUG_RTP_RX, 
+	   "Adding RTP packet of length %d to channel: %p\n", rlen, ztc);
 	spin_lock_irqsave(&cpvt->lock, flags);
 	list_add_tail(&cmd->node, &cpvt->rx_queue);
 	spin_unlock_irqrestore(&cpvt->lock, flags);
@@ -2514,10 +2429,8 @@
 	init_MUTEX(&wc->chansem);
 	spin_lock_init(&wc->reglock);
 	spin_lock_init(&wc->cmd_list_lock);
-	spin_lock_init(&wc->captured_list_lock);
 	INIT_LIST_HEAD(&wc->cmd_list);
 	INIT_LIST_HEAD(&wc->lost_cmd_list);
-	INIT_LIST_HEAD(&wc->captured_packets);
 
 	DTE_PRINTK(INFO, "Attached to device at %s.\n", pci_name(wc->pdev));
 
@@ -2587,7 +2500,7 @@
 
 	min_numchannels = min(g723_numchannels, g729_numchannels);
 
-#if 0 /* Still working on G.723 with new interface. Limit to G.729 for now. */
+#if 1 /* Still working on G.723 with new interface. Limit to G.729 for now. */
 	if (!mode || strlen(mode) < 4) {
 		sprintf(wc->complexname, "G.729a / G.723.1");
 		complexfmts = ZT_FORMAT_G729A | ZT_FORMAT_G723_1;
@@ -2617,6 +2530,12 @@
 	if ((res = initialize_decoders(wc, complexfmts))) {
 		goto error_exit_swinit;
 	}
+	
+	if (DTE_DEBUG_NETWORK_IF & debug) {
+		if ((res = wcdte_net_register(wc))) {
+			goto error_exit_swinit;
+		}
+	}
 
 	/* ------------------------------------------------------------------
 	 * Load the firmware and start the DTE.
@@ -2673,9 +2592,6 @@
 	wcdte_debugfs_create_board_entry(wc);
 	zt_transcoder_register(wc->uencode);
 	zt_transcoder_register(wc->udecode);
-	if (DTE_DEBUG_NETWORK_IF & debug) {
-		wcdte_net_register(wc);
-	}
 	LEAVING();
 	return 0;
 
@@ -2686,6 +2602,7 @@
 	pci_set_drvdata(pdev, NULL);
 	release_region(wc->iobase, 0xff);
 error_exit_swinit:
+	if (wc->netdev)   wcdte_net_unregister(wc);
 	if (wc->encoders) kfree(wc->encoders);
 	if (wc->decoders) kfree(wc->decoders);
 	if (wc->uencode)  zt_transcoder_free(wc->uencode);
@@ -2734,8 +2651,6 @@
 
 	wcdte_net_unregister(wc);
 
-	wcdte_cleanup_captured_packets(wc);	
-	
 	wcdte_debugfs_remove_board_entry(wc);
 
 	if (debug) {
@@ -2819,6 +2734,14 @@
 	resume:	NULL,
 	id_table: wcdte_pci_tbl,
 };
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
+/*! Used to allocate commands to submit to the dte. */
+kmem_cache_t *cmd_cache;
+#else
+/*! Used to allocate commands to submit to the dte. */
+struct kmem_cache *cmd_cache;
+#endif
 
 int __init ztdte_init(void)
 {

Modified: team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.c
URL: http://svn.digium.com/view/zaptel/team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.c?view=diff&rev=4256&r1=4255&r2=4256
==============================================================================
--- team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.c (original)
+++ team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.c Mon May 12 14:09:03 2008
@@ -27,13 +27,31 @@
  *
  */
 
+#include "wctc4xxp.h"
+
+#ifdef CONFIG_WCDTE_NETWORK_IF
+
 #include <linux/kernel.h>
 #include <linux/pci.h>
 #include <linux/etherdevice.h>
-
-#include "wctc4xxp.h"
-
-extern int debug;
+#include <linux/delay.h>
+
+
+#define HERE() printk(KERN_DEBUG "HERE: %s:%d\n", __FILE__, __LINE__)
+
+static struct sk_buff * 
+wcdte_cmd_to_skb(struct net_device *netdev, const struct dte_cmd *cmd)
+{
+	struct sk_buff *skb;
+	skb = alloc_skb(cmd->cmdlen, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
+	if (skb) {
+		skb->dev = netdev;
+		skb_put(skb, cmd->cmdlen);
+		memcpy(skb->data, cmd->cmd, cmd->cmdlen);
+		skb->protocol = eth_type_trans(skb,netdev);
+	}
+	return skb;
+}
 
 static void wcdte_net_set_multi(struct net_device *netdev)
 {
@@ -41,25 +59,19 @@
 	DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __FUNCTION__);
 }
 
-static int wcdte_net_open(struct net_device *netdev)
-{
-	struct wcdte *wc = netdev->priv;
-	DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __FUNCTION__);
-#if 0
-	if (!try_module_get(THIS_MODULE)) {
-		return -EBUSY;
-	}
-#endif
-	return 0;
-}
-
-static int wcdte_net_stop(struct net_device *netdev)
-{
-	struct wcdte *wc = netdev->priv;
-	DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __FUNCTION__);
-#if 0
-	module_put(THIS_MODULE);
-#endif
+static int wcdte_net_up(struct net_device *netdev)
+{
+	struct wcdte *wc = netdev->priv;
+	DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __FUNCTION__);
+	netif_poll_enable(netdev);
+	return 0;
+}
+
+static int wcdte_net_down(struct net_device *netdev)
+{
+	struct wcdte *wc = netdev->priv;
+	DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __FUNCTION__);
+	netif_poll_disable(netdev);
 	return 0;
 }
 
@@ -68,6 +80,40 @@
 	struct wcdte *wc = netdev->priv;
 	DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __FUNCTION__);
 	return 0;
+}
+
+static int wcdte_poll(struct net_device *netdev, int *budget)
+{
+	int res;
+	struct sk_buff *skb;
+	struct wcdte *wc = netdev->priv;
+	int count = 0;
+	int quota = min(netdev->quota, *budget);
+
+	while ((skb = skb_dequeue(&wc->captured_packets)) && (count++ < quota)) {
+		if ((res = netif_receive_skb(skb))) {
+			if (NET_RX_DROP == res ) {
+				DTE_DEBUG(DTE_DEBUG_GENERAL, 
+				   "Kernel dropped packet.\n");
+			} else {
+				DTE_DEBUG(DTE_DEBUG_GENERAL, 
+				   "ret = %d\n", res);
+			}
+		}
+	}
+
+	*budget -=       count;
+	netdev->quota -= count;
+
+	if (skb) {
+		/* We still have socket buffers ready. */
+		return -1;
+	} else {
+		/* There were not any more buffers in the queue, so we're
+		 * done. */
+		netif_rx_complete(netdev);
+		return 0;
+	}
 }
 
 int wcdte_net_register(struct wcdte *wc)
@@ -81,17 +127,44 @@
 
 	netdev->priv = wc;
 	netdev->set_multicast_list = &wcdte_net_set_multi;
-	netdev->open = &wcdte_net_open;
-	netdev->stop = &wcdte_net_stop;
+	netdev->open = &wcdte_net_up;
+	netdev->stop = &wcdte_net_down;
 	netdev->hard_start_xmit = &wcdte_hard_start_xmit;
+	netdev->poll = &wcdte_poll;
+	netdev->weight = 64;
+	set_bit(__LINK_STATE_START, &netdev->state);
 
 	wc->netdev = netdev;
+
+	skb_queue_head_init(&wc->captured_packets);
 
 	DTE_PRINTK(DEBUG, "Creating network device %s for debug.\n", wc->board_name);
 	if ((res = register_netdev(netdev))) {
 		goto error_sw;
 	}
 
+	netif_poll_disable(netdev);
+
+	if (debug & DTE_DEBUG_NETWORK_EARLY) {
+		unsigned int seconds = 15;
+		DTE_PRINTK(INFO, 
+		   "Waiting %d seconds for adapter to be placed in " \
+		   "promiscuous mode for early trace.\n", seconds);
+		while (!netdev->promiscuity) {
+			if (signal_pending(current)) {
+				DTE_PRINTK(INFO, 
+				   "Aborting wait due to signal.\n");
+				break;
+			}
+			msleep(1000);
+			if (!(seconds--)) {
+				DTE_PRINTK(INFO,
+				   "Aborting wait due to timeout.\n");
+				break;
+			}
+		}
+	}
+
 	return 0;
 
 error_sw:
@@ -101,36 +174,46 @@
 
 void wcdte_net_unregister(struct wcdte *wc)
 {
+	struct sk_buff *skb;
 	if (!wc->netdev) {
 		return;
 	}
 
 	unregister_netdev(wc->netdev);
+
+	while ((skb = skb_dequeue(&wc->captured_packets))) {
+		kfree_skb(skb);
+	}
+	
 	free_netdev(wc->netdev);
 	wc->netdev = NULL;
 }
 
 
 /* Called when either a dte_cmd is being transmitted or received by the driver
- * and should be sent up to any processed (i.e. tcpdump) that are monitoring
+ * and should be sent up to any processes (i.e. tcpdump) that are monitoring
  * the traffic.
  */
 void wcdte_net_capture_cmd(struct wcdte *wc, const struct dte_cmd *cmd)
 {
 	struct sk_buff *skb;
 
-	if (NULL == wc->netdev) {
-		return;
-	}
-
-	skb = netdev_alloc_skb(wc->netdev, cmd->cmdlen);
-	if (skb) {
-		skb->dev = wc->netdev;
-		skb_put(skb, cmd->cmdlen);
-		memcpy(skb->data, cmd->cmd, cmd->cmdlen);
-		skb->protocol = eth_type_trans(skb,wc->netdev);
-		netif_rx(skb);
-	}
-
+	if (!wc->netdev) {
+		return;
+	}
+
+	if (!wc->netdev->promiscuity) {
+		return;
+	}
+
+	if (!(skb = wcdte_cmd_to_skb(wc->netdev, cmd))) {
+		return;
+	}
+
+	skb_queue_tail(&wc->captured_packets, skb);
+	netif_rx_schedule(wc->netdev);
 	return;
 }
+
+
+#endif /* CONFIG_WCDTE_NETWORK_IF */

Modified: team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.h
URL: http://svn.digium.com/view/zaptel/team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.h?view=diff&rev=4256&r1=4255&r2=4256
==============================================================================
--- team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.h (original)
+++ team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wcdte_net.h Mon May 12 14:09:03 2008
@@ -4,8 +4,14 @@
 struct wcdte;
 struct dte_cmd;
 
+#ifdef CONFIG_WCDTE_NETWORK_IF
 extern int wcdte_net_register(struct wcdte *wc);
 extern void wcdte_net_unregister(struct wcdte *wc);
 extern void wcdte_net_capture_cmd(struct wcdte *wc, const struct dte_cmd *cmd);
+#else
+static inline int wcdte_net_register(struct wcdte *wc) { return 0; }
+#define wcdte_net_unregister(__x) do {;} while(0)
+#define wcdte_net_capture_cmd(__x, __b) do {;} while(0)
+#endif
 
 #endif

Modified: team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wctc4xxp.h
URL: http://svn.digium.com/view/zaptel/team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wctc4xxp.h?view=diff&rev=4256&r1=4255&r2=4256
==============================================================================
--- team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wctc4xxp.h (original)
+++ team/sruffell/zaptel-1.4-transcoder/kernel/wctc4xxp/wctc4xxp.h Mon May 12 14:09:03 2008
@@ -27,6 +27,7 @@
 #ifndef __WCTC4XXP_H__
 #define __WCTC4XXP_H__
 
+#include <linux/version.h>
 #include <linux/kernel.h>
 #include <linux/spinlock.h>
 #include <linux/wait.h>
@@ -46,6 +47,7 @@
 #define DTE_DEBUG_RTP_RX           (1 << 3) /* 8  */
 #define DTE_DEBUG_RX_TIMEOUT	   (1 << 4) /* 16 */
 #define DTE_DEBUG_NETWORK_IF       (1 << 5) /* 32 */
+#define DTE_DEBUG_NETWORK_EARLY    (1 << 6) /* 64 */
 
 #define DTE_DEBUG(_dbgmask, _fmt, _args...)                                 \
 	if ((debug & _dbgmask) == (_dbgmask)) {                             \
@@ -53,6 +55,8 @@
 	}                                                                   \
 
 #define SFRAME_SIZE  1518
+
+extern int debug;
 
 struct dte_cmd {
 	/*! number of bytes in cmd */
@@ -65,6 +69,48 @@
 	/* cmd must be the last field. */
 	u8 cmd[SFRAME_SIZE];
 };
+
+static inline void initialize_cmd(struct dte_cmd *cmd, unsigned long cmd_flags) 
+{
+	memset(cmd, 0, sizeof(*cmd));
+	INIT_LIST_HEAD(&cmd->node);
+	init_completion(&cmd->complete);
+	cmd->flags = cmd_flags;
+}
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
+/*! Used to allocate commands to submit to the dte. */
+extern kmem_cache_t *cmd_cache;
+#else
+/*! Used to allocate commands to submit to the dte. */
+extern struct kmem_cache *cmd_cache;
+#endif
+
+
+static inline struct dte_cmd *
+__alloc_cmd(unsigned alloc_flags, unsigned long cmd_flags)
+{
+	struct dte_cmd *cmd;
+
+	cmd = kmem_cache_alloc(cmd_cache, alloc_flags);
+	if (likely(cmd)) {
+		initialize_cmd(cmd, cmd_flags);
+	}
+	return cmd;
+}
+
+static inline struct dte_cmd *
+alloc_cmd(void)
+{
+	return __alloc_cmd(GFP_KERNEL, 0);
+}
+
+static inline void 
+free_cmd(struct dte_cmd *cmd)
+{
+	kmem_cache_free(cmd_cache, cmd);
+	return;
+}
 
 struct channel_pvt;
 struct dte_descriptor_ring;
@@ -115,17 +161,8 @@
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debugfs_file;
 #endif
-	/* \todo In order to add this to the list of cards checked by the watchdog
-	 * timer. */
-	struct list_head watchdog_node;
 
-	/* Used for debugging */
-	spinlock_t captured_list_lock;
-	struct list_head captured_packets;
-	/* Number of packets on captured_packets for this device. */
-	unsigned int captured_list_length;
-
-	/* \todo either this or the capture list... */
+	struct sk_buff_head captured_packets;
 	struct net_device *netdev;
 };
 
@@ -144,4 +181,6 @@
 	__res;                                                               \
 })
 
+#define CONFIG_WCDTE_NETWORK_IF
+
 #endif /* __WCTC4XXP_H__ */




More information about the zaptel-commits mailing list