mISDNipac.c 43 KB

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