tor2.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538
  1. /*
  2. * Tormenta 2 Quad-T1 PCI Driver
  3. *
  4. * Written by Mark Spencer <markster@digium.com>
  5. * Based on previous works, designs, and archetectures conceived and
  6. * written by Jim Dixon <jim@lambdatel.com>.
  7. *
  8. * Copyright (C) 2001 Jim Dixon / Zapata Telephony.
  9. * Copyright (C) 2001-2008, Digium, Inc.
  10. *
  11. */
  12. /*
  13. * See http://www.asterisk.org for more information about
  14. * the Asterisk project. Please do not directly contact
  15. * any of the maintainers of this project for assistance;
  16. * the project provides a web site, mailing lists and IRC
  17. * channels for your use.
  18. *
  19. * This program is free software, distributed under the terms of
  20. * the GNU General Public License Version 2 as published by the
  21. * Free Software Foundation. See the LICENSE file included with
  22. * this program for more details.
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/errno.h>
  26. #include <linux/module.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/sched.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/moduleparam.h>
  32. #include <linux/slab.h>
  33. #include <dahdi/kernel.h>
  34. #define NEED_PCI_IDS
  35. #include "tor2-hw.h"
  36. #include "tor2fw.h"
  37. /*
  38. * Tasklets provide better system interactive response at the cost of the
  39. * possibility of losing a frame of data at very infrequent intervals. If
  40. * you are more concerned with the performance of your machine, enable the
  41. * tasklets. If you are strict about absolutely no drops, then do not enable
  42. * tasklets.
  43. */
  44. /* #define ENABLE_TASKLETS */
  45. /* this stuff needs to work for 64 bit systems, however using the macro causes
  46. it to take twice as long */
  47. /* #define FIXTHISFOR64 */ /* as of now, un-comment for 32 bit only system */
  48. #define SPANS_PER_CARD 4
  49. #define MAX_SPANS 16
  50. #define FLAG_STARTED (1 << 0)
  51. #define TYPE_T1 1 /* is a T1 card */
  52. #define TYPE_E1 2 /* is an E1 card */
  53. struct tor2_chan {
  54. /* Private pointer for channel. We want to know our
  55. channel and span */
  56. struct tor2 *tor;
  57. int span; /* Index from 0 */
  58. };
  59. struct tor2_span {
  60. /* Private pointer for span. We want to know our
  61. span number and pointer to the tor device */
  62. struct tor2 *tor;
  63. int span; /* Index from 0 */
  64. struct dahdi_span dahdi_span;
  65. };
  66. struct tor2 {
  67. /* This structure exists one per card */
  68. struct pci_dev *pci; /* Pointer to PCI device */
  69. int num; /* Which card we are */
  70. int syncsrc; /* active sync source */
  71. int syncs[SPANS_PER_CARD]; /* sync sources */
  72. int psyncs[SPANS_PER_CARD]; /* span-relative sync sources */
  73. int alarmtimer[SPANS_PER_CARD]; /* Alarm timer */
  74. char *type; /* Type of tormenta 2 card */
  75. int irq; /* IRQ used by device */
  76. int order; /* Order */
  77. int flags; /* Device flags */
  78. int syncpos[SPANS_PER_CARD]; /* span-relative sync sources */
  79. int master; /* Are we master */
  80. unsigned long plx_region; /* phy addr of PCI9030 registers */
  81. unsigned long plx_len; /* length of PLX window */
  82. __iomem volatile unsigned short *plx; /* Virtual representation of local space */
  83. unsigned long xilinx32_region; /* 32 bit Region allocated to Xilinx */
  84. unsigned long xilinx32_len; /* Length of 32 bit Xilinx region */
  85. __iomem volatile unsigned int *mem32; /* Virtual representation of 32 bit Xilinx memory area */
  86. unsigned long xilinx8_region; /* 8 bit Region allocated to Xilinx */
  87. unsigned long xilinx8_len; /* Length of 8 bit Xilinx region */
  88. __iomem volatile unsigned char *mem8; /* Virtual representation of 8 bit Xilinx memory area */
  89. struct dahdi_device *ddev;
  90. struct tor2_span tspans[SPANS_PER_CARD]; /* Span data */
  91. struct dahdi_chan **chans[SPANS_PER_CARD]; /* Pointers to card channels */
  92. struct tor2_chan tchans[32 * SPANS_PER_CARD]; /* Channel user data */
  93. unsigned char txsigs[SPANS_PER_CARD][16]; /* Copy of tx sig registers */
  94. int loopupcnt[SPANS_PER_CARD]; /* loop up code counter */
  95. int loopdowncnt[SPANS_PER_CARD];/* loop down code counter */
  96. int spansstarted; /* number of spans started */
  97. spinlock_t lock; /* lock context */
  98. unsigned char leds; /* copy of LED register */
  99. unsigned char ec_chunk1[SPANS_PER_CARD][32][DAHDI_CHUNKSIZE]; /* first EC chunk buffer */
  100. unsigned char ec_chunk2[SPANS_PER_CARD][32][DAHDI_CHUNKSIZE]; /* second EC chunk buffer */
  101. #ifdef ENABLE_TASKLETS
  102. int taskletrun;
  103. int taskletsched;
  104. int taskletpending;
  105. int taskletexec;
  106. int txerrors;
  107. struct tasklet_struct tor2_tlet;
  108. #endif
  109. int cardtype; /* card type, T1 or E1 */
  110. unsigned int *datxlt; /* pointer to datxlt structure */
  111. unsigned int passno; /* number of interrupt passes */
  112. };
  113. #define t1out(tor, span, reg, val) \
  114. writeb(val, &tor->mem8[((span - 1) * 0x100) + reg])
  115. #define t1in(tor, span, reg) readb(&tor->mem8[((span - 1) * 0x100) + reg])
  116. #ifdef ENABLE_TASKLETS
  117. static void tor2_tasklet(unsigned long data);
  118. #endif
  119. #define GPIOC (PLX_LOC_GPIOC >> 1) /* word-oriented address for PLX GPIOC reg. (32 bit reg.) */
  120. #define LAS2BRD (0x30 >> 1)
  121. #define LAS3BRD (0x34 >> 1)
  122. #define INTCSR (0x4c >> 1) /* word-oriented address for PLX INTCSR reg. */
  123. #define PLX_INTENA 0x43 /* enable, hi-going, level trigger */
  124. #define SYNCREG 0x400
  125. #define CTLREG 0x401
  126. #define LEDREG 0x402
  127. #define STATREG 0x400
  128. #define SWREG 0x401
  129. #define CTLREG1 0x404
  130. #define INTENA (1 + ((loopback & 3) << 5))
  131. #define OUTBIT (2 + ((loopback & 3) << 5))
  132. #define E1DIV 0x10
  133. #define INTACK (0x80 + ((loopback & 3) << 5))
  134. #define INTACTIVE 2
  135. #define MASTER (1 << 3)
  136. /* un-define this if you dont want NON-REV A hardware support */
  137. /* #define NONREVA 1 */
  138. #define SYNCSELF 0
  139. #define SYNC1 1
  140. #define SYNC2 2
  141. #define SYNC3 3
  142. #define SYNC4 4
  143. #define SYNCEXTERN 5
  144. #define LEDRED 2
  145. #define LEDGREEN 1
  146. #define MAX_TOR_CARDS 64
  147. static struct tor2 *cards[MAX_TOR_CARDS];
  148. /* signalling bits */
  149. #define TOR_ABIT 8
  150. #define TOR_BBIT 4
  151. static int debug;
  152. static int japan;
  153. static int loopback;
  154. static int highestorder;
  155. static int timingcable;
  156. static void set_clear(struct tor2 *tor);
  157. static int tor2_startup(struct file *file, struct dahdi_span *span);
  158. static int tor2_shutdown(struct dahdi_span *span);
  159. static int tor2_rbsbits(struct dahdi_chan *chan, int bits);
  160. static int tor2_maint(struct dahdi_span *span, int cmd);
  161. static int tor2_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long data);
  162. DAHDI_IRQ_HANDLER(tor2_intr);
  163. /* translations of data channels for 24 channels in a 32 bit PCM highway */
  164. static unsigned datxlt_t1[] = {
  165. 1 ,2 ,3 ,5 ,6 ,7 ,9 ,10,11,13,14,15,17,18,19,21,22,23,25,26,27,29,30,31 };
  166. /* translations of data channels for 30/31 channels in a 32 bit PCM highway */
  167. static unsigned datxlt_e1[] = {
  168. 1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
  169. 25,26,27,28,29,30,31 };
  170. static int tor2_spanconfig(struct file *file, struct dahdi_span *span,
  171. struct dahdi_lineconfig *lc)
  172. {
  173. int i;
  174. struct tor2_span *p = container_of(span, struct tor2_span, dahdi_span);
  175. if (debug)
  176. printk(KERN_INFO "Tor2: Configuring span %d\n", span->spanno);
  177. if ((lc->sync < 0) || (lc->sync > SPANS_PER_CARD)) {
  178. printk(KERN_WARNING "%s %d: invalid span timing value %d.\n",
  179. THIS_MODULE->name, span->spanno, lc->sync);
  180. return -EINVAL;
  181. }
  182. span->syncsrc = p->tor->syncsrc;
  183. /* remove this span number from the current sync sources, if there */
  184. for (i = 0; i < SPANS_PER_CARD; i++) {
  185. if (p->tor->syncs[i] == span->spanno) {
  186. p->tor->syncs[i] = 0;
  187. p->tor->psyncs[i] = 0;
  188. }
  189. }
  190. p->tor->syncpos[p->span] = lc->sync;
  191. /* if a sync src, put it in the proper place */
  192. if (lc->sync) {
  193. p->tor->syncs[lc->sync - 1] = span->spanno;
  194. p->tor->psyncs[lc->sync - 1] = p->span + 1;
  195. }
  196. /* If we're already running, then go ahead and apply the changes */
  197. if (span->flags & DAHDI_FLAG_RUNNING)
  198. return tor2_startup(file, span);
  199. return 0;
  200. }
  201. static int tor2_chanconfig(struct file *file,
  202. struct dahdi_chan *chan, int sigtype)
  203. {
  204. int alreadyrunning;
  205. unsigned long flags;
  206. struct tor2_chan *p = chan->pvt;
  207. alreadyrunning = chan->span->flags & DAHDI_FLAG_RUNNING;
  208. if (debug) {
  209. if (alreadyrunning)
  210. printk(KERN_INFO "Tor2: Reconfigured channel %d (%s) sigtype %d\n", chan->channo, chan->name, sigtype);
  211. else
  212. printk(KERN_INFO "Tor2: Configured channel %d (%s) sigtype %d\n", chan->channo, chan->name, sigtype);
  213. }
  214. /* nothing more to do if an E1 */
  215. if (p->tor->cardtype == TYPE_E1) return 0;
  216. spin_lock_irqsave(&p->tor->lock, flags);
  217. if (alreadyrunning)
  218. set_clear(p->tor);
  219. spin_unlock_irqrestore(&p->tor->lock, flags);
  220. return 0;
  221. }
  222. static const struct dahdi_span_ops tor2_span_ops = {
  223. .owner = THIS_MODULE,
  224. .spanconfig = tor2_spanconfig,
  225. .chanconfig = tor2_chanconfig,
  226. .startup = tor2_startup,
  227. .shutdown = tor2_shutdown,
  228. .rbsbits = tor2_rbsbits,
  229. .maint = tor2_maint,
  230. .ioctl = tor2_ioctl,
  231. };
  232. static void init_spans(struct tor2 *tor)
  233. {
  234. int x, y, c;
  235. /* TODO: a debug printk macro */
  236. for (x = 0; x < SPANS_PER_CARD; x++) {
  237. struct dahdi_span *const s = &tor->tspans[x].dahdi_span;
  238. sprintf(s->name, "Tor2/%d/%d", tor->num, x + 1);
  239. snprintf(s->desc, sizeof(s->desc) - 1,
  240. "Tormenta 2 (PCI) Quad %s Card %d Span %d",
  241. (tor->cardtype == TYPE_T1) ? "T1" : "E1", tor->num, x + 1);
  242. if (tor->cardtype == TYPE_T1) {
  243. s->channels = 24;
  244. s->deflaw = DAHDI_LAW_MULAW;
  245. s->linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS | DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF;
  246. s->spantype = SPANTYPE_DIGITAL_T1;
  247. } else {
  248. s->channels = 31;
  249. s->deflaw = DAHDI_LAW_ALAW;
  250. s->linecompat = DAHDI_CONFIG_HDB3 | DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4;
  251. s->spantype = SPANTYPE_DIGITAL_E1;
  252. }
  253. s->chans = tor->chans[x];
  254. s->flags = DAHDI_FLAG_RBS;
  255. s->ops = &tor2_span_ops;
  256. tor->tspans[x].tor = tor;
  257. tor->tspans[x].span = x;
  258. for (y = 0; y < s->channels; y++) {
  259. struct dahdi_chan *mychans = tor->chans[x][y];
  260. sprintf(mychans->name, "Tor2/%d/%d/%d", tor->num, x + 1, y + 1);
  261. mychans->sigcap = DAHDI_SIG_EM | DAHDI_SIG_CLEAR | DAHDI_SIG_FXSLS | DAHDI_SIG_FXSGS | DAHDI_SIG_FXSKS |
  262. DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS | DAHDI_SIG_FXOKS | DAHDI_SIG_CAS | DAHDI_SIG_SF | DAHDI_SIG_EM_E1;
  263. c = (x * s->channels) + y;
  264. mychans->pvt = &tor->tchans[c];
  265. mychans->chanpos = y + 1;
  266. tor->tchans[c].span = x;
  267. tor->tchans[c].tor = tor;
  268. }
  269. }
  270. }
  271. static int __devinit tor2_launch(struct tor2 *tor)
  272. {
  273. int res;
  274. struct dahdi_span *s;
  275. int i;
  276. if (test_bit(DAHDI_FLAGBIT_REGISTERED, &tor->tspans[0].dahdi_span.flags))
  277. return 0;
  278. tor->ddev = dahdi_create_device();
  279. tor->ddev->location = kasprintf(GFP_KERNEL, "PCI Bus %02d Slot %02d",
  280. tor->pci->bus->number,
  281. PCI_SLOT(tor->pci->devfn) + 1);
  282. if (!tor->ddev->location)
  283. return -ENOMEM;
  284. printk(KERN_INFO "Tor2: Launching card: %d\n", tor->order);
  285. for (i = 0; i < SPANS_PER_CARD; ++i) {
  286. s = &tor->tspans[i].dahdi_span;
  287. list_add_tail(&s->device_node, &tor->ddev->spans);
  288. }
  289. res = dahdi_register_device(tor->ddev, &tor->pci->dev);
  290. if (res) {
  291. dev_err(&tor->pci->dev, "Unable to register with DAHDI.\n");
  292. return res;
  293. }
  294. writew(PLX_INTENA, &tor->plx[INTCSR]); /* enable PLX interrupt */
  295. #ifdef ENABLE_TASKLETS
  296. tasklet_init(&tor->tor2_tlet, tor2_tasklet, (unsigned long)tor);
  297. #endif
  298. return 0;
  299. }
  300. static void free_tor(struct tor2 *tor)
  301. {
  302. unsigned int x, f;
  303. for (x = 0; x < SPANS_PER_CARD; x++) {
  304. for (f = 0; f < (tor->cardtype == TYPE_E1 ? 31 : 24); f++) {
  305. if (tor->chans[x][f]) {
  306. kfree(tor->chans[x][f]);
  307. }
  308. }
  309. if (tor->chans[x])
  310. kfree(tor->chans[x]);
  311. }
  312. kfree(tor->ddev->location);
  313. dahdi_free_device(tor->ddev);
  314. kfree(tor);
  315. }
  316. static int __devinit tor2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  317. {
  318. int res,x,f;
  319. int ret = -ENODEV;
  320. struct tor2 *tor;
  321. unsigned long endjif;
  322. __iomem volatile unsigned long *gpdata_io, *lasdata_io;
  323. unsigned long gpdata,lasdata;
  324. res = pci_enable_device(pdev);
  325. if (res)
  326. return res;
  327. tor = kmalloc(sizeof(struct tor2), GFP_KERNEL);
  328. if (!tor)
  329. return -ENOMEM;
  330. memset(tor,0,sizeof(struct tor2));
  331. spin_lock_init(&tor->lock);
  332. /* Load the resources */
  333. tor->pci = pdev;
  334. tor->irq = pdev->irq;
  335. if (tor->irq < 1) {
  336. printk(KERN_ERR "No IRQ allocated for device\n");
  337. goto err_out_free_tor;
  338. }
  339. tor->plx_region = pci_resource_start(pdev, 0);
  340. tor->plx_len = pci_resource_len(pdev, 0);
  341. tor->plx = ioremap(tor->plx_region, tor->plx_len);
  342. /* We don't use the I/O space, so we dont do anything with section 1 */
  343. tor->xilinx32_region = pci_resource_start(pdev, 2);
  344. tor->xilinx32_len = pci_resource_len(pdev, 2);
  345. tor->mem32 = ioremap(tor->xilinx32_region, tor->xilinx32_len);
  346. tor->xilinx8_region = pci_resource_start(pdev, 3);
  347. tor->xilinx8_len = pci_resource_len(pdev, 3);
  348. tor->mem8 = ioremap(tor->xilinx8_region, tor->xilinx8_len);
  349. /* Record what type */
  350. tor->type = (char *)ent->driver_data;
  351. /* Verify existence and accuracy of resources */
  352. if (!tor->plx_region || !tor->plx ||
  353. (pci_resource_flags(pdev, 0) & IORESOURCE_IO)) {
  354. printk(KERN_ERR "Invalid PLX 9030 Base resource\n");
  355. goto err_out_free_tor;
  356. }
  357. if (!tor->xilinx32_region || !tor->mem32 ||
  358. (pci_resource_flags(pdev, 2) & IORESOURCE_IO)) {
  359. printk(KERN_ERR "Invalid Xilinx 32 bit Base resource\n");
  360. goto err_out_free_tor;
  361. }
  362. if (!tor->xilinx8_region || !tor->mem8 ||
  363. (pci_resource_flags(pdev, 3) & IORESOURCE_IO)) {
  364. printk(KERN_ERR "Invalid Xilinx 8 bit Base resource\n");
  365. goto err_out_free_tor;
  366. }
  367. /* Request regions */
  368. if (!request_mem_region(tor->plx_region, tor->plx_len, tor->type)) {
  369. printk(KERN_ERR "Unable to reserve PLX memory %08lx window at %08lx\n",
  370. tor->plx_len, tor->plx_region);
  371. goto err_out_free_tor;
  372. }
  373. if (!request_mem_region(tor->xilinx32_region, tor->xilinx32_len, tor->type)) {
  374. printk(KERN_ERR "Unable to reserve Xilinx 32 bit memory %08lx window at %08lx\n",
  375. tor->xilinx32_len, tor->xilinx32_region);
  376. goto err_out_release_plx_region;
  377. }
  378. if (!request_mem_region(tor->xilinx8_region, tor->xilinx8_len, tor->type)) {
  379. printk(KERN_ERR "Unable to reserve Xilinx memory %08lx window at %08lx\n",
  380. tor->xilinx8_len, tor->xilinx8_region);
  381. goto err_out_release_plx_region;
  382. }
  383. pci_set_drvdata(pdev, tor);
  384. printk(KERN_INFO "Detected %s at 0x%lx/0x%lx irq %d\n", tor->type,
  385. tor->xilinx32_region, tor->xilinx8_region,tor->irq);
  386. for (x = 0; x < MAX_TOR_CARDS; x++) {
  387. if (!cards[x]) break;
  388. }
  389. if (x >= MAX_TOR_CARDS) {
  390. printk(KERN_ERR "No cards[] slot available!!\n");
  391. goto err_out_release_all;
  392. }
  393. tor->num = x;
  394. cards[x] = tor;
  395. /* start programming mode */
  396. gpdata_io = (__iomem unsigned long *) &tor->plx[GPIOC];
  397. gpdata = readl(gpdata_io);
  398. gpdata |= GPIO_WRITE; /* make sure WRITE is not asserted */
  399. writel(gpdata, gpdata_io);
  400. gpdata &= ~GPIO_PROGRAM; /* activate the PROGRAM signal */
  401. writel(gpdata, gpdata_io);
  402. /* wait for INIT and DONE to go low */
  403. endjif = jiffies + 10;
  404. while (readl(gpdata_io) & (GPIO_INIT | GPIO_DONE) &&
  405. (jiffies <= endjif)) {
  406. ;
  407. }
  408. if (endjif < jiffies) {
  409. printk(KERN_ERR "Timeout waiting for INIT and DONE to go low\n");
  410. goto err_out_release_all;
  411. }
  412. if (debug) printk(KERN_ERR "fwload: Init and done gone to low\n");
  413. gpdata |= GPIO_PROGRAM;
  414. writel(gpdata, gpdata_io); /* de-activate the PROGRAM signal */
  415. /* wait for INIT to go high (clearing done */
  416. endjif = jiffies + 10;
  417. while (!(readl(gpdata_io) & GPIO_INIT) && (jiffies <= endjif))
  418. ;
  419. if (endjif < jiffies) {
  420. printk(KERN_ERR "Timeout waiting for INIT to go high\n");
  421. goto err_out_release_all;
  422. }
  423. if (debug) printk(KERN_ERR "fwload: Init went high (clearing done)\nNow loading...\n");
  424. /* assert WRITE signal */
  425. gpdata &= ~GPIO_WRITE;
  426. writel(gpdata, gpdata_io);
  427. for (x = 0; x < sizeof(tor2fw); x++)
  428. {
  429. /* write the byte */
  430. writeb(tor2fw[x], tor->mem8);
  431. /* if DONE signal, we're done, exit */
  432. if (readl(gpdata_io) & GPIO_DONE)
  433. break;
  434. /* if INIT drops, we're screwed, exit */
  435. if (!(readl(gpdata_io) & GPIO_INIT))
  436. break;
  437. }
  438. if (debug) printk(KERN_DEBUG "fwload: Transferred %d bytes into chip\n",x);
  439. /* Wait for FIFO to clear */
  440. endjif = jiffies + 2;
  441. while (jiffies < endjif); /* wait */
  442. /* de-assert write signal */
  443. gpdata |= GPIO_WRITE;
  444. writel(gpdata, gpdata_io);
  445. if (debug) printk(KERN_DEBUG "fwload: Loading done!\n");
  446. /* Wait for FIFO to clear */
  447. endjif = jiffies + 2;
  448. while (jiffies < endjif); /* wait */
  449. if (!(readl(gpdata_io) & GPIO_INIT))
  450. {
  451. printk(KERN_ERR "Drove Init low!! CRC Error!!!\n");
  452. goto err_out_release_all;
  453. }
  454. if (!(readl(gpdata_io) & GPIO_DONE))
  455. {
  456. printk(KERN_ERR "Did not get DONE signal. Short file maybe??\n");
  457. goto err_out_release_all;
  458. }
  459. printk(KERN_INFO "Xilinx Chip successfully loaded, configured and started!!\n");
  460. writeb(0, &tor->mem8[SYNCREG]);
  461. writeb(0, &tor->mem8[CTLREG]);
  462. writeb(0, &tor->mem8[CTLREG1]);
  463. writeb(0, &tor->mem8[LEDREG]);
  464. /* set the LA2BRD register so that we enable block transfer, read
  465. pre-fetch, and set to maximum read pre-fetch size */
  466. lasdata_io = (__iomem unsigned long *) &tor->plx[LAS2BRD];
  467. lasdata = readl(lasdata_io);
  468. lasdata |= 0x39;
  469. writel(lasdata, lasdata_io);
  470. /* set the LA3BRD register so that we enable block transfer */
  471. lasdata_io = (__iomem unsigned long *) &tor->plx[LAS3BRD];
  472. lasdata = readl(lasdata_io);
  473. lasdata |= 1;
  474. writel(lasdata, lasdata_io);
  475. /* check part revision data */
  476. x = t1in(tor,1,0xf) & 15;
  477. #ifdef NONREVA
  478. if (x > 3)
  479. {
  480. tor->mem8[CTLREG1] = NONREVA;
  481. }
  482. #endif
  483. for (x = 0; x < 256; x++)
  484. writel(0x7f7f7f7f, &tor->mem32[x]);
  485. if (request_irq(tor->irq, tor2_intr, IRQF_SHARED, "tor2", tor)) {
  486. printk(KERN_ERR "Unable to request tormenta IRQ %d\n", tor->irq);
  487. goto err_out_release_all;
  488. }
  489. if (t1in(tor,1,0xf) & 0x80) {
  490. printk(KERN_INFO "Tormenta 2 Quad E1/PRA Card\n");
  491. tor->cardtype = TYPE_E1;
  492. tor->datxlt = datxlt_e1;
  493. } else {
  494. printk(KERN_INFO "Tormenta 2 Quad T1/PRI Card\n");
  495. tor->cardtype = TYPE_T1;
  496. tor->datxlt = datxlt_t1;
  497. }
  498. for (x = 0; x < SPANS_PER_CARD; x++) {
  499. int num_chans = tor->cardtype == TYPE_E1 ? 31 : 24;
  500. if (!(tor->chans[x] = kmalloc(num_chans * sizeof(*tor->chans[x]), GFP_KERNEL))) {
  501. printk(KERN_ERR "tor2: Not enough memory for chans[%d]\n", x);
  502. ret = -ENOMEM;
  503. goto err_out_release_all;
  504. }
  505. for (f = 0; f < (num_chans); f++) {
  506. if (!(tor->chans[x][f] = kmalloc(sizeof(*tor->chans[x][f]), GFP_KERNEL))) {
  507. printk(KERN_ERR "tor2: Not enough memory for chans[%d][%d]\n",
  508. x, f);
  509. ret = -ENOMEM;
  510. goto err_out_release_all;
  511. }
  512. memset(tor->chans[x][f], 0, sizeof(*tor->chans[x][f]));
  513. }
  514. }
  515. init_spans(tor);
  516. tor->order = readb(&tor->mem8[SWREG]);
  517. printk(KERN_INFO "Detected Card number: %d\n", tor->order);
  518. /* Launch cards as appropriate */
  519. x = 0;
  520. for (;;) {
  521. /* Find a card to activate */
  522. f = 0;
  523. for (x=0;cards[x];x++) {
  524. if (cards[x]->order <= highestorder) {
  525. tor2_launch(cards[x]);
  526. if (cards[x]->order == highestorder)
  527. f = 1;
  528. }
  529. }
  530. /* If we found at least one, increment the highest order and search again, otherwise stop */
  531. if (f)
  532. highestorder++;
  533. else
  534. break;
  535. }
  536. return 0;
  537. err_out_release_all:
  538. release_mem_region(tor->xilinx32_region, tor->xilinx32_len);
  539. release_mem_region(tor->xilinx8_region, tor->xilinx8_len);
  540. err_out_release_plx_region:
  541. release_mem_region(tor->plx_region, tor->plx_len);
  542. err_out_free_tor:
  543. if (tor->plx) iounmap(tor->plx);
  544. if (tor->mem8) iounmap(tor->mem8);
  545. if (tor->mem32) iounmap(tor->mem32);
  546. if (tor) {
  547. free_tor(tor);
  548. }
  549. return ret;
  550. }
  551. static struct pci_driver tor2_driver;
  552. static void __devexit tor2_remove(struct pci_dev *pdev)
  553. {
  554. struct tor2 *tor;
  555. tor = pci_get_drvdata(pdev);
  556. if (!tor)
  557. BUG();
  558. writeb(0, &tor->mem8[SYNCREG]);
  559. writeb(0, &tor->mem8[CTLREG]);
  560. writeb(0, &tor->mem8[LEDREG]);
  561. writew(0, &tor->plx[INTCSR]);
  562. free_irq(tor->irq, tor);
  563. dahdi_unregister_device(tor->ddev);
  564. release_mem_region(tor->plx_region, tor->plx_len);
  565. release_mem_region(tor->xilinx32_region, tor->xilinx32_len);
  566. release_mem_region(tor->xilinx8_region, tor->xilinx8_len);
  567. if (tor->plx) iounmap(tor->plx);
  568. if (tor->mem8) iounmap(tor->mem8);
  569. if (tor->mem32) iounmap(tor->mem32);
  570. cards[tor->num] = NULL;
  571. pci_set_drvdata(pdev, NULL);
  572. free_tor(tor);
  573. }
  574. static struct pci_driver tor2_driver = {
  575. .name = "tormenta2",
  576. .probe = tor2_probe,
  577. .remove = __devexit_p(tor2_remove),
  578. .id_table = tor2_pci_ids,
  579. };
  580. static int __init tor2_init(void) {
  581. int res;
  582. res = dahdi_pci_module(&tor2_driver);
  583. printk(KERN_INFO "Registered Tormenta2 PCI\n");
  584. return res;
  585. }
  586. static void __exit tor2_cleanup(void) {
  587. pci_unregister_driver(&tor2_driver);
  588. printk(KERN_INFO "Unregistered Tormenta2\n");
  589. }
  590. static void set_clear(struct tor2 *tor)
  591. {
  592. int i,j,s;
  593. unsigned short val=0;
  594. for (s = 0; s < SPANS_PER_CARD; s++) {
  595. struct dahdi_span *span = &tor->tspans[s].dahdi_span;
  596. for (i = 0; i < 24; i++) {
  597. j = (i/8);
  598. if (span->chans[i]->flags & DAHDI_FLAG_CLEAR)
  599. val |= 1 << (i % 8);
  600. if ((i % 8)==7) {
  601. #if 0
  602. printk(KERN_DEBUG "Putting %d in register %02x on span %d\n",
  603. val, 0x39 + j, 1 + s);
  604. #endif
  605. t1out(tor,1 + s, 0x39 + j, val);
  606. val = 0;
  607. }
  608. }
  609. }
  610. }
  611. static int tor2_rbsbits(struct dahdi_chan *chan, int bits)
  612. {
  613. u_char m,c;
  614. int k,n,b;
  615. struct tor2_chan *p = chan->pvt;
  616. unsigned long flags;
  617. #if 0
  618. printk(KERN_DEBUG "Setting bits to %d on channel %s\n", bits, chan->name);
  619. #endif
  620. if (p->tor->cardtype == TYPE_E1) { /* do it E1 way */
  621. if (chan->chanpos == 16) return 0;
  622. n = chan->chanpos - 1;
  623. if (chan->chanpos > 16) n--;
  624. k = p->span;
  625. b = (n % 15) + 1;
  626. c = p->tor->txsigs[k][b];
  627. m = (n / 15) * 4; /* nibble selector */
  628. c &= (15 << m); /* keep the other nibble */
  629. c |= (bits & 15) << (4 - m); /* put our new nibble here */
  630. p->tor->txsigs[k][b] = c;
  631. /* output them to the chip */
  632. t1out(p->tor,k + 1,0x40 + b,c);
  633. return 0;
  634. }
  635. n = chan->chanpos - 1;
  636. k = p->span;
  637. b = (n / 8); /* get byte number */
  638. m = 1 << (n & 7); /* get mask */
  639. c = p->tor->txsigs[k][b];
  640. c &= ~m; /* clear mask bit */
  641. /* set mask bit, if bit is to be set */
  642. if (bits & DAHDI_ABIT) c |= m;
  643. p->tor->txsigs[k][b] = c;
  644. spin_lock_irqsave(&p->tor->lock, flags);
  645. t1out(p->tor,k + 1,0x70 + b,c);
  646. b += 3; /* now points to b bit stuff */
  647. /* get current signalling values */
  648. c = p->tor->txsigs[k][b];
  649. c &= ~m; /* clear mask bit */
  650. /* set mask bit, if bit is to be set */
  651. if (bits & DAHDI_BBIT) c |= m;
  652. /* save new signalling values */
  653. p->tor->txsigs[k][b] = c;
  654. /* output them into the chip */
  655. t1out(p->tor,k + 1,0x70 + b,c);
  656. b += 3; /* now points to c bit stuff */
  657. /* get current signalling values */
  658. c = p->tor->txsigs[k][b];
  659. c &= ~m; /* clear mask bit */
  660. /* set mask bit, if bit is to be set */
  661. if (bits & DAHDI_CBIT) c |= m;
  662. /* save new signalling values */
  663. p->tor->txsigs[k][b] = c;
  664. /* output them into the chip */
  665. t1out(p->tor,k + 1,0x70 + b,c);
  666. b += 3; /* now points to d bit stuff */
  667. /* get current signalling values */
  668. c = p->tor->txsigs[k][b];
  669. c &= ~m; /* clear mask bit */
  670. /* set mask bit, if bit is to be set */
  671. if (bits & DAHDI_DBIT) c |= m;
  672. /* save new signalling values */
  673. p->tor->txsigs[k][b] = c;
  674. /* output them into the chip */
  675. t1out(p->tor,k + 1,0x70 + b,c);
  676. spin_unlock_irqrestore(&p->tor->lock, flags);
  677. return 0;
  678. }
  679. static int tor2_shutdown(struct dahdi_span *span)
  680. {
  681. int i;
  682. int tspan;
  683. int wasrunning;
  684. unsigned long flags;
  685. struct tor2_span *const p = container_of(span, struct tor2_span, dahdi_span);
  686. struct tor2 *const tor = p->tor;
  687. tspan = p->span + 1;
  688. if (tspan < 0) {
  689. printk(KERN_DEBUG "Tor2: Span '%d' isn't us?\n", span->spanno);
  690. return -1;
  691. }
  692. spin_lock_irqsave(&tor->lock, flags);
  693. wasrunning = span->flags & DAHDI_FLAG_RUNNING;
  694. span->flags &= ~DAHDI_FLAG_RUNNING;
  695. /* Zero out all registers */
  696. if (tor->cardtype == TYPE_E1) {
  697. for (i = 0; i < 192; i++)
  698. t1out(tor, tspan, i, 0);
  699. } else {
  700. for (i = 0; i < 160; i++)
  701. t1out(tor, tspan, i, 0);
  702. }
  703. if (wasrunning)
  704. tor->spansstarted--;
  705. spin_unlock_irqrestore(&tor->lock, flags);
  706. if (!(tor->tspans[0].dahdi_span.flags & DAHDI_FLAG_RUNNING) &&
  707. !(tor->tspans[1].dahdi_span.flags & DAHDI_FLAG_RUNNING) &&
  708. !(tor->tspans[2].dahdi_span.flags & DAHDI_FLAG_RUNNING) &&
  709. !(tor->tspans[3].dahdi_span.flags & DAHDI_FLAG_RUNNING))
  710. /* No longer in use, disable interrupts */
  711. writeb(0, &tor->mem8[CTLREG]);
  712. if (debug)
  713. printk(KERN_DEBUG"Span %d (%s) shutdown\n", span->spanno, span->name);
  714. return 0;
  715. }
  716. static int tor2_startup(struct file *file, struct dahdi_span *span)
  717. {
  718. unsigned long endjif;
  719. int i;
  720. int tspan;
  721. unsigned long flags;
  722. char *coding;
  723. char *framing;
  724. char *crcing;
  725. int alreadyrunning;
  726. struct tor2_span *p = container_of(span, struct tor2_span, dahdi_span);
  727. tspan = p->span + 1;
  728. if (tspan < 0) {
  729. printk(KERN_DEBUG "Tor2: Span '%d' isn't us?\n", span->spanno);
  730. return -1;
  731. }
  732. spin_lock_irqsave(&p->tor->lock, flags);
  733. alreadyrunning = span->flags & DAHDI_FLAG_RUNNING;
  734. /* initialize the start value for the entire chunk of last ec buffer */
  735. for (i = 0; i < span->channels; i++)
  736. {
  737. memset(p->tor->ec_chunk1[p->span][i],
  738. DAHDI_LIN2X(0,span->chans[i]),DAHDI_CHUNKSIZE);
  739. memset(p->tor->ec_chunk2[p->span][i],
  740. DAHDI_LIN2X(0,span->chans[i]),DAHDI_CHUNKSIZE);
  741. }
  742. /* Force re-evaluation of the timing source */
  743. if (timingcable)
  744. p->tor->syncsrc = -1;
  745. if (p->tor->cardtype == TYPE_E1) { /* if this is an E1 card */
  746. unsigned char tcr1,ccr1,tcr2;
  747. if (!alreadyrunning) {
  748. writeb(SYNCSELF, &p->tor->mem8[SYNCREG]);
  749. writeb(E1DIV, &p->tor->mem8[CTLREG]);
  750. writeb(0, &p->tor->mem8[LEDREG]);
  751. /* Force re-evaluation of sync src */
  752. /* Zero out all registers */
  753. for (i = 0; i < 192; i++)
  754. t1out(p->tor,tspan, i, 0);
  755. /* Set up for Interleaved Serial Bus operation in byte mode */
  756. /* Set up all the spans every time, so we are sure they are
  757. in a consistent state. If we don't, a card without all
  758. its spans configured misbehaves in strange ways. */
  759. t1out(p->tor,1,0xb5,9);
  760. t1out(p->tor,2,0xb5,8);
  761. t1out(p->tor,3,0xb5,8);
  762. t1out(p->tor,4,0xb5,8);
  763. t1out(p->tor,tspan,0x1a,4); /* CCR2: set LOTCMC */
  764. for (i = 0; i <= 8; i++) t1out(p->tor,tspan,i,0);
  765. for (i = 0x10; i <= 0x4f; i++) if (i != 0x1a) t1out(p->tor,tspan,i,0);
  766. t1out(p->tor,tspan,0x10,0x20); /* RCR1: Rsync as input */
  767. t1out(p->tor,tspan,0x11,6); /* RCR2: Sysclk=2.048 Mhz */
  768. t1out(p->tor,tspan,0x12,9); /* TCR1: TSiS mode */
  769. }
  770. ccr1 = 0;
  771. crcing = "";
  772. tcr1 = 9; /* base TCR1 value: TSis mode */
  773. tcr2 = 0;
  774. if (span->lineconfig & DAHDI_CONFIG_CCS) {
  775. ccr1 |= 8; /* CCR1: Rx Sig mode: CCS */
  776. coding = "CCS";
  777. } else {
  778. tcr1 |= 0x20;
  779. coding = "CAS";
  780. }
  781. if (span->lineconfig & DAHDI_CONFIG_HDB3) {
  782. ccr1 |= 0x44; /* CCR1: TX and RX HDB3 */
  783. framing = "HDB3";
  784. } else framing = "AMI";
  785. if (span->lineconfig & DAHDI_CONFIG_CRC4) {
  786. ccr1 |= 0x11; /* CCR1: TX and TX CRC4 */
  787. tcr2 |= 0x02; /* TCR2: CRC4 bit auto */
  788. crcing = "/CRC4";
  789. }
  790. t1out(p->tor,tspan,0x12,tcr1);
  791. t1out(p->tor,tspan,0x13,tcr2);
  792. t1out(p->tor,tspan,0x14,ccr1);
  793. t1out(p->tor,tspan, 0x18, 0x20); /* 120 Ohm, normal */
  794. if (!alreadyrunning) {
  795. t1out(p->tor,tspan,0x1b,0x8a); /* CCR3: LIRST & TSCLKM */
  796. t1out(p->tor,tspan,0x20,0x1b); /* TAFR */
  797. t1out(p->tor,tspan,0x21,0x5f); /* TNAFR */
  798. t1out(p->tor,tspan,0x40,0xb); /* TSR1 */
  799. for (i = 0x41; i <= 0x4f; i++) t1out(p->tor,tspan,i,0x55);
  800. for (i = 0x22; i <= 0x25; i++) t1out(p->tor,tspan,i,0xff);
  801. /* Wait 100 ms */
  802. endjif = jiffies + 10;
  803. spin_unlock_irqrestore(&p->tor->lock, flags);
  804. while (jiffies < endjif); /* wait 100 ms */
  805. spin_lock_irqsave(&p->tor->lock, flags);
  806. t1out(p->tor,tspan,0x1b,0x9a); /* CCR3: set also ESR */
  807. t1out(p->tor,tspan,0x1b,0x82); /* CCR3: TSCLKM only now */
  808. span->flags |= DAHDI_FLAG_RUNNING;
  809. p->tor->spansstarted++;
  810. /* enable interrupts */
  811. writeb(INTENA | E1DIV, &p->tor->mem8[CTLREG]);
  812. }
  813. spin_unlock_irqrestore(&p->tor->lock, flags);
  814. if (debug) {
  815. if (alreadyrunning)
  816. printk(KERN_INFO "Tor2: Reconfigured span %d (%s/%s%s) 120 Ohms\n", span->spanno, coding, framing, crcing);
  817. else
  818. printk(KERN_INFO "Tor2: Startup span %d (%s/%s%s) 120 Ohms\n", span->spanno, coding, framing, crcing);
  819. }
  820. } else { /* is a T1 card */
  821. if (!alreadyrunning) {
  822. writeb(SYNCSELF, &p->tor->mem8[SYNCREG]);
  823. writeb(0, &p->tor->mem8[CTLREG]);
  824. writeb(0, &p->tor->mem8[LEDREG]);
  825. /* Zero out all registers */
  826. for (i = 0; i < 160; i++)
  827. t1out(p->tor,tspan, i, 0);
  828. /* Set up for Interleaved Serial Bus operation in byte mode */
  829. /* Set up all the spans every time, so we are sure they are
  830. in a consistent state. If we don't, a card without all
  831. its spans configured misbehaves in strange ways. */
  832. t1out(p->tor,1,0x94,9);
  833. t1out(p->tor,2,0x94,8);
  834. t1out(p->tor,3,0x94,8);
  835. t1out(p->tor,4,0x94,8);
  836. /* Full-on Sync required (RCR1) */
  837. t1out(p->tor,tspan, 0x2b, 8);
  838. /* RSYNC is an input (RCR2) */
  839. t1out(p->tor,tspan, 0x2c, 8);
  840. /* RBS enable (TCR1) */
  841. t1out(p->tor,tspan, 0x35, 0x10);
  842. /* TSYNC to be output (TCR2) */
  843. t1out(p->tor,tspan, 0x36, 4);
  844. /* Tx & Rx Elastic store, sysclk(s) = 2.048 mhz, loopback controls (CCR1) */
  845. t1out(p->tor,tspan, 0x37, 0x9c);
  846. /* Set up received loopup and loopdown codes */
  847. t1out(p->tor,tspan, 0x12, 0x22);
  848. t1out(p->tor,tspan, 0x14, 0x80);
  849. t1out(p->tor,tspan, 0x15, 0x80);
  850. /* Setup japanese mode if appropriate */
  851. t1out(p->tor,tspan,0x19,(japan ? 0x80 : 0x00)); /* no local loop */
  852. t1out(p->tor,tspan,0x1e,(japan ? 0x80 : 0x00)); /* no local loop */
  853. }
  854. /* Enable F bits pattern */
  855. i = 0x20;
  856. if (span->lineconfig & DAHDI_CONFIG_ESF)
  857. i = 0x88;
  858. if (span->lineconfig & DAHDI_CONFIG_B8ZS)
  859. i |= 0x44;
  860. t1out(p->tor,tspan, 0x38, i);
  861. if (i & 0x80)
  862. coding = "ESF";
  863. else
  864. coding = "SF";
  865. if (i & 0x40)
  866. framing = "B8ZS";
  867. else {
  868. framing = "AMI";
  869. t1out(p->tor,tspan,0x7e,0x1c); /* F bits pattern (0x1c) into FDL register */
  870. }
  871. t1out(p->tor,tspan, 0x7c, span->txlevel << 5);
  872. if (!alreadyrunning) {
  873. /* LIRST to reset line interface */
  874. t1out(p->tor,tspan, 0x0a, 0x80);
  875. /* Wait 100 ms */
  876. endjif = jiffies + 10;
  877. spin_unlock_irqrestore(&p->tor->lock, flags);
  878. while (jiffies < endjif); /* wait 100 ms */
  879. spin_lock_irqsave(&p->tor->lock, flags);
  880. t1out(p->tor,tspan,0x0a,0x30); /* LIRST back to normal, Resetting elastic stores */
  881. span->flags |= DAHDI_FLAG_RUNNING;
  882. p->tor->spansstarted++;
  883. /* enable interrupts */
  884. writeb(INTENA, &p->tor->mem8[CTLREG]);
  885. }
  886. set_clear(p->tor);
  887. spin_unlock_irqrestore(&p->tor->lock, flags);
  888. if (debug) {
  889. if (alreadyrunning)
  890. printk(KERN_INFO "Tor2: Reconfigured span %d (%s/%s) LBO: %s\n", span->spanno, coding, framing, dahdi_lboname(span->txlevel));
  891. else
  892. printk(KERN_INFO "Tor2: Startup span %d (%s/%s) LBO: %s\n", span->spanno, coding, framing, dahdi_lboname(span->txlevel));
  893. }
  894. }
  895. if (p->tor->syncs[0] == span->spanno) printk(KERN_INFO "SPAN %d: Primary Sync Source\n",span->spanno);
  896. if (p->tor->syncs[1] == span->spanno) printk(KERN_INFO "SPAN %d: Secondary Sync Source\n",span->spanno);
  897. if (p->tor->syncs[2] == span->spanno) printk(KERN_INFO "SPAN %d: Tertiary Sync Source\n",span->spanno);
  898. if (p->tor->syncs[3] == span->spanno) printk(KERN_INFO "SPAN %d: Quaternary Sync Source\n",span->spanno);
  899. return 0;
  900. }
  901. static int tor2_maint(struct dahdi_span *span, int cmd)
  902. {
  903. struct tor2_span *p = container_of(span, struct tor2_span, dahdi_span);
  904. int tspan = p->span + 1;
  905. if (p->tor->cardtype == TYPE_E1)
  906. {
  907. switch(cmd) {
  908. case DAHDI_MAINT_NONE:
  909. t1out(p->tor,tspan,0xa8,0); /* no loops */
  910. break;
  911. case DAHDI_MAINT_LOCALLOOP:
  912. t1out(p->tor,tspan,0xa8,0x40); /* local loop */
  913. break;
  914. case DAHDI_MAINT_REMOTELOOP:
  915. t1out(p->tor,tspan,0xa8,0x80); /* remote loop */
  916. break;
  917. case DAHDI_MAINT_LOOPUP:
  918. case DAHDI_MAINT_LOOPDOWN:
  919. return -ENOSYS;
  920. default:
  921. printk(KERN_NOTICE "Tor2: Unknown maint command: %d\n", cmd);
  922. break;
  923. }
  924. return 0;
  925. }
  926. switch(cmd) {
  927. case DAHDI_MAINT_NONE:
  928. t1out(p->tor,tspan,0x19,(japan ? 0x80 : 0x00)); /* no local loop */
  929. t1out(p->tor,tspan,0x0a,0); /* no remote loop */
  930. t1out(p->tor, tspan, 0x30, 0); /* stop sending loopup code */
  931. break;
  932. case DAHDI_MAINT_LOCALLOOP:
  933. t1out(p->tor,tspan,0x19,0x40 | (japan ? 0x80 : 0x00)); /* local loop */
  934. t1out(p->tor,tspan,0x0a,0); /* no remote loop */
  935. break;
  936. case DAHDI_MAINT_REMOTELOOP:
  937. t1out(p->tor,tspan,0x1e,(japan ? 0x80 : 0x00)); /* no local loop */
  938. t1out(p->tor,tspan,0x0a,0x40); /* remote loop */
  939. break;
  940. case DAHDI_MAINT_LOOPUP:
  941. t1out(p->tor,tspan,0x30,2); /* send loopup code */
  942. t1out(p->tor,tspan,0x12,0x22); /* send loopup code */
  943. t1out(p->tor,tspan,0x13,0x80); /* send loopup code */
  944. break;
  945. case DAHDI_MAINT_LOOPDOWN:
  946. t1out(p->tor,tspan,0x30,2); /* send loopdown code */
  947. t1out(p->tor,tspan,0x12,0x62); /* send loopdown code */
  948. t1out(p->tor,tspan,0x13,0x90); /* send loopdown code */
  949. break;
  950. default:
  951. printk(KERN_NOTICE "Tor2: Unknown maint command: %d\n", cmd);
  952. break;
  953. }
  954. return 0;
  955. }
  956. static inline void tor2_run(struct tor2 *tor)
  957. {
  958. int x,y;
  959. for (x = 0; x < SPANS_PER_CARD; x++) {
  960. struct dahdi_span *const s = &tor->tspans[x].dahdi_span;
  961. if (s->flags & DAHDI_FLAG_RUNNING) {
  962. /* since the Tormenta 2 PCI is double-buffered, you
  963. need to delay the transmit data 2 entire chunks so
  964. that the transmit will be in sync with the receive */
  965. for (y = 0; y < s->channels; y++) {
  966. dahdi_ec_chunk(s->chans[y],
  967. s->chans[y]->readchunk,
  968. tor->ec_chunk2[x][y]);
  969. memcpy(tor->ec_chunk2[x][y],tor->ec_chunk1[x][y],
  970. DAHDI_CHUNKSIZE);
  971. memcpy(tor->ec_chunk1[x][y],
  972. s->chans[y]->writechunk,
  973. DAHDI_CHUNKSIZE);
  974. }
  975. dahdi_receive(s);
  976. }
  977. }
  978. for (x = 0; x < SPANS_PER_CARD; x++) {
  979. struct dahdi_span *const s = &tor->tspans[x].dahdi_span;
  980. if (s->flags & DAHDI_FLAG_RUNNING)
  981. dahdi_transmit(s);
  982. }
  983. }
  984. #ifdef ENABLE_TASKLETS
  985. static void tor2_tasklet(unsigned long data)
  986. {
  987. struct tor2 *tor = (struct tor2 *)data;
  988. tor->taskletrun++;
  989. if (tor->taskletpending) {
  990. tor->taskletexec++;
  991. tor2_run(tor);
  992. }
  993. tor->taskletpending = 0;
  994. }
  995. #endif
  996. static int syncsrc = 0;
  997. static int syncnum = 0 /* -1 */;
  998. static int syncspan = 0;
  999. static DEFINE_SPINLOCK(synclock);
  1000. static int tor2_findsync(struct tor2 *tor)
  1001. {
  1002. int i;
  1003. int x;
  1004. unsigned long flags;
  1005. int p;
  1006. int nonzero;
  1007. int newsyncsrc = 0; /* DAHDI span number */
  1008. int newsyncnum = 0; /* tor2 card number */
  1009. int newsyncspan = 0; /* span on given tor2 card */
  1010. spin_lock_irqsave(&synclock, flags);
  1011. #if 1
  1012. if (!tor->num) {
  1013. /* If we're the first card, go through all the motions, up to 8 levels
  1014. of sync source */
  1015. p = 1;
  1016. while (p < 8) {
  1017. nonzero = 0;
  1018. for (x=0;cards[x];x++) {
  1019. for (i = 0; i < SPANS_PER_CARD; i++) {
  1020. if (cards[x]->syncpos[i]) {
  1021. nonzero = 1;
  1022. if ((cards[x]->syncpos[i] == p) &&
  1023. !(cards[x]->tspans[i].dahdi_span.alarms & (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE | DAHDI_ALARM_LOOPBACK)) &&
  1024. (cards[x]->tspans[i].dahdi_span.flags & DAHDI_FLAG_RUNNING)) {
  1025. /* This makes a good sync source */
  1026. newsyncsrc = cards[x]->tspans[i].dahdi_span.spanno;
  1027. newsyncnum = x;
  1028. newsyncspan = i + 1;
  1029. /* Jump out */
  1030. goto found;
  1031. }
  1032. }
  1033. }
  1034. }
  1035. if (nonzero)
  1036. p++;
  1037. else
  1038. break;
  1039. }
  1040. found:
  1041. if ((syncnum != newsyncnum) || (syncsrc != newsyncsrc) || (newsyncspan != syncspan)) {
  1042. syncnum = newsyncnum;
  1043. syncsrc = newsyncsrc;
  1044. syncspan = newsyncspan;
  1045. if (debug) printk(KERN_DEBUG "New syncnum: %d, syncsrc: %d, syncspan: %d\n", syncnum, syncsrc, syncspan);
  1046. }
  1047. }
  1048. #endif
  1049. /* update sync src info */
  1050. if (tor->syncsrc != syncsrc) {
  1051. tor->syncsrc = syncsrc;
  1052. /* Update sync sources */
  1053. for (i = 0; i < SPANS_PER_CARD; i++) {
  1054. tor->tspans[i].dahdi_span.syncsrc = tor->syncsrc;
  1055. }
  1056. if (syncnum == tor->num) {
  1057. #if 1
  1058. /* actually set the sync register */
  1059. writeb(syncspan, &tor->mem8[SYNCREG]);
  1060. #endif
  1061. if (debug) printk(KERN_DEBUG "Card %d, using sync span %d, master\n", tor->num, syncspan);
  1062. tor->master = MASTER;
  1063. } else {
  1064. #if 1
  1065. /* time from the timing cable */
  1066. writeb(SYNCEXTERN, &tor->mem8[SYNCREG]);
  1067. #endif
  1068. tor->master = 0;
  1069. if (debug) printk(KERN_DEBUG "Card %d, using Timing Bus, NOT master\n", tor->num);
  1070. }
  1071. }
  1072. spin_unlock_irqrestore(&synclock, flags);
  1073. return 0;
  1074. }
  1075. DAHDI_IRQ_HANDLER(tor2_intr)
  1076. {
  1077. int n, i, j, k, newsyncsrc;
  1078. unsigned int rxword,txword;
  1079. unsigned char c, rxc;
  1080. unsigned char abits, bbits;
  1081. struct tor2 *tor = (struct tor2 *) dev_id;
  1082. unsigned long flags;
  1083. /* make sure its a real interrupt for us */
  1084. if (!(readb(&tor->mem8[STATREG]) & INTACTIVE)) /* if not, just return */
  1085. {
  1086. return IRQ_NONE;
  1087. }
  1088. local_irq_save(flags);
  1089. if (tor->cardtype == TYPE_E1) {
  1090. /* set outbit, interrupt enable, and ack interrupt */
  1091. writeb(OUTBIT | INTENA | INTACK | E1DIV | tor->master,
  1092. &tor->mem8[CTLREG]);
  1093. } else {
  1094. /* set outbit, interrupt enable, and ack interrupt */
  1095. writeb(OUTBIT | INTENA | INTACK | tor->master,
  1096. &tor->mem8[CTLREG]);
  1097. }
  1098. #if 0
  1099. if (!tor->passno)
  1100. printk(KERN_DEBUG "Interrupt handler\n");
  1101. #endif
  1102. /* do the transmit output */
  1103. for (n = 0; n < tor->tspans[0].dahdi_span.channels; n++) {
  1104. for (i = 0; i < DAHDI_CHUNKSIZE; i++) {
  1105. /* span 1 */
  1106. txword = tor->tspans[0].dahdi_span.chans[n]->writechunk[i] << 24;
  1107. /* span 2 */
  1108. txword |= tor->tspans[1].dahdi_span.chans[n]->writechunk[i] << 16;
  1109. /* span 3 */
  1110. txword |= tor->tspans[2].dahdi_span.chans[n]->writechunk[i] << 8;
  1111. /* span 4 */
  1112. txword |= tor->tspans[3].dahdi_span.chans[n]->writechunk[i];
  1113. /* write to part */
  1114. #ifdef FIXTHISFOR64
  1115. tor->mem32[tor->datxlt[n] + (32 * i)] = txword;
  1116. #else
  1117. writel(txword, &tor->mem32[tor->datxlt[n] + (32 * i)]);
  1118. #endif
  1119. }
  1120. }
  1121. /* Do the receive input */
  1122. for (n = 0; n < tor->tspans[0].dahdi_span.channels; n++) {
  1123. for (i = 0; i < DAHDI_CHUNKSIZE; i++) {
  1124. /* read from */
  1125. #ifdef FIXTHISFOR64
  1126. rxword = tor->mem32[tor->datxlt[n] + (32 * i)];
  1127. #else
  1128. rxword = readl(&tor->mem32[tor->datxlt[n] + (32 * i)]);
  1129. #endif
  1130. /* span 1 */
  1131. tor->tspans[0].dahdi_span.chans[n]->readchunk[i] = rxword >> 24;
  1132. /* span 2 */
  1133. tor->tspans[1].dahdi_span.chans[n]->readchunk[i] = (rxword & 0xff0000) >> 16;
  1134. /* span 3 */
  1135. tor->tspans[2].dahdi_span.chans[n]->readchunk[i] = (rxword & 0xff00) >> 8;
  1136. /* span 4 */
  1137. tor->tspans[3].dahdi_span.chans[n]->readchunk[i] = rxword & 0xff;
  1138. }
  1139. }
  1140. i = tor->passno & 15;
  1141. /* if an E1 card, do rx signalling for it */
  1142. if ((i < 3) && (tor->cardtype == TYPE_E1)) { /* if an E1 card */
  1143. for (j = (i * 5); j < (i * 5) + 5; j++) {
  1144. for (k = 1; k <= SPANS_PER_CARD; k++) {
  1145. c = t1in(tor,k,0x31 + j);
  1146. rxc = c & 15;
  1147. if (rxc != tor->tspans[k - 1].dahdi_span.chans[j + 16]->rxsig) {
  1148. /* Check for changes in received bits */
  1149. if (!(tor->tspans[k - 1].dahdi_span.chans[j + 16]->sig & DAHDI_SIG_CLEAR))
  1150. dahdi_rbsbits(tor->tspans[k - 1].dahdi_span.chans[j + 16], rxc);
  1151. }
  1152. rxc = c >> 4;
  1153. if (rxc != tor->tspans[k - 1].dahdi_span.chans[j]->rxsig) {
  1154. /* Check for changes in received bits */
  1155. if (!(tor->tspans[k - 1].dahdi_span.chans[j]->sig & DAHDI_SIG_CLEAR))
  1156. dahdi_rbsbits(tor->tspans[k - 1].dahdi_span.chans[j], rxc);
  1157. }
  1158. }
  1159. }
  1160. }
  1161. /* if a T1, do the signalling */
  1162. if ((i < 12) && (tor->cardtype == TYPE_T1)) {
  1163. k = (i / 3); /* get span */
  1164. n = (i % 3); /* get base */
  1165. abits = t1in(tor,k + 1, 0x60 + n);
  1166. bbits = t1in(tor,k + 1, 0x63 + n);
  1167. for (j=0; j< 8; j++) {
  1168. /* Get channel number */
  1169. i = (n * 8) + j;
  1170. rxc = 0;
  1171. if (abits & (1 << j)) rxc |= DAHDI_ABIT;
  1172. if (bbits & (1 << j)) rxc |= DAHDI_BBIT;
  1173. if (tor->tspans[k].dahdi_span.chans[i]->rxsig != rxc) {
  1174. /* Check for changes in received bits */
  1175. if (!(tor->tspans[k].dahdi_span.chans[i]->sig & DAHDI_SIG_CLEAR))
  1176. dahdi_rbsbits(tor->tspans[k].dahdi_span.chans[i], rxc);
  1177. }
  1178. }
  1179. }
  1180. for (i = 0; i < SPANS_PER_CARD; i++) { /* Go thru all the spans */
  1181. /* if alarm timer, and it's timed out */
  1182. if (tor->alarmtimer[i]) {
  1183. if (!--tor->alarmtimer[i]) {
  1184. /* clear recover status */
  1185. tor->tspans[i].dahdi_span.alarms &= ~DAHDI_ALARM_RECOVER;
  1186. if (tor->cardtype == TYPE_E1)
  1187. t1out(tor,i + 1,0x21,0x5f); /* turn off yel */
  1188. else
  1189. t1out(tor,i + 1,0x35,0x10); /* turn off yel */
  1190. dahdi_alarm_notify(&tor->tspans[i].dahdi_span); /* let them know */
  1191. }
  1192. }
  1193. }
  1194. i = tor->passno & 15;
  1195. if ((i >= 10) && (i <= 13) && !(tor->passno & 0x30))
  1196. {
  1197. j = 0; /* clear this alarm status */
  1198. i -= 10;
  1199. if (tor->cardtype == TYPE_T1) {
  1200. c = t1in(tor,i + 1,0x31); /* get RIR2 */
  1201. tor->tspans[i].dahdi_span.rxlevel = c >> 6; /* get rx level */
  1202. t1out(tor,i + 1,0x20,0xff);
  1203. c = t1in(tor,i + 1,0x20); /* get the status */
  1204. /* detect the code, only if we are not sending one */
  1205. if ((!tor->tspans[i].dahdi_span.mainttimer) && (c & 0x80)) /* if loop-up code detected */
  1206. {
  1207. /* set into remote loop, if not there already */
  1208. if ((tor->loopupcnt[i]++ > 80) &&
  1209. (tor->tspans[i].dahdi_span.maintstat != DAHDI_MAINT_REMOTELOOP))
  1210. {
  1211. t1out(tor,i + 1,0x1e,(japan ? 0x80 : 0x00)); /* no local loop */
  1212. t1out(tor,i + 1,0x0a,0x40); /* remote loop */
  1213. tor->tspans[i].dahdi_span.maintstat = DAHDI_MAINT_REMOTELOOP;
  1214. }
  1215. } else tor->loopupcnt[i] = 0;
  1216. /* detect the code, only if we are not sending one */
  1217. if ((!tor->tspans[i].dahdi_span.mainttimer) && (c & 0x40)) /* if loop-down code detected */
  1218. {
  1219. /* if in remote loop, get out of it */
  1220. if ((tor->loopdowncnt[i]++ > 80) &&
  1221. (tor->tspans[i].dahdi_span.maintstat == DAHDI_MAINT_REMOTELOOP))
  1222. {
  1223. t1out(tor,i + 1,0x1e,(japan ? 0x80 : 0x00)); /* no local loop */
  1224. t1out(tor,i + 1,0x0a,0); /* no remote loop */
  1225. tor->tspans[i].dahdi_span.maintstat = DAHDI_MAINT_NONE;
  1226. }
  1227. } else tor->loopdowncnt[i] = 0;
  1228. if (c & 3) /* if red alarm */
  1229. {
  1230. j |= DAHDI_ALARM_RED;
  1231. }
  1232. if (c & 8) /* if blue alarm */
  1233. {
  1234. j |= DAHDI_ALARM_BLUE;
  1235. }
  1236. } else { /* its an E1 card */
  1237. t1out(tor,i + 1,6,0xff);
  1238. c = t1in(tor,i + 1,6); /* get the status */
  1239. if (c & 9) /* if red alarm */
  1240. {
  1241. j |= DAHDI_ALARM_RED;
  1242. }
  1243. if (c & 2) /* if blue alarm */
  1244. {
  1245. j |= DAHDI_ALARM_BLUE;
  1246. }
  1247. }
  1248. /* only consider previous carrier alarm state */
  1249. tor->tspans[i].dahdi_span.alarms &= (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE | DAHDI_ALARM_NOTOPEN);
  1250. n = 1; /* set to 1 so will not be in yellow alarm if we dont
  1251. care about open channels */
  1252. /* if to have yellow alarm if nothing open */
  1253. if (tor->tspans[i].dahdi_span.lineconfig & DAHDI_CONFIG_NOTOPEN) {
  1254. /* go thru all chans, and count # open */
  1255. for (n = 0, k = 0; k < tor->tspans[i].dahdi_span.channels; k++) {
  1256. if (((tor->chans[i][k])->flags & DAHDI_FLAG_OPEN) ||
  1257. dahdi_have_netdev(tor->chans[i][k]))
  1258. n++;
  1259. }
  1260. /* if none open, set alarm condition */
  1261. if (!n)
  1262. j |= DAHDI_ALARM_NOTOPEN;
  1263. }
  1264. /* if no more alarms, and we had some */
  1265. if ((!j) && tor->tspans[i].dahdi_span.alarms)
  1266. tor->alarmtimer[i] = DAHDI_ALARMSETTLE_TIME;
  1267. if (tor->alarmtimer[i]) j |= DAHDI_ALARM_RECOVER;
  1268. /* if going into alarm state, set yellow alarm */
  1269. if ((j) && (!tor->tspans[i].dahdi_span.alarms)) {
  1270. if (tor->cardtype == TYPE_E1)
  1271. t1out(tor,i + 1,0x21,0x7f);
  1272. else
  1273. t1out(tor,i + 1,0x35,0x11);
  1274. }
  1275. if (c & 4) /* if yellow alarm */
  1276. j |= DAHDI_ALARM_YELLOW;
  1277. if (tor->tspans[i].dahdi_span.maintstat || tor->tspans[i].dahdi_span.mainttimer)
  1278. j |= DAHDI_ALARM_LOOPBACK;
  1279. tor->tspans[i].dahdi_span.alarms = j;
  1280. c = (LEDRED | LEDGREEN) << (2 * i);
  1281. tor->leds &= ~c; /* mask out bits for this span */
  1282. /* light LED's if span configured and running */
  1283. if (tor->tspans[i].dahdi_span.flags & DAHDI_FLAG_RUNNING) {
  1284. if (j & DAHDI_ALARM_RED) tor->leds |= LEDRED << (2 * i);
  1285. else if (j & DAHDI_ALARM_YELLOW) tor->leds |= (LEDRED | LEDGREEN) << (2 * i);
  1286. else tor->leds |= LEDGREEN << (2 * i);
  1287. }
  1288. writeb(tor->leds, &tor->mem8[LEDREG]);
  1289. dahdi_alarm_notify(&tor->tspans[i].dahdi_span);
  1290. }
  1291. if (!(tor->passno % 1000)) /* even second boundary */
  1292. {
  1293. /* do all spans */
  1294. for (i = 1; i <= SPANS_PER_CARD; i++)
  1295. {
  1296. if (tor->cardtype == TYPE_E1)
  1297. {
  1298. /* add this second's BPV count to total one */
  1299. tor->tspans[i - 1].dahdi_span.count.bpv +=
  1300. t1in(tor, i, 1) + (t1in(tor, i, 0)<<8);
  1301. if (tor->tspans[i - 1].dahdi_span.lineconfig & DAHDI_CONFIG_CRC4)
  1302. {
  1303. tor->tspans[i - 1].dahdi_span.count.crc4 +=
  1304. t1in(tor, i, 3) +
  1305. ((t1in(tor, i, 2) & 3) << 8);
  1306. tor->tspans[i - 1].dahdi_span.count.ebit +=
  1307. t1in(tor, i, 5) +
  1308. ((t1in(tor, i, 4) & 3) << 8);
  1309. }
  1310. tor->tspans[i - 1].dahdi_span.count.fas +=
  1311. (t1in(tor, i, 4) >> 2) +
  1312. ((t1in(tor, i, 2) & 0x3F) << 6);
  1313. }
  1314. else
  1315. {
  1316. /* add this second's BPV count to total one */
  1317. tor->tspans[i - 1].dahdi_span.count.bpv +=
  1318. t1in(tor, i, 0x24) +
  1319. (t1in(tor, i, 0x23) << 8);
  1320. }
  1321. }
  1322. }
  1323. if (!timingcable) {
  1324. /* re-evaluate active sync src (no cable version) */
  1325. tor->syncsrc = 0;
  1326. newsyncsrc = 0;
  1327. /* if primary sync specified, see if we can use it */
  1328. if (tor->psyncs[0])
  1329. {
  1330. /* if no alarms, use it */
  1331. if (!(tor->tspans[tor->psyncs[0] - 1].dahdi_span.alarms & (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE |
  1332. DAHDI_ALARM_LOOPBACK))) {
  1333. tor->syncsrc = tor->psyncs[0];
  1334. newsyncsrc = tor->syncs[0];
  1335. }
  1336. }
  1337. /* if any others specified, see if we can use them */
  1338. for (i = 1; i < SPANS_PER_CARD; i++) {
  1339. /* if we dont have one yet, and there is one specified at this level, see if we can use it */
  1340. if ((!tor->syncsrc) && (tor->psyncs[i])) {
  1341. /* if no alarms, use it */
  1342. if (!(tor->tspans[tor->psyncs[i] - 1].dahdi_span.alarms & (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE |
  1343. DAHDI_ALARM_LOOPBACK))) {
  1344. tor->syncsrc = tor->psyncs[i];
  1345. newsyncsrc = tor->syncs[i];
  1346. }
  1347. }
  1348. }
  1349. /* update sync src info */
  1350. for (i = 0; i < SPANS_PER_CARD; i++)
  1351. tor->tspans[i].dahdi_span.syncsrc = newsyncsrc;
  1352. /* actually set the sync register */
  1353. writeb(tor->syncsrc, &tor->mem8[SYNCREG]);
  1354. } else /* Timing cable version */
  1355. tor2_findsync(tor);
  1356. tor->passno++;
  1357. #ifdef ENABLE_TASKLETS
  1358. if (!tor->taskletpending) {
  1359. tor->taskletpending = 1;
  1360. tor->taskletsched++;
  1361. tasklet_hi_schedule(&tor->tor2_tlet);
  1362. } else {
  1363. tor->txerrors++;
  1364. }
  1365. #else
  1366. tor2_run(tor);
  1367. #endif
  1368. /* We are not the timing bus master */
  1369. if (tor->cardtype == TYPE_E1)
  1370. /* clear OUTBIT and enable interrupts */
  1371. writeb(INTENA | E1DIV | tor->master, &tor->mem8[CTLREG]);
  1372. else
  1373. /* clear OUTBIT and enable interrupts */
  1374. writeb(INTENA | tor->master, &tor->mem8[CTLREG]);
  1375. local_irq_restore(flags);
  1376. return IRQ_RETVAL(1);
  1377. }
  1378. static int tor2_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long data)
  1379. {
  1380. switch(cmd) {
  1381. default:
  1382. return -ENOTTY;
  1383. }
  1384. return 0;
  1385. }
  1386. MODULE_AUTHOR("Mark Spencer");
  1387. MODULE_DESCRIPTION("Tormenta 2 PCI Quad T1 or E1 DAHDI Driver");
  1388. MODULE_LICENSE("GPL v2");
  1389. module_param(debug, int, 0600);
  1390. module_param(loopback, int, 0600);
  1391. module_param(timingcable, int, 0600);
  1392. module_param(japan, int, 0600);
  1393. MODULE_DEVICE_TABLE(pci, tor2_pci_ids);
  1394. module_init(tor2_init);
  1395. module_exit(tor2_cleanup);