Commit | Line | Data |
---|---|---|
82c29810 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
da2272c9 KK |
2 | /* |
3 | * mISDNisar.c ISAR (Siemens PSB 7110) specific functions | |
4 | * | |
5 | * Author Karsten Keil (keil@isdn4linux.de) | |
6 | * | |
7 | * Copyright 2009 by Karsten Keil <keil@isdn4linux.de> | |
da2272c9 KK |
8 | */ |
9 | ||
10 | /* define this to enable static debug messages, if you kernel supports | |
11 | * dynamic debugging, you should use debugfs for this | |
12 | */ | |
13 | /* #define DEBUG */ | |
14 | ||
5a0e3ad6 | 15 | #include <linux/gfp.h> |
da2272c9 KK |
16 | #include <linux/delay.h> |
17 | #include <linux/vmalloc.h> | |
18 | #include <linux/mISDNhw.h> | |
07a97fe8 | 19 | #include <linux/module.h> |
da2272c9 KK |
20 | #include "isar.h" |
21 | ||
22 | #define ISAR_REV "2.1" | |
23 | ||
24 | MODULE_AUTHOR("Karsten Keil"); | |
25 | MODULE_LICENSE("GPL v2"); | |
26 | MODULE_VERSION(ISAR_REV); | |
27 | ||
28 | #define DEBUG_HW_FIRMWARE_FIFO 0x10000 | |
29 | ||
30 | static const u8 faxmodulation_s[] = "3,24,48,72,73,74,96,97,98,121,122,145,146"; | |
31 | static const u8 faxmodulation[] = {3, 24, 48, 72, 73, 74, 96, 97, 98, 121, | |
475be4d8 | 32 | 122, 145, 146}; |
da2272c9 KK |
33 | #define FAXMODCNT 13 |
34 | ||
35 | static void isar_setup(struct isar_hw *); | |
36 | ||
37 | static inline int | |
38 | waitforHIA(struct isar_hw *isar, int timeout) | |
39 | { | |
40 | int t = timeout; | |
41 | u8 val = isar->read_reg(isar->hw, ISAR_HIA); | |
42 | ||
43 | while ((val & 1) && t) { | |
44 | udelay(1); | |
45 | t--; | |
46 | val = isar->read_reg(isar->hw, ISAR_HIA); | |
47 | } | |
48 | pr_debug("%s: HIA after %dus\n", isar->name, timeout - t); | |
49 | return timeout; | |
50 | } | |
51 | ||
52 | /* | |
53 | * send msg to ISAR mailbox | |
54 | * if msg is NULL use isar->buf | |
55 | */ | |
56 | static int | |
57 | send_mbox(struct isar_hw *isar, u8 his, u8 creg, u8 len, u8 *msg) | |
58 | { | |
59 | if (!waitforHIA(isar, 1000)) | |
60 | return 0; | |
61 | pr_debug("send_mbox(%02x,%02x,%d)\n", his, creg, len); | |
62 | isar->write_reg(isar->hw, ISAR_CTRL_H, creg); | |
63 | isar->write_reg(isar->hw, ISAR_CTRL_L, len); | |
64 | isar->write_reg(isar->hw, ISAR_WADR, 0); | |
65 | if (!msg) | |
66 | msg = isar->buf; | |
67 | if (msg && len) { | |
68 | isar->write_fifo(isar->hw, ISAR_MBOX, msg, len); | |
69 | if (isar->ch[0].bch.debug & DEBUG_HW_BFIFO) { | |
70 | int l = 0; | |
71 | ||
72 | while (l < (int)len) { | |
73 | hex_dump_to_buffer(msg + l, len - l, 32, 1, | |
475be4d8 | 74 | isar->log, 256, 1); |
da2272c9 | 75 | pr_debug("%s: %s %02x: %s\n", isar->name, |
475be4d8 | 76 | __func__, l, isar->log); |
da2272c9 KK |
77 | l += 32; |
78 | } | |
79 | } | |
80 | } | |
81 | isar->write_reg(isar->hw, ISAR_HIS, his); | |
82 | waitforHIA(isar, 1000); | |
83 | return 1; | |
84 | } | |
85 | ||
86 | /* | |
87 | * receive message from ISAR mailbox | |
88 | * if msg is NULL use isar->buf | |
89 | */ | |
90 | static void | |
91 | rcv_mbox(struct isar_hw *isar, u8 *msg) | |
92 | { | |
93 | if (!msg) | |
94 | msg = isar->buf; | |
95 | isar->write_reg(isar->hw, ISAR_RADR, 0); | |
96 | if (msg && isar->clsb) { | |
97 | isar->read_fifo(isar->hw, ISAR_MBOX, msg, isar->clsb); | |
98 | if (isar->ch[0].bch.debug & DEBUG_HW_BFIFO) { | |
99 | int l = 0; | |
100 | ||
101 | while (l < (int)isar->clsb) { | |
102 | hex_dump_to_buffer(msg + l, isar->clsb - l, 32, | |
475be4d8 | 103 | 1, isar->log, 256, 1); |
da2272c9 | 104 | pr_debug("%s: %s %02x: %s\n", isar->name, |
475be4d8 | 105 | __func__, l, isar->log); |
da2272c9 KK |
106 | l += 32; |
107 | } | |
108 | } | |
109 | } | |
110 | isar->write_reg(isar->hw, ISAR_IIA, 0); | |
111 | } | |
112 | ||
113 | static inline void | |
114 | get_irq_infos(struct isar_hw *isar) | |
115 | { | |
116 | isar->iis = isar->read_reg(isar->hw, ISAR_IIS); | |
117 | isar->cmsb = isar->read_reg(isar->hw, ISAR_CTRL_H); | |
118 | isar->clsb = isar->read_reg(isar->hw, ISAR_CTRL_L); | |
119 | pr_debug("%s: rcv_mbox(%02x,%02x,%d)\n", isar->name, | |
475be4d8 | 120 | isar->iis, isar->cmsb, isar->clsb); |
da2272c9 KK |
121 | } |
122 | ||
123 | /* | |
124 | * poll answer message from ISAR mailbox | |
125 | * should be used only with ISAR IRQs disabled before DSP was started | |
126 | * | |
127 | */ | |
128 | static int | |
129 | poll_mbox(struct isar_hw *isar, int maxdelay) | |
130 | { | |
131 | int t = maxdelay; | |
132 | u8 irq; | |
133 | ||
134 | irq = isar->read_reg(isar->hw, ISAR_IRQBIT); | |
135 | while (t && !(irq & ISAR_IRQSTA)) { | |
136 | udelay(1); | |
137 | t--; | |
138 | } | |
139 | if (t) { | |
140 | get_irq_infos(isar); | |
141 | rcv_mbox(isar, NULL); | |
142 | } | |
143 | pr_debug("%s: pulled %d bytes after %d us\n", | |
475be4d8 | 144 | isar->name, isar->clsb, maxdelay - t); |
da2272c9 KK |
145 | return t; |
146 | } | |
147 | ||
148 | static int | |
149 | ISARVersion(struct isar_hw *isar) | |
150 | { | |
151 | int ver; | |
152 | ||
153 | /* disable ISAR IRQ */ | |
154 | isar->write_reg(isar->hw, ISAR_IRQBIT, 0); | |
155 | isar->buf[0] = ISAR_MSG_HWVER; | |
156 | isar->buf[1] = 0; | |
157 | isar->buf[2] = 1; | |
158 | if (!send_mbox(isar, ISAR_HIS_VNR, 0, 3, NULL)) | |
159 | return -1; | |
160 | if (!poll_mbox(isar, 1000)) | |
161 | return -2; | |
162 | if (isar->iis == ISAR_IIS_VNR) { | |
163 | if (isar->clsb == 1) { | |
164 | ver = isar->buf[0] & 0xf; | |
165 | return ver; | |
166 | } | |
167 | return -3; | |
168 | } | |
169 | return -4; | |
170 | } | |
171 | ||
172 | static int | |
173 | load_firmware(struct isar_hw *isar, const u8 *buf, int size) | |
174 | { | |
175 | u32 saved_debug = isar->ch[0].bch.debug; | |
176 | int ret, cnt; | |
177 | u8 nom, noc; | |
178 | u16 left, val, *sp = (u16 *)buf; | |
179 | u8 *mp; | |
180 | u_long flags; | |
181 | ||
182 | struct { | |
183 | u16 sadr; | |
184 | u16 len; | |
185 | u16 d_key; | |
186 | } blk_head; | |
187 | ||
188 | if (1 != isar->version) { | |
189 | pr_err("%s: ISAR wrong version %d firmware download aborted\n", | |
475be4d8 | 190 | isar->name, isar->version); |
da2272c9 KK |
191 | return -EINVAL; |
192 | } | |
193 | if (!(saved_debug & DEBUG_HW_FIRMWARE_FIFO)) | |
194 | isar->ch[0].bch.debug &= ~DEBUG_HW_BFIFO; | |
195 | pr_debug("%s: load firmware %d words (%d bytes)\n", | |
475be4d8 | 196 | isar->name, size / 2, size); |
da2272c9 KK |
197 | cnt = 0; |
198 | size /= 2; | |
199 | /* disable ISAR IRQ */ | |
200 | spin_lock_irqsave(isar->hwlock, flags); | |
201 | isar->write_reg(isar->hw, ISAR_IRQBIT, 0); | |
202 | spin_unlock_irqrestore(isar->hwlock, flags); | |
203 | while (cnt < size) { | |
204 | blk_head.sadr = le16_to_cpu(*sp++); | |
205 | blk_head.len = le16_to_cpu(*sp++); | |
206 | blk_head.d_key = le16_to_cpu(*sp++); | |
207 | cnt += 3; | |
208 | pr_debug("ISAR firmware block (%#x,%d,%#x)\n", | |
475be4d8 | 209 | blk_head.sadr, blk_head.len, blk_head.d_key & 0xff); |
da2272c9 KK |
210 | left = blk_head.len; |
211 | if (cnt + left > size) { | |
212 | pr_info("%s: firmware error have %d need %d words\n", | |
213 | isar->name, size, cnt + left); | |
214 | ret = -EINVAL; | |
215 | goto reterrflg; | |
216 | } | |
217 | spin_lock_irqsave(isar->hwlock, flags); | |
218 | if (!send_mbox(isar, ISAR_HIS_DKEY, blk_head.d_key & 0xff, | |
475be4d8 | 219 | 0, NULL)) { |
da2272c9 KK |
220 | pr_info("ISAR send_mbox dkey failed\n"); |
221 | ret = -ETIME; | |
222 | goto reterror; | |
223 | } | |
224 | if (!poll_mbox(isar, 1000)) { | |
225 | pr_warning("ISAR poll_mbox dkey failed\n"); | |
226 | ret = -ETIME; | |
227 | goto reterror; | |
228 | } | |
229 | spin_unlock_irqrestore(isar->hwlock, flags); | |
230 | if ((isar->iis != ISAR_IIS_DKEY) || isar->cmsb || isar->clsb) { | |
231 | pr_info("ISAR wrong dkey response (%x,%x,%x)\n", | |
232 | isar->iis, isar->cmsb, isar->clsb); | |
233 | ret = 1; | |
234 | goto reterrflg; | |
235 | } | |
236 | while (left > 0) { | |
237 | if (left > 126) | |
238 | noc = 126; | |
239 | else | |
240 | noc = left; | |
241 | nom = (2 * noc) + 3; | |
242 | mp = isar->buf; | |
243 | /* the ISAR is big endian */ | |
244 | *mp++ = blk_head.sadr >> 8; | |
245 | *mp++ = blk_head.sadr & 0xFF; | |
246 | left -= noc; | |
247 | cnt += noc; | |
248 | *mp++ = noc; | |
249 | pr_debug("%s: load %3d words at %04x\n", isar->name, | |
475be4d8 | 250 | noc, blk_head.sadr); |
da2272c9 KK |
251 | blk_head.sadr += noc; |
252 | while (noc) { | |
253 | val = le16_to_cpu(*sp++); | |
254 | *mp++ = val >> 8; | |
ad65ffd1 | 255 | *mp++ = val & 0xFF; |
da2272c9 KK |
256 | noc--; |
257 | } | |
258 | spin_lock_irqsave(isar->hwlock, flags); | |
259 | if (!send_mbox(isar, ISAR_HIS_FIRM, 0, nom, NULL)) { | |
260 | pr_info("ISAR send_mbox prog failed\n"); | |
261 | ret = -ETIME; | |
262 | goto reterror; | |
263 | } | |
264 | if (!poll_mbox(isar, 1000)) { | |
265 | pr_info("ISAR poll_mbox prog failed\n"); | |
266 | ret = -ETIME; | |
267 | goto reterror; | |
268 | } | |
269 | spin_unlock_irqrestore(isar->hwlock, flags); | |
270 | if ((isar->iis != ISAR_IIS_FIRM) || | |
271 | isar->cmsb || isar->clsb) { | |
272 | pr_info("ISAR wrong prog response (%x,%x,%x)\n", | |
273 | isar->iis, isar->cmsb, isar->clsb); | |
274 | ret = -EIO; | |
275 | goto reterrflg; | |
276 | } | |
277 | } | |
278 | pr_debug("%s: ISAR firmware block %d words loaded\n", | |
475be4d8 | 279 | isar->name, blk_head.len); |
da2272c9 KK |
280 | } |
281 | isar->ch[0].bch.debug = saved_debug; | |
282 | /* 10ms delay */ | |
283 | cnt = 10; | |
284 | while (cnt--) | |
285 | mdelay(1); | |
286 | isar->buf[0] = 0xff; | |
287 | isar->buf[1] = 0xfe; | |
288 | isar->bstat = 0; | |
289 | spin_lock_irqsave(isar->hwlock, flags); | |
290 | if (!send_mbox(isar, ISAR_HIS_STDSP, 0, 2, NULL)) { | |
291 | pr_info("ISAR send_mbox start dsp failed\n"); | |
292 | ret = -ETIME; | |
293 | goto reterror; | |
294 | } | |
295 | if (!poll_mbox(isar, 1000)) { | |
296 | pr_info("ISAR poll_mbox start dsp failed\n"); | |
297 | ret = -ETIME; | |
298 | goto reterror; | |
299 | } | |
300 | if ((isar->iis != ISAR_IIS_STDSP) || isar->cmsb || isar->clsb) { | |
301 | pr_info("ISAR wrong start dsp response (%x,%x,%x)\n", | |
302 | isar->iis, isar->cmsb, isar->clsb); | |
303 | ret = -EIO; | |
304 | goto reterror; | |
305 | } else | |
306 | pr_debug("%s: ISAR start dsp success\n", isar->name); | |
307 | ||
308 | /* NORMAL mode entered */ | |
309 | /* Enable IRQs of ISAR */ | |
310 | isar->write_reg(isar->hw, ISAR_IRQBIT, ISAR_IRQSTA); | |
311 | spin_unlock_irqrestore(isar->hwlock, flags); | |
312 | cnt = 1000; /* max 1s */ | |
313 | while ((!isar->bstat) && cnt) { | |
314 | mdelay(1); | |
315 | cnt--; | |
316 | } | |
317 | if (!cnt) { | |
318 | pr_info("ISAR no general status event received\n"); | |
319 | ret = -ETIME; | |
320 | goto reterrflg; | |
321 | } else | |
322 | pr_debug("%s: ISAR general status event %x\n", | |
475be4d8 | 323 | isar->name, isar->bstat); |
da2272c9 KK |
324 | /* 10ms delay */ |
325 | cnt = 10; | |
326 | while (cnt--) | |
327 | mdelay(1); | |
328 | isar->iis = 0; | |
329 | spin_lock_irqsave(isar->hwlock, flags); | |
330 | if (!send_mbox(isar, ISAR_HIS_DIAG, ISAR_CTRL_STST, 0, NULL)) { | |
331 | pr_info("ISAR send_mbox self tst failed\n"); | |
332 | ret = -ETIME; | |
333 | goto reterror; | |
334 | } | |
335 | spin_unlock_irqrestore(isar->hwlock, flags); | |
336 | cnt = 10000; /* max 100 ms */ | |
337 | while ((isar->iis != ISAR_IIS_DIAG) && cnt) { | |
338 | udelay(10); | |
339 | cnt--; | |
340 | } | |
341 | mdelay(1); | |
342 | if (!cnt) { | |
343 | pr_info("ISAR no self tst response\n"); | |
344 | ret = -ETIME; | |
345 | goto reterrflg; | |
346 | } | |
347 | if ((isar->cmsb == ISAR_CTRL_STST) && (isar->clsb == 1) | |
348 | && (isar->buf[0] == 0)) | |
349 | pr_debug("%s: ISAR selftest OK\n", isar->name); | |
350 | else { | |
351 | pr_info("ISAR selftest not OK %x/%x/%x\n", | |
352 | isar->cmsb, isar->clsb, isar->buf[0]); | |
353 | ret = -EIO; | |
354 | goto reterrflg; | |
355 | } | |
356 | spin_lock_irqsave(isar->hwlock, flags); | |
357 | isar->iis = 0; | |
358 | if (!send_mbox(isar, ISAR_HIS_DIAG, ISAR_CTRL_SWVER, 0, NULL)) { | |
359 | pr_info("ISAR RQST SVN failed\n"); | |
360 | ret = -ETIME; | |
361 | goto reterror; | |
362 | } | |
363 | spin_unlock_irqrestore(isar->hwlock, flags); | |
364 | cnt = 30000; /* max 300 ms */ | |
365 | while ((isar->iis != ISAR_IIS_DIAG) && cnt) { | |
366 | udelay(10); | |
367 | cnt--; | |
368 | } | |
369 | mdelay(1); | |
370 | if (!cnt) { | |
371 | pr_info("ISAR no SVN response\n"); | |
372 | ret = -ETIME; | |
373 | goto reterrflg; | |
374 | } else { | |
375 | if ((isar->cmsb == ISAR_CTRL_SWVER) && (isar->clsb == 1)) { | |
376 | pr_notice("%s: ISAR software version %#x\n", | |
475be4d8 | 377 | isar->name, isar->buf[0]); |
da2272c9 KK |
378 | } else { |
379 | pr_info("%s: ISAR wrong swver response (%x,%x)" | |
380 | " cnt(%d)\n", isar->name, isar->cmsb, | |
381 | isar->clsb, cnt); | |
382 | ret = -EIO; | |
383 | goto reterrflg; | |
384 | } | |
385 | } | |
386 | spin_lock_irqsave(isar->hwlock, flags); | |
387 | isar_setup(isar); | |
388 | spin_unlock_irqrestore(isar->hwlock, flags); | |
389 | ret = 0; | |
390 | reterrflg: | |
391 | spin_lock_irqsave(isar->hwlock, flags); | |
392 | reterror: | |
393 | isar->ch[0].bch.debug = saved_debug; | |
394 | if (ret) | |
395 | /* disable ISAR IRQ */ | |
396 | isar->write_reg(isar->hw, ISAR_IRQBIT, 0); | |
397 | spin_unlock_irqrestore(isar->hwlock, flags); | |
398 | return ret; | |
399 | } | |
400 | ||
401 | static inline void | |
402 | deliver_status(struct isar_ch *ch, int status) | |
403 | { | |
404 | pr_debug("%s: HL->LL FAXIND %x\n", ch->is->name, status); | |
405 | _queue_data(&ch->bch.ch, PH_CONTROL_IND, status, 0, NULL, GFP_ATOMIC); | |
406 | } | |
407 | ||
408 | static inline void | |
409 | isar_rcv_frame(struct isar_ch *ch) | |
410 | { | |
7206e659 KK |
411 | u8 *ptr; |
412 | int maxlen; | |
da2272c9 KK |
413 | |
414 | if (!ch->is->clsb) { | |
415 | pr_debug("%s; ISAR zero len frame\n", ch->is->name); | |
416 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); | |
417 | return; | |
418 | } | |
c27b46e7 KK |
419 | if (test_bit(FLG_RX_OFF, &ch->bch.Flags)) { |
420 | ch->bch.dropcnt += ch->is->clsb; | |
421 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); | |
422 | return; | |
423 | } | |
da2272c9 KK |
424 | switch (ch->bch.state) { |
425 | case ISDN_P_NONE: | |
426 | pr_debug("%s: ISAR protocol 0 spurious IIS_RDATA %x/%x/%x\n", | |
475be4d8 | 427 | ch->is->name, ch->is->iis, ch->is->cmsb, ch->is->clsb); |
da2272c9 KK |
428 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); |
429 | break; | |
430 | case ISDN_P_B_RAW: | |
431 | case ISDN_P_B_L2DTMF: | |
432 | case ISDN_P_B_MODEM_ASYNC: | |
7206e659 KK |
433 | maxlen = bchannel_get_rxbuf(&ch->bch, ch->is->clsb); |
434 | if (maxlen < 0) { | |
435 | pr_warning("%s.B%d: No bufferspace for %d bytes\n", | |
436 | ch->is->name, ch->bch.nr, ch->is->clsb); | |
437 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); | |
438 | break; | |
da2272c9 KK |
439 | } |
440 | rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb)); | |
034005a0 | 441 | recv_Bchannel(&ch->bch, 0, false); |
da2272c9 KK |
442 | break; |
443 | case ISDN_P_B_HDLC: | |
7206e659 KK |
444 | maxlen = bchannel_get_rxbuf(&ch->bch, ch->is->clsb); |
445 | if (maxlen < 0) { | |
446 | pr_warning("%s.B%d: No bufferspace for %d bytes\n", | |
447 | ch->is->name, ch->bch.nr, ch->is->clsb); | |
da2272c9 | 448 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); |
da2272c9 KK |
449 | break; |
450 | } | |
451 | if (ch->is->cmsb & HDLC_ERROR) { | |
452 | pr_debug("%s: ISAR frame error %x len %d\n", | |
475be4d8 | 453 | ch->is->name, ch->is->cmsb, ch->is->clsb); |
da2272c9 KK |
454 | #ifdef ERROR_STATISTIC |
455 | if (ch->is->cmsb & HDLC_ERR_RER) | |
456 | ch->bch.err_inv++; | |
457 | if (ch->is->cmsb & HDLC_ERR_CER) | |
458 | ch->bch.err_crc++; | |
459 | #endif | |
460 | skb_trim(ch->bch.rx_skb, 0); | |
461 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); | |
462 | break; | |
463 | } | |
464 | if (ch->is->cmsb & HDLC_FSD) | |
465 | skb_trim(ch->bch.rx_skb, 0); | |
466 | ptr = skb_put(ch->bch.rx_skb, ch->is->clsb); | |
467 | rcv_mbox(ch->is, ptr); | |
468 | if (ch->is->cmsb & HDLC_FED) { | |
469 | if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */ | |
470 | pr_debug("%s: ISAR frame to short %d\n", | |
475be4d8 | 471 | ch->is->name, ch->bch.rx_skb->len); |
da2272c9 KK |
472 | skb_trim(ch->bch.rx_skb, 0); |
473 | break; | |
474 | } | |
475 | skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2); | |
034005a0 | 476 | recv_Bchannel(&ch->bch, 0, false); |
da2272c9 KK |
477 | } |
478 | break; | |
479 | case ISDN_P_B_T30_FAX: | |
480 | if (ch->state != STFAX_ACTIV) { | |
481 | pr_debug("%s: isar_rcv_frame: not ACTIV\n", | |
475be4d8 | 482 | ch->is->name); |
da2272c9 KK |
483 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); |
484 | if (ch->bch.rx_skb) | |
485 | skb_trim(ch->bch.rx_skb, 0); | |
486 | break; | |
487 | } | |
488 | if (!ch->bch.rx_skb) { | |
489 | ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen, | |
475be4d8 | 490 | GFP_ATOMIC); |
da2272c9 KK |
491 | if (unlikely(!ch->bch.rx_skb)) { |
492 | pr_info("%s: B receive out of memory\n", | |
493 | __func__); | |
494 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); | |
495 | break; | |
496 | } | |
497 | } | |
498 | if (ch->cmd == PCTRL_CMD_FRM) { | |
499 | rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb)); | |
500 | pr_debug("%s: isar_rcv_frame: %d\n", | |
475be4d8 | 501 | ch->is->name, ch->bch.rx_skb->len); |
da2272c9 KK |
502 | if (ch->is->cmsb & SART_NMD) { /* ABORT */ |
503 | pr_debug("%s: isar_rcv_frame: no more data\n", | |
475be4d8 | 504 | ch->is->name); |
da2272c9 KK |
505 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); |
506 | send_mbox(ch->is, SET_DPS(ch->dpath) | | |
475be4d8 JP |
507 | ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC, |
508 | 0, NULL); | |
da2272c9 KK |
509 | ch->state = STFAX_ESCAPE; |
510 | /* set_skb_flag(skb, DF_NOMOREDATA); */ | |
511 | } | |
034005a0 | 512 | recv_Bchannel(&ch->bch, 0, false); |
da2272c9 KK |
513 | if (ch->is->cmsb & SART_NMD) |
514 | deliver_status(ch, HW_MOD_NOCARR); | |
515 | break; | |
516 | } | |
517 | if (ch->cmd != PCTRL_CMD_FRH) { | |
518 | pr_debug("%s: isar_rcv_frame: unknown fax mode %x\n", | |
475be4d8 | 519 | ch->is->name, ch->cmd); |
da2272c9 KK |
520 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); |
521 | if (ch->bch.rx_skb) | |
522 | skb_trim(ch->bch.rx_skb, 0); | |
523 | break; | |
524 | } | |
525 | /* PCTRL_CMD_FRH */ | |
526 | if ((ch->bch.rx_skb->len + ch->is->clsb) > | |
527 | (ch->bch.maxlen + 2)) { | |
528 | pr_info("%s: %s incoming packet too large\n", | |
529 | ch->is->name, __func__); | |
530 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); | |
531 | skb_trim(ch->bch.rx_skb, 0); | |
532 | break; | |
533 | } else if (ch->is->cmsb & HDLC_ERROR) { | |
534 | pr_info("%s: ISAR frame error %x len %d\n", | |
535 | ch->is->name, ch->is->cmsb, ch->is->clsb); | |
536 | skb_trim(ch->bch.rx_skb, 0); | |
537 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); | |
538 | break; | |
539 | } | |
540 | if (ch->is->cmsb & HDLC_FSD) | |
541 | skb_trim(ch->bch.rx_skb, 0); | |
542 | ptr = skb_put(ch->bch.rx_skb, ch->is->clsb); | |
543 | rcv_mbox(ch->is, ptr); | |
544 | if (ch->is->cmsb & HDLC_FED) { | |
545 | if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */ | |
546 | pr_info("%s: ISAR frame to short %d\n", | |
547 | ch->is->name, ch->bch.rx_skb->len); | |
548 | skb_trim(ch->bch.rx_skb, 0); | |
549 | break; | |
550 | } | |
551 | skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2); | |
034005a0 | 552 | recv_Bchannel(&ch->bch, 0, false); |
da2272c9 KK |
553 | } |
554 | if (ch->is->cmsb & SART_NMD) { /* ABORT */ | |
555 | pr_debug("%s: isar_rcv_frame: no more data\n", | |
475be4d8 | 556 | ch->is->name); |
da2272c9 KK |
557 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); |
558 | if (ch->bch.rx_skb) | |
559 | skb_trim(ch->bch.rx_skb, 0); | |
560 | send_mbox(ch->is, SET_DPS(ch->dpath) | | |
475be4d8 | 561 | ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC, 0, NULL); |
da2272c9 KK |
562 | ch->state = STFAX_ESCAPE; |
563 | deliver_status(ch, HW_MOD_NOCARR); | |
564 | } | |
565 | break; | |
566 | default: | |
567 | pr_info("isar_rcv_frame protocol (%x)error\n", ch->bch.state); | |
568 | ch->is->write_reg(ch->is->hw, ISAR_IIA, 0); | |
569 | break; | |
570 | } | |
571 | } | |
572 | ||
573 | static void | |
574 | isar_fill_fifo(struct isar_ch *ch) | |
575 | { | |
576 | int count; | |
577 | u8 msb; | |
578 | u8 *ptr; | |
579 | ||
6d1ee48f KK |
580 | pr_debug("%s: ch%d tx_skb %d tx_idx %d\n", ch->is->name, ch->bch.nr, |
581 | ch->bch.tx_skb ? ch->bch.tx_skb->len : -1, ch->bch.tx_idx); | |
582 | if (!(ch->is->bstat & | |
583 | (ch->dpath == 1 ? BSTAT_RDM1 : BSTAT_RDM2))) | |
584 | return; | |
585 | if (!ch->bch.tx_skb) { | |
586 | if (!test_bit(FLG_TX_EMPTY, &ch->bch.Flags) || | |
587 | (ch->bch.state != ISDN_P_B_RAW)) | |
588 | return; | |
589 | count = ch->mml; | |
590 | /* use the card buffer */ | |
591 | memset(ch->is->buf, ch->bch.fill[0], count); | |
592 | send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA, | |
593 | 0, count, ch->is->buf); | |
da2272c9 | 594 | return; |
6d1ee48f | 595 | } |
da2272c9 KK |
596 | count = ch->bch.tx_skb->len - ch->bch.tx_idx; |
597 | if (count <= 0) | |
598 | return; | |
da2272c9 KK |
599 | if (count > ch->mml) { |
600 | msb = 0; | |
601 | count = ch->mml; | |
602 | } else { | |
603 | msb = HDLC_FED; | |
604 | } | |
605 | ptr = ch->bch.tx_skb->data + ch->bch.tx_idx; | |
606 | if (!ch->bch.tx_idx) { | |
607 | pr_debug("%s: frame start\n", ch->is->name); | |
608 | if ((ch->bch.state == ISDN_P_B_T30_FAX) && | |
475be4d8 | 609 | (ch->cmd == PCTRL_CMD_FTH)) { |
da2272c9 KK |
610 | if (count > 1) { |
611 | if ((ptr[0] == 0xff) && (ptr[1] == 0x13)) { | |
612 | /* last frame */ | |
613 | test_and_set_bit(FLG_LASTDATA, | |
475be4d8 | 614 | &ch->bch.Flags); |
da2272c9 | 615 | pr_debug("%s: set LASTDATA\n", |
475be4d8 | 616 | ch->is->name); |
da2272c9 KK |
617 | if (msb == HDLC_FED) |
618 | test_and_set_bit(FLG_DLEETX, | |
475be4d8 | 619 | &ch->bch.Flags); |
da2272c9 KK |
620 | } |
621 | } | |
622 | } | |
623 | msb |= HDLC_FST; | |
624 | } | |
625 | ch->bch.tx_idx += count; | |
626 | switch (ch->bch.state) { | |
627 | case ISDN_P_NONE: | |
628 | pr_info("%s: wrong protocol 0\n", __func__); | |
629 | break; | |
630 | case ISDN_P_B_RAW: | |
631 | case ISDN_P_B_L2DTMF: | |
632 | case ISDN_P_B_MODEM_ASYNC: | |
633 | send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA, | |
475be4d8 | 634 | 0, count, ptr); |
da2272c9 KK |
635 | break; |
636 | case ISDN_P_B_HDLC: | |
637 | send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA, | |
475be4d8 | 638 | msb, count, ptr); |
da2272c9 KK |
639 | break; |
640 | case ISDN_P_B_T30_FAX: | |
641 | if (ch->state != STFAX_ACTIV) | |
642 | pr_debug("%s: not ACTIV\n", ch->is->name); | |
643 | else if (ch->cmd == PCTRL_CMD_FTH) | |
644 | send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA, | |
475be4d8 | 645 | msb, count, ptr); |
da2272c9 KK |
646 | else if (ch->cmd == PCTRL_CMD_FTM) |
647 | send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA, | |
475be4d8 | 648 | 0, count, ptr); |
da2272c9 KK |
649 | else |
650 | pr_debug("%s: not FTH/FTM\n", ch->is->name); | |
651 | break; | |
652 | default: | |
653 | pr_info("%s: protocol(%x) error\n", | |
654 | __func__, ch->bch.state); | |
655 | break; | |
656 | } | |
657 | } | |
658 | ||
659 | static inline struct isar_ch * | |
660 | sel_bch_isar(struct isar_hw *isar, u8 dpath) | |
661 | { | |
662 | struct isar_ch *base = &isar->ch[0]; | |
663 | ||
664 | if ((!dpath) || (dpath > 2)) | |
665 | return NULL; | |
666 | if (base->dpath == dpath) | |
667 | return base; | |
668 | base++; | |
669 | if (base->dpath == dpath) | |
670 | return base; | |
671 | return NULL; | |
672 | } | |
673 | ||
674 | static void | |
675 | send_next(struct isar_ch *ch) | |
676 | { | |
6d1ee48f KK |
677 | pr_debug("%s: %s ch%d tx_skb %d tx_idx %d\n", ch->is->name, __func__, |
678 | ch->bch.nr, ch->bch.tx_skb ? ch->bch.tx_skb->len : -1, | |
679 | ch->bch.tx_idx); | |
da2272c9 KK |
680 | if (ch->bch.state == ISDN_P_B_T30_FAX) { |
681 | if (ch->cmd == PCTRL_CMD_FTH) { | |
682 | if (test_bit(FLG_LASTDATA, &ch->bch.Flags)) { | |
683 | pr_debug("set NMD_DATA\n"); | |
684 | test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags); | |
685 | } | |
686 | } else if (ch->cmd == PCTRL_CMD_FTM) { | |
687 | if (test_bit(FLG_DLEETX, &ch->bch.Flags)) { | |
688 | test_and_set_bit(FLG_LASTDATA, &ch->bch.Flags); | |
689 | test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags); | |
690 | } | |
691 | } | |
692 | } | |
8bfddfbe | 693 | if (ch->bch.tx_skb) |
da2272c9 | 694 | dev_kfree_skb(ch->bch.tx_skb); |
8bfddfbe | 695 | if (get_next_bframe(&ch->bch)) { |
da2272c9 | 696 | isar_fill_fifo(ch); |
6d1ee48f KK |
697 | test_and_clear_bit(FLG_TX_EMPTY, &ch->bch.Flags); |
698 | } else if (test_bit(FLG_TX_EMPTY, &ch->bch.Flags)) { | |
699 | isar_fill_fifo(ch); | |
8bfddfbe | 700 | } else { |
da2272c9 KK |
701 | if (test_and_clear_bit(FLG_DLEETX, &ch->bch.Flags)) { |
702 | if (test_and_clear_bit(FLG_LASTDATA, | |
475be4d8 | 703 | &ch->bch.Flags)) { |
da2272c9 | 704 | if (test_and_clear_bit(FLG_NMD_DATA, |
475be4d8 | 705 | &ch->bch.Flags)) { |
da2272c9 KK |
706 | u8 zd = 0; |
707 | send_mbox(ch->is, SET_DPS(ch->dpath) | | |
475be4d8 | 708 | ISAR_HIS_SDATA, 0x01, 1, &zd); |
da2272c9 KK |
709 | } |
710 | test_and_set_bit(FLG_LL_OK, &ch->bch.Flags); | |
711 | } else { | |
712 | deliver_status(ch, HW_MOD_CONNECT); | |
713 | } | |
6d1ee48f KK |
714 | } else if (test_bit(FLG_FILLEMPTY, &ch->bch.Flags)) { |
715 | test_and_set_bit(FLG_TX_EMPTY, &ch->bch.Flags); | |
da2272c9 KK |
716 | } |
717 | } | |
718 | } | |
719 | ||
720 | static void | |
721 | check_send(struct isar_hw *isar, u8 rdm) | |
722 | { | |
723 | struct isar_ch *ch; | |
724 | ||
725 | pr_debug("%s: rdm %x\n", isar->name, rdm); | |
726 | if (rdm & BSTAT_RDM1) { | |
727 | ch = sel_bch_isar(isar, 1); | |
728 | if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) { | |
729 | if (ch->bch.tx_skb && (ch->bch.tx_skb->len > | |
475be4d8 | 730 | ch->bch.tx_idx)) |
da2272c9 KK |
731 | isar_fill_fifo(ch); |
732 | else | |
733 | send_next(ch); | |
734 | } | |
735 | } | |
736 | if (rdm & BSTAT_RDM2) { | |
737 | ch = sel_bch_isar(isar, 2); | |
738 | if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) { | |
739 | if (ch->bch.tx_skb && (ch->bch.tx_skb->len > | |
475be4d8 | 740 | ch->bch.tx_idx)) |
da2272c9 KK |
741 | isar_fill_fifo(ch); |
742 | else | |
743 | send_next(ch); | |
744 | } | |
745 | } | |
746 | } | |
747 | ||
748 | const char *dmril[] = {"NO SPEED", "1200/75", "NODEF2", "75/1200", "NODEF4", | |
475be4d8 JP |
749 | "300", "600", "1200", "2400", "4800", "7200", |
750 | "9600nt", "9600t", "12000", "14400", "WRONG"}; | |
da2272c9 | 751 | const char *dmrim[] = {"NO MOD", "NO DEF", "V32/V32b", "V22", "V21", |
475be4d8 | 752 | "Bell103", "V23", "Bell202", "V17", "V29", "V27ter"}; |
da2272c9 KK |
753 | |
754 | static void | |
755 | isar_pump_status_rsp(struct isar_ch *ch) { | |
756 | u8 ril = ch->is->buf[0]; | |
757 | u8 rim; | |
758 | ||
759 | if (!test_and_clear_bit(ISAR_RATE_REQ, &ch->is->Flags)) | |
760 | return; | |
761 | if (ril > 14) { | |
762 | pr_info("%s: wrong pstrsp ril=%d\n", ch->is->name, ril); | |
763 | ril = 15; | |
764 | } | |
765 | switch (ch->is->buf[1]) { | |
766 | case 0: | |
767 | rim = 0; | |
768 | break; | |
769 | case 0x20: | |
770 | rim = 2; | |
771 | break; | |
772 | case 0x40: | |
773 | rim = 3; | |
774 | break; | |
775 | case 0x41: | |
776 | rim = 4; | |
777 | break; | |
778 | case 0x51: | |
779 | rim = 5; | |
780 | break; | |
781 | case 0x61: | |
782 | rim = 6; | |
783 | break; | |
784 | case 0x71: | |
785 | rim = 7; | |
786 | break; | |
787 | case 0x82: | |
788 | rim = 8; | |
789 | break; | |
790 | case 0x92: | |
791 | rim = 9; | |
792 | break; | |
793 | case 0xa2: | |
794 | rim = 10; | |
795 | break; | |
796 | default: | |
797 | rim = 1; | |
798 | break; | |
799 | } | |
800 | sprintf(ch->conmsg, "%s %s", dmril[ril], dmrim[rim]); | |
801 | pr_debug("%s: pump strsp %s\n", ch->is->name, ch->conmsg); | |
802 | } | |
803 | ||
804 | static void | |
805 | isar_pump_statev_modem(struct isar_ch *ch, u8 devt) { | |
806 | u8 dps = SET_DPS(ch->dpath); | |
807 | ||
808 | switch (devt) { | |
809 | case PSEV_10MS_TIMER: | |
810 | pr_debug("%s: pump stev TIMER\n", ch->is->name); | |
811 | break; | |
812 | case PSEV_CON_ON: | |
813 | pr_debug("%s: pump stev CONNECT\n", ch->is->name); | |
814 | deliver_status(ch, HW_MOD_CONNECT); | |
815 | break; | |
816 | case PSEV_CON_OFF: | |
817 | pr_debug("%s: pump stev NO CONNECT\n", ch->is->name); | |
818 | send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL); | |
819 | deliver_status(ch, HW_MOD_NOCARR); | |
820 | break; | |
821 | case PSEV_V24_OFF: | |
822 | pr_debug("%s: pump stev V24 OFF\n", ch->is->name); | |
823 | break; | |
824 | case PSEV_CTS_ON: | |
825 | pr_debug("%s: pump stev CTS ON\n", ch->is->name); | |
826 | break; | |
827 | case PSEV_CTS_OFF: | |
828 | pr_debug("%s pump stev CTS OFF\n", ch->is->name); | |
829 | break; | |
830 | case PSEV_DCD_ON: | |
831 | pr_debug("%s: pump stev CARRIER ON\n", ch->is->name); | |
832 | test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags); | |
833 | send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL); | |
834 | break; | |
835 | case PSEV_DCD_OFF: | |
836 | pr_debug("%s: pump stev CARRIER OFF\n", ch->is->name); | |
837 | break; | |
838 | case PSEV_DSR_ON: | |
839 | pr_debug("%s: pump stev DSR ON\n", ch->is->name); | |
840 | break; | |
841 | case PSEV_DSR_OFF: | |
842 | pr_debug("%s: pump stev DSR_OFF\n", ch->is->name); | |
843 | break; | |
844 | case PSEV_REM_RET: | |
845 | pr_debug("%s: pump stev REMOTE RETRAIN\n", ch->is->name); | |
846 | break; | |
847 | case PSEV_REM_REN: | |
848 | pr_debug("%s: pump stev REMOTE RENEGOTIATE\n", ch->is->name); | |
849 | break; | |
850 | case PSEV_GSTN_CLR: | |
851 | pr_debug("%s: pump stev GSTN CLEAR\n", ch->is->name); | |
852 | break; | |
853 | default: | |
af901ca1 | 854 | pr_info("u%s: unknown pump stev %x\n", ch->is->name, devt); |
da2272c9 KK |
855 | break; |
856 | } | |
857 | } | |
858 | ||
859 | static void | |
860 | isar_pump_statev_fax(struct isar_ch *ch, u8 devt) { | |
861 | u8 dps = SET_DPS(ch->dpath); | |
862 | u8 p1; | |
863 | ||
864 | switch (devt) { | |
865 | case PSEV_10MS_TIMER: | |
866 | pr_debug("%s: pump stev TIMER\n", ch->is->name); | |
867 | break; | |
868 | case PSEV_RSP_READY: | |
869 | pr_debug("%s: pump stev RSP_READY\n", ch->is->name); | |
870 | ch->state = STFAX_READY; | |
871 | deliver_status(ch, HW_MOD_READY); | |
872 | #ifdef AUTOCON | |
873 | if (test_bit(BC_FLG_ORIG, &ch->bch.Flags)) | |
874 | isar_pump_cmd(bch, HW_MOD_FRH, 3); | |
875 | else | |
876 | isar_pump_cmd(bch, HW_MOD_FTH, 3); | |
877 | #endif | |
878 | break; | |
879 | case PSEV_LINE_TX_H: | |
880 | if (ch->state == STFAX_LINE) { | |
881 | pr_debug("%s: pump stev LINE_TX_H\n", ch->is->name); | |
882 | ch->state = STFAX_CONT; | |
883 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, | |
475be4d8 | 884 | PCTRL_CMD_CONT, 0, NULL); |
da2272c9 KK |
885 | } else { |
886 | pr_debug("%s: pump stev LINE_TX_H wrong st %x\n", | |
475be4d8 | 887 | ch->is->name, ch->state); |
da2272c9 KK |
888 | } |
889 | break; | |
890 | case PSEV_LINE_RX_H: | |
891 | if (ch->state == STFAX_LINE) { | |
892 | pr_debug("%s: pump stev LINE_RX_H\n", ch->is->name); | |
893 | ch->state = STFAX_CONT; | |
894 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, | |
475be4d8 | 895 | PCTRL_CMD_CONT, 0, NULL); |
da2272c9 KK |
896 | } else { |
897 | pr_debug("%s: pump stev LINE_RX_H wrong st %x\n", | |
475be4d8 | 898 | ch->is->name, ch->state); |
da2272c9 KK |
899 | } |
900 | break; | |
901 | case PSEV_LINE_TX_B: | |
902 | if (ch->state == STFAX_LINE) { | |
903 | pr_debug("%s: pump stev LINE_TX_B\n", ch->is->name); | |
904 | ch->state = STFAX_CONT; | |
905 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, | |
475be4d8 | 906 | PCTRL_CMD_CONT, 0, NULL); |
da2272c9 KK |
907 | } else { |
908 | pr_debug("%s: pump stev LINE_TX_B wrong st %x\n", | |
475be4d8 | 909 | ch->is->name, ch->state); |
da2272c9 KK |
910 | } |
911 | break; | |
912 | case PSEV_LINE_RX_B: | |
913 | if (ch->state == STFAX_LINE) { | |
914 | pr_debug("%s: pump stev LINE_RX_B\n", ch->is->name); | |
915 | ch->state = STFAX_CONT; | |
916 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, | |
475be4d8 | 917 | PCTRL_CMD_CONT, 0, NULL); |
da2272c9 KK |
918 | } else { |
919 | pr_debug("%s: pump stev LINE_RX_B wrong st %x\n", | |
475be4d8 | 920 | ch->is->name, ch->state); |
da2272c9 KK |
921 | } |
922 | break; | |
923 | case PSEV_RSP_CONN: | |
924 | if (ch->state == STFAX_CONT) { | |
925 | pr_debug("%s: pump stev RSP_CONN\n", ch->is->name); | |
926 | ch->state = STFAX_ACTIV; | |
927 | test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags); | |
928 | send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL); | |
929 | if (ch->cmd == PCTRL_CMD_FTH) { | |
930 | int delay = (ch->mod == 3) ? 1000 : 200; | |
931 | /* 1s (200 ms) Flags before data */ | |
932 | if (test_and_set_bit(FLG_FTI_RUN, | |
475be4d8 | 933 | &ch->bch.Flags)) |
da2272c9 KK |
934 | del_timer(&ch->ftimer); |
935 | ch->ftimer.expires = | |
475be4d8 | 936 | jiffies + ((delay * HZ) / 1000); |
da2272c9 | 937 | test_and_set_bit(FLG_LL_CONN, |
475be4d8 | 938 | &ch->bch.Flags); |
da2272c9 KK |
939 | add_timer(&ch->ftimer); |
940 | } else { | |
941 | deliver_status(ch, HW_MOD_CONNECT); | |
942 | } | |
943 | } else { | |
944 | pr_debug("%s: pump stev RSP_CONN wrong st %x\n", | |
475be4d8 | 945 | ch->is->name, ch->state); |
da2272c9 KK |
946 | } |
947 | break; | |
948 | case PSEV_FLAGS_DET: | |
949 | pr_debug("%s: pump stev FLAGS_DET\n", ch->is->name); | |
950 | break; | |
951 | case PSEV_RSP_DISC: | |
952 | pr_debug("%s: pump stev RSP_DISC state(%d)\n", | |
475be4d8 | 953 | ch->is->name, ch->state); |
da2272c9 KK |
954 | if (ch->state == STFAX_ESCAPE) { |
955 | p1 = 5; | |
956 | switch (ch->newcmd) { | |
957 | case 0: | |
958 | ch->state = STFAX_READY; | |
959 | break; | |
960 | case PCTRL_CMD_FTM: | |
961 | p1 = 2; | |
d287c502 | 962 | /* fall through */ |
da2272c9 KK |
963 | case PCTRL_CMD_FTH: |
964 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, | |
475be4d8 | 965 | PCTRL_CMD_SILON, 1, &p1); |
da2272c9 KK |
966 | ch->state = STFAX_SILDET; |
967 | break; | |
968 | case PCTRL_CMD_FRH: | |
969 | case PCTRL_CMD_FRM: | |
970 | ch->mod = ch->newmod; | |
971 | p1 = ch->newmod; | |
972 | ch->newmod = 0; | |
973 | ch->cmd = ch->newcmd; | |
974 | ch->newcmd = 0; | |
975 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, | |
475be4d8 | 976 | ch->cmd, 1, &p1); |
da2272c9 KK |
977 | ch->state = STFAX_LINE; |
978 | ch->try_mod = 3; | |
979 | break; | |
980 | default: | |
981 | pr_debug("%s: RSP_DISC unknown newcmd %x\n", | |
475be4d8 | 982 | ch->is->name, ch->newcmd); |
da2272c9 KK |
983 | break; |
984 | } | |
985 | } else if (ch->state == STFAX_ACTIV) { | |
986 | if (test_and_clear_bit(FLG_LL_OK, &ch->bch.Flags)) | |
987 | deliver_status(ch, HW_MOD_OK); | |
988 | else if (ch->cmd == PCTRL_CMD_FRM) | |
989 | deliver_status(ch, HW_MOD_NOCARR); | |
990 | else | |
991 | deliver_status(ch, HW_MOD_FCERROR); | |
992 | ch->state = STFAX_READY; | |
993 | } else if (ch->state != STFAX_SILDET) { | |
994 | /* ignore in STFAX_SILDET */ | |
995 | ch->state = STFAX_READY; | |
996 | deliver_status(ch, HW_MOD_FCERROR); | |
997 | } | |
998 | break; | |
999 | case PSEV_RSP_SILDET: | |
1000 | pr_debug("%s: pump stev RSP_SILDET\n", ch->is->name); | |
1001 | if (ch->state == STFAX_SILDET) { | |
1002 | ch->mod = ch->newmod; | |
1003 | p1 = ch->newmod; | |
1004 | ch->newmod = 0; | |
1005 | ch->cmd = ch->newcmd; | |
1006 | ch->newcmd = 0; | |
1007 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, | |
475be4d8 | 1008 | ch->cmd, 1, &p1); |
da2272c9 KK |
1009 | ch->state = STFAX_LINE; |
1010 | ch->try_mod = 3; | |
1011 | } | |
1012 | break; | |
1013 | case PSEV_RSP_SILOFF: | |
1014 | pr_debug("%s: pump stev RSP_SILOFF\n", ch->is->name); | |
1015 | break; | |
1016 | case PSEV_RSP_FCERR: | |
1017 | if (ch->state == STFAX_LINE) { | |
1018 | pr_debug("%s: pump stev RSP_FCERR try %d\n", | |
475be4d8 | 1019 | ch->is->name, ch->try_mod); |
da2272c9 KK |
1020 | if (ch->try_mod--) { |
1021 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, | |
475be4d8 | 1022 | ch->cmd, 1, &ch->mod); |
da2272c9 KK |
1023 | break; |
1024 | } | |
1025 | } | |
1026 | pr_debug("%s: pump stev RSP_FCERR\n", ch->is->name); | |
1027 | ch->state = STFAX_ESCAPE; | |
1028 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC, | |
475be4d8 | 1029 | 0, NULL); |
da2272c9 KK |
1030 | deliver_status(ch, HW_MOD_FCERROR); |
1031 | break; | |
1032 | default: | |
1033 | break; | |
1034 | } | |
1035 | } | |
1036 | ||
1037 | void | |
1038 | mISDNisar_irq(struct isar_hw *isar) | |
1039 | { | |
1040 | struct isar_ch *ch; | |
1041 | ||
1042 | get_irq_infos(isar); | |
1043 | switch (isar->iis & ISAR_IIS_MSCMSD) { | |
1044 | case ISAR_IIS_RDATA: | |
1045 | ch = sel_bch_isar(isar, isar->iis >> 6); | |
1046 | if (ch) | |
1047 | isar_rcv_frame(ch); | |
1048 | else { | |
1049 | pr_debug("%s: ISAR spurious IIS_RDATA %x/%x/%x\n", | |
475be4d8 JP |
1050 | isar->name, isar->iis, isar->cmsb, |
1051 | isar->clsb); | |
da2272c9 KK |
1052 | isar->write_reg(isar->hw, ISAR_IIA, 0); |
1053 | } | |
1054 | break; | |
1055 | case ISAR_IIS_GSTEV: | |
1056 | isar->write_reg(isar->hw, ISAR_IIA, 0); | |
1057 | isar->bstat |= isar->cmsb; | |
1058 | check_send(isar, isar->cmsb); | |
1059 | break; | |
1060 | case ISAR_IIS_BSTEV: | |
1061 | #ifdef ERROR_STATISTIC | |
1062 | ch = sel_bch_isar(isar, isar->iis >> 6); | |
1063 | if (ch) { | |
1064 | if (isar->cmsb == BSTEV_TBO) | |
1065 | ch->bch.err_tx++; | |
1066 | if (isar->cmsb == BSTEV_RBO) | |
1067 | ch->bch.err_rdo++; | |
1068 | } | |
1069 | #endif | |
1070 | pr_debug("%s: Buffer STEV dpath%d msb(%x)\n", | |
475be4d8 | 1071 | isar->name, isar->iis >> 6, isar->cmsb); |
da2272c9 KK |
1072 | isar->write_reg(isar->hw, ISAR_IIA, 0); |
1073 | break; | |
1074 | case ISAR_IIS_PSTEV: | |
1075 | ch = sel_bch_isar(isar, isar->iis >> 6); | |
1076 | if (ch) { | |
1077 | rcv_mbox(isar, NULL); | |
1078 | if (ch->bch.state == ISDN_P_B_MODEM_ASYNC) | |
1079 | isar_pump_statev_modem(ch, isar->cmsb); | |
1080 | else if (ch->bch.state == ISDN_P_B_T30_FAX) | |
1081 | isar_pump_statev_fax(ch, isar->cmsb); | |
1082 | else if (ch->bch.state == ISDN_P_B_RAW) { | |
1083 | int tt; | |
1084 | tt = isar->cmsb | 0x30; | |
1085 | if (tt == 0x3e) | |
1086 | tt = '*'; | |
1087 | else if (tt == 0x3f) | |
1088 | tt = '#'; | |
1089 | else if (tt > '9') | |
1090 | tt += 7; | |
1091 | tt |= DTMF_TONE_VAL; | |
1092 | _queue_data(&ch->bch.ch, PH_CONTROL_IND, | |
475be4d8 JP |
1093 | MISDN_ID_ANY, sizeof(tt), &tt, |
1094 | GFP_ATOMIC); | |
da2272c9 KK |
1095 | } else |
1096 | pr_debug("%s: ISAR IIS_PSTEV pm %d sta %x\n", | |
475be4d8 JP |
1097 | isar->name, ch->bch.state, |
1098 | isar->cmsb); | |
da2272c9 KK |
1099 | } else { |
1100 | pr_debug("%s: ISAR spurious IIS_PSTEV %x/%x/%x\n", | |
475be4d8 JP |
1101 | isar->name, isar->iis, isar->cmsb, |
1102 | isar->clsb); | |
da2272c9 KK |
1103 | isar->write_reg(isar->hw, ISAR_IIA, 0); |
1104 | } | |
1105 | break; | |
1106 | case ISAR_IIS_PSTRSP: | |
1107 | ch = sel_bch_isar(isar, isar->iis >> 6); | |
1108 | if (ch) { | |
1109 | rcv_mbox(isar, NULL); | |
1110 | isar_pump_status_rsp(ch); | |
1111 | } else { | |
1112 | pr_debug("%s: ISAR spurious IIS_PSTRSP %x/%x/%x\n", | |
475be4d8 JP |
1113 | isar->name, isar->iis, isar->cmsb, |
1114 | isar->clsb); | |
da2272c9 KK |
1115 | isar->write_reg(isar->hw, ISAR_IIA, 0); |
1116 | } | |
1117 | break; | |
1118 | case ISAR_IIS_DIAG: | |
1119 | case ISAR_IIS_BSTRSP: | |
1120 | case ISAR_IIS_IOM2RSP: | |
1121 | rcv_mbox(isar, NULL); | |
1122 | break; | |
1123 | case ISAR_IIS_INVMSG: | |
1124 | rcv_mbox(isar, NULL); | |
1125 | pr_debug("%s: invalid msg his:%x\n", isar->name, isar->cmsb); | |
1126 | break; | |
1127 | default: | |
1128 | rcv_mbox(isar, NULL); | |
1129 | pr_debug("%s: unhandled msg iis(%x) ctrl(%x/%x)\n", | |
475be4d8 | 1130 | isar->name, isar->iis, isar->cmsb, isar->clsb); |
da2272c9 KK |
1131 | break; |
1132 | } | |
1133 | } | |
1134 | EXPORT_SYMBOL(mISDNisar_irq); | |
1135 | ||
1136 | static void | |
e99e88a9 | 1137 | ftimer_handler(struct timer_list *t) |
da2272c9 | 1138 | { |
e99e88a9 | 1139 | struct isar_ch *ch = from_timer(ch, t, ftimer); |
da2272c9 KK |
1140 | |
1141 | pr_debug("%s: ftimer flags %lx\n", ch->is->name, ch->bch.Flags); | |
1142 | test_and_clear_bit(FLG_FTI_RUN, &ch->bch.Flags); | |
1143 | if (test_and_clear_bit(FLG_LL_CONN, &ch->bch.Flags)) | |
1144 | deliver_status(ch, HW_MOD_CONNECT); | |
1145 | } | |
1146 | ||
1147 | static void | |
1148 | setup_pump(struct isar_ch *ch) { | |
1149 | u8 dps = SET_DPS(ch->dpath); | |
1150 | u8 ctrl, param[6]; | |
1151 | ||
1152 | switch (ch->bch.state) { | |
1153 | case ISDN_P_NONE: | |
1154 | case ISDN_P_B_RAW: | |
1155 | case ISDN_P_B_HDLC: | |
1156 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, PMOD_BYPASS, 0, NULL); | |
1157 | break; | |
1158 | case ISDN_P_B_L2DTMF: | |
1159 | if (test_bit(FLG_DTMFSEND, &ch->bch.Flags)) { | |
1160 | param[0] = 5; /* TOA 5 db */ | |
1161 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, | |
475be4d8 | 1162 | PMOD_DTMF_TRANS, 1, param); |
da2272c9 KK |
1163 | } else { |
1164 | param[0] = 40; /* REL -46 dbm */ | |
1165 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, | |
475be4d8 | 1166 | PMOD_DTMF, 1, param); |
da2272c9 | 1167 | } |
d287c502 | 1168 | /* fall through */ |
da2272c9 KK |
1169 | case ISDN_P_B_MODEM_ASYNC: |
1170 | ctrl = PMOD_DATAMODEM; | |
1171 | if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) { | |
1172 | ctrl |= PCTRL_ORIG; | |
1173 | param[5] = PV32P6_CTN; | |
1174 | } else { | |
1175 | param[5] = PV32P6_ATN; | |
1176 | } | |
1177 | param[0] = 6; /* 6 db */ | |
1178 | param[1] = PV32P2_V23R | PV32P2_V22A | PV32P2_V22B | | |
1179 | PV32P2_V22C | PV32P2_V21 | PV32P2_BEL; | |
1180 | param[2] = PV32P3_AMOD | PV32P3_V32B | PV32P3_V23B; | |
1181 | param[3] = PV32P4_UT144; | |
1182 | param[4] = PV32P5_UT144; | |
1183 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 6, param); | |
1184 | break; | |
1185 | case ISDN_P_B_T30_FAX: | |
1186 | ctrl = PMOD_FAX; | |
1187 | if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) { | |
1188 | ctrl |= PCTRL_ORIG; | |
1189 | param[1] = PFAXP2_CTN; | |
1190 | } else { | |
1191 | param[1] = PFAXP2_ATN; | |
1192 | } | |
1193 | param[0] = 6; /* 6 db */ | |
1194 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 2, param); | |
1195 | ch->state = STFAX_NULL; | |
1196 | ch->newcmd = 0; | |
1197 | ch->newmod = 0; | |
1198 | test_and_set_bit(FLG_FTI_RUN, &ch->bch.Flags); | |
1199 | break; | |
1200 | } | |
1201 | udelay(1000); | |
1202 | send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL); | |
1203 | udelay(1000); | |
1204 | } | |
1205 | ||
1206 | static void | |
1207 | setup_sart(struct isar_ch *ch) { | |
1208 | u8 dps = SET_DPS(ch->dpath); | |
1209 | u8 ctrl, param[2] = {0, 0}; | |
1210 | ||
1211 | switch (ch->bch.state) { | |
1212 | case ISDN_P_NONE: | |
1213 | send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_DISABLE, | |
475be4d8 | 1214 | 0, NULL); |
da2272c9 KK |
1215 | break; |
1216 | case ISDN_P_B_RAW: | |
1217 | case ISDN_P_B_L2DTMF: | |
1218 | send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_BINARY, | |
475be4d8 | 1219 | 2, param); |
da2272c9 KK |
1220 | break; |
1221 | case ISDN_P_B_HDLC: | |
1222 | case ISDN_P_B_T30_FAX: | |
1223 | send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_HDLC, | |
475be4d8 | 1224 | 1, param); |
da2272c9 KK |
1225 | break; |
1226 | case ISDN_P_B_MODEM_ASYNC: | |
1227 | ctrl = SMODE_V14 | SCTRL_HDMC_BOTH; | |
1228 | param[0] = S_P1_CHS_8; | |
1229 | param[1] = S_P2_BFT_DEF; | |
1230 | send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, ctrl, 2, param); | |
1231 | break; | |
1232 | } | |
1233 | udelay(1000); | |
1234 | send_mbox(ch->is, dps | ISAR_HIS_BSTREQ, 0, 0, NULL); | |
1235 | udelay(1000); | |
1236 | } | |
1237 | ||
1238 | static void | |
1239 | setup_iom2(struct isar_ch *ch) { | |
1240 | u8 dps = SET_DPS(ch->dpath); | |
1241 | u8 cmsb = IOM_CTRL_ENA, msg[5] = {IOM_P1_TXD, 0, 0, 0, 0}; | |
1242 | ||
1243 | if (ch->bch.nr == 2) { | |
1244 | msg[1] = 1; | |
1245 | msg[3] = 1; | |
1246 | } | |
1247 | switch (ch->bch.state) { | |
1248 | case ISDN_P_NONE: | |
1249 | cmsb = 0; | |
1250 | /* dummy slot */ | |
1251 | msg[1] = ch->dpath + 2; | |
1252 | msg[3] = ch->dpath + 2; | |
1253 | break; | |
1254 | case ISDN_P_B_RAW: | |
1255 | case ISDN_P_B_HDLC: | |
1256 | break; | |
1257 | case ISDN_P_B_MODEM_ASYNC: | |
1258 | case ISDN_P_B_T30_FAX: | |
1259 | cmsb |= IOM_CTRL_RCV; | |
d287c502 | 1260 | /* fall through */ |
da2272c9 KK |
1261 | case ISDN_P_B_L2DTMF: |
1262 | if (test_bit(FLG_DTMFSEND, &ch->bch.Flags)) | |
1263 | cmsb |= IOM_CTRL_RCV; | |
1264 | cmsb |= IOM_CTRL_ALAW; | |
1265 | break; | |
1266 | } | |
1267 | send_mbox(ch->is, dps | ISAR_HIS_IOM2CFG, cmsb, 5, msg); | |
1268 | udelay(1000); | |
1269 | send_mbox(ch->is, dps | ISAR_HIS_IOM2REQ, 0, 0, NULL); | |
1270 | udelay(1000); | |
1271 | } | |
1272 | ||
1273 | static int | |
1274 | modeisar(struct isar_ch *ch, u32 bprotocol) | |
1275 | { | |
1276 | /* Here we are selecting the best datapath for requested protocol */ | |
1277 | if (ch->bch.state == ISDN_P_NONE) { /* New Setup */ | |
1278 | switch (bprotocol) { | |
1279 | case ISDN_P_NONE: /* init */ | |
1280 | if (!ch->dpath) | |
1281 | /* no init for dpath 0 */ | |
1282 | return 0; | |
1283 | test_and_clear_bit(FLG_HDLC, &ch->bch.Flags); | |
1284 | test_and_clear_bit(FLG_TRANSPARENT, &ch->bch.Flags); | |
1285 | break; | |
1286 | case ISDN_P_B_RAW: | |
1287 | case ISDN_P_B_HDLC: | |
1288 | /* best is datapath 2 */ | |
1289 | if (!test_and_set_bit(ISAR_DP2_USE, &ch->is->Flags)) | |
1290 | ch->dpath = 2; | |
1291 | else if (!test_and_set_bit(ISAR_DP1_USE, | |
475be4d8 | 1292 | &ch->is->Flags)) |
da2272c9 KK |
1293 | ch->dpath = 1; |
1294 | else { | |
465b1678 | 1295 | pr_info("modeisar both paths in use\n"); |
da2272c9 KK |
1296 | return -EBUSY; |
1297 | } | |
1298 | if (bprotocol == ISDN_P_B_HDLC) | |
1299 | test_and_set_bit(FLG_HDLC, &ch->bch.Flags); | |
1300 | else | |
1301 | test_and_set_bit(FLG_TRANSPARENT, | |
475be4d8 | 1302 | &ch->bch.Flags); |
da2272c9 KK |
1303 | break; |
1304 | case ISDN_P_B_MODEM_ASYNC: | |
1305 | case ISDN_P_B_T30_FAX: | |
1306 | case ISDN_P_B_L2DTMF: | |
1307 | /* only datapath 1 */ | |
1308 | if (!test_and_set_bit(ISAR_DP1_USE, &ch->is->Flags)) | |
1309 | ch->dpath = 1; | |
1310 | else { | |
1311 | pr_info("%s: ISAR modeisar analog functions" | |
1312 | "only with DP1\n", ch->is->name); | |
1313 | return -EBUSY; | |
1314 | } | |
1315 | break; | |
1316 | default: | |
1317 | pr_info("%s: protocol not known %x\n", ch->is->name, | |
1318 | bprotocol); | |
1319 | return -ENOPROTOOPT; | |
1320 | } | |
1321 | } | |
1322 | pr_debug("%s: ISAR ch%d dp%d protocol %x->%x\n", ch->is->name, | |
475be4d8 | 1323 | ch->bch.nr, ch->dpath, ch->bch.state, bprotocol); |
da2272c9 KK |
1324 | ch->bch.state = bprotocol; |
1325 | setup_pump(ch); | |
1326 | setup_iom2(ch); | |
1327 | setup_sart(ch); | |
1328 | if (ch->bch.state == ISDN_P_NONE) { | |
1329 | /* Clear resources */ | |
1330 | if (ch->dpath == 1) | |
1331 | test_and_clear_bit(ISAR_DP1_USE, &ch->is->Flags); | |
1332 | else if (ch->dpath == 2) | |
1333 | test_and_clear_bit(ISAR_DP2_USE, &ch->is->Flags); | |
1334 | ch->dpath = 0; | |
1335 | ch->is->ctrl(ch->is->hw, HW_DEACT_IND, ch->bch.nr); | |
1336 | } else | |
1337 | ch->is->ctrl(ch->is->hw, HW_ACTIVATE_IND, ch->bch.nr); | |
1338 | return 0; | |
1339 | } | |
1340 | ||
1341 | static void | |
1342 | isar_pump_cmd(struct isar_ch *ch, u32 cmd, u8 para) | |
1343 | { | |
1344 | u8 dps = SET_DPS(ch->dpath); | |
1345 | u8 ctrl = 0, nom = 0, p1 = 0; | |
1346 | ||
1347 | pr_debug("%s: isar_pump_cmd %x/%x state(%x)\n", | |
475be4d8 | 1348 | ch->is->name, cmd, para, ch->bch.state); |
da2272c9 KK |
1349 | switch (cmd) { |
1350 | case HW_MOD_FTM: | |
1351 | if (ch->state == STFAX_READY) { | |
1352 | p1 = para; | |
1353 | ctrl = PCTRL_CMD_FTM; | |
1354 | nom = 1; | |
1355 | ch->state = STFAX_LINE; | |
1356 | ch->cmd = ctrl; | |
1357 | ch->mod = para; | |
1358 | ch->newmod = 0; | |
1359 | ch->newcmd = 0; | |
1360 | ch->try_mod = 3; | |
1361 | } else if ((ch->state == STFAX_ACTIV) && | |
475be4d8 | 1362 | (ch->cmd == PCTRL_CMD_FTM) && (ch->mod == para)) |
da2272c9 KK |
1363 | deliver_status(ch, HW_MOD_CONNECT); |
1364 | else { | |
1365 | ch->newmod = para; | |
1366 | ch->newcmd = PCTRL_CMD_FTM; | |
1367 | nom = 0; | |
1368 | ctrl = PCTRL_CMD_ESC; | |
1369 | ch->state = STFAX_ESCAPE; | |
1370 | } | |
1371 | break; | |
1372 | case HW_MOD_FTH: | |
1373 | if (ch->state == STFAX_READY) { | |
1374 | p1 = para; | |
1375 | ctrl = PCTRL_CMD_FTH; | |
1376 | nom = 1; | |
1377 | ch->state = STFAX_LINE; | |
1378 | ch->cmd = ctrl; | |
1379 | ch->mod = para; | |
1380 | ch->newmod = 0; | |
1381 | ch->newcmd = 0; | |
1382 | ch->try_mod = 3; | |
1383 | } else if ((ch->state == STFAX_ACTIV) && | |
475be4d8 JP |
1384 | (ch->cmd == PCTRL_CMD_FTH) && (ch->mod == para)) |
1385 | deliver_status(ch, HW_MOD_CONNECT); | |
da2272c9 KK |
1386 | else { |
1387 | ch->newmod = para; | |
1388 | ch->newcmd = PCTRL_CMD_FTH; | |
1389 | nom = 0; | |
1390 | ctrl = PCTRL_CMD_ESC; | |
1391 | ch->state = STFAX_ESCAPE; | |
1392 | } | |
1393 | break; | |
1394 | case HW_MOD_FRM: | |
1395 | if (ch->state == STFAX_READY) { | |
1396 | p1 = para; | |
1397 | ctrl = PCTRL_CMD_FRM; | |
1398 | nom = 1; | |
1399 | ch->state = STFAX_LINE; | |
1400 | ch->cmd = ctrl; | |
1401 | ch->mod = para; | |
1402 | ch->newmod = 0; | |
1403 | ch->newcmd = 0; | |
1404 | ch->try_mod = 3; | |
1405 | } else if ((ch->state == STFAX_ACTIV) && | |
475be4d8 | 1406 | (ch->cmd == PCTRL_CMD_FRM) && (ch->mod == para)) |
da2272c9 KK |
1407 | deliver_status(ch, HW_MOD_CONNECT); |
1408 | else { | |
1409 | ch->newmod = para; | |
1410 | ch->newcmd = PCTRL_CMD_FRM; | |
1411 | nom = 0; | |
1412 | ctrl = PCTRL_CMD_ESC; | |
1413 | ch->state = STFAX_ESCAPE; | |
1414 | } | |
1415 | break; | |
1416 | case HW_MOD_FRH: | |
1417 | if (ch->state == STFAX_READY) { | |
1418 | p1 = para; | |
1419 | ctrl = PCTRL_CMD_FRH; | |
1420 | nom = 1; | |
1421 | ch->state = STFAX_LINE; | |
1422 | ch->cmd = ctrl; | |
1423 | ch->mod = para; | |
1424 | ch->newmod = 0; | |
1425 | ch->newcmd = 0; | |
1426 | ch->try_mod = 3; | |
1427 | } else if ((ch->state == STFAX_ACTIV) && | |
475be4d8 | 1428 | (ch->cmd == PCTRL_CMD_FRH) && (ch->mod == para)) |
da2272c9 KK |
1429 | deliver_status(ch, HW_MOD_CONNECT); |
1430 | else { | |
1431 | ch->newmod = para; | |
1432 | ch->newcmd = PCTRL_CMD_FRH; | |
1433 | nom = 0; | |
1434 | ctrl = PCTRL_CMD_ESC; | |
1435 | ch->state = STFAX_ESCAPE; | |
1436 | } | |
1437 | break; | |
1438 | case PCTRL_CMD_TDTMF: | |
1439 | p1 = para; | |
1440 | nom = 1; | |
1441 | ctrl = PCTRL_CMD_TDTMF; | |
1442 | break; | |
1443 | } | |
1444 | if (ctrl) | |
1445 | send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, ctrl, nom, &p1); | |
1446 | } | |
1447 | ||
1448 | static void | |
1449 | isar_setup(struct isar_hw *isar) | |
1450 | { | |
1451 | u8 msg; | |
1452 | int i; | |
1453 | ||
1454 | /* Dpath 1, 2 */ | |
1455 | msg = 61; | |
1456 | for (i = 0; i < 2; i++) { | |
1457 | /* Buffer Config */ | |
1458 | send_mbox(isar, (i ? ISAR_HIS_DPS2 : ISAR_HIS_DPS1) | | |
475be4d8 | 1459 | ISAR_HIS_P12CFG, 4, 1, &msg); |
da2272c9 KK |
1460 | isar->ch[i].mml = msg; |
1461 | isar->ch[i].bch.state = 0; | |
1462 | isar->ch[i].dpath = i + 1; | |
1463 | modeisar(&isar->ch[i], ISDN_P_NONE); | |
1464 | } | |
1465 | } | |
1466 | ||
1467 | static int | |
1468 | isar_l2l1(struct mISDNchannel *ch, struct sk_buff *skb) | |
1469 | { | |
1470 | struct bchannel *bch = container_of(ch, struct bchannel, ch); | |
1471 | struct isar_ch *ich = container_of(bch, struct isar_ch, bch); | |
1472 | int ret = -EINVAL; | |
1473 | struct mISDNhead *hh = mISDN_HEAD_P(skb); | |
1474 | u32 id, *val; | |
1475 | u_long flags; | |
1476 | ||
1477 | switch (hh->prim) { | |
1478 | case PH_DATA_REQ: | |
1479 | spin_lock_irqsave(ich->is->hwlock, flags); | |
1480 | ret = bchannel_senddata(bch, skb); | |
1481 | if (ret > 0) { /* direct TX */ | |
da2272c9 KK |
1482 | ret = 0; |
1483 | isar_fill_fifo(ich); | |
8bfddfbe KK |
1484 | } |
1485 | spin_unlock_irqrestore(ich->is->hwlock, flags); | |
da2272c9 KK |
1486 | return ret; |
1487 | case PH_ACTIVATE_REQ: | |
1488 | spin_lock_irqsave(ich->is->hwlock, flags); | |
1489 | if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags)) | |
1490 | ret = modeisar(ich, ch->protocol); | |
1491 | else | |
1492 | ret = 0; | |
1493 | spin_unlock_irqrestore(ich->is->hwlock, flags); | |
1494 | if (!ret) | |
1495 | _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0, | |
475be4d8 | 1496 | NULL, GFP_KERNEL); |
da2272c9 KK |
1497 | break; |
1498 | case PH_DEACTIVATE_REQ: | |
1499 | spin_lock_irqsave(ich->is->hwlock, flags); | |
1500 | mISDN_clear_bchannel(bch); | |
1501 | modeisar(ich, ISDN_P_NONE); | |
1502 | spin_unlock_irqrestore(ich->is->hwlock, flags); | |
1503 | _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0, | |
475be4d8 | 1504 | NULL, GFP_KERNEL); |
da2272c9 KK |
1505 | ret = 0; |
1506 | break; | |
1507 | case PH_CONTROL_REQ: | |
1508 | val = (u32 *)skb->data; | |
1509 | pr_debug("%s: PH_CONTROL | REQUEST %x/%x\n", ich->is->name, | |
475be4d8 | 1510 | hh->id, *val); |
da2272c9 | 1511 | if ((hh->id == 0) && ((*val & ~DTMF_TONE_MASK) == |
475be4d8 | 1512 | DTMF_TONE_VAL)) { |
da2272c9 KK |
1513 | if (bch->state == ISDN_P_B_L2DTMF) { |
1514 | char tt = *val & DTMF_TONE_MASK; | |
1515 | ||
1516 | if (tt == '*') | |
1517 | tt = 0x1e; | |
1518 | else if (tt == '#') | |
1519 | tt = 0x1f; | |
1520 | else if (tt > '9') | |
1521 | tt -= 7; | |
1522 | tt &= 0x1f; | |
1523 | spin_lock_irqsave(ich->is->hwlock, flags); | |
1524 | isar_pump_cmd(ich, PCTRL_CMD_TDTMF, tt); | |
1525 | spin_unlock_irqrestore(ich->is->hwlock, flags); | |
1526 | } else { | |
1527 | pr_info("%s: DTMF send wrong protocol %x\n", | |
1528 | __func__, bch->state); | |
1529 | return -EINVAL; | |
1530 | } | |
1531 | } else if ((hh->id == HW_MOD_FRM) || (hh->id == HW_MOD_FRH) || | |
475be4d8 | 1532 | (hh->id == HW_MOD_FTM) || (hh->id == HW_MOD_FTH)) { |
da2272c9 KK |
1533 | for (id = 0; id < FAXMODCNT; id++) |
1534 | if (faxmodulation[id] == *val) | |
1535 | break; | |
1536 | if ((FAXMODCNT > id) && | |
1537 | test_bit(FLG_INITIALIZED, &bch->Flags)) { | |
1538 | pr_debug("%s: isar: new mod\n", ich->is->name); | |
1539 | isar_pump_cmd(ich, hh->id, *val); | |
1540 | ret = 0; | |
1541 | } else { | |
1542 | pr_info("%s: wrong modulation\n", | |
1543 | ich->is->name); | |
1544 | ret = -EINVAL; | |
1545 | } | |
1546 | } else if (hh->id == HW_MOD_LASTDATA) | |
1547 | test_and_set_bit(FLG_DLEETX, &bch->Flags); | |
1548 | else { | |
1549 | pr_info("%s: unknown PH_CONTROL_REQ %x\n", | |
1550 | ich->is->name, hh->id); | |
1551 | ret = -EINVAL; | |
1552 | } | |
d287c502 | 1553 | /* fall through */ |
da2272c9 KK |
1554 | default: |
1555 | pr_info("%s: %s unknown prim(%x,%x)\n", | |
1556 | ich->is->name, __func__, hh->prim, hh->id); | |
1557 | ret = -EINVAL; | |
1558 | } | |
1559 | if (!ret) | |
1560 | dev_kfree_skb(skb); | |
1561 | return ret; | |
1562 | } | |
1563 | ||
1564 | static int | |
1565 | channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq) | |
1566 | { | |
034005a0 | 1567 | return mISDN_ctrl_bchannel(bch, cq); |
da2272c9 KK |
1568 | } |
1569 | ||
1570 | static int | |
1571 | isar_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg) | |
1572 | { | |
1573 | struct bchannel *bch = container_of(ch, struct bchannel, ch); | |
1574 | struct isar_ch *ich = container_of(bch, struct isar_ch, bch); | |
1575 | int ret = -EINVAL; | |
1576 | u_long flags; | |
1577 | ||
1578 | pr_debug("%s: %s cmd:%x %p\n", ich->is->name, __func__, cmd, arg); | |
1579 | switch (cmd) { | |
1580 | case CLOSE_CHANNEL: | |
1581 | test_and_clear_bit(FLG_OPEN, &bch->Flags); | |
4b921eda | 1582 | cancel_work_sync(&bch->workq); |
1368112c | 1583 | spin_lock_irqsave(ich->is->hwlock, flags); |
4b921eda | 1584 | mISDN_clear_bchannel(bch); |
1368112c KK |
1585 | modeisar(ich, ISDN_P_NONE); |
1586 | spin_unlock_irqrestore(ich->is->hwlock, flags); | |
da2272c9 KK |
1587 | ch->protocol = ISDN_P_NONE; |
1588 | ch->peer = NULL; | |
1589 | module_put(ich->is->owner); | |
1590 | ret = 0; | |
1591 | break; | |
1592 | case CONTROL_CHANNEL: | |
1593 | ret = channel_bctrl(bch, arg); | |
1594 | break; | |
1595 | default: | |
1596 | pr_info("%s: %s unknown prim(%x)\n", | |
1597 | ich->is->name, __func__, cmd); | |
1598 | } | |
1599 | return ret; | |
1600 | } | |
1601 | ||
1602 | static void | |
1603 | free_isar(struct isar_hw *isar) | |
1604 | { | |
1605 | modeisar(&isar->ch[0], ISDN_P_NONE); | |
1606 | modeisar(&isar->ch[1], ISDN_P_NONE); | |
1607 | del_timer(&isar->ch[0].ftimer); | |
1608 | del_timer(&isar->ch[1].ftimer); | |
1609 | test_and_clear_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags); | |
1610 | test_and_clear_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags); | |
1611 | } | |
1612 | ||
1613 | static int | |
1614 | init_isar(struct isar_hw *isar) | |
1615 | { | |
1616 | int cnt = 3; | |
1617 | ||
1618 | while (cnt--) { | |
1619 | isar->version = ISARVersion(isar); | |
1620 | if (isar->ch[0].bch.debug & DEBUG_HW) | |
1621 | pr_notice("%s: Testing version %d (%d time)\n", | |
475be4d8 | 1622 | isar->name, isar->version, 3 - cnt); |
da2272c9 KK |
1623 | if (isar->version == 1) |
1624 | break; | |
1625 | isar->ctrl(isar->hw, HW_RESET_REQ, 0); | |
1626 | } | |
1627 | if (isar->version != 1) | |
1628 | return -EINVAL; | |
e99e88a9 | 1629 | timer_setup(&isar->ch[0].ftimer, ftimer_handler, 0); |
da2272c9 | 1630 | test_and_set_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags); |
e99e88a9 | 1631 | timer_setup(&isar->ch[1].ftimer, ftimer_handler, 0); |
da2272c9 KK |
1632 | test_and_set_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags); |
1633 | return 0; | |
1634 | } | |
1635 | ||
1636 | static int | |
1637 | isar_open(struct isar_hw *isar, struct channel_req *rq) | |
1638 | { | |
1639 | struct bchannel *bch; | |
1640 | ||
819a1008 | 1641 | if (rq->adr.channel == 0 || rq->adr.channel > 2) |
da2272c9 KK |
1642 | return -EINVAL; |
1643 | if (rq->protocol == ISDN_P_NONE) | |
1644 | return -EINVAL; | |
1645 | bch = &isar->ch[rq->adr.channel - 1].bch; | |
1646 | if (test_and_set_bit(FLG_OPEN, &bch->Flags)) | |
1647 | return -EBUSY; /* b-channel can be only open once */ | |
da2272c9 KK |
1648 | bch->ch.protocol = rq->protocol; |
1649 | rq->ch = &bch->ch; | |
1650 | return 0; | |
1651 | } | |
1652 | ||
1653 | u32 | |
1654 | mISDNisar_init(struct isar_hw *isar, void *hw) | |
1655 | { | |
1656 | u32 ret, i; | |
1657 | ||
1658 | isar->hw = hw; | |
1659 | for (i = 0; i < 2; i++) { | |
1660 | isar->ch[i].bch.nr = i + 1; | |
034005a0 | 1661 | mISDN_initbchannel(&isar->ch[i].bch, MAX_DATA_MEM, 32); |
da2272c9 KK |
1662 | isar->ch[i].bch.ch.nr = i + 1; |
1663 | isar->ch[i].bch.ch.send = &isar_l2l1; | |
1664 | isar->ch[i].bch.ch.ctrl = isar_bctrl; | |
1665 | isar->ch[i].bch.hw = hw; | |
1666 | isar->ch[i].is = isar; | |
1667 | } | |
1668 | ||
1669 | isar->init = &init_isar; | |
1670 | isar->release = &free_isar; | |
1671 | isar->firmware = &load_firmware; | |
1672 | isar->open = &isar_open; | |
1673 | ||
1674 | ret = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) | | |
1675 | (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK)) | | |
1676 | (1 << (ISDN_P_B_L2DTMF & ISDN_P_B_MASK)) | | |
1677 | (1 << (ISDN_P_B_MODEM_ASYNC & ISDN_P_B_MASK)) | | |
1678 | (1 << (ISDN_P_B_T30_FAX & ISDN_P_B_MASK)); | |
1679 | ||
1680 | return ret; | |
1681 | } | |
1682 | EXPORT_SYMBOL(mISDNisar_init); | |
1683 | ||
88850740 | 1684 | static int __init isar_mod_init(void) |
da2272c9 KK |
1685 | { |
1686 | pr_notice("mISDN: ISAR driver Rev. %s\n", ISAR_REV); | |
1687 | return 0; | |
1688 | } | |
1689 | ||
88850740 | 1690 | static void __exit isar_mod_cleanup(void) |
da2272c9 KK |
1691 | { |
1692 | pr_notice("mISDN: ISAR module unloaded\n"); | |
1693 | } | |
1694 | module_init(isar_mod_init); | |
1695 | module_exit(isar_mod_cleanup); |