hfc_sx.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517
  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 timer_list *t)
  367. {
  368. struct IsdnCardState *cs = from_timer(cs, t, hw.hfcsx.timer);
  369. cs->hw.hfcsx.timer.expires = jiffies + 75;
  370. /* WD RESET */
  371. /* WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcsx.ctmt | 0x80);
  372. add_timer(&cs->hw.hfcsx.timer);
  373. */
  374. }
  375. /************************************************/
  376. /* select a b-channel entry matching and active */
  377. /************************************************/
  378. static
  379. struct BCState *
  380. Sel_BCS(struct IsdnCardState *cs, int channel)
  381. {
  382. if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
  383. return (&cs->bcs[0]);
  384. else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
  385. return (&cs->bcs[1]);
  386. else
  387. return (NULL);
  388. }
  389. /*******************************/
  390. /* D-channel receive procedure */
  391. /*******************************/
  392. static
  393. int
  394. receive_dmsg(struct IsdnCardState *cs)
  395. {
  396. struct sk_buff *skb;
  397. int count = 5;
  398. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  399. debugl1(cs, "rec_dmsg blocked");
  400. return (1);
  401. }
  402. do {
  403. skb = read_fifo(cs, HFCSX_SEL_D_RX, 0);
  404. if (skb) {
  405. skb_queue_tail(&cs->rq, skb);
  406. schedule_event(cs, D_RCVBUFREADY);
  407. }
  408. } while (--count && skb);
  409. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  410. return (1);
  411. }
  412. /**********************************/
  413. /* B-channel main receive routine */
  414. /**********************************/
  415. static void
  416. main_rec_hfcsx(struct BCState *bcs)
  417. {
  418. struct IsdnCardState *cs = bcs->cs;
  419. int count = 5;
  420. struct sk_buff *skb;
  421. Begin:
  422. count--;
  423. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  424. debugl1(cs, "rec_data %d blocked", bcs->channel);
  425. return;
  426. }
  427. skb = read_fifo(cs, ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
  428. HFCSX_SEL_B2_RX : HFCSX_SEL_B1_RX,
  429. (bcs->mode == L1_MODE_TRANS) ?
  430. HFCSX_BTRANS_THRESHOLD : 0);
  431. if (skb) {
  432. skb_queue_tail(&bcs->rqueue, skb);
  433. schedule_event(bcs, B_RCVBUFREADY);
  434. }
  435. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  436. if (count && skb)
  437. goto Begin;
  438. return;
  439. }
  440. /**************************/
  441. /* D-channel send routine */
  442. /**************************/
  443. static void
  444. hfcsx_fill_dfifo(struct IsdnCardState *cs)
  445. {
  446. if (!cs->tx_skb)
  447. return;
  448. if (cs->tx_skb->len <= 0)
  449. return;
  450. if (write_fifo(cs, cs->tx_skb, HFCSX_SEL_D_TX, 0)) {
  451. dev_kfree_skb_any(cs->tx_skb);
  452. cs->tx_skb = NULL;
  453. }
  454. return;
  455. }
  456. /**************************/
  457. /* B-channel send routine */
  458. /**************************/
  459. static void
  460. hfcsx_fill_fifo(struct BCState *bcs)
  461. {
  462. struct IsdnCardState *cs = bcs->cs;
  463. if (!bcs->tx_skb)
  464. return;
  465. if (bcs->tx_skb->len <= 0)
  466. return;
  467. if (write_fifo(cs, bcs->tx_skb,
  468. ((bcs->channel) && (!cs->hw.hfcsx.bswapped)) ?
  469. HFCSX_SEL_B2_TX : HFCSX_SEL_B1_TX,
  470. (bcs->mode == L1_MODE_TRANS) ?
  471. HFCSX_BTRANS_THRESHOLD : 0)) {
  472. bcs->tx_cnt -= bcs->tx_skb->len;
  473. if (test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
  474. (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
  475. u_long flags;
  476. spin_lock_irqsave(&bcs->aclock, flags);
  477. bcs->ackcnt += bcs->tx_skb->len;
  478. spin_unlock_irqrestore(&bcs->aclock, flags);
  479. schedule_event(bcs, B_ACKPENDING);
  480. }
  481. dev_kfree_skb_any(bcs->tx_skb);
  482. bcs->tx_skb = NULL;
  483. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  484. }
  485. }
  486. /**********************************************/
  487. /* D-channel l1 state call for leased NT-mode */
  488. /**********************************************/
  489. static void
  490. dch_nt_l2l1(struct PStack *st, int pr, void *arg)
  491. {
  492. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  493. switch (pr) {
  494. case (PH_DATA | REQUEST):
  495. case (PH_PULL | REQUEST):
  496. case (PH_PULL | INDICATION):
  497. st->l1.l1hw(st, pr, arg);
  498. break;
  499. case (PH_ACTIVATE | REQUEST):
  500. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  501. break;
  502. case (PH_TESTLOOP | REQUEST):
  503. if (1 & (long) arg)
  504. debugl1(cs, "PH_TEST_LOOP B1");
  505. if (2 & (long) arg)
  506. debugl1(cs, "PH_TEST_LOOP B2");
  507. if (!(3 & (long) arg))
  508. debugl1(cs, "PH_TEST_LOOP DISABLED");
  509. st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
  510. break;
  511. default:
  512. if (cs->debug)
  513. debugl1(cs, "dch_nt_l2l1 msg %04X unhandled", pr);
  514. break;
  515. }
  516. }
  517. /***********************/
  518. /* set/reset echo mode */
  519. /***********************/
  520. static int
  521. hfcsx_auxcmd(struct IsdnCardState *cs, isdn_ctrl *ic)
  522. {
  523. unsigned long flags;
  524. int i = *(unsigned int *) ic->parm.num;
  525. if ((ic->arg == 98) &&
  526. (!(cs->hw.hfcsx.int_m1 & (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC + HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC)))) {
  527. spin_lock_irqsave(&cs->lock, flags);
  528. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 0); /* HFC ST G0 */
  529. udelay(10);
  530. cs->hw.hfcsx.sctrl |= SCTRL_MODE_NT;
  531. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl); /* set NT-mode */
  532. udelay(10);
  533. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 1); /* HFC ST G1 */
  534. udelay(10);
  535. Write_hfc(cs, HFCSX_STATES, 1 | HFCSX_ACTIVATE | HFCSX_DO_ACTION);
  536. cs->dc.hfcsx.ph_state = 1;
  537. cs->hw.hfcsx.nt_mode = 1;
  538. cs->hw.hfcsx.nt_timer = 0;
  539. spin_unlock_irqrestore(&cs->lock, flags);
  540. cs->stlist->l2.l2l1 = dch_nt_l2l1;
  541. debugl1(cs, "NT mode activated");
  542. return (0);
  543. }
  544. if ((cs->chanlimit > 1) || (cs->hw.hfcsx.bswapped) ||
  545. (cs->hw.hfcsx.nt_mode) || (ic->arg != 12))
  546. return (-EINVAL);
  547. if (i) {
  548. cs->logecho = 1;
  549. cs->hw.hfcsx.trm |= 0x20; /* enable echo chan */
  550. cs->hw.hfcsx.int_m1 |= HFCSX_INTS_B2REC;
  551. /* reset Channel !!!!! */
  552. } else {
  553. cs->logecho = 0;
  554. cs->hw.hfcsx.trm &= ~0x20; /* disable echo chan */
  555. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_B2REC;
  556. }
  557. cs->hw.hfcsx.sctrl_r &= ~SCTRL_B2_ENA;
  558. cs->hw.hfcsx.sctrl &= ~SCTRL_B2_ENA;
  559. cs->hw.hfcsx.conn |= 0x10; /* B2-IOM -> B2-ST */
  560. cs->hw.hfcsx.ctmt &= ~2;
  561. spin_lock_irqsave(&cs->lock, flags);
  562. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
  563. Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
  564. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
  565. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  566. Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
  567. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  568. spin_unlock_irqrestore(&cs->lock, flags);
  569. return (0);
  570. } /* hfcsx_auxcmd */
  571. /*****************************/
  572. /* E-channel receive routine */
  573. /*****************************/
  574. static void
  575. receive_emsg(struct IsdnCardState *cs)
  576. {
  577. int count = 5;
  578. u_char *ptr;
  579. struct sk_buff *skb;
  580. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  581. debugl1(cs, "echo_rec_data blocked");
  582. return;
  583. }
  584. do {
  585. skb = read_fifo(cs, HFCSX_SEL_B2_RX, 0);
  586. if (skb) {
  587. if (cs->debug & DEB_DLOG_HEX) {
  588. ptr = cs->dlog;
  589. if ((skb->len) < MAX_DLOG_SPACE / 3 - 10) {
  590. *ptr++ = 'E';
  591. *ptr++ = 'C';
  592. *ptr++ = 'H';
  593. *ptr++ = 'O';
  594. *ptr++ = ':';
  595. ptr += QuickHex(ptr, skb->data, skb->len);
  596. ptr--;
  597. *ptr++ = '\n';
  598. *ptr = 0;
  599. HiSax_putstatus(cs, NULL, cs->dlog);
  600. } else
  601. HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
  602. }
  603. dev_kfree_skb_any(skb);
  604. }
  605. } while (--count && skb);
  606. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  607. return;
  608. } /* receive_emsg */
  609. /*********************/
  610. /* Interrupt handler */
  611. /*********************/
  612. static irqreturn_t
  613. hfcsx_interrupt(int intno, void *dev_id)
  614. {
  615. struct IsdnCardState *cs = dev_id;
  616. u_char exval;
  617. struct BCState *bcs;
  618. int count = 15;
  619. u_long flags;
  620. u_char val, stat;
  621. if (!(cs->hw.hfcsx.int_m2 & 0x08))
  622. return IRQ_NONE; /* not initialised */
  623. spin_lock_irqsave(&cs->lock, flags);
  624. if (HFCSX_ANYINT & (stat = Read_hfc(cs, HFCSX_STATUS))) {
  625. val = Read_hfc(cs, HFCSX_INT_S1);
  626. if (cs->debug & L1_DEB_ISAC)
  627. debugl1(cs, "HFC-SX: stat(%02x) s1(%02x)", stat, val);
  628. } else {
  629. spin_unlock_irqrestore(&cs->lock, flags);
  630. return IRQ_NONE;
  631. }
  632. if (cs->debug & L1_DEB_ISAC)
  633. debugl1(cs, "HFC-SX irq %x %s", val,
  634. test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
  635. "locked" : "unlocked");
  636. val &= cs->hw.hfcsx.int_m1;
  637. if (val & 0x40) { /* state machine irq */
  638. exval = Read_hfc(cs, HFCSX_STATES) & 0xf;
  639. if (cs->debug & L1_DEB_ISAC)
  640. debugl1(cs, "ph_state chg %d->%d", cs->dc.hfcsx.ph_state,
  641. exval);
  642. cs->dc.hfcsx.ph_state = exval;
  643. schedule_event(cs, D_L1STATECHANGE);
  644. val &= ~0x40;
  645. }
  646. if (val & 0x80) { /* timer irq */
  647. if (cs->hw.hfcsx.nt_mode) {
  648. if ((--cs->hw.hfcsx.nt_timer) < 0)
  649. schedule_event(cs, D_L1STATECHANGE);
  650. }
  651. val &= ~0x80;
  652. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  653. }
  654. while (val) {
  655. if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  656. cs->hw.hfcsx.int_s1 |= val;
  657. spin_unlock_irqrestore(&cs->lock, flags);
  658. return IRQ_HANDLED;
  659. }
  660. if (cs->hw.hfcsx.int_s1 & 0x18) {
  661. exval = val;
  662. val = cs->hw.hfcsx.int_s1;
  663. cs->hw.hfcsx.int_s1 = exval;
  664. }
  665. if (val & 0x08) {
  666. if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
  667. if (cs->debug)
  668. debugl1(cs, "hfcsx spurious 0x08 IRQ");
  669. } else
  670. main_rec_hfcsx(bcs);
  671. }
  672. if (val & 0x10) {
  673. if (cs->logecho)
  674. receive_emsg(cs);
  675. else if (!(bcs = Sel_BCS(cs, 1))) {
  676. if (cs->debug)
  677. debugl1(cs, "hfcsx spurious 0x10 IRQ");
  678. } else
  679. main_rec_hfcsx(bcs);
  680. }
  681. if (val & 0x01) {
  682. if (!(bcs = Sel_BCS(cs, cs->hw.hfcsx.bswapped ? 1 : 0))) {
  683. if (cs->debug)
  684. debugl1(cs, "hfcsx spurious 0x01 IRQ");
  685. } else {
  686. if (bcs->tx_skb) {
  687. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  688. hfcsx_fill_fifo(bcs);
  689. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  690. } else
  691. debugl1(cs, "fill_data %d blocked", bcs->channel);
  692. } else {
  693. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  694. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  695. hfcsx_fill_fifo(bcs);
  696. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  697. } else
  698. debugl1(cs, "fill_data %d blocked", bcs->channel);
  699. } else {
  700. schedule_event(bcs, B_XMTBUFREADY);
  701. }
  702. }
  703. }
  704. }
  705. if (val & 0x02) {
  706. if (!(bcs = Sel_BCS(cs, 1))) {
  707. if (cs->debug)
  708. debugl1(cs, "hfcsx spurious 0x02 IRQ");
  709. } else {
  710. if (bcs->tx_skb) {
  711. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  712. hfcsx_fill_fifo(bcs);
  713. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  714. } else
  715. debugl1(cs, "fill_data %d blocked", bcs->channel);
  716. } else {
  717. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  718. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  719. hfcsx_fill_fifo(bcs);
  720. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  721. } else
  722. debugl1(cs, "fill_data %d blocked", bcs->channel);
  723. } else {
  724. schedule_event(bcs, B_XMTBUFREADY);
  725. }
  726. }
  727. }
  728. }
  729. if (val & 0x20) { /* receive dframe */
  730. receive_dmsg(cs);
  731. }
  732. if (val & 0x04) { /* dframe transmitted */
  733. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  734. del_timer(&cs->dbusytimer);
  735. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  736. schedule_event(cs, D_CLEARBUSY);
  737. if (cs->tx_skb) {
  738. if (cs->tx_skb->len) {
  739. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  740. hfcsx_fill_dfifo(cs);
  741. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  742. } else {
  743. debugl1(cs, "hfcsx_fill_dfifo irq blocked");
  744. }
  745. goto afterXPR;
  746. } else {
  747. dev_kfree_skb_irq(cs->tx_skb);
  748. cs->tx_cnt = 0;
  749. cs->tx_skb = NULL;
  750. }
  751. }
  752. if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
  753. cs->tx_cnt = 0;
  754. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  755. hfcsx_fill_dfifo(cs);
  756. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  757. } else {
  758. debugl1(cs, "hfcsx_fill_dfifo irq blocked");
  759. }
  760. } else
  761. schedule_event(cs, D_XMTBUFREADY);
  762. }
  763. afterXPR:
  764. if (cs->hw.hfcsx.int_s1 && count--) {
  765. val = cs->hw.hfcsx.int_s1;
  766. cs->hw.hfcsx.int_s1 = 0;
  767. if (cs->debug & L1_DEB_ISAC)
  768. debugl1(cs, "HFC-SX irq %x loop %d", val, 15 - count);
  769. } else
  770. val = 0;
  771. }
  772. spin_unlock_irqrestore(&cs->lock, flags);
  773. return IRQ_HANDLED;
  774. }
  775. /********************************************************************/
  776. /* timer callback for D-chan busy resolution. Currently no function */
  777. /********************************************************************/
  778. static void
  779. hfcsx_dbusy_timer(struct timer_list *t)
  780. {
  781. }
  782. /*************************************/
  783. /* Layer 1 D-channel hardware access */
  784. /*************************************/
  785. static void
  786. HFCSX_l1hw(struct PStack *st, int pr, void *arg)
  787. {
  788. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  789. struct sk_buff *skb = arg;
  790. u_long flags;
  791. switch (pr) {
  792. case (PH_DATA | REQUEST):
  793. if (cs->debug & DEB_DLOG_HEX)
  794. LogFrame(cs, skb->data, skb->len);
  795. if (cs->debug & DEB_DLOG_VERBOSE)
  796. dlogframe(cs, skb, 0);
  797. spin_lock_irqsave(&cs->lock, flags);
  798. if (cs->tx_skb) {
  799. skb_queue_tail(&cs->sq, skb);
  800. #ifdef L2FRAME_DEBUG /* psa */
  801. if (cs->debug & L1_DEB_LAPD)
  802. Logl2Frame(cs, skb, "PH_DATA Queued", 0);
  803. #endif
  804. } else {
  805. cs->tx_skb = skb;
  806. cs->tx_cnt = 0;
  807. #ifdef L2FRAME_DEBUG /* psa */
  808. if (cs->debug & L1_DEB_LAPD)
  809. Logl2Frame(cs, skb, "PH_DATA", 0);
  810. #endif
  811. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  812. hfcsx_fill_dfifo(cs);
  813. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  814. } else
  815. debugl1(cs, "hfcsx_fill_dfifo blocked");
  816. }
  817. spin_unlock_irqrestore(&cs->lock, flags);
  818. break;
  819. case (PH_PULL | INDICATION):
  820. spin_lock_irqsave(&cs->lock, flags);
  821. if (cs->tx_skb) {
  822. if (cs->debug & L1_DEB_WARN)
  823. debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
  824. skb_queue_tail(&cs->sq, skb);
  825. spin_unlock_irqrestore(&cs->lock, flags);
  826. break;
  827. }
  828. if (cs->debug & DEB_DLOG_HEX)
  829. LogFrame(cs, skb->data, skb->len);
  830. if (cs->debug & DEB_DLOG_VERBOSE)
  831. dlogframe(cs, skb, 0);
  832. cs->tx_skb = skb;
  833. cs->tx_cnt = 0;
  834. #ifdef L2FRAME_DEBUG /* psa */
  835. if (cs->debug & L1_DEB_LAPD)
  836. Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
  837. #endif
  838. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  839. hfcsx_fill_dfifo(cs);
  840. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  841. } else
  842. debugl1(cs, "hfcsx_fill_dfifo blocked");
  843. spin_unlock_irqrestore(&cs->lock, flags);
  844. break;
  845. case (PH_PULL | REQUEST):
  846. #ifdef L2FRAME_DEBUG /* psa */
  847. if (cs->debug & L1_DEB_LAPD)
  848. debugl1(cs, "-> PH_REQUEST_PULL");
  849. #endif
  850. if (!cs->tx_skb) {
  851. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  852. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  853. } else
  854. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  855. break;
  856. case (HW_RESET | REQUEST):
  857. spin_lock_irqsave(&cs->lock, flags);
  858. Write_hfc(cs, HFCSX_STATES, HFCSX_LOAD_STATE | 3); /* HFC ST 3 */
  859. udelay(6);
  860. Write_hfc(cs, HFCSX_STATES, 3); /* HFC ST 2 */
  861. cs->hw.hfcsx.mst_m |= HFCSX_MASTER;
  862. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  863. Write_hfc(cs, HFCSX_STATES, HFCSX_ACTIVATE | HFCSX_DO_ACTION);
  864. spin_unlock_irqrestore(&cs->lock, flags);
  865. l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
  866. break;
  867. case (HW_ENABLE | REQUEST):
  868. spin_lock_irqsave(&cs->lock, flags);
  869. Write_hfc(cs, HFCSX_STATES, HFCSX_ACTIVATE | HFCSX_DO_ACTION);
  870. spin_unlock_irqrestore(&cs->lock, flags);
  871. break;
  872. case (HW_DEACTIVATE | REQUEST):
  873. spin_lock_irqsave(&cs->lock, flags);
  874. cs->hw.hfcsx.mst_m &= ~HFCSX_MASTER;
  875. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  876. spin_unlock_irqrestore(&cs->lock, flags);
  877. break;
  878. case (HW_INFO3 | REQUEST):
  879. spin_lock_irqsave(&cs->lock, flags);
  880. cs->hw.hfcsx.mst_m |= HFCSX_MASTER;
  881. Write_hfc(cs, HFCSX_MST_MODE, cs->hw.hfcsx.mst_m);
  882. spin_unlock_irqrestore(&cs->lock, flags);
  883. break;
  884. case (HW_TESTLOOP | REQUEST):
  885. spin_lock_irqsave(&cs->lock, flags);
  886. switch ((long) arg) {
  887. case (1):
  888. Write_hfc(cs, HFCSX_B1_SSL, 0x80); /* tx slot */
  889. Write_hfc(cs, HFCSX_B1_RSL, 0x80); /* rx slot */
  890. cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~7) | 1;
  891. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  892. break;
  893. case (2):
  894. Write_hfc(cs, HFCSX_B2_SSL, 0x81); /* tx slot */
  895. Write_hfc(cs, HFCSX_B2_RSL, 0x81); /* rx slot */
  896. cs->hw.hfcsx.conn = (cs->hw.hfcsx.conn & ~0x38) | 0x08;
  897. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  898. break;
  899. default:
  900. spin_unlock_irqrestore(&cs->lock, flags);
  901. if (cs->debug & L1_DEB_WARN)
  902. debugl1(cs, "hfcsx_l1hw loop invalid %4lx", (unsigned long)arg);
  903. return;
  904. }
  905. cs->hw.hfcsx.trm |= 0x80; /* enable IOM-loop */
  906. Write_hfc(cs, HFCSX_TRM, cs->hw.hfcsx.trm);
  907. spin_unlock_irqrestore(&cs->lock, flags);
  908. break;
  909. default:
  910. if (cs->debug & L1_DEB_WARN)
  911. debugl1(cs, "hfcsx_l1hw unknown pr %4x", pr);
  912. break;
  913. }
  914. }
  915. /***********************************************/
  916. /* called during init setting l1 stack pointer */
  917. /***********************************************/
  918. static void
  919. setstack_hfcsx(struct PStack *st, struct IsdnCardState *cs)
  920. {
  921. st->l1.l1hw = HFCSX_l1hw;
  922. }
  923. /**************************************/
  924. /* send B-channel data if not blocked */
  925. /**************************************/
  926. static void
  927. hfcsx_send_data(struct BCState *bcs)
  928. {
  929. struct IsdnCardState *cs = bcs->cs;
  930. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  931. hfcsx_fill_fifo(bcs);
  932. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  933. } else
  934. debugl1(cs, "send_data %d blocked", bcs->channel);
  935. }
  936. /***************************************************************/
  937. /* activate/deactivate hardware for selected channels and mode */
  938. /***************************************************************/
  939. static void
  940. mode_hfcsx(struct BCState *bcs, int mode, int bc)
  941. {
  942. struct IsdnCardState *cs = bcs->cs;
  943. int fifo2;
  944. if (cs->debug & L1_DEB_HSCX)
  945. debugl1(cs, "HFCSX bchannel mode %d bchan %d/%d",
  946. mode, bc, bcs->channel);
  947. bcs->mode = mode;
  948. bcs->channel = bc;
  949. fifo2 = bc;
  950. if (cs->chanlimit > 1) {
  951. cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
  952. cs->hw.hfcsx.sctrl_e &= ~0x80;
  953. } else {
  954. if (bc) {
  955. if (mode != L1_MODE_NULL) {
  956. cs->hw.hfcsx.bswapped = 1; /* B1 and B2 exchanged */
  957. cs->hw.hfcsx.sctrl_e |= 0x80;
  958. } else {
  959. cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
  960. cs->hw.hfcsx.sctrl_e &= ~0x80;
  961. }
  962. fifo2 = 0;
  963. } else {
  964. cs->hw.hfcsx.bswapped = 0; /* B1 and B2 normal mode */
  965. cs->hw.hfcsx.sctrl_e &= ~0x80;
  966. }
  967. }
  968. switch (mode) {
  969. case (L1_MODE_NULL):
  970. if (bc) {
  971. cs->hw.hfcsx.sctrl &= ~SCTRL_B2_ENA;
  972. cs->hw.hfcsx.sctrl_r &= ~SCTRL_B2_ENA;
  973. } else {
  974. cs->hw.hfcsx.sctrl &= ~SCTRL_B1_ENA;
  975. cs->hw.hfcsx.sctrl_r &= ~SCTRL_B1_ENA;
  976. }
  977. if (fifo2) {
  978. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  979. } else {
  980. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  981. }
  982. break;
  983. case (L1_MODE_TRANS):
  984. if (bc) {
  985. cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
  986. cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
  987. } else {
  988. cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
  989. cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
  990. }
  991. if (fifo2) {
  992. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  993. cs->hw.hfcsx.ctmt |= 2;
  994. cs->hw.hfcsx.conn &= ~0x18;
  995. } else {
  996. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  997. cs->hw.hfcsx.ctmt |= 1;
  998. cs->hw.hfcsx.conn &= ~0x03;
  999. }
  1000. break;
  1001. case (L1_MODE_HDLC):
  1002. if (bc) {
  1003. cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
  1004. cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
  1005. } else {
  1006. cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
  1007. cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
  1008. }
  1009. if (fifo2) {
  1010. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  1011. cs->hw.hfcsx.ctmt &= ~2;
  1012. cs->hw.hfcsx.conn &= ~0x18;
  1013. } else {
  1014. cs->hw.hfcsx.int_m1 |= (HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  1015. cs->hw.hfcsx.ctmt &= ~1;
  1016. cs->hw.hfcsx.conn &= ~0x03;
  1017. }
  1018. break;
  1019. case (L1_MODE_EXTRN):
  1020. if (bc) {
  1021. cs->hw.hfcsx.conn |= 0x10;
  1022. cs->hw.hfcsx.sctrl |= SCTRL_B2_ENA;
  1023. cs->hw.hfcsx.sctrl_r |= SCTRL_B2_ENA;
  1024. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B2TRANS + HFCSX_INTS_B2REC);
  1025. } else {
  1026. cs->hw.hfcsx.conn |= 0x02;
  1027. cs->hw.hfcsx.sctrl |= SCTRL_B1_ENA;
  1028. cs->hw.hfcsx.sctrl_r |= SCTRL_B1_ENA;
  1029. cs->hw.hfcsx.int_m1 &= ~(HFCSX_INTS_B1TRANS + HFCSX_INTS_B1REC);
  1030. }
  1031. break;
  1032. }
  1033. Write_hfc(cs, HFCSX_SCTRL_E, cs->hw.hfcsx.sctrl_e);
  1034. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1035. Write_hfc(cs, HFCSX_SCTRL, cs->hw.hfcsx.sctrl);
  1036. Write_hfc(cs, HFCSX_SCTRL_R, cs->hw.hfcsx.sctrl_r);
  1037. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt);
  1038. Write_hfc(cs, HFCSX_CONNECT, cs->hw.hfcsx.conn);
  1039. if (mode != L1_MODE_EXTRN) {
  1040. reset_fifo(cs, fifo2 ? HFCSX_SEL_B2_RX : HFCSX_SEL_B1_RX);
  1041. reset_fifo(cs, fifo2 ? HFCSX_SEL_B2_TX : HFCSX_SEL_B1_TX);
  1042. }
  1043. }
  1044. /******************************/
  1045. /* Layer2 -> Layer 1 Transfer */
  1046. /******************************/
  1047. static void
  1048. hfcsx_l2l1(struct PStack *st, int pr, void *arg)
  1049. {
  1050. struct BCState *bcs = st->l1.bcs;
  1051. struct sk_buff *skb = arg;
  1052. u_long flags;
  1053. switch (pr) {
  1054. case (PH_DATA | REQUEST):
  1055. spin_lock_irqsave(&bcs->cs->lock, flags);
  1056. if (bcs->tx_skb) {
  1057. skb_queue_tail(&bcs->squeue, skb);
  1058. } else {
  1059. bcs->tx_skb = skb;
  1060. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1061. bcs->cs->BC_Send_Data(bcs);
  1062. }
  1063. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1064. break;
  1065. case (PH_PULL | INDICATION):
  1066. spin_lock_irqsave(&bcs->cs->lock, flags);
  1067. if (bcs->tx_skb) {
  1068. printk(KERN_WARNING "%s: this shouldn't happen\n",
  1069. __func__);
  1070. } else {
  1071. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1072. bcs->tx_skb = skb;
  1073. bcs->cs->BC_Send_Data(bcs);
  1074. }
  1075. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1076. break;
  1077. case (PH_PULL | REQUEST):
  1078. if (!bcs->tx_skb) {
  1079. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1080. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  1081. } else
  1082. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1083. break;
  1084. case (PH_ACTIVATE | REQUEST):
  1085. spin_lock_irqsave(&bcs->cs->lock, flags);
  1086. test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
  1087. mode_hfcsx(bcs, st->l1.mode, st->l1.bc);
  1088. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1089. l1_msg_b(st, pr, arg);
  1090. break;
  1091. case (PH_DEACTIVATE | REQUEST):
  1092. l1_msg_b(st, pr, arg);
  1093. break;
  1094. case (PH_DEACTIVATE | CONFIRM):
  1095. spin_lock_irqsave(&bcs->cs->lock, flags);
  1096. test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
  1097. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1098. mode_hfcsx(bcs, 0, st->l1.bc);
  1099. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1100. st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
  1101. break;
  1102. }
  1103. }
  1104. /******************************************/
  1105. /* deactivate B-channel access and queues */
  1106. /******************************************/
  1107. static void
  1108. close_hfcsx(struct BCState *bcs)
  1109. {
  1110. mode_hfcsx(bcs, 0, bcs->channel);
  1111. if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
  1112. skb_queue_purge(&bcs->rqueue);
  1113. skb_queue_purge(&bcs->squeue);
  1114. if (bcs->tx_skb) {
  1115. dev_kfree_skb_any(bcs->tx_skb);
  1116. bcs->tx_skb = NULL;
  1117. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1118. }
  1119. }
  1120. }
  1121. /*************************************/
  1122. /* init B-channel queues and control */
  1123. /*************************************/
  1124. static int
  1125. open_hfcsxstate(struct IsdnCardState *cs, struct BCState *bcs)
  1126. {
  1127. if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
  1128. skb_queue_head_init(&bcs->rqueue);
  1129. skb_queue_head_init(&bcs->squeue);
  1130. }
  1131. bcs->tx_skb = NULL;
  1132. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1133. bcs->event = 0;
  1134. bcs->tx_cnt = 0;
  1135. return (0);
  1136. }
  1137. /*********************************/
  1138. /* inits the stack for B-channel */
  1139. /*********************************/
  1140. static int
  1141. setstack_2b(struct PStack *st, struct BCState *bcs)
  1142. {
  1143. bcs->channel = st->l1.bc;
  1144. if (open_hfcsxstate(st->l1.hardware, bcs))
  1145. return (-1);
  1146. st->l1.bcs = bcs;
  1147. st->l2.l2l1 = hfcsx_l2l1;
  1148. setstack_manager(st);
  1149. bcs->st = st;
  1150. setstack_l1_B(st);
  1151. return (0);
  1152. }
  1153. /***************************/
  1154. /* handle L1 state changes */
  1155. /***************************/
  1156. static void
  1157. hfcsx_bh(struct work_struct *work)
  1158. {
  1159. struct IsdnCardState *cs =
  1160. container_of(work, struct IsdnCardState, tqueue);
  1161. u_long flags;
  1162. if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
  1163. if (!cs->hw.hfcsx.nt_mode)
  1164. switch (cs->dc.hfcsx.ph_state) {
  1165. case (0):
  1166. l1_msg(cs, HW_RESET | INDICATION, NULL);
  1167. break;
  1168. case (3):
  1169. l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
  1170. break;
  1171. case (8):
  1172. l1_msg(cs, HW_RSYNC | INDICATION, NULL);
  1173. break;
  1174. case (6):
  1175. l1_msg(cs, HW_INFO2 | INDICATION, NULL);
  1176. break;
  1177. case (7):
  1178. l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
  1179. break;
  1180. default:
  1181. break;
  1182. } else {
  1183. switch (cs->dc.hfcsx.ph_state) {
  1184. case (2):
  1185. spin_lock_irqsave(&cs->lock, flags);
  1186. if (cs->hw.hfcsx.nt_timer < 0) {
  1187. cs->hw.hfcsx.nt_timer = 0;
  1188. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1189. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1190. /* Clear already pending ints */
  1191. if (Read_hfc(cs, HFCSX_INT_S1));
  1192. Write_hfc(cs, HFCSX_STATES, 4 | HFCSX_LOAD_STATE);
  1193. udelay(10);
  1194. Write_hfc(cs, HFCSX_STATES, 4);
  1195. cs->dc.hfcsx.ph_state = 4;
  1196. } else {
  1197. cs->hw.hfcsx.int_m1 |= HFCSX_INTS_TIMER;
  1198. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1199. cs->hw.hfcsx.ctmt &= ~HFCSX_AUTO_TIMER;
  1200. cs->hw.hfcsx.ctmt |= HFCSX_TIM3_125;
  1201. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  1202. Write_hfc(cs, HFCSX_CTMT, cs->hw.hfcsx.ctmt | HFCSX_CLTIMER);
  1203. cs->hw.hfcsx.nt_timer = NT_T1_COUNT;
  1204. Write_hfc(cs, HFCSX_STATES, 2 | HFCSX_NT_G2_G3); /* allow G2 -> G3 transition */
  1205. }
  1206. spin_unlock_irqrestore(&cs->lock, flags);
  1207. break;
  1208. case (1):
  1209. case (3):
  1210. case (4):
  1211. spin_lock_irqsave(&cs->lock, flags);
  1212. cs->hw.hfcsx.nt_timer = 0;
  1213. cs->hw.hfcsx.int_m1 &= ~HFCSX_INTS_TIMER;
  1214. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1215. spin_unlock_irqrestore(&cs->lock, flags);
  1216. break;
  1217. default:
  1218. break;
  1219. }
  1220. }
  1221. }
  1222. if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
  1223. DChannel_proc_rcv(cs);
  1224. if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
  1225. DChannel_proc_xmt(cs);
  1226. }
  1227. /********************************/
  1228. /* called for card init message */
  1229. /********************************/
  1230. static void 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[] = {
  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 = &hfc_ids[0];
  1285. static struct pnp_card *pnp_c = NULL;
  1286. #endif
  1287. int setup_hfcsx(struct IsdnCard *card)
  1288. {
  1289. struct IsdnCardState *cs = card->cs;
  1290. char tmp[64];
  1291. strcpy(tmp, hfcsx_revision);
  1292. printk(KERN_INFO "HiSax: HFC-SX driver Rev. %s\n", HiSax_getrev(tmp));
  1293. #ifdef __ISAPNP__
  1294. if (!card->para[1] && isapnp_present()) {
  1295. struct pnp_dev *pnp_d;
  1296. while (ipid->card_vendor) {
  1297. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  1298. ipid->card_device, pnp_c))) {
  1299. pnp_d = NULL;
  1300. if ((pnp_d = pnp_find_dev(pnp_c,
  1301. ipid->vendor, ipid->function, pnp_d))) {
  1302. int err;
  1303. printk(KERN_INFO "HiSax: %s detected\n",
  1304. (char *)ipid->driver_data);
  1305. pnp_disable_dev(pnp_d);
  1306. err = pnp_activate_dev(pnp_d);
  1307. if (err < 0) {
  1308. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  1309. __func__, err);
  1310. return (0);
  1311. }
  1312. card->para[1] = pnp_port_start(pnp_d, 0);
  1313. card->para[0] = pnp_irq(pnp_d, 0);
  1314. if (card->para[0] == -1 || !card->para[1]) {
  1315. printk(KERN_ERR "HFC PnP:some resources are missing %ld/%lx\n",
  1316. card->para[0], card->para[1]);
  1317. pnp_disable_dev(pnp_d);
  1318. return (0);
  1319. }
  1320. break;
  1321. } else {
  1322. printk(KERN_ERR "HFC PnP: PnP error card found, no device\n");
  1323. }
  1324. }
  1325. ipid++;
  1326. pnp_c = NULL;
  1327. }
  1328. if (!ipid->card_vendor) {
  1329. printk(KERN_INFO "HFC PnP: no ISAPnP card found\n");
  1330. return (0);
  1331. }
  1332. }
  1333. #endif
  1334. cs->hw.hfcsx.base = card->para[1] & 0xfffe;
  1335. cs->irq = card->para[0];
  1336. cs->hw.hfcsx.int_s1 = 0;
  1337. cs->dc.hfcsx.ph_state = 0;
  1338. cs->hw.hfcsx.fifo = 255;
  1339. if ((cs->typ == ISDN_CTYPE_HFC_SX) ||
  1340. (cs->typ == ISDN_CTYPE_HFC_SP_PCMCIA)) {
  1341. if ((!cs->hw.hfcsx.base) || !request_region(cs->hw.hfcsx.base, 2, "HFCSX isdn")) {
  1342. printk(KERN_WARNING
  1343. "HiSax: HFC-SX io-base %#lx already in use\n",
  1344. cs->hw.hfcsx.base);
  1345. return (0);
  1346. }
  1347. byteout(cs->hw.hfcsx.base, cs->hw.hfcsx.base & 0xFF);
  1348. byteout(cs->hw.hfcsx.base + 1,
  1349. ((cs->hw.hfcsx.base >> 8) & 3) | 0x54);
  1350. udelay(10);
  1351. cs->hw.hfcsx.chip = Read_hfc(cs, HFCSX_CHIP_ID);
  1352. switch (cs->hw.hfcsx.chip >> 4) {
  1353. case 1:
  1354. tmp[0] = '+';
  1355. break;
  1356. case 9:
  1357. tmp[0] = 'P';
  1358. break;
  1359. default:
  1360. printk(KERN_WARNING
  1361. "HFC-SX: invalid chip id 0x%x\n",
  1362. cs->hw.hfcsx.chip >> 4);
  1363. release_region(cs->hw.hfcsx.base, 2);
  1364. return (0);
  1365. }
  1366. if (!ccd_sp_irqtab[cs->irq & 0xF]) {
  1367. printk(KERN_WARNING
  1368. "HFC_SX: invalid irq %d specified\n", cs->irq & 0xF);
  1369. release_region(cs->hw.hfcsx.base, 2);
  1370. return (0);
  1371. }
  1372. if (!(cs->hw.hfcsx.extra =
  1373. kmalloc(sizeof(struct hfcsx_extra), GFP_ATOMIC))) {
  1374. release_region(cs->hw.hfcsx.base, 2);
  1375. printk(KERN_WARNING "HFC-SX: unable to allocate memory\n");
  1376. return (0);
  1377. }
  1378. printk(KERN_INFO "HFC-S%c chip detected at base 0x%x IRQ %d HZ %d\n",
  1379. tmp[0], (u_int) cs->hw.hfcsx.base, cs->irq, HZ);
  1380. cs->hw.hfcsx.int_m2 = 0; /* disable alle interrupts */
  1381. cs->hw.hfcsx.int_m1 = 0;
  1382. Write_hfc(cs, HFCSX_INT_M1, cs->hw.hfcsx.int_m1);
  1383. Write_hfc(cs, HFCSX_INT_M2, cs->hw.hfcsx.int_m2);
  1384. } else
  1385. return (0); /* no valid card type */
  1386. timer_setup(&cs->dbusytimer, hfcsx_dbusy_timer, 0);
  1387. INIT_WORK(&cs->tqueue, hfcsx_bh);
  1388. cs->readisac = NULL;
  1389. cs->writeisac = NULL;
  1390. cs->readisacfifo = NULL;
  1391. cs->writeisacfifo = NULL;
  1392. cs->BC_Read_Reg = NULL;
  1393. cs->BC_Write_Reg = NULL;
  1394. cs->irq_func = &hfcsx_interrupt;
  1395. cs->hw.hfcsx.b_fifo_size = 0; /* fifo size still unknown */
  1396. cs->hw.hfcsx.cirm = ccd_sp_irqtab[cs->irq & 0xF]; /* RAM not evaluated */
  1397. timer_setup(&cs->hw.hfcsx.timer, hfcsx_Timer, 0);
  1398. reset_hfcsx(cs);
  1399. cs->cardmsg = &hfcsx_card_msg;
  1400. cs->auxcmd = &hfcsx_auxcmd;
  1401. return (1);
  1402. }