hfc_sx.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  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 (!cs)
  1159. return;
  1160. if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
  1161. if (!cs->hw.hfcsx.nt_mode)
  1162. switch (cs->dc.hfcsx.ph_state) {
  1163. case (0):
  1164. l1_msg(cs, HW_RESET | INDICATION, NULL);
  1165. break;
  1166. case (3):
  1167. l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
  1168. break;
  1169. case (8):
  1170. l1_msg(cs, HW_RSYNC | INDICATION, NULL);
  1171. break;
  1172. case (6):
  1173. l1_msg(cs, HW_INFO2 | INDICATION, NULL);
  1174. break;
  1175. case (7):
  1176. l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
  1177. break;
  1178. default:
  1179. break;
  1180. } else {
  1181. switch (cs->dc.hfcsx.ph_state) {
  1182. case (2):
  1183. spin_lock_irqsave(&cs->lock, flags);
  1184. if (cs->hw.hfcsx.nt_timer < 0) {
  1185. cs->hw.hfcsx.nt_timer = 0;
  1186. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1187. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1188. /* Clear already pending ints */
  1189. if (Read_hfc(cs, HFCSX_INT_S1));
  1190. Write_hfc(cs, HFCSX_STATES, 4 | HFCSX_LOAD_STATE);
  1191. udelay(10);
  1192. Write_hfc(cs, HFCSX_STATES, 4);
  1193. cs->dc.hfcsx.ph_state = 4;
  1194. } else {
  1195. cs->hw.hfcsx.int_m1 |= HFCSX_INTS_TIMER;
  1196. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1197. cs->hw.hfcsx.ctmt &= ~HFCSX_AUTO_TIMER;
  1198. cs->hw.hfcsx.ctmt |= HFCSX_TIM3_125;
  1199. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  1200. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  1201. cs->hw.hfcsx.nt_timer = NT_T1_COUNT;
  1202. Write_hfc(cs, HFCSX_STATES, 2 | HFCSX_NT_G2_G3); /* allow G2 -> G3 transition */
  1203. }
  1204. spin_unlock_irqrestore(&cs->lock, flags);
  1205. break;
  1206. case (1):
  1207. case (3):
  1208. case (4):
  1209. spin_lock_irqsave(&cs->lock, flags);
  1210. cs->hw.hfcsx.nt_timer = 0;
  1211. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1212. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1213. spin_unlock_irqrestore(&cs->lock, flags);
  1214. break;
  1215. default:
  1216. break;
  1217. }
  1218. }
  1219. }
  1220. if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
  1221. DChannel_proc_rcv(cs);
  1222. if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
  1223. DChannel_proc_xmt(cs);
  1224. }
  1225. /********************************/
  1226. /* called for card init message */
  1227. /********************************/
  1228. static void 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. __func__, 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, hfcsx_bh);
  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. }