hfc_sx.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518
  1. /* $Id: hfc_sx.c,v 1.12.2.5 2004/02/11 13:21:33 keil Exp $
  2. *
  3. * level driver for Cologne Chip Designs hfc-s+/sp based cards
  4. *
  5. * Author Werner Cornelius
  6. * based on existing driver for CCD HFC PCI cards
  7. * Copyright by Werner Cornelius <werner@isdn4linux.de>
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. */
  13. #include <linux/init.h>
  14. #include "hisax.h"
  15. #include "hfc_sx.h"
  16. #include "isdnl1.h"
  17. #include <linux/interrupt.h>
  18. #include <linux/isapnp.h>
  19. static const char *hfcsx_revision = "$Revision: 1.12.2.5 $";
  20. /***************************************/
  21. /* IRQ-table for CCDs demo board */
  22. /* IRQs 6,5,10,11,12,15 are supported */
  23. /***************************************/
  24. /* Teles 16.3c Vendor Id TAG2620, Version 1.0, Vendor version 2.1
  25. *
  26. * Thanks to Uwe Wisniewski
  27. *
  28. * ISA-SLOT Signal PIN
  29. * B25 IRQ3 92 IRQ_G
  30. * B23 IRQ5 94 IRQ_A
  31. * B4 IRQ2/9 95 IRQ_B
  32. * D3 IRQ10 96 IRQ_C
  33. * D4 IRQ11 97 IRQ_D
  34. * D5 IRQ12 98 IRQ_E
  35. * D6 IRQ15 99 IRQ_F
  36. */
  37. #undef CCD_DEMO_BOARD
  38. #ifdef CCD_DEMO_BOARD
  39. static u_char ccd_sp_irqtab[16] = {
  40. 0,0,0,0,0,2,1,0,0,0,3,4,5,0,0,6
  41. };
  42. #else /* Teles 16.3c */
  43. static u_char ccd_sp_irqtab[16] = {
  44. 0,0,0,7,0,1,0,0,0,2,3,4,5,0,0,6
  45. };
  46. #endif
  47. #define NT_T1_COUNT 20 /* number of 3.125ms interrupts for G2 timeout */
  48. #define byteout(addr,val) outb(val,addr)
  49. #define bytein(addr) inb(addr)
  50. /******************************/
  51. /* In/Out access to registers */
  52. /******************************/
  53. static inline void
  54. Write_hfc(struct IsdnCardState *cs, u_char regnum, u_char val)
  55. {
  56. byteout(cs->hw.hfcsx.base+1, regnum);
  57. byteout(cs->hw.hfcsx.base, val);
  58. }
  59. static inline u_char
  60. Read_hfc(struct IsdnCardState *cs, u_char regnum)
  61. {
  62. u_char ret;
  63. byteout(cs->hw.hfcsx.base+1, regnum);
  64. ret = bytein(cs->hw.hfcsx.base);
  65. return(ret);
  66. }
  67. /**************************************************/
  68. /* select a fifo and remember which one for reuse */
  69. /**************************************************/
  70. static void
  71. fifo_select(struct IsdnCardState *cs, u_char fifo)
  72. {
  73. if (fifo == cs->hw.hfcsx.last_fifo)
  74. return; /* still valid */
  75. byteout(cs->hw.hfcsx.base+1, HFCSX_FIF_SEL);
  76. byteout(cs->hw.hfcsx.base, fifo);
  77. while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
  78. udelay(4);
  79. byteout(cs->hw.hfcsx.base, fifo);
  80. while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
  81. }
  82. /******************************************/
  83. /* reset the specified fifo to defaults. */
  84. /* If its a send fifo init needed markers */
  85. /******************************************/
  86. static void
  87. reset_fifo(struct IsdnCardState *cs, u_char fifo)
  88. {
  89. fifo_select(cs, fifo); /* first select the fifo */
  90. byteout(cs->hw.hfcsx.base+1, HFCSX_CIRM);
  91. byteout(cs->hw.hfcsx.base, cs->hw.hfcsx.cirm | 0x80); /* reset cmd */
  92. udelay(1);
  93. while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
  94. }
  95. /*************************************************************/
  96. /* write_fifo writes the skb contents to the desired fifo */
  97. /* if no space is available or an error occurs 0 is returned */
  98. /* the skb is not released in any way. */
  99. /*************************************************************/
  100. static int
  101. write_fifo(struct IsdnCardState *cs, struct sk_buff *skb, u_char fifo, int trans_max)
  102. {
  103. unsigned short *msp;
  104. int fifo_size, count, z1, z2;
  105. u_char f_msk, f1, f2, *src;
  106. if (skb->len <= 0) return(0);
  107. if (fifo & 1) return(0); /* no write fifo */
  108. fifo_select(cs, fifo);
  109. if (fifo & 4) {
  110. fifo_size = D_FIFO_SIZE; /* D-channel */
  111. f_msk = MAX_D_FRAMES;
  112. if (trans_max) return(0); /* only HDLC */
  113. }
  114. else {
  115. fifo_size = cs->hw.hfcsx.b_fifo_size; /* B-channel */
  116. f_msk = MAX_B_FRAMES;
  117. }
  118. z1 = Read_hfc(cs, HFCSX_FIF_Z1H);
  119. z1 = ((z1 << 8) | Read_hfc(cs, HFCSX_FIF_Z1L));
  120. /* Check for transparent mode */
  121. if (trans_max) {
  122. z2 = Read_hfc(cs, HFCSX_FIF_Z2H);
  123. z2 = ((z2 << 8) | Read_hfc(cs, HFCSX_FIF_Z2L));
  124. count = z2 - z1;
  125. if (count <= 0)
  126. count += fifo_size; /* free bytes */
  127. if (count < skb->len+1) return(0); /* no room */
  128. count = fifo_size - count; /* bytes still not send */
  129. if (count > 2 * trans_max) return(0); /* delay to long */
  130. count = skb->len;
  131. src = skb->data;
  132. while (count--)
  133. Write_hfc(cs, HFCSX_FIF_DWR, *src++);
  134. return(1); /* success */
  135. }
  136. msp = ((struct hfcsx_extra *)(cs->hw.hfcsx.extra))->marker;
  137. msp += (((fifo >> 1) & 3) * (MAX_B_FRAMES+1));
  138. f1 = Read_hfc(cs, HFCSX_FIF_F1) & f_msk;
  139. f2 = Read_hfc(cs, HFCSX_FIF_F2) & f_msk;
  140. count = f1 - f2; /* frame count actually buffered */
  141. if (count < 0)
  142. count += (f_msk + 1); /* if wrap around */
  143. if (count > f_msk-1) {
  144. if (cs->debug & L1_DEB_ISAC_FIFO)
  145. debugl1(cs, "hfcsx_write_fifo %d more as %d frames",fifo,f_msk-1);
  146. return(0);
  147. }
  148. *(msp + f1) = z1; /* remember marker */
  149. if (cs->debug & L1_DEB_ISAC_FIFO)
  150. debugl1(cs, "hfcsx_write_fifo %d f1(%x) f2(%x) z1(f1)(%x)",
  151. fifo, f1, f2, z1);
  152. /* now determine free bytes in FIFO buffer */
  153. count = *(msp + f2) - z1;
  154. if (count <= 0)
  155. count += fifo_size; /* count now contains available bytes */
  156. if (cs->debug & L1_DEB_ISAC_FIFO)
  157. debugl1(cs, "hfcsx_write_fifo %d count(%ld/%d)",
  158. fifo, skb->len, count);
  159. if (count < skb->len) {
  160. if (cs->debug & L1_DEB_ISAC_FIFO)
  161. debugl1(cs, "hfcsx_write_fifo %d no fifo mem", fifo);
  162. return(0);
  163. }
  164. count = skb->len; /* get frame len */
  165. src = skb->data; /* source pointer */
  166. while (count--)
  167. Write_hfc(cs, HFCSX_FIF_DWR, *src++);
  168. Read_hfc(cs, HFCSX_FIF_INCF1); /* increment F1 */
  169. udelay(1);
  170. while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
  171. return(1);
  172. }
  173. /***************************************************************/
  174. /* read_fifo reads data to an skb from the desired fifo */
  175. /* if no data is available or an error occurs NULL is returned */
  176. /* the skb is not released in any way. */
  177. /***************************************************************/
  178. static struct sk_buff *
  179. read_fifo(struct IsdnCardState *cs, u_char fifo, int trans_max)
  180. { int fifo_size, count, z1, z2;
  181. u_char f_msk, f1, f2, *dst;
  182. struct sk_buff *skb;
  183. if (!(fifo & 1)) return(NULL); /* no read fifo */
  184. fifo_select(cs, fifo);
  185. if (fifo & 4) {
  186. fifo_size = D_FIFO_SIZE; /* D-channel */
  187. f_msk = MAX_D_FRAMES;
  188. if (trans_max) return(NULL); /* only hdlc */
  189. }
  190. else {
  191. fifo_size = cs->hw.hfcsx.b_fifo_size; /* B-channel */
  192. f_msk = MAX_B_FRAMES;
  193. }
  194. /* transparent mode */
  195. if (trans_max) {
  196. z1 = Read_hfc(cs, HFCSX_FIF_Z1H);
  197. z1 = ((z1 << 8) | Read_hfc(cs, HFCSX_FIF_Z1L));
  198. z2 = Read_hfc(cs, HFCSX_FIF_Z2H);
  199. z2 = ((z2 << 8) | Read_hfc(cs, HFCSX_FIF_Z2L));
  200. /* now determine bytes in actual FIFO buffer */
  201. count = z1 - z2;
  202. if (count <= 0)
  203. count += fifo_size; /* count now contains buffered bytes */
  204. count++;
  205. if (count > trans_max)
  206. count = trans_max; /* limit length */
  207. if ((skb = dev_alloc_skb(count))) {
  208. dst = skb_put(skb, count);
  209. while (count--)
  210. *dst++ = Read_hfc(cs, HFCSX_FIF_DRD);
  211. return(skb);
  212. }
  213. else return(NULL); /* no memory */
  214. }
  215. do {
  216. f1 = Read_hfc(cs, HFCSX_FIF_F1) & f_msk;
  217. f2 = Read_hfc(cs, HFCSX_FIF_F2) & f_msk;
  218. if (f1 == f2) return(NULL); /* no frame available */
  219. z1 = Read_hfc(cs, HFCSX_FIF_Z1H);
  220. z1 = ((z1 << 8) | Read_hfc(cs, HFCSX_FIF_Z1L));
  221. z2 = Read_hfc(cs, HFCSX_FIF_Z2H);
  222. z2 = ((z2 << 8) | Read_hfc(cs, HFCSX_FIF_Z2L));
  223. if (cs->debug & L1_DEB_ISAC_FIFO)
  224. debugl1(cs, "hfcsx_read_fifo %d f1(%x) f2(%x) z1(f2)(%x) z2(f2)(%x)",
  225. fifo, f1, f2, z1, z2);
  226. /* now determine bytes in actual FIFO buffer */
  227. count = z1 - z2;
  228. if (count <= 0)
  229. count += fifo_size; /* count now contains buffered bytes */
  230. count++;
  231. if (cs->debug & L1_DEB_ISAC_FIFO)
  232. debugl1(cs, "hfcsx_read_fifo %d count %ld)",
  233. fifo, count);
  234. if ((count > fifo_size) || (count < 4)) {
  235. if (cs->debug & L1_DEB_WARN)
  236. debugl1(cs, "hfcsx_read_fifo %d paket inv. len %d ", fifo , count);
  237. while (count) {
  238. count--; /* empty fifo */
  239. Read_hfc(cs, HFCSX_FIF_DRD);
  240. }
  241. skb = NULL;
  242. } else
  243. if ((skb = dev_alloc_skb(count - 3))) {
  244. count -= 3;
  245. dst = skb_put(skb, count);
  246. while (count--)
  247. *dst++ = Read_hfc(cs, HFCSX_FIF_DRD);
  248. Read_hfc(cs, HFCSX_FIF_DRD); /* CRC 1 */
  249. Read_hfc(cs, HFCSX_FIF_DRD); /* CRC 2 */
  250. if (Read_hfc(cs, HFCSX_FIF_DRD)) {
  251. dev_kfree_skb_irq(skb);
  252. if (cs->debug & L1_DEB_ISAC_FIFO)
  253. debugl1(cs, "hfcsx_read_fifo %d crc error", fifo);
  254. skb = NULL;
  255. }
  256. } else {
  257. printk(KERN_WARNING "HFC-SX: receive out of memory\n");
  258. return(NULL);
  259. }
  260. Read_hfc(cs, HFCSX_FIF_INCF2); /* increment F2 */
  261. udelay(1);
  262. while (bytein(cs->hw.hfcsx.base+1) & 1); /* wait for busy */
  263. udelay(1);
  264. } while (!skb); /* retry in case of crc error */
  265. return(skb);
  266. }
  267. /******************************************/
  268. /* free hardware resources used by driver */
  269. /******************************************/
  270. static void
  271. release_io_hfcsx(struct IsdnCardState *cs)
  272. {
  273. cs->hw.hfcsx.int_m2 = 0; /* interrupt output off ! */
  274. Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
  275. Write_hfc(cs, HFCSX_CIRM, HFCSX_RESET); /* Reset On */
  276. msleep(30); /* Timeout 30ms */
  277. Write_hfc(cs, HFCSX_CIRM, 0); /* Reset Off */
  278. del_timer(&cs->hw.hfcsx.timer);
  279. release_region(cs->hw.hfcsx.base, 2); /* release IO-Block */
  280. kfree(cs->hw.hfcsx.extra);
  281. cs->hw.hfcsx.extra = NULL;
  282. }
  283. /**********************************************************/
  284. /* set_fifo_size determines the size of the RAM and FIFOs */
  285. /* returning 0 -> need to reset the chip again. */
  286. /**********************************************************/
  287. static int set_fifo_size(struct IsdnCardState *cs)
  288. {
  289. if (cs->hw.hfcsx.b_fifo_size) return(1); /* already determined */
  290. if ((cs->hw.hfcsx.chip >> 4) == 9) {
  291. cs->hw.hfcsx.b_fifo_size = B_FIFO_SIZE_32K;
  292. return(1);
  293. }
  294. cs->hw.hfcsx.b_fifo_size = B_FIFO_SIZE_8K;
  295. cs->hw.hfcsx.cirm |= 0x10; /* only 8K of ram */
  296. return(0);
  297. }
  298. /********************************************************************************/
  299. /* function called to reset the HFC SX chip. A complete software reset of chip */
  300. /* and fifos is done. */
  301. /********************************************************************************/
  302. static void
  303. reset_hfcsx(struct IsdnCardState *cs)
  304. {
  305. cs->hw.hfcsx.int_m2 = 0; /* interrupt output off ! */
  306. Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
  307. printk(KERN_INFO "HFC_SX: resetting card\n");
  308. while (1) {
  309. Write_hfc(cs, HFCSX_CIRM, HFCSX_RESET | cs->hw.hfcsx.cirm ); /* Reset */
  310. mdelay(30);
  311. Write_hfc(cs, HFCSX_CIRM, cs->hw.hfcsx.cirm); /* Reset Off */
  312. mdelay(20);
  313. if (Read_hfc(cs, HFCSX_STATUS) & 2)
  314. printk(KERN_WARNING "HFC-SX init bit busy\n");
  315. cs->hw.hfcsx.last_fifo = 0xff; /* invalidate */
  316. if (!set_fifo_size(cs)) continue;
  317. break;
  318. }
  319. cs->hw.hfcsx.trm = 0 + HFCSX_BTRANS_THRESMASK; /* no echo connect , threshold */
  320. Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
  321. Write_hfc(cs, HFCSX_CLKDEL, 0x0e); /* ST-Bit delay for TE-Mode */
  322. cs->hw.hfcsx.sctrl_e = HFCSX_AUTO_AWAKE;
  323. Write_hfc(cs, HFCSX_SCTRL_E, cs->hw.hfcsx.sctrl_e); /* S/T Auto awake */
  324. cs->hw.hfcsx.bswapped = 0; /* no exchange */
  325. cs->hw.hfcsx.nt_mode = 0; /* we are in TE mode */
  326. cs->hw.hfcsx.ctmt = HFCSX_TIM3_125 | HFCSX_AUTO_TIMER;
  327. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
  328. cs->hw.hfcsx.int_m1 = HFCSX_INTS_DTRANS | HFCSX_INTS_DREC |
  329. HFCSX_INTS_L1STATE | HFCSX_INTS_TIMER;
  330. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  331. /* Clear already pending ints */
  332. if (Read_hfc(cs, HFCSX_INT_S1));
  333. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 2); /* HFC ST 2 */
  334. udelay(10);
  335. Write_hfc(cs, HFCSX_STATES, 2); /* HFC ST 2 */
  336. cs->hw.hfcsx.mst_m = HFCSX_MASTER; /* HFC Master Mode */
  337. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  338. cs->hw.hfcsx.sctrl = 0x40; /* set tx_lo mode, error in datasheet ! */
  339. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
  340. cs->hw.hfcsx.sctrl_r = 0;
  341. Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
  342. /* Init GCI/IOM2 in master mode */
  343. /* Slots 0 and 1 are set for B-chan 1 and 2 */
  344. /* D- and monitor/CI channel are not enabled */
  345. /* STIO1 is used as output for data, B1+B2 from ST->IOM+HFC */
  346. /* STIO2 is used as data input, B1+B2 from IOM->ST */
  347. /* ST B-channel send disabled -> continous 1s */
  348. /* The IOM slots are always enabled */
  349. cs->hw.hfcsx.conn = 0x36; /* set data flow directions */
  350. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  351. Write_hfc(cs, HFCSX_B1_SSL, 0x80); /* B1-Slot 0 STIO1 out enabled */
  352. Write_hfc(cs, HFCSX_B2_SSL, 0x81); /* B2-Slot 1 STIO1 out enabled */
  353. Write_hfc(cs, HFCSX_B1_RSL, 0x80); /* B1-Slot 0 STIO2 in enabled */
  354. Write_hfc(cs, HFCSX_B2_RSL, 0x81); /* B2-Slot 1 STIO2 in enabled */
  355. /* Finally enable IRQ output */
  356. cs->hw.hfcsx.int_m2 = HFCSX_IRQ_ENABLE;
  357. Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
  358. if (Read_hfc(cs, HFCSX_INT_S2));
  359. }
  360. /***************************************************/
  361. /* Timer function called when kernel timer expires */
  362. /***************************************************/
  363. static void
  364. hfcsx_Timer(struct IsdnCardState *cs)
  365. {
  366. cs->hw.hfcsx.timer.expires = jiffies + 75;
  367. /* WD RESET */
  368. /* WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcsx.ctmt | 0x80);
  369. add_timer(&cs->hw.hfcsx.timer);
  370. */
  371. }
  372. /************************************************/
  373. /* select a b-channel entry matching and active */
  374. /************************************************/
  375. static
  376. struct BCState *
  377. Sel_BCS(struct IsdnCardState *cs, int channel)
  378. {
  379. if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
  380. return (&cs->bcs[0]);
  381. else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
  382. return (&cs->bcs[1]);
  383. else
  384. return (NULL);
  385. }
  386. /*******************************/
  387. /* D-channel receive procedure */
  388. /*******************************/
  389. static
  390. int
  391. receive_dmsg(struct IsdnCardState *cs)
  392. {
  393. struct sk_buff *skb;
  394. int count = 5;
  395. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  396. debugl1(cs, "rec_dmsg blocked");
  397. return (1);
  398. }
  399. do {
  400. skb = read_fifo(cs, HFCSX_SEL_D_RX, 0);
  401. if (skb) {
  402. skb_queue_tail(&cs->rq, skb);
  403. schedule_event(cs, D_RCVBUFREADY);
  404. }
  405. } while (--count && skb);
  406. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  407. return (1);
  408. }
  409. /**********************************/
  410. /* B-channel main receive routine */
  411. /**********************************/
  412. static void
  413. main_rec_hfcsx(struct BCState *bcs)
  414. {
  415. struct IsdnCardState *cs = bcs->cs;
  416. int count = 5;
  417. struct sk_buff *skb;
  418. Begin:
  419. count--;
  420. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  421. debugl1(cs, "rec_data %d blocked", bcs->channel);
  422. return;
  423. }
  424. skb = read_fifo(cs, ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
  425. HFCSX_SEL_B2_RX : HFCSX_SEL_B1_RX,
  426. (bcs->mode == L1_MODE_TRANS) ?
  427. HFCSX_BTRANS_THRESHOLD : 0);
  428. if (skb) {
  429. skb_queue_tail(&bcs->rqueue, skb);
  430. schedule_event(bcs, B_RCVBUFREADY);
  431. }
  432. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  433. if (count && skb)
  434. goto Begin;
  435. return;
  436. }
  437. /**************************/
  438. /* D-channel send routine */
  439. /**************************/
  440. static void
  441. hfcsx_fill_dfifo(struct IsdnCardState *cs)
  442. {
  443. if (!cs->tx_skb)
  444. return;
  445. if (cs->tx_skb->len <= 0)
  446. return;
  447. if (write_fifo(cs, cs->tx_skb, HFCSX_SEL_D_TX, 0)) {
  448. dev_kfree_skb_any(cs->tx_skb);
  449. cs->tx_skb = NULL;
  450. }
  451. return;
  452. }
  453. /**************************/
  454. /* B-channel send routine */
  455. /**************************/
  456. static void
  457. hfcsx_fill_fifo(struct BCState *bcs)
  458. {
  459. struct IsdnCardState *cs = bcs->cs;
  460. if (!bcs->tx_skb)
  461. return;
  462. if (bcs->tx_skb->len <= 0)
  463. return;
  464. if (write_fifo(cs, bcs->tx_skb,
  465. ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
  466. HFCSX_SEL_B2_TX : HFCSX_SEL_B1_TX,
  467. (bcs->mode == L1_MODE_TRANS) ?
  468. HFCSX_BTRANS_THRESHOLD : 0)) {
  469. bcs->tx_cnt -= bcs->tx_skb->len;
  470. if (test_bit(FLG_LLI_L1WAKEUP,&bcs->st->lli.flag) &&
  471. (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
  472. u_long flags;
  473. spin_lock_irqsave(&bcs->aclock, flags);
  474. bcs->ackcnt += bcs->tx_skb->len;
  475. spin_unlock_irqrestore(&bcs->aclock, flags);
  476. schedule_event(bcs, B_ACKPENDING);
  477. }
  478. dev_kfree_skb_any(bcs->tx_skb);
  479. bcs->tx_skb = NULL;
  480. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  481. }
  482. }
  483. /**********************************************/
  484. /* D-channel l1 state call for leased NT-mode */
  485. /**********************************************/
  486. static void
  487. dch_nt_l2l1(struct PStack *st, int pr, void *arg)
  488. {
  489. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  490. switch (pr) {
  491. case (PH_DATA | REQUEST):
  492. case (PH_PULL | REQUEST):
  493. case (PH_PULL | INDICATION):
  494. st->l1.l1hw(st, pr, arg);
  495. break;
  496. case (PH_ACTIVATE | REQUEST):
  497. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  498. break;
  499. case (PH_TESTLOOP | REQUEST):
  500. if (1 & (long) arg)
  501. debugl1(cs, "PH_TEST_LOOP B1");
  502. if (2 & (long) arg)
  503. debugl1(cs, "PH_TEST_LOOP B2");
  504. if (!(3 & (long) arg))
  505. debugl1(cs, "PH_TEST_LOOP DISABLED");
  506. st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
  507. break;
  508. default:
  509. if (cs->debug)
  510. debugl1(cs, "dch_nt_l2l1 msg %04X unhandled", pr);
  511. break;
  512. }
  513. }
  514. /***********************/
  515. /* set/reset echo mode */
  516. /***********************/
  517. static int
  518. hfcsx_auxcmd(struct IsdnCardState *cs, isdn_ctrl * ic)
  519. {
  520. unsigned long flags;
  521. int i = *(unsigned int *) ic->parm.num;
  522. if ((ic->arg == 98) &&
  523. (!(cs->hw.hfcsx.int_m1 & (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC + HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC)))) {
  524. spin_lock_irqsave(&cs->lock, flags);
  525. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 0); /* HFC ST G0 */
  526. udelay(10);
  527. cs->hw.hfcsx.sctrl |= SCTRL_MODE_NT;
  528. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl); /* set NT-mode */
  529. udelay(10);
  530. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 1); /* HFC ST G1 */
  531. udelay(10);
  532. Write_hfc(cs, HFCSX_STATES, 1 | HFCSX_ACTIVATE | HFCSX_DO_ACTION);
  533. cs->dc.hfcsx.ph_state = 1;
  534. cs->hw.hfcsx.nt_mode = 1;
  535. cs->hw.hfcsx.nt_timer = 0;
  536. spin_unlock_irqrestore(&cs->lock, flags);
  537. cs->stlist->l2.l2l1 = dch_nt_l2l1;
  538. debugl1(cs, "NT mode activated");
  539. return (0);
  540. }
  541. if ((cs->chanlimit > 1) || (cs->hw.hfcsx.bswapped) ||
  542. (cs->hw.hfcsx.nt_mode) || (ic->arg != 12))
  543. return (-EINVAL);
  544. if (i) {
  545. cs->logecho = 1;
  546. cs->hw.hfcsx.trm |= 0x20; /* enable echo chan */
  547. cs->hw.hfcsx.int_m1 |= HFCSX_INTS_B2REC;
  548. /* reset Channel !!!!! */
  549. } else {
  550. cs->logecho = 0;
  551. cs->hw.hfcsx.trm &= ~0x20; /* disable echo chan */
  552. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_B2REC;
  553. }
  554. cs->hw.hfcsx.sctrl_r &= ~SCTRL_B2_ENA;
  555. cs->hw.hfcsx.sctrl &= ~SCTRL_B2_ENA;
  556. cs->hw.hfcsx.conn |= 0x10; /* B2-IOM -> B2-ST */
  557. cs->hw.hfcsx.ctmt &= ~2;
  558. spin_lock_irqsave(&cs->lock, flags);
  559. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
  560. Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
  561. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
  562. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  563. Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
  564. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  565. spin_unlock_irqrestore(&cs->lock, flags);
  566. return (0);
  567. } /* hfcsx_auxcmd */
  568. /*****************************/
  569. /* E-channel receive routine */
  570. /*****************************/
  571. static void
  572. receive_emsg(struct IsdnCardState *cs)
  573. {
  574. int count = 5;
  575. u_char *ptr;
  576. struct sk_buff *skb;
  577. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  578. debugl1(cs, "echo_rec_data blocked");
  579. return;
  580. }
  581. do {
  582. skb = read_fifo(cs, HFCSX_SEL_B2_RX, 0);
  583. if (skb) {
  584. if (cs->debug & DEB_DLOG_HEX) {
  585. ptr = cs->dlog;
  586. if ((skb->len) < MAX_DLOG_SPACE / 3 - 10) {
  587. *ptr++ = 'E';
  588. *ptr++ = 'C';
  589. *ptr++ = 'H';
  590. *ptr++ = 'O';
  591. *ptr++ = ':';
  592. ptr += QuickHex(ptr, skb->data, skb->len);
  593. ptr--;
  594. *ptr++ = '\n';
  595. *ptr = 0;
  596. HiSax_putstatus(cs, NULL, cs->dlog);
  597. } else
  598. HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
  599. }
  600. dev_kfree_skb_any(skb);
  601. }
  602. } while (--count && skb);
  603. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  604. return;
  605. } /* receive_emsg */
  606. /*********************/
  607. /* Interrupt handler */
  608. /*********************/
  609. static irqreturn_t
  610. hfcsx_interrupt(int intno, void *dev_id)
  611. {
  612. struct IsdnCardState *cs = dev_id;
  613. u_char exval;
  614. struct BCState *bcs;
  615. int count = 15;
  616. u_long flags;
  617. u_char val, stat;
  618. if (!(cs->hw.hfcsx.int_m2 & 0x08))
  619. return IRQ_NONE; /* not initialised */
  620. spin_lock_irqsave(&cs->lock, flags);
  621. if (HFCSX_ANYINT & (stat = Read_hfc(cs, HFCSX_STATUS))) {
  622. val = Read_hfc(cs, HFCSX_INT_S1);
  623. if (cs->debug & L1_DEB_ISAC)
  624. debugl1(cs, "HFC-SX: stat(%02x) s1(%02x)", stat, val);
  625. } else {
  626. spin_unlock_irqrestore(&cs->lock, flags);
  627. return IRQ_NONE;
  628. }
  629. if (cs->debug & L1_DEB_ISAC)
  630. debugl1(cs, "HFC-SX irq %x %s", val,
  631. test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
  632. "locked" : "unlocked");
  633. val &= cs->hw.hfcsx.int_m1;
  634. if (val & 0x40) { /* state machine irq */
  635. exval = Read_hfc(cs, HFCSX_STATES) & 0xf;
  636. if (cs->debug & L1_DEB_ISAC)
  637. debugl1(cs, "ph_state chg %d->%d", cs->dc.hfcsx.ph_state,
  638. exval);
  639. cs->dc.hfcsx.ph_state = exval;
  640. schedule_event(cs, D_L1STATECHANGE);
  641. val &= ~0x40;
  642. }
  643. if (val & 0x80) { /* timer irq */
  644. if (cs->hw.hfcsx.nt_mode) {
  645. if ((--cs->hw.hfcsx.nt_timer) < 0)
  646. schedule_event(cs, D_L1STATECHANGE);
  647. }
  648. val &= ~0x80;
  649. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  650. }
  651. while (val) {
  652. if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  653. cs->hw.hfcsx.int_s1 |= val;
  654. spin_unlock_irqrestore(&cs->lock, flags);
  655. return IRQ_HANDLED;
  656. }
  657. if (cs->hw.hfcsx.int_s1 & 0x18) {
  658. exval = val;
  659. val = cs->hw.hfcsx.int_s1;
  660. cs->hw.hfcsx.int_s1 = exval;
  661. }
  662. if (val & 0x08) {
  663. if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
  664. if (cs->debug)
  665. debugl1(cs, "hfcsx spurious 0x08 IRQ");
  666. } else
  667. main_rec_hfcsx(bcs);
  668. }
  669. if (val & 0x10) {
  670. if (cs->logecho)
  671. receive_emsg(cs);
  672. else if (!(bcs = Sel_BCS(cs, 1))) {
  673. if (cs->debug)
  674. debugl1(cs, "hfcsx spurious 0x10 IRQ");
  675. } else
  676. main_rec_hfcsx(bcs);
  677. }
  678. if (val & 0x01) {
  679. if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
  680. if (cs->debug)
  681. debugl1(cs, "hfcsx spurious 0x01 IRQ");
  682. } else {
  683. if (bcs->tx_skb) {
  684. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  685. hfcsx_fill_fifo(bcs);
  686. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  687. } else
  688. debugl1(cs, "fill_data %d blocked", bcs->channel);
  689. } else {
  690. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  691. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  692. hfcsx_fill_fifo(bcs);
  693. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  694. } else
  695. debugl1(cs, "fill_data %d blocked", bcs->channel);
  696. } else {
  697. schedule_event(bcs, B_XMTBUFREADY);
  698. }
  699. }
  700. }
  701. }
  702. if (val & 0x02) {
  703. if (!(bcs = Sel_BCS(cs, 1))) {
  704. if (cs->debug)
  705. debugl1(cs, "hfcsx spurious 0x02 IRQ");
  706. } else {
  707. if (bcs->tx_skb) {
  708. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  709. hfcsx_fill_fifo(bcs);
  710. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  711. } else
  712. debugl1(cs, "fill_data %d blocked", bcs->channel);
  713. } else {
  714. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  715. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  716. hfcsx_fill_fifo(bcs);
  717. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  718. } else
  719. debugl1(cs, "fill_data %d blocked", bcs->channel);
  720. } else {
  721. schedule_event(bcs, B_XMTBUFREADY);
  722. }
  723. }
  724. }
  725. }
  726. if (val & 0x20) { /* receive dframe */
  727. receive_dmsg(cs);
  728. }
  729. if (val & 0x04) { /* dframe transmitted */
  730. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  731. del_timer(&cs->dbusytimer);
  732. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  733. schedule_event(cs, D_CLEARBUSY);
  734. if (cs->tx_skb) {
  735. if (cs->tx_skb->len) {
  736. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  737. hfcsx_fill_dfifo(cs);
  738. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  739. } else {
  740. debugl1(cs, "hfcsx_fill_dfifo irq blocked");
  741. }
  742. goto afterXPR;
  743. } else {
  744. dev_kfree_skb_irq(cs->tx_skb);
  745. cs->tx_cnt = 0;
  746. cs->tx_skb = NULL;
  747. }
  748. }
  749. if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
  750. cs->tx_cnt = 0;
  751. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  752. hfcsx_fill_dfifo(cs);
  753. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  754. } else {
  755. debugl1(cs, "hfcsx_fill_dfifo irq blocked");
  756. }
  757. } else
  758. schedule_event(cs, D_XMTBUFREADY);
  759. }
  760. afterXPR:
  761. if (cs->hw.hfcsx.int_s1 && count--) {
  762. val = cs->hw.hfcsx.int_s1;
  763. cs->hw.hfcsx.int_s1 = 0;
  764. if (cs->debug & L1_DEB_ISAC)
  765. debugl1(cs, "HFC-SX irq %x loop %d", val, 15 - count);
  766. } else
  767. val = 0;
  768. }
  769. spin_unlock_irqrestore(&cs->lock, flags);
  770. return IRQ_HANDLED;
  771. }
  772. /********************************************************************/
  773. /* timer callback for D-chan busy resolution. Currently no function */
  774. /********************************************************************/
  775. static void
  776. hfcsx_dbusy_timer(struct IsdnCardState *cs)
  777. {
  778. }
  779. /*************************************/
  780. /* Layer 1 D-channel hardware access */
  781. /*************************************/
  782. static void
  783. HFCSX_l1hw(struct PStack *st, int pr, void *arg)
  784. {
  785. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  786. struct sk_buff *skb = arg;
  787. u_long flags;
  788. switch (pr) {
  789. case (PH_DATA | REQUEST):
  790. if (cs->debug & DEB_DLOG_HEX)
  791. LogFrame(cs, skb->data, skb->len);
  792. if (cs->debug & DEB_DLOG_VERBOSE)
  793. dlogframe(cs, skb, 0);
  794. spin_lock_irqsave(&cs->lock, flags);
  795. if (cs->tx_skb) {
  796. skb_queue_tail(&cs->sq, skb);
  797. #ifdef L2FRAME_DEBUG /* psa */
  798. if (cs->debug & L1_DEB_LAPD)
  799. Logl2Frame(cs, skb, "PH_DATA Queued", 0);
  800. #endif
  801. } else {
  802. cs->tx_skb = skb;
  803. cs->tx_cnt = 0;
  804. #ifdef L2FRAME_DEBUG /* psa */
  805. if (cs->debug & L1_DEB_LAPD)
  806. Logl2Frame(cs, skb, "PH_DATA", 0);
  807. #endif
  808. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  809. hfcsx_fill_dfifo(cs);
  810. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  811. } else
  812. debugl1(cs, "hfcsx_fill_dfifo blocked");
  813. }
  814. spin_unlock_irqrestore(&cs->lock, flags);
  815. break;
  816. case (PH_PULL | INDICATION):
  817. spin_lock_irqsave(&cs->lock, flags);
  818. if (cs->tx_skb) {
  819. if (cs->debug & L1_DEB_WARN)
  820. debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
  821. skb_queue_tail(&cs->sq, skb);
  822. spin_unlock_irqrestore(&cs->lock, flags);
  823. break;
  824. }
  825. if (cs->debug & DEB_DLOG_HEX)
  826. LogFrame(cs, skb->data, skb->len);
  827. if (cs->debug & DEB_DLOG_VERBOSE)
  828. dlogframe(cs, skb, 0);
  829. cs->tx_skb = skb;
  830. cs->tx_cnt = 0;
  831. #ifdef L2FRAME_DEBUG /* psa */
  832. if (cs->debug & L1_DEB_LAPD)
  833. Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
  834. #endif
  835. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  836. hfcsx_fill_dfifo(cs);
  837. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  838. } else
  839. debugl1(cs, "hfcsx_fill_dfifo blocked");
  840. spin_unlock_irqrestore(&cs->lock, flags);
  841. break;
  842. case (PH_PULL | REQUEST):
  843. #ifdef L2FRAME_DEBUG /* psa */
  844. if (cs->debug & L1_DEB_LAPD)
  845. debugl1(cs, "-> PH_REQUEST_PULL");
  846. #endif
  847. if (!cs->tx_skb) {
  848. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  849. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  850. } else
  851. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  852. break;
  853. case (HW_RESET | REQUEST):
  854. spin_lock_irqsave(&cs->lock, flags);
  855. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 3); /* HFC ST 3 */
  856. udelay(6);
  857. Write_hfc(cs, HFCSX_STATES, 3); /* HFC ST 2 */
  858. cs->hw.hfcsx.mst_m |= HFCSX_MASTER;
  859. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  860. Write_hfc(cs, HFCSX_STATES, HFCSX_ACTIVATE | HFCSX_DO_ACTION);
  861. spin_unlock_irqrestore(&cs->lock, flags);
  862. l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
  863. break;
  864. case (HW_ENABLE | REQUEST):
  865. spin_lock_irqsave(&cs->lock, flags);
  866. Write_hfc(cs, HFCSX_STATES, HFCSX_ACTIVATE | HFCSX_DO_ACTION);
  867. spin_unlock_irqrestore(&cs->lock, flags);
  868. break;
  869. case (HW_DEACTIVATE | REQUEST):
  870. spin_lock_irqsave(&cs->lock, flags);
  871. cs->hw.hfcsx.mst_m &= ~HFCSX_MASTER;
  872. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  873. spin_unlock_irqrestore(&cs->lock, flags);
  874. break;
  875. case (HW_INFO3 | REQUEST):
  876. spin_lock_irqsave(&cs->lock, flags);
  877. cs->hw.hfcsx.mst_m |= HFCSX_MASTER;
  878. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  879. spin_unlock_irqrestore(&cs->lock, flags);
  880. break;
  881. case (HW_TESTLOOP | REQUEST):
  882. spin_lock_irqsave(&cs->lock, flags);
  883. switch ((long) arg) {
  884. case (1):
  885. Write_hfc(cs, HFCSX_B1_SSL, 0x80); /* tx slot */
  886. Write_hfc(cs, HFCSX_B1_RSL, 0x80); /* rx slot */
  887. cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~7) | 1;
  888. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  889. break;
  890. case (2):
  891. Write_hfc(cs, HFCSX_B2_SSL, 0x81); /* tx slot */
  892. Write_hfc(cs, HFCSX_B2_RSL, 0x81); /* rx slot */
  893. cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~0x38) | 0x08;
  894. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  895. break;
  896. default:
  897. spin_unlock_irqrestore(&cs->lock, flags);
  898. if (cs->debug & L1_DEB_WARN)
  899. debugl1(cs, "hfcsx_l1hw loop invalid %4lx", arg);
  900. return;
  901. }
  902. cs->hw.hfcsx.trm |= 0x80; /* enable IOM-loop */
  903. Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
  904. spin_unlock_irqrestore(&cs->lock, flags);
  905. break;
  906. default:
  907. if (cs->debug & L1_DEB_WARN)
  908. debugl1(cs, "hfcsx_l1hw unknown pr %4x", pr);
  909. break;
  910. }
  911. }
  912. /***********************************************/
  913. /* called during init setting l1 stack pointer */
  914. /***********************************************/
  915. static void
  916. setstack_hfcsx(struct PStack *st, struct IsdnCardState *cs)
  917. {
  918. st->l1.l1hw = HFCSX_l1hw;
  919. }
  920. /**************************************/
  921. /* send B-channel data if not blocked */
  922. /**************************************/
  923. static void
  924. hfcsx_send_data(struct BCState *bcs)
  925. {
  926. struct IsdnCardState *cs = bcs->cs;
  927. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  928. hfcsx_fill_fifo(bcs);
  929. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  930. } else
  931. debugl1(cs, "send_data %d blocked", bcs->channel);
  932. }
  933. /***************************************************************/
  934. /* activate/deactivate hardware for selected channels and mode */
  935. /***************************************************************/
  936. static void
  937. mode_hfcsx(struct BCState *bcs, int mode, int bc)
  938. {
  939. struct IsdnCardState *cs = bcs->cs;
  940. int fifo2;
  941. if (cs->debug & L1_DEB_HSCX)
  942. debugl1(cs, "HFCSX bchannel mode %d bchan %d/%d",
  943. mode, bc, bcs->channel);
  944. bcs->mode = mode;
  945. bcs->channel = bc;
  946. fifo2 = bc;
  947. if (cs->chanlimit > 1) {
  948. cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
  949. cs->hw.hfcsx.sctrl_e &= ~0x80;
  950. } else {
  951. if (bc) {
  952. if (mode != L1_MODE_NULL) {
  953. cs->hw.hfcsx.bswapped = 1; /* B1 and B2 exchanged */
  954. cs->hw.hfcsx.sctrl_e |= 0x80;
  955. } else {
  956. cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
  957. cs->hw.hfcsx.sctrl_e &= ~0x80;
  958. }
  959. fifo2 = 0;
  960. } else {
  961. cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
  962. cs->hw.hfcsx.sctrl_e &= ~0x80;
  963. }
  964. }
  965. switch (mode) {
  966. case (L1_MODE_NULL):
  967. if (bc) {
  968. cs->hw.hfcsx.sctrl &= ~SCTRL_B2_ENA;
  969. cs->hw.hfcsx.sctrl_r &= ~SCTRL_B2_ENA;
  970. } else {
  971. cs->hw.hfcsx.sctrl &= ~SCTRL_B1_ENA;
  972. cs->hw.hfcsx.sctrl_r &= ~SCTRL_B1_ENA;
  973. }
  974. if (fifo2) {
  975. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  976. } else {
  977. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  978. }
  979. break;
  980. case (L1_MODE_TRANS):
  981. if (bc) {
  982. cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
  983. cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
  984. } else {
  985. cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
  986. cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
  987. }
  988. if (fifo2) {
  989. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  990. cs->hw.hfcsx.ctmt |= 2;
  991. cs->hw.hfcsx.conn &= ~0x18;
  992. } else {
  993. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  994. cs->hw.hfcsx.ctmt |= 1;
  995. cs->hw.hfcsx.conn &= ~0x03;
  996. }
  997. break;
  998. case (L1_MODE_HDLC):
  999. if (bc) {
  1000. cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
  1001. cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
  1002. } else {
  1003. cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
  1004. cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
  1005. }
  1006. if (fifo2) {
  1007. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  1008. cs->hw.hfcsx.ctmt &= ~2;
  1009. cs->hw.hfcsx.conn &= ~0x18;
  1010. } else {
  1011. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  1012. cs->hw.hfcsx.ctmt &= ~1;
  1013. cs->hw.hfcsx.conn &= ~0x03;
  1014. }
  1015. break;
  1016. case (L1_MODE_EXTRN):
  1017. if (bc) {
  1018. cs->hw.hfcsx.conn |= 0x10;
  1019. cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
  1020. cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
  1021. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  1022. } else {
  1023. cs->hw.hfcsx.conn |= 0x02;
  1024. cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
  1025. cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
  1026. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  1027. }
  1028. break;
  1029. }
  1030. Write_hfc(cs, HFCSX_SCTRL_E, cs->hw.hfcsx.sctrl_e);
  1031. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1032. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
  1033. Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
  1034. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
  1035. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  1036. if (mode != L1_MODE_EXTRN) {
  1037. reset_fifo(cs, fifo2 ? HFCSX_SEL_B2_RX : HFCSX_SEL_B1_RX);
  1038. reset_fifo(cs, fifo2 ? HFCSX_SEL_B2_TX : HFCSX_SEL_B1_TX);
  1039. }
  1040. }
  1041. /******************************/
  1042. /* Layer2 -> Layer 1 Transfer */
  1043. /******************************/
  1044. static void
  1045. hfcsx_l2l1(struct PStack *st, int pr, void *arg)
  1046. {
  1047. struct BCState *bcs = st->l1.bcs;
  1048. struct sk_buff *skb = arg;
  1049. u_long flags;
  1050. switch (pr) {
  1051. case (PH_DATA | REQUEST):
  1052. spin_lock_irqsave(&bcs->cs->lock, flags);
  1053. if (bcs->tx_skb) {
  1054. skb_queue_tail(&bcs->squeue, skb);
  1055. } else {
  1056. bcs->tx_skb = skb;
  1057. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1058. bcs->cs->BC_Send_Data(bcs);
  1059. }
  1060. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1061. break;
  1062. case (PH_PULL | INDICATION):
  1063. spin_lock_irqsave(&bcs->cs->lock, flags);
  1064. if (bcs->tx_skb) {
  1065. printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
  1066. } else {
  1067. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1068. bcs->tx_skb = skb;
  1069. bcs->cs->BC_Send_Data(bcs);
  1070. }
  1071. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1072. break;
  1073. case (PH_PULL | REQUEST):
  1074. if (!bcs->tx_skb) {
  1075. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1076. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  1077. } else
  1078. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1079. break;
  1080. case (PH_ACTIVATE | REQUEST):
  1081. spin_lock_irqsave(&bcs->cs->lock, flags);
  1082. test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
  1083. mode_hfcsx(bcs, st->l1.mode, st->l1.bc);
  1084. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1085. l1_msg_b(st, pr, arg);
  1086. break;
  1087. case (PH_DEACTIVATE | REQUEST):
  1088. l1_msg_b(st, pr, arg);
  1089. break;
  1090. case (PH_DEACTIVATE | CONFIRM):
  1091. spin_lock_irqsave(&bcs->cs->lock, flags);
  1092. test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
  1093. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1094. mode_hfcsx(bcs, 0, st->l1.bc);
  1095. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1096. st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
  1097. break;
  1098. }
  1099. }
  1100. /******************************************/
  1101. /* deactivate B-channel access and queues */
  1102. /******************************************/
  1103. static void
  1104. close_hfcsx(struct BCState *bcs)
  1105. {
  1106. mode_hfcsx(bcs, 0, bcs->channel);
  1107. if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
  1108. skb_queue_purge(&bcs->rqueue);
  1109. skb_queue_purge(&bcs->squeue);
  1110. if (bcs->tx_skb) {
  1111. dev_kfree_skb_any(bcs->tx_skb);
  1112. bcs->tx_skb = NULL;
  1113. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1114. }
  1115. }
  1116. }
  1117. /*************************************/
  1118. /* init B-channel queues and control */
  1119. /*************************************/
  1120. static int
  1121. open_hfcsxstate(struct IsdnCardState *cs, struct BCState *bcs)
  1122. {
  1123. if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
  1124. skb_queue_head_init(&bcs->rqueue);
  1125. skb_queue_head_init(&bcs->squeue);
  1126. }
  1127. bcs->tx_skb = NULL;
  1128. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1129. bcs->event = 0;
  1130. bcs->tx_cnt = 0;
  1131. return (0);
  1132. }
  1133. /*********************************/
  1134. /* inits the stack for B-channel */
  1135. /*********************************/
  1136. static int
  1137. setstack_2b(struct PStack *st, struct BCState *bcs)
  1138. {
  1139. bcs->channel = st->l1.bc;
  1140. if (open_hfcsxstate(st->l1.hardware, bcs))
  1141. return (-1);
  1142. st->l1.bcs = bcs;
  1143. st->l2.l2l1 = hfcsx_l2l1;
  1144. setstack_manager(st);
  1145. bcs->st = st;
  1146. setstack_l1_B(st);
  1147. return (0);
  1148. }
  1149. /***************************/
  1150. /* handle L1 state changes */
  1151. /***************************/
  1152. static void
  1153. hfcsx_bh(struct work_struct *work)
  1154. {
  1155. struct IsdnCardState *cs =
  1156. container_of(work, struct IsdnCardState, tqueue);
  1157. u_long flags;
  1158. if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
  1159. if (!cs->hw.hfcsx.nt_mode)
  1160. switch (cs->dc.hfcsx.ph_state) {
  1161. case (0):
  1162. l1_msg(cs, HW_RESET | INDICATION, NULL);
  1163. break;
  1164. case (3):
  1165. l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
  1166. break;
  1167. case (8):
  1168. l1_msg(cs, HW_RSYNC | INDICATION, NULL);
  1169. break;
  1170. case (6):
  1171. l1_msg(cs, HW_INFO2 | INDICATION, NULL);
  1172. break;
  1173. case (7):
  1174. l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
  1175. break;
  1176. default:
  1177. break;
  1178. } else {
  1179. switch (cs->dc.hfcsx.ph_state) {
  1180. case (2):
  1181. spin_lock_irqsave(&cs->lock, flags);
  1182. if (cs->hw.hfcsx.nt_timer < 0) {
  1183. cs->hw.hfcsx.nt_timer = 0;
  1184. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1185. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1186. /* Clear already pending ints */
  1187. if (Read_hfc(cs, HFCSX_INT_S1));
  1188. Write_hfc(cs, HFCSX_STATES, 4 | HFCSX_LOAD_STATE);
  1189. udelay(10);
  1190. Write_hfc(cs, HFCSX_STATES, 4);
  1191. cs->dc.hfcsx.ph_state = 4;
  1192. } else {
  1193. cs->hw.hfcsx.int_m1 |= HFCSX_INTS_TIMER;
  1194. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1195. cs->hw.hfcsx.ctmt &= ~HFCSX_AUTO_TIMER;
  1196. cs->hw.hfcsx.ctmt |= HFCSX_TIM3_125;
  1197. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  1198. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  1199. cs->hw.hfcsx.nt_timer = NT_T1_COUNT;
  1200. Write_hfc(cs, HFCSX_STATES, 2 | HFCSX_NT_G2_G3); /* allow G2 -> G3 transition */
  1201. }
  1202. spin_unlock_irqrestore(&cs->lock, flags);
  1203. break;
  1204. case (1):
  1205. case (3):
  1206. case (4):
  1207. spin_lock_irqsave(&cs->lock, flags);
  1208. cs->hw.hfcsx.nt_timer = 0;
  1209. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1210. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1211. spin_unlock_irqrestore(&cs->lock, flags);
  1212. break;
  1213. default:
  1214. break;
  1215. }
  1216. }
  1217. }
  1218. if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
  1219. DChannel_proc_rcv(cs);
  1220. if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
  1221. DChannel_proc_xmt(cs);
  1222. }
  1223. /********************************/
  1224. /* called for card init message */
  1225. /********************************/
  1226. static void inithfcsx(struct IsdnCardState *cs)
  1227. {
  1228. cs->setstack_d = setstack_hfcsx;
  1229. cs->BC_Send_Data = &hfcsx_send_data;
  1230. cs->bcs[0].BC_SetStack = setstack_2b;
  1231. cs->bcs[1].BC_SetStack = setstack_2b;
  1232. cs->bcs[0].BC_Close = close_hfcsx;
  1233. cs->bcs[1].BC_Close = close_hfcsx;
  1234. mode_hfcsx(cs->bcs, 0, 0);
  1235. mode_hfcsx(cs->bcs + 1, 0, 1);
  1236. }
  1237. /*******************************************/
  1238. /* handle card messages from control layer */
  1239. /*******************************************/
  1240. static int
  1241. hfcsx_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  1242. {
  1243. u_long flags;
  1244. if (cs->debug & L1_DEB_ISAC)
  1245. debugl1(cs, "HFCSX: card_msg %x", mt);
  1246. switch (mt) {
  1247. case CARD_RESET:
  1248. spin_lock_irqsave(&cs->lock, flags);
  1249. reset_hfcsx(cs);
  1250. spin_unlock_irqrestore(&cs->lock, flags);
  1251. return (0);
  1252. case CARD_RELEASE:
  1253. release_io_hfcsx(cs);
  1254. return (0);
  1255. case CARD_INIT:
  1256. spin_lock_irqsave(&cs->lock, flags);
  1257. inithfcsx(cs);
  1258. spin_unlock_irqrestore(&cs->lock, flags);
  1259. msleep(80); /* Timeout 80ms */
  1260. /* now switch timer interrupt off */
  1261. spin_lock_irqsave(&cs->lock, flags);
  1262. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1263. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1264. /* reinit mode reg */
  1265. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  1266. spin_unlock_irqrestore(&cs->lock, flags);
  1267. return (0);
  1268. case CARD_TEST:
  1269. return (0);
  1270. }
  1271. return (0);
  1272. }
  1273. #ifdef __ISAPNP__
  1274. static struct isapnp_device_id hfc_ids[] __devinitdata = {
  1275. { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2620),
  1276. ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2620),
  1277. (unsigned long) "Teles 16.3c2" },
  1278. { 0, }
  1279. };
  1280. static struct isapnp_device_id *ipid __devinitdata = &hfc_ids[0];
  1281. static struct pnp_card *pnp_c __devinitdata = NULL;
  1282. #endif
  1283. int __devinit
  1284. setup_hfcsx(struct IsdnCard *card)
  1285. {
  1286. struct IsdnCardState *cs = card->cs;
  1287. char tmp[64];
  1288. strcpy(tmp, hfcsx_revision);
  1289. printk(KERN_INFO "HiSax: HFC-SX driver Rev. %s\n", HiSax_getrev(tmp));
  1290. #ifdef __ISAPNP__
  1291. if (!card->para[1] && isapnp_present()) {
  1292. struct pnp_dev *pnp_d;
  1293. while(ipid->card_vendor) {
  1294. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  1295. ipid->card_device, pnp_c))) {
  1296. pnp_d = NULL;
  1297. if ((pnp_d = pnp_find_dev(pnp_c,
  1298. ipid->vendor, ipid->function, pnp_d))) {
  1299. int err;
  1300. printk(KERN_INFO "HiSax: %s detected\n",
  1301. (char *)ipid->driver_data);
  1302. pnp_disable_dev(pnp_d);
  1303. err = pnp_activate_dev(pnp_d);
  1304. if (err<0) {
  1305. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  1306. __func__, err);
  1307. return(0);
  1308. }
  1309. card->para[1] = pnp_port_start(pnp_d, 0);
  1310. card->para[0] = pnp_irq(pnp_d, 0);
  1311. if (!card->para[0] || !card->para[1]) {
  1312. printk(KERN_ERR "HFC PnP:some resources are missing %ld/%lx\n",
  1313. card->para[0], card->para[1]);
  1314. pnp_disable_dev(pnp_d);
  1315. return(0);
  1316. }
  1317. break;
  1318. } else {
  1319. printk(KERN_ERR "HFC PnP: PnP error card found, no device\n");
  1320. }
  1321. }
  1322. ipid++;
  1323. pnp_c = NULL;
  1324. }
  1325. if (!ipid->card_vendor) {
  1326. printk(KERN_INFO "HFC PnP: no ISAPnP card found\n");
  1327. return(0);
  1328. }
  1329. }
  1330. #endif
  1331. cs->hw.hfcsx.base = card->para[1] & 0xfffe;
  1332. cs->irq = card->para[0];
  1333. cs->hw.hfcsx.int_s1 = 0;
  1334. cs->dc.hfcsx.ph_state = 0;
  1335. cs->hw.hfcsx.fifo = 255;
  1336. if ((cs->typ == ISDN_CTYPE_HFC_SX) ||
  1337. (cs->typ == ISDN_CTYPE_HFC_SP_PCMCIA)) {
  1338. if ((!cs->hw.hfcsx.base) || !request_region(cs->hw.hfcsx.base, 2, "HFCSX isdn")) {
  1339. printk(KERN_WARNING
  1340. "HiSax: HFC-SX io-base %#lx already in use\n",
  1341. cs->hw.hfcsx.base);
  1342. return(0);
  1343. }
  1344. byteout(cs->hw.hfcsx.base, cs->hw.hfcsx.base & 0xFF);
  1345. byteout(cs->hw.hfcsx.base + 1,
  1346. ((cs->hw.hfcsx.base >> 8) & 3) | 0x54);
  1347. udelay(10);
  1348. cs->hw.hfcsx.chip = Read_hfc(cs,HFCSX_CHIP_ID);
  1349. switch (cs->hw.hfcsx.chip >> 4) {
  1350. case 1:
  1351. tmp[0] ='+';
  1352. break;
  1353. case 9:
  1354. tmp[0] ='P';
  1355. break;
  1356. default:
  1357. printk(KERN_WARNING
  1358. "HFC-SX: invalid chip id 0x%x\n",
  1359. cs->hw.hfcsx.chip >> 4);
  1360. release_region(cs->hw.hfcsx.base, 2);
  1361. return(0);
  1362. }
  1363. if (!ccd_sp_irqtab[cs->irq & 0xF]) {
  1364. printk(KERN_WARNING
  1365. "HFC_SX: invalid irq %d specified\n",cs->irq & 0xF);
  1366. release_region(cs->hw.hfcsx.base, 2);
  1367. return(0);
  1368. }
  1369. if (!(cs->hw.hfcsx.extra = (void *)
  1370. kmalloc(sizeof(struct hfcsx_extra), GFP_ATOMIC))) {
  1371. release_region(cs->hw.hfcsx.base, 2);
  1372. printk(KERN_WARNING "HFC-SX: unable to allocate memory\n");
  1373. return(0);
  1374. }
  1375. printk(KERN_INFO "HFC-S%c chip detected at base 0x%x IRQ %d HZ %d\n",
  1376. tmp[0], (u_int) cs->hw.hfcsx.base, cs->irq, HZ);
  1377. cs->hw.hfcsx.int_m2 = 0; /* disable alle interrupts */
  1378. cs->hw.hfcsx.int_m1 = 0;
  1379. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1380. Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
  1381. } else
  1382. return (0); /* no valid card type */
  1383. cs->dbusytimer.function = (void *) hfcsx_dbusy_timer;
  1384. cs->dbusytimer.data = (long) cs;
  1385. init_timer(&cs->dbusytimer);
  1386. INIT_WORK(&cs->tqueue, hfcsx_bh);
  1387. cs->readisac = NULL;
  1388. cs->writeisac = NULL;
  1389. cs->readisacfifo = NULL;
  1390. cs->writeisacfifo = NULL;
  1391. cs->BC_Read_Reg = NULL;
  1392. cs->BC_Write_Reg = NULL;
  1393. cs->irq_func = &hfcsx_interrupt;
  1394. cs->hw.hfcsx.timer.function = (void *) hfcsx_Timer;
  1395. cs->hw.hfcsx.timer.data = (long) cs;
  1396. cs->hw.hfcsx.b_fifo_size = 0; /* fifo size still unknown */
  1397. cs->hw.hfcsx.cirm = ccd_sp_irqtab[cs->irq & 0xF]; /* RAM not evaluated */
  1398. init_timer(&cs->hw.hfcsx.timer);
  1399. reset_hfcsx(cs);
  1400. cs->cardmsg = &hfcsx_card_msg;
  1401. cs->auxcmd = &hfcsx_auxcmd;
  1402. return (1);
  1403. }