[Pkg-voip-commits] r2822 - in zaptel/trunk: debian/patches qozap

Tzafrir Cohen tzafrir-guest at alioth.debian.org
Fri Dec 15 15:12:56 CET 2006


Author: tzafrir-guest
Date: 2006-12-15 15:12:56 +0100 (Fri, 15 Dec 2006)
New Revision: 2822

Modified:
   zaptel/trunk/debian/patches/bristuff.dpatch
   zaptel/trunk/qozap/TODO
   zaptel/trunk/qozap/qozap.c
   zaptel/trunk/qozap/qozap.h
Log:
Bristuff 0.3.0-PRE-1w

Modified: zaptel/trunk/debian/patches/bristuff.dpatch
===================================================================
--- zaptel/trunk/debian/patches/bristuff.dpatch	2006-12-15 03:43:08 UTC (rev 2821)
+++ zaptel/trunk/debian/patches/bristuff.dpatch	2006-12-15 14:12:56 UTC (rev 2822)
@@ -3,7 +3,7 @@
 ##
 ## All lines beginning with `## DP:' are a description of the patch.
 ## DP: This is the patch zaptel.patch from bristuff, with the Makefile
-## DP: patch removed. Version: bristuff-0.3.0-PRE-1v
+## DP: patch removed. Version: bristuff-0.3.0-PRE-1w
 
 @DPATCH@
 diff -urN zaptel-1.2.10.orig/zaptel.c zaptel-1.2.10/zaptel.c
@@ -178,15 +178,6 @@
  	spinlock_t lock;
  	char name[40];		/* Name */
  	/* Specified by zaptel */
-@@ -1068,7 +1075,7 @@
- 	int		txbufpolicy;			/* Buffer policy */
- 	int		rxbufpolicy;			/* Buffer policy */
- 	int		txdisable;				/* Disable transmitter */
--	int 	rxdisable;				/* Disable receiver */
-+	int 		rxdisable;				/* Disable receiver */
- 	
- 	
- 	/* Tone zone stuff */
 @@ -1231,6 +1238,10 @@
  #define ZT_FLAG_T1PPP			(1 << 15)
  #define ZT_FLAG_SIGFREEZE		(1 << 16)	/* Freeze signalling */
@@ -236,6 +227,116 @@
 +#define CONFIG_ZAPATA_BRI_DCHANS
 +
  #endif
+diff -urN zaptel-1.2.10.orig/ztcfg.c zaptel-1.2.10/ztcfg.c
+--- zaptel-1.2.10.orig/ztcfg.c	2006-02-01 03:33:54.000000000 +0100
++++ zaptel-1.2.10/ztcfg.c	2006-12-05 12:37:31.536696070 +0100
+@@ -90,6 +90,10 @@
+ 
+ static int stopmode = 0;
+ 
++static int stopwhich = -1;
++
++static int startwhich = -1;
++
+ static int numdynamic = 0;
+ 
+ static char zonestoload[ZT_TONE_ZONE_MAX][10];
+@@ -1141,7 +1145,8 @@
+ 		"  -d [level]        -- Generate debugging output. (Default level is 1.)\n"
+ 		"  -f                -- Always reconfigure every channel\n"
+ 		"  -h                -- Generate this help statement\n"
+-		"  -s                -- Shutdown spans only\n"
++		"  -s[span]          -- Deactivate/shutdown span [span]. Deactivates all spans if no [span] is given.\n"
++		"  -a[span]          -- Activate/start span [span]. Activates all spans if no [span] is given.\n"
+ 		"  -t                -- Test mode only, do not apply\n"
+ 		"  -v                -- Verbose (more -v's means more verbose)\n"
+ 	,c);
+@@ -1154,7 +1159,7 @@
+ 	char *buf;
+ 	char *key, *value;
+ 	int x,found;
+-	while((c = getopt(argc, argv, "fthc:vsd::")) != -1) {
++	while((c = getopt(argc, argv, "fthc:vs::a::d::")) != -1) {
+ 		switch(c) {
+ 		case 'c':
+ 			filename=optarg;
+@@ -1175,8 +1180,20 @@
+ 			fo_real = 0;
+ 			break;
+ 		case 's':
++			if (optarg) {
++			    stopwhich = atoi(optarg);
++			} else {
++			    stopwhich = -1;
++			}
+ 			stopmode = 1;
+ 			break;
++		case 'a':
++			if (optarg) {
++			    startwhich = atoi(optarg);
++			} else {
++			    startwhich = -1;
++			}
++			break;
+ 		case 'd':
+ 			if (optarg)
+ 				debug = atoi(optarg);
+@@ -1242,14 +1259,27 @@
+ 					ioctl(fd, ZT_DYNAMIC_DESTROY, &zds[x]);
+ 				}
+ 				if (stopmode) {
+-					for (x=0;x<spans;x++) {
++					if (stopwhich > 0){
++					    if ((stopwhich > spans) || (ioctl(fd, ZT_SHUTDOWN, &lc[stopwhich - 1].span))) {
++						fprintf(stderr, "Zaptel shutdown failed: %s\n", strerror(errno));
++						close(fd);
++						exit(1);						
++					    } else {
++						if (verbose) {
++						    printf("Deactivated span %d\n", stopwhich);
++						}
++					    }					    
++					} else {
++					    for (x=0;x<spans;x++) {
+ 						if (ioctl(fd, ZT_SHUTDOWN, &lc[x].span)) {
+ 							fprintf(stderr, "Zaptel shutdown failed: %s\n", strerror(errno));
+ 							close(fd);
+ 							exit(1);
+ 						}
++					    }
+ 					}
+ 				} else {
++				    if (startwhich == -1) {
+ 					for (x=0;x<spans;x++) {
+ 						if (ioctl(fd, ZT_SPANCONFIG, lc + x)) {
+ 							fprintf(stderr, "ZT_SPANCONFIG failed on span %d: %s (%d)\n", lc[x].span, strerror(errno), errno);
+@@ -1348,12 +1378,25 @@
+ 							exit(1);
+ 						}
+ 					}
+-					for (x=0;x<spans;x++) {
++				    }
++					if (startwhich > 0) {
++					    if ((startwhich > spans) || (ioctl(fd, ZT_STARTUP, &lc[startwhich - 1].span))) {
++						fprintf(stderr, "Zaptel startup failed: %s\n", strerror(errno));
++						close(fd);
++						exit(1);
++					    } else {
++						if (verbose) {
++						    printf("Activated span %d\n", startwhich);
++						}
++					    }
++					} else {
++					    for (x=0;x<spans;x++) {
+ 						if (ioctl(fd, ZT_STARTUP, &lc[x].span)) {
+ 							fprintf(stderr, "Zaptel startup failed: %s\n", strerror(errno));
+ 							close(fd);
+ 							exit(1);
+ 						}
++					    }
+ 					}
+ 				}
+ 			}
 diff -urN zaptel-1.2.10.orig/ztpty.c zaptel-1.2.10/ztpty.c
 --- zaptel-1.2.10.orig/ztpty.c	1970-01-01 01:00:00.000000000 +0100
 +++ zaptel-1.2.10/ztpty.c	2006-10-19 11:16:47.000000000 +0200

Modified: zaptel/trunk/qozap/TODO
===================================================================
--- zaptel/trunk/qozap/TODO	2006-12-15 03:43:08 UTC (rev 2821)
+++ zaptel/trunk/qozap/TODO	2006-12-15 14:12:56 UTC (rev 2822)
@@ -1,4 +1,3 @@
-- native-native bridging
 - onchip dtmf
 - E channel support for full debug
 

Modified: zaptel/trunk/qozap/qozap.c
===================================================================
--- zaptel/trunk/qozap/qozap.c	2006-12-15 03:43:08 UTC (rev 2821)
+++ zaptel/trunk/qozap/qozap.c	2006-12-15 14:12:56 UTC (rev 2822)
@@ -2,7 +2,7 @@
  * qozap.c - Zaptel driver for the quadBRI PCI ISDN card
  * and the octoBRI PCI ISDN card!
  *
- * Copyright (C) 2003, 2004, 2005 Junghanns.NET GmbH
+ * Copyright (C) 2003, 2004, 2005, 2006 Junghanns.NET GmbH
  *
  * Klaus-Peter Junghanns <kpj at junghanns.net>
  *
@@ -29,6 +29,7 @@
 static int pcmslave=0;
 static int bloop=0;
 static int debug=0;
+static int dacs=1;
 static struct qoz_card *qoz_dev_list = NULL;
 static int qoz_dev_count = 0;
 static int totalBRIs = 0;
@@ -50,6 +51,7 @@
 void qoz_shutdownCard(struct qoz_card *qoztmp) {
     int s=0;
     unsigned long flags;
+    
     int stports=0;
     if (qoztmp == NULL) {
 	printk(KERN_INFO "qozap: shutting down NULL card!\n");
@@ -63,38 +65,32 @@
     if (debug)
 	printk(KERN_INFO "qozap: shutting down card %d (cardID %d) at io port %#x.\n",qoztmp->cardno,qoztmp->cardID,(u_int) qoztmp->ioport);
 
-    if (qoztmp->ztdev != NULL) {
-	stports = qoztmp->stports;
-	for (s=0; s < stports; s++) {
-	    if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-		ztqoz_shutdown(&qoztmp->ztdev->spans[s]);
-		if (debug)
-		    printk(KERN_INFO "qozap: shutdown card %d span %d.\n",qoztmp->cardno,s+1);
-	    }
-	}
-    }
 
     spin_lock_irqsave(&qoztmp->lock,flags);
 
     // turn off irqs
-    qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0); 
     qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0); 
     qoz_outb(qoztmp,qoz_R_SCI_MSK, 0); 
+    qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0); 
 
+    spin_unlock_irqrestore(&qoztmp->lock,flags);
 
-    // softreset
-    qoz_outb(qoztmp,qoz_R_CIRM,0x8);
-    qoz_outb(qoztmp,qoz_R_CIRM,0x0); 
-    qoz_waitbusy(qoztmp);
+    stports = qoztmp->stports;
+    for (s=0; s < stports; s++) {
+        if(qoztmp->spans[s].flags & ZT_FLAG_REGISTERED) {
+    	    zt_unregister(&(qoztmp->spans[s]));
+	    if (debug > 2)
+	        printk(KERN_INFO "qozap: unregistered card %d span %d.\n",qoztmp->cardno,s+1);
+	}
+    }
 
-    qoz_outb(qoztmp,qoz_R_IRQMSK_MISC, 0); 
-    qoz_outb(qoztmp,qoz_R_SCI_MSK, 0); 
-    qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0); 
 
     release_region(qoztmp->ioport, 8);
     iounmap((void *) qoztmp->pci_io);
     release_mem_region((unsigned long) qoztmp->pci_io_phys, 256);
 
+    spin_lock_irqsave(&qoztmp->lock,flags);
+
     qoztmp->pci_io = NULL;
     qoztmp->ioport = 0;
 
@@ -106,22 +102,14 @@
     free_irq(qoztmp->irq,qoztmp);
     spin_unlock_irqrestore(&qoztmp->lock,flags);
 
-    if (qoztmp->ztdev != NULL) {
-	stports = qoztmp->stports;
-	for (s=0; s < stports; s++) {
-	    if(qoztmp->ztdev->spans[s].flags & ZT_FLAG_REGISTERED) {
-		zt_unregister(&qoztmp->ztdev->spans[s]);
-		if (debug)
-		    printk(KERN_INFO "qozap: unregistered card %d span %d.\n",qoztmp->cardno,s+1);
-	    }
-	}
-	kfree(qoztmp->ztdev);
-	qoztmp->ztdev = NULL;
-    }
+    
 }
 
 void qoz_doLEDs(struct qoz_card *qoztmp) {
     unsigned char leds = 0x0;
+    unsigned long flags;
+    spin_lock_irqsave(&qoztmp->lock,flags);
+
     if ((qoztmp->type == 0xb520) && (qoztmp->stports == 4)){
 //	if ((qoztmp->ticks > 0) && (qoztmp->ticks <= 300)) {
 	    qoz_outb(qoztmp,qoz_R_GPIO_SEL,0x20 | 0x10);
@@ -165,6 +153,7 @@
     */
 	    qoz_outb(qoztmp,qoz_R_GPIO_OUT1, leds);
     }
+    spin_unlock_irqrestore(&qoztmp->lock,flags);
 }
 
 void qoz_doWD(struct qoz_card *qoztmp) {
@@ -182,10 +171,14 @@
 }
 
 void qoz_undoWD(struct qoz_card *qoztmp) {
+    unsigned long flags;
+
+    spin_lock_irqsave(&qoztmp->lock,flags);
     printk(KERN_INFO "qozap: Stopping hardware watchdog.\n");
     qoz_outdw_io(qoztmp,0x4000, qoz_WD_P0);
     qoztmp->wdp = 0;
     qoz_inb_io(qoztmp,qoz_R_CHIP_ID);    
+    spin_unlock_irqrestore(&qoztmp->lock,flags);
 }
 
 void qoz_resetCard(struct qoz_card *qoztmp) {
@@ -285,17 +278,8 @@
 	qoztmp->wdp = 0;
     }
 
-/*    for (i=0;i<qoztmp->stports;i++) {
-	if (qoztmp->st[i].nt_mode) {
-	    qoz_outb(qoztmp,qoz_R_ST_SYNC,0x8 | i);
-	    if (debug)
-		printk(KERN_INFO "qoztmp: using NT port %d for sync\n", i);
-	    break;
-	}
-    }
-    if (i == qoztmp->stports) { */
-	qoz_outb(qoztmp,qoz_R_ST_SYNC,0x0);
-/*   } */
+    qoz_outb(qoztmp,qoz_R_ST_SYNC,0x0);
+    
     spin_unlock_irqrestore(&(qoztmp->lock),flags);
 }
 
@@ -320,7 +304,9 @@
     int x=0;
     char fifo = 0;
     char offset = 0;
+    unsigned long flags;
 
+
     if (qoztmp->type == 0xb552) {
 	offset = 24;
     } else {
@@ -329,9 +315,10 @@
 
     fifo = stport + offset;
 
-    if (qoztmp->ztdev->chans[stport][chan].bytes2transmit < 1) {
+    if (qoztmp->chans[stport][chan].bytes2transmit < 1) {
 	return 0;
     } else {
+	spin_lock_irqsave(&qoztmp->lock,flags);
 	/* select fifo */
 	qoz_outb(qoztmp,qoz_R_FIFO,fifo << 1);    
 	qoz_waitbusy(qoztmp);
@@ -339,19 +326,20 @@
 	if (debug > 1)
 	    printk(KERN_INFO "qozap: card %d stport %d TX [ ", qoztmp->cardno, stport + 1);
 	/* copy frame to fifo */
-    	for (x=0;x<qoztmp->ztdev->chans[stport][chan].bytes2transmit;x++) {
+    	for (x=0;x<qoztmp->chans[stport][chan].bytes2transmit;x++) {
 	    if (debug > 1)
 	        printk("%#x ",qoztmp->dtxbuf[stport][x]);
     	    qoz_outb(qoztmp,qoz_A_FIFO_DATA0,qoztmp->dtxbuf[stport][x]);
 	}
 	if (debug > 1)
-	    printk("] %d bytes\n",qoztmp->ztdev->chans[stport][chan].bytes2transmit);
+	    printk("] %d bytes\n",qoztmp->chans[stport][chan].bytes2transmit);
 
-	if (qoztmp->ztdev->chans[stport][chan].eoftx == 1) {
+	if (qoztmp->chans[stport][chan].eoftx == 1) {
 	    /* transmit HDLC frame */
     	    qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);    
     	    qoz_waitbusy(qoztmp);
 	}
+	spin_unlock_irqrestore(&qoztmp->lock,flags);
     }
     return 0;
 }
@@ -359,7 +347,9 @@
 static int qoz_fifo_tx(struct qoz_card *qoztmp, char fifo) {
     int stport = fifo / 2;
     int chan = fifo % 2;
+    unsigned long flags;
 
+    spin_lock_irqsave(&qoztmp->lock,flags);
     /* select fifo */
     qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1));    
     qoz_waitbusy(qoztmp);
@@ -367,6 +357,7 @@
     qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][0]));
     qoz_outdw(qoztmp,qoz_A_FIFO_DATA0,*((unsigned int *) &qoztmp->txbuf[stport][chan][4]));
 	    
+    spin_unlock_irqrestore(&qoztmp->lock,flags);
     return 0;
 }
 
@@ -378,6 +369,7 @@
     unsigned short oz1=0,oz2=0;
     char fifo = 0;
     char offset = 0;
+    unsigned long flags;
 
     if (qoztmp->type == 0xb552) {
 	offset = 24;
@@ -386,8 +378,9 @@
     }
 
     fifo = stport + offset;
+
+    spin_lock_irqsave(&qoztmp->lock,flags);
     // select rx fifo
-    
     qoz_outb(qoztmp,qoz_R_FIFO,(fifo << 1) | 1);    
     qoz_waitbusy(qoztmp);
 
@@ -401,7 +394,8 @@
     if (f1 == f2) {
 	/* no frame */
 	qoztmp->st[stport].drx--;
-	qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
+	qoztmp->chans[stport][2].bytes2receive = 0;
+	spin_unlock_irqrestore(&qoztmp->lock,flags);
 	return 0;
     }
     
@@ -431,8 +425,8 @@
 
     if (len > qoz_DFIFO_SIZE4) {
 	printk(KERN_INFO "\nqozap: buffer overflow in D channel RX!\n");
-	qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-	qoztmp->ztdev->chans[stport][2].eofrx = 0;
+	qoztmp->chans[stport][2].bytes2receive = 0;
+	qoztmp->chans[stport][2].eofrx = 0;
     } else {
 	if (debug > 1) printk(KERN_INFO "qozap: card %d span %d RX [ ", qoztmp->cardno, stport + 1);
 	for (i=0; i<len; i++) {
@@ -441,17 +435,17 @@
 	    if (debug > 1) printk("%#x ",data);
 	}
 	if (debug > 1) printk("] %d bytes\n", len);
-	qoztmp->ztdev->chans[stport][2].bytes2receive = i;
-	qoztmp->ztdev->chans[stport][2].eofrx = 1;
+	qoztmp->chans[stport][2].bytes2receive = i;
+	qoztmp->chans[stport][2].eofrx = 1;
     }
 
     stat = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
     if (stat != 0x0) {
 	// bad CRC, skip it
 	printk(KERN_INFO "qozap: CRC error for HDLC frame on card %d (cardID %d) S/T port %d\n",qoztmp->cardno, qoztmp->cardID, stport+1);
-	qoztmp->ztdev->chans[stport][2].bytes2receive = 0;
-	qoztmp->ztdev->chans[stport][2].eofrx = 0;
-//        zt_qevent_nolock(&qoztmp->ztdev->chans[stport][2], ZT_EVENT_BADFCS);
+	qoztmp->chans[stport][2].bytes2receive = 0;
+	qoztmp->chans[stport][2].eofrx = 0;
+//        zt_qevent_nolock(&qoztmp->chans[stport][2], ZT_EVENT_BADFCS);
     }
     qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x1);    
     qoz_waitbusy(qoztmp);
@@ -463,6 +457,7 @@
 	printk(KERN_INFO "qozap: trying to receive too much (card %d span %d drx %d)\n", qoztmp->cardno, stport+1, qoztmp->st[stport].drx);
 	qoztmp->st[stport].drx = 0;
     }
+    spin_unlock_irqrestore(&qoztmp->lock,flags);
     return 0;
 }
 
@@ -475,7 +470,10 @@
     unsigned short z1=1,z2=1;
     unsigned short oz1=0,oz2=0;
     int mumbojumbo=0;
+    unsigned long flags;
 
+    spin_lock_irqsave(&qoztmp->lock,flags);
+
         /* select rx fifo */
 	qoz_outb(qoztmp,qoz_R_FIFO,0x80 | (fifo << 1) | 1);    
         qoz_waitbusy(qoztmp);
@@ -497,13 +495,16 @@
     		data = qoz_inb(qoztmp,qoz_A_FIFO_DATA0);
 	    }
 	    qoztmp->clicks++;
-	    if ((qoztmp->clicks > 10) && (debug > 0)) {
+	    if ((qoztmp->clicks > 50) && (debug > 0)) {
 		printk(KERN_CRIT "qozap: dropped audio card %d cardid %d bytes %d z1 %d z2 %d\n", qoztmp->cardno, qoztmp->cardID, mumbojumbo, z1, z2);
 		qoztmp->clicks = 0;
 	    }
 	}
+
+
 	if (len < ZT_CHUNKSIZE) {
 //	    printk(KERN_INFO "qozap: not enough to receive (%d bytes)\n",len);
+	    spin_unlock_irqrestore(&qoztmp->lock,flags);
 	    return 0;
 	} else {
 	    if (bloop) {
@@ -514,20 +515,25 @@
 	        *((unsigned int *) &qoztmp->rxbuf[stport][chan][4]) = qoz_indw(qoztmp,qoz_A_FIFO_DATA0);
 	    }
 	}
+
+    spin_unlock_irqrestore(&qoztmp->lock,flags);
 	if (bloop == 0)
-	    zt_ec_chunk(&qoztmp->ztdev->spans[stport].chans[chan], qoztmp->ztdev->spans[stport].chans[chan].readchunk, qoztmp->ztdev->spans[stport].chans[chan].writechunk);
+	    zt_ec_chunk(&qoztmp->spans[stport].chans[chan], qoztmp->spans[stport].chans[chan].readchunk, qoztmp->spans[stport].chans[chan].writechunk);
 
 //    printk(KERN_INFO "s/t port %d, channel %d, dbufi=%d, f1=%d, f2=%d, z1=%d, z2=%d  => len = %d stat=%#x, hdlc=%d\n",stport,chan,qoztmp->st[stport].dbufi,f1,f2,z1,z2,len,stat,hdlc);    
     return 0;
 }
 
 static void qoz_assign(struct qoz_card *qoztmp, int src_span, int src_chan, int dst_span, int dst_chan) {
+    unsigned long flags;
     int timeslot = src_span * 2 + (src_chan - 1);
     int dst_fifo = dst_span * 2 + (dst_chan - 1); 
     int src_fifo = src_span * 2 + (src_chan - 1); 
     int src_hfc_chan = src_span * 4 + (src_chan - 1);
     int dst_hfc_chan = dst_span * 4 + (dst_chan - 1);
 
+    spin_lock_irqsave(&qoztmp->lock, flags);
+
     qoz_outb(qoztmp,qoz_R_FIFO,(src_fifo << 1) | 1); 
     qoz_waitbusy(qoztmp);
     qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
@@ -548,13 +554,18 @@
     qoz_outb(qoztmp,qoz_R_SLOT,(timeslot << 1) | 1); 
     qoz_outb(qoztmp,qoz_A_SL_CFG, (dst_hfc_chan << 1) | 1 | 0x40);
 
+    spin_unlock_irqrestore(&qoztmp->lock, flags);
 }
 
 static void qoz_unassign(struct qoz_card *qoztmp, int span, int chan) {
+    unsigned long flags;
+
     int timeslot = span * 2 + (chan - 1);
     int fifo = span * 2 + (chan - 1);
     int hfc_chan = span * 4 + (chan - 1);
 
+    spin_lock_irqsave(&qoztmp->lock, flags);
+
     qoz_outb(qoztmp,qoz_R_FIFO,(fifo << 1));
     qoz_waitbusy(qoztmp);
     qoz_outb(qoztmp,qoz_R_INC_RES_FIFO,0x2);
@@ -576,16 +587,18 @@
 
     qoz_outb(qoztmp,qoz_R_SLOT,timeslot << 1);
     qoz_outb(qoztmp,qoz_A_SL_CFG, 0x0);
+
+    spin_unlock_irqrestore(&qoztmp->lock, flags);
 }
 
 
 static int ztqoz_dacs(struct zt_chan *dst, struct zt_chan *src)
 {
-	struct zt_qoz *ztqoz = NULL;
 	struct qoz_card *qoztmp = NULL;
+	if (!dacs) return 0;
+
 	if (src) { 
-	    ztqoz = src->pvt;
-	    qoztmp = ztqoz->card;
+	    qoztmp = src->pvt;
 	}
 	if (src && (src->pvt != dst->pvt)) {
 		/* cross card bridging */
@@ -604,8 +617,7 @@
 		    qoz_assign(qoztmp, src->span->offset, src->chanpos, dst->span->offset, dst->chanpos);
 		}
 	} else {
-		ztqoz = dst->pvt;
-		qoztmp = ztqoz->card;
+		qoztmp = dst->pvt;
 		if (dst->chanpos == 3) {
 		    if (debug)
 			printk("Not Unassigning D-channel %d/%d!\n", dst->span->offset, dst->chanpos);
@@ -618,48 +630,71 @@
 	return 0;
 }
 
+static void qoz_resync(struct qoz_card *qoztmp) {
+    int i=0;
+    int best=99;
+    int src=-1;
 
+    for (i=0; i<qoztmp->stports; i++){
+	if (qoztmp->st[i].l1up && (qoztmp->st_sync[i] > 0) && (qoztmp->st_sync[i] < best)) {
+	    best = qoztmp->st_sync[i];
+	    src = i;
+	}
+    }
+    if (src == qoztmp->syncsrc)
+	return;
+    if (src >= 0) {
+	qoztmp->syncsrc = src;
+	qoz_outb(qoztmp, qoz_R_ST_SYNC, src | 0x08);
+	if (debug > 2)
+	    printk(KERN_INFO "qozap: Sync source changed to span %d\n", src + 1);
+    }
+}
+
 static inline void qoz_run(struct qoz_card *qoztmp) {
     int s=0;
-    if (qoztmp->ztdev != NULL) {
-	for (s=0;s<qoztmp->stports;s++) {
+    unsigned long flags;
+
+    for (s=0;s<qoztmp->stports;s++) {
 	if (!bloop) {
-	    if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
+	    if (qoztmp->spans[s].flags & ZT_FLAG_RUNNING) {
 		/* oh zaptel! tell us what to transmit... */
-    		zt_transmit(&qoztmp->ztdev->spans[s]);
+    		zt_transmit(&qoztmp->spans[s]);
 	        /* B1 xmit */
 		qoz_fifo_tx(qoztmp, s * 2);
 		/* B2 xmit */
 		qoz_fifo_tx(qoztmp, (s * 2) + 1);
 
-		if ((qoztmp->st[s].layer1state != 7) && (qoztmp->ztdev->chans[s][2].bytes2transmit > 0) && (qoztmp->st[s].nt_mode != 1)) {
+		if ((qoztmp->st[s].layer1state != 7) && (qoztmp->chans[s][2].bytes2transmit > 0) && (qoztmp->st[s].nt_mode != 1)) {
 		    if (qoztmp->st[s].t3 == -1) {
 			if (debug > 2)
 			    printk(KERN_INFO "qozap: activating layer 1, span %d\n",s);
 			qoztmp->st[s].t3 = 0;
-			qoz_outb(qoztmp,qoz_R_ST_SEL, s);
-			qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60); 
+			spin_lock_irqsave(&qoztmp->lock,flags);
+			    qoz_outb(qoztmp,qoz_R_ST_SEL, s);
+			    qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60); 
+			spin_unlock_irqrestore(&qoztmp->lock, flags);
 		    } else {
 		    }
 		}
 		
 		/* D xmit */
-		if (qoztmp->ztdev->spans[s].alarms != ZT_ALARM_RED) {
+		if (qoztmp->spans[s].alarms != ZT_ALARM_RED) {
 		    qoz_dfifo_tx(qoztmp, s);
 		} else {
 		    if ((qoztmp->st[s].t3 == -1) && (qoztmp->st[s].t4 == -1) && (qoztmp->st[s].layer1state == 3) && (qoztmp->st[s].nt_mode != 1)) {
 			/* clear alarms */
 			if (debug > 2)
 			    printk(KERN_INFO "qozap: clearing alarms on span %d\n",s);
-			qoztmp->ztdev->spans[s].alarms = ZT_ALARM_NONE;
-			zt_alarm_notify_no_master_change(&qoztmp->ztdev->spans[s]);
+			qoztmp->spans[s].alarms = ZT_ALARM_NONE;
+			zt_alarm_notify_no_master_change(&qoztmp->spans[s]);
 		    }
 		}
 
-		qoztmp->ztdev->chans[s][2].bytes2receive = 0;
-		qoztmp->ztdev->chans[s][2].bytes2transmit = 0;
-		qoztmp->ztdev->chans[s][2].eofrx = 0;
-		qoztmp->ztdev->chans[s][2].eoftx = 0;
+		qoztmp->chans[s][2].bytes2receive = 0;
+		qoztmp->chans[s][2].bytes2transmit = 0;
+		qoztmp->chans[s][2].eofrx = 0;
+		qoztmp->chans[s][2].eoftx = 0;
 
 	    }
 
@@ -673,9 +708,9 @@
 		    printk(KERN_CRIT "qozap: card %d st[%d].drx = %d\n", qoztmp->cardno, s, qoztmp->st[s].drx);
 		qoz_dfifo_rx(qoztmp, s);
 	    }
-	    if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
+	    if (qoztmp->spans[s].flags & ZT_FLAG_RUNNING) {
 	        /* oh zaptel! thou shall receive! */
-		zt_receive(&(qoztmp->ztdev->spans[s]));
+		zt_receive(&(qoztmp->spans[s]));
 	    }
 	} else {
 	    // loop
@@ -689,13 +724,13 @@
 		    printk(KERN_CRIT "qozap: card %d st[%d].drx = %d\n", qoztmp->cardno, s, qoztmp->st[s].drx);
 		qoz_dfifo_rx(qoztmp, s);
 	    } 
-	    if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
-		zt_receive(&(qoztmp->ztdev->spans[s]));
+	    if (qoztmp->spans[s].flags & ZT_FLAG_RUNNING) {
+		zt_receive(&(qoztmp->spans[s]));
 	    }
 */
-	    if (qoztmp->ztdev->spans[s].flags & ZT_FLAG_RUNNING) {
+	    if (qoztmp->spans[s].flags & ZT_FLAG_RUNNING) {
 		/* oh zaptel! tell us what to transmit... */
-    	//	zt_transmit(&qoztmp->ztdev->spans[s]);
+    	//	zt_transmit(&qoztmp->spans[s]);
 	        /* B1 xmit */
 		qoz_fifo_tx(qoztmp, s * 2);
 		/* B2 xmit */
@@ -703,15 +738,14 @@
 		/* D xmit */
 //		qoz_dfifo_tx(qoztmp, s);
 
-		qoztmp->ztdev->chans[s][2].bytes2receive = 0;
-		qoztmp->ztdev->chans[s][2].bytes2transmit = 0;
-		qoztmp->ztdev->chans[s][2].eofrx = 0;
-		qoztmp->ztdev->chans[s][2].eoftx = 0;
+		qoztmp->chans[s][2].bytes2receive = 0;
+		qoztmp->chans[s][2].bytes2transmit = 0;
+		qoztmp->chans[s][2].eofrx = 0;
+		qoztmp->chans[s][2].eoftx = 0;
 
 	    }
 	}
-	} 
-    }
+    } 
 }
 
 #ifdef LINUX26
@@ -720,10 +754,7 @@
 static void qoz_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
 #endif
     struct qoz_card *qoztmp = dev_id;
-    struct zt_qoz *ztqoz = qoztmp->ztdev;
-#ifndef RELAXED_LOCKING
     unsigned long flags;
-#endif
     unsigned char irq_misc,irq_sci,status,l1state,irq_foview,fi;
     int st=0,i=0,offset=0;
     int j=0;
@@ -753,22 +784,14 @@
     }
 
     
-#ifdef RELAXED_LOCKING
-    spin_lock(&(qoztmp->lock));
-#else
     spin_lock_irqsave(&(qoztmp->lock), flags);
-#endif
-    status = qoz_inb(qoztmp,qoz_R_STATUS);
-    irq_sci = qoz_inb(qoztmp,qoz_R_SCI);
+	status = qoz_inb(qoztmp,qoz_R_STATUS);
+	irq_sci = qoz_inb(qoztmp,qoz_R_SCI);
+    spin_unlock_irqrestore(&(qoztmp->lock), flags);
 
     if (!(status & 0x80) && !(status & 0x40) && (irq_sci == 0)) {
 //	printk(KERN_CRIT "qozap: status %#x\n", status);
 	// it's not us!
-#ifdef RELAXED_LOCKING
-	spin_unlock(&(qoztmp->lock));
-#else
-	spin_unlock_irqrestore(&(qoztmp->lock), flags);
-#endif
 #ifdef LINUX26
 		return IRQ_NONE;
 #else
@@ -785,6 +808,7 @@
         } else {
 	    offset = 28;
 	}
+	spin_lock_irqsave(&(qoztmp->lock), flags);
 	for (st=0;st<qoztmp->stports;st++) {
 	    if (irq_sci & (1 << st)) {
 		qoz_outb(qoztmp,qoz_R_ST_SEL,st);
@@ -798,19 +822,21 @@
 			printk(KERN_INFO "card %d span %d state G%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
 		    // NT state machine
 		    if (l1state == 3) {
+			qoztmp->st[st].l1up = 1;
 			// keep layer1 up!
 			if (qoztmp->stports == 8) {
-			    sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
+			    sprintf(qoztmp->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
 			} else {
-			    sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
+			    sprintf(qoztmp->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 ACTIVATED (G%d)",qoztmp->cardno ,st + 1,qoztmp->cardID, l1state);
 			}
 			qoz_outb(qoztmp,qoz_A_ST_WR_STA,3 | 0x10 );
 			qoztmp->leds[st] = 1;
 		    } else {
+			qoztmp->st[st].l1up = 0;
 			if (qoztmp->stports == 8) {
-			    sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
+			    sprintf(qoztmp->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [NT] Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1, l1state);
 			} else {
-			    sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
+			    sprintf(qoztmp->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d) Layer 1 DEACTIVATED (G%d)",qoztmp->cardno ,st + 1,qoztmp->cardID, l1state);
 			}
 			qoztmp->leds[st] = 0;
 		    }
@@ -819,9 +845,10 @@
 			printk(KERN_INFO "card %d span %d state F%d (A_ST_RD_STA = %#x)\n",qoztmp->cardno,st+1,l1state,qoz_inb(qoztmp,qoz_A_ST_RD_STA));
 		    // TE state machine
 		    if (l1state == 3) {
+			qoztmp->st[st].l1up = 0;
 			if (qoztmp->st[st].t3 > -1)  {
 			    /* keep layer1 up, if the span is started. */
-			    if (qoztmp->ztdev->spans[st].flags & ZT_FLAG_RUNNING) {
+			    if (qoztmp->spans[st].flags & ZT_FLAG_RUNNING) {
 				if (debug > 2) 
 				    printk("qozap: re-activating layer1 span %d\n", st);
     				qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x60);
@@ -831,17 +858,18 @@
 				    printk("qozap: not re-activating layer1 span %d\n", st);
     				qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x40);
 			    /* if we tried to activate layer 1 and it failed make this an alarm */
-//			    qoztmp->ztdev->spans[st].alarms = ZT_ALARM_RED;
-//			    zt_alarm_notify(&qoztmp->ztdev->spans[st]);
+//			    qoztmp->spans[st].alarms = ZT_ALARM_RED;
+//			    zt_alarm_notify(&qoztmp->spans[st]);
 			    /* if the network shuts us down in idle mode dont make this an alarm */
 			}
 			qoztmp->leds[st] = 0;
 			if (qoztmp->stports == 8) {
-			    sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
+			    sprintf(qoztmp->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
 			} else {
-			    sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
+			    sprintf(qoztmp->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,qoztmp->cardID, l1state);
 			}
 		    } else if (l1state == 7) {
+			qoztmp->st[st].l1up = 1;
 			/* reset D RX fifo */
 			qoz_outb(qoztmp,qoz_R_FIFO,((st + offset) << 1) | 1);
 			qoz_waitbusy(qoztmp);
@@ -849,13 +877,13 @@
 			qoz_waitbusy(qoztmp);
 			/* activation complete, stop timer t3 */
 			qoztmp->st[st].t3 = -1;
-			qoztmp->ztdev->spans[st].alarms = ZT_ALARM_NONE;
-			zt_alarm_notify(&qoztmp->ztdev->spans[st]);
+			qoztmp->spans[st].alarms = ZT_ALARM_NONE;
+			zt_alarm_notify(&qoztmp->spans[st]);
 			qoztmp->leds[st] = 1;
 			if (qoztmp->stports == 8) {
-			    sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
+			    sprintf(qoztmp->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
 			} else {
-			    sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
+			    sprintf(qoztmp->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 ACTIVATED (F%d)",qoztmp->cardno ,st + 1,qoztmp->cardID, l1state);
 			}
 		    } else if (l1state == 8) {
 			/* lost framing */
@@ -863,22 +891,27 @@
 			    printk(KERN_INFO "qozap: starting t4 for span %d\n", st);
 			qoztmp->st[st].t4 = 0;
 		    } else {
+			qoztmp->st[st].l1up = 0;
 			if (qoztmp->stports == 8) {
-			    sprintf(ztqoz->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
+			    sprintf(qoztmp->spans[st].desc,"octoBRI PCI ISDN Card %d Span %d [TE] Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1, l1state);
 			} else {
-			    sprintf(ztqoz->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,ztqoz->card->cardID, l1state);
+			    sprintf(qoztmp->spans[st].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d) Layer 1 DEACTIVATED (F%d)",qoztmp->cardno ,st + 1,qoztmp->cardID, l1state);
 			}    
 		    }
 		}
 		
 	    }
 	}
+	qoz_resync(qoztmp);
+	spin_unlock_irqrestore(&(qoztmp->lock), flags);
     }
 
 
     // misc irq
     if (status & 0x40) {
-	irq_misc = qoz_inb(qoztmp,qoz_R_IRQ_MISC);
+	spin_lock_irqsave(&(qoztmp->lock), flags);
+	    irq_misc = qoz_inb(qoztmp,qoz_R_IRQ_MISC);
+	spin_unlock_irqrestore(&(qoztmp->lock), flags);
 	if (irq_misc & 0x2)  {
 	    // qozap timer
 	    qoztmp->ticks++;
@@ -902,12 +935,14 @@
 			    /* deactivate layer 1 */
 			    if (debug > 2)
 				printk(KERN_INFO "qozap: t3 timer expired for span %d\n", j);
-			    qoz_outb(qoztmp,qoz_R_ST_SEL, j);
-			    qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
-			    qoztmp->st[j].t3 = -1;
-			    qoztmp->ztdev->spans[j].alarms = ZT_ALARM_RED;
-			    zt_alarm_notify_no_master_change(&qoztmp->ztdev->spans[j]);
-			    qoz_waitbusy(qoztmp);
+			    spin_lock_irqsave(&(qoztmp->lock), flags);
+				qoz_outb(qoztmp,qoz_R_ST_SEL, j);
+				qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
+				qoz_waitbusy(qoztmp);
+				qoztmp->st[j].t3 = -1;
+				qoztmp->spans[j].alarms = ZT_ALARM_RED;
+			    spin_unlock_irqrestore(&(qoztmp->lock), flags);
+			    zt_alarm_notify_no_master_change(&qoztmp->spans[j]);
 			}
 		    }
 		    /* t4 */
@@ -919,12 +954,15 @@
 			    /* deactivate layer 1 */
 			    if (debug > 2)
 				printk(KERN_INFO "qozap: t4 timer expired for span %d\n", j);
-			    qoz_outb(qoztmp,qoz_R_ST_SEL, j);
-			    qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
-			    qoztmp->st[j].t4 = -1;
-			    qoztmp->ztdev->spans[j].alarms = ZT_ALARM_RED;
-			    zt_alarm_notify_no_master_change(&qoztmp->ztdev->spans[j]);
-			    qoz_waitbusy(qoztmp);
+			    spin_lock_irqsave(&(qoztmp->lock), flags);
+				qoz_outb(qoztmp,qoz_R_ST_SEL, j);
+				qoz_outb(qoztmp,qoz_A_ST_WR_STA, 0x40 );
+				qoztmp->st[j].t4 = -1;
+				qoztmp->st[st].l1up = 0;
+				qoztmp->spans[j].alarms = ZT_ALARM_RED;
+				qoz_waitbusy(qoztmp);
+			    spin_unlock_irqrestore(&(qoztmp->lock), flags);
+			    zt_alarm_notify_no_master_change(&qoztmp->spans[j]);
 			}
 		    }
 		}
@@ -934,8 +972,10 @@
 	//    printk(KERN_INFO "qozap proc/nonproc irq\n");
 	}
     }
+
     if (status & 0x80) {
 	/* fifo irq */
+	spin_lock_irqsave(&(qoztmp->lock), flags);
 	irq_foview = qoz_inb(qoztmp,qoz_R_IRQ_OVIEW);
         if (qoztmp->type == 0xb552) {
 	    if (irq_foview & 0x60) {
@@ -990,13 +1030,9 @@
 		}
 	    }
 	}
+	spin_unlock_irqrestore(&(qoztmp->lock), flags);
     }
     
-#ifdef RELAXED_LOCKING
-    spin_unlock(&(qoztmp->lock));
-#else
-    spin_unlock_irqrestore(&(qoztmp->lock), flags);
-#endif
 #ifdef LINUX26
 	return IRQ_RETVAL(1);
 #endif		
@@ -1035,8 +1071,7 @@
 }
 
 static int ztqoz_startup(struct zt_span *span) {
-    struct zt_qoz *qozt = span->pvt;
-    struct qoz_card *qoztmp = qozt->card;
+    struct qoz_card *qoztmp = span->pvt;
     unsigned long flags;
     int alreadyrunning;
     int i=0;
@@ -1063,7 +1098,7 @@
 	/* setup D channel buffer */
     	memset(qoztmp->dtxbuf[span->offset],0x0,sizeof(qoztmp->dtxbuf[span->offset]));
 	span->chans[2].writechunk = qoztmp->dtxbuf[span->offset];
-	qoztmp->ztdev->chans[span->offset][2].maxbytes2transmit = sizeof(qoztmp->dtxbuf[span->offset]);
+	qoztmp->chans[span->offset][2].maxbytes2transmit = sizeof(qoztmp->dtxbuf[span->offset]);
 
 	memset(qoztmp->drxbuf[span->offset],0x0,sizeof(qoztmp->drxbuf[span->offset]));
     	span->chans[2].readchunk = qoztmp->drxbuf[span->offset];
@@ -1171,7 +1206,6 @@
     } else {
 	qoz_outb(qoztmp,qoz_A_ST_WR_STA,0x0); 
     }
-    spin_unlock_irqrestore(&qoztmp->lock,flags);
 
 
     qoz_outb(qoztmp,qoz_R_ST_SEL,span->offset);
@@ -1183,12 +1217,14 @@
 
     /* enable irqs */
     qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 8 | 1); 
+
+    spin_unlock_irqrestore(&qoztmp->lock,flags);
     return 0;
 }
 
 static int ztqoz_shutdown(struct zt_span *span) {
-    struct zt_qoz *ztqoz = span->pvt;
-    struct qoz_card *qoztmp = ztqoz->card;
+    unsigned long flags;
+    struct qoz_card *qoztmp = span->pvt;
     int alreadyrunning;
     int offset = 0;
     
@@ -1206,6 +1242,7 @@
 
 //    printk(KERN_CRIT "qozap: stopping card %d port %d.\n",qoztmp->cardno, span->offset + 1);
 
+    spin_lock_irqsave(&qoztmp->lock,flags);
     // turn off irqs for all fifos
     if (qoztmp->type == 0xb552) {
 	offset = 24;
@@ -1260,6 +1297,7 @@
     }
 
 
+    spin_unlock_irqrestore(&qoztmp->lock,flags);
 //    printk(KERN_CRIT "qozap: card %d span %d/%d down.\n",qoztmp->cardno,span->spanno,span->offset);
     return 0;
 }
@@ -1274,67 +1312,69 @@
 }
 
 static int ztqoz_spanconfig(struct zt_span *span,struct zt_lineconfig *lc) {
-//    span->lineconfig = lc->lineconfig;
+    struct qoz_card *qoztmp = span->pvt;
+    span->lineconfig = lc->lineconfig;
+    qoztmp->st_sync[span->offset] = lc->sync;
+    qoztmp->syncsrc = -1;
     return 0;
 }
 
-static int ztqoz_initialize(struct zt_qoz *ztqoz) {
-    struct qoz_card *qoztmp = ztqoz->card;
+static int ztqoz_initialize(struct qoz_card *qoztmp) {
     int i=0,s=0;
     
-    for (s=0; s < ztqoz->card->stports; s++) {
-	memset(&ztqoz->spans[s],0,sizeof(struct zt_span)); // you never can tell...
-	sprintf(ztqoz->spans[s].name,"ztqoz/%d/%d",qoz_dev_count + 1,s + 1);
-	if (ztqoz->card->stports == 8) {
+    for (s=0; s < qoztmp->stports; s++) {
+	memset(&qoztmp->spans[s],0,sizeof(struct zt_span));
+	sprintf(qoztmp->spans[s].name,"ztqoz/%d/%d",qoz_dev_count + 1,s + 1);
+	if (qoztmp->stports == 8) {
 	    if (qoztmp->st[s].nt_mode == 1){
-		sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
+		sprintf(qoztmp->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
 	    } else {
-		sprintf(ztqoz->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
+		sprintf(qoztmp->spans[s].desc,"octoBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
 	    }
 	} else {
-	    if (ztqoz->card->cardID < 0xff) {
+	    if (qoztmp->cardID < 0xff) {
 		if (qoztmp->st[s].nt_mode == 1){
-		    sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
+		    sprintf(qoztmp->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT] (cardID %d)",qoztmp->cardno,s + 1,qoztmp->cardID);
 		} else {
-		    sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d)",qoztmp->cardno,s + 1,ztqoz->card->cardID);
+		    sprintf(qoztmp->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE] (cardID %d)",qoztmp->cardno,s + 1,qoztmp->cardID);
 		}
 	    } else {
 		if (qoztmp->st[s].nt_mode == 1){
-		    sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
+		    sprintf(qoztmp->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [NT]",qoztmp->cardno,s + 1);
 		} else {
-		    sprintf(ztqoz->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
+		    sprintf(qoztmp->spans[s].desc,"quadBRI PCI ISDN Card %d Span %d [TE]",qoztmp->cardno,s + 1);
 		}
 	    }
 	}
 
-        ztqoz->spans[s].spanconfig = ztqoz_spanconfig;
-        ztqoz->spans[s].chanconfig = ztqoz_chanconfig;
-        ztqoz->spans[s].startup = ztqoz_startup;
-        ztqoz->spans[s].shutdown = ztqoz_shutdown;
-        ztqoz->spans[s].maint = ztqoz_maint;
-        ztqoz->spans[s].rbsbits = ztqoz_rbsbits;
-        ztqoz->spans[s].open = ztqoz_open;
-        ztqoz->spans[s].close = ztqoz_close;
-        ztqoz->spans[s].ioctl = ztqoz_ioctl;
-	ztqoz->spans[s].dacs = ztqoz_dacs;
+        qoztmp->spans[s].spanconfig = ztqoz_spanconfig;
+        qoztmp->spans[s].chanconfig = ztqoz_chanconfig;
+        qoztmp->spans[s].startup = ztqoz_startup;
+        qoztmp->spans[s].shutdown = ztqoz_shutdown;
+        qoztmp->spans[s].maint = ztqoz_maint;
+        qoztmp->spans[s].rbsbits = ztqoz_rbsbits;
+        qoztmp->spans[s].open = ztqoz_open;
+        qoztmp->spans[s].close = ztqoz_close;
+        qoztmp->spans[s].ioctl = ztqoz_ioctl;
+	qoztmp->spans[s].dacs = ztqoz_dacs;
 
-        ztqoz->spans[s].chans = ztqoz->chans[s];
-        ztqoz->spans[s].channels = 3;
-        ztqoz->spans[s].deflaw = ZT_LAW_ALAW;
-        ztqoz->spans[s].linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
-        init_waitqueue_head(&ztqoz->spans[s].maintq);
-        ztqoz->spans[s].pvt = ztqoz;
-        ztqoz->spans[s].offset = s;
+        qoztmp->spans[s].chans = qoztmp->chans[s];
+        qoztmp->spans[s].channels = 3;
+        qoztmp->spans[s].deflaw = ZT_LAW_ALAW;
+        qoztmp->spans[s].linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS;
+        init_waitqueue_head(&qoztmp->spans[s].maintq);
+        qoztmp->spans[s].pvt = qoztmp;
+        qoztmp->spans[s].offset = s;
 
-	for (i=0; i < ztqoz->spans[s].channels; i++) {
-	    memset(&(ztqoz->chans[s][i]),0x0,sizeof(struct zt_chan));
-	    sprintf(ztqoz->chans[s][i].name,"ztqoz%d/%d/%d",qoz_dev_count + 1,s + 1,i + 1);
-	    ztqoz->chans[s][i].pvt = ztqoz;
-	    ztqoz->chans[s][i].sigcap =  ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
-	    ztqoz->chans[s][i].chanpos = i + 1; 
+	for (i=0; i < qoztmp->spans[s].channels; i++) {
+	    memset(&(qoztmp->chans[s][i]),0x0,sizeof(struct zt_chan));
+	    sprintf(qoztmp->chans[s][i].name,"ztqoz%d/%d/%d",qoz_dev_count + 1,s + 1,i + 1);
+	    qoztmp->chans[s][i].pvt = qoztmp;
+	    qoztmp->chans[s][i].sigcap =  ZT_SIG_EM | ZT_SIG_CLEAR | ZT_SIG_FXSLS | ZT_SIG_FXSGS | ZT_SIG_FXSKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS | ZT_SIG_SF;
+	    qoztmp->chans[s][i].chanpos = i + 1; 
 	}
 
-	if (zt_register(&ztqoz->spans[s],0)) {
+	if (zt_register(&qoztmp->spans[s],0)) {
 	    printk(KERN_INFO "qozap: unable to register zaptel span %d!\n",s+1);
 	    return -1;
 	}
@@ -1347,7 +1387,6 @@
 int qoz_findCards(unsigned int pcidid) {
     struct pci_dev *tmp;
     struct qoz_card *qoztmp = NULL;
-    struct zt_qoz *ztqoz = NULL;
     int i=0;
     unsigned char dips=0;
     int cid=0;
@@ -1425,16 +1464,6 @@
 	// disable ints
 	qoz_outb(qoztmp,qoz_R_IRQ_CTRL, 0); 
 
-	ztqoz = kmalloc(sizeof(struct zt_qoz),GFP_KERNEL);
-	if (!ztqoz) {
-	    printk(KERN_INFO "qozap: unable to kmalloc!\n");
-	    qoz_shutdownCard(qoztmp);
-	    kfree(qoztmp);
-	    multi_qoz = NULL;
-	    return -ENOMEM;
-	}
-	memset(ztqoz, 0x0, sizeof(struct zt_qoz));
-
 	if (pcidid == PCI_DEVICE_ID_CCD_M) {
 	    qoztmp->stports = 8;
 	} else {
@@ -1539,6 +1568,7 @@
 
 	printk(KERN_INFO "qozap: S/T ports: %d [",qoztmp->stports);
 	for (i=0;i<qoztmp->stports;i++) {
+	    qoztmp->st_sync[i] = 0;
 	    if ((modes & (1 << i)) != 0) {
 	        qoztmp->st[i].nt_mode = 1;
 	        printk(" NT");
@@ -1549,9 +1579,6 @@
 	}
 	printk(" ]\n");
 	
-	ztqoz->card = qoztmp;
-	qoztmp->ztdev = ztqoz;
-
 	qoz_registerCard(qoztmp);
 	tmp = pci_find_device(PCI_VENDOR_ID_CCD,pcidid,multi_qoz);
     }
@@ -1601,7 +1628,7 @@
     struct qoz_card *tmpcard;
     tmpcard = qoz_dev_list;
     while (tmpcard != NULL) {
-	ztqoz_initialize(tmpcard->ztdev);
+	ztqoz_initialize(tmpcard);
 	qoz_resetCard(tmpcard);
 	tmpcard = tmpcard->next;
     }
@@ -1653,12 +1680,14 @@
 module_param(pcmslave, int, 0600);
 module_param(bloop, int, 0600);
 module_param(debug, int, 0600);
+module_param(dacs, int, 0600);
 #else
 MODULE_PARM(doubleclock,"i");
 MODULE_PARM(ports,"i");
 MODULE_PARM(pcmslave,"i");
 MODULE_PARM(bloop,"i");
 MODULE_PARM(debug,"i");
+MODULE_PARM(dacs,"i");
 #endif
 
 

Modified: zaptel/trunk/qozap/qozap.h
===================================================================
--- zaptel/trunk/qozap/qozap.h	2006-12-15 03:43:08 UTC (rev 2821)
+++ zaptel/trunk/qozap/qozap.h	2006-12-15 14:12:56 UTC (rev 2822)
@@ -10,6 +10,7 @@
     unsigned char drx;
     int t3;
     int t4;
+    int l1up;
     unsigned char layer1state;
 } qoz_span;
 
@@ -38,10 +39,13 @@
     void *pci_io_phys;
     unsigned long ioport;
     struct qoz_span st[qoz_SPANS];
+    int st_sync[qoz_SPANS];
+    int syncsrc;
     unsigned int pcibus;
     unsigned int pcidevfn;
     struct pci_dev *pcidev;
-    struct zt_qoz *ztdev;
+    struct zt_span spans[qoz_SPANS];
+    struct zt_chan chans[qoz_SPANS][3];
     unsigned char rxbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
     unsigned char txbuf[qoz_SPANS][2][ZT_CHUNKSIZE];
     unsigned char drxbuf[qoz_SPANS][qoz_DFIFO_SIZE4];
@@ -56,13 +60,6 @@
 } qoz_card;
 
 
-typedef struct zt_qoz {
-    unsigned int usecount;
-    struct zt_span spans[qoz_SPANS];
-    struct zt_chan chans[qoz_SPANS][3];
-    struct qoz_card *card;
-} zt_qoz;
-
 #define qoz_outb_io(a,b,c) \
     outw((b), ((a)->ioport+4)); \
     outb((c), ((a)->ioport));




More information about the Pkg-voip-commits mailing list