1 /* $Id: hfc_sx.c,v 1.1.1.1 2005/04/11 02:50:23 jack Exp $
3 * level driver for CCD´s hfc-s+/sp based cards
5 * Author Werner Cornelius
6 * based on existing driver for CCD HFC PCI cards
7 * Copyright by Werner Cornelius <werner@isdn4linux.de>
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
14 #define __NO_VERSION__
15 #include <linux/init.h>
19 #include <linux/interrupt.h>
20 #include <linux/isapnp.h>
22 extern const char *CardType[];
24 static const char *hfcsx_revision = "$Revision: 1.1.1.1 $";
26 /***************************************/
27 /* IRQ-table for CCDs demo board */
28 /* IRQs 6,5,10,11,12,15 are supported */
29 /***************************************/
31 /* Teles 16.3c Vendor Id TAG2620, Version 1.0, Vendor version 2.1
33 * Thanks to Uwe Wisniewski
47 static u_char ccd_sp_irqtab[16] = {
48 0,0,0,0,0,2,1,0,0,0,3,4,5,0,0,6
50 #else /* Teles 16.3c */
51 static u_char ccd_sp_irqtab[16] = {
52 0,0,0,7,0,1,0,0,0,2,3,4,5,0,0,6
55 #define NT_T1_COUNT 20 /* number of 3.125ms interrupts for G2 timeout */
57 #define byteout(addr,val) outb(val,addr)
58 #define bytein(addr) inb(addr)
60 /******************************/
61 /* In/Out access to registers */
62 /******************************/
64 Write_hfc(struct IsdnCardState *cs, u_char regnum, u_char val)
65 { unsigned long flags;
69 byteout(cs->hw.hfcsx.base+1, regnum);
70 byteout(cs->hw.hfcsx.base, val);
75 Read_hfc(struct IsdnCardState *cs, u_char regnum)
76 { unsigned long flags;
81 byteout(cs->hw.hfcsx.base+1, regnum);
82 ret = bytein(cs->hw.hfcsx.base);
88 /**************************************************/
89 /* select a fifo and remember which one for reuse */
90 /**************************************************/
92 fifo_select(struct IsdnCardState *cs, u_char fifo)
93 { unsigned long flags;
95 if (fifo == cs->hw.hfcsx.last_fifo)
96 return; /* still valid */
100 byteout(cs->hw.hfcsx.base+1, HFCSX_FIF_SEL);
101 byteout(cs->hw.hfcsx.base, fifo);
102 while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
104 byteout(cs->hw.hfcsx.base, fifo);
105 while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
106 restore_flags(flags);
109 /******************************************/
110 /* reset the specified fifo to defaults. */
111 /* If its a send fifo init needed markers */
112 /******************************************/
114 reset_fifo(struct IsdnCardState *cs, u_char fifo)
115 { unsigned long flags;
119 fifo_select(cs, fifo); /* first select the fifo */
120 byteout(cs->hw.hfcsx.base+1, HFCSX_CIRM);
121 byteout(cs->hw.hfcsx.base, cs->hw.hfcsx.cirm | 0x80); /* reset cmd */
123 while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
124 restore_flags(flags);
128 /*************************************************************/
129 /* write_fifo writes the skb contents to the desired fifo */
130 /* if no space is available or an error occurs 0 is returned */
131 /* the skb is not released in any way. */
132 /*************************************************************/
134 write_fifo(struct IsdnCardState *cs, struct sk_buff *skb, u_char fifo, int trans_max)
135 { unsigned short *msp;
136 int fifo_size, count, z1, z2;
137 u_char f_msk, f1, f2, *src;
139 if (skb->len <= 0) return(0);
140 if (fifo & 1) return(0); /* no write fifo */
142 fifo_select(cs, fifo);
144 fifo_size = D_FIFO_SIZE; /* D-channel */
145 f_msk = MAX_D_FRAMES;
146 if (trans_max) return(0); /* only HDLC */
149 fifo_size = cs->hw.hfcsx.b_fifo_size; /* B-channel */
150 f_msk = MAX_B_FRAMES;
153 z1 = Read_hfc(cs, HFCSX_FIF_Z1H);
154 z1 = ((z1 << 8) | Read_hfc(cs, HFCSX_FIF_Z1L));
156 /* Check for transparent mode */
158 z2 = Read_hfc(cs, HFCSX_FIF_Z2H);
159 z2 = ((z2 << 8) | Read_hfc(cs, HFCSX_FIF_Z2L));
162 count += fifo_size; /* free bytes */
163 if (count < skb->len+1) return(0); /* no room */
164 count = fifo_size - count; /* bytes still not send */
165 if (count > 2 * trans_max) return(0); /* delay to long */
169 Write_hfc(cs, HFCSX_FIF_DWR, *src++);
170 return(1); /* success */
173 msp = ((struct hfcsx_extra *)(cs->hw.hfcsx.extra))->marker;
174 msp += (((fifo >> 1) & 3) * (MAX_B_FRAMES+1));
175 f1 = Read_hfc(cs, HFCSX_FIF_F1) & f_msk;
176 f2 = Read_hfc(cs, HFCSX_FIF_F2) & f_msk;
178 count = f1 - f2; /* frame count actually buffered */
180 count += (f_msk + 1); /* if wrap around */
181 if (count > f_msk-1) {
182 if (cs->debug & L1_DEB_ISAC_FIFO)
183 debugl1(cs, "hfcsx_write_fifo %d more as %d frames",fifo,f_msk-1);
187 *(msp + f1) = z1; /* remember marker */
189 if (cs->debug & L1_DEB_ISAC_FIFO)
190 debugl1(cs, "hfcsx_write_fifo %d f1(%x) f2(%x) z1(f1)(%x)",
192 /* now determine free bytes in FIFO buffer */
193 count = *(msp + f2) - z1;
195 count += fifo_size; /* count now contains available bytes */
197 if (cs->debug & L1_DEB_ISAC_FIFO)
198 debugl1(cs, "hfcsx_write_fifo %d count(%ld/%d)",
199 fifo, skb->len, count);
200 if (count < skb->len) {
201 if (cs->debug & L1_DEB_ISAC_FIFO)
202 debugl1(cs, "hfcsx_write_fifo %d no fifo mem", fifo);
206 count = skb->len; /* get frame len */
207 src = skb->data; /* source pointer */
209 Write_hfc(cs, HFCSX_FIF_DWR, *src++);
211 Read_hfc(cs, HFCSX_FIF_INCF1); /* increment F1 */
213 while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
217 /***************************************************************/
218 /* read_fifo reads data to an skb from the desired fifo */
219 /* if no data is available or an error occurs NULL is returned */
220 /* the skb is not released in any way. */
221 /***************************************************************/
222 static struct sk_buff *
223 read_fifo(struct IsdnCardState *cs, u_char fifo, int trans_max)
224 { int fifo_size, count, z1, z2;
225 u_char f_msk, f1, f2, *dst;
228 if (!(fifo & 1)) return(NULL); /* no read fifo */
229 fifo_select(cs, fifo);
231 fifo_size = D_FIFO_SIZE; /* D-channel */
232 f_msk = MAX_D_FRAMES;
233 if (trans_max) return(NULL); /* only hdlc */
236 fifo_size = cs->hw.hfcsx.b_fifo_size; /* B-channel */
237 f_msk = MAX_B_FRAMES;
240 /* transparent mode */
242 z1 = Read_hfc(cs, HFCSX_FIF_Z1H);
243 z1 = ((z1 << 8) | Read_hfc(cs, HFCSX_FIF_Z1L));
244 z2 = Read_hfc(cs, HFCSX_FIF_Z2H);
245 z2 = ((z2 << 8) | Read_hfc(cs, HFCSX_FIF_Z2L));
246 /* now determine bytes in actual FIFO buffer */
249 count += fifo_size; /* count now contains buffered bytes */
251 if (count > trans_max)
252 count = trans_max; /* limit length */
253 if ((skb = dev_alloc_skb(count))) {
254 dst = skb_put(skb, count);
256 *dst++ = Read_hfc(cs, HFCSX_FIF_DRD);
259 else return(NULL); /* no memory */
263 f1 = Read_hfc(cs, HFCSX_FIF_F1) & f_msk;
264 f2 = Read_hfc(cs, HFCSX_FIF_F2) & f_msk;
266 if (f1 == f2) return(NULL); /* no frame available */
268 z1 = Read_hfc(cs, HFCSX_FIF_Z1H);
269 z1 = ((z1 << 8) | Read_hfc(cs, HFCSX_FIF_Z1L));
270 z2 = Read_hfc(cs, HFCSX_FIF_Z2H);
271 z2 = ((z2 << 8) | Read_hfc(cs, HFCSX_FIF_Z2L));
273 if (cs->debug & L1_DEB_ISAC_FIFO)
274 debugl1(cs, "hfcsx_read_fifo %d f1(%x) f2(%x) z1(f2)(%x) z2(f2)(%x)",
275 fifo, f1, f2, z1, z2);
276 /* now determine bytes in actual FIFO buffer */
279 count += fifo_size; /* count now contains buffered bytes */
282 if (cs->debug & L1_DEB_ISAC_FIFO)
283 debugl1(cs, "hfcsx_read_fifo %d count %ld)",
286 if ((count > fifo_size) || (count < 4)) {
287 if (cs->debug & L1_DEB_WARN)
288 debugl1(cs, "hfcsx_read_fifo %d paket inv. len %d ", fifo , count);
290 count--; /* empty fifo */
291 Read_hfc(cs, HFCSX_FIF_DRD);
295 if ((skb = dev_alloc_skb(count - 3))) {
297 dst = skb_put(skb, count);
300 *dst++ = Read_hfc(cs, HFCSX_FIF_DRD);
302 Read_hfc(cs, HFCSX_FIF_DRD); /* CRC 1 */
303 Read_hfc(cs, HFCSX_FIF_DRD); /* CRC 2 */
304 if (Read_hfc(cs, HFCSX_FIF_DRD)) {
305 dev_kfree_skb_irq(skb);
306 if (cs->debug & L1_DEB_ISAC_FIFO)
307 debugl1(cs, "hfcsx_read_fifo %d crc error", fifo);
311 printk(KERN_WARNING "HFC-SX: receive out of memory\n");
315 Read_hfc(cs, HFCSX_FIF_INCF2); /* increment F2 */
317 while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
319 } while (!skb); /* retry in case of crc error */
323 /******************************************/
324 /* free hardware resources used by driver */
325 /******************************************/
327 release_io_hfcsx(struct IsdnCardState *cs)
333 cs->hw.hfcsx.int_m2 = 0; /* interrupt output off ! */
334 Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
335 restore_flags(flags);
336 Write_hfc(cs, HFCSX_CIRM, HFCSX_RESET); /* Reset On */
338 set_current_state(TASK_UNINTERRUPTIBLE);
339 schedule_timeout((30 * HZ) / 1000); /* Timeout 30ms */
340 Write_hfc(cs, HFCSX_CIRM, 0); /* Reset Off */
341 del_timer(&cs->hw.hfcsx.timer);
342 release_region(cs->hw.hfcsx.base, 2); /* release IO-Block */
343 kfree(cs->hw.hfcsx.extra);
344 cs->hw.hfcsx.extra = NULL;
347 /**********************************************************/
348 /* set_fifo_size determines the size of the RAM and FIFOs */
349 /* returning 0 -> need to reset the chip again. */
350 /**********************************************************/
351 static int set_fifo_size(struct IsdnCardState *cs)
354 if (cs->hw.hfcsx.b_fifo_size) return(1); /* already determined */
356 if ((cs->hw.hfcsx.chip >> 4) == 9) {
357 cs->hw.hfcsx.b_fifo_size = B_FIFO_SIZE_32K;
361 cs->hw.hfcsx.b_fifo_size = B_FIFO_SIZE_8K;
362 cs->hw.hfcsx.cirm |= 0x10; /* only 8K of ram */
367 /********************************************************************************/
368 /* function called to reset the HFC SX chip. A complete software reset of chip */
369 /* and fifos is done. */
370 /********************************************************************************/
372 reset_hfcsx(struct IsdnCardState *cs)
378 cs->hw.hfcsx.int_m2 = 0; /* interrupt output off ! */
379 Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
381 printk(KERN_INFO "HFC_SX: resetting card\n");
383 Write_hfc(cs, HFCSX_CIRM, HFCSX_RESET | cs->hw.hfcsx.cirm ); /* Reset */
385 set_current_state(TASK_UNINTERRUPTIBLE);
386 schedule_timeout((30 * HZ) / 1000); /* Timeout 30ms */
387 Write_hfc(cs, HFCSX_CIRM, cs->hw.hfcsx.cirm); /* Reset Off */
388 set_current_state(TASK_UNINTERRUPTIBLE);
389 schedule_timeout((20 * HZ) / 1000); /* Timeout 20ms */
390 if (Read_hfc(cs, HFCSX_STATUS) & 2)
391 printk(KERN_WARNING "HFC-SX init bit busy\n");
392 cs->hw.hfcsx.last_fifo = 0xff; /* invalidate */
393 if (!set_fifo_size(cs)) continue;
397 cs->hw.hfcsx.trm = 0 + HFCSX_BTRANS_THRESMASK; /* no echo connect , threshold */
398 Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
400 Write_hfc(cs, HFCSX_CLKDEL, 0x0e); /* ST-Bit delay for TE-Mode */
401 cs->hw.hfcsx.sctrl_e = HFCSX_AUTO_AWAKE;
402 Write_hfc(cs, HFCSX_SCTRL_E, cs->hw.hfcsx.sctrl_e); /* S/T Auto awake */
403 cs->hw.hfcsx.bswapped = 0; /* no exchange */
404 cs->hw.hfcsx.nt_mode = 0; /* we are in TE mode */
405 cs->hw.hfcsx.ctmt = HFCSX_TIM3_125 | HFCSX_AUTO_TIMER;
406 Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
408 cs->hw.hfcsx.int_m1 = HFCSX_INTS_DTRANS | HFCSX_INTS_DREC |
409 HFCSX_INTS_L1STATE | HFCSX_INTS_TIMER;
410 Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
412 /* Clear already pending ints */
413 if (Read_hfc(cs, HFCSX_INT_S1));
415 Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 2); /* HFC ST 2 */
417 Write_hfc(cs, HFCSX_STATES, 2); /* HFC ST 2 */
418 cs->hw.hfcsx.mst_m = HFCSX_MASTER; /* HFC Master Mode */
420 Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
421 cs->hw.hfcsx.sctrl = 0x40; /* set tx_lo mode, error in datasheet ! */
422 Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
423 cs->hw.hfcsx.sctrl_r = 0;
424 Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
426 /* Init GCI/IOM2 in master mode */
427 /* Slots 0 and 1 are set for B-chan 1 and 2 */
428 /* D- and monitor/CI channel are not enabled */
429 /* STIO1 is used as output for data, B1+B2 from ST->IOM+HFC */
430 /* STIO2 is used as data input, B1+B2 from IOM->ST */
431 /* ST B-channel send disabled -> continous 1s */
432 /* The IOM slots are always enabled */
433 cs->hw.hfcsx.conn = 0x36; /* set data flow directions */
434 Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
435 Write_hfc(cs, HFCSX_B1_SSL, 0x80); /* B1-Slot 0 STIO1 out enabled */
436 Write_hfc(cs, HFCSX_B2_SSL, 0x81); /* B2-Slot 1 STIO1 out enabled */
437 Write_hfc(cs, HFCSX_B1_RSL, 0x80); /* B1-Slot 0 STIO2 in enabled */
438 Write_hfc(cs, HFCSX_B2_RSL, 0x81); /* B2-Slot 1 STIO2 in enabled */
440 /* Finally enable IRQ output */
441 cs->hw.hfcsx.int_m2 = HFCSX_IRQ_ENABLE;
442 Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
443 if (Read_hfc(cs, HFCSX_INT_S2));
444 restore_flags(flags);
447 /***************************************************/
448 /* Timer function called when kernel timer expires */
449 /***************************************************/
451 hfcsx_Timer(struct IsdnCardState *cs)
453 cs->hw.hfcsx.timer.expires = jiffies + 75;
455 /* WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcsx.ctmt | 0x80);
456 add_timer(&cs->hw.hfcsx.timer);
461 /*********************************/
462 /* schedule a new D-channel task */
463 /*********************************/
465 sched_event_D_sx(struct IsdnCardState *cs, int event)
467 test_and_set_bit(event, &cs->event);
468 queue_task(&cs->tqueue, &tq_immediate);
469 mark_bh(IMMEDIATE_BH);
472 /*********************************/
473 /* schedule a new b_channel task */
474 /*********************************/
476 hfcsx_sched_event(struct BCState *bcs, int event)
478 bcs->event |= 1 << event;
479 queue_task(&bcs->tqueue, &tq_immediate);
480 mark_bh(IMMEDIATE_BH);
483 /************************************************/
484 /* select a b-channel entry matching and active */
485 /************************************************/
488 Sel_BCS(struct IsdnCardState *cs, int channel)
490 if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
491 return (&cs->bcs[0]);
492 else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
493 return (&cs->bcs[1]);
498 /*******************************/
499 /* D-channel receive procedure */
500 /*******************************/
503 receive_dmsg(struct IsdnCardState *cs)
508 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
509 debugl1(cs, "rec_dmsg blocked");
514 skb = read_fifo(cs, HFCSX_SEL_D_RX, 0);
516 skb_queue_tail(&cs->rq, skb);
517 sched_event_D_sx(cs, D_RCVBUFREADY);
519 } while (--count && skb);
521 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
525 /**********************************/
526 /* B-channel main receive routine */
527 /**********************************/
529 main_rec_hfcsx(struct BCState *bcs)
532 struct IsdnCardState *cs = bcs->cs;
541 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
542 debugl1(cs, "rec_data %d blocked", bcs->channel);
543 restore_flags(flags);
547 skb = read_fifo(cs, ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
548 HFCSX_SEL_B2_RX : HFCSX_SEL_B1_RX,
549 (bcs->mode == L1_MODE_TRANS) ?
550 HFCSX_BTRANS_THRESHOLD : 0);
554 skb_queue_tail(&bcs->rqueue, skb);
556 hfcsx_sched_event(bcs, B_RCVBUFREADY);
559 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
562 restore_flags(flags);
566 /**************************/
567 /* D-channel send routine */
568 /**************************/
570 hfcsx_fill_dfifo(struct IsdnCardState *cs)
574 if (cs->tx_skb->len <= 0)
577 if (write_fifo(cs, cs->tx_skb, HFCSX_SEL_D_TX, 0)) {
578 dev_kfree_skb_any(cs->tx_skb);
584 /**************************/
585 /* B-channel send routine */
586 /**************************/
588 hfcsx_fill_fifo(struct BCState *bcs)
590 struct IsdnCardState *cs = bcs->cs;
595 if (bcs->tx_skb->len <= 0)
601 if (write_fifo(cs, bcs->tx_skb,
602 ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
603 HFCSX_SEL_B2_TX : HFCSX_SEL_B1_TX,
604 (bcs->mode == L1_MODE_TRANS) ?
605 HFCSX_BTRANS_THRESHOLD : 0)) {
607 bcs->tx_cnt -= bcs->tx_skb->len;
608 if (bcs->st->lli.l1writewakeup &&
609 (PACKET_NOACK != bcs->tx_skb->pkt_type))
610 bcs->st->lli.l1writewakeup(bcs->st, bcs->tx_skb->len);
611 dev_kfree_skb_any(bcs->tx_skb);
613 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
617 restore_flags(flags);
621 /**********************************************/
622 /* D-channel l1 state call for leased NT-mode */
623 /**********************************************/
625 dch_nt_l2l1(struct PStack *st, int pr, void *arg)
627 struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
630 case (PH_DATA | REQUEST):
631 case (PH_PULL | REQUEST):
632 case (PH_PULL | INDICATION):
633 st->l1.l1hw(st, pr, arg);
635 case (PH_ACTIVATE | REQUEST):
636 st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
638 case (PH_TESTLOOP | REQUEST):
640 debugl1(cs, "PH_TEST_LOOP B1");
642 debugl1(cs, "PH_TEST_LOOP B2");
643 if (!(3 & (long) arg))
644 debugl1(cs, "PH_TEST_LOOP DISABLED");
645 st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
649 debugl1(cs, "dch_nt_l2l1 msg %04X unhandled", pr);
656 /***********************/
657 /* set/reset echo mode */
658 /***********************/
660 hfcsx_auxcmd(struct IsdnCardState *cs, isdn_ctrl * ic)
663 int i = *(unsigned int *) ic->parm.num;
665 if ((ic->arg == 98) &&
666 (!(cs->hw.hfcsx.int_m1 & (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC + HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC)))) {
669 Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 0); /* HFC ST G0 */
671 cs->hw.hfcsx.sctrl |= SCTRL_MODE_NT;
672 Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl); /* set NT-mode */
674 Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 1); /* HFC ST G1 */
676 Write_hfc(cs, HFCSX_STATES, 1 | HFCSX_ACTIVATE | HFCSX_DO_ACTION);
677 cs->dc.hfcsx.ph_state = 1;
678 cs->hw.hfcsx.nt_mode = 1;
679 cs->hw.hfcsx.nt_timer = 0;
680 cs->stlist->l2.l2l1 = dch_nt_l2l1;
681 restore_flags(flags);
682 debugl1(cs, "NT mode activated");
685 if ((cs->chanlimit > 1) || (cs->hw.hfcsx.bswapped) ||
686 (cs->hw.hfcsx.nt_mode) || (ic->arg != 12))
693 cs->hw.hfcsx.trm |= 0x20; /* enable echo chan */
694 cs->hw.hfcsx.int_m1 |= HFCSX_INTS_B2REC;
695 /* reset Channel !!!!! */
698 cs->hw.hfcsx.trm &= ~0x20; /* disable echo chan */
699 cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_B2REC;
701 cs->hw.hfcsx.sctrl_r &= ~SCTRL_B2_ENA;
702 cs->hw.hfcsx.sctrl &= ~SCTRL_B2_ENA;
703 cs->hw.hfcsx.conn |= 0x10; /* B2-IOM -> B2-ST */
704 cs->hw.hfcsx.ctmt &= ~2;
705 Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
706 Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
707 Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
708 Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
709 Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
710 Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
711 restore_flags(flags);
715 /*****************************/
716 /* E-channel receive routine */
717 /*****************************/
719 receive_emsg(struct IsdnCardState *cs)
729 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
730 debugl1(cs, "echo_rec_data blocked");
731 restore_flags(flags);
737 skb = read_fifo(cs, HFCSX_SEL_B2_RX, 0);
739 if (cs->debug & DEB_DLOG_HEX) {
741 if ((skb->len) < MAX_DLOG_SPACE / 3 - 10) {
747 ptr += QuickHex(ptr, skb->data, skb->len);
751 HiSax_putstatus(cs, NULL, cs->dlog);
753 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
755 dev_kfree_skb_any(skb);
757 } while (--count && skb);
759 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
760 restore_flags(flags);
765 /*********************/
766 /* Interrupt handler */
767 /*********************/
769 hfcsx_interrupt(int intno, void *dev_id, struct pt_regs *regs)
771 struct IsdnCardState *cs = dev_id;
779 printk(KERN_WARNING "HFC-SX: Spurious interrupt!\n");
782 if (!(cs->hw.hfcsx.int_m2 & 0x08))
783 return; /* not initialised */
785 if (HFCSX_ANYINT & (stat = Read_hfc(cs, HFCSX_STATUS))) {
786 val = Read_hfc(cs, HFCSX_INT_S1);
787 if (cs->debug & L1_DEB_ISAC)
788 debugl1(cs, "HFC-SX: stat(%02x) s1(%02x)", stat, val);
792 if (cs->debug & L1_DEB_ISAC)
793 debugl1(cs, "HFC-SX irq %x %s", val,
794 test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
795 "locked" : "unlocked");
796 val &= cs->hw.hfcsx.int_m1;
797 if (val & 0x40) { /* state machine irq */
798 exval = Read_hfc(cs, HFCSX_STATES) & 0xf;
799 if (cs->debug & L1_DEB_ISAC)
800 debugl1(cs, "ph_state chg %d->%d", cs->dc.hfcsx.ph_state,
802 cs->dc.hfcsx.ph_state = exval;
803 sched_event_D_sx(cs, D_L1STATECHANGE);
806 if (val & 0x80) { /* timer irq */
807 if (cs->hw.hfcsx.nt_mode) {
808 if ((--cs->hw.hfcsx.nt_timer) < 0)
809 sched_event_D_sx(cs, D_L1STATECHANGE);
812 Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
817 if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
818 cs->hw.hfcsx.int_s1 |= val;
819 restore_flags(flags);
822 if (cs->hw.hfcsx.int_s1 & 0x18) {
824 val = cs->hw.hfcsx.int_s1;
825 cs->hw.hfcsx.int_s1 = exval;
828 if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
830 debugl1(cs, "hfcsx spurious 0x08 IRQ");
837 else if (!(bcs = Sel_BCS(cs, 1))) {
839 debugl1(cs, "hfcsx spurious 0x10 IRQ");
844 if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
846 debugl1(cs, "hfcsx spurious 0x01 IRQ");
849 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
850 hfcsx_fill_fifo(bcs);
851 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
853 debugl1(cs, "fill_data %d blocked", bcs->channel);
855 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
856 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
857 hfcsx_fill_fifo(bcs);
858 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
860 debugl1(cs, "fill_data %d blocked", bcs->channel);
862 hfcsx_sched_event(bcs, B_XMTBUFREADY);
868 if (!(bcs = Sel_BCS(cs, 1))) {
870 debugl1(cs, "hfcsx spurious 0x02 IRQ");
873 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
874 hfcsx_fill_fifo(bcs);
875 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
877 debugl1(cs, "fill_data %d blocked", bcs->channel);
879 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
880 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
881 hfcsx_fill_fifo(bcs);
882 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
884 debugl1(cs, "fill_data %d blocked", bcs->channel);
886 hfcsx_sched_event(bcs, B_XMTBUFREADY);
891 if (val & 0x20) { /* receive dframe */
894 if (val & 0x04) { /* dframe transmitted */
895 if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
896 del_timer(&cs->dbusytimer);
897 if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
898 sched_event_D_sx(cs, D_CLEARBUSY);
900 if (cs->tx_skb->len) {
901 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
902 hfcsx_fill_dfifo(cs);
903 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
905 debugl1(cs, "hfcsx_fill_dfifo irq blocked");
909 dev_kfree_skb_irq(cs->tx_skb);
914 if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
916 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
917 hfcsx_fill_dfifo(cs);
918 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
920 debugl1(cs, "hfcsx_fill_dfifo irq blocked");
923 sched_event_D_sx(cs, D_XMTBUFREADY);
926 if (cs->hw.hfcsx.int_s1 && count--) {
927 val = cs->hw.hfcsx.int_s1;
928 cs->hw.hfcsx.int_s1 = 0;
929 if (cs->debug & L1_DEB_ISAC)
930 debugl1(cs, "HFC-SX irq %x loop %d", val, 15 - count);
933 restore_flags(flags);
937 /********************************************************************/
938 /* timer callback for D-chan busy resolution. Currently no function */
939 /********************************************************************/
941 hfcsx_dbusy_timer(struct IsdnCardState *cs)
945 /*************************************/
946 /* Layer 1 D-channel hardware access */
947 /*************************************/
949 HFCSX_l1hw(struct PStack *st, int pr, void *arg)
951 struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
952 struct sk_buff *skb = arg;
956 case (PH_DATA | REQUEST):
957 if (cs->debug & DEB_DLOG_HEX)
958 LogFrame(cs, skb->data, skb->len);
959 if (cs->debug & DEB_DLOG_VERBOSE)
960 dlogframe(cs, skb, 0);
962 skb_queue_tail(&cs->sq, skb);
963 #ifdef L2FRAME_DEBUG /* psa */
964 if (cs->debug & L1_DEB_LAPD)
965 Logl2Frame(cs, skb, "PH_DATA Queued", 0);
970 #ifdef L2FRAME_DEBUG /* psa */
971 if (cs->debug & L1_DEB_LAPD)
972 Logl2Frame(cs, skb, "PH_DATA", 0);
974 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
975 hfcsx_fill_dfifo(cs);
976 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
978 debugl1(cs, "hfcsx_fill_dfifo blocked");
982 case (PH_PULL | INDICATION):
984 if (cs->debug & L1_DEB_WARN)
985 debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
986 skb_queue_tail(&cs->sq, skb);
989 if (cs->debug & DEB_DLOG_HEX)
990 LogFrame(cs, skb->data, skb->len);
991 if (cs->debug & DEB_DLOG_VERBOSE)
992 dlogframe(cs, skb, 0);
995 #ifdef L2FRAME_DEBUG /* psa */
996 if (cs->debug & L1_DEB_LAPD)
997 Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
999 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1000 hfcsx_fill_dfifo(cs);
1001 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1003 debugl1(cs, "hfcsx_fill_dfifo blocked");
1005 case (PH_PULL | REQUEST):
1006 #ifdef L2FRAME_DEBUG /* psa */
1007 if (cs->debug & L1_DEB_LAPD)
1008 debugl1(cs, "-> PH_REQUEST_PULL");
1011 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1012 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1014 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1016 case (HW_RESET | REQUEST):
1017 Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 3); /* HFC ST 3 */
1019 Write_hfc(cs, HFCSX_STATES, 3); /* HFC ST 2 */
1020 cs->hw.hfcsx.mst_m |= HFCSX_MASTER;
1021 Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
1022 Write_hfc(cs, HFCSX_STATES, HFCSX_ACTIVATE | HFCSX_DO_ACTION);
1023 l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
1025 case (HW_ENABLE | REQUEST):
1026 Write_hfc(cs, HFCSX_STATES, HFCSX_ACTIVATE | HFCSX_DO_ACTION);
1028 case (HW_DEACTIVATE | REQUEST):
1029 cs->hw.hfcsx.mst_m &= ~HFCSX_MASTER;
1030 Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
1032 case (HW_INFO3 | REQUEST):
1033 cs->hw.hfcsx.mst_m |= HFCSX_MASTER;
1034 Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
1036 case (HW_TESTLOOP | REQUEST):
1037 switch ((int) arg) {
1039 Write_hfc(cs, HFCSX_B1_SSL, 0x80); /* tx slot */
1040 Write_hfc(cs, HFCSX_B1_RSL, 0x80); /* rx slot */
1043 cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~7) | 1;
1044 Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
1045 restore_flags(flags);
1049 Write_hfc(cs, HFCSX_B2_SSL, 0x81); /* tx slot */
1050 Write_hfc(cs, HFCSX_B2_RSL, 0x81); /* rx slot */
1053 cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~0x38) | 0x08;
1054 Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
1055 restore_flags(flags);
1059 if (cs->debug & L1_DEB_WARN)
1060 debugl1(cs, "hfcsx_l1hw loop invalid %4x", (int) arg);
1065 cs->hw.hfcsx.trm |= 0x80; /* enable IOM-loop */
1066 Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
1067 restore_flags(flags);
1070 if (cs->debug & L1_DEB_WARN)
1071 debugl1(cs, "hfcsx_l1hw unknown pr %4x", pr);
1076 /***********************************************/
1077 /* called during init setting l1 stack pointer */
1078 /***********************************************/
1080 setstack_hfcsx(struct PStack *st, struct IsdnCardState *cs)
1082 st->l1.l1hw = HFCSX_l1hw;
1085 /**************************************/
1086 /* send B-channel data if not blocked */
1087 /**************************************/
1089 hfcsx_send_data(struct BCState *bcs)
1091 struct IsdnCardState *cs = bcs->cs;
1093 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1094 hfcsx_fill_fifo(bcs);
1095 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1097 debugl1(cs, "send_data %d blocked", bcs->channel);
1100 /***************************************************************/
1101 /* activate/deactivate hardware for selected channels and mode */
1102 /***************************************************************/
1104 mode_hfcsx(struct BCState *bcs, int mode, int bc)
1106 struct IsdnCardState *cs = bcs->cs;
1107 unsigned long flags;
1110 if (cs->debug & L1_DEB_HSCX)
1111 debugl1(cs, "HFCSX bchannel mode %d bchan %d/%d",
1112 mode, bc, bcs->channel);
1118 if (cs->chanlimit > 1) {
1119 cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
1120 cs->hw.hfcsx.sctrl_e &= ~0x80;
1123 if (mode != L1_MODE_NULL) {
1124 cs->hw.hfcsx.bswapped = 1; /* B1 and B2 exchanged */
1125 cs->hw.hfcsx.sctrl_e |= 0x80;
1127 cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
1128 cs->hw.hfcsx.sctrl_e &= ~0x80;
1132 cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
1133 cs->hw.hfcsx.sctrl_e &= ~0x80;
1137 case (L1_MODE_NULL):
1139 cs->hw.hfcsx.sctrl &= ~SCTRL_B2_ENA;
1140 cs->hw.hfcsx.sctrl_r &= ~SCTRL_B2_ENA;
1142 cs->hw.hfcsx.sctrl &= ~SCTRL_B1_ENA;
1143 cs->hw.hfcsx.sctrl_r &= ~SCTRL_B1_ENA;
1146 cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
1148 cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
1151 case (L1_MODE_TRANS):
1153 cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
1154 cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
1156 cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
1157 cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
1160 cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
1161 cs->hw.hfcsx.ctmt |= 2;
1162 cs->hw.hfcsx.conn &= ~0x18;
1164 cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
1165 cs->hw.hfcsx.ctmt |= 1;
1166 cs->hw.hfcsx.conn &= ~0x03;
1169 case (L1_MODE_HDLC):
1171 cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
1172 cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
1174 cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
1175 cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
1178 cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
1179 cs->hw.hfcsx.ctmt &= ~2;
1180 cs->hw.hfcsx.conn &= ~0x18;
1182 cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
1183 cs->hw.hfcsx.ctmt &= ~1;
1184 cs->hw.hfcsx.conn &= ~0x03;
1187 case (L1_MODE_EXTRN):
1189 cs->hw.hfcsx.conn |= 0x10;
1190 cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
1191 cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
1192 cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
1194 cs->hw.hfcsx.conn |= 0x02;
1195 cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
1196 cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
1197 cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
1201 Write_hfc(cs, HFCSX_SCTRL_E, cs->hw.hfcsx.sctrl_e);
1202 Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
1203 Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
1204 Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
1205 Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
1206 Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
1207 if (mode != L1_MODE_EXTRN) {
1208 reset_fifo(cs, fifo2 ? HFCSX_SEL_B2_RX : HFCSX_SEL_B1_RX);
1209 reset_fifo(cs, fifo2 ? HFCSX_SEL_B2_TX : HFCSX_SEL_B1_TX);
1211 restore_flags(flags);
1214 /******************************/
1215 /* Layer2 -> Layer 1 Transfer */
1216 /******************************/
1218 hfcsx_l2l1(struct PStack *st, int pr, void *arg)
1220 struct sk_buff *skb = arg;
1224 case (PH_DATA | REQUEST):
1227 if (st->l1.bcs->tx_skb) {
1228 skb_queue_tail(&st->l1.bcs->squeue, skb);
1229 restore_flags(flags);
1231 st->l1.bcs->tx_skb = skb;
1232 /* test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
1233 */ st->l1.bcs->cs->BC_Send_Data(st->l1.bcs);
1234 restore_flags(flags);
1237 case (PH_PULL | INDICATION):
1238 if (st->l1.bcs->tx_skb) {
1239 printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
1244 /* test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
1245 */ st->l1.bcs->tx_skb = skb;
1246 st->l1.bcs->cs->BC_Send_Data(st->l1.bcs);
1247 restore_flags(flags);
1249 case (PH_PULL | REQUEST):
1250 if (!st->l1.bcs->tx_skb) {
1251 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1252 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1254 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1256 case (PH_ACTIVATE | REQUEST):
1257 test_and_set_bit(BC_FLG_ACTIV, &st->l1.bcs->Flag);
1258 mode_hfcsx(st->l1.bcs, st->l1.mode, st->l1.bc);
1259 l1_msg_b(st, pr, arg);
1261 case (PH_DEACTIVATE | REQUEST):
1262 l1_msg_b(st, pr, arg);
1264 case (PH_DEACTIVATE | CONFIRM):
1265 test_and_clear_bit(BC_FLG_ACTIV, &st->l1.bcs->Flag);
1266 test_and_clear_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
1267 mode_hfcsx(st->l1.bcs, 0, st->l1.bc);
1268 st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
1273 /******************************************/
1274 /* deactivate B-channel access and queues */
1275 /******************************************/
1277 close_hfcsx(struct BCState *bcs)
1279 mode_hfcsx(bcs, 0, bcs->channel);
1280 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
1281 skb_queue_purge(&bcs->rqueue);
1282 skb_queue_purge(&bcs->squeue);
1284 dev_kfree_skb_any(bcs->tx_skb);
1286 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
1291 /*************************************/
1292 /* init B-channel queues and control */
1293 /*************************************/
1295 open_hfcsxstate(struct IsdnCardState *cs, struct BCState *bcs)
1297 if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
1298 skb_queue_head_init(&bcs->rqueue);
1299 skb_queue_head_init(&bcs->squeue);
1302 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
1308 /*********************************/
1309 /* inits the stack for B-channel */
1310 /*********************************/
1312 setstack_2b(struct PStack *st, struct BCState *bcs)
1314 bcs->channel = st->l1.bc;
1315 if (open_hfcsxstate(st->l1.hardware, bcs))
1318 st->l2.l2l1 = hfcsx_l2l1;
1319 setstack_manager(st);
1325 /***************************/
1326 /* handle L1 state changes */
1327 /***************************/
1329 hfcsx_bh(struct IsdnCardState *cs)
1331 unsigned long flags;
1332 /* struct PStack *stptr;
1336 if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
1337 if (!cs->hw.hfcsx.nt_mode)
1338 switch (cs->dc.hfcsx.ph_state) {
1340 l1_msg(cs, HW_RESET | INDICATION, NULL);
1343 l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
1346 l1_msg(cs, HW_RSYNC | INDICATION, NULL);
1349 l1_msg(cs, HW_INFO2 | INDICATION, NULL);
1352 l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
1357 switch (cs->dc.hfcsx.ph_state) {
1361 if (cs->hw.hfcsx.nt_timer < 0) {
1362 cs->hw.hfcsx.nt_timer = 0;
1363 cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
1364 Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
1365 /* Clear already pending ints */
1366 if (Read_hfc(cs, HFCSX_INT_S1));
1368 Write_hfc(cs, HFCSX_STATES, 4 | HFCSX_LOAD_STATE);
1370 Write_hfc(cs, HFCSX_STATES, 4);
1371 cs->dc.hfcsx.ph_state = 4;
1373 cs->hw.hfcsx.int_m1 |= HFCSX_INTS_TIMER;
1374 Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
1375 cs->hw.hfcsx.ctmt &= ~HFCSX_AUTO_TIMER;
1376 cs->hw.hfcsx.ctmt |= HFCSX_TIM3_125;
1377 Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
1378 Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
1379 cs->hw.hfcsx.nt_timer = NT_T1_COUNT;
1380 Write_hfc(cs, HFCSX_STATES, 2 | HFCSX_NT_G2_G3); /* allow G2 -> G3 transition */
1382 restore_flags(flags);
1389 cs->hw.hfcsx.nt_timer = 0;
1390 cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
1391 Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
1392 restore_flags(flags);
1399 if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
1400 DChannel_proc_rcv(cs);
1401 if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
1402 DChannel_proc_xmt(cs);
1406 /********************************/
1407 /* called for card init message */
1408 /********************************/
1410 inithfcsx(struct IsdnCardState *cs)
1412 cs->setstack_d = setstack_hfcsx;
1413 cs->dbusytimer.function = (void *) hfcsx_dbusy_timer;
1414 cs->dbusytimer.data = (long) cs;
1415 init_timer(&cs->dbusytimer);
1416 cs->tqueue.routine = (void *) (void *) hfcsx_bh;
1417 cs->BC_Send_Data = &hfcsx_send_data;
1418 cs->bcs[0].BC_SetStack = setstack_2b;
1419 cs->bcs[1].BC_SetStack = setstack_2b;
1420 cs->bcs[0].BC_Close = close_hfcsx;
1421 cs->bcs[1].BC_Close = close_hfcsx;
1422 mode_hfcsx(cs->bcs, 0, 0);
1423 mode_hfcsx(cs->bcs + 1, 0, 1);
1428 /*******************************************/
1429 /* handle card messages from control layer */
1430 /*******************************************/
1432 hfcsx_card_msg(struct IsdnCardState *cs, int mt, void *arg)
1436 if (cs->debug & L1_DEB_ISAC)
1437 debugl1(cs, "HFCSX: card_msg %x", mt);
1443 release_io_hfcsx(cs);
1449 set_current_state(TASK_UNINTERRUPTIBLE);
1450 schedule_timeout((80 * HZ) / 1000); /* Timeout 80ms */
1451 /* now switch timer interrupt off */
1452 cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
1453 Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
1454 /* reinit mode reg */
1455 Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
1456 restore_flags(flags);
1465 static struct isapnp_device_id hfc_ids[] __initdata = {
1466 { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2620),
1467 ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2620),
1468 (unsigned long) "Teles 16.3c2" },
1472 static struct isapnp_device_id *hdev = &hfc_ids[0];
1473 static struct pci_bus *pnp_c __devinitdata = NULL;
1477 setup_hfcsx(struct IsdnCard *card)
1479 struct IsdnCardState *cs = card->cs;
1481 unsigned long flags;
1483 strcpy(tmp, hfcsx_revision);
1484 printk(KERN_INFO "HiSax: HFC-SX driver Rev. %s\n", HiSax_getrev(tmp));
1486 if (!card->para[1] && isapnp_present()) {
1490 while(hdev->card_vendor) {
1491 if ((pb = isapnp_find_card(hdev->card_vendor,
1492 hdev->card_device, pnp_c))) {
1495 if ((pd = isapnp_find_dev(pnp_c,
1496 hdev->vendor, hdev->function, pd))) {
1497 printk(KERN_INFO "HiSax: %s detected\n",
1498 (char *)hdev->driver_data);
1502 card->para[1] = pd->resource[0].start;
1503 card->para[0] = pd->irq_resource[0].start;
1504 if (!card->para[0] || !card->para[1]) {
1505 printk(KERN_ERR "HFC PnP:some resources are missing %ld/%lx\n",
1506 card->para[0], card->para[1]);
1512 printk(KERN_ERR "HFC PnP: PnP error card found, no device\n");
1518 if (!hdev->card_vendor) {
1519 printk(KERN_INFO "HFC PnP: no ISAPnP card found\n");
1524 cs->hw.hfcsx.base = card->para[1] & 0xfffe;
1525 cs->irq = card->para[0];
1526 cs->hw.hfcsx.int_s1 = 0;
1527 cs->dc.hfcsx.ph_state = 0;
1528 cs->hw.hfcsx.fifo = 255;
1529 if ((cs->typ == ISDN_CTYPE_HFC_SX) ||
1530 (cs->typ == ISDN_CTYPE_HFC_SP_PCMCIA)) {
1531 if ((!cs->hw.hfcsx.base) ||
1532 check_region((cs->hw.hfcsx.base), 2)) {
1534 "HiSax: HFC-SX io-base %#lx already in use\n",
1538 request_region(cs->hw.hfcsx.base, 2, "HFCSX isdn");
1540 byteout(cs->hw.hfcsx.base, cs->hw.hfcsx.base & 0xFF);
1541 byteout(cs->hw.hfcsx.base + 1,
1542 ((cs->hw.hfcsx.base >> 8) & 3) | 0x54);
1544 cs->hw.hfcsx.chip = Read_hfc(cs,HFCSX_CHIP_ID);
1545 switch (cs->hw.hfcsx.chip >> 4) {
1554 "HFC-SX: invalid chip id 0x%x\n",
1555 cs->hw.hfcsx.chip >> 4);
1556 release_region(cs->hw.hfcsx.base, 2);
1559 if (!ccd_sp_irqtab[cs->irq & 0xF]) {
1561 "HFC_SX: invalid irq %d specified\n",cs->irq & 0xF);
1562 release_region(cs->hw.hfcsx.base, 2);
1567 if (!(cs->hw.hfcsx.extra = (void *)
1568 kmalloc(sizeof(struct hfcsx_extra), GFP_ATOMIC))) {
1569 restore_flags(flags);
1570 release_region(cs->hw.hfcsx.base, 2);
1571 printk(KERN_WARNING "HFC-SX: unable to allocate memory\n");
1574 restore_flags(flags);
1577 "HFC-S%c chip detected at base 0x%x IRQ %d HZ %d\n",
1578 tmp[0], (u_int) cs->hw.hfcsx.base,
1580 cs->hw.hfcsx.int_m2 = 0; /* disable alle interrupts */
1581 cs->hw.hfcsx.int_m1 = 0;
1582 Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
1583 Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
1585 return (0); /* no valid card type */
1587 cs->readisac = NULL;
1588 cs->writeisac = NULL;
1589 cs->readisacfifo = NULL;
1590 cs->writeisacfifo = NULL;
1591 cs->BC_Read_Reg = NULL;
1592 cs->BC_Write_Reg = NULL;
1593 cs->irq_func = &hfcsx_interrupt;
1595 cs->hw.hfcsx.timer.function = (void *) hfcsx_Timer;
1596 cs->hw.hfcsx.timer.data = (long) cs;
1597 cs->hw.hfcsx.b_fifo_size = 0; /* fifo size still unknown */
1598 cs->hw.hfcsx.cirm = ccd_sp_irqtab[cs->irq & 0xF]; /* RAM not evaluated */
1599 init_timer(&cs->hw.hfcsx.timer);
1602 cs->cardmsg = &hfcsx_card_msg;
1603 cs->auxcmd = &hfcsx_auxcmd;