hfc_sx.c 44 KB

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