19 #include <linux/slab.h>
22 WaitForBusy(
struct IsdnCardState *
cs)
29 (cs->hw.hfc.cip & 3));
41 WaitNoBusy(
struct IsdnCardState *cs)
57 GetFreeFifoBytes(
struct BCState *bcs)
61 if (bcs->hw.hfc.f1 == bcs->hw.hfc.f2)
62 return (bcs->cs->hw.hfc.fifosize);
63 s = bcs->hw.hfc.send[bcs->hw.hfc.f1] - bcs->hw.hfc.send[bcs->hw.hfc.f2];
65 s += bcs->cs->hw.hfc.fifosize;
66 s = bcs->cs->hw.hfc.fifosize -
s;
83 hfc_clear_fifo(
struct BCState *bcs)
85 struct IsdnCardState *cs = bcs->cs;
90 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
93 if ((cip & 0xc3) != (cs->hw.hfc.cip & 0xc3)) {
98 f1 = cs->BC_Read_Reg(cs,
HFC_DATA, cip);
101 f2 = cs->BC_Read_Reg(cs,
HFC_DATA, cip);
105 while (((f1 != f2) || (z1 != z2)) && cnt--) {
106 if (cs->debug & L1_DEB_HSCX)
107 debugl1(cs,
"hfc clear %d f1(%d) f2(%d)",
108 bcs->channel, f1, f2);
111 rcnt += cs->hw.hfc.fifosize;
114 if (cs->debug & L1_DEB_HSCX)
115 debugl1(cs,
"hfc clear %d z1(%x) z2(%x) cnt(%d)",
116 bcs->channel, z1, z2, rcnt);
119 while ((idx < rcnt) && WaitNoBusy(cs)) {
131 f1 = cs->BC_Read_Reg(cs,
HFC_DATA, cip);
134 f2 = cs->BC_Read_Reg(cs,
HFC_DATA, cip);
144 hfc_empty_fifo(
struct BCState *bcs,
int count)
148 struct IsdnCardState *cs = bcs->cs;
153 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
157 if (cs->debug & L1_DEB_WARN)
158 debugl1(cs,
"hfc_empty_fifo: incoming packet too large");
160 while ((idx++ < count) && WaitNoBusy(cs))
169 if (cs->debug & L1_DEB_WARN)
170 debugl1(cs,
"hfc_empty_fifo: incoming packet too small");
172 while ((idx++ < count) && WaitNoBusy(cs))
178 #ifdef ERROR_STATISTIC
187 if (!(skb = dev_alloc_skb(count)))
193 while ((idx < count) && WaitNoBusy(cs)) {
198 debugl1(cs,
"RFIFO BUSY error");
211 chksum = (cs->BC_Read_Reg(cs,
HFC_DATA, cip) << 8);
213 chksum += cs->BC_Read_Reg(cs,
HFC_DATA, cip);
215 stat = cs->BC_Read_Reg(cs,
HFC_DATA, cip);
216 if (cs->debug & L1_DEB_HSCX)
217 debugl1(cs,
"hfc_empty_fifo %d chksum %x stat %x",
218 bcs->channel, chksum, stat);
223 #ifdef ERROR_STATISTIC
237 hfc_fill_fifo(
struct BCState *bcs)
239 struct IsdnCardState *cs = bcs->cs;
247 if (bcs->tx_skb->len <= 0)
251 if ((cip & 0xc3) != (cs->hw.hfc.cip & 0xc3)) {
257 bcs->hw.hfc.f1 = cs->BC_Read_Reg(cs,
HFC_DATA, cip);
260 bcs->hw.hfc.f2 = cs->BC_Read_Reg(cs,
HFC_DATA, cip);
262 if (cs->debug & L1_DEB_HSCX)
263 debugl1(cs,
"hfc_fill_fifo %d f1(%d) f2(%d) z1(%x)",
264 bcs->channel, bcs->hw.hfc.f1, bcs->hw.hfc.f2,
265 bcs->hw.hfc.send[bcs->hw.hfc.f1]);
266 fcnt = bcs->hw.hfc.f1 - bcs->hw.hfc.f2;
270 if (cs->debug & L1_DEB_HSCX)
271 debugl1(cs,
"hfc_fill_fifo more as 30 frames");
274 count = GetFreeFifoBytes(bcs);
282 count += cs->hw.hfc.fifosize;
284 if (cs->debug & L1_DEB_HSCX)
285 debugl1(cs,
"hfc_fill_fifo %d count(%u/%d)",
286 bcs->channel, bcs->tx_skb->len,
288 if (count < bcs->tx_skb->len) {
289 if (cs->debug & L1_DEB_HSCX)
290 debugl1(cs,
"hfc_fill_fifo no fifo mem");
295 while ((idx < bcs->tx_skb->len) && WaitNoBusy(cs))
296 cs->BC_Write_Reg(cs,
HFC_DATA_NODEB, cip, bcs->tx_skb->data[idx++]);
297 if (idx != bcs->tx_skb->len) {
298 debugl1(cs,
"FIFO Send BUSY error");
301 count = bcs->tx_skb->len;
302 bcs->tx_cnt -=
count;
303 if (PACKET_NOACK == bcs->tx_skb->pkt_type)
312 if (
test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
316 bcs->ackcnt +=
count;
317 spin_unlock_irqrestore(&bcs->aclock, flags);
328 struct IsdnCardState *cs = bcs->cs;
331 int receive, transmit, count = 5;
337 if ((cip & 0xc3) != (cs->hw.hfc.cip & 0xc3)) {
344 f1 = cs->BC_Read_Reg(cs,
HFC_DATA, cip);
347 f2 = cs->BC_Read_Reg(cs,
HFC_DATA, cip);
349 if (cs->debug & L1_DEB_HSCX)
350 debugl1(cs,
"hfc rec %d f1(%d) f2(%d)",
351 bcs->channel, f1, f2);
361 rcnt += cs->hw.hfc.fifosize;
364 if (cs->debug & L1_DEB_HSCX)
365 debugl1(cs,
"hfc rec %d z1(%x) z2(%x) cnt(%d)",
366 bcs->channel, z1, z2, rcnt);
368 if ((skb = hfc_empty_fifo(bcs, rcnt))) {
379 if (
test_bit(BC_FLG_BUSY, &bcs->Flag))
386 if (
test_bit(BC_FLG_BUSY, &bcs->Flag))
393 if ((receive || transmit) && count)
399 mode_hfc(
struct BCState *bcs,
int mode,
int bc)
401 struct IsdnCardState *cs = bcs->cs;
403 if (cs->debug & L1_DEB_HSCX)
404 debugl1(cs,
"HFC 2BS0 mode %d bchan %d/%d",
405 mode, bc, bcs->channel);
412 cs->hw.hfc.ctmt &= ~1;
413 cs->hw.hfc.isac_spcr &= ~0x03;
416 cs->hw.hfc.ctmt &= ~2;
417 cs->hw.hfc.isac_spcr &= ~0x0c;
421 cs->hw.hfc.ctmt &= ~(1 <<
bc);
422 cs->BC_Write_Reg(cs,
HFC_STATUS, cs->hw.hfc.ctmt, cs->hw.hfc.ctmt);
425 cs->hw.hfc.ctmt |= 1;
426 cs->hw.hfc.isac_spcr &= ~0x03;
427 cs->hw.hfc.isac_spcr |= 0x02;
429 cs->hw.hfc.ctmt |= 2;
430 cs->hw.hfc.isac_spcr &= ~0x0c;
431 cs->hw.hfc.isac_spcr |= 0x08;
436 cs->hw.hfc.ctmt &= ~1;
437 cs->hw.hfc.isac_spcr &= ~0x03;
438 cs->hw.hfc.isac_spcr |= 0x02;
440 cs->hw.hfc.ctmt &= ~2;
441 cs->hw.hfc.isac_spcr &= ~0x0c;
442 cs->hw.hfc.isac_spcr |= 0x08;
446 cs->BC_Write_Reg(cs,
HFC_STATUS, cs->hw.hfc.ctmt, cs->hw.hfc.ctmt);
447 cs->writeisac(cs,
ISAC_SPCR, cs->hw.hfc.isac_spcr);
453 hfc_l2l1(
struct PStack *
st,
int pr,
void *
arg)
455 struct BCState *bcs = st->l1.bcs;
467 bcs->cs->BC_Send_Data(bcs);
469 spin_unlock_irqrestore(&bcs->cs->lock, flags);
478 bcs->cs->BC_Send_Data(bcs);
480 spin_unlock_irqrestore(&bcs->cs->lock, flags);
492 mode_hfc(bcs, st->l1.mode, st->l1.bc);
493 spin_unlock_irqrestore(&bcs->cs->lock, flags);
503 mode_hfc(bcs, 0, st->l1.bc);
504 spin_unlock_irqrestore(&bcs->cs->lock, flags);
512 close_hfcstate(
struct BCState *bcs)
514 mode_hfc(bcs, 0, bcs->channel);
515 if (
test_bit(BC_FLG_INIT, &bcs->Flag)) {
528 open_hfcstate(
struct IsdnCardState *cs,
struct BCState *bcs)
531 skb_queue_head_init(&bcs->rqueue);
532 skb_queue_head_init(&bcs->squeue);
542 setstack_hfc(
struct PStack *st,
struct BCState *bcs)
544 bcs->channel = st->l1.bc;
545 if (open_hfcstate(st->l1.hardware, bcs))
548 st->l2.l2l1 = hfc_l2l1;
556 init_send(
struct BCState *bcs)
562 "HiSax: No memory for hfc.send\n");
565 for (i = 0; i < 32; i++)
566 bcs->hw.hfc.send[i] = 0x1fff;
572 init_send(&cs->bcs[0]);
573 init_send(&cs->bcs[1]);
574 cs->BC_Send_Data = &hfc_fill_fifo;
575 cs->bcs[0].BC_SetStack = setstack_hfc;
576 cs->bcs[1].BC_SetStack = setstack_hfc;
577 cs->bcs[0].BC_Close = close_hfcstate;
578 cs->bcs[1].BC_Close = close_hfcstate;
579 mode_hfc(cs->bcs, 0, 0);
580 mode_hfc(cs->bcs + 1, 0, 0);
586 kfree(cs->bcs[0].hw.hfc.send);
587 cs->bcs[0].hw.hfc.send =
NULL;
588 kfree(cs->bcs[1].hw.hfc.send);
589 cs->bcs[1].hw.hfc.send =
NULL;