isdnl1.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  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. #include <linux/init.h>
  21. #include <linux/gfp.h>
  22. #include "hisax.h"
  23. #include "isdnl1.h"
  24. const char *l1_revision = "$Revision: 2.46.2.5 $";
  25. #define TIMER3_VALUE 7000
  26. static struct Fsm l1fsm_b;
  27. static struct Fsm l1fsm_s;
  28. enum {
  29. ST_L1_F2,
  30. ST_L1_F3,
  31. ST_L1_F4,
  32. ST_L1_F5,
  33. ST_L1_F6,
  34. ST_L1_F7,
  35. ST_L1_F8,
  36. };
  37. #define L1S_STATE_COUNT (ST_L1_F8 + 1)
  38. static char *strL1SState[] =
  39. {
  40. "ST_L1_F2",
  41. "ST_L1_F3",
  42. "ST_L1_F4",
  43. "ST_L1_F5",
  44. "ST_L1_F6",
  45. "ST_L1_F7",
  46. "ST_L1_F8",
  47. };
  48. #ifdef HISAX_UINTERFACE
  49. static
  50. struct Fsm l1fsm_u =
  51. {NULL, 0, 0, NULL, NULL};
  52. enum {
  53. ST_L1_RESET,
  54. ST_L1_DEACT,
  55. ST_L1_SYNC2,
  56. ST_L1_TRANS,
  57. };
  58. #define L1U_STATE_COUNT (ST_L1_TRANS + 1)
  59. static char *strL1UState[] =
  60. {
  61. "ST_L1_RESET",
  62. "ST_L1_DEACT",
  63. "ST_L1_SYNC2",
  64. "ST_L1_TRANS",
  65. };
  66. #endif
  67. enum {
  68. ST_L1_NULL,
  69. ST_L1_WAIT_ACT,
  70. ST_L1_WAIT_DEACT,
  71. ST_L1_ACTIV,
  72. };
  73. #define L1B_STATE_COUNT (ST_L1_ACTIV + 1)
  74. static char *strL1BState[] =
  75. {
  76. "ST_L1_NULL",
  77. "ST_L1_WAIT_ACT",
  78. "ST_L1_WAIT_DEACT",
  79. "ST_L1_ACTIV",
  80. };
  81. enum {
  82. EV_PH_ACTIVATE,
  83. EV_PH_DEACTIVATE,
  84. EV_RESET_IND,
  85. EV_DEACT_CNF,
  86. EV_DEACT_IND,
  87. EV_POWER_UP,
  88. EV_RSYNC_IND,
  89. EV_INFO2_IND,
  90. EV_INFO4_IND,
  91. EV_TIMER_DEACT,
  92. EV_TIMER_ACT,
  93. EV_TIMER3,
  94. };
  95. #define L1_EVENT_COUNT (EV_TIMER3 + 1)
  96. static char *strL1Event[] =
  97. {
  98. "EV_PH_ACTIVATE",
  99. "EV_PH_DEACTIVATE",
  100. "EV_RESET_IND",
  101. "EV_DEACT_CNF",
  102. "EV_DEACT_IND",
  103. "EV_POWER_UP",
  104. "EV_RSYNC_IND",
  105. "EV_INFO2_IND",
  106. "EV_INFO4_IND",
  107. "EV_TIMER_DEACT",
  108. "EV_TIMER_ACT",
  109. "EV_TIMER3",
  110. };
  111. void
  112. debugl1(struct IsdnCardState *cs, char *fmt, ...)
  113. {
  114. va_list args;
  115. char tmp[8];
  116. va_start(args, fmt);
  117. sprintf(tmp, "Card%d ", cs->cardnr + 1);
  118. VHiSax_putstatus(cs, tmp, fmt, args);
  119. va_end(args);
  120. }
  121. static void
  122. l1m_debug(struct FsmInst *fi, char *fmt, ...)
  123. {
  124. va_list args;
  125. struct PStack *st = fi->userdata;
  126. struct IsdnCardState *cs = st->l1.hardware;
  127. char tmp[8];
  128. va_start(args, fmt);
  129. sprintf(tmp, "Card%d ", cs->cardnr + 1);
  130. VHiSax_putstatus(cs, tmp, fmt, args);
  131. va_end(args);
  132. }
  133. static void
  134. L1activated(struct IsdnCardState *cs)
  135. {
  136. struct PStack *st;
  137. st = cs->stlist;
  138. while (st) {
  139. if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  140. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  141. else
  142. st->l1.l1l2(st, PH_ACTIVATE | INDICATION, NULL);
  143. st = st->next;
  144. }
  145. }
  146. static void
  147. L1deactivated(struct IsdnCardState *cs)
  148. {
  149. struct PStack *st;
  150. st = cs->stlist;
  151. while (st) {
  152. if (test_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  153. st->l1.l1l2(st, PH_PAUSE | CONFIRM, NULL);
  154. st->l1.l1l2(st, PH_DEACTIVATE | INDICATION, NULL);
  155. st = st->next;
  156. }
  157. test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags);
  158. }
  159. void
  160. DChannel_proc_xmt(struct IsdnCardState *cs)
  161. {
  162. struct PStack *stptr;
  163. if (cs->tx_skb)
  164. return;
  165. stptr = cs->stlist;
  166. while (stptr != NULL) {
  167. if (test_and_clear_bit(FLG_L1_PULL_REQ, &stptr->l1.Flags)) {
  168. stptr->l1.l1l2(stptr, PH_PULL | CONFIRM, NULL);
  169. break;
  170. } else
  171. stptr = stptr->next;
  172. }
  173. }
  174. void
  175. DChannel_proc_rcv(struct IsdnCardState *cs)
  176. {
  177. struct sk_buff *skb, *nskb;
  178. struct PStack *stptr = cs->stlist;
  179. int found, tei, sapi;
  180. if (stptr)
  181. if (test_bit(FLG_L1_ACTTIMER, &stptr->l1.Flags))
  182. FsmEvent(&stptr->l1.l1m, EV_TIMER_ACT, NULL);
  183. while ((skb = skb_dequeue(&cs->rq))) {
  184. #ifdef L2FRAME_DEBUG /* psa */
  185. if (cs->debug & L1_DEB_LAPD)
  186. Logl2Frame(cs, skb, "PH_DATA", 1);
  187. #endif
  188. stptr = cs->stlist;
  189. if (skb->len < 3) {
  190. debugl1(cs, "D-channel frame too short(%d)", skb->len);
  191. dev_kfree_skb(skb);
  192. return;
  193. }
  194. if ((skb->data[0] & 1) || !(skb->data[1] & 1)) {
  195. debugl1(cs, "D-channel frame wrong EA0/EA1");
  196. dev_kfree_skb(skb);
  197. return;
  198. }
  199. sapi = skb->data[0] >> 2;
  200. tei = skb->data[1] >> 1;
  201. if (cs->debug & DEB_DLOG_HEX)
  202. LogFrame(cs, skb->data, skb->len);
  203. if (cs->debug & DEB_DLOG_VERBOSE)
  204. dlogframe(cs, skb, 1);
  205. if (tei == GROUP_TEI) {
  206. if (sapi == CTRL_SAPI) { /* sapi 0 */
  207. while (stptr != NULL) {
  208. if ((nskb = skb_clone(skb, GFP_ATOMIC)))
  209. stptr->l1.l1l2(stptr, PH_DATA | INDICATION, nskb);
  210. else
  211. printk(KERN_WARNING "HiSax: isdn broadcast buffer shortage\n");
  212. stptr = stptr->next;
  213. }
  214. } else if (sapi == TEI_SAPI) {
  215. while (stptr != NULL) {
  216. if ((nskb = skb_clone(skb, GFP_ATOMIC)))
  217. stptr->l1.l1tei(stptr, PH_DATA | INDICATION, nskb);
  218. else
  219. printk(KERN_WARNING "HiSax: tei broadcast buffer shortage\n");
  220. stptr = stptr->next;
  221. }
  222. }
  223. dev_kfree_skb(skb);
  224. } else if (sapi == CTRL_SAPI) { /* sapi 0 */
  225. found = 0;
  226. while (stptr != NULL)
  227. if (tei == stptr->l2.tei) {
  228. stptr->l1.l1l2(stptr, PH_DATA | INDICATION, skb);
  229. found = !0;
  230. break;
  231. } else
  232. stptr = stptr->next;
  233. if (!found)
  234. dev_kfree_skb(skb);
  235. } else
  236. dev_kfree_skb(skb);
  237. }
  238. }
  239. static void
  240. BChannel_proc_xmt(struct BCState *bcs)
  241. {
  242. struct PStack *st = bcs->st;
  243. if (test_bit(BC_FLG_BUSY, &bcs->Flag)) {
  244. debugl1(bcs->cs, "BC_BUSY Error");
  245. return;
  246. }
  247. if (test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags))
  248. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  249. if (!test_bit(BC_FLG_ACTIV, &bcs->Flag)) {
  250. if (!test_bit(BC_FLG_BUSY, &bcs->Flag) &&
  251. skb_queue_empty(&bcs->squeue)) {
  252. st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
  253. }
  254. }
  255. }
  256. static void
  257. BChannel_proc_rcv(struct BCState *bcs)
  258. {
  259. struct sk_buff *skb;
  260. if (bcs->st->l1.l1m.state == ST_L1_WAIT_ACT) {
  261. FsmDelTimer(&bcs->st->l1.timer, 4);
  262. FsmEvent(&bcs->st->l1.l1m, EV_TIMER_ACT, NULL);
  263. }
  264. while ((skb = skb_dequeue(&bcs->rqueue))) {
  265. bcs->st->l1.l1l2(bcs->st, PH_DATA | INDICATION, skb);
  266. }
  267. }
  268. static void
  269. BChannel_proc_ack(struct BCState *bcs)
  270. {
  271. u_long flags;
  272. int ack;
  273. spin_lock_irqsave(&bcs->aclock, flags);
  274. ack = bcs->ackcnt;
  275. bcs->ackcnt = 0;
  276. spin_unlock_irqrestore(&bcs->aclock, flags);
  277. if (ack)
  278. lli_writewakeup(bcs->st, ack);
  279. }
  280. void
  281. BChannel_bh(struct work_struct *work)
  282. {
  283. struct BCState *bcs = container_of(work, struct BCState, tqueue);
  284. if (!bcs)
  285. return;
  286. if (test_and_clear_bit(B_RCVBUFREADY, &bcs->event))
  287. BChannel_proc_rcv(bcs);
  288. if (test_and_clear_bit(B_XMTBUFREADY, &bcs->event))
  289. BChannel_proc_xmt(bcs);
  290. if (test_and_clear_bit(B_ACKPENDING, &bcs->event))
  291. BChannel_proc_ack(bcs);
  292. }
  293. void
  294. HiSax_addlist(struct IsdnCardState *cs,
  295. struct PStack *st)
  296. {
  297. st->next = cs->stlist;
  298. cs->stlist = st;
  299. }
  300. void
  301. HiSax_rmlist(struct IsdnCardState *cs,
  302. struct PStack *st)
  303. {
  304. struct PStack *p;
  305. FsmDelTimer(&st->l1.timer, 0);
  306. if (cs->stlist == st)
  307. cs->stlist = st->next;
  308. else {
  309. p = cs->stlist;
  310. while (p)
  311. if (p->next == st) {
  312. p->next = st->next;
  313. return;
  314. } else
  315. p = p->next;
  316. }
  317. }
  318. void
  319. init_bcstate(struct IsdnCardState *cs, int bc)
  320. {
  321. struct BCState *bcs = cs->bcs + bc;
  322. bcs->cs = cs;
  323. bcs->channel = bc;
  324. INIT_WORK(&bcs->tqueue, BChannel_bh);
  325. spin_lock_init(&bcs->aclock);
  326. bcs->BC_SetStack = NULL;
  327. bcs->BC_Close = NULL;
  328. bcs->Flag = 0;
  329. }
  330. #ifdef L2FRAME_DEBUG /* psa */
  331. static char *
  332. l2cmd(u_char cmd)
  333. {
  334. switch (cmd & ~0x10) {
  335. case 1:
  336. return "RR";
  337. case 5:
  338. return "RNR";
  339. case 9:
  340. return "REJ";
  341. case 0x6f:
  342. return "SABME";
  343. case 0x0f:
  344. return "DM";
  345. case 3:
  346. return "UI";
  347. case 0x43:
  348. return "DISC";
  349. case 0x63:
  350. return "UA";
  351. case 0x87:
  352. return "FRMR";
  353. case 0xaf:
  354. return "XID";
  355. default:
  356. if (!(cmd & 1))
  357. return "I";
  358. else
  359. return "invalid command";
  360. }
  361. }
  362. static char tmpdeb[32];
  363. static char *
  364. l2frames(u_char *ptr)
  365. {
  366. switch (ptr[2] & ~0x10) {
  367. case 1:
  368. case 5:
  369. case 9:
  370. sprintf(tmpdeb, "%s[%d](nr %d)", l2cmd(ptr[2]), ptr[3] & 1, ptr[3] >> 1);
  371. break;
  372. case 0x6f:
  373. case 0x0f:
  374. case 3:
  375. case 0x43:
  376. case 0x63:
  377. case 0x87:
  378. case 0xaf:
  379. sprintf(tmpdeb, "%s[%d]", l2cmd(ptr[2]), (ptr[2] & 0x10) >> 4);
  380. break;
  381. default:
  382. if (!(ptr[2] & 1)) {
  383. sprintf(tmpdeb, "I[%d](ns %d, nr %d)", ptr[3] & 1, ptr[2] >> 1, ptr[3] >> 1);
  384. break;
  385. } else
  386. return "invalid command";
  387. }
  388. return tmpdeb;
  389. }
  390. void
  391. Logl2Frame(struct IsdnCardState *cs, struct sk_buff *skb, char *buf, int dir)
  392. {
  393. u_char *ptr;
  394. ptr = skb->data;
  395. if (ptr[0] & 1 || !(ptr[1] & 1))
  396. debugl1(cs, "Address not LAPD");
  397. else
  398. debugl1(cs, "%s %s: %s%c (sapi %d, tei %d)",
  399. (dir ? "<-" : "->"), buf, l2frames(ptr),
  400. ((ptr[0] & 2) >> 1) == dir ? 'C' : 'R', ptr[0] >> 2, ptr[1] >> 1);
  401. }
  402. #endif
  403. static void
  404. l1_reset(struct FsmInst *fi, int event, void *arg)
  405. {
  406. FsmChangeState(fi, ST_L1_F3);
  407. }
  408. static void
  409. l1_deact_cnf(struct FsmInst *fi, int event, void *arg)
  410. {
  411. struct PStack *st = fi->userdata;
  412. FsmChangeState(fi, ST_L1_F3);
  413. if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  414. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  415. }
  416. static void
  417. l1_deact_req_s(struct FsmInst *fi, int event, void *arg)
  418. {
  419. struct PStack *st = fi->userdata;
  420. FsmChangeState(fi, ST_L1_F3);
  421. FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
  422. test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  423. }
  424. static void
  425. l1_power_up_s(struct FsmInst *fi, int event, void *arg)
  426. {
  427. struct PStack *st = fi->userdata;
  428. if (test_bit(FLG_L1_ACTIVATING, &st->l1.Flags)) {
  429. FsmChangeState(fi, ST_L1_F4);
  430. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  431. FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
  432. test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
  433. } else
  434. FsmChangeState(fi, ST_L1_F3);
  435. }
  436. static void
  437. l1_go_F5(struct FsmInst *fi, int event, void *arg)
  438. {
  439. FsmChangeState(fi, ST_L1_F5);
  440. }
  441. static void
  442. l1_go_F8(struct FsmInst *fi, int event, void *arg)
  443. {
  444. FsmChangeState(fi, ST_L1_F8);
  445. }
  446. static void
  447. l1_info2_ind(struct FsmInst *fi, int event, void *arg)
  448. {
  449. struct PStack *st = fi->userdata;
  450. #ifdef HISAX_UINTERFACE
  451. if (test_bit(FLG_L1_UINT, &st->l1.Flags))
  452. FsmChangeState(fi, ST_L1_SYNC2);
  453. else
  454. #endif
  455. FsmChangeState(fi, ST_L1_F6);
  456. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  457. }
  458. static void
  459. l1_info4_ind(struct FsmInst *fi, int event, void *arg)
  460. {
  461. struct PStack *st = fi->userdata;
  462. #ifdef HISAX_UINTERFACE
  463. if (test_bit(FLG_L1_UINT, &st->l1.Flags))
  464. FsmChangeState(fi, ST_L1_TRANS);
  465. else
  466. #endif
  467. FsmChangeState(fi, ST_L1_F7);
  468. st->l1.l1hw(st, HW_INFO3 | REQUEST, NULL);
  469. if (test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags))
  470. FsmDelTimer(&st->l1.timer, 4);
  471. if (!test_bit(FLG_L1_ACTIVATED, &st->l1.Flags)) {
  472. if (test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags))
  473. FsmDelTimer(&st->l1.timer, 3);
  474. FsmRestartTimer(&st->l1.timer, 110, EV_TIMER_ACT, NULL, 2);
  475. test_and_set_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
  476. }
  477. }
  478. static void
  479. l1_timer3(struct FsmInst *fi, int event, void *arg)
  480. {
  481. struct PStack *st = fi->userdata;
  482. test_and_clear_bit(FLG_L1_T3RUN, &st->l1.Flags);
  483. if (test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags))
  484. L1deactivated(st->l1.hardware);
  485. #ifdef HISAX_UINTERFACE
  486. if (!test_bit(FLG_L1_UINT, &st->l1.Flags))
  487. #endif
  488. if (st->l1.l1m.state != ST_L1_F6) {
  489. FsmChangeState(fi, ST_L1_F3);
  490. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  491. }
  492. }
  493. static void
  494. l1_timer_act(struct FsmInst *fi, int event, void *arg)
  495. {
  496. struct PStack *st = fi->userdata;
  497. test_and_clear_bit(FLG_L1_ACTTIMER, &st->l1.Flags);
  498. test_and_set_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
  499. L1activated(st->l1.hardware);
  500. }
  501. static void
  502. l1_timer_deact(struct FsmInst *fi, int event, void *arg)
  503. {
  504. struct PStack *st = fi->userdata;
  505. test_and_clear_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  506. test_and_clear_bit(FLG_L1_ACTIVATED, &st->l1.Flags);
  507. L1deactivated(st->l1.hardware);
  508. st->l1.l1hw(st, HW_DEACTIVATE | RESPONSE, NULL);
  509. }
  510. static void
  511. l1_activate_s(struct FsmInst *fi, int event, void *arg)
  512. {
  513. struct PStack *st = fi->userdata;
  514. st->l1.l1hw(st, HW_RESET | REQUEST, NULL);
  515. }
  516. static void
  517. l1_activate_no(struct FsmInst *fi, int event, void *arg)
  518. {
  519. struct PStack *st = fi->userdata;
  520. if ((!test_bit(FLG_L1_DEACTTIMER, &st->l1.Flags)) && (!test_bit(FLG_L1_T3RUN, &st->l1.Flags))) {
  521. test_and_clear_bit(FLG_L1_ACTIVATING, &st->l1.Flags);
  522. L1deactivated(st->l1.hardware);
  523. }
  524. }
  525. static struct FsmNode L1SFnList[] __initdata =
  526. {
  527. {ST_L1_F3, EV_PH_ACTIVATE, l1_activate_s},
  528. {ST_L1_F6, EV_PH_ACTIVATE, l1_activate_no},
  529. {ST_L1_F8, EV_PH_ACTIVATE, l1_activate_no},
  530. {ST_L1_F3, EV_RESET_IND, l1_reset},
  531. {ST_L1_F4, EV_RESET_IND, l1_reset},
  532. {ST_L1_F5, EV_RESET_IND, l1_reset},
  533. {ST_L1_F6, EV_RESET_IND, l1_reset},
  534. {ST_L1_F7, EV_RESET_IND, l1_reset},
  535. {ST_L1_F8, EV_RESET_IND, l1_reset},
  536. {ST_L1_F3, EV_DEACT_CNF, l1_deact_cnf},
  537. {ST_L1_F4, EV_DEACT_CNF, l1_deact_cnf},
  538. {ST_L1_F5, EV_DEACT_CNF, l1_deact_cnf},
  539. {ST_L1_F6, EV_DEACT_CNF, l1_deact_cnf},
  540. {ST_L1_F7, EV_DEACT_CNF, l1_deact_cnf},
  541. {ST_L1_F8, EV_DEACT_CNF, l1_deact_cnf},
  542. {ST_L1_F6, EV_DEACT_IND, l1_deact_req_s},
  543. {ST_L1_F7, EV_DEACT_IND, l1_deact_req_s},
  544. {ST_L1_F8, EV_DEACT_IND, l1_deact_req_s},
  545. {ST_L1_F3, EV_POWER_UP, l1_power_up_s},
  546. {ST_L1_F4, EV_RSYNC_IND, l1_go_F5},
  547. {ST_L1_F6, EV_RSYNC_IND, l1_go_F8},
  548. {ST_L1_F7, EV_RSYNC_IND, l1_go_F8},
  549. {ST_L1_F3, EV_INFO2_IND, l1_info2_ind},
  550. {ST_L1_F4, EV_INFO2_IND, l1_info2_ind},
  551. {ST_L1_F5, EV_INFO2_IND, l1_info2_ind},
  552. {ST_L1_F7, EV_INFO2_IND, l1_info2_ind},
  553. {ST_L1_F8, EV_INFO2_IND, l1_info2_ind},
  554. {ST_L1_F3, EV_INFO4_IND, l1_info4_ind},
  555. {ST_L1_F4, EV_INFO4_IND, l1_info4_ind},
  556. {ST_L1_F5, EV_INFO4_IND, l1_info4_ind},
  557. {ST_L1_F6, EV_INFO4_IND, l1_info4_ind},
  558. {ST_L1_F8, EV_INFO4_IND, l1_info4_ind},
  559. {ST_L1_F3, EV_TIMER3, l1_timer3},
  560. {ST_L1_F4, EV_TIMER3, l1_timer3},
  561. {ST_L1_F5, EV_TIMER3, l1_timer3},
  562. {ST_L1_F6, EV_TIMER3, l1_timer3},
  563. {ST_L1_F8, EV_TIMER3, l1_timer3},
  564. {ST_L1_F7, EV_TIMER_ACT, l1_timer_act},
  565. {ST_L1_F3, EV_TIMER_DEACT, l1_timer_deact},
  566. {ST_L1_F4, EV_TIMER_DEACT, l1_timer_deact},
  567. {ST_L1_F5, EV_TIMER_DEACT, l1_timer_deact},
  568. {ST_L1_F6, EV_TIMER_DEACT, l1_timer_deact},
  569. {ST_L1_F7, EV_TIMER_DEACT, l1_timer_deact},
  570. {ST_L1_F8, EV_TIMER_DEACT, l1_timer_deact},
  571. };
  572. #ifdef HISAX_UINTERFACE
  573. static void
  574. l1_deact_req_u(struct FsmInst *fi, int event, void *arg)
  575. {
  576. struct PStack *st = fi->userdata;
  577. FsmChangeState(fi, ST_L1_RESET);
  578. FsmRestartTimer(&st->l1.timer, 550, EV_TIMER_DEACT, NULL, 2);
  579. test_and_set_bit(FLG_L1_DEACTTIMER, &st->l1.Flags);
  580. st->l1.l1hw(st, HW_ENABLE | REQUEST, NULL);
  581. }
  582. static void
  583. l1_power_up_u(struct FsmInst *fi, int event, void *arg)
  584. {
  585. struct PStack *st = fi->userdata;
  586. FsmRestartTimer(&st->l1.timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
  587. test_and_set_bit(FLG_L1_T3RUN, &st->l1.Flags);
  588. }
  589. static void
  590. l1_info0_ind(struct FsmInst *fi, int event, void *arg)
  591. {
  592. FsmChangeState(fi, ST_L1_DEACT);
  593. }
  594. static void
  595. l1_activate_u(struct FsmInst *fi, int event, void *arg)
  596. {
  597. struct PStack *st = fi->userdata;
  598. st->l1.l1hw(st, HW_INFO1 | REQUEST, NULL);
  599. }
  600. static struct FsmNode L1UFnList[] __initdata =
  601. {
  602. {ST_L1_RESET, EV_DEACT_IND, l1_deact_req_u},
  603. {ST_L1_DEACT, EV_DEACT_IND, l1_deact_req_u},
  604. {ST_L1_SYNC2, EV_DEACT_IND, l1_deact_req_u},
  605. {ST_L1_TRANS, EV_DEACT_IND, l1_deact_req_u},
  606. {ST_L1_DEACT, EV_PH_ACTIVATE, l1_activate_u},
  607. {ST_L1_DEACT, EV_POWER_UP, l1_power_up_u},
  608. {ST_L1_DEACT, EV_INFO2_IND, l1_info2_ind},
  609. {ST_L1_TRANS, EV_INFO2_IND, l1_info2_ind},
  610. {ST_L1_RESET, EV_DEACT_CNF, l1_info0_ind},
  611. {ST_L1_DEACT, EV_INFO4_IND, l1_info4_ind},
  612. {ST_L1_SYNC2, EV_INFO4_IND, l1_info4_ind},
  613. {ST_L1_RESET, EV_INFO4_IND, l1_info4_ind},
  614. {ST_L1_DEACT, EV_TIMER3, l1_timer3},
  615. {ST_L1_SYNC2, EV_TIMER3, l1_timer3},
  616. {ST_L1_TRANS, EV_TIMER_ACT, l1_timer_act},
  617. {ST_L1_DEACT, EV_TIMER_DEACT, l1_timer_deact},
  618. {ST_L1_SYNC2, EV_TIMER_DEACT, l1_timer_deact},
  619. {ST_L1_RESET, EV_TIMER_DEACT, l1_timer_deact},
  620. };
  621. #endif
  622. static void
  623. l1b_activate(struct FsmInst *fi, int event, void *arg)
  624. {
  625. struct PStack *st = fi->userdata;
  626. FsmChangeState(fi, ST_L1_WAIT_ACT);
  627. FsmRestartTimer(&st->l1.timer, st->l1.delay, EV_TIMER_ACT, NULL, 2);
  628. }
  629. static void
  630. l1b_deactivate(struct FsmInst *fi, int event, void *arg)
  631. {
  632. struct PStack *st = fi->userdata;
  633. FsmChangeState(fi, ST_L1_WAIT_DEACT);
  634. FsmRestartTimer(&st->l1.timer, 10, EV_TIMER_DEACT, NULL, 2);
  635. }
  636. static void
  637. l1b_timer_act(struct FsmInst *fi, int event, void *arg)
  638. {
  639. struct PStack *st = fi->userdata;
  640. FsmChangeState(fi, ST_L1_ACTIV);
  641. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  642. }
  643. static void
  644. l1b_timer_deact(struct FsmInst *fi, int event, void *arg)
  645. {
  646. struct PStack *st = fi->userdata;
  647. FsmChangeState(fi, ST_L1_NULL);
  648. st->l2.l2l1(st, PH_DEACTIVATE | CONFIRM, NULL);
  649. }
  650. static struct FsmNode L1BFnList[] __initdata =
  651. {
  652. {ST_L1_NULL, EV_PH_ACTIVATE, l1b_activate},
  653. {ST_L1_WAIT_ACT, EV_TIMER_ACT, l1b_timer_act},
  654. {ST_L1_ACTIV, EV_PH_DEACTIVATE, l1b_deactivate},
  655. {ST_L1_WAIT_DEACT, EV_TIMER_DEACT, l1b_timer_deact},
  656. };
  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, ARRAY_SIZE(L1SFnList));
  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, ARRAY_SIZE(L1BFnList));
  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, ARRAY_SIZE(L1UFnList));
  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, "%s %04X unhandled", __func__, 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. }