hfc_2bds0.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. /* $Id: hfc_2bds0.c,v 1.18.2.6 2004/02/11 13:21:33 keil Exp $
  2. *
  3. * specific routines for CCD's HFC 2BDS0
  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_2bds0.h"
  15. #include "isdnl1.h"
  16. #include <linux/interrupt.h>
  17. /*
  18. #define KDEBUG_DEF
  19. #include "kdebug.h"
  20. */
  21. #define byteout(addr,val) outb(val,addr)
  22. #define bytein(addr) inb(addr)
  23. static void
  24. dummyf(struct IsdnCardState *cs, u_char * data, int size)
  25. {
  26. printk(KERN_WARNING "HiSax: hfcd dummy fifo called\n");
  27. }
  28. static inline u_char
  29. ReadReg(struct IsdnCardState *cs, int data, u_char reg)
  30. {
  31. register u_char ret;
  32. if (data) {
  33. if (cs->hw.hfcD.cip != reg) {
  34. cs->hw.hfcD.cip = reg;
  35. byteout(cs->hw.hfcD.addr | 1, reg);
  36. }
  37. ret = bytein(cs->hw.hfcD.addr);
  38. #ifdef HFC_REG_DEBUG
  39. if (cs->debug & L1_DEB_HSCX_FIFO && (data != 2))
  40. debugl1(cs, "t3c RD %02x %02x", reg, ret);
  41. #endif
  42. } else
  43. ret = bytein(cs->hw.hfcD.addr | 1);
  44. return (ret);
  45. }
  46. static inline void
  47. WriteReg(struct IsdnCardState *cs, int data, u_char reg, u_char value)
  48. {
  49. if (cs->hw.hfcD.cip != reg) {
  50. cs->hw.hfcD.cip = reg;
  51. byteout(cs->hw.hfcD.addr | 1, reg);
  52. }
  53. if (data)
  54. byteout(cs->hw.hfcD.addr, value);
  55. #ifdef HFC_REG_DEBUG
  56. if (cs->debug & L1_DEB_HSCX_FIFO && (data != HFCD_DATA_NODEB))
  57. debugl1(cs, "t3c W%c %02x %02x", data ? 'D' : 'C', reg, value);
  58. #endif
  59. }
  60. /* Interface functions */
  61. static u_char
  62. readreghfcd(struct IsdnCardState *cs, u_char offset)
  63. {
  64. return(ReadReg(cs, HFCD_DATA, offset));
  65. }
  66. static void
  67. writereghfcd(struct IsdnCardState *cs, u_char offset, u_char value)
  68. {
  69. WriteReg(cs, HFCD_DATA, offset, value);
  70. }
  71. static inline int
  72. WaitForBusy(struct IsdnCardState *cs)
  73. {
  74. int to = 130;
  75. while (!(ReadReg(cs, HFCD_DATA, HFCD_STAT) & HFCD_BUSY) && to) {
  76. udelay(1);
  77. to--;
  78. }
  79. if (!to)
  80. printk(KERN_WARNING "HiSax: WaitForBusy timeout\n");
  81. return (to);
  82. }
  83. static inline int
  84. WaitNoBusy(struct IsdnCardState *cs)
  85. {
  86. int to = 130;
  87. while ((ReadReg(cs, HFCD_STATUS, HFCD_STATUS) & HFCD_BUSY) && to) {
  88. udelay(1);
  89. to--;
  90. }
  91. if (!to)
  92. printk(KERN_WARNING "HiSax: WaitNoBusy timeout\n");
  93. return (to);
  94. }
  95. static int
  96. SelFiFo(struct IsdnCardState *cs, u_char FiFo)
  97. {
  98. u_char cip;
  99. if (cs->hw.hfcD.fifo == FiFo)
  100. return(1);
  101. switch(FiFo) {
  102. case 0: cip = HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_B1;
  103. break;
  104. case 1: cip = HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_B1;
  105. break;
  106. case 2: cip = HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_B2;
  107. break;
  108. case 3: cip = HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_B2;
  109. break;
  110. case 4: cip = HFCD_FIFO | HFCD_Z1 | HFCD_SEND;
  111. break;
  112. case 5: cip = HFCD_FIFO | HFCD_Z1 | HFCD_REC;
  113. break;
  114. default:
  115. debugl1(cs, "SelFiFo Error");
  116. return(0);
  117. }
  118. cs->hw.hfcD.fifo = FiFo;
  119. WaitNoBusy(cs);
  120. cs->BC_Write_Reg(cs, HFCD_DATA, cip, 0);
  121. WaitForBusy(cs);
  122. return(2);
  123. }
  124. static int
  125. GetFreeFifoBytes_B(struct BCState *bcs)
  126. {
  127. int s;
  128. if (bcs->hw.hfc.f1 == bcs->hw.hfc.f2)
  129. return (bcs->cs->hw.hfcD.bfifosize);
  130. s = bcs->hw.hfc.send[bcs->hw.hfc.f1] - bcs->hw.hfc.send[bcs->hw.hfc.f2];
  131. if (s <= 0)
  132. s += bcs->cs->hw.hfcD.bfifosize;
  133. s = bcs->cs->hw.hfcD.bfifosize - s;
  134. return (s);
  135. }
  136. static int
  137. GetFreeFifoBytes_D(struct IsdnCardState *cs)
  138. {
  139. int s;
  140. if (cs->hw.hfcD.f1 == cs->hw.hfcD.f2)
  141. return (cs->hw.hfcD.dfifosize);
  142. s = cs->hw.hfcD.send[cs->hw.hfcD.f1] - cs->hw.hfcD.send[cs->hw.hfcD.f2];
  143. if (s <= 0)
  144. s += cs->hw.hfcD.dfifosize;
  145. s = cs->hw.hfcD.dfifosize - s;
  146. return (s);
  147. }
  148. static int
  149. ReadZReg(struct IsdnCardState *cs, u_char reg)
  150. {
  151. int val;
  152. WaitNoBusy(cs);
  153. val = 256 * ReadReg(cs, HFCD_DATA, reg | HFCB_Z_HIGH);
  154. WaitNoBusy(cs);
  155. val += ReadReg(cs, HFCD_DATA, reg | HFCB_Z_LOW);
  156. return (val);
  157. }
  158. static struct sk_buff
  159. *hfc_empty_fifo(struct BCState *bcs, int count)
  160. {
  161. u_char *ptr;
  162. struct sk_buff *skb;
  163. struct IsdnCardState *cs = bcs->cs;
  164. int idx;
  165. int chksum;
  166. u_char stat, cip;
  167. if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
  168. debugl1(cs, "hfc_empty_fifo");
  169. idx = 0;
  170. if (count > HSCX_BUFMAX + 3) {
  171. if (cs->debug & L1_DEB_WARN)
  172. debugl1(cs, "hfc_empty_fifo: incoming packet too large");
  173. cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
  174. while (idx++ < count) {
  175. WaitNoBusy(cs);
  176. ReadReg(cs, HFCD_DATA_NODEB, cip);
  177. }
  178. skb = NULL;
  179. } else if (count < 4) {
  180. if (cs->debug & L1_DEB_WARN)
  181. debugl1(cs, "hfc_empty_fifo: incoming packet too small");
  182. cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
  183. #ifdef ERROR_STATISTIC
  184. bcs->err_inv++;
  185. #endif
  186. while ((idx++ < count) && WaitNoBusy(cs))
  187. ReadReg(cs, HFCD_DATA_NODEB, cip);
  188. skb = NULL;
  189. } else if (!(skb = dev_alloc_skb(count - 3)))
  190. printk(KERN_WARNING "HFC: receive out of memory\n");
  191. else {
  192. ptr = skb_put(skb, count - 3);
  193. idx = 0;
  194. cip = HFCB_FIFO | HFCB_FIFO_OUT | HFCB_REC | HFCB_CHANNEL(bcs->channel);
  195. while (idx < (count - 3)) {
  196. if (!WaitNoBusy(cs))
  197. break;
  198. *ptr = ReadReg(cs, HFCD_DATA_NODEB, cip);
  199. ptr++;
  200. idx++;
  201. }
  202. if (idx != count - 3) {
  203. debugl1(cs, "RFIFO BUSY error");
  204. printk(KERN_WARNING "HFC FIFO channel %d BUSY Error\n", bcs->channel);
  205. dev_kfree_skb_irq(skb);
  206. skb = NULL;
  207. } else {
  208. WaitNoBusy(cs);
  209. chksum = (ReadReg(cs, HFCD_DATA, cip) << 8);
  210. WaitNoBusy(cs);
  211. chksum += ReadReg(cs, HFCD_DATA, cip);
  212. WaitNoBusy(cs);
  213. stat = ReadReg(cs, HFCD_DATA, cip);
  214. if (cs->debug & L1_DEB_HSCX)
  215. debugl1(cs, "hfc_empty_fifo %d chksum %x stat %x",
  216. bcs->channel, chksum, stat);
  217. if (stat) {
  218. debugl1(cs, "FIFO CRC error");
  219. dev_kfree_skb_irq(skb);
  220. skb = NULL;
  221. #ifdef ERROR_STATISTIC
  222. bcs->err_crc++;
  223. #endif
  224. }
  225. }
  226. }
  227. WaitForBusy(cs);
  228. WaitNoBusy(cs);
  229. stat = ReadReg(cs, HFCD_DATA, HFCB_FIFO | HFCB_F2_INC |
  230. HFCB_REC | HFCB_CHANNEL(bcs->channel));
  231. WaitForBusy(cs);
  232. return (skb);
  233. }
  234. static void
  235. hfc_fill_fifo(struct BCState *bcs)
  236. {
  237. struct IsdnCardState *cs = bcs->cs;
  238. int idx, fcnt;
  239. int count;
  240. u_char cip;
  241. if (!bcs->tx_skb)
  242. return;
  243. if (bcs->tx_skb->len <= 0)
  244. return;
  245. SelFiFo(cs, HFCB_SEND | HFCB_CHANNEL(bcs->channel));
  246. cip = HFCB_FIFO | HFCB_F1 | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
  247. WaitNoBusy(cs);
  248. bcs->hw.hfc.f1 = ReadReg(cs, HFCD_DATA, cip);
  249. WaitNoBusy(cs);
  250. cip = HFCB_FIFO | HFCB_F2 | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
  251. WaitNoBusy(cs);
  252. bcs->hw.hfc.f2 = ReadReg(cs, HFCD_DATA, cip);
  253. bcs->hw.hfc.send[bcs->hw.hfc.f1] = ReadZReg(cs, HFCB_FIFO | HFCB_Z1 | HFCB_SEND | HFCB_CHANNEL(bcs->channel));
  254. if (cs->debug & L1_DEB_HSCX)
  255. debugl1(cs, "hfc_fill_fifo %d f1(%d) f2(%d) z1(%x)",
  256. bcs->channel, bcs->hw.hfc.f1, bcs->hw.hfc.f2,
  257. bcs->hw.hfc.send[bcs->hw.hfc.f1]);
  258. fcnt = bcs->hw.hfc.f1 - bcs->hw.hfc.f2;
  259. if (fcnt < 0)
  260. fcnt += 32;
  261. if (fcnt > 30) {
  262. if (cs->debug & L1_DEB_HSCX)
  263. debugl1(cs, "hfc_fill_fifo more as 30 frames");
  264. return;
  265. }
  266. count = GetFreeFifoBytes_B(bcs);
  267. if (cs->debug & L1_DEB_HSCX)
  268. debugl1(cs, "hfc_fill_fifo %d count(%ld/%d),%lx",
  269. bcs->channel, bcs->tx_skb->len,
  270. count, current->state);
  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 = HFCB_FIFO | HFCB_FIFO_IN | HFCB_SEND | HFCB_CHANNEL(bcs->channel);
  277. idx = 0;
  278. WaitForBusy(cs);
  279. WaitNoBusy(cs);
  280. WriteReg(cs, HFCD_DATA_NODEB, cip, bcs->tx_skb->data[idx++]);
  281. while (idx < bcs->tx_skb->len) {
  282. if (!WaitNoBusy(cs))
  283. break;
  284. WriteReg(cs, HFCD_DATA_NODEB, cip, bcs->tx_skb->data[idx]);
  285. idx++;
  286. }
  287. if (idx != bcs->tx_skb->len) {
  288. debugl1(cs, "FIFO Send BUSY error");
  289. printk(KERN_WARNING "HFC S FIFO channel %d BUSY Error\n", bcs->channel);
  290. } else {
  291. bcs->tx_cnt -= bcs->tx_skb->len;
  292. if (test_bit(FLG_LLI_L1WAKEUP,&bcs->st->lli.flag) &&
  293. (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
  294. u_long flags;
  295. spin_lock_irqsave(&bcs->aclock, flags);
  296. bcs->ackcnt += bcs->tx_skb->len;
  297. spin_unlock_irqrestore(&bcs->aclock, flags);
  298. schedule_event(bcs, B_ACKPENDING);
  299. }
  300. dev_kfree_skb_any(bcs->tx_skb);
  301. bcs->tx_skb = NULL;
  302. }
  303. WaitForBusy(cs);
  304. WaitNoBusy(cs);
  305. ReadReg(cs, HFCD_DATA, HFCB_FIFO | HFCB_F1_INC | HFCB_SEND | HFCB_CHANNEL(bcs->channel));
  306. WaitForBusy(cs);
  307. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  308. return;
  309. }
  310. static void
  311. hfc_send_data(struct BCState *bcs)
  312. {
  313. struct IsdnCardState *cs = bcs->cs;
  314. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  315. hfc_fill_fifo(bcs);
  316. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  317. } else
  318. debugl1(cs,"send_data %d blocked", bcs->channel);
  319. }
  320. static void
  321. main_rec_2bds0(struct BCState *bcs)
  322. {
  323. struct IsdnCardState *cs = bcs->cs;
  324. int z1, z2, rcnt;
  325. u_char f1, f2, cip;
  326. int receive, count = 5;
  327. struct sk_buff *skb;
  328. Begin:
  329. count--;
  330. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  331. debugl1(cs,"rec_data %d blocked", bcs->channel);
  332. return;
  333. }
  334. SelFiFo(cs, HFCB_REC | HFCB_CHANNEL(bcs->channel));
  335. cip = HFCB_FIFO | HFCB_F1 | HFCB_REC | HFCB_CHANNEL(bcs->channel);
  336. WaitNoBusy(cs);
  337. f1 = ReadReg(cs, HFCD_DATA, cip);
  338. cip = HFCB_FIFO | HFCB_F2 | HFCB_REC | HFCB_CHANNEL(bcs->channel);
  339. WaitNoBusy(cs);
  340. f2 = ReadReg(cs, HFCD_DATA, cip);
  341. if (f1 != f2) {
  342. if (cs->debug & L1_DEB_HSCX)
  343. debugl1(cs, "hfc rec %d f1(%d) f2(%d)",
  344. bcs->channel, f1, f2);
  345. z1 = ReadZReg(cs, HFCB_FIFO | HFCB_Z1 | HFCB_REC | HFCB_CHANNEL(bcs->channel));
  346. z2 = ReadZReg(cs, HFCB_FIFO | HFCB_Z2 | HFCB_REC | HFCB_CHANNEL(bcs->channel));
  347. rcnt = z1 - z2;
  348. if (rcnt < 0)
  349. rcnt += cs->hw.hfcD.bfifosize;
  350. rcnt++;
  351. if (cs->debug & L1_DEB_HSCX)
  352. debugl1(cs, "hfc rec %d z1(%x) z2(%x) cnt(%d)",
  353. bcs->channel, z1, z2, rcnt);
  354. if ((skb = hfc_empty_fifo(bcs, rcnt))) {
  355. skb_queue_tail(&bcs->rqueue, skb);
  356. schedule_event(bcs, B_RCVBUFREADY);
  357. }
  358. rcnt = f1 -f2;
  359. if (rcnt<0)
  360. rcnt += 32;
  361. if (rcnt>1)
  362. receive = 1;
  363. else
  364. receive = 0;
  365. } else
  366. receive = 0;
  367. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  368. if (count && receive)
  369. goto Begin;
  370. return;
  371. }
  372. static void
  373. mode_2bs0(struct BCState *bcs, int mode, int bc)
  374. {
  375. struct IsdnCardState *cs = bcs->cs;
  376. if (cs->debug & L1_DEB_HSCX)
  377. debugl1(cs, "HFCD bchannel mode %d bchan %d/%d",
  378. mode, bc, bcs->channel);
  379. bcs->mode = mode;
  380. bcs->channel = bc;
  381. switch (mode) {
  382. case (L1_MODE_NULL):
  383. if (bc) {
  384. cs->hw.hfcD.conn |= 0x18;
  385. cs->hw.hfcD.sctrl &= ~SCTRL_B2_ENA;
  386. } else {
  387. cs->hw.hfcD.conn |= 0x3;
  388. cs->hw.hfcD.sctrl &= ~SCTRL_B1_ENA;
  389. }
  390. break;
  391. case (L1_MODE_TRANS):
  392. if (bc) {
  393. cs->hw.hfcD.ctmt |= 2;
  394. cs->hw.hfcD.conn &= ~0x18;
  395. cs->hw.hfcD.sctrl |= SCTRL_B2_ENA;
  396. } else {
  397. cs->hw.hfcD.ctmt |= 1;
  398. cs->hw.hfcD.conn &= ~0x3;
  399. cs->hw.hfcD.sctrl |= SCTRL_B1_ENA;
  400. }
  401. break;
  402. case (L1_MODE_HDLC):
  403. if (bc) {
  404. cs->hw.hfcD.ctmt &= ~2;
  405. cs->hw.hfcD.conn &= ~0x18;
  406. cs->hw.hfcD.sctrl |= SCTRL_B2_ENA;
  407. } else {
  408. cs->hw.hfcD.ctmt &= ~1;
  409. cs->hw.hfcD.conn &= ~0x3;
  410. cs->hw.hfcD.sctrl |= SCTRL_B1_ENA;
  411. }
  412. break;
  413. }
  414. WriteReg(cs, HFCD_DATA, HFCD_SCTRL, cs->hw.hfcD.sctrl);
  415. WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt);
  416. WriteReg(cs, HFCD_DATA, HFCD_CONN, cs->hw.hfcD.conn);
  417. }
  418. static void
  419. hfc_l2l1(struct PStack *st, int pr, void *arg)
  420. {
  421. struct BCState *bcs = st->l1.bcs;
  422. struct sk_buff *skb = arg;
  423. u_long flags;
  424. switch (pr) {
  425. case (PH_DATA | REQUEST):
  426. spin_lock_irqsave(&bcs->cs->lock, flags);
  427. if (bcs->tx_skb) {
  428. skb_queue_tail(&bcs->squeue, skb);
  429. } else {
  430. bcs->tx_skb = skb;
  431. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  432. bcs->cs->BC_Send_Data(bcs);
  433. }
  434. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  435. break;
  436. case (PH_PULL | INDICATION):
  437. spin_lock_irqsave(&bcs->cs->lock, flags);
  438. if (bcs->tx_skb) {
  439. printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
  440. } else {
  441. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  442. bcs->tx_skb = skb;
  443. bcs->cs->BC_Send_Data(bcs);
  444. }
  445. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  446. break;
  447. case (PH_PULL | REQUEST):
  448. if (!bcs->tx_skb) {
  449. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  450. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  451. } else
  452. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  453. break;
  454. case (PH_ACTIVATE | REQUEST):
  455. spin_lock_irqsave(&bcs->cs->lock, flags);
  456. test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
  457. mode_2bs0(bcs, st->l1.mode, st->l1.bc);
  458. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  459. l1_msg_b(st, pr, arg);
  460. break;
  461. case (PH_DEACTIVATE | REQUEST):
  462. l1_msg_b(st, pr, arg);
  463. break;
  464. case (PH_DEACTIVATE | CONFIRM):
  465. spin_lock_irqsave(&bcs->cs->lock, flags);
  466. test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
  467. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  468. mode_2bs0(bcs, 0, st->l1.bc);
  469. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  470. st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
  471. break;
  472. }
  473. }
  474. static void
  475. close_2bs0(struct BCState *bcs)
  476. {
  477. mode_2bs0(bcs, 0, bcs->channel);
  478. if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
  479. skb_queue_purge(&bcs->rqueue);
  480. skb_queue_purge(&bcs->squeue);
  481. if (bcs->tx_skb) {
  482. dev_kfree_skb_any(bcs->tx_skb);
  483. bcs->tx_skb = NULL;
  484. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  485. }
  486. }
  487. }
  488. static int
  489. open_hfcstate(struct IsdnCardState *cs, struct BCState *bcs)
  490. {
  491. if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
  492. skb_queue_head_init(&bcs->rqueue);
  493. skb_queue_head_init(&bcs->squeue);
  494. }
  495. bcs->tx_skb = NULL;
  496. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  497. bcs->event = 0;
  498. bcs->tx_cnt = 0;
  499. return (0);
  500. }
  501. static int
  502. setstack_2b(struct PStack *st, struct BCState *bcs)
  503. {
  504. bcs->channel = st->l1.bc;
  505. if (open_hfcstate(st->l1.hardware, bcs))
  506. return (-1);
  507. st->l1.bcs = bcs;
  508. st->l2.l2l1 = hfc_l2l1;
  509. setstack_manager(st);
  510. bcs->st = st;
  511. setstack_l1_B(st);
  512. return (0);
  513. }
  514. static void
  515. hfcd_bh(struct work_struct *work)
  516. {
  517. struct IsdnCardState *cs =
  518. container_of(work, struct IsdnCardState, tqueue);
  519. if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
  520. switch (cs->dc.hfcd.ph_state) {
  521. case (0):
  522. l1_msg(cs, HW_RESET | INDICATION, NULL);
  523. break;
  524. case (3):
  525. l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
  526. break;
  527. case (8):
  528. l1_msg(cs, HW_RSYNC | INDICATION, NULL);
  529. break;
  530. case (6):
  531. l1_msg(cs, HW_INFO2 | INDICATION, NULL);
  532. break;
  533. case (7):
  534. l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
  535. break;
  536. default:
  537. break;
  538. }
  539. }
  540. if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
  541. DChannel_proc_rcv(cs);
  542. if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
  543. DChannel_proc_xmt(cs);
  544. }
  545. static
  546. int receive_dmsg(struct IsdnCardState *cs)
  547. {
  548. struct sk_buff *skb;
  549. int idx;
  550. int rcnt, z1, z2;
  551. u_char stat, cip, f1, f2;
  552. int chksum;
  553. int count=5;
  554. u_char *ptr;
  555. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  556. debugl1(cs, "rec_dmsg blocked");
  557. return(1);
  558. }
  559. SelFiFo(cs, 4 | HFCD_REC);
  560. cip = HFCD_FIFO | HFCD_F1 | HFCD_REC;
  561. WaitNoBusy(cs);
  562. f1 = cs->readisac(cs, cip) & 0xf;
  563. cip = HFCD_FIFO | HFCD_F2 | HFCD_REC;
  564. WaitNoBusy(cs);
  565. f2 = cs->readisac(cs, cip) & 0xf;
  566. while ((f1 != f2) && count--) {
  567. z1 = ReadZReg(cs, HFCD_FIFO | HFCD_Z1 | HFCD_REC);
  568. z2 = ReadZReg(cs, HFCD_FIFO | HFCD_Z2 | HFCD_REC);
  569. rcnt = z1 - z2;
  570. if (rcnt < 0)
  571. rcnt += cs->hw.hfcD.dfifosize;
  572. rcnt++;
  573. if (cs->debug & L1_DEB_ISAC)
  574. debugl1(cs, "hfcd recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)",
  575. f1, f2, z1, z2, rcnt);
  576. idx = 0;
  577. cip = HFCD_FIFO | HFCD_FIFO_OUT | HFCD_REC;
  578. if (rcnt > MAX_DFRAME_LEN + 3) {
  579. if (cs->debug & L1_DEB_WARN)
  580. debugl1(cs, "empty_fifo d: incoming packet too large");
  581. while (idx < rcnt) {
  582. if (!(WaitNoBusy(cs)))
  583. break;
  584. ReadReg(cs, HFCD_DATA_NODEB, cip);
  585. idx++;
  586. }
  587. } else if (rcnt < 4) {
  588. if (cs->debug & L1_DEB_WARN)
  589. debugl1(cs, "empty_fifo d: incoming packet too small");
  590. while ((idx++ < rcnt) && WaitNoBusy(cs))
  591. ReadReg(cs, HFCD_DATA_NODEB, cip);
  592. } else if ((skb = dev_alloc_skb(rcnt - 3))) {
  593. ptr = skb_put(skb, rcnt - 3);
  594. while (idx < (rcnt - 3)) {
  595. if (!(WaitNoBusy(cs)))
  596. break;
  597. *ptr = ReadReg(cs, HFCD_DATA_NODEB, cip);
  598. idx++;
  599. ptr++;
  600. }
  601. if (idx != (rcnt - 3)) {
  602. debugl1(cs, "RFIFO D BUSY error");
  603. printk(KERN_WARNING "HFC DFIFO channel BUSY Error\n");
  604. dev_kfree_skb_irq(skb);
  605. skb = NULL;
  606. #ifdef ERROR_STATISTIC
  607. cs->err_rx++;
  608. #endif
  609. } else {
  610. WaitNoBusy(cs);
  611. chksum = (ReadReg(cs, HFCD_DATA, cip) << 8);
  612. WaitNoBusy(cs);
  613. chksum += ReadReg(cs, HFCD_DATA, cip);
  614. WaitNoBusy(cs);
  615. stat = ReadReg(cs, HFCD_DATA, cip);
  616. if (cs->debug & L1_DEB_ISAC)
  617. debugl1(cs, "empty_dfifo chksum %x stat %x",
  618. chksum, stat);
  619. if (stat) {
  620. debugl1(cs, "FIFO CRC error");
  621. dev_kfree_skb_irq(skb);
  622. skb = NULL;
  623. #ifdef ERROR_STATISTIC
  624. cs->err_crc++;
  625. #endif
  626. } else {
  627. skb_queue_tail(&cs->rq, skb);
  628. schedule_event(cs, D_RCVBUFREADY);
  629. }
  630. }
  631. } else
  632. printk(KERN_WARNING "HFC: D receive out of memory\n");
  633. WaitForBusy(cs);
  634. cip = HFCD_FIFO | HFCD_F2_INC | HFCD_REC;
  635. WaitNoBusy(cs);
  636. stat = ReadReg(cs, HFCD_DATA, cip);
  637. WaitForBusy(cs);
  638. cip = HFCD_FIFO | HFCD_F2 | HFCD_REC;
  639. WaitNoBusy(cs);
  640. f2 = cs->readisac(cs, cip) & 0xf;
  641. }
  642. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  643. return(1);
  644. }
  645. static void
  646. hfc_fill_dfifo(struct IsdnCardState *cs)
  647. {
  648. int idx, fcnt;
  649. int count;
  650. u_char cip;
  651. if (!cs->tx_skb)
  652. return;
  653. if (cs->tx_skb->len <= 0)
  654. return;
  655. SelFiFo(cs, 4 | HFCD_SEND);
  656. cip = HFCD_FIFO | HFCD_F1 | HFCD_SEND;
  657. WaitNoBusy(cs);
  658. cs->hw.hfcD.f1 = ReadReg(cs, HFCD_DATA, cip) & 0xf;
  659. WaitNoBusy(cs);
  660. cip = HFCD_FIFO | HFCD_F2 | HFCD_SEND;
  661. cs->hw.hfcD.f2 = ReadReg(cs, HFCD_DATA, cip) & 0xf;
  662. cs->hw.hfcD.send[cs->hw.hfcD.f1] = ReadZReg(cs, HFCD_FIFO | HFCD_Z1 | HFCD_SEND);
  663. if (cs->debug & L1_DEB_ISAC)
  664. debugl1(cs, "hfc_fill_Dfifo f1(%d) f2(%d) z1(%x)",
  665. cs->hw.hfcD.f1, cs->hw.hfcD.f2,
  666. cs->hw.hfcD.send[cs->hw.hfcD.f1]);
  667. fcnt = cs->hw.hfcD.f1 - cs->hw.hfcD.f2;
  668. if (fcnt < 0)
  669. fcnt += 16;
  670. if (fcnt > 14) {
  671. if (cs->debug & L1_DEB_HSCX)
  672. debugl1(cs, "hfc_fill_Dfifo more as 14 frames");
  673. return;
  674. }
  675. count = GetFreeFifoBytes_D(cs);
  676. if (cs->debug & L1_DEB_ISAC)
  677. debugl1(cs, "hfc_fill_Dfifo count(%ld/%d)",
  678. cs->tx_skb->len, count);
  679. if (count < cs->tx_skb->len) {
  680. if (cs->debug & L1_DEB_ISAC)
  681. debugl1(cs, "hfc_fill_Dfifo no fifo mem");
  682. return;
  683. }
  684. cip = HFCD_FIFO | HFCD_FIFO_IN | HFCD_SEND;
  685. idx = 0;
  686. WaitForBusy(cs);
  687. WaitNoBusy(cs);
  688. WriteReg(cs, HFCD_DATA_NODEB, cip, cs->tx_skb->data[idx++]);
  689. while (idx < cs->tx_skb->len) {
  690. if (!(WaitNoBusy(cs)))
  691. break;
  692. WriteReg(cs, HFCD_DATA_NODEB, cip, cs->tx_skb->data[idx]);
  693. idx++;
  694. }
  695. if (idx != cs->tx_skb->len) {
  696. debugl1(cs, "DFIFO Send BUSY error");
  697. printk(KERN_WARNING "HFC S DFIFO channel BUSY Error\n");
  698. }
  699. WaitForBusy(cs);
  700. WaitNoBusy(cs);
  701. ReadReg(cs, HFCD_DATA, HFCD_FIFO | HFCD_F1_INC | HFCD_SEND);
  702. dev_kfree_skb_any(cs->tx_skb);
  703. cs->tx_skb = NULL;
  704. WaitForBusy(cs);
  705. return;
  706. }
  707. static
  708. struct BCState *Sel_BCS(struct IsdnCardState *cs, int channel)
  709. {
  710. if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
  711. return(&cs->bcs[0]);
  712. else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
  713. return(&cs->bcs[1]);
  714. else
  715. return(NULL);
  716. }
  717. void
  718. hfc2bds0_interrupt(struct IsdnCardState *cs, u_char val)
  719. {
  720. u_char exval;
  721. struct BCState *bcs;
  722. int count=15;
  723. if (cs->debug & L1_DEB_ISAC)
  724. debugl1(cs, "HFCD irq %x %s", val,
  725. test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
  726. "locked" : "unlocked");
  727. val &= cs->hw.hfcD.int_m1;
  728. if (val & 0x40) { /* TE state machine irq */
  729. exval = cs->readisac(cs, HFCD_STATES) & 0xf;
  730. if (cs->debug & L1_DEB_ISAC)
  731. debugl1(cs, "ph_state chg %d->%d", cs->dc.hfcd.ph_state,
  732. exval);
  733. cs->dc.hfcd.ph_state = exval;
  734. schedule_event(cs, D_L1STATECHANGE);
  735. val &= ~0x40;
  736. }
  737. while (val) {
  738. if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  739. cs->hw.hfcD.int_s1 |= val;
  740. return;
  741. }
  742. if (cs->hw.hfcD.int_s1 & 0x18) {
  743. exval = val;
  744. val = cs->hw.hfcD.int_s1;
  745. cs->hw.hfcD.int_s1 = exval;
  746. }
  747. if (val & 0x08) {
  748. if (!(bcs=Sel_BCS(cs, 0))) {
  749. if (cs->debug)
  750. debugl1(cs, "hfcd spurious 0x08 IRQ");
  751. } else
  752. main_rec_2bds0(bcs);
  753. }
  754. if (val & 0x10) {
  755. if (!(bcs=Sel_BCS(cs, 1))) {
  756. if (cs->debug)
  757. debugl1(cs, "hfcd spurious 0x10 IRQ");
  758. } else
  759. main_rec_2bds0(bcs);
  760. }
  761. if (val & 0x01) {
  762. if (!(bcs=Sel_BCS(cs, 0))) {
  763. if (cs->debug)
  764. debugl1(cs, "hfcd spurious 0x01 IRQ");
  765. } else {
  766. if (bcs->tx_skb) {
  767. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  768. hfc_fill_fifo(bcs);
  769. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  770. } else
  771. debugl1(cs,"fill_data %d blocked", bcs->channel);
  772. } else {
  773. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  774. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  775. hfc_fill_fifo(bcs);
  776. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  777. } else
  778. debugl1(cs,"fill_data %d blocked", bcs->channel);
  779. } else {
  780. schedule_event(bcs, B_XMTBUFREADY);
  781. }
  782. }
  783. }
  784. }
  785. if (val & 0x02) {
  786. if (!(bcs=Sel_BCS(cs, 1))) {
  787. if (cs->debug)
  788. debugl1(cs, "hfcd spurious 0x02 IRQ");
  789. } else {
  790. if (bcs->tx_skb) {
  791. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  792. hfc_fill_fifo(bcs);
  793. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  794. } else
  795. debugl1(cs,"fill_data %d blocked", bcs->channel);
  796. } else {
  797. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  798. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  799. hfc_fill_fifo(bcs);
  800. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  801. } else
  802. debugl1(cs,"fill_data %d blocked", bcs->channel);
  803. } else {
  804. schedule_event(bcs, B_XMTBUFREADY);
  805. }
  806. }
  807. }
  808. }
  809. if (val & 0x20) { /* receive dframe */
  810. receive_dmsg(cs);
  811. }
  812. if (val & 0x04) { /* dframe transmitted */
  813. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  814. del_timer(&cs->dbusytimer);
  815. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  816. schedule_event(cs, D_CLEARBUSY);
  817. if (cs->tx_skb) {
  818. if (cs->tx_skb->len) {
  819. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  820. hfc_fill_dfifo(cs);
  821. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  822. } else {
  823. debugl1(cs, "hfc_fill_dfifo irq blocked");
  824. }
  825. goto afterXPR;
  826. } else {
  827. dev_kfree_skb_irq(cs->tx_skb);
  828. cs->tx_cnt = 0;
  829. cs->tx_skb = NULL;
  830. }
  831. }
  832. if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
  833. cs->tx_cnt = 0;
  834. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  835. hfc_fill_dfifo(cs);
  836. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  837. } else {
  838. debugl1(cs, "hfc_fill_dfifo irq blocked");
  839. }
  840. } else
  841. schedule_event(cs, D_XMTBUFREADY);
  842. }
  843. afterXPR:
  844. if (cs->hw.hfcD.int_s1 && count--) {
  845. val = cs->hw.hfcD.int_s1;
  846. cs->hw.hfcD.int_s1 = 0;
  847. if (cs->debug & L1_DEB_ISAC)
  848. debugl1(cs, "HFCD irq %x loop %d", val, 15-count);
  849. } else
  850. val = 0;
  851. }
  852. }
  853. static void
  854. HFCD_l1hw(struct PStack *st, int pr, void *arg)
  855. {
  856. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  857. struct sk_buff *skb = arg;
  858. u_long flags;
  859. switch (pr) {
  860. case (PH_DATA | REQUEST):
  861. if (cs->debug & DEB_DLOG_HEX)
  862. LogFrame(cs, skb->data, skb->len);
  863. if (cs->debug & DEB_DLOG_VERBOSE)
  864. dlogframe(cs, skb, 0);
  865. spin_lock_irqsave(&cs->lock, flags);
  866. if (cs->tx_skb) {
  867. skb_queue_tail(&cs->sq, skb);
  868. #ifdef L2FRAME_DEBUG /* psa */
  869. if (cs->debug & L1_DEB_LAPD)
  870. Logl2Frame(cs, skb, "PH_DATA Queued", 0);
  871. #endif
  872. } else {
  873. cs->tx_skb = skb;
  874. cs->tx_cnt = 0;
  875. #ifdef L2FRAME_DEBUG /* psa */
  876. if (cs->debug & L1_DEB_LAPD)
  877. Logl2Frame(cs, skb, "PH_DATA", 0);
  878. #endif
  879. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  880. hfc_fill_dfifo(cs);
  881. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  882. } else
  883. debugl1(cs, "hfc_fill_dfifo blocked");
  884. }
  885. spin_unlock_irqrestore(&cs->lock, flags);
  886. break;
  887. case (PH_PULL | INDICATION):
  888. spin_lock_irqsave(&cs->lock, flags);
  889. if (cs->tx_skb) {
  890. if (cs->debug & L1_DEB_WARN)
  891. debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
  892. skb_queue_tail(&cs->sq, skb);
  893. spin_unlock_irqrestore(&cs->lock, flags);
  894. break;
  895. }
  896. if (cs->debug & DEB_DLOG_HEX)
  897. LogFrame(cs, skb->data, skb->len);
  898. if (cs->debug & DEB_DLOG_VERBOSE)
  899. dlogframe(cs, skb, 0);
  900. cs->tx_skb = skb;
  901. cs->tx_cnt = 0;
  902. #ifdef L2FRAME_DEBUG /* psa */
  903. if (cs->debug & L1_DEB_LAPD)
  904. Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
  905. #endif
  906. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  907. hfc_fill_dfifo(cs);
  908. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  909. } else
  910. debugl1(cs, "hfc_fill_dfifo blocked");
  911. spin_unlock_irqrestore(&cs->lock, flags);
  912. break;
  913. case (PH_PULL | REQUEST):
  914. #ifdef L2FRAME_DEBUG /* psa */
  915. if (cs->debug & L1_DEB_LAPD)
  916. debugl1(cs, "-> PH_REQUEST_PULL");
  917. #endif
  918. if (!cs->tx_skb) {
  919. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  920. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  921. } else
  922. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  923. break;
  924. case (HW_RESET | REQUEST):
  925. spin_lock_irqsave(&cs->lock, flags);
  926. cs->writeisac(cs, HFCD_STATES, HFCD_LOAD_STATE | 3); /* HFC ST 3 */
  927. udelay(6);
  928. cs->writeisac(cs, HFCD_STATES, 3); /* HFC ST 2 */
  929. cs->hw.hfcD.mst_m |= HFCD_MASTER;
  930. cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
  931. cs->writeisac(cs, HFCD_STATES, HFCD_ACTIVATE | HFCD_DO_ACTION);
  932. spin_unlock_irqrestore(&cs->lock, flags);
  933. l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
  934. break;
  935. case (HW_ENABLE | REQUEST):
  936. spin_lock_irqsave(&cs->lock, flags);
  937. cs->writeisac(cs, HFCD_STATES, HFCD_ACTIVATE | HFCD_DO_ACTION);
  938. spin_unlock_irqrestore(&cs->lock, flags);
  939. break;
  940. case (HW_DEACTIVATE | REQUEST):
  941. spin_lock_irqsave(&cs->lock, flags);
  942. cs->hw.hfcD.mst_m &= ~HFCD_MASTER;
  943. cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
  944. spin_unlock_irqrestore(&cs->lock, flags);
  945. break;
  946. case (HW_INFO3 | REQUEST):
  947. spin_lock_irqsave(&cs->lock, flags);
  948. cs->hw.hfcD.mst_m |= HFCD_MASTER;
  949. cs->writeisac(cs, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
  950. spin_unlock_irqrestore(&cs->lock, flags);
  951. break;
  952. default:
  953. if (cs->debug & L1_DEB_WARN)
  954. debugl1(cs, "hfcd_l1hw unknown pr %4x", pr);
  955. break;
  956. }
  957. }
  958. static void
  959. setstack_hfcd(struct PStack *st, struct IsdnCardState *cs)
  960. {
  961. st->l1.l1hw = HFCD_l1hw;
  962. }
  963. static void
  964. hfc_dbusy_timer(struct IsdnCardState *cs)
  965. {
  966. }
  967. static unsigned int
  968. *init_send_hfcd(int cnt)
  969. {
  970. int i;
  971. unsigned *send;
  972. if (!(send = kmalloc(cnt * sizeof(unsigned int), GFP_ATOMIC))) {
  973. printk(KERN_WARNING
  974. "HiSax: No memory for hfcd.send\n");
  975. return(NULL);
  976. }
  977. for (i = 0; i < cnt; i++)
  978. send[i] = 0x1fff;
  979. return(send);
  980. }
  981. void
  982. init2bds0(struct IsdnCardState *cs)
  983. {
  984. cs->setstack_d = setstack_hfcd;
  985. if (!cs->hw.hfcD.send)
  986. cs->hw.hfcD.send = init_send_hfcd(16);
  987. if (!cs->bcs[0].hw.hfc.send)
  988. cs->bcs[0].hw.hfc.send = init_send_hfcd(32);
  989. if (!cs->bcs[1].hw.hfc.send)
  990. cs->bcs[1].hw.hfc.send = init_send_hfcd(32);
  991. cs->BC_Send_Data = &hfc_send_data;
  992. cs->bcs[0].BC_SetStack = setstack_2b;
  993. cs->bcs[1].BC_SetStack = setstack_2b;
  994. cs->bcs[0].BC_Close = close_2bs0;
  995. cs->bcs[1].BC_Close = close_2bs0;
  996. mode_2bs0(cs->bcs, 0, 0);
  997. mode_2bs0(cs->bcs + 1, 0, 1);
  998. }
  999. void
  1000. release2bds0(struct IsdnCardState *cs)
  1001. {
  1002. kfree(cs->bcs[0].hw.hfc.send);
  1003. cs->bcs[0].hw.hfc.send = NULL;
  1004. kfree(cs->bcs[1].hw.hfc.send);
  1005. cs->bcs[1].hw.hfc.send = NULL;
  1006. kfree(cs->hw.hfcD.send);
  1007. cs->hw.hfcD.send = NULL;
  1008. }
  1009. void
  1010. set_cs_func(struct IsdnCardState *cs)
  1011. {
  1012. cs->readisac = &readreghfcd;
  1013. cs->writeisac = &writereghfcd;
  1014. cs->readisacfifo = &dummyf;
  1015. cs->writeisacfifo = &dummyf;
  1016. cs->BC_Read_Reg = &ReadReg;
  1017. cs->BC_Write_Reg = &WriteReg;
  1018. cs->dbusytimer.function = (void *) hfc_dbusy_timer;
  1019. cs->dbusytimer.data = (long) cs;
  1020. init_timer(&cs->dbusytimer);
  1021. INIT_WORK(&cs->tqueue, hfcd_bh);
  1022. }