isdnl1.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. /* $Id: isdnl1.c,v 2.46.2.5 2004/02/11 13:21:34 keil Exp $
  2. *
  3. * common low level stuff for Siemens Chipsetbased isdn cards
  4. *
  5. * Author Karsten Keil
  6. * based on the teles driver from Jan den Ouden
  7. * Copyright by Karsten Keil <keil@isdn4linux.de>
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. * For changes and modifications please read
  13. * Documentation/isdn/HiSax.cert
  14. *
  15. * Thanks to Jan den Ouden
  16. * Fritz Elfert
  17. * Beat Doebeli
  18. *
  19. */
  20. const char *l1_revision = "$Revision: 2.46.2.5 $";
  21. #include <linux/init.h>
  22. #include "hisax.h"
  23. #include "isdnl1.h"
  24. #define TIMER3_VALUE 7000
  25. static struct Fsm l1fsm_b;
  26. static struct Fsm l1fsm_s;
  27. enum {
  28. ST_L1_F2,
  29. ST_L1_F3,
  30. ST_L1_F4,
  31. ST_L1_F5,
  32. ST_L1_F6,
  33. ST_L1_F7,
  34. ST_L1_F8,
  35. };
  36. #define L1S_STATE_COUNT (ST_L1_F8+1)
  37. static char *strL1SState[] =
  38. {
  39. "ST_L1_F2",
  40. "ST_L1_F3",
  41. "ST_L1_F4",
  42. "ST_L1_F5",
  43. "ST_L1_F6",
  44. "ST_L1_F7",
  45. "ST_L1_F8",
  46. };
  47. #ifdef HISAX_UINTERFACE
  48. static
  49. struct Fsm l1fsm_u =
  50. {NULL, 0, 0, NULL, NULL};
  51. enum {
  52. ST_L1_RESET,
  53. ST_L1_DEACT,
  54. ST_L1_SYNC2,
  55. ST_L1_TRANS,
  56. };
  57. #define L1U_STATE_COUNT (ST_L1_TRANS+1)
  58. static char *strL1UState[] =
  59. {
  60. "ST_L1_RESET",
  61. "ST_L1_DEACT",
  62. "ST_L1_SYNC2",
  63. "ST_L1_TRANS",
  64. };
  65. #endif
  66. enum {
  67. ST_L1_NULL,
  68. ST_L1_WAIT_ACT,
  69. ST_L1_WAIT_DEACT,
  70. ST_L1_ACTIV,
  71. };
  72. #define L1B_STATE_COUNT (ST_L1_ACTIV+1)
  73. static char *strL1BState[] =
  74. {
  75. "ST_L1_NULL",
  76. "ST_L1_WAIT_ACT",
  77. "ST_L1_WAIT_DEACT",
  78. "ST_L1_ACTIV",
  79. };
  80. enum {
  81. EV_PH_ACTIVATE,
  82. EV_PH_DEACTIVATE,
  83. EV_RESET_IND,
  84. EV_DEACT_CNF,
  85. EV_DEACT_IND,
  86. EV_POWER_UP,
  87. EV_RSYNC_IND,
  88. EV_INFO2_IND,
  89. EV_INFO4_IND,
  90. EV_TIMER_DEACT,
  91. EV_TIMER_ACT,
  92. EV_TIMER3,
  93. };
  94. #define L1_EVENT_COUNT (EV_TIMER3 + 1)
  95. static char *strL1Event[] =
  96. {
  97. "EV_PH_ACTIVATE",
  98. "EV_PH_DEACTIVATE",
  99. "EV_RESET_IND",
  100. "EV_DEACT_CNF",
  101. "EV_DEACT_IND",
  102. "EV_POWER_UP",
  103. "EV_RSYNC_IND",
  104. "EV_INFO2_IND",
  105. "EV_INFO4_IND",
  106. "EV_TIMER_DEACT",
  107. "EV_TIMER_ACT",
  108. "EV_TIMER3",
  109. };
  110. void
  111. debugl1(struct IsdnCardState *cs, char *fmt, ...)
  112. {
  113. va_list args;
  114. char tmp[8];
  115. va_start(args, fmt);
  116. sprintf(tmp, "Card%d ", cs->cardnr + 1);
  117. VHiSax_putstatus(cs, tmp, fmt, args);
  118. va_end(args);
  119. }
  120. static void
  121. l1m_debug(struct FsmInst *fi, char *fmt, ...)
  122. {
  123. va_list args;
  124. struct PStack *st = fi->userdata;
  125. struct IsdnCardState *cs = st->l1.hardware;
  126. char tmp[8];
  127. va_start(args, fmt);
  128. sprintf(tmp, "Card%d ", cs->cardnr + 1);
  129. VHiSax_putstatus(cs, tmp, fmt, args);
  130. va_end(args);
  131. }
  132. static void
  133. L1activated(struct IsdnCardState *cs)
  134. {
  135. struct PStack *st;
  136. st = cs->stlist;
  137. while (st) {
  138. if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  139. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  140. else
  141. st->l1.l1l2(st, PH_ACTIVATE | INDICATION, NULL);
  142. st = st->next;
  143. }
  144. }
  145. static void
  146. L1deactivated(struct IsdnCardState *cs)
  147. {
  148. struct PStack *st;
  149. st = cs->stlist;
  150. while (st) {
  151. if (test_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  152. st->l1.l1l2(st, PH_PAUSE | CONFIRM, NULL);
  153. st->l1.l1l2(st, PH_DEACTIVATE | INDICATION, NULL);
  154. st = st->next;
  155. }
  156. test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags);
  157. }
  158. void
  159. DChannel_proc_xmt(struct IsdnCardState *cs)
  160. {
  161. struct PStack *stptr;
  162. if (cs->tx_skb)
  163. return;
  164. stptr = cs->stlist;
  165. while (stptr != NULL) {
  166. if (test_and_clear_bit(FLG_L1_PULL_REQ, &stptr->l1.Flags)) {
  167. stptr->l1.l1l2(stptr, PH_PULL | CONFIRM, NULL);
  168. break;
  169. } else
  170. stptr = stptr->next;
  171. }
  172. }
  173. void
  174. DChannel_proc_rcv(struct IsdnCardState *cs)
  175. {
  176. struct sk_buff *skb, *nskb;
  177. struct PStack *stptr = cs->stlist;
  178. int found, tei, sapi;
  179. if (stptr)
  180. if (test_bit(FLG_L1_ACTTIMER, &stptr->l1.Flags))
  181. FsmEvent(&stptr->l1.l1m, EV_TIMER_ACT, NULL);
  182. while ((skb = skb_dequeue(&cs->rq))) {
  183. #ifdef L2FRAME_DEBUG /* psa */
  184. if (cs->debug & L1_DEB_LAPD)
  185. Logl2Frame(cs, skb, "PH_DATA", 1);
  186. #endif
  187. stptr = cs->stlist;
  188. if (skb->len<3) {
  189. debugl1(cs, "D-channel frame too short(%d)",skb->len);
  190. dev_kfree_skb(skb);
  191. return;
  192. }
  193. if ((skb->data[0] & 1) || !(skb->data[1] &1)) {
  194. debugl1(cs, "D-channel frame wrong EA0/EA1");
  195. dev_kfree_skb(skb);
  196. return;
  197. }
  198. sapi = skb->data[0] >> 2;
  199. tei = skb->data[1] >> 1;
  200. if (cs->debug & DEB_DLOG_HEX)
  201. LogFrame(cs, skb->data, skb->len);
  202. if (cs->debug & DEB_DLOG_VERBOSE)
  203. dlogframe(cs, skb, 1);
  204. if (tei == GROUP_TEI) {
  205. if (sapi == CTRL_SAPI) { /* sapi 0 */
  206. while (stptr != NULL) {
  207. if ((nskb = skb_clone(skb, GFP_ATOMIC)))
  208. stptr->l1.l1l2(stptr, PH_DATA | INDICATION, nskb);
  209. else
  210. printk(KERN_WARNING "HiSax: isdn broadcast buffer shortage\n");
  211. stptr = stptr->next;
  212. }
  213. } else if (sapi == TEI_SAPI) {
  214. while (stptr != NULL) {
  215. if ((nskb = skb_clone(skb, GFP_ATOMIC)))
  216. stptr->l1.l1tei(stptr, PH_DATA | INDICATION, nskb);
  217. else
  218. printk(KERN_WARNING "HiSax: tei broadcast buffer shortage\n");
  219. stptr = stptr->next;
  220. }
  221. }
  222. dev_kfree_skb(skb);
  223. } else if (sapi == CTRL_SAPI) { /* sapi 0 */
  224. found = 0;
  225. while (stptr != NULL)
  226. if (tei == stptr->l2.tei) {
  227. stptr->l1.l1l2(stptr, PH_DATA | INDICATION, skb);
  228. found = !0;
  229. break;
  230. } else
  231. stptr = stptr->next;
  232. if (!found)
  233. dev_kfree_skb(skb);
  234. } else
  235. dev_kfree_skb(skb);
  236. }
  237. }
  238. static void
  239. BChannel_proc_xmt(struct BCState *bcs)
  240. {
  241. struct PStack *st = bcs->st;
  242. if (test_bit(BC_FLG_BUSY, &bcs->Flag)) {
  243. debugl1(bcs->cs, "BC_BUSY Error");
  244. return;
  245. }
  246. if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags))
  247. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  248. if (!test_bit(BC_FLG_ACTIV, &bcs->Flag)) {
  249. if (!test_bit(BC_FLG_BUSY, &bcs->Flag) && (!skb_queue_len(&bcs->squeue))) {
  250. st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
  251. }
  252. }
  253. }
  254. static void
  255. BChannel_proc_rcv(struct BCState *bcs)
  256. {
  257. struct sk_buff *skb;
  258. if (bcs->st->l1.l1m.state == ST_L1_WAIT_ACT) {
  259. FsmDelTimer(&bcs->st->l1.timer, 4);
  260. FsmEvent(&bcs->st->l1.l1m, EV_TIMER_ACT, NULL);
  261. }
  262. while ((skb = skb_dequeue(&bcs->rqueue))) {
  263. bcs->st->l1.l1l2(bcs->st, PH_DATA | INDICATION, skb);
  264. }
  265. }
  266. static void
  267. BChannel_proc_ack(struct BCState *bcs)
  268. {
  269. u_long flags;
  270. int ack;
  271. spin_lock_irqsave(&bcs->aclock, flags);
  272. ack = bcs->ackcnt;
  273. bcs->ackcnt = 0;
  274. spin_unlock_irqrestore(&bcs->aclock, flags);
  275. if (ack)
  276. lli_writewakeup(bcs->st, ack);
  277. }
  278. void
  279. BChannel_bh(struct BCState *bcs)
  280. {
  281. if (!bcs)
  282. return;
  283. if (test_and_clear_bit(B_RCVBUFREADY, &bcs->event))
  284. BChannel_proc_rcv(bcs);
  285. if (test_and_clear_bit(B_XMTBUFREADY, &bcs->event))
  286. BChannel_proc_xmt(bcs);
  287. if (test_and_clear_bit(B_ACKPENDING, &bcs->event))
  288. BChannel_proc_ack(bcs);
  289. }
  290. void
  291. HiSax_addlist(struct IsdnCardState *cs,
  292. struct PStack *st)
  293. {
  294. st->next = cs->stlist;
  295. cs->stlist = st;
  296. }
  297. void
  298. HiSax_rmlist(struct IsdnCardState *cs,
  299. struct PStack *st)
  300. {
  301. struct PStack *p;
  302. FsmDelTimer(&st->l1.timer, 0);
  303. if (cs->stlist == st)
  304. cs->stlist = st->next;
  305. else {
  306. p = cs->stlist;
  307. while (p)
  308. if (p->next == st) {
  309. p->next = st->next;
  310. return;
  311. } else
  312. p = p->next;
  313. }
  314. }
  315. void
  316. init_bcstate(struct IsdnCardState *cs, int bc)
  317. {
  318. struct BCState *bcs = cs->bcs + bc;
  319. bcs->cs = cs;
  320. bcs->channel = bc;
  321. INIT_WORK(&bcs->tqueue, (void *)(void *) BChannel_bh, bcs);
  322. spin_lock_init(&bcs->aclock);
  323. bcs->BC_SetStack = NULL;
  324. bcs->BC_Close = NULL;
  325. bcs->Flag = 0;
  326. }
  327. #ifdef L2FRAME_DEBUG /* psa */
  328. static char *
  329. l2cmd(u_char cmd)
  330. {
  331. switch (cmd & ~0x10) {
  332. case 1:
  333. return "RR";
  334. case 5:
  335. return "RNR";
  336. case 9:
  337. return "REJ";
  338. case 0x6f:
  339. return "SABME";
  340. case 0x0f:
  341. return "DM";
  342. case 3:
  343. return "UI";
  344. case 0x43:
  345. return "DISC";
  346. case 0x63:
  347. return "UA";
  348. case 0x87:
  349. return "FRMR";
  350. case 0xaf:
  351. return "XID";
  352. default:
  353. if (!(cmd & 1))
  354. return "I";
  355. else
  356. return "invalid command";
  357. }
  358. }
  359. static char tmpdeb[32];
  360. static char *
  361. l2frames(u_char * ptr)
  362. {
  363. switch (ptr[2] & ~0x10) {
  364. case 1:
  365. case 5:
  366. case 9:
  367. sprintf(tmpdeb, "%s[%d](nr %d)", l2cmd(ptr[2]), ptr[3] & 1, ptr[3] >> 1);
  368. break;
  369. case 0x6f:
  370. case 0x0f:
  371. case 3:
  372. case 0x43:
  373. case 0x63:
  374. case 0x87:
  375. case 0xaf:
  376. sprintf(tmpdeb, "%s[%d]", l2cmd(ptr[2]), (ptr[2] & 0x10) >> 4);
  377. break;
  378. default:
  379. if (!(ptr[2] & 1)) {
  380. sprintf(tmpdeb, "I[%d](ns %d, nr %d)", ptr[3] & 1, ptr[2] >> 1, ptr[3] >> 1);
  381. break;
  382. } else
  383. return "invalid command";
  384. }
  385. return tmpdeb;
  386. }
  387. void
  388. Logl2Frame(struct IsdnCardState *cs, struct sk_buff *skb, char *buf, int dir)
  389. {
  390. u_char *ptr;
  391. ptr = skb->data;
  392. if (ptr[0] & 1 || !(ptr[1] & 1))
  393. debugl1(cs, "Address not LAPD");
  394. else
  395. debugl1(cs, "%s %s: %s%c (sapi %d, tei %d)",
  396. (dir ? "<-" : "->"), buf, l2frames(ptr),
  397. ((ptr[0] & 2) >> 1) == dir ? 'C' : 'R', ptr[0] >> 2, ptr[1] >> 1);
  398. }
  399. #endif
  400. static void
  401. l1_reset(struct FsmInst *fi, int event, void *arg)
  402. {
  403. FsmChangeState(fi, ST_L1_F3);
  404. }
  405. static void
  406. l1_deact_cnf(struct FsmInst *fi, int event, void *arg)
  407. {
  408. struct PStack *st = fi->userdata;
  409. FsmChangeState(fi, ST_L1_F3);
  410. if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  411. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  412. }
  413. static void
  414. l1_deact_req_s(struct FsmInst *fi, int event, void *arg)
  415. {
  416. struct PStack *st = fi->userdata;
  417. FsmChangeState(fi, ST_L1_F3);
  418. FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
  419. test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  420. }
  421. static void
  422. l1_power_up_s(struct FsmInst *fi, int event, void *arg)
  423. {
  424. struct PStack *st = fi->userdata;
  425. if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags)) {
  426. FsmChangeState(fi, ST_L1_F4);
  427. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  428. FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
  429. test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
  430. } else
  431. FsmChangeState(fi, ST_L1_F3);
  432. }
  433. static void
  434. l1_go_F5(struct FsmInst *fi, int event, void *arg)
  435. {
  436. FsmChangeState(fi, ST_L1_F5);
  437. }
  438. static void
  439. l1_go_F8(struct FsmInst *fi, int event, void *arg)
  440. {
  441. FsmChangeState(fi, ST_L1_F8);
  442. }
  443. static void
  444. l1_info2_ind(struct FsmInst *fi, int event, void *arg)
  445. {
  446. struct PStack *st = fi->userdata;
  447. #ifdef HISAX_UINTERFACE
  448. if (test_bit(FLG_L1_UINT, &st->l1.Flags))
  449. FsmChangeState(fi, ST_L1_SYNC2);
  450. else
  451. #endif
  452. FsmChangeState(fi, ST_L1_F6);
  453. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  454. }
  455. static void
  456. l1_info4_ind(struct FsmInst *fi, int event, void *arg)
  457. {
  458. struct PStack *st = fi->userdata;
  459. #ifdef HISAX_UINTERFACE
  460. if (test_bit(FLG_L1_UINT, &st->l1.Flags))
  461. FsmChangeState(fi, ST_L1_TRANS);
  462. else
  463. #endif
  464. FsmChangeState(fi, ST_L1_F7);
  465. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  466. if (test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags))
  467. FsmDelTimer(&st->l1.timer, 4);
  468. if (!test_bit(FLG_L1_ACTIVATED, &st->l1.Flags)) {
  469. if (test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags))
  470. FsmDelTimer(&st->l1.timer, 3);
  471. FsmRestartTimer(&st->l1.timer, 110, EV_TIMER_ACT, NULL, 2);
  472. test_and_set_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
  473. }
  474. }
  475. static void
  476. l1_timer3(struct FsmInst *fi, int event, void *arg)
  477. {
  478. struct PStack *st = fi->userdata;
  479. test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags);
  480. if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  481. L1deactivated(st->l1.hardware);
  482. #ifdef HISAX_UINTERFACE
  483. if (!test_bit(FLG_L1_UINT, &st->l1.Flags))
  484. #endif
  485. if (st->l1.l1m.state != ST_L1_F6) {
  486. FsmChangeState(fi, ST_L1_F3);
  487. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  488. }
  489. }
  490. static void
  491. l1_timer_act(struct FsmInst *fi, int event, void *arg)
  492. {
  493. struct PStack *st = fi->userdata;
  494. test_and_clear_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
  495. test_and_set_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
  496. L1activated(st->l1.hardware);
  497. }
  498. static void
  499. l1_timer_deact(struct FsmInst *fi, int event, void *arg)
  500. {
  501. struct PStack *st = fi->userdata;
  502. test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  503. test_and_clear_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
  504. L1deactivated(st->l1.hardware);
  505. st->l1.l1hw(st, HW_DEACTIVATE | RESPONSE, NULL);
  506. }
  507. static void
  508. l1_activate_s(struct FsmInst *fi, int event, void *arg)
  509. {
  510. struct PStack *st = fi->userdata;
  511. st->l1.l1hw(st, HW_RESET | REQUEST, NULL);
  512. }
  513. static void
  514. l1_activate_no(struct FsmInst *fi, int event, void *arg)
  515. {
  516. struct PStack *st = fi->userdata;
  517. if ((!test_bit(FLG_L1_DEACTTIMER, &st->l1.Flags)) && (!test_bit(FLG_L1_T3RUN, &st->l1.Flags))) {
  518. test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
  519. L1deactivated(st->l1.hardware);
  520. }
  521. }
  522. static struct FsmNode L1SFnList[] __initdata =
  523. {
  524. {ST_L1_F3, EV_PH_ACTIVATE, l1_activate_s},
  525. {ST_L1_F6, EV_PH_ACTIVATE, l1_activate_no},
  526. {ST_L1_F8, EV_PH_ACTIVATE, l1_activate_no},
  527. {ST_L1_F3, EV_RESET_IND, l1_reset},
  528. {ST_L1_F4, EV_RESET_IND, l1_reset},
  529. {ST_L1_F5, EV_RESET_IND, l1_reset},
  530. {ST_L1_F6, EV_RESET_IND, l1_reset},
  531. {ST_L1_F7, EV_RESET_IND, l1_reset},
  532. {ST_L1_F8, EV_RESET_IND, l1_reset},
  533. {ST_L1_F3, EV_DEACT_CNF, l1_deact_cnf},
  534. {ST_L1_F4, EV_DEACT_CNF, l1_deact_cnf},
  535. {ST_L1_F5, EV_DEACT_CNF, l1_deact_cnf},
  536. {ST_L1_F6, EV_DEACT_CNF, l1_deact_cnf},
  537. {ST_L1_F7, EV_DEACT_CNF, l1_deact_cnf},
  538. {ST_L1_F8, EV_DEACT_CNF, l1_deact_cnf},
  539. {ST_L1_F6, EV_DEACT_IND, l1_deact_req_s},
  540. {ST_L1_F7, EV_DEACT_IND, l1_deact_req_s},
  541. {ST_L1_F8, EV_DEACT_IND, l1_deact_req_s},
  542. {ST_L1_F3, EV_POWER_UP, l1_power_up_s},
  543. {ST_L1_F4, EV_RSYNC_IND, l1_go_F5},
  544. {ST_L1_F6, EV_RSYNC_IND, l1_go_F8},
  545. {ST_L1_F7, EV_RSYNC_IND, l1_go_F8},
  546. {ST_L1_F3, EV_INFO2_IND, l1_info2_ind},
  547. {ST_L1_F4, EV_INFO2_IND, l1_info2_ind},
  548. {ST_L1_F5, EV_INFO2_IND, l1_info2_ind},
  549. {ST_L1_F7, EV_INFO2_IND, l1_info2_ind},
  550. {ST_L1_F8, EV_INFO2_IND, l1_info2_ind},
  551. {ST_L1_F3, EV_INFO4_IND, l1_info4_ind},
  552. {ST_L1_F4, EV_INFO4_IND, l1_info4_ind},
  553. {ST_L1_F5, EV_INFO4_IND, l1_info4_ind},
  554. {ST_L1_F6, EV_INFO4_IND, l1_info4_ind},
  555. {ST_L1_F8, EV_INFO4_IND, l1_info4_ind},
  556. {ST_L1_F3, EV_TIMER3, l1_timer3},
  557. {ST_L1_F4, EV_TIMER3, l1_timer3},
  558. {ST_L1_F5, EV_TIMER3, l1_timer3},
  559. {ST_L1_F6, EV_TIMER3, l1_timer3},
  560. {ST_L1_F8, EV_TIMER3, l1_timer3},
  561. {ST_L1_F7, EV_TIMER_ACT, l1_timer_act},
  562. {ST_L1_F3, EV_TIMER_DEACT, l1_timer_deact},
  563. {ST_L1_F4, EV_TIMER_DEACT, l1_timer_deact},
  564. {ST_L1_F5, EV_TIMER_DEACT, l1_timer_deact},
  565. {ST_L1_F6, EV_TIMER_DEACT, l1_timer_deact},
  566. {ST_L1_F7, EV_TIMER_DEACT, l1_timer_deact},
  567. {ST_L1_F8, EV_TIMER_DEACT, l1_timer_deact},
  568. };
  569. #define L1S_FN_COUNT (sizeof(L1SFnList)/sizeof(struct FsmNode))
  570. #ifdef HISAX_UINTERFACE
  571. static void
  572. l1_deact_req_u(struct FsmInst *fi, int event, void *arg)
  573. {
  574. struct PStack *st = fi->userdata;
  575. FsmChangeState(fi, ST_L1_RESET);
  576. FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
  577. test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  578. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  579. }
  580. static void
  581. l1_power_up_u(struct FsmInst *fi, int event, void *arg)
  582. {
  583. struct PStack *st = fi->userdata;
  584. FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
  585. test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
  586. }
  587. static void
  588. l1_info0_ind(struct FsmInst *fi, int event, void *arg)
  589. {
  590. FsmChangeState(fi, ST_L1_DEACT);
  591. }
  592. static void
  593. l1_activate_u(struct FsmInst *fi, int event, void *arg)
  594. {
  595. struct PStack *st = fi->userdata;
  596. st->l1.l1hw(st, HW_INFO1 | REQUEST, NULL);
  597. }
  598. static struct FsmNode L1UFnList[] __initdata =
  599. {
  600. {ST_L1_RESET, EV_DEACT_IND, l1_deact_req_u},
  601. {ST_L1_DEACT, EV_DEACT_IND, l1_deact_req_u},
  602. {ST_L1_SYNC2, EV_DEACT_IND, l1_deact_req_u},
  603. {ST_L1_TRANS, EV_DEACT_IND, l1_deact_req_u},
  604. {ST_L1_DEACT, EV_PH_ACTIVATE, l1_activate_u},
  605. {ST_L1_DEACT, EV_POWER_UP, l1_power_up_u},
  606. {ST_L1_DEACT, EV_INFO2_IND, l1_info2_ind},
  607. {ST_L1_TRANS, EV_INFO2_IND, l1_info2_ind},
  608. {ST_L1_RESET, EV_DEACT_CNF, l1_info0_ind},
  609. {ST_L1_DEACT, EV_INFO4_IND, l1_info4_ind},
  610. {ST_L1_SYNC2, EV_INFO4_IND, l1_info4_ind},
  611. {ST_L1_RESET, EV_INFO4_IND, l1_info4_ind},
  612. {ST_L1_DEACT, EV_TIMER3, l1_timer3},
  613. {ST_L1_SYNC2, EV_TIMER3, l1_timer3},
  614. {ST_L1_TRANS, EV_TIMER_ACT, l1_timer_act},
  615. {ST_L1_DEACT, EV_TIMER_DEACT, l1_timer_deact},
  616. {ST_L1_SYNC2, EV_TIMER_DEACT, l1_timer_deact},
  617. {ST_L1_RESET, EV_TIMER_DEACT, l1_timer_deact},
  618. };
  619. #define L1U_FN_COUNT (sizeof(L1UFnList)/sizeof(struct FsmNode))
  620. #endif
  621. static void
  622. l1b_activate(struct FsmInst *fi, int event, void *arg)
  623. {
  624. struct PStack *st = fi->userdata;
  625. FsmChangeState(fi, ST_L1_WAIT_ACT);
  626. FsmRestartTimer(&st->l1.timer, st->l1.delay, EV_TIMER_ACT, NULL, 2);
  627. }
  628. static void
  629. l1b_deactivate(struct FsmInst *fi, int event, void *arg)
  630. {
  631. struct PStack *st = fi->userdata;
  632. FsmChangeState(fi, ST_L1_WAIT_DEACT);
  633. FsmRestartTimer(&st->l1.timer, 10, EV_TIMER_DEACT, NULL, 2);
  634. }
  635. static void
  636. l1b_timer_act(struct FsmInst *fi, int event, void *arg)
  637. {
  638. struct PStack *st = fi->userdata;
  639. FsmChangeState(fi, ST_L1_ACTIV);
  640. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  641. }
  642. static void
  643. l1b_timer_deact(struct FsmInst *fi, int event, void *arg)
  644. {
  645. struct PStack *st = fi->userdata;
  646. FsmChangeState(fi, ST_L1_NULL);
  647. st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
  648. }
  649. static struct FsmNode L1BFnList[] __initdata =
  650. {
  651. {ST_L1_NULL, EV_PH_ACTIVATE, l1b_activate},
  652. {ST_L1_WAIT_ACT, EV_TIMER_ACT, l1b_timer_act},
  653. {ST_L1_ACTIV, EV_PH_DEACTIVATE, l1b_deactivate},
  654. {ST_L1_WAIT_DEACT, EV_TIMER_DEACT, l1b_timer_deact},
  655. };
  656. #define L1B_FN_COUNT (sizeof(L1BFnList)/sizeof(struct FsmNode))
  657. int __init
  658. Isdnl1New(void)
  659. {
  660. int retval;
  661. l1fsm_s.state_count = L1S_STATE_COUNT;
  662. l1fsm_s.event_count = L1_EVENT_COUNT;
  663. l1fsm_s.strEvent = strL1Event;
  664. l1fsm_s.strState = strL1SState;
  665. retval = FsmNew(&l1fsm_s, L1SFnList, L1S_FN_COUNT);
  666. if (retval)
  667. return retval;
  668. l1fsm_b.state_count = L1B_STATE_COUNT;
  669. l1fsm_b.event_count = L1_EVENT_COUNT;
  670. l1fsm_b.strEvent = strL1Event;
  671. l1fsm_b.strState = strL1BState;
  672. retval = FsmNew(&l1fsm_b, L1BFnList, L1B_FN_COUNT);
  673. if (retval) {
  674. FsmFree(&l1fsm_s);
  675. return retval;
  676. }
  677. #ifdef HISAX_UINTERFACE
  678. l1fsm_u.state_count = L1U_STATE_COUNT;
  679. l1fsm_u.event_count = L1_EVENT_COUNT;
  680. l1fsm_u.strEvent = strL1Event;
  681. l1fsm_u.strState = strL1UState;
  682. retval = FsmNew(&l1fsm_u, L1UFnList, L1U_FN_COUNT);
  683. if (retval) {
  684. FsmFree(&l1fsm_s);
  685. FsmFree(&l1fsm_b);
  686. return retval;
  687. }
  688. #endif
  689. return 0;
  690. }
  691. void Isdnl1Free(void)
  692. {
  693. #ifdef HISAX_UINTERFACE
  694. FsmFree(&l1fsm_u);
  695. #endif
  696. FsmFree(&l1fsm_s);
  697. FsmFree(&l1fsm_b);
  698. }
  699. static void
  700. dch_l2l1(struct PStack *st, int pr, void *arg)
  701. {
  702. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  703. switch (pr) {
  704. case (PH_DATA | REQUEST):
  705. case (PH_PULL | REQUEST):
  706. case (PH_PULL |INDICATION):
  707. st->l1.l1hw(st, pr, arg);
  708. break;
  709. case (PH_ACTIVATE | REQUEST):
  710. if (cs->debug)
  711. debugl1(cs, "PH_ACTIVATE_REQ %s",
  712. st->l1.l1m.fsm->strState[st->l1.l1m.state]);
  713. if (test_bit(FLG_L1_ACTIVATED, &st->l1.Flags))
  714. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  715. else {
  716. test_and_set_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
  717. FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, arg);
  718. }
  719. break;
  720. case (PH_TESTLOOP | REQUEST):
  721. if (1 & (long) arg)
  722. debugl1(cs, "PH_TEST_LOOP B1");
  723. if (2 & (long) arg)
  724. debugl1(cs, "PH_TEST_LOOP B2");
  725. if (!(3 & (long) arg))
  726. debugl1(cs, "PH_TEST_LOOP DISABLED");
  727. st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
  728. break;
  729. default:
  730. if (cs->debug)
  731. debugl1(cs, "dch_l2l1 msg %04X unhandled", pr);
  732. break;
  733. }
  734. }
  735. void
  736. l1_msg(struct IsdnCardState *cs, int pr, void *arg) {
  737. struct PStack *st;
  738. st = cs->stlist;
  739. while (st) {
  740. switch(pr) {
  741. case (HW_RESET | INDICATION):
  742. FsmEvent(&st->l1.l1m, EV_RESET_IND, arg);
  743. break;
  744. case (HW_DEACTIVATE | CONFIRM):
  745. FsmEvent(&st->l1.l1m, EV_DEACT_CNF, arg);
  746. break;
  747. case (HW_DEACTIVATE | INDICATION):
  748. FsmEvent(&st->l1.l1m, EV_DEACT_IND, arg);
  749. break;
  750. case (HW_POWERUP | CONFIRM):
  751. FsmEvent(&st->l1.l1m, EV_POWER_UP, arg);
  752. break;
  753. case (HW_RSYNC | INDICATION):
  754. FsmEvent(&st->l1.l1m, EV_RSYNC_IND, arg);
  755. break;
  756. case (HW_INFO2 | INDICATION):
  757. FsmEvent(&st->l1.l1m, EV_INFO2_IND, arg);
  758. break;
  759. case (HW_INFO4_P8 | INDICATION):
  760. case (HW_INFO4_P10 | INDICATION):
  761. FsmEvent(&st->l1.l1m, EV_INFO4_IND, arg);
  762. break;
  763. default:
  764. if (cs->debug)
  765. debugl1(cs, "l1msg %04X unhandled", pr);
  766. break;
  767. }
  768. st = st->next;
  769. }
  770. }
  771. void
  772. l1_msg_b(struct PStack *st, int pr, void *arg) {
  773. switch(pr) {
  774. case (PH_ACTIVATE | REQUEST):
  775. FsmEvent(&st->l1.l1m, EV_PH_ACTIVATE, NULL);
  776. break;
  777. case (PH_DEACTIVATE | REQUEST):
  778. FsmEvent(&st->l1.l1m, EV_PH_DEACTIVATE, NULL);
  779. break;
  780. }
  781. }
  782. void
  783. setstack_HiSax(struct PStack *st, struct IsdnCardState *cs)
  784. {
  785. st->l1.hardware = cs;
  786. st->protocol = cs->protocol;
  787. st->l1.l1m.fsm = &l1fsm_s;
  788. st->l1.l1m.state = ST_L1_F3;
  789. st->l1.Flags = 0;
  790. #ifdef HISAX_UINTERFACE
  791. if (test_bit(FLG_HW_L1_UINT, &cs->HW_Flags)) {
  792. st->l1.l1m.fsm = &l1fsm_u;
  793. st->l1.l1m.state = ST_L1_RESET;
  794. st->l1.Flags = FLG_L1_UINT;
  795. }
  796. #endif
  797. st->l1.l1m.debug = cs->debug;
  798. st->l1.l1m.userdata = st;
  799. st->l1.l1m.userint = 0;
  800. st->l1.l1m.printdebug = l1m_debug;
  801. FsmInitTimer(&st->l1.l1m, &st->l1.timer);
  802. setstack_tei(st);
  803. setstack_manager(st);
  804. st->l1.stlistp = &(cs->stlist);
  805. st->l2.l2l1 = dch_l2l1;
  806. if (cs->setstack_d)
  807. cs->setstack_d(st, cs);
  808. }
  809. void
  810. setstack_l1_B(struct PStack *st)
  811. {
  812. struct IsdnCardState *cs = st->l1.hardware;
  813. st->l1.l1m.fsm = &l1fsm_b;
  814. st->l1.l1m.state = ST_L1_NULL;
  815. st->l1.l1m.debug = cs->debug;
  816. st->l1.l1m.userdata = st;
  817. st->l1.l1m.userint = 0;
  818. st->l1.l1m.printdebug = l1m_debug;
  819. st->l1.Flags = 0;
  820. FsmInitTimer(&st->l1.l1m, &st->l1.timer);
  821. }