Merge branch 'for_2.6.29' of git://git.kernel.org/pub/scm/linux/kernel/git/kkeil/ISDN-2.6

* 'for_2.6.29' of git://git.kernel.org/pub/scm/linux/kernel/git/kkeil/ISDN-2.6: (28 commits)
mISDN: Add HFC USB driver
mISDN: Add layer1 prim MPH_INFORMATION_REQ
mISDN: Fix kernel crash when doing hardware conference with more than two members
mISDN: Added missing create_l1() call
mISDN: Add MODULE_DEVICE_TABLE() to hfcpci
mISDN: Minor cleanups
mISDN: Create /sys/class/mISDN
mISDN: Add missing release functions
mISDN: Add different different timer settings for hfc-pci
mISDN: Minor fixes
mISDN: Correct busy device detection
mISDN: Fix deactivation, if peer IP is removed from l1oip instance.
mISDN: Add ISDN_P_TE_UP0 / ISDN_P_NT_UP0
mISDN: Fix irq detection
mISDN: Add ISDN sample clock API to mISDN core
mISDN: Return error on E-channel access
mISDN: Add E-Channel logging features
mISDN: Use protocol to detect D-channel
mISDN: Fixed more indexing bugs
mISDN: Make debug output a little bit more verbose
...

+3734 -379
+7
drivers/isdn/hardware/mISDN/Kconfig
··· 23 23 * HFC-8S (8 S/T interfaces on one chip) 24 24 * HFC-E1 (E1 interface for 2Mbit ISDN) 25 25 26 + config MISDN_HFCUSB 27 + tristate "Support for HFC-S USB based TAs" 28 + depends on USB 29 + help 30 + Enable support for USB ISDN TAs with Cologne Chip AG's 31 + HFC-S USB ISDN Controller 32 +
+1
drivers/isdn/hardware/mISDN/Makefile
··· 5 5 6 6 obj-$(CONFIG_MISDN_HFCPCI) += hfcpci.o 7 7 obj-$(CONFIG_MISDN_HFCMULTI) += hfcmulti.o 8 + obj-$(CONFIG_MISDN_HFCUSB) += hfcsusb.o
+6 -4
drivers/isdn/hardware/mISDN/hfc_multi.h
··· 2 2 * see notice in hfc_multi.c 3 3 */ 4 4 5 - extern void ztdummy_extern_interrupt(void); 6 - extern void ztdummy_register_interrupt(void); 7 - extern int ztdummy_unregister_interrupt(void); 8 - 9 5 #define DEBUG_HFCMULTI_FIFO 0x00010000 10 6 #define DEBUG_HFCMULTI_CRC 0x00020000 11 7 #define DEBUG_HFCMULTI_INIT 0x00040000 ··· 9 13 #define DEBUG_HFCMULTI_MODE 0x00100000 10 14 #define DEBUG_HFCMULTI_MSG 0x00200000 11 15 #define DEBUG_HFCMULTI_STATE 0x00400000 16 + #define DEBUG_HFCMULTI_FILL 0x00800000 12 17 #define DEBUG_HFCMULTI_SYNC 0x01000000 13 18 #define DEBUG_HFCMULTI_DTMF 0x02000000 14 19 #define DEBUG_HFCMULTI_LOCK 0x80000000 ··· 167 170 168 171 u_long chip; /* chip configuration */ 169 172 int masterclk; /* port that provides master clock -1=off */ 173 + unsigned char silence;/* silence byte */ 174 + unsigned char silence_data[128];/* silence block */ 170 175 int dtmf; /* flag that dtmf is currently in process */ 171 176 int Flen; /* F-buffer size */ 172 177 int Zlen; /* Z-buffer size (must be int for calculation)*/ ··· 196 197 int e1_resync; /* resync jobs */ 197 198 198 199 spinlock_t lock; /* the lock */ 200 + 201 + struct mISDNclock *iclock; /* isdn clock support */ 202 + int iclock_on; 199 203 200 204 /* 201 205 * the channel index is counted from 0, regardless where the channel
+1 -1
drivers/isdn/hardware/mISDN/hfc_pci.h
··· 26 26 * change mask and threshold simultaneously 27 27 */ 28 28 #define HFCPCI_BTRANS_THRESHOLD 128 29 - #define HFCPCI_BTRANS_MAX 256 29 + #define HFCPCI_FILLEMPTY 64 30 30 #define HFCPCI_BTRANS_THRESMASK 0x00 31 31 32 32 /* defines for PCI config */
+101 -105
drivers/isdn/hardware/mISDN/hfcmulti.c
··· 133 133 * Give the value of the clock control register (A_ST_CLK_DLY) 134 134 * of the S/T interfaces in TE mode. 135 135 * This register is needed for the TBR3 certification, so don't change it. 136 + * 137 + * clock: 138 + * NOTE: only one clock value must be given once 139 + * Selects interface with clock source for mISDN and applications. 140 + * Set to card number starting with 1. Set to -1 to disable. 141 + * By default, the first card is used as clock source. 136 142 */ 137 143 138 144 /* ··· 146 140 * #define HFC_REGISTER_DEBUG 147 141 */ 148 142 149 - static const char *hfcmulti_revision = "2.02"; 143 + #define HFC_MULTI_VERSION "2.03" 150 144 151 145 #include <linux/module.h> 152 146 #include <linux/pci.h> ··· 171 165 static spinlock_t HFClock; /* global hfc list lock */ 172 166 173 167 static void ph_state_change(struct dchannel *); 174 - static void (*hfc_interrupt)(void); 175 - static void (*register_interrupt)(void); 176 - static int (*unregister_interrupt)(void); 177 - static int interrupt_registered; 178 168 179 169 static struct hfc_multi *syncmaster; 180 170 static int plxsd_master; /* if we have a master card (yet) */ ··· 186 184 #define CLKDEL_TE 0x0f /* CLKDEL in TE mode */ 187 185 #define CLKDEL_NT 0x6c /* CLKDEL in NT mode 188 186 (0x60 MUST be included!) */ 189 - static u_char silence = 0xff; /* silence by LAW */ 190 187 191 188 #define DIP_4S 0x1 /* DIP Switches for Beronet 1S/2S/4S cards */ 192 189 #define DIP_8S 0x2 /* DIP Switches for Beronet 8S+ cards */ ··· 196 195 */ 197 196 198 197 static uint type[MAX_CARDS]; 199 - static uint pcm[MAX_CARDS]; 200 - static uint dslot[MAX_CARDS]; 198 + static int pcm[MAX_CARDS]; 199 + static int dslot[MAX_CARDS]; 201 200 static uint iomode[MAX_CARDS]; 202 201 static uint port[MAX_PORTS]; 203 202 static uint debug; 204 203 static uint poll; 204 + static int clock; 205 205 static uint timer; 206 206 static uint clockdelay_te = CLKDEL_TE; 207 207 static uint clockdelay_nt = CLKDEL_NT; ··· 211 209 212 210 MODULE_AUTHOR("Andreas Eversberg"); 213 211 MODULE_LICENSE("GPL"); 212 + MODULE_VERSION(HFC_MULTI_VERSION); 214 213 module_param(debug, uint, S_IRUGO | S_IWUSR); 215 214 module_param(poll, uint, S_IRUGO | S_IWUSR); 215 + module_param(clock, int, S_IRUGO | S_IWUSR); 216 216 module_param(timer, uint, S_IRUGO | S_IWUSR); 217 217 module_param(clockdelay_te, uint, S_IRUGO | S_IWUSR); 218 218 module_param(clockdelay_nt, uint, S_IRUGO | S_IWUSR); 219 219 module_param_array(type, uint, NULL, S_IRUGO | S_IWUSR); 220 - module_param_array(pcm, uint, NULL, S_IRUGO | S_IWUSR); 221 - module_param_array(dslot, uint, NULL, S_IRUGO | S_IWUSR); 220 + module_param_array(pcm, int, NULL, S_IRUGO | S_IWUSR); 221 + module_param_array(dslot, int, NULL, S_IRUGO | S_IWUSR); 222 222 module_param_array(iomode, uint, NULL, S_IRUGO | S_IWUSR); 223 223 module_param_array(port, uint, NULL, S_IRUGO | S_IWUSR); 224 224 ··· 1423 1419 HFC_outb(hc, R_TI_WD, poll_timer); 1424 1420 hc->hw.r_irqmsk_misc |= V_TI_IRQMSK; 1425 1421 1426 - /* 1427 - * set up 125us interrupt, only if function pointer is available 1428 - * and module parameter timer is set 1429 - */ 1430 - if (timer && hfc_interrupt && register_interrupt) { 1431 - /* only one chip should use this interrupt */ 1432 - timer = 0; 1433 - interrupt_registered = 1; 1434 - hc->hw.r_irqmsk_misc |= V_PROC_IRQMSK; 1435 - /* deactivate other interrupts in ztdummy */ 1436 - register_interrupt(); 1437 - } 1438 - 1439 1422 /* set E1 state machine IRQ */ 1440 1423 if (hc->type == 1) 1441 1424 hc->hw.r_irqmsk_misc |= V_STA_IRQMSK; ··· 1982 1991 return; /* no data */ 1983 1992 } 1984 1993 1994 + /* "fill fifo if empty" feature */ 1995 + if (bch && test_bit(FLG_FILLEMPTY, &bch->Flags) 1996 + && !test_bit(FLG_HDLC, &bch->Flags) && z2 == z1) { 1997 + if (debug & DEBUG_HFCMULTI_FILL) 1998 + printk(KERN_DEBUG "%s: buffer empty, so we have " 1999 + "underrun\n", __func__); 2000 + /* fill buffer, to prevent future underrun */ 2001 + hc->write_fifo(hc, hc->silence_data, poll >> 1); 2002 + Zspace -= (poll >> 1); 2003 + } 2004 + 1985 2005 /* if audio data and connected slot */ 1986 2006 if (bch && (!test_bit(FLG_HDLC, &bch->Flags)) && (!*txpending) 1987 2007 && slot_tx >= 0) { ··· 2028 2026 "left (z1=%04x, z2=%04x) sending %d of %d bytes %s\n", 2029 2027 __func__, hc->id + 1, ch, Zspace, z1, z2, ii-i, len-i, 2030 2028 temp ? "HDLC":"TRANS"); 2031 - 2032 2029 2033 2030 /* Have to prep the audio data */ 2034 2031 hc->write_fifo(hc, d, ii - i); ··· 2067 2066 * no more data at all. this prevents sending an undefined value. 2068 2067 */ 2069 2068 if (bch && test_bit(FLG_TRANSPARENT, &bch->Flags)) 2070 - HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, silence); 2069 + HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, hc->silence); 2071 2070 } 2072 2071 2073 2072 ··· 2584 2583 static int iq1 = 0, iq2 = 0, iq3 = 0, iq4 = 0, 2585 2584 iq5 = 0, iq6 = 0, iqcnt = 0; 2586 2585 #endif 2587 - static int count; 2588 2586 struct hfc_multi *hc = dev_id; 2589 2587 struct dchannel *dch; 2590 2588 u_char r_irq_statech, status, r_irq_misc, r_irq_oview; ··· 2637 2637 iqcnt = 0; 2638 2638 } 2639 2639 #endif 2640 + 2640 2641 if (!r_irq_statech && 2641 2642 !(status & (V_DTMF_STA | V_LOST_STA | V_EXT_IRQSTA | 2642 2643 V_MISC_IRQSTA | V_FR_IRQSTA))) { ··· 2658 2657 if (status & V_MISC_IRQSTA) { 2659 2658 /* misc IRQ */ 2660 2659 r_irq_misc = HFC_inb_nodebug(hc, R_IRQ_MISC); 2660 + r_irq_misc &= hc->hw.r_irqmsk_misc; /* ignore disabled irqs */ 2661 2661 if (r_irq_misc & V_STA_IRQ) { 2662 2662 if (hc->type == 1) { 2663 2663 /* state machine */ ··· 2693 2691 plxsd_checksync(hc, 0); 2694 2692 } 2695 2693 } 2696 - if (r_irq_misc & V_TI_IRQ) 2694 + if (r_irq_misc & V_TI_IRQ) { 2695 + if (hc->iclock_on) 2696 + mISDN_clock_update(hc->iclock, poll, NULL); 2697 2697 handle_timer_irq(hc); 2698 + } 2698 2699 2699 2700 if (r_irq_misc & V_DTMF_IRQ) { 2700 - /* -> DTMF IRQ */ 2701 2701 hfcmulti_dtmf(hc); 2702 2702 } 2703 - /* TODO: REPLACE !!!! 125 us Interrupts are not acceptable */ 2704 2703 if (r_irq_misc & V_IRQ_PROC) { 2705 - /* IRQ every 125us */ 2706 - count++; 2707 - /* generate 1kHz signal */ 2708 - if (count == 8) { 2709 - if (hfc_interrupt) 2710 - hfc_interrupt(); 2711 - count = 0; 2712 - } 2704 + static int irq_proc_cnt; 2705 + if (!irq_proc_cnt++) 2706 + printk(KERN_WARNING "%s: got V_IRQ_PROC -" 2707 + " this should not happen\n", __func__); 2713 2708 } 2714 2709 2715 2710 } ··· 2953 2954 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F); 2954 2955 HFC_wait(hc); 2955 2956 /* tx silence */ 2956 - HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, silence); 2957 + HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, hc->silence); 2957 2958 HFC_outb(hc, R_SLOT, (((ch / 4) * 8) + 2958 2959 ((ch % 4) * 4)) << 1); 2959 2960 HFC_outb(hc, A_SL_CFG, 0x80 | 0x20 | (ch << 1)); ··· 2968 2969 HFC_outb(hc, R_INC_RES_FIFO, V_RES_F); 2969 2970 HFC_wait(hc); 2970 2971 /* tx silence */ 2971 - HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, silence); 2972 + HFC_outb_nodebug(hc, A_FIFO_DATA0_NOINC, hc->silence); 2972 2973 /* enable RX fifo */ 2973 2974 HFC_outb(hc, R_FIFO, (ch<<1)|1); 2974 2975 HFC_wait(hc); ··· 3460 3461 switch (cq->op) { 3461 3462 case MISDN_CTRL_GETOP: 3462 3463 cq->op = MISDN_CTRL_HFC_OP | MISDN_CTRL_HW_FEATURES_OP 3463 - | MISDN_CTRL_RX_OFF; 3464 + | MISDN_CTRL_RX_OFF | MISDN_CTRL_FILL_EMPTY; 3464 3465 break; 3465 3466 case MISDN_CTRL_RX_OFF: /* turn off / on rx stream */ 3466 3467 hc->chan[bch->slot].rx_off = !!cq->p1; ··· 3474 3475 if (debug & DEBUG_HFCMULTI_MSG) 3475 3476 printk(KERN_DEBUG "%s: RX_OFF request (nr=%d off=%d)\n", 3476 3477 __func__, bch->nr, hc->chan[bch->slot].rx_off); 3478 + break; 3479 + case MISDN_CTRL_FILL_EMPTY: /* fill fifo, if empty */ 3480 + test_and_set_bit(FLG_FILLEMPTY, &bch->Flags); 3481 + if (debug & DEBUG_HFCMULTI_MSG) 3482 + printk(KERN_DEBUG "%s: FILL_EMPTY request (nr=%d " 3483 + "off=%d)\n", __func__, bch->nr, !!cq->p1); 3477 3484 break; 3478 3485 case MISDN_CTRL_HW_FEATURES: /* fill features structure */ 3479 3486 if (debug & DEBUG_HFCMULTI_MSG) ··· 3997 3992 } 3998 3993 if (test_and_set_bit(FLG_OPEN, &bch->Flags)) 3999 3994 return -EBUSY; /* b-channel can be only open once */ 3995 + test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags); 4000 3996 bch->ch.protocol = rq->protocol; 4001 3997 hc->chan[ch].rx_off = 0; 4002 3998 rq->ch = &bch->ch; ··· 4085 4079 err = -EINVAL; 4086 4080 } 4087 4081 return err; 4082 + } 4083 + 4084 + static int 4085 + clockctl(void *priv, int enable) 4086 + { 4087 + struct hfc_multi *hc = priv; 4088 + 4089 + hc->iclock_on = enable; 4090 + return 0; 4088 4091 } 4089 4092 4090 4093 /* ··· 4510 4495 printk(KERN_WARNING "%s: release card (%d) entered\n", 4511 4496 __func__, hc->id); 4512 4497 4498 + /* unregister clock source */ 4499 + if (hc->iclock) 4500 + mISDN_unregister_clock(hc->iclock); 4501 + 4502 + /* disable irq */ 4513 4503 spin_lock_irqsave(&hc->lock, flags); 4514 4504 disable_hwirq(hc); 4515 4505 spin_unlock_irqrestore(&hc->lock, flags); 4516 - 4517 4506 udelay(1000); 4518 4507 4519 4508 /* dimm leds */ ··· 4718 4699 } else 4719 4700 hc->chan[hc->dslot].jitter = 2; /* default */ 4720 4701 snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-e1.%d", HFC_cnt + 1); 4721 - ret = mISDN_register_device(&dch->dev, name); 4702 + ret = mISDN_register_device(&dch->dev, &hc->pci_dev->dev, name); 4722 4703 if (ret) 4723 4704 goto free_chan; 4724 4705 hc->created[0] = 1; ··· 4826 4807 test_and_set_bit(HFC_CFG_DIS_ECHANNEL, 4827 4808 &hc->chan[i + 2].cfg); 4828 4809 } 4829 - snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-%ds.%d/%d", 4810 + snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-%ds.%d-%d", 4830 4811 hc->type, HFC_cnt + 1, pt + 1); 4831 - ret = mISDN_register_device(&dch->dev, name); 4812 + ret = mISDN_register_device(&dch->dev, &hc->pci_dev->dev, name); 4832 4813 if (ret) 4833 4814 goto free_chan; 4834 4815 hc->created[pt] = 1; ··· 4847 4828 struct hfc_multi *hc; 4848 4829 u_long flags; 4849 4830 u_char dips = 0, pmj = 0; /* dip settings, port mode Jumpers */ 4831 + int i; 4850 4832 4851 4833 if (HFC_cnt >= MAX_CARDS) { 4852 4834 printk(KERN_ERR "too many cards (max=%d).\n", ··· 4881 4861 hc->id = HFC_cnt; 4882 4862 hc->pcm = pcm[HFC_cnt]; 4883 4863 hc->io_mode = iomode[HFC_cnt]; 4884 - if (dslot[HFC_cnt] < 0) { 4864 + if (dslot[HFC_cnt] < 0 && hc->type == 1) { 4885 4865 hc->dslot = 0; 4886 4866 printk(KERN_INFO "HFC-E1 card has disabled D-channel, but " 4887 4867 "31 B-channels\n"); 4888 - } if (dslot[HFC_cnt] > 0 && dslot[HFC_cnt] < 32) { 4868 + } if (dslot[HFC_cnt] > 0 && dslot[HFC_cnt] < 32 && hc->type == 1) { 4889 4869 hc->dslot = dslot[HFC_cnt]; 4890 4870 printk(KERN_INFO "HFC-E1 card has alternating D-channel on " 4891 4871 "time slot %d\n", dslot[HFC_cnt]); ··· 4896 4876 hc->masterclk = -1; 4897 4877 if (type[HFC_cnt] & 0x100) { 4898 4878 test_and_set_bit(HFC_CHIP_ULAW, &hc->chip); 4899 - silence = 0xff; /* ulaw silence */ 4879 + hc->silence = 0xff; /* ulaw silence */ 4900 4880 } else 4901 - silence = 0x2a; /* alaw silence */ 4881 + hc->silence = 0x2a; /* alaw silence */ 4882 + if ((poll >> 1) > sizeof(hc->silence_data)) { 4883 + printk(KERN_ERR "HFCMULTI error: silence_data too small, " 4884 + "please fix\n"); 4885 + return -EINVAL; 4886 + } 4887 + for (i = 0; i < (poll >> 1); i++) 4888 + hc->silence_data[i] = hc->silence; 4889 + 4902 4890 if (!(type[HFC_cnt] & 0x200)) 4903 4891 test_and_set_bit(HFC_CHIP_DTMF, &hc->chip); 4904 4892 ··· 4973 4945 switch (m->dip_type) { 4974 4946 case DIP_4S: 4975 4947 /* 4976 - * get DIP Setting for beroNet 1S/2S/4S cards 4977 - * check if Port Jumper config matches 4978 - * module param 'protocol' 4948 + * Get DIP setting for beroNet 1S/2S/4S cards 4979 4949 * DIP Setting: (collect GPIO 13/14/15 (R_GPIO_IN1) + 4980 4950 * GPI 19/23 (R_GPI_IN2)) 4981 4951 */ ··· 4992 4966 break; 4993 4967 case DIP_8S: 4994 4968 /* 4995 - * get DIP Setting for beroNet 8S0+ cards 4996 - * 4997 - * enable PCI auxbridge function 4969 + * Get DIP Setting for beroNet 8S0+ cards 4970 + * Enable PCI auxbridge function 4998 4971 */ 4999 4972 HFC_outb(hc, R_BRG_PCM_CFG, 1 | V_PCM_CLK); 5000 4973 /* prepare access to auxport */ ··· 5027 5002 spin_lock_irqsave(&HFClock, flags); 5028 5003 list_add_tail(&hc->list, &HFClist); 5029 5004 spin_unlock_irqrestore(&HFClock, flags); 5005 + 5006 + /* use as clock source */ 5007 + if (clock == HFC_cnt + 1) 5008 + hc->iclock = mISDN_register_clock("HFCMulti", 0, clockctl, hc); 5030 5009 5031 5010 /* initialize hardware */ 5032 5011 ret_err = init_card(hc); ··· 5166 5137 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD, 5167 5138 PCI_DEVICE_ID_CCD_HFC8S, 0, 0, H(14)}, /* old Eval */ 5168 5139 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD, 5169 - PCI_SUBDEVICE_ID_CCD_IOB8STR, 0, 0, H(15)}, 5170 - /* IOB8ST Recording */ 5140 + PCI_SUBDEVICE_ID_CCD_IOB8STR, 0, 0, H(15)}, /* IOB8ST Recording */ 5171 5141 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD, 5172 5142 PCI_SUBDEVICE_ID_CCD_IOB8ST, 0, 0, H(16)}, /* IOB8ST */ 5173 5143 { PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_HFC8S, PCI_VENDOR_ID_CCD, ··· 5216 5188 struct hm_map *m = (struct hm_map *)ent->driver_data; 5217 5189 int ret; 5218 5190 5219 - if (m == NULL) { 5220 - if (ent->vendor == PCI_VENDOR_ID_CCD) 5221 - if (ent->device == PCI_DEVICE_ID_CCD_HFC4S || 5222 - ent->device == PCI_DEVICE_ID_CCD_HFC8S || 5223 - ent->device == PCI_DEVICE_ID_CCD_HFCE1) 5224 - printk(KERN_ERR 5225 - "unknown HFC multiport controller " 5226 - "(vendor:%x device:%x subvendor:%x " 5227 - "subdevice:%x) Please contact the " 5228 - "driver maintainer for support.\n", 5229 - ent->vendor, ent->device, 5230 - ent->subvendor, ent->subdevice); 5191 + if (m == NULL && ent->vendor == PCI_VENDOR_ID_CCD && ( 5192 + ent->device == PCI_DEVICE_ID_CCD_HFC4S || 5193 + ent->device == PCI_DEVICE_ID_CCD_HFC8S || 5194 + ent->device == PCI_DEVICE_ID_CCD_HFCE1)) { 5195 + printk(KERN_ERR 5196 + "Unknown HFC multiport controller (vendor:%x device:%x " 5197 + "subvendor:%x subdevice:%x)\n", ent->vendor, ent->device, 5198 + ent->subvendor, ent->subdevice); 5199 + printk(KERN_ERR 5200 + "Please contact the driver maintainer for support.\n"); 5231 5201 return -ENODEV; 5232 5202 } 5233 5203 ret = hfcmulti_init(pdev, ent); ··· 5248 5222 { 5249 5223 struct hfc_multi *card, *next; 5250 5224 5251 - /* unload interrupt function symbol */ 5252 - if (hfc_interrupt) 5253 - symbol_put(ztdummy_extern_interrupt); 5254 - if (register_interrupt) 5255 - symbol_put(ztdummy_register_interrupt); 5256 - if (unregister_interrupt) { 5257 - if (interrupt_registered) { 5258 - interrupt_registered = 0; 5259 - unregister_interrupt(); 5260 - } 5261 - symbol_put(ztdummy_unregister_interrupt); 5262 - } 5263 - 5225 + /* get rid of all devices of this driver */ 5264 5226 list_for_each_entry_safe(card, next, &HFClist, list) 5265 5227 release_card(card); 5266 - /* get rid of all devices of this driver */ 5267 5228 pci_unregister_driver(&hfcmultipci_driver); 5268 5229 } 5269 5230 ··· 5259 5246 { 5260 5247 int err; 5261 5248 5249 + printk(KERN_INFO "mISDN: HFC-multi driver %s\n", HFC_MULTI_VERSION); 5250 + 5262 5251 #ifdef IRQ_DEBUG 5263 - printk(KERN_ERR "%s: IRQ_DEBUG IS ENABLED!\n", __func__); 5252 + printk(KERN_DEBUG "%s: IRQ_DEBUG IS ENABLED!\n", __func__); 5264 5253 #endif 5265 5254 5266 5255 spin_lock_init(&HFClock); ··· 5271 5256 if (debug & DEBUG_HFCMULTI_INIT) 5272 5257 printk(KERN_DEBUG "%s: init entered\n", __func__); 5273 5258 5274 - hfc_interrupt = symbol_get(ztdummy_extern_interrupt); 5275 - register_interrupt = symbol_get(ztdummy_register_interrupt); 5276 - unregister_interrupt = symbol_get(ztdummy_unregister_interrupt); 5277 - printk(KERN_INFO "mISDN: HFC-multi driver %s\n", 5278 - hfcmulti_revision); 5279 - 5280 5259 switch (poll) { 5281 5260 case 0: 5282 5261 poll_timer = 6; 5283 5262 poll = 128; 5284 5263 break; 5285 - /* 5286 - * wenn dieses break nochmal verschwindet, 5287 - * gibt es heisse ohren :-) 5288 - * "without the break you will get hot ears ???" 5289 - */ 5290 5264 case 8: 5291 5265 poll_timer = 2; 5292 5266 break; ··· 5302 5298 5303 5299 } 5304 5300 5301 + if (!clock) 5302 + clock = 1; 5303 + 5305 5304 err = pci_register_driver(&hfcmultipci_driver); 5306 5305 if (err < 0) { 5307 5306 printk(KERN_ERR "error registering pci driver: %x\n", err); 5308 - if (hfc_interrupt) 5309 - symbol_put(ztdummy_extern_interrupt); 5310 - if (register_interrupt) 5311 - symbol_put(ztdummy_register_interrupt); 5312 - if (unregister_interrupt) { 5313 - if (interrupt_registered) { 5314 - interrupt_registered = 0; 5315 - unregister_interrupt(); 5316 - } 5317 - symbol_put(ztdummy_unregister_interrupt); 5318 - } 5319 5307 return err; 5320 5308 } 5321 5309 return 0;
+185 -54
drivers/isdn/hardware/mISDN/hfcpci.c
··· 23 23 * along with this program; if not, write to the Free Software 24 24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 25 * 26 + * Module options: 27 + * 28 + * debug: 29 + * NOTE: only one poll value must be given for all cards 30 + * See hfc_pci.h for debug flags. 31 + * 32 + * poll: 33 + * NOTE: only one poll value must be given for all cards 34 + * Give the number of samples for each fifo process. 35 + * By default 128 is used. Decrease to reduce delay, increase to 36 + * reduce cpu load. If unsure, don't mess with it! 37 + * A value of 128 will use controller's interrupt. Other values will 38 + * use kernel timer, because the controller will not allow lower values 39 + * than 128. 40 + * Also note that the value depends on the kernel timer frequency. 41 + * If kernel uses a frequency of 1000 Hz, steps of 8 samples are possible. 42 + * If the kernel uses 100 Hz, steps of 80 samples are possible. 43 + * If the kernel uses 300 Hz, steps of about 26 samples are possible. 44 + * 26 45 */ 27 46 28 47 #include <linux/module.h> ··· 53 34 54 35 static const char *hfcpci_revision = "2.0"; 55 36 56 - #define MAX_CARDS 8 57 37 static int HFC_cnt; 58 38 static uint debug; 39 + static uint poll, tics; 40 + struct timer_list hfc_tl; 41 + u32 hfc_jiffies; 59 42 60 43 MODULE_AUTHOR("Karsten Keil"); 61 44 MODULE_LICENSE("GPL"); 62 45 module_param(debug, uint, 0); 63 - 64 - static LIST_HEAD(HFClist); 65 - static DEFINE_RWLOCK(HFClock); 46 + module_param(poll, uint, S_IRUGO | S_IWUSR); 66 47 67 48 enum { 68 49 HFC_CCD_2BD0, ··· 133 114 134 115 135 116 struct hfc_pci { 136 - struct list_head list; 137 117 u_char subtype; 138 118 u_char chanlimit; 139 119 u_char initdone; ··· 538 520 } 539 521 540 522 /* 541 - * check for transparent receive data and read max one threshold size if avail 523 + * check for transparent receive data and read max one 'poll' size if avail 542 524 */ 543 - static int 525 + static void 544 526 hfcpci_empty_fifo_trans(struct bchannel *bch, struct bzfifo *bz, u_char *bdata) 545 527 { 546 528 __le16 *z1r, *z2r; ··· 552 534 553 535 fcnt = le16_to_cpu(*z1r) - le16_to_cpu(*z2r); 554 536 if (!fcnt) 555 - return 0; /* no data avail */ 537 + return; /* no data avail */ 556 538 557 539 if (fcnt <= 0) 558 540 fcnt += B_FIFO_SIZE; /* bytes actually buffered */ 559 - if (fcnt > HFCPCI_BTRANS_THRESHOLD) 560 - fcnt = HFCPCI_BTRANS_THRESHOLD; /* limit size */ 561 - 562 541 new_z2 = le16_to_cpu(*z2r) + fcnt; /* new position in fifo */ 563 542 if (new_z2 >= (B_FIFO_SIZE + B_SUB_VAL)) 564 543 new_z2 -= B_FIFO_SIZE; /* buffer wrap */ 544 + 545 + if (fcnt > MAX_DATA_SIZE) { /* flush, if oversized */ 546 + *z2r = cpu_to_le16(new_z2); /* new position */ 547 + return; 548 + } 565 549 566 550 bch->rx_skb = mI_alloc_skb(fcnt, GFP_ATOMIC); 567 551 if (bch->rx_skb) { ··· 589 569 printk(KERN_WARNING "HFCPCI: receive out of memory\n"); 590 570 591 571 *z2r = cpu_to_le16(new_z2); /* new position */ 592 - return 1; 593 572 } 594 573 595 574 /* ··· 599 580 { 600 581 struct hfc_pci *hc = bch->hw; 601 582 int rcnt, real_fifo; 602 - int receive, count = 5; 583 + int receive = 0, count = 5; 603 584 struct bzfifo *bz; 604 585 u_char *bdata; 605 586 struct zt *zp; 606 - 607 587 608 588 if ((bch->nr & 2) && (!hc->hw.bswapped)) { 609 589 bz = &((union fifo_area *)(hc->hw.fifos))->b_chans.rxbz_b2; ··· 643 625 receive = 1; 644 626 else 645 627 receive = 0; 646 - } else if (test_bit(FLG_TRANSPARENT, &bch->Flags)) 647 - receive = hfcpci_empty_fifo_trans(bch, bz, bdata); 648 - else 628 + } else if (test_bit(FLG_TRANSPARENT, &bch->Flags)) { 629 + hfcpci_empty_fifo_trans(bch, bz, bdata); 630 + return; 631 + } else 649 632 receive = 0; 650 633 if (count && receive) 651 634 goto Begin; ··· 770 751 /* fcnt contains available bytes in fifo */ 771 752 fcnt = B_FIFO_SIZE - fcnt; 772 753 /* remaining bytes to send (bytes in fifo) */ 754 + 755 + /* "fill fifo if empty" feature */ 756 + if (test_bit(FLG_FILLEMPTY, &bch->Flags) && !fcnt) { 757 + /* printk(KERN_DEBUG "%s: buffer empty, so we have " 758 + "underrun\n", __func__); */ 759 + /* fill buffer, to prevent future underrun */ 760 + count = HFCPCI_FILLEMPTY; 761 + new_z1 = le16_to_cpu(*z1t) + count; 762 + /* new buffer Position */ 763 + if (new_z1 >= (B_FIFO_SIZE + B_SUB_VAL)) 764 + new_z1 -= B_FIFO_SIZE; /* buffer wrap */ 765 + dst = bdata + (le16_to_cpu(*z1t) - B_SUB_VAL); 766 + maxlen = (B_FIFO_SIZE + B_SUB_VAL) - le16_to_cpu(*z1t); 767 + /* end of fifo */ 768 + if (bch->debug & DEBUG_HW_BFIFO) 769 + printk(KERN_DEBUG "hfcpci_FFt fillempty " 770 + "fcnt(%d) maxl(%d) nz1(%x) dst(%p)\n", 771 + fcnt, maxlen, new_z1, dst); 772 + fcnt += count; 773 + if (maxlen > count) 774 + maxlen = count; /* limit size */ 775 + memset(dst, 0x2a, maxlen); /* first copy */ 776 + count -= maxlen; /* remaining bytes */ 777 + if (count) { 778 + dst = bdata; /* start of buffer */ 779 + memset(dst, 0x2a, count); 780 + } 781 + *z1t = cpu_to_le16(new_z1); /* now send data */ 782 + } 783 + 773 784 next_t_frame: 774 785 count = bch->tx_skb->len - bch->tx_idx; 775 - /* maximum fill shall be HFCPCI_BTRANS_MAX */ 776 - if (count > HFCPCI_BTRANS_MAX - fcnt) 777 - count = HFCPCI_BTRANS_MAX - fcnt; 786 + /* maximum fill shall be poll*2 */ 787 + if (count > (poll << 1) - fcnt) 788 + count = (poll << 1) - fcnt; 778 789 if (count <= 0) 779 790 return; 780 791 /* data is suitable for fifo */ ··· 1184 1135 val &= ~0x80; 1185 1136 Write_hfc(hc, HFCPCI_CTMT, hc->hw.ctmt | HFCPCI_CLTIMER); 1186 1137 } 1187 - if (val & 0x08) { 1138 + if (val & 0x08) { /* B1 rx */ 1188 1139 bch = Sel_BCS(hc, hc->hw.bswapped ? 2 : 1); 1189 1140 if (bch) 1190 1141 main_rec_hfcpci(bch); 1191 1142 else if (hc->dch.debug) 1192 1143 printk(KERN_DEBUG "hfcpci spurious 0x08 IRQ\n"); 1193 1144 } 1194 - if (val & 0x10) { 1145 + if (val & 0x10) { /* B2 rx */ 1195 1146 bch = Sel_BCS(hc, 2); 1196 1147 if (bch) 1197 1148 main_rec_hfcpci(bch); 1198 1149 else if (hc->dch.debug) 1199 1150 printk(KERN_DEBUG "hfcpci spurious 0x10 IRQ\n"); 1200 1151 } 1201 - if (val & 0x01) { 1152 + if (val & 0x01) { /* B1 tx */ 1202 1153 bch = Sel_BCS(hc, hc->hw.bswapped ? 2 : 1); 1203 1154 if (bch) 1204 1155 tx_birq(bch); 1205 1156 else if (hc->dch.debug) 1206 1157 printk(KERN_DEBUG "hfcpci spurious 0x01 IRQ\n"); 1207 1158 } 1208 - if (val & 0x02) { 1159 + if (val & 0x02) { /* B2 tx */ 1209 1160 bch = Sel_BCS(hc, 2); 1210 1161 if (bch) 1211 1162 tx_birq(bch); 1212 1163 else if (hc->dch.debug) 1213 1164 printk(KERN_DEBUG "hfcpci spurious 0x02 IRQ\n"); 1214 1165 } 1215 - if (val & 0x20) 1166 + if (val & 0x20) /* D rx */ 1216 1167 receive_dmsg(hc); 1217 - if (val & 0x04) { /* dframe transmitted */ 1168 + if (val & 0x04) { /* D tx */ 1218 1169 if (test_and_clear_bit(FLG_BUSY_TIMER, &hc->dch.Flags)) 1219 1170 del_timer(&hc->dch.timer); 1220 1171 tx_dirq(&hc->dch); ··· 1332 1283 } 1333 1284 if (fifo2 & 2) { 1334 1285 hc->hw.fifo_en |= HFCPCI_FIFOEN_B2; 1335 - hc->hw.int_m1 |= (HFCPCI_INTS_B2TRANS + 1336 - HFCPCI_INTS_B2REC); 1286 + if (!tics) 1287 + hc->hw.int_m1 |= (HFCPCI_INTS_B2TRANS + 1288 + HFCPCI_INTS_B2REC); 1337 1289 hc->hw.ctmt |= 2; 1338 1290 hc->hw.conn &= ~0x18; 1339 1291 } else { 1340 1292 hc->hw.fifo_en |= HFCPCI_FIFOEN_B1; 1341 - hc->hw.int_m1 |= (HFCPCI_INTS_B1TRANS + 1342 - HFCPCI_INTS_B1REC); 1293 + if (!tics) 1294 + hc->hw.int_m1 |= (HFCPCI_INTS_B1TRANS + 1295 + HFCPCI_INTS_B1REC); 1343 1296 hc->hw.ctmt |= 1; 1344 1297 hc->hw.conn &= ~0x03; 1345 1298 } ··· 1449 1398 if (chan & 2) { 1450 1399 hc->hw.sctrl_r |= SCTRL_B2_ENA; 1451 1400 hc->hw.fifo_en |= HFCPCI_FIFOEN_B2RX; 1452 - hc->hw.int_m1 |= HFCPCI_INTS_B2REC; 1401 + if (!tics) 1402 + hc->hw.int_m1 |= HFCPCI_INTS_B2REC; 1453 1403 hc->hw.ctmt |= 2; 1454 1404 hc->hw.conn &= ~0x18; 1455 1405 #ifdef REVERSE_BITORDER ··· 1459 1407 } else { 1460 1408 hc->hw.sctrl_r |= SCTRL_B1_ENA; 1461 1409 hc->hw.fifo_en |= HFCPCI_FIFOEN_B1RX; 1462 - hc->hw.int_m1 |= HFCPCI_INTS_B1REC; 1410 + if (!tics) 1411 + hc->hw.int_m1 |= HFCPCI_INTS_B1REC; 1463 1412 hc->hw.ctmt |= 1; 1464 1413 hc->hw.conn &= ~0x03; 1465 1414 #ifdef REVERSE_BITORDER ··· 1534 1481 static int 1535 1482 channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq) 1536 1483 { 1537 - int ret = 0; 1484 + int ret = 0; 1538 1485 1539 1486 switch (cq->op) { 1540 1487 case MISDN_CTRL_GETOP: 1541 - cq->op = 0; 1488 + cq->op = MISDN_CTRL_FILL_EMPTY; 1489 + break; 1490 + case MISDN_CTRL_FILL_EMPTY: /* fill fifo, if empty */ 1491 + test_and_set_bit(FLG_FILLEMPTY, &bch->Flags); 1492 + if (debug & DEBUG_HW_OPEN) 1493 + printk(KERN_DEBUG "%s: FILL_EMPTY request (nr=%d " 1494 + "off=%d)\n", __func__, bch->nr, !!cq->p1); 1542 1495 break; 1543 1496 default: 1544 1497 printk(KERN_WARNING "%s: unknown Op %x\n", __func__, cq->op); ··· 1918 1859 hc->dch.dev.id, __builtin_return_address(0)); 1919 1860 if (rq->protocol == ISDN_P_NONE) 1920 1861 return -EINVAL; 1862 + if (rq->adr.channel == 1) { 1863 + /* TODO: E-Channel */ 1864 + return -EINVAL; 1865 + } 1921 1866 if (!hc->initdone) { 1922 1867 if (rq->protocol == ISDN_P_TE_S0) { 1923 1868 err = create_l1(&hc->dch, hfc_l1callback); ··· 1937 1874 if (rq->protocol != ch->protocol) { 1938 1875 if (hc->hw.protocol == ISDN_P_TE_S0) 1939 1876 l1_event(hc->dch.l1, CLOSE_CHANNEL); 1877 + if (rq->protocol == ISDN_P_TE_S0) { 1878 + err = create_l1(&hc->dch, hfc_l1callback); 1879 + if (err) 1880 + return err; 1881 + } 1940 1882 hc->hw.protocol = rq->protocol; 1941 1883 ch->protocol = rq->protocol; 1942 1884 hfcpci_setmode(hc); ··· 1971 1903 bch = &hc->bch[rq->adr.channel - 1]; 1972 1904 if (test_and_set_bit(FLG_OPEN, &bch->Flags)) 1973 1905 return -EBUSY; /* b-channel can be only open once */ 1906 + test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags); 1974 1907 bch->ch.protocol = rq->protocol; 1975 1908 rq->ch = &bch->ch; /* TODO: E-channel */ 1976 1909 if (!try_module_get(THIS_MODULE)) ··· 1997 1928 switch (cmd) { 1998 1929 case OPEN_CHANNEL: 1999 1930 rq = arg; 2000 - if (rq->adr.channel == 0) 1931 + if ((rq->protocol == ISDN_P_TE_S0) || 1932 + (rq->protocol == ISDN_P_NT_S0)) 2001 1933 err = open_dchannel(hc, ch, rq); 2002 1934 else 2003 1935 err = open_bchannel(hc, rq); ··· 2097 2027 mISDN_freebchannel(&hc->bch[1]); 2098 2028 mISDN_freebchannel(&hc->bch[0]); 2099 2029 mISDN_freedchannel(&hc->dch); 2100 - list_del(&hc->list); 2101 2030 pci_set_drvdata(hc->pdev, NULL); 2102 2031 kfree(hc); 2103 2032 } ··· 2106 2037 { 2107 2038 int err = -EINVAL; 2108 2039 u_int i; 2109 - u_long flags; 2110 2040 char name[MISDN_MAX_IDLEN]; 2111 - 2112 - if (HFC_cnt >= MAX_CARDS) 2113 - return -EINVAL; /* maybe better value */ 2114 2041 2115 2042 card->dch.debug = debug; 2116 2043 spin_lock_init(&card->lock); ··· 2133 2068 if (err) 2134 2069 goto error; 2135 2070 snprintf(name, MISDN_MAX_IDLEN - 1, "hfc-pci.%d", HFC_cnt + 1); 2136 - err = mISDN_register_device(&card->dch.dev, name); 2071 + err = mISDN_register_device(&card->dch.dev, &card->pdev->dev, name); 2137 2072 if (err) 2138 2073 goto error; 2139 2074 HFC_cnt++; 2140 - write_lock_irqsave(&HFClock, flags); 2141 - list_add_tail(&card->list, &HFClist); 2142 - write_unlock_irqrestore(&HFClock, flags); 2143 2075 printk(KERN_INFO "HFC %d cards installed\n", HFC_cnt); 2144 2076 return 0; 2145 2077 error: ··· 2272 2210 hfc_remove_pci(struct pci_dev *pdev) 2273 2211 { 2274 2212 struct hfc_pci *card = pci_get_drvdata(pdev); 2275 - u_long flags; 2276 2213 2277 - if (card) { 2278 - write_lock_irqsave(&HFClock, flags); 2214 + if (card) 2279 2215 release_card(card); 2280 - write_unlock_irqrestore(&HFClock, flags); 2281 - } else 2216 + else 2282 2217 if (debug) 2283 - printk(KERN_WARNING "%s: drvdata allready removed\n", 2218 + printk(KERN_WARNING "%s: drvdata already removed\n", 2284 2219 __func__); 2285 2220 } 2286 2221 ··· 2289 2230 .id_table = hfc_ids, 2290 2231 }; 2291 2232 2233 + static int 2234 + _hfcpci_softirq(struct device *dev, void *arg) 2235 + { 2236 + struct hfc_pci *hc = dev_get_drvdata(dev); 2237 + struct bchannel *bch; 2238 + if (hc == NULL) 2239 + return 0; 2240 + 2241 + if (hc->hw.int_m2 & HFCPCI_IRQ_ENABLE) { 2242 + spin_lock(&hc->lock); 2243 + bch = Sel_BCS(hc, hc->hw.bswapped ? 2 : 1); 2244 + if (bch && bch->state == ISDN_P_B_RAW) { /* B1 rx&tx */ 2245 + main_rec_hfcpci(bch); 2246 + tx_birq(bch); 2247 + } 2248 + bch = Sel_BCS(hc, hc->hw.bswapped ? 1 : 2); 2249 + if (bch && bch->state == ISDN_P_B_RAW) { /* B2 rx&tx */ 2250 + main_rec_hfcpci(bch); 2251 + tx_birq(bch); 2252 + } 2253 + spin_unlock(&hc->lock); 2254 + } 2255 + return 0; 2256 + } 2257 + 2258 + static void 2259 + hfcpci_softirq(void *arg) 2260 + { 2261 + (void) driver_for_each_device(&hfc_driver.driver, NULL, arg, 2262 + _hfcpci_softirq); 2263 + 2264 + /* if next event would be in the past ... */ 2265 + if ((s32)(hfc_jiffies + tics - jiffies) <= 0) 2266 + hfc_jiffies = jiffies + 1; 2267 + else 2268 + hfc_jiffies += tics; 2269 + hfc_tl.expires = hfc_jiffies; 2270 + add_timer(&hfc_tl); 2271 + } 2272 + 2292 2273 static int __init 2293 2274 HFC_init(void) 2294 2275 { 2295 2276 int err; 2296 2277 2278 + if (!poll) 2279 + poll = HFCPCI_BTRANS_THRESHOLD; 2280 + 2281 + if (poll != HFCPCI_BTRANS_THRESHOLD) { 2282 + tics = (poll * HZ) / 8000; 2283 + if (tics < 1) 2284 + tics = 1; 2285 + poll = (tics * 8000) / HZ; 2286 + if (poll > 256 || poll < 8) { 2287 + printk(KERN_ERR "%s: Wrong poll value %d not in range " 2288 + "of 8..256.\n", __func__, poll); 2289 + err = -EINVAL; 2290 + return err; 2291 + } 2292 + } 2293 + if (poll != HFCPCI_BTRANS_THRESHOLD) { 2294 + printk(KERN_INFO "%s: Using alternative poll value of %d\n", 2295 + __func__, poll); 2296 + hfc_tl.function = (void *)hfcpci_softirq; 2297 + hfc_tl.data = 0; 2298 + init_timer(&hfc_tl); 2299 + hfc_tl.expires = jiffies + tics; 2300 + hfc_jiffies = hfc_tl.expires; 2301 + add_timer(&hfc_tl); 2302 + } else 2303 + tics = 0; /* indicate the use of controller's timer */ 2304 + 2297 2305 err = pci_register_driver(&hfc_driver); 2306 + if (err) { 2307 + if (timer_pending(&hfc_tl)) 2308 + del_timer(&hfc_tl); 2309 + } 2310 + 2298 2311 return err; 2299 2312 } 2300 2313 2301 2314 static void __exit 2302 2315 HFC_cleanup(void) 2303 2316 { 2304 - struct hfc_pci *card, *next; 2317 + if (timer_pending(&hfc_tl)) 2318 + del_timer(&hfc_tl); 2305 2319 2306 - list_for_each_entry_safe(card, next, &HFClist, list) { 2307 - release_card(card); 2308 - } 2309 2320 pci_unregister_driver(&hfc_driver); 2310 2321 } 2311 2322 2312 2323 module_init(HFC_init); 2313 2324 module_exit(HFC_cleanup); 2325 + 2326 + MODULE_DEVICE_TABLE(pci, hfc_ids);
+2196
drivers/isdn/hardware/mISDN/hfcsusb.c
··· 1 + /* hfcsusb.c 2 + * mISDN driver for Colognechip HFC-S USB chip 3 + * 4 + * Copyright 2001 by Peter Sprenger (sprenger@moving-bytes.de) 5 + * Copyright 2008 by Martin Bachem (info@bachem-it.com) 6 + * 7 + * This program is free software; you can redistribute it and/or modify 8 + * it under the terms of the GNU General Public License as published by 9 + * the Free Software Foundation; either version 2, or (at your option) 10 + * any later version. 11 + * 12 + * This program is distributed in the hope that it will be useful, 13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + * GNU General Public License for more details. 16 + * 17 + * You should have received a copy of the GNU General Public License 18 + * along with this program; if not, write to the Free Software 19 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 + * 21 + * 22 + * module params 23 + * debug=<n>, default=0, with n=0xHHHHGGGG 24 + * H - l1 driver flags described in hfcsusb.h 25 + * G - common mISDN debug flags described at mISDNhw.h 26 + * 27 + * poll=<n>, default 128 28 + * n : burst size of PH_DATA_IND at transparent rx data 29 + * 30 + */ 31 + 32 + #include <linux/module.h> 33 + #include <linux/delay.h> 34 + #include <linux/usb.h> 35 + #include <linux/mISDNhw.h> 36 + #include "hfcsusb.h" 37 + 38 + const char *hfcsusb_rev = "Revision: 0.3.3 (socket), 2008-11-05"; 39 + 40 + static unsigned int debug; 41 + static int poll = DEFAULT_TRANSP_BURST_SZ; 42 + 43 + static LIST_HEAD(HFClist); 44 + static DEFINE_RWLOCK(HFClock); 45 + 46 + 47 + MODULE_AUTHOR("Martin Bachem"); 48 + MODULE_LICENSE("GPL"); 49 + module_param(debug, uint, S_IRUGO | S_IWUSR); 50 + module_param(poll, int, 0); 51 + 52 + static int hfcsusb_cnt; 53 + 54 + /* some function prototypes */ 55 + static void hfcsusb_ph_command(struct hfcsusb *hw, u_char command); 56 + static void release_hw(struct hfcsusb *hw); 57 + static void reset_hfcsusb(struct hfcsusb *hw); 58 + static void setPortMode(struct hfcsusb *hw); 59 + static void hfcsusb_start_endpoint(struct hfcsusb *hw, int channel); 60 + static void hfcsusb_stop_endpoint(struct hfcsusb *hw, int channel); 61 + static int hfcsusb_setup_bch(struct bchannel *bch, int protocol); 62 + static void deactivate_bchannel(struct bchannel *bch); 63 + static void hfcsusb_ph_info(struct hfcsusb *hw); 64 + 65 + /* start next background transfer for control channel */ 66 + static void 67 + ctrl_start_transfer(struct hfcsusb *hw) 68 + { 69 + if (debug & DBG_HFC_CALL_TRACE) 70 + printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); 71 + 72 + if (hw->ctrl_cnt) { 73 + hw->ctrl_urb->pipe = hw->ctrl_out_pipe; 74 + hw->ctrl_urb->setup_packet = (u_char *)&hw->ctrl_write; 75 + hw->ctrl_urb->transfer_buffer = NULL; 76 + hw->ctrl_urb->transfer_buffer_length = 0; 77 + hw->ctrl_write.wIndex = 78 + cpu_to_le16(hw->ctrl_buff[hw->ctrl_out_idx].hfcs_reg); 79 + hw->ctrl_write.wValue = 80 + cpu_to_le16(hw->ctrl_buff[hw->ctrl_out_idx].reg_val); 81 + 82 + usb_submit_urb(hw->ctrl_urb, GFP_ATOMIC); 83 + } 84 + } 85 + 86 + /* 87 + * queue a control transfer request to write HFC-S USB 88 + * chip register using CTRL resuest queue 89 + */ 90 + static int write_reg(struct hfcsusb *hw, __u8 reg, __u8 val) 91 + { 92 + struct ctrl_buf *buf; 93 + 94 + if (debug & DBG_HFC_CALL_TRACE) 95 + printk(KERN_DEBUG "%s: %s reg(0x%02x) val(0x%02x)\n", 96 + hw->name, __func__, reg, val); 97 + 98 + spin_lock(&hw->ctrl_lock); 99 + if (hw->ctrl_cnt >= HFC_CTRL_BUFSIZE) 100 + return 1; 101 + buf = &hw->ctrl_buff[hw->ctrl_in_idx]; 102 + buf->hfcs_reg = reg; 103 + buf->reg_val = val; 104 + if (++hw->ctrl_in_idx >= HFC_CTRL_BUFSIZE) 105 + hw->ctrl_in_idx = 0; 106 + if (++hw->ctrl_cnt == 1) 107 + ctrl_start_transfer(hw); 108 + spin_unlock(&hw->ctrl_lock); 109 + 110 + return 0; 111 + } 112 + 113 + /* control completion routine handling background control cmds */ 114 + static void 115 + ctrl_complete(struct urb *urb) 116 + { 117 + struct hfcsusb *hw = (struct hfcsusb *) urb->context; 118 + struct ctrl_buf *buf; 119 + 120 + if (debug & DBG_HFC_CALL_TRACE) 121 + printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); 122 + 123 + urb->dev = hw->dev; 124 + if (hw->ctrl_cnt) { 125 + buf = &hw->ctrl_buff[hw->ctrl_out_idx]; 126 + hw->ctrl_cnt--; /* decrement actual count */ 127 + if (++hw->ctrl_out_idx >= HFC_CTRL_BUFSIZE) 128 + hw->ctrl_out_idx = 0; /* pointer wrap */ 129 + 130 + ctrl_start_transfer(hw); /* start next transfer */ 131 + } 132 + } 133 + 134 + /* handle LED bits */ 135 + static void 136 + set_led_bit(struct hfcsusb *hw, signed short led_bits, int set_on) 137 + { 138 + if (set_on) { 139 + if (led_bits < 0) 140 + hw->led_state &= ~abs(led_bits); 141 + else 142 + hw->led_state |= led_bits; 143 + } else { 144 + if (led_bits < 0) 145 + hw->led_state |= abs(led_bits); 146 + else 147 + hw->led_state &= ~led_bits; 148 + } 149 + } 150 + 151 + /* handle LED requests */ 152 + static void 153 + handle_led(struct hfcsusb *hw, int event) 154 + { 155 + struct hfcsusb_vdata *driver_info = (struct hfcsusb_vdata *) 156 + hfcsusb_idtab[hw->vend_idx].driver_info; 157 + __u8 tmpled; 158 + 159 + if (driver_info->led_scheme == LED_OFF) 160 + return; 161 + tmpled = hw->led_state; 162 + 163 + switch (event) { 164 + case LED_POWER_ON: 165 + set_led_bit(hw, driver_info->led_bits[0], 1); 166 + set_led_bit(hw, driver_info->led_bits[1], 0); 167 + set_led_bit(hw, driver_info->led_bits[2], 0); 168 + set_led_bit(hw, driver_info->led_bits[3], 0); 169 + break; 170 + case LED_POWER_OFF: 171 + set_led_bit(hw, driver_info->led_bits[0], 0); 172 + set_led_bit(hw, driver_info->led_bits[1], 0); 173 + set_led_bit(hw, driver_info->led_bits[2], 0); 174 + set_led_bit(hw, driver_info->led_bits[3], 0); 175 + break; 176 + case LED_S0_ON: 177 + set_led_bit(hw, driver_info->led_bits[1], 1); 178 + break; 179 + case LED_S0_OFF: 180 + set_led_bit(hw, driver_info->led_bits[1], 0); 181 + break; 182 + case LED_B1_ON: 183 + set_led_bit(hw, driver_info->led_bits[2], 1); 184 + break; 185 + case LED_B1_OFF: 186 + set_led_bit(hw, driver_info->led_bits[2], 0); 187 + break; 188 + case LED_B2_ON: 189 + set_led_bit(hw, driver_info->led_bits[3], 1); 190 + break; 191 + case LED_B2_OFF: 192 + set_led_bit(hw, driver_info->led_bits[3], 0); 193 + break; 194 + } 195 + 196 + if (hw->led_state != tmpled) { 197 + if (debug & DBG_HFC_CALL_TRACE) 198 + printk(KERN_DEBUG "%s: %s reg(0x%02x) val(x%02x)\n", 199 + hw->name, __func__, 200 + HFCUSB_P_DATA, hw->led_state); 201 + 202 + write_reg(hw, HFCUSB_P_DATA, hw->led_state); 203 + } 204 + } 205 + 206 + /* 207 + * Layer2 -> Layer 1 Bchannel data 208 + */ 209 + static int 210 + hfcusb_l2l1B(struct mISDNchannel *ch, struct sk_buff *skb) 211 + { 212 + struct bchannel *bch = container_of(ch, struct bchannel, ch); 213 + struct hfcsusb *hw = bch->hw; 214 + int ret = -EINVAL; 215 + struct mISDNhead *hh = mISDN_HEAD_P(skb); 216 + u_long flags; 217 + 218 + if (debug & DBG_HFC_CALL_TRACE) 219 + printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); 220 + 221 + switch (hh->prim) { 222 + case PH_DATA_REQ: 223 + spin_lock_irqsave(&hw->lock, flags); 224 + ret = bchannel_senddata(bch, skb); 225 + spin_unlock_irqrestore(&hw->lock, flags); 226 + if (debug & DBG_HFC_CALL_TRACE) 227 + printk(KERN_DEBUG "%s: %s PH_DATA_REQ ret(%i)\n", 228 + hw->name, __func__, ret); 229 + if (ret > 0) { 230 + /* 231 + * other l1 drivers don't send early confirms on 232 + * transp data, but hfcsusb does because tx_next 233 + * skb is needed in tx_iso_complete() 234 + */ 235 + queue_ch_frame(ch, PH_DATA_CNF, hh->id, NULL); 236 + ret = 0; 237 + } 238 + return ret; 239 + case PH_ACTIVATE_REQ: 240 + if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags)) { 241 + hfcsusb_start_endpoint(hw, bch->nr); 242 + ret = hfcsusb_setup_bch(bch, ch->protocol); 243 + } else 244 + ret = 0; 245 + if (!ret) 246 + _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 247 + 0, NULL, GFP_KERNEL); 248 + break; 249 + case PH_DEACTIVATE_REQ: 250 + deactivate_bchannel(bch); 251 + _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 252 + 0, NULL, GFP_KERNEL); 253 + ret = 0; 254 + break; 255 + } 256 + if (!ret) 257 + dev_kfree_skb(skb); 258 + return ret; 259 + } 260 + 261 + /* 262 + * send full D/B channel status information 263 + * as MPH_INFORMATION_IND 264 + */ 265 + static void 266 + hfcsusb_ph_info(struct hfcsusb *hw) 267 + { 268 + struct ph_info *phi; 269 + struct dchannel *dch = &hw->dch; 270 + int i; 271 + 272 + phi = kzalloc(sizeof(struct ph_info) + 273 + dch->dev.nrbchan * sizeof(struct ph_info_ch), GFP_ATOMIC); 274 + phi->dch.ch.protocol = hw->protocol; 275 + phi->dch.ch.Flags = dch->Flags; 276 + phi->dch.state = dch->state; 277 + phi->dch.num_bch = dch->dev.nrbchan; 278 + for (i = 0; i < dch->dev.nrbchan; i++) { 279 + phi->bch[i].protocol = hw->bch[i].ch.protocol; 280 + phi->bch[i].Flags = hw->bch[i].Flags; 281 + } 282 + _queue_data(&dch->dev.D, MPH_INFORMATION_IND, MISDN_ID_ANY, 283 + sizeof(struct ph_info_dch) + dch->dev.nrbchan * 284 + sizeof(struct ph_info_ch), phi, GFP_ATOMIC); 285 + } 286 + 287 + /* 288 + * Layer2 -> Layer 1 Dchannel data 289 + */ 290 + static int 291 + hfcusb_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb) 292 + { 293 + struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D); 294 + struct dchannel *dch = container_of(dev, struct dchannel, dev); 295 + struct mISDNhead *hh = mISDN_HEAD_P(skb); 296 + struct hfcsusb *hw = dch->hw; 297 + int ret = -EINVAL; 298 + u_long flags; 299 + 300 + switch (hh->prim) { 301 + case PH_DATA_REQ: 302 + if (debug & DBG_HFC_CALL_TRACE) 303 + printk(KERN_DEBUG "%s: %s: PH_DATA_REQ\n", 304 + hw->name, __func__); 305 + 306 + spin_lock_irqsave(&hw->lock, flags); 307 + ret = dchannel_senddata(dch, skb); 308 + spin_unlock_irqrestore(&hw->lock, flags); 309 + if (ret > 0) { 310 + ret = 0; 311 + queue_ch_frame(ch, PH_DATA_CNF, hh->id, NULL); 312 + } 313 + break; 314 + 315 + case PH_ACTIVATE_REQ: 316 + if (debug & DBG_HFC_CALL_TRACE) 317 + printk(KERN_DEBUG "%s: %s: PH_ACTIVATE_REQ %s\n", 318 + hw->name, __func__, 319 + (hw->protocol == ISDN_P_NT_S0) ? "NT" : "TE"); 320 + 321 + if (hw->protocol == ISDN_P_NT_S0) { 322 + ret = 0; 323 + if (test_bit(FLG_ACTIVE, &dch->Flags)) { 324 + _queue_data(&dch->dev.D, 325 + PH_ACTIVATE_IND, MISDN_ID_ANY, 0, 326 + NULL, GFP_ATOMIC); 327 + } else { 328 + hfcsusb_ph_command(hw, 329 + HFC_L1_ACTIVATE_NT); 330 + test_and_set_bit(FLG_L2_ACTIVATED, 331 + &dch->Flags); 332 + } 333 + } else { 334 + hfcsusb_ph_command(hw, HFC_L1_ACTIVATE_TE); 335 + ret = l1_event(dch->l1, hh->prim); 336 + } 337 + break; 338 + 339 + case PH_DEACTIVATE_REQ: 340 + if (debug & DBG_HFC_CALL_TRACE) 341 + printk(KERN_DEBUG "%s: %s: PH_DEACTIVATE_REQ\n", 342 + hw->name, __func__); 343 + test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags); 344 + 345 + if (hw->protocol == ISDN_P_NT_S0) { 346 + hfcsusb_ph_command(hw, HFC_L1_DEACTIVATE_NT); 347 + spin_lock_irqsave(&hw->lock, flags); 348 + skb_queue_purge(&dch->squeue); 349 + if (dch->tx_skb) { 350 + dev_kfree_skb(dch->tx_skb); 351 + dch->tx_skb = NULL; 352 + } 353 + dch->tx_idx = 0; 354 + if (dch->rx_skb) { 355 + dev_kfree_skb(dch->rx_skb); 356 + dch->rx_skb = NULL; 357 + } 358 + test_and_clear_bit(FLG_TX_BUSY, &dch->Flags); 359 + spin_unlock_irqrestore(&hw->lock, flags); 360 + #ifdef FIXME 361 + if (test_and_clear_bit(FLG_L1_BUSY, &dch->Flags)) 362 + dchannel_sched_event(&hc->dch, D_CLEARBUSY); 363 + #endif 364 + ret = 0; 365 + } else 366 + ret = l1_event(dch->l1, hh->prim); 367 + break; 368 + case MPH_INFORMATION_REQ: 369 + hfcsusb_ph_info(hw); 370 + ret = 0; 371 + break; 372 + } 373 + 374 + return ret; 375 + } 376 + 377 + /* 378 + * Layer 1 callback function 379 + */ 380 + static int 381 + hfc_l1callback(struct dchannel *dch, u_int cmd) 382 + { 383 + struct hfcsusb *hw = dch->hw; 384 + 385 + if (debug & DBG_HFC_CALL_TRACE) 386 + printk(KERN_DEBUG "%s: %s cmd 0x%x\n", 387 + hw->name, __func__, cmd); 388 + 389 + switch (cmd) { 390 + case INFO3_P8: 391 + case INFO3_P10: 392 + case HW_RESET_REQ: 393 + case HW_POWERUP_REQ: 394 + break; 395 + 396 + case HW_DEACT_REQ: 397 + skb_queue_purge(&dch->squeue); 398 + if (dch->tx_skb) { 399 + dev_kfree_skb(dch->tx_skb); 400 + dch->tx_skb = NULL; 401 + } 402 + dch->tx_idx = 0; 403 + if (dch->rx_skb) { 404 + dev_kfree_skb(dch->rx_skb); 405 + dch->rx_skb = NULL; 406 + } 407 + test_and_clear_bit(FLG_TX_BUSY, &dch->Flags); 408 + break; 409 + case PH_ACTIVATE_IND: 410 + test_and_set_bit(FLG_ACTIVE, &dch->Flags); 411 + _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL, 412 + GFP_ATOMIC); 413 + break; 414 + case PH_DEACTIVATE_IND: 415 + test_and_clear_bit(FLG_ACTIVE, &dch->Flags); 416 + _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL, 417 + GFP_ATOMIC); 418 + break; 419 + default: 420 + if (dch->debug & DEBUG_HW) 421 + printk(KERN_DEBUG "%s: %s: unknown cmd %x\n", 422 + hw->name, __func__, cmd); 423 + return -1; 424 + } 425 + hfcsusb_ph_info(hw); 426 + return 0; 427 + } 428 + 429 + static int 430 + open_dchannel(struct hfcsusb *hw, struct mISDNchannel *ch, 431 + struct channel_req *rq) 432 + { 433 + int err = 0; 434 + 435 + if (debug & DEBUG_HW_OPEN) 436 + printk(KERN_DEBUG "%s: %s: dev(%d) open addr(%i) from %p\n", 437 + hw->name, __func__, hw->dch.dev.id, rq->adr.channel, 438 + __builtin_return_address(0)); 439 + if (rq->protocol == ISDN_P_NONE) 440 + return -EINVAL; 441 + 442 + test_and_clear_bit(FLG_ACTIVE, &hw->dch.Flags); 443 + test_and_clear_bit(FLG_ACTIVE, &hw->ech.Flags); 444 + hfcsusb_start_endpoint(hw, HFC_CHAN_D); 445 + 446 + /* E-Channel logging */ 447 + if (rq->adr.channel == 1) { 448 + if (hw->fifos[HFCUSB_PCM_RX].pipe) { 449 + hfcsusb_start_endpoint(hw, HFC_CHAN_E); 450 + set_bit(FLG_ACTIVE, &hw->ech.Flags); 451 + _queue_data(&hw->ech.dev.D, PH_ACTIVATE_IND, 452 + MISDN_ID_ANY, 0, NULL, GFP_ATOMIC); 453 + } else 454 + return -EINVAL; 455 + } 456 + 457 + if (!hw->initdone) { 458 + hw->protocol = rq->protocol; 459 + if (rq->protocol == ISDN_P_TE_S0) { 460 + err = create_l1(&hw->dch, hfc_l1callback); 461 + if (err) 462 + return err; 463 + } 464 + setPortMode(hw); 465 + ch->protocol = rq->protocol; 466 + hw->initdone = 1; 467 + } else { 468 + if (rq->protocol != ch->protocol) 469 + return -EPROTONOSUPPORT; 470 + } 471 + 472 + if (((ch->protocol == ISDN_P_NT_S0) && (hw->dch.state == 3)) || 473 + ((ch->protocol == ISDN_P_TE_S0) && (hw->dch.state == 7))) 474 + _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 475 + 0, NULL, GFP_KERNEL); 476 + rq->ch = ch; 477 + if (!try_module_get(THIS_MODULE)) 478 + printk(KERN_WARNING "%s: %s: cannot get module\n", 479 + hw->name, __func__); 480 + return 0; 481 + } 482 + 483 + static int 484 + open_bchannel(struct hfcsusb *hw, struct channel_req *rq) 485 + { 486 + struct bchannel *bch; 487 + 488 + if (rq->adr.channel > 2) 489 + return -EINVAL; 490 + if (rq->protocol == ISDN_P_NONE) 491 + return -EINVAL; 492 + 493 + if (debug & DBG_HFC_CALL_TRACE) 494 + printk(KERN_DEBUG "%s: %s B%i\n", 495 + hw->name, __func__, rq->adr.channel); 496 + 497 + bch = &hw->bch[rq->adr.channel - 1]; 498 + if (test_and_set_bit(FLG_OPEN, &bch->Flags)) 499 + return -EBUSY; /* b-channel can be only open once */ 500 + test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags); 501 + bch->ch.protocol = rq->protocol; 502 + rq->ch = &bch->ch; 503 + 504 + /* start USB endpoint for bchannel */ 505 + if (rq->adr.channel == 1) 506 + hfcsusb_start_endpoint(hw, HFC_CHAN_B1); 507 + else 508 + hfcsusb_start_endpoint(hw, HFC_CHAN_B2); 509 + 510 + if (!try_module_get(THIS_MODULE)) 511 + printk(KERN_WARNING "%s: %s:cannot get module\n", 512 + hw->name, __func__); 513 + return 0; 514 + } 515 + 516 + static int 517 + channel_ctrl(struct hfcsusb *hw, struct mISDN_ctrl_req *cq) 518 + { 519 + int ret = 0; 520 + 521 + if (debug & DBG_HFC_CALL_TRACE) 522 + printk(KERN_DEBUG "%s: %s op(0x%x) channel(0x%x)\n", 523 + hw->name, __func__, (cq->op), (cq->channel)); 524 + 525 + switch (cq->op) { 526 + case MISDN_CTRL_GETOP: 527 + cq->op = MISDN_CTRL_LOOP | MISDN_CTRL_CONNECT | 528 + MISDN_CTRL_DISCONNECT; 529 + break; 530 + default: 531 + printk(KERN_WARNING "%s: %s: unknown Op %x\n", 532 + hw->name, __func__, cq->op); 533 + ret = -EINVAL; 534 + break; 535 + } 536 + return ret; 537 + } 538 + 539 + /* 540 + * device control function 541 + */ 542 + static int 543 + hfc_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg) 544 + { 545 + struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D); 546 + struct dchannel *dch = container_of(dev, struct dchannel, dev); 547 + struct hfcsusb *hw = dch->hw; 548 + struct channel_req *rq; 549 + int err = 0; 550 + 551 + if (dch->debug & DEBUG_HW) 552 + printk(KERN_DEBUG "%s: %s: cmd:%x %p\n", 553 + hw->name, __func__, cmd, arg); 554 + switch (cmd) { 555 + case OPEN_CHANNEL: 556 + rq = arg; 557 + if ((rq->protocol == ISDN_P_TE_S0) || 558 + (rq->protocol == ISDN_P_NT_S0)) 559 + err = open_dchannel(hw, ch, rq); 560 + else 561 + err = open_bchannel(hw, rq); 562 + if (!err) 563 + hw->open++; 564 + break; 565 + case CLOSE_CHANNEL: 566 + hw->open--; 567 + if (debug & DEBUG_HW_OPEN) 568 + printk(KERN_DEBUG 569 + "%s: %s: dev(%d) close from %p (open %d)\n", 570 + hw->name, __func__, hw->dch.dev.id, 571 + __builtin_return_address(0), hw->open); 572 + if (!hw->open) { 573 + hfcsusb_stop_endpoint(hw, HFC_CHAN_D); 574 + if (hw->fifos[HFCUSB_PCM_RX].pipe) 575 + hfcsusb_stop_endpoint(hw, HFC_CHAN_E); 576 + handle_led(hw, LED_POWER_ON); 577 + } 578 + module_put(THIS_MODULE); 579 + break; 580 + case CONTROL_CHANNEL: 581 + err = channel_ctrl(hw, arg); 582 + break; 583 + default: 584 + if (dch->debug & DEBUG_HW) 585 + printk(KERN_DEBUG "%s: %s: unknown command %x\n", 586 + hw->name, __func__, cmd); 587 + return -EINVAL; 588 + } 589 + return err; 590 + } 591 + 592 + /* 593 + * S0 TE state change event handler 594 + */ 595 + static void 596 + ph_state_te(struct dchannel *dch) 597 + { 598 + struct hfcsusb *hw = dch->hw; 599 + 600 + if (debug & DEBUG_HW) { 601 + if (dch->state <= HFC_MAX_TE_LAYER1_STATE) 602 + printk(KERN_DEBUG "%s: %s: %s\n", hw->name, __func__, 603 + HFC_TE_LAYER1_STATES[dch->state]); 604 + else 605 + printk(KERN_DEBUG "%s: %s: TE F%d\n", 606 + hw->name, __func__, dch->state); 607 + } 608 + 609 + switch (dch->state) { 610 + case 0: 611 + l1_event(dch->l1, HW_RESET_IND); 612 + break; 613 + case 3: 614 + l1_event(dch->l1, HW_DEACT_IND); 615 + break; 616 + case 5: 617 + case 8: 618 + l1_event(dch->l1, ANYSIGNAL); 619 + break; 620 + case 6: 621 + l1_event(dch->l1, INFO2); 622 + break; 623 + case 7: 624 + l1_event(dch->l1, INFO4_P8); 625 + break; 626 + } 627 + if (dch->state == 7) 628 + handle_led(hw, LED_S0_ON); 629 + else 630 + handle_led(hw, LED_S0_OFF); 631 + } 632 + 633 + /* 634 + * S0 NT state change event handler 635 + */ 636 + static void 637 + ph_state_nt(struct dchannel *dch) 638 + { 639 + struct hfcsusb *hw = dch->hw; 640 + 641 + if (debug & DEBUG_HW) { 642 + if (dch->state <= HFC_MAX_NT_LAYER1_STATE) 643 + printk(KERN_DEBUG "%s: %s: %s\n", 644 + hw->name, __func__, 645 + HFC_NT_LAYER1_STATES[dch->state]); 646 + 647 + else 648 + printk(KERN_INFO DRIVER_NAME "%s: %s: NT G%d\n", 649 + hw->name, __func__, dch->state); 650 + } 651 + 652 + switch (dch->state) { 653 + case (1): 654 + test_and_clear_bit(FLG_ACTIVE, &dch->Flags); 655 + test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags); 656 + hw->nt_timer = 0; 657 + hw->timers &= ~NT_ACTIVATION_TIMER; 658 + handle_led(hw, LED_S0_OFF); 659 + break; 660 + 661 + case (2): 662 + if (hw->nt_timer < 0) { 663 + hw->nt_timer = 0; 664 + hw->timers &= ~NT_ACTIVATION_TIMER; 665 + hfcsusb_ph_command(dch->hw, HFC_L1_DEACTIVATE_NT); 666 + } else { 667 + hw->timers |= NT_ACTIVATION_TIMER; 668 + hw->nt_timer = NT_T1_COUNT; 669 + /* allow G2 -> G3 transition */ 670 + write_reg(hw, HFCUSB_STATES, 2 | HFCUSB_NT_G2_G3); 671 + } 672 + break; 673 + case (3): 674 + hw->nt_timer = 0; 675 + hw->timers &= ~NT_ACTIVATION_TIMER; 676 + test_and_set_bit(FLG_ACTIVE, &dch->Flags); 677 + _queue_data(&dch->dev.D, PH_ACTIVATE_IND, 678 + MISDN_ID_ANY, 0, NULL, GFP_ATOMIC); 679 + handle_led(hw, LED_S0_ON); 680 + break; 681 + case (4): 682 + hw->nt_timer = 0; 683 + hw->timers &= ~NT_ACTIVATION_TIMER; 684 + break; 685 + default: 686 + break; 687 + } 688 + hfcsusb_ph_info(hw); 689 + } 690 + 691 + static void 692 + ph_state(struct dchannel *dch) 693 + { 694 + struct hfcsusb *hw = dch->hw; 695 + 696 + if (hw->protocol == ISDN_P_NT_S0) 697 + ph_state_nt(dch); 698 + else if (hw->protocol == ISDN_P_TE_S0) 699 + ph_state_te(dch); 700 + } 701 + 702 + /* 703 + * disable/enable BChannel for desired protocoll 704 + */ 705 + static int 706 + hfcsusb_setup_bch(struct bchannel *bch, int protocol) 707 + { 708 + struct hfcsusb *hw = bch->hw; 709 + __u8 conhdlc, sctrl, sctrl_r; 710 + 711 + if (debug & DEBUG_HW) 712 + printk(KERN_DEBUG "%s: %s: protocol %x-->%x B%d\n", 713 + hw->name, __func__, bch->state, protocol, 714 + bch->nr); 715 + 716 + /* setup val for CON_HDLC */ 717 + conhdlc = 0; 718 + if (protocol > ISDN_P_NONE) 719 + conhdlc = 8; /* enable FIFO */ 720 + 721 + switch (protocol) { 722 + case (-1): /* used for init */ 723 + bch->state = -1; 724 + /* fall trough */ 725 + case (ISDN_P_NONE): 726 + if (bch->state == ISDN_P_NONE) 727 + return 0; /* already in idle state */ 728 + bch->state = ISDN_P_NONE; 729 + clear_bit(FLG_HDLC, &bch->Flags); 730 + clear_bit(FLG_TRANSPARENT, &bch->Flags); 731 + break; 732 + case (ISDN_P_B_RAW): 733 + conhdlc |= 2; 734 + bch->state = protocol; 735 + set_bit(FLG_TRANSPARENT, &bch->Flags); 736 + break; 737 + case (ISDN_P_B_HDLC): 738 + bch->state = protocol; 739 + set_bit(FLG_HDLC, &bch->Flags); 740 + break; 741 + default: 742 + if (debug & DEBUG_HW) 743 + printk(KERN_DEBUG "%s: %s: prot not known %x\n", 744 + hw->name, __func__, protocol); 745 + return -ENOPROTOOPT; 746 + } 747 + 748 + if (protocol >= ISDN_P_NONE) { 749 + write_reg(hw, HFCUSB_FIFO, (bch->nr == 1) ? 0 : 2); 750 + write_reg(hw, HFCUSB_CON_HDLC, conhdlc); 751 + write_reg(hw, HFCUSB_INC_RES_F, 2); 752 + write_reg(hw, HFCUSB_FIFO, (bch->nr == 1) ? 1 : 3); 753 + write_reg(hw, HFCUSB_CON_HDLC, conhdlc); 754 + write_reg(hw, HFCUSB_INC_RES_F, 2); 755 + 756 + sctrl = 0x40 + ((hw->protocol == ISDN_P_TE_S0) ? 0x00 : 0x04); 757 + sctrl_r = 0x0; 758 + if (test_bit(FLG_ACTIVE, &hw->bch[0].Flags)) { 759 + sctrl |= 1; 760 + sctrl_r |= 1; 761 + } 762 + if (test_bit(FLG_ACTIVE, &hw->bch[1].Flags)) { 763 + sctrl |= 2; 764 + sctrl_r |= 2; 765 + } 766 + write_reg(hw, HFCUSB_SCTRL, sctrl); 767 + write_reg(hw, HFCUSB_SCTRL_R, sctrl_r); 768 + 769 + if (protocol > ISDN_P_NONE) 770 + handle_led(hw, (bch->nr == 1) ? LED_B1_ON : LED_B2_ON); 771 + else 772 + handle_led(hw, (bch->nr == 1) ? LED_B1_OFF : 773 + LED_B2_OFF); 774 + } 775 + hfcsusb_ph_info(hw); 776 + return 0; 777 + } 778 + 779 + static void 780 + hfcsusb_ph_command(struct hfcsusb *hw, u_char command) 781 + { 782 + if (debug & DEBUG_HW) 783 + printk(KERN_DEBUG "%s: %s: %x\n", 784 + hw->name, __func__, command); 785 + 786 + switch (command) { 787 + case HFC_L1_ACTIVATE_TE: 788 + /* force sending sending INFO1 */ 789 + write_reg(hw, HFCUSB_STATES, 0x14); 790 + /* start l1 activation */ 791 + write_reg(hw, HFCUSB_STATES, 0x04); 792 + break; 793 + 794 + case HFC_L1_FORCE_DEACTIVATE_TE: 795 + write_reg(hw, HFCUSB_STATES, 0x10); 796 + write_reg(hw, HFCUSB_STATES, 0x03); 797 + break; 798 + 799 + case HFC_L1_ACTIVATE_NT: 800 + if (hw->dch.state == 3) 801 + _queue_data(&hw->dch.dev.D, PH_ACTIVATE_IND, 802 + MISDN_ID_ANY, 0, NULL, GFP_ATOMIC); 803 + else 804 + write_reg(hw, HFCUSB_STATES, HFCUSB_ACTIVATE | 805 + HFCUSB_DO_ACTION | HFCUSB_NT_G2_G3); 806 + break; 807 + 808 + case HFC_L1_DEACTIVATE_NT: 809 + write_reg(hw, HFCUSB_STATES, 810 + HFCUSB_DO_ACTION); 811 + break; 812 + } 813 + } 814 + 815 + /* 816 + * Layer 1 B-channel hardware access 817 + */ 818 + static int 819 + channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq) 820 + { 821 + int ret = 0; 822 + 823 + switch (cq->op) { 824 + case MISDN_CTRL_GETOP: 825 + cq->op = MISDN_CTRL_FILL_EMPTY; 826 + break; 827 + case MISDN_CTRL_FILL_EMPTY: /* fill fifo, if empty */ 828 + test_and_set_bit(FLG_FILLEMPTY, &bch->Flags); 829 + if (debug & DEBUG_HW_OPEN) 830 + printk(KERN_DEBUG "%s: FILL_EMPTY request (nr=%d " 831 + "off=%d)\n", __func__, bch->nr, !!cq->p1); 832 + break; 833 + default: 834 + printk(KERN_WARNING "%s: unknown Op %x\n", __func__, cq->op); 835 + ret = -EINVAL; 836 + break; 837 + } 838 + return ret; 839 + } 840 + 841 + /* collect data from incoming interrupt or isochron USB data */ 842 + static void 843 + hfcsusb_rx_frame(struct usb_fifo *fifo, __u8 *data, unsigned int len, 844 + int finish) 845 + { 846 + struct hfcsusb *hw = fifo->hw; 847 + struct sk_buff *rx_skb = NULL; 848 + int maxlen = 0; 849 + int fifon = fifo->fifonum; 850 + int i; 851 + int hdlc = 0; 852 + 853 + if (debug & DBG_HFC_CALL_TRACE) 854 + printk(KERN_DEBUG "%s: %s: fifo(%i) len(%i) " 855 + "dch(%p) bch(%p) ech(%p)\n", 856 + hw->name, __func__, fifon, len, 857 + fifo->dch, fifo->bch, fifo->ech); 858 + 859 + if (!len) 860 + return; 861 + 862 + if ((!!fifo->dch + !!fifo->bch + !!fifo->ech) != 1) { 863 + printk(KERN_DEBUG "%s: %s: undefined channel\n", 864 + hw->name, __func__); 865 + return; 866 + } 867 + 868 + spin_lock(&hw->lock); 869 + if (fifo->dch) { 870 + rx_skb = fifo->dch->rx_skb; 871 + maxlen = fifo->dch->maxlen; 872 + hdlc = 1; 873 + } 874 + if (fifo->bch) { 875 + rx_skb = fifo->bch->rx_skb; 876 + maxlen = fifo->bch->maxlen; 877 + hdlc = test_bit(FLG_HDLC, &fifo->bch->Flags); 878 + } 879 + if (fifo->ech) { 880 + rx_skb = fifo->ech->rx_skb; 881 + maxlen = fifo->ech->maxlen; 882 + hdlc = 1; 883 + } 884 + 885 + if (!rx_skb) { 886 + rx_skb = mI_alloc_skb(maxlen, GFP_ATOMIC); 887 + if (rx_skb) { 888 + if (fifo->dch) 889 + fifo->dch->rx_skb = rx_skb; 890 + if (fifo->bch) 891 + fifo->bch->rx_skb = rx_skb; 892 + if (fifo->ech) 893 + fifo->ech->rx_skb = rx_skb; 894 + skb_trim(rx_skb, 0); 895 + } else { 896 + printk(KERN_DEBUG "%s: %s: No mem for rx_skb\n", 897 + hw->name, __func__); 898 + spin_unlock(&hw->lock); 899 + return; 900 + } 901 + } 902 + 903 + if (fifo->dch || fifo->ech) { 904 + /* D/E-Channel SKB range check */ 905 + if ((rx_skb->len + len) >= MAX_DFRAME_LEN_L1) { 906 + printk(KERN_DEBUG "%s: %s: sbk mem exceeded " 907 + "for fifo(%d) HFCUSB_D_RX\n", 908 + hw->name, __func__, fifon); 909 + skb_trim(rx_skb, 0); 910 + spin_unlock(&hw->lock); 911 + return; 912 + } 913 + } else if (fifo->bch) { 914 + /* B-Channel SKB range check */ 915 + if ((rx_skb->len + len) >= (MAX_BCH_SIZE + 3)) { 916 + printk(KERN_DEBUG "%s: %s: sbk mem exceeded " 917 + "for fifo(%d) HFCUSB_B_RX\n", 918 + hw->name, __func__, fifon); 919 + skb_trim(rx_skb, 0); 920 + spin_unlock(&hw->lock); 921 + return; 922 + } 923 + } 924 + 925 + memcpy(skb_put(rx_skb, len), data, len); 926 + 927 + if (hdlc) { 928 + /* we have a complete hdlc packet */ 929 + if (finish) { 930 + if ((rx_skb->len > 3) && 931 + (!(rx_skb->data[rx_skb->len - 1]))) { 932 + if (debug & DBG_HFC_FIFO_VERBOSE) { 933 + printk(KERN_DEBUG "%s: %s: fifon(%i)" 934 + " new RX len(%i): ", 935 + hw->name, __func__, fifon, 936 + rx_skb->len); 937 + i = 0; 938 + while (i < rx_skb->len) 939 + printk("%02x ", 940 + rx_skb->data[i++]); 941 + printk("\n"); 942 + } 943 + 944 + /* remove CRC & status */ 945 + skb_trim(rx_skb, rx_skb->len - 3); 946 + 947 + if (fifo->dch) 948 + recv_Dchannel(fifo->dch); 949 + if (fifo->bch) 950 + recv_Bchannel(fifo->bch); 951 + if (fifo->ech) 952 + recv_Echannel(fifo->ech, 953 + &hw->dch); 954 + } else { 955 + if (debug & DBG_HFC_FIFO_VERBOSE) { 956 + printk(KERN_DEBUG 957 + "%s: CRC or minlen ERROR fifon(%i) " 958 + "RX len(%i): ", 959 + hw->name, fifon, rx_skb->len); 960 + i = 0; 961 + while (i < rx_skb->len) 962 + printk("%02x ", 963 + rx_skb->data[i++]); 964 + printk("\n"); 965 + } 966 + skb_trim(rx_skb, 0); 967 + } 968 + } 969 + } else { 970 + /* deliver transparent data to layer2 */ 971 + if (rx_skb->len >= poll) 972 + recv_Bchannel(fifo->bch); 973 + } 974 + spin_unlock(&hw->lock); 975 + } 976 + 977 + void 978 + fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe, 979 + void *buf, int num_packets, int packet_size, int interval, 980 + usb_complete_t complete, void *context) 981 + { 982 + int k; 983 + 984 + usb_fill_bulk_urb(urb, dev, pipe, buf, packet_size * num_packets, 985 + complete, context); 986 + 987 + urb->number_of_packets = num_packets; 988 + urb->transfer_flags = URB_ISO_ASAP; 989 + urb->actual_length = 0; 990 + urb->interval = interval; 991 + 992 + for (k = 0; k < num_packets; k++) { 993 + urb->iso_frame_desc[k].offset = packet_size * k; 994 + urb->iso_frame_desc[k].length = packet_size; 995 + urb->iso_frame_desc[k].actual_length = 0; 996 + } 997 + } 998 + 999 + /* receive completion routine for all ISO tx fifos */ 1000 + static void 1001 + rx_iso_complete(struct urb *urb) 1002 + { 1003 + struct iso_urb *context_iso_urb = (struct iso_urb *) urb->context; 1004 + struct usb_fifo *fifo = context_iso_urb->owner_fifo; 1005 + struct hfcsusb *hw = fifo->hw; 1006 + int k, len, errcode, offset, num_isoc_packets, fifon, maxlen, 1007 + status, iso_status, i; 1008 + __u8 *buf; 1009 + static __u8 eof[8]; 1010 + __u8 s0_state; 1011 + 1012 + fifon = fifo->fifonum; 1013 + status = urb->status; 1014 + 1015 + spin_lock(&hw->lock); 1016 + if (fifo->stop_gracefull) { 1017 + fifo->stop_gracefull = 0; 1018 + fifo->active = 0; 1019 + spin_unlock(&hw->lock); 1020 + return; 1021 + } 1022 + spin_unlock(&hw->lock); 1023 + 1024 + /* 1025 + * ISO transfer only partially completed, 1026 + * look at individual frame status for details 1027 + */ 1028 + if (status == -EXDEV) { 1029 + if (debug & DEBUG_HW) 1030 + printk(KERN_DEBUG "%s: %s: with -EXDEV " 1031 + "urb->status %d, fifonum %d\n", 1032 + hw->name, __func__, status, fifon); 1033 + 1034 + /* clear status, so go on with ISO transfers */ 1035 + status = 0; 1036 + } 1037 + 1038 + s0_state = 0; 1039 + if (fifo->active && !status) { 1040 + num_isoc_packets = iso_packets[fifon]; 1041 + maxlen = fifo->usb_packet_maxlen; 1042 + 1043 + for (k = 0; k < num_isoc_packets; ++k) { 1044 + len = urb->iso_frame_desc[k].actual_length; 1045 + offset = urb->iso_frame_desc[k].offset; 1046 + buf = context_iso_urb->buffer + offset; 1047 + iso_status = urb->iso_frame_desc[k].status; 1048 + 1049 + if (iso_status && (debug & DBG_HFC_FIFO_VERBOSE)) { 1050 + printk(KERN_DEBUG "%s: %s: " 1051 + "ISO packet %i, status: %i\n", 1052 + hw->name, __func__, k, iso_status); 1053 + } 1054 + 1055 + /* USB data log for every D ISO in */ 1056 + if ((fifon == HFCUSB_D_RX) && 1057 + (debug & DBG_HFC_USB_VERBOSE)) { 1058 + printk(KERN_DEBUG 1059 + "%s: %s: %d (%d/%d) len(%d) ", 1060 + hw->name, __func__, urb->start_frame, 1061 + k, num_isoc_packets-1, 1062 + len); 1063 + for (i = 0; i < len; i++) 1064 + printk("%x ", buf[i]); 1065 + printk("\n"); 1066 + } 1067 + 1068 + if (!iso_status) { 1069 + if (fifo->last_urblen != maxlen) { 1070 + /* 1071 + * save fifo fill-level threshold bits 1072 + * to use them later in TX ISO URB 1073 + * completions 1074 + */ 1075 + hw->threshold_mask = buf[1]; 1076 + 1077 + if (fifon == HFCUSB_D_RX) 1078 + s0_state = (buf[0] >> 4); 1079 + 1080 + eof[fifon] = buf[0] & 1; 1081 + if (len > 2) 1082 + hfcsusb_rx_frame(fifo, buf + 2, 1083 + len - 2, (len < maxlen) 1084 + ? eof[fifon] : 0); 1085 + } else 1086 + hfcsusb_rx_frame(fifo, buf, len, 1087 + (len < maxlen) ? 1088 + eof[fifon] : 0); 1089 + fifo->last_urblen = len; 1090 + } 1091 + } 1092 + 1093 + /* signal S0 layer1 state change */ 1094 + if ((s0_state) && (hw->initdone) && 1095 + (s0_state != hw->dch.state)) { 1096 + hw->dch.state = s0_state; 1097 + schedule_event(&hw->dch, FLG_PHCHANGE); 1098 + } 1099 + 1100 + fill_isoc_urb(urb, fifo->hw->dev, fifo->pipe, 1101 + context_iso_urb->buffer, num_isoc_packets, 1102 + fifo->usb_packet_maxlen, fifo->intervall, 1103 + (usb_complete_t)rx_iso_complete, urb->context); 1104 + errcode = usb_submit_urb(urb, GFP_ATOMIC); 1105 + if (errcode < 0) { 1106 + if (debug & DEBUG_HW) 1107 + printk(KERN_DEBUG "%s: %s: error submitting " 1108 + "ISO URB: %d\n", 1109 + hw->name, __func__, errcode); 1110 + } 1111 + } else { 1112 + if (status && (debug & DBG_HFC_URB_INFO)) 1113 + printk(KERN_DEBUG "%s: %s: rx_iso_complete : " 1114 + "urb->status %d, fifonum %d\n", 1115 + hw->name, __func__, status, fifon); 1116 + } 1117 + } 1118 + 1119 + /* receive completion routine for all interrupt rx fifos */ 1120 + static void 1121 + rx_int_complete(struct urb *urb) 1122 + { 1123 + int len, status, i; 1124 + __u8 *buf, maxlen, fifon; 1125 + struct usb_fifo *fifo = (struct usb_fifo *) urb->context; 1126 + struct hfcsusb *hw = fifo->hw; 1127 + static __u8 eof[8]; 1128 + 1129 + spin_lock(&hw->lock); 1130 + if (fifo->stop_gracefull) { 1131 + fifo->stop_gracefull = 0; 1132 + fifo->active = 0; 1133 + spin_unlock(&hw->lock); 1134 + return; 1135 + } 1136 + spin_unlock(&hw->lock); 1137 + 1138 + fifon = fifo->fifonum; 1139 + if ((!fifo->active) || (urb->status)) { 1140 + if (debug & DBG_HFC_URB_ERROR) 1141 + printk(KERN_DEBUG 1142 + "%s: %s: RX-Fifo %i is going down (%i)\n", 1143 + hw->name, __func__, fifon, urb->status); 1144 + 1145 + fifo->urb->interval = 0; /* cancel automatic rescheduling */ 1146 + return; 1147 + } 1148 + len = urb->actual_length; 1149 + buf = fifo->buffer; 1150 + maxlen = fifo->usb_packet_maxlen; 1151 + 1152 + /* USB data log for every D INT in */ 1153 + if ((fifon == HFCUSB_D_RX) && (debug & DBG_HFC_USB_VERBOSE)) { 1154 + printk(KERN_DEBUG "%s: %s: D RX INT len(%d) ", 1155 + hw->name, __func__, len); 1156 + for (i = 0; i < len; i++) 1157 + printk("%02x ", buf[i]); 1158 + printk("\n"); 1159 + } 1160 + 1161 + if (fifo->last_urblen != fifo->usb_packet_maxlen) { 1162 + /* the threshold mask is in the 2nd status byte */ 1163 + hw->threshold_mask = buf[1]; 1164 + 1165 + /* signal S0 layer1 state change */ 1166 + if (hw->initdone && ((buf[0] >> 4) != hw->dch.state)) { 1167 + hw->dch.state = (buf[0] >> 4); 1168 + schedule_event(&hw->dch, FLG_PHCHANGE); 1169 + } 1170 + 1171 + eof[fifon] = buf[0] & 1; 1172 + /* if we have more than the 2 status bytes -> collect data */ 1173 + if (len > 2) 1174 + hfcsusb_rx_frame(fifo, buf + 2, 1175 + urb->actual_length - 2, 1176 + (len < maxlen) ? eof[fifon] : 0); 1177 + } else { 1178 + hfcsusb_rx_frame(fifo, buf, urb->actual_length, 1179 + (len < maxlen) ? eof[fifon] : 0); 1180 + } 1181 + fifo->last_urblen = urb->actual_length; 1182 + 1183 + status = usb_submit_urb(urb, GFP_ATOMIC); 1184 + if (status) { 1185 + if (debug & DEBUG_HW) 1186 + printk(KERN_DEBUG "%s: %s: error resubmitting USB\n", 1187 + hw->name, __func__); 1188 + } 1189 + } 1190 + 1191 + /* transmit completion routine for all ISO tx fifos */ 1192 + static void 1193 + tx_iso_complete(struct urb *urb) 1194 + { 1195 + struct iso_urb *context_iso_urb = (struct iso_urb *) urb->context; 1196 + struct usb_fifo *fifo = context_iso_urb->owner_fifo; 1197 + struct hfcsusb *hw = fifo->hw; 1198 + struct sk_buff *tx_skb; 1199 + int k, tx_offset, num_isoc_packets, sink, remain, current_len, 1200 + errcode, hdlc, i; 1201 + int *tx_idx; 1202 + int frame_complete, fifon, status; 1203 + __u8 threshbit; 1204 + 1205 + spin_lock(&hw->lock); 1206 + if (fifo->stop_gracefull) { 1207 + fifo->stop_gracefull = 0; 1208 + fifo->active = 0; 1209 + spin_unlock(&hw->lock); 1210 + return; 1211 + } 1212 + 1213 + if (fifo->dch) { 1214 + tx_skb = fifo->dch->tx_skb; 1215 + tx_idx = &fifo->dch->tx_idx; 1216 + hdlc = 1; 1217 + } else if (fifo->bch) { 1218 + tx_skb = fifo->bch->tx_skb; 1219 + tx_idx = &fifo->bch->tx_idx; 1220 + hdlc = test_bit(FLG_HDLC, &fifo->bch->Flags); 1221 + } else { 1222 + printk(KERN_DEBUG "%s: %s: neither BCH nor DCH\n", 1223 + hw->name, __func__); 1224 + spin_unlock(&hw->lock); 1225 + return; 1226 + } 1227 + 1228 + fifon = fifo->fifonum; 1229 + status = urb->status; 1230 + 1231 + tx_offset = 0; 1232 + 1233 + /* 1234 + * ISO transfer only partially completed, 1235 + * look at individual frame status for details 1236 + */ 1237 + if (status == -EXDEV) { 1238 + if (debug & DBG_HFC_URB_ERROR) 1239 + printk(KERN_DEBUG "%s: %s: " 1240 + "-EXDEV (%i) fifon (%d)\n", 1241 + hw->name, __func__, status, fifon); 1242 + 1243 + /* clear status, so go on with ISO transfers */ 1244 + status = 0; 1245 + } 1246 + 1247 + if (fifo->active && !status) { 1248 + /* is FifoFull-threshold set for our channel? */ 1249 + threshbit = (hw->threshold_mask & (1 << fifon)); 1250 + num_isoc_packets = iso_packets[fifon]; 1251 + 1252 + /* predict dataflow to avoid fifo overflow */ 1253 + if (fifon >= HFCUSB_D_TX) 1254 + sink = (threshbit) ? SINK_DMIN : SINK_DMAX; 1255 + else 1256 + sink = (threshbit) ? SINK_MIN : SINK_MAX; 1257 + fill_isoc_urb(urb, fifo->hw->dev, fifo->pipe, 1258 + context_iso_urb->buffer, num_isoc_packets, 1259 + fifo->usb_packet_maxlen, fifo->intervall, 1260 + (usb_complete_t)tx_iso_complete, urb->context); 1261 + memset(context_iso_urb->buffer, 0, 1262 + sizeof(context_iso_urb->buffer)); 1263 + frame_complete = 0; 1264 + 1265 + for (k = 0; k < num_isoc_packets; ++k) { 1266 + /* analyze tx success of previous ISO packets */ 1267 + if (debug & DBG_HFC_URB_ERROR) { 1268 + errcode = urb->iso_frame_desc[k].status; 1269 + if (errcode) { 1270 + printk(KERN_DEBUG "%s: %s: " 1271 + "ISO packet %i, status: %i\n", 1272 + hw->name, __func__, k, errcode); 1273 + } 1274 + } 1275 + 1276 + /* Generate next ISO Packets */ 1277 + if (tx_skb) 1278 + remain = tx_skb->len - *tx_idx; 1279 + else 1280 + remain = 0; 1281 + 1282 + if (remain > 0) { 1283 + fifo->bit_line -= sink; 1284 + current_len = (0 - fifo->bit_line) / 8; 1285 + if (current_len > 14) 1286 + current_len = 14; 1287 + if (current_len < 0) 1288 + current_len = 0; 1289 + if (remain < current_len) 1290 + current_len = remain; 1291 + 1292 + /* how much bit do we put on the line? */ 1293 + fifo->bit_line += current_len * 8; 1294 + 1295 + context_iso_urb->buffer[tx_offset] = 0; 1296 + if (current_len == remain) { 1297 + if (hdlc) { 1298 + /* signal frame completion */ 1299 + context_iso_urb-> 1300 + buffer[tx_offset] = 1; 1301 + /* add 2 byte flags and 16bit 1302 + * CRC at end of ISDN frame */ 1303 + fifo->bit_line += 32; 1304 + } 1305 + frame_complete = 1; 1306 + } 1307 + 1308 + /* copy tx data to iso-urb buffer */ 1309 + memcpy(context_iso_urb->buffer + tx_offset + 1, 1310 + (tx_skb->data + *tx_idx), current_len); 1311 + *tx_idx += current_len; 1312 + 1313 + urb->iso_frame_desc[k].offset = tx_offset; 1314 + urb->iso_frame_desc[k].length = current_len + 1; 1315 + 1316 + /* USB data log for every D ISO out */ 1317 + if ((fifon == HFCUSB_D_RX) && 1318 + (debug & DBG_HFC_USB_VERBOSE)) { 1319 + printk(KERN_DEBUG 1320 + "%s: %s (%d/%d) offs(%d) len(%d) ", 1321 + hw->name, __func__, 1322 + k, num_isoc_packets-1, 1323 + urb->iso_frame_desc[k].offset, 1324 + urb->iso_frame_desc[k].length); 1325 + 1326 + for (i = urb->iso_frame_desc[k].offset; 1327 + i < (urb->iso_frame_desc[k].offset 1328 + + urb->iso_frame_desc[k].length); 1329 + i++) 1330 + printk("%x ", 1331 + context_iso_urb->buffer[i]); 1332 + 1333 + printk(" skb->len(%i) tx-idx(%d)\n", 1334 + tx_skb->len, *tx_idx); 1335 + } 1336 + 1337 + tx_offset += (current_len + 1); 1338 + } else { 1339 + urb->iso_frame_desc[k].offset = tx_offset++; 1340 + urb->iso_frame_desc[k].length = 1; 1341 + /* we lower data margin every msec */ 1342 + fifo->bit_line -= sink; 1343 + if (fifo->bit_line < BITLINE_INF) 1344 + fifo->bit_line = BITLINE_INF; 1345 + } 1346 + 1347 + if (frame_complete) { 1348 + frame_complete = 0; 1349 + 1350 + if (debug & DBG_HFC_FIFO_VERBOSE) { 1351 + printk(KERN_DEBUG "%s: %s: " 1352 + "fifon(%i) new TX len(%i): ", 1353 + hw->name, __func__, 1354 + fifon, tx_skb->len); 1355 + i = 0; 1356 + while (i < tx_skb->len) 1357 + printk("%02x ", 1358 + tx_skb->data[i++]); 1359 + printk("\n"); 1360 + } 1361 + 1362 + dev_kfree_skb(tx_skb); 1363 + tx_skb = NULL; 1364 + if (fifo->dch && get_next_dframe(fifo->dch)) 1365 + tx_skb = fifo->dch->tx_skb; 1366 + else if (fifo->bch && 1367 + get_next_bframe(fifo->bch)) { 1368 + if (test_bit(FLG_TRANSPARENT, 1369 + &fifo->bch->Flags)) 1370 + confirm_Bsend(fifo->bch); 1371 + tx_skb = fifo->bch->tx_skb; 1372 + } 1373 + } 1374 + } 1375 + errcode = usb_submit_urb(urb, GFP_ATOMIC); 1376 + if (errcode < 0) { 1377 + if (debug & DEBUG_HW) 1378 + printk(KERN_DEBUG 1379 + "%s: %s: error submitting ISO URB: %d \n", 1380 + hw->name, __func__, errcode); 1381 + } 1382 + 1383 + /* 1384 + * abuse DChannel tx iso completion to trigger NT mode state 1385 + * changes tx_iso_complete is assumed to be called every 1386 + * fifo->intervall (ms) 1387 + */ 1388 + if ((fifon == HFCUSB_D_TX) && (hw->protocol == ISDN_P_NT_S0) 1389 + && (hw->timers & NT_ACTIVATION_TIMER)) { 1390 + if ((--hw->nt_timer) < 0) 1391 + schedule_event(&hw->dch, FLG_PHCHANGE); 1392 + } 1393 + 1394 + } else { 1395 + if (status && (debug & DBG_HFC_URB_ERROR)) 1396 + printk(KERN_DEBUG "%s: %s: urb->status %s (%i)" 1397 + "fifonum=%d\n", 1398 + hw->name, __func__, 1399 + symbolic(urb_errlist, status), status, fifon); 1400 + } 1401 + spin_unlock(&hw->lock); 1402 + } 1403 + 1404 + /* 1405 + * allocs urbs and start isoc transfer with two pending urbs to avoid 1406 + * gaps in the transfer chain 1407 + */ 1408 + static int 1409 + start_isoc_chain(struct usb_fifo *fifo, int num_packets_per_urb, 1410 + usb_complete_t complete, int packet_size) 1411 + { 1412 + struct hfcsusb *hw = fifo->hw; 1413 + int i, k, errcode; 1414 + 1415 + if (debug) 1416 + printk(KERN_DEBUG "%s: %s: fifo %i\n", 1417 + hw->name, __func__, fifo->fifonum); 1418 + 1419 + /* allocate Memory for Iso out Urbs */ 1420 + for (i = 0; i < 2; i++) { 1421 + if (!(fifo->iso[i].urb)) { 1422 + fifo->iso[i].urb = 1423 + usb_alloc_urb(num_packets_per_urb, GFP_KERNEL); 1424 + if (!(fifo->iso[i].urb)) { 1425 + printk(KERN_DEBUG 1426 + "%s: %s: alloc urb for fifo %i failed", 1427 + hw->name, __func__, fifo->fifonum); 1428 + } 1429 + fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo; 1430 + fifo->iso[i].indx = i; 1431 + 1432 + /* Init the first iso */ 1433 + if (ISO_BUFFER_SIZE >= 1434 + (fifo->usb_packet_maxlen * 1435 + num_packets_per_urb)) { 1436 + fill_isoc_urb(fifo->iso[i].urb, 1437 + fifo->hw->dev, fifo->pipe, 1438 + fifo->iso[i].buffer, 1439 + num_packets_per_urb, 1440 + fifo->usb_packet_maxlen, 1441 + fifo->intervall, complete, 1442 + &fifo->iso[i]); 1443 + memset(fifo->iso[i].buffer, 0, 1444 + sizeof(fifo->iso[i].buffer)); 1445 + 1446 + for (k = 0; k < num_packets_per_urb; k++) { 1447 + fifo->iso[i].urb-> 1448 + iso_frame_desc[k].offset = 1449 + k * packet_size; 1450 + fifo->iso[i].urb-> 1451 + iso_frame_desc[k].length = 1452 + packet_size; 1453 + } 1454 + } else { 1455 + printk(KERN_DEBUG 1456 + "%s: %s: ISO Buffer size to small!\n", 1457 + hw->name, __func__); 1458 + } 1459 + } 1460 + fifo->bit_line = BITLINE_INF; 1461 + 1462 + errcode = usb_submit_urb(fifo->iso[i].urb, GFP_KERNEL); 1463 + fifo->active = (errcode >= 0) ? 1 : 0; 1464 + fifo->stop_gracefull = 0; 1465 + if (errcode < 0) { 1466 + printk(KERN_DEBUG "%s: %s: %s URB nr:%d\n", 1467 + hw->name, __func__, 1468 + symbolic(urb_errlist, errcode), i); 1469 + } 1470 + } 1471 + return fifo->active; 1472 + } 1473 + 1474 + static void 1475 + stop_iso_gracefull(struct usb_fifo *fifo) 1476 + { 1477 + struct hfcsusb *hw = fifo->hw; 1478 + int i, timeout; 1479 + u_long flags; 1480 + 1481 + for (i = 0; i < 2; i++) { 1482 + spin_lock_irqsave(&hw->lock, flags); 1483 + if (debug) 1484 + printk(KERN_DEBUG "%s: %s for fifo %i.%i\n", 1485 + hw->name, __func__, fifo->fifonum, i); 1486 + fifo->stop_gracefull = 1; 1487 + spin_unlock_irqrestore(&hw->lock, flags); 1488 + } 1489 + 1490 + for (i = 0; i < 2; i++) { 1491 + timeout = 3; 1492 + while (fifo->stop_gracefull && timeout--) 1493 + schedule_timeout_interruptible((HZ/1000)*16); 1494 + if (debug && fifo->stop_gracefull) 1495 + printk(KERN_DEBUG "%s: ERROR %s for fifo %i.%i\n", 1496 + hw->name, __func__, fifo->fifonum, i); 1497 + } 1498 + } 1499 + 1500 + static void 1501 + stop_int_gracefull(struct usb_fifo *fifo) 1502 + { 1503 + struct hfcsusb *hw = fifo->hw; 1504 + int timeout; 1505 + u_long flags; 1506 + 1507 + spin_lock_irqsave(&hw->lock, flags); 1508 + if (debug) 1509 + printk(KERN_DEBUG "%s: %s for fifo %i\n", 1510 + hw->name, __func__, fifo->fifonum); 1511 + fifo->stop_gracefull = 1; 1512 + spin_unlock_irqrestore(&hw->lock, flags); 1513 + 1514 + timeout = 3; 1515 + while (fifo->stop_gracefull && timeout--) 1516 + schedule_timeout_interruptible((HZ/1000)*3); 1517 + if (debug && fifo->stop_gracefull) 1518 + printk(KERN_DEBUG "%s: ERROR %s for fifo %i\n", 1519 + hw->name, __func__, fifo->fifonum); 1520 + } 1521 + 1522 + /* start the interrupt transfer for the given fifo */ 1523 + static void 1524 + start_int_fifo(struct usb_fifo *fifo) 1525 + { 1526 + struct hfcsusb *hw = fifo->hw; 1527 + int errcode; 1528 + 1529 + if (debug) 1530 + printk(KERN_DEBUG "%s: %s: INT IN fifo:%d\n", 1531 + hw->name, __func__, fifo->fifonum); 1532 + 1533 + if (!fifo->urb) { 1534 + fifo->urb = usb_alloc_urb(0, GFP_KERNEL); 1535 + if (!fifo->urb) 1536 + return; 1537 + } 1538 + usb_fill_int_urb(fifo->urb, fifo->hw->dev, fifo->pipe, 1539 + fifo->buffer, fifo->usb_packet_maxlen, 1540 + (usb_complete_t)rx_int_complete, fifo, fifo->intervall); 1541 + fifo->active = 1; 1542 + fifo->stop_gracefull = 0; 1543 + errcode = usb_submit_urb(fifo->urb, GFP_KERNEL); 1544 + if (errcode) { 1545 + printk(KERN_DEBUG "%s: %s: submit URB: status:%i\n", 1546 + hw->name, __func__, errcode); 1547 + fifo->active = 0; 1548 + } 1549 + } 1550 + 1551 + static void 1552 + setPortMode(struct hfcsusb *hw) 1553 + { 1554 + if (debug & DEBUG_HW) 1555 + printk(KERN_DEBUG "%s: %s %s\n", hw->name, __func__, 1556 + (hw->protocol == ISDN_P_TE_S0) ? "TE" : "NT"); 1557 + 1558 + if (hw->protocol == ISDN_P_TE_S0) { 1559 + write_reg(hw, HFCUSB_SCTRL, 0x40); 1560 + write_reg(hw, HFCUSB_SCTRL_E, 0x00); 1561 + write_reg(hw, HFCUSB_CLKDEL, CLKDEL_TE); 1562 + write_reg(hw, HFCUSB_STATES, 3 | 0x10); 1563 + write_reg(hw, HFCUSB_STATES, 3); 1564 + } else { 1565 + write_reg(hw, HFCUSB_SCTRL, 0x44); 1566 + write_reg(hw, HFCUSB_SCTRL_E, 0x09); 1567 + write_reg(hw, HFCUSB_CLKDEL, CLKDEL_NT); 1568 + write_reg(hw, HFCUSB_STATES, 1 | 0x10); 1569 + write_reg(hw, HFCUSB_STATES, 1); 1570 + } 1571 + } 1572 + 1573 + static void 1574 + reset_hfcsusb(struct hfcsusb *hw) 1575 + { 1576 + struct usb_fifo *fifo; 1577 + int i; 1578 + 1579 + if (debug & DEBUG_HW) 1580 + printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); 1581 + 1582 + /* do Chip reset */ 1583 + write_reg(hw, HFCUSB_CIRM, 8); 1584 + 1585 + /* aux = output, reset off */ 1586 + write_reg(hw, HFCUSB_CIRM, 0x10); 1587 + 1588 + /* set USB_SIZE to match the wMaxPacketSize for INT or BULK transfers */ 1589 + write_reg(hw, HFCUSB_USB_SIZE, (hw->packet_size / 8) | 1590 + ((hw->packet_size / 8) << 4)); 1591 + 1592 + /* set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers */ 1593 + write_reg(hw, HFCUSB_USB_SIZE_I, hw->iso_packet_size); 1594 + 1595 + /* enable PCM/GCI master mode */ 1596 + write_reg(hw, HFCUSB_MST_MODE1, 0); /* set default values */ 1597 + write_reg(hw, HFCUSB_MST_MODE0, 1); /* enable master mode */ 1598 + 1599 + /* init the fifos */ 1600 + write_reg(hw, HFCUSB_F_THRES, 1601 + (HFCUSB_TX_THRESHOLD / 8) | ((HFCUSB_RX_THRESHOLD / 8) << 4)); 1602 + 1603 + fifo = hw->fifos; 1604 + for (i = 0; i < HFCUSB_NUM_FIFOS; i++) { 1605 + write_reg(hw, HFCUSB_FIFO, i); /* select the desired fifo */ 1606 + fifo[i].max_size = 1607 + (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN; 1608 + fifo[i].last_urblen = 0; 1609 + 1610 + /* set 2 bit for D- & E-channel */ 1611 + write_reg(hw, HFCUSB_HDLC_PAR, ((i <= HFCUSB_B2_RX) ? 0 : 2)); 1612 + 1613 + /* enable all fifos */ 1614 + if (i == HFCUSB_D_TX) 1615 + write_reg(hw, HFCUSB_CON_HDLC, 1616 + (hw->protocol == ISDN_P_NT_S0) ? 0x08 : 0x09); 1617 + else 1618 + write_reg(hw, HFCUSB_CON_HDLC, 0x08); 1619 + write_reg(hw, HFCUSB_INC_RES_F, 2); /* reset the fifo */ 1620 + } 1621 + 1622 + write_reg(hw, HFCUSB_SCTRL_R, 0); /* disable both B receivers */ 1623 + handle_led(hw, LED_POWER_ON); 1624 + } 1625 + 1626 + /* start USB data pipes dependand on device's endpoint configuration */ 1627 + static void 1628 + hfcsusb_start_endpoint(struct hfcsusb *hw, int channel) 1629 + { 1630 + /* quick check if endpoint already running */ 1631 + if ((channel == HFC_CHAN_D) && (hw->fifos[HFCUSB_D_RX].active)) 1632 + return; 1633 + if ((channel == HFC_CHAN_B1) && (hw->fifos[HFCUSB_B1_RX].active)) 1634 + return; 1635 + if ((channel == HFC_CHAN_B2) && (hw->fifos[HFCUSB_B2_RX].active)) 1636 + return; 1637 + if ((channel == HFC_CHAN_E) && (hw->fifos[HFCUSB_PCM_RX].active)) 1638 + return; 1639 + 1640 + /* start rx endpoints using USB INT IN method */ 1641 + if (hw->cfg_used == CNF_3INT3ISO || hw->cfg_used == CNF_4INT3ISO) 1642 + start_int_fifo(hw->fifos + channel*2 + 1); 1643 + 1644 + /* start rx endpoints using USB ISO IN method */ 1645 + if (hw->cfg_used == CNF_3ISO3ISO || hw->cfg_used == CNF_4ISO3ISO) { 1646 + switch (channel) { 1647 + case HFC_CHAN_D: 1648 + start_isoc_chain(hw->fifos + HFCUSB_D_RX, 1649 + ISOC_PACKETS_D, 1650 + (usb_complete_t)rx_iso_complete, 1651 + 16); 1652 + break; 1653 + case HFC_CHAN_E: 1654 + start_isoc_chain(hw->fifos + HFCUSB_PCM_RX, 1655 + ISOC_PACKETS_D, 1656 + (usb_complete_t)rx_iso_complete, 1657 + 16); 1658 + break; 1659 + case HFC_CHAN_B1: 1660 + start_isoc_chain(hw->fifos + HFCUSB_B1_RX, 1661 + ISOC_PACKETS_B, 1662 + (usb_complete_t)rx_iso_complete, 1663 + 16); 1664 + break; 1665 + case HFC_CHAN_B2: 1666 + start_isoc_chain(hw->fifos + HFCUSB_B2_RX, 1667 + ISOC_PACKETS_B, 1668 + (usb_complete_t)rx_iso_complete, 1669 + 16); 1670 + break; 1671 + } 1672 + } 1673 + 1674 + /* start tx endpoints using USB ISO OUT method */ 1675 + switch (channel) { 1676 + case HFC_CHAN_D: 1677 + start_isoc_chain(hw->fifos + HFCUSB_D_TX, 1678 + ISOC_PACKETS_B, 1679 + (usb_complete_t)tx_iso_complete, 1); 1680 + break; 1681 + case HFC_CHAN_B1: 1682 + start_isoc_chain(hw->fifos + HFCUSB_B1_TX, 1683 + ISOC_PACKETS_D, 1684 + (usb_complete_t)tx_iso_complete, 1); 1685 + break; 1686 + case HFC_CHAN_B2: 1687 + start_isoc_chain(hw->fifos + HFCUSB_B2_TX, 1688 + ISOC_PACKETS_B, 1689 + (usb_complete_t)tx_iso_complete, 1); 1690 + break; 1691 + } 1692 + } 1693 + 1694 + /* stop USB data pipes dependand on device's endpoint configuration */ 1695 + static void 1696 + hfcsusb_stop_endpoint(struct hfcsusb *hw, int channel) 1697 + { 1698 + /* quick check if endpoint currently running */ 1699 + if ((channel == HFC_CHAN_D) && (!hw->fifos[HFCUSB_D_RX].active)) 1700 + return; 1701 + if ((channel == HFC_CHAN_B1) && (!hw->fifos[HFCUSB_B1_RX].active)) 1702 + return; 1703 + if ((channel == HFC_CHAN_B2) && (!hw->fifos[HFCUSB_B2_RX].active)) 1704 + return; 1705 + if ((channel == HFC_CHAN_E) && (!hw->fifos[HFCUSB_PCM_RX].active)) 1706 + return; 1707 + 1708 + /* rx endpoints using USB INT IN method */ 1709 + if (hw->cfg_used == CNF_3INT3ISO || hw->cfg_used == CNF_4INT3ISO) 1710 + stop_int_gracefull(hw->fifos + channel*2 + 1); 1711 + 1712 + /* rx endpoints using USB ISO IN method */ 1713 + if (hw->cfg_used == CNF_3ISO3ISO || hw->cfg_used == CNF_4ISO3ISO) 1714 + stop_iso_gracefull(hw->fifos + channel*2 + 1); 1715 + 1716 + /* tx endpoints using USB ISO OUT method */ 1717 + if (channel != HFC_CHAN_E) 1718 + stop_iso_gracefull(hw->fifos + channel*2); 1719 + } 1720 + 1721 + 1722 + /* Hardware Initialization */ 1723 + int 1724 + setup_hfcsusb(struct hfcsusb *hw) 1725 + { 1726 + int err; 1727 + u_char b; 1728 + 1729 + if (debug & DBG_HFC_CALL_TRACE) 1730 + printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); 1731 + 1732 + /* check the chip id */ 1733 + if (read_reg_atomic(hw, HFCUSB_CHIP_ID, &b) != 1) { 1734 + printk(KERN_DEBUG "%s: %s: cannot read chip id\n", 1735 + hw->name, __func__); 1736 + return 1; 1737 + } 1738 + if (b != HFCUSB_CHIPID) { 1739 + printk(KERN_DEBUG "%s: %s: Invalid chip id 0x%02x\n", 1740 + hw->name, __func__, b); 1741 + return 1; 1742 + } 1743 + 1744 + /* first set the needed config, interface and alternate */ 1745 + err = usb_set_interface(hw->dev, hw->if_used, hw->alt_used); 1746 + 1747 + hw->led_state = 0; 1748 + 1749 + /* init the background machinery for control requests */ 1750 + hw->ctrl_read.bRequestType = 0xc0; 1751 + hw->ctrl_read.bRequest = 1; 1752 + hw->ctrl_read.wLength = cpu_to_le16(1); 1753 + hw->ctrl_write.bRequestType = 0x40; 1754 + hw->ctrl_write.bRequest = 0; 1755 + hw->ctrl_write.wLength = 0; 1756 + usb_fill_control_urb(hw->ctrl_urb, hw->dev, hw->ctrl_out_pipe, 1757 + (u_char *)&hw->ctrl_write, NULL, 0, 1758 + (usb_complete_t)ctrl_complete, hw); 1759 + 1760 + reset_hfcsusb(hw); 1761 + return 0; 1762 + } 1763 + 1764 + static void 1765 + release_hw(struct hfcsusb *hw) 1766 + { 1767 + if (debug & DBG_HFC_CALL_TRACE) 1768 + printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); 1769 + 1770 + /* 1771 + * stop all endpoints gracefully 1772 + * TODO: mISDN_core should generate CLOSE_CHANNEL 1773 + * signals after calling mISDN_unregister_device() 1774 + */ 1775 + hfcsusb_stop_endpoint(hw, HFC_CHAN_D); 1776 + hfcsusb_stop_endpoint(hw, HFC_CHAN_B1); 1777 + hfcsusb_stop_endpoint(hw, HFC_CHAN_B2); 1778 + if (hw->fifos[HFCUSB_PCM_RX].pipe) 1779 + hfcsusb_stop_endpoint(hw, HFC_CHAN_E); 1780 + if (hw->protocol == ISDN_P_TE_S0) 1781 + l1_event(hw->dch.l1, CLOSE_CHANNEL); 1782 + 1783 + mISDN_unregister_device(&hw->dch.dev); 1784 + mISDN_freebchannel(&hw->bch[1]); 1785 + mISDN_freebchannel(&hw->bch[0]); 1786 + mISDN_freedchannel(&hw->dch); 1787 + 1788 + if (hw->ctrl_urb) { 1789 + usb_kill_urb(hw->ctrl_urb); 1790 + usb_free_urb(hw->ctrl_urb); 1791 + hw->ctrl_urb = NULL; 1792 + } 1793 + 1794 + if (hw->intf) 1795 + usb_set_intfdata(hw->intf, NULL); 1796 + list_del(&hw->list); 1797 + kfree(hw); 1798 + hw = NULL; 1799 + } 1800 + 1801 + static void 1802 + deactivate_bchannel(struct bchannel *bch) 1803 + { 1804 + struct hfcsusb *hw = bch->hw; 1805 + u_long flags; 1806 + 1807 + if (bch->debug & DEBUG_HW) 1808 + printk(KERN_DEBUG "%s: %s: bch->nr(%i)\n", 1809 + hw->name, __func__, bch->nr); 1810 + 1811 + spin_lock_irqsave(&hw->lock, flags); 1812 + if (test_and_clear_bit(FLG_TX_NEXT, &bch->Flags)) { 1813 + dev_kfree_skb(bch->next_skb); 1814 + bch->next_skb = NULL; 1815 + } 1816 + if (bch->tx_skb) { 1817 + dev_kfree_skb(bch->tx_skb); 1818 + bch->tx_skb = NULL; 1819 + } 1820 + bch->tx_idx = 0; 1821 + if (bch->rx_skb) { 1822 + dev_kfree_skb(bch->rx_skb); 1823 + bch->rx_skb = NULL; 1824 + } 1825 + clear_bit(FLG_ACTIVE, &bch->Flags); 1826 + clear_bit(FLG_TX_BUSY, &bch->Flags); 1827 + spin_unlock_irqrestore(&hw->lock, flags); 1828 + hfcsusb_setup_bch(bch, ISDN_P_NONE); 1829 + hfcsusb_stop_endpoint(hw, bch->nr); 1830 + } 1831 + 1832 + /* 1833 + * Layer 1 B-channel hardware access 1834 + */ 1835 + static int 1836 + hfc_bctrl(struct mISDNchannel *ch, u_int cmd, void *arg) 1837 + { 1838 + struct bchannel *bch = container_of(ch, struct bchannel, ch); 1839 + int ret = -EINVAL; 1840 + 1841 + if (bch->debug & DEBUG_HW) 1842 + printk(KERN_DEBUG "%s: cmd:%x %p\n", __func__, cmd, arg); 1843 + 1844 + switch (cmd) { 1845 + case HW_TESTRX_RAW: 1846 + case HW_TESTRX_HDLC: 1847 + case HW_TESTRX_OFF: 1848 + ret = -EINVAL; 1849 + break; 1850 + 1851 + case CLOSE_CHANNEL: 1852 + test_and_clear_bit(FLG_OPEN, &bch->Flags); 1853 + if (test_bit(FLG_ACTIVE, &bch->Flags)) 1854 + deactivate_bchannel(bch); 1855 + ch->protocol = ISDN_P_NONE; 1856 + ch->peer = NULL; 1857 + module_put(THIS_MODULE); 1858 + ret = 0; 1859 + break; 1860 + case CONTROL_CHANNEL: 1861 + ret = channel_bctrl(bch, arg); 1862 + break; 1863 + default: 1864 + printk(KERN_WARNING "%s: unknown prim(%x)\n", 1865 + __func__, cmd); 1866 + } 1867 + return ret; 1868 + } 1869 + 1870 + static int 1871 + setup_instance(struct hfcsusb *hw, struct device *parent) 1872 + { 1873 + u_long flags; 1874 + int err, i; 1875 + 1876 + if (debug & DBG_HFC_CALL_TRACE) 1877 + printk(KERN_DEBUG "%s: %s\n", hw->name, __func__); 1878 + 1879 + spin_lock_init(&hw->ctrl_lock); 1880 + spin_lock_init(&hw->lock); 1881 + 1882 + mISDN_initdchannel(&hw->dch, MAX_DFRAME_LEN_L1, ph_state); 1883 + hw->dch.debug = debug & 0xFFFF; 1884 + hw->dch.hw = hw; 1885 + hw->dch.dev.Dprotocols = (1 << ISDN_P_TE_S0) | (1 << ISDN_P_NT_S0); 1886 + hw->dch.dev.D.send = hfcusb_l2l1D; 1887 + hw->dch.dev.D.ctrl = hfc_dctrl; 1888 + 1889 + /* enable E-Channel logging */ 1890 + if (hw->fifos[HFCUSB_PCM_RX].pipe) 1891 + mISDN_initdchannel(&hw->ech, MAX_DFRAME_LEN_L1, NULL); 1892 + 1893 + hw->dch.dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) | 1894 + (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK)); 1895 + hw->dch.dev.nrbchan = 2; 1896 + for (i = 0; i < 2; i++) { 1897 + hw->bch[i].nr = i + 1; 1898 + set_channelmap(i + 1, hw->dch.dev.channelmap); 1899 + hw->bch[i].debug = debug; 1900 + mISDN_initbchannel(&hw->bch[i], MAX_DATA_MEM); 1901 + hw->bch[i].hw = hw; 1902 + hw->bch[i].ch.send = hfcusb_l2l1B; 1903 + hw->bch[i].ch.ctrl = hfc_bctrl; 1904 + hw->bch[i].ch.nr = i + 1; 1905 + list_add(&hw->bch[i].ch.list, &hw->dch.dev.bchannels); 1906 + } 1907 + 1908 + hw->fifos[HFCUSB_B1_TX].bch = &hw->bch[0]; 1909 + hw->fifos[HFCUSB_B1_RX].bch = &hw->bch[0]; 1910 + hw->fifos[HFCUSB_B2_TX].bch = &hw->bch[1]; 1911 + hw->fifos[HFCUSB_B2_RX].bch = &hw->bch[1]; 1912 + hw->fifos[HFCUSB_D_TX].dch = &hw->dch; 1913 + hw->fifos[HFCUSB_D_RX].dch = &hw->dch; 1914 + hw->fifos[HFCUSB_PCM_RX].ech = &hw->ech; 1915 + hw->fifos[HFCUSB_PCM_TX].ech = &hw->ech; 1916 + 1917 + err = setup_hfcsusb(hw); 1918 + if (err) 1919 + goto out; 1920 + 1921 + snprintf(hw->name, MISDN_MAX_IDLEN - 1, "%s.%d", DRIVER_NAME, 1922 + hfcsusb_cnt + 1); 1923 + printk(KERN_INFO "%s: registered as '%s'\n", 1924 + DRIVER_NAME, hw->name); 1925 + 1926 + err = mISDN_register_device(&hw->dch.dev, parent, hw->name); 1927 + if (err) 1928 + goto out; 1929 + 1930 + hfcsusb_cnt++; 1931 + write_lock_irqsave(&HFClock, flags); 1932 + list_add_tail(&hw->list, &HFClist); 1933 + write_unlock_irqrestore(&HFClock, flags); 1934 + return 0; 1935 + 1936 + out: 1937 + mISDN_freebchannel(&hw->bch[1]); 1938 + mISDN_freebchannel(&hw->bch[0]); 1939 + mISDN_freedchannel(&hw->dch); 1940 + kfree(hw); 1941 + return err; 1942 + } 1943 + 1944 + static int 1945 + hfcsusb_probe(struct usb_interface *intf, const struct usb_device_id *id) 1946 + { 1947 + struct hfcsusb *hw; 1948 + struct usb_device *dev = interface_to_usbdev(intf); 1949 + struct usb_host_interface *iface = intf->cur_altsetting; 1950 + struct usb_host_interface *iface_used = NULL; 1951 + struct usb_host_endpoint *ep; 1952 + struct hfcsusb_vdata *driver_info; 1953 + int ifnum = iface->desc.bInterfaceNumber, i, idx, alt_idx, 1954 + probe_alt_setting, vend_idx, cfg_used, *vcf, attr, cfg_found, 1955 + ep_addr, cmptbl[16], small_match, iso_packet_size, packet_size, 1956 + alt_used = 0; 1957 + 1958 + vend_idx = 0xffff; 1959 + for (i = 0; hfcsusb_idtab[i].idVendor; i++) { 1960 + if ((le16_to_cpu(dev->descriptor.idVendor) 1961 + == hfcsusb_idtab[i].idVendor) && 1962 + (le16_to_cpu(dev->descriptor.idProduct) 1963 + == hfcsusb_idtab[i].idProduct)) { 1964 + vend_idx = i; 1965 + continue; 1966 + } 1967 + } 1968 + 1969 + printk(KERN_DEBUG 1970 + "%s: interface(%d) actalt(%d) minor(%d) vend_idx(%d)\n", 1971 + __func__, ifnum, iface->desc.bAlternateSetting, 1972 + intf->minor, vend_idx); 1973 + 1974 + if (vend_idx == 0xffff) { 1975 + printk(KERN_WARNING 1976 + "%s: no valid vendor found in USB descriptor\n", 1977 + __func__); 1978 + return -EIO; 1979 + } 1980 + /* if vendor and product ID is OK, start probing alternate settings */ 1981 + alt_idx = 0; 1982 + small_match = -1; 1983 + 1984 + /* default settings */ 1985 + iso_packet_size = 16; 1986 + packet_size = 64; 1987 + 1988 + while (alt_idx < intf->num_altsetting) { 1989 + iface = intf->altsetting + alt_idx; 1990 + probe_alt_setting = iface->desc.bAlternateSetting; 1991 + cfg_used = 0; 1992 + 1993 + while (validconf[cfg_used][0]) { 1994 + cfg_found = 1; 1995 + vcf = validconf[cfg_used]; 1996 + ep = iface->endpoint; 1997 + memcpy(cmptbl, vcf, 16 * sizeof(int)); 1998 + 1999 + /* check for all endpoints in this alternate setting */ 2000 + for (i = 0; i < iface->desc.bNumEndpoints; i++) { 2001 + ep_addr = ep->desc.bEndpointAddress; 2002 + 2003 + /* get endpoint base */ 2004 + idx = ((ep_addr & 0x7f) - 1) * 2; 2005 + if (ep_addr & 0x80) 2006 + idx++; 2007 + attr = ep->desc.bmAttributes; 2008 + 2009 + if (cmptbl[idx] != EP_NOP) { 2010 + if (cmptbl[idx] == EP_NUL) 2011 + cfg_found = 0; 2012 + if (attr == USB_ENDPOINT_XFER_INT 2013 + && cmptbl[idx] == EP_INT) 2014 + cmptbl[idx] = EP_NUL; 2015 + if (attr == USB_ENDPOINT_XFER_BULK 2016 + && cmptbl[idx] == EP_BLK) 2017 + cmptbl[idx] = EP_NUL; 2018 + if (attr == USB_ENDPOINT_XFER_ISOC 2019 + && cmptbl[idx] == EP_ISO) 2020 + cmptbl[idx] = EP_NUL; 2021 + 2022 + if (attr == USB_ENDPOINT_XFER_INT && 2023 + ep->desc.bInterval < vcf[17]) { 2024 + cfg_found = 0; 2025 + } 2026 + } 2027 + ep++; 2028 + } 2029 + 2030 + for (i = 0; i < 16; i++) 2031 + if (cmptbl[i] != EP_NOP && cmptbl[i] != EP_NUL) 2032 + cfg_found = 0; 2033 + 2034 + if (cfg_found) { 2035 + if (small_match < cfg_used) { 2036 + small_match = cfg_used; 2037 + alt_used = probe_alt_setting; 2038 + iface_used = iface; 2039 + } 2040 + } 2041 + cfg_used++; 2042 + } 2043 + alt_idx++; 2044 + } /* (alt_idx < intf->num_altsetting) */ 2045 + 2046 + /* not found a valid USB Ta Endpoint config */ 2047 + if (small_match == -1) 2048 + return -EIO; 2049 + 2050 + iface = iface_used; 2051 + hw = kzalloc(sizeof(struct hfcsusb), GFP_KERNEL); 2052 + if (!hw) 2053 + return -ENOMEM; /* got no mem */ 2054 + snprintf(hw->name, MISDN_MAX_IDLEN - 1, "%s", DRIVER_NAME); 2055 + 2056 + ep = iface->endpoint; 2057 + vcf = validconf[small_match]; 2058 + 2059 + for (i = 0; i < iface->desc.bNumEndpoints; i++) { 2060 + struct usb_fifo *f; 2061 + 2062 + ep_addr = ep->desc.bEndpointAddress; 2063 + /* get endpoint base */ 2064 + idx = ((ep_addr & 0x7f) - 1) * 2; 2065 + if (ep_addr & 0x80) 2066 + idx++; 2067 + f = &hw->fifos[idx & 7]; 2068 + 2069 + /* init Endpoints */ 2070 + if (vcf[idx] == EP_NOP || vcf[idx] == EP_NUL) { 2071 + ep++; 2072 + continue; 2073 + } 2074 + switch (ep->desc.bmAttributes) { 2075 + case USB_ENDPOINT_XFER_INT: 2076 + f->pipe = usb_rcvintpipe(dev, 2077 + ep->desc.bEndpointAddress); 2078 + f->usb_transfer_mode = USB_INT; 2079 + packet_size = le16_to_cpu(ep->desc.wMaxPacketSize); 2080 + break; 2081 + case USB_ENDPOINT_XFER_BULK: 2082 + if (ep_addr & 0x80) 2083 + f->pipe = usb_rcvbulkpipe(dev, 2084 + ep->desc.bEndpointAddress); 2085 + else 2086 + f->pipe = usb_sndbulkpipe(dev, 2087 + ep->desc.bEndpointAddress); 2088 + f->usb_transfer_mode = USB_BULK; 2089 + packet_size = le16_to_cpu(ep->desc.wMaxPacketSize); 2090 + break; 2091 + case USB_ENDPOINT_XFER_ISOC: 2092 + if (ep_addr & 0x80) 2093 + f->pipe = usb_rcvisocpipe(dev, 2094 + ep->desc.bEndpointAddress); 2095 + else 2096 + f->pipe = usb_sndisocpipe(dev, 2097 + ep->desc.bEndpointAddress); 2098 + f->usb_transfer_mode = USB_ISOC; 2099 + iso_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize); 2100 + break; 2101 + default: 2102 + f->pipe = 0; 2103 + } 2104 + 2105 + if (f->pipe) { 2106 + f->fifonum = idx & 7; 2107 + f->hw = hw; 2108 + f->usb_packet_maxlen = 2109 + le16_to_cpu(ep->desc.wMaxPacketSize); 2110 + f->intervall = ep->desc.bInterval; 2111 + } 2112 + ep++; 2113 + } 2114 + hw->dev = dev; /* save device */ 2115 + hw->if_used = ifnum; /* save used interface */ 2116 + hw->alt_used = alt_used; /* and alternate config */ 2117 + hw->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */ 2118 + hw->cfg_used = vcf[16]; /* store used config */ 2119 + hw->vend_idx = vend_idx; /* store found vendor */ 2120 + hw->packet_size = packet_size; 2121 + hw->iso_packet_size = iso_packet_size; 2122 + 2123 + /* create the control pipes needed for register access */ 2124 + hw->ctrl_in_pipe = usb_rcvctrlpipe(hw->dev, 0); 2125 + hw->ctrl_out_pipe = usb_sndctrlpipe(hw->dev, 0); 2126 + hw->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL); 2127 + 2128 + driver_info = 2129 + (struct hfcsusb_vdata *)hfcsusb_idtab[vend_idx].driver_info; 2130 + printk(KERN_DEBUG "%s: %s: detected \"%s\" (%s, if=%d alt=%d)\n", 2131 + hw->name, __func__, driver_info->vend_name, 2132 + conf_str[small_match], ifnum, alt_used); 2133 + 2134 + if (setup_instance(hw, dev->dev.parent)) 2135 + return -EIO; 2136 + 2137 + hw->intf = intf; 2138 + usb_set_intfdata(hw->intf, hw); 2139 + return 0; 2140 + } 2141 + 2142 + /* function called when an active device is removed */ 2143 + static void 2144 + hfcsusb_disconnect(struct usb_interface *intf) 2145 + { 2146 + struct hfcsusb *hw = usb_get_intfdata(intf); 2147 + struct hfcsusb *next; 2148 + int cnt = 0; 2149 + 2150 + printk(KERN_INFO "%s: device disconnected\n", hw->name); 2151 + 2152 + handle_led(hw, LED_POWER_OFF); 2153 + release_hw(hw); 2154 + 2155 + list_for_each_entry_safe(hw, next, &HFClist, list) 2156 + cnt++; 2157 + if (!cnt) 2158 + hfcsusb_cnt = 0; 2159 + 2160 + usb_set_intfdata(intf, NULL); 2161 + } 2162 + 2163 + static struct usb_driver hfcsusb_drv = { 2164 + .name = DRIVER_NAME, 2165 + .id_table = hfcsusb_idtab, 2166 + .probe = hfcsusb_probe, 2167 + .disconnect = hfcsusb_disconnect, 2168 + }; 2169 + 2170 + static int __init 2171 + hfcsusb_init(void) 2172 + { 2173 + printk(KERN_INFO DRIVER_NAME " driver Rev. %s debug(0x%x) poll(%i)\n", 2174 + hfcsusb_rev, debug, poll); 2175 + 2176 + if (usb_register(&hfcsusb_drv)) { 2177 + printk(KERN_INFO DRIVER_NAME 2178 + ": Unable to register hfcsusb module at usb stack\n"); 2179 + return -ENODEV; 2180 + } 2181 + 2182 + return 0; 2183 + } 2184 + 2185 + static void __exit 2186 + hfcsusb_cleanup(void) 2187 + { 2188 + if (debug & DBG_HFC_CALL_TRACE) 2189 + printk(KERN_INFO DRIVER_NAME ": %s\n", __func__); 2190 + 2191 + /* unregister Hardware */ 2192 + usb_deregister(&hfcsusb_drv); /* release our driver */ 2193 + } 2194 + 2195 + module_init(hfcsusb_init); 2196 + module_exit(hfcsusb_cleanup);
+418
drivers/isdn/hardware/mISDN/hfcsusb.h
··· 1 + /* 2 + * hfcsusb.h, HFC-S USB mISDN driver 3 + */ 4 + 5 + #ifndef __HFCSUSB_H__ 6 + #define __HFCSUSB_H__ 7 + 8 + 9 + #define DRIVER_NAME "HFC-S_USB" 10 + 11 + #define DBG_HFC_CALL_TRACE 0x00010000 12 + #define DBG_HFC_FIFO_VERBOSE 0x00020000 13 + #define DBG_HFC_USB_VERBOSE 0x00100000 14 + #define DBG_HFC_URB_INFO 0x00200000 15 + #define DBG_HFC_URB_ERROR 0x00400000 16 + 17 + #define DEFAULT_TRANSP_BURST_SZ 128 18 + 19 + #define HFC_CTRL_TIMEOUT 20 /* 5ms timeout writing/reading regs */ 20 + #define CLKDEL_TE 0x0f /* CLKDEL in TE mode */ 21 + #define CLKDEL_NT 0x6c /* CLKDEL in NT mode */ 22 + 23 + /* hfcsusb Layer1 commands */ 24 + #define HFC_L1_ACTIVATE_TE 1 25 + #define HFC_L1_ACTIVATE_NT 2 26 + #define HFC_L1_DEACTIVATE_NT 3 27 + #define HFC_L1_FORCE_DEACTIVATE_TE 4 28 + 29 + /* cmd FLAGS in HFCUSB_STATES register */ 30 + #define HFCUSB_LOAD_STATE 0x10 31 + #define HFCUSB_ACTIVATE 0x20 32 + #define HFCUSB_DO_ACTION 0x40 33 + #define HFCUSB_NT_G2_G3 0x80 34 + 35 + /* timers */ 36 + #define NT_ACTIVATION_TIMER 0x01 /* enables NT mode activation Timer */ 37 + #define NT_T1_COUNT 10 38 + 39 + #define MAX_BCH_SIZE 2048 /* allowed B-channel packet size */ 40 + 41 + #define HFCUSB_RX_THRESHOLD 64 /* threshold for fifo report bit rx */ 42 + #define HFCUSB_TX_THRESHOLD 96 /* threshold for fifo report bit tx */ 43 + 44 + #define HFCUSB_CHIP_ID 0x16 /* Chip ID register index */ 45 + #define HFCUSB_CIRM 0x00 /* cirm register index */ 46 + #define HFCUSB_USB_SIZE 0x07 /* int length register */ 47 + #define HFCUSB_USB_SIZE_I 0x06 /* iso length register */ 48 + #define HFCUSB_F_CROSS 0x0b /* bit order register */ 49 + #define HFCUSB_CLKDEL 0x37 /* bit delay register */ 50 + #define HFCUSB_CON_HDLC 0xfa /* channel connect register */ 51 + #define HFCUSB_HDLC_PAR 0xfb 52 + #define HFCUSB_SCTRL 0x31 /* S-bus control register (tx) */ 53 + #define HFCUSB_SCTRL_E 0x32 /* same for E and special funcs */ 54 + #define HFCUSB_SCTRL_R 0x33 /* S-bus control register (rx) */ 55 + #define HFCUSB_F_THRES 0x0c /* threshold register */ 56 + #define HFCUSB_FIFO 0x0f /* fifo select register */ 57 + #define HFCUSB_F_USAGE 0x1a /* fifo usage register */ 58 + #define HFCUSB_MST_MODE0 0x14 59 + #define HFCUSB_MST_MODE1 0x15 60 + #define HFCUSB_P_DATA 0x1f 61 + #define HFCUSB_INC_RES_F 0x0e 62 + #define HFCUSB_B1_SSL 0x20 63 + #define HFCUSB_B2_SSL 0x21 64 + #define HFCUSB_B1_RSL 0x24 65 + #define HFCUSB_B2_RSL 0x25 66 + #define HFCUSB_STATES 0x30 67 + 68 + 69 + #define HFCUSB_CHIPID 0x40 /* ID value of HFC-S USB */ 70 + 71 + /* fifo registers */ 72 + #define HFCUSB_NUM_FIFOS 8 /* maximum number of fifos */ 73 + #define HFCUSB_B1_TX 0 /* index for B1 transmit bulk/int */ 74 + #define HFCUSB_B1_RX 1 /* index for B1 receive bulk/int */ 75 + #define HFCUSB_B2_TX 2 76 + #define HFCUSB_B2_RX 3 77 + #define HFCUSB_D_TX 4 78 + #define HFCUSB_D_RX 5 79 + #define HFCUSB_PCM_TX 6 80 + #define HFCUSB_PCM_RX 7 81 + 82 + 83 + #define USB_INT 0 84 + #define USB_BULK 1 85 + #define USB_ISOC 2 86 + 87 + #define ISOC_PACKETS_D 8 88 + #define ISOC_PACKETS_B 8 89 + #define ISO_BUFFER_SIZE 128 90 + 91 + /* defines how much ISO packets are handled in one URB */ 92 + static int iso_packets[8] = 93 + { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, 94 + ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D 95 + }; 96 + 97 + 98 + /* Fifo flow Control for TX ISO */ 99 + #define SINK_MAX 68 100 + #define SINK_MIN 48 101 + #define SINK_DMIN 12 102 + #define SINK_DMAX 18 103 + #define BITLINE_INF (-96*8) 104 + 105 + /* HFC-S USB register access by Control-URSs */ 106 + #define write_reg_atomic(a, b, c) \ 107 + usb_control_msg((a)->dev, (a)->ctrl_out_pipe, 0, 0x40, (c), (b), \ 108 + 0, 0, HFC_CTRL_TIMEOUT) 109 + #define read_reg_atomic(a, b, c) \ 110 + usb_control_msg((a)->dev, (a)->ctrl_in_pipe, 1, 0xC0, 0, (b), (c), \ 111 + 1, HFC_CTRL_TIMEOUT) 112 + #define HFC_CTRL_BUFSIZE 64 113 + 114 + struct ctrl_buf { 115 + __u8 hfcs_reg; /* register number */ 116 + __u8 reg_val; /* value to be written (or read) */ 117 + }; 118 + 119 + /* 120 + * URB error codes 121 + * Used to represent a list of values and their respective symbolic names 122 + */ 123 + struct hfcusb_symbolic_list { 124 + const int num; 125 + const char *name; 126 + }; 127 + 128 + static struct hfcusb_symbolic_list urb_errlist[] = { 129 + {-ENOMEM, "No memory for allocation of internal structures"}, 130 + {-ENOSPC, "The host controller's bandwidth is already consumed"}, 131 + {-ENOENT, "URB was canceled by unlink_urb"}, 132 + {-EXDEV, "ISO transfer only partially completed"}, 133 + {-EAGAIN, "Too match scheduled for the future"}, 134 + {-ENXIO, "URB already queued"}, 135 + {-EFBIG, "Too much ISO frames requested"}, 136 + {-ENOSR, "Buffer error (overrun)"}, 137 + {-EPIPE, "Specified endpoint is stalled (device not responding)"}, 138 + {-EOVERFLOW, "Babble (bad cable?)"}, 139 + {-EPROTO, "Bit-stuff error (bad cable?)"}, 140 + {-EILSEQ, "CRC/Timeout"}, 141 + {-ETIMEDOUT, "NAK (device does not respond)"}, 142 + {-ESHUTDOWN, "Device unplugged"}, 143 + {-1, NULL} 144 + }; 145 + 146 + static inline const char * 147 + symbolic(struct hfcusb_symbolic_list list[], const int num) 148 + { 149 + int i; 150 + for (i = 0; list[i].name != NULL; i++) 151 + if (list[i].num == num) 152 + return list[i].name; 153 + return "<unkown USB Error>"; 154 + } 155 + 156 + /* USB descriptor need to contain one of the following EndPoint combination: */ 157 + #define CNF_4INT3ISO 1 /* 4 INT IN, 3 ISO OUT */ 158 + #define CNF_3INT3ISO 2 /* 3 INT IN, 3 ISO OUT */ 159 + #define CNF_4ISO3ISO 3 /* 4 ISO IN, 3 ISO OUT */ 160 + #define CNF_3ISO3ISO 4 /* 3 ISO IN, 3 ISO OUT */ 161 + 162 + #define EP_NUL 1 /* Endpoint at this position not allowed */ 163 + #define EP_NOP 2 /* all type of endpoints allowed at this position */ 164 + #define EP_ISO 3 /* Isochron endpoint mandatory at this position */ 165 + #define EP_BLK 4 /* Bulk endpoint mandatory at this position */ 166 + #define EP_INT 5 /* Interrupt endpoint mandatory at this position */ 167 + 168 + #define HFC_CHAN_B1 0 169 + #define HFC_CHAN_B2 1 170 + #define HFC_CHAN_D 2 171 + #define HFC_CHAN_E 3 172 + 173 + 174 + /* 175 + * List of all supported enpoints configiration sets, used to find the 176 + * best matching endpoint configuration within a devices' USB descriptor. 177 + * We need at least 3 RX endpoints, and 3 TX endpoints, either 178 + * INT-in and ISO-out, or ISO-in and ISO-out) 179 + * with 4 RX endpoints even E-Channel logging is possible 180 + */ 181 + static int 182 + validconf[][19] = { 183 + /* INT in, ISO out config */ 184 + {EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NOP, EP_INT, 185 + EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_NUL, EP_NUL, 186 + CNF_4INT3ISO, 2, 1}, 187 + {EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_INT, EP_NUL, EP_NUL, 188 + EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_ISO, EP_NUL, EP_NUL, EP_NUL, 189 + CNF_3INT3ISO, 2, 0}, 190 + /* ISO in, ISO out config */ 191 + {EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, EP_NOP, 192 + EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_NOP, EP_ISO, 193 + CNF_4ISO3ISO, 2, 1}, 194 + {EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, EP_NUL, 195 + EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_ISO, EP_NUL, EP_NUL, 196 + CNF_3ISO3ISO, 2, 0}, 197 + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /* EOL element */ 198 + }; 199 + 200 + /* string description of chosen config */ 201 + char *conf_str[] = { 202 + "4 Interrupt IN + 3 Isochron OUT", 203 + "3 Interrupt IN + 3 Isochron OUT", 204 + "4 Isochron IN + 3 Isochron OUT", 205 + "3 Isochron IN + 3 Isochron OUT" 206 + }; 207 + 208 + 209 + #define LED_OFF 0 /* no LED support */ 210 + #define LED_SCHEME1 1 /* LED standard scheme */ 211 + #define LED_SCHEME2 2 /* not used yet... */ 212 + 213 + #define LED_POWER_ON 1 214 + #define LED_POWER_OFF 2 215 + #define LED_S0_ON 3 216 + #define LED_S0_OFF 4 217 + #define LED_B1_ON 5 218 + #define LED_B1_OFF 6 219 + #define LED_B1_DATA 7 220 + #define LED_B2_ON 8 221 + #define LED_B2_OFF 9 222 + #define LED_B2_DATA 10 223 + 224 + #define LED_NORMAL 0 /* LEDs are normal */ 225 + #define LED_INVERTED 1 /* LEDs are inverted */ 226 + 227 + /* time in ms to perform a Flashing LED when B-Channel has traffic */ 228 + #define LED_TIME 250 229 + 230 + 231 + 232 + struct hfcsusb; 233 + struct usb_fifo; 234 + 235 + /* structure defining input+output fifos (interrupt/bulk mode) */ 236 + struct iso_urb { 237 + struct urb *urb; 238 + __u8 buffer[ISO_BUFFER_SIZE]; /* buffer rx/tx USB URB data */ 239 + struct usb_fifo *owner_fifo; /* pointer to owner fifo */ 240 + __u8 indx; /* Fifos's ISO double buffer 0 or 1 ? */ 241 + #ifdef ISO_FRAME_START_DEBUG 242 + int start_frames[ISO_FRAME_START_RING_COUNT]; 243 + __u8 iso_frm_strt_pos; /* index in start_frame[] */ 244 + #endif 245 + }; 246 + 247 + struct usb_fifo { 248 + int fifonum; /* fifo index attached to this structure */ 249 + int active; /* fifo is currently active */ 250 + struct hfcsusb *hw; /* pointer to main structure */ 251 + int pipe; /* address of endpoint */ 252 + __u8 usb_packet_maxlen; /* maximum length for usb transfer */ 253 + unsigned int max_size; /* maximum size of receive/send packet */ 254 + __u8 intervall; /* interrupt interval */ 255 + struct urb *urb; /* transfer structure for usb routines */ 256 + __u8 buffer[128]; /* buffer USB INT OUT URB data */ 257 + int bit_line; /* how much bits are in the fifo? */ 258 + 259 + __u8 usb_transfer_mode; /* switched between ISO and INT */ 260 + struct iso_urb iso[2]; /* two urbs to have one always 261 + one pending */ 262 + 263 + struct dchannel *dch; /* link to hfcsusb_t->dch */ 264 + struct bchannel *bch; /* link to hfcsusb_t->bch */ 265 + struct dchannel *ech; /* link to hfcsusb_t->ech, TODO: E-CHANNEL */ 266 + int last_urblen; /* remember length of last packet */ 267 + __u8 stop_gracefull; /* stops URB retransmission */ 268 + }; 269 + 270 + struct hfcsusb { 271 + struct list_head list; 272 + struct dchannel dch; 273 + struct bchannel bch[2]; 274 + struct dchannel ech; /* TODO : wait for struct echannel ;) */ 275 + 276 + struct usb_device *dev; /* our device */ 277 + struct usb_interface *intf; /* used interface */ 278 + int if_used; /* used interface number */ 279 + int alt_used; /* used alternate config */ 280 + int cfg_used; /* configuration index used */ 281 + int vend_idx; /* index in hfcsusb_idtab */ 282 + int packet_size; 283 + int iso_packet_size; 284 + struct usb_fifo fifos[HFCUSB_NUM_FIFOS]; 285 + 286 + /* control pipe background handling */ 287 + struct ctrl_buf ctrl_buff[HFC_CTRL_BUFSIZE]; 288 + int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; 289 + struct urb *ctrl_urb; 290 + struct usb_ctrlrequest ctrl_write; 291 + struct usb_ctrlrequest ctrl_read; 292 + int ctrl_paksize; 293 + int ctrl_in_pipe, ctrl_out_pipe; 294 + spinlock_t ctrl_lock; /* lock for ctrl */ 295 + spinlock_t lock; 296 + 297 + __u8 threshold_mask; 298 + __u8 led_state; 299 + 300 + __u8 protocol; 301 + int nt_timer; 302 + int open; 303 + __u8 timers; 304 + __u8 initdone; 305 + char name[MISDN_MAX_IDLEN]; 306 + }; 307 + 308 + /* private vendor specific data */ 309 + struct hfcsusb_vdata { 310 + __u8 led_scheme; /* led display scheme */ 311 + signed short led_bits[8]; /* array of 8 possible LED bitmask */ 312 + char *vend_name; /* device name */ 313 + }; 314 + 315 + 316 + #define HFC_MAX_TE_LAYER1_STATE 8 317 + #define HFC_MAX_NT_LAYER1_STATE 4 318 + 319 + const char *HFC_TE_LAYER1_STATES[HFC_MAX_TE_LAYER1_STATE + 1] = { 320 + "TE F0 - Reset", 321 + "TE F1 - Reset", 322 + "TE F2 - Sensing", 323 + "TE F3 - Deactivated", 324 + "TE F4 - Awaiting signal", 325 + "TE F5 - Identifying input", 326 + "TE F6 - Synchronized", 327 + "TE F7 - Activated", 328 + "TE F8 - Lost framing", 329 + }; 330 + 331 + const char *HFC_NT_LAYER1_STATES[HFC_MAX_NT_LAYER1_STATE + 1] = { 332 + "NT G0 - Reset", 333 + "NT G1 - Deactive", 334 + "NT G2 - Pending activation", 335 + "NT G3 - Active", 336 + "NT G4 - Pending deactivation", 337 + }; 338 + 339 + /* supported devices */ 340 + static struct usb_device_id hfcsusb_idtab[] = { 341 + { 342 + USB_DEVICE(0x0959, 0x2bd0), 343 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 344 + {LED_OFF, {4, 0, 2, 1}, 345 + "ISDN USB TA (Cologne Chip HFC-S USB based)"}), 346 + }, 347 + { 348 + USB_DEVICE(0x0675, 0x1688), 349 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 350 + {LED_SCHEME1, {1, 2, 0, 0}, 351 + "DrayTek miniVigor 128 USB ISDN TA"}), 352 + }, 353 + { 354 + USB_DEVICE(0x07b0, 0x0007), 355 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 356 + {LED_SCHEME1, {0x80, -64, -32, -16}, 357 + "Billion tiny USB ISDN TA 128"}), 358 + }, 359 + { 360 + USB_DEVICE(0x0742, 0x2008), 361 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 362 + {LED_SCHEME1, {4, 0, 2, 1}, 363 + "Stollmann USB TA"}), 364 + }, 365 + { 366 + USB_DEVICE(0x0742, 0x2009), 367 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 368 + {LED_SCHEME1, {4, 0, 2, 1}, 369 + "Aceex USB ISDN TA"}), 370 + }, 371 + { 372 + USB_DEVICE(0x0742, 0x200A), 373 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 374 + {LED_SCHEME1, {4, 0, 2, 1}, 375 + "OEM USB ISDN TA"}), 376 + }, 377 + { 378 + USB_DEVICE(0x08e3, 0x0301), 379 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 380 + {LED_SCHEME1, {2, 0, 1, 4}, 381 + "Olitec USB RNIS"}), 382 + }, 383 + { 384 + USB_DEVICE(0x07fa, 0x0846), 385 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 386 + {LED_SCHEME1, {0x80, -64, -32, -16}, 387 + "Bewan Modem RNIS USB"}), 388 + }, 389 + { 390 + USB_DEVICE(0x07fa, 0x0847), 391 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 392 + {LED_SCHEME1, {0x80, -64, -32, -16}, 393 + "Djinn Numeris USB"}), 394 + }, 395 + { 396 + USB_DEVICE(0x07b0, 0x0006), 397 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 398 + {LED_SCHEME1, {0x80, -64, -32, -16}, 399 + "Twister ISDN TA"}), 400 + }, 401 + { 402 + USB_DEVICE(0x071d, 0x1005), 403 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 404 + {LED_SCHEME1, {0x02, 0, 0x01, 0x04}, 405 + "Eicon DIVA USB 4.0"}), 406 + }, 407 + { 408 + USB_DEVICE(0x0586, 0x0102), 409 + .driver_info = (unsigned long) &((struct hfcsusb_vdata) 410 + {LED_SCHEME1, {0x88, -64, -32, -16}, 411 + "ZyXEL OMNI.NET USB II"}), 412 + }, 413 + { } 414 + }; 415 + 416 + MODULE_DEVICE_TABLE(usb, hfcsusb_idtab); 417 + 418 + #endif /* __HFCSUSB_H__ */
+1 -1
drivers/isdn/mISDN/Makefile
··· 8 8 9 9 # multi objects 10 10 11 - mISDN_core-objs := core.o fsm.o socket.o hwchannel.o stack.o layer1.o layer2.o tei.o timerdev.o 11 + mISDN_core-objs := core.o fsm.o socket.o clock.o hwchannel.o stack.o layer1.o layer2.o tei.o timerdev.o 12 12 mISDN_dsp-objs := dsp_core.o dsp_cmx.o dsp_tones.o dsp_dtmf.o dsp_audio.o dsp_blowfish.o dsp_pipeline.o dsp_hwec.o 13 13 l1oip-objs := l1oip_core.o l1oip_codec.o
+216
drivers/isdn/mISDN/clock.c
··· 1 + /* 2 + * Copyright 2008 by Andreas Eversberg <andreas@eversberg.eu> 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License version 2 as 6 + * published by the Free Software Foundation. 7 + * 8 + * This program is distributed in the hope that it will be useful, 9 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + * 13 + * Quick API description: 14 + * 15 + * A clock source registers using mISDN_register_clock: 16 + * name = text string to name clock source 17 + * priority = value to priorize clock sources (0 = default) 18 + * ctl = callback function to enable/disable clock source 19 + * priv = private pointer of clock source 20 + * return = pointer to clock source structure; 21 + * 22 + * Note: Callback 'ctl' can be called before mISDN_register_clock returns! 23 + * Also it can be called during mISDN_unregister_clock. 24 + * 25 + * A clock source calls mISDN_clock_update with given samples elapsed, if 26 + * enabled. If function call is delayed, tv must be set with the timestamp 27 + * of the actual event. 28 + * 29 + * A clock source unregisters using mISDN_unregister_clock. 30 + * 31 + * To get current clock, call mISDN_clock_get. The signed short value 32 + * counts the number of samples since. Time since last clock event is added. 33 + * 34 + */ 35 + 36 + #include <linux/types.h> 37 + #include <linux/stddef.h> 38 + #include <linux/spinlock.h> 39 + #include <linux/mISDNif.h> 40 + #include "core.h" 41 + 42 + static u_int *debug; 43 + static LIST_HEAD(iclock_list); 44 + DEFINE_RWLOCK(iclock_lock); 45 + u16 iclock_count; /* counter of last clock */ 46 + struct timeval iclock_tv; /* time stamp of last clock */ 47 + int iclock_tv_valid; /* already received one timestamp */ 48 + struct mISDNclock *iclock_current; 49 + 50 + void 51 + mISDN_init_clock(u_int *dp) 52 + { 53 + debug = dp; 54 + do_gettimeofday(&iclock_tv); 55 + } 56 + 57 + static void 58 + select_iclock(void) 59 + { 60 + struct mISDNclock *iclock, *bestclock = NULL, *lastclock = NULL; 61 + int pri = -128; 62 + 63 + list_for_each_entry(iclock, &iclock_list, list) { 64 + if (iclock->pri > pri) { 65 + pri = iclock->pri; 66 + bestclock = iclock; 67 + } 68 + if (iclock_current == iclock) 69 + lastclock = iclock; 70 + } 71 + if (lastclock && bestclock != lastclock) { 72 + /* last used clock source still exists but changes, disable */ 73 + if (*debug & DEBUG_CLOCK) 74 + printk(KERN_DEBUG "Old clock source '%s' disable.\n", 75 + lastclock->name); 76 + lastclock->ctl(lastclock->priv, 0); 77 + } 78 + if (bestclock && bestclock != iclock_current) { 79 + /* new clock source selected, enable */ 80 + if (*debug & DEBUG_CLOCK) 81 + printk(KERN_DEBUG "New clock source '%s' enable.\n", 82 + bestclock->name); 83 + bestclock->ctl(bestclock->priv, 1); 84 + } 85 + if (bestclock != iclock_current) { 86 + /* no clock received yet */ 87 + iclock_tv_valid = 0; 88 + } 89 + iclock_current = bestclock; 90 + } 91 + 92 + struct mISDNclock 93 + *mISDN_register_clock(char *name, int pri, clockctl_func_t *ctl, void *priv) 94 + { 95 + u_long flags; 96 + struct mISDNclock *iclock; 97 + 98 + if (*debug & (DEBUG_CORE | DEBUG_CLOCK)) 99 + printk(KERN_DEBUG "%s: %s %d\n", __func__, name, pri); 100 + iclock = kzalloc(sizeof(struct mISDNclock), GFP_ATOMIC); 101 + if (!iclock) { 102 + printk(KERN_ERR "%s: No memory for clock entry.\n", __func__); 103 + return NULL; 104 + } 105 + strncpy(iclock->name, name, sizeof(iclock->name)-1); 106 + iclock->pri = pri; 107 + iclock->priv = priv; 108 + iclock->ctl = ctl; 109 + write_lock_irqsave(&iclock_lock, flags); 110 + list_add_tail(&iclock->list, &iclock_list); 111 + select_iclock(); 112 + write_unlock_irqrestore(&iclock_lock, flags); 113 + return iclock; 114 + } 115 + EXPORT_SYMBOL(mISDN_register_clock); 116 + 117 + void 118 + mISDN_unregister_clock(struct mISDNclock *iclock) 119 + { 120 + u_long flags; 121 + 122 + if (*debug & (DEBUG_CORE | DEBUG_CLOCK)) 123 + printk(KERN_DEBUG "%s: %s %d\n", __func__, iclock->name, 124 + iclock->pri); 125 + write_lock_irqsave(&iclock_lock, flags); 126 + if (iclock_current == iclock) { 127 + if (*debug & DEBUG_CLOCK) 128 + printk(KERN_DEBUG 129 + "Current clock source '%s' unregisters.\n", 130 + iclock->name); 131 + iclock->ctl(iclock->priv, 0); 132 + } 133 + list_del(&iclock->list); 134 + select_iclock(); 135 + write_unlock_irqrestore(&iclock_lock, flags); 136 + } 137 + EXPORT_SYMBOL(mISDN_unregister_clock); 138 + 139 + void 140 + mISDN_clock_update(struct mISDNclock *iclock, int samples, struct timeval *tv) 141 + { 142 + u_long flags; 143 + struct timeval tv_now; 144 + time_t elapsed_sec; 145 + int elapsed_8000th; 146 + 147 + write_lock_irqsave(&iclock_lock, flags); 148 + if (iclock_current != iclock) { 149 + printk(KERN_ERR "%s: '%s' sends us clock updates, but we do " 150 + "listen to '%s'. This is a bug!\n", __func__, 151 + iclock->name, 152 + iclock_current ? iclock_current->name : "nothing"); 153 + iclock->ctl(iclock->priv, 0); 154 + write_unlock_irqrestore(&iclock_lock, flags); 155 + return; 156 + } 157 + if (iclock_tv_valid) { 158 + /* increment sample counter by given samples */ 159 + iclock_count += samples; 160 + if (tv) { /* tv must be set, if function call is delayed */ 161 + iclock_tv.tv_sec = tv->tv_sec; 162 + iclock_tv.tv_usec = tv->tv_usec; 163 + } else 164 + do_gettimeofday(&iclock_tv); 165 + } else { 166 + /* calc elapsed time by system clock */ 167 + if (tv) { /* tv must be set, if function call is delayed */ 168 + tv_now.tv_sec = tv->tv_sec; 169 + tv_now.tv_usec = tv->tv_usec; 170 + } else 171 + do_gettimeofday(&tv_now); 172 + elapsed_sec = tv_now.tv_sec - iclock_tv.tv_sec; 173 + elapsed_8000th = (tv_now.tv_usec / 125) 174 + - (iclock_tv.tv_usec / 125); 175 + if (elapsed_8000th < 0) { 176 + elapsed_sec -= 1; 177 + elapsed_8000th += 8000; 178 + } 179 + /* add elapsed time to counter and set new timestamp */ 180 + iclock_count += elapsed_sec * 8000 + elapsed_8000th; 181 + iclock_tv.tv_sec = tv_now.tv_sec; 182 + iclock_tv.tv_usec = tv_now.tv_usec; 183 + iclock_tv_valid = 1; 184 + if (*debug & DEBUG_CLOCK) 185 + printk("Received first clock from source '%s'.\n", 186 + iclock_current ? iclock_current->name : "nothing"); 187 + } 188 + write_unlock_irqrestore(&iclock_lock, flags); 189 + } 190 + EXPORT_SYMBOL(mISDN_clock_update); 191 + 192 + unsigned short 193 + mISDN_clock_get(void) 194 + { 195 + u_long flags; 196 + struct timeval tv_now; 197 + time_t elapsed_sec; 198 + int elapsed_8000th; 199 + u16 count; 200 + 201 + read_lock_irqsave(&iclock_lock, flags); 202 + /* calc elapsed time by system clock */ 203 + do_gettimeofday(&tv_now); 204 + elapsed_sec = tv_now.tv_sec - iclock_tv.tv_sec; 205 + elapsed_8000th = (tv_now.tv_usec / 125) - (iclock_tv.tv_usec / 125); 206 + if (elapsed_8000th < 0) { 207 + elapsed_sec -= 1; 208 + elapsed_8000th += 8000; 209 + } 210 + /* add elapsed time to counter */ 211 + count = iclock_count + elapsed_sec * 8000 + elapsed_8000th; 212 + read_unlock_irqrestore(&iclock_lock, flags); 213 + return count; 214 + } 215 + EXPORT_SYMBOL(mISDN_clock_get); 216 +
+222 -58
drivers/isdn/mISDN/core.c
··· 25 25 MODULE_LICENSE("GPL"); 26 26 module_param(debug, uint, S_IRUGO | S_IWUSR); 27 27 28 - static LIST_HEAD(devices); 29 - static DEFINE_RWLOCK(device_lock); 30 28 static u64 device_ids; 31 29 #define MAX_DEVICE_ID 63 32 30 33 31 static LIST_HEAD(Bprotocols); 34 32 static DEFINE_RWLOCK(bp_lock); 35 33 34 + static void mISDN_dev_release(struct device *dev) 35 + { 36 + /* nothing to do: the device is part of its parent's data structure */ 37 + } 38 + 39 + static ssize_t _show_id(struct device *dev, 40 + struct device_attribute *attr, char *buf) 41 + { 42 + struct mISDNdevice *mdev = dev_to_mISDN(dev); 43 + 44 + if (!mdev) 45 + return -ENODEV; 46 + return sprintf(buf, "%d\n", mdev->id); 47 + } 48 + 49 + static ssize_t _show_nrbchan(struct device *dev, 50 + struct device_attribute *attr, char *buf) 51 + { 52 + struct mISDNdevice *mdev = dev_to_mISDN(dev); 53 + 54 + if (!mdev) 55 + return -ENODEV; 56 + return sprintf(buf, "%d\n", mdev->nrbchan); 57 + } 58 + 59 + static ssize_t _show_d_protocols(struct device *dev, 60 + struct device_attribute *attr, char *buf) 61 + { 62 + struct mISDNdevice *mdev = dev_to_mISDN(dev); 63 + 64 + if (!mdev) 65 + return -ENODEV; 66 + return sprintf(buf, "%d\n", mdev->Dprotocols); 67 + } 68 + 69 + static ssize_t _show_b_protocols(struct device *dev, 70 + struct device_attribute *attr, char *buf) 71 + { 72 + struct mISDNdevice *mdev = dev_to_mISDN(dev); 73 + 74 + if (!mdev) 75 + return -ENODEV; 76 + return sprintf(buf, "%d\n", mdev->Bprotocols | get_all_Bprotocols()); 77 + } 78 + 79 + static ssize_t _show_protocol(struct device *dev, 80 + struct device_attribute *attr, char *buf) 81 + { 82 + struct mISDNdevice *mdev = dev_to_mISDN(dev); 83 + 84 + if (!mdev) 85 + return -ENODEV; 86 + return sprintf(buf, "%d\n", mdev->D.protocol); 87 + } 88 + 89 + static ssize_t _show_name(struct device *dev, 90 + struct device_attribute *attr, char *buf) 91 + { 92 + strcpy(buf, dev_name(dev)); 93 + return strlen(buf); 94 + } 95 + 96 + #if 0 /* hangs */ 97 + static ssize_t _set_name(struct device *dev, struct device_attribute *attr, 98 + const char *buf, size_t count) 99 + { 100 + int err = 0; 101 + char *out = kmalloc(count + 1, GFP_KERNEL); 102 + 103 + if (!out) 104 + return -ENOMEM; 105 + 106 + memcpy(out, buf, count); 107 + if (count && out[count - 1] == '\n') 108 + out[--count] = 0; 109 + if (count) 110 + err = device_rename(dev, out); 111 + kfree(out); 112 + 113 + return (err < 0) ? err : count; 114 + } 115 + #endif 116 + 117 + static ssize_t _show_channelmap(struct device *dev, 118 + struct device_attribute *attr, char *buf) 119 + { 120 + struct mISDNdevice *mdev = dev_to_mISDN(dev); 121 + char *bp = buf; 122 + int i; 123 + 124 + for (i = 0; i <= mdev->nrbchan; i++) 125 + *bp++ = test_channelmap(i, mdev->channelmap) ? '1' : '0'; 126 + 127 + return bp - buf; 128 + } 129 + 130 + static struct device_attribute mISDN_dev_attrs[] = { 131 + __ATTR(id, S_IRUGO, _show_id, NULL), 132 + __ATTR(d_protocols, S_IRUGO, _show_d_protocols, NULL), 133 + __ATTR(b_protocols, S_IRUGO, _show_b_protocols, NULL), 134 + __ATTR(protocol, S_IRUGO, _show_protocol, NULL), 135 + __ATTR(channelmap, S_IRUGO, _show_channelmap, NULL), 136 + __ATTR(nrbchan, S_IRUGO, _show_nrbchan, NULL), 137 + __ATTR(name, S_IRUGO, _show_name, NULL), 138 + /* __ATTR(name, S_IRUGO|S_IWUSR, _show_name, _set_name), */ 139 + {} 140 + }; 141 + 142 + #ifdef CONFIG_HOTPLUG 143 + static int mISDN_uevent(struct device *dev, struct kobj_uevent_env *env) 144 + { 145 + struct mISDNdevice *mdev = dev_to_mISDN(dev); 146 + 147 + if (!mdev) 148 + return 0; 149 + 150 + if (add_uevent_var(env, "nchans=%d", mdev->nrbchan)) 151 + return -ENOMEM; 152 + 153 + return 0; 154 + } 155 + #endif 156 + 157 + static void mISDN_class_release(struct class *cls) 158 + { 159 + /* do nothing, it's static */ 160 + } 161 + 162 + static struct class mISDN_class = { 163 + .name = "mISDN", 164 + .owner = THIS_MODULE, 165 + #ifdef CONFIG_HOTPLUG 166 + .dev_uevent = mISDN_uevent, 167 + #endif 168 + .dev_attrs = mISDN_dev_attrs, 169 + .dev_release = mISDN_dev_release, 170 + .class_release = mISDN_class_release, 171 + }; 172 + 173 + static int 174 + _get_mdevice(struct device *dev, void *id) 175 + { 176 + struct mISDNdevice *mdev = dev_to_mISDN(dev); 177 + 178 + if (!mdev) 179 + return 0; 180 + if (mdev->id != *(u_int *)id) 181 + return 0; 182 + return 1; 183 + } 184 + 36 185 struct mISDNdevice 37 186 *get_mdevice(u_int id) 38 187 { 39 - struct mISDNdevice *dev; 188 + return dev_to_mISDN(class_find_device(&mISDN_class, NULL, &id, 189 + _get_mdevice)); 190 + } 40 191 41 - read_lock(&device_lock); 42 - list_for_each_entry(dev, &devices, D.list) 43 - if (dev->id == id) { 44 - read_unlock(&device_lock); 45 - return dev; 46 - } 47 - read_unlock(&device_lock); 48 - return NULL; 192 + static int 193 + _get_mdevice_count(struct device *dev, void *cnt) 194 + { 195 + *(int *)cnt += 1; 196 + return 0; 49 197 } 50 198 51 199 int 52 200 get_mdevice_count(void) 53 201 { 54 - struct mISDNdevice *dev; 55 - int cnt = 0; 202 + int cnt = 0; 56 203 57 - read_lock(&device_lock); 58 - list_for_each_entry(dev, &devices, D.list) 59 - cnt++; 60 - read_unlock(&device_lock); 204 + class_for_each_device(&mISDN_class, NULL, &cnt, _get_mdevice_count); 61 205 return cnt; 62 206 } 63 207 ··· 212 68 213 69 for (i = 0; i <= MAX_DEVICE_ID; i++) 214 70 if (!test_and_set_bit(i, (u_long *)&device_ids)) 215 - return i; 216 - return -1; 71 + break; 72 + if (i > MAX_DEVICE_ID) 73 + return -1; 74 + return i; 217 75 } 218 76 219 77 int 220 - mISDN_register_device(struct mISDNdevice *dev, char *name) 78 + mISDN_register_device(struct mISDNdevice *dev, 79 + struct device *parent, char *name) 221 80 { 222 - u_long flags; 223 81 int err; 224 82 225 83 dev->id = get_free_devid(); 84 + err = -EBUSY; 226 85 if (dev->id < 0) 227 - return -EBUSY; 86 + goto error1; 87 + 88 + device_initialize(&dev->dev); 228 89 if (name && name[0]) 229 - strcpy(dev->name, name); 90 + dev_set_name(&dev->dev, "%s", name); 230 91 else 231 - sprintf(dev->name, "mISDN%d", dev->id); 92 + dev_set_name(&dev->dev, "mISDN%d", dev->id); 232 93 if (debug & DEBUG_CORE) 233 94 printk(KERN_DEBUG "mISDN_register %s %d\n", 234 - dev->name, dev->id); 95 + dev_name(&dev->dev), dev->id); 235 96 err = create_stack(dev); 236 97 if (err) 237 - return err; 238 - write_lock_irqsave(&device_lock, flags); 239 - list_add_tail(&dev->D.list, &devices); 240 - write_unlock_irqrestore(&device_lock, flags); 98 + goto error1; 99 + 100 + dev->dev.class = &mISDN_class; 101 + dev->dev.platform_data = dev; 102 + dev->dev.parent = parent; 103 + dev_set_drvdata(&dev->dev, dev); 104 + 105 + err = device_add(&dev->dev); 106 + if (err) 107 + goto error3; 241 108 return 0; 109 + 110 + error3: 111 + delete_stack(dev); 112 + return err; 113 + error1: 114 + return err; 115 + 242 116 } 243 117 EXPORT_SYMBOL(mISDN_register_device); 244 118 245 119 void 246 120 mISDN_unregister_device(struct mISDNdevice *dev) { 247 - u_long flags; 248 - 249 121 if (debug & DEBUG_CORE) 250 122 printk(KERN_DEBUG "mISDN_unregister %s %d\n", 251 - dev->name, dev->id); 252 - write_lock_irqsave(&device_lock, flags); 253 - list_del(&dev->D.list); 254 - write_unlock_irqrestore(&device_lock, flags); 123 + dev_name(&dev->dev), dev->id); 124 + /* sysfs_remove_link(&dev->dev.kobj, "device"); */ 125 + device_del(&dev->dev); 126 + dev_set_drvdata(&dev->dev, NULL); 127 + 255 128 test_and_clear_bit(dev->id, (u_long *)&device_ids); 256 129 delete_stack(dev); 130 + put_device(&dev->dev); 257 131 } 258 132 EXPORT_SYMBOL(mISDN_unregister_device); 259 133 ··· 361 199 362 200 printk(KERN_INFO "Modular ISDN core version %d.%d.%d\n", 363 201 MISDN_MAJOR_VERSION, MISDN_MINOR_VERSION, MISDN_RELEASE); 202 + mISDN_init_clock(&debug); 364 203 mISDN_initstack(&debug); 204 + err = class_register(&mISDN_class); 205 + if (err) 206 + goto error1; 365 207 err = mISDN_inittimer(&debug); 366 208 if (err) 367 - goto error; 209 + goto error2; 368 210 err = l1_init(&debug); 369 - if (err) { 370 - mISDN_timer_cleanup(); 371 - goto error; 372 - } 211 + if (err) 212 + goto error3; 373 213 err = Isdnl2_Init(&debug); 374 - if (err) { 375 - mISDN_timer_cleanup(); 376 - l1_cleanup(); 377 - goto error; 378 - } 214 + if (err) 215 + goto error4; 379 216 err = misdn_sock_init(&debug); 380 - if (err) { 381 - mISDN_timer_cleanup(); 382 - l1_cleanup(); 383 - Isdnl2_cleanup(); 384 - } 385 - error: 217 + if (err) 218 + goto error5; 219 + return 0; 220 + 221 + error5: 222 + Isdnl2_cleanup(); 223 + error4: 224 + l1_cleanup(); 225 + error3: 226 + mISDN_timer_cleanup(); 227 + error2: 228 + class_unregister(&mISDN_class); 229 + error1: 386 230 return err; 387 231 } 388 232 389 233 static void mISDN_cleanup(void) 390 234 { 391 235 misdn_sock_cleanup(); 392 - mISDN_timer_cleanup(); 393 - l1_cleanup(); 394 236 Isdnl2_cleanup(); 237 + l1_cleanup(); 238 + mISDN_timer_cleanup(); 239 + class_unregister(&mISDN_class); 395 240 396 - if (!list_empty(&devices)) 397 - printk(KERN_ERR "%s devices still registered\n", __func__); 398 - 399 - if (!list_empty(&Bprotocols)) 400 - printk(KERN_ERR "%s Bprotocols still registered\n", __func__); 401 241 printk(KERN_DEBUG "mISDNcore unloaded\n"); 402 242 } 403 243
+2
drivers/isdn/mISDN/core.h
··· 74 74 extern int Isdnl2_Init(u_int *); 75 75 extern void Isdnl2_cleanup(void); 76 76 77 + extern void mISDN_init_clock(u_int *); 78 + 77 79 #endif
+2
drivers/isdn/mISDN/dsp.h
··· 15 15 #define DEBUG_DSP_TONE 0x0020 16 16 #define DEBUG_DSP_BLOWFISH 0x0040 17 17 #define DEBUG_DSP_DELAY 0x0100 18 + #define DEBUG_DSP_CLOCK 0x0200 18 19 #define DEBUG_DSP_DTMFCOEFF 0x8000 /* heavy output */ 19 20 20 21 /* options may be: ··· 199 198 /* hardware stuff */ 200 199 struct dsp_features features; 201 200 int features_rx_off; /* set if rx_off is featured */ 201 + int features_fill_empty; /* set if fill_empty is featured */ 202 202 int pcm_slot_rx; /* current PCM slot (or -1) */ 203 203 int pcm_bank_rx; 204 204 int pcm_slot_tx;
+91 -55
drivers/isdn/mISDN/dsp_cmx.c
··· 137 137 /* #define CMX_CONF_DEBUG */ 138 138 139 139 /*#define CMX_DEBUG * massive read/write pointer output */ 140 + /*#define CMX_DELAY_DEBUG * gives rx-buffer delay overview */ 140 141 /*#define CMX_TX_DEBUG * massive read/write on tx-buffer with content */ 141 142 142 143 static inline int ··· 745 744 if (dsp->pcm_slot_rx >= 0 && 746 745 dsp->pcm_slot_rx < 747 746 sizeof(freeslots)) 748 - freeslots[dsp->pcm_slot_tx] = 0; 747 + freeslots[dsp->pcm_slot_rx] = 0; 749 748 if (dsp->pcm_slot_tx >= 0 && 750 749 dsp->pcm_slot_tx < 751 750 sizeof(freeslots)) 752 - freeslots[dsp->pcm_slot_rx] = 0; 751 + freeslots[dsp->pcm_slot_tx] = 0; 753 752 } 754 753 } 755 754 i = 0; ··· 837 836 if (dsp->pcm_slot_rx >= 0 && 838 837 dsp->pcm_slot_rx < 839 838 sizeof(freeslots)) 840 - freeslots[dsp->pcm_slot_tx] = 0; 839 + freeslots[dsp->pcm_slot_rx] = 0; 841 840 if (dsp->pcm_slot_tx >= 0 && 842 841 dsp->pcm_slot_tx < 843 842 sizeof(freeslots)) 844 - freeslots[dsp->pcm_slot_rx] = 0; 843 + freeslots[dsp->pcm_slot_tx] = 0; 845 844 } 846 845 } 847 846 i1 = 0; ··· 927 926 928 927 /* for more than two members.. */ 929 928 930 - /* in case of hdlc, we change to software */ 931 - if (dsp->hdlc) 932 - goto conf_software; 933 - 934 929 /* if all members already have the same conference */ 935 930 if (all_conf) 936 931 return; ··· 937 940 if (current_conf >= 0) { 938 941 join_members: 939 942 list_for_each_entry(member, &conf->mlist, list) { 943 + /* in case of hdlc, change to software */ 944 + if (member->dsp->hdlc) 945 + goto conf_software; 940 946 /* join to current conference */ 941 947 if (member->dsp->hfc_conf == current_conf) 942 948 continue; ··· 1135 1135 return 0; 1136 1136 } 1137 1137 1138 + #ifdef CMX_DELAY_DEBUG 1139 + int delaycount; 1140 + static void 1141 + showdelay(struct dsp *dsp, int samples, int delay) 1142 + { 1143 + char bar[] = "--------------------------------------------------|"; 1144 + int sdelay; 1145 + 1146 + delaycount += samples; 1147 + if (delaycount < 8000) 1148 + return; 1149 + delaycount = 0; 1150 + 1151 + sdelay = delay * 50 / (dsp_poll << 2); 1152 + 1153 + printk(KERN_DEBUG "DELAY (%s) %3d >%s\n", dsp->name, delay, 1154 + sdelay > 50 ? "..." : bar + 50 - sdelay); 1155 + } 1156 + #endif 1138 1157 1139 1158 /* 1140 1159 * audio data is received from card ··· 1187 1168 dsp->rx_init = 0; 1188 1169 if (dsp->features.unordered) { 1189 1170 dsp->rx_R = (hh->id & CMX_BUFF_MASK); 1190 - dsp->rx_W = (dsp->rx_R + dsp->cmx_delay) 1191 - & CMX_BUFF_MASK; 1171 + if (dsp->cmx_delay) 1172 + dsp->rx_W = (dsp->rx_R + dsp->cmx_delay) 1173 + & CMX_BUFF_MASK; 1174 + else 1175 + dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1)) 1176 + & CMX_BUFF_MASK; 1192 1177 } else { 1193 1178 dsp->rx_R = 0; 1194 - dsp->rx_W = dsp->cmx_delay; 1179 + if (dsp->cmx_delay) 1180 + dsp->rx_W = dsp->cmx_delay; 1181 + else 1182 + dsp->rx_W = dsp_poll >> 1; 1195 1183 } 1196 1184 } 1197 1185 /* if frame contains time code, write directly */ ··· 1211 1185 * we set our new read pointer, and write silence to buffer 1212 1186 */ 1213 1187 if (((dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK) >= CMX_BUFF_HALF) { 1214 - if (dsp_debug & DEBUG_DSP_CMX) 1188 + if (dsp_debug & DEBUG_DSP_CLOCK) 1215 1189 printk(KERN_DEBUG 1216 1190 "cmx_receive(dsp=%lx): UNDERRUN (or overrun the " 1217 1191 "maximum delay), adjusting read pointer! " 1218 1192 "(inst %s)\n", (u_long)dsp, dsp->name); 1219 - /* flush buffer */ 1193 + /* flush rx buffer and set delay to dsp_poll / 2 */ 1220 1194 if (dsp->features.unordered) { 1221 1195 dsp->rx_R = (hh->id & CMX_BUFF_MASK); 1222 - dsp->rx_W = (dsp->rx_R + dsp->cmx_delay) 1223 - & CMX_BUFF_MASK; 1196 + if (dsp->cmx_delay) 1197 + dsp->rx_W = (dsp->rx_R + dsp->cmx_delay) 1198 + & CMX_BUFF_MASK; 1199 + dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1)) 1200 + & CMX_BUFF_MASK; 1224 1201 } else { 1225 1202 dsp->rx_R = 0; 1226 - dsp->rx_W = dsp->cmx_delay; 1203 + if (dsp->cmx_delay) 1204 + dsp->rx_W = dsp->cmx_delay; 1205 + else 1206 + dsp->rx_W = dsp_poll >> 1; 1227 1207 } 1228 1208 memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff)); 1229 1209 } ··· 1237 1205 if (dsp->cmx_delay) 1238 1206 if (((dsp->rx_W - dsp->rx_R) & CMX_BUFF_MASK) >= 1239 1207 (dsp->cmx_delay << 1)) { 1240 - if (dsp_debug & DEBUG_DSP_CMX) 1208 + if (dsp_debug & DEBUG_DSP_CLOCK) 1241 1209 printk(KERN_DEBUG 1242 1210 "cmx_receive(dsp=%lx): OVERRUN (because " 1243 1211 "twice the delay is reached), adjusting " ··· 1275 1243 1276 1244 /* increase write-pointer */ 1277 1245 dsp->rx_W = ((dsp->rx_W+len) & CMX_BUFF_MASK); 1246 + #ifdef CMX_DELAY_DEBUG 1247 + showdelay(dsp, len, (dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK); 1248 + #endif 1278 1249 } 1279 1250 1280 1251 ··· 1395 1360 t = (t+1) & CMX_BUFF_MASK; 1396 1361 r = (r+1) & CMX_BUFF_MASK; 1397 1362 } 1398 - if (r != rr) 1363 + if (r != rr) { 1364 + if (dsp_debug & DEBUG_DSP_CLOCK) 1365 + printk(KERN_DEBUG "%s: RX empty\n", 1366 + __func__); 1399 1367 memset(d, dsp_silence, (rr-r)&CMX_BUFF_MASK); 1368 + } 1400 1369 /* -> if echo is enabled */ 1401 1370 } else { 1402 1371 /* ··· 1579 1540 schedule_work(&dsp->workq); 1580 1541 } 1581 1542 1582 - static u32 samplecount; 1543 + static u32 jittercount; /* counter for jitter check */; 1583 1544 struct timer_list dsp_spl_tl; 1584 1545 u32 dsp_spl_jiffies; /* calculate the next time to fire */ 1585 - #ifdef UNUSED 1586 - static u32 dsp_start_jiffies; /* jiffies at the time, the calculation begins */ 1587 - #endif /* UNUSED */ 1588 - static struct timeval dsp_start_tv; /* time at start of calculation */ 1546 + static u16 dsp_count; /* last sample count */ 1547 + static int dsp_count_valid ; /* if we have last sample count */ 1589 1548 1590 1549 void 1591 1550 dsp_cmx_send(void *arg) ··· 1597 1560 int r, rr; 1598 1561 int jittercheck = 0, delay, i; 1599 1562 u_long flags; 1600 - struct timeval tv; 1601 - u32 elapsed; 1602 - s16 length; 1563 + u16 length, count; 1603 1564 1604 1565 /* lock */ 1605 1566 spin_lock_irqsave(&dsp_lock, flags); 1606 1567 1607 - if (!dsp_start_tv.tv_sec) { 1608 - do_gettimeofday(&dsp_start_tv); 1568 + if (!dsp_count_valid) { 1569 + dsp_count = mISDN_clock_get(); 1609 1570 length = dsp_poll; 1571 + dsp_count_valid = 1; 1610 1572 } else { 1611 - do_gettimeofday(&tv); 1612 - elapsed = ((tv.tv_sec - dsp_start_tv.tv_sec) * 8000) 1613 - + ((s32)(tv.tv_usec / 125) - (dsp_start_tv.tv_usec / 125)); 1614 - dsp_start_tv.tv_sec = tv.tv_sec; 1615 - dsp_start_tv.tv_usec = tv.tv_usec; 1616 - length = elapsed; 1573 + count = mISDN_clock_get(); 1574 + length = count - dsp_count; 1575 + dsp_count = count; 1617 1576 } 1618 1577 if (length > MAX_POLL + 100) 1619 1578 length = MAX_POLL + 100; 1620 - /* printk(KERN_DEBUG "len=%d dsp_count=0x%x.%04x dsp_poll_diff=0x%x.%04x\n", 1621 - length, dsp_count >> 16, dsp_count & 0xffff, dsp_poll_diff >> 16, 1622 - dsp_poll_diff & 0xffff); 1623 - */ 1579 + /* printk(KERN_DEBUG "len=%d dsp_count=0x%x\n", length, dsp_count); */ 1624 1580 1625 1581 /* 1626 - * check if jitter needs to be checked 1627 - * (this is about every second = 8192 samples) 1582 + * check if jitter needs to be checked (this is every second) 1628 1583 */ 1629 - samplecount += length; 1630 - if ((samplecount & 8191) < length) 1584 + jittercount += length; 1585 + if (jittercount >= 8000) { 1586 + jittercount -= 8000; 1631 1587 jittercheck = 1; 1588 + } 1632 1589 1633 1590 /* loop all members that do not require conference mixing */ 1634 1591 list_for_each_entry(dsp, &dsp_ilist, list) { ··· 1735 1704 } 1736 1705 /* 1737 1706 * remove rx_delay only if we have delay AND we 1738 - * have not preset cmx_delay 1707 + * have not preset cmx_delay AND 1708 + * the delay is greater dsp_poll 1739 1709 */ 1740 - if (delay && !dsp->cmx_delay) { 1741 - if (dsp_debug & DEBUG_DSP_CMX) 1710 + if (delay > dsp_poll && !dsp->cmx_delay) { 1711 + if (dsp_debug & DEBUG_DSP_CLOCK) 1742 1712 printk(KERN_DEBUG 1743 1713 "%s lowest rx_delay of %d bytes for" 1744 1714 " dsp %s are now removed.\n", 1745 1715 __func__, delay, 1746 1716 dsp->name); 1747 1717 r = dsp->rx_R; 1748 - rr = (r + delay) & CMX_BUFF_MASK; 1718 + rr = (r + delay - (dsp_poll >> 1)) 1719 + & CMX_BUFF_MASK; 1749 1720 /* delete rx-data */ 1750 1721 while (r != rr) { 1751 1722 p[r] = dsp_silence; ··· 1769 1736 * remove delay only if we have delay AND we 1770 1737 * have enabled tx_dejitter 1771 1738 */ 1772 - if (delay && dsp->tx_dejitter) { 1773 - if (dsp_debug & DEBUG_DSP_CMX) 1739 + if (delay > dsp_poll && dsp->tx_dejitter) { 1740 + if (dsp_debug & DEBUG_DSP_CLOCK) 1774 1741 printk(KERN_DEBUG 1775 1742 "%s lowest tx_delay of %d bytes for" 1776 1743 " dsp %s are now removed.\n", 1777 1744 __func__, delay, 1778 1745 dsp->name); 1779 1746 r = dsp->tx_R; 1780 - rr = (r + delay) & CMX_BUFF_MASK; 1747 + rr = (r + delay - (dsp_poll >> 1)) 1748 + & CMX_BUFF_MASK; 1781 1749 /* delete tx-data */ 1782 1750 while (r != rr) { 1783 1751 q[r] = dsp_silence; ··· 1831 1797 ww = dsp->tx_R; 1832 1798 p = dsp->tx_buff; 1833 1799 d = skb->data; 1834 - space = ww-w; 1835 - if (space <= 0) 1836 - space += CMX_BUFF_SIZE; 1800 + space = (ww - w - 1) & CMX_BUFF_MASK; 1837 1801 /* write-pointer should not overrun nor reach read pointer */ 1838 - if (space-1 < skb->len) 1802 + if (space < skb->len) { 1839 1803 /* write to the space we have left */ 1840 - ww = (ww - 1) & CMX_BUFF_MASK; 1841 - else 1804 + ww = (ww - 1) & CMX_BUFF_MASK; /* end one byte prior tx_R */ 1805 + if (dsp_debug & DEBUG_DSP_CLOCK) 1806 + printk(KERN_DEBUG "%s: TX overflow space=%d skb->len=" 1807 + "%d, w=0x%04x, ww=0x%04x\n", __func__, space, 1808 + skb->len, w, ww); 1809 + } else 1842 1810 /* write until all byte are copied */ 1843 1811 ww = (w + skb->len) & CMX_BUFF_MASK; 1844 1812 dsp->tx_W = ww;
+46 -9
drivers/isdn/mISDN/dsp_core.c
··· 191 191 struct mISDN_ctrl_req cq; 192 192 int rx_off = 1; 193 193 194 + memset(&cq, 0, sizeof(cq)); 195 + 194 196 if (!dsp->features_rx_off) 195 197 return; 196 198 ··· 251 249 } 252 250 } 253 251 252 + /* enable "fill empty" feature */ 253 + static void 254 + dsp_fill_empty(struct dsp *dsp) 255 + { 256 + struct mISDN_ctrl_req cq; 257 + 258 + memset(&cq, 0, sizeof(cq)); 259 + 260 + if (!dsp->ch.peer) { 261 + if (dsp_debug & DEBUG_DSP_CORE) 262 + printk(KERN_DEBUG "%s: no peer, no fill_empty\n", 263 + __func__); 264 + return; 265 + } 266 + cq.op = MISDN_CTRL_FILL_EMPTY; 267 + cq.p1 = 1; 268 + if (dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq)) { 269 + printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n", 270 + __func__); 271 + return; 272 + } 273 + if (dsp_debug & DEBUG_DSP_CORE) 274 + printk(KERN_DEBUG "%s: %s set fill_empty = 1\n", 275 + __func__, dsp->name); 276 + } 277 + 254 278 static int 255 279 dsp_control_req(struct dsp *dsp, struct mISDNhead *hh, struct sk_buff *skb) 256 280 { ··· 301 273 if (dsp_debug & DEBUG_DSP_CORE) 302 274 printk(KERN_DEBUG "%s: start dtmf\n", __func__); 303 275 if (len == sizeof(int)) { 304 - printk(KERN_NOTICE "changing DTMF Threshold " 305 - "to %d\n", *((int *)data)); 276 + if (dsp_debug & DEBUG_DSP_CORE) 277 + printk(KERN_NOTICE "changing DTMF Threshold " 278 + "to %d\n", *((int *)data)); 306 279 dsp->dtmf.treshold = (*(int *)data) * 10000; 307 280 } 308 281 /* init goertzel */ ··· 622 593 struct dsp *dsp = container_of(ch, struct dsp, ch); 623 594 struct mISDN_ctrl_req cq; 624 595 625 - if (dsp_options & DSP_OPT_NOHARDWARE) 626 - return; 627 596 if (!ch->peer) { 628 597 if (dsp_debug & DEBUG_DSP_CORE) 629 598 printk(KERN_DEBUG "%s: no peer, no features\n", ··· 637 610 } 638 611 if (cq.op & MISDN_CTRL_RX_OFF) 639 612 dsp->features_rx_off = 1; 613 + if (cq.op & MISDN_CTRL_FILL_EMPTY) 614 + dsp->features_fill_empty = 1; 615 + if (dsp_options & DSP_OPT_NOHARDWARE) 616 + return; 640 617 if ((cq.op & MISDN_CTRL_HW_FEATURES_OP)) { 641 618 cq.op = MISDN_CTRL_HW_FEATURES; 642 619 *((u_long *)&cq.p1) = (u_long)&dsp->features; ··· 868 837 } 869 838 if (dsp->hdlc) { 870 839 /* hdlc */ 871 - spin_lock_irqsave(&dsp_lock, flags); 872 - if (dsp->b_active) { 873 - skb_queue_tail(&dsp->sendq, skb); 874 - schedule_work(&dsp->workq); 840 + if (!dsp->b_active) { 841 + ret = -EIO; 842 + break; 875 843 } 844 + hh->prim = PH_DATA_REQ; 845 + spin_lock_irqsave(&dsp_lock, flags); 846 + skb_queue_tail(&dsp->sendq, skb); 847 + schedule_work(&dsp->workq); 876 848 spin_unlock_irqrestore(&dsp_lock, flags); 877 849 return 0; 878 850 } ··· 899 865 if (dsp->dtmf.hardware || dsp->dtmf.software) 900 866 dsp_dtmf_goertzel_init(dsp); 901 867 get_features(ch); 868 + /* enable fill_empty feature */ 869 + if (dsp->features_fill_empty) 870 + dsp_fill_empty(dsp); 902 871 /* send ph_activate */ 903 872 hh->prim = PH_ACTIVATE_REQ; 904 873 if (ch->peer) ··· 1142 1105 } else { 1143 1106 poll = 8; 1144 1107 while (poll <= MAX_POLL) { 1145 - tics = poll * HZ / 8000; 1108 + tics = (poll * HZ) / 8000; 1146 1109 if (tics * 8000 == poll * HZ) { 1147 1110 dsp_tics = tics; 1148 1111 dsp_poll = poll;
+24 -10
drivers/isdn/mISDN/dsp_pipeline.c
··· 75 75 __ATTR(args, 0444, attr_show_args, NULL), 76 76 }; 77 77 78 + static void 79 + mISDN_dsp_dev_release(struct device *dev) 80 + { 81 + struct dsp_element_entry *entry = 82 + container_of(dev, struct dsp_element_entry, dev); 83 + list_del(&entry->list); 84 + kfree(entry); 85 + } 86 + 78 87 int mISDN_dsp_element_register(struct mISDN_dsp_element *elem) 79 88 { 80 89 struct dsp_element_entry *entry; ··· 92 83 if (!elem) 93 84 return -EINVAL; 94 85 95 - entry = kzalloc(sizeof(struct dsp_element_entry), GFP_KERNEL); 86 + entry = kzalloc(sizeof(struct dsp_element_entry), GFP_ATOMIC); 96 87 if (!entry) 97 88 return -ENOMEM; 98 89 99 90 entry->elem = elem; 100 91 101 92 entry->dev.class = elements_class; 93 + entry->dev.release = mISDN_dsp_dev_release; 102 94 dev_set_drvdata(&entry->dev, elem); 103 95 dev_set_name(&entry->dev, elem->name); 104 96 ret = device_register(&entry->dev); ··· 108 98 __func__, elem->name); 109 99 goto err1; 110 100 } 101 + list_add_tail(&entry->list, &dsp_elements); 111 102 112 103 for (i = 0; i < (sizeof(element_attributes) 113 104 / sizeof(struct device_attribute)); ++i) ··· 120 109 goto err2; 121 110 } 122 111 123 - list_add_tail(&entry->list, &dsp_elements); 124 - 112 + #ifdef PIPELINE_DEBUG 125 113 printk(KERN_DEBUG "%s: %s registered\n", __func__, elem->name); 114 + #endif 126 115 127 116 return 0; 128 117 129 118 err2: 130 119 device_unregister(&entry->dev); 120 + return ret; 131 121 err1: 132 122 kfree(entry); 133 123 return ret; ··· 144 132 145 133 list_for_each_entry_safe(entry, n, &dsp_elements, list) 146 134 if (entry->elem == elem) { 147 - list_del(&entry->list); 148 135 device_unregister(&entry->dev); 149 - kfree(entry); 136 + #ifdef PIPELINE_DEBUG 150 137 printk(KERN_DEBUG "%s: %s unregistered\n", 151 138 __func__, elem->name); 139 + #endif 152 140 return; 153 141 } 154 142 printk(KERN_ERR "%s: element %s not in list.\n", __func__, elem->name); ··· 185 173 kfree(entry); 186 174 } 187 175 176 + #ifdef PIPELINE_DEBUG 188 177 printk(KERN_DEBUG "%s: dsp pipeline module exited\n", __func__); 178 + #endif 189 179 } 190 180 191 181 int dsp_pipeline_init(struct dsp_pipeline *pipeline) ··· 253 239 if (!len) 254 240 return 0; 255 241 256 - dup = kmalloc(len + 1, GFP_KERNEL); 242 + dup = kmalloc(len + 1, GFP_ATOMIC); 257 243 if (!dup) 258 244 return 0; 259 245 strcpy(dup, cfg); ··· 270 256 elem = entry->elem; 271 257 272 258 pipeline_entry = kmalloc(sizeof(struct 273 - dsp_pipeline_entry), GFP_KERNEL); 259 + dsp_pipeline_entry), GFP_ATOMIC); 274 260 if (!pipeline_entry) { 275 - printk(KERN_DEBUG "%s: failed to add " 261 + printk(KERN_ERR "%s: failed to add " 276 262 "entry to pipeline: %s (out of " 277 263 "memory)\n", __func__, elem->name); 278 264 incomplete = 1; ··· 300 286 args : ""); 301 287 #endif 302 288 } else { 303 - printk(KERN_DEBUG "%s: failed " 289 + printk(KERN_ERR "%s: failed " 304 290 "to add entry to pipeline: " 305 291 "%s (new() returned NULL)\n", 306 292 __func__, elem->name); ··· 315 301 if (found) 316 302 found = 0; 317 303 else { 318 - printk(KERN_DEBUG "%s: element not found, skipping: " 304 + printk(KERN_ERR "%s: element not found, skipping: " 319 305 "%s\n", __func__, name); 320 306 incomplete = 1; 321 307 }
+33 -9
drivers/isdn/mISDN/hwchannel.c
··· 50 50 51 51 if (test_and_clear_bit(FLG_RECVQUEUE, &bch->Flags)) { 52 52 while ((skb = skb_dequeue(&bch->rqueue))) { 53 - if (bch->rcount >= 64) 54 - printk(KERN_WARNING "B-channel %p receive " 55 - "queue if full, but empties...\n", bch); 56 53 bch->rcount--; 57 54 if (likely(bch->ch.peer)) { 58 55 err = bch->ch.recv(bch->ch.peer, skb); ··· 166 169 EXPORT_SYMBOL(recv_Dchannel); 167 170 168 171 void 172 + recv_Echannel(struct dchannel *ech, struct dchannel *dch) 173 + { 174 + struct mISDNhead *hh; 175 + 176 + if (ech->rx_skb->len < 2) { /* at least 2 for sapi / tei */ 177 + dev_kfree_skb(ech->rx_skb); 178 + ech->rx_skb = NULL; 179 + return; 180 + } 181 + hh = mISDN_HEAD_P(ech->rx_skb); 182 + hh->prim = PH_DATA_E_IND; 183 + hh->id = get_sapi_tei(ech->rx_skb->data); 184 + skb_queue_tail(&dch->rqueue, ech->rx_skb); 185 + ech->rx_skb = NULL; 186 + schedule_event(dch, FLG_RECVQUEUE); 187 + } 188 + EXPORT_SYMBOL(recv_Echannel); 189 + 190 + void 169 191 recv_Bchannel(struct bchannel *bch) 170 192 { 171 193 struct mISDNhead *hh; ··· 193 177 hh->prim = PH_DATA_IND; 194 178 hh->id = MISDN_ID_ANY; 195 179 if (bch->rcount >= 64) { 196 - dev_kfree_skb(bch->rx_skb); 197 - bch->rx_skb = NULL; 180 + printk(KERN_WARNING "B-channel %p receive queue overflow, " 181 + "fushing!\n", bch); 182 + skb_queue_purge(&bch->rqueue); 183 + bch->rcount = 0; 198 184 return; 199 185 } 200 186 bch->rcount++; ··· 218 200 recv_Bchannel_skb(struct bchannel *bch, struct sk_buff *skb) 219 201 { 220 202 if (bch->rcount >= 64) { 221 - dev_kfree_skb(skb); 222 - return; 203 + printk(KERN_WARNING "B-channel %p receive queue overflow, " 204 + "fushing!\n", bch); 205 + skb_queue_purge(&bch->rqueue); 206 + bch->rcount = 0; 223 207 } 224 208 bch->rcount++; 225 209 skb_queue_tail(&bch->rqueue, skb); ··· 265 245 { 266 246 struct sk_buff *skb; 267 247 268 - if (bch->rcount >= 64) 269 - return; 248 + if (bch->rcount >= 64) { 249 + printk(KERN_WARNING "B-channel %p receive queue overflow, " 250 + "fushing!\n", bch); 251 + skb_queue_purge(&bch->rqueue); 252 + bch->rcount = 0; 253 + } 270 254 skb = _alloc_mISDN_skb(PH_DATA_CNF, mISDN_HEAD_ID(bch->tx_skb), 271 255 0, NULL, GFP_ATOMIC); 272 256 if (!skb) {
+23 -2
drivers/isdn/mISDN/l1oip_core.c
··· 777 777 static void 778 778 l1oip_socket_close(struct l1oip *hc) 779 779 { 780 + struct dchannel *dch = hc->chan[hc->d_idx].dch; 781 + 780 782 /* kill thread */ 781 783 if (hc->socket_thread) { 782 784 if (debug & DEBUG_L1OIP_SOCKET) ··· 786 784 "killing...\n", __func__); 787 785 send_sig(SIGTERM, hc->socket_thread, 0); 788 786 wait_for_completion(&hc->socket_complete); 787 + } 788 + 789 + /* if active, we send up a PH_DEACTIVATE and deactivate */ 790 + if (test_bit(FLG_ACTIVE, &dch->Flags)) { 791 + if (debug & (DEBUG_L1OIP_MSG|DEBUG_L1OIP_SOCKET)) 792 + printk(KERN_DEBUG "%s: interface become deactivated " 793 + "due to timeout\n", __func__); 794 + test_and_clear_bit(FLG_ACTIVE, &dch->Flags); 795 + _queue_data(&dch->dev.D, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0, 796 + NULL, GFP_ATOMIC); 789 797 } 790 798 } 791 799 ··· 956 944 957 945 switch (cq->op) { 958 946 case MISDN_CTRL_GETOP: 959 - cq->op = MISDN_CTRL_SETPEER | MISDN_CTRL_UNSETPEER; 947 + cq->op = MISDN_CTRL_SETPEER | MISDN_CTRL_UNSETPEER 948 + | MISDN_CTRL_GETPEER; 960 949 break; 961 950 case MISDN_CTRL_SETPEER: 962 951 hc->remoteip = (u32)cq->p1; ··· 976 963 __func__); 977 964 hc->remoteip = 0; 978 965 l1oip_socket_open(hc); 966 + break; 967 + case MISDN_CTRL_GETPEER: 968 + if (debug & DEBUG_L1OIP_SOCKET) 969 + printk(KERN_DEBUG "%s: getting ip address.\n", 970 + __func__); 971 + cq->p1 = hc->remoteip; 972 + cq->p2 = hc->remoteport | (hc->localport << 16); 979 973 break; 980 974 default: 981 975 printk(KERN_WARNING "%s: unknown Op %x\n", ··· 1433 1413 hc->chan[i + ch].bch = bch; 1434 1414 set_channelmap(bch->nr, dch->dev.channelmap); 1435 1415 } 1436 - ret = mISDN_register_device(&dch->dev, hc->name); 1416 + /* TODO: create a parent device for this driver */ 1417 + ret = mISDN_register_device(&dch->dev, NULL, hc->name); 1437 1418 if (ret) 1438 1419 return ret; 1439 1420 hc->registered = 1;
+1 -1
drivers/isdn/mISDN/layer1.c
··· 101 101 va_list va; 102 102 103 103 va_start(va, fmt); 104 - printk(KERN_DEBUG "%s: ", l1->dch->dev.name); 104 + printk(KERN_DEBUG "%s: ", dev_name(&l1->dch->dev.dev)); 105 105 vprintk(fmt, va); 106 106 printk("\n"); 107 107 va_end(va);
+39 -2
drivers/isdn/mISDN/socket.c
··· 381 381 memcpy(di.channelmap, dev->channelmap, 382 382 sizeof(di.channelmap)); 383 383 di.nrbchan = dev->nrbchan; 384 - strcpy(di.name, dev->name); 384 + strcpy(di.name, dev_name(&dev->dev)); 385 385 if (copy_to_user((void __user *)arg, &di, sizeof(di))) 386 386 err = -EFAULT; 387 387 } else ··· 460 460 { 461 461 struct sockaddr_mISDN *maddr = (struct sockaddr_mISDN *) addr; 462 462 struct sock *sk = sock->sk; 463 + struct hlist_node *node; 464 + struct sock *csk; 463 465 int err = 0; 464 466 465 467 if (*debug & DEBUG_SOCKET) ··· 482 480 err = -ENODEV; 483 481 goto done; 484 482 } 483 + 484 + if (sk->sk_protocol < ISDN_P_B_START) { 485 + read_lock_bh(&data_sockets.lock); 486 + sk_for_each(csk, node, &data_sockets.head) { 487 + if (sk == csk) 488 + continue; 489 + if (_pms(csk)->dev != _pms(sk)->dev) 490 + continue; 491 + if (csk->sk_protocol >= ISDN_P_B_START) 492 + continue; 493 + if (IS_ISDN_P_TE(csk->sk_protocol) 494 + == IS_ISDN_P_TE(sk->sk_protocol)) 495 + continue; 496 + read_unlock_bh(&data_sockets.lock); 497 + err = -EBUSY; 498 + goto done; 499 + } 500 + read_unlock_bh(&data_sockets.lock); 501 + } 502 + 485 503 _pms(sk)->ch.send = mISDN_send; 486 504 _pms(sk)->ch.ctrl = mISDN_ctrl; 487 505 ··· 661 639 memcpy(di.channelmap, dev->channelmap, 662 640 sizeof(di.channelmap)); 663 641 di.nrbchan = dev->nrbchan; 664 - strcpy(di.name, dev->name); 642 + strcpy(di.name, dev_name(&dev->dev)); 665 643 if (copy_to_user((void __user *)arg, &di, sizeof(di))) 666 644 err = -EFAULT; 667 645 } else 668 646 err = -ENODEV; 647 + break; 648 + case IMSETDEVNAME: 649 + { 650 + struct mISDN_devrename dn; 651 + if (copy_from_user(&dn, (void __user *)arg, 652 + sizeof(dn))) { 653 + err = -EFAULT; 654 + break; 655 + } 656 + dev = get_mdevice(dn.id); 657 + if (dev) 658 + err = device_rename(&dev->dev, dn.name); 659 + else 660 + err = -ENODEV; 661 + } 669 662 break; 670 663 default: 671 664 err = -EINVAL;
+27 -39
drivers/isdn/mISDN/stack.c
··· 172 172 else 173 173 printk(KERN_WARNING 174 174 "%s: dev(%s) prim(%x) id(%x) no channel\n", 175 - __func__, st->dev->name, hh->prim, hh->id); 175 + __func__, dev_name(&st->dev->dev), hh->prim, 176 + hh->id); 176 177 } else if (lm == 0x8) { 177 178 WARN_ON(lm == 0x8); 178 179 ch = get_channel4id(st, hh->id); ··· 182 181 else 183 182 printk(KERN_WARNING 184 183 "%s: dev(%s) prim(%x) id(%x) no channel\n", 185 - __func__, st->dev->name, hh->prim, hh->id); 184 + __func__, dev_name(&st->dev->dev), hh->prim, 185 + hh->id); 186 186 } else { 187 187 /* broadcast not handled yet */ 188 188 printk(KERN_WARNING "%s: dev(%s) prim %x not delivered\n", 189 - __func__, st->dev->name, hh->prim); 189 + __func__, dev_name(&st->dev->dev), hh->prim); 190 190 } 191 191 return -ESRCH; 192 192 } ··· 211 209 unlock_kernel(); 212 210 #endif 213 211 if (*debug & DEBUG_MSG_THREAD) 214 - printk(KERN_DEBUG "mISDNStackd %s started\n", st->dev->name); 212 + printk(KERN_DEBUG "mISDNStackd %s started\n", 213 + dev_name(&st->dev->dev)); 215 214 216 215 if (st->notify != NULL) { 217 216 complete(st->notify); ··· 248 245 printk(KERN_DEBUG 249 246 "%s: %s prim(%x) id(%x) " 250 247 "send call(%d)\n", 251 - __func__, st->dev->name, 248 + __func__, dev_name(&st->dev->dev), 252 249 mISDN_HEAD_PRIM(skb), 253 250 mISDN_HEAD_ID(skb), err); 254 251 dev_kfree_skb(skb); ··· 291 288 mISDN_STACK_ACTION_MASK)); 292 289 if (*debug & DEBUG_MSG_THREAD) 293 290 printk(KERN_DEBUG "%s: %s wake status %08lx\n", 294 - __func__, st->dev->name, st->status); 291 + __func__, dev_name(&st->dev->dev), st->status); 295 292 test_and_set_bit(mISDN_STACK_ACTIVE, &st->status); 296 293 297 294 test_and_clear_bit(mISDN_STACK_WAKEUP, &st->status); ··· 306 303 #ifdef MISDN_MSG_STATS 307 304 printk(KERN_DEBUG "mISDNStackd daemon for %s proceed %d " 308 305 "msg %d sleep %d stopped\n", 309 - st->dev->name, st->msg_cnt, st->sleep_cnt, st->stopped_cnt); 306 + dev_name(&st->dev->dev), st->msg_cnt, st->sleep_cnt, 307 + st->stopped_cnt); 310 308 printk(KERN_DEBUG 311 309 "mISDNStackd daemon for %s utime(%ld) stime(%ld)\n", 312 - st->dev->name, st->thread->utime, st->thread->stime); 310 + dev_name(&st->dev->dev), st->thread->utime, st->thread->stime); 313 311 printk(KERN_DEBUG 314 312 "mISDNStackd daemon for %s nvcsw(%ld) nivcsw(%ld)\n", 315 - st->dev->name, st->thread->nvcsw, st->thread->nivcsw); 313 + dev_name(&st->dev->dev), st->thread->nvcsw, st->thread->nivcsw); 316 314 printk(KERN_DEBUG "mISDNStackd daemon for %s killed now\n", 317 - st->dev->name); 315 + dev_name(&st->dev->dev)); 318 316 #endif 319 317 test_and_set_bit(mISDN_STACK_KILLED, &st->status); 320 318 test_and_clear_bit(mISDN_STACK_RUNNING, &st->status); ··· 405 401 newst->own.send = mISDN_queue_message; 406 402 newst->own.recv = mISDN_queue_message; 407 403 if (*debug & DEBUG_CORE_FUNC) 408 - printk(KERN_DEBUG "%s: st(%s)\n", __func__, newst->dev->name); 404 + printk(KERN_DEBUG "%s: st(%s)\n", __func__, 405 + dev_name(&newst->dev->dev)); 409 406 newst->notify = &done; 410 407 newst->thread = kthread_run(mISDNStackd, (void *)newst, "mISDN_%s", 411 - newst->dev->name); 408 + dev_name(&newst->dev->dev)); 412 409 if (IS_ERR(newst->thread)) { 413 410 err = PTR_ERR(newst->thread); 414 411 printk(KERN_ERR 415 412 "mISDN:cannot create kernel thread for %s (%d)\n", 416 - newst->dev->name, err); 413 + dev_name(&newst->dev->dev), err); 417 414 delete_teimanager(dev->teimgr); 418 415 kfree(newst); 419 416 } else ··· 433 428 434 429 if (*debug & DEBUG_CORE_FUNC) 435 430 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n", 436 - __func__, dev->name, protocol, adr->dev, adr->channel, 437 - adr->sapi, adr->tei); 431 + __func__, dev_name(&dev->dev), protocol, adr->dev, 432 + adr->channel, adr->sapi, adr->tei); 438 433 switch (protocol) { 439 434 case ISDN_P_NT_S0: 440 435 case ISDN_P_NT_E1: 441 436 case ISDN_P_TE_S0: 442 437 case ISDN_P_TE_E1: 443 - #ifdef PROTOCOL_CHECK 444 - /* this should be enhanced */ 445 - if (!list_empty(&dev->D.st->layer2) 446 - && dev->D.protocol != protocol) 447 - return -EBUSY; 448 - if (!hlist_empty(&dev->D.st->l1sock.head) 449 - && dev->D.protocol != protocol) 450 - return -EBUSY; 451 - #endif 452 438 ch->recv = mISDN_queue_message; 453 439 ch->peer = &dev->D.st->own; 454 440 ch->st = dev->D.st; 455 441 rq.protocol = protocol; 456 - rq.adr.channel = 0; 442 + rq.adr.channel = adr->channel; 457 443 err = dev->D.ctrl(&dev->D, OPEN_CHANNEL, &rq); 458 - printk(KERN_DEBUG "%s: ret 1 %d\n", __func__, err); 444 + printk(KERN_DEBUG "%s: ret %d (dev %d)\n", __func__, err, 445 + dev->id); 459 446 if (err) 460 447 return err; 461 448 write_lock_bh(&dev->D.st->l1sock.lock); ··· 470 473 471 474 if (*debug & DEBUG_CORE_FUNC) 472 475 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n", 473 - __func__, dev->name, protocol, 476 + __func__, dev_name(&dev->dev), protocol, 474 477 adr->dev, adr->channel, adr->sapi, 475 478 adr->tei); 476 479 ch->st = dev->D.st; ··· 526 529 527 530 if (*debug & DEBUG_CORE_FUNC) 528 531 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n", 529 - __func__, dev->name, protocol, 532 + __func__, dev_name(&dev->dev), protocol, 530 533 adr->dev, adr->channel, adr->sapi, 531 534 adr->tei); 532 535 rq.protocol = ISDN_P_TE_S0; ··· 538 541 if (dev->Dprotocols & (1 << ISDN_P_NT_E1)) 539 542 rq.protocol = ISDN_P_NT_E1; 540 543 case ISDN_P_LAPD_TE: 541 - #ifdef PROTOCOL_CHECK 542 - /* this should be enhanced */ 543 - if (!list_empty(&dev->D.st->layer2) 544 - && dev->D.protocol != protocol) 545 - return -EBUSY; 546 - if (!hlist_empty(&dev->D.st->l1sock.head) 547 - && dev->D.protocol != protocol) 548 - return -EBUSY; 549 - #endif 550 544 ch->recv = mISDN_queue_message; 551 545 ch->peer = &dev->D.st->own; 552 546 ch->st = dev->D.st; ··· 578 590 } 579 591 if (*debug & DEBUG_CORE_FUNC) 580 592 printk(KERN_DEBUG "%s: st(%s) protocol(%x)\n", __func__, 581 - ch->st->dev->name, ch->protocol); 593 + dev_name(&ch->st->dev->dev), ch->protocol); 582 594 if (ch->protocol >= ISDN_P_B_START) { 583 595 if (ch->peer) { 584 596 ch->peer->ctrl(ch->peer, CLOSE_CHANNEL, NULL); ··· 631 643 632 644 if (*debug & DEBUG_CORE_FUNC) 633 645 printk(KERN_DEBUG "%s: st(%s)\n", __func__, 634 - st->dev->name); 646 + dev_name(&st->dev->dev)); 635 647 if (dev->teimgr) 636 648 delete_teimanager(dev->teimgr); 637 649 if (st->thread) {
+3 -3
drivers/isdn/mISDN/tei.c
··· 968 968 969 969 if (*debug & DEBUG_L2_TEI) 970 970 printk(KERN_DEBUG "%s: %s proto(%x) adr(%d %d %d %d)\n", 971 - __func__, mgr->ch.st->dev->name, crq->protocol, 972 - crq->adr.dev, crq->adr.channel, crq->adr.sapi, 973 - crq->adr.tei); 971 + __func__, dev_name(&mgr->ch.st->dev->dev), 972 + crq->protocol, crq->adr.dev, crq->adr.channel, 973 + crq->adr.sapi, crq->adr.tei); 974 974 if (crq->adr.sapi != 0) /* not supported yet */ 975 975 return -EINVAL; 976 976 if (crq->adr.tei > GROUP_TEI)
+14 -12
include/linux/mISDNhw.h
··· 57 57 #define FLG_L2DATA 14 /* channel use L2 DATA primitivs */ 58 58 #define FLG_ORIGIN 15 /* channel is on origin site */ 59 59 /* channel specific stuff */ 60 + #define FLG_FILLEMPTY 16 /* fill fifo on first frame (empty) */ 60 61 /* arcofi specific */ 61 - #define FLG_ARCOFI_TIMER 16 62 - #define FLG_ARCOFI_ERROR 17 62 + #define FLG_ARCOFI_TIMER 17 63 + #define FLG_ARCOFI_ERROR 18 63 64 /* isar specific */ 64 - #define FLG_INITIALIZED 16 65 - #define FLG_DLEETX 17 66 - #define FLG_LASTDLE 18 67 - #define FLG_FIRST 19 68 - #define FLG_LASTDATA 20 69 - #define FLG_NMD_DATA 21 70 - #define FLG_FTI_RUN 22 71 - #define FLG_LL_OK 23 72 - #define FLG_LL_CONN 24 73 - #define FLG_DTMFSEND 25 65 + #define FLG_INITIALIZED 17 66 + #define FLG_DLEETX 18 67 + #define FLG_LASTDLE 19 68 + #define FLG_FIRST 20 69 + #define FLG_LASTDATA 21 70 + #define FLG_NMD_DATA 22 71 + #define FLG_FTI_RUN 23 72 + #define FLG_LL_OK 24 73 + #define FLG_LL_CONN 25 74 + #define FLG_DTMFSEND 26 74 75 75 76 /* workq events */ 76 77 #define FLG_RECVQUEUE 30 ··· 184 183 extern int dchannel_senddata(struct dchannel *, struct sk_buff *); 185 184 extern int bchannel_senddata(struct bchannel *, struct sk_buff *); 186 185 extern void recv_Dchannel(struct dchannel *); 186 + extern void recv_Echannel(struct dchannel *, struct dchannel *); 187 187 extern void recv_Bchannel(struct bchannel *); 188 188 extern void recv_Dchannel_skb(struct dchannel *, struct sk_buff *); 189 189 extern void recv_Bchannel_skb(struct bchannel *, struct sk_buff *);
+75 -14
include/linux/mISDNif.h
··· 36 36 * - should be incremented on every checkin 37 37 */ 38 38 #define MISDN_MAJOR_VERSION 1 39 - #define MISDN_MINOR_VERSION 0 40 - #define MISDN_RELEASE 19 39 + #define MISDN_MINOR_VERSION 1 40 + #define MISDN_RELEASE 20 41 41 42 42 /* primitives for information exchange 43 43 * generell format ··· 80 80 #define PH_DEACTIVATE_IND 0x0202 81 81 #define PH_DEACTIVATE_CNF 0x4202 82 82 #define PH_DATA_IND 0x2002 83 + #define PH_DATA_E_IND 0x3002 83 84 #define MPH_ACTIVATE_IND 0x0502 84 85 #define MPH_DEACTIVATE_IND 0x0602 85 86 #define MPH_INFORMATION_IND 0x0702 ··· 200 199 #define ISDN_P_NT_S0 0x02 201 200 #define ISDN_P_TE_E1 0x03 202 201 #define ISDN_P_NT_E1 0x04 202 + #define ISDN_P_TE_UP0 0x05 203 + #define ISDN_P_NT_UP0 0x06 204 + 205 + #define IS_ISDN_P_TE(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_TE_E1) || \ 206 + (p == ISDN_P_TE_UP0) || (p == ISDN_P_LAPD_TE)) 207 + #define IS_ISDN_P_NT(p) ((p == ISDN_P_NT_S0) || (p == ISDN_P_NT_E1) || \ 208 + (p == ISDN_P_NT_UP0) || (p == ISDN_P_LAPD_NT)) 209 + #define IS_ISDN_P_S0(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_NT_S0)) 210 + #define IS_ISDN_P_E1(p) ((p == ISDN_P_TE_E1) || (p == ISDN_P_NT_E1)) 211 + #define IS_ISDN_P_UP0(p) ((p == ISDN_P_TE_UP0) || (p == ISDN_P_NT_UP0)) 212 + 213 + 203 214 #define ISDN_P_LAPD_TE 0x10 204 215 #define ISDN_P_LAPD_NT 0x11 205 216 ··· 268 255 unsigned char tei; 269 256 }; 270 257 271 - /* timer device ioctl */ 272 - #define IMADDTIMER _IOR('I', 64, int) 273 - #define IMDELTIMER _IOR('I', 65, int) 274 - /* socket ioctls */ 275 - #define IMGETVERSION _IOR('I', 66, int) 276 - #define IMGETCOUNT _IOR('I', 67, int) 277 - #define IMGETDEVINFO _IOR('I', 68, int) 278 - #define IMCTRLREQ _IOR('I', 69, int) 279 - #define IMCLEAR_L2 _IOR('I', 70, int) 280 - 281 258 struct mISDNversion { 282 259 unsigned char major; 283 260 unsigned char minor; ··· 283 280 u_int nrbchan; 284 281 char name[MISDN_MAX_IDLEN]; 285 282 }; 283 + 284 + struct mISDN_devrename { 285 + u_int id; 286 + char name[MISDN_MAX_IDLEN]; /* new name */ 287 + }; 288 + 289 + /* MPH_INFORMATION_REQ payload */ 290 + struct ph_info_ch { 291 + __u32 protocol; 292 + __u64 Flags; 293 + }; 294 + 295 + struct ph_info_dch { 296 + struct ph_info_ch ch; 297 + __u16 state; 298 + __u16 num_bch; 299 + }; 300 + 301 + struct ph_info { 302 + struct ph_info_dch dch; 303 + struct ph_info_ch bch[]; 304 + }; 305 + 306 + /* timer device ioctl */ 307 + #define IMADDTIMER _IOR('I', 64, int) 308 + #define IMDELTIMER _IOR('I', 65, int) 309 + 310 + /* socket ioctls */ 311 + #define IMGETVERSION _IOR('I', 66, int) 312 + #define IMGETCOUNT _IOR('I', 67, int) 313 + #define IMGETDEVINFO _IOR('I', 68, int) 314 + #define IMCTRLREQ _IOR('I', 69, int) 315 + #define IMCLEAR_L2 _IOR('I', 70, int) 316 + #define IMSETDEVNAME _IOR('I', 71, struct mISDN_devrename) 286 317 287 318 static inline int 288 319 test_channelmap(u_int nr, u_char *map) ··· 349 312 #define MISDN_CTRL_SETPEER 0x0040 350 313 #define MISDN_CTRL_UNSETPEER 0x0080 351 314 #define MISDN_CTRL_RX_OFF 0x0100 315 + #define MISDN_CTRL_FILL_EMPTY 0x0200 316 + #define MISDN_CTRL_GETPEER 0x0400 352 317 #define MISDN_CTRL_HW_FEATURES_OP 0x2000 353 318 #define MISDN_CTRL_HW_FEATURES 0x2001 354 319 #define MISDN_CTRL_HFC_OP 0x4000 ··· 401 362 #define DEBUG_L2_TEI 0x00100000 402 363 #define DEBUG_L2_TEIFSM 0x00200000 403 364 #define DEBUG_TIMER 0x01000000 365 + #define DEBUG_CLOCK 0x02000000 404 366 405 367 #define mISDN_HEAD_P(s) ((struct mISDNhead *)&s->cb[0]) 406 368 #define mISDN_HEAD_PRIM(s) (((struct mISDNhead *)&s->cb[0])->prim) ··· 415 375 struct mISDNchannel; 416 376 struct mISDNdevice; 417 377 struct mISDNstack; 378 + struct mISDNclock; 418 379 419 380 struct channel_req { 420 381 u_int protocol; ··· 464 423 struct mISDNdevice { 465 424 struct mISDNchannel D; 466 425 u_int id; 467 - char name[MISDN_MAX_IDLEN]; 468 426 u_int Dprotocols; 469 427 u_int Bprotocols; 470 428 u_int nrbchan; ··· 490 450 u_int sleep_cnt; 491 451 u_int stopped_cnt; 492 452 #endif 453 + }; 454 + 455 + typedef int (clockctl_func_t)(void *, int); 456 + 457 + struct mISDNclock { 458 + struct list_head list; 459 + char name[64]; 460 + int pri; 461 + clockctl_func_t *ctl; 462 + void *priv; 493 463 }; 494 464 495 465 /* global alloc/queue functions */ ··· 548 498 549 499 /* global register/unregister functions */ 550 500 551 - extern int mISDN_register_device(struct mISDNdevice *, char *name); 501 + extern int mISDN_register_device(struct mISDNdevice *, 502 + struct device *parent, char *name); 552 503 extern void mISDN_unregister_device(struct mISDNdevice *); 553 504 extern int mISDN_register_Bprotocol(struct Bprotocol *); 554 505 extern void mISDN_unregister_Bprotocol(struct Bprotocol *); 506 + extern struct mISDNclock *mISDN_register_clock(char *, int, clockctl_func_t *, 507 + void *); 508 + extern void mISDN_unregister_clock(struct mISDNclock *); 509 + 510 + static inline struct mISDNdevice *dev_to_mISDN(struct device *dev) 511 + { 512 + return dev_get_drvdata(dev); 513 + } 555 514 556 515 extern void set_channel_address(struct mISDNchannel *, u_int, u_int); 516 + extern void mISDN_clock_update(struct mISDNclock *, int, struct timeval *); 517 + extern unsigned short mISDN_clock_get(void); 557 518 558 519 #endif /* __KERNEL__ */ 559 520 #endif /* mISDNIF_H */