Linux 4.18.10
[linux/fpc-iii.git] / drivers / isdn / hisax / hscx_irq.c
blob0d7e783c8bef1a275dbb02e6b1b47ee63baf1785
1 /* $Id: hscx_irq.c,v 1.18.2.3 2004/02/11 13:21:34 keil Exp $
3 * low level b-channel stuff for Siemens HSCX
5 * Author Karsten Keil
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
11 * This is an include file for fast inline IRQ stuff
16 static inline void
17 waitforCEC(struct IsdnCardState *cs, int hscx)
19 int to = 50;
21 while ((READHSCX(cs, hscx, HSCX_STAR) & 0x04) && to) {
22 udelay(1);
23 to--;
25 if (!to)
26 printk(KERN_WARNING "HiSax: waitforCEC timeout\n");
30 static inline void
31 waitforXFW(struct IsdnCardState *cs, int hscx)
33 int to = 50;
35 while (((READHSCX(cs, hscx, HSCX_STAR) & 0x44) != 0x40) && to) {
36 udelay(1);
37 to--;
39 if (!to)
40 printk(KERN_WARNING "HiSax: waitforXFW timeout\n");
43 static inline void
44 WriteHSCXCMDR(struct IsdnCardState *cs, int hscx, u_char data)
46 waitforCEC(cs, hscx);
47 WRITEHSCX(cs, hscx, HSCX_CMDR, data);
52 static void
53 hscx_empty_fifo(struct BCState *bcs, int count)
55 u_char *ptr;
56 struct IsdnCardState *cs = bcs->cs;
58 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
59 debugl1(cs, "hscx_empty_fifo");
61 if (bcs->hw.hscx.rcvidx + count > HSCX_BUFMAX) {
62 if (cs->debug & L1_DEB_WARN)
63 debugl1(cs, "hscx_empty_fifo: incoming packet too large");
64 WriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x80);
65 bcs->hw.hscx.rcvidx = 0;
66 return;
68 ptr = bcs->hw.hscx.rcvbuf + bcs->hw.hscx.rcvidx;
69 bcs->hw.hscx.rcvidx += count;
70 READHSCXFIFO(cs, bcs->hw.hscx.hscx, ptr, count);
71 WriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x80);
72 if (cs->debug & L1_DEB_HSCX_FIFO) {
73 char *t = bcs->blog;
75 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
76 bcs->hw.hscx.hscx ? 'B' : 'A', count);
77 QuickHex(t, ptr, count);
78 debugl1(cs, "%s", bcs->blog);
82 static void
83 hscx_fill_fifo(struct BCState *bcs)
85 struct IsdnCardState *cs = bcs->cs;
86 int more, count;
87 int fifo_size = test_bit(HW_IPAC, &cs->HW_Flags) ? 64 : 32;
88 u_char *ptr;
90 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
91 debugl1(cs, "hscx_fill_fifo");
93 if (!bcs->tx_skb)
94 return;
95 if (bcs->tx_skb->len <= 0)
96 return;
98 more = (bcs->mode == L1_MODE_TRANS) ? 1 : 0;
99 if (bcs->tx_skb->len > fifo_size) {
100 more = !0;
101 count = fifo_size;
102 } else
103 count = bcs->tx_skb->len;
105 waitforXFW(cs, bcs->hw.hscx.hscx);
106 ptr = bcs->tx_skb->data;
107 skb_pull(bcs->tx_skb, count);
108 bcs->tx_cnt -= count;
109 bcs->hw.hscx.count += count;
110 WRITEHSCXFIFO(cs, bcs->hw.hscx.hscx, ptr, count);
111 WriteHSCXCMDR(cs, bcs->hw.hscx.hscx, more ? 0x8 : 0xa);
112 if (cs->debug & L1_DEB_HSCX_FIFO) {
113 char *t = bcs->blog;
115 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
116 bcs->hw.hscx.hscx ? 'B' : 'A', count);
117 QuickHex(t, ptr, count);
118 debugl1(cs, "%s", bcs->blog);
122 static void
123 hscx_interrupt(struct IsdnCardState *cs, u_char val, u_char hscx)
125 u_char r;
126 struct BCState *bcs = cs->bcs + hscx;
127 struct sk_buff *skb;
128 int fifo_size = test_bit(HW_IPAC, &cs->HW_Flags) ? 64 : 32;
129 int count;
131 if (!test_bit(BC_FLG_INIT, &bcs->Flag))
132 return;
134 if (val & 0x80) { /* RME */
135 r = READHSCX(cs, hscx, HSCX_RSTA);
136 if ((r & 0xf0) != 0xa0) {
137 if (!(r & 0x80)) {
138 if (cs->debug & L1_DEB_WARN)
139 debugl1(cs, "HSCX invalid frame");
140 #ifdef ERROR_STATISTIC
141 bcs->err_inv++;
142 #endif
144 if ((r & 0x40) && bcs->mode) {
145 if (cs->debug & L1_DEB_WARN)
146 debugl1(cs, "HSCX RDO mode=%d",
147 bcs->mode);
148 #ifdef ERROR_STATISTIC
149 bcs->err_rdo++;
150 #endif
152 if (!(r & 0x20)) {
153 if (cs->debug & L1_DEB_WARN)
154 debugl1(cs, "HSCX CRC error");
155 #ifdef ERROR_STATISTIC
156 bcs->err_crc++;
157 #endif
159 WriteHSCXCMDR(cs, hscx, 0x80);
160 } else {
161 count = READHSCX(cs, hscx, HSCX_RBCL) & (
162 test_bit(HW_IPAC, &cs->HW_Flags) ? 0x3f : 0x1f);
163 if (count == 0)
164 count = fifo_size;
165 hscx_empty_fifo(bcs, count);
166 if ((count = bcs->hw.hscx.rcvidx - 1) > 0) {
167 if (cs->debug & L1_DEB_HSCX_FIFO)
168 debugl1(cs, "HX Frame %d", count);
169 if (!(skb = dev_alloc_skb(count)))
170 printk(KERN_WARNING "HSCX: receive out of memory\n");
171 else {
172 skb_put_data(skb, bcs->hw.hscx.rcvbuf,
173 count);
174 skb_queue_tail(&bcs->rqueue, skb);
178 bcs->hw.hscx.rcvidx = 0;
179 schedule_event(bcs, B_RCVBUFREADY);
181 if (val & 0x40) { /* RPF */
182 hscx_empty_fifo(bcs, fifo_size);
183 if (bcs->mode == L1_MODE_TRANS) {
184 /* receive audio data */
185 if (!(skb = dev_alloc_skb(fifo_size)))
186 printk(KERN_WARNING "HiSax: receive out of memory\n");
187 else {
188 skb_put_data(skb, bcs->hw.hscx.rcvbuf,
189 fifo_size);
190 skb_queue_tail(&bcs->rqueue, skb);
192 bcs->hw.hscx.rcvidx = 0;
193 schedule_event(bcs, B_RCVBUFREADY);
196 if (val & 0x10) { /* XPR */
197 if (bcs->tx_skb) {
198 if (bcs->tx_skb->len) {
199 hscx_fill_fifo(bcs);
200 return;
201 } else {
202 if (test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
203 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
204 u_long flags;
205 spin_lock_irqsave(&bcs->aclock, flags);
206 bcs->ackcnt += bcs->hw.hscx.count;
207 spin_unlock_irqrestore(&bcs->aclock, flags);
208 schedule_event(bcs, B_ACKPENDING);
210 dev_kfree_skb_irq(bcs->tx_skb);
211 bcs->hw.hscx.count = 0;
212 bcs->tx_skb = NULL;
215 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
216 bcs->hw.hscx.count = 0;
217 test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
218 hscx_fill_fifo(bcs);
219 } else {
220 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
221 schedule_event(bcs, B_XMTBUFREADY);
226 static void
227 hscx_int_main(struct IsdnCardState *cs, u_char val)
230 u_char exval;
231 struct BCState *bcs;
233 if (val & 0x01) {
234 bcs = cs->bcs + 1;
235 exval = READHSCX(cs, 1, HSCX_EXIR);
236 if (exval & 0x40) {
237 if (bcs->mode == 1)
238 hscx_fill_fifo(bcs);
239 else {
240 #ifdef ERROR_STATISTIC
241 bcs->err_tx++;
242 #endif
243 /* Here we lost an TX interrupt, so
244 * restart transmitting the whole frame.
246 if (bcs->tx_skb) {
247 skb_push(bcs->tx_skb, bcs->hw.hscx.count);
248 bcs->tx_cnt += bcs->hw.hscx.count;
249 bcs->hw.hscx.count = 0;
251 WriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x01);
252 if (cs->debug & L1_DEB_WARN)
253 debugl1(cs, "HSCX B EXIR %x Lost TX", exval);
255 } else if (cs->debug & L1_DEB_HSCX)
256 debugl1(cs, "HSCX B EXIR %x", exval);
258 if (val & 0xf8) {
259 if (cs->debug & L1_DEB_HSCX)
260 debugl1(cs, "HSCX B interrupt %x", val);
261 hscx_interrupt(cs, val, 1);
263 if (val & 0x02) {
264 bcs = cs->bcs;
265 exval = READHSCX(cs, 0, HSCX_EXIR);
266 if (exval & 0x40) {
267 if (bcs->mode == L1_MODE_TRANS)
268 hscx_fill_fifo(bcs);
269 else {
270 /* Here we lost an TX interrupt, so
271 * restart transmitting the whole frame.
273 #ifdef ERROR_STATISTIC
274 bcs->err_tx++;
275 #endif
276 if (bcs->tx_skb) {
277 skb_push(bcs->tx_skb, bcs->hw.hscx.count);
278 bcs->tx_cnt += bcs->hw.hscx.count;
279 bcs->hw.hscx.count = 0;
281 WriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x01);
282 if (cs->debug & L1_DEB_WARN)
283 debugl1(cs, "HSCX A EXIR %x Lost TX", exval);
285 } else if (cs->debug & L1_DEB_HSCX)
286 debugl1(cs, "HSCX A EXIR %x", exval);
288 if (val & 0x04) {
289 exval = READHSCX(cs, 0, HSCX_ISTA);
290 if (cs->debug & L1_DEB_HSCX)
291 debugl1(cs, "HSCX A interrupt %x", exval);
292 hscx_interrupt(cs, exval, 0);