1 /* $Id: hfc_pci.c,v 1.1.4.1 2001/11/20 14:19:35 kai Exp $
3 * low level driver for CCD´s hfc-pci based cards
5 * Author Werner Cornelius
6 * based on existing driver for CCD hfc ISA cards
7 * Copyright by Werner Cornelius <werner@isdn4linux.de>
8 * by Karsten Keil <keil@isdn4linux.de>
10 * This software may be used and distributed according to the terms
11 * of the GNU General Public License, incorporated herein by reference.
13 * For changes and modifications please read
14 * ../../../Documentation/isdn/HiSax.cert
18 #include <linux/init.h>
19 #include <linux/config.h>
20 #define __NO_VERSION__
24 #include <linux/pci.h>
25 #include <linux/interrupt.h>
27 extern const char *CardType[];
29 static const char *hfcpci_revision = "$Revision: 1.1.4.1 $";
31 /* table entry in the PCI devices list */
39 #define NT_T1_COUNT 20 /* number of 3.125ms interrupts for G2 timeout */
40 #define CLKDEL_TE 0x0e /* CLKDEL in TE mode */
41 #define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
43 static const PCI_ENTRY id_list[] =
45 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0, "CCD/Billion/Asuscom", "2BD0"},
46 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000, "Billion", "B000"},
47 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006, "Billion", "B006"},
48 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007, "Billion", "B007"},
49 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008, "Billion", "B008"},
50 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009, "Billion", "B009"},
51 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A, "Billion", "B00A"},
52 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B, "Billion", "B00B"},
53 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C, "Billion", "B00C"},
54 {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100, "Seyeon", "B100"},
55 {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1, "Abocom/Magitek", "2BD1"},
56 {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675, "Asuscom/Askey", "675"},
57 {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT, "German telekom", "T-Concept"},
58 {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T, "German telekom", "A1T"},
59 {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575, "Motorola MC145575", "MC145575"},
60 {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0, "Zoltrix", "2BD0"},
61 {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,"Digi International", "Digi DataFire Micro V IOM2 (Europe)"},
62 {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,"Digi International", "Digi DataFire Micro V (Europe)"},
63 {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,"Digi International", "Digi DataFire Micro V IOM2 (North America)"},
64 {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,"Digi International", "Digi DataFire Micro V (North America)"},
71 /******************************************/
72 /* free hardware resources used by driver */
73 /******************************************/
75 release_io_hfcpci(struct IsdnCardState *cs)
79 printk(KERN_INFO "HiSax: release hfcpci at %p\n",
80 cs->hw.hfcpci.pci_io);
83 cs->hw.hfcpci.int_m2 = 0; /* interrupt output off ! */
84 Write_hfc(cs, HFCPCI_INT_M2, cs->hw.hfcpci.int_m2);
86 Write_hfc(cs, HFCPCI_CIRM, HFCPCI_RESET); /* Reset On */
88 set_current_state(TASK_UNINTERRUPTIBLE);
89 schedule_timeout((30 * HZ) / 1000); /* Timeout 30ms */
90 Write_hfc(cs, HFCPCI_CIRM, 0); /* Reset Off */
91 pcibios_write_config_word(cs->hw.hfcpci.pci_bus, cs->hw.hfcpci.pci_device_fn, PCI_COMMAND, 0); /* disable memory mapped ports + busmaster */
92 del_timer(&cs->hw.hfcpci.timer);
93 kfree(cs->hw.hfcpci.share_start);
94 cs->hw.hfcpci.share_start = NULL;
95 iounmap((void *)cs->hw.hfcpci.pci_io);
98 /********************************************************************************/
99 /* function called to reset the HFC PCI chip. A complete software reset of chip */
100 /* and fifos is done. */
101 /********************************************************************************/
103 reset_hfcpci(struct IsdnCardState *cs)
109 pcibios_write_config_word(cs->hw.hfcpci.pci_bus, cs->hw.hfcpci.pci_device_fn, PCI_COMMAND, PCI_ENA_MEMIO); /* enable memory mapped ports, disable busmaster */
110 cs->hw.hfcpci.int_m2 = 0; /* interrupt output off ! */
111 Write_hfc(cs, HFCPCI_INT_M2, cs->hw.hfcpci.int_m2);
113 printk(KERN_INFO "HFC_PCI: resetting card\n");
114 pcibios_write_config_word(cs->hw.hfcpci.pci_bus, cs->hw.hfcpci.pci_device_fn, PCI_COMMAND, PCI_ENA_MEMIO + PCI_ENA_MASTER); /* enable memory ports + busmaster */
115 Write_hfc(cs, HFCPCI_CIRM, HFCPCI_RESET); /* Reset On */
117 set_current_state(TASK_UNINTERRUPTIBLE);
118 schedule_timeout((30 * HZ) / 1000); /* Timeout 30ms */
119 Write_hfc(cs, HFCPCI_CIRM, 0); /* Reset Off */
120 set_current_state(TASK_UNINTERRUPTIBLE);
121 schedule_timeout((20 * HZ) / 1000); /* Timeout 20ms */
122 if (Read_hfc(cs, HFCPCI_STATUS) & 2)
123 printk(KERN_WARNING "HFC-PCI init bit busy\n");
125 cs->hw.hfcpci.fifo_en = 0x30; /* only D fifos enabled */
126 Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
128 cs->hw.hfcpci.trm = 0 + HFCPCI_BTRANS_THRESMASK; /* no echo connect , threshold */
129 Write_hfc(cs, HFCPCI_TRM, cs->hw.hfcpci.trm);
131 Write_hfc(cs, HFCPCI_CLKDEL, CLKDEL_TE); /* ST-Bit delay for TE-Mode */
132 cs->hw.hfcpci.sctrl_e = HFCPCI_AUTO_AWAKE;
133 Write_hfc(cs, HFCPCI_SCTRL_E, cs->hw.hfcpci.sctrl_e); /* S/T Auto awake */
134 cs->hw.hfcpci.bswapped = 0; /* no exchange */
135 cs->hw.hfcpci.nt_mode = 0; /* we are in TE mode */
136 cs->hw.hfcpci.ctmt = HFCPCI_TIM3_125 | HFCPCI_AUTO_TIMER;
137 Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt);
139 cs->hw.hfcpci.int_m1 = HFCPCI_INTS_DTRANS | HFCPCI_INTS_DREC |
140 HFCPCI_INTS_L1STATE | HFCPCI_INTS_TIMER;
141 Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
143 /* Clear already pending ints */
144 if (Read_hfc(cs, HFCPCI_INT_S1));
146 Write_hfc(cs, HFCPCI_STATES, HFCPCI_LOAD_STATE | 2); /* HFC ST 2 */
148 Write_hfc(cs, HFCPCI_STATES, 2); /* HFC ST 2 */
149 cs->hw.hfcpci.mst_m = HFCPCI_MASTER; /* HFC Master Mode */
151 Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
152 cs->hw.hfcpci.sctrl = 0x40; /* set tx_lo mode, error in datasheet ! */
153 Write_hfc(cs, HFCPCI_SCTRL, cs->hw.hfcpci.sctrl);
154 cs->hw.hfcpci.sctrl_r = 0;
155 Write_hfc(cs, HFCPCI_SCTRL_R, cs->hw.hfcpci.sctrl_r);
157 /* Init GCI/IOM2 in master mode */
158 /* Slots 0 and 1 are set for B-chan 1 and 2 */
159 /* D- and monitor/CI channel are not enabled */
160 /* STIO1 is used as output for data, B1+B2 from ST->IOM+HFC */
161 /* STIO2 is used as data input, B1+B2 from IOM->ST */
162 /* ST B-channel send disabled -> continous 1s */
163 /* The IOM slots are always enabled */
164 cs->hw.hfcpci.conn = 0x36; /* set data flow directions */
165 Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
166 Write_hfc(cs, HFCPCI_B1_SSL, 0x80); /* B1-Slot 0 STIO1 out enabled */
167 Write_hfc(cs, HFCPCI_B2_SSL, 0x81); /* B2-Slot 1 STIO1 out enabled */
168 Write_hfc(cs, HFCPCI_B1_RSL, 0x80); /* B1-Slot 0 STIO2 in enabled */
169 Write_hfc(cs, HFCPCI_B2_RSL, 0x81); /* B2-Slot 1 STIO2 in enabled */
171 /* Finally enable IRQ output */
172 cs->hw.hfcpci.int_m2 = HFCPCI_IRQ_ENABLE;
173 Write_hfc(cs, HFCPCI_INT_M2, cs->hw.hfcpci.int_m2);
174 if (Read_hfc(cs, HFCPCI_INT_S2));
175 restore_flags(flags);
178 /***************************************************/
179 /* Timer function called when kernel timer expires */
180 /***************************************************/
182 hfcpci_Timer(struct IsdnCardState *cs)
184 cs->hw.hfcpci.timer.expires = jiffies + 75;
186 /* WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcpci.ctmt | 0x80);
187 add_timer(&cs->hw.hfcpci.timer);
192 /*********************************/
193 /* schedule a new D-channel task */
194 /*********************************/
196 sched_event_D_pci(struct IsdnCardState *cs, int event)
198 test_and_set_bit(event, &cs->event);
199 queue_task(&cs->tqueue, &tq_immediate);
200 mark_bh(IMMEDIATE_BH);
203 /*********************************/
204 /* schedule a new b_channel task */
205 /*********************************/
207 hfcpci_sched_event(struct BCState *bcs, int event)
209 bcs->event |= 1 << event;
210 queue_task(&bcs->tqueue, &tq_immediate);
211 mark_bh(IMMEDIATE_BH);
214 /************************************************/
215 /* select a b-channel entry matching and active */
216 /************************************************/
219 Sel_BCS(struct IsdnCardState *cs, int channel)
221 if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
222 return (&cs->bcs[0]);
223 else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
224 return (&cs->bcs[1]);
229 /***************************************/
230 /* clear the desired B-channel rx fifo */
231 /***************************************/
232 static void hfcpci_clear_fifo_rx(struct IsdnCardState *cs, int fifo)
237 bzr = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b2;
238 fifo_state = cs->hw.hfcpci.fifo_en & HFCPCI_FIFOEN_B2RX;
240 bzr = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b1;
241 fifo_state = cs->hw.hfcpci.fifo_en & HFCPCI_FIFOEN_B1RX;
244 cs->hw.hfcpci.fifo_en ^= fifo_state;
245 Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
246 cs->hw.hfcpci.last_bfifo_cnt[fifo] = 0;
247 bzr->za[MAX_B_FRAMES].z1 = B_FIFO_SIZE + B_SUB_VAL - 1;
248 bzr->za[MAX_B_FRAMES].z2 = bzr->za[MAX_B_FRAMES].z1;
249 bzr->f1 = MAX_B_FRAMES;
250 bzr->f2 = bzr->f1; /* init F pointers to remain constant */
252 cs->hw.hfcpci.fifo_en |= fifo_state;
253 Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
256 /***************************************/
257 /* clear the desired B-channel tx fifo */
258 /***************************************/
259 static void hfcpci_clear_fifo_tx(struct IsdnCardState *cs, int fifo)
264 bzt = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txbz_b2;
265 fifo_state = cs->hw.hfcpci.fifo_en & HFCPCI_FIFOEN_B2TX;
267 bzt = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txbz_b1;
268 fifo_state = cs->hw.hfcpci.fifo_en & HFCPCI_FIFOEN_B1TX;
271 cs->hw.hfcpci.fifo_en ^= fifo_state;
272 Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
273 bzt->za[MAX_B_FRAMES].z1 = B_FIFO_SIZE + B_SUB_VAL - 1;
274 bzt->za[MAX_B_FRAMES].z2 = bzt->za[MAX_B_FRAMES].z1;
275 bzt->f1 = MAX_B_FRAMES;
276 bzt->f2 = bzt->f1; /* init F pointers to remain constant */
278 cs->hw.hfcpci.fifo_en |= fifo_state;
279 Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
282 /*********************************************/
283 /* read a complete B-frame out of the buffer */
284 /*********************************************/
285 static struct sk_buff
287 hfcpci_empty_fifo(struct BCState *bcs, bzfifo_type * bz, u_char * bdata, int count)
289 u_char *ptr, *ptr1, new_f2;
291 struct IsdnCardState *cs = bcs->cs;
293 int total, maxlen, new_z2;
298 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
299 debugl1(cs, "hfcpci_empty_fifo");
300 zp = &bz->za[bz->f2]; /* point to Z-Regs */
301 new_z2 = zp->z2 + count; /* new position in fifo */
302 if (new_z2 >= (B_FIFO_SIZE + B_SUB_VAL))
303 new_z2 -= B_FIFO_SIZE; /* buffer wrap */
304 new_f2 = (bz->f2 + 1) & MAX_B_FRAMES;
305 if ((count > HSCX_BUFMAX + 3) || (count < 4) ||
306 (*(bdata + (zp->z1 - B_SUB_VAL)))) {
307 if (cs->debug & L1_DEB_WARN)
308 debugl1(cs, "hfcpci_empty_fifo: incoming packet invalid length %d or crc", count);
309 #ifdef ERROR_STATISTIC
312 bz->za[new_f2].z2 = new_z2;
313 bz->f2 = new_f2; /* next buffer */
315 } else if (!(skb = dev_alloc_skb(count - 3)))
316 printk(KERN_WARNING "HFCPCI: receive out of memory\n");
320 ptr = skb_put(skb, count);
322 if (zp->z2 + count <= B_FIFO_SIZE + B_SUB_VAL)
323 maxlen = count; /* complete transfer */
325 maxlen = B_FIFO_SIZE + B_SUB_VAL - zp->z2; /* maximum */
327 ptr1 = bdata + (zp->z2 - B_SUB_VAL); /* start of data */
328 memcpy(ptr, ptr1, maxlen); /* copy data */
331 if (count) { /* rest remaining */
333 ptr1 = bdata; /* start of buffer */
334 memcpy(ptr, ptr1, count); /* rest */
336 bz->za[new_f2].z2 = new_z2;
337 bz->f2 = new_f2; /* next buffer */
340 restore_flags(flags);
344 /*******************************/
345 /* D-channel receive procedure */
346 /*******************************/
349 receive_dmsg(struct IsdnCardState *cs)
359 df = &((fifo_area *) (cs->hw.hfcpci.fifos))->d_chan.d_rx;
360 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
361 debugl1(cs, "rec_dmsg blocked");
364 while (((df->f1 & D_FREG_MASK) != (df->f2 & D_FREG_MASK)) && count--) {
365 zp = &df->za[df->f2 & D_FREG_MASK];
366 rcnt = zp->z1 - zp->z2;
370 if (cs->debug & L1_DEB_ISAC)
371 debugl1(cs, "hfcpci recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)",
372 df->f1, df->f2, zp->z1, zp->z2, rcnt);
374 if ((rcnt > MAX_DFRAME_LEN + 3) || (rcnt < 4) ||
375 (df->data[zp->z1])) {
376 if (cs->debug & L1_DEB_WARN)
377 debugl1(cs, "empty_fifo hfcpci paket inv. len %d or crc %d", rcnt, df->data[zp->z1]);
378 #ifdef ERROR_STATISTIC
381 df->f2 = ((df->f2 + 1) & MAX_D_FRAMES) | (MAX_D_FRAMES + 1); /* next buffer */
382 df->za[df->f2 & D_FREG_MASK].z2 = (zp->z2 + rcnt) & (D_FIFO_SIZE - 1);
383 } else if ((skb = dev_alloc_skb(rcnt - 3))) {
386 ptr = skb_put(skb, rcnt);
388 if (zp->z2 + rcnt <= D_FIFO_SIZE)
389 maxlen = rcnt; /* complete transfer */
391 maxlen = D_FIFO_SIZE - zp->z2; /* maximum */
393 ptr1 = df->data + zp->z2; /* start of data */
394 memcpy(ptr, ptr1, maxlen); /* copy data */
397 if (rcnt) { /* rest remaining */
399 ptr1 = df->data; /* start of buffer */
400 memcpy(ptr, ptr1, rcnt); /* rest */
402 df->f2 = ((df->f2 + 1) & MAX_D_FRAMES) | (MAX_D_FRAMES + 1); /* next buffer */
403 df->za[df->f2 & D_FREG_MASK].z2 = (zp->z2 + total) & (D_FIFO_SIZE - 1);
405 skb_queue_tail(&cs->rq, skb);
406 sched_event_D_pci(cs, D_RCVBUFREADY);
408 printk(KERN_WARNING "HFC-PCI: D receive out of memory\n");
410 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
414 /*******************************************************************************/
415 /* check for transparent receive data and read max one threshold size if avail */
416 /*******************************************************************************/
418 hfcpci_empty_fifo_trans(struct BCState *bcs, bzfifo_type * bz, u_char * bdata)
420 unsigned short *z1r, *z2r;
421 int new_z2, fcnt, maxlen;
425 z1r = &bz->za[MAX_B_FRAMES].z1; /* pointer to z reg */
428 if (!(fcnt = *z1r - *z2r))
429 return (0); /* no data avail */
432 fcnt += B_FIFO_SIZE; /* bytes actually buffered */
433 if (fcnt > HFCPCI_BTRANS_THRESHOLD)
434 fcnt = HFCPCI_BTRANS_THRESHOLD; /* limit size */
436 new_z2 = *z2r + fcnt; /* new position in fifo */
437 if (new_z2 >= (B_FIFO_SIZE + B_SUB_VAL))
438 new_z2 -= B_FIFO_SIZE; /* buffer wrap */
440 if (!(skb = dev_alloc_skb(fcnt)))
441 printk(KERN_WARNING "HFCPCI: receive out of memory\n");
443 ptr = skb_put(skb, fcnt);
444 if (*z2r + fcnt <= B_FIFO_SIZE + B_SUB_VAL)
445 maxlen = fcnt; /* complete transfer */
447 maxlen = B_FIFO_SIZE + B_SUB_VAL - *z2r; /* maximum */
449 ptr1 = bdata + (*z2r - B_SUB_VAL); /* start of data */
450 memcpy(ptr, ptr1, maxlen); /* copy data */
453 if (fcnt) { /* rest remaining */
455 ptr1 = bdata; /* start of buffer */
456 memcpy(ptr, ptr1, fcnt); /* rest */
459 skb_queue_tail(&bcs->rqueue, skb);
461 hfcpci_sched_event(bcs, B_RCVBUFREADY);
464 *z2r = new_z2; /* new position */
466 } /* hfcpci_empty_fifo_trans */
468 /**********************************/
469 /* B-channel main receive routine */
470 /**********************************/
472 main_rec_hfcpci(struct BCState *bcs)
475 struct IsdnCardState *cs = bcs->cs;
477 int receive, count = 5;
485 if ((bcs->channel) && (!cs->hw.hfcpci.bswapped)) {
486 bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b2;
487 bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxdat_b2;
490 bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b1;
491 bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxdat_b1;
497 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
498 debugl1(cs, "rec_data %d blocked", bcs->channel);
499 restore_flags(flags);
503 if (bz->f1 != bz->f2) {
504 if (cs->debug & L1_DEB_HSCX)
505 debugl1(cs, "hfcpci rec %d f1(%d) f2(%d)",
506 bcs->channel, bz->f1, bz->f2);
507 zp = &bz->za[bz->f2];
509 rcnt = zp->z1 - zp->z2;
513 if (cs->debug & L1_DEB_HSCX)
514 debugl1(cs, "hfcpci rec %d z1(%x) z2(%x) cnt(%d)",
515 bcs->channel, zp->z1, zp->z2, rcnt);
516 if ((skb = hfcpci_empty_fifo(bcs, bz, bdata, rcnt))) {
518 skb_queue_tail(&bcs->rqueue, skb);
520 hfcpci_sched_event(bcs, B_RCVBUFREADY);
522 rcnt = bz->f1 - bz->f2;
524 rcnt += MAX_B_FRAMES + 1;
525 if (cs->hw.hfcpci.last_bfifo_cnt[real_fifo] > rcnt + 1) {
527 hfcpci_clear_fifo_rx(cs, real_fifo);
529 cs->hw.hfcpci.last_bfifo_cnt[real_fifo] = rcnt;
534 } else if (bcs->mode == L1_MODE_TRANS)
535 receive = hfcpci_empty_fifo_trans(bcs, bz, bdata);
538 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
539 if (count && receive)
541 restore_flags(flags);
545 /**************************/
546 /* D-channel send routine */
547 /**************************/
549 hfcpci_fill_dfifo(struct IsdnCardState *cs)
553 int count, new_z1, maxlen;
555 u_char *src, *dst, new_f1;
559 if (cs->tx_skb->len <= 0)
562 df = &((fifo_area *) (cs->hw.hfcpci.fifos))->d_chan.d_tx;
564 if (cs->debug & L1_DEB_ISAC)
565 debugl1(cs, "hfcpci_fill_Dfifo f1(%d) f2(%d) z1(f1)(%x)",
567 df->za[df->f1 & D_FREG_MASK].z1);
568 fcnt = df->f1 - df->f2; /* frame count actually buffered */
570 fcnt += (MAX_D_FRAMES + 1); /* if wrap around */
571 if (fcnt > (MAX_D_FRAMES - 1)) {
572 if (cs->debug & L1_DEB_ISAC)
573 debugl1(cs, "hfcpci_fill_Dfifo more as 14 frames");
574 #ifdef ERROR_STATISTIC
579 /* now determine free bytes in FIFO buffer */
580 count = df->za[df->f1 & D_FREG_MASK].z2 - df->za[df->f1 & D_FREG_MASK].z1;
582 count += D_FIFO_SIZE; /* count now contains available bytes */
584 if (cs->debug & L1_DEB_ISAC)
585 debugl1(cs, "hfcpci_fill_Dfifo count(%ld/%d)",
586 cs->tx_skb->len, count);
587 if (count < cs->tx_skb->len) {
588 if (cs->debug & L1_DEB_ISAC)
589 debugl1(cs, "hfcpci_fill_Dfifo no fifo mem");
592 count = cs->tx_skb->len; /* get frame len */
593 new_z1 = (df->za[df->f1 & D_FREG_MASK].z1 + count) & (D_FIFO_SIZE - 1);
594 new_f1 = ((df->f1 + 1) & D_FREG_MASK) | (D_FREG_MASK + 1);
595 src = cs->tx_skb->data; /* source pointer */
596 dst = df->data + df->za[df->f1 & D_FREG_MASK].z1;
597 maxlen = D_FIFO_SIZE - df->za[df->f1 & D_FREG_MASK].z1; /* end fifo */
599 maxlen = count; /* limit size */
600 memcpy(dst, src, maxlen); /* first copy */
602 count -= maxlen; /* remaining bytes */
604 dst = df->data; /* start of buffer */
605 src += maxlen; /* new position */
606 memcpy(dst, src, count);
610 df->za[new_f1 & D_FREG_MASK].z1 = new_z1; /* for next buffer */
611 df->za[df->f1 & D_FREG_MASK].z1 = new_z1; /* new pos actual buffer */
612 df->f1 = new_f1; /* next frame */
613 restore_flags(flags);
615 dev_kfree_skb_any(cs->tx_skb);
620 /**************************/
621 /* B-channel send routine */
622 /**************************/
624 hfcpci_fill_fifo(struct BCState *bcs)
626 struct IsdnCardState *cs = bcs->cs;
632 u_char new_f1, *src, *dst;
633 unsigned short *z1t, *z2t;
637 if (bcs->tx_skb->len <= 0)
643 if ((bcs->channel) && (!cs->hw.hfcpci.bswapped)) {
644 bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txbz_b2;
645 bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txdat_b2;
647 bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txbz_b1;
648 bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txdat_b1;
651 if (bcs->mode == L1_MODE_TRANS) {
652 z1t = &bz->za[MAX_B_FRAMES].z1;
654 if (cs->debug & L1_DEB_HSCX)
655 debugl1(cs, "hfcpci_fill_fifo_trans %d z1(%x) z2(%x)",
656 bcs->channel, *z1t, *z2t);
659 fcnt += B_FIFO_SIZE; /* fcnt contains available bytes in fifo */
660 fcnt = B_FIFO_SIZE - fcnt; /* remaining bytes to send */
662 while ((fcnt < 2 * HFCPCI_BTRANS_THRESHOLD) && (bcs->tx_skb)) {
663 if (bcs->tx_skb->len < B_FIFO_SIZE - fcnt) {
664 /* data is suitable for fifo */
665 count = bcs->tx_skb->len;
667 new_z1 = *z1t + count; /* new buffer Position */
668 if (new_z1 >= (B_FIFO_SIZE + B_SUB_VAL))
669 new_z1 -= B_FIFO_SIZE; /* buffer wrap */
670 src = bcs->tx_skb->data; /* source pointer */
671 dst = bdata + (*z1t - B_SUB_VAL);
672 maxlen = (B_FIFO_SIZE + B_SUB_VAL) - *z1t; /* end of fifo */
674 maxlen = count; /* limit size */
675 memcpy(dst, src, maxlen); /* first copy */
677 count -= maxlen; /* remaining bytes */
679 dst = bdata; /* start of buffer */
680 src += maxlen; /* new position */
681 memcpy(dst, src, count);
683 bcs->tx_cnt -= bcs->tx_skb->len;
684 fcnt += bcs->tx_skb->len;
685 *z1t = new_z1; /* now send data */
686 } else if (cs->debug & L1_DEB_HSCX)
687 debugl1(cs, "hfcpci_fill_fifo_trans %d frame length %d discarded",
688 bcs->channel, bcs->tx_skb->len);
690 if (bcs->st->lli.l1writewakeup &&
691 (PACKET_NOACK != bcs->tx_skb->pkt_type))
692 bcs->st->lli.l1writewakeup(bcs->st, bcs->tx_skb->len);
694 dev_kfree_skb_any(bcs->tx_skb);
696 bcs->tx_skb = skb_dequeue(&bcs->squeue); /* fetch next data */
699 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
700 restore_flags(flags);
703 if (cs->debug & L1_DEB_HSCX)
704 debugl1(cs, "hfcpci_fill_fifo_hdlc %d f1(%d) f2(%d) z1(f1)(%x)",
705 bcs->channel, bz->f1, bz->f2,
708 fcnt = bz->f1 - bz->f2; /* frame count actually buffered */
710 fcnt += (MAX_B_FRAMES + 1); /* if wrap around */
711 if (fcnt > (MAX_B_FRAMES - 1)) {
712 if (cs->debug & L1_DEB_HSCX)
713 debugl1(cs, "hfcpci_fill_Bfifo more as 14 frames");
714 restore_flags(flags);
717 /* now determine free bytes in FIFO buffer */
718 count = bz->za[bz->f1].z2 - bz->za[bz->f1].z1;
720 count += B_FIFO_SIZE; /* count now contains available bytes */
722 if (cs->debug & L1_DEB_HSCX)
723 debugl1(cs, "hfcpci_fill_fifo %d count(%ld/%d),%lx",
724 bcs->channel, bcs->tx_skb->len,
725 count, current->state);
727 if (count < bcs->tx_skb->len) {
728 if (cs->debug & L1_DEB_HSCX)
729 debugl1(cs, "hfcpci_fill_fifo no fifo mem");
730 restore_flags(flags);
733 count = bcs->tx_skb->len; /* get frame len */
734 new_z1 = bz->za[bz->f1].z1 + count; /* new buffer Position */
735 if (new_z1 >= (B_FIFO_SIZE + B_SUB_VAL))
736 new_z1 -= B_FIFO_SIZE; /* buffer wrap */
738 new_f1 = ((bz->f1 + 1) & MAX_B_FRAMES);
739 src = bcs->tx_skb->data; /* source pointer */
740 dst = bdata + (bz->za[bz->f1].z1 - B_SUB_VAL);
741 maxlen = (B_FIFO_SIZE + B_SUB_VAL) - bz->za[bz->f1].z1; /* end fifo */
743 maxlen = count; /* limit size */
744 memcpy(dst, src, maxlen); /* first copy */
746 count -= maxlen; /* remaining bytes */
748 dst = bdata; /* start of buffer */
749 src += maxlen; /* new position */
750 memcpy(dst, src, count);
752 bcs->tx_cnt -= bcs->tx_skb->len;
753 if (bcs->st->lli.l1writewakeup &&
754 (PACKET_NOACK != bcs->tx_skb->pkt_type))
755 bcs->st->lli.l1writewakeup(bcs->st, bcs->tx_skb->len);
758 bz->za[new_f1].z1 = new_z1; /* for next buffer */
759 bz->f1 = new_f1; /* next frame */
760 restore_flags(flags);
762 dev_kfree_skb_any(bcs->tx_skb);
764 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
768 /**********************************************/
769 /* D-channel l1 state call for leased NT-mode */
770 /**********************************************/
772 dch_nt_l2l1(struct PStack *st, int pr, void *arg)
774 struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
777 case (PH_DATA | REQUEST):
778 case (PH_PULL | REQUEST):
779 case (PH_PULL | INDICATION):
780 st->l1.l1hw(st, pr, arg);
782 case (PH_ACTIVATE | REQUEST):
783 st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
785 case (PH_TESTLOOP | REQUEST):
787 debugl1(cs, "PH_TEST_LOOP B1");
789 debugl1(cs, "PH_TEST_LOOP B2");
790 if (!(3 & (long) arg))
791 debugl1(cs, "PH_TEST_LOOP DISABLED");
792 st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
796 debugl1(cs, "dch_nt_l2l1 msg %04X unhandled", pr);
803 /***********************/
804 /* set/reset echo mode */
805 /***********************/
807 hfcpci_auxcmd(struct IsdnCardState *cs, isdn_ctrl * ic)
810 int i = *(unsigned int *) ic->parm.num;
812 if ((ic->arg == 98) &&
813 (!(cs->hw.hfcpci.int_m1 & (HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC + HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC)))) {
816 Write_hfc(cs, HFCPCI_CLKDEL, CLKDEL_NT); /* ST-Bit delay for NT-Mode */
817 Write_hfc(cs, HFCPCI_STATES, HFCPCI_LOAD_STATE | 0); /* HFC ST G0 */
819 cs->hw.hfcpci.sctrl |= SCTRL_MODE_NT;
820 Write_hfc(cs, HFCPCI_SCTRL, cs->hw.hfcpci.sctrl); /* set NT-mode */
822 Write_hfc(cs, HFCPCI_STATES, HFCPCI_LOAD_STATE | 1); /* HFC ST G1 */
824 Write_hfc(cs, HFCPCI_STATES, 1 | HFCPCI_ACTIVATE | HFCPCI_DO_ACTION);
825 cs->dc.hfcpci.ph_state = 1;
826 cs->hw.hfcpci.nt_mode = 1;
827 cs->hw.hfcpci.nt_timer = 0;
828 cs->stlist->l2.l2l1 = dch_nt_l2l1;
829 restore_flags(flags);
830 debugl1(cs, "NT mode activated");
833 if ((cs->chanlimit > 1) || (cs->hw.hfcpci.bswapped) ||
834 (cs->hw.hfcpci.nt_mode) || (ic->arg != 12))
841 cs->hw.hfcpci.trm |= 0x20; /* enable echo chan */
842 cs->hw.hfcpci.int_m1 |= HFCPCI_INTS_B2REC;
843 cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B2RX;
846 cs->hw.hfcpci.trm &= ~0x20; /* disable echo chan */
847 cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_B2REC;
848 cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B2RX;
850 cs->hw.hfcpci.sctrl_r &= ~SCTRL_B2_ENA;
851 cs->hw.hfcpci.sctrl &= ~SCTRL_B2_ENA;
852 cs->hw.hfcpci.conn |= 0x10; /* B2-IOM -> B2-ST */
853 cs->hw.hfcpci.ctmt &= ~2;
854 Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt);
855 Write_hfc(cs, HFCPCI_SCTRL_R, cs->hw.hfcpci.sctrl_r);
856 Write_hfc(cs, HFCPCI_SCTRL, cs->hw.hfcpci.sctrl);
857 Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
858 Write_hfc(cs, HFCPCI_TRM, cs->hw.hfcpci.trm);
859 Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
860 Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
861 restore_flags(flags);
863 } /* hfcpci_auxcmd */
865 /*****************************/
866 /* E-channel receive routine */
867 /*****************************/
869 receive_emsg(struct IsdnCardState *cs)
873 int receive, count = 5;
877 u_char *ptr, *ptr1, new_f2;
878 int total, maxlen, new_z2;
879 u_char e_buffer[256];
882 bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b2;
883 bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxdat_b2;
887 if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
888 debugl1(cs, "echo_rec_data blocked");
889 restore_flags(flags);
893 if (bz->f1 != bz->f2) {
894 if (cs->debug & L1_DEB_ISAC)
895 debugl1(cs, "hfcpci e_rec f1(%d) f2(%d)",
897 zp = &bz->za[bz->f2];
899 rcnt = zp->z1 - zp->z2;
903 if (cs->debug & L1_DEB_ISAC)
904 debugl1(cs, "hfcpci e_rec z1(%x) z2(%x) cnt(%d)",
905 zp->z1, zp->z2, rcnt);
906 new_z2 = zp->z2 + rcnt; /* new position in fifo */
907 if (new_z2 >= (B_FIFO_SIZE + B_SUB_VAL))
908 new_z2 -= B_FIFO_SIZE; /* buffer wrap */
909 new_f2 = (bz->f2 + 1) & MAX_B_FRAMES;
910 if ((rcnt > 256 + 3) || (count < 4) ||
911 (*(bdata + (zp->z1 - B_SUB_VAL)))) {
912 if (cs->debug & L1_DEB_WARN)
913 debugl1(cs, "hfcpci_empty_echan: incoming packet invalid length %d or crc", rcnt);
914 bz->za[new_f2].z2 = new_z2;
915 bz->f2 = new_f2; /* next buffer */
921 if (zp->z2 <= B_FIFO_SIZE + B_SUB_VAL)
922 maxlen = rcnt; /* complete transfer */
924 maxlen = B_FIFO_SIZE + B_SUB_VAL - zp->z2; /* maximum */
926 ptr1 = bdata + (zp->z2 - B_SUB_VAL); /* start of data */
927 memcpy(ptr, ptr1, maxlen); /* copy data */
930 if (rcnt) { /* rest remaining */
932 ptr1 = bdata; /* start of buffer */
933 memcpy(ptr, ptr1, rcnt); /* rest */
935 bz->za[new_f2].z2 = new_z2;
936 bz->f2 = new_f2; /* next buffer */
937 if (cs->debug & DEB_DLOG_HEX) {
939 if ((total - 3) < MAX_DLOG_SPACE / 3 - 10) {
945 ptr += QuickHex(ptr, e_buffer, total - 3);
949 HiSax_putstatus(cs, NULL, cs->dlog);
951 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
955 rcnt = bz->f1 - bz->f2;
957 rcnt += MAX_B_FRAMES + 1;
964 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
965 if (count && receive)
967 restore_flags(flags);
971 /*********************/
972 /* Interrupt handler */
973 /*********************/
975 hfcpci_interrupt(int intno, void *dev_id, struct pt_regs *regs)
977 struct IsdnCardState *cs = dev_id;
985 printk(KERN_WARNING "HFC-PCI: Spurious interrupt!\n");
988 if (!(cs->hw.hfcpci.int_m2 & 0x08))
989 return; /* not initialised */
991 if (HFCPCI_ANYINT & (stat = Read_hfc(cs, HFCPCI_STATUS))) {
992 val = Read_hfc(cs, HFCPCI_INT_S1);
993 if (cs->debug & L1_DEB_ISAC)
994 debugl1(cs, "HFC-PCI: stat(%02x) s1(%02x)", stat, val);
998 if (cs->debug & L1_DEB_ISAC)
999 debugl1(cs, "HFC-PCI irq %x %s", val,
1000 test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
1001 "locked" : "unlocked");
1002 val &= cs->hw.hfcpci.int_m1;
1003 if (val & 0x40) { /* state machine irq */
1004 exval = Read_hfc(cs, HFCPCI_STATES) & 0xf;
1005 if (cs->debug & L1_DEB_ISAC)
1006 debugl1(cs, "ph_state chg %d->%d", cs->dc.hfcpci.ph_state,
1008 cs->dc.hfcpci.ph_state = exval;
1009 sched_event_D_pci(cs, D_L1STATECHANGE);
1012 if (val & 0x80) { /* timer irq */
1013 if (cs->hw.hfcpci.nt_mode) {
1014 if ((--cs->hw.hfcpci.nt_timer) < 0)
1015 sched_event_D_pci(cs, D_L1STATECHANGE);
1018 Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt | HFCPCI_CLTIMER);
1023 if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1024 cs->hw.hfcpci.int_s1 |= val;
1025 restore_flags(flags);
1028 if (cs->hw.hfcpci.int_s1 & 0x18) {
1030 val = cs->hw.hfcpci.int_s1;
1031 cs->hw.hfcpci.int_s1 = exval;
1034 if (!(bcs = Sel_BCS(cs, cs->hw.hfcpci.bswapped ? 1 : 0))) {
1036 debugl1(cs, "hfcpci spurious 0x08 IRQ");
1038 main_rec_hfcpci(bcs);
1043 else if (!(bcs = Sel_BCS(cs, 1))) {
1045 debugl1(cs, "hfcpci spurious 0x10 IRQ");
1047 main_rec_hfcpci(bcs);
1050 if (!(bcs = Sel_BCS(cs, cs->hw.hfcpci.bswapped ? 1 : 0))) {
1052 debugl1(cs, "hfcpci spurious 0x01 IRQ");
1055 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1056 hfcpci_fill_fifo(bcs);
1057 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1059 debugl1(cs, "fill_data %d blocked", bcs->channel);
1061 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
1062 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1063 hfcpci_fill_fifo(bcs);
1064 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1066 debugl1(cs, "fill_data %d blocked", bcs->channel);
1068 hfcpci_sched_event(bcs, B_XMTBUFREADY);
1074 if (!(bcs = Sel_BCS(cs, 1))) {
1076 debugl1(cs, "hfcpci spurious 0x02 IRQ");
1079 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1080 hfcpci_fill_fifo(bcs);
1081 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1083 debugl1(cs, "fill_data %d blocked", bcs->channel);
1085 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
1086 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1087 hfcpci_fill_fifo(bcs);
1088 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1090 debugl1(cs, "fill_data %d blocked", bcs->channel);
1092 hfcpci_sched_event(bcs, B_XMTBUFREADY);
1097 if (val & 0x20) { /* receive dframe */
1100 if (val & 0x04) { /* dframe transmitted */
1101 if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
1102 del_timer(&cs->dbusytimer);
1103 if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
1104 sched_event_D_pci(cs, D_CLEARBUSY);
1106 if (cs->tx_skb->len) {
1107 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1108 hfcpci_fill_dfifo(cs);
1109 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1111 debugl1(cs, "hfcpci_fill_dfifo irq blocked");
1115 dev_kfree_skb_irq(cs->tx_skb);
1120 if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
1122 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1123 hfcpci_fill_dfifo(cs);
1124 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1126 debugl1(cs, "hfcpci_fill_dfifo irq blocked");
1129 sched_event_D_pci(cs, D_XMTBUFREADY);
1132 if (cs->hw.hfcpci.int_s1 && count--) {
1133 val = cs->hw.hfcpci.int_s1;
1134 cs->hw.hfcpci.int_s1 = 0;
1135 if (cs->debug & L1_DEB_ISAC)
1136 debugl1(cs, "HFC-PCI irq %x loop %d", val, 15 - count);
1139 restore_flags(flags);
1143 /********************************************************************/
1144 /* timer callback for D-chan busy resolution. Currently no function */
1145 /********************************************************************/
1147 hfcpci_dbusy_timer(struct IsdnCardState *cs)
1151 /*************************************/
1152 /* Layer 1 D-channel hardware access */
1153 /*************************************/
1155 HFCPCI_l1hw(struct PStack *st, int pr, void *arg)
1157 struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
1158 struct sk_buff *skb = arg;
1159 unsigned long flags;
1162 case (PH_DATA | REQUEST):
1163 if (cs->debug & DEB_DLOG_HEX)
1164 LogFrame(cs, skb->data, skb->len);
1165 if (cs->debug & DEB_DLOG_VERBOSE)
1166 dlogframe(cs, skb, 0);
1168 skb_queue_tail(&cs->sq, skb);
1169 #ifdef L2FRAME_DEBUG /* psa */
1170 if (cs->debug & L1_DEB_LAPD)
1171 Logl2Frame(cs, skb, "PH_DATA Queued", 0);
1176 #ifdef L2FRAME_DEBUG /* psa */
1177 if (cs->debug & L1_DEB_LAPD)
1178 Logl2Frame(cs, skb, "PH_DATA", 0);
1180 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1181 hfcpci_fill_dfifo(cs);
1182 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1184 debugl1(cs, "hfcpci_fill_dfifo blocked");
1188 case (PH_PULL | INDICATION):
1190 if (cs->debug & L1_DEB_WARN)
1191 debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
1192 skb_queue_tail(&cs->sq, skb);
1195 if (cs->debug & DEB_DLOG_HEX)
1196 LogFrame(cs, skb->data, skb->len);
1197 if (cs->debug & DEB_DLOG_VERBOSE)
1198 dlogframe(cs, skb, 0);
1201 #ifdef L2FRAME_DEBUG /* psa */
1202 if (cs->debug & L1_DEB_LAPD)
1203 Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
1205 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1206 hfcpci_fill_dfifo(cs);
1207 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1209 debugl1(cs, "hfcpci_fill_dfifo blocked");
1211 case (PH_PULL | REQUEST):
1212 #ifdef L2FRAME_DEBUG /* psa */
1213 if (cs->debug & L1_DEB_LAPD)
1214 debugl1(cs, "-> PH_REQUEST_PULL");
1217 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1218 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1220 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1222 case (HW_RESET | REQUEST):
1223 Write_hfc(cs, HFCPCI_STATES, HFCPCI_LOAD_STATE | 3); /* HFC ST 3 */
1225 Write_hfc(cs, HFCPCI_STATES, 3); /* HFC ST 2 */
1226 cs->hw.hfcpci.mst_m |= HFCPCI_MASTER;
1227 Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
1228 Write_hfc(cs, HFCPCI_STATES, HFCPCI_ACTIVATE | HFCPCI_DO_ACTION);
1229 l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
1231 case (HW_ENABLE | REQUEST):
1232 Write_hfc(cs, HFCPCI_STATES, HFCPCI_DO_ACTION);
1234 case (HW_DEACTIVATE | REQUEST):
1235 cs->hw.hfcpci.mst_m &= ~HFCPCI_MASTER;
1236 Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
1238 case (HW_INFO3 | REQUEST):
1239 cs->hw.hfcpci.mst_m |= HFCPCI_MASTER;
1240 Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
1242 case (HW_TESTLOOP | REQUEST):
1243 switch ((int) arg) {
1245 Write_hfc(cs, HFCPCI_B1_SSL, 0x80); /* tx slot */
1246 Write_hfc(cs, HFCPCI_B1_RSL, 0x80); /* rx slot */
1249 cs->hw.hfcpci.conn = (cs->hw.hfcpci.conn & ~7) | 1;
1250 Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
1251 restore_flags(flags);
1255 Write_hfc(cs, HFCPCI_B2_SSL, 0x81); /* tx slot */
1256 Write_hfc(cs, HFCPCI_B2_RSL, 0x81); /* rx slot */
1259 cs->hw.hfcpci.conn = (cs->hw.hfcpci.conn & ~0x38) | 0x08;
1260 Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
1261 restore_flags(flags);
1265 if (cs->debug & L1_DEB_WARN)
1266 debugl1(cs, "hfcpci_l1hw loop invalid %4x", (int) arg);
1271 cs->hw.hfcpci.trm |= 0x80; /* enable IOM-loop */
1272 Write_hfc(cs, HFCPCI_TRM, cs->hw.hfcpci.trm);
1273 restore_flags(flags);
1276 if (cs->debug & L1_DEB_WARN)
1277 debugl1(cs, "hfcpci_l1hw unknown pr %4x", pr);
1282 /***********************************************/
1283 /* called during init setting l1 stack pointer */
1284 /***********************************************/
1286 setstack_hfcpci(struct PStack *st, struct IsdnCardState *cs)
1288 st->l1.l1hw = HFCPCI_l1hw;
1291 /**************************************/
1292 /* send B-channel data if not blocked */
1293 /**************************************/
1295 hfcpci_send_data(struct BCState *bcs)
1297 struct IsdnCardState *cs = bcs->cs;
1299 if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
1300 hfcpci_fill_fifo(bcs);
1301 test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
1303 debugl1(cs, "send_data %d blocked", bcs->channel);
1306 /***************************************************************/
1307 /* activate/deactivate hardware for selected channels and mode */
1308 /***************************************************************/
1310 mode_hfcpci(struct BCState *bcs, int mode, int bc)
1312 struct IsdnCardState *cs = bcs->cs;
1313 unsigned long flags;
1316 if (cs->debug & L1_DEB_HSCX)
1317 debugl1(cs, "HFCPCI bchannel mode %d bchan %d/%d",
1318 mode, bc, bcs->channel);
1324 if (cs->chanlimit > 1) {
1325 cs->hw.hfcpci.bswapped = 0; /* B1 and B2 normal mode */
1326 cs->hw.hfcpci.sctrl_e &= ~0x80;
1329 if (mode != L1_MODE_NULL) {
1330 cs->hw.hfcpci.bswapped = 1; /* B1 and B2 exchanged */
1331 cs->hw.hfcpci.sctrl_e |= 0x80;
1333 cs->hw.hfcpci.bswapped = 0; /* B1 and B2 normal mode */
1334 cs->hw.hfcpci.sctrl_e &= ~0x80;
1338 cs->hw.hfcpci.bswapped = 0; /* B1 and B2 normal mode */
1339 cs->hw.hfcpci.sctrl_e &= ~0x80;
1343 case (L1_MODE_NULL):
1345 cs->hw.hfcpci.sctrl &= ~SCTRL_B2_ENA;
1346 cs->hw.hfcpci.sctrl_r &= ~SCTRL_B2_ENA;
1348 cs->hw.hfcpci.sctrl &= ~SCTRL_B1_ENA;
1349 cs->hw.hfcpci.sctrl_r &= ~SCTRL_B1_ENA;
1352 cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B2;
1353 cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
1355 cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B1;
1356 cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
1359 case (L1_MODE_TRANS):
1360 hfcpci_clear_fifo_rx(cs, fifo2);
1361 hfcpci_clear_fifo_tx(cs, fifo2);
1363 cs->hw.hfcpci.sctrl |= SCTRL_B2_ENA;
1364 cs->hw.hfcpci.sctrl_r |= SCTRL_B2_ENA;
1366 cs->hw.hfcpci.sctrl |= SCTRL_B1_ENA;
1367 cs->hw.hfcpci.sctrl_r |= SCTRL_B1_ENA;
1370 cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B2;
1371 cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
1372 cs->hw.hfcpci.ctmt |= 2;
1373 cs->hw.hfcpci.conn &= ~0x18;
1375 cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B1;
1376 cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
1377 cs->hw.hfcpci.ctmt |= 1;
1378 cs->hw.hfcpci.conn &= ~0x03;
1381 case (L1_MODE_HDLC):
1382 hfcpci_clear_fifo_rx(cs, fifo2);
1383 hfcpci_clear_fifo_tx(cs, fifo2);
1385 cs->hw.hfcpci.sctrl |= SCTRL_B2_ENA;
1386 cs->hw.hfcpci.sctrl_r |= SCTRL_B2_ENA;
1388 cs->hw.hfcpci.sctrl |= SCTRL_B1_ENA;
1389 cs->hw.hfcpci.sctrl_r |= SCTRL_B1_ENA;
1392 cs->hw.hfcpci.last_bfifo_cnt[1] = 0;
1393 cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B2;
1394 cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
1395 cs->hw.hfcpci.ctmt &= ~2;
1396 cs->hw.hfcpci.conn &= ~0x18;
1398 cs->hw.hfcpci.last_bfifo_cnt[0] = 0;
1399 cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B1;
1400 cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
1401 cs->hw.hfcpci.ctmt &= ~1;
1402 cs->hw.hfcpci.conn &= ~0x03;
1405 case (L1_MODE_EXTRN):
1407 cs->hw.hfcpci.conn |= 0x10;
1408 cs->hw.hfcpci.sctrl |= SCTRL_B2_ENA;
1409 cs->hw.hfcpci.sctrl_r |= SCTRL_B2_ENA;
1410 cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B2;
1411 cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
1413 cs->hw.hfcpci.conn |= 0x02;
1414 cs->hw.hfcpci.sctrl |= SCTRL_B1_ENA;
1415 cs->hw.hfcpci.sctrl_r |= SCTRL_B1_ENA;
1416 cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B1;
1417 cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
1421 Write_hfc(cs, HFCPCI_SCTRL_E, cs->hw.hfcpci.sctrl_e);
1422 Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
1423 Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
1424 Write_hfc(cs, HFCPCI_SCTRL, cs->hw.hfcpci.sctrl);
1425 Write_hfc(cs, HFCPCI_SCTRL_R, cs->hw.hfcpci.sctrl_r);
1426 Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt);
1427 Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
1428 restore_flags(flags);
1431 /******************************/
1432 /* Layer2 -> Layer 1 Transfer */
1433 /******************************/
1435 hfcpci_l2l1(struct PStack *st, int pr, void *arg)
1437 struct sk_buff *skb = arg;
1441 case (PH_DATA | REQUEST):
1444 if (st->l1.bcs->tx_skb) {
1445 skb_queue_tail(&st->l1.bcs->squeue, skb);
1446 restore_flags(flags);
1448 st->l1.bcs->tx_skb = skb;
1449 /* test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
1450 */ st->l1.bcs->cs->BC_Send_Data(st->l1.bcs);
1451 restore_flags(flags);
1454 case (PH_PULL | INDICATION):
1455 if (st->l1.bcs->tx_skb) {
1456 printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
1461 /* test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
1462 */ st->l1.bcs->tx_skb = skb;
1463 st->l1.bcs->cs->BC_Send_Data(st->l1.bcs);
1464 restore_flags(flags);
1466 case (PH_PULL | REQUEST):
1467 if (!st->l1.bcs->tx_skb) {
1468 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1469 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
1471 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
1473 case (PH_ACTIVATE | REQUEST):
1474 test_and_set_bit(BC_FLG_ACTIV, &st->l1.bcs->Flag);
1475 mode_hfcpci(st->l1.bcs, st->l1.mode, st->l1.bc);
1476 l1_msg_b(st, pr, arg);
1478 case (PH_DEACTIVATE | REQUEST):
1479 l1_msg_b(st, pr, arg);
1481 case (PH_DEACTIVATE | CONFIRM):
1482 test_and_clear_bit(BC_FLG_ACTIV, &st->l1.bcs->Flag);
1483 test_and_clear_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
1484 mode_hfcpci(st->l1.bcs, 0, st->l1.bc);
1485 st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
1490 /******************************************/
1491 /* deactivate B-channel access and queues */
1492 /******************************************/
1494 close_hfcpci(struct BCState *bcs)
1496 mode_hfcpci(bcs, 0, bcs->channel);
1497 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
1498 skb_queue_purge(&bcs->rqueue);
1499 skb_queue_purge(&bcs->squeue);
1501 dev_kfree_skb_any(bcs->tx_skb);
1503 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
1508 /*************************************/
1509 /* init B-channel queues and control */
1510 /*************************************/
1512 open_hfcpcistate(struct IsdnCardState *cs, struct BCState *bcs)
1514 if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
1515 skb_queue_head_init(&bcs->rqueue);
1516 skb_queue_head_init(&bcs->squeue);
1519 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
1525 /*********************************/
1526 /* inits the stack for B-channel */
1527 /*********************************/
1529 setstack_2b(struct PStack *st, struct BCState *bcs)
1531 bcs->channel = st->l1.bc;
1532 if (open_hfcpcistate(st->l1.hardware, bcs))
1535 st->l2.l2l1 = hfcpci_l2l1;
1536 setstack_manager(st);
1542 /***************************/
1543 /* handle L1 state changes */
1544 /***************************/
1546 hfcpci_bh(struct IsdnCardState *cs)
1548 unsigned long flags;
1549 /* struct PStack *stptr;
1553 if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
1554 if (!cs->hw.hfcpci.nt_mode)
1555 switch (cs->dc.hfcpci.ph_state) {
1557 l1_msg(cs, HW_RESET | INDICATION, NULL);
1560 l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
1563 l1_msg(cs, HW_RSYNC | INDICATION, NULL);
1566 l1_msg(cs, HW_INFO2 | INDICATION, NULL);
1569 l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
1574 switch (cs->dc.hfcpci.ph_state) {
1578 if (cs->hw.hfcpci.nt_timer < 0) {
1579 cs->hw.hfcpci.nt_timer = 0;
1580 cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_TIMER;
1581 Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
1582 /* Clear already pending ints */
1583 if (Read_hfc(cs, HFCPCI_INT_S1));
1585 Write_hfc(cs, HFCPCI_STATES, 4 | HFCPCI_LOAD_STATE);
1587 Write_hfc(cs, HFCPCI_STATES, 4);
1588 cs->dc.hfcpci.ph_state = 4;
1590 cs->hw.hfcpci.int_m1 |= HFCPCI_INTS_TIMER;
1591 Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
1592 cs->hw.hfcpci.ctmt &= ~HFCPCI_AUTO_TIMER;
1593 cs->hw.hfcpci.ctmt |= HFCPCI_TIM3_125;
1594 Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt | HFCPCI_CLTIMER);
1595 Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt | HFCPCI_CLTIMER);
1596 cs->hw.hfcpci.nt_timer = NT_T1_COUNT;
1597 Write_hfc(cs, HFCPCI_STATES, 2 | HFCPCI_NT_G2_G3); /* allow G2 -> G3 transition */
1599 restore_flags(flags);
1606 cs->hw.hfcpci.nt_timer = 0;
1607 cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_TIMER;
1608 Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
1609 restore_flags(flags);
1616 if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
1617 DChannel_proc_rcv(cs);
1618 if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
1619 DChannel_proc_xmt(cs);
1623 /********************************/
1624 /* called for card init message */
1625 /********************************/
1627 inithfcpci(struct IsdnCardState *cs)
1629 cs->setstack_d = setstack_hfcpci;
1630 cs->dbusytimer.function = (void *) hfcpci_dbusy_timer;
1631 cs->dbusytimer.data = (long) cs;
1632 init_timer(&cs->dbusytimer);
1633 cs->tqueue.routine = (void *) (void *) hfcpci_bh;
1634 cs->BC_Send_Data = &hfcpci_send_data;
1635 cs->bcs[0].BC_SetStack = setstack_2b;
1636 cs->bcs[1].BC_SetStack = setstack_2b;
1637 cs->bcs[0].BC_Close = close_hfcpci;
1638 cs->bcs[1].BC_Close = close_hfcpci;
1639 mode_hfcpci(cs->bcs, 0, 0);
1640 mode_hfcpci(cs->bcs + 1, 0, 1);
1645 /*******************************************/
1646 /* handle card messages from control layer */
1647 /*******************************************/
1649 hfcpci_card_msg(struct IsdnCardState *cs, int mt, void *arg)
1653 if (cs->debug & L1_DEB_ISAC)
1654 debugl1(cs, "HFCPCI: card_msg %x", mt);
1660 release_io_hfcpci(cs);
1666 set_current_state(TASK_UNINTERRUPTIBLE);
1667 schedule_timeout((80 * HZ) / 1000); /* Timeout 80ms */
1668 /* now switch timer interrupt off */
1669 cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_TIMER;
1670 Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
1671 /* reinit mode reg */
1672 Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
1673 restore_flags(flags);
1682 /* this variable is used as card index when more than one cards are present */
1683 static struct pci_dev *dev_hfcpci __initdata = NULL;
1685 #endif /* CONFIG_PCI */
1688 setup_hfcpci(struct IsdnCard *card)
1690 struct IsdnCardState *cs = card->cs;
1693 struct pci_dev *tmp_hfcpci = NULL;
1696 #error "not running on big endian machines now"
1698 strcpy(tmp, hfcpci_revision);
1699 printk(KERN_INFO "HiSax: HFC-PCI driver Rev. %s\n", HiSax_getrev(tmp));
1701 cs->hw.hfcpci.int_s1 = 0;
1702 cs->dc.hfcpci.ph_state = 0;
1703 cs->hw.hfcpci.fifo = 255;
1704 if (cs->typ == ISDN_CTYPE_HFC_PCI) {
1706 while (id_list[i].vendor_id) {
1707 tmp_hfcpci = pci_find_device(id_list[i].vendor_id,
1708 id_list[i].device_id,
1712 if (pci_enable_device(tmp_hfcpci))
1714 pci_set_master(tmp_hfcpci);
1715 if ((card->para[0]) && (card->para[0] != (tmp_hfcpci->resource[ 0].start & PCI_BASE_ADDRESS_IO_MASK)))
1724 dev_hfcpci = tmp_hfcpci; /* old device */
1725 cs->hw.hfcpci.pci_bus = dev_hfcpci->bus->number;
1726 cs->hw.hfcpci.pci_device_fn = dev_hfcpci->devfn;
1727 cs->irq = dev_hfcpci->irq;
1729 printk(KERN_WARNING "HFC-PCI: No IRQ for PCI card found\n");
1732 cs->hw.hfcpci.pci_io = (char *) dev_hfcpci->resource[ 1].start;
1733 printk(KERN_INFO "HiSax: HFC-PCI card manufacturer: %s card name: %s\n", id_list[i].vendor_name, id_list[i].card_name);
1735 printk(KERN_WARNING "HFC-PCI: No PCI card found\n");
1738 if (!cs->hw.hfcpci.pci_io) {
1739 printk(KERN_WARNING "HFC-PCI: No IO-Mem for PCI card found\n");
1742 /* Allocate memory for FIFOS */
1743 /* Because the HFC-PCI needs a 32K physical alignment, we */
1744 /* need to allocate the double mem and align the address */
1745 if (!(cs->hw.hfcpci.share_start = kmalloc(65536, GFP_KERNEL))) {
1746 printk(KERN_WARNING "HFC-PCI: Error allocating memory for FIFO!\n");
1749 cs->hw.hfcpci.fifos = (void *)
1750 (((ulong) cs->hw.hfcpci.share_start) & ~0x7FFF) + 0x8000;
1751 pcibios_write_config_dword(cs->hw.hfcpci.pci_bus,
1752 cs->hw.hfcpci.pci_device_fn, 0x80,
1753 (u_int) virt_to_bus(cs->hw.hfcpci.fifos));
1754 cs->hw.hfcpci.pci_io = ioremap((ulong) cs->hw.hfcpci.pci_io, 256);
1756 "HFC-PCI: defined at mem %#x fifo %#x(%#x) IRQ %d HZ %d\n",
1757 (u_int) cs->hw.hfcpci.pci_io,
1758 (u_int) cs->hw.hfcpci.fifos,
1759 (u_int) virt_to_bus(cs->hw.hfcpci.fifos),
1761 pcibios_write_config_word(cs->hw.hfcpci.pci_bus, cs->hw.hfcpci.pci_device_fn, PCI_COMMAND, PCI_ENA_MEMIO); /* enable memory mapped ports, disable busmaster */
1762 cs->hw.hfcpci.int_m2 = 0; /* disable alle interrupts */
1763 cs->hw.hfcpci.int_m1 = 0;
1764 Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
1765 Write_hfc(cs, HFCPCI_INT_M2, cs->hw.hfcpci.int_m2);
1766 /* At this point the needed PCI config is done */
1767 /* fifos are still not enabled */
1769 return (0); /* no valid card type */
1772 cs->readisac = NULL;
1773 cs->writeisac = NULL;
1774 cs->readisacfifo = NULL;
1775 cs->writeisacfifo = NULL;
1776 cs->BC_Read_Reg = NULL;
1777 cs->BC_Write_Reg = NULL;
1778 cs->irq_func = &hfcpci_interrupt;
1779 cs->irq_flags |= SA_SHIRQ;
1781 cs->hw.hfcpci.timer.function = (void *) hfcpci_Timer;
1782 cs->hw.hfcpci.timer.data = (long) cs;
1783 init_timer(&cs->hw.hfcpci.timer);
1786 cs->cardmsg = &hfcpci_card_msg;
1787 cs->auxcmd = &hfcpci_auxcmd;
1790 printk(KERN_WARNING "HFC-PCI: NO_PCI_BIOS\n");
1792 #endif /* CONFIG_PCI */