hfc_pci.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  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. if (!cs->tx_skb) {
  1077. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1078. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  1079. } else
  1080. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1081. break;
  1082. case (HW_RESET | REQUEST):
  1083. spin_lock_irqsave(&cs->lock, flags);
  1084. Write_hfc(cs, HFCPCI_STATES, HFCPCI_LOAD_STATE | 3); /* HFC ST 3 */
  1085. udelay(6);
  1086. Write_hfc(cs, HFCPCI_STATES, 3); /* HFC ST 2 */
  1087. cs->hw.hfcpci.mst_m |= HFCPCI_MASTER;
  1088. Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
  1089. Write_hfc(cs, HFCPCI_STATES, HFCPCI_ACTIVATE | HFCPCI_DO_ACTION);
  1090. spin_unlock_irqrestore(&cs->lock, flags);
  1091. l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
  1092. break;
  1093. case (HW_ENABLE | REQUEST):
  1094. spin_lock_irqsave(&cs->lock, flags);
  1095. Write_hfc(cs, HFCPCI_STATES, HFCPCI_DO_ACTION);
  1096. spin_unlock_irqrestore(&cs->lock, flags);
  1097. break;
  1098. case (HW_DEACTIVATE | REQUEST):
  1099. spin_lock_irqsave(&cs->lock, flags);
  1100. cs->hw.hfcpci.mst_m &= ~HFCPCI_MASTER;
  1101. Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
  1102. spin_unlock_irqrestore(&cs->lock, flags);
  1103. break;
  1104. case (HW_INFO3 | REQUEST):
  1105. spin_lock_irqsave(&cs->lock, flags);
  1106. cs->hw.hfcpci.mst_m |= HFCPCI_MASTER;
  1107. Write_hfc(cs, HFCPCI_MST_MODE, cs->hw.hfcpci.mst_m);
  1108. spin_unlock_irqrestore(&cs->lock, flags);
  1109. break;
  1110. case (HW_TESTLOOP | REQUEST):
  1111. spin_lock_irqsave(&cs->lock, flags);
  1112. switch ((long) arg) {
  1113. case (1):
  1114. Write_hfc(cs, HFCPCI_B1_SSL, 0x80); /* tx slot */
  1115. Write_hfc(cs, HFCPCI_B1_RSL, 0x80); /* rx slot */
  1116. cs->hw.hfcpci.conn = (cs->hw.hfcpci.conn & ~7) | 1;
  1117. Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
  1118. break;
  1119. case (2):
  1120. Write_hfc(cs, HFCPCI_B2_SSL, 0x81); /* tx slot */
  1121. Write_hfc(cs, HFCPCI_B2_RSL, 0x81); /* rx slot */
  1122. cs->hw.hfcpci.conn = (cs->hw.hfcpci.conn & ~0x38) | 0x08;
  1123. Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
  1124. break;
  1125. default:
  1126. spin_unlock_irqrestore(&cs->lock, flags);
  1127. if (cs->debug & L1_DEB_WARN)
  1128. debugl1(cs, "hfcpci_l1hw loop invalid %4lx", (long) arg);
  1129. return;
  1130. }
  1131. cs->hw.hfcpci.trm |= 0x80; /* enable IOM-loop */
  1132. Write_hfc(cs, HFCPCI_TRM, cs->hw.hfcpci.trm);
  1133. spin_unlock_irqrestore(&cs->lock, flags);
  1134. break;
  1135. default:
  1136. if (cs->debug & L1_DEB_WARN)
  1137. debugl1(cs, "hfcpci_l1hw unknown pr %4x", pr);
  1138. break;
  1139. }
  1140. }
  1141. /***********************************************/
  1142. /* called during init setting l1 stack pointer */
  1143. /***********************************************/
  1144. static void
  1145. setstack_hfcpci(struct PStack *st, struct IsdnCardState *cs)
  1146. {
  1147. st->l1.l1hw = HFCPCI_l1hw;
  1148. }
  1149. /**************************************/
  1150. /* send B-channel data if not blocked */
  1151. /**************************************/
  1152. static void
  1153. hfcpci_send_data(struct BCState *bcs)
  1154. {
  1155. struct IsdnCardState *cs = bcs->cs;
  1156. if (!test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  1157. hfcpci_fill_fifo(bcs);
  1158. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  1159. } else
  1160. debugl1(cs, "send_data %d blocked", bcs->channel);
  1161. }
  1162. /***************************************************************/
  1163. /* activate/deactivate hardware for selected channels and mode */
  1164. /***************************************************************/
  1165. static void
  1166. mode_hfcpci(struct BCState *bcs, int mode, int bc)
  1167. {
  1168. struct IsdnCardState *cs = bcs->cs;
  1169. int fifo2;
  1170. if (cs->debug & L1_DEB_HSCX)
  1171. debugl1(cs, "HFCPCI bchannel mode %d bchan %d/%d",
  1172. mode, bc, bcs->channel);
  1173. bcs->mode = mode;
  1174. bcs->channel = bc;
  1175. fifo2 = bc;
  1176. if (cs->chanlimit > 1) {
  1177. cs->hw.hfcpci.bswapped = 0; /* B1 and B2 normal mode */
  1178. cs->hw.hfcpci.sctrl_e &= ~0x80;
  1179. } else {
  1180. if (bc) {
  1181. if (mode != L1_MODE_NULL) {
  1182. cs->hw.hfcpci.bswapped = 1; /* B1 and B2 exchanged */
  1183. cs->hw.hfcpci.sctrl_e |= 0x80;
  1184. } else {
  1185. cs->hw.hfcpci.bswapped = 0; /* B1 and B2 normal mode */
  1186. cs->hw.hfcpci.sctrl_e &= ~0x80;
  1187. }
  1188. fifo2 = 0;
  1189. } else {
  1190. cs->hw.hfcpci.bswapped = 0; /* B1 and B2 normal mode */
  1191. cs->hw.hfcpci.sctrl_e &= ~0x80;
  1192. }
  1193. }
  1194. switch (mode) {
  1195. case (L1_MODE_NULL):
  1196. if (bc) {
  1197. cs->hw.hfcpci.sctrl &= ~SCTRL_B2_ENA;
  1198. cs->hw.hfcpci.sctrl_r &= ~SCTRL_B2_ENA;
  1199. } else {
  1200. cs->hw.hfcpci.sctrl &= ~SCTRL_B1_ENA;
  1201. cs->hw.hfcpci.sctrl_r &= ~SCTRL_B1_ENA;
  1202. }
  1203. if (fifo2) {
  1204. cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B2;
  1205. cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
  1206. } else {
  1207. cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B1;
  1208. cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
  1209. }
  1210. break;
  1211. case (L1_MODE_TRANS):
  1212. hfcpci_clear_fifo_rx(cs, fifo2);
  1213. hfcpci_clear_fifo_tx(cs, fifo2);
  1214. if (bc) {
  1215. cs->hw.hfcpci.sctrl |= SCTRL_B2_ENA;
  1216. cs->hw.hfcpci.sctrl_r |= SCTRL_B2_ENA;
  1217. } else {
  1218. cs->hw.hfcpci.sctrl |= SCTRL_B1_ENA;
  1219. cs->hw.hfcpci.sctrl_r |= SCTRL_B1_ENA;
  1220. }
  1221. if (fifo2) {
  1222. cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B2;
  1223. cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
  1224. cs->hw.hfcpci.ctmt |= 2;
  1225. cs->hw.hfcpci.conn &= ~0x18;
  1226. } else {
  1227. cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B1;
  1228. cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
  1229. cs->hw.hfcpci.ctmt |= 1;
  1230. cs->hw.hfcpci.conn &= ~0x03;
  1231. }
  1232. break;
  1233. case (L1_MODE_HDLC):
  1234. hfcpci_clear_fifo_rx(cs, fifo2);
  1235. hfcpci_clear_fifo_tx(cs, fifo2);
  1236. if (bc) {
  1237. cs->hw.hfcpci.sctrl |= SCTRL_B2_ENA;
  1238. cs->hw.hfcpci.sctrl_r |= SCTRL_B2_ENA;
  1239. } else {
  1240. cs->hw.hfcpci.sctrl |= SCTRL_B1_ENA;
  1241. cs->hw.hfcpci.sctrl_r |= SCTRL_B1_ENA;
  1242. }
  1243. if (fifo2) {
  1244. cs->hw.hfcpci.last_bfifo_cnt[1] = 0;
  1245. cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B2;
  1246. cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
  1247. cs->hw.hfcpci.ctmt &= ~2;
  1248. cs->hw.hfcpci.conn &= ~0x18;
  1249. } else {
  1250. cs->hw.hfcpci.last_bfifo_cnt[0] = 0;
  1251. cs->hw.hfcpci.fifo_en |= HFCPCI_FIFOEN_B1;
  1252. cs->hw.hfcpci.int_m1 |= (HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
  1253. cs->hw.hfcpci.ctmt &= ~1;
  1254. cs->hw.hfcpci.conn &= ~0x03;
  1255. }
  1256. break;
  1257. case (L1_MODE_EXTRN):
  1258. if (bc) {
  1259. cs->hw.hfcpci.conn |= 0x10;
  1260. cs->hw.hfcpci.sctrl |= SCTRL_B2_ENA;
  1261. cs->hw.hfcpci.sctrl_r |= SCTRL_B2_ENA;
  1262. cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B2;
  1263. cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B2TRANS + HFCPCI_INTS_B2REC);
  1264. } else {
  1265. cs->hw.hfcpci.conn |= 0x02;
  1266. cs->hw.hfcpci.sctrl |= SCTRL_B1_ENA;
  1267. cs->hw.hfcpci.sctrl_r |= SCTRL_B1_ENA;
  1268. cs->hw.hfcpci.fifo_en &= ~HFCPCI_FIFOEN_B1;
  1269. cs->hw.hfcpci.int_m1 &= ~(HFCPCI_INTS_B1TRANS + HFCPCI_INTS_B1REC);
  1270. }
  1271. break;
  1272. }
  1273. Write_hfc(cs, HFCPCI_SCTRL_E, cs->hw.hfcpci.sctrl_e);
  1274. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1275. Write_hfc(cs, HFCPCI_FIFO_EN, cs->hw.hfcpci.fifo_en);
  1276. Write_hfc(cs, HFCPCI_SCTRL, cs->hw.hfcpci.sctrl);
  1277. Write_hfc(cs, HFCPCI_SCTRL_R, cs->hw.hfcpci.sctrl_r);
  1278. Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt);
  1279. Write_hfc(cs, HFCPCI_CONNECT, cs->hw.hfcpci.conn);
  1280. }
  1281. /******************************/
  1282. /* Layer2 -> Layer 1 Transfer */
  1283. /******************************/
  1284. static void
  1285. hfcpci_l2l1(struct PStack *st, int pr, void *arg)
  1286. {
  1287. struct BCState *bcs = st->l1.bcs;
  1288. u_long flags;
  1289. struct sk_buff *skb = arg;
  1290. switch (pr) {
  1291. case (PH_DATA | REQUEST):
  1292. spin_lock_irqsave(&bcs->cs->lock, flags);
  1293. if (bcs->tx_skb) {
  1294. skb_queue_tail(&bcs->squeue, skb);
  1295. } else {
  1296. bcs->tx_skb = skb;
  1297. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1298. bcs->cs->BC_Send_Data(bcs);
  1299. }
  1300. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1301. break;
  1302. case (PH_PULL | INDICATION):
  1303. spin_lock_irqsave(&bcs->cs->lock, flags);
  1304. if (bcs->tx_skb) {
  1305. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1306. printk(KERN_WARNING "hfc_l2l1: this shouldn't happen\n");
  1307. break;
  1308. }
  1309. // test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  1310. bcs->tx_skb = skb;
  1311. bcs->cs->BC_Send_Data(bcs);
  1312. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1313. break;
  1314. case (PH_PULL | REQUEST):
  1315. if (!bcs->tx_skb) {
  1316. test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1317. st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
  1318. } else
  1319. test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
  1320. break;
  1321. case (PH_ACTIVATE | REQUEST):
  1322. spin_lock_irqsave(&bcs->cs->lock, flags);
  1323. test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
  1324. mode_hfcpci(bcs, st->l1.mode, st->l1.bc);
  1325. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1326. l1_msg_b(st, pr, arg);
  1327. break;
  1328. case (PH_DEACTIVATE | REQUEST):
  1329. l1_msg_b(st, pr, arg);
  1330. break;
  1331. case (PH_DEACTIVATE | CONFIRM):
  1332. spin_lock_irqsave(&bcs->cs->lock, flags);
  1333. test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
  1334. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1335. mode_hfcpci(bcs, 0, st->l1.bc);
  1336. spin_unlock_irqrestore(&bcs->cs->lock, flags);
  1337. st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
  1338. break;
  1339. }
  1340. }
  1341. /******************************************/
  1342. /* deactivate B-channel access and queues */
  1343. /******************************************/
  1344. static void
  1345. close_hfcpci(struct BCState *bcs)
  1346. {
  1347. mode_hfcpci(bcs, 0, bcs->channel);
  1348. if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
  1349. skb_queue_purge(&bcs->rqueue);
  1350. skb_queue_purge(&bcs->squeue);
  1351. if (bcs->tx_skb) {
  1352. dev_kfree_skb_any(bcs->tx_skb);
  1353. bcs->tx_skb = NULL;
  1354. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1355. }
  1356. }
  1357. }
  1358. /*************************************/
  1359. /* init B-channel queues and control */
  1360. /*************************************/
  1361. static int
  1362. open_hfcpcistate(struct IsdnCardState *cs, struct BCState *bcs)
  1363. {
  1364. if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
  1365. skb_queue_head_init(&bcs->rqueue);
  1366. skb_queue_head_init(&bcs->squeue);
  1367. }
  1368. bcs->tx_skb = NULL;
  1369. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  1370. bcs->event = 0;
  1371. bcs->tx_cnt = 0;
  1372. return (0);
  1373. }
  1374. /*********************************/
  1375. /* inits the stack for B-channel */
  1376. /*********************************/
  1377. static int
  1378. setstack_2b(struct PStack *st, struct BCState *bcs)
  1379. {
  1380. bcs->channel = st->l1.bc;
  1381. if (open_hfcpcistate(st->l1.hardware, bcs))
  1382. return (-1);
  1383. st->l1.bcs = bcs;
  1384. st->l2.l2l1 = hfcpci_l2l1;
  1385. setstack_manager(st);
  1386. bcs->st = st;
  1387. setstack_l1_B(st);
  1388. return (0);
  1389. }
  1390. /***************************/
  1391. /* handle L1 state changes */
  1392. /***************************/
  1393. static void
  1394. hfcpci_bh(struct work_struct *work)
  1395. {
  1396. struct IsdnCardState *cs =
  1397. container_of(work, struct IsdnCardState, tqueue);
  1398. u_long flags;
  1399. // struct PStack *stptr;
  1400. if (test_and_clear_bit(D_L1STATECHANGE, &cs->event)) {
  1401. if (!cs->hw.hfcpci.nt_mode)
  1402. switch (cs->dc.hfcpci.ph_state) {
  1403. case (0):
  1404. l1_msg(cs, HW_RESET | INDICATION, NULL);
  1405. break;
  1406. case (3):
  1407. l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
  1408. break;
  1409. case (8):
  1410. l1_msg(cs, HW_RSYNC | INDICATION, NULL);
  1411. break;
  1412. case (6):
  1413. l1_msg(cs, HW_INFO2 | INDICATION, NULL);
  1414. break;
  1415. case (7):
  1416. l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
  1417. break;
  1418. default:
  1419. break;
  1420. } else {
  1421. spin_lock_irqsave(&cs->lock, flags);
  1422. switch (cs->dc.hfcpci.ph_state) {
  1423. case (2):
  1424. if (cs->hw.hfcpci.nt_timer < 0) {
  1425. cs->hw.hfcpci.nt_timer = 0;
  1426. cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_TIMER;
  1427. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1428. /* Clear already pending ints */
  1429. if (Read_hfc(cs, HFCPCI_INT_S1));
  1430. Write_hfc(cs, HFCPCI_STATES, 4 | HFCPCI_LOAD_STATE);
  1431. udelay(10);
  1432. Write_hfc(cs, HFCPCI_STATES, 4);
  1433. cs->dc.hfcpci.ph_state = 4;
  1434. } else {
  1435. cs->hw.hfcpci.int_m1 |= HFCPCI_INTS_TIMER;
  1436. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1437. cs->hw.hfcpci.ctmt &= ~HFCPCI_AUTO_TIMER;
  1438. cs->hw.hfcpci.ctmt |= HFCPCI_TIM3_125;
  1439. Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt | HFCPCI_CLTIMER);
  1440. Write_hfc(cs, HFCPCI_CTMT, cs->hw.hfcpci.ctmt | HFCPCI_CLTIMER);
  1441. cs->hw.hfcpci.nt_timer = NT_T1_COUNT;
  1442. Write_hfc(cs, HFCPCI_STATES, 2 | HFCPCI_NT_G2_G3); /* allow G2 -> G3 transition */
  1443. }
  1444. break;
  1445. case (1):
  1446. case (3):
  1447. case (4):
  1448. cs->hw.hfcpci.nt_timer = 0;
  1449. cs->hw.hfcpci.int_m1 &= ~HFCPCI_INTS_TIMER;
  1450. Write_hfc(cs, HFCPCI_INT_M1, cs->hw.hfcpci.int_m1);
  1451. break;
  1452. default:
  1453. break;
  1454. }
  1455. spin_unlock_irqrestore(&cs->lock, flags);
  1456. }
  1457. }
  1458. if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
  1459. DChannel_proc_rcv(cs);
  1460. if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
  1461. DChannel_proc_xmt(cs);
  1462. }
  1463. /********************************/
  1464. /* called for card init message */
  1465. /********************************/
  1466. static void
  1467. inithfcpci(struct IsdnCardState *cs)
  1468. {
  1469. cs->bcs[0].BC_SetStack = setstack_2b;
  1470. cs->bcs[1].BC_SetStack = setstack_2b;
  1471. cs->bcs[0].BC_Close = close_hfcpci;
  1472. cs->bcs[1].BC_Close = close_hfcpci;
  1473. cs->dbusytimer.function = (void *) hfcpci_dbusy_timer;
  1474. cs->dbusytimer.data = (long) cs;
  1475. init_timer(&cs->dbusytimer);
  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. cs->hw.hfcpci.timer.function = (void *) hfcpci_Timer;
  1621. cs->hw.hfcpci.timer.data = (long) cs;
  1622. init_timer(&cs->hw.hfcpci.timer);
  1623. cs->cardmsg = &hfcpci_card_msg;
  1624. cs->auxcmd = &hfcpci_auxcmd;
  1625. spin_unlock_irqrestore(&cs->lock, flags);
  1626. return (1);
  1627. }