1 /* $Id: isar.c,v 1.5 1999/08/25 16:59:55 keil Exp $
3 * isar.c ISAR (Siemens PSB 7110) specific routines
5 * Author Karsten Keil (keil@isdn4linux.de)
9 * Revision 1.5 1999/08/25 16:59:55 keil
10 * Make ISAR V32bis modem running
11 * Make LL->HL interface open for additional commands
13 * Revision 1.4 1999/08/05 20:43:18 keil
14 * ISAR analog modem support
16 * Revision 1.3 1999/07/01 08:11:45 keil
17 * Common HiSax version for 2.0, 2.1, 2.2 and 2.3 kernel
19 * Revision 1.2 1998/11/15 23:54:53 keil
22 * Revision 1.1 1998/08/13 23:33:47 keil
23 * First version, only init
28 #define __NO_VERSION__
32 #include <linux/interrupt.h>
34 #define DBG_LOADFIRM 0
35 #define DUMP_MBOXFRAME 2
37 #define MIN(a,b) ((a<b)?a:b)
39 void isar_setup(struct IsdnCardState
*cs
);
42 waitforHIA(struct IsdnCardState
*cs
, int timeout
)
45 while ((cs
->BC_Read_Reg(cs
, 0, ISAR_HIA
) & 1) && timeout
) {
50 printk(KERN_WARNING
"HiSax: ISAR waitforHIA timeout\n");
56 sendmsg(struct IsdnCardState
*cs
, u_char his
, u_char creg
, u_char len
,
62 if (!waitforHIA(cs
, 4000))
65 if (cs
->debug
& L1_DEB_HSCX
)
66 debugl1(cs
, "sendmsg(%02x,%02x,%d)", his
, creg
, len
);
70 cs
->BC_Write_Reg(cs
, 0, ISAR_CTRL_H
, creg
);
71 cs
->BC_Write_Reg(cs
, 0, ISAR_CTRL_L
, len
);
72 cs
->BC_Write_Reg(cs
, 0, ISAR_WADR
, 0);
74 cs
->BC_Write_Reg(cs
, 1, ISAR_MBOX
, msg
[0]);
76 cs
->BC_Write_Reg(cs
, 2, ISAR_MBOX
, msg
[i
]);
78 if (cs
->debug
& L1_DEB_HSCX_FIFO
) {
84 t
+= sprintf(t
, "sendmbox cnt %d", len
);
85 QuickHex(t
, &msg
[len
-i
], (i
>64) ? 64:i
);
92 cs
->BC_Write_Reg(cs
, 1, ISAR_HIS
, his
);
94 waitforHIA(cs
, 10000);
98 /* Call only with IRQ disabled !!! */
100 rcv_mbox(struct IsdnCardState
*cs
, struct isar_reg
*ireg
, u_char
*msg
)
104 cs
->BC_Write_Reg(cs
, 1, ISAR_RADR
, 0);
105 if (msg
&& ireg
->clsb
) {
106 msg
[0] = cs
->BC_Read_Reg(cs
, 1, ISAR_MBOX
);
107 for (i
=1; i
< ireg
->clsb
; i
++)
108 msg
[i
] = cs
->BC_Read_Reg(cs
, 2, ISAR_MBOX
);
110 if (cs
->debug
& L1_DEB_HSCX_FIFO
) {
116 t
+= sprintf(t
, "rcv_mbox cnt %d", ireg
->clsb
);
117 QuickHex(t
, &msg
[ireg
->clsb
-i
], (i
>64) ? 64:i
);
124 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
127 /* Call only with IRQ disabled !!! */
129 get_irq_infos(struct IsdnCardState
*cs
, struct isar_reg
*ireg
)
131 ireg
->iis
= cs
->BC_Read_Reg(cs
, 1, ISAR_IIS
);
132 ireg
->cmsb
= cs
->BC_Read_Reg(cs
, 1, ISAR_CTRL_H
);
133 ireg
->clsb
= cs
->BC_Read_Reg(cs
, 1, ISAR_CTRL_L
);
135 if (cs
->debug
& L1_DEB_HSCX
)
136 debugl1(cs
, "rcv_mbox(%02x,%02x,%d)", ireg
->iis
, ireg
->cmsb
,
142 waitrecmsg(struct IsdnCardState
*cs
, u_char
*len
,
143 u_char
*msg
, int maxdelay
)
147 struct isar_reg
*ir
= cs
->bcs
[0].hw
.isar
.reg
;
150 while((!(cs
->BC_Read_Reg(cs
, 0, ISAR_IRQBIT
) & ISAR_IRQSTA
)) &&
151 (timeout
++ < maxdelay
))
153 if (timeout
>= maxdelay
) {
154 printk(KERN_WARNING
"isar recmsg IRQSTA timeout\n");
159 get_irq_infos(cs
, ir
);
160 rcv_mbox(cs
, ir
, msg
);
162 restore_flags(flags
);
167 ISARVersion(struct IsdnCardState
*cs
, char *s
)
170 u_char msg
[] = ISAR_MSG_HWVER
;
175 cs
->cardmsg(cs
, CARD_RESET
, NULL
);
176 /* disable ISAR IRQ */
177 cs
->BC_Write_Reg(cs
, 0, ISAR_IRQBIT
, 0);
179 cs
->debug
&= ~(L1_DEB_HSCX
| L1_DEB_HSCX_FIFO
);
180 if (!sendmsg(cs
, ISAR_HIS_VNR
, 0, 3, msg
))
182 if (!waitrecmsg(cs
, &len
, tmp
, 100000))
185 if (cs
->bcs
[0].hw
.isar
.reg
->iis
== ISAR_IIS_VNR
) {
188 printk(KERN_INFO
"%s ISAR version %d\n", s
, ver
);
197 isar_load_firmware(struct IsdnCardState
*cs
, u_char
*buf
)
199 int ret
, size
, cnt
, debug
;
200 u_char len
, nom
, noc
;
201 u_short sadr
, left
, *sp
;
203 u_char
*msg
, *tmpmsg
, *mp
, tmp
[64];
205 struct isar_reg
*ireg
= cs
->bcs
[0].hw
.isar
.reg
;
207 struct {u_short sadr
;
212 #define BLK_HEAD_SIZE 6
213 if (1 != (ret
= ISARVersion(cs
, "Testing"))) {
214 printk(KERN_ERR
"isar_load_firmware wrong isar version %d\n", ret
);
219 cs
->debug
&= ~(L1_DEB_HSCX
| L1_DEB_HSCX_FIFO
);
221 printk(KERN_DEBUG
"isar_load_firmware buf %#lx\n", (u_long
)buf
);
222 if ((ret
= verify_area(VERIFY_READ
, (void *) p
, sizeof(int)))) {
223 printk(KERN_ERR
"isar_load_firmware verify_area ret %d\n", ret
);
226 if ((ret
= copy_from_user(&size
, p
, sizeof(int)))) {
227 printk(KERN_ERR
"isar_load_firmware copy_from_user ret %d\n", ret
);
231 printk(KERN_DEBUG
"isar_load_firmware size: %d\n", size
);
232 if ((ret
= verify_area(VERIFY_READ
, (void *) p
, size
))) {
233 printk(KERN_ERR
"isar_load_firmware verify_area ret %d\n", ret
);
237 /* disable ISAR IRQ */
238 cs
->BC_Write_Reg(cs
, 0, ISAR_IRQBIT
, 0);
239 if (!(msg
= kmalloc(256, GFP_KERNEL
))) {
240 printk(KERN_ERR
"isar_load_firmware no buffer\n");
243 if (!(tmpmsg
= kmalloc(256, GFP_KERNEL
))) {
244 printk(KERN_ERR
"isar_load_firmware no tmp buffer\n");
249 if ((ret
= copy_from_user(&blk_head
, p
, BLK_HEAD_SIZE
))) {
250 printk(KERN_ERR
"isar_load_firmware copy_from_user ret %d\n", ret
);
253 cnt
+= BLK_HEAD_SIZE
;
255 printk(KERN_DEBUG
"isar firmware block (%#x,%5d,%#x)\n",
256 blk_head
.sadr
, blk_head
.len
, blk_head
.d_key
& 0xff);
257 sadr
= blk_head
.sadr
;
259 if (!sendmsg(cs
, ISAR_HIS_DKEY
, blk_head
.d_key
& 0xff, 0, NULL
)) {
260 printk(KERN_ERR
"isar sendmsg dkey failed\n");
261 ret
= 1;goto reterror
;
263 if (!waitrecmsg(cs
, &len
, tmp
, 100000)) {
264 printk(KERN_ERR
"isar waitrecmsg dkey failed\n");
265 ret
= 1;goto reterror
;
267 if ((ireg
->iis
!= ISAR_IIS_DKEY
) || ireg
->cmsb
|| len
) {
268 printk(KERN_ERR
"isar wrong dkey response (%x,%x,%x)\n",
269 ireg
->iis
, ireg
->cmsb
, len
);
270 ret
= 1;goto reterror
;
273 noc
= MIN(126, left
);
280 if ((ret
= copy_from_user(tmpmsg
, p
, nom
))) {
281 printk(KERN_ERR
"isar_load_firmware copy_from_user ret %d\n", ret
);
287 sp
= (u_short
*)tmpmsg
;
289 printk(KERN_DEBUG
"isar: load %3d words at %04x\n",
299 if (!sendmsg(cs
, ISAR_HIS_FIRM
, 0, nom
, msg
)) {
300 printk(KERN_ERR
"isar sendmsg prog failed\n");
301 ret
= 1;goto reterror
;
303 if (!waitrecmsg(cs
, &len
, tmp
, 100000)) {
304 printk(KERN_ERR
"isar waitrecmsg prog failed\n");
305 ret
= 1;goto reterror
;
307 if ((ireg
->iis
!= ISAR_IIS_FIRM
) || ireg
->cmsb
|| len
) {
308 printk(KERN_ERR
"isar wrong prog response (%x,%x,%x)\n",
309 ireg
->iis
, ireg
->cmsb
, len
);
310 ret
= 1;goto reterror
;
313 printk(KERN_DEBUG
"isar firmware block %5d words loaded\n",
323 if (!sendmsg(cs
, ISAR_HIS_STDSP
, 0, 2, msg
)) {
324 printk(KERN_ERR
"isar sendmsg start dsp failed\n");
325 ret
= 1;goto reterror
;
327 if (!waitrecmsg(cs
, &len
, tmp
, 100000)) {
328 printk(KERN_ERR
"isar waitrecmsg start dsp failed\n");
329 ret
= 1;goto reterror
;
331 if ((ireg
->iis
!= ISAR_IIS_STDSP
) || ireg
->cmsb
|| len
) {
332 printk(KERN_ERR
"isar wrong start dsp response (%x,%x,%x)\n",
333 ireg
->iis
, ireg
->cmsb
, len
);
334 ret
= 1;goto reterror
;
336 printk(KERN_DEBUG
"isar start dsp success\n");
337 /* NORMAL mode entered */
338 /* Enable IRQs of ISAR */
339 cs
->BC_Write_Reg(cs
, 0, ISAR_IRQBIT
, ISAR_IRQSTA
);
342 cnt
= 1000; /* max 1s */
343 while ((!ireg
->bstat
) && cnt
) {
348 printk(KERN_ERR
"isar no general status event received\n");
349 ret
= 1;goto reterrflg
;
351 printk(KERN_DEBUG
"isar general status event %x\n",
359 if (!sendmsg(cs
, ISAR_HIS_DIAG
, ISAR_CTRL_STST
, 0, NULL
)) {
360 printk(KERN_ERR
"isar sendmsg self tst failed\n");
361 ret
= 1;goto reterrflg
;
363 cnt
= 10000; /* max 100 ms */
364 while ((ireg
->iis
!= ISAR_IIS_DIAG
) && cnt
) {
370 printk(KERN_ERR
"isar no self tst response\n");
371 ret
= 1;goto reterrflg
;
373 if ((ireg
->cmsb
== ISAR_CTRL_STST
) && (ireg
->clsb
== 1)
374 && (ireg
->par
[0] == 0)) {
375 printk(KERN_DEBUG
"isar selftest OK\n");
377 printk(KERN_DEBUG
"isar selftest not OK %x/%x/%x\n",
378 ireg
->cmsb
, ireg
->clsb
, ireg
->par
[0]);
379 ret
= 1;goto reterror
;
382 if (!sendmsg(cs
, ISAR_HIS_DIAG
, ISAR_CTRL_SWVER
, 0, NULL
)) {
383 printk(KERN_ERR
"isar RQST SVN failed\n");
384 ret
= 1;goto reterror
;
386 cnt
= 30000; /* max 300 ms */
387 while ((ireg
->iis
!= ISAR_IIS_DIAG
) && cnt
) {
393 printk(KERN_ERR
"isar no SVN response\n");
394 ret
= 1;goto reterrflg
;
396 if ((ireg
->cmsb
== ISAR_CTRL_SWVER
) && (ireg
->clsb
== 1))
397 printk(KERN_DEBUG
"isar software version %#x\n",
400 printk(KERN_ERR
"isar wrong swver response (%x,%x) cnt(%d)\n",
401 ireg
->cmsb
, ireg
->clsb
, cnt
);
402 ret
= 1;goto reterrflg
;
409 restore_flags(flags
);
413 /* disable ISAR IRQ */
414 cs
->BC_Write_Reg(cs
, 0, ISAR_IRQBIT
, 0);
420 extern void BChannel_bh(struct BCState
*);
421 #define B_LL_NOCARRIER 8
422 #define B_LL_CONNECT 9
426 isar_bh(struct BCState
*bcs
)
432 isar_sched_event(struct BCState
*bcs
, int event
)
434 bcs
->event
|= 1 << event
;
435 queue_task(&bcs
->tqueue
, &tq_immediate
);
436 mark_bh(IMMEDIATE_BH
);
440 isar_rcv_frame(struct IsdnCardState
*cs
, struct BCState
*bcs
)
444 struct isar_reg
*ireg
= bcs
->hw
.isar
.reg
;
447 debugl1(cs
, "isar zero len frame");
448 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
453 debugl1(cs
, "isar mode 0 spurious IIS_RDATA %x/%x/%x",
454 ireg
->iis
, ireg
->cmsb
, ireg
->clsb
);
455 printk(KERN_WARNING
"isar mode 0 spurious IIS_RDATA %x/%x/%x\n",
456 ireg
->iis
, ireg
->cmsb
, ireg
->clsb
);
457 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
461 if ((skb
= dev_alloc_skb(ireg
->clsb
))) {
463 rcv_mbox(cs
, ireg
, (u_char
*)skb_put(skb
, ireg
->clsb
));
464 skb_queue_tail(&bcs
->rqueue
, skb
);
465 isar_sched_event(bcs
, B_RCVBUFREADY
);
467 printk(KERN_WARNING
"HiSax: skb out of memory\n");
468 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
472 if ((bcs
->hw
.isar
.rcvidx
+ ireg
->clsb
) > HSCX_BUFMAX
) {
473 if (cs
->debug
& L1_DEB_WARN
)
474 debugl1(cs
, "isar_rcv_frame: incoming packet too large");
475 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
476 bcs
->hw
.isar
.rcvidx
= 0;
477 } else if (ireg
->cmsb
& HDLC_ERROR
) {
478 if (cs
->debug
& L1_DEB_WARN
)
479 debugl1(cs
, "isar frame error %x len %d",
480 ireg
->cmsb
, ireg
->clsb
);
481 bcs
->hw
.isar
.rcvidx
= 0;
482 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
484 if (ireg
->cmsb
& HDLC_FSD
)
485 bcs
->hw
.isar
.rcvidx
= 0;
486 ptr
= bcs
->hw
.isar
.rcvbuf
+ bcs
->hw
.isar
.rcvidx
;
487 bcs
->hw
.isar
.rcvidx
+= ireg
->clsb
;
488 rcv_mbox(cs
, ireg
, ptr
);
489 if (ireg
->cmsb
& HDLC_FED
) {
490 if (bcs
->hw
.isar
.rcvidx
< 3) { /* last 2 bytes are the FCS */
491 printk(KERN_WARNING
"ISAR: HDLC frame too short(%d)\n",
492 bcs
->hw
.isar
.rcvidx
);
493 } else if (!(skb
= dev_alloc_skb(bcs
->hw
.isar
.rcvidx
-2))) {
494 printk(KERN_WARNING
"ISAR: receive out of memory\n");
497 memcpy(skb_put(skb
, bcs
->hw
.isar
.rcvidx
-2),
498 bcs
->hw
.isar
.rcvbuf
, bcs
->hw
.isar
.rcvidx
-2);
499 skb_queue_tail(&bcs
->rqueue
, skb
);
500 isar_sched_event(bcs
, B_RCVBUFREADY
);
506 printk(KERN_ERR
"isar_rcv_frame mode (%x)error\n", bcs
->mode
);
507 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
513 isar_fill_fifo(struct BCState
*bcs
)
515 struct IsdnCardState
*cs
= bcs
->cs
;
521 if ((cs
->debug
& L1_DEB_HSCX
) && !(cs
->debug
& L1_DEB_HSCX_FIFO
))
522 debugl1(cs
, "isar_fill_fifo");
525 if (bcs
->tx_skb
->len
<= 0)
527 if (!(bcs
->hw
.isar
.reg
->bstat
&
528 (bcs
->hw
.isar
.dpath
== 1 ? BSTAT_RDM1
: BSTAT_RDM2
)))
530 if (bcs
->tx_skb
->len
> bcs
->hw
.isar
.mml
) {
532 count
= bcs
->hw
.isar
.mml
;
534 count
= bcs
->tx_skb
->len
;
537 if (!bcs
->hw
.isar
.txcnt
)
541 ptr
= bcs
->tx_skb
->data
;
542 skb_pull(bcs
->tx_skb
, count
);
543 bcs
->tx_cnt
-= count
;
544 bcs
->hw
.isar
.txcnt
+= count
;
547 printk(KERN_ERR
"isar_fill_fifo wrong mode 0\n");
551 if (!sendmsg(cs
, SET_DPS(bcs
->hw
.isar
.dpath
) | ISAR_HIS_SDATA
,
554 debugl1(cs
, "isar bin data send dp%d failed",
559 if (!sendmsg(cs
, SET_DPS(bcs
->hw
.isar
.dpath
) | ISAR_HIS_SDATA
,
562 debugl1(cs
, "isar hdlc data send dp%d failed",
567 printk(KERN_ERR
"isar_fill_fifo mode (%x)error\n", bcs
->mode
);
570 restore_flags(flags
);
574 struct BCState
*sel_bcs_isar(struct IsdnCardState
*cs
, u_char dpath
)
576 if ((!dpath
) || (dpath
== 3))
578 if (cs
->bcs
[0].hw
.isar
.dpath
== dpath
)
580 if (cs
->bcs
[1].hw
.isar
.dpath
== dpath
)
586 send_frames(struct BCState
*bcs
)
589 if (bcs
->tx_skb
->len
) {
593 if (bcs
->st
->lli
.l1writewakeup
&&
594 (PACKET_NOACK
!= bcs
->tx_skb
->pkt_type
))
595 bcs
->st
->lli
.l1writewakeup(bcs
->st
, bcs
->hw
.isar
.txcnt
);
596 idev_kfree_skb(bcs
->tx_skb
, FREE_WRITE
);
597 bcs
->hw
.isar
.txcnt
= 0;
601 if ((bcs
->tx_skb
= skb_dequeue(&bcs
->squeue
))) {
602 bcs
->hw
.isar
.txcnt
= 0;
603 test_and_set_bit(BC_FLG_BUSY
, &bcs
->Flag
);
606 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
607 isar_sched_event(bcs
, B_XMTBUFREADY
);
612 check_send(struct IsdnCardState
*cs
, u_char rdm
)
616 if (rdm
& BSTAT_RDM1
) {
617 if ((bcs
= sel_bcs_isar(cs
, 1))) {
623 if (rdm
& BSTAT_RDM2
) {
624 if ((bcs
= sel_bcs_isar(cs
, 2))) {
632 const char *dmril
[] = {"NO SPEED", "1200/75", "NODEF2", "75/1200", "NODEF4",
633 "300", "600", "1200", "2400", "4800", "7200",
634 "9600nt", "9600t", "12000", "14400", "WRONG"};
635 const char *dmrim
[] = {"NO MOD", "NO DEF", "V32/V32b", "V22", "V21",
636 "Bell103", "V23", "Bell202", "V17", "V29", "V27ter"};
639 isar_pump_status_rsp(struct BCState
*bcs
, struct isar_reg
*ireg
) {
640 struct IsdnCardState
*cs
= bcs
->cs
;
641 u_char ril
= ireg
->par
[0];
644 if (!test_and_clear_bit(ISAR_RATE_REQ
, &bcs
->hw
.isar
.reg
->Flags
))
647 if (cs
->debug
& L1_DEB_WARN
)
648 debugl1(cs
, "wrong pstrsp ril=%d",ril
);
651 switch(ireg
->par
[1]) {
686 sprintf(bcs
->hw
.isar
.conmsg
,"%s %s", dmril
[ril
], dmrim
[rim
]);
687 bcs
->conmsg
= bcs
->hw
.isar
.conmsg
;
688 if (cs
->debug
& L1_DEB_HSCX
)
689 debugl1(cs
, "pump strsp %s", bcs
->conmsg
);
693 isar_pump_status_ev(struct BCState
*bcs
, u_char devt
) {
694 struct IsdnCardState
*cs
= bcs
->cs
;
695 u_char dps
= SET_DPS(bcs
->hw
.isar
.dpath
);
698 case PSEV_10MS_TIMER
:
699 if (cs
->debug
& L1_DEB_HSCX
)
700 debugl1(cs
, "pump stev TIMER");
703 if (cs
->debug
& L1_DEB_HSCX
)
704 debugl1(cs
, "pump stev CONNECT");
705 l1_msg_b(bcs
->st
, PH_ACTIVATE
| REQUEST
, NULL
);
708 if (cs
->debug
& L1_DEB_HSCX
)
709 debugl1(cs
, "pump stev NO CONNECT");
710 sendmsg(cs
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
711 l1_msg_b(bcs
->st
, PH_DEACTIVATE
| REQUEST
, NULL
);
714 if (cs
->debug
& L1_DEB_HSCX
)
715 debugl1(cs
, "pump stev V24 OFF");
718 if (cs
->debug
& L1_DEB_HSCX
)
719 debugl1(cs
, "pump stev CTS ON");
722 if (cs
->debug
& L1_DEB_HSCX
)
723 debugl1(cs
, "pump stev CTS OFF");
726 if (cs
->debug
& L1_DEB_HSCX
)
727 debugl1(cs
, "pump stev CARRIER ON");
728 test_and_set_bit(ISAR_RATE_REQ
, &bcs
->hw
.isar
.reg
->Flags
);
729 sendmsg(cs
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
);
732 if (cs
->debug
& L1_DEB_HSCX
)
733 debugl1(cs
, "pump stev CARRIER OFF");
736 if (cs
->debug
& L1_DEB_HSCX
)
737 debugl1(cs
, "pump stev DSR ON");
740 if (cs
->debug
& L1_DEB_HSCX
)
741 debugl1(cs
, "pump stev DSR_OFF");
744 if (cs
->debug
& L1_DEB_HSCX
)
745 debugl1(cs
, "pump stev REMOTE RETRAIN");
748 if (cs
->debug
& L1_DEB_HSCX
)
749 debugl1(cs
, "pump stev REMOTE RENEGOTIATE");
752 if (cs
->debug
& L1_DEB_HSCX
)
753 debugl1(cs
, "pump stev GSTN CLEAR", devt
);
756 if (cs
->debug
& L1_DEB_HSCX
)
757 debugl1(cs
, "unknown pump stev %x", devt
);
762 static char debbuf
[128];
765 isar_int_main(struct IsdnCardState
*cs
)
768 struct isar_reg
*ireg
= cs
->bcs
[0].hw
.isar
.reg
;
773 get_irq_infos(cs
, ireg
);
774 switch (ireg
->iis
& ISAR_IIS_MSCMSD
) {
776 if ((bcs
= sel_bcs_isar(cs
, ireg
->iis
>> 6))) {
777 isar_rcv_frame(cs
, bcs
);
779 debugl1(cs
, "isar spurious IIS_RDATA %x/%x/%x",
780 ireg
->iis
, ireg
->cmsb
, ireg
->clsb
);
781 printk(KERN_WARNING
"isar spurious IIS_RDATA %x/%x/%x\n",
782 ireg
->iis
, ireg
->cmsb
, ireg
->clsb
);
783 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
787 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
788 ireg
->bstat
|= ireg
->cmsb
;
789 check_send(cs
, ireg
->cmsb
);
792 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
793 if (cs
->debug
& L1_DEB_WARN
)
794 debugl1(cs
, "Buffer STEV dpath%d msb(%x)",
795 ireg
->iis
>>6, ireg
->cmsb
);
797 if ((bcs
= sel_bcs_isar(cs
, ireg
->iis
>> 6))) {
798 rcv_mbox(cs
, ireg
, (u_char
*)ireg
->par
);
799 isar_pump_status_ev(bcs
, ireg
->cmsb
);
801 debugl1(cs
, "isar spurious IIS_PSTEV %x/%x/%x",
802 ireg
->iis
, ireg
->cmsb
, ireg
->clsb
);
803 printk(KERN_WARNING
"isar spurious IIS_PSTEV %x/%x/%x\n",
804 ireg
->iis
, ireg
->cmsb
, ireg
->clsb
);
805 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
808 case ISAR_IIS_PSTRSP
:
809 if ((bcs
= sel_bcs_isar(cs
, ireg
->iis
>> 6))) {
810 rcv_mbox(cs
, ireg
, (u_char
*)ireg
->par
);
811 isar_pump_status_rsp(bcs
, ireg
);
813 debugl1(cs
, "isar spurious IIS_PSTRSP %x/%x/%x",
814 ireg
->iis
, ireg
->cmsb
, ireg
->clsb
);
815 printk(KERN_WARNING
"isar spurious IIS_PSTRSP %x/%x/%x\n",
816 ireg
->iis
, ireg
->cmsb
, ireg
->clsb
);
817 cs
->BC_Write_Reg(cs
, 1, ISAR_IIA
, 0);
821 case ISAR_IIS_BSTRSP
:
822 case ISAR_IIS_IOM2RSP
:
823 rcv_mbox(cs
, ireg
, (u_char
*)ireg
->par
);
824 if ((cs
->debug
& (L1_DEB_HSCX
| L1_DEB_HSCX_FIFO
))
828 tp
+= sprintf(debbuf
, "msg iis(%x) msb(%x)",
829 ireg
->iis
, ireg
->cmsb
);
830 QuickHex(tp
, (u_char
*)ireg
->par
, ireg
->clsb
);
834 case ISAR_IIS_INVMSG
:
835 rcv_mbox(cs
, ireg
, debbuf
);
836 if (cs
->debug
& L1_DEB_WARN
)
837 debugl1(cs
, "invalid msg his:%x",
841 rcv_mbox(cs
, ireg
, debbuf
);
842 if (cs
->debug
& L1_DEB_WARN
)
843 debugl1(cs
, "unhandled msg iis(%x) ctrl(%x/%x)",
844 ireg
->iis
, ireg
->cmsb
, ireg
->clsb
);
847 restore_flags(flags
);
851 setup_pump(struct BCState
*bcs
) {
852 struct IsdnCardState
*cs
= bcs
->cs
;
853 u_char dps
= SET_DPS(bcs
->hw
.isar
.dpath
);
854 u_char ctrl
, param
[6];
860 if (!sendmsg(cs
, dps
| ISAR_HIS_PUMPCFG
, PMOD_BYPASS
, 0, NULL
)) {
862 debugl1(cs
, "isar pump bypass cfg dp%d failed",
867 ctrl
= PMOD_DATAMODEM
;
868 if (test_bit(BC_FLG_ORIG
, &bcs
->Flag
)) {
870 param
[5] = PV32P6_CTN
;
872 param
[5] = PV32P6_ATN
;
874 param
[0] = 6; /* 6 db */
875 param
[1] = PV32P2_V23R
| PV32P2_V22A
| PV32P2_V22B
|
876 PV32P2_V22C
| PV32P2_V21
| PV32P2_BEL
;
877 param
[2] = PV32P3_AMOD
| PV32P3_V32B
| PV32P3_V23B
;
878 param
[3] = PV32P4_UT144
;
879 param
[4] = PV32P5_UT144
;
880 if (!sendmsg(cs
, dps
| ISAR_HIS_PUMPCFG
, ctrl
, 6, param
)) {
882 debugl1(cs
, "isar pump datamodem cfg dp%d failed",
888 if (test_bit(BC_FLG_ORIG
, &bcs
->Flag
)) {
890 param
[1] = PFAXP2_CTN
;
892 param
[1] = PFAXP2_ATN
;
894 param
[0] = 6; /* 6 db */
895 if (!sendmsg(cs
, dps
| ISAR_HIS_PUMPCFG
, ctrl
, 2, param
)) {
897 debugl1(cs
, "isar pump faxmodem cfg dp%d failed",
902 if (!sendmsg(cs
, dps
| ISAR_HIS_PSTREQ
, 0, 0, NULL
)) {
904 debugl1(cs
, "isar pump status req dp%d failed",
910 setup_sart(struct BCState
*bcs
) {
911 struct IsdnCardState
*cs
= bcs
->cs
;
912 u_char dps
= SET_DPS(bcs
->hw
.isar
.dpath
);
913 u_char ctrl
, param
[2];
917 if (!sendmsg(cs
, dps
| ISAR_HIS_SARTCFG
, SMODE_DISABLE
, 0, NULL
)) {
919 debugl1(cs
, "isar sart disable dp%d failed",
924 if (!sendmsg(cs
, dps
| ISAR_HIS_SARTCFG
, SMODE_BINARY
, 2, "\0\0")) {
926 debugl1(cs
, "isar sart binary dp%d failed",
933 if (!sendmsg(cs
, dps
| ISAR_HIS_SARTCFG
, SMODE_HDLC
, 1, param
)) {
935 debugl1(cs
, "isar sart hdlc dp%d failed",
940 ctrl
= SMODE_V14
| SCTRL_HDMC_BOTH
;
941 param
[0] = S_P1_CHS_8
;
942 param
[1] = S_P2_BFT_DEF
;
943 if (!sendmsg(cs
, dps
| ISAR_HIS_SARTCFG
, ctrl
, 2, param
)) {
945 debugl1(cs
, "isar sart v14 dp%d failed",
950 if (!sendmsg(cs
, dps
| ISAR_HIS_BSTREQ
, 0, 0, NULL
)) {
952 debugl1(cs
, "isar buf stat req dp%d failed",
958 setup_iom2(struct BCState
*bcs
) {
959 struct IsdnCardState
*cs
= bcs
->cs
;
960 u_char dps
= SET_DPS(bcs
->hw
.isar
.dpath
);
961 u_char cmsb
= IOM_CTRL_ENA
, msg
[5] = {IOM_P1_TXD
,0,0,0,0};
969 msg
[1] = msg
[3] = bcs
->hw
.isar
.dpath
+ 2;
976 cmsb
|= IOM_CTRL_ALAW
| IOM_CTRL_RCV
;
979 if (!sendmsg(cs
, dps
| ISAR_HIS_IOM2CFG
, cmsb
, 5, msg
)) {
981 debugl1(cs
, "isar iom2 dp%d failed", bcs
->hw
.isar
.dpath
);
983 if (!sendmsg(cs
, dps
| ISAR_HIS_IOM2REQ
, 0, 0, NULL
)) {
985 debugl1(cs
, "isar IOM2 cfg req dp%d failed",
991 modeisar(struct BCState
*bcs
, int mode
, int bc
)
993 struct IsdnCardState
*cs
= bcs
->cs
;
995 /* Here we are selecting the best datapath for requested mode */
996 if(bcs
->mode
== L1_MODE_NULL
) { /* New Setup */
999 case L1_MODE_NULL
: /* init */
1000 if (!bcs
->hw
.isar
.dpath
)
1001 /* no init for dpath 0 */
1006 /* best is datapath 2 */
1007 if (!test_and_set_bit(ISAR_DP2_USE
,
1008 &bcs
->hw
.isar
.reg
->Flags
))
1009 bcs
->hw
.isar
.dpath
= 2;
1010 else if (!test_and_set_bit(ISAR_DP1_USE
,
1011 &bcs
->hw
.isar
.reg
->Flags
))
1012 bcs
->hw
.isar
.dpath
= 1;
1014 printk(KERN_WARNING
"isar modeisar both pathes in use\n");
1020 /* only datapath 1 */
1021 if (!test_and_set_bit(ISAR_DP1_USE
,
1022 &bcs
->hw
.isar
.reg
->Flags
))
1023 bcs
->hw
.isar
.dpath
= 1;
1025 printk(KERN_WARNING
"isar modeisar analog funktions only with DP1\n");
1026 debugl1(cs
, "isar modeisar analog funktions only with DP1");
1032 if (cs
->debug
& L1_DEB_HSCX
)
1033 debugl1(cs
, "isar dp%d mode %d->%d ichan %d",
1034 bcs
->hw
.isar
.dpath
, bcs
->mode
, mode
, bc
);
1039 if (bcs
->mode
== L1_MODE_NULL
) {
1040 /* Clear resources */
1041 if (bcs
->hw
.isar
.dpath
== 1)
1042 test_and_clear_bit(ISAR_DP1_USE
, &bcs
->hw
.isar
.reg
->Flags
);
1043 else if (bcs
->hw
.isar
.dpath
== 2)
1044 test_and_clear_bit(ISAR_DP2_USE
, &bcs
->hw
.isar
.reg
->Flags
);
1045 bcs
->hw
.isar
.dpath
= 0;
1051 isar_setup(struct IsdnCardState
*cs
)
1058 for (i
=0; i
<2; i
++) {
1060 if (!sendmsg(cs
, (i
? ISAR_HIS_DPS2
: ISAR_HIS_DPS1
) |
1061 ISAR_HIS_P12CFG
, 4, 1, &msg
)) {
1063 debugl1(cs
, "isar P%dCFG failed", i
+1);
1065 cs
->bcs
[i
].hw
.isar
.mml
= msg
;
1066 cs
->bcs
[i
].mode
= 0;
1067 cs
->bcs
[i
].hw
.isar
.dpath
= i
+ 1;
1068 modeisar(&cs
->bcs
[i
], 0, 0);
1069 cs
->bcs
[i
].tqueue
.routine
= (void *) (void *) isar_bh
;
1074 isar_l2l1(struct PStack
*st
, int pr
, void *arg
)
1076 struct sk_buff
*skb
= arg
;
1080 case (PH_DATA
| REQUEST
):
1083 if (st
->l1
.bcs
->tx_skb
) {
1084 skb_queue_tail(&st
->l1
.bcs
->squeue
, skb
);
1085 restore_flags(flags
);
1087 st
->l1
.bcs
->tx_skb
= skb
;
1088 test_and_set_bit(BC_FLG_BUSY
, &st
->l1
.bcs
->Flag
);
1089 if (st
->l1
.bcs
->cs
->debug
& L1_DEB_HSCX
)
1090 debugl1(st
->l1
.bcs
->cs
, "DRQ set BC_FLG_BUSY");
1091 st
->l1
.bcs
->hw
.isar
.txcnt
= 0;
1092 restore_flags(flags
);
1093 st
->l1
.bcs
->cs
->BC_Send_Data(st
->l1
.bcs
);
1096 case (PH_PULL
| INDICATION
):
1097 if (st
->l1
.bcs
->tx_skb
) {
1098 printk(KERN_WARNING
"isar_l2l1: this shouldn't happen\n");
1101 test_and_set_bit(BC_FLG_BUSY
, &st
->l1
.bcs
->Flag
);
1102 if (st
->l1
.bcs
->cs
->debug
& L1_DEB_HSCX
)
1103 debugl1(st
->l1
.bcs
->cs
, "PUI set BC_FLG_BUSY");
1104 st
->l1
.bcs
->tx_skb
= skb
;
1105 st
->l1
.bcs
->hw
.isar
.txcnt
= 0;
1106 st
->l1
.bcs
->cs
->BC_Send_Data(st
->l1
.bcs
);
1108 case (PH_PULL
| REQUEST
):
1109 if (!st
->l1
.bcs
->tx_skb
) {
1110 test_and_clear_bit(FLG_L1_PULL_REQ
, &st
->l1
.Flags
);
1111 st
->l1
.l1l2(st
, PH_PULL
| CONFIRM
, NULL
);
1113 test_and_set_bit(FLG_L1_PULL_REQ
, &st
->l1
.Flags
);
1115 case (PH_ACTIVATE
| REQUEST
):
1116 test_and_set_bit(BC_FLG_ACTIV
, &st
->l1
.bcs
->Flag
);
1117 st
->l1
.bcs
->hw
.isar
.conmsg
[0] = 0;
1118 if (test_bit(FLG_ORIG
, &st
->l2
.flag
))
1119 test_and_set_bit(BC_FLG_ORIG
, &st
->l1
.bcs
->Flag
);
1121 test_and_clear_bit(BC_FLG_ORIG
, &st
->l1
.bcs
->Flag
);
1122 switch(st
->l1
.mode
) {
1125 if (modeisar(st
->l1
.bcs
, st
->l1
.mode
, st
->l1
.bc
))
1126 l1_msg_b(st
, PH_DEACTIVATE
| REQUEST
, arg
);
1128 l1_msg_b(st
, PH_ACTIVATE
| REQUEST
, arg
);
1131 if (modeisar(st
->l1
.bcs
, st
->l1
.mode
, st
->l1
.bc
))
1132 l1_msg_b(st
, PH_DEACTIVATE
| REQUEST
, arg
);
1136 case (PH_DEACTIVATE
| REQUEST
):
1137 l1_msg_b(st
, pr
, arg
);
1139 case (PH_DEACTIVATE
| CONFIRM
):
1140 test_and_clear_bit(BC_FLG_ACTIV
, &st
->l1
.bcs
->Flag
);
1141 test_and_clear_bit(BC_FLG_BUSY
, &st
->l1
.bcs
->Flag
);
1142 if (st
->l1
.bcs
->cs
->debug
& L1_DEB_HSCX
)
1143 debugl1(st
->l1
.bcs
->cs
, "PDAC clear BC_FLG_BUSY");
1144 modeisar(st
->l1
.bcs
, 0, st
->l1
.bc
);
1145 st
->l1
.l1l2(st
, PH_DEACTIVATE
| CONFIRM
, NULL
);
1151 close_isarstate(struct BCState
*bcs
)
1153 modeisar(bcs
, 0, bcs
->channel
);
1154 if (test_and_clear_bit(BC_FLG_INIT
, &bcs
->Flag
)) {
1155 if (bcs
->hw
.isar
.rcvbuf
) {
1156 kfree(bcs
->hw
.isar
.rcvbuf
);
1157 bcs
->hw
.isar
.rcvbuf
= NULL
;
1159 discard_queue(&bcs
->rqueue
);
1160 discard_queue(&bcs
->squeue
);
1162 idev_kfree_skb(bcs
->tx_skb
, FREE_WRITE
);
1164 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
1165 if (bcs
->cs
->debug
& L1_DEB_HSCX
)
1166 debugl1(bcs
->cs
, "closeisar clear BC_FLG_BUSY");
1172 open_isarstate(struct IsdnCardState
*cs
, struct BCState
*bcs
)
1174 if (!test_and_set_bit(BC_FLG_INIT
, &bcs
->Flag
)) {
1175 if (!(bcs
->hw
.isar
.rcvbuf
= kmalloc(HSCX_BUFMAX
, GFP_ATOMIC
))) {
1177 "HiSax: No memory for isar.rcvbuf\n");
1180 skb_queue_head_init(&bcs
->rqueue
);
1181 skb_queue_head_init(&bcs
->squeue
);
1184 test_and_clear_bit(BC_FLG_BUSY
, &bcs
->Flag
);
1185 if (cs
->debug
& L1_DEB_HSCX
)
1186 debugl1(cs
, "openisar clear BC_FLG_BUSY");
1188 bcs
->hw
.isar
.rcvidx
= 0;
1194 setstack_isar(struct PStack
*st
, struct BCState
*bcs
)
1196 bcs
->channel
= st
->l1
.bc
;
1197 if (open_isarstate(st
->l1
.hardware
, bcs
))
1200 st
->l2
.l2l1
= isar_l2l1
;
1201 setstack_manager(st
);
1208 isar_auxcmd(struct IsdnCardState
*cs
, isdn_ctrl
*ic
) {
1212 if (cs
->debug
& L1_DEB_HSCX
)
1213 debugl1(cs
, "isar_auxcmd cmd/ch %x/%d", ic
->command
, ic
->arg
);
1214 switch (ic
->command
) {
1215 case (ISDN_CMD_IOCTL
):
1217 case (9): /* load firmware */
1218 features
= ISDN_FEATURE_L2_MODEM
;
1219 memcpy(&adr
, ic
->parm
.num
, sizeof(ulong
));
1220 if (isar_load_firmware(cs
, (u_char
*)adr
))
1223 ll_run(cs
, features
);
1226 printk(KERN_DEBUG
"HiSax: invalid ioclt %d\n",
1238 initisar(struct IsdnCardState
*cs
))
1240 cs
->bcs
[0].BC_SetStack
= setstack_isar
;
1241 cs
->bcs
[1].BC_SetStack
= setstack_isar
;
1242 cs
->bcs
[0].BC_Close
= close_isarstate
;
1243 cs
->bcs
[1].BC_Close
= close_isarstate
;