From acd467a174669dff9e804c7f7eb66f98326ed6fc Mon Sep 17 00:00:00 2001 From: markster Date: Sun, 30 Jun 2002 01:29:54 +0000 Subject: Version 0.2.0 from FTP git-svn-id: http://svn.digium.com/svn/zaptel/trunk@90 5390a7c7-147a-4af0-8ec9-7488f05a26cb --- tor2.c | 106 ++++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 37 deletions(-) (limited to 'tor2.c') diff --git a/tor2.c b/tor2.c index de55c00..fbe7c37 100755 --- a/tor2.c +++ b/tor2.c @@ -50,7 +50,7 @@ * tasklets. */ -#define ENABLE_TASKLETS +/* #define ENABLE_TASKLETS */ #define MAX_SPANS 16 @@ -273,7 +273,7 @@ static void init_spans(struct tor2 *tor) struct zt_chan *mychans = tor->chans[x] + y; sprintf(mychans->name, "Tor2/%d/%d/%d", tor->num, x + 1, y + 1); mychans->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_FXOLS | ZT_SIG_FXOGS | ZT_SIG_FXOKS | ZT_SIG_CAS; c = (x * tor->spans[x].channels) + y; mychans->pvt = &tor->tchans[c]; mychans->chanpos = y + 1; @@ -288,7 +288,8 @@ static int __devinit tor2_probe(struct pci_dev *pdev, const struct pci_device_id int res,x; struct tor2 *tor; unsigned long endjif; - volatile unsigned long *gpioc_data; + volatile unsigned long *gpdata_io; + unsigned long gpdata; res = pci_enable_device(pdev); if (res) @@ -367,44 +368,67 @@ static int __devinit tor2_probe(struct pci_dev *pdev, const struct pci_device_id } tor->num = x; cards[x] = tor; + /* start programming mode */ - gpioc_data = (unsigned long *)&tor->plx[GPIOC]; - *gpioc_data |= GPIO_WRITE; /* make sure WRITE is not asserted */ - *gpioc_data &= ~GPIO_PROGRAM; /* activate the PROGRAM signal */ + gpdata_io = (unsigned long *)&tor->plx[GPIOC]; + gpdata = le32_to_cpu(*gpdata_io); + + gpdata |= GPIO_WRITE; /* make sure WRITE is not asserted */ + *gpdata_io = cpu_to_le32(gpdata); + + gpdata &= ~GPIO_PROGRAM; /* activate the PROGRAM signal */ + *gpdata_io = cpu_to_le32(gpdata); + /* wait for INIT and DONE to go low */ - while (*gpioc_data & (GPIO_INIT | GPIO_DONE)); + endjif = jiffies + 10; + while (le32_to_cpu(*gpdata_io) & (GPIO_INIT | GPIO_DONE) && (jiffies <= endjif)); + + if (endjif < jiffies) { + printk("Timeout waiting for INIT and DONE to go low\n"); + goto err_out_release_all; + } if (debug) printk("fwload: Init and done gone to low\n"); - *gpioc_data |= GPIO_PROGRAM; /* de-activate the PROGRAM signal */ + gpdata |= GPIO_PROGRAM; + *gpdata_io = cpu_to_le32(gpdata); /* de-activate the PROGRAM signal */ /* wait for INIT to go high (clearing done */ - while (!(*gpioc_data & GPIO_INIT)); + endjif = jiffies + 10; + while (!(le32_to_cpu(*gpdata_io) & GPIO_INIT) && (jiffies <= endjif)); + if (endjif < jiffies) { + printk("Timeout waiting for INIT to go high\n"); + goto err_out_release_all; + } + if (debug) printk("fwload: Init went high (clearing done)\nNow loading...\n"); /* assert WRITE signal */ - *gpioc_data &= ~GPIO_WRITE; + gpdata &= ~GPIO_WRITE; + *gpdata_io = cpu_to_le32(gpdata); for(x = 0; x < sizeof(tor2fw); x++) { /* write the byte */ *tor->mem8 = tor2fw[x]; /* if DONE signal, we're done, exit */ - if (*gpioc_data & GPIO_DONE) break; + if (le32_to_cpu(*gpdata_io) & GPIO_DONE) break; /* if INIT drops, we're screwed, exit */ - if (!(*gpioc_data & GPIO_INIT)) break; + if (!(le32_to_cpu(*gpdata_io) & GPIO_INIT)) break; } if (debug) printk("fwload: Transferred %d bytes into chip\n",x); /* Wait for FIFO to clear */ endjif = jiffies + 2; while(jiffies < endjif); /* wait */ /* de-assert write signal */ - *gpioc_data |= GPIO_WRITE; + gpdata |= GPIO_WRITE; + *gpdata_io = cpu_to_le32(gpdata); if (debug) printk("fwload: Loading done!\n"); + /* Wait for FIFO to clear */ endjif = jiffies + 2; while(jiffies < endjif); /* wait */ - if (!(*gpioc_data & GPIO_INIT)) + if (!(le32_to_cpu(*gpdata_io) & GPIO_INIT)) { printk("Drove Init low!! CRC Error!!!\n"); goto err_out_release_all; } - if (!(*gpioc_data & GPIO_DONE)) + if (!(le32_to_cpu(*gpdata_io) & GPIO_DONE)) { printk("Did not get DONE signal. Short file maybe??\n"); goto err_out_release_all; @@ -454,7 +478,7 @@ static int __devinit tor2_probe(struct pci_dev *pdev, const struct pci_device_id zt_unregister(&tor->spans[2]); goto err_out_release_all; } - tor->plx[INTCSR] = PLX_INTENA; /* enable PLX interrupt */ + tor->plx[INTCSR] = cpu_to_le16(PLX_INTENA); /* enable PLX interrupt */ #ifdef ENABLE_TASKLETS tasklet_init(&tor->tor2_tlet, tor2_tasklet, (unsigned long)tor); #endif @@ -488,7 +512,7 @@ static void __devexit tor2_remove(struct pci_dev *pdev) tor->mem8[SYNCREG] = 0; tor->mem8[CTLREG] = 0; tor->mem8[LEDREG] = 0; - tor->plx[INTCSR] = 0; + tor->plx[INTCSR] = cpu_to_le16(0); free_irq(tor->irq, tor); if (tor->spans[0].flags & ZT_FLAG_REGISTERED) zt_unregister(&tor->spans[0]); @@ -507,7 +531,9 @@ static void __devexit tor2_remove(struct pci_dev *pdev) cards[tor->num] = 0; pci_set_drvdata(pdev, NULL); - for(x = 0; x < 3; x++) kfree(tor->chans[x]); + for(x = 0; x < 3; x++) + if (tor->chans[x]) + kfree(tor->chans[x]); kfree(tor); } @@ -906,22 +932,34 @@ static int tor2_maint(struct zt_span *span, int cmd) return 0; } +static inline void tor2_run(struct tor2 *tor) +{ + int x,y; + for (x=0;x<4;x++) { + if (tor->spans[x].flags & ZT_FLAG_RUNNING) { + for (y=0;yspans[x].channels;y++) { + /* XXX Technically, we're wasting 8 taps of echo canceller + because we're cancelling against something that won't be sent + until the next chunk XXX */ + zt_ec_chunk(&tor->spans[x].chans[y], tor->spans[x].chans[y].readchunk, tor->spans[x].chans[y].writechunk); + } + zt_receive(&tor->spans[x]); + } + } + for (x=0;x<4;x++) { + if (tor->spans[x].flags & ZT_FLAG_RUNNING) + zt_transmit(&tor->spans[x]); + } +} + #ifdef ENABLE_TASKLETS static void tor2_tasklet(unsigned long data) { struct tor2 *tor = (struct tor2 *)data; - int x; tor->taskletrun++; if (tor->taskletpending) { tor->taskletexec++; - for (x=0;x<4;x++) { - if (tor->spans[x].flags & ZT_FLAG_RUNNING) - zt_receive(&tor->spans[x]); - } - for (x=0;x<4;x++) { - if (tor->spans[x].flags & ZT_FLAG_RUNNING) - zt_transmit(&tor->spans[x]); - } + tor2_run(tor); } tor->taskletpending = 0; } @@ -931,6 +969,7 @@ static void tor2_intr(int irq, void *dev_id, struct pt_regs *regs) { int n, i, j, k, syncsrc; unsigned long rxword,txword; + unsigned char c, rxc; unsigned char abits, bbits; struct tor2 *tor = (struct tor2 *) dev_id; @@ -965,7 +1004,7 @@ static void tor2_intr(int irq, void *dev_id, struct pt_regs *regs) /* span 4 */ txword |= tor->spans[3].chans[n].writechunk[i]; /* write to part */ - tor->mem32[tor->datxlt[n] + (32 * i)] = txword; + tor->mem32[tor->datxlt[n] + (32 * i)] = cpu_to_le32(txword); } } @@ -973,7 +1012,7 @@ static void tor2_intr(int irq, void *dev_id, struct pt_regs *regs) for(n = 0; n < tor->spans[0].channels; n++) { for(i = 0; i < ZT_CHUNKSIZE; i++) { /* read from */ - rxword = tor->mem32[tor->datxlt[n] + (32 * i)]; + rxword = le32_to_cpu(tor->mem32[tor->datxlt[n] + (32 * i)]); /* span 1 */ tor->spans[0].chans[n].readchunk[i] = rxword >> 24; /* span 2 */ @@ -1197,14 +1236,7 @@ static void tor2_intr(int irq, void *dev_id, struct pt_regs *regs) tor->txerrors++; } #else - for (i=0;i<4;i++) { - if (tor->spans[i].flags & ZT_FLAG_RUNNING) - zt_receive(&tor->spans[i]); - } - for (i=0;i<4;i++) { - if (tor->spans[i].flags & ZT_FLAG_RUNNING) - zt_transmit(&tor->spans[i]); - } + tor2_run(tor); #endif if (tor->cardtype == TYPE_E1) -- cgit v1.2.3