hfc_2bs0.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /* $Id: hfc_2bs0.c,v 1.20.2.6 2004/02/11 13:21:33 keil Exp $
  2. *
  3. * specific routines for CCD's HFC 2BS0
  4. *
  5. * Author Karsten Keil
  6. * Copyright by Karsten Keil <keil@isdn4linux.de>
  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. */
  12. #include <linux/init.h>
  13. #include "hisax.h"
  14. #include "hfc_2bs0.h"
  15. #include "isac.h"
  16. #include "isdnl1.h"
  17. #include <linux/interrupt.h>
  18. #include <linux/slab.h>
  19. static inline int
  20. WaitForBusy(struct IsdnCardState *cs)
  21. {
  22. int to = 130;
  23. u_char val;
  24. while (!(cs->BC_Read_Reg(cs, HFC_STATUS, 0) & HFC_BUSY) && to) {
  25. val = cs->BC_Read_Reg(cs, HFC_DATA, HFC_CIP | HFC_F2 |
  26. (cs->hw.hfc.cip & 3));
  27. udelay(1);
  28. to--;
  29. }
  30. if (!to) {
  31. printk(KERN_WARNING "HiSax: %s timeout\n", __func__);
  32. return (0);
  33. } else
  34. return (to);
  35. }
  36. static inline int
  37. WaitNoBusy(struct IsdnCardState *cs)
  38. {
  39. int to = 125;
  40. while ((cs->BC_Read_Reg(cs, HFC_STATUS, 0) & HFC_BUSY) && to) {
  41. udelay(1);
  42. to--;
  43. }
  44. if (!to) {
  45. printk(KERN_WARNING "HiSax: waitforBusy timeout\n");
  46. return (0);
  47. } else
  48. return (to);
  49. }
  50. static int
  51. GetFreeFifoBytes(struct BCState *bcs)
  52. {
  53. int s;
  54. if (bcs->hw.hfc.f1 == bcs->hw.hfc.f2)
  55. return (bcs->cs->hw.hfc.fifosize);
  56. s = bcs->hw.hfc.send[bcs->hw.hfc.f1] - bcs->hw.hfc.send[bcs->hw.hfc.f2];
  57. if (s <= 0)
  58. s += bcs->cs->hw.hfc.fifosize;
  59. s = bcs->cs->hw.hfc.fifosize - s;
  60. return (s);
  61. }
  62. static int
  63. ReadZReg(struct BCState *bcs, u_char reg)
  64. {
  65. int val;
  66. WaitNoBusy(bcs->cs);
  67. val = 256 * bcs->cs->BC_Read_Reg(bcs->cs, HFC_DATA, reg | HFC_CIP | HFC_Z_HIGH);
  68. WaitNoBusy(bcs->cs);
  69. val += bcs->cs->BC_Read_Reg(bcs->cs, HFC_DATA, reg | HFC_CIP | HFC_Z_LOW);
  70. return (val);
  71. }
  72. static void
  73. hfc_clear_fifo(struct BCState *bcs)
  74. {
  75. struct IsdnCardState *cs = bcs->cs;
  76. int idx, cnt;
  77. int rcnt, z1, z2;
  78. u_char cip, f1, f2;
  79. if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
  80. debugl1(cs, "hfc_clear_fifo");
  81. cip = HFC_CIP | HFC_F1 | HFC_REC | HFC_CHANNEL(bcs->channel);
  82. if ((cip & 0xc3) != (cs->hw.hfc.cip & 0xc3)) {
  83. cs->BC_Write_Reg(cs, HFC_STATUS, cip, cip);
  84. WaitForBusy(cs);
  85. }
  86. WaitNoBusy(cs);
  87. f1 = cs->BC_Read_Reg(cs, HFC_DATA, cip);
  88. cip = HFC_CIP | HFC_F2 | HFC_REC | HFC_CHANNEL(bcs->channel);
  89. WaitNoBusy(cs);
  90. f2 = cs->BC_Read_Reg(cs, HFC_DATA, cip);
  91. z1 = ReadZReg(bcs, HFC_Z1 | HFC_REC | HFC_CHANNEL(bcs->channel));
  92. z2 = ReadZReg(bcs, HFC_Z2 | HFC_REC | HFC_CHANNEL(bcs->channel));
  93. cnt = 32;
  94. while (((f1 != f2) || (z1 != z2)) && cnt--) {
  95. if (cs->debug & L1_DEB_HSCX)
  96. debugl1(cs, "hfc clear %d f1(%d) f2(%d)",
  97. bcs->channel, f1, f2);
  98. rcnt = z1 - z2;
  99. if (rcnt < 0)
  100. rcnt += cs->hw.hfc.fifosize;
  101. if (rcnt)
  102. rcnt++;
  103. if (cs->debug & L1_DEB_HSCX)
  104. debugl1(cs, "hfc clear %d z1(%x) z2(%x) cnt(%d)",
  105. bcs->channel, z1, z2, rcnt);
  106. cip = HFC_CIP | HFC_FIFO_OUT | HFC_REC | HFC_CHANNEL(bcs->channel);
  107. idx = 0;
  108. while ((idx < rcnt) && WaitNoBusy(cs)) {
  109. cs->BC_Read_Reg(cs, HFC_DATA_NODEB, cip);
  110. idx++;
  111. }
  112. if (f1 != f2) {
  113. WaitNoBusy(cs);
  114. cs->BC_Read_Reg(cs, HFC_DATA, HFC_CIP | HFC_F2_INC | HFC_REC |
  115. HFC_CHANNEL(bcs->channel));
  116. WaitForBusy(cs);
  117. }
  118. cip = HFC_CIP | HFC_F1 | HFC_REC | HFC_CHANNEL(bcs->channel);
  119. WaitNoBusy(cs);
  120. f1 = cs->BC_Read_Reg(cs, HFC_DATA, cip);
  121. cip = HFC_CIP | HFC_F2 | HFC_REC | HFC_CHANNEL(bcs->channel);
  122. WaitNoBusy(cs);
  123. f2 = cs->BC_Read_Reg(cs, HFC_DATA, cip);
  124. z1 = ReadZReg(bcs, HFC_Z1 | HFC_REC | HFC_CHANNEL(bcs->channel));
  125. z2 = ReadZReg(bcs, HFC_Z2 | HFC_REC | HFC_CHANNEL(bcs->channel));
  126. }
  127. return;
  128. }
  129. static struct sk_buff
  130. *
  131. hfc_empty_fifo(struct BCState *bcs, int count)
  132. {
  133. u_char *ptr;
  134. struct sk_buff *skb;
  135. struct IsdnCardState *cs = bcs->cs;
  136. int idx;
  137. int chksum;
  138. u_char stat, cip;
  139. if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
  140. debugl1(cs, "hfc_empty_fifo");
  141. idx = 0;
  142. if (count > HSCX_BUFMAX + 3) {
  143. if (cs->debug & L1_DEB_WARN)
  144. debugl1(cs, "hfc_empty_fifo: incoming packet too large");
  145. cip = HFC_CIP | HFC_FIFO_OUT | HFC_REC | HFC_CHANNEL(bcs->channel);
  146. while ((idx++ < count) && WaitNoBusy(cs))
  147. cs->BC_Read_Reg(cs, HFC_DATA_NODEB, cip);
  148. WaitNoBusy(cs);
  149. stat = cs->BC_Read_Reg(cs, HFC_DATA, HFC_CIP | HFC_F2_INC | HFC_REC |
  150. HFC_CHANNEL(bcs->channel));
  151. WaitForBusy(cs);
  152. return (NULL);
  153. }
  154. if ((count < 4) && (bcs->mode != L1_MODE_TRANS)) {
  155. if (cs->debug & L1_DEB_WARN)
  156. debugl1(cs, "hfc_empty_fifo: incoming packet too small");
  157. cip = HFC_CIP | HFC_FIFO_OUT | HFC_REC | HFC_CHANNEL(bcs->channel);
  158. while ((idx++ < count) && WaitNoBusy(cs))
  159. cs->BC_Read_Reg(cs, HFC_DATA_NODEB, cip);
  160. WaitNoBusy(cs);
  161. stat = cs->BC_Read_Reg(cs, HFC_DATA, HFC_CIP | HFC_F2_INC | HFC_REC |
  162. HFC_CHANNEL(bcs->channel));
  163. WaitForBusy(cs);
  164. #ifdef ERROR_STATISTIC
  165. bcs->err_inv++;
  166. #endif
  167. return (NULL);
  168. }
  169. if (bcs->mode == L1_MODE_TRANS)
  170. count -= 1;
  171. else
  172. count -= 3;
  173. if (!(skb = dev_alloc_skb(count)))
  174. printk(KERN_WARNING "HFC: receive out of memory\n");
  175. else {
  176. ptr = skb_put(skb, count);
  177. idx = 0;
  178. cip = HFC_CIP | HFC_FIFO_OUT | HFC_REC | HFC_CHANNEL(bcs->channel);
  179. while ((idx < count) && WaitNoBusy(cs)) {
  180. *ptr++ = cs->BC_Read_Reg(cs, HFC_DATA_NODEB, cip);
  181. idx++;
  182. }
  183. if (idx != count) {
  184. debugl1(cs, "RFIFO BUSY error");
  185. printk(KERN_WARNING "HFC FIFO channel %d BUSY Error\n", bcs->channel);
  186. dev_kfree_skb_any(skb);
  187. if (bcs->mode != L1_MODE_TRANS) {
  188. WaitNoBusy(cs);
  189. stat = cs->BC_Read_Reg(cs, HFC_DATA, HFC_CIP | HFC_F2_INC | HFC_REC |
  190. HFC_CHANNEL(bcs->channel));
  191. WaitForBusy(cs);
  192. }
  193. return (NULL);
  194. }
  195. if (bcs->mode != L1_MODE_TRANS) {
  196. WaitNoBusy(cs);
  197. chksum = (cs->BC_Read_Reg(cs, HFC_DATA, cip) << 8);
  198. WaitNoBusy(cs);
  199. chksum += cs->BC_Read_Reg(cs, HFC_DATA, cip);
  200. WaitNoBusy(cs);
  201. stat = cs->BC_Read_Reg(cs, HFC_DATA, cip);
  202. if (cs->debug & L1_DEB_HSCX)
  203. debugl1(cs, "hfc_empty_fifo %d chksum %x stat %x",
  204. bcs->channel, chksum, stat);
  205. if (stat) {
  206. debugl1(cs, "FIFO CRC error");
  207. dev_kfree_skb_any(skb);
  208. skb = NULL;
  209. #ifdef ERROR_STATISTIC
  210. bcs->err_crc++;
  211. #endif
  212. }
  213. WaitNoBusy(cs);
  214. stat = cs->BC_Read_Reg(cs, HFC_DATA, HFC_CIP | HFC_F2_INC | HFC_REC |
  215. HFC_CHANNEL(bcs->channel));
  216. WaitForBusy(cs);
  217. }
  218. }
  219. return (skb);
  220. }
  221. static void
  222. hfc_fill_fifo(struct BCState *bcs)
  223. {
  224. struct IsdnCardState *cs = bcs->cs;
  225. int idx, fcnt;
  226. int count;
  227. int z1, z2;
  228. u_char cip;
  229. if (!bcs->tx_skb)
  230. return;
  231. if (bcs->tx_skb->len <= 0)
  232. return;
  233. cip = HFC_CIP | HFC_F1 | HFC_SEND | HFC_CHANNEL(bcs->channel);
  234. if ((cip & 0xc3) != (cs->hw.hfc.cip & 0xc3)) {
  235. cs->BC_Write_Reg(cs, HFC_STATUS, cip, cip);
  236. WaitForBusy(cs);
  237. }
  238. WaitNoBusy(cs);
  239. if (bcs->mode != L1_MODE_TRANS) {
  240. bcs->hw.hfc.f1 = cs->BC_Read_Reg(cs, HFC_DATA, cip);
  241. cip = HFC_CIP | HFC_F2 | HFC_SEND | HFC_CHANNEL(bcs->channel);
  242. WaitNoBusy(cs);
  243. bcs->hw.hfc.f2 = cs->BC_Read_Reg(cs, HFC_DATA, cip);
  244. bcs->hw.hfc.send[bcs->hw.hfc.f1] = ReadZReg(bcs, HFC_Z1 | HFC_SEND | HFC_CHANNEL(bcs->channel));
  245. if (cs->debug & L1_DEB_HSCX)
  246. debugl1(cs, "hfc_fill_fifo %d f1(%d) f2(%d) z1(%x)",
  247. bcs->channel, bcs->hw.hfc.f1, bcs->hw.hfc.f2,
  248. bcs->hw.hfc.send[bcs->hw.hfc.f1]);
  249. fcnt = bcs->hw.hfc.f1 - bcs->hw.hfc.f2;
  250. if (fcnt < 0)
  251. fcnt += 32;
  252. if (fcnt > 30) {
  253. if (cs->debug & L1_DEB_HSCX)
  254. debugl1(cs, "hfc_fill_fifo more as 30 frames");
  255. return;
  256. }
  257. count = GetFreeFifoBytes(bcs);
  258. }
  259. else {
  260. WaitForBusy(cs);
  261. z1 = ReadZReg(bcs, HFC_Z1 | HFC_REC | HFC_CHANNEL(bcs->channel));
  262. z2 = ReadZReg(bcs, HFC_Z2 | HFC_REC | HFC_CHANNEL(bcs->channel));
  263. count = z1 - z2;
  264. if (count < 0)
  265. count += cs->hw.hfc.fifosize;
  266. } /* L1_MODE_TRANS */
  267. if (cs->debug & L1_DEB_HSCX)
  268. debugl1(cs, "hfc_fill_fifo %d count(%u/%d)",
  269. bcs->channel, bcs->tx_skb->len,
  270. count);
  271. if (count < bcs->tx_skb->len) {
  272. if (cs->debug & L1_DEB_HSCX)
  273. debugl1(cs, "hfc_fill_fifo no fifo mem");
  274. return;
  275. }
  276. cip = HFC_CIP | HFC_FIFO_IN | HFC_SEND | HFC_CHANNEL(bcs->channel);
  277. idx = 0;
  278. while ((idx < bcs->tx_skb->len) && WaitNoBusy(cs))
  279. cs->BC_Write_Reg(cs, HFC_DATA_NODEB, cip, bcs->tx_skb->data[idx++]);
  280. if (idx != bcs->tx_skb->len) {
  281. debugl1(cs, "FIFO Send BUSY error");
  282. printk(KERN_WARNING "HFC S FIFO channel %d BUSY Error\n", bcs->channel);
  283. } else {
  284. count = bcs->tx_skb->len;
  285. bcs->tx_cnt -= count;
  286. if (PACKET_NOACK == bcs->tx_skb->pkt_type)
  287. count = -1;
  288. dev_kfree_skb_any(bcs->tx_skb);
  289. bcs->tx_skb = NULL;
  290. if (bcs->mode != L1_MODE_TRANS) {
  291. WaitForBusy(cs);
  292. WaitNoBusy(cs);
  293. cs->BC_Read_Reg(cs, HFC_DATA, HFC_CIP | HFC_F1_INC | HFC_SEND | HFC_CHANNEL(bcs->channel));
  294. }
  295. if (test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
  296. (count >= 0)) {
  297. u_long flags;
  298. spin_lock_irqsave(&bcs->aclock, flags);
  299. bcs->ackcnt += count;
  300. spin_unlock_irqrestore(&bcs->aclock, flags);
  301. schedule_event(bcs, B_ACKPENDING);
  302. }
  303. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  304. }
  305. return;
  306. }
  307. void
  308. main_irq_hfc(struct BCState *bcs)
  309. {
  310. struct IsdnCardState *cs = bcs->cs;
  311. int z1, z2, rcnt;
  312. u_char f1, f2, cip;
  313. int receive, transmit, count = 5;
  314. struct sk_buff *skb;
  315. Begin:
  316. count--;
  317. cip = HFC_CIP | HFC_F1 | HFC_REC | HFC_CHANNEL(bcs->channel);
  318. if ((cip & 0xc3) != (cs->hw.hfc.cip & 0xc3)) {
  319. cs->BC_Write_Reg(cs, HFC_STATUS, cip, cip);
  320. WaitForBusy(cs);
  321. }
  322. WaitNoBusy(cs);
  323. receive = 0;
  324. if (bcs->mode == L1_MODE_HDLC) {
  325. f1 = cs->BC_Read_Reg(cs, HFC_DATA, cip);
  326. cip = HFC_CIP | HFC_F2 | HFC_REC | HFC_CHANNEL(bcs->channel);
  327. WaitNoBusy(cs);
  328. f2 = cs->BC_Read_Reg(cs, HFC_DATA, cip);
  329. if (f1 != f2) {
  330. if (cs->debug & L1_DEB_HSCX)
  331. debugl1(cs, "hfc rec %d f1(%d) f2(%d)",
  332. bcs->channel, f1, f2);
  333. receive = 1;
  334. }
  335. }
  336. if (receive || (bcs->mode == L1_MODE_TRANS)) {
  337. WaitForBusy(cs);
  338. z1 = ReadZReg(bcs, HFC_Z1 | HFC_REC | HFC_CHANNEL(bcs->channel));
  339. z2 = ReadZReg(bcs, HFC_Z2 | HFC_REC | HFC_CHANNEL(bcs->channel));
  340. rcnt = z1 - z2;
  341. if (rcnt < 0)
  342. rcnt += cs->hw.hfc.fifosize;
  343. if ((bcs->mode == L1_MODE_HDLC) || (rcnt)) {
  344. rcnt++;
  345. if (cs->debug & L1_DEB_HSCX)
  346. debugl1(cs, "hfc rec %d z1(%x) z2(%x) cnt(%d)",
  347. bcs->channel, z1, z2, rcnt);
  348. /* sti(); */
  349. if ((skb = hfc_empty_fifo(bcs, rcnt))) {
  350. skb_queue_tail(&bcs->rqueue, skb);
  351. schedule_event(bcs, B_RCVBUFREADY);
  352. }
  353. }
  354. receive = 1;
  355. }
  356. if (bcs->tx_skb) {
  357. transmit = 1;
  358. test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  359. hfc_fill_fifo(bcs);
  360. if (test_bit(BC_FLG_BUSY, &bcs->Flag))
  361. transmit = 0;
  362. } else {
  363. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  364. transmit = 1;
  365. test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  366. hfc_fill_fifo(bcs);
  367. if (test_bit(BC_FLG_BUSY, &bcs->Flag))
  368. transmit = 0;
  369. } else {
  370. transmit = 0;
  371. schedule_event(bcs, B_XMTBUFREADY);
  372. }
  373. }
  374. if ((receive || transmit) && count)
  375. goto Begin;
  376. return;
  377. }
  378. static void
  379. mode_hfc(struct BCState *bcs, int mode, int bc)
  380. {
  381. struct IsdnCardState *cs = bcs->cs;
  382. if (cs->debug & L1_DEB_HSCX)
  383. debugl1(cs, "HFC 2BS0 mode %d bchan %d/%d",
  384. mode, bc, bcs->channel);
  385. bcs->mode = mode;
  386. bcs->channel = bc;
  387. switch (mode) {
  388. case (L1_MODE_NULL):
  389. if (bc) {
  390. cs->hw.hfc.ctmt &= ~1;
  391. cs->hw.hfc.isac_spcr &= ~0x03;
  392. }
  393. else {
  394. cs->hw.hfc.ctmt &= ~2;
  395. cs->hw.hfc.isac_spcr &= ~0x0c;
  396. }
  397. break;
  398. case (L1_MODE_TRANS):
  399. cs->hw.hfc.ctmt &= ~(1 << bc); /* set HDLC mode */
  400. cs->BC_Write_Reg(cs, HFC_STATUS, cs->hw.hfc.ctmt, cs->hw.hfc.ctmt);
  401. hfc_clear_fifo(bcs); /* complete fifo clear */
  402. if (bc) {
  403. cs->hw.hfc.ctmt |= 1;
  404. cs->hw.hfc.isac_spcr &= ~0x03;
  405. cs->hw.hfc.isac_spcr |= 0x02;
  406. } else {
  407. cs->hw.hfc.ctmt |= 2;
  408. cs->hw.hfc.isac_spcr &= ~0x0c;
  409. cs->hw.hfc.isac_spcr |= 0x08;
  410. }
  411. break;
  412. case (L1_MODE_HDLC):
  413. if (bc) {
  414. cs->hw.hfc.ctmt &= ~1;
  415. cs->hw.hfc.isac_spcr &= ~0x03;
  416. cs->hw.hfc.isac_spcr |= 0x02;
  417. } else {
  418. cs->hw.hfc.ctmt &= ~2;
  419. cs->hw.hfc.isac_spcr &= ~0x0c;
  420. cs->hw.hfc.isac_spcr |= 0x08;
  421. }
  422. break;
  423. }
  424. cs->BC_Write_Reg(cs, HFC_STATUS, cs->hw.hfc.ctmt, cs->hw.hfc.ctmt);
  425. cs->writeisac(cs, ISAC_SPCR, cs->hw.hfc.isac_spcr);
  426. if (mode == L1_MODE_HDLC)
  427. hfc_clear_fifo(bcs);
  428. }
  429. static void
  430. hfc_l2l1(struct PStack *st, int pr, void *arg)
  431. {
  432. struct BCState *bcs = st->l1.bcs;
  433. struct sk_buff *skb = arg;
  434. u_long flags;
  435. switch (pr) {
  436. case (PH_DATA | REQUEST):
  437. spin_lock_irqsave(&bcs->cs->lock, flags);
  438. if (bcs->tx_skb) {
  439. skb_queue_tail(&bcs->squeue, skb);
  440. } else {
  441. bcs->tx_skb = skb;
  442. test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  443. bcs->cs->BC_Send_Data(bcs);
  444. }
  445. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  446. break;
  447. case (PH_PULL | INDICATION):
  448. spin_lock_irqsave(&bcs->cs->lock, flags);
  449. if (bcs->tx_skb) {
  450. printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
  451. } else {
  452. test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  453. bcs->tx_skb = skb;
  454. bcs->cs->BC_Send_Data(bcs);
  455. }
  456. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  457. break;
  458. case (PH_PULL | REQUEST):
  459. if (!bcs->tx_skb) {
  460. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  461. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  462. } else
  463. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  464. break;
  465. case (PH_ACTIVATE | REQUEST):
  466. spin_lock_irqsave(&bcs->cs->lock, flags);
  467. test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
  468. mode_hfc(bcs, st->l1.mode, st->l1.bc);
  469. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  470. l1_msg_b(st, pr, arg);
  471. break;
  472. case (PH_DEACTIVATE | REQUEST):
  473. l1_msg_b(st, pr, arg);
  474. break;
  475. case (PH_DEACTIVATE | CONFIRM):
  476. spin_lock_irqsave(&bcs->cs->lock, flags);
  477. test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
  478. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  479. mode_hfc(bcs, 0, st->l1.bc);
  480. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  481. st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
  482. break;
  483. }
  484. }
  485. static void
  486. close_hfcstate(struct BCState *bcs)
  487. {
  488. mode_hfc(bcs, 0, bcs->channel);
  489. if (test_bit(BC_FLG_INIT, &bcs->Flag)) {
  490. skb_queue_purge(&bcs->rqueue);
  491. skb_queue_purge(&bcs->squeue);
  492. if (bcs->tx_skb) {
  493. dev_kfree_skb_any(bcs->tx_skb);
  494. bcs->tx_skb = NULL;
  495. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  496. }
  497. }
  498. test_and_clear_bit(BC_FLG_INIT, &bcs->Flag);
  499. }
  500. static int
  501. open_hfcstate(struct IsdnCardState *cs, struct BCState *bcs)
  502. {
  503. if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
  504. skb_queue_head_init(&bcs->rqueue);
  505. skb_queue_head_init(&bcs->squeue);
  506. }
  507. bcs->tx_skb = NULL;
  508. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  509. bcs->event = 0;
  510. bcs->tx_cnt = 0;
  511. return (0);
  512. }
  513. static int
  514. setstack_hfc(struct PStack *st, struct BCState *bcs)
  515. {
  516. bcs->channel = st->l1.bc;
  517. if (open_hfcstate(st->l1.hardware, bcs))
  518. return (-1);
  519. st->l1.bcs = bcs;
  520. st->l2.l2l1 = hfc_l2l1;
  521. setstack_manager(st);
  522. bcs->st = st;
  523. setstack_l1_B(st);
  524. return (0);
  525. }
  526. static void
  527. init_send(struct BCState *bcs)
  528. {
  529. int i;
  530. if (!(bcs->hw.hfc.send = kmalloc(32 * sizeof(unsigned int), GFP_ATOMIC))) {
  531. printk(KERN_WARNING
  532. "HiSax: No memory for hfc.send\n");
  533. return;
  534. }
  535. for (i = 0; i < 32; i++)
  536. bcs->hw.hfc.send[i] = 0x1fff;
  537. }
  538. void
  539. inithfc(struct IsdnCardState *cs)
  540. {
  541. init_send(&cs->bcs[0]);
  542. init_send(&cs->bcs[1]);
  543. cs->BC_Send_Data = &hfc_fill_fifo;
  544. cs->bcs[0].BC_SetStack = setstack_hfc;
  545. cs->bcs[1].BC_SetStack = setstack_hfc;
  546. cs->bcs[0].BC_Close = close_hfcstate;
  547. cs->bcs[1].BC_Close = close_hfcstate;
  548. mode_hfc(cs->bcs, 0, 0);
  549. mode_hfc(cs->bcs + 1, 0, 0);
  550. }
  551. void
  552. releasehfc(struct IsdnCardState *cs)
  553. {
  554. kfree(cs->bcs[0].hw.hfc.send);
  555. cs->bcs[0].hw.hfc.send = NULL;
  556. kfree(cs->bcs[1].hw.hfc.send);
  557. cs->bcs[1].hw.hfc.send = NULL;
  558. }