hfc_sx.c 43 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. #include <linux/slab.h>
  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(%u/%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. skb = dev_alloc_skb(count);
  209. if (skb) {
  210. dst = skb_put(skb, count);
  211. while (count--)
  212. *dst++ = Read_hfc(cs, HFCSX_FIF_DRD);
  213. return skb;
  214. } else
  215. return NULL; /* no memory */
  216. }
  217. do {
  218. f1 = Read_hfc(cs, HFCSX_FIF_F1) & f_msk;
  219. f2 = Read_hfc(cs, HFCSX_FIF_F2) & f_msk;
  220. if (f1 == f2) return (NULL); /* no frame available */
  221. z1 = Read_hfc(cs, HFCSX_FIF_Z1H);
  222. z1 = ((z1 << 8) | Read_hfc(cs, HFCSX_FIF_Z1L));
  223. z2 = Read_hfc(cs, HFCSX_FIF_Z2H);
  224. z2 = ((z2 << 8) | Read_hfc(cs, HFCSX_FIF_Z2L));
  225. if (cs->debug & L1_DEB_ISAC_FIFO)
  226. debugl1(cs, "hfcsx_read_fifo %d f1(%x) f2(%x) z1(f2)(%x) z2(f2)(%x)",
  227. fifo, f1, f2, z1, z2);
  228. /* now determine bytes in actual FIFO buffer */
  229. count = z1 - z2;
  230. if (count <= 0)
  231. count += fifo_size; /* count now contains buffered bytes */
  232. count++;
  233. if (cs->debug & L1_DEB_ISAC_FIFO)
  234. debugl1(cs, "hfcsx_read_fifo %d count %u)",
  235. fifo, count);
  236. if ((count > fifo_size) || (count < 4)) {
  237. if (cs->debug & L1_DEB_WARN)
  238. debugl1(cs, "hfcsx_read_fifo %d packet inv. len %d ", fifo , count);
  239. while (count) {
  240. count--; /* empty fifo */
  241. Read_hfc(cs, HFCSX_FIF_DRD);
  242. }
  243. skb = NULL;
  244. } else
  245. if ((skb = dev_alloc_skb(count - 3))) {
  246. count -= 3;
  247. dst = skb_put(skb, count);
  248. while (count--)
  249. *dst++ = Read_hfc(cs, HFCSX_FIF_DRD);
  250. Read_hfc(cs, HFCSX_FIF_DRD); /* CRC 1 */
  251. Read_hfc(cs, HFCSX_FIF_DRD); /* CRC 2 */
  252. if (Read_hfc(cs, HFCSX_FIF_DRD)) {
  253. dev_kfree_skb_irq(skb);
  254. if (cs->debug & L1_DEB_ISAC_FIFO)
  255. debugl1(cs, "hfcsx_read_fifo %d crc error", fifo);
  256. skb = NULL;
  257. }
  258. } else {
  259. printk(KERN_WARNING "HFC-SX: receive out of memory\n");
  260. return (NULL);
  261. }
  262. Read_hfc(cs, HFCSX_FIF_INCF2); /* increment F2 */
  263. udelay(1);
  264. while (bytein(cs->hw.hfcsx.base + 1) & 1); /* wait for busy */
  265. udelay(1);
  266. } while (!skb); /* retry in case of crc error */
  267. return (skb);
  268. }
  269. /******************************************/
  270. /* free hardware resources used by driver */
  271. /******************************************/
  272. static void
  273. release_io_hfcsx(struct IsdnCardState *cs)
  274. {
  275. cs->hw.hfcsx.int_m2 = 0; /* interrupt output off ! */
  276. Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
  277. Write_hfc(cs, HFCSX_CIRM, HFCSX_RESET); /* Reset On */
  278. msleep(30); /* Timeout 30ms */
  279. Write_hfc(cs, HFCSX_CIRM, 0); /* Reset Off */
  280. del_timer(&cs->hw.hfcsx.timer);
  281. release_region(cs->hw.hfcsx.base, 2); /* release IO-Block */
  282. kfree(cs->hw.hfcsx.extra);
  283. cs->hw.hfcsx.extra = NULL;
  284. }
  285. /**********************************************************/
  286. /* set_fifo_size determines the size of the RAM and FIFOs */
  287. /* returning 0 -> need to reset the chip again. */
  288. /**********************************************************/
  289. static int set_fifo_size(struct IsdnCardState *cs)
  290. {
  291. if (cs->hw.hfcsx.b_fifo_size) return (1); /* already determined */
  292. if ((cs->hw.hfcsx.chip >> 4) == 9) {
  293. cs->hw.hfcsx.b_fifo_size = B_FIFO_SIZE_32K;
  294. return (1);
  295. }
  296. cs->hw.hfcsx.b_fifo_size = B_FIFO_SIZE_8K;
  297. cs->hw.hfcsx.cirm |= 0x10; /* only 8K of ram */
  298. return (0);
  299. }
  300. /********************************************************************************/
  301. /* function called to reset the HFC SX chip. A complete software reset of chip */
  302. /* and fifos is done. */
  303. /********************************************************************************/
  304. static void
  305. reset_hfcsx(struct IsdnCardState *cs)
  306. {
  307. cs->hw.hfcsx.int_m2 = 0; /* interrupt output off ! */
  308. Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
  309. printk(KERN_INFO "HFC_SX: resetting card\n");
  310. while (1) {
  311. Write_hfc(cs, HFCSX_CIRM, HFCSX_RESET | cs->hw.hfcsx.cirm); /* Reset */
  312. mdelay(30);
  313. Write_hfc(cs, HFCSX_CIRM, cs->hw.hfcsx.cirm); /* Reset Off */
  314. mdelay(20);
  315. if (Read_hfc(cs, HFCSX_STATUS) & 2)
  316. printk(KERN_WARNING "HFC-SX init bit busy\n");
  317. cs->hw.hfcsx.last_fifo = 0xff; /* invalidate */
  318. if (!set_fifo_size(cs)) continue;
  319. break;
  320. }
  321. cs->hw.hfcsx.trm = 0 + HFCSX_BTRANS_THRESMASK; /* no echo connect , threshold */
  322. Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
  323. Write_hfc(cs, HFCSX_CLKDEL, 0x0e); /* ST-Bit delay for TE-Mode */
  324. cs->hw.hfcsx.sctrl_e = HFCSX_AUTO_AWAKE;
  325. Write_hfc(cs, HFCSX_SCTRL_E, cs->hw.hfcsx.sctrl_e); /* S/T Auto awake */
  326. cs->hw.hfcsx.bswapped = 0; /* no exchange */
  327. cs->hw.hfcsx.nt_mode = 0; /* we are in TE mode */
  328. cs->hw.hfcsx.ctmt = HFCSX_TIM3_125 | HFCSX_AUTO_TIMER;
  329. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
  330. cs->hw.hfcsx.int_m1 = HFCSX_INTS_DTRANS | HFCSX_INTS_DREC |
  331. HFCSX_INTS_L1STATE | HFCSX_INTS_TIMER;
  332. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  333. /* Clear already pending ints */
  334. if (Read_hfc(cs, HFCSX_INT_S1));
  335. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 2); /* HFC ST 2 */
  336. udelay(10);
  337. Write_hfc(cs, HFCSX_STATES, 2); /* HFC ST 2 */
  338. cs->hw.hfcsx.mst_m = HFCSX_MASTER; /* HFC Master Mode */
  339. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  340. cs->hw.hfcsx.sctrl = 0x40; /* set tx_lo mode, error in datasheet ! */
  341. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
  342. cs->hw.hfcsx.sctrl_r = 0;
  343. Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
  344. /* Init GCI/IOM2 in master mode */
  345. /* Slots 0 and 1 are set for B-chan 1 and 2 */
  346. /* D- and monitor/CI channel are not enabled */
  347. /* STIO1 is used as output for data, B1+B2 from ST->IOM+HFC */
  348. /* STIO2 is used as data input, B1+B2 from IOM->ST */
  349. /* ST B-channel send disabled -> continuous 1s */
  350. /* The IOM slots are always enabled */
  351. cs->hw.hfcsx.conn = 0x36; /* set data flow directions */
  352. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  353. Write_hfc(cs, HFCSX_B1_SSL, 0x80); /* B1-Slot 0 STIO1 out enabled */
  354. Write_hfc(cs, HFCSX_B2_SSL, 0x81); /* B2-Slot 1 STIO1 out enabled */
  355. Write_hfc(cs, HFCSX_B1_RSL, 0x80); /* B1-Slot 0 STIO2 in enabled */
  356. Write_hfc(cs, HFCSX_B2_RSL, 0x81); /* B2-Slot 1 STIO2 in enabled */
  357. /* Finally enable IRQ output */
  358. cs->hw.hfcsx.int_m2 = HFCSX_IRQ_ENABLE;
  359. Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
  360. if (Read_hfc(cs, HFCSX_INT_S2));
  361. }
  362. /***************************************************/
  363. /* Timer function called when kernel timer expires */
  364. /***************************************************/
  365. static void
  366. hfcsx_Timer(struct IsdnCardState *cs)
  367. {
  368. cs->hw.hfcsx.timer.expires = jiffies + 75;
  369. /* WD RESET */
  370. /* WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcsx.ctmt | 0x80);
  371. add_timer(&cs->hw.hfcsx.timer);
  372. */
  373. }
  374. /************************************************/
  375. /* select a b-channel entry matching and active */
  376. /************************************************/
  377. static
  378. struct BCState *
  379. Sel_BCS(struct IsdnCardState *cs, int channel)
  380. {
  381. if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
  382. return (&cs->bcs[0]);
  383. else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
  384. return (&cs->bcs[1]);
  385. else
  386. return (NULL);
  387. }
  388. /*******************************/
  389. /* D-channel receive procedure */
  390. /*******************************/
  391. static
  392. int
  393. receive_dmsg(struct IsdnCardState *cs)
  394. {
  395. struct sk_buff *skb;
  396. int count = 5;
  397. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  398. debugl1(cs, "rec_dmsg blocked");
  399. return (1);
  400. }
  401. do {
  402. skb = read_fifo(cs, HFCSX_SEL_D_RX, 0);
  403. if (skb) {
  404. skb_queue_tail(&cs->rq, skb);
  405. schedule_event(cs, D_RCVBUFREADY);
  406. }
  407. } while (--count && skb);
  408. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  409. return (1);
  410. }
  411. /**********************************/
  412. /* B-channel main receive routine */
  413. /**********************************/
  414. static void
  415. main_rec_hfcsx(struct BCState *bcs)
  416. {
  417. struct IsdnCardState *cs = bcs->cs;
  418. int count = 5;
  419. struct sk_buff *skb;
  420. Begin:
  421. count--;
  422. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  423. debugl1(cs, "rec_data %d blocked", bcs->channel);
  424. return;
  425. }
  426. skb = read_fifo(cs, ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
  427. HFCSX_SEL_B2_RX : HFCSX_SEL_B1_RX,
  428. (bcs->mode == L1_MODE_TRANS) ?
  429. HFCSX_BTRANS_THRESHOLD : 0);
  430. if (skb) {
  431. skb_queue_tail(&bcs->rqueue, skb);
  432. schedule_event(bcs, B_RCVBUFREADY);
  433. }
  434. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  435. if (count && skb)
  436. goto Begin;
  437. return;
  438. }
  439. /**************************/
  440. /* D-channel send routine */
  441. /**************************/
  442. static void
  443. hfcsx_fill_dfifo(struct IsdnCardState *cs)
  444. {
  445. if (!cs->tx_skb)
  446. return;
  447. if (cs->tx_skb->len <= 0)
  448. return;
  449. if (write_fifo(cs, cs->tx_skb, HFCSX_SEL_D_TX, 0)) {
  450. dev_kfree_skb_any(cs->tx_skb);
  451. cs->tx_skb = NULL;
  452. }
  453. return;
  454. }
  455. /**************************/
  456. /* B-channel send routine */
  457. /**************************/
  458. static void
  459. hfcsx_fill_fifo(struct BCState *bcs)
  460. {
  461. struct IsdnCardState *cs = bcs->cs;
  462. if (!bcs->tx_skb)
  463. return;
  464. if (bcs->tx_skb->len <= 0)
  465. return;
  466. if (write_fifo(cs, bcs->tx_skb,
  467. ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
  468. HFCSX_SEL_B2_TX : HFCSX_SEL_B1_TX,
  469. (bcs->mode == L1_MODE_TRANS) ?
  470. HFCSX_BTRANS_THRESHOLD : 0)) {
  471. bcs->tx_cnt -= bcs->tx_skb->len;
  472. if (test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
  473. (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
  474. u_long flags;
  475. spin_lock_irqsave(&bcs->aclock, flags);
  476. bcs->ackcnt += bcs->tx_skb->len;
  477. spin_unlock_irqrestore(&bcs->aclock, flags);
  478. schedule_event(bcs, B_ACKPENDING);
  479. }
  480. dev_kfree_skb_any(bcs->tx_skb);
  481. bcs->tx_skb = NULL;
  482. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  483. }
  484. }
  485. /**********************************************/
  486. /* D-channel l1 state call for leased NT-mode */
  487. /**********************************************/
  488. static void
  489. dch_nt_l2l1(struct PStack *st, int pr, void *arg)
  490. {
  491. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  492. switch (pr) {
  493. case (PH_DATA | REQUEST):
  494. case (PH_PULL | REQUEST):
  495. case (PH_PULL | INDICATION):
  496. st->l1.l1hw(st, pr, arg);
  497. break;
  498. case (PH_ACTIVATE | REQUEST):
  499. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  500. break;
  501. case (PH_TESTLOOP | REQUEST):
  502. if (1 & (long) arg)
  503. debugl1(cs, "PH_TEST_LOOP B1");
  504. if (2 & (long) arg)
  505. debugl1(cs, "PH_TEST_LOOP B2");
  506. if (!(3 & (long) arg))
  507. debugl1(cs, "PH_TEST_LOOP DISABLED");
  508. st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
  509. break;
  510. default:
  511. if (cs->debug)
  512. debugl1(cs, "dch_nt_l2l1 msg %04X unhandled", pr);
  513. break;
  514. }
  515. }
  516. /***********************/
  517. /* set/reset echo mode */
  518. /***********************/
  519. static int
  520. hfcsx_auxcmd(struct IsdnCardState *cs, isdn_ctrl *ic)
  521. {
  522. unsigned long flags;
  523. int i = *(unsigned int *) ic->parm.num;
  524. if ((ic->arg == 98) &&
  525. (!(cs->hw.hfcsx.int_m1 & (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC + HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC)))) {
  526. spin_lock_irqsave(&cs->lock, flags);
  527. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 0); /* HFC ST G0 */
  528. udelay(10);
  529. cs->hw.hfcsx.sctrl |= SCTRL_MODE_NT;
  530. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl); /* set NT-mode */
  531. udelay(10);
  532. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 1); /* HFC ST G1 */
  533. udelay(10);
  534. Write_hfc(cs, HFCSX_STATES, 1 | HFCSX_ACTIVATE | HFCSX_DO_ACTION);
  535. cs->dc.hfcsx.ph_state = 1;
  536. cs->hw.hfcsx.nt_mode = 1;
  537. cs->hw.hfcsx.nt_timer = 0;
  538. spin_unlock_irqrestore(&cs->lock, flags);
  539. cs->stlist->l2.l2l1 = dch_nt_l2l1;
  540. debugl1(cs, "NT mode activated");
  541. return (0);
  542. }
  543. if ((cs->chanlimit > 1) || (cs->hw.hfcsx.bswapped) ||
  544. (cs->hw.hfcsx.nt_mode) || (ic->arg != 12))
  545. return (-EINVAL);
  546. if (i) {
  547. cs->logecho = 1;
  548. cs->hw.hfcsx.trm |= 0x20; /* enable echo chan */
  549. cs->hw.hfcsx.int_m1 |= HFCSX_INTS_B2REC;
  550. /* reset Channel !!!!! */
  551. } else {
  552. cs->logecho = 0;
  553. cs->hw.hfcsx.trm &= ~0x20; /* disable echo chan */
  554. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_B2REC;
  555. }
  556. cs->hw.hfcsx.sctrl_r &= ~SCTRL_B2_ENA;
  557. cs->hw.hfcsx.sctrl &= ~SCTRL_B2_ENA;
  558. cs->hw.hfcsx.conn |= 0x10; /* B2-IOM -> B2-ST */
  559. cs->hw.hfcsx.ctmt &= ~2;
  560. spin_lock_irqsave(&cs->lock, flags);
  561. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
  562. Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
  563. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
  564. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  565. Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
  566. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  567. spin_unlock_irqrestore(&cs->lock, flags);
  568. return (0);
  569. } /* hfcsx_auxcmd */
  570. /*****************************/
  571. /* E-channel receive routine */
  572. /*****************************/
  573. static void
  574. receive_emsg(struct IsdnCardState *cs)
  575. {
  576. int count = 5;
  577. u_char *ptr;
  578. struct sk_buff *skb;
  579. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  580. debugl1(cs, "echo_rec_data blocked");
  581. return;
  582. }
  583. do {
  584. skb = read_fifo(cs, HFCSX_SEL_B2_RX, 0);
  585. if (skb) {
  586. if (cs->debug & DEB_DLOG_HEX) {
  587. ptr = cs->dlog;
  588. if ((skb->len) < MAX_DLOG_SPACE / 3 - 10) {
  589. *ptr++ = 'E';
  590. *ptr++ = 'C';
  591. *ptr++ = 'H';
  592. *ptr++ = 'O';
  593. *ptr++ = ':';
  594. ptr += QuickHex(ptr, skb->data, skb->len);
  595. ptr--;
  596. *ptr++ = '\n';
  597. *ptr = 0;
  598. HiSax_putstatus(cs, NULL, cs->dlog);
  599. } else
  600. HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
  601. }
  602. dev_kfree_skb_any(skb);
  603. }
  604. } while (--count && skb);
  605. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  606. return;
  607. } /* receive_emsg */
  608. /*********************/
  609. /* Interrupt handler */
  610. /*********************/
  611. static irqreturn_t
  612. hfcsx_interrupt(int intno, void *dev_id)
  613. {
  614. struct IsdnCardState *cs = dev_id;
  615. u_char exval;
  616. struct BCState *bcs;
  617. int count = 15;
  618. u_long flags;
  619. u_char val, stat;
  620. if (!(cs->hw.hfcsx.int_m2 & 0x08))
  621. return IRQ_NONE; /* not initialised */
  622. spin_lock_irqsave(&cs->lock, flags);
  623. if (HFCSX_ANYINT & (stat = Read_hfc(cs, HFCSX_STATUS))) {
  624. val = Read_hfc(cs, HFCSX_INT_S1);
  625. if (cs->debug & L1_DEB_ISAC)
  626. debugl1(cs, "HFC-SX: stat(%02x) s1(%02x)", stat, val);
  627. } else {
  628. spin_unlock_irqrestore(&cs->lock, flags);
  629. return IRQ_NONE;
  630. }
  631. if (cs->debug & L1_DEB_ISAC)
  632. debugl1(cs, "HFC-SX irq %x %s", val,
  633. test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
  634. "locked" : "unlocked");
  635. val &= cs->hw.hfcsx.int_m1;
  636. if (val & 0x40) { /* state machine irq */
  637. exval = Read_hfc(cs, HFCSX_STATES) & 0xf;
  638. if (cs->debug & L1_DEB_ISAC)
  639. debugl1(cs, "ph_state chg %d->%d", cs->dc.hfcsx.ph_state,
  640. exval);
  641. cs->dc.hfcsx.ph_state = exval;
  642. schedule_event(cs, D_L1STATECHANGE);
  643. val &= ~0x40;
  644. }
  645. if (val & 0x80) { /* timer irq */
  646. if (cs->hw.hfcsx.nt_mode) {
  647. if ((--cs->hw.hfcsx.nt_timer) < 0)
  648. schedule_event(cs, D_L1STATECHANGE);
  649. }
  650. val &= ~0x80;
  651. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  652. }
  653. while (val) {
  654. if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  655. cs->hw.hfcsx.int_s1 |= val;
  656. spin_unlock_irqrestore(&cs->lock, flags);
  657. return IRQ_HANDLED;
  658. }
  659. if (cs->hw.hfcsx.int_s1 & 0x18) {
  660. exval = val;
  661. val = cs->hw.hfcsx.int_s1;
  662. cs->hw.hfcsx.int_s1 = exval;
  663. }
  664. if (val & 0x08) {
  665. if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
  666. if (cs->debug)
  667. debugl1(cs, "hfcsx spurious 0x08 IRQ");
  668. } else
  669. main_rec_hfcsx(bcs);
  670. }
  671. if (val & 0x10) {
  672. if (cs->logecho)
  673. receive_emsg(cs);
  674. else if (!(bcs = Sel_BCS(cs, 1))) {
  675. if (cs->debug)
  676. debugl1(cs, "hfcsx spurious 0x10 IRQ");
  677. } else
  678. main_rec_hfcsx(bcs);
  679. }
  680. if (val & 0x01) {
  681. if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
  682. if (cs->debug)
  683. debugl1(cs, "hfcsx spurious 0x01 IRQ");
  684. } else {
  685. if (bcs->tx_skb) {
  686. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  687. hfcsx_fill_fifo(bcs);
  688. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  689. } else
  690. debugl1(cs, "fill_data %d blocked", bcs->channel);
  691. } else {
  692. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  693. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  694. hfcsx_fill_fifo(bcs);
  695. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  696. } else
  697. debugl1(cs, "fill_data %d blocked", bcs->channel);
  698. } else {
  699. schedule_event(bcs, B_XMTBUFREADY);
  700. }
  701. }
  702. }
  703. }
  704. if (val & 0x02) {
  705. if (!(bcs = Sel_BCS(cs, 1))) {
  706. if (cs->debug)
  707. debugl1(cs, "hfcsx spurious 0x02 IRQ");
  708. } else {
  709. if (bcs->tx_skb) {
  710. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  711. hfcsx_fill_fifo(bcs);
  712. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  713. } else
  714. debugl1(cs, "fill_data %d blocked", bcs->channel);
  715. } else {
  716. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  717. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  718. hfcsx_fill_fifo(bcs);
  719. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  720. } else
  721. debugl1(cs, "fill_data %d blocked", bcs->channel);
  722. } else {
  723. schedule_event(bcs, B_XMTBUFREADY);
  724. }
  725. }
  726. }
  727. }
  728. if (val & 0x20) { /* receive dframe */
  729. receive_dmsg(cs);
  730. }
  731. if (val & 0x04) { /* dframe transmitted */
  732. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  733. del_timer(&cs->dbusytimer);
  734. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  735. schedule_event(cs, D_CLEARBUSY);
  736. if (cs->tx_skb) {
  737. if (cs->tx_skb->len) {
  738. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  739. hfcsx_fill_dfifo(cs);
  740. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  741. } else {
  742. debugl1(cs, "hfcsx_fill_dfifo irq blocked");
  743. }
  744. goto afterXPR;
  745. } else {
  746. dev_kfree_skb_irq(cs->tx_skb);
  747. cs->tx_cnt = 0;
  748. cs->tx_skb = NULL;
  749. }
  750. }
  751. if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
  752. cs->tx_cnt = 0;
  753. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  754. hfcsx_fill_dfifo(cs);
  755. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  756. } else {
  757. debugl1(cs, "hfcsx_fill_dfifo irq blocked");
  758. }
  759. } else
  760. schedule_event(cs, D_XMTBUFREADY);
  761. }
  762. afterXPR:
  763. if (cs->hw.hfcsx.int_s1 && count--) {
  764. val = cs->hw.hfcsx.int_s1;
  765. cs->hw.hfcsx.int_s1 = 0;
  766. if (cs->debug & L1_DEB_ISAC)
  767. debugl1(cs, "HFC-SX irq %x loop %d", val, 15 - count);
  768. } else
  769. val = 0;
  770. }
  771. spin_unlock_irqrestore(&cs->lock, flags);
  772. return IRQ_HANDLED;
  773. }
  774. /********************************************************************/
  775. /* timer callback for D-chan busy resolution. Currently no function */
  776. /********************************************************************/
  777. static void
  778. hfcsx_dbusy_timer(struct IsdnCardState *cs)
  779. {
  780. }
  781. /*************************************/
  782. /* Layer 1 D-channel hardware access */
  783. /*************************************/
  784. static void
  785. HFCSX_l1hw(struct PStack *st, int pr, void *arg)
  786. {
  787. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  788. struct sk_buff *skb = arg;
  789. u_long flags;
  790. switch (pr) {
  791. case (PH_DATA | REQUEST):
  792. if (cs->debug & DEB_DLOG_HEX)
  793. LogFrame(cs, skb->data, skb->len);
  794. if (cs->debug & DEB_DLOG_VERBOSE)
  795. dlogframe(cs, skb, 0);
  796. spin_lock_irqsave(&cs->lock, flags);
  797. if (cs->tx_skb) {
  798. skb_queue_tail(&cs->sq, skb);
  799. #ifdef L2FRAME_DEBUG /* psa */
  800. if (cs->debug & L1_DEB_LAPD)
  801. Logl2Frame(cs, skb, "PH_DATA Queued", 0);
  802. #endif
  803. } else {
  804. cs->tx_skb = skb;
  805. cs->tx_cnt = 0;
  806. #ifdef L2FRAME_DEBUG /* psa */
  807. if (cs->debug & L1_DEB_LAPD)
  808. Logl2Frame(cs, skb, "PH_DATA", 0);
  809. #endif
  810. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  811. hfcsx_fill_dfifo(cs);
  812. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  813. } else
  814. debugl1(cs, "hfcsx_fill_dfifo blocked");
  815. }
  816. spin_unlock_irqrestore(&cs->lock, flags);
  817. break;
  818. case (PH_PULL | INDICATION):
  819. spin_lock_irqsave(&cs->lock, flags);
  820. if (cs->tx_skb) {
  821. if (cs->debug & L1_DEB_WARN)
  822. debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
  823. skb_queue_tail(&cs->sq, skb);
  824. spin_unlock_irqrestore(&cs->lock, flags);
  825. break;
  826. }
  827. if (cs->debug & DEB_DLOG_HEX)
  828. LogFrame(cs, skb->data, skb->len);
  829. if (cs->debug & DEB_DLOG_VERBOSE)
  830. dlogframe(cs, skb, 0);
  831. cs->tx_skb = skb;
  832. cs->tx_cnt = 0;
  833. #ifdef L2FRAME_DEBUG /* psa */
  834. if (cs->debug & L1_DEB_LAPD)
  835. Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
  836. #endif
  837. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  838. hfcsx_fill_dfifo(cs);
  839. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  840. } else
  841. debugl1(cs, "hfcsx_fill_dfifo blocked");
  842. spin_unlock_irqrestore(&cs->lock, flags);
  843. break;
  844. case (PH_PULL | REQUEST):
  845. #ifdef L2FRAME_DEBUG /* psa */
  846. if (cs->debug & L1_DEB_LAPD)
  847. debugl1(cs, "-> PH_REQUEST_PULL");
  848. #endif
  849. if (!cs->tx_skb) {
  850. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  851. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  852. } else
  853. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  854. break;
  855. case (HW_RESET | REQUEST):
  856. spin_lock_irqsave(&cs->lock, flags);
  857. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 3); /* HFC ST 3 */
  858. udelay(6);
  859. Write_hfc(cs, HFCSX_STATES, 3); /* HFC ST 2 */
  860. cs->hw.hfcsx.mst_m |= HFCSX_MASTER;
  861. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  862. Write_hfc(cs, HFCSX_STATES, HFCSX_ACTIVATE | HFCSX_DO_ACTION);
  863. spin_unlock_irqrestore(&cs->lock, flags);
  864. l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
  865. break;
  866. case (HW_ENABLE | REQUEST):
  867. spin_lock_irqsave(&cs->lock, flags);
  868. Write_hfc(cs, HFCSX_STATES, HFCSX_ACTIVATE | HFCSX_DO_ACTION);
  869. spin_unlock_irqrestore(&cs->lock, flags);
  870. break;
  871. case (HW_DEACTIVATE | REQUEST):
  872. spin_lock_irqsave(&cs->lock, flags);
  873. cs->hw.hfcsx.mst_m &= ~HFCSX_MASTER;
  874. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  875. spin_unlock_irqrestore(&cs->lock, flags);
  876. break;
  877. case (HW_INFO3 | REQUEST):
  878. spin_lock_irqsave(&cs->lock, flags);
  879. cs->hw.hfcsx.mst_m |= HFCSX_MASTER;
  880. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  881. spin_unlock_irqrestore(&cs->lock, flags);
  882. break;
  883. case (HW_TESTLOOP | REQUEST):
  884. spin_lock_irqsave(&cs->lock, flags);
  885. switch ((long) arg) {
  886. case (1):
  887. Write_hfc(cs, HFCSX_B1_SSL, 0x80); /* tx slot */
  888. Write_hfc(cs, HFCSX_B1_RSL, 0x80); /* rx slot */
  889. cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~7) | 1;
  890. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  891. break;
  892. case (2):
  893. Write_hfc(cs, HFCSX_B2_SSL, 0x81); /* tx slot */
  894. Write_hfc(cs, HFCSX_B2_RSL, 0x81); /* rx slot */
  895. cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~0x38) | 0x08;
  896. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  897. break;
  898. default:
  899. spin_unlock_irqrestore(&cs->lock, flags);
  900. if (cs->debug & L1_DEB_WARN)
  901. debugl1(cs, "hfcsx_l1hw loop invalid %4lx", (unsigned long)arg);
  902. return;
  903. }
  904. cs->hw.hfcsx.trm |= 0x80; /* enable IOM-loop */
  905. Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
  906. spin_unlock_irqrestore(&cs->lock, flags);
  907. break;
  908. default:
  909. if (cs->debug & L1_DEB_WARN)
  910. debugl1(cs, "hfcsx_l1hw unknown pr %4x", pr);
  911. break;
  912. }
  913. }
  914. /***********************************************/
  915. /* called during init setting l1 stack pointer */
  916. /***********************************************/
  917. static void
  918. setstack_hfcsx(struct PStack *st, struct IsdnCardState *cs)
  919. {
  920. st->l1.l1hw = HFCSX_l1hw;
  921. }
  922. /**************************************/
  923. /* send B-channel data if not blocked */
  924. /**************************************/
  925. static void
  926. hfcsx_send_data(struct BCState *bcs)
  927. {
  928. struct IsdnCardState *cs = bcs->cs;
  929. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  930. hfcsx_fill_fifo(bcs);
  931. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  932. } else
  933. debugl1(cs, "send_data %d blocked", bcs->channel);
  934. }
  935. /***************************************************************/
  936. /* activate/deactivate hardware for selected channels and mode */
  937. /***************************************************************/
  938. static void
  939. mode_hfcsx(struct BCState *bcs, int mode, int bc)
  940. {
  941. struct IsdnCardState *cs = bcs->cs;
  942. int fifo2;
  943. if (cs->debug & L1_DEB_HSCX)
  944. debugl1(cs, "HFCSX bchannel mode %d bchan %d/%d",
  945. mode, bc, bcs->channel);
  946. bcs->mode = mode;
  947. bcs->channel = bc;
  948. fifo2 = bc;
  949. if (cs->chanlimit > 1) {
  950. cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
  951. cs->hw.hfcsx.sctrl_e &= ~0x80;
  952. } else {
  953. if (bc) {
  954. if (mode != L1_MODE_NULL) {
  955. cs->hw.hfcsx.bswapped = 1; /* B1 and B2 exchanged */
  956. cs->hw.hfcsx.sctrl_e |= 0x80;
  957. } else {
  958. cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
  959. cs->hw.hfcsx.sctrl_e &= ~0x80;
  960. }
  961. fifo2 = 0;
  962. } else {
  963. cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
  964. cs->hw.hfcsx.sctrl_e &= ~0x80;
  965. }
  966. }
  967. switch (mode) {
  968. case (L1_MODE_NULL):
  969. if (bc) {
  970. cs->hw.hfcsx.sctrl &= ~SCTRL_B2_ENA;
  971. cs->hw.hfcsx.sctrl_r &= ~SCTRL_B2_ENA;
  972. } else {
  973. cs->hw.hfcsx.sctrl &= ~SCTRL_B1_ENA;
  974. cs->hw.hfcsx.sctrl_r &= ~SCTRL_B1_ENA;
  975. }
  976. if (fifo2) {
  977. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  978. } else {
  979. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  980. }
  981. break;
  982. case (L1_MODE_TRANS):
  983. if (bc) {
  984. cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
  985. cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
  986. } else {
  987. cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
  988. cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
  989. }
  990. if (fifo2) {
  991. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  992. cs->hw.hfcsx.ctmt |= 2;
  993. cs->hw.hfcsx.conn &= ~0x18;
  994. } else {
  995. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  996. cs->hw.hfcsx.ctmt |= 1;
  997. cs->hw.hfcsx.conn &= ~0x03;
  998. }
  999. break;
  1000. case (L1_MODE_HDLC):
  1001. if (bc) {
  1002. cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
  1003. cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
  1004. } else {
  1005. cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
  1006. cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
  1007. }
  1008. if (fifo2) {
  1009. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  1010. cs->hw.hfcsx.ctmt &= ~2;
  1011. cs->hw.hfcsx.conn &= ~0x18;
  1012. } else {
  1013. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  1014. cs->hw.hfcsx.ctmt &= ~1;
  1015. cs->hw.hfcsx.conn &= ~0x03;
  1016. }
  1017. break;
  1018. case (L1_MODE_EXTRN):
  1019. if (bc) {
  1020. cs->hw.hfcsx.conn |= 0x10;
  1021. cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
  1022. cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
  1023. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  1024. } else {
  1025. cs->hw.hfcsx.conn |= 0x02;
  1026. cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
  1027. cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
  1028. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  1029. }
  1030. break;
  1031. }
  1032. Write_hfc(cs, HFCSX_SCTRL_E, cs->hw.hfcsx.sctrl_e);
  1033. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1034. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
  1035. Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
  1036. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
  1037. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  1038. if (mode != L1_MODE_EXTRN) {
  1039. reset_fifo(cs, fifo2 ? HFCSX_SEL_B2_RX : HFCSX_SEL_B1_RX);
  1040. reset_fifo(cs, fifo2 ? HFCSX_SEL_B2_TX : HFCSX_SEL_B1_TX);
  1041. }
  1042. }
  1043. /******************************/
  1044. /* Layer2 -> Layer 1 Transfer */
  1045. /******************************/
  1046. static void
  1047. hfcsx_l2l1(struct PStack *st, int pr, void *arg)
  1048. {
  1049. struct BCState *bcs = st->l1.bcs;
  1050. struct sk_buff *skb = arg;
  1051. u_long flags;
  1052. switch (pr) {
  1053. case (PH_DATA | REQUEST):
  1054. spin_lock_irqsave(&bcs->cs->lock, flags);
  1055. if (bcs->tx_skb) {
  1056. skb_queue_tail(&bcs->squeue, skb);
  1057. } else {
  1058. bcs->tx_skb = skb;
  1059. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1060. bcs->cs->BC_Send_Data(bcs);
  1061. }
  1062. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1063. break;
  1064. case (PH_PULL | INDICATION):
  1065. spin_lock_irqsave(&bcs->cs->lock, flags);
  1066. if (bcs->tx_skb) {
  1067. printk(KERN_WARNING "%s: this shouldn't happen\n",
  1068. __func__);
  1069. } else {
  1070. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1071. bcs->tx_skb = skb;
  1072. bcs->cs->BC_Send_Data(bcs);
  1073. }
  1074. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1075. break;
  1076. case (PH_PULL | REQUEST):
  1077. if (!bcs->tx_skb) {
  1078. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1079. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  1080. } else
  1081. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1082. break;
  1083. case (PH_ACTIVATE | REQUEST):
  1084. spin_lock_irqsave(&bcs->cs->lock, flags);
  1085. test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
  1086. mode_hfcsx(bcs, st->l1.mode, st->l1.bc);
  1087. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1088. l1_msg_b(st, pr, arg);
  1089. break;
  1090. case (PH_DEACTIVATE | REQUEST):
  1091. l1_msg_b(st, pr, arg);
  1092. break;
  1093. case (PH_DEACTIVATE | CONFIRM):
  1094. spin_lock_irqsave(&bcs->cs->lock, flags);
  1095. test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
  1096. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1097. mode_hfcsx(bcs, 0, st->l1.bc);
  1098. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1099. st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
  1100. break;
  1101. }
  1102. }
  1103. /******************************************/
  1104. /* deactivate B-channel access and queues */
  1105. /******************************************/
  1106. static void
  1107. close_hfcsx(struct BCState *bcs)
  1108. {
  1109. mode_hfcsx(bcs, 0, bcs->channel);
  1110. if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
  1111. skb_queue_purge(&bcs->rqueue);
  1112. skb_queue_purge(&bcs->squeue);
  1113. if (bcs->tx_skb) {
  1114. dev_kfree_skb_any(bcs->tx_skb);
  1115. bcs->tx_skb = NULL;
  1116. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1117. }
  1118. }
  1119. }
  1120. /*************************************/
  1121. /* init B-channel queues and control */
  1122. /*************************************/
  1123. static int
  1124. open_hfcsxstate(struct IsdnCardState *cs, struct BCState *bcs)
  1125. {
  1126. if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
  1127. skb_queue_head_init(&bcs->rqueue);
  1128. skb_queue_head_init(&bcs->squeue);
  1129. }
  1130. bcs->tx_skb = NULL;
  1131. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1132. bcs->event = 0;
  1133. bcs->tx_cnt = 0;
  1134. return (0);
  1135. }
  1136. /*********************************/
  1137. /* inits the stack for B-channel */
  1138. /*********************************/
  1139. static int
  1140. setstack_2b(struct PStack *st, struct BCState *bcs)
  1141. {
  1142. bcs->channel = st->l1.bc;
  1143. if (open_hfcsxstate(st->l1.hardware, bcs))
  1144. return (-1);
  1145. st->l1.bcs = bcs;
  1146. st->l2.l2l1 = hfcsx_l2l1;
  1147. setstack_manager(st);
  1148. bcs->st = st;
  1149. setstack_l1_B(st);
  1150. return (0);
  1151. }
  1152. /***************************/
  1153. /* handle L1 state changes */
  1154. /***************************/
  1155. static void
  1156. hfcsx_bh(struct work_struct *work)
  1157. {
  1158. struct IsdnCardState *cs =
  1159. container_of(work, struct IsdnCardState, tqueue);
  1160. u_long flags;
  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 inithfcsx(struct IsdnCardState *cs)
  1230. {
  1231. cs->setstack_d = setstack_hfcsx;
  1232. cs->BC_Send_Data = &hfcsx_send_data;
  1233. cs->bcs[0].BC_SetStack = setstack_2b;
  1234. cs->bcs[1].BC_SetStack = setstack_2b;
  1235. cs->bcs[0].BC_Close = close_hfcsx;
  1236. cs->bcs[1].BC_Close = close_hfcsx;
  1237. mode_hfcsx(cs->bcs, 0, 0);
  1238. mode_hfcsx(cs->bcs + 1, 0, 1);
  1239. }
  1240. /*******************************************/
  1241. /* handle card messages from control layer */
  1242. /*******************************************/
  1243. static int
  1244. hfcsx_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  1245. {
  1246. u_long flags;
  1247. if (cs->debug & L1_DEB_ISAC)
  1248. debugl1(cs, "HFCSX: card_msg %x", mt);
  1249. switch (mt) {
  1250. case CARD_RESET:
  1251. spin_lock_irqsave(&cs->lock, flags);
  1252. reset_hfcsx(cs);
  1253. spin_unlock_irqrestore(&cs->lock, flags);
  1254. return (0);
  1255. case CARD_RELEASE:
  1256. release_io_hfcsx(cs);
  1257. return (0);
  1258. case CARD_INIT:
  1259. spin_lock_irqsave(&cs->lock, flags);
  1260. inithfcsx(cs);
  1261. spin_unlock_irqrestore(&cs->lock, flags);
  1262. msleep(80); /* Timeout 80ms */
  1263. /* now switch timer interrupt off */
  1264. spin_lock_irqsave(&cs->lock, flags);
  1265. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1266. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1267. /* reinit mode reg */
  1268. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  1269. spin_unlock_irqrestore(&cs->lock, flags);
  1270. return (0);
  1271. case CARD_TEST:
  1272. return (0);
  1273. }
  1274. return (0);
  1275. }
  1276. #ifdef __ISAPNP__
  1277. static struct isapnp_device_id hfc_ids[] = {
  1278. { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2620),
  1279. ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2620),
  1280. (unsigned long) "Teles 16.3c2" },
  1281. { 0, }
  1282. };
  1283. static struct isapnp_device_id *ipid = &hfc_ids[0];
  1284. static struct pnp_card *pnp_c = NULL;
  1285. #endif
  1286. int 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 =
  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. }