hfc_sx.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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 work_struct *work)
  1155. {
  1156. struct IsdnCardState *cs =
  1157. container_of(work, struct IsdnCardState, tqueue);
  1158. u_long flags;
  1159. if (!cs)
  1160. return;
  1161. if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
  1162. if (!cs->hw.hfcsx.nt_mode)
  1163. switch (cs->dc.hfcsx.ph_state) {
  1164. case (0):
  1165. l1_msg(cs, HW_RESET | INDICATION, NULL);
  1166. break;
  1167. case (3):
  1168. l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
  1169. break;
  1170. case (8):
  1171. l1_msg(cs, HW_RSYNC | INDICATION, NULL);
  1172. break;
  1173. case (6):
  1174. l1_msg(cs, HW_INFO2 | INDICATION, NULL);
  1175. break;
  1176. case (7):
  1177. l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
  1178. break;
  1179. default:
  1180. break;
  1181. } else {
  1182. switch (cs->dc.hfcsx.ph_state) {
  1183. case (2):
  1184. spin_lock_irqsave(&cs->lock, flags);
  1185. if (cs->hw.hfcsx.nt_timer < 0) {
  1186. cs->hw.hfcsx.nt_timer = 0;
  1187. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1188. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1189. /* Clear already pending ints */
  1190. if (Read_hfc(cs, HFCSX_INT_S1));
  1191. Write_hfc(cs, HFCSX_STATES, 4 | HFCSX_LOAD_STATE);
  1192. udelay(10);
  1193. Write_hfc(cs, HFCSX_STATES, 4);
  1194. cs->dc.hfcsx.ph_state = 4;
  1195. } else {
  1196. cs->hw.hfcsx.int_m1 |= HFCSX_INTS_TIMER;
  1197. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1198. cs->hw.hfcsx.ctmt &= ~HFCSX_AUTO_TIMER;
  1199. cs->hw.hfcsx.ctmt |= HFCSX_TIM3_125;
  1200. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  1201. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  1202. cs->hw.hfcsx.nt_timer = NT_T1_COUNT;
  1203. Write_hfc(cs, HFCSX_STATES, 2 | HFCSX_NT_G2_G3); /* allow G2 -> G3 transition */
  1204. }
  1205. spin_unlock_irqrestore(&cs->lock, flags);
  1206. break;
  1207. case (1):
  1208. case (3):
  1209. case (4):
  1210. spin_lock_irqsave(&cs->lock, flags);
  1211. cs->hw.hfcsx.nt_timer = 0;
  1212. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1213. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1214. spin_unlock_irqrestore(&cs->lock, flags);
  1215. break;
  1216. default:
  1217. break;
  1218. }
  1219. }
  1220. }
  1221. if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
  1222. DChannel_proc_rcv(cs);
  1223. if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
  1224. DChannel_proc_xmt(cs);
  1225. }
  1226. /********************************/
  1227. /* called for card init message */
  1228. /********************************/
  1229. static void __devinit
  1230. inithfcsx(struct IsdnCardState *cs)
  1231. {
  1232. cs->setstack_d = setstack_hfcsx;
  1233. cs->BC_Send_Data = &hfcsx_send_data;
  1234. cs->bcs[0].BC_SetStack = setstack_2b;
  1235. cs->bcs[1].BC_SetStack = setstack_2b;
  1236. cs->bcs[0].BC_Close = close_hfcsx;
  1237. cs->bcs[1].BC_Close = close_hfcsx;
  1238. mode_hfcsx(cs->bcs, 0, 0);
  1239. mode_hfcsx(cs->bcs + 1, 0, 1);
  1240. }
  1241. /*******************************************/
  1242. /* handle card messages from control layer */
  1243. /*******************************************/
  1244. static int
  1245. hfcsx_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  1246. {
  1247. u_long flags;
  1248. if (cs->debug & L1_DEB_ISAC)
  1249. debugl1(cs, "HFCSX: card_msg %x", mt);
  1250. switch (mt) {
  1251. case CARD_RESET:
  1252. spin_lock_irqsave(&cs->lock, flags);
  1253. reset_hfcsx(cs);
  1254. spin_unlock_irqrestore(&cs->lock, flags);
  1255. return (0);
  1256. case CARD_RELEASE:
  1257. release_io_hfcsx(cs);
  1258. return (0);
  1259. case CARD_INIT:
  1260. spin_lock_irqsave(&cs->lock, flags);
  1261. inithfcsx(cs);
  1262. spin_unlock_irqrestore(&cs->lock, flags);
  1263. msleep(80); /* Timeout 80ms */
  1264. /* now switch timer interrupt off */
  1265. spin_lock_irqsave(&cs->lock, flags);
  1266. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1267. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1268. /* reinit mode reg */
  1269. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  1270. spin_unlock_irqrestore(&cs->lock, flags);
  1271. return (0);
  1272. case CARD_TEST:
  1273. return (0);
  1274. }
  1275. return (0);
  1276. }
  1277. #ifdef __ISAPNP__
  1278. static struct isapnp_device_id hfc_ids[] __devinitdata = {
  1279. { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2620),
  1280. ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2620),
  1281. (unsigned long) "Teles 16.3c2" },
  1282. { 0, }
  1283. };
  1284. static struct isapnp_device_id *ipid __devinitdata = &hfc_ids[0];
  1285. static struct pnp_card *pnp_c __devinitdata = NULL;
  1286. #endif
  1287. int __devinit
  1288. setup_hfcsx(struct IsdnCard *card)
  1289. {
  1290. struct IsdnCardState *cs = card->cs;
  1291. char tmp[64];
  1292. strcpy(tmp, hfcsx_revision);
  1293. printk(KERN_INFO "HiSax: HFC-SX driver Rev. %s\n", HiSax_getrev(tmp));
  1294. #ifdef __ISAPNP__
  1295. if (!card->para[1] && isapnp_present()) {
  1296. struct pnp_dev *pnp_d;
  1297. while(ipid->card_vendor) {
  1298. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  1299. ipid->card_device, pnp_c))) {
  1300. pnp_d = NULL;
  1301. if ((pnp_d = pnp_find_dev(pnp_c,
  1302. ipid->vendor, ipid->function, pnp_d))) {
  1303. int err;
  1304. printk(KERN_INFO "HiSax: %s detected\n",
  1305. (char *)ipid->driver_data);
  1306. pnp_disable_dev(pnp_d);
  1307. err = pnp_activate_dev(pnp_d);
  1308. if (err<0) {
  1309. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  1310. __FUNCTION__, err);
  1311. return(0);
  1312. }
  1313. card->para[1] = pnp_port_start(pnp_d, 0);
  1314. card->para[0] = pnp_irq(pnp_d, 0);
  1315. if (!card->para[0] || !card->para[1]) {
  1316. printk(KERN_ERR "HFC PnP:some resources are missing %ld/%lx\n",
  1317. card->para[0], card->para[1]);
  1318. pnp_disable_dev(pnp_d);
  1319. return(0);
  1320. }
  1321. break;
  1322. } else {
  1323. printk(KERN_ERR "HFC PnP: PnP error card found, no device\n");
  1324. }
  1325. }
  1326. ipid++;
  1327. pnp_c = NULL;
  1328. }
  1329. if (!ipid->card_vendor) {
  1330. printk(KERN_INFO "HFC PnP: no ISAPnP card found\n");
  1331. return(0);
  1332. }
  1333. }
  1334. #endif
  1335. cs->hw.hfcsx.base = card->para[1] & 0xfffe;
  1336. cs->irq = card->para[0];
  1337. cs->hw.hfcsx.int_s1 = 0;
  1338. cs->dc.hfcsx.ph_state = 0;
  1339. cs->hw.hfcsx.fifo = 255;
  1340. if ((cs->typ == ISDN_CTYPE_HFC_SX) ||
  1341. (cs->typ == ISDN_CTYPE_HFC_SP_PCMCIA)) {
  1342. if ((!cs->hw.hfcsx.base) || !request_region(cs->hw.hfcsx.base, 2, "HFCSX isdn")) {
  1343. printk(KERN_WARNING
  1344. "HiSax: HFC-SX io-base %#lx already in use\n",
  1345. cs->hw.hfcsx.base);
  1346. return(0);
  1347. }
  1348. byteout(cs->hw.hfcsx.base, cs->hw.hfcsx.base & 0xFF);
  1349. byteout(cs->hw.hfcsx.base + 1,
  1350. ((cs->hw.hfcsx.base >> 8) & 3) | 0x54);
  1351. udelay(10);
  1352. cs->hw.hfcsx.chip = Read_hfc(cs,HFCSX_CHIP_ID);
  1353. switch (cs->hw.hfcsx.chip >> 4) {
  1354. case 1:
  1355. tmp[0] ='+';
  1356. break;
  1357. case 9:
  1358. tmp[0] ='P';
  1359. break;
  1360. default:
  1361. printk(KERN_WARNING
  1362. "HFC-SX: invalid chip id 0x%x\n",
  1363. cs->hw.hfcsx.chip >> 4);
  1364. release_region(cs->hw.hfcsx.base, 2);
  1365. return(0);
  1366. }
  1367. if (!ccd_sp_irqtab[cs->irq & 0xF]) {
  1368. printk(KERN_WARNING
  1369. "HFC_SX: invalid irq %d specified\n",cs->irq & 0xF);
  1370. release_region(cs->hw.hfcsx.base, 2);
  1371. return(0);
  1372. }
  1373. if (!(cs->hw.hfcsx.extra = (void *)
  1374. kmalloc(sizeof(struct hfcsx_extra), GFP_ATOMIC))) {
  1375. release_region(cs->hw.hfcsx.base, 2);
  1376. printk(KERN_WARNING "HFC-SX: unable to allocate memory\n");
  1377. return(0);
  1378. }
  1379. printk(KERN_INFO "HFC-S%c chip detected at base 0x%x IRQ %d HZ %d\n",
  1380. tmp[0], (u_int) cs->hw.hfcsx.base, cs->irq, HZ);
  1381. cs->hw.hfcsx.int_m2 = 0; /* disable alle interrupts */
  1382. cs->hw.hfcsx.int_m1 = 0;
  1383. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1384. Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
  1385. } else
  1386. return (0); /* no valid card type */
  1387. cs->dbusytimer.function = (void *) hfcsx_dbusy_timer;
  1388. cs->dbusytimer.data = (long) cs;
  1389. init_timer(&cs->dbusytimer);
  1390. INIT_WORK(&cs->tqueue, hfcsx_bh);
  1391. cs->readisac = NULL;
  1392. cs->writeisac = NULL;
  1393. cs->readisacfifo = NULL;
  1394. cs->writeisacfifo = NULL;
  1395. cs->BC_Read_Reg = NULL;
  1396. cs->BC_Write_Reg = NULL;
  1397. cs->irq_func = &hfcsx_interrupt;
  1398. cs->hw.hfcsx.timer.function = (void *) hfcsx_Timer;
  1399. cs->hw.hfcsx.timer.data = (long) cs;
  1400. cs->hw.hfcsx.b_fifo_size = 0; /* fifo size still unknown */
  1401. cs->hw.hfcsx.cirm = ccd_sp_irqtab[cs->irq & 0xF]; /* RAM not evaluated */
  1402. init_timer(&cs->hw.hfcsx.timer);
  1403. reset_hfcsx(cs);
  1404. cs->cardmsg = &hfcsx_card_msg;
  1405. cs->auxcmd = &hfcsx_auxcmd;
  1406. return (1);
  1407. }