hfc_pci.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757
  1. /* $Id: hfc_pci.c,v 1.48.2.4 2004/02/11 13:21:33 keil Exp $
  2. *
  3. * low level driver for CCD's hfc-pci based cards
  4. *
  5. * Author Werner Cornelius
  6. * based on existing driver for CCD hfc ISA cards
  7. * Copyright by Werner Cornelius <werner@isdn4linux.de>
  8. * by Karsten Keil <keil@isdn4linux.de>
  9. *
  10. * This software may be used and distributed according to the terms
  11. * of the GNU General Public License, incorporated herein by reference.
  12. *
  13. * For changes and modifications please read
  14. * Documentation/isdn/HiSax.cert
  15. *
  16. */
  17. #include <linux/init.h>
  18. #include "hisax.h"
  19. #include "hfc_pci.h"
  20. #include "isdnl1.h"
  21. #include <linux/pci.h>
  22. #include <linux/sched.h>
  23. #include <linux/interrupt.h>
  24. static const char *hfcpci_revision = "$Revision: 1.48.2.4 $";
  25. /* table entry in the PCI devices list */
  26. typedef struct {
  27. int vendor_id;
  28. int device_id;
  29. char *vendor_name;
  30. char *card_name;
  31. } PCI_ENTRY;
  32. #define NT_T1_COUNT 20 /* number of 3.125ms interrupts for G2 timeout */
  33. #define CLKDEL_TE 0x0e /* CLKDEL in TE mode */
  34. #define CLKDEL_NT 0x6c /* CLKDEL in NT mode */
  35. static const PCI_ENTRY id_list[] =
  36. {
  37. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0, "CCD/Billion/Asuscom", "2BD0"},
  38. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000, "Billion", "B000"},
  39. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006, "Billion", "B006"},
  40. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007, "Billion", "B007"},
  41. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008, "Billion", "B008"},
  42. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009, "Billion", "B009"},
  43. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A, "Billion", "B00A"},
  44. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B, "Billion", "B00B"},
  45. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C, "Billion", "B00C"},
  46. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100, "Seyeon", "B100"},
  47. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B700, "Primux II S0", "B700"},
  48. {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B701, "Primux II S0 NT", "B701"},
  49. {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1, "Abocom/Magitek", "2BD1"},
  50. {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675, "Asuscom/Askey", "675"},
  51. {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT, "German telekom", "T-Concept"},
  52. {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T, "German telekom", "A1T"},
  53. {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575, "Motorola MC145575", "MC145575"},
  54. {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0, "Zoltrix", "2BD0"},
  55. {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E, "Digi International", "Digi DataFire Micro V IOM2 (Europe)"},
  56. {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E, "Digi International", "Digi DataFire Micro V (Europe)"},
  57. {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A, "Digi International", "Digi DataFire Micro V IOM2 (North America)"},
  58. {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A, "Digi International", "Digi DataFire Micro V (North America)"},
  59. {PCI_VENDOR_ID_SITECOM, PCI_DEVICE_ID_SITECOM_DC105V2, "Sitecom Europe", "DC-105 ISDN PCI"},
  60. {0, 0, NULL, NULL},
  61. };
  62. /******************************************/
  63. /* free hardware resources used by driver */
  64. /******************************************/
  65. static void
  66. release_io_hfcpci(struct IsdnCardState *cs)
  67. {
  68. printk(KERN_INFO "HiSax: release hfcpci at %p\n",
  69. cs->hw.hfcpci.pci_io);
  70. cs->hw.hfcpci.int_m2 = 0; /* interrupt output off ! */
  71. Write_hfc(cs, HFCPCI_INT_M2, cs->hw.hfcpci.int_m2);
  72. Write_hfc(cs, HFCPCI_CIRM, HFCPCI_RESET); /* Reset On */
  73. mdelay(10);
  74. Write_hfc(cs, HFCPCI_CIRM, 0); /* Reset Off */
  75. mdelay(10);
  76. Write_hfc(cs, HFCPCI_INT_M2, cs->hw.hfcpci.int_m2);
  77. pci_write_config_word(cs->hw.hfcpci.dev, PCI_COMMAND, 0); /* disable memory mapped ports + busmaster */
  78. del_timer(&cs->hw.hfcpci.timer);
  79. pci_free_consistent(cs->hw.hfcpci.dev, 0x8000,
  80. cs->hw.hfcpci.fifos, cs->hw.hfcpci.dma);
  81. cs->hw.hfcpci.fifos = NULL;
  82. iounmap((void *)cs->hw.hfcpci.pci_io);
  83. }
  84. /********************************************************************************/
  85. /* function called to reset the HFC PCI chip. A complete software reset of chip */
  86. /* and fifos is done. */
  87. /********************************************************************************/
  88. static void
  89. reset_hfcpci(struct IsdnCardState *cs)
  90. {
  91. pci_write_config_word(cs->hw.hfcpci.dev, PCI_COMMAND, PCI_ENA_MEMIO); /* enable memory mapped ports, disable busmaster */
  92. cs->hw.hfcpci.int_m2 = 0; /* interrupt output off ! */
  93. Write_hfc(cs, HFCPCI_INT_M2, cs->hw.hfcpci.int_m2);
  94. printk(KERN_INFO "HFC_PCI: resetting card\n");
  95. pci_write_config_word(cs->hw.hfcpci.dev, PCI_COMMAND, PCI_ENA_MEMIO + PCI_ENA_MASTER); /* enable memory ports + busmaster */
  96. Write_hfc(cs, HFCPCI_CIRM, HFCPCI_RESET); /* Reset On */
  97. mdelay(10);
  98. Write_hfc(cs, HFCPCI_CIRM, 0); /* Reset Off */
  99. mdelay(10);
  100. if (Read_hfc(cs, HFCPCI_STATUS) & 2)
  101. printk(KERN_WARNING "HFC-PCI init bit busy\n");
  102. cs->hw.hfcpci.fifo_en = 0x30; /* only D fifos enabled */
  103. Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
  104. cs->hw.hfcpci.trm = 0 + HFCPCI_BTRANS_THRESMASK; /* no echo connect , threshold */
  105. Write_hfc(cs, HFCPCI_TRM, cs->hw.hfcpci.trm);
  106. Write_hfc(cs, HFCPCI_CLKDEL, CLKDEL_TE); /* ST-Bit delay for TE-Mode */
  107. cs->hw.hfcpci.sctrl_e = HFCPCI_AUTO_AWAKE;
  108. Write_hfc(cs, HFCPCI_SCTRL_E, cs->hw.hfcpci.sctrl_e); /* S/T Auto awake */
  109. cs->hw.hfcpci.bswapped = 0; /* no exchange */
  110. cs->hw.hfcpci.nt_mode = 0; /* we are in TE mode */
  111. cs->hw.hfcpci.ctmt = HFCPCI_TIM3_125 | HFCPCI_AUTO_TIMER;
  112. Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt);
  113. cs->hw.hfcpci.int_m1 = HFCPCI_INTS_DTRANS | HFCPCI_INTS_DREC |
  114. HFCPCI_INTS_L1STATE | HFCPCI_INTS_TIMER;
  115. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  116. /* Clear already pending ints */
  117. if (Read_hfc(cs, HFCPCI_INT_S1));
  118. Write_hfc(cs, HFCPCI_STATES, HFCPCI_LOAD_STATE | 2); /* HFC ST 2 */
  119. udelay(10);
  120. Write_hfc(cs, HFCPCI_STATES, 2); /* HFC ST 2 */
  121. cs->hw.hfcpci.mst_m = HFCPCI_MASTER; /* HFC Master Mode */
  122. Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
  123. cs->hw.hfcpci.sctrl = 0x40; /* set tx_lo mode, error in datasheet ! */
  124. Write_hfc(cs, HFCPCI_SCTRL, cs->hw.hfcpci.sctrl);
  125. cs->hw.hfcpci.sctrl_r = 0;
  126. Write_hfc(cs, HFCPCI_SCTRL_R, cs->hw.hfcpci.sctrl_r);
  127. /* Init GCI/IOM2 in master mode */
  128. /* Slots 0 and 1 are set for B-chan 1 and 2 */
  129. /* D- and monitor/CI channel are not enabled */
  130. /* STIO1 is used as output for data, B1+B2 from ST->IOM+HFC */
  131. /* STIO2 is used as data input, B1+B2 from IOM->ST */
  132. /* ST B-channel send disabled -> continuous 1s */
  133. /* The IOM slots are always enabled */
  134. cs->hw.hfcpci.conn = 0x36; /* set data flow directions */
  135. Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
  136. Write_hfc(cs, HFCPCI_B1_SSL, 0x80); /* B1-Slot 0 STIO1 out enabled */
  137. Write_hfc(cs, HFCPCI_B2_SSL, 0x81); /* B2-Slot 1 STIO1 out enabled */
  138. Write_hfc(cs, HFCPCI_B1_RSL, 0x80); /* B1-Slot 0 STIO2 in enabled */
  139. Write_hfc(cs, HFCPCI_B2_RSL, 0x81); /* B2-Slot 1 STIO2 in enabled */
  140. /* Finally enable IRQ output */
  141. cs->hw.hfcpci.int_m2 = HFCPCI_IRQ_ENABLE;
  142. Write_hfc(cs, HFCPCI_INT_M2, cs->hw.hfcpci.int_m2);
  143. if (Read_hfc(cs, HFCPCI_INT_S1));
  144. }
  145. /***************************************************/
  146. /* Timer function called when kernel timer expires */
  147. /***************************************************/
  148. static void
  149. hfcpci_Timer(struct IsdnCardState *cs)
  150. {
  151. cs->hw.hfcpci.timer.expires = jiffies + 75;
  152. /* WD RESET */
  153. /* WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcpci.ctmt | 0x80);
  154. add_timer(&cs->hw.hfcpci.timer);
  155. */
  156. }
  157. /*********************************/
  158. /* schedule a new D-channel task */
  159. /*********************************/
  160. static void
  161. sched_event_D_pci(struct IsdnCardState *cs, int event)
  162. {
  163. test_and_set_bit(event, &cs->event);
  164. schedule_work(&cs->tqueue);
  165. }
  166. /*********************************/
  167. /* schedule a new b_channel task */
  168. /*********************************/
  169. static void
  170. hfcpci_sched_event(struct BCState *bcs, int event)
  171. {
  172. test_and_set_bit(event, &bcs->event);
  173. schedule_work(&bcs->tqueue);
  174. }
  175. /************************************************/
  176. /* select a b-channel entry matching and active */
  177. /************************************************/
  178. static
  179. struct BCState *
  180. Sel_BCS(struct IsdnCardState *cs, int channel)
  181. {
  182. if (cs->bcs[0].mode && (cs->bcs[0].channel == channel))
  183. return (&cs->bcs[0]);
  184. else if (cs->bcs[1].mode && (cs->bcs[1].channel == channel))
  185. return (&cs->bcs[1]);
  186. else
  187. return (NULL);
  188. }
  189. /***************************************/
  190. /* clear the desired B-channel rx fifo */
  191. /***************************************/
  192. static void hfcpci_clear_fifo_rx(struct IsdnCardState *cs, int fifo)
  193. { u_char fifo_state;
  194. bzfifo_type *bzr;
  195. if (fifo) {
  196. bzr = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b2;
  197. fifo_state = cs->hw.hfcpci.fifo_en & HFCPCI_FIFOEN_B2RX;
  198. } else {
  199. bzr = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b1;
  200. fifo_state = cs->hw.hfcpci.fifo_en & HFCPCI_FIFOEN_B1RX;
  201. }
  202. if (fifo_state)
  203. cs->hw.hfcpci.fifo_en ^= fifo_state;
  204. Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
  205. cs->hw.hfcpci.last_bfifo_cnt[fifo] = 0;
  206. bzr->za[MAX_B_FRAMES].z1 = B_FIFO_SIZE + B_SUB_VAL - 1;
  207. bzr->za[MAX_B_FRAMES].z2 = bzr->za[MAX_B_FRAMES].z1;
  208. bzr->f1 = MAX_B_FRAMES;
  209. bzr->f2 = bzr->f1; /* init F pointers to remain constant */
  210. if (fifo_state)
  211. cs->hw.hfcpci.fifo_en |= fifo_state;
  212. Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
  213. }
  214. /***************************************/
  215. /* clear the desired B-channel tx fifo */
  216. /***************************************/
  217. static void hfcpci_clear_fifo_tx(struct IsdnCardState *cs, int fifo)
  218. { u_char fifo_state;
  219. bzfifo_type *bzt;
  220. if (fifo) {
  221. bzt = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txbz_b2;
  222. fifo_state = cs->hw.hfcpci.fifo_en & HFCPCI_FIFOEN_B2TX;
  223. } else {
  224. bzt = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txbz_b1;
  225. fifo_state = cs->hw.hfcpci.fifo_en & HFCPCI_FIFOEN_B1TX;
  226. }
  227. if (fifo_state)
  228. cs->hw.hfcpci.fifo_en ^= fifo_state;
  229. Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
  230. bzt->za[MAX_B_FRAMES].z1 = B_FIFO_SIZE + B_SUB_VAL - 1;
  231. bzt->za[MAX_B_FRAMES].z2 = bzt->za[MAX_B_FRAMES].z1;
  232. bzt->f1 = MAX_B_FRAMES;
  233. bzt->f2 = bzt->f1; /* init F pointers to remain constant */
  234. if (fifo_state)
  235. cs->hw.hfcpci.fifo_en |= fifo_state;
  236. Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
  237. }
  238. /*********************************************/
  239. /* read a complete B-frame out of the buffer */
  240. /*********************************************/
  241. static struct sk_buff
  242. *
  243. hfcpci_empty_fifo(struct BCState *bcs, bzfifo_type *bz, u_char *bdata, int count)
  244. {
  245. u_char *ptr, *ptr1, new_f2;
  246. struct sk_buff *skb;
  247. struct IsdnCardState *cs = bcs->cs;
  248. int total, maxlen, new_z2;
  249. z_type *zp;
  250. if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
  251. debugl1(cs, "hfcpci_empty_fifo");
  252. zp = &bz->za[bz->f2]; /* point to Z-Regs */
  253. new_z2 = zp->z2 + count; /* new position in fifo */
  254. if (new_z2 >= (B_FIFO_SIZE + B_SUB_VAL))
  255. new_z2 -= B_FIFO_SIZE; /* buffer wrap */
  256. new_f2 = (bz->f2 + 1) & MAX_B_FRAMES;
  257. if ((count > HSCX_BUFMAX + 3) || (count < 4) ||
  258. (*(bdata + (zp->z1 - B_SUB_VAL)))) {
  259. if (cs->debug & L1_DEB_WARN)
  260. debugl1(cs, "hfcpci_empty_fifo: incoming packet invalid length %d or crc", count);
  261. #ifdef ERROR_STATISTIC
  262. bcs->err_inv++;
  263. #endif
  264. bz->za[new_f2].z2 = new_z2;
  265. bz->f2 = new_f2; /* next buffer */
  266. skb = NULL;
  267. } else if (!(skb = dev_alloc_skb(count - 3)))
  268. printk(KERN_WARNING "HFCPCI: receive out of memory\n");
  269. else {
  270. total = count;
  271. count -= 3;
  272. ptr = skb_put(skb, count);
  273. if (zp->z2 + count <= B_FIFO_SIZE + B_SUB_VAL)
  274. maxlen = count; /* complete transfer */
  275. else
  276. maxlen = B_FIFO_SIZE + B_SUB_VAL - zp->z2; /* maximum */
  277. ptr1 = bdata + (zp->z2 - B_SUB_VAL); /* start of data */
  278. memcpy(ptr, ptr1, maxlen); /* copy data */
  279. count -= maxlen;
  280. if (count) { /* rest remaining */
  281. ptr += maxlen;
  282. ptr1 = bdata; /* start of buffer */
  283. memcpy(ptr, ptr1, count); /* rest */
  284. }
  285. bz->za[new_f2].z2 = new_z2;
  286. bz->f2 = new_f2; /* next buffer */
  287. }
  288. return (skb);
  289. }
  290. /*******************************/
  291. /* D-channel receive procedure */
  292. /*******************************/
  293. static
  294. int
  295. receive_dmsg(struct IsdnCardState *cs)
  296. {
  297. struct sk_buff *skb;
  298. int maxlen;
  299. int rcnt, total;
  300. int count = 5;
  301. u_char *ptr, *ptr1;
  302. dfifo_type *df;
  303. z_type *zp;
  304. df = &((fifo_area *) (cs->hw.hfcpci.fifos))->d_chan.d_rx;
  305. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  306. debugl1(cs, "rec_dmsg blocked");
  307. return (1);
  308. }
  309. while (((df->f1 & D_FREG_MASK) != (df->f2 & D_FREG_MASK)) && count--) {
  310. zp = &df->za[df->f2 & D_FREG_MASK];
  311. rcnt = zp->z1 - zp->z2;
  312. if (rcnt < 0)
  313. rcnt += D_FIFO_SIZE;
  314. rcnt++;
  315. if (cs->debug & L1_DEB_ISAC)
  316. debugl1(cs, "hfcpci recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)",
  317. df->f1, df->f2, zp->z1, zp->z2, rcnt);
  318. if ((rcnt > MAX_DFRAME_LEN + 3) || (rcnt < 4) ||
  319. (df->data[zp->z1])) {
  320. if (cs->debug & L1_DEB_WARN)
  321. debugl1(cs, "empty_fifo hfcpci packet inv. len %d or crc %d", rcnt, df->data[zp->z1]);
  322. #ifdef ERROR_STATISTIC
  323. cs->err_rx++;
  324. #endif
  325. df->f2 = ((df->f2 + 1) & MAX_D_FRAMES) | (MAX_D_FRAMES + 1); /* next buffer */
  326. df->za[df->f2 & D_FREG_MASK].z2 = (zp->z2 + rcnt) & (D_FIFO_SIZE - 1);
  327. } else if ((skb = dev_alloc_skb(rcnt - 3))) {
  328. total = rcnt;
  329. rcnt -= 3;
  330. ptr = skb_put(skb, rcnt);
  331. if (zp->z2 + rcnt <= D_FIFO_SIZE)
  332. maxlen = rcnt; /* complete transfer */
  333. else
  334. maxlen = D_FIFO_SIZE - zp->z2; /* maximum */
  335. ptr1 = df->data + zp->z2; /* start of data */
  336. memcpy(ptr, ptr1, maxlen); /* copy data */
  337. rcnt -= maxlen;
  338. if (rcnt) { /* rest remaining */
  339. ptr += maxlen;
  340. ptr1 = df->data; /* start of buffer */
  341. memcpy(ptr, ptr1, rcnt); /* rest */
  342. }
  343. df->f2 = ((df->f2 + 1) & MAX_D_FRAMES) | (MAX_D_FRAMES + 1); /* next buffer */
  344. df->za[df->f2 & D_FREG_MASK].z2 = (zp->z2 + total) & (D_FIFO_SIZE - 1);
  345. skb_queue_tail(&cs->rq, skb);
  346. sched_event_D_pci(cs, D_RCVBUFREADY);
  347. } else
  348. printk(KERN_WARNING "HFC-PCI: D receive out of memory\n");
  349. }
  350. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  351. return (1);
  352. }
  353. /*******************************************************************************/
  354. /* check for transparent receive data and read max one threshold size if avail */
  355. /*******************************************************************************/
  356. static int
  357. hfcpci_empty_fifo_trans(struct BCState *bcs, bzfifo_type *bz, u_char *bdata)
  358. {
  359. unsigned short *z1r, *z2r;
  360. int new_z2, fcnt, maxlen;
  361. struct sk_buff *skb;
  362. u_char *ptr, *ptr1;
  363. z1r = &bz->za[MAX_B_FRAMES].z1; /* pointer to z reg */
  364. z2r = z1r + 1;
  365. if (!(fcnt = *z1r - *z2r))
  366. return (0); /* no data avail */
  367. if (fcnt <= 0)
  368. fcnt += B_FIFO_SIZE; /* bytes actually buffered */
  369. if (fcnt > HFCPCI_BTRANS_THRESHOLD)
  370. fcnt = HFCPCI_BTRANS_THRESHOLD; /* limit size */
  371. new_z2 = *z2r + fcnt; /* new position in fifo */
  372. if (new_z2 >= (B_FIFO_SIZE + B_SUB_VAL))
  373. new_z2 -= B_FIFO_SIZE; /* buffer wrap */
  374. if (!(skb = dev_alloc_skb(fcnt)))
  375. printk(KERN_WARNING "HFCPCI: receive out of memory\n");
  376. else {
  377. ptr = skb_put(skb, fcnt);
  378. if (*z2r + fcnt <= B_FIFO_SIZE + B_SUB_VAL)
  379. maxlen = fcnt; /* complete transfer */
  380. else
  381. maxlen = B_FIFO_SIZE + B_SUB_VAL - *z2r; /* maximum */
  382. ptr1 = bdata + (*z2r - B_SUB_VAL); /* start of data */
  383. memcpy(ptr, ptr1, maxlen); /* copy data */
  384. fcnt -= maxlen;
  385. if (fcnt) { /* rest remaining */
  386. ptr += maxlen;
  387. ptr1 = bdata; /* start of buffer */
  388. memcpy(ptr, ptr1, fcnt); /* rest */
  389. }
  390. skb_queue_tail(&bcs->rqueue, skb);
  391. hfcpci_sched_event(bcs, B_RCVBUFREADY);
  392. }
  393. *z2r = new_z2; /* new position */
  394. return (1);
  395. } /* hfcpci_empty_fifo_trans */
  396. /**********************************/
  397. /* B-channel main receive routine */
  398. /**********************************/
  399. static void
  400. main_rec_hfcpci(struct BCState *bcs)
  401. {
  402. struct IsdnCardState *cs = bcs->cs;
  403. int rcnt, real_fifo;
  404. int receive, count = 5;
  405. struct sk_buff *skb;
  406. bzfifo_type *bz;
  407. u_char *bdata;
  408. z_type *zp;
  409. if ((bcs->channel) && (!cs->hw.hfcpci.bswapped)) {
  410. bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b2;
  411. bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxdat_b2;
  412. real_fifo = 1;
  413. } else {
  414. bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b1;
  415. bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxdat_b1;
  416. real_fifo = 0;
  417. }
  418. Begin:
  419. count--;
  420. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  421. debugl1(cs, "rec_data %d blocked", bcs->channel);
  422. return;
  423. }
  424. if (bz->f1 != bz->f2) {
  425. if (cs->debug & L1_DEB_HSCX)
  426. debugl1(cs, "hfcpci rec %d f1(%d) f2(%d)",
  427. bcs->channel, bz->f1, bz->f2);
  428. zp = &bz->za[bz->f2];
  429. rcnt = zp->z1 - zp->z2;
  430. if (rcnt < 0)
  431. rcnt += B_FIFO_SIZE;
  432. rcnt++;
  433. if (cs->debug & L1_DEB_HSCX)
  434. debugl1(cs, "hfcpci rec %d z1(%x) z2(%x) cnt(%d)",
  435. bcs->channel, zp->z1, zp->z2, rcnt);
  436. if ((skb = hfcpci_empty_fifo(bcs, bz, bdata, rcnt))) {
  437. skb_queue_tail(&bcs->rqueue, skb);
  438. hfcpci_sched_event(bcs, B_RCVBUFREADY);
  439. }
  440. rcnt = bz->f1 - bz->f2;
  441. if (rcnt < 0)
  442. rcnt += MAX_B_FRAMES + 1;
  443. if (cs->hw.hfcpci.last_bfifo_cnt[real_fifo] > rcnt + 1) {
  444. rcnt = 0;
  445. hfcpci_clear_fifo_rx(cs, real_fifo);
  446. }
  447. cs->hw.hfcpci.last_bfifo_cnt[real_fifo] = rcnt;
  448. if (rcnt > 1)
  449. receive = 1;
  450. else
  451. receive = 0;
  452. } else if (bcs->mode == L1_MODE_TRANS)
  453. receive = hfcpci_empty_fifo_trans(bcs, bz, bdata);
  454. else
  455. receive = 0;
  456. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  457. if (count && receive)
  458. goto Begin;
  459. }
  460. /**************************/
  461. /* D-channel send routine */
  462. /**************************/
  463. static void
  464. hfcpci_fill_dfifo(struct IsdnCardState *cs)
  465. {
  466. int fcnt;
  467. int count, new_z1, maxlen;
  468. dfifo_type *df;
  469. u_char *src, *dst, new_f1;
  470. if (!cs->tx_skb)
  471. return;
  472. if (cs->tx_skb->len <= 0)
  473. return;
  474. df = &((fifo_area *) (cs->hw.hfcpci.fifos))->d_chan.d_tx;
  475. if (cs->debug & L1_DEB_ISAC)
  476. debugl1(cs, "hfcpci_fill_Dfifo f1(%d) f2(%d) z1(f1)(%x)",
  477. df->f1, df->f2,
  478. df->za[df->f1 & D_FREG_MASK].z1);
  479. fcnt = df->f1 - df->f2; /* frame count actually buffered */
  480. if (fcnt < 0)
  481. fcnt += (MAX_D_FRAMES + 1); /* if wrap around */
  482. if (fcnt > (MAX_D_FRAMES - 1)) {
  483. if (cs->debug & L1_DEB_ISAC)
  484. debugl1(cs, "hfcpci_fill_Dfifo more as 14 frames");
  485. #ifdef ERROR_STATISTIC
  486. cs->err_tx++;
  487. #endif
  488. return;
  489. }
  490. /* now determine free bytes in FIFO buffer */
  491. count = df->za[df->f2 & D_FREG_MASK].z2 - df->za[df->f1 & D_FREG_MASK].z1 - 1;
  492. if (count <= 0)
  493. count += D_FIFO_SIZE; /* count now contains available bytes */
  494. if (cs->debug & L1_DEB_ISAC)
  495. debugl1(cs, "hfcpci_fill_Dfifo count(%u/%d)",
  496. cs->tx_skb->len, count);
  497. if (count < cs->tx_skb->len) {
  498. if (cs->debug & L1_DEB_ISAC)
  499. debugl1(cs, "hfcpci_fill_Dfifo no fifo mem");
  500. return;
  501. }
  502. count = cs->tx_skb->len; /* get frame len */
  503. new_z1 = (df->za[df->f1 & D_FREG_MASK].z1 + count) & (D_FIFO_SIZE - 1);
  504. new_f1 = ((df->f1 + 1) & D_FREG_MASK) | (D_FREG_MASK + 1);
  505. src = cs->tx_skb->data; /* source pointer */
  506. dst = df->data + df->za[df->f1 & D_FREG_MASK].z1;
  507. maxlen = D_FIFO_SIZE - df->za[df->f1 & D_FREG_MASK].z1; /* end fifo */
  508. if (maxlen > count)
  509. maxlen = count; /* limit size */
  510. memcpy(dst, src, maxlen); /* first copy */
  511. count -= maxlen; /* remaining bytes */
  512. if (count) {
  513. dst = df->data; /* start of buffer */
  514. src += maxlen; /* new position */
  515. memcpy(dst, src, count);
  516. }
  517. df->za[new_f1 & D_FREG_MASK].z1 = new_z1; /* for next buffer */
  518. df->za[df->f1 & D_FREG_MASK].z1 = new_z1; /* new pos actual buffer */
  519. df->f1 = new_f1; /* next frame */
  520. dev_kfree_skb_any(cs->tx_skb);
  521. cs->tx_skb = NULL;
  522. }
  523. /**************************/
  524. /* B-channel send routine */
  525. /**************************/
  526. static void
  527. hfcpci_fill_fifo(struct BCState *bcs)
  528. {
  529. struct IsdnCardState *cs = bcs->cs;
  530. int maxlen, fcnt;
  531. int count, new_z1;
  532. bzfifo_type *bz;
  533. u_char *bdata;
  534. u_char new_f1, *src, *dst;
  535. unsigned short *z1t, *z2t;
  536. if (!bcs->tx_skb)
  537. return;
  538. if (bcs->tx_skb->len <= 0)
  539. return;
  540. if ((bcs->channel) && (!cs->hw.hfcpci.bswapped)) {
  541. bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txbz_b2;
  542. bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txdat_b2;
  543. } else {
  544. bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txbz_b1;
  545. bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.txdat_b1;
  546. }
  547. if (bcs->mode == L1_MODE_TRANS) {
  548. z1t = &bz->za[MAX_B_FRAMES].z1;
  549. z2t = z1t + 1;
  550. if (cs->debug & L1_DEB_HSCX)
  551. debugl1(cs, "hfcpci_fill_fifo_trans %d z1(%x) z2(%x)",
  552. bcs->channel, *z1t, *z2t);
  553. fcnt = *z2t - *z1t;
  554. if (fcnt <= 0)
  555. fcnt += B_FIFO_SIZE; /* fcnt contains available bytes in fifo */
  556. fcnt = B_FIFO_SIZE - fcnt; /* remaining bytes to send */
  557. while ((fcnt < 2 * HFCPCI_BTRANS_THRESHOLD) && (bcs->tx_skb)) {
  558. if (bcs->tx_skb->len < B_FIFO_SIZE - fcnt) {
  559. /* data is suitable for fifo */
  560. count = bcs->tx_skb->len;
  561. new_z1 = *z1t + count; /* new buffer Position */
  562. if (new_z1 >= (B_FIFO_SIZE + B_SUB_VAL))
  563. new_z1 -= B_FIFO_SIZE; /* buffer wrap */
  564. src = bcs->tx_skb->data; /* source pointer */
  565. dst = bdata + (*z1t - B_SUB_VAL);
  566. maxlen = (B_FIFO_SIZE + B_SUB_VAL) - *z1t; /* end of fifo */
  567. if (maxlen > count)
  568. maxlen = count; /* limit size */
  569. memcpy(dst, src, maxlen); /* first copy */
  570. count -= maxlen; /* remaining bytes */
  571. if (count) {
  572. dst = bdata; /* start of buffer */
  573. src += maxlen; /* new position */
  574. memcpy(dst, src, count);
  575. }
  576. bcs->tx_cnt -= bcs->tx_skb->len;
  577. fcnt += bcs->tx_skb->len;
  578. *z1t = new_z1; /* now send data */
  579. } else if (cs->debug & L1_DEB_HSCX)
  580. debugl1(cs, "hfcpci_fill_fifo_trans %d frame length %d discarded",
  581. bcs->channel, bcs->tx_skb->len);
  582. if (test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
  583. (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
  584. u_long flags;
  585. spin_lock_irqsave(&bcs->aclock, flags);
  586. bcs->ackcnt += bcs->tx_skb->len;
  587. spin_unlock_irqrestore(&bcs->aclock, flags);
  588. schedule_event(bcs, B_ACKPENDING);
  589. }
  590. dev_kfree_skb_any(bcs->tx_skb);
  591. bcs->tx_skb = skb_dequeue(&bcs->squeue); /* fetch next data */
  592. }
  593. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  594. return;
  595. }
  596. if (cs->debug & L1_DEB_HSCX)
  597. debugl1(cs, "hfcpci_fill_fifo_hdlc %d f1(%d) f2(%d) z1(f1)(%x)",
  598. bcs->channel, bz->f1, bz->f2,
  599. bz->za[bz->f1].z1);
  600. fcnt = bz->f1 - bz->f2; /* frame count actually buffered */
  601. if (fcnt < 0)
  602. fcnt += (MAX_B_FRAMES + 1); /* if wrap around */
  603. if (fcnt > (MAX_B_FRAMES - 1)) {
  604. if (cs->debug & L1_DEB_HSCX)
  605. debugl1(cs, "hfcpci_fill_Bfifo more as 14 frames");
  606. return;
  607. }
  608. /* now determine free bytes in FIFO buffer */
  609. count = bz->za[bz->f2].z2 - bz->za[bz->f1].z1 - 1;
  610. if (count <= 0)
  611. count += B_FIFO_SIZE; /* count now contains available bytes */
  612. if (cs->debug & L1_DEB_HSCX)
  613. debugl1(cs, "hfcpci_fill_fifo %d count(%u/%d),%lx",
  614. bcs->channel, bcs->tx_skb->len,
  615. count, current->state);
  616. if (count < bcs->tx_skb->len) {
  617. if (cs->debug & L1_DEB_HSCX)
  618. debugl1(cs, "hfcpci_fill_fifo no fifo mem");
  619. return;
  620. }
  621. count = bcs->tx_skb->len; /* get frame len */
  622. new_z1 = bz->za[bz->f1].z1 + count; /* new buffer Position */
  623. if (new_z1 >= (B_FIFO_SIZE + B_SUB_VAL))
  624. new_z1 -= B_FIFO_SIZE; /* buffer wrap */
  625. new_f1 = ((bz->f1 + 1) & MAX_B_FRAMES);
  626. src = bcs->tx_skb->data; /* source pointer */
  627. dst = bdata + (bz->za[bz->f1].z1 - B_SUB_VAL);
  628. maxlen = (B_FIFO_SIZE + B_SUB_VAL) - bz->za[bz->f1].z1; /* end fifo */
  629. if (maxlen > count)
  630. maxlen = count; /* limit size */
  631. memcpy(dst, src, maxlen); /* first copy */
  632. count -= maxlen; /* remaining bytes */
  633. if (count) {
  634. dst = bdata; /* start of buffer */
  635. src += maxlen; /* new position */
  636. memcpy(dst, src, count);
  637. }
  638. bcs->tx_cnt -= bcs->tx_skb->len;
  639. if (test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
  640. (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
  641. u_long flags;
  642. spin_lock_irqsave(&bcs->aclock, flags);
  643. bcs->ackcnt += bcs->tx_skb->len;
  644. spin_unlock_irqrestore(&bcs->aclock, flags);
  645. schedule_event(bcs, B_ACKPENDING);
  646. }
  647. bz->za[new_f1].z1 = new_z1; /* for next buffer */
  648. bz->f1 = new_f1; /* next frame */
  649. dev_kfree_skb_any(bcs->tx_skb);
  650. bcs->tx_skb = NULL;
  651. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  652. }
  653. /**********************************************/
  654. /* D-channel l1 state call for leased NT-mode */
  655. /**********************************************/
  656. static void
  657. dch_nt_l2l1(struct PStack *st, int pr, void *arg)
  658. {
  659. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  660. switch (pr) {
  661. case (PH_DATA | REQUEST):
  662. case (PH_PULL | REQUEST):
  663. case (PH_PULL | INDICATION):
  664. st->l1.l1hw(st, pr, arg);
  665. break;
  666. case (PH_ACTIVATE | REQUEST):
  667. st->l1.l1l2(st, PH_ACTIVATE | CONFIRM, NULL);
  668. break;
  669. case (PH_TESTLOOP | REQUEST):
  670. if (1 & (long) arg)
  671. debugl1(cs, "PH_TEST_LOOP B1");
  672. if (2 & (long) arg)
  673. debugl1(cs, "PH_TEST_LOOP B2");
  674. if (!(3 & (long) arg))
  675. debugl1(cs, "PH_TEST_LOOP DISABLED");
  676. st->l1.l1hw(st, HW_TESTLOOP | REQUEST, arg);
  677. break;
  678. default:
  679. if (cs->debug)
  680. debugl1(cs, "dch_nt_l2l1 msg %04X unhandled", pr);
  681. break;
  682. }
  683. }
  684. /***********************/
  685. /* set/reset echo mode */
  686. /***********************/
  687. static int
  688. hfcpci_auxcmd(struct IsdnCardState *cs, isdn_ctrl *ic)
  689. {
  690. u_long flags;
  691. int i = *(unsigned int *) ic->parm.num;
  692. if ((ic->arg == 98) &&
  693. (!(cs->hw.hfcpci.int_m1 & (HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC + HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC)))) {
  694. spin_lock_irqsave(&cs->lock, flags);
  695. Write_hfc(cs, HFCPCI_CLKDEL, CLKDEL_NT); /* ST-Bit delay for NT-Mode */
  696. Write_hfc(cs, HFCPCI_STATES, HFCPCI_LOAD_STATE | 0); /* HFC ST G0 */
  697. udelay(10);
  698. cs->hw.hfcpci.sctrl |= SCTRL_MODE_NT;
  699. Write_hfc(cs, HFCPCI_SCTRL, cs->hw.hfcpci.sctrl); /* set NT-mode */
  700. udelay(10);
  701. Write_hfc(cs, HFCPCI_STATES, HFCPCI_LOAD_STATE | 1); /* HFC ST G1 */
  702. udelay(10);
  703. Write_hfc(cs, HFCPCI_STATES, 1 | HFCPCI_ACTIVATE | HFCPCI_DO_ACTION);
  704. cs->dc.hfcpci.ph_state = 1;
  705. cs->hw.hfcpci.nt_mode = 1;
  706. cs->hw.hfcpci.nt_timer = 0;
  707. cs->stlist->l2.l2l1 = dch_nt_l2l1;
  708. spin_unlock_irqrestore(&cs->lock, flags);
  709. debugl1(cs, "NT mode activated");
  710. return (0);
  711. }
  712. if ((cs->chanlimit > 1) || (cs->hw.hfcpci.bswapped) ||
  713. (cs->hw.hfcpci.nt_mode) || (ic->arg != 12))
  714. return (-EINVAL);
  715. spin_lock_irqsave(&cs->lock, flags);
  716. if (i) {
  717. cs->logecho = 1;
  718. cs->hw.hfcpci.trm |= 0x20; /* enable echo chan */
  719. cs->hw.hfcpci.int_m1 |= HFCPCI_INTS_B2REC;
  720. cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B2RX;
  721. } else {
  722. cs->logecho = 0;
  723. cs->hw.hfcpci.trm &= ~0x20; /* disable echo chan */
  724. cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_B2REC;
  725. cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B2RX;
  726. }
  727. cs->hw.hfcpci.sctrl_r &= ~SCTRL_B2_ENA;
  728. cs->hw.hfcpci.sctrl &= ~SCTRL_B2_ENA;
  729. cs->hw.hfcpci.conn |= 0x10; /* B2-IOM -> B2-ST */
  730. cs->hw.hfcpci.ctmt &= ~2;
  731. Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt);
  732. Write_hfc(cs, HFCPCI_SCTRL_R, cs->hw.hfcpci.sctrl_r);
  733. Write_hfc(cs, HFCPCI_SCTRL, cs->hw.hfcpci.sctrl);
  734. Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
  735. Write_hfc(cs, HFCPCI_TRM, cs->hw.hfcpci.trm);
  736. Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
  737. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  738. spin_unlock_irqrestore(&cs->lock, flags);
  739. return (0);
  740. } /* hfcpci_auxcmd */
  741. /*****************************/
  742. /* E-channel receive routine */
  743. /*****************************/
  744. static void
  745. receive_emsg(struct IsdnCardState *cs)
  746. {
  747. int rcnt;
  748. int receive, count = 5;
  749. bzfifo_type *bz;
  750. u_char *bdata;
  751. z_type *zp;
  752. u_char *ptr, *ptr1, new_f2;
  753. int total, maxlen, new_z2;
  754. u_char e_buffer[256];
  755. bz = &((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxbz_b2;
  756. bdata = ((fifo_area *) (cs->hw.hfcpci.fifos))->b_chans.rxdat_b2;
  757. Begin:
  758. count--;
  759. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  760. debugl1(cs, "echo_rec_data blocked");
  761. return;
  762. }
  763. if (bz->f1 != bz->f2) {
  764. if (cs->debug & L1_DEB_ISAC)
  765. debugl1(cs, "hfcpci e_rec f1(%d) f2(%d)",
  766. bz->f1, bz->f2);
  767. zp = &bz->za[bz->f2];
  768. rcnt = zp->z1 - zp->z2;
  769. if (rcnt < 0)
  770. rcnt += B_FIFO_SIZE;
  771. rcnt++;
  772. if (cs->debug & L1_DEB_ISAC)
  773. debugl1(cs, "hfcpci e_rec z1(%x) z2(%x) cnt(%d)",
  774. zp->z1, zp->z2, rcnt);
  775. new_z2 = zp->z2 + rcnt; /* new position in fifo */
  776. if (new_z2 >= (B_FIFO_SIZE + B_SUB_VAL))
  777. new_z2 -= B_FIFO_SIZE; /* buffer wrap */
  778. new_f2 = (bz->f2 + 1) & MAX_B_FRAMES;
  779. if ((rcnt > 256 + 3) || (count < 4) ||
  780. (*(bdata + (zp->z1 - B_SUB_VAL)))) {
  781. if (cs->debug & L1_DEB_WARN)
  782. debugl1(cs, "hfcpci_empty_echan: incoming packet invalid length %d or crc", rcnt);
  783. bz->za[new_f2].z2 = new_z2;
  784. bz->f2 = new_f2; /* next buffer */
  785. } else {
  786. total = rcnt;
  787. rcnt -= 3;
  788. ptr = e_buffer;
  789. if (zp->z2 <= B_FIFO_SIZE + B_SUB_VAL)
  790. maxlen = rcnt; /* complete transfer */
  791. else
  792. maxlen = B_FIFO_SIZE + B_SUB_VAL - zp->z2; /* maximum */
  793. ptr1 = bdata + (zp->z2 - B_SUB_VAL); /* start of data */
  794. memcpy(ptr, ptr1, maxlen); /* copy data */
  795. rcnt -= maxlen;
  796. if (rcnt) { /* rest remaining */
  797. ptr += maxlen;
  798. ptr1 = bdata; /* start of buffer */
  799. memcpy(ptr, ptr1, rcnt); /* rest */
  800. }
  801. bz->za[new_f2].z2 = new_z2;
  802. bz->f2 = new_f2; /* next buffer */
  803. if (cs->debug & DEB_DLOG_HEX) {
  804. ptr = cs->dlog;
  805. if ((total - 3) < MAX_DLOG_SPACE / 3 - 10) {
  806. *ptr++ = 'E';
  807. *ptr++ = 'C';
  808. *ptr++ = 'H';
  809. *ptr++ = 'O';
  810. *ptr++ = ':';
  811. ptr += QuickHex(ptr, e_buffer, total - 3);
  812. ptr--;
  813. *ptr++ = '\n';
  814. *ptr = 0;
  815. HiSax_putstatus(cs, NULL, cs->dlog);
  816. } else
  817. HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
  818. }
  819. }
  820. rcnt = bz->f1 - bz->f2;
  821. if (rcnt < 0)
  822. rcnt += MAX_B_FRAMES + 1;
  823. if (rcnt > 1)
  824. receive = 1;
  825. else
  826. receive = 0;
  827. } else
  828. receive = 0;
  829. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  830. if (count && receive)
  831. goto Begin;
  832. } /* receive_emsg */
  833. /*********************/
  834. /* Interrupt handler */
  835. /*********************/
  836. static irqreturn_t
  837. hfcpci_interrupt(int intno, void *dev_id)
  838. {
  839. u_long flags;
  840. struct IsdnCardState *cs = dev_id;
  841. u_char exval;
  842. struct BCState *bcs;
  843. int count = 15;
  844. u_char val, stat;
  845. if (!(cs->hw.hfcpci.int_m2 & 0x08)) {
  846. debugl1(cs, "HFC-PCI: int_m2 %x not initialised", cs->hw.hfcpci.int_m2);
  847. return IRQ_NONE; /* not initialised */
  848. }
  849. spin_lock_irqsave(&cs->lock, flags);
  850. if (HFCPCI_ANYINT & (stat = Read_hfc(cs, HFCPCI_STATUS))) {
  851. val = Read_hfc(cs, HFCPCI_INT_S1);
  852. if (cs->debug & L1_DEB_ISAC)
  853. debugl1(cs, "HFC-PCI: stat(%02x) s1(%02x)", stat, val);
  854. } else {
  855. spin_unlock_irqrestore(&cs->lock, flags);
  856. return IRQ_NONE;
  857. }
  858. if (cs->debug & L1_DEB_ISAC)
  859. debugl1(cs, "HFC-PCI irq %x %s", val,
  860. test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags) ?
  861. "locked" : "unlocked");
  862. val &= cs->hw.hfcpci.int_m1;
  863. if (val & 0x40) { /* state machine irq */
  864. exval = Read_hfc(cs, HFCPCI_STATES) & 0xf;
  865. if (cs->debug & L1_DEB_ISAC)
  866. debugl1(cs, "ph_state chg %d->%d", cs->dc.hfcpci.ph_state,
  867. exval);
  868. cs->dc.hfcpci.ph_state = exval;
  869. sched_event_D_pci(cs, D_L1STATECHANGE);
  870. val &= ~0x40;
  871. }
  872. if (val & 0x80) { /* timer irq */
  873. if (cs->hw.hfcpci.nt_mode) {
  874. if ((--cs->hw.hfcpci.nt_timer) < 0)
  875. sched_event_D_pci(cs, D_L1STATECHANGE);
  876. }
  877. val &= ~0x80;
  878. Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt | HFCPCI_CLTIMER);
  879. }
  880. while (val) {
  881. if (test_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  882. cs->hw.hfcpci.int_s1 |= val;
  883. spin_unlock_irqrestore(&cs->lock, flags);
  884. return IRQ_HANDLED;
  885. }
  886. if (cs->hw.hfcpci.int_s1 & 0x18) {
  887. exval = val;
  888. val = cs->hw.hfcpci.int_s1;
  889. cs->hw.hfcpci.int_s1 = exval;
  890. }
  891. if (val & 0x08) {
  892. if (!(bcs = Sel_BCS(cs, cs->hw.hfcpci.bswapped ? 1 : 0))) {
  893. if (cs->debug)
  894. debugl1(cs, "hfcpci spurious 0x08 IRQ");
  895. } else
  896. main_rec_hfcpci(bcs);
  897. }
  898. if (val & 0x10) {
  899. if (cs->logecho)
  900. receive_emsg(cs);
  901. else if (!(bcs = Sel_BCS(cs, 1))) {
  902. if (cs->debug)
  903. debugl1(cs, "hfcpci spurious 0x10 IRQ");
  904. } else
  905. main_rec_hfcpci(bcs);
  906. }
  907. if (val & 0x01) {
  908. if (!(bcs = Sel_BCS(cs, cs->hw.hfcpci.bswapped ? 1 : 0))) {
  909. if (cs->debug)
  910. debugl1(cs, "hfcpci spurious 0x01 IRQ");
  911. } else {
  912. if (bcs->tx_skb) {
  913. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  914. hfcpci_fill_fifo(bcs);
  915. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  916. } else
  917. debugl1(cs, "fill_data %d blocked", bcs->channel);
  918. } else {
  919. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  920. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  921. hfcpci_fill_fifo(bcs);
  922. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  923. } else
  924. debugl1(cs, "fill_data %d blocked", bcs->channel);
  925. } else {
  926. hfcpci_sched_event(bcs, B_XMTBUFREADY);
  927. }
  928. }
  929. }
  930. }
  931. if (val & 0x02) {
  932. if (!(bcs = Sel_BCS(cs, 1))) {
  933. if (cs->debug)
  934. debugl1(cs, "hfcpci spurious 0x02 IRQ");
  935. } else {
  936. if (bcs->tx_skb) {
  937. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  938. hfcpci_fill_fifo(bcs);
  939. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  940. } else
  941. debugl1(cs, "fill_data %d blocked", bcs->channel);
  942. } else {
  943. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  944. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  945. hfcpci_fill_fifo(bcs);
  946. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  947. } else
  948. debugl1(cs, "fill_data %d blocked", bcs->channel);
  949. } else {
  950. hfcpci_sched_event(bcs, B_XMTBUFREADY);
  951. }
  952. }
  953. }
  954. }
  955. if (val & 0x20) { /* receive dframe */
  956. receive_dmsg(cs);
  957. }
  958. if (val & 0x04) { /* dframe transmitted */
  959. if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
  960. del_timer(&cs->dbusytimer);
  961. if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
  962. sched_event_D_pci(cs, D_CLEARBUSY);
  963. if (cs->tx_skb) {
  964. if (cs->tx_skb->len) {
  965. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  966. hfcpci_fill_dfifo(cs);
  967. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  968. } else {
  969. debugl1(cs, "hfcpci_fill_dfifo irq blocked");
  970. }
  971. goto afterXPR;
  972. } else {
  973. dev_kfree_skb_irq(cs->tx_skb);
  974. cs->tx_cnt = 0;
  975. cs->tx_skb = NULL;
  976. }
  977. }
  978. if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
  979. cs->tx_cnt = 0;
  980. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  981. hfcpci_fill_dfifo(cs);
  982. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  983. } else {
  984. debugl1(cs, "hfcpci_fill_dfifo irq blocked");
  985. }
  986. } else
  987. sched_event_D_pci(cs, D_XMTBUFREADY);
  988. }
  989. afterXPR:
  990. if (cs->hw.hfcpci.int_s1 && count--) {
  991. val = cs->hw.hfcpci.int_s1;
  992. cs->hw.hfcpci.int_s1 = 0;
  993. if (cs->debug & L1_DEB_ISAC)
  994. debugl1(cs, "HFC-PCI irq %x loop %d", val, 15 - count);
  995. } else
  996. val = 0;
  997. }
  998. spin_unlock_irqrestore(&cs->lock, flags);
  999. return IRQ_HANDLED;
  1000. }
  1001. /********************************************************************/
  1002. /* timer callback for D-chan busy resolution. Currently no function */
  1003. /********************************************************************/
  1004. static void
  1005. hfcpci_dbusy_timer(struct IsdnCardState *cs)
  1006. {
  1007. }
  1008. /*************************************/
  1009. /* Layer 1 D-channel hardware access */
  1010. /*************************************/
  1011. static void
  1012. HFCPCI_l1hw(struct PStack *st, int pr, void *arg)
  1013. {
  1014. u_long flags;
  1015. struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
  1016. struct sk_buff *skb = arg;
  1017. switch (pr) {
  1018. case (PH_DATA | REQUEST):
  1019. if (cs->debug & DEB_DLOG_HEX)
  1020. LogFrame(cs, skb->data, skb->len);
  1021. if (cs->debug & DEB_DLOG_VERBOSE)
  1022. dlogframe(cs, skb, 0);
  1023. spin_lock_irqsave(&cs->lock, flags);
  1024. if (cs->tx_skb) {
  1025. skb_queue_tail(&cs->sq, skb);
  1026. #ifdef L2FRAME_DEBUG /* psa */
  1027. if (cs->debug & L1_DEB_LAPD)
  1028. Logl2Frame(cs, skb, "PH_DATA Queued", 0);
  1029. #endif
  1030. } else {
  1031. cs->tx_skb = skb;
  1032. cs->tx_cnt = 0;
  1033. #ifdef L2FRAME_DEBUG /* psa */
  1034. if (cs->debug & L1_DEB_LAPD)
  1035. Logl2Frame(cs, skb, "PH_DATA", 0);
  1036. #endif
  1037. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  1038. hfcpci_fill_dfifo(cs);
  1039. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  1040. } else
  1041. debugl1(cs, "hfcpci_fill_dfifo blocked");
  1042. }
  1043. spin_unlock_irqrestore(&cs->lock, flags);
  1044. break;
  1045. case (PH_PULL | INDICATION):
  1046. spin_lock_irqsave(&cs->lock, flags);
  1047. if (cs->tx_skb) {
  1048. if (cs->debug & L1_DEB_WARN)
  1049. debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
  1050. skb_queue_tail(&cs->sq, skb);
  1051. spin_unlock_irqrestore(&cs->lock, flags);
  1052. break;
  1053. }
  1054. if (cs->debug & DEB_DLOG_HEX)
  1055. LogFrame(cs, skb->data, skb->len);
  1056. if (cs->debug & DEB_DLOG_VERBOSE)
  1057. dlogframe(cs, skb, 0);
  1058. cs->tx_skb = skb;
  1059. cs->tx_cnt = 0;
  1060. #ifdef L2FRAME_DEBUG /* psa */
  1061. if (cs->debug & L1_DEB_LAPD)
  1062. Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
  1063. #endif
  1064. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  1065. hfcpci_fill_dfifo(cs);
  1066. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  1067. } else
  1068. debugl1(cs, "hfcpci_fill_dfifo blocked");
  1069. spin_unlock_irqrestore(&cs->lock, flags);
  1070. break;
  1071. case (PH_PULL | REQUEST):
  1072. #ifdef L2FRAME_DEBUG /* psa */
  1073. if (cs->debug & L1_DEB_LAPD)
  1074. debugl1(cs, "-> PH_REQUEST_PULL");
  1075. #endif
  1076. spin_lock_irqsave(&cs->lock, flags);
  1077. if (!cs->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. spin_unlock_irqrestore(&cs->lock, flags);
  1083. break;
  1084. case (HW_RESET | REQUEST):
  1085. spin_lock_irqsave(&cs->lock, flags);
  1086. Write_hfc(cs, HFCPCI_STATES, HFCPCI_LOAD_STATE | 3); /* HFC ST 3 */
  1087. udelay(6);
  1088. Write_hfc(cs, HFCPCI_STATES, 3); /* HFC ST 2 */
  1089. cs->hw.hfcpci.mst_m |= HFCPCI_MASTER;
  1090. Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
  1091. Write_hfc(cs, HFCPCI_STATES, HFCPCI_ACTIVATE | HFCPCI_DO_ACTION);
  1092. spin_unlock_irqrestore(&cs->lock, flags);
  1093. l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
  1094. break;
  1095. case (HW_ENABLE | REQUEST):
  1096. spin_lock_irqsave(&cs->lock, flags);
  1097. Write_hfc(cs, HFCPCI_STATES, HFCPCI_DO_ACTION);
  1098. spin_unlock_irqrestore(&cs->lock, flags);
  1099. break;
  1100. case (HW_DEACTIVATE | REQUEST):
  1101. spin_lock_irqsave(&cs->lock, flags);
  1102. cs->hw.hfcpci.mst_m &= ~HFCPCI_MASTER;
  1103. Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
  1104. spin_unlock_irqrestore(&cs->lock, flags);
  1105. break;
  1106. case (HW_INFO3 | REQUEST):
  1107. spin_lock_irqsave(&cs->lock, flags);
  1108. cs->hw.hfcpci.mst_m |= HFCPCI_MASTER;
  1109. Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
  1110. spin_unlock_irqrestore(&cs->lock, flags);
  1111. break;
  1112. case (HW_TESTLOOP | REQUEST):
  1113. spin_lock_irqsave(&cs->lock, flags);
  1114. switch ((long) arg) {
  1115. case (1):
  1116. Write_hfc(cs, HFCPCI_B1_SSL, 0x80); /* tx slot */
  1117. Write_hfc(cs, HFCPCI_B1_RSL, 0x80); /* rx slot */
  1118. cs->hw.hfcpci.conn = (cs->hw.hfcpci.conn & ~7) | 1;
  1119. Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
  1120. break;
  1121. case (2):
  1122. Write_hfc(cs, HFCPCI_B2_SSL, 0x81); /* tx slot */
  1123. Write_hfc(cs, HFCPCI_B2_RSL, 0x81); /* rx slot */
  1124. cs->hw.hfcpci.conn = (cs->hw.hfcpci.conn & ~0x38) | 0x08;
  1125. Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
  1126. break;
  1127. default:
  1128. spin_unlock_irqrestore(&cs->lock, flags);
  1129. if (cs->debug & L1_DEB_WARN)
  1130. debugl1(cs, "hfcpci_l1hw loop invalid %4lx", (long) arg);
  1131. return;
  1132. }
  1133. cs->hw.hfcpci.trm |= 0x80; /* enable IOM-loop */
  1134. Write_hfc(cs, HFCPCI_TRM, cs->hw.hfcpci.trm);
  1135. spin_unlock_irqrestore(&cs->lock, flags);
  1136. break;
  1137. default:
  1138. if (cs->debug & L1_DEB_WARN)
  1139. debugl1(cs, "hfcpci_l1hw unknown pr %4x", pr);
  1140. break;
  1141. }
  1142. }
  1143. /***********************************************/
  1144. /* called during init setting l1 stack pointer */
  1145. /***********************************************/
  1146. static void
  1147. setstack_hfcpci(struct PStack *st, struct IsdnCardState *cs)
  1148. {
  1149. st->l1.l1hw = HFCPCI_l1hw;
  1150. }
  1151. /**************************************/
  1152. /* send B-channel data if not blocked */
  1153. /**************************************/
  1154. static void
  1155. hfcpci_send_data(struct BCState *bcs)
  1156. {
  1157. struct IsdnCardState *cs = bcs->cs;
  1158. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  1159. hfcpci_fill_fifo(bcs);
  1160. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  1161. } else
  1162. debugl1(cs, "send_data %d blocked", bcs->channel);
  1163. }
  1164. /***************************************************************/
  1165. /* activate/deactivate hardware for selected channels and mode */
  1166. /***************************************************************/
  1167. static void
  1168. mode_hfcpci(struct BCState *bcs, int mode, int bc)
  1169. {
  1170. struct IsdnCardState *cs = bcs->cs;
  1171. int fifo2;
  1172. if (cs->debug & L1_DEB_HSCX)
  1173. debugl1(cs, "HFCPCI bchannel mode %d bchan %d/%d",
  1174. mode, bc, bcs->channel);
  1175. bcs->mode = mode;
  1176. bcs->channel = bc;
  1177. fifo2 = bc;
  1178. if (cs->chanlimit > 1) {
  1179. cs->hw.hfcpci.bswapped = 0; /* B1 and B2 normal mode */
  1180. cs->hw.hfcpci.sctrl_e &= ~0x80;
  1181. } else {
  1182. if (bc) {
  1183. if (mode != L1_MODE_NULL) {
  1184. cs->hw.hfcpci.bswapped = 1; /* B1 and B2 exchanged */
  1185. cs->hw.hfcpci.sctrl_e |= 0x80;
  1186. } else {
  1187. cs->hw.hfcpci.bswapped = 0; /* B1 and B2 normal mode */
  1188. cs->hw.hfcpci.sctrl_e &= ~0x80;
  1189. }
  1190. fifo2 = 0;
  1191. } else {
  1192. cs->hw.hfcpci.bswapped = 0; /* B1 and B2 normal mode */
  1193. cs->hw.hfcpci.sctrl_e &= ~0x80;
  1194. }
  1195. }
  1196. switch (mode) {
  1197. case (L1_MODE_NULL):
  1198. if (bc) {
  1199. cs->hw.hfcpci.sctrl &= ~SCTRL_B2_ENA;
  1200. cs->hw.hfcpci.sctrl_r &= ~SCTRL_B2_ENA;
  1201. } else {
  1202. cs->hw.hfcpci.sctrl &= ~SCTRL_B1_ENA;
  1203. cs->hw.hfcpci.sctrl_r &= ~SCTRL_B1_ENA;
  1204. }
  1205. if (fifo2) {
  1206. cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B2;
  1207. cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
  1208. } else {
  1209. cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B1;
  1210. cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
  1211. }
  1212. break;
  1213. case (L1_MODE_TRANS):
  1214. hfcpci_clear_fifo_rx(cs, fifo2);
  1215. hfcpci_clear_fifo_tx(cs, fifo2);
  1216. if (bc) {
  1217. cs->hw.hfcpci.sctrl |= SCTRL_B2_ENA;
  1218. cs->hw.hfcpci.sctrl_r |= SCTRL_B2_ENA;
  1219. } else {
  1220. cs->hw.hfcpci.sctrl |= SCTRL_B1_ENA;
  1221. cs->hw.hfcpci.sctrl_r |= SCTRL_B1_ENA;
  1222. }
  1223. if (fifo2) {
  1224. cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B2;
  1225. cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
  1226. cs->hw.hfcpci.ctmt |= 2;
  1227. cs->hw.hfcpci.conn &= ~0x18;
  1228. } else {
  1229. cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B1;
  1230. cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
  1231. cs->hw.hfcpci.ctmt |= 1;
  1232. cs->hw.hfcpci.conn &= ~0x03;
  1233. }
  1234. break;
  1235. case (L1_MODE_HDLC):
  1236. hfcpci_clear_fifo_rx(cs, fifo2);
  1237. hfcpci_clear_fifo_tx(cs, fifo2);
  1238. if (bc) {
  1239. cs->hw.hfcpci.sctrl |= SCTRL_B2_ENA;
  1240. cs->hw.hfcpci.sctrl_r |= SCTRL_B2_ENA;
  1241. } else {
  1242. cs->hw.hfcpci.sctrl |= SCTRL_B1_ENA;
  1243. cs->hw.hfcpci.sctrl_r |= SCTRL_B1_ENA;
  1244. }
  1245. if (fifo2) {
  1246. cs->hw.hfcpci.last_bfifo_cnt[1] = 0;
  1247. cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B2;
  1248. cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
  1249. cs->hw.hfcpci.ctmt &= ~2;
  1250. cs->hw.hfcpci.conn &= ~0x18;
  1251. } else {
  1252. cs->hw.hfcpci.last_bfifo_cnt[0] = 0;
  1253. cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B1;
  1254. cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
  1255. cs->hw.hfcpci.ctmt &= ~1;
  1256. cs->hw.hfcpci.conn &= ~0x03;
  1257. }
  1258. break;
  1259. case (L1_MODE_EXTRN):
  1260. if (bc) {
  1261. cs->hw.hfcpci.conn |= 0x10;
  1262. cs->hw.hfcpci.sctrl |= SCTRL_B2_ENA;
  1263. cs->hw.hfcpci.sctrl_r |= SCTRL_B2_ENA;
  1264. cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B2;
  1265. cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
  1266. } else {
  1267. cs->hw.hfcpci.conn |= 0x02;
  1268. cs->hw.hfcpci.sctrl |= SCTRL_B1_ENA;
  1269. cs->hw.hfcpci.sctrl_r |= SCTRL_B1_ENA;
  1270. cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B1;
  1271. cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
  1272. }
  1273. break;
  1274. }
  1275. Write_hfc(cs, HFCPCI_SCTRL_E, cs->hw.hfcpci.sctrl_e);
  1276. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1277. Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
  1278. Write_hfc(cs, HFCPCI_SCTRL, cs->hw.hfcpci.sctrl);
  1279. Write_hfc(cs, HFCPCI_SCTRL_R, cs->hw.hfcpci.sctrl_r);
  1280. Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt);
  1281. Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
  1282. }
  1283. /******************************/
  1284. /* Layer2 -> Layer 1 Transfer */
  1285. /******************************/
  1286. static void
  1287. hfcpci_l2l1(struct PStack *st, int pr, void *arg)
  1288. {
  1289. struct BCState *bcs = st->l1.bcs;
  1290. u_long flags;
  1291. struct sk_buff *skb = arg;
  1292. switch (pr) {
  1293. case (PH_DATA | REQUEST):
  1294. spin_lock_irqsave(&bcs->cs->lock, flags);
  1295. if (bcs->tx_skb) {
  1296. skb_queue_tail(&bcs->squeue, skb);
  1297. } else {
  1298. bcs->tx_skb = skb;
  1299. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1300. bcs->cs->BC_Send_Data(bcs);
  1301. }
  1302. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1303. break;
  1304. case (PH_PULL | INDICATION):
  1305. spin_lock_irqsave(&bcs->cs->lock, flags);
  1306. if (bcs->tx_skb) {
  1307. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1308. printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
  1309. break;
  1310. }
  1311. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1312. bcs->tx_skb = skb;
  1313. bcs->cs->BC_Send_Data(bcs);
  1314. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1315. break;
  1316. case (PH_PULL | REQUEST):
  1317. if (!bcs->tx_skb) {
  1318. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1319. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  1320. } else
  1321. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1322. break;
  1323. case (PH_ACTIVATE | REQUEST):
  1324. spin_lock_irqsave(&bcs->cs->lock, flags);
  1325. test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
  1326. mode_hfcpci(bcs, st->l1.mode, st->l1.bc);
  1327. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1328. l1_msg_b(st, pr, arg);
  1329. break;
  1330. case (PH_DEACTIVATE | REQUEST):
  1331. l1_msg_b(st, pr, arg);
  1332. break;
  1333. case (PH_DEACTIVATE | CONFIRM):
  1334. spin_lock_irqsave(&bcs->cs->lock, flags);
  1335. test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
  1336. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1337. mode_hfcpci(bcs, 0, st->l1.bc);
  1338. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1339. st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
  1340. break;
  1341. }
  1342. }
  1343. /******************************************/
  1344. /* deactivate B-channel access and queues */
  1345. /******************************************/
  1346. static void
  1347. close_hfcpci(struct BCState *bcs)
  1348. {
  1349. mode_hfcpci(bcs, 0, bcs->channel);
  1350. if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
  1351. skb_queue_purge(&bcs->rqueue);
  1352. skb_queue_purge(&bcs->squeue);
  1353. if (bcs->tx_skb) {
  1354. dev_kfree_skb_any(bcs->tx_skb);
  1355. bcs->tx_skb = NULL;
  1356. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1357. }
  1358. }
  1359. }
  1360. /*************************************/
  1361. /* init B-channel queues and control */
  1362. /*************************************/
  1363. static int
  1364. open_hfcpcistate(struct IsdnCardState *cs, struct BCState *bcs)
  1365. {
  1366. if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
  1367. skb_queue_head_init(&bcs->rqueue);
  1368. skb_queue_head_init(&bcs->squeue);
  1369. }
  1370. bcs->tx_skb = NULL;
  1371. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1372. bcs->event = 0;
  1373. bcs->tx_cnt = 0;
  1374. return (0);
  1375. }
  1376. /*********************************/
  1377. /* inits the stack for B-channel */
  1378. /*********************************/
  1379. static int
  1380. setstack_2b(struct PStack *st, struct BCState *bcs)
  1381. {
  1382. bcs->channel = st->l1.bc;
  1383. if (open_hfcpcistate(st->l1.hardware, bcs))
  1384. return (-1);
  1385. st->l1.bcs = bcs;
  1386. st->l2.l2l1 = hfcpci_l2l1;
  1387. setstack_manager(st);
  1388. bcs->st = st;
  1389. setstack_l1_B(st);
  1390. return (0);
  1391. }
  1392. /***************************/
  1393. /* handle L1 state changes */
  1394. /***************************/
  1395. static void
  1396. hfcpci_bh(struct work_struct *work)
  1397. {
  1398. struct IsdnCardState *cs =
  1399. container_of(work, struct IsdnCardState, tqueue);
  1400. u_long flags;
  1401. // struct PStack *stptr;
  1402. if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
  1403. if (!cs->hw.hfcpci.nt_mode)
  1404. switch (cs->dc.hfcpci.ph_state) {
  1405. case (0):
  1406. l1_msg(cs, HW_RESET | INDICATION, NULL);
  1407. break;
  1408. case (3):
  1409. l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
  1410. break;
  1411. case (8):
  1412. l1_msg(cs, HW_RSYNC | INDICATION, NULL);
  1413. break;
  1414. case (6):
  1415. l1_msg(cs, HW_INFO2 | INDICATION, NULL);
  1416. break;
  1417. case (7):
  1418. l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
  1419. break;
  1420. default:
  1421. break;
  1422. } else {
  1423. spin_lock_irqsave(&cs->lock, flags);
  1424. switch (cs->dc.hfcpci.ph_state) {
  1425. case (2):
  1426. if (cs->hw.hfcpci.nt_timer < 0) {
  1427. cs->hw.hfcpci.nt_timer = 0;
  1428. cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_TIMER;
  1429. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1430. /* Clear already pending ints */
  1431. if (Read_hfc(cs, HFCPCI_INT_S1));
  1432. Write_hfc(cs, HFCPCI_STATES, 4 | HFCPCI_LOAD_STATE);
  1433. udelay(10);
  1434. Write_hfc(cs, HFCPCI_STATES, 4);
  1435. cs->dc.hfcpci.ph_state = 4;
  1436. } else {
  1437. cs->hw.hfcpci.int_m1 |= HFCPCI_INTS_TIMER;
  1438. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1439. cs->hw.hfcpci.ctmt &= ~HFCPCI_AUTO_TIMER;
  1440. cs->hw.hfcpci.ctmt |= HFCPCI_TIM3_125;
  1441. Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt | HFCPCI_CLTIMER);
  1442. Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt | HFCPCI_CLTIMER);
  1443. cs->hw.hfcpci.nt_timer = NT_T1_COUNT;
  1444. Write_hfc(cs, HFCPCI_STATES, 2 | HFCPCI_NT_G2_G3); /* allow G2 -> G3 transition */
  1445. }
  1446. break;
  1447. case (1):
  1448. case (3):
  1449. case (4):
  1450. cs->hw.hfcpci.nt_timer = 0;
  1451. cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_TIMER;
  1452. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1453. break;
  1454. default:
  1455. break;
  1456. }
  1457. spin_unlock_irqrestore(&cs->lock, flags);
  1458. }
  1459. }
  1460. if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
  1461. DChannel_proc_rcv(cs);
  1462. if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
  1463. DChannel_proc_xmt(cs);
  1464. }
  1465. /********************************/
  1466. /* called for card init message */
  1467. /********************************/
  1468. static void
  1469. inithfcpci(struct IsdnCardState *cs)
  1470. {
  1471. cs->bcs[0].BC_SetStack = setstack_2b;
  1472. cs->bcs[1].BC_SetStack = setstack_2b;
  1473. cs->bcs[0].BC_Close = close_hfcpci;
  1474. cs->bcs[1].BC_Close = close_hfcpci;
  1475. setup_timer(&cs->dbusytimer, (void *)hfcpci_dbusy_timer, (long)cs);
  1476. mode_hfcpci(cs->bcs, 0, 0);
  1477. mode_hfcpci(cs->bcs + 1, 0, 1);
  1478. }
  1479. /*******************************************/
  1480. /* handle card messages from control layer */
  1481. /*******************************************/
  1482. static int
  1483. hfcpci_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  1484. {
  1485. u_long flags;
  1486. if (cs->debug & L1_DEB_ISAC)
  1487. debugl1(cs, "HFCPCI: card_msg %x", mt);
  1488. switch (mt) {
  1489. case CARD_RESET:
  1490. spin_lock_irqsave(&cs->lock, flags);
  1491. reset_hfcpci(cs);
  1492. spin_unlock_irqrestore(&cs->lock, flags);
  1493. return (0);
  1494. case CARD_RELEASE:
  1495. release_io_hfcpci(cs);
  1496. return (0);
  1497. case CARD_INIT:
  1498. spin_lock_irqsave(&cs->lock, flags);
  1499. inithfcpci(cs);
  1500. reset_hfcpci(cs);
  1501. spin_unlock_irqrestore(&cs->lock, flags);
  1502. msleep(80); /* Timeout 80ms */
  1503. /* now switch timer interrupt off */
  1504. spin_lock_irqsave(&cs->lock, flags);
  1505. cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_TIMER;
  1506. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1507. /* reinit mode reg */
  1508. Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
  1509. spin_unlock_irqrestore(&cs->lock, flags);
  1510. return (0);
  1511. case CARD_TEST:
  1512. return (0);
  1513. }
  1514. return (0);
  1515. }
  1516. /* this variable is used as card index when more than one cards are present */
  1517. static struct pci_dev *dev_hfcpci = NULL;
  1518. int
  1519. setup_hfcpci(struct IsdnCard *card)
  1520. {
  1521. u_long flags;
  1522. struct IsdnCardState *cs = card->cs;
  1523. char tmp[64];
  1524. int i;
  1525. struct pci_dev *tmp_hfcpci = NULL;
  1526. strcpy(tmp, hfcpci_revision);
  1527. printk(KERN_INFO "HiSax: HFC-PCI driver Rev. %s\n", HiSax_getrev(tmp));
  1528. cs->hw.hfcpci.int_s1 = 0;
  1529. cs->dc.hfcpci.ph_state = 0;
  1530. cs->hw.hfcpci.fifo = 255;
  1531. if (cs->typ != ISDN_CTYPE_HFC_PCI)
  1532. return (0);
  1533. i = 0;
  1534. while (id_list[i].vendor_id) {
  1535. tmp_hfcpci = hisax_find_pci_device(id_list[i].vendor_id,
  1536. id_list[i].device_id,
  1537. dev_hfcpci);
  1538. i++;
  1539. if (tmp_hfcpci) {
  1540. dma_addr_t dma_mask = DMA_BIT_MASK(32) & ~0x7fffUL;
  1541. if (pci_enable_device(tmp_hfcpci))
  1542. continue;
  1543. if (pci_set_dma_mask(tmp_hfcpci, dma_mask)) {
  1544. printk(KERN_WARNING
  1545. "HiSax hfc_pci: No suitable DMA available.\n");
  1546. continue;
  1547. }
  1548. if (pci_set_consistent_dma_mask(tmp_hfcpci, dma_mask)) {
  1549. printk(KERN_WARNING
  1550. "HiSax hfc_pci: No suitable consistent DMA available.\n");
  1551. continue;
  1552. }
  1553. pci_set_master(tmp_hfcpci);
  1554. if ((card->para[0]) && (card->para[0] != (tmp_hfcpci->resource[0].start & PCI_BASE_ADDRESS_IO_MASK)))
  1555. continue;
  1556. else
  1557. break;
  1558. }
  1559. }
  1560. if (!tmp_hfcpci) {
  1561. printk(KERN_WARNING "HFC-PCI: No PCI card found\n");
  1562. return (0);
  1563. }
  1564. i--;
  1565. dev_hfcpci = tmp_hfcpci; /* old device */
  1566. cs->hw.hfcpci.dev = dev_hfcpci;
  1567. cs->irq = dev_hfcpci->irq;
  1568. if (!cs->irq) {
  1569. printk(KERN_WARNING "HFC-PCI: No IRQ for PCI card found\n");
  1570. return (0);
  1571. }
  1572. cs->hw.hfcpci.pci_io = (char *)(unsigned long)dev_hfcpci->resource[1].start;
  1573. printk(KERN_INFO "HiSax: HFC-PCI card manufacturer: %s card name: %s\n", id_list[i].vendor_name, id_list[i].card_name);
  1574. if (!cs->hw.hfcpci.pci_io) {
  1575. printk(KERN_WARNING "HFC-PCI: No IO-Mem for PCI card found\n");
  1576. return (0);
  1577. }
  1578. /* Allocate memory for FIFOS */
  1579. cs->hw.hfcpci.fifos = pci_alloc_consistent(cs->hw.hfcpci.dev,
  1580. 0x8000, &cs->hw.hfcpci.dma);
  1581. if (!cs->hw.hfcpci.fifos) {
  1582. printk(KERN_WARNING "HFC-PCI: Error allocating FIFO memory!\n");
  1583. return 0;
  1584. }
  1585. if (cs->hw.hfcpci.dma & 0x7fff) {
  1586. printk(KERN_WARNING
  1587. "HFC-PCI: Error DMA memory not on 32K boundary (%lx)\n",
  1588. (u_long)cs->hw.hfcpci.dma);
  1589. pci_free_consistent(cs->hw.hfcpci.dev, 0x8000,
  1590. cs->hw.hfcpci.fifos, cs->hw.hfcpci.dma);
  1591. return 0;
  1592. }
  1593. pci_write_config_dword(cs->hw.hfcpci.dev, 0x80, (u32)cs->hw.hfcpci.dma);
  1594. cs->hw.hfcpci.pci_io = ioremap((ulong) cs->hw.hfcpci.pci_io, 256);
  1595. printk(KERN_INFO
  1596. "HFC-PCI: defined at mem %p fifo %p(%lx) IRQ %d HZ %d\n",
  1597. cs->hw.hfcpci.pci_io,
  1598. cs->hw.hfcpci.fifos,
  1599. (u_long)cs->hw.hfcpci.dma,
  1600. cs->irq, HZ);
  1601. spin_lock_irqsave(&cs->lock, flags);
  1602. pci_write_config_word(cs->hw.hfcpci.dev, PCI_COMMAND, PCI_ENA_MEMIO); /* enable memory mapped ports, disable busmaster */
  1603. cs->hw.hfcpci.int_m2 = 0; /* disable alle interrupts */
  1604. cs->hw.hfcpci.int_m1 = 0;
  1605. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1606. Write_hfc(cs, HFCPCI_INT_M2, cs->hw.hfcpci.int_m2);
  1607. /* At this point the needed PCI config is done */
  1608. /* fifos are still not enabled */
  1609. INIT_WORK(&cs->tqueue, hfcpci_bh);
  1610. cs->setstack_d = setstack_hfcpci;
  1611. cs->BC_Send_Data = &hfcpci_send_data;
  1612. cs->readisac = NULL;
  1613. cs->writeisac = NULL;
  1614. cs->readisacfifo = NULL;
  1615. cs->writeisacfifo = NULL;
  1616. cs->BC_Read_Reg = NULL;
  1617. cs->BC_Write_Reg = NULL;
  1618. cs->irq_func = &hfcpci_interrupt;
  1619. cs->irq_flags |= IRQF_SHARED;
  1620. setup_timer(&cs->hw.hfcpci.timer, (void *)hfcpci_Timer, (long)cs);
  1621. cs->cardmsg = &hfcpci_card_msg;
  1622. cs->auxcmd = &hfcpci_auxcmd;
  1623. spin_unlock_irqrestore(&cs->lock, flags);
  1624. return (1);
  1625. }