hfc_2bds0.c 27 KB

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