mISDNipac.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  1. /*
  2. * isac.c ISAC specific routines
  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. #include <linux/slab.h>
  23. #include <linux/module.h>
  24. #include <linux/mISDNhw.h>
  25. #include "ipac.h"
  26. #define DBUSY_TIMER_VALUE 80
  27. #define ARCOFI_USE 1
  28. #define ISAC_REV "2.0"
  29. MODULE_AUTHOR("Karsten Keil");
  30. MODULE_VERSION(ISAC_REV);
  31. MODULE_LICENSE("GPL v2");
  32. #define ReadISAC(is, o) (is->read_reg(is->dch.hw, o + is->off))
  33. #define WriteISAC(is, o, v) (is->write_reg(is->dch.hw, o + is->off, v))
  34. #define ReadHSCX(h, o) (h->ip->read_reg(h->ip->hw, h->off + o))
  35. #define WriteHSCX(h, o, v) (h->ip->write_reg(h->ip->hw, h->off + o, v))
  36. #define ReadIPAC(ip, o) (ip->read_reg(ip->hw, o))
  37. #define WriteIPAC(ip, o, v) (ip->write_reg(ip->hw, o, v))
  38. static inline void
  39. ph_command(struct isac_hw *isac, u8 command)
  40. {
  41. pr_debug("%s: ph_command %x\n", isac->name, command);
  42. if (isac->type & IPAC_TYPE_ISACX)
  43. WriteISAC(isac, ISACX_CIX0, (command << 4) | 0xE);
  44. else
  45. WriteISAC(isac, ISAC_CIX0, (command << 2) | 3);
  46. }
  47. static void
  48. isac_ph_state_change(struct isac_hw *isac)
  49. {
  50. switch (isac->state) {
  51. case (ISAC_IND_RS):
  52. case (ISAC_IND_EI):
  53. ph_command(isac, ISAC_CMD_DUI);
  54. }
  55. schedule_event(&isac->dch, FLG_PHCHANGE);
  56. }
  57. static void
  58. isac_ph_state_bh(struct dchannel *dch)
  59. {
  60. struct isac_hw *isac = container_of(dch, struct isac_hw, dch);
  61. switch (isac->state) {
  62. case ISAC_IND_RS:
  63. case ISAC_IND_EI:
  64. dch->state = 0;
  65. l1_event(dch->l1, HW_RESET_IND);
  66. break;
  67. case ISAC_IND_DID:
  68. dch->state = 3;
  69. l1_event(dch->l1, HW_DEACT_CNF);
  70. break;
  71. case ISAC_IND_DR:
  72. dch->state = 3;
  73. l1_event(dch->l1, HW_DEACT_IND);
  74. break;
  75. case ISAC_IND_PU:
  76. dch->state = 4;
  77. l1_event(dch->l1, HW_POWERUP_IND);
  78. break;
  79. case ISAC_IND_RSY:
  80. if (dch->state <= 5) {
  81. dch->state = 5;
  82. l1_event(dch->l1, ANYSIGNAL);
  83. } else {
  84. dch->state = 8;
  85. l1_event(dch->l1, LOSTFRAMING);
  86. }
  87. break;
  88. case ISAC_IND_ARD:
  89. dch->state = 6;
  90. l1_event(dch->l1, INFO2);
  91. break;
  92. case ISAC_IND_AI8:
  93. dch->state = 7;
  94. l1_event(dch->l1, INFO4_P8);
  95. break;
  96. case ISAC_IND_AI10:
  97. dch->state = 7;
  98. l1_event(dch->l1, INFO4_P10);
  99. break;
  100. }
  101. pr_debug("%s: TE newstate %x\n", isac->name, dch->state);
  102. }
  103. void
  104. isac_empty_fifo(struct isac_hw *isac, int count)
  105. {
  106. u8 *ptr;
  107. pr_debug("%s: %s %d\n", isac->name, __func__, count);
  108. if (!isac->dch.rx_skb) {
  109. isac->dch.rx_skb = mI_alloc_skb(isac->dch.maxlen, GFP_ATOMIC);
  110. if (!isac->dch.rx_skb) {
  111. pr_info("%s: D receive out of memory\n", isac->name);
  112. WriteISAC(isac, ISAC_CMDR, 0x80);
  113. return;
  114. }
  115. }
  116. if ((isac->dch.rx_skb->len + count) >= isac->dch.maxlen) {
  117. pr_debug("%s: %s overrun %d\n", isac->name, __func__,
  118. isac->dch.rx_skb->len + count);
  119. WriteISAC(isac, ISAC_CMDR, 0x80);
  120. return;
  121. }
  122. ptr = skb_put(isac->dch.rx_skb, count);
  123. isac->read_fifo(isac->dch.hw, isac->off, ptr, count);
  124. WriteISAC(isac, ISAC_CMDR, 0x80);
  125. if (isac->dch.debug & DEBUG_HW_DFIFO) {
  126. char pfx[MISDN_MAX_IDLEN + 16];
  127. snprintf(pfx, MISDN_MAX_IDLEN + 15, "D-recv %s %d ",
  128. isac->name, count);
  129. print_hex_dump_bytes(pfx, DUMP_PREFIX_OFFSET, ptr, count);
  130. }
  131. }
  132. static void
  133. isac_fill_fifo(struct isac_hw *isac)
  134. {
  135. int count, more;
  136. u8 *ptr;
  137. if (!isac->dch.tx_skb)
  138. return;
  139. count = isac->dch.tx_skb->len - isac->dch.tx_idx;
  140. if (count <= 0)
  141. return;
  142. more = 0;
  143. if (count > 32) {
  144. more = !0;
  145. count = 32;
  146. }
  147. pr_debug("%s: %s %d\n", isac->name, __func__, count);
  148. ptr = isac->dch.tx_skb->data + isac->dch.tx_idx;
  149. isac->dch.tx_idx += count;
  150. isac->write_fifo(isac->dch.hw, isac->off, ptr, count);
  151. WriteISAC(isac, ISAC_CMDR, more ? 0x8 : 0xa);
  152. if (test_and_set_bit(FLG_BUSY_TIMER, &isac->dch.Flags)) {
  153. pr_debug("%s: %s dbusytimer running\n", isac->name, __func__);
  154. del_timer(&isac->dch.timer);
  155. }
  156. init_timer(&isac->dch.timer);
  157. isac->dch.timer.expires = jiffies + ((DBUSY_TIMER_VALUE * HZ)/1000);
  158. add_timer(&isac->dch.timer);
  159. if (isac->dch.debug & DEBUG_HW_DFIFO) {
  160. char pfx[MISDN_MAX_IDLEN + 16];
  161. snprintf(pfx, MISDN_MAX_IDLEN + 15, "D-send %s %d ",
  162. isac->name, count);
  163. print_hex_dump_bytes(pfx, DUMP_PREFIX_OFFSET, ptr, count);
  164. }
  165. }
  166. static void
  167. isac_rme_irq(struct isac_hw *isac)
  168. {
  169. u8 val, count;
  170. val = ReadISAC(isac, ISAC_RSTA);
  171. if ((val & 0x70) != 0x20) {
  172. if (val & 0x40) {
  173. pr_debug("%s: ISAC RDO\n", isac->name);
  174. #ifdef ERROR_STATISTIC
  175. isac->dch.err_rx++;
  176. #endif
  177. }
  178. if (!(val & 0x20)) {
  179. pr_debug("%s: ISAC CRC error\n", isac->name);
  180. #ifdef ERROR_STATISTIC
  181. isac->dch.err_crc++;
  182. #endif
  183. }
  184. WriteISAC(isac, ISAC_CMDR, 0x80);
  185. if (isac->dch.rx_skb)
  186. dev_kfree_skb(isac->dch.rx_skb);
  187. isac->dch.rx_skb = NULL;
  188. } else {
  189. count = ReadISAC(isac, ISAC_RBCL) & 0x1f;
  190. if (count == 0)
  191. count = 32;
  192. isac_empty_fifo(isac, count);
  193. recv_Dchannel(&isac->dch);
  194. }
  195. }
  196. static void
  197. isac_xpr_irq(struct isac_hw *isac)
  198. {
  199. if (test_and_clear_bit(FLG_BUSY_TIMER, &isac->dch.Flags))
  200. del_timer(&isac->dch.timer);
  201. if (isac->dch.tx_skb && isac->dch.tx_idx < isac->dch.tx_skb->len) {
  202. isac_fill_fifo(isac);
  203. } else {
  204. if (isac->dch.tx_skb)
  205. dev_kfree_skb(isac->dch.tx_skb);
  206. if (get_next_dframe(&isac->dch))
  207. isac_fill_fifo(isac);
  208. }
  209. }
  210. static void
  211. isac_retransmit(struct isac_hw *isac)
  212. {
  213. if (test_and_clear_bit(FLG_BUSY_TIMER, &isac->dch.Flags))
  214. del_timer(&isac->dch.timer);
  215. if (test_bit(FLG_TX_BUSY, &isac->dch.Flags)) {
  216. /* Restart frame */
  217. isac->dch.tx_idx = 0;
  218. isac_fill_fifo(isac);
  219. } else if (isac->dch.tx_skb) { /* should not happen */
  220. pr_info("%s: tx_skb exist but not busy\n", isac->name);
  221. test_and_set_bit(FLG_TX_BUSY, &isac->dch.Flags);
  222. isac->dch.tx_idx = 0;
  223. isac_fill_fifo(isac);
  224. } else {
  225. pr_info("%s: ISAC XDU no TX_BUSY\n", isac->name);
  226. if (get_next_dframe(&isac->dch))
  227. isac_fill_fifo(isac);
  228. }
  229. }
  230. static void
  231. isac_mos_irq(struct isac_hw *isac)
  232. {
  233. u8 val;
  234. int ret;
  235. val = ReadISAC(isac, ISAC_MOSR);
  236. pr_debug("%s: ISAC MOSR %02x\n", isac->name, val);
  237. #if ARCOFI_USE
  238. if (val & 0x08) {
  239. if (!isac->mon_rx) {
  240. isac->mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
  241. if (!isac->mon_rx) {
  242. pr_info("%s: ISAC MON RX out of memory!\n",
  243. isac->name);
  244. isac->mocr &= 0xf0;
  245. isac->mocr |= 0x0a;
  246. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  247. goto afterMONR0;
  248. } else
  249. isac->mon_rxp = 0;
  250. }
  251. if (isac->mon_rxp >= MAX_MON_FRAME) {
  252. isac->mocr &= 0xf0;
  253. isac->mocr |= 0x0a;
  254. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  255. isac->mon_rxp = 0;
  256. pr_debug("%s: ISAC MON RX overflow!\n", isac->name);
  257. goto afterMONR0;
  258. }
  259. isac->mon_rx[isac->mon_rxp++] = ReadISAC(isac, ISAC_MOR0);
  260. pr_debug("%s: ISAC MOR0 %02x\n", isac->name,
  261. isac->mon_rx[isac->mon_rxp - 1]);
  262. if (isac->mon_rxp == 1) {
  263. isac->mocr |= 0x04;
  264. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  265. }
  266. }
  267. afterMONR0:
  268. if (val & 0x80) {
  269. if (!isac->mon_rx) {
  270. isac->mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC);
  271. if (!isac->mon_rx) {
  272. pr_info("%s: ISAC MON RX out of memory!\n",
  273. isac->name);
  274. isac->mocr &= 0x0f;
  275. isac->mocr |= 0xa0;
  276. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  277. goto afterMONR1;
  278. } else
  279. isac->mon_rxp = 0;
  280. }
  281. if (isac->mon_rxp >= MAX_MON_FRAME) {
  282. isac->mocr &= 0x0f;
  283. isac->mocr |= 0xa0;
  284. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  285. isac->mon_rxp = 0;
  286. pr_debug("%s: ISAC MON RX overflow!\n", isac->name);
  287. goto afterMONR1;
  288. }
  289. isac->mon_rx[isac->mon_rxp++] = ReadISAC(isac, ISAC_MOR1);
  290. pr_debug("%s: ISAC MOR1 %02x\n", isac->name,
  291. isac->mon_rx[isac->mon_rxp - 1]);
  292. isac->mocr |= 0x40;
  293. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  294. }
  295. afterMONR1:
  296. if (val & 0x04) {
  297. isac->mocr &= 0xf0;
  298. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  299. isac->mocr |= 0x0a;
  300. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  301. if (isac->monitor) {
  302. ret = isac->monitor(isac->dch.hw, MONITOR_RX_0,
  303. isac->mon_rx, isac->mon_rxp);
  304. if (ret)
  305. kfree(isac->mon_rx);
  306. } else {
  307. pr_info("%s: MONITOR 0 received %d but no user\n",
  308. isac->name, isac->mon_rxp);
  309. kfree(isac->mon_rx);
  310. }
  311. isac->mon_rx = NULL;
  312. isac->mon_rxp = 0;
  313. }
  314. if (val & 0x40) {
  315. isac->mocr &= 0x0f;
  316. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  317. isac->mocr |= 0xa0;
  318. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  319. if (isac->monitor) {
  320. ret = isac->monitor(isac->dch.hw, MONITOR_RX_1,
  321. isac->mon_rx, isac->mon_rxp);
  322. if (ret)
  323. kfree(isac->mon_rx);
  324. } else {
  325. pr_info("%s: MONITOR 1 received %d but no user\n",
  326. isac->name, isac->mon_rxp);
  327. kfree(isac->mon_rx);
  328. }
  329. isac->mon_rx = NULL;
  330. isac->mon_rxp = 0;
  331. }
  332. if (val & 0x02) {
  333. if ((!isac->mon_tx) || (isac->mon_txc &&
  334. (isac->mon_txp >= isac->mon_txc) && !(val & 0x08))) {
  335. isac->mocr &= 0xf0;
  336. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  337. isac->mocr |= 0x0a;
  338. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  339. if (isac->mon_txc && (isac->mon_txp >= isac->mon_txc)) {
  340. if (isac->monitor)
  341. ret = isac->monitor(isac->dch.hw,
  342. MONITOR_TX_0, NULL, 0);
  343. }
  344. kfree(isac->mon_tx);
  345. isac->mon_tx = NULL;
  346. isac->mon_txc = 0;
  347. isac->mon_txp = 0;
  348. goto AfterMOX0;
  349. }
  350. if (isac->mon_txc && (isac->mon_txp >= isac->mon_txc)) {
  351. if (isac->monitor)
  352. ret = isac->monitor(isac->dch.hw,
  353. MONITOR_TX_0, NULL, 0);
  354. kfree(isac->mon_tx);
  355. isac->mon_tx = NULL;
  356. isac->mon_txc = 0;
  357. isac->mon_txp = 0;
  358. goto AfterMOX0;
  359. }
  360. WriteISAC(isac, ISAC_MOX0, isac->mon_tx[isac->mon_txp++]);
  361. pr_debug("%s: ISAC %02x -> MOX0\n", isac->name,
  362. isac->mon_tx[isac->mon_txp - 1]);
  363. }
  364. AfterMOX0:
  365. if (val & 0x20) {
  366. if ((!isac->mon_tx) || (isac->mon_txc &&
  367. (isac->mon_txp >= isac->mon_txc) && !(val & 0x80))) {
  368. isac->mocr &= 0x0f;
  369. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  370. isac->mocr |= 0xa0;
  371. WriteISAC(isac, ISAC_MOCR, isac->mocr);
  372. if (isac->mon_txc && (isac->mon_txp >= isac->mon_txc)) {
  373. if (isac->monitor)
  374. ret = isac->monitor(isac->dch.hw,
  375. MONITOR_TX_1, NULL, 0);
  376. }
  377. kfree(isac->mon_tx);
  378. isac->mon_tx = NULL;
  379. isac->mon_txc = 0;
  380. isac->mon_txp = 0;
  381. goto AfterMOX1;
  382. }
  383. if (isac->mon_txc && (isac->mon_txp >= isac->mon_txc)) {
  384. if (isac->monitor)
  385. ret = isac->monitor(isac->dch.hw,
  386. MONITOR_TX_1, NULL, 0);
  387. kfree(isac->mon_tx);
  388. isac->mon_tx = NULL;
  389. isac->mon_txc = 0;
  390. isac->mon_txp = 0;
  391. goto AfterMOX1;
  392. }
  393. WriteISAC(isac, ISAC_MOX1, isac->mon_tx[isac->mon_txp++]);
  394. pr_debug("%s: ISAC %02x -> MOX1\n", isac->name,
  395. isac->mon_tx[isac->mon_txp - 1]);
  396. }
  397. AfterMOX1:
  398. val = 0; /* dummy to avoid warning */
  399. #endif
  400. }
  401. static void
  402. isac_cisq_irq(struct isac_hw *isac) {
  403. u8 val;
  404. val = ReadISAC(isac, ISAC_CIR0);
  405. pr_debug("%s: ISAC CIR0 %02X\n", isac->name, val);
  406. if (val & 2) {
  407. pr_debug("%s: ph_state change %x->%x\n", isac->name,
  408. isac->state, (val >> 2) & 0xf);
  409. isac->state = (val >> 2) & 0xf;
  410. isac_ph_state_change(isac);
  411. }
  412. if (val & 1) {
  413. val = ReadISAC(isac, ISAC_CIR1);
  414. pr_debug("%s: ISAC CIR1 %02X\n", isac->name, val);
  415. }
  416. }
  417. static void
  418. isacsx_cic_irq(struct isac_hw *isac)
  419. {
  420. u8 val;
  421. val = ReadISAC(isac, ISACX_CIR0);
  422. pr_debug("%s: ISACX CIR0 %02X\n", isac->name, val);
  423. if (val & ISACX_CIR0_CIC0) {
  424. pr_debug("%s: ph_state change %x->%x\n", isac->name,
  425. isac->state, val >> 4);
  426. isac->state = val >> 4;
  427. isac_ph_state_change(isac);
  428. }
  429. }
  430. static void
  431. isacsx_rme_irq(struct isac_hw *isac)
  432. {
  433. int count;
  434. u8 val;
  435. val = ReadISAC(isac, ISACX_RSTAD);
  436. if ((val & (ISACX_RSTAD_VFR |
  437. ISACX_RSTAD_RDO |
  438. ISACX_RSTAD_CRC |
  439. ISACX_RSTAD_RAB))
  440. != (ISACX_RSTAD_VFR | ISACX_RSTAD_CRC)) {
  441. pr_debug("%s: RSTAD %#x, dropped\n", isac->name, val);
  442. #ifdef ERROR_STATISTIC
  443. if (val & ISACX_RSTAD_CRC)
  444. isac->dch.err_rx++;
  445. else
  446. isac->dch.err_crc++;
  447. #endif
  448. WriteISAC(isac, ISACX_CMDRD, ISACX_CMDRD_RMC);
  449. if (isac->dch.rx_skb)
  450. dev_kfree_skb(isac->dch.rx_skb);
  451. isac->dch.rx_skb = NULL;
  452. } else {
  453. count = ReadISAC(isac, ISACX_RBCLD) & 0x1f;
  454. if (count == 0)
  455. count = 32;
  456. isac_empty_fifo(isac, count);
  457. if (isac->dch.rx_skb) {
  458. skb_trim(isac->dch.rx_skb, isac->dch.rx_skb->len - 1);
  459. pr_debug("%s: dchannel received %d\n", isac->name,
  460. isac->dch.rx_skb->len);
  461. recv_Dchannel(&isac->dch);
  462. }
  463. }
  464. }
  465. irqreturn_t
  466. mISDNisac_irq(struct isac_hw *isac, u8 val)
  467. {
  468. if (unlikely(!val))
  469. return IRQ_NONE;
  470. pr_debug("%s: ISAC interrupt %02x\n", isac->name, val);
  471. if (isac->type & IPAC_TYPE_ISACX) {
  472. if (val & ISACX__CIC)
  473. isacsx_cic_irq(isac);
  474. if (val & ISACX__ICD) {
  475. val = ReadISAC(isac, ISACX_ISTAD);
  476. pr_debug("%s: ISTAD %02x\n", isac->name, val);
  477. if (val & ISACX_D_XDU) {
  478. pr_debug("%s: ISAC XDU\n", isac->name);
  479. #ifdef ERROR_STATISTIC
  480. isac->dch.err_tx++;
  481. #endif
  482. isac_retransmit(isac);
  483. }
  484. if (val & ISACX_D_XMR) {
  485. pr_debug("%s: ISAC XMR\n", isac->name);
  486. #ifdef ERROR_STATISTIC
  487. isac->dch.err_tx++;
  488. #endif
  489. isac_retransmit(isac);
  490. }
  491. if (val & ISACX_D_XPR)
  492. isac_xpr_irq(isac);
  493. if (val & ISACX_D_RFO) {
  494. pr_debug("%s: ISAC RFO\n", isac->name);
  495. WriteISAC(isac, ISACX_CMDRD, ISACX_CMDRD_RMC);
  496. }
  497. if (val & ISACX_D_RME)
  498. isacsx_rme_irq(isac);
  499. if (val & ISACX_D_RPF)
  500. isac_empty_fifo(isac, 0x20);
  501. }
  502. } else {
  503. if (val & 0x80) /* RME */
  504. isac_rme_irq(isac);
  505. if (val & 0x40) /* RPF */
  506. isac_empty_fifo(isac, 32);
  507. if (val & 0x10) /* XPR */
  508. isac_xpr_irq(isac);
  509. if (val & 0x04) /* CISQ */
  510. isac_cisq_irq(isac);
  511. if (val & 0x20) /* RSC - never */
  512. pr_debug("%s: ISAC RSC interrupt\n", isac->name);
  513. if (val & 0x02) /* SIN - never */
  514. pr_debug("%s: ISAC SIN interrupt\n", isac->name);
  515. if (val & 0x01) { /* EXI */
  516. val = ReadISAC(isac, ISAC_EXIR);
  517. pr_debug("%s: ISAC EXIR %02x\n", isac->name, val);
  518. if (val & 0x80) /* XMR */
  519. pr_debug("%s: ISAC XMR\n", isac->name);
  520. if (val & 0x40) { /* XDU */
  521. pr_debug("%s: ISAC XDU\n", isac->name);
  522. #ifdef ERROR_STATISTIC
  523. isac->dch.err_tx++;
  524. #endif
  525. isac_retransmit(isac);
  526. }
  527. if (val & 0x04) /* MOS */
  528. isac_mos_irq(isac);
  529. }
  530. }
  531. return IRQ_HANDLED;
  532. }
  533. EXPORT_SYMBOL(mISDNisac_irq);
  534. static int
  535. isac_l1hw(struct mISDNchannel *ch, struct sk_buff *skb)
  536. {
  537. struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
  538. struct dchannel *dch = container_of(dev, struct dchannel, dev);
  539. struct isac_hw *isac = container_of(dch, struct isac_hw, dch);
  540. int ret = -EINVAL;
  541. struct mISDNhead *hh = mISDN_HEAD_P(skb);
  542. u32 id;
  543. u_long flags;
  544. switch (hh->prim) {
  545. case PH_DATA_REQ:
  546. spin_lock_irqsave(isac->hwlock, flags);
  547. ret = dchannel_senddata(dch, skb);
  548. if (ret > 0) { /* direct TX */
  549. id = hh->id; /* skb can be freed */
  550. isac_fill_fifo(isac);
  551. ret = 0;
  552. spin_unlock_irqrestore(isac->hwlock, flags);
  553. queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
  554. } else
  555. spin_unlock_irqrestore(isac->hwlock, flags);
  556. return ret;
  557. case PH_ACTIVATE_REQ:
  558. ret = l1_event(dch->l1, hh->prim);
  559. break;
  560. case PH_DEACTIVATE_REQ:
  561. test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
  562. ret = l1_event(dch->l1, hh->prim);
  563. break;
  564. }
  565. if (!ret)
  566. dev_kfree_skb(skb);
  567. return ret;
  568. }
  569. static int
  570. isac_ctrl(struct isac_hw *isac, u32 cmd, u_long para)
  571. {
  572. u8 tl = 0;
  573. u_long flags;
  574. switch (cmd) {
  575. case HW_TESTLOOP:
  576. spin_lock_irqsave(isac->hwlock, flags);
  577. if (!(isac->type & IPAC_TYPE_ISACX)) {
  578. /* TODO: implement for IPAC_TYPE_ISACX */
  579. if (para & 1) /* B1 */
  580. tl |= 0x0c;
  581. else if (para & 2) /* B2 */
  582. tl |= 0x3;
  583. /* we only support IOM2 mode */
  584. WriteISAC(isac, ISAC_SPCR, tl);
  585. if (tl)
  586. WriteISAC(isac, ISAC_ADF1, 0x8);
  587. else
  588. WriteISAC(isac, ISAC_ADF1, 0x0);
  589. }
  590. spin_unlock_irqrestore(isac->hwlock, flags);
  591. break;
  592. default:
  593. pr_debug("%s: %s unknown command %x %lx\n", isac->name,
  594. __func__, cmd, para);
  595. return -1;
  596. }
  597. return 0;
  598. }
  599. static int
  600. isac_l1cmd(struct dchannel *dch, u32 cmd)
  601. {
  602. struct isac_hw *isac = container_of(dch, struct isac_hw, dch);
  603. u_long flags;
  604. pr_debug("%s: cmd(%x) state(%02x)\n", isac->name, cmd, isac->state);
  605. switch (cmd) {
  606. case INFO3_P8:
  607. spin_lock_irqsave(isac->hwlock, flags);
  608. ph_command(isac, ISAC_CMD_AR8);
  609. spin_unlock_irqrestore(isac->hwlock, flags);
  610. break;
  611. case INFO3_P10:
  612. spin_lock_irqsave(isac->hwlock, flags);
  613. ph_command(isac, ISAC_CMD_AR10);
  614. spin_unlock_irqrestore(isac->hwlock, flags);
  615. break;
  616. case HW_RESET_REQ:
  617. spin_lock_irqsave(isac->hwlock, flags);
  618. if ((isac->state == ISAC_IND_EI) ||
  619. (isac->state == ISAC_IND_DR) ||
  620. (isac->state == ISAC_IND_RS))
  621. ph_command(isac, ISAC_CMD_TIM);
  622. else
  623. ph_command(isac, ISAC_CMD_RS);
  624. spin_unlock_irqrestore(isac->hwlock, flags);
  625. break;
  626. case HW_DEACT_REQ:
  627. skb_queue_purge(&dch->squeue);
  628. if (dch->tx_skb) {
  629. dev_kfree_skb(dch->tx_skb);
  630. dch->tx_skb = NULL;
  631. }
  632. dch->tx_idx = 0;
  633. if (dch->rx_skb) {
  634. dev_kfree_skb(dch->rx_skb);
  635. dch->rx_skb = NULL;
  636. }
  637. test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
  638. if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
  639. del_timer(&dch->timer);
  640. break;
  641. case HW_POWERUP_REQ:
  642. spin_lock_irqsave(isac->hwlock, flags);
  643. ph_command(isac, ISAC_CMD_TIM);
  644. spin_unlock_irqrestore(isac->hwlock, flags);
  645. break;
  646. case PH_ACTIVATE_IND:
  647. test_and_set_bit(FLG_ACTIVE, &dch->Flags);
  648. _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
  649. GFP_ATOMIC);
  650. break;
  651. case PH_DEACTIVATE_IND:
  652. test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
  653. _queue_data(&dch->dev.D, cmd, MISDN_ID_ANY, 0, NULL,
  654. GFP_ATOMIC);
  655. break;
  656. default:
  657. pr_debug("%s: %s unknown command %x\n", isac->name,
  658. __func__, cmd);
  659. return -1;
  660. }
  661. return 0;
  662. }
  663. static void
  664. isac_release(struct isac_hw *isac)
  665. {
  666. if (isac->type & IPAC_TYPE_ISACX)
  667. WriteISAC(isac, ISACX_MASK, 0xff);
  668. else
  669. WriteISAC(isac, ISAC_MASK, 0xff);
  670. if (isac->dch.timer.function != NULL) {
  671. del_timer(&isac->dch.timer);
  672. isac->dch.timer.function = NULL;
  673. }
  674. kfree(isac->mon_rx);
  675. isac->mon_rx = NULL;
  676. kfree(isac->mon_tx);
  677. isac->mon_tx = NULL;
  678. if (isac->dch.l1)
  679. l1_event(isac->dch.l1, CLOSE_CHANNEL);
  680. mISDN_freedchannel(&isac->dch);
  681. }
  682. static void
  683. dbusy_timer_handler(struct isac_hw *isac)
  684. {
  685. int rbch, star;
  686. u_long flags;
  687. if (test_bit(FLG_BUSY_TIMER, &isac->dch.Flags)) {
  688. spin_lock_irqsave(isac->hwlock, flags);
  689. rbch = ReadISAC(isac, ISAC_RBCH);
  690. star = ReadISAC(isac, ISAC_STAR);
  691. pr_debug("%s: D-Channel Busy RBCH %02x STAR %02x\n",
  692. isac->name, rbch, star);
  693. if (rbch & ISAC_RBCH_XAC) /* D-Channel Busy */
  694. test_and_set_bit(FLG_L1_BUSY, &isac->dch.Flags);
  695. else {
  696. /* discard frame; reset transceiver */
  697. test_and_clear_bit(FLG_BUSY_TIMER, &isac->dch.Flags);
  698. if (isac->dch.tx_idx)
  699. isac->dch.tx_idx = 0;
  700. else
  701. pr_info("%s: ISAC D-Channel Busy no tx_idx\n",
  702. isac->name);
  703. /* Transmitter reset */
  704. WriteISAC(isac, ISAC_CMDR, 0x01);
  705. }
  706. spin_unlock_irqrestore(isac->hwlock, flags);
  707. }
  708. }
  709. static int
  710. open_dchannel(struct isac_hw *isac, struct channel_req *rq)
  711. {
  712. pr_debug("%s: %s dev(%d) open from %p\n", isac->name, __func__,
  713. isac->dch.dev.id, __builtin_return_address(1));
  714. if (rq->protocol != ISDN_P_TE_S0)
  715. return -EINVAL;
  716. if (rq->adr.channel == 1)
  717. /* E-Channel not supported */
  718. return -EINVAL;
  719. rq->ch = &isac->dch.dev.D;
  720. rq->ch->protocol = rq->protocol;
  721. if (isac->dch.state == 7)
  722. _queue_data(rq->ch, PH_ACTIVATE_IND, MISDN_ID_ANY,
  723. 0, NULL, GFP_KERNEL);
  724. return 0;
  725. }
  726. static const char *ISACVer[] =
  727. {"2086/2186 V1.1", "2085 B1", "2085 B2",
  728. "2085 V2.3"};
  729. static int
  730. isac_init(struct isac_hw *isac)
  731. {
  732. u8 val;
  733. int err = 0;
  734. if (!isac->dch.l1) {
  735. err = create_l1(&isac->dch, isac_l1cmd);
  736. if (err)
  737. return err;
  738. }
  739. isac->mon_tx = NULL;
  740. isac->mon_rx = NULL;
  741. isac->dch.timer.function = (void *) dbusy_timer_handler;
  742. isac->dch.timer.data = (long)isac;
  743. init_timer(&isac->dch.timer);
  744. isac->mocr = 0xaa;
  745. if (isac->type & IPAC_TYPE_ISACX) {
  746. /* Disable all IRQ */
  747. WriteISAC(isac, ISACX_MASK, 0xff);
  748. val = ReadISAC(isac, ISACX_STARD);
  749. pr_debug("%s: ISACX STARD %x\n", isac->name, val);
  750. val = ReadISAC(isac, ISACX_ISTAD);
  751. pr_debug("%s: ISACX ISTAD %x\n", isac->name, val);
  752. val = ReadISAC(isac, ISACX_ISTA);
  753. pr_debug("%s: ISACX ISTA %x\n", isac->name, val);
  754. /* clear LDD */
  755. WriteISAC(isac, ISACX_TR_CONF0, 0x00);
  756. /* enable transmitter */
  757. WriteISAC(isac, ISACX_TR_CONF2, 0x00);
  758. /* transparent mode 0, RAC, stop/go */
  759. WriteISAC(isac, ISACX_MODED, 0xc9);
  760. /* all HDLC IRQ unmasked */
  761. val = ReadISAC(isac, ISACX_ID);
  762. if (isac->dch.debug & DEBUG_HW)
  763. pr_notice("%s: ISACX Design ID %x\n",
  764. isac->name, val & 0x3f);
  765. val = ReadISAC(isac, ISACX_CIR0);
  766. pr_debug("%s: ISACX CIR0 %02X\n", isac->name, val);
  767. isac->state = val >> 4;
  768. isac_ph_state_change(isac);
  769. ph_command(isac, ISAC_CMD_RS);
  770. WriteISAC(isac, ISACX_MASK, IPACX__ON);
  771. WriteISAC(isac, ISACX_MASKD, 0x00);
  772. } else { /* old isac */
  773. WriteISAC(isac, ISAC_MASK, 0xff);
  774. val = ReadISAC(isac, ISAC_STAR);
  775. pr_debug("%s: ISAC STAR %x\n", isac->name, val);
  776. val = ReadISAC(isac, ISAC_MODE);
  777. pr_debug("%s: ISAC MODE %x\n", isac->name, val);
  778. val = ReadISAC(isac, ISAC_ADF2);
  779. pr_debug("%s: ISAC ADF2 %x\n", isac->name, val);
  780. val = ReadISAC(isac, ISAC_ISTA);
  781. pr_debug("%s: ISAC ISTA %x\n", isac->name, val);
  782. if (val & 0x01) {
  783. val = ReadISAC(isac, ISAC_EXIR);
  784. pr_debug("%s: ISAC EXIR %x\n", isac->name, val);
  785. }
  786. val = ReadISAC(isac, ISAC_RBCH);
  787. if (isac->dch.debug & DEBUG_HW)
  788. pr_notice("%s: ISAC version (%x): %s\n", isac->name,
  789. val, ISACVer[(val >> 5) & 3]);
  790. isac->type |= ((val >> 5) & 3);
  791. if (!isac->adf2)
  792. isac->adf2 = 0x80;
  793. if (!(isac->adf2 & 0x80)) { /* only IOM 2 Mode */
  794. pr_info("%s: only support IOM2 mode but adf2=%02x\n",
  795. isac->name, isac->adf2);
  796. isac_release(isac);
  797. return -EINVAL;
  798. }
  799. WriteISAC(isac, ISAC_ADF2, isac->adf2);
  800. WriteISAC(isac, ISAC_SQXR, 0x2f);
  801. WriteISAC(isac, ISAC_SPCR, 0x00);
  802. WriteISAC(isac, ISAC_STCR, 0x70);
  803. WriteISAC(isac, ISAC_MODE, 0xc9);
  804. WriteISAC(isac, ISAC_TIMR, 0x00);
  805. WriteISAC(isac, ISAC_ADF1, 0x00);
  806. val = ReadISAC(isac, ISAC_CIR0);
  807. pr_debug("%s: ISAC CIR0 %x\n", isac->name, val);
  808. isac->state = (val >> 2) & 0xf;
  809. isac_ph_state_change(isac);
  810. ph_command(isac, ISAC_CMD_RS);
  811. WriteISAC(isac, ISAC_MASK, 0);
  812. }
  813. return err;
  814. }
  815. int
  816. mISDNisac_init(struct isac_hw *isac, void *hw)
  817. {
  818. mISDN_initdchannel(&isac->dch, MAX_DFRAME_LEN_L1, isac_ph_state_bh);
  819. isac->dch.hw = hw;
  820. isac->dch.dev.D.send = isac_l1hw;
  821. isac->init = isac_init;
  822. isac->release = isac_release;
  823. isac->ctrl = isac_ctrl;
  824. isac->open = open_dchannel;
  825. isac->dch.dev.Dprotocols = (1 << ISDN_P_TE_S0);
  826. isac->dch.dev.nrbchan = 2;
  827. return 0;
  828. }
  829. EXPORT_SYMBOL(mISDNisac_init);
  830. static void
  831. waitforCEC(struct hscx_hw *hx)
  832. {
  833. u8 starb, to = 50;
  834. while (to) {
  835. starb = ReadHSCX(hx, IPAC_STARB);
  836. if (!(starb & 0x04))
  837. break;
  838. udelay(1);
  839. to--;
  840. }
  841. if (to < 50)
  842. pr_debug("%s: B%1d CEC %d us\n", hx->ip->name, hx->bch.nr,
  843. 50 - to);
  844. if (!to)
  845. pr_info("%s: B%1d CEC timeout\n", hx->ip->name, hx->bch.nr);
  846. }
  847. static void
  848. waitforXFW(struct hscx_hw *hx)
  849. {
  850. u8 starb, to = 50;
  851. while (to) {
  852. starb = ReadHSCX(hx, IPAC_STARB);
  853. if ((starb & 0x44) == 0x40)
  854. break;
  855. udelay(1);
  856. to--;
  857. }
  858. if (to < 50)
  859. pr_debug("%s: B%1d XFW %d us\n", hx->ip->name, hx->bch.nr,
  860. 50 - to);
  861. if (!to)
  862. pr_info("%s: B%1d XFW timeout\n", hx->ip->name, hx->bch.nr);
  863. }
  864. static void
  865. hscx_cmdr(struct hscx_hw *hx, u8 cmd)
  866. {
  867. if (hx->ip->type & IPAC_TYPE_IPACX)
  868. WriteHSCX(hx, IPACX_CMDRB, cmd);
  869. else {
  870. waitforCEC(hx);
  871. WriteHSCX(hx, IPAC_CMDRB, cmd);
  872. }
  873. }
  874. static void
  875. hscx_empty_fifo(struct hscx_hw *hscx, u8 count)
  876. {
  877. u8 *p;
  878. pr_debug("%s: B%1d %d\n", hscx->ip->name, hscx->bch.nr, count);
  879. if (!hscx->bch.rx_skb) {
  880. hscx->bch.rx_skb = mI_alloc_skb(hscx->bch.maxlen, GFP_ATOMIC);
  881. if (!hscx->bch.rx_skb) {
  882. pr_info("%s: B receive out of memory\n",
  883. hscx->ip->name);
  884. hscx_cmdr(hscx, 0x80); /* RMC */
  885. return;
  886. }
  887. }
  888. if ((hscx->bch.rx_skb->len + count) > hscx->bch.maxlen) {
  889. pr_debug("%s: overrun %d\n", hscx->ip->name,
  890. hscx->bch.rx_skb->len + count);
  891. skb_trim(hscx->bch.rx_skb, 0);
  892. hscx_cmdr(hscx, 0x80); /* RMC */
  893. return;
  894. }
  895. p = skb_put(hscx->bch.rx_skb, count);
  896. if (hscx->ip->type & IPAC_TYPE_IPACX)
  897. hscx->ip->read_fifo(hscx->ip->hw,
  898. hscx->off + IPACX_RFIFOB, p, count);
  899. else
  900. hscx->ip->read_fifo(hscx->ip->hw,
  901. hscx->off, p, count);
  902. hscx_cmdr(hscx, 0x80); /* RMC */
  903. if (hscx->bch.debug & DEBUG_HW_BFIFO) {
  904. snprintf(hscx->log, 64, "B%1d-recv %s %d ",
  905. hscx->bch.nr, hscx->ip->name, count);
  906. print_hex_dump_bytes(hscx->log, DUMP_PREFIX_OFFSET, p, count);
  907. }
  908. }
  909. static void
  910. hscx_fill_fifo(struct hscx_hw *hscx)
  911. {
  912. int count, more;
  913. u8 *p;
  914. if (!hscx->bch.tx_skb)
  915. return;
  916. count = hscx->bch.tx_skb->len - hscx->bch.tx_idx;
  917. if (count <= 0)
  918. return;
  919. p = hscx->bch.tx_skb->data + hscx->bch.tx_idx;
  920. more = test_bit(FLG_TRANSPARENT, &hscx->bch.Flags) ? 1 : 0;
  921. if (count > hscx->fifo_size) {
  922. count = hscx->fifo_size;
  923. more = 1;
  924. }
  925. pr_debug("%s: B%1d %d/%d/%d\n", hscx->ip->name, hscx->bch.nr, count,
  926. hscx->bch.tx_idx, hscx->bch.tx_skb->len);
  927. hscx->bch.tx_idx += count;
  928. if (hscx->ip->type & IPAC_TYPE_IPACX)
  929. hscx->ip->write_fifo(hscx->ip->hw,
  930. hscx->off + IPACX_XFIFOB, p, count);
  931. else {
  932. waitforXFW(hscx);
  933. hscx->ip->write_fifo(hscx->ip->hw,
  934. hscx->off, p, count);
  935. }
  936. hscx_cmdr(hscx, more ? 0x08 : 0x0a);
  937. if (hscx->bch.debug & DEBUG_HW_BFIFO) {
  938. snprintf(hscx->log, 64, "B%1d-send %s %d ",
  939. hscx->bch.nr, hscx->ip->name, count);
  940. print_hex_dump_bytes(hscx->log, DUMP_PREFIX_OFFSET, p, count);
  941. }
  942. }
  943. static void
  944. hscx_xpr(struct hscx_hw *hx)
  945. {
  946. if (hx->bch.tx_skb && hx->bch.tx_idx < hx->bch.tx_skb->len)
  947. hscx_fill_fifo(hx);
  948. else {
  949. if (hx->bch.tx_skb) {
  950. /* send confirm, on trans, free on hdlc. */
  951. if (test_bit(FLG_TRANSPARENT, &hx->bch.Flags))
  952. confirm_Bsend(&hx->bch);
  953. dev_kfree_skb(hx->bch.tx_skb);
  954. }
  955. if (get_next_bframe(&hx->bch))
  956. hscx_fill_fifo(hx);
  957. }
  958. }
  959. static void
  960. ipac_rme(struct hscx_hw *hx)
  961. {
  962. int count;
  963. u8 rstab;
  964. if (hx->ip->type & IPAC_TYPE_IPACX)
  965. rstab = ReadHSCX(hx, IPACX_RSTAB);
  966. else
  967. rstab = ReadHSCX(hx, IPAC_RSTAB);
  968. pr_debug("%s: B%1d RSTAB %02x\n", hx->ip->name, hx->bch.nr, rstab);
  969. if ((rstab & 0xf0) != 0xa0) {
  970. /* !(VFR && !RDO && CRC && !RAB) */
  971. if (!(rstab & 0x80)) {
  972. if (hx->bch.debug & DEBUG_HW_BCHANNEL)
  973. pr_notice("%s: B%1d invalid frame\n",
  974. hx->ip->name, hx->bch.nr);
  975. }
  976. if (rstab & 0x40) {
  977. if (hx->bch.debug & DEBUG_HW_BCHANNEL)
  978. pr_notice("%s: B%1d RDO proto=%x\n",
  979. hx->ip->name, hx->bch.nr,
  980. hx->bch.state);
  981. }
  982. if (!(rstab & 0x20)) {
  983. if (hx->bch.debug & DEBUG_HW_BCHANNEL)
  984. pr_notice("%s: B%1d CRC error\n",
  985. hx->ip->name, hx->bch.nr);
  986. }
  987. hscx_cmdr(hx, 0x80); /* Do RMC */
  988. return;
  989. }
  990. if (hx->ip->type & IPAC_TYPE_IPACX)
  991. count = ReadHSCX(hx, IPACX_RBCLB);
  992. else
  993. count = ReadHSCX(hx, IPAC_RBCLB);
  994. count &= (hx->fifo_size - 1);
  995. if (count == 0)
  996. count = hx->fifo_size;
  997. hscx_empty_fifo(hx, count);
  998. if (!hx->bch.rx_skb)
  999. return;
  1000. if (hx->bch.rx_skb->len < 2) {
  1001. pr_debug("%s: B%1d frame to short %d\n",
  1002. hx->ip->name, hx->bch.nr, hx->bch.rx_skb->len);
  1003. skb_trim(hx->bch.rx_skb, 0);
  1004. } else {
  1005. skb_trim(hx->bch.rx_skb, hx->bch.rx_skb->len - 1);
  1006. recv_Bchannel(&hx->bch, 0);
  1007. }
  1008. }
  1009. static void
  1010. ipac_irq(struct hscx_hw *hx, u8 ista)
  1011. {
  1012. u8 istab, m, exirb = 0;
  1013. if (hx->ip->type & IPAC_TYPE_IPACX)
  1014. istab = ReadHSCX(hx, IPACX_ISTAB);
  1015. else if (hx->ip->type & IPAC_TYPE_IPAC) {
  1016. istab = ReadHSCX(hx, IPAC_ISTAB);
  1017. m = (hx->bch.nr & 1) ? IPAC__EXA : IPAC__EXB;
  1018. if (m & ista) {
  1019. exirb = ReadHSCX(hx, IPAC_EXIRB);
  1020. pr_debug("%s: B%1d EXIRB %02x\n", hx->ip->name,
  1021. hx->bch.nr, exirb);
  1022. }
  1023. } else if (hx->bch.nr & 2) { /* HSCX B */
  1024. if (ista & (HSCX__EXA | HSCX__ICA))
  1025. ipac_irq(&hx->ip->hscx[0], ista);
  1026. if (ista & HSCX__EXB) {
  1027. exirb = ReadHSCX(hx, IPAC_EXIRB);
  1028. pr_debug("%s: B%1d EXIRB %02x\n", hx->ip->name,
  1029. hx->bch.nr, exirb);
  1030. }
  1031. istab = ista & 0xF8;
  1032. } else { /* HSCX A */
  1033. istab = ReadHSCX(hx, IPAC_ISTAB);
  1034. if (ista & HSCX__EXA) {
  1035. exirb = ReadHSCX(hx, IPAC_EXIRB);
  1036. pr_debug("%s: B%1d EXIRB %02x\n", hx->ip->name,
  1037. hx->bch.nr, exirb);
  1038. }
  1039. istab = istab & 0xF8;
  1040. }
  1041. if (exirb & IPAC_B_XDU)
  1042. istab |= IPACX_B_XDU;
  1043. if (exirb & IPAC_B_RFO)
  1044. istab |= IPACX_B_RFO;
  1045. pr_debug("%s: B%1d ISTAB %02x\n", hx->ip->name, hx->bch.nr, istab);
  1046. if (!test_bit(FLG_ACTIVE, &hx->bch.Flags))
  1047. return;
  1048. if (istab & IPACX_B_RME)
  1049. ipac_rme(hx);
  1050. if (istab & IPACX_B_RPF) {
  1051. hscx_empty_fifo(hx, hx->fifo_size);
  1052. if (test_bit(FLG_TRANSPARENT, &hx->bch.Flags)) {
  1053. /* receive transparent audio data */
  1054. if (hx->bch.rx_skb)
  1055. recv_Bchannel(&hx->bch, 0);
  1056. }
  1057. }
  1058. if (istab & IPACX_B_RFO) {
  1059. pr_debug("%s: B%1d RFO error\n", hx->ip->name, hx->bch.nr);
  1060. hscx_cmdr(hx, 0x40); /* RRES */
  1061. }
  1062. if (istab & IPACX_B_XPR)
  1063. hscx_xpr(hx);
  1064. if (istab & IPACX_B_XDU) {
  1065. if (test_bit(FLG_TRANSPARENT, &hx->bch.Flags)) {
  1066. hscx_fill_fifo(hx);
  1067. return;
  1068. }
  1069. pr_debug("%s: B%1d XDU error at len %d\n", hx->ip->name,
  1070. hx->bch.nr, hx->bch.tx_idx);
  1071. hx->bch.tx_idx = 0;
  1072. hscx_cmdr(hx, 0x01); /* XRES */
  1073. }
  1074. }
  1075. irqreturn_t
  1076. mISDNipac_irq(struct ipac_hw *ipac, int maxloop)
  1077. {
  1078. int cnt = maxloop + 1;
  1079. u8 ista, istad;
  1080. struct isac_hw *isac = &ipac->isac;
  1081. if (ipac->type & IPAC_TYPE_IPACX) {
  1082. ista = ReadIPAC(ipac, ISACX_ISTA);
  1083. while (ista && cnt--) {
  1084. pr_debug("%s: ISTA %02x\n", ipac->name, ista);
  1085. if (ista & IPACX__ICA)
  1086. ipac_irq(&ipac->hscx[0], ista);
  1087. if (ista & IPACX__ICB)
  1088. ipac_irq(&ipac->hscx[1], ista);
  1089. if (ista & (ISACX__ICD | ISACX__CIC))
  1090. mISDNisac_irq(&ipac->isac, ista);
  1091. ista = ReadIPAC(ipac, ISACX_ISTA);
  1092. }
  1093. } else if (ipac->type & IPAC_TYPE_IPAC) {
  1094. ista = ReadIPAC(ipac, IPAC_ISTA);
  1095. while (ista && cnt--) {
  1096. pr_debug("%s: ISTA %02x\n", ipac->name, ista);
  1097. if (ista & (IPAC__ICD | IPAC__EXD)) {
  1098. istad = ReadISAC(isac, ISAC_ISTA);
  1099. pr_debug("%s: ISTAD %02x\n", ipac->name, istad);
  1100. if (istad & IPAC_D_TIN2)
  1101. pr_debug("%s TIN2 irq\n", ipac->name);
  1102. if (ista & IPAC__EXD)
  1103. istad |= 1; /* ISAC EXI */
  1104. mISDNisac_irq(isac, istad);
  1105. }
  1106. if (ista & (IPAC__ICA | IPAC__EXA))
  1107. ipac_irq(&ipac->hscx[0], ista);
  1108. if (ista & (IPAC__ICB | IPAC__EXB))
  1109. ipac_irq(&ipac->hscx[1], ista);
  1110. ista = ReadIPAC(ipac, IPAC_ISTA);
  1111. }
  1112. } else if (ipac->type & IPAC_TYPE_HSCX) {
  1113. while (cnt) {
  1114. ista = ReadIPAC(ipac, IPAC_ISTAB + ipac->hscx[1].off);
  1115. pr_debug("%s: B2 ISTA %02x\n", ipac->name, ista);
  1116. if (ista)
  1117. ipac_irq(&ipac->hscx[1], ista);
  1118. istad = ReadISAC(isac, ISAC_ISTA);
  1119. pr_debug("%s: ISTAD %02x\n", ipac->name, istad);
  1120. if (istad)
  1121. mISDNisac_irq(isac, istad);
  1122. if (0 == (ista | istad))
  1123. break;
  1124. cnt--;
  1125. }
  1126. }
  1127. if (cnt > maxloop) /* only for ISAC/HSCX without PCI IRQ test */
  1128. return IRQ_NONE;
  1129. if (cnt < maxloop)
  1130. pr_debug("%s: %d irqloops cpu%d\n", ipac->name,
  1131. maxloop - cnt, smp_processor_id());
  1132. if (maxloop && !cnt)
  1133. pr_notice("%s: %d IRQ LOOP cpu%d\n", ipac->name,
  1134. maxloop, smp_processor_id());
  1135. return IRQ_HANDLED;
  1136. }
  1137. EXPORT_SYMBOL(mISDNipac_irq);
  1138. static int
  1139. hscx_mode(struct hscx_hw *hscx, u32 bprotocol)
  1140. {
  1141. pr_debug("%s: HSCX %c protocol %x-->%x ch %d\n", hscx->ip->name,
  1142. '@' + hscx->bch.nr, hscx->bch.state, bprotocol, hscx->bch.nr);
  1143. if (hscx->ip->type & IPAC_TYPE_IPACX) {
  1144. if (hscx->bch.nr & 1) { /* B1 and ICA */
  1145. WriteIPAC(hscx->ip, ISACX_BCHA_TSDP_BC1, 0x80);
  1146. WriteIPAC(hscx->ip, ISACX_BCHA_CR, 0x88);
  1147. } else { /* B2 and ICB */
  1148. WriteIPAC(hscx->ip, ISACX_BCHB_TSDP_BC1, 0x81);
  1149. WriteIPAC(hscx->ip, ISACX_BCHB_CR, 0x88);
  1150. }
  1151. switch (bprotocol) {
  1152. case ISDN_P_NONE: /* init */
  1153. WriteHSCX(hscx, IPACX_MODEB, 0xC0); /* rec off */
  1154. WriteHSCX(hscx, IPACX_EXMB, 0x30); /* std adj. */
  1155. WriteHSCX(hscx, IPACX_MASKB, 0xFF); /* ints off */
  1156. hscx_cmdr(hscx, 0x41);
  1157. test_and_clear_bit(FLG_HDLC, &hscx->bch.Flags);
  1158. test_and_clear_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
  1159. break;
  1160. case ISDN_P_B_RAW:
  1161. WriteHSCX(hscx, IPACX_MODEB, 0x88); /* ex trans */
  1162. WriteHSCX(hscx, IPACX_EXMB, 0x00); /* trans */
  1163. hscx_cmdr(hscx, 0x41);
  1164. WriteHSCX(hscx, IPACX_MASKB, IPACX_B_ON);
  1165. test_and_set_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
  1166. break;
  1167. case ISDN_P_B_HDLC:
  1168. WriteHSCX(hscx, IPACX_MODEB, 0xC0); /* trans */
  1169. WriteHSCX(hscx, IPACX_EXMB, 0x00); /* hdlc,crc */
  1170. hscx_cmdr(hscx, 0x41);
  1171. WriteHSCX(hscx, IPACX_MASKB, IPACX_B_ON);
  1172. test_and_set_bit(FLG_HDLC, &hscx->bch.Flags);
  1173. break;
  1174. default:
  1175. pr_info("%s: protocol not known %x\n", hscx->ip->name,
  1176. bprotocol);
  1177. return -ENOPROTOOPT;
  1178. }
  1179. } else if (hscx->ip->type & IPAC_TYPE_IPAC) { /* IPAC */
  1180. WriteHSCX(hscx, IPAC_CCR1, 0x82);
  1181. WriteHSCX(hscx, IPAC_CCR2, 0x30);
  1182. WriteHSCX(hscx, IPAC_XCCR, 0x07);
  1183. WriteHSCX(hscx, IPAC_RCCR, 0x07);
  1184. WriteHSCX(hscx, IPAC_TSAX, hscx->slot);
  1185. WriteHSCX(hscx, IPAC_TSAR, hscx->slot);
  1186. switch (bprotocol) {
  1187. case ISDN_P_NONE:
  1188. WriteHSCX(hscx, IPAC_TSAX, 0x1F);
  1189. WriteHSCX(hscx, IPAC_TSAR, 0x1F);
  1190. WriteHSCX(hscx, IPAC_MODEB, 0x84);
  1191. WriteHSCX(hscx, IPAC_CCR1, 0x82);
  1192. WriteHSCX(hscx, IPAC_MASKB, 0xFF); /* ints off */
  1193. test_and_clear_bit(FLG_HDLC, &hscx->bch.Flags);
  1194. test_and_clear_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
  1195. break;
  1196. case ISDN_P_B_RAW:
  1197. WriteHSCX(hscx, IPAC_MODEB, 0xe4); /* ex trans */
  1198. WriteHSCX(hscx, IPAC_CCR1, 0x82);
  1199. hscx_cmdr(hscx, 0x41);
  1200. WriteHSCX(hscx, IPAC_MASKB, 0);
  1201. test_and_set_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
  1202. break;
  1203. case ISDN_P_B_HDLC:
  1204. WriteHSCX(hscx, IPAC_MODEB, 0x8c);
  1205. WriteHSCX(hscx, IPAC_CCR1, 0x8a);
  1206. hscx_cmdr(hscx, 0x41);
  1207. WriteHSCX(hscx, IPAC_MASKB, 0);
  1208. test_and_set_bit(FLG_HDLC, &hscx->bch.Flags);
  1209. break;
  1210. default:
  1211. pr_info("%s: protocol not known %x\n", hscx->ip->name,
  1212. bprotocol);
  1213. return -ENOPROTOOPT;
  1214. }
  1215. } else if (hscx->ip->type & IPAC_TYPE_HSCX) { /* HSCX */
  1216. WriteHSCX(hscx, IPAC_CCR1, 0x85);
  1217. WriteHSCX(hscx, IPAC_CCR2, 0x30);
  1218. WriteHSCX(hscx, IPAC_XCCR, 0x07);
  1219. WriteHSCX(hscx, IPAC_RCCR, 0x07);
  1220. WriteHSCX(hscx, IPAC_TSAX, hscx->slot);
  1221. WriteHSCX(hscx, IPAC_TSAR, hscx->slot);
  1222. switch (bprotocol) {
  1223. case ISDN_P_NONE:
  1224. WriteHSCX(hscx, IPAC_TSAX, 0x1F);
  1225. WriteHSCX(hscx, IPAC_TSAR, 0x1F);
  1226. WriteHSCX(hscx, IPAC_MODEB, 0x84);
  1227. WriteHSCX(hscx, IPAC_CCR1, 0x85);
  1228. WriteHSCX(hscx, IPAC_MASKB, 0xFF); /* ints off */
  1229. test_and_clear_bit(FLG_HDLC, &hscx->bch.Flags);
  1230. test_and_clear_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
  1231. break;
  1232. case ISDN_P_B_RAW:
  1233. WriteHSCX(hscx, IPAC_MODEB, 0xe4); /* ex trans */
  1234. WriteHSCX(hscx, IPAC_CCR1, 0x85);
  1235. hscx_cmdr(hscx, 0x41);
  1236. WriteHSCX(hscx, IPAC_MASKB, 0);
  1237. test_and_set_bit(FLG_TRANSPARENT, &hscx->bch.Flags);
  1238. break;
  1239. case ISDN_P_B_HDLC:
  1240. WriteHSCX(hscx, IPAC_MODEB, 0x8c);
  1241. WriteHSCX(hscx, IPAC_CCR1, 0x8d);
  1242. hscx_cmdr(hscx, 0x41);
  1243. WriteHSCX(hscx, IPAC_MASKB, 0);
  1244. test_and_set_bit(FLG_HDLC, &hscx->bch.Flags);
  1245. break;
  1246. default:
  1247. pr_info("%s: protocol not known %x\n", hscx->ip->name,
  1248. bprotocol);
  1249. return -ENOPROTOOPT;
  1250. }
  1251. } else
  1252. return -EINVAL;
  1253. hscx->bch.state = bprotocol;
  1254. return 0;
  1255. }
  1256. static int
  1257. hscx_l2l1(struct mISDNchannel *ch, struct sk_buff *skb)
  1258. {
  1259. struct bchannel *bch = container_of(ch, struct bchannel, ch);
  1260. struct hscx_hw *hx = container_of(bch, struct hscx_hw, bch);
  1261. int ret = -EINVAL;
  1262. struct mISDNhead *hh = mISDN_HEAD_P(skb);
  1263. u32 id;
  1264. u_long flags;
  1265. switch (hh->prim) {
  1266. case PH_DATA_REQ:
  1267. spin_lock_irqsave(hx->ip->hwlock, flags);
  1268. ret = bchannel_senddata(bch, skb);
  1269. if (ret > 0) { /* direct TX */
  1270. id = hh->id; /* skb can be freed */
  1271. ret = 0;
  1272. hscx_fill_fifo(hx);
  1273. spin_unlock_irqrestore(hx->ip->hwlock, flags);
  1274. if (!test_bit(FLG_TRANSPARENT, &bch->Flags))
  1275. queue_ch_frame(ch, PH_DATA_CNF, id, NULL);
  1276. } else
  1277. spin_unlock_irqrestore(hx->ip->hwlock, flags);
  1278. return ret;
  1279. case PH_ACTIVATE_REQ:
  1280. spin_lock_irqsave(hx->ip->hwlock, flags);
  1281. if (!test_and_set_bit(FLG_ACTIVE, &bch->Flags))
  1282. ret = hscx_mode(hx, ch->protocol);
  1283. else
  1284. ret = 0;
  1285. spin_unlock_irqrestore(hx->ip->hwlock, flags);
  1286. if (!ret)
  1287. _queue_data(ch, PH_ACTIVATE_IND, MISDN_ID_ANY, 0,
  1288. NULL, GFP_KERNEL);
  1289. break;
  1290. case PH_DEACTIVATE_REQ:
  1291. spin_lock_irqsave(hx->ip->hwlock, flags);
  1292. mISDN_clear_bchannel(bch);
  1293. hscx_mode(hx, ISDN_P_NONE);
  1294. spin_unlock_irqrestore(hx->ip->hwlock, flags);
  1295. _queue_data(ch, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,
  1296. NULL, GFP_KERNEL);
  1297. ret = 0;
  1298. break;
  1299. default:
  1300. pr_info("%s: %s unknown prim(%x,%x)\n",
  1301. hx->ip->name, __func__, hh->prim, hh->id);
  1302. ret = -EINVAL;
  1303. }
  1304. if (!ret)
  1305. dev_kfree_skb(skb);
  1306. return ret;
  1307. }
  1308. static int
  1309. channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
  1310. {
  1311. int ret = 0;
  1312. switch (cq->op) {
  1313. case MISDN_CTRL_GETOP:
  1314. cq->op = 0;
  1315. break;
  1316. /* Nothing implemented yet */
  1317. case MISDN_CTRL_FILL_EMPTY:
  1318. default:
  1319. pr_info("%s: unknown Op %x\n", __func__, cq->op);
  1320. ret = -EINVAL;
  1321. break;
  1322. }
  1323. return ret;
  1324. }
  1325. static int
  1326. hscx_bctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
  1327. {
  1328. struct bchannel *bch = container_of(ch, struct bchannel, ch);
  1329. struct hscx_hw *hx = container_of(bch, struct hscx_hw, bch);
  1330. int ret = -EINVAL;
  1331. u_long flags;
  1332. pr_debug("%s: %s cmd:%x %p\n", hx->ip->name, __func__, cmd, arg);
  1333. switch (cmd) {
  1334. case CLOSE_CHANNEL:
  1335. test_and_clear_bit(FLG_OPEN, &bch->Flags);
  1336. if (test_bit(FLG_ACTIVE, &bch->Flags)) {
  1337. spin_lock_irqsave(hx->ip->hwlock, flags);
  1338. mISDN_freebchannel(bch);
  1339. hscx_mode(hx, ISDN_P_NONE);
  1340. spin_unlock_irqrestore(hx->ip->hwlock, flags);
  1341. } else {
  1342. skb_queue_purge(&bch->rqueue);
  1343. bch->rcount = 0;
  1344. }
  1345. ch->protocol = ISDN_P_NONE;
  1346. ch->peer = NULL;
  1347. module_put(hx->ip->owner);
  1348. ret = 0;
  1349. break;
  1350. case CONTROL_CHANNEL:
  1351. ret = channel_bctrl(bch, arg);
  1352. break;
  1353. default:
  1354. pr_info("%s: %s unknown prim(%x)\n",
  1355. hx->ip->name, __func__, cmd);
  1356. }
  1357. return ret;
  1358. }
  1359. static void
  1360. free_ipac(struct ipac_hw *ipac)
  1361. {
  1362. isac_release(&ipac->isac);
  1363. }
  1364. static const char *HSCXVer[] =
  1365. {"A1", "?1", "A2", "?3", "A3", "V2.1", "?6", "?7",
  1366. "?8", "?9", "?10", "?11", "?12", "?13", "?14", "???"};
  1367. static void
  1368. hscx_init(struct hscx_hw *hx)
  1369. {
  1370. u8 val;
  1371. WriteHSCX(hx, IPAC_RAH2, 0xFF);
  1372. WriteHSCX(hx, IPAC_XBCH, 0x00);
  1373. WriteHSCX(hx, IPAC_RLCR, 0x00);
  1374. if (hx->ip->type & IPAC_TYPE_HSCX) {
  1375. WriteHSCX(hx, IPAC_CCR1, 0x85);
  1376. val = ReadHSCX(hx, HSCX_VSTR);
  1377. pr_debug("%s: HSCX VSTR %02x\n", hx->ip->name, val);
  1378. if (hx->bch.debug & DEBUG_HW)
  1379. pr_notice("%s: HSCX version %s\n", hx->ip->name,
  1380. HSCXVer[val & 0x0f]);
  1381. } else
  1382. WriteHSCX(hx, IPAC_CCR1, 0x82);
  1383. WriteHSCX(hx, IPAC_CCR2, 0x30);
  1384. WriteHSCX(hx, IPAC_XCCR, 0x07);
  1385. WriteHSCX(hx, IPAC_RCCR, 0x07);
  1386. }
  1387. static int
  1388. ipac_init(struct ipac_hw *ipac)
  1389. {
  1390. u8 val;
  1391. if (ipac->type & IPAC_TYPE_HSCX) {
  1392. hscx_init(&ipac->hscx[0]);
  1393. hscx_init(&ipac->hscx[1]);
  1394. val = ReadIPAC(ipac, IPAC_ID);
  1395. } else if (ipac->type & IPAC_TYPE_IPAC) {
  1396. hscx_init(&ipac->hscx[0]);
  1397. hscx_init(&ipac->hscx[1]);
  1398. WriteIPAC(ipac, IPAC_MASK, IPAC__ON);
  1399. val = ReadIPAC(ipac, IPAC_CONF);
  1400. /* conf is default 0, but can be overwritten by card setup */
  1401. pr_debug("%s: IPAC CONF %02x/%02x\n", ipac->name,
  1402. val, ipac->conf);
  1403. WriteIPAC(ipac, IPAC_CONF, ipac->conf);
  1404. val = ReadIPAC(ipac, IPAC_ID);
  1405. if (ipac->hscx[0].bch.debug & DEBUG_HW)
  1406. pr_notice("%s: IPAC Design ID %02x\n", ipac->name, val);
  1407. }
  1408. /* nothing special for IPACX to do here */
  1409. return isac_init(&ipac->isac);
  1410. }
  1411. static int
  1412. open_bchannel(struct ipac_hw *ipac, struct channel_req *rq)
  1413. {
  1414. struct bchannel *bch;
  1415. if (rq->adr.channel > 2)
  1416. return -EINVAL;
  1417. if (rq->protocol == ISDN_P_NONE)
  1418. return -EINVAL;
  1419. bch = &ipac->hscx[rq->adr.channel - 1].bch;
  1420. if (test_and_set_bit(FLG_OPEN, &bch->Flags))
  1421. return -EBUSY; /* b-channel can be only open once */
  1422. test_and_clear_bit(FLG_FILLEMPTY, &bch->Flags);
  1423. bch->ch.protocol = rq->protocol;
  1424. rq->ch = &bch->ch;
  1425. return 0;
  1426. }
  1427. static int
  1428. channel_ctrl(struct ipac_hw *ipac, struct mISDN_ctrl_req *cq)
  1429. {
  1430. int ret = 0;
  1431. switch (cq->op) {
  1432. case MISDN_CTRL_GETOP:
  1433. cq->op = MISDN_CTRL_LOOP;
  1434. break;
  1435. case MISDN_CTRL_LOOP:
  1436. /* cq->channel: 0 disable, 1 B1 loop 2 B2 loop, 3 both */
  1437. if (cq->channel < 0 || cq->channel > 3) {
  1438. ret = -EINVAL;
  1439. break;
  1440. }
  1441. ret = ipac->ctrl(ipac, HW_TESTLOOP, cq->channel);
  1442. break;
  1443. default:
  1444. pr_info("%s: unknown CTRL OP %x\n", ipac->name, cq->op);
  1445. ret = -EINVAL;
  1446. break;
  1447. }
  1448. return ret;
  1449. }
  1450. static int
  1451. ipac_dctrl(struct mISDNchannel *ch, u32 cmd, void *arg)
  1452. {
  1453. struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
  1454. struct dchannel *dch = container_of(dev, struct dchannel, dev);
  1455. struct isac_hw *isac = container_of(dch, struct isac_hw, dch);
  1456. struct ipac_hw *ipac = container_of(isac, struct ipac_hw, isac);
  1457. struct channel_req *rq;
  1458. int err = 0;
  1459. pr_debug("%s: DCTRL: %x %p\n", ipac->name, cmd, arg);
  1460. switch (cmd) {
  1461. case OPEN_CHANNEL:
  1462. rq = arg;
  1463. if (rq->protocol == ISDN_P_TE_S0)
  1464. err = open_dchannel(isac, rq);
  1465. else
  1466. err = open_bchannel(ipac, rq);
  1467. if (err)
  1468. break;
  1469. if (!try_module_get(ipac->owner))
  1470. pr_info("%s: cannot get module\n", ipac->name);
  1471. break;
  1472. case CLOSE_CHANNEL:
  1473. pr_debug("%s: dev(%d) close from %p\n", ipac->name,
  1474. dch->dev.id, __builtin_return_address(0));
  1475. module_put(ipac->owner);
  1476. break;
  1477. case CONTROL_CHANNEL:
  1478. err = channel_ctrl(ipac, arg);
  1479. break;
  1480. default:
  1481. pr_debug("%s: unknown DCTRL command %x\n", ipac->name, cmd);
  1482. return -EINVAL;
  1483. }
  1484. return err;
  1485. }
  1486. u32
  1487. mISDNipac_init(struct ipac_hw *ipac, void *hw)
  1488. {
  1489. u32 ret;
  1490. u8 i;
  1491. ipac->hw = hw;
  1492. if (ipac->isac.dch.debug & DEBUG_HW)
  1493. pr_notice("%s: ipac type %x\n", ipac->name, ipac->type);
  1494. if (ipac->type & IPAC_TYPE_HSCX) {
  1495. ipac->isac.type = IPAC_TYPE_ISAC;
  1496. ipac->hscx[0].off = 0;
  1497. ipac->hscx[1].off = 0x40;
  1498. ipac->hscx[0].fifo_size = 32;
  1499. ipac->hscx[1].fifo_size = 32;
  1500. } else if (ipac->type & IPAC_TYPE_IPAC) {
  1501. ipac->isac.type = IPAC_TYPE_IPAC | IPAC_TYPE_ISAC;
  1502. ipac->hscx[0].off = 0;
  1503. ipac->hscx[1].off = 0x40;
  1504. ipac->hscx[0].fifo_size = 64;
  1505. ipac->hscx[1].fifo_size = 64;
  1506. } else if (ipac->type & IPAC_TYPE_IPACX) {
  1507. ipac->isac.type = IPAC_TYPE_IPACX | IPAC_TYPE_ISACX;
  1508. ipac->hscx[0].off = IPACX_OFF_ICA;
  1509. ipac->hscx[1].off = IPACX_OFF_ICB;
  1510. ipac->hscx[0].fifo_size = 64;
  1511. ipac->hscx[1].fifo_size = 64;
  1512. } else
  1513. return 0;
  1514. mISDNisac_init(&ipac->isac, hw);
  1515. ipac->isac.dch.dev.D.ctrl = ipac_dctrl;
  1516. for (i = 0; i < 2; i++) {
  1517. ipac->hscx[i].bch.nr = i + 1;
  1518. set_channelmap(i + 1, ipac->isac.dch.dev.channelmap);
  1519. list_add(&ipac->hscx[i].bch.ch.list,
  1520. &ipac->isac.dch.dev.bchannels);
  1521. mISDN_initbchannel(&ipac->hscx[i].bch, MAX_DATA_MEM);
  1522. ipac->hscx[i].bch.ch.nr = i + 1;
  1523. ipac->hscx[i].bch.ch.send = &hscx_l2l1;
  1524. ipac->hscx[i].bch.ch.ctrl = hscx_bctrl;
  1525. ipac->hscx[i].bch.hw = hw;
  1526. ipac->hscx[i].ip = ipac;
  1527. /* default values for IOM time slots
  1528. * can be overwriten by card */
  1529. ipac->hscx[i].slot = (i == 0) ? 0x2f : 0x03;
  1530. }
  1531. ipac->init = ipac_init;
  1532. ipac->release = free_ipac;
  1533. ret = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
  1534. (1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
  1535. return ret;
  1536. }
  1537. EXPORT_SYMBOL(mISDNipac_init);
  1538. static int __init
  1539. isac_mod_init(void)
  1540. {
  1541. pr_notice("mISDNipac module version %s\n", ISAC_REV);
  1542. return 0;
  1543. }
  1544. static void __exit
  1545. isac_mod_cleanup(void)
  1546. {
  1547. pr_notice("mISDNipac module unloaded\n");
  1548. }
  1549. module_init(isac_mod_init);
  1550. module_exit(isac_mod_cleanup);