icc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /* $Id: icc.c,v 1.8.2.3 2004/01/13 14:31:25 keil Exp $
  2. *
  3. * ICC specific routines
  4. *
  5. * Author Matt Henderson & Guy Ellis
  6. * Copyright by Traverse Technologies Pty Ltd, www.travers.com.au
  7. *
  8. * This software may be used and distributed according to the terms
  9. * of the GNU General Public License, incorporated herein by reference.
  10. *
  11. * 1999.6.25 Initial implementation of routines for Siemens ISDN
  12. * Communication Controller PEB 2070 based on the ISAC routines
  13. * written by Karsten Keil.
  14. *
  15. */
  16. #include <linux/init.h>
  17. #include "hisax.h"
  18. #include "icc.h"
  19. // #include "arcofi.h"
  20. #include "isdnl1.h"
  21. #include <linux/interrupt.h>
  22. #include <linux/slab.h>
  23. #define DBUSY_TIMER_VALUE 80
  24. #define ARCOFI_USE 0
  25. static char *ICCVer[] =
  26. {"2070 A1/A3", "2070 B1", "2070 B2/B3", "2070 V2.4"};
  27. void
  28. ICCVersion(struct IsdnCardState *cs, char *s)
  29. {
  30. int val;
  31. val = cs->readisac(cs, ICC_RBCH);
  32. printk(KERN_INFO "%s ICC version (%x): %s\n", s, val, ICCVer[(val >> 5) & 3]);
  33. }
  34. static void
  35. ph_command(struct IsdnCardState *cs, unsigned int command)
  36. {
  37. if (cs->debug & L1_DEB_ISAC)
  38. debugl1(cs, "ph_command %x", command);
  39. cs->writeisac(cs, ICC_CIX0, (command << 2) | 3);
  40. }
  41. static void
  42. icc_new_ph(struct IsdnCardState *cs)
  43. {
  44. switch (cs->dc.icc.ph_state) {
  45. case (ICC_IND_EI1):
  46. ph_command(cs, ICC_CMD_DI);
  47. l1_msg(cs, HW_RESET | INDICATION, NULL);
  48. break;
  49. case (ICC_IND_DC):
  50. l1_msg(cs, HW_DEACTIVATE | CONFIRM, NULL);
  51. break;
  52. case (ICC_IND_DR):
  53. l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
  54. break;
  55. case (ICC_IND_PU):
  56. l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
  57. break;
  58. case (ICC_IND_FJ):
  59. l1_msg(cs, HW_RSYNC | INDICATION, NULL);
  60. break;
  61. case (ICC_IND_AR):
  62. l1_msg(cs, HW_INFO2 | INDICATION, NULL);
  63. break;
  64. case (ICC_IND_AI):
  65. l1_msg(cs, HW_INFO4 | INDICATION, NULL);
  66. break;
  67. default:
  68. break;
  69. }
  70. }
  71. static void
  72. icc_bh(struct work_struct *work)
  73. {
  74. struct IsdnCardState *cs =
  75. container_of(work, struct IsdnCardState, tqueue);
  76. struct PStack *stptr;
  77. if (test_and_clear_bit(D_CLEARBUSY, &cs->event)) {
  78. if (cs->debug)
  79. debugl1(cs, "D-Channel Busy cleared");
  80. stptr = cs->stlist;
  81. while (stptr != NULL) {
  82. stptr->l1.l1l2(stptr, PH_PAUSE | CONFIRM, NULL);
  83. stptr = stptr->next;
  84. }
  85. }
  86. if (test_and_clear_bit(D_L1STATECHANGE, &cs->event))
  87. icc_new_ph(cs);
  88. if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
  89. DChannel_proc_rcv(cs);
  90. if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
  91. DChannel_proc_xmt(cs);
  92. #if ARCOFI_USE
  93. if (!test_bit(HW_ARCOFI, &cs->HW_Flags))
  94. return;
  95. if (test_and_clear_bit(D_RX_MON1, &cs->event))
  96. arcofi_fsm(cs, ARCOFI_RX_END, NULL);
  97. if (test_and_clear_bit(D_TX_MON1, &cs->event))
  98. arcofi_fsm(cs, ARCOFI_TX_END, NULL);
  99. #endif
  100. }
  101. static void
  102. icc_empty_fifo(struct IsdnCardState *cs, int count)
  103. {
  104. u_char *ptr;
  105. if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
  106. debugl1(cs, "icc_empty_fifo");
  107. if ((cs->rcvidx + count) >= MAX_DFRAME_LEN_L1) {
  108. if (cs->debug & L1_DEB_WARN)
  109. debugl1(cs, "icc_empty_fifo overrun %d",
  110. cs->rcvidx + count);
  111. cs->writeisac(cs, ICC_CMDR, 0x80);
  112. cs->rcvidx = 0;
  113. return;
  114. }
  115. ptr = cs->rcvbuf + cs->rcvidx;
  116. cs->rcvidx += count;
  117. cs->readisacfifo(cs, ptr, count);
  118. cs->writeisac(cs, ICC_CMDR, 0x80);
  119. if (cs->debug & L1_DEB_ISAC_FIFO) {
  120. char *t = cs->dlog;
  121. t += sprintf(t, "icc_empty_fifo cnt %d", count);
  122. QuickHex(t, ptr, count);
  123. debugl1(cs, cs->dlog);
  124. }
  125. }
  126. static void
  127. icc_fill_fifo(struct IsdnCardState *cs)
  128. {
  129. int count, more;
  130. u_char *ptr;
  131. if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
  132. debugl1(cs, "icc_fill_fifo");
  133. if (!cs->tx_skb)
  134. return;
  135. count = cs->tx_skb->len;
  136. if (count <= 0)
  137. return;
  138. more = 0;
  139. if (count > 32) {
  140. more = !0;
  141. count = 32;
  142. }
  143. ptr = cs->tx_skb->data;
  144. skb_pull(cs->tx_skb, count);
  145. cs->tx_cnt += count;
  146. cs->writeisacfifo(cs, ptr, count);
  147. cs->writeisac(cs, ICC_CMDR, more ? 0x8 : 0xa);
  148. if (test_and_set_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
  149. debugl1(cs, "icc_fill_fifo dbusytimer running");
  150. del_timer(&cs->dbusytimer);
  151. }
  152. init_timer(&cs->dbusytimer);
  153. cs->dbusytimer.expires = jiffies + ((DBUSY_TIMER_VALUE * HZ)/1000);
  154. add_timer(&cs->dbusytimer);
  155. if (cs->debug & L1_DEB_ISAC_FIFO) {
  156. char *t = cs->dlog;
  157. t += sprintf(t, "icc_fill_fifo cnt %d", count);
  158. QuickHex(t, ptr, count);
  159. debugl1(cs, cs->dlog);
  160. }
  161. }
  162. void
  163. icc_interrupt(struct IsdnCardState *cs, u_char val)
  164. {
  165. u_char exval, v1;
  166. struct sk_buff *skb;
  167. unsigned int count;
  168. if (cs->debug & L1_DEB_ISAC)
  169. debugl1(cs, "ICC interrupt %x", val);
  170. if (val & 0x80) { /* RME */
  171. exval = cs->readisac(cs, ICC_RSTA);
  172. if ((exval & 0x70) != 0x20) {
  173. if (exval & 0x40) {
  174. if (cs->debug & L1_DEB_WARN)
  175. debugl1(cs, "ICC RDO");
  176. #ifdef ERROR_STATISTIC
  177. cs->err_rx++;
  178. #endif
  179. }
  180. if (!(exval & 0x20)) {
  181. if (cs->debug & L1_DEB_WARN)
  182. debugl1(cs, "ICC CRC error");
  183. #ifdef ERROR_STATISTIC
  184. cs->err_crc++;
  185. #endif
  186. }
  187. cs->writeisac(cs, ICC_CMDR, 0x80);
  188. } else {
  189. count = cs->readisac(cs, ICC_RBCL) & 0x1f;
  190. if (count == 0)
  191. count = 32;
  192. icc_empty_fifo(cs, count);
  193. if ((count = cs->rcvidx) > 0) {
  194. cs->rcvidx = 0;
  195. if (!(skb = alloc_skb(count, GFP_ATOMIC)))
  196. printk(KERN_WARNING "HiSax: D receive out of memory\n");
  197. else {
  198. memcpy(skb_put(skb, count), cs->rcvbuf, count);
  199. skb_queue_tail(&cs->rq, skb);
  200. }
  201. }
  202. }
  203. cs->rcvidx = 0;
  204. schedule_event(cs, D_RCVBUFREADY);
  205. }
  206. if (val & 0x40) { /* RPF */
  207. icc_empty_fifo(cs, 32);
  208. }
  209. if (val & 0x20) { /* RSC */
  210. /* never */
  211. if (cs->debug & L1_DEB_WARN)
  212. debugl1(cs, "ICC RSC interrupt");
  213. }
  214. if (val & 0x10) { /* XPR */
  215. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  216. del_timer(&cs->dbusytimer);
  217. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  218. schedule_event(cs, D_CLEARBUSY);
  219. if (cs->tx_skb) {
  220. if (cs->tx_skb->len) {
  221. icc_fill_fifo(cs);
  222. goto afterXPR;
  223. } else {
  224. dev_kfree_skb_irq(cs->tx_skb);
  225. cs->tx_cnt = 0;
  226. cs->tx_skb = NULL;
  227. }
  228. }
  229. if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
  230. cs->tx_cnt = 0;
  231. icc_fill_fifo(cs);
  232. } else
  233. schedule_event(cs, D_XMTBUFREADY);
  234. }
  235. afterXPR:
  236. if (val & 0x04) { /* CISQ */
  237. exval = cs->readisac(cs, ICC_CIR0);
  238. if (cs->debug & L1_DEB_ISAC)
  239. debugl1(cs, "ICC CIR0 %02X", exval );
  240. if (exval & 2) {
  241. cs->dc.icc.ph_state = (exval >> 2) & 0xf;
  242. if (cs->debug & L1_DEB_ISAC)
  243. debugl1(cs, "ph_state change %x", cs->dc.icc.ph_state);
  244. schedule_event(cs, D_L1STATECHANGE);
  245. }
  246. if (exval & 1) {
  247. exval = cs->readisac(cs, ICC_CIR1);
  248. if (cs->debug & L1_DEB_ISAC)
  249. debugl1(cs, "ICC CIR1 %02X", exval );
  250. }
  251. }
  252. if (val & 0x02) { /* SIN */
  253. /* never */
  254. if (cs->debug & L1_DEB_WARN)
  255. debugl1(cs, "ICC SIN interrupt");
  256. }
  257. if (val & 0x01) { /* EXI */
  258. exval = cs->readisac(cs, ICC_EXIR);
  259. if (cs->debug & L1_DEB_WARN)
  260. debugl1(cs, "ICC EXIR %02x", exval);
  261. if (exval & 0x80) { /* XMR */
  262. debugl1(cs, "ICC XMR");
  263. printk(KERN_WARNING "HiSax: ICC XMR\n");
  264. }
  265. if (exval & 0x40) { /* XDU */
  266. debugl1(cs, "ICC XDU");
  267. printk(KERN_WARNING "HiSax: ICC XDU\n");
  268. #ifdef ERROR_STATISTIC
  269. cs->err_tx++;
  270. #endif
  271. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  272. del_timer(&cs->dbusytimer);
  273. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  274. schedule_event(cs, D_CLEARBUSY);
  275. if (cs->tx_skb) { /* Restart frame */
  276. skb_push(cs->tx_skb, cs->tx_cnt);
  277. cs->tx_cnt = 0;
  278. icc_fill_fifo(cs);
  279. } else {
  280. printk(KERN_WARNING "HiSax: ICC XDU no skb\n");
  281. debugl1(cs, "ICC XDU no skb");
  282. }
  283. }
  284. if (exval & 0x04) { /* MOS */
  285. v1 = cs->readisac(cs, ICC_MOSR);
  286. if (cs->debug & L1_DEB_MONITOR)
  287. debugl1(cs, "ICC MOSR %02x", v1);
  288. #if ARCOFI_USE
  289. if (v1 & 0x08) {
  290. if (!cs->dc.icc.mon_rx) {
  291. if (!(cs->dc.icc.mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
  292. if (cs->debug & L1_DEB_WARN)
  293. debugl1(cs, "ICC MON RX out of memory!");
  294. cs->dc.icc.mocr &= 0xf0;
  295. cs->dc.icc.mocr |= 0x0a;
  296. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  297. goto afterMONR0;
  298. } else
  299. cs->dc.icc.mon_rxp = 0;
  300. }
  301. if (cs->dc.icc.mon_rxp >= MAX_MON_FRAME) {
  302. cs->dc.icc.mocr &= 0xf0;
  303. cs->dc.icc.mocr |= 0x0a;
  304. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  305. cs->dc.icc.mon_rxp = 0;
  306. if (cs->debug & L1_DEB_WARN)
  307. debugl1(cs, "ICC MON RX overflow!");
  308. goto afterMONR0;
  309. }
  310. cs->dc.icc.mon_rx[cs->dc.icc.mon_rxp++] = cs->readisac(cs, ICC_MOR0);
  311. if (cs->debug & L1_DEB_MONITOR)
  312. debugl1(cs, "ICC MOR0 %02x", cs->dc.icc.mon_rx[cs->dc.icc.mon_rxp -1]);
  313. if (cs->dc.icc.mon_rxp == 1) {
  314. cs->dc.icc.mocr |= 0x04;
  315. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  316. }
  317. }
  318. afterMONR0:
  319. if (v1 & 0x80) {
  320. if (!cs->dc.icc.mon_rx) {
  321. if (!(cs->dc.icc.mon_rx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
  322. if (cs->debug & L1_DEB_WARN)
  323. debugl1(cs, "ICC MON RX out of memory!");
  324. cs->dc.icc.mocr &= 0x0f;
  325. cs->dc.icc.mocr |= 0xa0;
  326. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  327. goto afterMONR1;
  328. } else
  329. cs->dc.icc.mon_rxp = 0;
  330. }
  331. if (cs->dc.icc.mon_rxp >= MAX_MON_FRAME) {
  332. cs->dc.icc.mocr &= 0x0f;
  333. cs->dc.icc.mocr |= 0xa0;
  334. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  335. cs->dc.icc.mon_rxp = 0;
  336. if (cs->debug & L1_DEB_WARN)
  337. debugl1(cs, "ICC MON RX overflow!");
  338. goto afterMONR1;
  339. }
  340. cs->dc.icc.mon_rx[cs->dc.icc.mon_rxp++] = cs->readisac(cs, ICC_MOR1);
  341. if (cs->debug & L1_DEB_MONITOR)
  342. debugl1(cs, "ICC MOR1 %02x", cs->dc.icc.mon_rx[cs->dc.icc.mon_rxp -1]);
  343. cs->dc.icc.mocr |= 0x40;
  344. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  345. }
  346. afterMONR1:
  347. if (v1 & 0x04) {
  348. cs->dc.icc.mocr &= 0xf0;
  349. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  350. cs->dc.icc.mocr |= 0x0a;
  351. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  352. schedule_event(cs, D_RX_MON0);
  353. }
  354. if (v1 & 0x40) {
  355. cs->dc.icc.mocr &= 0x0f;
  356. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  357. cs->dc.icc.mocr |= 0xa0;
  358. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  359. schedule_event(cs, D_RX_MON1);
  360. }
  361. if (v1 & 0x02) {
  362. if ((!cs->dc.icc.mon_tx) || (cs->dc.icc.mon_txc &&
  363. (cs->dc.icc.mon_txp >= cs->dc.icc.mon_txc) &&
  364. !(v1 & 0x08))) {
  365. cs->dc.icc.mocr &= 0xf0;
  366. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  367. cs->dc.icc.mocr |= 0x0a;
  368. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  369. if (cs->dc.icc.mon_txc &&
  370. (cs->dc.icc.mon_txp >= cs->dc.icc.mon_txc))
  371. schedule_event(cs, D_TX_MON0);
  372. goto AfterMOX0;
  373. }
  374. if (cs->dc.icc.mon_txc && (cs->dc.icc.mon_txp >= cs->dc.icc.mon_txc)) {
  375. schedule_event(cs, D_TX_MON0);
  376. goto AfterMOX0;
  377. }
  378. cs->writeisac(cs, ICC_MOX0,
  379. cs->dc.icc.mon_tx[cs->dc.icc.mon_txp++]);
  380. if (cs->debug & L1_DEB_MONITOR)
  381. debugl1(cs, "ICC %02x -> MOX0", cs->dc.icc.mon_tx[cs->dc.icc.mon_txp -1]);
  382. }
  383. AfterMOX0:
  384. if (v1 & 0x20) {
  385. if ((!cs->dc.icc.mon_tx) || (cs->dc.icc.mon_txc &&
  386. (cs->dc.icc.mon_txp >= cs->dc.icc.mon_txc) &&
  387. !(v1 & 0x80))) {
  388. cs->dc.icc.mocr &= 0x0f;
  389. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  390. cs->dc.icc.mocr |= 0xa0;
  391. cs->writeisac(cs, ICC_MOCR, cs->dc.icc.mocr);
  392. if (cs->dc.icc.mon_txc &&
  393. (cs->dc.icc.mon_txp >= cs->dc.icc.mon_txc))
  394. schedule_event(cs, D_TX_MON1);
  395. goto AfterMOX1;
  396. }
  397. if (cs->dc.icc.mon_txc && (cs->dc.icc.mon_txp >= cs->dc.icc.mon_txc)) {
  398. schedule_event(cs, D_TX_MON1);
  399. goto AfterMOX1;
  400. }
  401. cs->writeisac(cs, ICC_MOX1,
  402. cs->dc.icc.mon_tx[cs->dc.icc.mon_txp++]);
  403. if (cs->debug & L1_DEB_MONITOR)
  404. debugl1(cs, "ICC %02x -> MOX1", cs->dc.icc.mon_tx[cs->dc.icc.mon_txp -1]);
  405. }
  406. AfterMOX1:
  407. #endif
  408. }
  409. }
  410. }
  411. static void
  412. ICC_l1hw(struct PStack *st, int pr, void *arg)
  413. {
  414. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  415. struct sk_buff *skb = arg;
  416. u_long flags;
  417. int val;
  418. switch (pr) {
  419. case (PH_DATA |REQUEST):
  420. if (cs->debug & DEB_DLOG_HEX)
  421. LogFrame(cs, skb->data, skb->len);
  422. if (cs->debug & DEB_DLOG_VERBOSE)
  423. dlogframe(cs, skb, 0);
  424. spin_lock_irqsave(&cs->lock, flags);
  425. if (cs->tx_skb) {
  426. skb_queue_tail(&cs->sq, skb);
  427. #ifdef L2FRAME_DEBUG /* psa */
  428. if (cs->debug & L1_DEB_LAPD)
  429. Logl2Frame(cs, skb, "PH_DATA Queued", 0);
  430. #endif
  431. } else {
  432. cs->tx_skb = skb;
  433. cs->tx_cnt = 0;
  434. #ifdef L2FRAME_DEBUG /* psa */
  435. if (cs->debug & L1_DEB_LAPD)
  436. Logl2Frame(cs, skb, "PH_DATA", 0);
  437. #endif
  438. icc_fill_fifo(cs);
  439. }
  440. spin_unlock_irqrestore(&cs->lock, flags);
  441. break;
  442. case (PH_PULL |INDICATION):
  443. spin_lock_irqsave(&cs->lock, flags);
  444. if (cs->tx_skb) {
  445. if (cs->debug & L1_DEB_WARN)
  446. debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
  447. skb_queue_tail(&cs->sq, skb);
  448. spin_unlock_irqrestore(&cs->lock, flags);
  449. break;
  450. }
  451. if (cs->debug & DEB_DLOG_HEX)
  452. LogFrame(cs, skb->data, skb->len);
  453. if (cs->debug & DEB_DLOG_VERBOSE)
  454. dlogframe(cs, skb, 0);
  455. cs->tx_skb = skb;
  456. cs->tx_cnt = 0;
  457. #ifdef L2FRAME_DEBUG /* psa */
  458. if (cs->debug & L1_DEB_LAPD)
  459. Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
  460. #endif
  461. icc_fill_fifo(cs);
  462. spin_unlock_irqrestore(&cs->lock, flags);
  463. break;
  464. case (PH_PULL | REQUEST):
  465. #ifdef L2FRAME_DEBUG /* psa */
  466. if (cs->debug & L1_DEB_LAPD)
  467. debugl1(cs, "-> PH_REQUEST_PULL");
  468. #endif
  469. if (!cs->tx_skb) {
  470. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  471. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  472. } else
  473. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  474. break;
  475. case (HW_RESET | REQUEST):
  476. spin_lock_irqsave(&cs->lock, flags);
  477. if ((cs->dc.icc.ph_state == ICC_IND_EI1) ||
  478. (cs->dc.icc.ph_state == ICC_IND_DR))
  479. ph_command(cs, ICC_CMD_DI);
  480. else
  481. ph_command(cs, ICC_CMD_RES);
  482. spin_unlock_irqrestore(&cs->lock, flags);
  483. break;
  484. case (HW_ENABLE | REQUEST):
  485. spin_lock_irqsave(&cs->lock, flags);
  486. ph_command(cs, ICC_CMD_DI);
  487. spin_unlock_irqrestore(&cs->lock, flags);
  488. break;
  489. case (HW_INFO1 | REQUEST):
  490. spin_lock_irqsave(&cs->lock, flags);
  491. ph_command(cs, ICC_CMD_AR);
  492. spin_unlock_irqrestore(&cs->lock, flags);
  493. break;
  494. case (HW_INFO3 | REQUEST):
  495. spin_lock_irqsave(&cs->lock, flags);
  496. ph_command(cs, ICC_CMD_AI);
  497. spin_unlock_irqrestore(&cs->lock, flags);
  498. break;
  499. case (HW_TESTLOOP | REQUEST):
  500. spin_lock_irqsave(&cs->lock, flags);
  501. val = 0;
  502. if (1 & (long) arg)
  503. val |= 0x0c;
  504. if (2 & (long) arg)
  505. val |= 0x3;
  506. if (test_bit(HW_IOM1, &cs->HW_Flags)) {
  507. /* IOM 1 Mode */
  508. if (!val) {
  509. cs->writeisac(cs, ICC_SPCR, 0xa);
  510. cs->writeisac(cs, ICC_ADF1, 0x2);
  511. } else {
  512. cs->writeisac(cs, ICC_SPCR, val);
  513. cs->writeisac(cs, ICC_ADF1, 0xa);
  514. }
  515. } else {
  516. /* IOM 2 Mode */
  517. cs->writeisac(cs, ICC_SPCR, val);
  518. if (val)
  519. cs->writeisac(cs, ICC_ADF1, 0x8);
  520. else
  521. cs->writeisac(cs, ICC_ADF1, 0x0);
  522. }
  523. spin_unlock_irqrestore(&cs->lock, flags);
  524. break;
  525. case (HW_DEACTIVATE | RESPONSE):
  526. skb_queue_purge(&cs->rq);
  527. skb_queue_purge(&cs->sq);
  528. if (cs->tx_skb) {
  529. dev_kfree_skb_any(cs->tx_skb);
  530. cs->tx_skb = NULL;
  531. }
  532. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  533. del_timer(&cs->dbusytimer);
  534. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  535. schedule_event(cs, D_CLEARBUSY);
  536. break;
  537. default:
  538. if (cs->debug & L1_DEB_WARN)
  539. debugl1(cs, "icc_l1hw unknown %04x", pr);
  540. break;
  541. }
  542. }
  543. static void
  544. setstack_icc(struct PStack *st, struct IsdnCardState *cs)
  545. {
  546. st->l1.l1hw = ICC_l1hw;
  547. }
  548. static void
  549. DC_Close_icc(struct IsdnCardState *cs) {
  550. kfree(cs->dc.icc.mon_rx);
  551. cs->dc.icc.mon_rx = NULL;
  552. kfree(cs->dc.icc.mon_tx);
  553. cs->dc.icc.mon_tx = NULL;
  554. }
  555. static void
  556. dbusy_timer_handler(struct IsdnCardState *cs)
  557. {
  558. struct PStack *stptr;
  559. int rbch, star;
  560. if (test_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
  561. rbch = cs->readisac(cs, ICC_RBCH);
  562. star = cs->readisac(cs, ICC_STAR);
  563. if (cs->debug)
  564. debugl1(cs, "D-Channel Busy RBCH %02x STAR %02x",
  565. rbch, star);
  566. if (rbch & ICC_RBCH_XAC) { /* D-Channel Busy */
  567. test_and_set_bit(FLG_L1_DBUSY, &cs->HW_Flags);
  568. stptr = cs->stlist;
  569. while (stptr != NULL) {
  570. stptr->l1.l1l2(stptr, PH_PAUSE | INDICATION, NULL);
  571. stptr = stptr->next;
  572. }
  573. } else {
  574. /* discard frame; reset transceiver */
  575. test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags);
  576. if (cs->tx_skb) {
  577. dev_kfree_skb_any(cs->tx_skb);
  578. cs->tx_cnt = 0;
  579. cs->tx_skb = NULL;
  580. } else {
  581. printk(KERN_WARNING "HiSax: ICC D-Channel Busy no skb\n");
  582. debugl1(cs, "D-Channel Busy no skb");
  583. }
  584. cs->writeisac(cs, ICC_CMDR, 0x01); /* Transmitter reset */
  585. cs->irq_func(cs->irq, cs);
  586. }
  587. }
  588. }
  589. void
  590. initicc(struct IsdnCardState *cs)
  591. {
  592. cs->setstack_d = setstack_icc;
  593. cs->DC_Close = DC_Close_icc;
  594. cs->dc.icc.mon_tx = NULL;
  595. cs->dc.icc.mon_rx = NULL;
  596. cs->writeisac(cs, ICC_MASK, 0xff);
  597. cs->dc.icc.mocr = 0xaa;
  598. if (test_bit(HW_IOM1, &cs->HW_Flags)) {
  599. /* IOM 1 Mode */
  600. cs->writeisac(cs, ICC_ADF2, 0x0);
  601. cs->writeisac(cs, ICC_SPCR, 0xa);
  602. cs->writeisac(cs, ICC_ADF1, 0x2);
  603. cs->writeisac(cs, ICC_STCR, 0x70);
  604. cs->writeisac(cs, ICC_MODE, 0xc9);
  605. } else {
  606. /* IOM 2 Mode */
  607. if (!cs->dc.icc.adf2)
  608. cs->dc.icc.adf2 = 0x80;
  609. cs->writeisac(cs, ICC_ADF2, cs->dc.icc.adf2);
  610. cs->writeisac(cs, ICC_SQXR, 0xa0);
  611. cs->writeisac(cs, ICC_SPCR, 0x20);
  612. cs->writeisac(cs, ICC_STCR, 0x70);
  613. cs->writeisac(cs, ICC_MODE, 0xca);
  614. cs->writeisac(cs, ICC_TIMR, 0x00);
  615. cs->writeisac(cs, ICC_ADF1, 0x20);
  616. }
  617. ph_command(cs, ICC_CMD_RES);
  618. cs->writeisac(cs, ICC_MASK, 0x0);
  619. ph_command(cs, ICC_CMD_DI);
  620. }
  621. void
  622. clear_pending_icc_ints(struct IsdnCardState *cs)
  623. {
  624. int val, eval;
  625. val = cs->readisac(cs, ICC_STAR);
  626. debugl1(cs, "ICC STAR %x", val);
  627. val = cs->readisac(cs, ICC_MODE);
  628. debugl1(cs, "ICC MODE %x", val);
  629. val = cs->readisac(cs, ICC_ADF2);
  630. debugl1(cs, "ICC ADF2 %x", val);
  631. val = cs->readisac(cs, ICC_ISTA);
  632. debugl1(cs, "ICC ISTA %x", val);
  633. if (val & 0x01) {
  634. eval = cs->readisac(cs, ICC_EXIR);
  635. debugl1(cs, "ICC EXIR %x", eval);
  636. }
  637. val = cs->readisac(cs, ICC_CIR0);
  638. debugl1(cs, "ICC CIR0 %x", val);
  639. cs->dc.icc.ph_state = (val >> 2) & 0xf;
  640. schedule_event(cs, D_L1STATECHANGE);
  641. /* Disable all IRQ */
  642. cs->writeisac(cs, ICC_MASK, 0xFF);
  643. }
  644. void __devinit
  645. setup_icc(struct IsdnCardState *cs)
  646. {
  647. INIT_WORK(&cs->tqueue, icc_bh);
  648. cs->dbusytimer.function = (void *) dbusy_timer_handler;
  649. cs->dbusytimer.data = (long) cs;
  650. init_timer(&cs->dbusytimer);
  651. }