1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * hfcpci.c low level driver for CCD's hfc-pci based cards
6 * Author Werner Cornelius (werner@isdn4linux.de)
7 * based on existing driver for CCD hfc ISA cards
8 * type approval valid for HFC-S PCI A based card
10 * Copyright 1999 by Werner Cornelius (werner@isdn-development.de)
11 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
16 * NOTE: only one poll value must be given for all cards
17 * See hfc_pci.h for debug flags.
20 * NOTE: only one poll value must be given for all cards
21 * Give the number of samples for each fifo process.
22 * By default 128 is used. Decrease to reduce delay, increase to
23 * reduce cpu load. If unsure, don't mess with it!
24 * A value of 128 will use controller's interrupt. Other values will
25 * use kernel timer, because the controller will not allow lower values
27 * Also note that the value depends on the kernel timer frequency.
28 * If kernel uses a frequency of 1000 Hz, steps of 8 samples are possible.
29 * If the kernel uses 100 Hz, steps of 80 samples are possible.
30 * If the kernel uses 300 Hz, steps of about 26 samples are possible.
33 #include <linux/interrupt.h>
34 #include <linux/module.h>
35 #include <linux/pci.h>
36 #include <linux/delay.h>
37 #include <linux/mISDNhw.h>
38 #include <linux/slab.h>
42 static const char *hfcpci_revision
= "2.0";
46 static uint poll
, tics
;
47 static struct timer_list hfc_tl
;
48 static unsigned long hfc_jiffies
;
50 MODULE_AUTHOR("Karsten Keil");
51 MODULE_LICENSE("GPL");
52 module_param(debug
, uint
, S_IRUGO
| S_IWUSR
);
53 module_param(poll
, uint
, S_IRUGO
| S_IWUSR
);
91 unsigned char sctrl_r
;
92 unsigned char sctrl_e
;
94 unsigned char fifo_en
;
95 unsigned char bswapped
;
96 unsigned char protocol
;
98 unsigned char __iomem
*pci_io
; /* start of PCI IO memory */
100 void *fifos
; /* FIFO memory */
101 int last_bfifo_cnt
[2];
102 /* marker saving last b-fifo frame count */
103 struct timer_list timer
;
106 #define HFC_CFG_MASTER 1
107 #define HFC_CFG_SLAVE 2
108 #define HFC_CFG_PCM 3
109 #define HFC_CFG_2HFC 4
110 #define HFC_CFG_SLAVEHFC 5
111 #define HFC_CFG_NEG_F0 6
112 #define HFC_CFG_SW_DD_DU 7
114 #define FLG_HFC_TIMER_T1 16
115 #define FLG_HFC_TIMER_T3 17
117 #define NT_T1_COUNT 1120 /* number of 3.125ms interrupts (3.5s) */
118 #define NT_T3_COUNT 31 /* number of 3.125ms interrupts (97 ms) */
119 #define CLKDEL_TE 0x0e /* CLKDEL in TE mode */
120 #define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
130 struct pci_dev
*pdev
;
132 spinlock_t lock
; /* card lock */
134 struct bchannel bch
[2];
137 /* Interface functions */
139 enable_hwirq(struct hfc_pci
*hc
)
141 hc
->hw
.int_m2
|= HFCPCI_IRQ_ENABLE
;
142 Write_hfc(hc
, HFCPCI_INT_M2
, hc
->hw
.int_m2
);
146 disable_hwirq(struct hfc_pci
*hc
)
148 hc
->hw
.int_m2
&= ~((u_char
)HFCPCI_IRQ_ENABLE
);
149 Write_hfc(hc
, HFCPCI_INT_M2
, hc
->hw
.int_m2
);
153 * free hardware resources used by driver
156 release_io_hfcpci(struct hfc_pci
*hc
)
158 /* disable memory mapped ports + busmaster */
159 pci_write_config_word(hc
->pdev
, PCI_COMMAND
, 0);
160 del_timer(&hc
->hw
.timer
);
161 pci_free_consistent(hc
->pdev
, 0x8000, hc
->hw
.fifos
, hc
->hw
.dmahandle
);
162 iounmap(hc
->hw
.pci_io
);
166 * set mode (NT or TE)
169 hfcpci_setmode(struct hfc_pci
*hc
)
171 if (hc
->hw
.protocol
== ISDN_P_NT_S0
) {
172 hc
->hw
.clkdel
= CLKDEL_NT
; /* ST-Bit delay for NT-Mode */
173 hc
->hw
.sctrl
|= SCTRL_MODE_NT
; /* NT-MODE */
174 hc
->hw
.states
= 1; /* G1 */
176 hc
->hw
.clkdel
= CLKDEL_TE
; /* ST-Bit delay for TE-Mode */
177 hc
->hw
.sctrl
&= ~SCTRL_MODE_NT
; /* TE-MODE */
178 hc
->hw
.states
= 2; /* F2 */
180 Write_hfc(hc
, HFCPCI_CLKDEL
, hc
->hw
.clkdel
);
181 Write_hfc(hc
, HFCPCI_STATES
, HFCPCI_LOAD_STATE
| hc
->hw
.states
);
183 Write_hfc(hc
, HFCPCI_STATES
, hc
->hw
.states
| 0x40); /* Deactivate */
184 Write_hfc(hc
, HFCPCI_SCTRL
, hc
->hw
.sctrl
);
188 * function called to reset the HFC PCI chip. A complete software reset of chip
192 reset_hfcpci(struct hfc_pci
*hc
)
197 printk(KERN_DEBUG
"reset_hfcpci: entered\n");
198 val
= Read_hfc(hc
, HFCPCI_CHIP_ID
);
199 printk(KERN_INFO
"HFC_PCI: resetting HFC ChipId(%x)\n", val
);
200 /* enable memory mapped ports, disable busmaster */
201 pci_write_config_word(hc
->pdev
, PCI_COMMAND
, PCI_ENA_MEMIO
);
203 /* enable memory ports + busmaster */
204 pci_write_config_word(hc
->pdev
, PCI_COMMAND
,
205 PCI_ENA_MEMIO
+ PCI_ENA_MASTER
);
206 val
= Read_hfc(hc
, HFCPCI_STATUS
);
207 printk(KERN_DEBUG
"HFC-PCI status(%x) before reset\n", val
);
208 hc
->hw
.cirm
= HFCPCI_RESET
; /* Reset On */
209 Write_hfc(hc
, HFCPCI_CIRM
, hc
->hw
.cirm
);
210 set_current_state(TASK_UNINTERRUPTIBLE
);
211 mdelay(10); /* Timeout 10ms */
212 hc
->hw
.cirm
= 0; /* Reset Off */
213 Write_hfc(hc
, HFCPCI_CIRM
, hc
->hw
.cirm
);
214 val
= Read_hfc(hc
, HFCPCI_STATUS
);
215 printk(KERN_DEBUG
"HFC-PCI status(%x) after reset\n", val
);
216 while (cnt
< 50000) { /* max 50000 us */
219 val
= Read_hfc(hc
, HFCPCI_STATUS
);
223 printk(KERN_DEBUG
"HFC-PCI status(%x) after %dus\n", val
, cnt
);
225 hc
->hw
.fifo_en
= 0x30; /* only D fifos enabled */
227 hc
->hw
.bswapped
= 0; /* no exchange */
228 hc
->hw
.ctmt
= HFCPCI_TIM3_125
| HFCPCI_AUTO_TIMER
;
229 hc
->hw
.trm
= HFCPCI_BTRANS_THRESMASK
; /* no echo connect , threshold */
230 hc
->hw
.sctrl
= 0x40; /* set tx_lo mode, error in datasheet ! */
232 hc
->hw
.sctrl_e
= HFCPCI_AUTO_AWAKE
; /* S/T Auto awake */
234 if (test_bit(HFC_CFG_MASTER
, &hc
->cfg
))
235 hc
->hw
.mst_m
|= HFCPCI_MASTER
; /* HFC Master Mode */
236 if (test_bit(HFC_CFG_NEG_F0
, &hc
->cfg
))
237 hc
->hw
.mst_m
|= HFCPCI_F0_NEGATIV
;
238 Write_hfc(hc
, HFCPCI_FIFO_EN
, hc
->hw
.fifo_en
);
239 Write_hfc(hc
, HFCPCI_TRM
, hc
->hw
.trm
);
240 Write_hfc(hc
, HFCPCI_SCTRL_E
, hc
->hw
.sctrl_e
);
241 Write_hfc(hc
, HFCPCI_CTMT
, hc
->hw
.ctmt
);
243 hc
->hw
.int_m1
= HFCPCI_INTS_DTRANS
| HFCPCI_INTS_DREC
|
244 HFCPCI_INTS_L1STATE
| HFCPCI_INTS_TIMER
;
245 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
247 /* Clear already pending ints */
248 val
= Read_hfc(hc
, HFCPCI_INT_S1
);
253 Write_hfc(hc
, HFCPCI_MST_MODE
, hc
->hw
.mst_m
);
254 Write_hfc(hc
, HFCPCI_SCTRL_R
, hc
->hw
.sctrl_r
);
257 * Init GCI/IOM2 in master mode
258 * Slots 0 and 1 are set for B-chan 1 and 2
259 * D- and monitor/CI channel are not enabled
260 * STIO1 is used as output for data, B1+B2 from ST->IOM+HFC
261 * STIO2 is used as data input, B1+B2 from IOM->ST
262 * ST B-channel send disabled -> continuous 1s
263 * The IOM slots are always enabled
265 if (test_bit(HFC_CFG_PCM
, &hc
->cfg
)) {
266 /* set data flow directions: connect B1,B2: HFC to/from PCM */
269 hc
->hw
.conn
= 0x36; /* set data flow directions */
270 if (test_bit(HFC_CFG_SW_DD_DU
, &hc
->cfg
)) {
271 Write_hfc(hc
, HFCPCI_B1_SSL
, 0xC0);
272 Write_hfc(hc
, HFCPCI_B2_SSL
, 0xC1);
273 Write_hfc(hc
, HFCPCI_B1_RSL
, 0xC0);
274 Write_hfc(hc
, HFCPCI_B2_RSL
, 0xC1);
276 Write_hfc(hc
, HFCPCI_B1_SSL
, 0x80);
277 Write_hfc(hc
, HFCPCI_B2_SSL
, 0x81);
278 Write_hfc(hc
, HFCPCI_B1_RSL
, 0x80);
279 Write_hfc(hc
, HFCPCI_B2_RSL
, 0x81);
282 Write_hfc(hc
, HFCPCI_CONNECT
, hc
->hw
.conn
);
283 val
= Read_hfc(hc
, HFCPCI_INT_S2
);
287 * Timer function called when kernel timer expires
290 hfcpci_Timer(struct timer_list
*t
)
292 struct hfc_pci
*hc
= from_timer(hc
, t
, hw
.timer
);
293 hc
->hw
.timer
.expires
= jiffies
+ 75;
296 * WriteReg(hc, HFCD_DATA, HFCD_CTMT, hc->hw.ctmt | 0x80);
297 * add_timer(&hc->hw.timer);
303 * select a b-channel entry matching and active
305 static struct bchannel
*
306 Sel_BCS(struct hfc_pci
*hc
, int channel
)
308 if (test_bit(FLG_ACTIVE
, &hc
->bch
[0].Flags
) &&
309 (hc
->bch
[0].nr
& channel
))
311 else if (test_bit(FLG_ACTIVE
, &hc
->bch
[1].Flags
) &&
312 (hc
->bch
[1].nr
& channel
))
319 * clear the desired B-channel rx fifo
322 hfcpci_clear_fifo_rx(struct hfc_pci
*hc
, int fifo
)
328 bzr
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.rxbz_b2
;
329 fifo_state
= hc
->hw
.fifo_en
& HFCPCI_FIFOEN_B2RX
;
331 bzr
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.rxbz_b1
;
332 fifo_state
= hc
->hw
.fifo_en
& HFCPCI_FIFOEN_B1RX
;
335 hc
->hw
.fifo_en
^= fifo_state
;
336 Write_hfc(hc
, HFCPCI_FIFO_EN
, hc
->hw
.fifo_en
);
337 hc
->hw
.last_bfifo_cnt
[fifo
] = 0;
338 bzr
->f1
= MAX_B_FRAMES
;
339 bzr
->f2
= bzr
->f1
; /* init F pointers to remain constant */
340 bzr
->za
[MAX_B_FRAMES
].z1
= cpu_to_le16(B_FIFO_SIZE
+ B_SUB_VAL
- 1);
341 bzr
->za
[MAX_B_FRAMES
].z2
= cpu_to_le16(
342 le16_to_cpu(bzr
->za
[MAX_B_FRAMES
].z1
));
344 hc
->hw
.fifo_en
|= fifo_state
;
345 Write_hfc(hc
, HFCPCI_FIFO_EN
, hc
->hw
.fifo_en
);
349 * clear the desired B-channel tx fifo
351 static void hfcpci_clear_fifo_tx(struct hfc_pci
*hc
, int fifo
)
357 bzt
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.txbz_b2
;
358 fifo_state
= hc
->hw
.fifo_en
& HFCPCI_FIFOEN_B2TX
;
360 bzt
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.txbz_b1
;
361 fifo_state
= hc
->hw
.fifo_en
& HFCPCI_FIFOEN_B1TX
;
364 hc
->hw
.fifo_en
^= fifo_state
;
365 Write_hfc(hc
, HFCPCI_FIFO_EN
, hc
->hw
.fifo_en
);
366 if (hc
->bch
[fifo
].debug
& DEBUG_HW_BCHANNEL
)
367 printk(KERN_DEBUG
"hfcpci_clear_fifo_tx%d f1(%x) f2(%x) "
368 "z1(%x) z2(%x) state(%x)\n",
369 fifo
, bzt
->f1
, bzt
->f2
,
370 le16_to_cpu(bzt
->za
[MAX_B_FRAMES
].z1
),
371 le16_to_cpu(bzt
->za
[MAX_B_FRAMES
].z2
),
373 bzt
->f2
= MAX_B_FRAMES
;
374 bzt
->f1
= bzt
->f2
; /* init F pointers to remain constant */
375 bzt
->za
[MAX_B_FRAMES
].z1
= cpu_to_le16(B_FIFO_SIZE
+ B_SUB_VAL
- 1);
376 bzt
->za
[MAX_B_FRAMES
].z2
= cpu_to_le16(B_FIFO_SIZE
+ B_SUB_VAL
- 2);
378 hc
->hw
.fifo_en
|= fifo_state
;
379 Write_hfc(hc
, HFCPCI_FIFO_EN
, hc
->hw
.fifo_en
);
380 if (hc
->bch
[fifo
].debug
& DEBUG_HW_BCHANNEL
)
382 "hfcpci_clear_fifo_tx%d f1(%x) f2(%x) z1(%x) z2(%x)\n",
383 fifo
, bzt
->f1
, bzt
->f2
,
384 le16_to_cpu(bzt
->za
[MAX_B_FRAMES
].z1
),
385 le16_to_cpu(bzt
->za
[MAX_B_FRAMES
].z2
));
389 * read a complete B-frame out of the buffer
392 hfcpci_empty_bfifo(struct bchannel
*bch
, struct bzfifo
*bz
,
393 u_char
*bdata
, int count
)
395 u_char
*ptr
, *ptr1
, new_f2
;
399 if ((bch
->debug
& DEBUG_HW_BCHANNEL
) && !(bch
->debug
& DEBUG_HW_BFIFO
))
400 printk(KERN_DEBUG
"hfcpci_empty_fifo\n");
401 zp
= &bz
->za
[bz
->f2
]; /* point to Z-Regs */
402 new_z2
= le16_to_cpu(zp
->z2
) + count
; /* new position in fifo */
403 if (new_z2
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
404 new_z2
-= B_FIFO_SIZE
; /* buffer wrap */
405 new_f2
= (bz
->f2
+ 1) & MAX_B_FRAMES
;
406 if ((count
> MAX_DATA_SIZE
+ 3) || (count
< 4) ||
407 (*(bdata
+ (le16_to_cpu(zp
->z1
) - B_SUB_VAL
)))) {
408 if (bch
->debug
& DEBUG_HW
)
409 printk(KERN_DEBUG
"hfcpci_empty_fifo: incoming packet "
410 "invalid length %d or crc\n", count
);
411 #ifdef ERROR_STATISTIC
414 bz
->za
[new_f2
].z2
= cpu_to_le16(new_z2
);
415 bz
->f2
= new_f2
; /* next buffer */
417 bch
->rx_skb
= mI_alloc_skb(count
- 3, GFP_ATOMIC
);
419 printk(KERN_WARNING
"HFCPCI: receive out of memory\n");
423 ptr
= skb_put(bch
->rx_skb
, count
);
425 if (le16_to_cpu(zp
->z2
) + count
<= B_FIFO_SIZE
+ B_SUB_VAL
)
426 maxlen
= count
; /* complete transfer */
428 maxlen
= B_FIFO_SIZE
+ B_SUB_VAL
-
429 le16_to_cpu(zp
->z2
); /* maximum */
431 ptr1
= bdata
+ (le16_to_cpu(zp
->z2
) - B_SUB_VAL
);
433 memcpy(ptr
, ptr1
, maxlen
); /* copy data */
436 if (count
) { /* rest remaining */
438 ptr1
= bdata
; /* start of buffer */
439 memcpy(ptr
, ptr1
, count
); /* rest */
441 bz
->za
[new_f2
].z2
= cpu_to_le16(new_z2
);
442 bz
->f2
= new_f2
; /* next buffer */
443 recv_Bchannel(bch
, MISDN_ID_ANY
, false);
448 * D-channel receive procedure
451 receive_dmsg(struct hfc_pci
*hc
)
453 struct dchannel
*dch
= &hc
->dch
;
461 df
= &((union fifo_area
*)(hc
->hw
.fifos
))->d_chan
.d_rx
;
462 while (((df
->f1
& D_FREG_MASK
) != (df
->f2
& D_FREG_MASK
)) && count
--) {
463 zp
= &df
->za
[df
->f2
& D_FREG_MASK
];
464 rcnt
= le16_to_cpu(zp
->z1
) - le16_to_cpu(zp
->z2
);
468 if (dch
->debug
& DEBUG_HW_DCHANNEL
)
470 "hfcpci recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)\n",
476 if ((rcnt
> MAX_DFRAME_LEN
+ 3) || (rcnt
< 4) ||
477 (df
->data
[le16_to_cpu(zp
->z1
)])) {
478 if (dch
->debug
& DEBUG_HW
)
480 "empty_fifo hfcpci packet inv. len "
483 df
->data
[le16_to_cpu(zp
->z1
)]);
484 #ifdef ERROR_STATISTIC
487 df
->f2
= ((df
->f2
+ 1) & MAX_D_FRAMES
) |
488 (MAX_D_FRAMES
+ 1); /* next buffer */
489 df
->za
[df
->f2
& D_FREG_MASK
].z2
=
490 cpu_to_le16((le16_to_cpu(zp
->z2
) + rcnt
) &
493 dch
->rx_skb
= mI_alloc_skb(rcnt
- 3, GFP_ATOMIC
);
496 "HFC-PCI: D receive out of memory\n");
501 ptr
= skb_put(dch
->rx_skb
, rcnt
);
503 if (le16_to_cpu(zp
->z2
) + rcnt
<= D_FIFO_SIZE
)
504 maxlen
= rcnt
; /* complete transfer */
506 maxlen
= D_FIFO_SIZE
- le16_to_cpu(zp
->z2
);
509 ptr1
= df
->data
+ le16_to_cpu(zp
->z2
);
511 memcpy(ptr
, ptr1
, maxlen
); /* copy data */
514 if (rcnt
) { /* rest remaining */
516 ptr1
= df
->data
; /* start of buffer */
517 memcpy(ptr
, ptr1
, rcnt
); /* rest */
519 df
->f2
= ((df
->f2
+ 1) & MAX_D_FRAMES
) |
520 (MAX_D_FRAMES
+ 1); /* next buffer */
521 df
->za
[df
->f2
& D_FREG_MASK
].z2
= cpu_to_le16((
522 le16_to_cpu(zp
->z2
) + total
) & (D_FIFO_SIZE
- 1));
530 * check for transparent receive data and read max one 'poll' size if avail
533 hfcpci_empty_fifo_trans(struct bchannel
*bch
, struct bzfifo
*rxbz
,
534 struct bzfifo
*txbz
, u_char
*bdata
)
536 __le16
*z1r
, *z2r
, *z1t
, *z2t
;
537 int new_z2
, fcnt_rx
, fcnt_tx
, maxlen
;
540 z1r
= &rxbz
->za
[MAX_B_FRAMES
].z1
; /* pointer to z reg */
542 z1t
= &txbz
->za
[MAX_B_FRAMES
].z1
;
545 fcnt_rx
= le16_to_cpu(*z1r
) - le16_to_cpu(*z2r
);
547 return; /* no data avail */
550 fcnt_rx
+= B_FIFO_SIZE
; /* bytes actually buffered */
551 new_z2
= le16_to_cpu(*z2r
) + fcnt_rx
; /* new position in fifo */
552 if (new_z2
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
553 new_z2
-= B_FIFO_SIZE
; /* buffer wrap */
555 fcnt_tx
= le16_to_cpu(*z2t
) - le16_to_cpu(*z1t
);
557 fcnt_tx
+= B_FIFO_SIZE
;
558 /* fcnt_tx contains available bytes in tx-fifo */
559 fcnt_tx
= B_FIFO_SIZE
- fcnt_tx
;
560 /* remaining bytes to send (bytes in tx-fifo) */
562 if (test_bit(FLG_RX_OFF
, &bch
->Flags
)) {
563 bch
->dropcnt
+= fcnt_rx
;
564 *z2r
= cpu_to_le16(new_z2
);
567 maxlen
= bchannel_get_rxbuf(bch
, fcnt_rx
);
569 pr_warn("B%d: No bufferspace for %d bytes\n", bch
->nr
, fcnt_rx
);
571 ptr
= skb_put(bch
->rx_skb
, fcnt_rx
);
572 if (le16_to_cpu(*z2r
) + fcnt_rx
<= B_FIFO_SIZE
+ B_SUB_VAL
)
573 maxlen
= fcnt_rx
; /* complete transfer */
575 maxlen
= B_FIFO_SIZE
+ B_SUB_VAL
- le16_to_cpu(*z2r
);
578 ptr1
= bdata
+ (le16_to_cpu(*z2r
) - B_SUB_VAL
);
580 memcpy(ptr
, ptr1
, maxlen
); /* copy data */
583 if (fcnt_rx
) { /* rest remaining */
585 ptr1
= bdata
; /* start of buffer */
586 memcpy(ptr
, ptr1
, fcnt_rx
); /* rest */
588 recv_Bchannel(bch
, fcnt_tx
, false); /* bch, id, !force */
590 *z2r
= cpu_to_le16(new_z2
); /* new position */
594 * B-channel main receive routine
597 main_rec_hfcpci(struct bchannel
*bch
)
599 struct hfc_pci
*hc
= bch
->hw
;
601 int receive
= 0, count
= 5;
602 struct bzfifo
*txbz
, *rxbz
;
606 if ((bch
->nr
& 2) && (!hc
->hw
.bswapped
)) {
607 rxbz
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.rxbz_b2
;
608 txbz
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.txbz_b2
;
609 bdata
= ((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.rxdat_b2
;
612 rxbz
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.rxbz_b1
;
613 txbz
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.txbz_b1
;
614 bdata
= ((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.rxdat_b1
;
619 if (rxbz
->f1
!= rxbz
->f2
) {
620 if (bch
->debug
& DEBUG_HW_BCHANNEL
)
621 printk(KERN_DEBUG
"hfcpci rec ch(%x) f1(%d) f2(%d)\n",
622 bch
->nr
, rxbz
->f1
, rxbz
->f2
);
623 zp
= &rxbz
->za
[rxbz
->f2
];
625 rcnt
= le16_to_cpu(zp
->z1
) - le16_to_cpu(zp
->z2
);
629 if (bch
->debug
& DEBUG_HW_BCHANNEL
)
631 "hfcpci rec ch(%x) z1(%x) z2(%x) cnt(%d)\n",
632 bch
->nr
, le16_to_cpu(zp
->z1
),
633 le16_to_cpu(zp
->z2
), rcnt
);
634 hfcpci_empty_bfifo(bch
, rxbz
, bdata
, rcnt
);
635 rcnt
= rxbz
->f1
- rxbz
->f2
;
637 rcnt
+= MAX_B_FRAMES
+ 1;
638 if (hc
->hw
.last_bfifo_cnt
[real_fifo
] > rcnt
+ 1) {
640 hfcpci_clear_fifo_rx(hc
, real_fifo
);
642 hc
->hw
.last_bfifo_cnt
[real_fifo
] = rcnt
;
647 } else if (test_bit(FLG_TRANSPARENT
, &bch
->Flags
)) {
648 hfcpci_empty_fifo_trans(bch
, rxbz
, txbz
, bdata
);
652 if (count
&& receive
)
658 * D-channel send routine
661 hfcpci_fill_dfifo(struct hfc_pci
*hc
)
663 struct dchannel
*dch
= &hc
->dch
;
665 int count
, new_z1
, maxlen
;
667 u_char
*src
, *dst
, new_f1
;
669 if ((dch
->debug
& DEBUG_HW_DCHANNEL
) && !(dch
->debug
& DEBUG_HW_DFIFO
))
670 printk(KERN_DEBUG
"%s\n", __func__
);
674 count
= dch
->tx_skb
->len
- dch
->tx_idx
;
677 df
= &((union fifo_area
*) (hc
->hw
.fifos
))->d_chan
.d_tx
;
679 if (dch
->debug
& DEBUG_HW_DFIFO
)
680 printk(KERN_DEBUG
"%s:f1(%d) f2(%d) z1(f1)(%x)\n", __func__
,
682 le16_to_cpu(df
->za
[df
->f1
& D_FREG_MASK
].z1
));
683 fcnt
= df
->f1
- df
->f2
; /* frame count actually buffered */
685 fcnt
+= (MAX_D_FRAMES
+ 1); /* if wrap around */
686 if (fcnt
> (MAX_D_FRAMES
- 1)) {
687 if (dch
->debug
& DEBUG_HW_DCHANNEL
)
689 "hfcpci_fill_Dfifo more as 14 frames\n");
690 #ifdef ERROR_STATISTIC
695 /* now determine free bytes in FIFO buffer */
696 maxlen
= le16_to_cpu(df
->za
[df
->f2
& D_FREG_MASK
].z2
) -
697 le16_to_cpu(df
->za
[df
->f1
& D_FREG_MASK
].z1
) - 1;
699 maxlen
+= D_FIFO_SIZE
; /* count now contains available bytes */
701 if (dch
->debug
& DEBUG_HW_DCHANNEL
)
702 printk(KERN_DEBUG
"hfcpci_fill_Dfifo count(%d/%d)\n",
704 if (count
> maxlen
) {
705 if (dch
->debug
& DEBUG_HW_DCHANNEL
)
706 printk(KERN_DEBUG
"hfcpci_fill_Dfifo no fifo mem\n");
709 new_z1
= (le16_to_cpu(df
->za
[df
->f1
& D_FREG_MASK
].z1
) + count
) &
711 new_f1
= ((df
->f1
+ 1) & D_FREG_MASK
) | (D_FREG_MASK
+ 1);
712 src
= dch
->tx_skb
->data
+ dch
->tx_idx
; /* source pointer */
713 dst
= df
->data
+ le16_to_cpu(df
->za
[df
->f1
& D_FREG_MASK
].z1
);
714 maxlen
= D_FIFO_SIZE
- le16_to_cpu(df
->za
[df
->f1
& D_FREG_MASK
].z1
);
717 maxlen
= count
; /* limit size */
718 memcpy(dst
, src
, maxlen
); /* first copy */
720 count
-= maxlen
; /* remaining bytes */
722 dst
= df
->data
; /* start of buffer */
723 src
+= maxlen
; /* new position */
724 memcpy(dst
, src
, count
);
726 df
->za
[new_f1
& D_FREG_MASK
].z1
= cpu_to_le16(new_z1
);
727 /* for next buffer */
728 df
->za
[df
->f1
& D_FREG_MASK
].z1
= cpu_to_le16(new_z1
);
729 /* new pos actual buffer */
730 df
->f1
= new_f1
; /* next frame */
731 dch
->tx_idx
= dch
->tx_skb
->len
;
735 * B-channel send routine
738 hfcpci_fill_fifo(struct bchannel
*bch
)
740 struct hfc_pci
*hc
= bch
->hw
;
745 u_char new_f1
, *src
, *dst
;
748 if ((bch
->debug
& DEBUG_HW_BCHANNEL
) && !(bch
->debug
& DEBUG_HW_BFIFO
))
749 printk(KERN_DEBUG
"%s\n", __func__
);
750 if ((!bch
->tx_skb
) || bch
->tx_skb
->len
== 0) {
751 if (!test_bit(FLG_FILLEMPTY
, &bch
->Flags
) &&
752 !test_bit(FLG_TRANSPARENT
, &bch
->Flags
))
754 count
= HFCPCI_FILLEMPTY
;
756 count
= bch
->tx_skb
->len
- bch
->tx_idx
;
758 if ((bch
->nr
& 2) && (!hc
->hw
.bswapped
)) {
759 bz
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.txbz_b2
;
760 bdata
= ((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.txdat_b2
;
762 bz
= &((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.txbz_b1
;
763 bdata
= ((union fifo_area
*)(hc
->hw
.fifos
))->b_chans
.txdat_b1
;
766 if (test_bit(FLG_TRANSPARENT
, &bch
->Flags
)) {
767 z1t
= &bz
->za
[MAX_B_FRAMES
].z1
;
769 if (bch
->debug
& DEBUG_HW_BCHANNEL
)
770 printk(KERN_DEBUG
"hfcpci_fill_fifo_trans ch(%x) "
771 "cnt(%d) z1(%x) z2(%x)\n", bch
->nr
, count
,
772 le16_to_cpu(*z1t
), le16_to_cpu(*z2t
));
773 fcnt
= le16_to_cpu(*z2t
) - le16_to_cpu(*z1t
);
776 if (test_bit(FLG_FILLEMPTY
, &bch
->Flags
)) {
777 /* fcnt contains available bytes in fifo */
780 new_z1
= le16_to_cpu(*z1t
) + count
;
781 /* new buffer Position */
782 if (new_z1
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
783 new_z1
-= B_FIFO_SIZE
; /* buffer wrap */
784 dst
= bdata
+ (le16_to_cpu(*z1t
) - B_SUB_VAL
);
785 maxlen
= (B_FIFO_SIZE
+ B_SUB_VAL
) - le16_to_cpu(*z1t
);
787 if (bch
->debug
& DEBUG_HW_BFIFO
)
788 printk(KERN_DEBUG
"hfcpci_FFt fillempty "
789 "fcnt(%d) maxl(%d) nz1(%x) dst(%p)\n",
790 fcnt
, maxlen
, new_z1
, dst
);
792 maxlen
= count
; /* limit size */
793 memset(dst
, bch
->fill
[0], maxlen
); /* first copy */
794 count
-= maxlen
; /* remaining bytes */
796 dst
= bdata
; /* start of buffer */
797 memset(dst
, bch
->fill
[0], count
);
799 *z1t
= cpu_to_le16(new_z1
); /* now send data */
802 /* fcnt contains available bytes in fifo */
803 fcnt
= B_FIFO_SIZE
- fcnt
;
804 /* remaining bytes to send (bytes in fifo) */
807 count
= bch
->tx_skb
->len
- bch
->tx_idx
;
808 /* maximum fill shall be poll*2 */
809 if (count
> (poll
<< 1) - fcnt
)
810 count
= (poll
<< 1) - fcnt
;
813 /* data is suitable for fifo */
814 new_z1
= le16_to_cpu(*z1t
) + count
;
815 /* new buffer Position */
816 if (new_z1
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
817 new_z1
-= B_FIFO_SIZE
; /* buffer wrap */
818 src
= bch
->tx_skb
->data
+ bch
->tx_idx
;
820 dst
= bdata
+ (le16_to_cpu(*z1t
) - B_SUB_VAL
);
821 maxlen
= (B_FIFO_SIZE
+ B_SUB_VAL
) - le16_to_cpu(*z1t
);
823 if (bch
->debug
& DEBUG_HW_BFIFO
)
824 printk(KERN_DEBUG
"hfcpci_FFt fcnt(%d) "
825 "maxl(%d) nz1(%x) dst(%p)\n",
826 fcnt
, maxlen
, new_z1
, dst
);
828 bch
->tx_idx
+= count
;
830 maxlen
= count
; /* limit size */
831 memcpy(dst
, src
, maxlen
); /* first copy */
832 count
-= maxlen
; /* remaining bytes */
834 dst
= bdata
; /* start of buffer */
835 src
+= maxlen
; /* new position */
836 memcpy(dst
, src
, count
);
838 *z1t
= cpu_to_le16(new_z1
); /* now send data */
839 if (bch
->tx_idx
< bch
->tx_skb
->len
)
841 dev_kfree_skb(bch
->tx_skb
);
842 if (get_next_bframe(bch
))
846 if (bch
->debug
& DEBUG_HW_BCHANNEL
)
848 "%s: ch(%x) f1(%d) f2(%d) z1(f1)(%x)\n",
849 __func__
, bch
->nr
, bz
->f1
, bz
->f2
,
851 fcnt
= bz
->f1
- bz
->f2
; /* frame count actually buffered */
853 fcnt
+= (MAX_B_FRAMES
+ 1); /* if wrap around */
854 if (fcnt
> (MAX_B_FRAMES
- 1)) {
855 if (bch
->debug
& DEBUG_HW_BCHANNEL
)
857 "hfcpci_fill_Bfifo more as 14 frames\n");
860 /* now determine free bytes in FIFO buffer */
861 maxlen
= le16_to_cpu(bz
->za
[bz
->f2
].z2
) -
862 le16_to_cpu(bz
->za
[bz
->f1
].z1
) - 1;
864 maxlen
+= B_FIFO_SIZE
; /* count now contains available bytes */
866 if (bch
->debug
& DEBUG_HW_BCHANNEL
)
867 printk(KERN_DEBUG
"hfcpci_fill_fifo ch(%x) count(%d/%d)\n",
868 bch
->nr
, count
, maxlen
);
870 if (maxlen
< count
) {
871 if (bch
->debug
& DEBUG_HW_BCHANNEL
)
872 printk(KERN_DEBUG
"hfcpci_fill_fifo no fifo mem\n");
875 new_z1
= le16_to_cpu(bz
->za
[bz
->f1
].z1
) + count
;
876 /* new buffer Position */
877 if (new_z1
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
878 new_z1
-= B_FIFO_SIZE
; /* buffer wrap */
880 new_f1
= ((bz
->f1
+ 1) & MAX_B_FRAMES
);
881 src
= bch
->tx_skb
->data
+ bch
->tx_idx
; /* source pointer */
882 dst
= bdata
+ (le16_to_cpu(bz
->za
[bz
->f1
].z1
) - B_SUB_VAL
);
883 maxlen
= (B_FIFO_SIZE
+ B_SUB_VAL
) - le16_to_cpu(bz
->za
[bz
->f1
].z1
);
886 maxlen
= count
; /* limit size */
887 memcpy(dst
, src
, maxlen
); /* first copy */
889 count
-= maxlen
; /* remaining bytes */
891 dst
= bdata
; /* start of buffer */
892 src
+= maxlen
; /* new position */
893 memcpy(dst
, src
, count
);
895 bz
->za
[new_f1
].z1
= cpu_to_le16(new_z1
); /* for next buffer */
896 bz
->f1
= new_f1
; /* next frame */
897 dev_kfree_skb(bch
->tx_skb
);
898 get_next_bframe(bch
);
904 * handle L1 state changes TE
908 ph_state_te(struct dchannel
*dch
)
911 printk(KERN_DEBUG
"%s: TE newstate %x\n",
912 __func__
, dch
->state
);
913 switch (dch
->state
) {
915 l1_event(dch
->l1
, HW_RESET_IND
);
918 l1_event(dch
->l1
, HW_DEACT_IND
);
922 l1_event(dch
->l1
, ANYSIGNAL
);
925 l1_event(dch
->l1
, INFO2
);
928 l1_event(dch
->l1
, INFO4_P8
);
934 * handle L1 state changes NT
938 handle_nt_timer3(struct dchannel
*dch
) {
939 struct hfc_pci
*hc
= dch
->hw
;
941 test_and_clear_bit(FLG_HFC_TIMER_T3
, &dch
->Flags
);
942 hc
->hw
.int_m1
&= ~HFCPCI_INTS_TIMER
;
943 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
945 test_and_set_bit(FLG_ACTIVE
, &dch
->Flags
);
946 if (test_bit(HFC_CFG_MASTER
, &hc
->cfg
))
947 hc
->hw
.mst_m
|= HFCPCI_MASTER
;
948 Write_hfc(hc
, HFCPCI_MST_MODE
, hc
->hw
.mst_m
);
949 _queue_data(&dch
->dev
.D
, PH_ACTIVATE_IND
,
950 MISDN_ID_ANY
, 0, NULL
, GFP_ATOMIC
);
954 ph_state_nt(struct dchannel
*dch
)
956 struct hfc_pci
*hc
= dch
->hw
;
959 printk(KERN_DEBUG
"%s: NT newstate %x\n",
960 __func__
, dch
->state
);
961 switch (dch
->state
) {
963 if (hc
->hw
.nt_timer
< 0) {
965 test_and_clear_bit(FLG_HFC_TIMER_T3
, &dch
->Flags
);
966 test_and_clear_bit(FLG_HFC_TIMER_T1
, &dch
->Flags
);
967 hc
->hw
.int_m1
&= ~HFCPCI_INTS_TIMER
;
968 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
969 /* Clear already pending ints */
970 (void) Read_hfc(hc
, HFCPCI_INT_S1
);
971 Write_hfc(hc
, HFCPCI_STATES
, 4 | HFCPCI_LOAD_STATE
);
973 Write_hfc(hc
, HFCPCI_STATES
, 4);
975 } else if (hc
->hw
.nt_timer
== 0) {
976 hc
->hw
.int_m1
|= HFCPCI_INTS_TIMER
;
977 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
978 hc
->hw
.nt_timer
= NT_T1_COUNT
;
979 hc
->hw
.ctmt
&= ~HFCPCI_AUTO_TIMER
;
980 hc
->hw
.ctmt
|= HFCPCI_TIM3_125
;
981 Write_hfc(hc
, HFCPCI_CTMT
, hc
->hw
.ctmt
|
983 test_and_clear_bit(FLG_HFC_TIMER_T3
, &dch
->Flags
);
984 test_and_set_bit(FLG_HFC_TIMER_T1
, &dch
->Flags
);
985 /* allow G2 -> G3 transition */
986 Write_hfc(hc
, HFCPCI_STATES
, 2 | HFCPCI_NT_G2_G3
);
988 Write_hfc(hc
, HFCPCI_STATES
, 2 | HFCPCI_NT_G2_G3
);
993 test_and_clear_bit(FLG_HFC_TIMER_T3
, &dch
->Flags
);
994 test_and_clear_bit(FLG_HFC_TIMER_T1
, &dch
->Flags
);
995 hc
->hw
.int_m1
&= ~HFCPCI_INTS_TIMER
;
996 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
997 test_and_clear_bit(FLG_ACTIVE
, &dch
->Flags
);
998 hc
->hw
.mst_m
&= ~HFCPCI_MASTER
;
999 Write_hfc(hc
, HFCPCI_MST_MODE
, hc
->hw
.mst_m
);
1000 test_and_clear_bit(FLG_L2_ACTIVATED
, &dch
->Flags
);
1001 _queue_data(&dch
->dev
.D
, PH_DEACTIVATE_IND
,
1002 MISDN_ID_ANY
, 0, NULL
, GFP_ATOMIC
);
1005 hc
->hw
.nt_timer
= 0;
1006 test_and_clear_bit(FLG_HFC_TIMER_T3
, &dch
->Flags
);
1007 test_and_clear_bit(FLG_HFC_TIMER_T1
, &dch
->Flags
);
1008 hc
->hw
.int_m1
&= ~HFCPCI_INTS_TIMER
;
1009 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
1012 if (!test_and_set_bit(FLG_HFC_TIMER_T3
, &dch
->Flags
)) {
1013 if (!test_and_clear_bit(FLG_L2_ACTIVATED
,
1015 handle_nt_timer3(dch
);
1018 test_and_clear_bit(FLG_HFC_TIMER_T1
, &dch
->Flags
);
1019 hc
->hw
.int_m1
|= HFCPCI_INTS_TIMER
;
1020 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
1021 hc
->hw
.nt_timer
= NT_T3_COUNT
;
1022 hc
->hw
.ctmt
&= ~HFCPCI_AUTO_TIMER
;
1023 hc
->hw
.ctmt
|= HFCPCI_TIM3_125
;
1024 Write_hfc(hc
, HFCPCI_CTMT
, hc
->hw
.ctmt
|
1032 ph_state(struct dchannel
*dch
)
1034 struct hfc_pci
*hc
= dch
->hw
;
1036 if (hc
->hw
.protocol
== ISDN_P_NT_S0
) {
1037 if (test_bit(FLG_HFC_TIMER_T3
, &dch
->Flags
) &&
1038 hc
->hw
.nt_timer
< 0)
1039 handle_nt_timer3(dch
);
1047 * Layer 1 callback function
1050 hfc_l1callback(struct dchannel
*dch
, u_int cmd
)
1052 struct hfc_pci
*hc
= dch
->hw
;
1057 if (test_bit(HFC_CFG_MASTER
, &hc
->cfg
))
1058 hc
->hw
.mst_m
|= HFCPCI_MASTER
;
1059 Write_hfc(hc
, HFCPCI_MST_MODE
, hc
->hw
.mst_m
);
1062 Write_hfc(hc
, HFCPCI_STATES
, HFCPCI_LOAD_STATE
| 3);
1065 Write_hfc(hc
, HFCPCI_STATES
, 3); /* HFC ST 2 */
1066 if (test_bit(HFC_CFG_MASTER
, &hc
->cfg
))
1067 hc
->hw
.mst_m
|= HFCPCI_MASTER
;
1068 Write_hfc(hc
, HFCPCI_MST_MODE
, hc
->hw
.mst_m
);
1069 Write_hfc(hc
, HFCPCI_STATES
, HFCPCI_ACTIVATE
|
1071 l1_event(dch
->l1
, HW_POWERUP_IND
);
1074 hc
->hw
.mst_m
&= ~HFCPCI_MASTER
;
1075 Write_hfc(hc
, HFCPCI_MST_MODE
, hc
->hw
.mst_m
);
1076 skb_queue_purge(&dch
->squeue
);
1078 dev_kfree_skb(dch
->tx_skb
);
1083 dev_kfree_skb(dch
->rx_skb
);
1086 test_and_clear_bit(FLG_TX_BUSY
, &dch
->Flags
);
1087 if (test_and_clear_bit(FLG_BUSY_TIMER
, &dch
->Flags
))
1088 del_timer(&dch
->timer
);
1090 case HW_POWERUP_REQ
:
1091 Write_hfc(hc
, HFCPCI_STATES
, HFCPCI_DO_ACTION
);
1093 case PH_ACTIVATE_IND
:
1094 test_and_set_bit(FLG_ACTIVE
, &dch
->Flags
);
1095 _queue_data(&dch
->dev
.D
, cmd
, MISDN_ID_ANY
, 0, NULL
,
1098 case PH_DEACTIVATE_IND
:
1099 test_and_clear_bit(FLG_ACTIVE
, &dch
->Flags
);
1100 _queue_data(&dch
->dev
.D
, cmd
, MISDN_ID_ANY
, 0, NULL
,
1104 if (dch
->debug
& DEBUG_HW
)
1105 printk(KERN_DEBUG
"%s: unknown command %x\n",
1116 tx_birq(struct bchannel
*bch
)
1118 if (bch
->tx_skb
&& bch
->tx_idx
< bch
->tx_skb
->len
)
1119 hfcpci_fill_fifo(bch
);
1121 dev_kfree_skb(bch
->tx_skb
);
1122 if (get_next_bframe(bch
))
1123 hfcpci_fill_fifo(bch
);
1128 tx_dirq(struct dchannel
*dch
)
1130 if (dch
->tx_skb
&& dch
->tx_idx
< dch
->tx_skb
->len
)
1131 hfcpci_fill_dfifo(dch
->hw
);
1133 dev_kfree_skb(dch
->tx_skb
);
1134 if (get_next_dframe(dch
))
1135 hfcpci_fill_dfifo(dch
->hw
);
1140 hfcpci_int(int intno
, void *dev_id
)
1142 struct hfc_pci
*hc
= dev_id
;
1144 struct bchannel
*bch
;
1147 spin_lock(&hc
->lock
);
1148 if (!(hc
->hw
.int_m2
& 0x08)) {
1149 spin_unlock(&hc
->lock
);
1150 return IRQ_NONE
; /* not initialised */
1152 stat
= Read_hfc(hc
, HFCPCI_STATUS
);
1153 if (HFCPCI_ANYINT
& stat
) {
1154 val
= Read_hfc(hc
, HFCPCI_INT_S1
);
1155 if (hc
->dch
.debug
& DEBUG_HW_DCHANNEL
)
1157 "HFC-PCI: stat(%02x) s1(%02x)\n", stat
, val
);
1160 spin_unlock(&hc
->lock
);
1165 if (hc
->dch
.debug
& DEBUG_HW_DCHANNEL
)
1166 printk(KERN_DEBUG
"HFC-PCI irq %x\n", val
);
1167 val
&= hc
->hw
.int_m1
;
1168 if (val
& 0x40) { /* state machine irq */
1169 exval
= Read_hfc(hc
, HFCPCI_STATES
) & 0xf;
1170 if (hc
->dch
.debug
& DEBUG_HW_DCHANNEL
)
1171 printk(KERN_DEBUG
"ph_state chg %d->%d\n",
1172 hc
->dch
.state
, exval
);
1173 hc
->dch
.state
= exval
;
1174 schedule_event(&hc
->dch
, FLG_PHCHANGE
);
1177 if (val
& 0x80) { /* timer irq */
1178 if (hc
->hw
.protocol
== ISDN_P_NT_S0
) {
1179 if ((--hc
->hw
.nt_timer
) < 0)
1180 schedule_event(&hc
->dch
, FLG_PHCHANGE
);
1183 Write_hfc(hc
, HFCPCI_CTMT
, hc
->hw
.ctmt
| HFCPCI_CLTIMER
);
1185 if (val
& 0x08) { /* B1 rx */
1186 bch
= Sel_BCS(hc
, hc
->hw
.bswapped
? 2 : 1);
1188 main_rec_hfcpci(bch
);
1189 else if (hc
->dch
.debug
)
1190 printk(KERN_DEBUG
"hfcpci spurious 0x08 IRQ\n");
1192 if (val
& 0x10) { /* B2 rx */
1193 bch
= Sel_BCS(hc
, 2);
1195 main_rec_hfcpci(bch
);
1196 else if (hc
->dch
.debug
)
1197 printk(KERN_DEBUG
"hfcpci spurious 0x10 IRQ\n");
1199 if (val
& 0x01) { /* B1 tx */
1200 bch
= Sel_BCS(hc
, hc
->hw
.bswapped
? 2 : 1);
1203 else if (hc
->dch
.debug
)
1204 printk(KERN_DEBUG
"hfcpci spurious 0x01 IRQ\n");
1206 if (val
& 0x02) { /* B2 tx */
1207 bch
= Sel_BCS(hc
, 2);
1210 else if (hc
->dch
.debug
)
1211 printk(KERN_DEBUG
"hfcpci spurious 0x02 IRQ\n");
1213 if (val
& 0x20) /* D rx */
1215 if (val
& 0x04) { /* D tx */
1216 if (test_and_clear_bit(FLG_BUSY_TIMER
, &hc
->dch
.Flags
))
1217 del_timer(&hc
->dch
.timer
);
1220 spin_unlock(&hc
->lock
);
1225 * timer callback for D-chan busy resolution. Currently no function
1228 hfcpci_dbusy_timer(struct timer_list
*t
)
1233 * activate/deactivate hardware for selected channels and mode
1236 mode_hfcpci(struct bchannel
*bch
, int bc
, int protocol
)
1238 struct hfc_pci
*hc
= bch
->hw
;
1240 u_char rx_slot
= 0, tx_slot
= 0, pcm_mode
;
1242 if (bch
->debug
& DEBUG_HW_BCHANNEL
)
1244 "HFCPCI bchannel protocol %x-->%x ch %x-->%x\n",
1245 bch
->state
, protocol
, bch
->nr
, bc
);
1248 pcm_mode
= (bc
>> 24) & 0xff;
1249 if (pcm_mode
) { /* PCM SLOT USE */
1250 if (!test_bit(HFC_CFG_PCM
, &hc
->cfg
))
1252 "%s: pcm channel id without HFC_CFG_PCM\n",
1254 rx_slot
= (bc
>> 8) & 0xff;
1255 tx_slot
= (bc
>> 16) & 0xff;
1257 } else if (test_bit(HFC_CFG_PCM
, &hc
->cfg
) && (protocol
> ISDN_P_NONE
))
1258 printk(KERN_WARNING
"%s: no pcm channel id but HFC_CFG_PCM\n",
1260 if (hc
->chanlimit
> 1) {
1261 hc
->hw
.bswapped
= 0; /* B1 and B2 normal mode */
1262 hc
->hw
.sctrl_e
&= ~0x80;
1265 if (protocol
!= ISDN_P_NONE
) {
1266 hc
->hw
.bswapped
= 1; /* B1 and B2 exchanged */
1267 hc
->hw
.sctrl_e
|= 0x80;
1269 hc
->hw
.bswapped
= 0; /* B1 and B2 normal mode */
1270 hc
->hw
.sctrl_e
&= ~0x80;
1274 hc
->hw
.bswapped
= 0; /* B1 and B2 normal mode */
1275 hc
->hw
.sctrl_e
&= ~0x80;
1279 case (-1): /* used for init */
1284 if (bch
->state
== ISDN_P_NONE
)
1287 hc
->hw
.sctrl
&= ~SCTRL_B2_ENA
;
1288 hc
->hw
.sctrl_r
&= ~SCTRL_B2_ENA
;
1290 hc
->hw
.sctrl
&= ~SCTRL_B1_ENA
;
1291 hc
->hw
.sctrl_r
&= ~SCTRL_B1_ENA
;
1294 hc
->hw
.fifo_en
&= ~HFCPCI_FIFOEN_B2
;
1295 hc
->hw
.int_m1
&= ~(HFCPCI_INTS_B2TRANS
|
1298 hc
->hw
.fifo_en
&= ~HFCPCI_FIFOEN_B1
;
1299 hc
->hw
.int_m1
&= ~(HFCPCI_INTS_B1TRANS
|
1302 #ifdef REVERSE_BITORDER
1304 hc
->hw
.cirm
&= 0x7f;
1306 hc
->hw
.cirm
&= 0xbf;
1308 bch
->state
= ISDN_P_NONE
;
1310 test_and_clear_bit(FLG_HDLC
, &bch
->Flags
);
1311 test_and_clear_bit(FLG_TRANSPARENT
, &bch
->Flags
);
1313 case (ISDN_P_B_RAW
):
1314 bch
->state
= protocol
;
1316 hfcpci_clear_fifo_rx(hc
, (fifo2
& 2) ? 1 : 0);
1317 hfcpci_clear_fifo_tx(hc
, (fifo2
& 2) ? 1 : 0);
1319 hc
->hw
.sctrl
|= SCTRL_B2_ENA
;
1320 hc
->hw
.sctrl_r
|= SCTRL_B2_ENA
;
1321 #ifdef REVERSE_BITORDER
1322 hc
->hw
.cirm
|= 0x80;
1325 hc
->hw
.sctrl
|= SCTRL_B1_ENA
;
1326 hc
->hw
.sctrl_r
|= SCTRL_B1_ENA
;
1327 #ifdef REVERSE_BITORDER
1328 hc
->hw
.cirm
|= 0x40;
1332 hc
->hw
.fifo_en
|= HFCPCI_FIFOEN_B2
;
1334 hc
->hw
.int_m1
|= (HFCPCI_INTS_B2TRANS
|
1337 hc
->hw
.conn
&= ~0x18;
1339 hc
->hw
.fifo_en
|= HFCPCI_FIFOEN_B1
;
1341 hc
->hw
.int_m1
|= (HFCPCI_INTS_B1TRANS
|
1344 hc
->hw
.conn
&= ~0x03;
1346 test_and_set_bit(FLG_TRANSPARENT
, &bch
->Flags
);
1348 case (ISDN_P_B_HDLC
):
1349 bch
->state
= protocol
;
1351 hfcpci_clear_fifo_rx(hc
, (fifo2
& 2) ? 1 : 0);
1352 hfcpci_clear_fifo_tx(hc
, (fifo2
& 2) ? 1 : 0);
1354 hc
->hw
.sctrl
|= SCTRL_B2_ENA
;
1355 hc
->hw
.sctrl_r
|= SCTRL_B2_ENA
;
1357 hc
->hw
.sctrl
|= SCTRL_B1_ENA
;
1358 hc
->hw
.sctrl_r
|= SCTRL_B1_ENA
;
1361 hc
->hw
.last_bfifo_cnt
[1] = 0;
1362 hc
->hw
.fifo_en
|= HFCPCI_FIFOEN_B2
;
1363 hc
->hw
.int_m1
|= (HFCPCI_INTS_B2TRANS
|
1366 hc
->hw
.conn
&= ~0x18;
1368 hc
->hw
.last_bfifo_cnt
[0] = 0;
1369 hc
->hw
.fifo_en
|= HFCPCI_FIFOEN_B1
;
1370 hc
->hw
.int_m1
|= (HFCPCI_INTS_B1TRANS
|
1373 hc
->hw
.conn
&= ~0x03;
1375 test_and_set_bit(FLG_HDLC
, &bch
->Flags
);
1378 printk(KERN_DEBUG
"prot not known %x\n", protocol
);
1379 return -ENOPROTOOPT
;
1381 if (test_bit(HFC_CFG_PCM
, &hc
->cfg
)) {
1382 if ((protocol
== ISDN_P_NONE
) ||
1383 (protocol
== -1)) { /* init case */
1387 if (test_bit(HFC_CFG_SW_DD_DU
, &hc
->cfg
)) {
1396 hc
->hw
.conn
&= 0xc7;
1397 hc
->hw
.conn
|= 0x08;
1398 printk(KERN_DEBUG
"%s: Write_hfc: B2_SSL 0x%x\n",
1400 printk(KERN_DEBUG
"%s: Write_hfc: B2_RSL 0x%x\n",
1402 Write_hfc(hc
, HFCPCI_B2_SSL
, tx_slot
);
1403 Write_hfc(hc
, HFCPCI_B2_RSL
, rx_slot
);
1405 hc
->hw
.conn
&= 0xf8;
1406 hc
->hw
.conn
|= 0x01;
1407 printk(KERN_DEBUG
"%s: Write_hfc: B1_SSL 0x%x\n",
1409 printk(KERN_DEBUG
"%s: Write_hfc: B1_RSL 0x%x\n",
1411 Write_hfc(hc
, HFCPCI_B1_SSL
, tx_slot
);
1412 Write_hfc(hc
, HFCPCI_B1_RSL
, rx_slot
);
1415 Write_hfc(hc
, HFCPCI_SCTRL_E
, hc
->hw
.sctrl_e
);
1416 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
1417 Write_hfc(hc
, HFCPCI_FIFO_EN
, hc
->hw
.fifo_en
);
1418 Write_hfc(hc
, HFCPCI_SCTRL
, hc
->hw
.sctrl
);
1419 Write_hfc(hc
, HFCPCI_SCTRL_R
, hc
->hw
.sctrl_r
);
1420 Write_hfc(hc
, HFCPCI_CTMT
, hc
->hw
.ctmt
);
1421 Write_hfc(hc
, HFCPCI_CONNECT
, hc
->hw
.conn
);
1422 #ifdef REVERSE_BITORDER
1423 Write_hfc(hc
, HFCPCI_CIRM
, hc
->hw
.cirm
);
1429 set_hfcpci_rxtest(struct bchannel
*bch
, int protocol
, int chan
)
1431 struct hfc_pci
*hc
= bch
->hw
;
1433 if (bch
->debug
& DEBUG_HW_BCHANNEL
)
1435 "HFCPCI bchannel test rx protocol %x-->%x ch %x-->%x\n",
1436 bch
->state
, protocol
, bch
->nr
, chan
);
1437 if (bch
->nr
!= chan
) {
1439 "HFCPCI rxtest wrong channel parameter %x/%x\n",
1444 case (ISDN_P_B_RAW
):
1445 bch
->state
= protocol
;
1446 hfcpci_clear_fifo_rx(hc
, (chan
& 2) ? 1 : 0);
1448 hc
->hw
.sctrl_r
|= SCTRL_B2_ENA
;
1449 hc
->hw
.fifo_en
|= HFCPCI_FIFOEN_B2RX
;
1451 hc
->hw
.int_m1
|= HFCPCI_INTS_B2REC
;
1453 hc
->hw
.conn
&= ~0x18;
1454 #ifdef REVERSE_BITORDER
1455 hc
->hw
.cirm
|= 0x80;
1458 hc
->hw
.sctrl_r
|= SCTRL_B1_ENA
;
1459 hc
->hw
.fifo_en
|= HFCPCI_FIFOEN_B1RX
;
1461 hc
->hw
.int_m1
|= HFCPCI_INTS_B1REC
;
1463 hc
->hw
.conn
&= ~0x03;
1464 #ifdef REVERSE_BITORDER
1465 hc
->hw
.cirm
|= 0x40;
1469 case (ISDN_P_B_HDLC
):
1470 bch
->state
= protocol
;
1471 hfcpci_clear_fifo_rx(hc
, (chan
& 2) ? 1 : 0);
1473 hc
->hw
.sctrl_r
|= SCTRL_B2_ENA
;
1474 hc
->hw
.last_bfifo_cnt
[1] = 0;
1475 hc
->hw
.fifo_en
|= HFCPCI_FIFOEN_B2RX
;
1476 hc
->hw
.int_m1
|= HFCPCI_INTS_B2REC
;
1478 hc
->hw
.conn
&= ~0x18;
1480 hc
->hw
.sctrl_r
|= SCTRL_B1_ENA
;
1481 hc
->hw
.last_bfifo_cnt
[0] = 0;
1482 hc
->hw
.fifo_en
|= HFCPCI_FIFOEN_B1RX
;
1483 hc
->hw
.int_m1
|= HFCPCI_INTS_B1REC
;
1485 hc
->hw
.conn
&= ~0x03;
1489 printk(KERN_DEBUG
"prot not known %x\n", protocol
);
1490 return -ENOPROTOOPT
;
1492 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
1493 Write_hfc(hc
, HFCPCI_FIFO_EN
, hc
->hw
.fifo_en
);
1494 Write_hfc(hc
, HFCPCI_SCTRL_R
, hc
->hw
.sctrl_r
);
1495 Write_hfc(hc
, HFCPCI_CTMT
, hc
->hw
.ctmt
);
1496 Write_hfc(hc
, HFCPCI_CONNECT
, hc
->hw
.conn
);
1497 #ifdef REVERSE_BITORDER
1498 Write_hfc(hc
, HFCPCI_CIRM
, hc
->hw
.cirm
);
1504 deactivate_bchannel(struct bchannel
*bch
)
1506 struct hfc_pci
*hc
= bch
->hw
;
1509 spin_lock_irqsave(&hc
->lock
, flags
);
1510 mISDN_clear_bchannel(bch
);
1511 mode_hfcpci(bch
, bch
->nr
, ISDN_P_NONE
);
1512 spin_unlock_irqrestore(&hc
->lock
, flags
);
1516 * Layer 1 B-channel hardware access
1519 channel_bctrl(struct bchannel
*bch
, struct mISDN_ctrl_req
*cq
)
1521 return mISDN_ctrl_bchannel(bch
, cq
);
1524 hfc_bctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
1526 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1527 struct hfc_pci
*hc
= bch
->hw
;
1531 if (bch
->debug
& DEBUG_HW
)
1532 printk(KERN_DEBUG
"%s: cmd:%x %p\n", __func__
, cmd
, arg
);
1535 spin_lock_irqsave(&hc
->lock
, flags
);
1536 ret
= set_hfcpci_rxtest(bch
, ISDN_P_B_RAW
, (int)(long)arg
);
1537 spin_unlock_irqrestore(&hc
->lock
, flags
);
1539 case HW_TESTRX_HDLC
:
1540 spin_lock_irqsave(&hc
->lock
, flags
);
1541 ret
= set_hfcpci_rxtest(bch
, ISDN_P_B_HDLC
, (int)(long)arg
);
1542 spin_unlock_irqrestore(&hc
->lock
, flags
);
1545 spin_lock_irqsave(&hc
->lock
, flags
);
1546 mode_hfcpci(bch
, bch
->nr
, ISDN_P_NONE
);
1547 spin_unlock_irqrestore(&hc
->lock
, flags
);
1551 test_and_clear_bit(FLG_OPEN
, &bch
->Flags
);
1552 deactivate_bchannel(bch
);
1553 ch
->protocol
= ISDN_P_NONE
;
1555 module_put(THIS_MODULE
);
1558 case CONTROL_CHANNEL
:
1559 ret
= channel_bctrl(bch
, arg
);
1562 printk(KERN_WARNING
"%s: unknown prim(%x)\n",
1569 * Layer2 -> Layer 1 Dchannel data
1572 hfcpci_l2l1D(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
1574 struct mISDNdevice
*dev
= container_of(ch
, struct mISDNdevice
, D
);
1575 struct dchannel
*dch
= container_of(dev
, struct dchannel
, dev
);
1576 struct hfc_pci
*hc
= dch
->hw
;
1578 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1584 spin_lock_irqsave(&hc
->lock
, flags
);
1585 ret
= dchannel_senddata(dch
, skb
);
1586 if (ret
> 0) { /* direct TX */
1587 id
= hh
->id
; /* skb can be freed */
1588 hfcpci_fill_dfifo(dch
->hw
);
1590 spin_unlock_irqrestore(&hc
->lock
, flags
);
1591 queue_ch_frame(ch
, PH_DATA_CNF
, id
, NULL
);
1593 spin_unlock_irqrestore(&hc
->lock
, flags
);
1595 case PH_ACTIVATE_REQ
:
1596 spin_lock_irqsave(&hc
->lock
, flags
);
1597 if (hc
->hw
.protocol
== ISDN_P_NT_S0
) {
1599 if (test_bit(HFC_CFG_MASTER
, &hc
->cfg
))
1600 hc
->hw
.mst_m
|= HFCPCI_MASTER
;
1601 Write_hfc(hc
, HFCPCI_MST_MODE
, hc
->hw
.mst_m
);
1602 if (test_bit(FLG_ACTIVE
, &dch
->Flags
)) {
1603 spin_unlock_irqrestore(&hc
->lock
, flags
);
1604 _queue_data(&dch
->dev
.D
, PH_ACTIVATE_IND
,
1605 MISDN_ID_ANY
, 0, NULL
, GFP_ATOMIC
);
1608 test_and_set_bit(FLG_L2_ACTIVATED
, &dch
->Flags
);
1609 Write_hfc(hc
, HFCPCI_STATES
, HFCPCI_ACTIVATE
|
1610 HFCPCI_DO_ACTION
| 1);
1612 ret
= l1_event(dch
->l1
, hh
->prim
);
1613 spin_unlock_irqrestore(&hc
->lock
, flags
);
1615 case PH_DEACTIVATE_REQ
:
1616 test_and_clear_bit(FLG_L2_ACTIVATED
, &dch
->Flags
);
1617 spin_lock_irqsave(&hc
->lock
, flags
);
1618 if (hc
->hw
.protocol
== ISDN_P_NT_S0
) {
1619 /* prepare deactivation */
1620 Write_hfc(hc
, HFCPCI_STATES
, 0x40);
1621 skb_queue_purge(&dch
->squeue
);
1623 dev_kfree_skb(dch
->tx_skb
);
1628 dev_kfree_skb(dch
->rx_skb
);
1631 test_and_clear_bit(FLG_TX_BUSY
, &dch
->Flags
);
1632 if (test_and_clear_bit(FLG_BUSY_TIMER
, &dch
->Flags
))
1633 del_timer(&dch
->timer
);
1635 if (test_and_clear_bit(FLG_L1_BUSY
, &dch
->Flags
))
1636 dchannel_sched_event(&hc
->dch
, D_CLEARBUSY
);
1638 hc
->hw
.mst_m
&= ~HFCPCI_MASTER
;
1639 Write_hfc(hc
, HFCPCI_MST_MODE
, hc
->hw
.mst_m
);
1642 ret
= l1_event(dch
->l1
, hh
->prim
);
1644 spin_unlock_irqrestore(&hc
->lock
, flags
);
1653 * Layer2 -> Layer 1 Bchannel data
1656 hfcpci_l2l1B(struct mISDNchannel
*ch
, struct sk_buff
*skb
)
1658 struct bchannel
*bch
= container_of(ch
, struct bchannel
, ch
);
1659 struct hfc_pci
*hc
= bch
->hw
;
1661 struct mISDNhead
*hh
= mISDN_HEAD_P(skb
);
1662 unsigned long flags
;
1666 spin_lock_irqsave(&hc
->lock
, flags
);
1667 ret
= bchannel_senddata(bch
, skb
);
1668 if (ret
> 0) { /* direct TX */
1669 hfcpci_fill_fifo(bch
);
1672 spin_unlock_irqrestore(&hc
->lock
, flags
);
1674 case PH_ACTIVATE_REQ
:
1675 spin_lock_irqsave(&hc
->lock
, flags
);
1676 if (!test_and_set_bit(FLG_ACTIVE
, &bch
->Flags
))
1677 ret
= mode_hfcpci(bch
, bch
->nr
, ch
->protocol
);
1680 spin_unlock_irqrestore(&hc
->lock
, flags
);
1682 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
, 0,
1685 case PH_DEACTIVATE_REQ
:
1686 deactivate_bchannel(bch
);
1687 _queue_data(ch
, PH_DEACTIVATE_IND
, MISDN_ID_ANY
, 0,
1698 * called for card init message
1702 inithfcpci(struct hfc_pci
*hc
)
1704 printk(KERN_DEBUG
"inithfcpci: entered\n");
1705 timer_setup(&hc
->dch
.timer
, hfcpci_dbusy_timer
, 0);
1707 mode_hfcpci(&hc
->bch
[0], 1, -1);
1708 mode_hfcpci(&hc
->bch
[1], 2, -1);
1713 init_card(struct hfc_pci
*hc
)
1718 printk(KERN_DEBUG
"init_card: entered\n");
1721 spin_lock_irqsave(&hc
->lock
, flags
);
1723 spin_unlock_irqrestore(&hc
->lock
, flags
);
1724 if (request_irq(hc
->irq
, hfcpci_int
, IRQF_SHARED
, "HFC PCI", hc
)) {
1726 "mISDN: couldn't get interrupt %d\n", hc
->irq
);
1729 spin_lock_irqsave(&hc
->lock
, flags
);
1734 * Finally enable IRQ output
1735 * this is only allowed, if an IRQ routine is already
1736 * established for this HFC, so don't do that earlier
1739 spin_unlock_irqrestore(&hc
->lock
, flags
);
1741 set_current_state(TASK_UNINTERRUPTIBLE
);
1742 schedule_timeout((80 * HZ
) / 1000);
1743 printk(KERN_INFO
"HFC PCI: IRQ %d count %d\n",
1744 hc
->irq
, hc
->irqcnt
);
1745 /* now switch timer interrupt off */
1746 spin_lock_irqsave(&hc
->lock
, flags
);
1747 hc
->hw
.int_m1
&= ~HFCPCI_INTS_TIMER
;
1748 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
1749 /* reinit mode reg */
1750 Write_hfc(hc
, HFCPCI_MST_MODE
, hc
->hw
.mst_m
);
1753 "HFC PCI: IRQ(%d) getting no interrupts "
1754 "during init %d\n", hc
->irq
, 4 - cnt
);
1762 spin_unlock_irqrestore(&hc
->lock
, flags
);
1768 spin_unlock_irqrestore(&hc
->lock
, flags
);
1769 free_irq(hc
->irq
, hc
);
1774 channel_ctrl(struct hfc_pci
*hc
, struct mISDN_ctrl_req
*cq
)
1780 case MISDN_CTRL_GETOP
:
1781 cq
->op
= MISDN_CTRL_LOOP
| MISDN_CTRL_CONNECT
|
1782 MISDN_CTRL_DISCONNECT
| MISDN_CTRL_L1_TIMER3
;
1784 case MISDN_CTRL_LOOP
:
1785 /* channel 0 disabled loop */
1786 if (cq
->channel
< 0 || cq
->channel
> 2) {
1790 if (cq
->channel
& 1) {
1791 if (test_bit(HFC_CFG_SW_DD_DU
, &hc
->cfg
))
1795 printk(KERN_DEBUG
"%s: Write_hfc: B1_SSL/RSL 0x%x\n",
1797 Write_hfc(hc
, HFCPCI_B1_SSL
, slot
);
1798 Write_hfc(hc
, HFCPCI_B1_RSL
, slot
);
1799 hc
->hw
.conn
= (hc
->hw
.conn
& ~7) | 6;
1800 Write_hfc(hc
, HFCPCI_CONNECT
, hc
->hw
.conn
);
1802 if (cq
->channel
& 2) {
1803 if (test_bit(HFC_CFG_SW_DD_DU
, &hc
->cfg
))
1807 printk(KERN_DEBUG
"%s: Write_hfc: B2_SSL/RSL 0x%x\n",
1809 Write_hfc(hc
, HFCPCI_B2_SSL
, slot
);
1810 Write_hfc(hc
, HFCPCI_B2_RSL
, slot
);
1811 hc
->hw
.conn
= (hc
->hw
.conn
& ~0x38) | 0x30;
1812 Write_hfc(hc
, HFCPCI_CONNECT
, hc
->hw
.conn
);
1814 if (cq
->channel
& 3)
1815 hc
->hw
.trm
|= 0x80; /* enable IOM-loop */
1817 hc
->hw
.conn
= (hc
->hw
.conn
& ~0x3f) | 0x09;
1818 Write_hfc(hc
, HFCPCI_CONNECT
, hc
->hw
.conn
);
1819 hc
->hw
.trm
&= 0x7f; /* disable IOM-loop */
1821 Write_hfc(hc
, HFCPCI_TRM
, hc
->hw
.trm
);
1823 case MISDN_CTRL_CONNECT
:
1824 if (cq
->channel
== cq
->p1
) {
1828 if (cq
->channel
< 1 || cq
->channel
> 2 ||
1829 cq
->p1
< 1 || cq
->p1
> 2) {
1833 if (test_bit(HFC_CFG_SW_DD_DU
, &hc
->cfg
))
1837 printk(KERN_DEBUG
"%s: Write_hfc: B1_SSL/RSL 0x%x\n",
1839 Write_hfc(hc
, HFCPCI_B1_SSL
, slot
);
1840 Write_hfc(hc
, HFCPCI_B2_RSL
, slot
);
1841 if (test_bit(HFC_CFG_SW_DD_DU
, &hc
->cfg
))
1845 printk(KERN_DEBUG
"%s: Write_hfc: B2_SSL/RSL 0x%x\n",
1847 Write_hfc(hc
, HFCPCI_B2_SSL
, slot
);
1848 Write_hfc(hc
, HFCPCI_B1_RSL
, slot
);
1849 hc
->hw
.conn
= (hc
->hw
.conn
& ~0x3f) | 0x36;
1850 Write_hfc(hc
, HFCPCI_CONNECT
, hc
->hw
.conn
);
1852 Write_hfc(hc
, HFCPCI_TRM
, hc
->hw
.trm
);
1854 case MISDN_CTRL_DISCONNECT
:
1855 hc
->hw
.conn
= (hc
->hw
.conn
& ~0x3f) | 0x09;
1856 Write_hfc(hc
, HFCPCI_CONNECT
, hc
->hw
.conn
);
1857 hc
->hw
.trm
&= 0x7f; /* disable IOM-loop */
1859 case MISDN_CTRL_L1_TIMER3
:
1860 ret
= l1_event(hc
->dch
.l1
, HW_TIMER3_VALUE
| (cq
->p1
& 0xff));
1863 printk(KERN_WARNING
"%s: unknown Op %x\n",
1872 open_dchannel(struct hfc_pci
*hc
, struct mISDNchannel
*ch
,
1873 struct channel_req
*rq
)
1877 if (debug
& DEBUG_HW_OPEN
)
1878 printk(KERN_DEBUG
"%s: dev(%d) open from %p\n", __func__
,
1879 hc
->dch
.dev
.id
, __builtin_return_address(0));
1880 if (rq
->protocol
== ISDN_P_NONE
)
1882 if (rq
->adr
.channel
== 1) {
1883 /* TODO: E-Channel */
1886 if (!hc
->initdone
) {
1887 if (rq
->protocol
== ISDN_P_TE_S0
) {
1888 err
= create_l1(&hc
->dch
, hfc_l1callback
);
1892 hc
->hw
.protocol
= rq
->protocol
;
1893 ch
->protocol
= rq
->protocol
;
1894 err
= init_card(hc
);
1898 if (rq
->protocol
!= ch
->protocol
) {
1899 if (hc
->hw
.protocol
== ISDN_P_TE_S0
)
1900 l1_event(hc
->dch
.l1
, CLOSE_CHANNEL
);
1901 if (rq
->protocol
== ISDN_P_TE_S0
) {
1902 err
= create_l1(&hc
->dch
, hfc_l1callback
);
1906 hc
->hw
.protocol
= rq
->protocol
;
1907 ch
->protocol
= rq
->protocol
;
1912 if (((ch
->protocol
== ISDN_P_NT_S0
) && (hc
->dch
.state
== 3)) ||
1913 ((ch
->protocol
== ISDN_P_TE_S0
) && (hc
->dch
.state
== 7))) {
1914 _queue_data(ch
, PH_ACTIVATE_IND
, MISDN_ID_ANY
,
1915 0, NULL
, GFP_KERNEL
);
1918 if (!try_module_get(THIS_MODULE
))
1919 printk(KERN_WARNING
"%s:cannot get module\n", __func__
);
1924 open_bchannel(struct hfc_pci
*hc
, struct channel_req
*rq
)
1926 struct bchannel
*bch
;
1928 if (rq
->adr
.channel
== 0 || rq
->adr
.channel
> 2)
1930 if (rq
->protocol
== ISDN_P_NONE
)
1932 bch
= &hc
->bch
[rq
->adr
.channel
- 1];
1933 if (test_and_set_bit(FLG_OPEN
, &bch
->Flags
))
1934 return -EBUSY
; /* b-channel can be only open once */
1935 bch
->ch
.protocol
= rq
->protocol
;
1936 rq
->ch
= &bch
->ch
; /* TODO: E-channel */
1937 if (!try_module_get(THIS_MODULE
))
1938 printk(KERN_WARNING
"%s:cannot get module\n", __func__
);
1943 * device control function
1946 hfc_dctrl(struct mISDNchannel
*ch
, u_int cmd
, void *arg
)
1948 struct mISDNdevice
*dev
= container_of(ch
, struct mISDNdevice
, D
);
1949 struct dchannel
*dch
= container_of(dev
, struct dchannel
, dev
);
1950 struct hfc_pci
*hc
= dch
->hw
;
1951 struct channel_req
*rq
;
1954 if (dch
->debug
& DEBUG_HW
)
1955 printk(KERN_DEBUG
"%s: cmd:%x %p\n",
1956 __func__
, cmd
, arg
);
1960 if ((rq
->protocol
== ISDN_P_TE_S0
) ||
1961 (rq
->protocol
== ISDN_P_NT_S0
))
1962 err
= open_dchannel(hc
, ch
, rq
);
1964 err
= open_bchannel(hc
, rq
);
1967 if (debug
& DEBUG_HW_OPEN
)
1968 printk(KERN_DEBUG
"%s: dev(%d) close from %p\n",
1969 __func__
, hc
->dch
.dev
.id
,
1970 __builtin_return_address(0));
1971 module_put(THIS_MODULE
);
1973 case CONTROL_CHANNEL
:
1974 err
= channel_ctrl(hc
, arg
);
1977 if (dch
->debug
& DEBUG_HW
)
1978 printk(KERN_DEBUG
"%s: unknown command %x\n",
1986 setup_hw(struct hfc_pci
*hc
)
1990 printk(KERN_INFO
"mISDN: HFC-PCI driver %s\n", hfcpci_revision
);
1993 pci_set_master(hc
->pdev
);
1995 printk(KERN_WARNING
"HFC-PCI: No IRQ for PCI card found\n");
1999 (char __iomem
*)(unsigned long)hc
->pdev
->resource
[1].start
;
2001 if (!hc
->hw
.pci_io
) {
2002 printk(KERN_WARNING
"HFC-PCI: No IO-Mem for PCI card found\n");
2005 /* Allocate memory for FIFOS */
2006 /* the memory needs to be on a 32k boundary within the first 4G */
2007 pci_set_dma_mask(hc
->pdev
, 0xFFFF8000);
2008 buffer
= pci_alloc_consistent(hc
->pdev
, 0x8000, &hc
->hw
.dmahandle
);
2009 /* We silently assume the address is okay if nonzero */
2012 "HFC-PCI: Error allocating memory for FIFO!\n");
2015 hc
->hw
.fifos
= buffer
;
2016 pci_write_config_dword(hc
->pdev
, 0x80, hc
->hw
.dmahandle
);
2017 hc
->hw
.pci_io
= ioremap((ulong
) hc
->hw
.pci_io
, 256);
2018 if (unlikely(!hc
->hw
.pci_io
)) {
2020 "HFC-PCI: Error in ioremap for PCI!\n");
2021 pci_free_consistent(hc
->pdev
, 0x8000, hc
->hw
.fifos
,
2027 "HFC-PCI: defined at mem %#lx fifo %p(%pad) IRQ %d HZ %d\n",
2028 (u_long
) hc
->hw
.pci_io
, hc
->hw
.fifos
,
2029 &hc
->hw
.dmahandle
, hc
->irq
, HZ
);
2031 /* enable memory mapped ports, disable busmaster */
2032 pci_write_config_word(hc
->pdev
, PCI_COMMAND
, PCI_ENA_MEMIO
);
2036 Write_hfc(hc
, HFCPCI_INT_M1
, hc
->hw
.int_m1
);
2037 /* At this point the needed PCI config is done */
2038 /* fifos are still not enabled */
2039 timer_setup(&hc
->hw
.timer
, hfcpci_Timer
, 0);
2040 /* default PCM master */
2041 test_and_set_bit(HFC_CFG_MASTER
, &hc
->cfg
);
2046 release_card(struct hfc_pci
*hc
) {
2049 spin_lock_irqsave(&hc
->lock
, flags
);
2050 hc
->hw
.int_m2
= 0; /* interrupt output off ! */
2052 mode_hfcpci(&hc
->bch
[0], 1, ISDN_P_NONE
);
2053 mode_hfcpci(&hc
->bch
[1], 2, ISDN_P_NONE
);
2054 if (hc
->dch
.timer
.function
!= NULL
) {
2055 del_timer(&hc
->dch
.timer
);
2056 hc
->dch
.timer
.function
= NULL
;
2058 spin_unlock_irqrestore(&hc
->lock
, flags
);
2059 if (hc
->hw
.protocol
== ISDN_P_TE_S0
)
2060 l1_event(hc
->dch
.l1
, CLOSE_CHANNEL
);
2062 free_irq(hc
->irq
, hc
);
2063 release_io_hfcpci(hc
); /* must release after free_irq! */
2064 mISDN_unregister_device(&hc
->dch
.dev
);
2065 mISDN_freebchannel(&hc
->bch
[1]);
2066 mISDN_freebchannel(&hc
->bch
[0]);
2067 mISDN_freedchannel(&hc
->dch
);
2068 pci_set_drvdata(hc
->pdev
, NULL
);
2073 setup_card(struct hfc_pci
*card
)
2077 char name
[MISDN_MAX_IDLEN
];
2079 card
->dch
.debug
= debug
;
2080 spin_lock_init(&card
->lock
);
2081 mISDN_initdchannel(&card
->dch
, MAX_DFRAME_LEN_L1
, ph_state
);
2082 card
->dch
.hw
= card
;
2083 card
->dch
.dev
.Dprotocols
= (1 << ISDN_P_TE_S0
) | (1 << ISDN_P_NT_S0
);
2084 card
->dch
.dev
.Bprotocols
= (1 << (ISDN_P_B_RAW
& ISDN_P_B_MASK
)) |
2085 (1 << (ISDN_P_B_HDLC
& ISDN_P_B_MASK
));
2086 card
->dch
.dev
.D
.send
= hfcpci_l2l1D
;
2087 card
->dch
.dev
.D
.ctrl
= hfc_dctrl
;
2088 card
->dch
.dev
.nrbchan
= 2;
2089 for (i
= 0; i
< 2; i
++) {
2090 card
->bch
[i
].nr
= i
+ 1;
2091 set_channelmap(i
+ 1, card
->dch
.dev
.channelmap
);
2092 card
->bch
[i
].debug
= debug
;
2093 mISDN_initbchannel(&card
->bch
[i
], MAX_DATA_MEM
, poll
>> 1);
2094 card
->bch
[i
].hw
= card
;
2095 card
->bch
[i
].ch
.send
= hfcpci_l2l1B
;
2096 card
->bch
[i
].ch
.ctrl
= hfc_bctrl
;
2097 card
->bch
[i
].ch
.nr
= i
+ 1;
2098 list_add(&card
->bch
[i
].ch
.list
, &card
->dch
.dev
.bchannels
);
2100 err
= setup_hw(card
);
2103 snprintf(name
, MISDN_MAX_IDLEN
- 1, "hfc-pci.%d", HFC_cnt
+ 1);
2104 err
= mISDN_register_device(&card
->dch
.dev
, &card
->pdev
->dev
, name
);
2108 printk(KERN_INFO
"HFC %d cards installed\n", HFC_cnt
);
2111 mISDN_freebchannel(&card
->bch
[1]);
2112 mISDN_freebchannel(&card
->bch
[0]);
2113 mISDN_freedchannel(&card
->dch
);
2118 /* private data in the PCI devices list */
2125 static const struct _hfc_map hfc_map
[] =
2127 {HFC_CCD_2BD0
, 0, "CCD/Billion/Asuscom 2BD0"},
2128 {HFC_CCD_B000
, 0, "Billion B000"},
2129 {HFC_CCD_B006
, 0, "Billion B006"},
2130 {HFC_CCD_B007
, 0, "Billion B007"},
2131 {HFC_CCD_B008
, 0, "Billion B008"},
2132 {HFC_CCD_B009
, 0, "Billion B009"},
2133 {HFC_CCD_B00A
, 0, "Billion B00A"},
2134 {HFC_CCD_B00B
, 0, "Billion B00B"},
2135 {HFC_CCD_B00C
, 0, "Billion B00C"},
2136 {HFC_CCD_B100
, 0, "Seyeon B100"},
2137 {HFC_CCD_B700
, 0, "Primux II S0 B700"},
2138 {HFC_CCD_B701
, 0, "Primux II S0 NT B701"},
2139 {HFC_ABOCOM_2BD1
, 0, "Abocom/Magitek 2BD1"},
2140 {HFC_ASUS_0675
, 0, "Asuscom/Askey 675"},
2141 {HFC_BERKOM_TCONCEPT
, 0, "German telekom T-Concept"},
2142 {HFC_BERKOM_A1T
, 0, "German telekom A1T"},
2143 {HFC_ANIGMA_MC145575
, 0, "Motorola MC145575"},
2144 {HFC_ZOLTRIX_2BD0
, 0, "Zoltrix 2BD0"},
2145 {HFC_DIGI_DF_M_IOM2_E
, 0,
2146 "Digi International DataFire Micro V IOM2 (Europe)"},
2147 {HFC_DIGI_DF_M_E
, 0,
2148 "Digi International DataFire Micro V (Europe)"},
2149 {HFC_DIGI_DF_M_IOM2_A
, 0,
2150 "Digi International DataFire Micro V IOM2 (North America)"},
2151 {HFC_DIGI_DF_M_A
, 0,
2152 "Digi International DataFire Micro V (North America)"},
2153 {HFC_SITECOM_DC105V2
, 0, "Sitecom Connectivity DC-105 ISDN TA"},
2157 static const struct pci_device_id hfc_ids
[] =
2159 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_2BD0
),
2160 (unsigned long) &hfc_map
[0] },
2161 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B000
),
2162 (unsigned long) &hfc_map
[1] },
2163 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B006
),
2164 (unsigned long) &hfc_map
[2] },
2165 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B007
),
2166 (unsigned long) &hfc_map
[3] },
2167 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B008
),
2168 (unsigned long) &hfc_map
[4] },
2169 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B009
),
2170 (unsigned long) &hfc_map
[5] },
2171 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B00A
),
2172 (unsigned long) &hfc_map
[6] },
2173 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B00B
),
2174 (unsigned long) &hfc_map
[7] },
2175 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B00C
),
2176 (unsigned long) &hfc_map
[8] },
2177 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B100
),
2178 (unsigned long) &hfc_map
[9] },
2179 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B700
),
2180 (unsigned long) &hfc_map
[10] },
2181 { PCI_VDEVICE(CCD
, PCI_DEVICE_ID_CCD_B701
),
2182 (unsigned long) &hfc_map
[11] },
2183 { PCI_VDEVICE(ABOCOM
, PCI_DEVICE_ID_ABOCOM_2BD1
),
2184 (unsigned long) &hfc_map
[12] },
2185 { PCI_VDEVICE(ASUSTEK
, PCI_DEVICE_ID_ASUSTEK_0675
),
2186 (unsigned long) &hfc_map
[13] },
2187 { PCI_VDEVICE(BERKOM
, PCI_DEVICE_ID_BERKOM_T_CONCEPT
),
2188 (unsigned long) &hfc_map
[14] },
2189 { PCI_VDEVICE(BERKOM
, PCI_DEVICE_ID_BERKOM_A1T
),
2190 (unsigned long) &hfc_map
[15] },
2191 { PCI_VDEVICE(ANIGMA
, PCI_DEVICE_ID_ANIGMA_MC145575
),
2192 (unsigned long) &hfc_map
[16] },
2193 { PCI_VDEVICE(ZOLTRIX
, PCI_DEVICE_ID_ZOLTRIX_2BD0
),
2194 (unsigned long) &hfc_map
[17] },
2195 { PCI_VDEVICE(DIGI
, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E
),
2196 (unsigned long) &hfc_map
[18] },
2197 { PCI_VDEVICE(DIGI
, PCI_DEVICE_ID_DIGI_DF_M_E
),
2198 (unsigned long) &hfc_map
[19] },
2199 { PCI_VDEVICE(DIGI
, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A
),
2200 (unsigned long) &hfc_map
[20] },
2201 { PCI_VDEVICE(DIGI
, PCI_DEVICE_ID_DIGI_DF_M_A
),
2202 (unsigned long) &hfc_map
[21] },
2203 { PCI_VDEVICE(SITECOM
, PCI_DEVICE_ID_SITECOM_DC105V2
),
2204 (unsigned long) &hfc_map
[22] },
2209 hfc_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
2212 struct hfc_pci
*card
;
2213 struct _hfc_map
*m
= (struct _hfc_map
*)ent
->driver_data
;
2215 card
= kzalloc(sizeof(struct hfc_pci
), GFP_KERNEL
);
2217 printk(KERN_ERR
"No kmem for HFC card\n");
2221 card
->subtype
= m
->subtype
;
2222 err
= pci_enable_device(pdev
);
2228 printk(KERN_INFO
"mISDN_hfcpci: found adapter %s at %s\n",
2229 m
->name
, pci_name(pdev
));
2231 card
->irq
= pdev
->irq
;
2232 pci_set_drvdata(pdev
, card
);
2233 err
= setup_card(card
);
2235 pci_set_drvdata(pdev
, NULL
);
2240 hfc_remove_pci(struct pci_dev
*pdev
)
2242 struct hfc_pci
*card
= pci_get_drvdata(pdev
);
2248 printk(KERN_DEBUG
"%s: drvdata already removed\n",
2253 static struct pci_driver hfc_driver
= {
2256 .remove
= hfc_remove_pci
,
2257 .id_table
= hfc_ids
,
2261 _hfcpci_softirq(struct device
*dev
, void *unused
)
2263 struct hfc_pci
*hc
= dev_get_drvdata(dev
);
2264 struct bchannel
*bch
;
2268 if (hc
->hw
.int_m2
& HFCPCI_IRQ_ENABLE
) {
2269 spin_lock(&hc
->lock
);
2270 bch
= Sel_BCS(hc
, hc
->hw
.bswapped
? 2 : 1);
2271 if (bch
&& bch
->state
== ISDN_P_B_RAW
) { /* B1 rx&tx */
2272 main_rec_hfcpci(bch
);
2275 bch
= Sel_BCS(hc
, hc
->hw
.bswapped
? 1 : 2);
2276 if (bch
&& bch
->state
== ISDN_P_B_RAW
) { /* B2 rx&tx */
2277 main_rec_hfcpci(bch
);
2280 spin_unlock(&hc
->lock
);
2286 hfcpci_softirq(struct timer_list
*unused
)
2288 WARN_ON_ONCE(driver_for_each_device(&hfc_driver
.driver
, NULL
, NULL
,
2289 _hfcpci_softirq
) != 0);
2291 /* if next event would be in the past ... */
2292 if ((s32
)(hfc_jiffies
+ tics
- jiffies
) <= 0)
2293 hfc_jiffies
= jiffies
+ 1;
2295 hfc_jiffies
+= tics
;
2296 hfc_tl
.expires
= hfc_jiffies
;
2306 poll
= HFCPCI_BTRANS_THRESHOLD
;
2308 if (poll
!= HFCPCI_BTRANS_THRESHOLD
) {
2309 tics
= (poll
* HZ
) / 8000;
2312 poll
= (tics
* 8000) / HZ
;
2313 if (poll
> 256 || poll
< 8) {
2314 printk(KERN_ERR
"%s: Wrong poll value %d not in range "
2315 "of 8..256.\n", __func__
, poll
);
2320 if (poll
!= HFCPCI_BTRANS_THRESHOLD
) {
2321 printk(KERN_INFO
"%s: Using alternative poll value of %d\n",
2323 timer_setup(&hfc_tl
, hfcpci_softirq
, 0);
2324 hfc_tl
.expires
= jiffies
+ tics
;
2325 hfc_jiffies
= hfc_tl
.expires
;
2328 tics
= 0; /* indicate the use of controller's timer */
2330 err
= pci_register_driver(&hfc_driver
);
2332 if (timer_pending(&hfc_tl
))
2342 if (timer_pending(&hfc_tl
))
2345 pci_unregister_driver(&hfc_driver
);
2348 module_init(HFC_init
);
2349 module_exit(HFC_cleanup
);
2351 MODULE_DEVICE_TABLE(pci
, hfc_ids
);