1 --- a/drivers/dahdi/Kbuild
2 +++ b/drivers/dahdi/Kbuild
3 @@ -13,6 +13,7 @@ obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCT
4 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCTDM24XXP) += wctdm24xxp/
5 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCTE12XP) += wcte12xp/
6 obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_WCTE13XP) += wcte13xp.o
7 +obj-$(DAHDI_BUILD_ALL)$(CONFIG_DAHDI_HFCS) += hfcs/
9 wcte13xp-objs := wcte13xp-base.o wcxb_spi.o wcxb.o wcxb_flash.o
10 CFLAGS_wcte13xp-base.o += -I$(src)/oct612x -I$(src)/oct612x/include -I$(src)/oct612x/octdeviceapi -I$(src)/oct612x/octdeviceapi/oct6100api
11 --- a/drivers/dahdi/Kconfig
12 +++ b/drivers/dahdi/Kconfig
13 @@ -291,4 +291,14 @@ config DAHDI_WCTE11XP
18 + tristate "Support for various HFC-S PCI BRI adapters"
19 + depends on DAHDI && PCI
22 + To compile this driver as a module, choose M here: the
23 + module will be called dahdi_hfcs.
27 source "drivers/dahdi/xpp/Kconfig"
29 +++ b/drivers/dahdi/hfcs/base.c
32 + * dahdi_hfcs.c - Dahdi driver for HFC-S PCI A based ISDN BRI cards
34 + * Dahdi rewrite in hardhdlc mode
35 + * Jose A. Deniz <odicha@hotmail.com>
37 + * Copyright (C) 2011, Raoul Bönisch
38 + * Copyright (C) 2009, Jose A. Deniz
39 + * Copyright (C) 2006, headissue GmbH; Jens Wilke
40 + * Copyright (C) 2004 Daniele Orlandi
41 + * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
43 + * Jens Wilke <jw_vzaphfc@headissue.com>
45 + * Original author of this code is
46 + * Daniele "Vihai" Orlandi <daniele@orlandi.com>
48 + * Major rewrite of the driver made by
49 + * Klaus-Peter Junghanns <kpj@junghanns.net>
51 + * This program is free software and may be modified and
52 + * distributed under the terms of the GNU Public License.
54 + * Please read the README file for important infos.
57 +#include <linux/spinlock.h>
58 +#include <linux/init.h>
59 +#include <linux/pci.h>
60 +#include <linux/interrupt.h>
61 +#include <linux/module.h>
62 +#include <linux/moduleparam.h>
63 +#include <linux/version.h>
64 +#include <linux/kernel.h>
65 +#include <linux/delay.h>
66 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
67 +#include <linux/sched.h>
69 +#include <linux/proc_fs.h>
70 +#include <linux/if_arp.h>
72 +#include <dahdi/kernel.h>
74 +#include "dahdi_hfcs.h"
91 +static int nt_modes[hfc_MAX_BOARDS];
92 +static int nt_modes_count;
93 +static int force_l1_up;
94 +static struct proc_dir_entry *hfc_proc_dahdi_hfcs_dir;
105 +#define TRUE (!FALSE)
108 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
109 +#define SET_PROC_DIRENTRY_OWNER(p) do { (p)->owner = THIS_MODULE; } while(0);
111 +#define SET_PROC_DIRENTRY_OWNER(p) do { } while(0);
114 +static DEFINE_PCI_DEVICE_TABLE(hfc_pci_ids) = {
115 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0,
116 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
117 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000,
118 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
119 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006,
120 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
121 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007,
122 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
123 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008,
124 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
125 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009,
126 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
127 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A,
128 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
129 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B,
130 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
131 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C,
132 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
133 + {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100,
134 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
135 + {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1,
136 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
137 + {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675,
138 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
139 + {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT,
140 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
141 + {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T,
142 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
143 + {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575,
144 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
145 + {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0,
146 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
147 + {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,
148 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
149 + {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,
150 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
151 + {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,
152 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
153 + {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,
154 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
155 + {PCI_VENDOR_ID_SITECOM, PCI_DEVICE_ID_SITECOM_3069,
156 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
160 +MODULE_DEVICE_TABLE(pci, hfc_pci_ids);
162 +static int __devinit hfc_probe(struct pci_dev *dev
163 + , const struct pci_device_id *ent);
164 +static void __devexit hfc_remove(struct pci_dev *dev);
166 +static struct pci_driver hfc_driver = {
167 + .name = hfc_DRIVER_NAME,
168 + .id_table = hfc_pci_ids,
169 + .probe = hfc_probe,
170 + .remove = __devexit_p(hfc_remove),
173 +/******************************************
175 + ******************************************/
177 +static void hfc_softreset(struct hfc_card *card)
179 + printk(KERN_INFO hfc_DRIVER_PREFIX
185 + * Softreset procedure. Put it on, wait and off again
187 + hfc_outb(card, hfc_CIRM, hfc_CIRM_RESET);
189 + hfc_outb(card, hfc_CIRM, 0);
191 + set_current_state(TASK_UNINTERRUPTIBLE);
192 + schedule_timeout((hfc_RESET_DELAY * HZ) / 1000);
195 +static void hfc_resetCard(struct hfc_card *card)
198 + hfc_outb(card, hfc_INT_M1, card->regs.m1);
201 + hfc_outb(card, hfc_INT_M2, card->regs.m2);
203 + hfc_softreset(card);
205 + card->regs.trm = 0;
206 + hfc_outb(card, hfc_TRM, card->regs.trm);
209 + * Select the non-capacitive line mode for the S/T interface
211 + card->regs.sctrl = hfc_SCTRL_NONE_CAP;
213 + if (card->nt_mode) {
215 + * ST-Bit delay for NT-Mode
217 + hfc_outb(card, hfc_CLKDEL, hfc_CLKDEL_NT);
219 + card->regs.sctrl |= hfc_SCTRL_MODE_NT;
222 + * ST-Bit delay for TE-Mode
224 + hfc_outb(card, hfc_CLKDEL, hfc_CLKDEL_TE);
226 + card->regs.sctrl |= hfc_SCTRL_MODE_TE;
229 + hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
234 + card->regs.sctrl_e = hfc_SCTRL_E_AUTO_AWAKE;
235 + hfc_outb(card, hfc_SCTRL_E, card->regs.sctrl_e);
238 + * No B-channel enabled at startup
240 + card->regs.sctrl_r = 0;
241 + hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
246 + hfc_outb(card, hfc_MST_MODE, hfc_MST_MODE_MASTER);
249 + * Connect internal blocks
251 + card->regs.connect =
252 + hfc_CONNECT_B1_HFC_from_ST |
253 + hfc_CONNECT_B1_ST_from_HFC |
254 + hfc_CONNECT_B1_GCI_from_HFC |
255 + hfc_CONNECT_B2_HFC_from_ST |
256 + hfc_CONNECT_B2_ST_from_HFC |
257 + hfc_CONNECT_B2_GCI_from_HFC;
258 + hfc_outb(card, hfc_CONNECT, card->regs.connect);
261 + * All bchans are HDLC by default, not useful, actually
262 + * since mode is set during open()
264 + hfc_outb(card, hfc_CTMT, 0);
269 + hfc_outb(card, hfc_CIRM, 0);
272 + * Enable D-rx FIFO. At least one FIFO must be enabled (by specs)
274 + card->regs.fifo_en = hfc_FIFOEN_DRX;
275 + hfc_outb(card, hfc_FIFO_EN, card->regs.fifo_en);
277 + card->late_irqs = 0;
280 + * Clear already pending ints
282 + hfc_inb(card, hfc_INT_S1);
283 + hfc_inb(card, hfc_INT_S2);
286 + * Enable IRQ output
288 + card->regs.m1 = hfc_INTS_DREC | hfc_INTS_L1STATE | hfc_INTS_TIMER;
289 + hfc_outb(card, hfc_INT_M1, card->regs.m1);
291 + card->regs.m2 = hfc_M2_IRQ_ENABLE;
292 + hfc_outb(card, hfc_INT_M2, card->regs.m2);
295 + * Unlocks the states machine
297 + hfc_outb(card, hfc_STATES, 0);
300 + * There's no need to explicitly activate L1 now.
301 + * Activation is managed inside the interrupt routine.
305 +static void hfc_update_fifo_state(struct hfc_card *card)
308 + * I'm not sure if irqsave is needed but there could be a race
309 + * condition since hfc_update_fifo_state could be called from
310 + * both the IRQ handler and the *_(open|close) functions
313 + unsigned long flags;
314 + spin_lock_irqsave(&card->chans[B1].lock, flags);
315 + if (!card->fifo_suspended &&
316 + (card->chans[B1].status == open_framed ||
317 + card->chans[B1].status == open_voice)) {
319 + if (!(card->regs.fifo_en & hfc_FIFOEN_B1RX)) {
320 + card->regs.fifo_en |= hfc_FIFOEN_B1RX;
321 + hfc_clear_fifo_rx(&card->chans[B1].rx);
324 + if (!(card->regs.fifo_en & hfc_FIFOEN_B1TX)) {
325 + card->regs.fifo_en |= hfc_FIFOEN_B1TX;
326 + hfc_clear_fifo_tx(&card->chans[B1].tx);
329 + if (card->regs.fifo_en & hfc_FIFOEN_B1RX)
330 + card->regs.fifo_en &= ~hfc_FIFOEN_B1RX;
331 + if (card->regs.fifo_en & hfc_FIFOEN_B1TX)
332 + card->regs.fifo_en &= ~hfc_FIFOEN_B1TX;
334 + spin_unlock_irqrestore(&card->chans[B1].lock, flags);
336 + spin_lock_irqsave(&card->chans[B2].lock, flags);
337 + if (!card->fifo_suspended &&
338 + (card->chans[B2].status == open_framed ||
339 + card->chans[B2].status == open_voice ||
340 + card->chans[B2].status == sniff_aux)) {
342 + if (!(card->regs.fifo_en & hfc_FIFOEN_B2RX)) {
343 + card->regs.fifo_en |= hfc_FIFOEN_B2RX;
344 + hfc_clear_fifo_rx(&card->chans[B2].rx);
347 + if (!(card->regs.fifo_en & hfc_FIFOEN_B2TX)) {
348 + card->regs.fifo_en |= hfc_FIFOEN_B2TX;
349 + hfc_clear_fifo_tx(&card->chans[B2].tx);
352 + if (card->regs.fifo_en & hfc_FIFOEN_B2RX)
353 + card->regs.fifo_en &= ~hfc_FIFOEN_B2RX;
354 + if (card->regs.fifo_en & hfc_FIFOEN_B2TX)
355 + card->regs.fifo_en &= ~hfc_FIFOEN_B2TX;
357 + spin_unlock_irqrestore(&card->chans[B2].lock, flags);
359 + spin_lock_irqsave(&card->chans[D].lock, flags);
360 + if (!card->fifo_suspended &&
361 + card->chans[D].status == open_framed) {
363 + if (!(card->regs.fifo_en & hfc_FIFOEN_DTX)) {
364 + card->regs.fifo_en |= hfc_FIFOEN_DTX;
366 + card->chans[D].tx.ugly_framebuf_size = 0;
367 + card->chans[D].tx.ugly_framebuf_off = 0;
370 + if (card->regs.fifo_en & hfc_FIFOEN_DTX)
371 + card->regs.fifo_en &= ~hfc_FIFOEN_DTX;
373 + spin_unlock_irqrestore(&card->chans[D].lock, flags);
375 + hfc_outb(card, hfc_FIFO_EN, card->regs.fifo_en);
378 +static inline void hfc_suspend_fifo(struct hfc_card *card)
380 + card->fifo_suspended = TRUE;
382 + hfc_update_fifo_state(card);
385 + * When L1 goes down D rx receives garbage; it is nice to
386 + * clear it to avoid a CRC error on reactivation
387 + * udelay is needed because the FIFO deactivation happens
391 + hfc_clear_fifo_rx(&card->chans[D].rx);
394 + if (debug_level >= 3) {
395 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
397 + "FIFOs suspended\n",
403 +static inline void hfc_resume_fifo(struct hfc_card *card)
405 + card->fifo_suspended = FALSE;
407 + hfc_update_fifo_state(card);
410 + if (debug_level >= 3) {
411 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
419 +static void hfc_check_l1_up(struct hfc_card *card)
421 + if ((!card->nt_mode && card->l1_state != 7)
422 + || (card->nt_mode && card->l1_state != 3)) {
424 + hfc_outb(card, hfc_STATES, hfc_STATES_DO_ACTION |
425 + hfc_STATES_ACTIVATE|
426 + hfc_STATES_NT_G2_G3);
429 + * 0 because this is quite verbose when an inferface is unconnected, jaw
432 + if (debug_level >= 1) {
433 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
435 + "L1 is down, bringing up L1.\n",
443 +/*******************
444 + * Dahdi interface *
445 + *******************/
447 +static int hfc_dahdi_open(struct dahdi_chan *dahdi_chan)
449 + struct hfc_chan_duplex *chan = dahdi_chan->pvt;
450 + struct hfc_card *card = chan->card;
452 + spin_lock(&chan->lock);
454 + switch (chan->number) {
456 + if (chan->status != free &&
457 + chan->status != open_framed) {
458 + spin_unlock(&chan->lock);
461 + chan->status = open_framed;
466 + if (chan->status != free) {
467 + spin_unlock(&chan->lock);
470 + chan->status = open_voice;
474 + chan->open_by_dahdi = TRUE;
475 + try_module_get(THIS_MODULE);
476 + spin_unlock(&chan->lock);
478 + switch (chan->number) {
483 + card->regs.m2 |= hfc_M2_PROC_TRANS;
485 + * Enable transparent mode
487 + card->regs.ctmt |= hfc_CTMT_TRANSB1;
489 + * Reversed bit order
491 + card->regs.cirm |= hfc_CIRM_B1_REV;
493 + * Enable transmission
495 + card->regs.sctrl |= hfc_SCTRL_B1_ENA;
499 + card->regs.sctrl_r |= hfc_SCTRL_R_B1_ENA;
503 + card->regs.m2 |= hfc_M2_PROC_TRANS;
504 + card->regs.ctmt |= hfc_CTMT_TRANSB2;
505 + card->regs.cirm |= hfc_CIRM_B2_REV;
506 + card->regs.sctrl |= hfc_SCTRL_B2_ENA;
507 + card->regs.sctrl_r |= hfc_SCTRL_R_B2_ENA;
513 + * If not already enabled, enable processing transition (8KHz)
516 + hfc_outb(card, hfc_INT_M2, card->regs.m2);
517 + hfc_outb(card, hfc_CTMT, card->regs.ctmt);
518 + hfc_outb(card, hfc_CIRM, card->regs.cirm);
519 + hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
520 + hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
522 + hfc_update_fifo_state(card);
524 + printk(KERN_INFO hfc_DRIVER_PREFIX
526 + "chan %s opened as %s.\n",
534 +static int hfc_dahdi_close(struct dahdi_chan *dahdi_chan)
536 + struct hfc_chan_duplex *chan = dahdi_chan->pvt;
537 + struct hfc_card *card = chan->card;
540 + printk(KERN_CRIT hfc_DRIVER_PREFIX
541 + "hfc_dahdi_close called with NULL card\n");
545 + spin_lock(&chan->lock);
547 + if (chan->status == free) {
548 + spin_unlock(&chan->lock);
552 + chan->status = free;
553 + chan->open_by_dahdi = FALSE;
555 + spin_unlock(&chan->lock);
557 + switch (chan->number) {
562 + card->regs.ctmt &= ~hfc_CTMT_TRANSB1;
563 + card->regs.cirm &= ~hfc_CIRM_B1_REV;
564 + card->regs.sctrl &= ~hfc_SCTRL_B1_ENA;
565 + card->regs.sctrl_r &= ~hfc_SCTRL_R_B1_ENA;
569 + card->regs.ctmt &= ~hfc_CTMT_TRANSB2;
570 + card->regs.cirm &= ~hfc_CIRM_B2_REV;
571 + card->regs.sctrl &= ~hfc_SCTRL_B2_ENA;
572 + card->regs.sctrl_r &= ~hfc_SCTRL_R_B2_ENA;
576 + if (card->chans[B1].status == free &&
577 + card->chans[B2].status == free)
578 + card->regs.m2 &= ~hfc_M2_PROC_TRANS;
580 + hfc_outb(card, hfc_INT_M2, card->regs.m2);
581 + hfc_outb(card, hfc_CTMT, card->regs.ctmt);
582 + hfc_outb(card, hfc_CIRM, card->regs.cirm);
583 + hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
584 + hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
586 + hfc_update_fifo_state(card);
588 + module_put(THIS_MODULE);
590 + printk(KERN_INFO hfc_DRIVER_PREFIX
592 + "chan %s closed as %s.\n",
600 +static int hfc_dahdi_rbsbits(struct dahdi_chan *chan, int bits)
605 +static int hfc_dahdi_ioctl(struct dahdi_chan *chan,
606 + unsigned int cmd, unsigned long data)
617 +static void hfc_hdlc_hard_xmit(struct dahdi_chan *d_chan)
619 + struct hfc_chan_duplex *chan = d_chan->pvt;
620 + struct hfc_card *card = chan->card;
621 + struct dahdi_hfc *hfccard = card->dahdi_dev;
623 + atomic_inc(&hfccard->hdlc_pending);
627 +static int hfc_dahdi_startup(struct file *file, struct dahdi_span *span)
629 + struct dahdi_hfc *dahdi_hfcs = dahdi_hfc_from_span(span);
630 + struct hfc_card *hfctmp = dahdi_hfcs->card;
631 + int alreadyrunning;
634 + printk(KERN_INFO hfc_DRIVER_PREFIX
636 + "no card for span at startup!\n",
640 + alreadyrunning = span->flags & DAHDI_FLAG_RUNNING;
642 + if (!alreadyrunning)
643 + span->flags |= DAHDI_FLAG_RUNNING;
648 +static int hfc_dahdi_shutdown(struct dahdi_span *span)
653 +static int hfc_dahdi_maint(struct dahdi_span *span, int cmd)
658 +static int hfc_dahdi_chanconfig(struct file *file, struct dahdi_chan *d_chan, int sigtype)
660 + struct hfc_chan_duplex *chan = d_chan->pvt;
661 + struct hfc_card *card = chan->card;
662 + struct dahdi_hfc *hfccard = card->dahdi_dev;
664 + if ((sigtype == DAHDI_SIG_HARDHDLC) && (hfccard->sigchan == d_chan)) {
665 + hfccard->sigactive = 0;
666 + atomic_set(&hfccard->hdlc_pending, 0);
672 +static int hfc_dahdi_spanconfig(struct file *file, struct dahdi_span *span,
673 + struct dahdi_lineconfig *lc)
675 + span->lineconfig = lc->lineconfig;
680 +static const struct dahdi_span_ops hfc_dahdi_span_ops = {
681 + .owner = THIS_MODULE,
682 + .chanconfig = hfc_dahdi_chanconfig,
683 + .spanconfig = hfc_dahdi_spanconfig,
684 + .startup = hfc_dahdi_startup,
685 + .shutdown = hfc_dahdi_shutdown,
686 + .maint = hfc_dahdi_maint,
687 + .rbsbits = hfc_dahdi_rbsbits,
688 + .open = hfc_dahdi_open,
689 + .close = hfc_dahdi_close,
690 + .ioctl = hfc_dahdi_ioctl,
691 + .hdlc_hard_xmit = hfc_hdlc_hard_xmit
694 +static int hfc_dahdi_initialize(struct dahdi_hfc *hfccard)
696 + struct hfc_card *hfctmp = hfccard->card;
699 + hfccard->ddev = dahdi_create_device();
700 + if (!hfccard->ddev)
703 + memset(&hfccard->span, 0x0, sizeof(struct dahdi_span));
708 + * Cards' and channels' names shall contain "ZTHFC"
709 + * as the dahdi-tools look for this string to guess framing.
710 + * We don't want to modify dahdi-tools only in order to change this.
712 + * So we choose for a span name: DAHDI HFC-S formerly known as ZTHFC. :-)
715 + sprintf(hfccard->span.name, "DAHDI_HFCS_FKA_ZTHFC%d", hfctmp->cardnum + 1);
716 + sprintf(hfccard->span.desc,
717 + "HFC-S PCI A ISDN card %d [%s] ",
719 + hfctmp->nt_mode ? "NT" : "TE");
720 + hfccard->span.spantype = hfctmp->nt_mode ? SPANTYPE_DIGITAL_BRI_NT :
721 + SPANTYPE_DIGITAL_BRI_TE;
722 + hfccard->ddev->manufacturer = "Cologne Chips";
723 + hfccard->span.flags = 0;
724 + hfccard->span.ops = &hfc_dahdi_span_ops;
725 + hfccard->ddev->devicetype = kasprintf(GFP_KERNEL, "HFC-S PCI-A ISDN");
726 + hfccard->ddev->location = kasprintf(GFP_KERNEL, "PCI Bus %02d Slot %02d",
727 + hfctmp->pcidev->bus->number,
728 + PCI_SLOT(hfctmp->pcidev->devfn) + 1);
729 + hfccard->span.chans = hfccard->_chans;
730 + hfccard->span.channels = 3;
731 + for (i = 0; i < hfccard->span.channels; i++)
732 + hfccard->_chans[i] = &hfccard->chans[i];
733 + hfccard->span.deflaw = DAHDI_LAW_ALAW;
734 + hfccard->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_CCS;
735 + hfccard->span.offset = 0;
737 + for (i = 0; i < hfccard->span.channels; i++) {
738 + memset(&hfccard->chans[i], 0x0, sizeof(struct dahdi_chan));
740 + sprintf(hfccard->chans[i].name,
741 + "DAHDI_HFCS_FKA_ZTHFC%d/%d/%d",
742 + hfctmp->cardnum + 1, 0, i + 1);
744 + printk(KERN_INFO hfc_DRIVER_PREFIX
748 + hfccard->chans[i].name);
750 + if (i == hfccard->span.channels - 1) {
751 + hfccard->chans[i].sigcap = DAHDI_SIG_HARDHDLC;
752 + hfccard->sigchan = &hfccard->chans[DAHDI_D];
753 + hfccard->sigactive = 0;
754 + atomic_set(&hfccard->hdlc_pending, 0);
756 + hfccard->chans[i].sigcap =
757 + DAHDI_SIG_CLEAR | DAHDI_SIG_DACS;
760 + hfccard->chans[i].chanpos = i + 1;
763 + hfccard->chans[DAHDI_D].readchunk =
764 + hfctmp->chans[D].rx.dahdi_buffer;
766 + hfccard->chans[DAHDI_D].writechunk =
767 + hfctmp->chans[D].tx.dahdi_buffer;
769 + hfccard->chans[DAHDI_D].pvt = &hfctmp->chans[D];
771 + hfccard->chans[DAHDI_B1].readchunk =
772 + hfctmp->chans[B1].rx.dahdi_buffer;
774 + hfccard->chans[DAHDI_B1].writechunk =
775 + hfctmp->chans[B1].tx.dahdi_buffer;
777 + hfccard->chans[DAHDI_B1].pvt = &hfctmp->chans[B1];
779 + hfccard->chans[DAHDI_B2].readchunk =
780 + hfctmp->chans[B2].rx.dahdi_buffer;
782 + hfccard->chans[DAHDI_B2].writechunk =
783 + hfctmp->chans[B2].tx.dahdi_buffer;
785 + hfccard->chans[DAHDI_B2].pvt = &hfctmp->chans[B2];
787 + list_add_tail(&hfccard->span.device_node, &hfccard->ddev->spans);
788 + if (dahdi_register_device(hfccard->ddev, &hfccard->card->pcidev->dev)) {
789 + printk(KERN_NOTICE "Unable to register device with DAHDI\n");
796 +static void hfc_dahdi_transmit(struct hfc_chan_simplex *chan)
798 + hfc_fifo_put(chan, chan->dahdi_buffer, DAHDI_CHUNKSIZE);
801 +static void hfc_dahdi_receive(struct hfc_chan_simplex *chan)
803 + hfc_fifo_get(chan, chan->dahdi_buffer, DAHDI_CHUNKSIZE);
806 +/******************************************
807 + * Interrupt Handler
808 + ******************************************/
810 +static void hfc_handle_timer_interrupt(struct hfc_card *card);
811 +static void hfc_handle_state_interrupt(struct hfc_card *card);
812 +static void hfc_handle_processing_interrupt(struct hfc_card *card);
813 +static void hfc_frame_arrived(struct hfc_chan_duplex *chan);
814 +static void hfc_handle_voice(struct hfc_card *card);
816 +#if (KERNEL_VERSION(2, 6, 24) < LINUX_VERSION_CODE)
817 +static irqreturn_t hfc_interrupt(int irq, void *dev_id)
819 +static irqreturn_t hfc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
822 + struct hfc_card *card = dev_id;
823 + unsigned long flags;
827 + printk(KERN_CRIT hfc_DRIVER_PREFIX
828 + "spurious interrupt (IRQ %d)\n",
833 + spin_lock_irqsave(&card->lock, flags);
834 + status = hfc_inb(card, hfc_STATUS);
835 + if (!(status & hfc_STATUS_ANYINT)) {
837 + * maybe we are sharing the irq
839 + spin_unlock_irqrestore(&card->lock, flags);
843 + /* We used to ingore the IRQ when the card was in processing
844 + * state but apparently there is no restriction to access the
845 + * card in such state:
847 + * Joerg Ciesielski wrote:
848 + * > There is no restriction for the IRQ handler to access
849 + * > HFC-S PCI during processing phase. A IRQ latency of 375 us
850 + * > is also no problem since there are no interrupt sources in
851 + * > HFC-S PCI which must be handled very fast.
852 + * > Due to its deep fifos the IRQ latency can be several ms with
853 + * > out the risk of loosing data. Even the S/T state interrupts
854 + * > must not be handled with a latency less than <5ms.
856 + * > The processing phase only indicates that HFC-S PCI is
857 + * > processing the Fifos as PCI master so that data is read and
858 + * > written in the 32k memory window. But there is no restriction
859 + * > to access data in the memory window during this time.
861 + * // if (status & hfc_STATUS_PCI_PROC) {
862 + * // return IRQ_HANDLED;
866 + s1 = hfc_inb(card, hfc_INT_S1);
867 + s2 = hfc_inb(card, hfc_INT_S2);
870 + if (s1 & hfc_INTS_TIMER) {
874 + hfc_handle_timer_interrupt(card);
877 + if (s1 & hfc_INTS_L1STATE) {
879 + * state machine (bit 6)
881 + hfc_handle_state_interrupt(card);
884 + if (s1 & hfc_INTS_DREC) {
886 + * D chan RX (bit 5)
888 + hfc_frame_arrived(&card->chans[D]);
891 + if (s1 & hfc_INTS_B1REC) {
893 + * B1 chan RX (bit 3)
895 + hfc_frame_arrived(&card->chans[B1]);
898 + if (s1 & hfc_INTS_B2REC) {
900 + * B2 chan RX (bit 4)
902 + hfc_frame_arrived(&card->chans[B2]);
905 + if (s1 & hfc_INTS_DTRANS) {
907 + * D chan TX (bit 2)
911 + if (s1 & hfc_INTS_B1TRANS) {
913 + * B1 chan TX (bit 0)
917 + if (s1 & hfc_INTS_B2TRANS) {
919 + * B2 chan TX (bit 1)
926 + if (s2 & hfc_M2_PMESEL) {
928 + * kaboom irq (bit 7)
930 + * CologneChip says:
932 + * the meaning of this fatal error bit is that HFC-S
933 + * PCI as PCI master could not access the PCI bus
934 + * within 125us to finish its data processing. If this
935 + * happens only very seldom it does not cause big
936 + * problems but of course some B-channel or D-channel
937 + * data will be corrupted due to this event.
939 + * Unfortunately this bit is only set once after the
940 + * problem occurs and can only be reseted by a
941 + * software reset. That means it is not easily
942 + * possible to check how often this fatal error
947 + if (!card->sync_loss_reported) {
948 + printk(KERN_CRIT hfc_DRIVER_PREFIX
950 + "sync lost, pci performance too low!\n",
953 + card->sync_loss_reported = TRUE;
957 + if (s2 & hfc_M2_GCI_MON_REC) {
959 + * RxR monitor channel (bit 2)
963 + if (s2 & hfc_M2_GCI_I_CHG) {
965 + * GCI I-change (bit 1)
969 + if (s2 & hfc_M2_PROC_TRANS) {
971 + * processing/non-processing transition (bit 0)
973 + hfc_handle_processing_interrupt(card);
978 + spin_unlock_irqrestore(&card->lock, flags);
980 + return IRQ_HANDLED;
983 +static void hfc_handle_timer_interrupt(struct hfc_card *card)
985 + if (card->ignore_first_timer_interrupt) {
986 + card->ignore_first_timer_interrupt = FALSE;
990 + if ((card->nt_mode && card->l1_state == 3) ||
991 + (!card->nt_mode && card->l1_state == 7)) {
993 + card->regs.ctmt &= ~hfc_CTMT_TIMER_MASK;
994 + hfc_outb(card, hfc_CTMT, card->regs.ctmt);
996 + hfc_resume_fifo(card);
1000 +static void hfc_handle_state_interrupt(struct hfc_card *card)
1002 + u8 new_state = hfc_inb(card, hfc_STATES) & hfc_STATES_STATE_MASK;
1005 + if (debug_level >= 1) {
1006 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
1008 + "layer 1 state = %c%d\n",
1010 + card->nt_mode ? 'G' : 'F',
1015 + if (card->nt_mode) {
1020 + if (new_state == 3) {
1022 + * fix to G3 state (see specs)
1024 + hfc_outb(card, hfc_STATES, hfc_STATES_LOAD_STATE | 3);
1027 + if (new_state == 3 && card->l1_state != 3)
1028 + hfc_resume_fifo(card);
1030 + if (new_state != 3 && card->l1_state == 3)
1031 + hfc_suspend_fifo(card);
1034 + if (new_state == 3) {
1036 + * Keep L1 up... zaptel & libpri expects
1037 + * a always up L1...
1038 + * Enable only when using an unpatched libpri
1040 + * Are we still using unpatched libpri? Is this tested at runtime???
1041 + * Does it only affect zaptel or DAHDI, too?
1044 + if (force_l1_up) {
1045 + hfc_outb(card, hfc_STATES,
1046 + hfc_STATES_DO_ACTION |
1047 + hfc_STATES_ACTIVATE|
1048 + hfc_STATES_NT_G2_G3);
1052 + if (new_state == 7 && card->l1_state != 7) {
1054 + * TE is now active, schedule FIFO activation after
1055 + * some time, otherwise the first frames are lost
1058 + card->regs.ctmt |= hfc_CTMT_TIMER_50 |
1059 + hfc_CTMT_TIMER_CLEAR;
1060 + hfc_outb(card, hfc_CTMT, card->regs.ctmt);
1063 + * Activating the timer firest an
1064 + * interrupt immediately, we
1065 + * obviously need to ignore it
1067 + card->ignore_first_timer_interrupt = TRUE;
1070 + if (new_state != 7 && card->l1_state == 7) {
1072 + * TE has become inactive, disable FIFO
1074 + hfc_suspend_fifo(card);
1078 + card->l1_state = new_state;
1081 +static void hfc_handle_processing_interrupt(struct hfc_card *card)
1083 + int available_bytes = 0;
1086 + * Synchronize with the first enabled channel
1088 + if (card->regs.fifo_en & hfc_FIFOEN_B1RX)
1089 + available_bytes = hfc_fifo_used_rx(&card->chans[B1].rx);
1090 + if (card->regs.fifo_en & hfc_FIFOEN_B2RX)
1091 + available_bytes = hfc_fifo_used_rx(&card->chans[B2].rx);
1093 + available_bytes = -1;
1095 + if ((available_bytes == -1 && card->ticks == 8) ||
1096 + available_bytes >= DAHDI_CHUNKSIZE + hfc_RX_FIFO_PRELOAD) {
1099 + if (available_bytes > DAHDI_CHUNKSIZE*2 + hfc_RX_FIFO_PRELOAD) {
1100 + card->late_irqs++;
1102 + * we are out of sync, clear fifos, jaw
1104 + hfc_clear_fifo_rx(&card->chans[B1].rx);
1105 + hfc_clear_fifo_tx(&card->chans[B1].tx);
1106 + hfc_clear_fifo_rx(&card->chans[B2].rx);
1107 + hfc_clear_fifo_tx(&card->chans[B2].tx);
1110 + if (debug_level >= 4) {
1111 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
1113 + "late IRQ, %d bytes late\n",
1116 + (DAHDI_CHUNKSIZE +
1117 + hfc_RX_FIFO_PRELOAD));
1121 + hfc_handle_voice(card);
1129 +static void hfc_handle_voice(struct hfc_card *card)
1131 + struct dahdi_hfc *hfccard = card->dahdi_dev;
1132 + int frame_left, res;
1133 + unsigned char buf[hfc_HDLC_BUF_LEN];
1134 + unsigned int size = sizeof(buf) / sizeof(buf[0]);
1137 + if (card->chans[B1].status != open_voice &&
1138 + card->chans[B2].status != open_voice)
1141 + dahdi_transmit(&hfccard->span);
1143 + if (card->regs.fifo_en & hfc_FIFOEN_B1TX)
1144 + hfc_dahdi_transmit(&card->chans[B1].tx);
1145 + if (card->regs.fifo_en & hfc_FIFOEN_B2TX)
1146 + hfc_dahdi_transmit(&card->chans[B2].tx);
1149 + * dahdi hdlc frame tx
1152 + if (atomic_read(&hfccard->hdlc_pending)) {
1153 + hfc_check_l1_up(card);
1154 + res = dahdi_hdlc_getbuf(hfccard->sigchan, buf, &size);
1156 + hfccard->sigactive = 1;
1157 + memcpy(card->chans[D].tx.ugly_framebuf +
1158 + card->chans[D].tx.ugly_framebuf_size,
1160 + card->chans[D].tx.ugly_framebuf_size += size;
1162 + hfc_fifo_put_frame(&card->chans[D].tx,
1163 + card->chans[D].tx.ugly_framebuf,
1164 + card->chans[D].tx.ugly_framebuf_size);
1165 + ++hfccard->frames_out;
1166 + hfccard->sigactive = 0;
1167 + card->chans[D].tx.ugly_framebuf_size
1169 + atomic_dec(&hfccard->hdlc_pending);
1174 + * dahdi hdlc frame tx done
1177 + if (card->regs.fifo_en & hfc_FIFOEN_B1RX)
1178 + hfc_dahdi_receive(&card->chans[B1].rx);
1180 + memset(&card->chans[B1].rx.dahdi_buffer, 0x7f,
1181 + sizeof(card->chans[B1].rx.dahdi_buffer));
1183 + if (card->regs.fifo_en & hfc_FIFOEN_B2RX)
1184 + hfc_dahdi_receive(&card->chans[B2].rx);
1186 + memset(&card->chans[B2].rx.dahdi_buffer, 0x7f,
1187 + sizeof(card->chans[B1].rx.dahdi_buffer));
1190 + * Echo cancellation
1192 + dahdi_ec_chunk(&hfccard->chans[DAHDI_B1],
1193 + card->chans[B1].rx.dahdi_buffer,
1194 + card->chans[B1].tx.dahdi_buffer);
1195 + dahdi_ec_chunk(&hfccard->chans[DAHDI_B2],
1196 + card->chans[B2].rx.dahdi_buffer,
1197 + card->chans[B2].tx.dahdi_buffer);
1200 + * dahdi hdlc frame rx
1202 + if (hfc_fifo_has_frames(&card->chans[D].rx))
1203 + hfc_frame_arrived(&card->chans[D]);
1205 + if (card->chans[D].rx.ugly_framebuf_size) {
1206 + frame_left = card->chans[D].rx.ugly_framebuf_size -
1207 + card->chans[D].rx.ugly_framebuf_off ;
1208 + if (frame_left > hfc_HDLC_BUF_LEN) {
1209 + dahdi_hdlc_putbuf(hfccard->sigchan,
1210 + card->chans[D].rx.ugly_framebuf +
1211 + card->chans[D].rx.ugly_framebuf_off,
1212 + hfc_HDLC_BUF_LEN);
1213 + card->chans[D].rx.ugly_framebuf_off +=
1216 + dahdi_hdlc_putbuf(hfccard->sigchan,
1217 + card->chans[D].rx.ugly_framebuf +
1218 + card->chans[D].rx.ugly_framebuf_off,
1220 + dahdi_hdlc_finish(hfccard->sigchan);
1221 + card->chans[D].rx.ugly_framebuf_size = 0;
1222 + card->chans[D].rx.ugly_framebuf_off = 0;
1226 + * dahdi hdlc frame rx done
1229 + if (hfccard->span.flags & DAHDI_FLAG_RUNNING)
1230 + dahdi_receive(&hfccard->span);
1234 +static void hfc_frame_arrived(struct hfc_chan_duplex *chan)
1236 + struct hfc_card *card = chan->card;
1237 + int antiloop = 16;
1238 + struct sk_buff *skb;
1240 + while (hfc_fifo_has_frames(&chan->rx) && --antiloop) {
1241 + int frame_size = hfc_fifo_get_frame_size(&chan->rx);
1243 + if (frame_size < 3) {
1245 + if (debug_level >= 2)
1246 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
1249 + "invalid frame received, "
1250 + "just %d bytes\n",
1256 + hfc_fifo_drop_frame(&chan->rx);
1260 + } else if (frame_size == 3) {
1262 + if (debug_level >= 2)
1263 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
1266 + "empty frame received\n",
1271 + hfc_fifo_drop_frame(&chan->rx);
1277 + if (chan->open_by_dahdi &&
1278 + card->chans[D].rx.ugly_framebuf_size) {
1281 + * We have to wait for Dahdi to transmit the
1282 + * frame... wait for next time
1288 + skb = dev_alloc_skb(frame_size - 3);
1291 + printk(KERN_ERR hfc_DRIVER_PREFIX
1294 + "cannot allocate skb: frame dropped\n",
1298 + hfc_fifo_drop_frame(&chan->rx);
1306 + * HFC does the checksum
1308 +#ifndef CHECKSUM_HW
1309 + skb->ip_summed = CHECKSUM_COMPLETE;
1311 + skb->ip_summed = CHECKSUM_HW;
1314 + if (chan->open_by_dahdi) {
1315 + card->chans[D].rx.ugly_framebuf_size = frame_size - 1;
1317 + if (hfc_fifo_get_frame(&card->chans[D].rx,
1318 + card->chans[D].rx.ugly_framebuf,
1319 + frame_size - 1) == -1) {
1320 + dev_kfree_skb(skb);
1324 + memcpy(skb_put(skb, frame_size - 3),
1325 + card->chans[D].rx.ugly_framebuf,
1328 + if (hfc_fifo_get_frame(&chan->rx,
1329 + skb_put(skb, frame_size - 3),
1330 + frame_size - 3) == -1) {
1331 + dev_kfree_skb(skb);
1338 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1340 + "Infinite loop detected\n",
1344 +/******************************************
1345 + * Module initialization and cleanup
1346 + ******************************************/
1348 +static int __devinit hfc_probe(struct pci_dev *pci_dev,
1349 + const struct pci_device_id *ent)
1351 + static int cardnum;
1355 + struct hfc_card *card = NULL;
1356 + struct dahdi_hfc *dahdi_hfcs = NULL;
1357 + card = kmalloc(sizeof(struct hfc_card), GFP_KERNEL);
1359 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1360 + "unable to kmalloc!\n");
1362 + goto err_alloc_hfccard;
1365 + memset(card, 0x00, sizeof(struct hfc_card));
1366 + card->cardnum = cardnum;
1367 + card->pcidev = pci_dev;
1368 + spin_lock_init(&card->lock);
1370 + pci_set_drvdata(pci_dev, card);
1372 + err = pci_enable_device(pci_dev);
1374 + goto err_pci_enable_device;
1376 + err = pci_set_dma_mask(pci_dev, PCI_DMA_32BIT);
1378 + printk(KERN_ERR hfc_DRIVER_PREFIX
1380 + "No suitable DMA configuration available.\n",
1382 + goto err_pci_set_dma_mask;
1385 + pci_write_config_word(pci_dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
1386 + err = pci_request_regions(pci_dev, hfc_DRIVER_NAME);
1388 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1390 + "cannot request I/O memory region\n",
1392 + goto err_pci_request_regions;
1395 + pci_set_master(pci_dev);
1397 + if (!pci_dev->irq) {
1398 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1406 + card->io_bus_mem = pci_resource_start(pci_dev, 1);
1407 + if (!card->io_bus_mem) {
1408 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1413 + goto err_noiobase;
1416 + card->io_mem = ioremap(card->io_bus_mem, hfc_PCI_MEM_SIZE);
1417 + if (!(card->io_mem)) {
1418 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1420 + "cannot ioremap I/O memory\n",
1427 + * pci_alloc_consistent guarantees alignment
1428 + * (Documentation/DMA-mapping.txt)
1430 + card->fifo_mem = pci_alloc_consistent(pci_dev,
1431 + hfc_FIFO_SIZE, &card->fifo_bus_mem);
1432 + if (!card->fifo_mem) {
1433 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1435 + "unable to allocate FIFO DMA memory!\n",
1438 + goto err_alloc_fifo;
1441 + memset(card->fifo_mem, 0x00, hfc_FIFO_SIZE);
1443 + card->fifos = card->fifo_mem;
1445 + pci_write_config_dword(card->pcidev, hfc_PCI_MWBA, card->fifo_bus_mem);
1447 + err = request_irq(card->pcidev->irq, &hfc_interrupt,
1449 +#if (KERNEL_VERSION(2, 6, 23) < LINUX_VERSION_CODE)
1450 + IRQF_SHARED, hfc_DRIVER_NAME, card);
1452 + SA_SHIRQ, hfc_DRIVER_NAME, card);
1456 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1458 + "unable to register irq\n",
1460 + goto err_request_irq;
1463 + card->nt_mode = FALSE;
1465 + if (modes & (1 << card->cardnum))
1466 + card->nt_mode = TRUE;
1468 + for (i = 0; i < nt_modes_count; i++) {
1469 + if (nt_modes[i] == card->cardnum)
1470 + card->nt_mode = TRUE;
1476 + card->chans[D].card = card;
1477 + card->chans[D].name = "D";
1478 + card->chans[D].status = free;
1479 + card->chans[D].number = D;
1480 + spin_lock_init(&card->chans[D].lock);
1482 + card->chans[D].rx.chan = &card->chans[D];
1483 + card->chans[D].rx.fifo_base = card->fifos + 0x4000;
1484 + card->chans[D].rx.z_base = card->fifos + 0x4000;
1485 + card->chans[D].rx.z1_base = card->fifos + 0x6080;
1486 + card->chans[D].rx.z2_base = card->fifos + 0x6082;
1487 + card->chans[D].rx.z_min = 0x0000;
1488 + card->chans[D].rx.z_max = 0x01FF;
1489 + card->chans[D].rx.f_min = 0x10;
1490 + card->chans[D].rx.f_max = 0x1F;
1491 + card->chans[D].rx.f1 = card->fifos + 0x60a0;
1492 + card->chans[D].rx.f2 = card->fifos + 0x60a1;
1493 + card->chans[D].rx.fifo_size = card->chans[D].rx.z_max
1494 + - card->chans[D].rx.z_min + 1;
1495 + card->chans[D].rx.f_num = card->chans[D].rx.f_max
1496 + - card->chans[D].rx.f_min + 1;
1498 + card->chans[D].tx.chan = &card->chans[D];
1499 + card->chans[D].tx.fifo_base = card->fifos + 0x0000;
1500 + card->chans[D].tx.z_base = card->fifos + 0x0000;
1501 + card->chans[D].tx.z1_base = card->fifos + 0x2080;
1502 + card->chans[D].tx.z2_base = card->fifos + 0x2082;
1503 + card->chans[D].tx.z_min = 0x0000;
1504 + card->chans[D].tx.z_max = 0x01FF;
1505 + card->chans[D].tx.f_min = 0x10;
1506 + card->chans[D].tx.f_max = 0x1F;
1507 + card->chans[D].tx.f1 = card->fifos + 0x20a0;
1508 + card->chans[D].tx.f2 = card->fifos + 0x20a1;
1509 + card->chans[D].tx.fifo_size = card->chans[D].tx.z_max -
1510 + card->chans[D].tx.z_min + 1;
1511 + card->chans[D].tx.f_num = card->chans[D].tx.f_max -
1512 + card->chans[D].tx.f_min + 1;
1517 + card->chans[B1].card = card;
1518 + card->chans[B1].name = "B1";
1519 + card->chans[B1].status = free;
1520 + card->chans[B1].number = B1;
1521 + card->chans[B1].protocol = 0;
1522 + spin_lock_init(&card->chans[B1].lock);
1524 + card->chans[B1].rx.chan = &card->chans[B1];
1525 + card->chans[B1].rx.fifo_base = card->fifos + 0x4200;
1526 + card->chans[B1].rx.z_base = card->fifos + 0x4000;
1527 + card->chans[B1].rx.z1_base = card->fifos + 0x6000;
1528 + card->chans[B1].rx.z2_base = card->fifos + 0x6002;
1529 + card->chans[B1].rx.z_min = 0x0200;
1530 + card->chans[B1].rx.z_max = 0x1FFF;
1531 + card->chans[B1].rx.f_min = 0x00;
1532 + card->chans[B1].rx.f_max = 0x1F;
1533 + card->chans[B1].rx.f1 = card->fifos + 0x6080;
1534 + card->chans[B1].rx.f2 = card->fifos + 0x6081;
1535 + card->chans[B1].rx.fifo_size = card->chans[B1].rx.z_max -
1536 + card->chans[B1].rx.z_min + 1;
1537 + card->chans[B1].rx.f_num = card->chans[B1].rx.f_max -
1538 + card->chans[B1].rx.f_min + 1;
1540 + card->chans[B1].tx.chan = &card->chans[B1];
1541 + card->chans[B1].tx.fifo_base = card->fifos + 0x0200;
1542 + card->chans[B1].tx.z_base = card->fifos + 0x0000;
1543 + card->chans[B1].tx.z1_base = card->fifos + 0x2000;
1544 + card->chans[B1].tx.z2_base = card->fifos + 0x2002;
1545 + card->chans[B1].tx.z_min = 0x0200;
1546 + card->chans[B1].tx.z_max = 0x1FFF;
1547 + card->chans[B1].tx.f_min = 0x00;
1548 + card->chans[B1].tx.f_max = 0x1F;
1549 + card->chans[B1].tx.f1 = card->fifos + 0x2080;
1550 + card->chans[B1].tx.f2 = card->fifos + 0x2081;
1551 + card->chans[B1].tx.fifo_size = card->chans[B1].tx.z_max -
1552 + card->chans[B1].tx.z_min + 1;
1553 + card->chans[B1].tx.f_num = card->chans[B1].tx.f_max -
1554 + card->chans[B1].tx.f_min + 1;
1559 + card->chans[B2].card = card;
1560 + card->chans[B2].name = "B2";
1561 + card->chans[B2].status = free;
1562 + card->chans[B2].number = B2;
1563 + card->chans[B2].protocol = 0;
1564 + spin_lock_init(&card->chans[B2].lock);
1566 + card->chans[B2].rx.chan = &card->chans[B2];
1567 + card->chans[B2].rx.fifo_base = card->fifos + 0x6200,
1568 + card->chans[B2].rx.z_base = card->fifos + 0x6000;
1569 + card->chans[B2].rx.z1_base = card->fifos + 0x6100;
1570 + card->chans[B2].rx.z2_base = card->fifos + 0x6102;
1571 + card->chans[B2].rx.z_min = 0x0200;
1572 + card->chans[B2].rx.z_max = 0x1FFF;
1573 + card->chans[B2].rx.f_min = 0x00;
1574 + card->chans[B2].rx.f_max = 0x1F;
1575 + card->chans[B2].rx.f1 = card->fifos + 0x6180;
1576 + card->chans[B2].rx.f2 = card->fifos + 0x6181;
1577 + card->chans[B2].rx.fifo_size = card->chans[B2].rx.z_max -
1578 + card->chans[B2].rx.z_min + 1;
1579 + card->chans[B2].rx.f_num = card->chans[B2].rx.f_max -
1580 + card->chans[B2].rx.f_min + 1;
1582 + card->chans[B2].tx.chan = &card->chans[B2];
1583 + card->chans[B2].tx.fifo_base = card->fifos + 0x2200;
1584 + card->chans[B2].tx.z_base = card->fifos + 0x2000;
1585 + card->chans[B2].tx.z1_base = card->fifos + 0x2100;
1586 + card->chans[B2].tx.z2_base = card->fifos + 0x2102;
1587 + card->chans[B2].tx.z_min = 0x0200;
1588 + card->chans[B2].tx.z_max = 0x1FFF;
1589 + card->chans[B2].tx.f_min = 0x00;
1590 + card->chans[B2].tx.f_max = 0x1F;
1591 + card->chans[B2].tx.f1 = card->fifos + 0x2180;
1592 + card->chans[B2].tx.f2 = card->fifos + 0x2181;
1593 + card->chans[B2].tx.fifo_size = card->chans[B2].tx.z_max -
1594 + card->chans[B2].tx.z_min + 1;
1595 + card->chans[B2].tx.f_num = card->chans[B2].tx.f_max -
1596 + card->chans[B2].tx.f_min + 1;
1602 + dahdi_hfcs = kmalloc(sizeof(struct dahdi_hfc), GFP_KERNEL);
1603 + if (!dahdi_hfcs) {
1604 + printk(KERN_CRIT hfc_DRIVER_PREFIX
1605 + "unable to kmalloc!\n");
1606 + goto err_request_irq;
1608 + memset(dahdi_hfcs, 0x0, sizeof(struct dahdi_hfc));
1610 + dahdi_hfcs->card = card;
1611 + hfc_dahdi_initialize(dahdi_hfcs);
1612 + card->dahdi_dev = dahdi_hfcs;
1614 + snprintf(card->proc_dir_name,
1615 + sizeof(card->proc_dir_name),
1616 + "%d", card->cardnum);
1617 + card->proc_dir = proc_mkdir(card->proc_dir_name, hfc_proc_dahdi_hfcs_dir);
1618 + SET_PROC_DIRENTRY_OWNER(card->proc_dir);
1620 + hfc_resetCard(card);
1622 + printk(KERN_INFO hfc_DRIVER_PREFIX
1623 + "card %d configured for %s mode at mem %#lx (0x%p) IRQ %u\n",
1625 + card->nt_mode ? "NT" : "TE",
1628 + card->pcidev->irq);
1635 + pci_free_consistent(pci_dev, hfc_FIFO_SIZE,
1636 + card->fifo_mem, card->fifo_bus_mem);
1638 + iounmap(card->io_mem);
1642 + pci_release_regions(pci_dev);
1643 +err_pci_request_regions:
1644 +err_pci_set_dma_mask:
1645 +err_pci_enable_device:
1651 +static void __devexit hfc_remove(struct pci_dev *pci_dev)
1653 + struct hfc_card *card = pci_get_drvdata(pci_dev);
1656 + printk(KERN_INFO hfc_DRIVER_PREFIX
1658 + "shutting down card at %p.\n",
1666 + hfc_softreset(card);
1668 + dahdi_unregister_device(card->dahdi_dev->ddev);
1672 + * disable memio and bustmaster
1674 + pci_write_config_word(pci_dev, PCI_COMMAND, 0);
1677 +BUG: these proc entries just cause Call traces, so removed.
1678 + remove_proc_entry("bufs", card->proc_dir);
1679 + remove_proc_entry("fifos", card->proc_dir);
1680 + remove_proc_entry("info", card->proc_dir);
1682 + remove_proc_entry(card->proc_dir_name, hfc_proc_dahdi_hfcs_dir);
1684 + free_irq(pci_dev->irq, card);
1686 + pci_free_consistent(pci_dev, hfc_FIFO_SIZE,
1687 + card->fifo_mem, card->fifo_bus_mem);
1689 + iounmap(card->io_mem);
1691 + pci_release_regions(pci_dev);
1693 + pci_disable_device(pci_dev);
1698 +/******************************************
1700 + ******************************************/
1702 +static int __init hfc_init_module(void)
1706 + printk(KERN_INFO hfc_DRIVER_PREFIX
1707 + hfc_DRIVER_STRING " loading\n");
1709 +printk(KERN_INFO hfc_DRIVER_PREFIX "Check /var/log/kern-debug.log for debugging output level %d.", debug_level);
1710 +printk(KERN_DEBUG hfc_DRIVER_PREFIX "base.c is debugging.");
1713 +#if (KERNEL_VERSION(2, 6, 26) <= LINUX_VERSION_CODE)
1714 + hfc_proc_dahdi_hfcs_dir = proc_mkdir(hfc_DRIVER_NAME, NULL);
1716 + hfc_proc_dahdi_hfcs_dir = proc_mkdir(hfc_DRIVER_NAME, proc_root_driver);
1719 + ret = dahdi_pci_module(&hfc_driver);
1723 +module_init(hfc_init_module);
1725 +static void __exit hfc_module_exit(void)
1727 + pci_unregister_driver(&hfc_driver);
1729 +#if (KERNEL_VERSION(2, 6, 26) <= LINUX_VERSION_CODE)
1730 + remove_proc_entry(hfc_DRIVER_NAME, NULL);
1732 + remove_proc_entry(hfc_DRIVER_NAME, proc_root_driver);
1735 + printk(KERN_INFO hfc_DRIVER_PREFIX
1736 + hfc_DRIVER_STRING " unloaded\n");
1739 +module_exit(hfc_module_exit);
1743 +MODULE_DESCRIPTION(hfc_DRIVER_DESCR);
1744 +MODULE_AUTHOR("Jens Wilke <jw_vzaphfc@headissue.com>, "
1745 + "Daniele (Vihai) Orlandi <daniele@orlandi.com>, "
1746 + "Jose A. Deniz <odicha@hotmail.com>");
1747 +MODULE_ALIAS("dahdi_hfcs");
1748 +#ifdef MODULE_LICENSE
1749 +MODULE_LICENSE("GPL");
1753 +module_param(modes, int, 0444);
1755 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
1756 +module_param_array(nt_modes, int, &nt_modes_count, 0444);
1758 +module_param_array(nt_modes, int, nt_modes_count, 0444);
1761 +module_param(force_l1_up, int, 0444);
1763 +module_param(debug_level, int, 0444);
1766 +MODULE_PARM_DESC(modes, "[Deprecated] bit-mask to configure NT mode");
1767 +MODULE_PARM_DESC(nt_modes,
1768 + "Comma-separated list of card IDs to configure in NT mode");
1769 +MODULE_PARM_DESC(force_l1_up, "Don't allow L1 to go down");
1771 +MODULE_PARM_DESC(debug_level, "Debug verbosity level");
1774 +++ b/drivers/dahdi/hfcs/dahdi_hfcs.h
1777 + * dahdi_hfcs.h - Dahdi driver for HFC-S PCI A based ISDN BRI cards
1779 + * Dahdi port by Jose A. Deniz <odicha@hotmail.com>
1781 + * Copyright (C) 2009 Jose A. Deniz
1782 + * Copyright (C) 2006 headissue GmbH; Jens Wilke
1783 + * Copyright (C) 2004 Daniele Orlandi
1784 + * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
1786 + * Jens Wilke <jw_vzaphfc@headissue.com>
1788 + * Orginal author of this code is
1789 + * Daniele "Vihai" Orlandi <daniele@orlandi.com>
1791 + * Major rewrite of the driver made by
1792 + * Klaus-Peter Junghanns <kpj@junghanns.net>
1794 + * This program is free software and may be modified and
1795 + * distributed under the terms of the GNU Public License.
1799 +#ifndef _HFC_ZAPHFC_H
1800 +#define _HFC_ZAPHFC_H
1802 +#include <asm/io.h>
1804 +#define hfc_DRIVER_NAME "dahdi_hfcs"
1805 +#define hfc_DRIVER_PREFIX hfc_DRIVER_NAME ": "
1806 +#define hfc_DRIVER_DESCR "HFC-S PCI A ISDN"
1807 +#define hfc_DRIVER_VERSION "1.42"
1808 +#define hfc_DRIVER_STRING hfc_DRIVER_DESCR " (V" hfc_DRIVER_VERSION ")"
1810 +#define hfc_MAX_BOARDS 32
1812 +#ifndef PCI_DMA_32BIT
1813 +#define PCI_DMA_32BIT 0x00000000ffffffffULL
1816 +#ifndef PCI_VENDOR_ID_SITECOM
1817 +#define PCI_VENDOR_ID_SITECOM 0x182D
1820 +#ifndef PCI_DEVICE_ID_SITECOM_3069
1821 +#define PCI_DEVICE_ID_SITECOM_3069 0x3069
1824 +#define hfc_RESET_DELAY 20
1826 +#define hfc_CLKDEL_TE 0x0f /* CLKDEL in TE mode */
1827 +#define hfc_CLKDEL_NT 0x6c /* CLKDEL in NT mode */
1829 +/* PCI memory mapped I/O */
1831 +#define hfc_PCI_MEM_SIZE 0x0100
1832 +#define hfc_PCI_MWBA 0x80
1834 +/* GCI/IOM bus monitor registers */
1836 +#define hfc_C_I 0x08
1837 +#define hfc_TRxR 0x0C
1838 +#define hfc_MON1_D 0x28
1839 +#define hfc_MON2_D 0x2C
1842 +/* GCI/IOM bus timeslot registers */
1844 +#define hfc_B1_SSL 0x80
1845 +#define hfc_B2_SSL 0x84
1846 +#define hfc_AUX1_SSL 0x88
1847 +#define hfc_AUX2_SSL 0x8C
1848 +#define hfc_B1_RSL 0x90
1849 +#define hfc_B2_RSL 0x94
1850 +#define hfc_AUX1_RSL 0x98
1851 +#define hfc_AUX2_RSL 0x9C
1853 +/* GCI/IOM bus data registers */
1855 +#define hfc_B1_D 0xA0
1856 +#define hfc_B2_D 0xA4
1857 +#define hfc_AUX1_D 0xA8
1858 +#define hfc_AUX2_D 0xAC
1860 +/* GCI/IOM bus configuration registers */
1862 +#define hfc_MST_EMOD 0xB4
1863 +#define hfc_MST_MODE 0xB8
1864 +#define hfc_CONNECT 0xBC
1867 +/* Interrupt and status registers */
1869 +#define hfc_FIFO_EN 0x44
1870 +#define hfc_TRM 0x48
1871 +#define hfc_B_MODE 0x4C
1872 +#define hfc_CHIP_ID 0x58
1873 +#define hfc_CIRM 0x60
1874 +#define hfc_CTMT 0x64
1875 +#define hfc_INT_M1 0x68
1876 +#define hfc_INT_M2 0x6C
1877 +#define hfc_INT_S1 0x78
1878 +#define hfc_INT_S2 0x7C
1879 +#define hfc_STATUS 0x70
1881 +/* S/T section registers */
1883 +#define hfc_STATES 0xC0
1884 +#define hfc_SCTRL 0xC4
1885 +#define hfc_SCTRL_E 0xC8
1886 +#define hfc_SCTRL_R 0xCC
1887 +#define hfc_SQ 0xD0
1888 +#define hfc_CLKDEL 0xDC
1889 +#define hfc_B1_REC 0xF0
1890 +#define hfc_B1_SEND 0xF0
1891 +#define hfc_B2_REC 0xF4
1892 +#define hfc_B2_SEND 0xF4
1893 +#define hfc_D_REC 0xF8
1894 +#define hfc_D_SEND 0xF8
1895 +#define hfc_E_REC 0xFC
1897 +/* Bits and values in various HFC PCI registers */
1899 +/* bits in status register (READ) */
1900 +#define hfc_STATUS_PCI_PROC 0x02
1901 +#define hfc_STATUS_NBUSY 0x04
1902 +#define hfc_STATUS_TIMER_ELAP 0x10
1903 +#define hfc_STATUS_STATINT 0x20
1904 +#define hfc_STATUS_FRAMEINT 0x40
1905 +#define hfc_STATUS_ANYINT 0x80
1907 +/* bits in CTMT (Write) */
1908 +#define hfc_CTMT_TRANSB1 0x01
1909 +#define hfc_CTMT_TRANSB2 0x02
1910 +#define hfc_CTMT_TIMER_CLEAR 0x80
1911 +#define hfc_CTMT_TIMER_MASK 0x1C
1912 +#define hfc_CTMT_TIMER_3_125 (0x01 << 2)
1913 +#define hfc_CTMT_TIMER_6_25 (0x02 << 2)
1914 +#define hfc_CTMT_TIMER_12_5 (0x03 << 2)
1915 +#define hfc_CTMT_TIMER_25 (0x04 << 2)
1916 +#define hfc_CTMT_TIMER_50 (0x05 << 2)
1917 +#define hfc_CTMT_TIMER_400 (0x06 << 2)
1918 +#define hfc_CTMT_TIMER_800 (0x07 << 2)
1919 +#define hfc_CTMT_AUTO_TIMER 0x20
1921 +/* bits in CIRM (Write) */
1922 +#define hfc_CIRM_AUX_MSK 0x07
1923 +#define hfc_CIRM_RESET 0x08
1924 +#define hfc_CIRM_B1_REV 0x40
1925 +#define hfc_CIRM_B2_REV 0x80
1927 +/* bits in INT_M1 and INT_S1 */
1928 +#define hfc_INTS_B1TRANS 0x01
1929 +#define hfc_INTS_B2TRANS 0x02
1930 +#define hfc_INTS_DTRANS 0x04
1931 +#define hfc_INTS_B1REC 0x08
1932 +#define hfc_INTS_B2REC 0x10
1933 +#define hfc_INTS_DREC 0x20
1934 +#define hfc_INTS_L1STATE 0x40
1935 +#define hfc_INTS_TIMER 0x80
1937 +/* bits in INT_M2 */
1938 +#define hfc_M2_PROC_TRANS 0x01
1939 +#define hfc_M2_GCI_I_CHG 0x02
1940 +#define hfc_M2_GCI_MON_REC 0x04
1941 +#define hfc_M2_IRQ_ENABLE 0x08
1942 +#define hfc_M2_PMESEL 0x80
1944 +/* bits in STATES */
1945 +#define hfc_STATES_STATE_MASK 0x0F
1946 +#define hfc_STATES_LOAD_STATE 0x10
1947 +#define hfc_STATES_ACTIVATE 0x20
1948 +#define hfc_STATES_DO_ACTION 0x40
1949 +#define hfc_STATES_NT_G2_G3 0x80
1951 +/* bits in HFCD_MST_MODE */
1952 +#define hfc_MST_MODE_MASTER 0x01
1953 +#define hfc_MST_MODE_SLAVE 0x00
1954 +/* remaining bits are for codecs control */
1956 +/* bits in HFCD_SCTRL */
1957 +#define hfc_SCTRL_B1_ENA 0x01
1958 +#define hfc_SCTRL_B2_ENA 0x02
1959 +#define hfc_SCTRL_MODE_TE 0x00
1960 +#define hfc_SCTRL_MODE_NT 0x04
1961 +#define hfc_SCTRL_LOW_PRIO 0x08
1962 +#define hfc_SCTRL_SQ_ENA 0x10
1963 +#define hfc_SCTRL_TEST 0x20
1964 +#define hfc_SCTRL_NONE_CAP 0x40
1965 +#define hfc_SCTRL_PWR_DOWN 0x80
1967 +/* bits in SCTRL_E */
1968 +#define hfc_SCTRL_E_AUTO_AWAKE 0x01
1969 +#define hfc_SCTRL_E_DBIT_1 0x04
1970 +#define hfc_SCTRL_E_IGNORE_COL 0x08
1971 +#define hfc_SCTRL_E_CHG_B1_B2 0x80
1973 +/* bits in SCTRL_R */
1974 +#define hfc_SCTRL_R_B1_ENA 0x01
1975 +#define hfc_SCTRL_R_B2_ENA 0x02
1977 +/* bits in FIFO_EN register */
1978 +#define hfc_FIFOEN_B1TX 0x01
1979 +#define hfc_FIFOEN_B1RX 0x02
1980 +#define hfc_FIFOEN_B2TX 0x04
1981 +#define hfc_FIFOEN_B2RX 0x08
1982 +#define hfc_FIFOEN_DTX 0x10
1983 +#define hfc_FIFOEN_DRX 0x20
1985 +#define hfc_FIFOEN_B1 (hfc_FIFOEN_B1TX|hfc_FIFOEN_B1RX)
1986 +#define hfc_FIFOEN_B2 (hfc_FIFOEN_B2TX|hfc_FIFOEN_B2RX)
1987 +#define hfc_FIFOEN_D (hfc_FIFOEN_DTX|hfc_FIFOEN_DRX)
1989 +/* bits in the CONNECT register */
1990 +#define hfc_CONNECT_B1_HFC_from_ST 0x00
1991 +#define hfc_CONNECT_B1_HFC_from_GCI 0x01
1992 +#define hfc_CONNECT_B1_ST_from_HFC 0x00
1993 +#define hfc_CONNECT_B1_ST_from_GCI 0x02
1994 +#define hfc_CONNECT_B1_GCI_from_HFC 0x00
1995 +#define hfc_CONNECT_B1_GCI_from_ST 0x04
1997 +#define hfc_CONNECT_B2_HFC_from_ST 0x00
1998 +#define hfc_CONNECT_B2_HFC_from_GCI 0x08
1999 +#define hfc_CONNECT_B2_ST_from_HFC 0x00
2000 +#define hfc_CONNECT_B2_ST_from_GCI 0x10
2001 +#define hfc_CONNECT_B2_GCI_from_HFC 0x00
2002 +#define hfc_CONNECT_B2_GCI_from_ST 0x20
2004 +/* bits in the TRM register */
2005 +#define hfc_TRM_TRANS_INT_00 0x00
2006 +#define hfc_TRM_TRANS_INT_01 0x01
2007 +#define hfc_TRM_TRANS_INT_10 0x02
2008 +#define hfc_TRM_TRANS_INT_11 0x04
2009 +#define hfc_TRM_ECHO 0x20
2010 +#define hfc_TRM_B1_PLUS_B2 0x40
2011 +#define hfc_TRM_IOM_TEST_LOOP 0x80
2013 +/* bits in the __SSL and __RSL registers */
2014 +#define hfc_SRSL_STIO 0x40
2015 +#define hfc_SRSL_ENABLE 0x80
2016 +#define hfc_SRCL_SLOT_MASK 0x1f
2018 +/* FIFO memory definitions */
2020 +#define hfc_FIFO_SIZE 0x8000
2022 +#define hfc_UGLY_FRAMEBUF 0x2000
2024 +#define hfc_TX_FIFO_PRELOAD (DAHDI_CHUNKSIZE + 2)
2025 +#define hfc_RX_FIFO_PRELOAD 4
2028 +#define hfc_HDLC_BUF_LEN 32
2029 +/* arbitrary, just the max # of byts we will send to DAHDI per call */
2032 +/* NOTE: FIFO pointers are not declared volatile because accesses to the
2033 + * FIFOs are inherently safe.
2037 +extern int debug_level;
2042 +struct hfc_chan_simplex {
2043 + struct hfc_chan_duplex *chan;
2045 + u8 dahdi_buffer[DAHDI_CHUNKSIZE];
2047 + u8 ugly_framebuf[hfc_UGLY_FRAMEBUF];
2048 + int ugly_framebuf_size;
2049 + u16 ugly_framebuf_off;
2051 + void *z1_base, *z2_base;
2063 + unsigned long long frames;
2064 + unsigned long long bytes;
2065 + unsigned long long fifo_full;
2066 + unsigned long long crc;
2067 + unsigned long long fifo_underrun;
2070 +enum hfc_chan_status {
2078 +struct hfc_chan_duplex {
2079 + struct hfc_card *card;
2084 + enum hfc_chan_status status;
2085 + int open_by_netdev;
2086 + int open_by_dahdi;
2088 + unsigned short protocol;
2092 + struct hfc_chan_simplex rx;
2093 + struct hfc_chan_simplex tx;
2097 +typedef struct hfc_card {
2099 + struct pci_dev *pcidev;
2100 + struct dahdi_hfc *dahdi_dev;
2101 + struct proc_dir_entry *proc_dir;
2102 + char proc_dir_name[32];
2104 + struct proc_dir_entry *proc_info;
2105 + struct proc_dir_entry *proc_fifos;
2106 + struct proc_dir_entry *proc_bufs;
2108 + unsigned long io_bus_mem;
2109 + void __iomem *io_mem;
2111 + dma_addr_t fifo_bus_mem;
2116 + int sync_loss_reported;
2120 + int fifo_suspended;
2121 + int ignore_first_timer_interrupt;
2136 + struct hfc_chan_duplex chans[3];
2145 + unsigned int iomem;
2148 + unsigned char *pci_io;
2149 + void *fifomem; /* start of the shared mem */
2151 + unsigned int pcibus;
2152 + unsigned int pcidevfn;
2156 + unsigned char cardno;
2157 + struct hfc_card *next;
2161 +typedef struct dahdi_hfc {
2162 + unsigned int usecount;
2163 + struct dahdi_device *ddev;
2164 + struct dahdi_span span;
2165 + struct dahdi_chan chans[3];
2166 + struct dahdi_chan *_chans[3];
2167 + struct hfc_card *card;
2169 + /* pointer to the signalling channel for this span */
2170 + struct dahdi_chan *sigchan;
2171 + /* nonzero means we're in the middle of sending an HDLC frame */
2173 + /* hdlc_hard_xmit() increments, hdlc_tx_frame() decrements */
2174 + atomic_t hdlc_pending;
2180 +static inline struct dahdi_hfc* dahdi_hfc_from_span(struct dahdi_span *span) {
2181 + return container_of(span, struct dahdi_hfc, span);
2184 +static inline u8 hfc_inb(struct hfc_card *card, int offset)
2186 + return readb(card->io_mem + offset);
2189 +static inline void hfc_outb(struct hfc_card *card, int offset, u8 value)
2191 + writeb(value, card->io_mem + offset);
2196 +++ b/drivers/dahdi/hfcs/fifo.c
2199 + * fifo.c - HFC FIFO management routines
2201 + * Copyright (C) 2006 headissue GmbH; Jens Wilke
2202 + * Copyright (C) 2004 Daniele Orlandi
2203 + * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
2205 + * Original author of this code is
2206 + * Daniele "Vihai" Orlandi <daniele@orlandi.com>
2208 + * This program is free software and may be modified and
2209 + * distributed under the terms of the GNU Public License.
2215 +extern int debug_level;
2218 +#include <linux/kernel.h>
2220 +#include <dahdi/kernel.h>
2224 +static void hfc_fifo_mem_read(struct hfc_chan_simplex *chan,
2226 + void *data, int size)
2228 + int bytes_to_boundary = chan->z_max - z_start + 1;
2229 + if (bytes_to_boundary >= size) {
2231 + chan->z_base + z_start,
2238 + chan->z_base + z_start,
2239 + bytes_to_boundary);
2241 + memcpy(data + bytes_to_boundary,
2243 + size - bytes_to_boundary);
2247 +static void hfc_fifo_mem_write(struct hfc_chan_simplex *chan,
2248 + void *data, int size)
2250 + int bytes_to_boundary = chan->z_max - *Z1_F1(chan) + 1;
2251 + if (bytes_to_boundary >= size) {
2252 + memcpy(chan->z_base + *Z1_F1(chan),
2260 + memcpy(chan->z_base + *Z1_F1(chan),
2262 + bytes_to_boundary);
2264 + memcpy(chan->fifo_base,
2265 + data + bytes_to_boundary,
2266 + size - bytes_to_boundary);
2270 +int hfc_fifo_get(struct hfc_chan_simplex *chan,
2271 + void *data, int size)
2273 + int available_bytes;
2276 + * Some useless statistic
2278 + chan->bytes += size;
2280 + available_bytes = hfc_fifo_used_rx(chan);
2282 + if (available_bytes < size && !chan->fifo_underrun++) {
2284 + * print the warning only once
2286 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2289 + "RX FIFO not enough (%d) bytes to receive!\n",
2290 + chan->chan->card->cardnum,
2296 + hfc_fifo_mem_read(chan, *Z2_F2(chan), data, size);
2297 + *Z2_F2(chan) = Z_inc(chan, *Z2_F2(chan), size);
2298 + return available_bytes - size;
2301 +void hfc_fifo_put(struct hfc_chan_simplex *chan,
2302 + void *data, int size)
2304 + struct hfc_card *card = chan->chan->card;
2305 + int used_bytes = hfc_fifo_used_tx(chan);
2306 + int free_bytes = hfc_fifo_free_tx(chan);
2308 + if (!used_bytes && !chan->fifo_underrun++) {
2310 + * print warning only once, to make timing not worse
2312 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2315 + "TX FIFO has become empty\n",
2317 + chan->chan->name);
2319 + if (free_bytes < size) {
2320 + printk(KERN_CRIT hfc_DRIVER_PREFIX
2323 + "TX FIFO full!\n",
2324 + chan->chan->card->cardnum,
2325 + chan->chan->name);
2326 + chan->fifo_full++;
2327 + hfc_clear_fifo_tx(chan);
2330 + hfc_fifo_mem_write(chan, data, size);
2331 + chan->bytes += size;
2332 + *Z1_F1(chan) = Z_inc(chan, *Z1_F1(chan), size);
2335 +int hfc_fifo_get_frame(struct hfc_chan_simplex *chan, void *data, int max_size)
2340 + if (*chan->f1 == *chan->f2) {
2342 + * nothing received, strange uh?
2344 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2347 + "get_frame called with no frame in FIFO.\n",
2348 + chan->chan->card->cardnum,
2349 + chan->chan->name);
2355 + * frame_size includes CRC+CRC+STAT
2357 + frame_size = hfc_fifo_get_frame_size(chan);
2360 + if (debug_level == 3) {
2361 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2365 + chan->chan->card->cardnum,
2368 + } else if (debug_level >= 4) {
2369 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2372 + "RX (f1=%02x, f2=%02x, z1=%04x, z2=%04x) len %2d: ",
2373 + chan->chan->card->cardnum,
2375 + *chan->f1, *chan->f2, *Z1_F2(chan), *Z2_F2(chan),
2379 + if (debug_level >= 3) {
2381 + for (i = 0; i < frame_size; i++) {
2382 + printk("%02x", hfc_fifo_u8(chan,
2383 + Z_inc(chan, *Z2_F2(chan), i)));
2390 + if (frame_size <= 0) {
2392 + if (debug_level >= 2) {
2393 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2396 + "invalid (empty) frame received.\n",
2397 + chan->chan->card->cardnum,
2398 + chan->chan->name);
2402 + hfc_fifo_drop_frame(chan);
2407 + * STAT is not really received
2409 + chan->bytes += frame_size - 1;
2412 + * Calculate beginning of the next frame
2414 + newz2 = Z_inc(chan, *Z2_F2(chan), frame_size);
2417 + * We cannot use hfc_fifo_get because of different semantic of
2418 + * "available bytes" and to avoid useless increment of Z2
2420 + hfc_fifo_mem_read(chan, *Z2_F2(chan), data,
2421 + frame_size < max_size ? frame_size : max_size);
2423 + if (hfc_fifo_u8(chan, Z_inc(chan, *Z2_F2(chan),
2424 + frame_size - 1)) != 0x00) {
2426 + * CRC not ok, frame broken, skipping
2429 + if (debug_level >= 2) {
2430 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2433 + "Received frame with wrong CRC\n",
2434 + chan->chan->card->cardnum,
2435 + chan->chan->name);
2441 + hfc_fifo_drop_frame(chan);
2447 + *chan->f2 = F_inc(chan, *chan->f2, 1);
2450 + * Set Z2 for the next frame we're going to receive
2452 + *Z2_F2(chan) = newz2;
2454 + return frame_size;
2457 +void hfc_fifo_drop_frame(struct hfc_chan_simplex *chan)
2459 + int available_bytes;
2462 + if (*chan->f1 == *chan->f2) {
2464 + * nothing received, strange eh?
2466 + printk(KERN_WARNING hfc_DRIVER_PREFIX
2469 + "skip_frame called with no frame in FIFO.\n",
2470 + chan->chan->card->cardnum,
2471 + chan->chan->name);
2476 + available_bytes = hfc_fifo_used_rx(chan) + 1;
2479 + * Calculate beginning of the next frame
2481 + newz2 = Z_inc(chan, *Z2_F2(chan), available_bytes);
2483 + *chan->f2 = F_inc(chan, *chan->f2, 1);
2486 + * Set Z2 for the next frame we're going to receive
2488 + *Z2_F2(chan) = newz2;
2491 +void hfc_fifo_put_frame(struct hfc_chan_simplex *chan,
2492 + void *data, int size)
2495 + int available_frames;
2498 + if (debug_level == 3) {
2499 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2503 + chan->chan->card->cardnum,
2506 + } else if (debug_level >= 4) {
2507 + printk(KERN_DEBUG hfc_DRIVER_PREFIX
2510 + "TX (f1=%02x, f2=%02x, z1=%04x, z2=%04x) len %2d: ",
2511 + chan->chan->card->cardnum,
2513 + *chan->f1, *chan->f2, *Z1_F1(chan), *Z2_F1(chan),
2517 + if (debug_level >= 3) {
2519 + for (i = 0; i < size; i++)
2520 + printk("%02x", ((u8 *)data)[i]);
2526 + available_frames = hfc_fifo_free_frames(chan);
2528 + if (available_frames >= chan->f_num) {
2529 + printk(KERN_CRIT hfc_DRIVER_PREFIX
2532 + "TX FIFO total number of frames exceeded!\n",
2533 + chan->chan->card->cardnum,
2534 + chan->chan->name);
2536 + chan->fifo_full++;
2541 + hfc_fifo_put(chan, data, size);
2543 + newz1 = *Z1_F1(chan);
2545 + *chan->f1 = F_inc(chan, *chan->f1, 1);
2547 + *Z1_F1(chan) = newz1;
2552 +void hfc_clear_fifo_rx(struct hfc_chan_simplex *chan)
2554 + *chan->f2 = *chan->f1;
2555 + *Z2_F2(chan) = *Z1_F2(chan);
2558 +void hfc_clear_fifo_tx(struct hfc_chan_simplex *chan)
2560 + *chan->f1 = *chan->f2;
2561 + *Z1_F1(chan) = *Z2_F1(chan);
2563 + if (chan->chan->status == open_voice) {
2565 + * Make sure that at least hfc_TX_FIFO_PRELOAD bytes are
2566 + * present in the TX FIFOs
2567 + * Create hfc_TX_FIFO_PRELOAD bytes of empty data
2568 + * (0x7f is mute audio)
2570 + u8 empty_fifo[hfc_TX_FIFO_PRELOAD +
2571 + DAHDI_CHUNKSIZE + hfc_RX_FIFO_PRELOAD];
2572 + memset(empty_fifo, 0x7f, sizeof(empty_fifo));
2574 + hfc_fifo_put(chan, empty_fifo, sizeof(empty_fifo));
2579 +++ b/drivers/dahdi/hfcs/fifo.h
2582 + * fifo.h - Dahdi driver for HFC-S PCI A based ISDN BRI cards
2584 + * Copyright (C) 2004 Daniele Orlandi
2585 + * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
2587 + * Daniele "Vihai" Orlandi <daniele@orlandi.com>
2589 + * Major rewrite of the driver made by
2590 + * Klaus-Peter Junghanns <kpj@junghanns.net>
2592 + * This program is free software and may be modified and
2593 + * distributed under the terms of the GNU Public License.
2597 +#ifndef _HFC_FIFO_H
2598 +#define _HFC_FIFO_H
2600 +#include "dahdi_hfcs.h"
2602 +static inline u16 *Z1_F1(struct hfc_chan_simplex *chan)
2604 + return chan->z1_base + (*chan->f1 * 4);
2607 +static inline u16 *Z2_F1(struct hfc_chan_simplex *chan)
2609 + return chan->z2_base + (*chan->f1 * 4);
2612 +static inline u16 *Z1_F2(struct hfc_chan_simplex *chan)
2614 + return chan->z1_base + (*chan->f2 * 4);
2617 +static inline u16 *Z2_F2(struct hfc_chan_simplex *chan)
2619 + return chan->z2_base + (*chan->f2 * 4);
2622 +static inline u16 Z_inc(struct hfc_chan_simplex *chan, u16 z, u16 inc)
2625 + * declared as u32 in order to manage overflows
2627 + u32 newz = z + inc;
2628 + if (newz > chan->z_max)
2629 + newz -= chan->fifo_size;
2634 +static inline u8 F_inc(struct hfc_chan_simplex *chan, u8 f, u8 inc)
2637 + * declared as u16 in order to manage overflows
2639 + u16 newf = f + inc;
2640 + if (newf > chan->f_max)
2641 + newf -= chan->f_num;
2646 +static inline u16 hfc_fifo_used_rx(struct hfc_chan_simplex *chan)
2648 + return (*Z1_F2(chan) - *Z2_F2(chan) +
2649 + chan->fifo_size) % chan->fifo_size;
2652 +static inline u16 hfc_fifo_get_frame_size(struct hfc_chan_simplex *chan)
2655 + * This +1 is needed because in frame mode the available bytes are Z2-Z1+1
2656 + * while in transparent mode I wouldn't consider the byte pointed by Z2 to
2657 + * be available, otherwise, the FIFO would always contain one byte, even
2661 + return hfc_fifo_used_rx(chan) + 1;
2664 +static inline u8 hfc_fifo_u8(struct hfc_chan_simplex *chan, u16 z)
2666 + return *((u8 *)(chan->z_base + z));
2669 +static inline u16 hfc_fifo_used_tx(struct hfc_chan_simplex *chan)
2671 + return (*Z1_F1(chan) - *Z2_F1(chan) +
2672 + chan->fifo_size) % chan->fifo_size;
2675 +static inline u16 hfc_fifo_free_rx(struct hfc_chan_simplex *chan)
2677 + u16 free_bytes = *Z2_F1(chan) - *Z1_F1(chan);
2679 + if (free_bytes > 0)
2680 + return free_bytes;
2682 + return free_bytes + chan->fifo_size;
2685 +static inline u16 hfc_fifo_free_tx(struct hfc_chan_simplex *chan)
2687 + u16 free_bytes = *Z2_F1(chan) - *Z1_F1(chan);
2689 + if (free_bytes > 0)
2690 + return free_bytes;
2692 + return free_bytes + chan->fifo_size;
2695 +static inline int hfc_fifo_has_frames(struct hfc_chan_simplex *chan)
2697 + return *chan->f1 != *chan->f2;
2700 +static inline u8 hfc_fifo_used_frames(struct hfc_chan_simplex *chan)
2702 + return (*chan->f1 - *chan->f2 + chan->f_num) % chan->f_num;
2705 +static inline u8 hfc_fifo_free_frames(struct hfc_chan_simplex *chan)
2707 + return (*chan->f2 - *chan->f1 + chan->f_num) % chan->f_num;
2710 +int hfc_fifo_get(struct hfc_chan_simplex *chan, void *data, int size);
2711 +void hfc_fifo_put(struct hfc_chan_simplex *chan, void *data, int size);
2712 +void hfc_fifo_drop(struct hfc_chan_simplex *chan, int size);
2713 +int hfc_fifo_get_frame(struct hfc_chan_simplex *chan, void *data, int max_size);
2714 +void hfc_fifo_drop_frame(struct hfc_chan_simplex *chan);
2715 +void hfc_fifo_put_frame(struct hfc_chan_simplex *chan, void *data, int size);
2716 +void hfc_clear_fifo_rx(struct hfc_chan_simplex *chan);
2717 +void hfc_clear_fifo_tx(struct hfc_chan_simplex *chan);
2721 +++ b/drivers/dahdi/hfcs/Kbuild
2723 +obj-m += dahdi_hfcs.o
2725 +EXTRA_CFLAGS := -I$(src)/.. -Wno-undef
2727 +dahdi_hfcs-objs := base.o fifo.o
2729 +$(obj)/base.o: $(src)/dahdi_hfcs.h
2730 +$(obj)/fifo.o: $(src)/fifo.h