mISDNisar.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  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. if (!ch->is->clsb) {
  402. pr_debug("%s; ISAR zero len frame\n", ch->is->name);
  403. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  404. return;
  405. }
  406. switch (ch->bch.state) {
  407. case ISDN_P_NONE:
  408. pr_debug("%s: ISAR protocol 0 spurious IIS_RDATA %x/%x/%x\n",
  409. ch->is->name, ch->is->iis, ch->is->cmsb, ch->is->clsb);
  410. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  411. break;
  412. case ISDN_P_B_RAW:
  413. case ISDN_P_B_L2DTMF:
  414. case ISDN_P_B_MODEM_ASYNC:
  415. if (!ch->bch.rx_skb) {
  416. ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,
  417. GFP_ATOMIC);
  418. if (unlikely(!ch->bch.rx_skb)) {
  419. pr_info("%s: B receive out of memory\n",
  420. ch->is->name);
  421. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  422. break;
  423. }
  424. }
  425. rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb));
  426. recv_Bchannel(&ch->bch, 0);
  427. break;
  428. case ISDN_P_B_HDLC:
  429. if (!ch->bch.rx_skb) {
  430. ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,
  431. GFP_ATOMIC);
  432. if (unlikely(!ch->bch.rx_skb)) {
  433. pr_info("%s: B receive out of memory\n",
  434. ch->is->name);
  435. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  436. break;
  437. }
  438. }
  439. if ((ch->bch.rx_skb->len + ch->is->clsb) >
  440. (ch->bch.maxlen + 2)) {
  441. pr_debug("%s: incoming packet too large\n",
  442. ch->is->name);
  443. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  444. skb_trim(ch->bch.rx_skb, 0);
  445. break;
  446. }
  447. if (ch->is->cmsb & HDLC_ERROR) {
  448. pr_debug("%s: ISAR frame error %x len %d\n",
  449. ch->is->name, ch->is->cmsb, ch->is->clsb);
  450. #ifdef ERROR_STATISTIC
  451. if (ch->is->cmsb & HDLC_ERR_RER)
  452. ch->bch.err_inv++;
  453. if (ch->is->cmsb & HDLC_ERR_CER)
  454. ch->bch.err_crc++;
  455. #endif
  456. skb_trim(ch->bch.rx_skb, 0);
  457. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  458. break;
  459. }
  460. if (ch->is->cmsb & HDLC_FSD)
  461. skb_trim(ch->bch.rx_skb, 0);
  462. ptr = skb_put(ch->bch.rx_skb, ch->is->clsb);
  463. rcv_mbox(ch->is, ptr);
  464. if (ch->is->cmsb & HDLC_FED) {
  465. if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */
  466. pr_debug("%s: ISAR frame to short %d\n",
  467. ch->is->name, ch->bch.rx_skb->len);
  468. skb_trim(ch->bch.rx_skb, 0);
  469. break;
  470. }
  471. skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2);
  472. recv_Bchannel(&ch->bch, 0);
  473. }
  474. break;
  475. case ISDN_P_B_T30_FAX:
  476. if (ch->state != STFAX_ACTIV) {
  477. pr_debug("%s: isar_rcv_frame: not ACTIV\n",
  478. ch->is->name);
  479. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  480. if (ch->bch.rx_skb)
  481. skb_trim(ch->bch.rx_skb, 0);
  482. break;
  483. }
  484. if (!ch->bch.rx_skb) {
  485. ch->bch.rx_skb = mI_alloc_skb(ch->bch.maxlen,
  486. GFP_ATOMIC);
  487. if (unlikely(!ch->bch.rx_skb)) {
  488. pr_info("%s: B receive out of memory\n",
  489. __func__);
  490. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  491. break;
  492. }
  493. }
  494. if (ch->cmd == PCTRL_CMD_FRM) {
  495. rcv_mbox(ch->is, skb_put(ch->bch.rx_skb, ch->is->clsb));
  496. pr_debug("%s: isar_rcv_frame: %d\n",
  497. ch->is->name, ch->bch.rx_skb->len);
  498. if (ch->is->cmsb & SART_NMD) { /* ABORT */
  499. pr_debug("%s: isar_rcv_frame: no more data\n",
  500. ch->is->name);
  501. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  502. send_mbox(ch->is, SET_DPS(ch->dpath) |
  503. ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC,
  504. 0, NULL);
  505. ch->state = STFAX_ESCAPE;
  506. /* set_skb_flag(skb, DF_NOMOREDATA); */
  507. }
  508. recv_Bchannel(&ch->bch, 0);
  509. if (ch->is->cmsb & SART_NMD)
  510. deliver_status(ch, HW_MOD_NOCARR);
  511. break;
  512. }
  513. if (ch->cmd != PCTRL_CMD_FRH) {
  514. pr_debug("%s: isar_rcv_frame: unknown fax mode %x\n",
  515. ch->is->name, ch->cmd);
  516. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  517. if (ch->bch.rx_skb)
  518. skb_trim(ch->bch.rx_skb, 0);
  519. break;
  520. }
  521. /* PCTRL_CMD_FRH */
  522. if ((ch->bch.rx_skb->len + ch->is->clsb) >
  523. (ch->bch.maxlen + 2)) {
  524. pr_info("%s: %s incoming packet too large\n",
  525. ch->is->name, __func__);
  526. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  527. skb_trim(ch->bch.rx_skb, 0);
  528. break;
  529. } else if (ch->is->cmsb & HDLC_ERROR) {
  530. pr_info("%s: ISAR frame error %x len %d\n",
  531. ch->is->name, ch->is->cmsb, ch->is->clsb);
  532. skb_trim(ch->bch.rx_skb, 0);
  533. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  534. break;
  535. }
  536. if (ch->is->cmsb & HDLC_FSD)
  537. skb_trim(ch->bch.rx_skb, 0);
  538. ptr = skb_put(ch->bch.rx_skb, ch->is->clsb);
  539. rcv_mbox(ch->is, ptr);
  540. if (ch->is->cmsb & HDLC_FED) {
  541. if (ch->bch.rx_skb->len < 3) { /* last 2 are the FCS */
  542. pr_info("%s: ISAR frame to short %d\n",
  543. ch->is->name, ch->bch.rx_skb->len);
  544. skb_trim(ch->bch.rx_skb, 0);
  545. break;
  546. }
  547. skb_trim(ch->bch.rx_skb, ch->bch.rx_skb->len - 2);
  548. recv_Bchannel(&ch->bch, 0);
  549. }
  550. if (ch->is->cmsb & SART_NMD) { /* ABORT */
  551. pr_debug("%s: isar_rcv_frame: no more data\n",
  552. ch->is->name);
  553. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  554. if (ch->bch.rx_skb)
  555. skb_trim(ch->bch.rx_skb, 0);
  556. send_mbox(ch->is, SET_DPS(ch->dpath) |
  557. ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC, 0, NULL);
  558. ch->state = STFAX_ESCAPE;
  559. deliver_status(ch, HW_MOD_NOCARR);
  560. }
  561. break;
  562. default:
  563. pr_info("isar_rcv_frame protocol (%x)error\n", ch->bch.state);
  564. ch->is->write_reg(ch->is->hw, ISAR_IIA, 0);
  565. break;
  566. }
  567. }
  568. static void
  569. isar_fill_fifo(struct isar_ch *ch)
  570. {
  571. int count;
  572. u8 msb;
  573. u8 *ptr;
  574. pr_debug("%s: ch%d tx_skb %p tx_idx %d\n",
  575. ch->is->name, ch->bch.nr, ch->bch.tx_skb, ch->bch.tx_idx);
  576. if (!ch->bch.tx_skb)
  577. return;
  578. count = ch->bch.tx_skb->len - ch->bch.tx_idx;
  579. if (count <= 0)
  580. return;
  581. if (!(ch->is->bstat &
  582. (ch->dpath == 1 ? BSTAT_RDM1 : BSTAT_RDM2)))
  583. return;
  584. if (count > ch->mml) {
  585. msb = 0;
  586. count = ch->mml;
  587. } else {
  588. msb = HDLC_FED;
  589. }
  590. ptr = ch->bch.tx_skb->data + ch->bch.tx_idx;
  591. if (!ch->bch.tx_idx) {
  592. pr_debug("%s: frame start\n", ch->is->name);
  593. if ((ch->bch.state == ISDN_P_B_T30_FAX) &&
  594. (ch->cmd == PCTRL_CMD_FTH)) {
  595. if (count > 1) {
  596. if ((ptr[0] == 0xff) && (ptr[1] == 0x13)) {
  597. /* last frame */
  598. test_and_set_bit(FLG_LASTDATA,
  599. &ch->bch.Flags);
  600. pr_debug("%s: set LASTDATA\n",
  601. ch->is->name);
  602. if (msb == HDLC_FED)
  603. test_and_set_bit(FLG_DLEETX,
  604. &ch->bch.Flags);
  605. }
  606. }
  607. }
  608. msb |= HDLC_FST;
  609. }
  610. ch->bch.tx_idx += count;
  611. switch (ch->bch.state) {
  612. case ISDN_P_NONE:
  613. pr_info("%s: wrong protocol 0\n", __func__);
  614. break;
  615. case ISDN_P_B_RAW:
  616. case ISDN_P_B_L2DTMF:
  617. case ISDN_P_B_MODEM_ASYNC:
  618. send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
  619. 0, count, ptr);
  620. break;
  621. case ISDN_P_B_HDLC:
  622. send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
  623. msb, count, ptr);
  624. break;
  625. case ISDN_P_B_T30_FAX:
  626. if (ch->state != STFAX_ACTIV)
  627. pr_debug("%s: not ACTIV\n", ch->is->name);
  628. else if (ch->cmd == PCTRL_CMD_FTH)
  629. send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
  630. msb, count, ptr);
  631. else if (ch->cmd == PCTRL_CMD_FTM)
  632. send_mbox(ch->is, SET_DPS(ch->dpath) | ISAR_HIS_SDATA,
  633. 0, count, ptr);
  634. else
  635. pr_debug("%s: not FTH/FTM\n", ch->is->name);
  636. break;
  637. default:
  638. pr_info("%s: protocol(%x) error\n",
  639. __func__, ch->bch.state);
  640. break;
  641. }
  642. }
  643. static inline struct isar_ch *
  644. sel_bch_isar(struct isar_hw *isar, u8 dpath)
  645. {
  646. struct isar_ch *base = &isar->ch[0];
  647. if ((!dpath) || (dpath > 2))
  648. return NULL;
  649. if (base->dpath == dpath)
  650. return base;
  651. base++;
  652. if (base->dpath == dpath)
  653. return base;
  654. return NULL;
  655. }
  656. static void
  657. send_next(struct isar_ch *ch)
  658. {
  659. pr_debug("%s: %s ch%d tx_skb %p tx_idx %d\n",
  660. ch->is->name, __func__, ch->bch.nr,
  661. ch->bch.tx_skb, ch->bch.tx_idx);
  662. if (ch->bch.state == ISDN_P_B_T30_FAX) {
  663. if (ch->cmd == PCTRL_CMD_FTH) {
  664. if (test_bit(FLG_LASTDATA, &ch->bch.Flags)) {
  665. pr_debug("set NMD_DATA\n");
  666. test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags);
  667. }
  668. } else if (ch->cmd == PCTRL_CMD_FTM) {
  669. if (test_bit(FLG_DLEETX, &ch->bch.Flags)) {
  670. test_and_set_bit(FLG_LASTDATA, &ch->bch.Flags);
  671. test_and_set_bit(FLG_NMD_DATA, &ch->bch.Flags);
  672. }
  673. }
  674. }
  675. if (ch->bch.tx_skb) {
  676. /* send confirm, on trans, free on hdlc. */
  677. if (test_bit(FLG_TRANSPARENT, &ch->bch.Flags))
  678. confirm_Bsend(&ch->bch);
  679. dev_kfree_skb(ch->bch.tx_skb);
  680. }
  681. if (get_next_bframe(&ch->bch))
  682. isar_fill_fifo(ch);
  683. else {
  684. if (test_and_clear_bit(FLG_DLEETX, &ch->bch.Flags)) {
  685. if (test_and_clear_bit(FLG_LASTDATA,
  686. &ch->bch.Flags)) {
  687. if (test_and_clear_bit(FLG_NMD_DATA,
  688. &ch->bch.Flags)) {
  689. u8 zd = 0;
  690. send_mbox(ch->is, SET_DPS(ch->dpath) |
  691. ISAR_HIS_SDATA, 0x01, 1, &zd);
  692. }
  693. test_and_set_bit(FLG_LL_OK, &ch->bch.Flags);
  694. } else {
  695. deliver_status(ch, HW_MOD_CONNECT);
  696. }
  697. }
  698. }
  699. }
  700. static void
  701. check_send(struct isar_hw *isar, u8 rdm)
  702. {
  703. struct isar_ch *ch;
  704. pr_debug("%s: rdm %x\n", isar->name, rdm);
  705. if (rdm & BSTAT_RDM1) {
  706. ch = sel_bch_isar(isar, 1);
  707. if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) {
  708. if (ch->bch.tx_skb && (ch->bch.tx_skb->len >
  709. ch->bch.tx_idx))
  710. isar_fill_fifo(ch);
  711. else
  712. send_next(ch);
  713. }
  714. }
  715. if (rdm & BSTAT_RDM2) {
  716. ch = sel_bch_isar(isar, 2);
  717. if (ch && test_bit(FLG_ACTIVE, &ch->bch.Flags)) {
  718. if (ch->bch.tx_skb && (ch->bch.tx_skb->len >
  719. ch->bch.tx_idx))
  720. isar_fill_fifo(ch);
  721. else
  722. send_next(ch);
  723. }
  724. }
  725. }
  726. const char *dmril[] = {"NO SPEED", "1200/75", "NODEF2", "75/1200", "NODEF4",
  727. "300", "600", "1200", "2400", "4800", "7200",
  728. "9600nt", "9600t", "12000", "14400", "WRONG"};
  729. const char *dmrim[] = {"NO MOD", "NO DEF", "V32/V32b", "V22", "V21",
  730. "Bell103", "V23", "Bell202", "V17", "V29", "V27ter"};
  731. static void
  732. isar_pump_status_rsp(struct isar_ch *ch) {
  733. u8 ril = ch->is->buf[0];
  734. u8 rim;
  735. if (!test_and_clear_bit(ISAR_RATE_REQ, &ch->is->Flags))
  736. return;
  737. if (ril > 14) {
  738. pr_info("%s: wrong pstrsp ril=%d\n", ch->is->name, ril);
  739. ril = 15;
  740. }
  741. switch (ch->is->buf[1]) {
  742. case 0:
  743. rim = 0;
  744. break;
  745. case 0x20:
  746. rim = 2;
  747. break;
  748. case 0x40:
  749. rim = 3;
  750. break;
  751. case 0x41:
  752. rim = 4;
  753. break;
  754. case 0x51:
  755. rim = 5;
  756. break;
  757. case 0x61:
  758. rim = 6;
  759. break;
  760. case 0x71:
  761. rim = 7;
  762. break;
  763. case 0x82:
  764. rim = 8;
  765. break;
  766. case 0x92:
  767. rim = 9;
  768. break;
  769. case 0xa2:
  770. rim = 10;
  771. break;
  772. default:
  773. rim = 1;
  774. break;
  775. }
  776. sprintf(ch->conmsg, "%s %s", dmril[ril], dmrim[rim]);
  777. pr_debug("%s: pump strsp %s\n", ch->is->name, ch->conmsg);
  778. }
  779. static void
  780. isar_pump_statev_modem(struct isar_ch *ch, u8 devt) {
  781. u8 dps = SET_DPS(ch->dpath);
  782. switch (devt) {
  783. case PSEV_10MS_TIMER:
  784. pr_debug("%s: pump stev TIMER\n", ch->is->name);
  785. break;
  786. case PSEV_CON_ON:
  787. pr_debug("%s: pump stev CONNECT\n", ch->is->name);
  788. deliver_status(ch, HW_MOD_CONNECT);
  789. break;
  790. case PSEV_CON_OFF:
  791. pr_debug("%s: pump stev NO CONNECT\n", ch->is->name);
  792. send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
  793. deliver_status(ch, HW_MOD_NOCARR);
  794. break;
  795. case PSEV_V24_OFF:
  796. pr_debug("%s: pump stev V24 OFF\n", ch->is->name);
  797. break;
  798. case PSEV_CTS_ON:
  799. pr_debug("%s: pump stev CTS ON\n", ch->is->name);
  800. break;
  801. case PSEV_CTS_OFF:
  802. pr_debug("%s pump stev CTS OFF\n", ch->is->name);
  803. break;
  804. case PSEV_DCD_ON:
  805. pr_debug("%s: pump stev CARRIER ON\n", ch->is->name);
  806. test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags);
  807. send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
  808. break;
  809. case PSEV_DCD_OFF:
  810. pr_debug("%s: pump stev CARRIER OFF\n", ch->is->name);
  811. break;
  812. case PSEV_DSR_ON:
  813. pr_debug("%s: pump stev DSR ON\n", ch->is->name);
  814. break;
  815. case PSEV_DSR_OFF:
  816. pr_debug("%s: pump stev DSR_OFF\n", ch->is->name);
  817. break;
  818. case PSEV_REM_RET:
  819. pr_debug("%s: pump stev REMOTE RETRAIN\n", ch->is->name);
  820. break;
  821. case PSEV_REM_REN:
  822. pr_debug("%s: pump stev REMOTE RENEGOTIATE\n", ch->is->name);
  823. break;
  824. case PSEV_GSTN_CLR:
  825. pr_debug("%s: pump stev GSTN CLEAR\n", ch->is->name);
  826. break;
  827. default:
  828. pr_info("u%s: unknown pump stev %x\n", ch->is->name, devt);
  829. break;
  830. }
  831. }
  832. static void
  833. isar_pump_statev_fax(struct isar_ch *ch, u8 devt) {
  834. u8 dps = SET_DPS(ch->dpath);
  835. u8 p1;
  836. switch (devt) {
  837. case PSEV_10MS_TIMER:
  838. pr_debug("%s: pump stev TIMER\n", ch->is->name);
  839. break;
  840. case PSEV_RSP_READY:
  841. pr_debug("%s: pump stev RSP_READY\n", ch->is->name);
  842. ch->state = STFAX_READY;
  843. deliver_status(ch, HW_MOD_READY);
  844. #ifdef AUTOCON
  845. if (test_bit(BC_FLG_ORIG, &ch->bch.Flags))
  846. isar_pump_cmd(bch, HW_MOD_FRH, 3);
  847. else
  848. isar_pump_cmd(bch, HW_MOD_FTH, 3);
  849. #endif
  850. break;
  851. case PSEV_LINE_TX_H:
  852. if (ch->state == STFAX_LINE) {
  853. pr_debug("%s: pump stev LINE_TX_H\n", ch->is->name);
  854. ch->state = STFAX_CONT;
  855. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
  856. PCTRL_CMD_CONT, 0, NULL);
  857. } else {
  858. pr_debug("%s: pump stev LINE_TX_H wrong st %x\n",
  859. ch->is->name, ch->state);
  860. }
  861. break;
  862. case PSEV_LINE_RX_H:
  863. if (ch->state == STFAX_LINE) {
  864. pr_debug("%s: pump stev LINE_RX_H\n", ch->is->name);
  865. ch->state = STFAX_CONT;
  866. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
  867. PCTRL_CMD_CONT, 0, NULL);
  868. } else {
  869. pr_debug("%s: pump stev LINE_RX_H wrong st %x\n",
  870. ch->is->name, ch->state);
  871. }
  872. break;
  873. case PSEV_LINE_TX_B:
  874. if (ch->state == STFAX_LINE) {
  875. pr_debug("%s: pump stev LINE_TX_B\n", ch->is->name);
  876. ch->state = STFAX_CONT;
  877. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
  878. PCTRL_CMD_CONT, 0, NULL);
  879. } else {
  880. pr_debug("%s: pump stev LINE_TX_B wrong st %x\n",
  881. ch->is->name, ch->state);
  882. }
  883. break;
  884. case PSEV_LINE_RX_B:
  885. if (ch->state == STFAX_LINE) {
  886. pr_debug("%s: pump stev LINE_RX_B\n", ch->is->name);
  887. ch->state = STFAX_CONT;
  888. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
  889. PCTRL_CMD_CONT, 0, NULL);
  890. } else {
  891. pr_debug("%s: pump stev LINE_RX_B wrong st %x\n",
  892. ch->is->name, ch->state);
  893. }
  894. break;
  895. case PSEV_RSP_CONN:
  896. if (ch->state == STFAX_CONT) {
  897. pr_debug("%s: pump stev RSP_CONN\n", ch->is->name);
  898. ch->state = STFAX_ACTIV;
  899. test_and_set_bit(ISAR_RATE_REQ, &ch->is->Flags);
  900. send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
  901. if (ch->cmd == PCTRL_CMD_FTH) {
  902. int delay = (ch->mod == 3) ? 1000 : 200;
  903. /* 1s (200 ms) Flags before data */
  904. if (test_and_set_bit(FLG_FTI_RUN,
  905. &ch->bch.Flags))
  906. del_timer(&ch->ftimer);
  907. ch->ftimer.expires =
  908. jiffies + ((delay * HZ) / 1000);
  909. test_and_set_bit(FLG_LL_CONN,
  910. &ch->bch.Flags);
  911. add_timer(&ch->ftimer);
  912. } else {
  913. deliver_status(ch, HW_MOD_CONNECT);
  914. }
  915. } else {
  916. pr_debug("%s: pump stev RSP_CONN wrong st %x\n",
  917. ch->is->name, ch->state);
  918. }
  919. break;
  920. case PSEV_FLAGS_DET:
  921. pr_debug("%s: pump stev FLAGS_DET\n", ch->is->name);
  922. break;
  923. case PSEV_RSP_DISC:
  924. pr_debug("%s: pump stev RSP_DISC state(%d)\n",
  925. ch->is->name, ch->state);
  926. if (ch->state == STFAX_ESCAPE) {
  927. p1 = 5;
  928. switch (ch->newcmd) {
  929. case 0:
  930. ch->state = STFAX_READY;
  931. break;
  932. case PCTRL_CMD_FTM:
  933. p1 = 2;
  934. case PCTRL_CMD_FTH:
  935. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
  936. PCTRL_CMD_SILON, 1, &p1);
  937. ch->state = STFAX_SILDET;
  938. break;
  939. case PCTRL_CMD_FRH:
  940. case PCTRL_CMD_FRM:
  941. ch->mod = ch->newmod;
  942. p1 = ch->newmod;
  943. ch->newmod = 0;
  944. ch->cmd = ch->newcmd;
  945. ch->newcmd = 0;
  946. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
  947. ch->cmd, 1, &p1);
  948. ch->state = STFAX_LINE;
  949. ch->try_mod = 3;
  950. break;
  951. default:
  952. pr_debug("%s: RSP_DISC unknown newcmd %x\n",
  953. ch->is->name, ch->newcmd);
  954. break;
  955. }
  956. } else if (ch->state == STFAX_ACTIV) {
  957. if (test_and_clear_bit(FLG_LL_OK, &ch->bch.Flags))
  958. deliver_status(ch, HW_MOD_OK);
  959. else if (ch->cmd == PCTRL_CMD_FRM)
  960. deliver_status(ch, HW_MOD_NOCARR);
  961. else
  962. deliver_status(ch, HW_MOD_FCERROR);
  963. ch->state = STFAX_READY;
  964. } else if (ch->state != STFAX_SILDET) {
  965. /* ignore in STFAX_SILDET */
  966. ch->state = STFAX_READY;
  967. deliver_status(ch, HW_MOD_FCERROR);
  968. }
  969. break;
  970. case PSEV_RSP_SILDET:
  971. pr_debug("%s: pump stev RSP_SILDET\n", ch->is->name);
  972. if (ch->state == STFAX_SILDET) {
  973. ch->mod = ch->newmod;
  974. p1 = ch->newmod;
  975. ch->newmod = 0;
  976. ch->cmd = ch->newcmd;
  977. ch->newcmd = 0;
  978. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
  979. ch->cmd, 1, &p1);
  980. ch->state = STFAX_LINE;
  981. ch->try_mod = 3;
  982. }
  983. break;
  984. case PSEV_RSP_SILOFF:
  985. pr_debug("%s: pump stev RSP_SILOFF\n", ch->is->name);
  986. break;
  987. case PSEV_RSP_FCERR:
  988. if (ch->state == STFAX_LINE) {
  989. pr_debug("%s: pump stev RSP_FCERR try %d\n",
  990. ch->is->name, ch->try_mod);
  991. if (ch->try_mod--) {
  992. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL,
  993. ch->cmd, 1, &ch->mod);
  994. break;
  995. }
  996. }
  997. pr_debug("%s: pump stev RSP_FCERR\n", ch->is->name);
  998. ch->state = STFAX_ESCAPE;
  999. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, PCTRL_CMD_ESC,
  1000. 0, NULL);
  1001. deliver_status(ch, HW_MOD_FCERROR);
  1002. break;
  1003. default:
  1004. break;
  1005. }
  1006. }
  1007. void
  1008. mISDNisar_irq(struct isar_hw *isar)
  1009. {
  1010. struct isar_ch *ch;
  1011. get_irq_infos(isar);
  1012. switch (isar->iis & ISAR_IIS_MSCMSD) {
  1013. case ISAR_IIS_RDATA:
  1014. ch = sel_bch_isar(isar, isar->iis >> 6);
  1015. if (ch)
  1016. isar_rcv_frame(ch);
  1017. else {
  1018. pr_debug("%s: ISAR spurious IIS_RDATA %x/%x/%x\n",
  1019. isar->name, isar->iis, isar->cmsb,
  1020. isar->clsb);
  1021. isar->write_reg(isar->hw, ISAR_IIA, 0);
  1022. }
  1023. break;
  1024. case ISAR_IIS_GSTEV:
  1025. isar->write_reg(isar->hw, ISAR_IIA, 0);
  1026. isar->bstat |= isar->cmsb;
  1027. check_send(isar, isar->cmsb);
  1028. break;
  1029. case ISAR_IIS_BSTEV:
  1030. #ifdef ERROR_STATISTIC
  1031. ch = sel_bch_isar(isar, isar->iis >> 6);
  1032. if (ch) {
  1033. if (isar->cmsb == BSTEV_TBO)
  1034. ch->bch.err_tx++;
  1035. if (isar->cmsb == BSTEV_RBO)
  1036. ch->bch.err_rdo++;
  1037. }
  1038. #endif
  1039. pr_debug("%s: Buffer STEV dpath%d msb(%x)\n",
  1040. isar->name, isar->iis >> 6, isar->cmsb);
  1041. isar->write_reg(isar->hw, ISAR_IIA, 0);
  1042. break;
  1043. case ISAR_IIS_PSTEV:
  1044. ch = sel_bch_isar(isar, isar->iis >> 6);
  1045. if (ch) {
  1046. rcv_mbox(isar, NULL);
  1047. if (ch->bch.state == ISDN_P_B_MODEM_ASYNC)
  1048. isar_pump_statev_modem(ch, isar->cmsb);
  1049. else if (ch->bch.state == ISDN_P_B_T30_FAX)
  1050. isar_pump_statev_fax(ch, isar->cmsb);
  1051. else if (ch->bch.state == ISDN_P_B_RAW) {
  1052. int tt;
  1053. tt = isar->cmsb | 0x30;
  1054. if (tt == 0x3e)
  1055. tt = '*';
  1056. else if (tt == 0x3f)
  1057. tt = '#';
  1058. else if (tt > '9')
  1059. tt += 7;
  1060. tt |= DTMF_TONE_VAL;
  1061. _queue_data(&ch->bch.ch, PH_CONTROL_IND,
  1062. MISDN_ID_ANY, sizeof(tt), &tt,
  1063. GFP_ATOMIC);
  1064. } else
  1065. pr_debug("%s: ISAR IIS_PSTEV pm %d sta %x\n",
  1066. isar->name, ch->bch.state,
  1067. isar->cmsb);
  1068. } else {
  1069. pr_debug("%s: ISAR spurious IIS_PSTEV %x/%x/%x\n",
  1070. isar->name, isar->iis, isar->cmsb,
  1071. isar->clsb);
  1072. isar->write_reg(isar->hw, ISAR_IIA, 0);
  1073. }
  1074. break;
  1075. case ISAR_IIS_PSTRSP:
  1076. ch = sel_bch_isar(isar, isar->iis >> 6);
  1077. if (ch) {
  1078. rcv_mbox(isar, NULL);
  1079. isar_pump_status_rsp(ch);
  1080. } else {
  1081. pr_debug("%s: ISAR spurious IIS_PSTRSP %x/%x/%x\n",
  1082. isar->name, isar->iis, isar->cmsb,
  1083. isar->clsb);
  1084. isar->write_reg(isar->hw, ISAR_IIA, 0);
  1085. }
  1086. break;
  1087. case ISAR_IIS_DIAG:
  1088. case ISAR_IIS_BSTRSP:
  1089. case ISAR_IIS_IOM2RSP:
  1090. rcv_mbox(isar, NULL);
  1091. break;
  1092. case ISAR_IIS_INVMSG:
  1093. rcv_mbox(isar, NULL);
  1094. pr_debug("%s: invalid msg his:%x\n", isar->name, isar->cmsb);
  1095. break;
  1096. default:
  1097. rcv_mbox(isar, NULL);
  1098. pr_debug("%s: unhandled msg iis(%x) ctrl(%x/%x)\n",
  1099. isar->name, isar->iis, isar->cmsb, isar->clsb);
  1100. break;
  1101. }
  1102. }
  1103. EXPORT_SYMBOL(mISDNisar_irq);
  1104. static void
  1105. ftimer_handler(unsigned long data)
  1106. {
  1107. struct isar_ch *ch = (struct isar_ch *)data;
  1108. pr_debug("%s: ftimer flags %lx\n", ch->is->name, ch->bch.Flags);
  1109. test_and_clear_bit(FLG_FTI_RUN, &ch->bch.Flags);
  1110. if (test_and_clear_bit(FLG_LL_CONN, &ch->bch.Flags))
  1111. deliver_status(ch, HW_MOD_CONNECT);
  1112. }
  1113. static void
  1114. setup_pump(struct isar_ch *ch) {
  1115. u8 dps = SET_DPS(ch->dpath);
  1116. u8 ctrl, param[6];
  1117. switch (ch->bch.state) {
  1118. case ISDN_P_NONE:
  1119. case ISDN_P_B_RAW:
  1120. case ISDN_P_B_HDLC:
  1121. send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, PMOD_BYPASS, 0, NULL);
  1122. break;
  1123. case ISDN_P_B_L2DTMF:
  1124. if (test_bit(FLG_DTMFSEND, &ch->bch.Flags)) {
  1125. param[0] = 5; /* TOA 5 db */
  1126. send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG,
  1127. PMOD_DTMF_TRANS, 1, param);
  1128. } else {
  1129. param[0] = 40; /* REL -46 dbm */
  1130. send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG,
  1131. PMOD_DTMF, 1, param);
  1132. }
  1133. case ISDN_P_B_MODEM_ASYNC:
  1134. ctrl = PMOD_DATAMODEM;
  1135. if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) {
  1136. ctrl |= PCTRL_ORIG;
  1137. param[5] = PV32P6_CTN;
  1138. } else {
  1139. param[5] = PV32P6_ATN;
  1140. }
  1141. param[0] = 6; /* 6 db */
  1142. param[1] = PV32P2_V23R | PV32P2_V22A | PV32P2_V22B |
  1143. PV32P2_V22C | PV32P2_V21 | PV32P2_BEL;
  1144. param[2] = PV32P3_AMOD | PV32P3_V32B | PV32P3_V23B;
  1145. param[3] = PV32P4_UT144;
  1146. param[4] = PV32P5_UT144;
  1147. send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 6, param);
  1148. break;
  1149. case ISDN_P_B_T30_FAX:
  1150. ctrl = PMOD_FAX;
  1151. if (test_bit(FLG_ORIGIN, &ch->bch.Flags)) {
  1152. ctrl |= PCTRL_ORIG;
  1153. param[1] = PFAXP2_CTN;
  1154. } else {
  1155. param[1] = PFAXP2_ATN;
  1156. }
  1157. param[0] = 6; /* 6 db */
  1158. send_mbox(ch->is, dps | ISAR_HIS_PUMPCFG, ctrl, 2, param);
  1159. ch->state = STFAX_NULL;
  1160. ch->newcmd = 0;
  1161. ch->newmod = 0;
  1162. test_and_set_bit(FLG_FTI_RUN, &ch->bch.Flags);
  1163. break;
  1164. }
  1165. udelay(1000);
  1166. send_mbox(ch->is, dps | ISAR_HIS_PSTREQ, 0, 0, NULL);
  1167. udelay(1000);
  1168. }
  1169. static void
  1170. setup_sart(struct isar_ch *ch) {
  1171. u8 dps = SET_DPS(ch->dpath);
  1172. u8 ctrl, param[2] = {0, 0};
  1173. switch (ch->bch.state) {
  1174. case ISDN_P_NONE:
  1175. send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_DISABLE,
  1176. 0, NULL);
  1177. break;
  1178. case ISDN_P_B_RAW:
  1179. case ISDN_P_B_L2DTMF:
  1180. send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_BINARY,
  1181. 2, param);
  1182. break;
  1183. case ISDN_P_B_HDLC:
  1184. case ISDN_P_B_T30_FAX:
  1185. send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, SMODE_HDLC,
  1186. 1, param);
  1187. break;
  1188. case ISDN_P_B_MODEM_ASYNC:
  1189. ctrl = SMODE_V14 | SCTRL_HDMC_BOTH;
  1190. param[0] = S_P1_CHS_8;
  1191. param[1] = S_P2_BFT_DEF;
  1192. send_mbox(ch->is, dps | ISAR_HIS_SARTCFG, ctrl, 2, param);
  1193. break;
  1194. }
  1195. udelay(1000);
  1196. send_mbox(ch->is, dps | ISAR_HIS_BSTREQ, 0, 0, NULL);
  1197. udelay(1000);
  1198. }
  1199. static void
  1200. setup_iom2(struct isar_ch *ch) {
  1201. u8 dps = SET_DPS(ch->dpath);
  1202. u8 cmsb = IOM_CTRL_ENA, msg[5] = {IOM_P1_TXD, 0, 0, 0, 0};
  1203. if (ch->bch.nr == 2) {
  1204. msg[1] = 1;
  1205. msg[3] = 1;
  1206. }
  1207. switch (ch->bch.state) {
  1208. case ISDN_P_NONE:
  1209. cmsb = 0;
  1210. /* dummy slot */
  1211. msg[1] = ch->dpath + 2;
  1212. msg[3] = ch->dpath + 2;
  1213. break;
  1214. case ISDN_P_B_RAW:
  1215. case ISDN_P_B_HDLC:
  1216. break;
  1217. case ISDN_P_B_MODEM_ASYNC:
  1218. case ISDN_P_B_T30_FAX:
  1219. cmsb |= IOM_CTRL_RCV;
  1220. case ISDN_P_B_L2DTMF:
  1221. if (test_bit(FLG_DTMFSEND, &ch->bch.Flags))
  1222. cmsb |= IOM_CTRL_RCV;
  1223. cmsb |= IOM_CTRL_ALAW;
  1224. break;
  1225. }
  1226. send_mbox(ch->is, dps | ISAR_HIS_IOM2CFG, cmsb, 5, msg);
  1227. udelay(1000);
  1228. send_mbox(ch->is, dps | ISAR_HIS_IOM2REQ, 0, 0, NULL);
  1229. udelay(1000);
  1230. }
  1231. static int
  1232. modeisar(struct isar_ch *ch, u32 bprotocol)
  1233. {
  1234. /* Here we are selecting the best datapath for requested protocol */
  1235. if (ch->bch.state == ISDN_P_NONE) { /* New Setup */
  1236. switch (bprotocol) {
  1237. case ISDN_P_NONE: /* init */
  1238. if (!ch->dpath)
  1239. /* no init for dpath 0 */
  1240. return 0;
  1241. test_and_clear_bit(FLG_HDLC, &ch->bch.Flags);
  1242. test_and_clear_bit(FLG_TRANSPARENT, &ch->bch.Flags);
  1243. break;
  1244. case ISDN_P_B_RAW:
  1245. case ISDN_P_B_HDLC:
  1246. /* best is datapath 2 */
  1247. if (!test_and_set_bit(ISAR_DP2_USE, &ch->is->Flags))
  1248. ch->dpath = 2;
  1249. else if (!test_and_set_bit(ISAR_DP1_USE,
  1250. &ch->is->Flags))
  1251. ch->dpath = 1;
  1252. else {
  1253. pr_info("modeisar both pathes in use\n");
  1254. return -EBUSY;
  1255. }
  1256. if (bprotocol == ISDN_P_B_HDLC)
  1257. test_and_set_bit(FLG_HDLC, &ch->bch.Flags);
  1258. else
  1259. test_and_set_bit(FLG_TRANSPARENT,
  1260. &ch->bch.Flags);
  1261. break;
  1262. case ISDN_P_B_MODEM_ASYNC:
  1263. case ISDN_P_B_T30_FAX:
  1264. case ISDN_P_B_L2DTMF:
  1265. /* only datapath 1 */
  1266. if (!test_and_set_bit(ISAR_DP1_USE, &ch->is->Flags))
  1267. ch->dpath = 1;
  1268. else {
  1269. pr_info("%s: ISAR modeisar analog functions"
  1270. "only with DP1\n", ch->is->name);
  1271. return -EBUSY;
  1272. }
  1273. break;
  1274. default:
  1275. pr_info("%s: protocol not known %x\n", ch->is->name,
  1276. bprotocol);
  1277. return -ENOPROTOOPT;
  1278. }
  1279. }
  1280. pr_debug("%s: ISAR ch%d dp%d protocol %x->%x\n", ch->is->name,
  1281. ch->bch.nr, ch->dpath, ch->bch.state, bprotocol);
  1282. ch->bch.state = bprotocol;
  1283. setup_pump(ch);
  1284. setup_iom2(ch);
  1285. setup_sart(ch);
  1286. if (ch->bch.state == ISDN_P_NONE) {
  1287. /* Clear resources */
  1288. if (ch->dpath == 1)
  1289. test_and_clear_bit(ISAR_DP1_USE, &ch->is->Flags);
  1290. else if (ch->dpath == 2)
  1291. test_and_clear_bit(ISAR_DP2_USE, &ch->is->Flags);
  1292. ch->dpath = 0;
  1293. ch->is->ctrl(ch->is->hw, HW_DEACT_IND, ch->bch.nr);
  1294. } else
  1295. ch->is->ctrl(ch->is->hw, HW_ACTIVATE_IND, ch->bch.nr);
  1296. return 0;
  1297. }
  1298. static void
  1299. isar_pump_cmd(struct isar_ch *ch, u32 cmd, u8 para)
  1300. {
  1301. u8 dps = SET_DPS(ch->dpath);
  1302. u8 ctrl = 0, nom = 0, p1 = 0;
  1303. pr_debug("%s: isar_pump_cmd %x/%x state(%x)\n",
  1304. ch->is->name, cmd, para, ch->bch.state);
  1305. switch (cmd) {
  1306. case HW_MOD_FTM:
  1307. if (ch->state == STFAX_READY) {
  1308. p1 = para;
  1309. ctrl = PCTRL_CMD_FTM;
  1310. nom = 1;
  1311. ch->state = STFAX_LINE;
  1312. ch->cmd = ctrl;
  1313. ch->mod = para;
  1314. ch->newmod = 0;
  1315. ch->newcmd = 0;
  1316. ch->try_mod = 3;
  1317. } else if ((ch->state == STFAX_ACTIV) &&
  1318. (ch->cmd == PCTRL_CMD_FTM) && (ch->mod == para))
  1319. deliver_status(ch, HW_MOD_CONNECT);
  1320. else {
  1321. ch->newmod = para;
  1322. ch->newcmd = PCTRL_CMD_FTM;
  1323. nom = 0;
  1324. ctrl = PCTRL_CMD_ESC;
  1325. ch->state = STFAX_ESCAPE;
  1326. }
  1327. break;
  1328. case HW_MOD_FTH:
  1329. if (ch->state == STFAX_READY) {
  1330. p1 = para;
  1331. ctrl = PCTRL_CMD_FTH;
  1332. nom = 1;
  1333. ch->state = STFAX_LINE;
  1334. ch->cmd = ctrl;
  1335. ch->mod = para;
  1336. ch->newmod = 0;
  1337. ch->newcmd = 0;
  1338. ch->try_mod = 3;
  1339. } else if ((ch->state == STFAX_ACTIV) &&
  1340. (ch->cmd == PCTRL_CMD_FTH) && (ch->mod == para))
  1341. deliver_status(ch, HW_MOD_CONNECT);
  1342. else {
  1343. ch->newmod = para;
  1344. ch->newcmd = PCTRL_CMD_FTH;
  1345. nom = 0;
  1346. ctrl = PCTRL_CMD_ESC;
  1347. ch->state = STFAX_ESCAPE;
  1348. }
  1349. break;
  1350. case HW_MOD_FRM:
  1351. if (ch->state == STFAX_READY) {
  1352. p1 = para;
  1353. ctrl = PCTRL_CMD_FRM;
  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) &&
  1362. (ch->cmd == PCTRL_CMD_FRM) && (ch->mod == para))
  1363. deliver_status(ch, HW_MOD_CONNECT);
  1364. else {
  1365. ch->newmod = para;
  1366. ch->newcmd = PCTRL_CMD_FRM;
  1367. nom = 0;
  1368. ctrl = PCTRL_CMD_ESC;
  1369. ch->state = STFAX_ESCAPE;
  1370. }
  1371. break;
  1372. case HW_MOD_FRH:
  1373. if (ch->state == STFAX_READY) {
  1374. p1 = para;
  1375. ctrl = PCTRL_CMD_FRH;
  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) &&
  1384. (ch->cmd == PCTRL_CMD_FRH) && (ch->mod == para))
  1385. deliver_status(ch, HW_MOD_CONNECT);
  1386. else {
  1387. ch->newmod = para;
  1388. ch->newcmd = PCTRL_CMD_FRH;
  1389. nom = 0;
  1390. ctrl = PCTRL_CMD_ESC;
  1391. ch->state = STFAX_ESCAPE;
  1392. }
  1393. break;
  1394. case PCTRL_CMD_TDTMF:
  1395. p1 = para;
  1396. nom = 1;
  1397. ctrl = PCTRL_CMD_TDTMF;
  1398. break;
  1399. }
  1400. if (ctrl)
  1401. send_mbox(ch->is, dps | ISAR_HIS_PUMPCTRL, ctrl, nom, &p1);
  1402. }
  1403. static void
  1404. isar_setup(struct isar_hw *isar)
  1405. {
  1406. u8 msg;
  1407. int i;
  1408. /* Dpath 1, 2 */
  1409. msg = 61;
  1410. for (i = 0; i < 2; i++) {
  1411. /* Buffer Config */
  1412. send_mbox(isar, (i ? ISAR_HIS_DPS2 : ISAR_HIS_DPS1) |
  1413. ISAR_HIS_P12CFG, 4, 1, &msg);
  1414. isar->ch[i].mml = msg;
  1415. isar->ch[i].bch.state = 0;
  1416. isar->ch[i].dpath = i + 1;
  1417. modeisar(&isar->ch[i], ISDN_P_NONE);
  1418. }
  1419. }
  1420. static int
  1421. isar_l2l1(struct mISDNchannel *ch, struct sk_buff *skb)
  1422. {
  1423. struct bchannel *bch = container_of(ch, struct bchannel, ch);
  1424. struct isar_ch *ich = container_of(bch, struct isar_ch, bch);
  1425. int ret = -EINVAL;
  1426. struct mISDNhead *hh = mISDN_HEAD_P(skb);
  1427. u32 id, *val;
  1428. u_long flags;
  1429. switch (hh->prim) {
  1430. case PH_DATA_REQ:
  1431. spin_lock_irqsave(ich->is->hwlock, flags);
  1432. ret = bchannel_senddata(bch, skb);
  1433. if (ret > 0) { /* direct TX */
  1434. id = hh->id; /* skb can be freed */
  1435. ret = 0;
  1436. isar_fill_fifo(ich);
  1437. spin_unlock_irqrestore(ich->is->hwlock, flags);
  1438. if (!test_bit(FLG_TRANSPARENT, &bch->Flags))
  1439. queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
  1440. } else
  1441. spin_unlock_irqrestore(ich->is->hwlock, flags);
  1442. return ret;
  1443. case PH_ACTIVATE_REQ:
  1444. spin_lock_irqsave(ich->is->hwlock, flags);
  1445. if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags))
  1446. ret = modeisar(ich, ch->protocol);
  1447. else
  1448. ret = 0;
  1449. spin_unlock_irqrestore(ich->is->hwlock, flags);
  1450. if (!ret)
  1451. _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0,
  1452. NULL, GFP_KERNEL);
  1453. break;
  1454. case PH_DEACTIVATE_REQ:
  1455. spin_lock_irqsave(ich->is->hwlock, flags);
  1456. mISDN_clear_bchannel(bch);
  1457. modeisar(ich, ISDN_P_NONE);
  1458. spin_unlock_irqrestore(ich->is->hwlock, flags);
  1459. _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,
  1460. NULL, GFP_KERNEL);
  1461. ret = 0;
  1462. break;
  1463. case PH_CONTROL_REQ:
  1464. val = (u32 *)skb->data;
  1465. pr_debug("%s: PH_CONTROL | REQUEST %x/%x\n", ich->is->name,
  1466. hh->id, *val);
  1467. if ((hh->id == 0) && ((*val & ~DTMF_TONE_MASK) ==
  1468. DTMF_TONE_VAL)) {
  1469. if (bch->state == ISDN_P_B_L2DTMF) {
  1470. char tt = *val & DTMF_TONE_MASK;
  1471. if (tt == '*')
  1472. tt = 0x1e;
  1473. else if (tt == '#')
  1474. tt = 0x1f;
  1475. else if (tt > '9')
  1476. tt -= 7;
  1477. tt &= 0x1f;
  1478. spin_lock_irqsave(ich->is->hwlock, flags);
  1479. isar_pump_cmd(ich, PCTRL_CMD_TDTMF, tt);
  1480. spin_unlock_irqrestore(ich->is->hwlock, flags);
  1481. } else {
  1482. pr_info("%s: DTMF send wrong protocol %x\n",
  1483. __func__, bch->state);
  1484. return -EINVAL;
  1485. }
  1486. } else if ((hh->id == HW_MOD_FRM) || (hh->id == HW_MOD_FRH) ||
  1487. (hh->id == HW_MOD_FTM) || (hh->id == HW_MOD_FTH)) {
  1488. for (id = 0; id < FAXMODCNT; id++)
  1489. if (faxmodulation[id] == *val)
  1490. break;
  1491. if ((FAXMODCNT > id) &&
  1492. test_bit(FLG_INITIALIZED, &bch->Flags)) {
  1493. pr_debug("%s: isar: new mod\n", ich->is->name);
  1494. isar_pump_cmd(ich, hh->id, *val);
  1495. ret = 0;
  1496. } else {
  1497. pr_info("%s: wrong modulation\n",
  1498. ich->is->name);
  1499. ret = -EINVAL;
  1500. }
  1501. } else if (hh->id == HW_MOD_LASTDATA)
  1502. test_and_set_bit(FLG_DLEETX, &bch->Flags);
  1503. else {
  1504. pr_info("%s: unknown PH_CONTROL_REQ %x\n",
  1505. ich->is->name, hh->id);
  1506. ret = -EINVAL;
  1507. }
  1508. default:
  1509. pr_info("%s: %s unknown prim(%x,%x)\n",
  1510. ich->is->name, __func__, hh->prim, hh->id);
  1511. ret = -EINVAL;
  1512. }
  1513. if (!ret)
  1514. dev_kfree_skb(skb);
  1515. return ret;
  1516. }
  1517. static int
  1518. channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
  1519. {
  1520. int ret = 0;
  1521. switch (cq->op) {
  1522. case MISDN_CTRL_GETOP:
  1523. cq->op = 0;
  1524. break;
  1525. /* Nothing implemented yet */
  1526. case MISDN_CTRL_FILL_EMPTY:
  1527. default:
  1528. pr_info("%s: unknown Op %x\n", __func__, cq->op);
  1529. ret = -EINVAL;
  1530. break;
  1531. }
  1532. return ret;
  1533. }
  1534. static int
  1535. isar_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
  1536. {
  1537. struct bchannel *bch = container_of(ch, struct bchannel, ch);
  1538. struct isar_ch *ich = container_of(bch, struct isar_ch, bch);
  1539. int ret = -EINVAL;
  1540. u_long flags;
  1541. pr_debug("%s: %s cmd:%x %p\n", ich->is->name, __func__, cmd, arg);
  1542. switch (cmd) {
  1543. case CLOSE_CHANNEL:
  1544. test_and_clear_bit(FLG_OPEN, &bch->Flags);
  1545. if (test_bit(FLG_ACTIVE, &bch->Flags)) {
  1546. spin_lock_irqsave(ich->is->hwlock, flags);
  1547. mISDN_freebchannel(bch);
  1548. modeisar(ich, ISDN_P_NONE);
  1549. spin_unlock_irqrestore(ich->is->hwlock, flags);
  1550. } else {
  1551. skb_queue_purge(&bch->rqueue);
  1552. bch->rcount = 0;
  1553. }
  1554. ch->protocol = ISDN_P_NONE;
  1555. ch->peer = NULL;
  1556. module_put(ich->is->owner);
  1557. ret = 0;
  1558. break;
  1559. case CONTROL_CHANNEL:
  1560. ret = channel_bctrl(bch, arg);
  1561. break;
  1562. default:
  1563. pr_info("%s: %s unknown prim(%x)\n",
  1564. ich->is->name, __func__, cmd);
  1565. }
  1566. return ret;
  1567. }
  1568. static void
  1569. free_isar(struct isar_hw *isar)
  1570. {
  1571. modeisar(&isar->ch[0], ISDN_P_NONE);
  1572. modeisar(&isar->ch[1], ISDN_P_NONE);
  1573. del_timer(&isar->ch[0].ftimer);
  1574. del_timer(&isar->ch[1].ftimer);
  1575. test_and_clear_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags);
  1576. test_and_clear_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags);
  1577. }
  1578. static int
  1579. init_isar(struct isar_hw *isar)
  1580. {
  1581. int cnt = 3;
  1582. while (cnt--) {
  1583. isar->version = ISARVersion(isar);
  1584. if (isar->ch[0].bch.debug & DEBUG_HW)
  1585. pr_notice("%s: Testing version %d (%d time)\n",
  1586. isar->name, isar->version, 3 - cnt);
  1587. if (isar->version == 1)
  1588. break;
  1589. isar->ctrl(isar->hw, HW_RESET_REQ, 0);
  1590. }
  1591. if (isar->version != 1)
  1592. return -EINVAL;
  1593. isar->ch[0].ftimer.function = &ftimer_handler;
  1594. isar->ch[0].ftimer.data = (long)&isar->ch[0];
  1595. init_timer(&isar->ch[0].ftimer);
  1596. test_and_set_bit(FLG_INITIALIZED, &isar->ch[0].bch.Flags);
  1597. isar->ch[1].ftimer.function = &ftimer_handler;
  1598. isar->ch[1].ftimer.data = (long)&isar->ch[1];
  1599. init_timer(&isar->ch[1].ftimer);
  1600. test_and_set_bit(FLG_INITIALIZED, &isar->ch[1].bch.Flags);
  1601. return 0;
  1602. }
  1603. static int
  1604. isar_open(struct isar_hw *isar, struct channel_req *rq)
  1605. {
  1606. struct bchannel *bch;
  1607. if (rq->adr.channel == 0 || rq->adr.channel > 2)
  1608. return -EINVAL;
  1609. if (rq->protocol == ISDN_P_NONE)
  1610. return -EINVAL;
  1611. bch = &isar->ch[rq->adr.channel - 1].bch;
  1612. if (test_and_set_bit(FLG_OPEN, &bch->Flags))
  1613. return -EBUSY; /* b-channel can be only open once */
  1614. test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags);
  1615. bch->ch.protocol = rq->protocol;
  1616. rq->ch = &bch->ch;
  1617. return 0;
  1618. }
  1619. u32
  1620. mISDNisar_init(struct isar_hw *isar, void *hw)
  1621. {
  1622. u32 ret, i;
  1623. isar->hw = hw;
  1624. for (i = 0; i < 2; i++) {
  1625. isar->ch[i].bch.nr = i + 1;
  1626. mISDN_initbchannel(&isar->ch[i].bch, MAX_DATA_MEM);
  1627. isar->ch[i].bch.ch.nr = i + 1;
  1628. isar->ch[i].bch.ch.send = &isar_l2l1;
  1629. isar->ch[i].bch.ch.ctrl = isar_bctrl;
  1630. isar->ch[i].bch.hw = hw;
  1631. isar->ch[i].is = isar;
  1632. }
  1633. isar->init = &init_isar;
  1634. isar->release = &free_isar;
  1635. isar->firmware = &load_firmware;
  1636. isar->open = &isar_open;
  1637. ret = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
  1638. (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK)) |
  1639. (1 << (ISDN_P_B_L2DTMF & ISDN_P_B_MASK)) |
  1640. (1 << (ISDN_P_B_MODEM_ASYNC & ISDN_P_B_MASK)) |
  1641. (1 << (ISDN_P_B_T30_FAX & ISDN_P_B_MASK));
  1642. return ret;
  1643. }
  1644. EXPORT_SYMBOL(mISDNisar_init);
  1645. static int __init isar_mod_init(void)
  1646. {
  1647. pr_notice("mISDN: ISAR driver Rev. %s\n", ISAR_REV);
  1648. return 0;
  1649. }
  1650. static void __exit isar_mod_cleanup(void)
  1651. {
  1652. pr_notice("mISDN: ISAR module unloaded\n");
  1653. }
  1654. module_init(isar_mod_init);
  1655. module_exit(isar_mod_cleanup);