mISDNisar.c 43 KB

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