1 /* $Id: hfc_pci.c,v 1.34.6.3 2000/12/10 23:39:19 kai Exp $
3 * hfc_pci.c low level driver for CCD´s hfc-pci based cards
5 * Author Werner Cornelius (werner@isdn4linux.de)
6 * based on existing driver for CCD hfc ISA cards
8 * Copyright 1999 by Werner Cornelius (werner@isdn4linux.de)
9 * Copyright 1999 by Karsten Keil (keil@isdn4linux.de)
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <linux/init.h>
28 #include <linux/config.h>
29 #define __NO_VERSION__
33 #include <linux/pci.h>
34 #include <linux/interrupt.h>
36 extern const char *CardType
[];
38 static const char *hfcpci_revision
= "$Revision: 1.34.6.3 $";
40 /* table entry in the PCI devices list */
48 #define NT_T1_COUNT 20 /* number of 3.125ms interrupts for G2 timeout */
49 #define CLKDEL_TE 0x0e /* CLKDEL in TE mode */
50 #define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
52 static const PCI_ENTRY id_list
[] =
54 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_2BD0
, "CCD/Billion/Asuscom", "2BD0"},
55 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_B000
, "Billion", "B000"},
56 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_B006
, "Billion", "B006"},
57 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_B007
, "Billion", "B007"},
58 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_B008
, "Billion", "B008"},
59 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_B009
, "Billion", "B009"},
60 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_B00A
, "Billion", "B00A"},
61 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_B00B
, "Billion", "B00B"},
62 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_B00C
, "Billion", "B00C"},
63 {PCI_VENDOR_ID_CCD
, PCI_DEVICE_ID_CCD_B100
, "Seyeon", "B100"},
64 {PCI_VENDOR_ID_ABOCOM
, PCI_DEVICE_ID_ABOCOM_2BD1
, "Abocom/Magitek", "2BD1"},
65 {PCI_VENDOR_ID_ASUSTEK
, PCI_DEVICE_ID_ASUSTEK_0675
, "Asuscom/Askey", "675"},
66 {PCI_VENDOR_ID_BERKOM
, PCI_DEVICE_ID_BERKOM_T_CONCEPT
, "German telekom", "T-Concept"},
67 {PCI_VENDOR_ID_BERKOM
, PCI_DEVICE_ID_BERKOM_A1T
, "German telekom", "A1T"},
68 {PCI_VENDOR_ID_ANIGMA
, PCI_DEVICE_ID_ANIGMA_MC145575
, "Motorola MC145575", "MC145575"},
69 {PCI_VENDOR_ID_ZOLTRIX
, PCI_DEVICE_ID_ZOLTRIX_2BD0
, "Zoltrix", "2BD0"},
70 {PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E
,"Digi International", "Digi DataFire Micro V IOM2 (Europe)"},
71 {PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_DIGI_DF_M_E
,"Digi International", "Digi DataFire Micro V (Europe)"},
72 {PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A
,"Digi International", "Digi DataFire Micro V IOM2 (North America)"},
73 {PCI_VENDOR_ID_DIGI
, PCI_DEVICE_ID_DIGI_DF_M_A
,"Digi International", "Digi DataFire Micro V (North America)"},
80 /******************************************/
81 /* free hardware resources used by driver */
82 /******************************************/
84 release_io_hfcpci(struct IsdnCardState
*cs
)
90 cs
->hw
.hfcpci
.int_m2
= 0; /* interrupt output off ! */
91 Write_hfc(cs
, HFCPCI_INT_M2
, cs
->hw
.hfcpci
.int_m2
);
93 Write_hfc(cs
, HFCPCI_CIRM
, HFCPCI_RESET
); /* Reset On */
95 set_current_state(TASK_UNINTERRUPTIBLE
);
96 schedule_timeout((30 * HZ
) / 1000); /* Timeout 30ms */
97 Write_hfc(cs
, HFCPCI_CIRM
, 0); /* Reset Off */
99 pcibios_write_config_word(cs
->hw
.hfcpci
.pci_bus
, cs
->hw
.hfcpci
.pci_device_fn
, PCI_COMMAND
, 0); /* disable memory mapped ports + busmaster */
100 #endif /* CONFIG_PCI */
101 del_timer(&cs
->hw
.hfcpci
.timer
);
102 kfree(cs
->hw
.hfcpci
.share_start
);
103 cs
->hw
.hfcpci
.share_start
= NULL
;
104 vfree(cs
->hw
.hfcpci
.pci_io
);
107 /********************************************************************************/
108 /* function called to reset the HFC PCI chip. A complete software reset of chip */
109 /* and fifos is done. */
110 /********************************************************************************/
112 reset_hfcpci(struct IsdnCardState
*cs
)
118 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 */
119 cs
->hw
.hfcpci
.int_m2
= 0; /* interrupt output off ! */
120 Write_hfc(cs
, HFCPCI_INT_M2
, cs
->hw
.hfcpci
.int_m2
);
122 printk(KERN_INFO
"HFC_PCI: resetting card\n");
123 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 */
124 Write_hfc(cs
, HFCPCI_CIRM
, HFCPCI_RESET
); /* Reset On */
126 set_current_state(TASK_UNINTERRUPTIBLE
);
127 schedule_timeout((30 * HZ
) / 1000); /* Timeout 30ms */
128 Write_hfc(cs
, HFCPCI_CIRM
, 0); /* Reset Off */
129 set_current_state(TASK_UNINTERRUPTIBLE
);
130 schedule_timeout((20 * HZ
) / 1000); /* Timeout 20ms */
131 if (Read_hfc(cs
, HFCPCI_STATUS
) & 2)
132 printk(KERN_WARNING
"HFC-PCI init bit busy\n");
134 cs
->hw
.hfcpci
.fifo_en
= 0x30; /* only D fifos enabled */
135 Write_hfc(cs
, HFCPCI_FIFO_EN
, cs
->hw
.hfcpci
.fifo_en
);
137 cs
->hw
.hfcpci
.trm
= 0 + HFCPCI_BTRANS_THRESMASK
; /* no echo connect , threshold */
138 Write_hfc(cs
, HFCPCI_TRM
, cs
->hw
.hfcpci
.trm
);
140 Write_hfc(cs
, HFCPCI_CLKDEL
, CLKDEL_TE
); /* ST-Bit delay for TE-Mode */
141 cs
->hw
.hfcpci
.sctrl_e
= HFCPCI_AUTO_AWAKE
;
142 Write_hfc(cs
, HFCPCI_SCTRL_E
, cs
->hw
.hfcpci
.sctrl_e
); /* S/T Auto awake */
143 cs
->hw
.hfcpci
.bswapped
= 0; /* no exchange */
144 cs
->hw
.hfcpci
.nt_mode
= 0; /* we are in TE mode */
145 cs
->hw
.hfcpci
.ctmt
= HFCPCI_TIM3_125
| HFCPCI_AUTO_TIMER
;
146 Write_hfc(cs
, HFCPCI_CTMT
, cs
->hw
.hfcpci
.ctmt
);
148 cs
->hw
.hfcpci
.int_m1
= HFCPCI_INTS_DTRANS
| HFCPCI_INTS_DREC
|
149 HFCPCI_INTS_L1STATE
| HFCPCI_INTS_TIMER
;
150 Write_hfc(cs
, HFCPCI_INT_M1
, cs
->hw
.hfcpci
.int_m1
);
152 /* Clear already pending ints */
153 if (Read_hfc(cs
, HFCPCI_INT_S1
));
155 Write_hfc(cs
, HFCPCI_STATES
, HFCPCI_LOAD_STATE
| 2); /* HFC ST 2 */
157 Write_hfc(cs
, HFCPCI_STATES
, 2); /* HFC ST 2 */
158 cs
->hw
.hfcpci
.mst_m
= HFCPCI_MASTER
; /* HFC Master Mode */
160 Write_hfc(cs
, HFCPCI_MST_MODE
, cs
->hw
.hfcpci
.mst_m
);
161 cs
->hw
.hfcpci
.sctrl
= 0x40; /* set tx_lo mode, error in datasheet ! */
162 Write_hfc(cs
, HFCPCI_SCTRL
, cs
->hw
.hfcpci
.sctrl
);
163 cs
->hw
.hfcpci
.sctrl_r
= 0;
164 Write_hfc(cs
, HFCPCI_SCTRL_R
, cs
->hw
.hfcpci
.sctrl_r
);
166 /* Init GCI/IOM2 in master mode */
167 /* Slots 0 and 1 are set for B-chan 1 and 2 */
168 /* D- and monitor/CI channel are not enabled */
169 /* STIO1 is used as output for data, B1+B2 from ST->IOM+HFC */
170 /* STIO2 is used as data input, B1+B2 from IOM->ST */
171 /* ST B-channel send disabled -> continous 1s */
172 /* The IOM slots are always enabled */
173 cs
->hw
.hfcpci
.conn
= 0x36; /* set data flow directions */
174 Write_hfc(cs
, HFCPCI_CONNECT
, cs
->hw
.hfcpci
.conn
);
175 Write_hfc(cs
, HFCPCI_B1_SSL
, 0x80); /* B1-Slot 0 STIO1 out enabled */
176 Write_hfc(cs
, HFCPCI_B2_SSL
, 0x81); /* B2-Slot 1 STIO1 out enabled */
177 Write_hfc(cs
, HFCPCI_B1_RSL
, 0x80); /* B1-Slot 0 STIO2 in enabled */
178 Write_hfc(cs
, HFCPCI_B2_RSL
, 0x81); /* B2-Slot 1 STIO2 in enabled */
180 /* Finally enable IRQ output */
181 cs
->hw
.hfcpci
.int_m2
= HFCPCI_IRQ_ENABLE
;
182 Write_hfc(cs
, HFCPCI_INT_M2
, cs
->hw
.hfcpci
.int_m2
);
183 if (Read_hfc(cs
, HFCPCI_INT_S2
));
184 restore_flags(flags
);
187 /***************************************************/
188 /* Timer function called when kernel timer expires */
189 /***************************************************/
191 hfcpci_Timer(struct IsdnCardState
*cs
)
193 cs
->hw
.hfcpci
.timer
.expires
= jiffies
+ 75;
195 /* WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcpci.ctmt | 0x80);
196 add_timer(&cs->hw.hfcpci.timer);
201 /*********************************/
202 /* schedule a new D-channel task */
203 /*********************************/
205 sched_event_D_pci(struct IsdnCardState
*cs
, int event
)
207 test_and_set_bit(event
, &cs
->event
);
208 queue_task(&cs
->tqueue
, &tq_immediate
);
209 mark_bh(IMMEDIATE_BH
);
212 /*********************************/
213 /* schedule a new b_channel task */
214 /*********************************/
216 hfcpci_sched_event(struct BCState
*bcs
, int event
)
218 bcs
->event
|= 1 << event
;
219 queue_task(&bcs
->tqueue
, &tq_immediate
);
220 mark_bh(IMMEDIATE_BH
);
223 /************************************************/
224 /* select a b-channel entry matching and active */
225 /************************************************/
228 Sel_BCS(struct IsdnCardState
*cs
, int channel
)
230 if (cs
->bcs
[0].mode
&& (cs
->bcs
[0].channel
== channel
))
231 return (&cs
->bcs
[0]);
232 else if (cs
->bcs
[1].mode
&& (cs
->bcs
[1].channel
== channel
))
233 return (&cs
->bcs
[1]);
238 /*********************************************/
239 /* read a complete B-frame out of the buffer */
240 /*********************************************/
241 static struct sk_buff
243 hfcpci_empty_fifo(struct BCState
*bcs
, bzfifo_type
* bz
, u_char
* bdata
, int count
)
245 u_char
*ptr
, *ptr1
, new_f2
;
247 struct IsdnCardState
*cs
= bcs
->cs
;
248 int flags
, total
, maxlen
, new_z2
;
253 if ((cs
->debug
& L1_DEB_HSCX
) && !(cs
->debug
& L1_DEB_HSCX_FIFO
))
254 debugl1(cs
, "hfcpci_empty_fifo");
255 zp
= &bz
->za
[bz
->f2
]; /* point to Z-Regs */
256 new_z2
= zp
->z2
+ count
; /* new position in fifo */
257 if (new_z2
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
258 new_z2
-= B_FIFO_SIZE
; /* buffer wrap */
259 new_f2
= (bz
->f2
+ 1) & MAX_B_FRAMES
;
260 if ((count
> HSCX_BUFMAX
+ 3) || (count
< 4) ||
261 (*(bdata
+ (zp
->z1
- B_SUB_VAL
)))) {
262 if (cs
->debug
& L1_DEB_WARN
)
263 debugl1(cs
, "hfcpci_empty_fifo: incoming packet invalid length %d or crc", count
);
264 #ifdef ERROR_STATISTIC
267 bz
->za
[new_f2
].z2
= new_z2
;
268 bz
->f2
= new_f2
; /* next buffer */
270 } else if (!(skb
= dev_alloc_skb(count
- 3)))
271 printk(KERN_WARNING
"HFCPCI: receive out of memory\n");
275 ptr
= skb_put(skb
, count
);
277 if (zp
->z2
+ count
<= B_FIFO_SIZE
+ B_SUB_VAL
)
278 maxlen
= count
; /* complete transfer */
280 maxlen
= B_FIFO_SIZE
+ B_SUB_VAL
- zp
->z2
; /* maximum */
282 ptr1
= bdata
+ (zp
->z2
- B_SUB_VAL
); /* start of data */
283 memcpy(ptr
, ptr1
, maxlen
); /* copy data */
286 if (count
) { /* rest remaining */
288 ptr1
= bdata
; /* start of buffer */
289 memcpy(ptr
, ptr1
, count
); /* rest */
291 bz
->za
[new_f2
].z2
= new_z2
;
292 bz
->f2
= new_f2
; /* next buffer */
295 restore_flags(flags
);
299 /*******************************/
300 /* D-channel receive procedure */
301 /*******************************/
304 receive_dmsg(struct IsdnCardState
*cs
)
314 df
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->d_chan
.d_rx
;
315 if (test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
316 debugl1(cs
, "rec_dmsg blocked");
319 while (((df
->f1
& D_FREG_MASK
) != (df
->f2
& D_FREG_MASK
)) && count
--) {
320 zp
= &df
->za
[df
->f2
& D_FREG_MASK
];
321 rcnt
= zp
->z1
- zp
->z2
;
325 if (cs
->debug
& L1_DEB_ISAC
)
326 debugl1(cs
, "hfcpci recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)",
327 df
->f1
, df
->f2
, zp
->z1
, zp
->z2
, rcnt
);
329 if ((rcnt
> MAX_DFRAME_LEN
+ 3) || (rcnt
< 4) ||
330 (df
->data
[zp
->z1
])) {
331 if (cs
->debug
& L1_DEB_WARN
)
332 debugl1(cs
, "empty_fifo hfcpci paket inv. len %d or crc %d", rcnt
, df
->data
[zp
->z1
]);
333 #ifdef ERROR_STATISTIC
336 df
->f2
= ((df
->f2
+ 1) & MAX_D_FRAMES
) | (MAX_D_FRAMES
+ 1); /* next buffer */
337 df
->za
[df
->f2
& D_FREG_MASK
].z2
= (zp
->z2
+ rcnt
) & (D_FIFO_SIZE
- 1);
338 } else if ((skb
= dev_alloc_skb(rcnt
- 3))) {
341 ptr
= skb_put(skb
, rcnt
);
343 if (zp
->z2
+ rcnt
<= D_FIFO_SIZE
)
344 maxlen
= rcnt
; /* complete transfer */
346 maxlen
= D_FIFO_SIZE
- zp
->z2
; /* maximum */
348 ptr1
= df
->data
+ zp
->z2
; /* start of data */
349 memcpy(ptr
, ptr1
, maxlen
); /* copy data */
352 if (rcnt
) { /* rest remaining */
354 ptr1
= df
->data
; /* start of buffer */
355 memcpy(ptr
, ptr1
, rcnt
); /* rest */
357 df
->f2
= ((df
->f2
+ 1) & MAX_D_FRAMES
) | (MAX_D_FRAMES
+ 1); /* next buffer */
358 df
->za
[df
->f2
& D_FREG_MASK
].z2
= (zp
->z2
+ total
) & (D_FIFO_SIZE
- 1);
360 skb_queue_tail(&cs
->rq
, skb
);
361 sched_event_D_pci(cs
, D_RCVBUFREADY
);
363 printk(KERN_WARNING
"HFC-PCI: D receive out of memory\n");
365 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
369 /*******************************************************************************/
370 /* check for transparent receive data and read max one threshold size if avail */
371 /*******************************************************************************/
373 hfcpci_empty_fifo_trans(struct BCState
*bcs
, bzfifo_type
* bz
, u_char
* bdata
)
375 unsigned short *z1r
, *z2r
;
376 int new_z2
, fcnt
, maxlen
;
380 z1r
= &bz
->za
[MAX_B_FRAMES
].z1
; /* pointer to z reg */
383 if (!(fcnt
= *z1r
- *z2r
))
384 return (0); /* no data avail */
387 fcnt
+= B_FIFO_SIZE
; /* bytes actually buffered */
388 if (fcnt
> HFCPCI_BTRANS_THRESHOLD
)
389 fcnt
= HFCPCI_BTRANS_THRESHOLD
; /* limit size */
391 new_z2
= *z2r
+ fcnt
; /* new position in fifo */
392 if (new_z2
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
393 new_z2
-= B_FIFO_SIZE
; /* buffer wrap */
395 if (!(skb
= dev_alloc_skb(fcnt
)))
396 printk(KERN_WARNING
"HFCPCI: receive out of memory\n");
398 ptr
= skb_put(skb
, fcnt
);
399 if (*z2r
+ fcnt
<= B_FIFO_SIZE
+ B_SUB_VAL
)
400 maxlen
= fcnt
; /* complete transfer */
402 maxlen
= B_FIFO_SIZE
+ B_SUB_VAL
- *z2r
; /* maximum */
404 ptr1
= bdata
+ (*z2r
- B_SUB_VAL
); /* start of data */
405 memcpy(ptr
, ptr1
, maxlen
); /* copy data */
408 if (fcnt
) { /* rest remaining */
410 ptr1
= bdata
; /* start of buffer */
411 memcpy(ptr
, ptr1
, fcnt
); /* rest */
414 skb_queue_tail(&bcs
->rqueue
, skb
);
416 hfcpci_sched_event(bcs
, B_RCVBUFREADY
);
419 *z2r
= new_z2
; /* new position */
421 } /* hfcpci_empty_fifo_trans */
423 /**********************************/
424 /* B-channel main receive routine */
425 /**********************************/
427 main_rec_hfcpci(struct BCState
*bcs
)
430 struct IsdnCardState
*cs
= bcs
->cs
;
432 int receive
, count
= 5;
440 if ((bcs
->channel
) && (!cs
->hw
.hfcpci
.bswapped
)) {
441 bz
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.rxbz_b2
;
442 bdata
= ((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.rxdat_b2
;
444 bz
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.rxbz_b1
;
445 bdata
= ((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.rxdat_b1
;
450 if (test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
451 debugl1(cs
, "rec_data %d blocked", bcs
->channel
);
452 restore_flags(flags
);
456 if (bz
->f1
!= bz
->f2
) {
457 if (cs
->debug
& L1_DEB_HSCX
)
458 debugl1(cs
, "hfcpci rec %d f1(%d) f2(%d)",
459 bcs
->channel
, bz
->f1
, bz
->f2
);
460 zp
= &bz
->za
[bz
->f2
];
462 rcnt
= zp
->z1
- zp
->z2
;
466 if (cs
->debug
& L1_DEB_HSCX
)
467 debugl1(cs
, "hfcpci rec %d z1(%x) z2(%x) cnt(%d)",
468 bcs
->channel
, zp
->z1
, zp
->z2
, rcnt
);
469 if ((skb
= hfcpci_empty_fifo(bcs
, bz
, bdata
, rcnt
))) {
471 skb_queue_tail(&bcs
->rqueue
, skb
);
473 hfcpci_sched_event(bcs
, B_RCVBUFREADY
);
475 rcnt
= bz
->f1
- bz
->f2
;
477 rcnt
+= MAX_B_FRAMES
+ 1;
482 } else if (bcs
->mode
== L1_MODE_TRANS
)
483 receive
= hfcpci_empty_fifo_trans(bcs
, bz
, bdata
);
486 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
487 if (count
&& receive
)
489 restore_flags(flags
);
493 /**************************/
494 /* D-channel send routine */
495 /**************************/
497 hfcpci_fill_dfifo(struct IsdnCardState
*cs
)
501 int count
, new_z1
, maxlen
;
503 u_char
*src
, *dst
, new_f1
;
507 if (cs
->tx_skb
->len
<= 0)
510 df
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->d_chan
.d_tx
;
512 if (cs
->debug
& L1_DEB_ISAC
)
513 debugl1(cs
, "hfcpci_fill_Dfifo f1(%d) f2(%d) z1(f1)(%x)",
515 df
->za
[df
->f1
& D_FREG_MASK
].z1
);
516 fcnt
= df
->f1
- df
->f2
; /* frame count actually buffered */
518 fcnt
+= (MAX_D_FRAMES
+ 1); /* if wrap around */
519 if (fcnt
> (MAX_D_FRAMES
- 1)) {
520 if (cs
->debug
& L1_DEB_ISAC
)
521 debugl1(cs
, "hfcpci_fill_Dfifo more as 14 frames");
522 #ifdef ERROR_STATISTIC
527 /* now determine free bytes in FIFO buffer */
528 count
= df
->za
[df
->f1
& D_FREG_MASK
].z2
- df
->za
[df
->f1
& D_FREG_MASK
].z1
;
530 count
+= D_FIFO_SIZE
; /* count now contains available bytes */
532 if (cs
->debug
& L1_DEB_ISAC
)
533 debugl1(cs
, "hfcpci_fill_Dfifo count(%ld/%d)",
534 cs
->tx_skb
->len
, count
);
535 if (count
< cs
->tx_skb
->len
) {
536 if (cs
->debug
& L1_DEB_ISAC
)
537 debugl1(cs
, "hfcpci_fill_Dfifo no fifo mem");
540 count
= cs
->tx_skb
->len
; /* get frame len */
541 new_z1
= (df
->za
[df
->f1
& D_FREG_MASK
].z1
+ count
) & (D_FIFO_SIZE
- 1);
542 new_f1
= ((df
->f1
+ 1) & D_FREG_MASK
) | (D_FREG_MASK
+ 1);
543 src
= cs
->tx_skb
->data
; /* source pointer */
544 dst
= df
->data
+ df
->za
[df
->f1
& D_FREG_MASK
].z1
;
545 maxlen
= D_FIFO_SIZE
- df
->za
[df
->f1
& D_FREG_MASK
].z1
; /* end fifo */
547 maxlen
= count
; /* limit size */
548 memcpy(dst
, src
, maxlen
); /* first copy */
550 count
-= maxlen
; /* remaining bytes */
552 dst
= df
->data
; /* start of buffer */
553 src
+= maxlen
; /* new position */
554 memcpy(dst
, src
, count
);
558 df
->za
[new_f1
& D_FREG_MASK
].z1
= new_z1
; /* for next buffer */
559 df
->za
[df
->f1
& D_FREG_MASK
].z1
= new_z1
; /* new pos actual buffer */
560 df
->f1
= new_f1
; /* next frame */
561 restore_flags(flags
);
563 dev_kfree_skb_any(cs
->tx_skb
);
568 /**************************/
569 /* B-channel send routine */
570 /**************************/
572 hfcpci_fill_fifo(struct BCState
*bcs
)
574 struct IsdnCardState
*cs
= bcs
->cs
;
575 int flags
, maxlen
, fcnt
;
579 u_char new_f1
, *src
, *dst
;
580 unsigned short *z1t
, *z2t
;
584 if (bcs
->tx_skb
->len
<= 0)
590 if ((bcs
->channel
) && (!cs
->hw
.hfcpci
.bswapped
)) {
591 bz
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.txbz_b2
;
592 bdata
= ((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.txdat_b2
;
594 bz
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.txbz_b1
;
595 bdata
= ((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.txdat_b1
;
598 if (bcs
->mode
== L1_MODE_TRANS
) {
599 z1t
= &bz
->za
[MAX_B_FRAMES
].z1
;
601 if (cs
->debug
& L1_DEB_HSCX
)
602 debugl1(cs
, "hfcpci_fill_fifo_trans %d z1(%x) z2(%x)",
603 bcs
->channel
, *z1t
, *z2t
);
606 fcnt
+= B_FIFO_SIZE
; /* fcnt contains available bytes in fifo */
607 fcnt
= B_FIFO_SIZE
- fcnt
; /* remaining bytes to send */
609 while ((fcnt
< 2 * HFCPCI_BTRANS_THRESHOLD
) && (bcs
->tx_skb
)) {
610 if (bcs
->tx_skb
->len
< B_FIFO_SIZE
- fcnt
) {
611 /* data is suitable for fifo */
612 count
= bcs
->tx_skb
->len
;
614 new_z1
= *z1t
+ count
; /* new buffer Position */
615 if (new_z1
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
616 new_z1
-= B_FIFO_SIZE
; /* buffer wrap */
617 src
= bcs
->tx_skb
->data
; /* source pointer */
618 dst
= bdata
+ (*z1t
- B_SUB_VAL
);
619 maxlen
= (B_FIFO_SIZE
+ B_SUB_VAL
) - *z1t
; /* end of fifo */
621 maxlen
= count
; /* limit size */
622 memcpy(dst
, src
, maxlen
); /* first copy */
624 count
-= maxlen
; /* remaining bytes */
626 dst
= bdata
; /* start of buffer */
627 src
+= maxlen
; /* new position */
628 memcpy(dst
, src
, count
);
630 bcs
->tx_cnt
-= bcs
->tx_skb
->len
;
631 fcnt
+= bcs
->tx_skb
->len
;
632 *z1t
= new_z1
; /* now send data */
633 } else if (cs
->debug
& L1_DEB_HSCX
)
634 debugl1(cs
, "hfcpci_fill_fifo_trans %d frame length %d discarded",
635 bcs
->channel
, bcs
->tx_skb
->len
);
637 dev_kfree_skb_any(bcs
->tx_skb
);
639 bcs
->tx_skb
= skb_dequeue(&bcs
->squeue
); /* fetch next data */
642 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
643 restore_flags(flags
);
646 if (cs
->debug
& L1_DEB_HSCX
)
647 debugl1(cs
, "hfcpci_fill_fifo_hdlc %d f1(%d) f2(%d) z1(f1)(%x)",
648 bcs
->channel
, bz
->f1
, bz
->f2
,
651 fcnt
= bz
->f1
- bz
->f2
; /* frame count actually buffered */
653 fcnt
+= (MAX_B_FRAMES
+ 1); /* if wrap around */
654 if (fcnt
> (MAX_B_FRAMES
- 1)) {
655 if (cs
->debug
& L1_DEB_HSCX
)
656 debugl1(cs
, "hfcpci_fill_Bfifo more as 14 frames");
657 restore_flags(flags
);
660 /* now determine free bytes in FIFO buffer */
661 count
= bz
->za
[bz
->f1
].z2
- bz
->za
[bz
->f1
].z1
;
663 count
+= B_FIFO_SIZE
; /* count now contains available bytes */
665 if (cs
->debug
& L1_DEB_HSCX
)
666 debugl1(cs
, "hfcpci_fill_fifo %d count(%ld/%d),%lx",
667 bcs
->channel
, bcs
->tx_skb
->len
,
668 count
, current
->state
);
670 if (count
< bcs
->tx_skb
->len
) {
671 if (cs
->debug
& L1_DEB_HSCX
)
672 debugl1(cs
, "hfcpci_fill_fifo no fifo mem");
673 restore_flags(flags
);
676 count
= bcs
->tx_skb
->len
; /* get frame len */
677 new_z1
= bz
->za
[bz
->f1
].z1
+ count
; /* new buffer Position */
678 if (new_z1
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
679 new_z1
-= B_FIFO_SIZE
; /* buffer wrap */
681 new_f1
= ((bz
->f1
+ 1) & MAX_B_FRAMES
);
682 src
= bcs
->tx_skb
->data
; /* source pointer */
683 dst
= bdata
+ (bz
->za
[bz
->f1
].z1
- B_SUB_VAL
);
684 maxlen
= (B_FIFO_SIZE
+ B_SUB_VAL
) - bz
->za
[bz
->f1
].z1
; /* end fifo */
686 maxlen
= count
; /* limit size */
687 memcpy(dst
, src
, maxlen
); /* first copy */
689 count
-= maxlen
; /* remaining bytes */
691 dst
= bdata
; /* start of buffer */
692 src
+= maxlen
; /* new position */
693 memcpy(dst
, src
, count
);
695 bcs
->tx_cnt
-= bcs
->tx_skb
->len
;
696 if (bcs
->st
->lli
.l1writewakeup
&&
697 (PACKET_NOACK
!= bcs
->tx_skb
->pkt_type
))
698 bcs
->st
->lli
.l1writewakeup(bcs
->st
, bcs
->tx_skb
->len
);
701 bz
->za
[new_f1
].z1
= new_z1
; /* for next buffer */
702 bz
->f1
= new_f1
; /* next frame */
703 restore_flags(flags
);
705 dev_kfree_skb_any(bcs
->tx_skb
);
707 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
711 /**********************************************/
712 /* D-channel l1 state call for leased NT-mode */
713 /**********************************************/
715 dch_nt_l2l1(struct PStack
*st
, int pr
, void *arg
)
717 struct IsdnCardState
*cs
= (struct IsdnCardState
*) st
->l1
.hardware
;
720 case (PH_DATA
| REQUEST
):
721 case (PH_PULL
| REQUEST
):
722 case (PH_PULL
| INDICATION
):
723 st
->l1
.l1hw(st
, pr
, arg
);
725 case (PH_ACTIVATE
| REQUEST
):
726 st
->l1
.l1l2(st
, PH_ACTIVATE
| CONFIRM
, NULL
);
728 case (PH_TESTLOOP
| REQUEST
):
730 debugl1(cs
, "PH_TEST_LOOP B1");
732 debugl1(cs
, "PH_TEST_LOOP B2");
733 if (!(3 & (long) arg
))
734 debugl1(cs
, "PH_TEST_LOOP DISABLED");
735 st
->l1
.l1hw(st
, HW_TESTLOOP
| REQUEST
, arg
);
739 debugl1(cs
, "dch_nt_l2l1 msg %04X unhandled", pr
);
746 /***********************/
747 /* set/reset echo mode */
748 /***********************/
750 hfcpci_auxcmd(struct IsdnCardState
*cs
, isdn_ctrl
* ic
)
753 int i
= *(unsigned int *) ic
->parm
.num
;
755 if ((ic
->arg
== 98) &&
756 (!(cs
->hw
.hfcpci
.int_m1
& (HFCPCI_INTS_B2TRANS
+ HFCPCI_INTS_B2REC
+ HFCPCI_INTS_B1TRANS
+ HFCPCI_INTS_B1REC
)))) {
759 Write_hfc(cs
, HFCPCI_CLKDEL
, CLKDEL_NT
); /* ST-Bit delay for NT-Mode */
760 Write_hfc(cs
, HFCPCI_STATES
, HFCPCI_LOAD_STATE
| 0); /* HFC ST G0 */
762 cs
->hw
.hfcpci
.sctrl
|= SCTRL_MODE_NT
;
763 Write_hfc(cs
, HFCPCI_SCTRL
, cs
->hw
.hfcpci
.sctrl
); /* set NT-mode */
765 Write_hfc(cs
, HFCPCI_STATES
, HFCPCI_LOAD_STATE
| 1); /* HFC ST G1 */
767 Write_hfc(cs
, HFCPCI_STATES
, 1 | HFCPCI_ACTIVATE
| HFCPCI_DO_ACTION
);
768 cs
->dc
.hfcpci
.ph_state
= 1;
769 cs
->hw
.hfcpci
.nt_mode
= 1;
770 cs
->hw
.hfcpci
.nt_timer
= 0;
771 cs
->stlist
->l2
.l2l1
= dch_nt_l2l1
;
772 restore_flags(flags
);
773 debugl1(cs
, "NT mode activated");
776 if ((cs
->chanlimit
> 1) || (cs
->hw
.hfcpci
.bswapped
) ||
777 (cs
->hw
.hfcpci
.nt_mode
) || (ic
->arg
!= 12))
784 cs
->hw
.hfcpci
.trm
|= 0x20; /* enable echo chan */
785 cs
->hw
.hfcpci
.int_m1
|= HFCPCI_INTS_B2REC
;
786 cs
->hw
.hfcpci
.fifo_en
|= HFCPCI_FIFOEN_B2RX
;
789 cs
->hw
.hfcpci
.trm
&= ~0x20; /* disable echo chan */
790 cs
->hw
.hfcpci
.int_m1
&= ~HFCPCI_INTS_B2REC
;
791 cs
->hw
.hfcpci
.fifo_en
&= ~HFCPCI_FIFOEN_B2RX
;
793 cs
->hw
.hfcpci
.sctrl_r
&= ~SCTRL_B2_ENA
;
794 cs
->hw
.hfcpci
.sctrl
&= ~SCTRL_B2_ENA
;
795 cs
->hw
.hfcpci
.conn
|= 0x10; /* B2-IOM -> B2-ST */
796 cs
->hw
.hfcpci
.ctmt
&= ~2;
797 Write_hfc(cs
, HFCPCI_CTMT
, cs
->hw
.hfcpci
.ctmt
);
798 Write_hfc(cs
, HFCPCI_SCTRL_R
, cs
->hw
.hfcpci
.sctrl_r
);
799 Write_hfc(cs
, HFCPCI_SCTRL
, cs
->hw
.hfcpci
.sctrl
);
800 Write_hfc(cs
, HFCPCI_CONNECT
, cs
->hw
.hfcpci
.conn
);
801 Write_hfc(cs
, HFCPCI_TRM
, cs
->hw
.hfcpci
.trm
);
802 Write_hfc(cs
, HFCPCI_FIFO_EN
, cs
->hw
.hfcpci
.fifo_en
);
803 Write_hfc(cs
, HFCPCI_INT_M1
, cs
->hw
.hfcpci
.int_m1
);
804 restore_flags(flags
);
806 } /* hfcpci_auxcmd */
808 /*****************************/
809 /* E-channel receive routine */
810 /*****************************/
812 receive_emsg(struct IsdnCardState
*cs
)
816 int receive
, count
= 5;
820 u_char
*ptr
, *ptr1
, new_f2
;
821 int total
, maxlen
, new_z2
;
822 u_char e_buffer
[256];
825 bz
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.rxbz_b2
;
826 bdata
= ((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.rxdat_b2
;
830 if (test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
831 debugl1(cs
, "echo_rec_data blocked");
832 restore_flags(flags
);
836 if (bz
->f1
!= bz
->f2
) {
837 if (cs
->debug
& L1_DEB_ISAC
)
838 debugl1(cs
, "hfcpci e_rec f1(%d) f2(%d)",
840 zp
= &bz
->za
[bz
->f2
];
842 rcnt
= zp
->z1
- zp
->z2
;
846 if (cs
->debug
& L1_DEB_ISAC
)
847 debugl1(cs
, "hfcpci e_rec z1(%x) z2(%x) cnt(%d)",
848 zp
->z1
, zp
->z2
, rcnt
);
849 new_z2
= zp
->z2
+ rcnt
; /* new position in fifo */
850 if (new_z2
>= (B_FIFO_SIZE
+ B_SUB_VAL
))
851 new_z2
-= B_FIFO_SIZE
; /* buffer wrap */
852 new_f2
= (bz
->f2
+ 1) & MAX_B_FRAMES
;
853 if ((rcnt
> 256 + 3) || (count
< 4) ||
854 (*(bdata
+ (zp
->z1
- B_SUB_VAL
)))) {
855 if (cs
->debug
& L1_DEB_WARN
)
856 debugl1(cs
, "hfcpci_empty_echan: incoming packet invalid length %d or crc", rcnt
);
857 bz
->za
[new_f2
].z2
= new_z2
;
858 bz
->f2
= new_f2
; /* next buffer */
864 if (zp
->z2
<= B_FIFO_SIZE
+ B_SUB_VAL
)
865 maxlen
= rcnt
; /* complete transfer */
867 maxlen
= B_FIFO_SIZE
+ B_SUB_VAL
- zp
->z2
; /* maximum */
869 ptr1
= bdata
+ (zp
->z2
- B_SUB_VAL
); /* start of data */
870 memcpy(ptr
, ptr1
, maxlen
); /* copy data */
873 if (rcnt
) { /* rest remaining */
875 ptr1
= bdata
; /* start of buffer */
876 memcpy(ptr
, ptr1
, rcnt
); /* rest */
878 bz
->za
[new_f2
].z2
= new_z2
;
879 bz
->f2
= new_f2
; /* next buffer */
880 if (cs
->debug
& DEB_DLOG_HEX
) {
882 if ((total
- 3) < MAX_DLOG_SPACE
/ 3 - 10) {
888 ptr
+= QuickHex(ptr
, e_buffer
, total
- 3);
892 HiSax_putstatus(cs
, NULL
, cs
->dlog
);
894 HiSax_putstatus(cs
, "LogEcho: ", "warning Frame too big (%d)", total
- 3);
898 rcnt
= bz
->f1
- bz
->f2
;
900 rcnt
+= MAX_B_FRAMES
+ 1;
907 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
908 if (count
&& receive
)
910 restore_flags(flags
);
914 /*********************/
915 /* Interrupt handler */
916 /*********************/
918 hfcpci_interrupt(int intno
, void *dev_id
, struct pt_regs
*regs
)
920 struct IsdnCardState
*cs
= dev_id
;
928 printk(KERN_WARNING
"HFC-PCI: Spurious interrupt!\n");
931 if (!(cs
->hw
.hfcpci
.int_m2
& 0x08))
932 return; /* not initialised */
934 if (HFCPCI_ANYINT
& (stat
= Read_hfc(cs
, HFCPCI_STATUS
))) {
935 val
= Read_hfc(cs
, HFCPCI_INT_S1
);
936 if (cs
->debug
& L1_DEB_ISAC
)
937 debugl1(cs
, "HFC-PCI: stat(%02x) s1(%02x)", stat
, val
);
941 if (cs
->debug
& L1_DEB_ISAC
)
942 debugl1(cs
, "HFC-PCI irq %x %s", val
,
943 test_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
) ?
944 "locked" : "unlocked");
945 val
&= cs
->hw
.hfcpci
.int_m1
;
946 if (val
& 0x40) { /* state machine irq */
947 exval
= Read_hfc(cs
, HFCPCI_STATES
) & 0xf;
948 if (cs
->debug
& L1_DEB_ISAC
)
949 debugl1(cs
, "ph_state chg %d->%d", cs
->dc
.hfcpci
.ph_state
,
951 cs
->dc
.hfcpci
.ph_state
= exval
;
952 sched_event_D_pci(cs
, D_L1STATECHANGE
);
955 if (val
& 0x80) { /* timer irq */
956 if (cs
->hw
.hfcpci
.nt_mode
) {
957 if ((--cs
->hw
.hfcpci
.nt_timer
) < 0)
958 sched_event_D_pci(cs
, D_L1STATECHANGE
);
961 Write_hfc(cs
, HFCPCI_CTMT
, cs
->hw
.hfcpci
.ctmt
| HFCPCI_CLTIMER
);
966 if (test_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
967 cs
->hw
.hfcpci
.int_s1
|= val
;
968 restore_flags(flags
);
971 if (cs
->hw
.hfcpci
.int_s1
& 0x18) {
973 val
= cs
->hw
.hfcpci
.int_s1
;
974 cs
->hw
.hfcpci
.int_s1
= exval
;
977 if (!(bcs
= Sel_BCS(cs
, cs
->hw
.hfcpci
.bswapped
? 1 : 0))) {
979 debugl1(cs
, "hfcpci spurious 0x08 IRQ");
981 main_rec_hfcpci(bcs
);
986 else if (!(bcs
= Sel_BCS(cs
, 1))) {
988 debugl1(cs
, "hfcpci spurious 0x10 IRQ");
990 main_rec_hfcpci(bcs
);
993 if (!(bcs
= Sel_BCS(cs
, cs
->hw
.hfcpci
.bswapped
? 1 : 0))) {
995 debugl1(cs
, "hfcpci spurious 0x01 IRQ");
998 if (!test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
999 hfcpci_fill_fifo(bcs
);
1000 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
1002 debugl1(cs
, "fill_data %d blocked", bcs
->channel
);
1004 if ((bcs
->tx_skb
= skb_dequeue(&bcs
->squeue
))) {
1005 if (!test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
1006 hfcpci_fill_fifo(bcs
);
1007 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
1009 debugl1(cs
, "fill_data %d blocked", bcs
->channel
);
1011 hfcpci_sched_event(bcs
, B_XMTBUFREADY
);
1017 if (!(bcs
= Sel_BCS(cs
, 1))) {
1019 debugl1(cs
, "hfcpci spurious 0x02 IRQ");
1022 if (!test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
1023 hfcpci_fill_fifo(bcs
);
1024 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
1026 debugl1(cs
, "fill_data %d blocked", bcs
->channel
);
1028 if ((bcs
->tx_skb
= skb_dequeue(&bcs
->squeue
))) {
1029 if (!test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
1030 hfcpci_fill_fifo(bcs
);
1031 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
1033 debugl1(cs
, "fill_data %d blocked", bcs
->channel
);
1035 hfcpci_sched_event(bcs
, B_XMTBUFREADY
);
1040 if (val
& 0x20) { /* receive dframe */
1043 if (val
& 0x04) { /* dframe transmitted */
1044 if (test_and_clear_bit(FLG_DBUSY_TIMER
, &cs
->HW_Flags
))
1045 del_timer(&cs
->dbusytimer
);
1046 if (test_and_clear_bit(FLG_L1_DBUSY
, &cs
->HW_Flags
))
1047 sched_event_D_pci(cs
, D_CLEARBUSY
);
1049 if (cs
->tx_skb
->len
) {
1050 if (!test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
1051 hfcpci_fill_dfifo(cs
);
1052 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
1054 debugl1(cs
, "hfcpci_fill_dfifo irq blocked");
1058 dev_kfree_skb_irq(cs
->tx_skb
);
1063 if ((cs
->tx_skb
= skb_dequeue(&cs
->sq
))) {
1065 if (!test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
1066 hfcpci_fill_dfifo(cs
);
1067 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
1069 debugl1(cs
, "hfcpci_fill_dfifo irq blocked");
1072 sched_event_D_pci(cs
, D_XMTBUFREADY
);
1075 if (cs
->hw
.hfcpci
.int_s1
&& count
--) {
1076 val
= cs
->hw
.hfcpci
.int_s1
;
1077 cs
->hw
.hfcpci
.int_s1
= 0;
1078 if (cs
->debug
& L1_DEB_ISAC
)
1079 debugl1(cs
, "HFC-PCI irq %x loop %d", val
, 15 - count
);
1082 restore_flags(flags
);
1086 /********************************************************************/
1087 /* timer callback for D-chan busy resolution. Currently no function */
1088 /********************************************************************/
1090 hfcpci_dbusy_timer(struct IsdnCardState
*cs
)
1094 /*************************************/
1095 /* Layer 1 D-channel hardware access */
1096 /*************************************/
1098 HFCPCI_l1hw(struct PStack
*st
, int pr
, void *arg
)
1100 struct IsdnCardState
*cs
= (struct IsdnCardState
*) st
->l1
.hardware
;
1101 struct sk_buff
*skb
= arg
;
1105 case (PH_DATA
| REQUEST
):
1106 if (cs
->debug
& DEB_DLOG_HEX
)
1107 LogFrame(cs
, skb
->data
, skb
->len
);
1108 if (cs
->debug
& DEB_DLOG_VERBOSE
)
1109 dlogframe(cs
, skb
, 0);
1111 skb_queue_tail(&cs
->sq
, skb
);
1112 #ifdef L2FRAME_DEBUG /* psa */
1113 if (cs
->debug
& L1_DEB_LAPD
)
1114 Logl2Frame(cs
, skb
, "PH_DATA Queued", 0);
1119 #ifdef L2FRAME_DEBUG /* psa */
1120 if (cs
->debug
& L1_DEB_LAPD
)
1121 Logl2Frame(cs
, skb
, "PH_DATA", 0);
1123 if (!test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
1124 hfcpci_fill_dfifo(cs
);
1125 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
1127 debugl1(cs
, "hfcpci_fill_dfifo blocked");
1131 case (PH_PULL
| INDICATION
):
1133 if (cs
->debug
& L1_DEB_WARN
)
1134 debugl1(cs
, " l2l1 tx_skb exist this shouldn't happen");
1135 skb_queue_tail(&cs
->sq
, skb
);
1138 if (cs
->debug
& DEB_DLOG_HEX
)
1139 LogFrame(cs
, skb
->data
, skb
->len
);
1140 if (cs
->debug
& DEB_DLOG_VERBOSE
)
1141 dlogframe(cs
, skb
, 0);
1144 #ifdef L2FRAME_DEBUG /* psa */
1145 if (cs
->debug
& L1_DEB_LAPD
)
1146 Logl2Frame(cs
, skb
, "PH_DATA_PULLED", 0);
1148 if (!test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
1149 hfcpci_fill_dfifo(cs
);
1150 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
1152 debugl1(cs
, "hfcpci_fill_dfifo blocked");
1154 case (PH_PULL
| REQUEST
):
1155 #ifdef L2FRAME_DEBUG /* psa */
1156 if (cs
->debug
& L1_DEB_LAPD
)
1157 debugl1(cs
, "-> PH_REQUEST_PULL");
1160 test_and_clear_bit(FLG_L1_PULL_REQ
, &st
->l1
.Flags
);
1161 st
->l1
.l1l2(st
, PH_PULL
| CONFIRM
, NULL
);
1163 test_and_set_bit(FLG_L1_PULL_REQ
, &st
->l1
.Flags
);
1165 case (HW_RESET
| REQUEST
):
1166 Write_hfc(cs
, HFCPCI_STATES
, HFCPCI_LOAD_STATE
| 3); /* HFC ST 3 */
1168 Write_hfc(cs
, HFCPCI_STATES
, 3); /* HFC ST 2 */
1169 cs
->hw
.hfcpci
.mst_m
|= HFCPCI_MASTER
;
1170 Write_hfc(cs
, HFCPCI_MST_MODE
, cs
->hw
.hfcpci
.mst_m
);
1171 Write_hfc(cs
, HFCPCI_STATES
, HFCPCI_ACTIVATE
| HFCPCI_DO_ACTION
);
1172 l1_msg(cs
, HW_POWERUP
| CONFIRM
, NULL
);
1174 case (HW_ENABLE
| REQUEST
):
1175 Write_hfc(cs
, HFCPCI_STATES
, HFCPCI_ACTIVATE
| HFCPCI_DO_ACTION
);
1177 case (HW_DEACTIVATE
| REQUEST
):
1178 cs
->hw
.hfcpci
.mst_m
&= ~HFCPCI_MASTER
;
1179 Write_hfc(cs
, HFCPCI_MST_MODE
, cs
->hw
.hfcpci
.mst_m
);
1181 case (HW_INFO3
| REQUEST
):
1182 cs
->hw
.hfcpci
.mst_m
|= HFCPCI_MASTER
;
1183 Write_hfc(cs
, HFCPCI_MST_MODE
, cs
->hw
.hfcpci
.mst_m
);
1185 case (HW_TESTLOOP
| REQUEST
):
1186 switch ((int) arg
) {
1188 Write_hfc(cs
, HFCPCI_B1_SSL
, 0x80); /* tx slot */
1189 Write_hfc(cs
, HFCPCI_B1_RSL
, 0x80); /* rx slot */
1192 cs
->hw
.hfcpci
.conn
= (cs
->hw
.hfcpci
.conn
& ~7) | 1;
1193 Write_hfc(cs
, HFCPCI_CONNECT
, cs
->hw
.hfcpci
.conn
);
1194 restore_flags(flags
);
1198 Write_hfc(cs
, HFCPCI_B2_SSL
, 0x81); /* tx slot */
1199 Write_hfc(cs
, HFCPCI_B2_RSL
, 0x81); /* rx slot */
1202 cs
->hw
.hfcpci
.conn
= (cs
->hw
.hfcpci
.conn
& ~0x38) | 0x08;
1203 Write_hfc(cs
, HFCPCI_CONNECT
, cs
->hw
.hfcpci
.conn
);
1204 restore_flags(flags
);
1208 if (cs
->debug
& L1_DEB_WARN
)
1209 debugl1(cs
, "hfcpci_l1hw loop invalid %4x", (int) arg
);
1214 cs
->hw
.hfcpci
.trm
|= 0x80; /* enable IOM-loop */
1215 Write_hfc(cs
, HFCPCI_TRM
, cs
->hw
.hfcpci
.trm
);
1216 restore_flags(flags
);
1219 if (cs
->debug
& L1_DEB_WARN
)
1220 debugl1(cs
, "hfcpci_l1hw unknown pr %4x", pr
);
1225 /***********************************************/
1226 /* called during init setting l1 stack pointer */
1227 /***********************************************/
1229 setstack_hfcpci(struct PStack
*st
, struct IsdnCardState
*cs
)
1231 st
->l1
.l1hw
= HFCPCI_l1hw
;
1234 /**************************************/
1235 /* send B-channel data if not blocked */
1236 /**************************************/
1238 hfcpci_send_data(struct BCState
*bcs
)
1240 struct IsdnCardState
*cs
= bcs
->cs
;
1242 if (!test_and_set_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
)) {
1243 hfcpci_fill_fifo(bcs
);
1244 test_and_clear_bit(FLG_LOCK_ATOMIC
, &cs
->HW_Flags
);
1246 debugl1(cs
, "send_data %d blocked", bcs
->channel
);
1249 /***************************************************************/
1250 /* activate/deactivate hardware for selected channels and mode */
1251 /***************************************************************/
1253 mode_hfcpci(struct BCState
*bcs
, int mode
, int bc
)
1255 struct IsdnCardState
*cs
= bcs
->cs
;
1256 bzfifo_type
*bzr
, *bzt
;
1259 if (cs
->debug
& L1_DEB_HSCX
)
1260 debugl1(cs
, "HFCPCI bchannel mode %d bchan %d/%d",
1261 mode
, bc
, bcs
->channel
);
1267 if (cs
->chanlimit
> 1) {
1268 cs
->hw
.hfcpci
.bswapped
= 0; /* B1 and B2 normal mode */
1269 cs
->hw
.hfcpci
.sctrl_e
&= ~0x80;
1272 if (mode
!= L1_MODE_NULL
) {
1273 cs
->hw
.hfcpci
.bswapped
= 1; /* B1 and B2 exchanged */
1274 cs
->hw
.hfcpci
.sctrl_e
|= 0x80;
1276 cs
->hw
.hfcpci
.bswapped
= 0; /* B1 and B2 normal mode */
1277 cs
->hw
.hfcpci
.sctrl_e
&= ~0x80;
1281 cs
->hw
.hfcpci
.bswapped
= 0; /* B1 and B2 normal mode */
1282 cs
->hw
.hfcpci
.sctrl_e
&= ~0x80;
1286 case (L1_MODE_NULL
):
1288 cs
->hw
.hfcpci
.sctrl
&= ~SCTRL_B2_ENA
;
1289 cs
->hw
.hfcpci
.sctrl_r
&= ~SCTRL_B2_ENA
;
1291 cs
->hw
.hfcpci
.sctrl
&= ~SCTRL_B1_ENA
;
1292 cs
->hw
.hfcpci
.sctrl_r
&= ~SCTRL_B1_ENA
;
1295 cs
->hw
.hfcpci
.fifo_en
&= ~HFCPCI_FIFOEN_B2
;
1296 cs
->hw
.hfcpci
.int_m1
&= ~(HFCPCI_INTS_B2TRANS
+ HFCPCI_INTS_B2REC
);
1298 cs
->hw
.hfcpci
.fifo_en
&= ~HFCPCI_FIFOEN_B1
;
1299 cs
->hw
.hfcpci
.int_m1
&= ~(HFCPCI_INTS_B1TRANS
+ HFCPCI_INTS_B1REC
);
1302 case (L1_MODE_TRANS
):
1304 cs
->hw
.hfcpci
.sctrl
|= SCTRL_B2_ENA
;
1305 cs
->hw
.hfcpci
.sctrl_r
|= SCTRL_B2_ENA
;
1307 cs
->hw
.hfcpci
.sctrl
|= SCTRL_B1_ENA
;
1308 cs
->hw
.hfcpci
.sctrl_r
|= SCTRL_B1_ENA
;
1311 cs
->hw
.hfcpci
.fifo_en
|= HFCPCI_FIFOEN_B2
;
1312 cs
->hw
.hfcpci
.int_m1
|= (HFCPCI_INTS_B2TRANS
+ HFCPCI_INTS_B2REC
);
1313 cs
->hw
.hfcpci
.ctmt
|= 2;
1314 cs
->hw
.hfcpci
.conn
&= ~0x18;
1315 bzr
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.rxbz_b2
;
1316 bzt
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.txbz_b2
;
1318 cs
->hw
.hfcpci
.fifo_en
|= HFCPCI_FIFOEN_B1
;
1319 cs
->hw
.hfcpci
.int_m1
|= (HFCPCI_INTS_B1TRANS
+ HFCPCI_INTS_B1REC
);
1320 cs
->hw
.hfcpci
.ctmt
|= 1;
1321 cs
->hw
.hfcpci
.conn
&= ~0x03;
1322 bzr
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.rxbz_b1
;
1323 bzt
= &((fifo_area
*) (cs
->hw
.hfcpci
.fifos
))->b_chans
.txbz_b1
;
1325 bzr
->za
[MAX_B_FRAMES
].z1
= B_FIFO_SIZE
+ B_SUB_VAL
- 1;
1326 bzr
->za
[MAX_B_FRAMES
].z2
= bzr
->za
[MAX_B_FRAMES
].z1
;
1327 bzr
->f1
= MAX_B_FRAMES
;
1328 bzr
->f2
= bzr
->f1
; /* init F pointers to remain constant */
1329 bzt
->za
[MAX_B_FRAMES
].z1
= B_FIFO_SIZE
+ B_SUB_VAL
- 1;
1330 bzt
->za
[MAX_B_FRAMES
].z2
= bzt
->za
[MAX_B_FRAMES
].z1
;
1331 bzt
->f1
= MAX_B_FRAMES
;
1332 bzt
->f2
= bzt
->f1
; /* init F pointers to remain constant */
1334 case (L1_MODE_HDLC
):
1336 cs
->hw
.hfcpci
.sctrl
|= SCTRL_B2_ENA
;
1337 cs
->hw
.hfcpci
.sctrl_r
|= SCTRL_B2_ENA
;
1339 cs
->hw
.hfcpci
.sctrl
|= SCTRL_B1_ENA
;
1340 cs
->hw
.hfcpci
.sctrl_r
|= SCTRL_B1_ENA
;
1343 cs
->hw
.hfcpci
.fifo_en
|= HFCPCI_FIFOEN_B2
;
1344 cs
->hw
.hfcpci
.int_m1
|= (HFCPCI_INTS_B2TRANS
+ HFCPCI_INTS_B2REC
);
1345 cs
->hw
.hfcpci
.ctmt
&= ~2;
1346 cs
->hw
.hfcpci
.conn
&= ~0x18;
1348 cs
->hw
.hfcpci
.fifo_en
|= HFCPCI_FIFOEN_B1
;
1349 cs
->hw
.hfcpci
.int_m1
|= (HFCPCI_INTS_B1TRANS
+ HFCPCI_INTS_B1REC
);
1350 cs
->hw
.hfcpci
.ctmt
&= ~1;
1351 cs
->hw
.hfcpci
.conn
&= ~0x03;
1354 case (L1_MODE_EXTRN
):
1356 cs
->hw
.hfcpci
.conn
|= 0x10;
1357 cs
->hw
.hfcpci
.sctrl
|= SCTRL_B2_ENA
;
1358 cs
->hw
.hfcpci
.sctrl_r
|= SCTRL_B2_ENA
;
1359 cs
->hw
.hfcpci
.fifo_en
&= ~HFCPCI_FIFOEN_B2
;
1360 cs
->hw
.hfcpci
.int_m1
&= ~(HFCPCI_INTS_B2TRANS
+ HFCPCI_INTS_B2REC
);
1362 cs
->hw
.hfcpci
.conn
|= 0x02;
1363 cs
->hw
.hfcpci
.sctrl
|= SCTRL_B1_ENA
;
1364 cs
->hw
.hfcpci
.sctrl_r
|= SCTRL_B1_ENA
;
1365 cs
->hw
.hfcpci
.fifo_en
&= ~HFCPCI_FIFOEN_B1
;
1366 cs
->hw
.hfcpci
.int_m1
&= ~(HFCPCI_INTS_B1TRANS
+ HFCPCI_INTS_B1REC
);
1370 Write_hfc(cs
, HFCPCI_SCTRL_E
, cs
->hw
.hfcpci
.sctrl_e
);
1371 Write_hfc(cs
, HFCPCI_INT_M1
, cs
->hw
.hfcpci
.int_m1
);
1372 Write_hfc(cs
, HFCPCI_FIFO_EN
, cs
->hw
.hfcpci
.fifo_en
);
1373 Write_hfc(cs
, HFCPCI_SCTRL
, cs
->hw
.hfcpci
.sctrl
);
1374 Write_hfc(cs
, HFCPCI_SCTRL_R
, cs
->hw
.hfcpci
.sctrl_r
);
1375 Write_hfc(cs
, HFCPCI_CTMT
, cs
->hw
.hfcpci
.ctmt
);
1376 Write_hfc(cs
, HFCPCI_CONNECT
, cs
->hw
.hfcpci
.conn
);
1377 restore_flags(flags
);
1380 /******************************/
1381 /* Layer2 -> Layer 1 Transfer */
1382 /******************************/
1384 hfcpci_l2l1(struct PStack
*st
, int pr
, void *arg
)
1386 struct sk_buff
*skb
= arg
;
1390 case (PH_DATA
| REQUEST
):
1393 if (st
->l1
.bcs
->tx_skb
) {
1394 skb_queue_tail(&st
->l1
.bcs
->squeue
, skb
);
1395 restore_flags(flags
);
1397 st
->l1
.bcs
->tx_skb
= skb
;
1398 /* test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
1399 */ st
->l1
.bcs
->cs
->BC_Send_Data(st
->l1
.bcs
);
1400 restore_flags(flags
);
1403 case (PH_PULL
| INDICATION
):
1404 if (st
->l1
.bcs
->tx_skb
) {
1405 printk(KERN_WARNING
"hfc_l2l1: this shouldn't happen\n");
1410 /* test_and_set_bit(BC_FLG_BUSY, &st->l1.bcs->Flag);
1411 */ st
->l1
.bcs
->tx_skb
= skb
;
1412 st
->l1
.bcs
->cs
->BC_Send_Data(st
->l1
.bcs
);
1413 restore_flags(flags
);
1415 case (PH_PULL
| REQUEST
):
1416 if (!st
->l1
.bcs
->tx_skb
) {
1417 test_and_clear_bit(FLG_L1_PULL_REQ
, &st
->l1
.Flags
);
1418 st
->l1
.l1l2(st
, PH_PULL
| CONFIRM
, NULL
);
1420 test_and_set_bit(FLG_L1_PULL_REQ
, &st
->l1
.Flags
);
1422 case (PH_ACTIVATE
| REQUEST
):
1423 test_and_set_bit(BC_FLG_ACTIV
, &st
->l1
.bcs
->Flag
);
1424 mode_hfcpci(st
->l1
.bcs
, st
->l1
.mode
, st
->l1
.bc
);
1425 l1_msg_b(st
, pr
, arg
);
1427 case (PH_DEACTIVATE
| REQUEST
):
1428 l1_msg_b(st
, pr
, arg
);
1430 case (PH_DEACTIVATE
| CONFIRM
):
1431 test_and_clear_bit(BC_FLG_ACTIV
, &st
->l1
.bcs
->Flag
);
1432 test_and_clear_bit(BC_FLG_BUSY
, &st
->l1
.bcs
->Flag
);
1433 mode_hfcpci(st
->l1
.bcs
, 0, st
->l1
.bc
);
1434 st
->l1
.l1l2(st
, PH_DEACTIVATE
| CONFIRM
, NULL
);
1439 /******************************************/
1440 /* deactivate B-channel access and queues */
1441 /******************************************/
1443 close_hfcpci(struct BCState
*bcs
)
1445 mode_hfcpci(bcs
, 0, bcs
->channel
);
1446 if (test_and_clear_bit(BC_FLG_INIT
, &bcs
->Flag
)) {
1447 discard_queue(&bcs
->rqueue
);
1448 discard_queue(&bcs
->squeue
);
1450 dev_kfree_skb_any(bcs
->tx_skb
);
1452 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
1457 /*************************************/
1458 /* init B-channel queues and control */
1459 /*************************************/
1461 open_hfcpcistate(struct IsdnCardState
*cs
, struct BCState
*bcs
)
1463 if (!test_and_set_bit(BC_FLG_INIT
, &bcs
->Flag
)) {
1464 skb_queue_head_init(&bcs
->rqueue
);
1465 skb_queue_head_init(&bcs
->squeue
);
1468 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
1474 /*********************************/
1475 /* inits the stack for B-channel */
1476 /*********************************/
1478 setstack_2b(struct PStack
*st
, struct BCState
*bcs
)
1480 bcs
->channel
= st
->l1
.bc
;
1481 if (open_hfcpcistate(st
->l1
.hardware
, bcs
))
1484 st
->l2
.l2l1
= hfcpci_l2l1
;
1485 setstack_manager(st
);
1491 /***************************/
1492 /* handle L1 state changes */
1493 /***************************/
1495 hfcpci_bh(struct IsdnCardState
*cs
)
1498 /* struct PStack *stptr;
1502 if (test_and_clear_bit(D_L1STATECHANGE
, &cs
->event
)) {
1503 if (!cs
->hw
.hfcpci
.nt_mode
)
1504 switch (cs
->dc
.hfcpci
.ph_state
) {
1506 l1_msg(cs
, HW_RESET
| INDICATION
, NULL
);
1509 l1_msg(cs
, HW_DEACTIVATE
| INDICATION
, NULL
);
1512 l1_msg(cs
, HW_RSYNC
| INDICATION
, NULL
);
1515 l1_msg(cs
, HW_INFO2
| INDICATION
, NULL
);
1518 l1_msg(cs
, HW_INFO4_P8
| INDICATION
, NULL
);
1523 switch (cs
->dc
.hfcpci
.ph_state
) {
1527 if (cs
->hw
.hfcpci
.nt_timer
< 0) {
1528 cs
->hw
.hfcpci
.nt_timer
= 0;
1529 cs
->hw
.hfcpci
.int_m1
&= ~HFCPCI_INTS_TIMER
;
1530 Write_hfc(cs
, HFCPCI_INT_M1
, cs
->hw
.hfcpci
.int_m1
);
1531 /* Clear already pending ints */
1532 if (Read_hfc(cs
, HFCPCI_INT_S1
));
1534 Write_hfc(cs
, HFCPCI_STATES
, 4 | HFCPCI_LOAD_STATE
);
1536 Write_hfc(cs
, HFCPCI_STATES
, 4);
1537 cs
->dc
.hfcpci
.ph_state
= 4;
1539 cs
->hw
.hfcpci
.int_m1
|= HFCPCI_INTS_TIMER
;
1540 Write_hfc(cs
, HFCPCI_INT_M1
, cs
->hw
.hfcpci
.int_m1
);
1541 cs
->hw
.hfcpci
.ctmt
&= ~HFCPCI_AUTO_TIMER
;
1542 cs
->hw
.hfcpci
.ctmt
|= HFCPCI_TIM3_125
;
1543 Write_hfc(cs
, HFCPCI_CTMT
, cs
->hw
.hfcpci
.ctmt
| HFCPCI_CLTIMER
);
1544 Write_hfc(cs
, HFCPCI_CTMT
, cs
->hw
.hfcpci
.ctmt
| HFCPCI_CLTIMER
);
1545 cs
->hw
.hfcpci
.nt_timer
= NT_T1_COUNT
;
1546 Write_hfc(cs
, HFCPCI_STATES
, 2 | HFCPCI_NT_G2_G3
); /* allow G2 -> G3 transition */
1548 restore_flags(flags
);
1555 cs
->hw
.hfcpci
.nt_timer
= 0;
1556 cs
->hw
.hfcpci
.int_m1
&= ~HFCPCI_INTS_TIMER
;
1557 Write_hfc(cs
, HFCPCI_INT_M1
, cs
->hw
.hfcpci
.int_m1
);
1558 restore_flags(flags
);
1565 if (test_and_clear_bit(D_RCVBUFREADY
, &cs
->event
))
1566 DChannel_proc_rcv(cs
);
1567 if (test_and_clear_bit(D_XMTBUFREADY
, &cs
->event
))
1568 DChannel_proc_xmt(cs
);
1572 /********************************/
1573 /* called for card init message */
1574 /********************************/
1576 inithfcpci(struct IsdnCardState
*cs
)
1578 cs
->setstack_d
= setstack_hfcpci
;
1579 cs
->dbusytimer
.function
= (void *) hfcpci_dbusy_timer
;
1580 cs
->dbusytimer
.data
= (long) cs
;
1581 init_timer(&cs
->dbusytimer
);
1582 cs
->tqueue
.routine
= (void *) (void *) hfcpci_bh
;
1583 cs
->BC_Send_Data
= &hfcpci_send_data
;
1584 cs
->bcs
[0].BC_SetStack
= setstack_2b
;
1585 cs
->bcs
[1].BC_SetStack
= setstack_2b
;
1586 cs
->bcs
[0].BC_Close
= close_hfcpci
;
1587 cs
->bcs
[1].BC_Close
= close_hfcpci
;
1588 mode_hfcpci(cs
->bcs
, 0, 0);
1589 mode_hfcpci(cs
->bcs
+ 1, 0, 1);
1594 /*******************************************/
1595 /* handle card messages from control layer */
1596 /*******************************************/
1598 hfcpci_card_msg(struct IsdnCardState
*cs
, int mt
, void *arg
)
1602 if (cs
->debug
& L1_DEB_ISAC
)
1603 debugl1(cs
, "HFCPCI: card_msg %x", mt
);
1609 release_io_hfcpci(cs
);
1615 set_current_state(TASK_UNINTERRUPTIBLE
);
1616 schedule_timeout((80 * HZ
) / 1000); /* Timeout 80ms */
1617 /* now switch timer interrupt off */
1618 cs
->hw
.hfcpci
.int_m1
&= ~HFCPCI_INTS_TIMER
;
1619 Write_hfc(cs
, HFCPCI_INT_M1
, cs
->hw
.hfcpci
.int_m1
);
1620 /* reinit mode reg */
1621 Write_hfc(cs
, HFCPCI_MST_MODE
, cs
->hw
.hfcpci
.mst_m
);
1622 restore_flags(flags
);
1631 /* this variable is used as card index when more than one cards are present */
1632 static struct pci_dev
*dev_hfcpci __initdata
= NULL
;
1634 #endif /* CONFIG_PCI */
1636 int __init
setup_hfcpci(struct IsdnCard
*card
)
1638 struct IsdnCardState
*cs
= card
->cs
;
1641 struct pci_dev
*tmp_hfcpci
= NULL
;
1644 #error "not running on big endian machines now"
1646 strcpy(tmp
, hfcpci_revision
);
1647 printk(KERN_INFO
"HiSax: HFC-PCI driver Rev. %s\n", HiSax_getrev(tmp
));
1649 cs
->hw
.hfcpci
.int_s1
= 0;
1650 cs
->dc
.hfcpci
.ph_state
= 0;
1651 cs
->hw
.hfcpci
.fifo
= 255;
1652 if (cs
->typ
== ISDN_CTYPE_HFC_PCI
) {
1654 while (id_list
[i
].vendor_id
) {
1655 tmp_hfcpci
= pci_find_device(id_list
[i
].vendor_id
,
1656 id_list
[i
].device_id
,
1660 if (pci_enable_device(tmp_hfcpci
))
1662 if ((card
->para
[0]) && (card
->para
[0] != (tmp_hfcpci
->resource
[ 0].start
& PCI_BASE_ADDRESS_IO_MASK
)))
1671 dev_hfcpci
= tmp_hfcpci
; /* old device */
1672 cs
->hw
.hfcpci
.pci_bus
= dev_hfcpci
->bus
->number
;
1673 cs
->hw
.hfcpci
.pci_device_fn
= dev_hfcpci
->devfn
;
1674 cs
->irq
= dev_hfcpci
->irq
;
1676 printk(KERN_WARNING
"HFC-PCI: No IRQ for PCI card found\n");
1679 cs
->hw
.hfcpci
.pci_io
= (char *) dev_hfcpci
->resource
[ 1].start
;
1680 printk(KERN_INFO
"HiSax: HFC-PCI card manufacturer: %s card name: %s\n", id_list
[i
].vendor_name
, id_list
[i
].card_name
);
1682 printk(KERN_WARNING
"HFC-PCI: No PCI card found\n");
1685 if (!cs
->hw
.hfcpci
.pci_io
) {
1686 printk(KERN_WARNING
"HFC-PCI: No IO-Mem for PCI card found\n");
1689 /* Allocate memory for FIFOS */
1690 /* Because the HFC-PCI needs a 32K physical alignment, we */
1691 /* need to allocate the double mem and align the address */
1692 if (!((void *) cs
->hw
.hfcpci
.share_start
= kmalloc(65536, GFP_KERNEL
))) {
1693 printk(KERN_WARNING
"HFC-PCI: Error allocating memory for FIFO!\n");
1696 (ulong
) cs
->hw
.hfcpci
.fifos
=
1697 (((ulong
) cs
->hw
.hfcpci
.share_start
) & ~0x7FFF) + 0x8000;
1698 pcibios_write_config_dword(cs
->hw
.hfcpci
.pci_bus
,
1699 cs
->hw
.hfcpci
.pci_device_fn
, 0x80,
1700 (u_int
) virt_to_bus(cs
->hw
.hfcpci
.fifos
));
1701 cs
->hw
.hfcpci
.pci_io
= ioremap((ulong
) cs
->hw
.hfcpci
.pci_io
, 256);
1703 "HFC-PCI: defined at mem %#x fifo %#x(%#x) IRQ %d HZ %d\n",
1704 (u_int
) cs
->hw
.hfcpci
.pci_io
,
1705 (u_int
) cs
->hw
.hfcpci
.fifos
,
1706 (u_int
) virt_to_bus(cs
->hw
.hfcpci
.fifos
),
1708 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 */
1709 cs
->hw
.hfcpci
.int_m2
= 0; /* disable alle interrupts */
1710 cs
->hw
.hfcpci
.int_m1
= 0;
1711 Write_hfc(cs
, HFCPCI_INT_M1
, cs
->hw
.hfcpci
.int_m1
);
1712 Write_hfc(cs
, HFCPCI_INT_M2
, cs
->hw
.hfcpci
.int_m2
);
1713 /* At this point the needed PCI config is done */
1714 /* fifos are still not enabled */
1716 return (0); /* no valid card type */
1719 cs
->readisac
= NULL
;
1720 cs
->writeisac
= NULL
;
1721 cs
->readisacfifo
= NULL
;
1722 cs
->writeisacfifo
= NULL
;
1723 cs
->BC_Read_Reg
= NULL
;
1724 cs
->BC_Write_Reg
= NULL
;
1725 cs
->irq_func
= &hfcpci_interrupt
;
1726 cs
->irq_flags
|= SA_SHIRQ
;
1728 cs
->hw
.hfcpci
.timer
.function
= (void *) hfcpci_Timer
;
1729 cs
->hw
.hfcpci
.timer
.data
= (long) cs
;
1730 init_timer(&cs
->hw
.hfcpci
.timer
);
1733 cs
->cardmsg
= &hfcpci_card_msg
;
1734 cs
->auxcmd
= &hfcpci_auxcmd
;
1737 printk(KERN_WARNING
"HFC-PCI: NO_PCI_BIOS\n");
1739 #endif /* CONFIG_PCI */