Line 0
Link Here
|
|
|
1 |
/* |
2 |
* OpenVox D115P/D115E PCI/PCI-E Driver version 0.1 01/07/2011 |
3 |
* |
4 |
* Written by Mark Spencer <markster@digium.com> |
5 |
* Modify from wct4xxp module by mark.liu@openvox.cn |
6 |
|
7 |
* Based on previous works, designs, and archetectures conceived and |
8 |
* written by Jim Dixon <jim@lambdatel.com>. |
9 |
* |
10 |
* Copyright (C) 2001 Jim Dixon / Zapata Telephony. |
11 |
* Copyright (C) 2001-2010, Digium, Inc. |
12 |
* |
13 |
* All rights reserved. |
14 |
* |
15 |
*/ |
16 |
|
17 |
/* |
18 |
* See http://www.asterisk.org for more information about |
19 |
* the Asterisk project. Please do not directly contact |
20 |
* any of the maintainers of this project for assistance; |
21 |
* the project provides a web site, mailing lists and IRC |
22 |
* channels for your use. |
23 |
* |
24 |
* This program is free software, distributed under the terms of |
25 |
* the GNU General Public License Version 2 as published by the |
26 |
* Free Software Foundation. See the LICENSE file included with |
27 |
* this program for more details. |
28 |
*/ |
29 |
|
30 |
#include <linux/kernel.h> |
31 |
#include <linux/errno.h> |
32 |
#include <linux/module.h> |
33 |
#include <linux/pci.h> |
34 |
#include <linux/init.h> |
35 |
#include <linux/sched.h> |
36 |
#include <linux/interrupt.h> |
37 |
#include <linux/spinlock.h> |
38 |
#include <asm/io.h> |
39 |
#include <linux/version.h> |
40 |
#include <linux/delay.h> |
41 |
#include <linux/moduleparam.h> |
42 |
|
43 |
#include <dahdi/kernel.h> |
44 |
|
45 |
#include "opvxd115.h" |
46 |
#include "vpm450m.h" |
47 |
|
48 |
/* Work queues are a way to better distribute load on SMP systems */ |
49 |
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)) |
50 |
/* |
51 |
* Work queues can significantly improve performance and scalability |
52 |
* on multi-processor machines, but requires bypassing some kernel |
53 |
* API's, so it's not guaranteed to be compatible with all kernels. |
54 |
*/ |
55 |
/* #define ENABLE_WORKQUEUES */ |
56 |
#endif |
57 |
|
58 |
/* Enable prefetching may help performance */ |
59 |
#define ENABLE_PREFETCH |
60 |
|
61 |
/* Support first generation cards? */ |
62 |
#define SUPPORT_GEN1 |
63 |
|
64 |
/* Define to get more attention-grabbing but slightly more I/O using |
65 |
alarm status */ |
66 |
#define FANCY_ALARM |
67 |
|
68 |
/* Define to support Digium Voice Processing Module expansion card */ |
69 |
#define VPM_SUPPORT |
70 |
|
71 |
#define DEBUG_MAIN (1 << 0) |
72 |
#define DEBUG_DTMF (1 << 1) |
73 |
#define DEBUG_REGS (1 << 2) |
74 |
#define DEBUG_TSI (1 << 3) |
75 |
#define DEBUG_ECHOCAN (1 << 4) |
76 |
#define DEBUG_RBS (1 << 5) |
77 |
#define DEBUG_FRAMER (1 << 6) |
78 |
|
79 |
/* Maximum latency to be used with Gen 5 */ |
80 |
#define GEN5_MAX_LATENCY 127 |
81 |
|
82 |
#define T4_BASE_SIZE (DAHDI_MAX_CHUNKSIZE * 32 * 4) |
83 |
|
84 |
#ifdef ENABLE_WORKQUEUES |
85 |
#include <linux/cpu.h> |
86 |
|
87 |
/* XXX UGLY!!!! XXX We have to access the direct structures of the workqueue which |
88 |
are only defined within workqueue.c because they don't give us a routine to allow us |
89 |
to nail a work to a particular thread of the CPU. Nailing to threads gives us substantially |
90 |
higher scalability in multi-CPU environments though! */ |
91 |
|
92 |
/* |
93 |
* The per-CPU workqueue (if single thread, we always use cpu 0's). |
94 |
* |
95 |
* The sequence counters are for flush_scheduled_work(). It wants to wait |
96 |
* until until all currently-scheduled works are completed, but it doesn't |
97 |
* want to be livelocked by new, incoming ones. So it waits until |
98 |
* remove_sequence is >= the insert_sequence which pertained when |
99 |
* flush_scheduled_work() was called. |
100 |
*/ |
101 |
|
102 |
struct cpu_workqueue_struct { |
103 |
|
104 |
spinlock_t lock; |
105 |
|
106 |
long remove_sequence; /* Least-recently added (next to run) */ |
107 |
long insert_sequence; /* Next to add */ |
108 |
|
109 |
struct list_head worklist; |
110 |
wait_queue_head_t more_work; |
111 |
wait_queue_head_t work_done; |
112 |
|
113 |
struct workqueue_struct *wq; |
114 |
task_t *thread; |
115 |
|
116 |
int run_depth; /* Detect run_workqueue() recursion depth */ |
117 |
} ____cacheline_aligned; |
118 |
|
119 |
/* |
120 |
* The externally visible workqueue abstraction is an array of |
121 |
* per-CPU workqueues: |
122 |
*/ |
123 |
struct workqueue_struct { |
124 |
/* TODO: Find out exactly where the API changed */ |
125 |
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,15) |
126 |
struct cpu_workqueue_struct *cpu_wq; |
127 |
#else |
128 |
struct cpu_workqueue_struct cpu_wq[NR_CPUS]; |
129 |
#endif |
130 |
const char *name; |
131 |
struct list_head list; /* Empty if single thread */ |
132 |
}; |
133 |
|
134 |
/* Preempt must be disabled. */ |
135 |
static void __t4_queue_work(struct cpu_workqueue_struct *cwq, |
136 |
struct work_struct *work) |
137 |
{ |
138 |
unsigned long flags; |
139 |
|
140 |
spin_lock_irqsave(&cwq->lock, flags); |
141 |
work->wq_data = cwq; |
142 |
list_add_tail(&work->entry, &cwq->worklist); |
143 |
cwq->insert_sequence++; |
144 |
wake_up(&cwq->more_work); |
145 |
spin_unlock_irqrestore(&cwq->lock, flags); |
146 |
} |
147 |
|
148 |
/* |
149 |
* Queue work on a workqueue. Return non-zero if it was successfully |
150 |
* added. |
151 |
* |
152 |
* We queue the work to the CPU it was submitted, but there is no |
153 |
* guarantee that it will be processed by that CPU. |
154 |
*/ |
155 |
static inline int t4_queue_work(struct workqueue_struct *wq, struct work_struct *work, int cpu) |
156 |
{ |
157 |
int ret = 0; |
158 |
get_cpu(); |
159 |
if (!test_and_set_bit(0, &work->pending)) { |
160 |
BUG_ON(!list_empty(&work->entry)); |
161 |
__t4_queue_work(wq->cpu_wq + cpu, work); |
162 |
ret = 1; |
163 |
} |
164 |
put_cpu(); |
165 |
return ret; |
166 |
} |
167 |
|
168 |
#endif |
169 |
|
170 |
/* |
171 |
* Define CONFIG_EXTENDED_RESET to allow the qfalc framer extra time |
172 |
* to reset itself upon hardware initialization. This exits for rare |
173 |
* cases for customers who are seeing the qfalc returning unexpected |
174 |
* information at initialization |
175 |
*/ |
176 |
#undef CONFIG_EXTENDED_RESET |
177 |
|
178 |
static int pedanticpci = 1; |
179 |
static int debug=0; |
180 |
static int timingcable = 0; |
181 |
static int t1e1override = -1; /* 0xff for E1, 0x00 for T1 */ |
182 |
static int j1mode = 0; |
183 |
static int sigmode = FRMR_MODE_NO_ADDR_CMP; |
184 |
static int alarmdebounce = 2500; /* LOF/LFA def to 2.5s AT&T TR54016*/ |
185 |
static int losalarmdebounce = 2500;/* LOS def to 2.5s AT&T TR54016*/ |
186 |
static int aisalarmdebounce = 2500;/* AIS(blue) def to 2.5s AT&T TR54016*/ |
187 |
static int yelalarmdebounce = 500;/* RAI(yellow) def to 0.5s AT&T devguide */ |
188 |
static int max_latency = GEN5_MAX_LATENCY; /* Used to set a maximum latency (if you don't wish it to hard cap it at a certain value) in milliseconds */ |
189 |
#ifdef VPM_SUPPORT |
190 |
static int vpmsupport = 1; |
191 |
/* If set to auto, vpmdtmfsupport is enabled for VPM400M and disabled for VPM450M */ |
192 |
static int vpmdtmfsupport = -1; /* -1=auto, 0=disabled, 1=enabled*/ |
193 |
static int vpmspans = 1; |
194 |
#define VPM_DEFAULT_DTMFTHRESHOLD 1000 |
195 |
static int dtmfthreshold = VPM_DEFAULT_DTMFTHRESHOLD; |
196 |
static int lastdtmfthreshold = VPM_DEFAULT_DTMFTHRESHOLD; |
197 |
#endif |
198 |
/* Enabling bursting can more efficiently utilize PCI bus bandwidth, but |
199 |
can also cause PCI bus starvation, especially in combination with other |
200 |
aggressive cards. Please note that burst mode has no effect on CPU |
201 |
utilization / max number of calls / etc. */ |
202 |
static int noburst; |
203 |
/* For 56kbps links, set this module parameter to 0x7f */ |
204 |
static int hardhdlcmode = 0xff; |
205 |
|
206 |
static int latency = 1; |
207 |
|
208 |
static int ms_per_irq = 1; |
209 |
|
210 |
#ifdef FANCY_ALARM |
211 |
static int altab[] = { |
212 |
0, 0, 0, 1, 2, 3, 4, 6, 8, 9, 11, 13, 16, 18, 20, 22, 24, 25, 27, 28, 29, 30, 31, 31, 32, 31, 31, 30, 29, 28, 27, 25, 23, 22, 20, 18, 16, 13, 11, 9, 8, 6, 4, 3, 2, 1, 0, 0, |
213 |
}; |
214 |
#endif |
215 |
|
216 |
#define MAX_SPANS 16 |
217 |
|
218 |
#define FLAG_STARTED (1 << 0) |
219 |
#define FLAG_NMF (1 << 1) |
220 |
#define FLAG_SENDINGYELLOW (1 << 2) |
221 |
|
222 |
|
223 |
#define TYPE_T1 1 /* is a T1 card */ |
224 |
#define TYPE_E1 2 /* is an E1 card */ |
225 |
#define TYPE_J1 3 /* is a running J1 */ |
226 |
|
227 |
#define FLAG_2NDGEN (1 << 3) |
228 |
#define FLAG_2PORT (1 << 4) |
229 |
#define FLAG_VPM2GEN (1 << 5) |
230 |
#define FLAG_OCTOPT (1 << 6) |
231 |
#define FLAG_3RDGEN (1 << 7) |
232 |
#define FLAG_BURST (1 << 8) |
233 |
#define FLAG_EXPRESS (1 << 9) |
234 |
#define FLAG_5THGEN (1 << 10) |
235 |
|
236 |
#define CANARY 0xc0de |
237 |
|
238 |
|
239 |
#define PORTS_PER_FRAMER 4 |
240 |
|
241 |
struct devtype { |
242 |
char *desc; |
243 |
unsigned int flags; |
244 |
}; |
245 |
|
246 |
static struct devtype opvxd115 = { "OpenVox D115P/D115E ", FLAG_2NDGEN}; |
247 |
static struct devtype opvxd130 = { "OpenVox D130P/D130E", FLAG_5THGEN | FLAG_BURST | FLAG_2NDGEN | FLAG_3RDGEN}; |
248 |
|
249 |
|
250 |
struct t4; |
251 |
|
252 |
struct t4_span { |
253 |
struct t4 *owner; |
254 |
unsigned int *writechunk; /* Double-word aligned write memory */ |
255 |
unsigned int *readchunk; /* Double-word aligned read memory */ |
256 |
int spantype; /* card type, T1 or E1 or J1 */ |
257 |
int sync; |
258 |
int psync; |
259 |
int alarmtimer; |
260 |
int redalarms; |
261 |
int notclear; |
262 |
int alarmcount; |
263 |
int losalarmcount; |
264 |
int aisalarmcount; |
265 |
int yelalarmcount; |
266 |
int spanflags; |
267 |
int syncpos; |
268 |
#ifdef SUPPORT_GEN1 |
269 |
int e1check; /* E1 check */ |
270 |
#endif |
271 |
struct dahdi_span span; |
272 |
unsigned char txsigs[16]; /* Transmit sigs */ |
273 |
int loopupcnt; |
274 |
int loopdowncnt; |
275 |
#ifdef SUPPORT_GEN1 |
276 |
unsigned char ec_chunk1[31][DAHDI_CHUNKSIZE]; /* first EC chunk buffer */ |
277 |
unsigned char ec_chunk2[31][DAHDI_CHUNKSIZE]; /* second EC chunk buffer */ |
278 |
#endif |
279 |
int irqmisses; |
280 |
|
281 |
/* HDLC controller fields */ |
282 |
struct dahdi_chan *sigchan; |
283 |
unsigned char sigmode; |
284 |
int sigactive; |
285 |
int frames_out; |
286 |
int frames_in; |
287 |
|
288 |
#ifdef VPM_SUPPORT |
289 |
unsigned long dtmfactive; |
290 |
unsigned long dtmfmask; |
291 |
unsigned long dtmfmutemask; |
292 |
short dtmfenergy[31]; |
293 |
short dtmfdigit[31]; |
294 |
#endif |
295 |
#ifdef ENABLE_WORKQUEUES |
296 |
struct work_struct swork; |
297 |
#endif |
298 |
struct dahdi_chan *chans[32]; /* Individual channels */ |
299 |
struct dahdi_echocan_state *ec[32]; /* Echocan state for each channel */ |
300 |
}; |
301 |
|
302 |
struct t4 { |
303 |
/* This structure exists one per card */ |
304 |
struct pci_dev *dev; /* Pointer to PCI device */ |
305 |
struct dahdi_device *ddev; /* Pointer to DAHDI device */ |
306 |
unsigned int intcount; |
307 |
int num; /* Which card we are */ |
308 |
int t1e1; /* T1/E1 select pins */ |
309 |
int globalconfig; /* Whether global setup has been done */ |
310 |
int syncsrc; /* active sync source */ |
311 |
struct t4_span *tspans[4]; /* Individual spans */ |
312 |
int numspans; /* Number of spans on the card */ |
313 |
int blinktimer; |
314 |
#ifdef FANCY_ALARM |
315 |
int alarmpos; |
316 |
#endif |
317 |
int irq; /* IRQ used by device */ |
318 |
int order; /* Order */ |
319 |
int flags; /* Device flags */ |
320 |
unsigned int falc31 : 1; /* are we falc v3.1 (atomic not necessary) */ |
321 |
int master; /* Are we master */ |
322 |
int ledreg; /* LED Register */ |
323 |
unsigned int gpio; |
324 |
unsigned int gpioctl; |
325 |
int e1recover; /* E1 recovery timer */ |
326 |
spinlock_t reglock; /* lock register access */ |
327 |
int spansstarted; /* number of spans started */ |
328 |
volatile unsigned int *writechunk; /* Double-word aligned write memory */ |
329 |
volatile unsigned int *readchunk; /* Double-word aligned read memory */ |
330 |
unsigned short canary; |
331 |
#ifdef ENABLE_WORKQUEUES |
332 |
atomic_t worklist; |
333 |
struct workqueue_struct *workq; |
334 |
#endif |
335 |
unsigned int passno; /* number of interrupt passes */ |
336 |
char *variety; |
337 |
int last0; /* for detecting double-missed IRQ */ |
338 |
|
339 |
/* DMA related fields */ |
340 |
unsigned int dmactrl; |
341 |
dma_addr_t readdma; |
342 |
dma_addr_t writedma; |
343 |
unsigned long memaddr; /* Base address of card */ |
344 |
unsigned long memlen; |
345 |
__iomem volatile unsigned int *membase; /* Base address of card */ |
346 |
|
347 |
/* Add this for our softlockup protector */ |
348 |
unsigned int oct_rw_count; |
349 |
|
350 |
/* Flags for our bottom half */ |
351 |
unsigned long checkflag; |
352 |
struct tasklet_struct t4_tlet; |
353 |
unsigned int vpm400checkstatus; |
354 |
/* Latency related additions */ |
355 |
unsigned char rxident; |
356 |
unsigned char lastindex; |
357 |
int numbufs; |
358 |
int needed_latency; |
359 |
|
360 |
#ifdef VPM_SUPPORT |
361 |
struct vpm450m *vpm450m; |
362 |
int vpm; |
363 |
#endif |
364 |
|
365 |
}; |
366 |
|
367 |
#define T4_VPM_PRESENT (1 << 28) |
368 |
|
369 |
#ifdef VPM_SUPPORT |
370 |
static void t4_vpm400_init(struct t4 *wc); |
371 |
static void t4_vpm450_init(struct t4 *wc); |
372 |
static void t4_vpm_set_dtmf_threshold(struct t4 *wc, unsigned int threshold); |
373 |
|
374 |
static void echocan_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec); |
375 |
|
376 |
static const struct dahdi_echocan_features vpm400m_ec_features = { |
377 |
.NLP_automatic = 1, |
378 |
.CED_tx_detect = 1, |
379 |
.CED_rx_detect = 1, |
380 |
}; |
381 |
|
382 |
static const struct dahdi_echocan_features vpm450m_ec_features = { |
383 |
.NLP_automatic = 1, |
384 |
.CED_tx_detect = 1, |
385 |
.CED_rx_detect = 1, |
386 |
}; |
387 |
|
388 |
static const struct dahdi_echocan_ops vpm400m_ec_ops = { |
389 |
.echocan_free = echocan_free, |
390 |
}; |
391 |
|
392 |
static const struct dahdi_echocan_ops vpm450m_ec_ops = { |
393 |
.echocan_free = echocan_free, |
394 |
}; |
395 |
#endif |
396 |
|
397 |
static void __set_clear(struct t4 *wc, int span); |
398 |
static int t4_startup(struct file *file, struct dahdi_span *span); |
399 |
static int t4_shutdown(struct dahdi_span *span); |
400 |
static int t4_rbsbits(struct dahdi_chan *chan, int bits); |
401 |
static int t4_maint(struct dahdi_span *span, int cmd); |
402 |
static int t4_clear_maint(struct dahdi_span *span); |
403 |
#if (defined(DAHDI_SPAN_OPS) || defined(DAHDI_SPAN_MODULE) ) |
404 |
static int t4_reset_counters(struct dahdi_span *span); |
405 |
#endif |
406 |
#ifdef SUPPORT_GEN1 |
407 |
static int t4_reset_dma(struct t4 *wc); |
408 |
#endif |
409 |
static void t4_hdlc_hard_xmit(struct dahdi_chan *chan); |
410 |
static int t4_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long data); |
411 |
static void t4_tsi_assign(struct t4 *wc, int fromspan, int fromchan, int tospan, int tochan); |
412 |
static void t4_tsi_unassign(struct t4 *wc, int tospan, int tochan); |
413 |
static void __t4_set_rclk_src(struct t4 *wc, int span); |
414 |
static void __t4_set_sclk_src(struct t4 *wc, int mode, int master, int slave); |
415 |
static void t4_check_alarms(struct t4 *wc, int span); |
416 |
static void t4_check_sigbits(struct t4 *wc, int span); |
417 |
|
418 |
#define WC_RDADDR 0 |
419 |
#define WC_WRADDR 1 |
420 |
#define WC_COUNT 2 |
421 |
#define WC_DMACTRL 3 |
422 |
#define WC_INTR 4 |
423 |
/* #define WC_GPIO 5 */ |
424 |
#define WC_VERSION 6 |
425 |
#define WC_LEDS 7 |
426 |
#define WC_GPIOCTL 8 |
427 |
#define WC_GPIO 9 |
428 |
#define WC_LADDR 10 |
429 |
#define WC_LDATA 11 |
430 |
#define WC_LCS (1 << 11) |
431 |
#define WC_LCS2 (1 << 12) |
432 |
#define WC_LALE (1 << 13) |
433 |
#define WC_LFRMR_CS (1 << 10) /* Framer's ChipSelect signal */ |
434 |
#define WC_ACTIVATE (1 << 12) |
435 |
#define WC_LREAD (1 << 15) |
436 |
#define WC_LWRITE (1 << 16) |
437 |
|
438 |
#define WC_OFF (0) |
439 |
#define WC_RED (1) |
440 |
#define WC_GREEN (2) |
441 |
#define WC_YELLOW (3) |
442 |
|
443 |
#define WC_RECOVER 0 |
444 |
#define WC_SELF 1 |
445 |
|
446 |
#define LIM0_T 0x36 /* Line interface mode 0 register */ |
447 |
#define LIM0_LL (1 << 1) /* Local Loop */ |
448 |
#define LIM1_T 0x37 /* Line interface mode 1 register */ |
449 |
#define LIM1_RL (1 << 1) /* Remote Loop */ |
450 |
|
451 |
#define FMR0 0x1C /* Framer Mode Register 0 */ |
452 |
#define FMR0_SIM (1 << 0) /* Alarm Simulation */ |
453 |
#define FMR1_T 0x1D /* Framer Mode Register 1 */ |
454 |
#define FMR1_ECM (1 << 2) /* Error Counter 1sec Interrupt Enable */ |
455 |
#define DEC_T 0x60 /* Diable Error Counter */ |
456 |
#define IERR_T 0x1B /* Single Bit Defect Insertion Register */ |
457 |
#define IBV 0 /* Bipolar violation */ |
458 |
#define IPE (1 << 1) /* PRBS defect */ |
459 |
#define ICASE (1 << 2) /* CAS defect */ |
460 |
#define ICRCE (1 << 3) /* CRC defect */ |
461 |
#define IMFE (1 << 4) /* Multiframe defect */ |
462 |
#define IFASE (1 << 5) /* FAS defect */ |
463 |
#define ISR3_SEC (1 << 6) /* Internal one-second interrupt bit mask */ |
464 |
#define ISR3_ES (1 << 7) /* Errored Second interrupt bit mask */ |
465 |
#define ESM 0x47 /* Errored Second mask register */ |
466 |
|
467 |
#define FMR2_T 0x1E /* Framer Mode Register 2 */ |
468 |
#define FMR2_PLB (1 << 2) /* Framer Mode Register 2 */ |
469 |
|
470 |
#define FECL_T 0x50 /* Framing Error Counter Lower Byte */ |
471 |
#define FECH_T 0x51 /* Framing Error Counter Higher Byte */ |
472 |
#define CVCL_T 0x52 /* Code Violation Counter Lower Byte */ |
473 |
#define CVCH_T 0x53 /* Code Violation Counter Higher Byte */ |
474 |
#define CEC1L_T 0x54 /* CRC Error Counter 1 Lower Byte */ |
475 |
#define CEC1H_T 0x55 /* CRC Error Counter 1 Higher Byte */ |
476 |
#define EBCL_T 0x56 /* E-Bit Error Counter Lower Byte */ |
477 |
#define EBCH_T 0x57 /* E-Bit Error Counter Higher Byte */ |
478 |
#define BECL_T 0x58 /* Bit Error Counter Lower Byte */ |
479 |
#define BECH_T 0x59 /* Bit Error Counter Higher Byte */ |
480 |
#define COEC_T 0x5A /* COFA Event Counter */ |
481 |
#define PRBSSTA_T 0xDA /* PRBS Status Register */ |
482 |
|
483 |
#define LCR1_T 0x3B /* Loop Code Register 1 */ |
484 |
#define EPRM (1 << 7) /* Enable PRBS rx */ |
485 |
#define XPRBS (1 << 6) /* Enable PRBS tx */ |
486 |
#define FLLB (1 << 1) /* Framed line loop/Invert */ |
487 |
#define LLBP (1 << 0) /* Line Loopback Pattern */ |
488 |
#define TPC0_T 0xA8 /* Test Pattern Control Register */ |
489 |
#define FRA (1 << 6) /* Framed/Unframed Selection */ |
490 |
#define PRBS23 (3 << 4) /* Pattern selection (23 poly) */ |
491 |
#define PRM (1 << 2) /* Non framed mode */ |
492 |
#define FRS1_T 0x4D /* Framer Receive Status Reg 1 */ |
493 |
#define LLBDD (1 << 4) |
494 |
#define LLBAD (1 << 3) |
495 |
|
496 |
#define MAX_T4_CARDS 64 |
497 |
|
498 |
static void t4_isr_bh(unsigned long data); |
499 |
|
500 |
static struct t4 *cards[MAX_T4_CARDS]; |
501 |
|
502 |
|
503 |
#define MAX_TDM_CHAN 32 |
504 |
#define MAX_DTMF_DET 16 |
505 |
|
506 |
#define HDLC_IMR0_MASK (FRMR_IMR0_RME | FRMR_IMR0_RPF) |
507 |
#if 0 |
508 |
#define HDLC_IMR1_MASK (FRMR_IMR1_ALLS | FRMR_IMR1_XDU | FRMR_IMR1_XPR) |
509 |
#else |
510 |
#define HDLC_IMR1_MASK (FRMR_IMR1_XDU | FRMR_IMR1_XPR) |
511 |
#endif |
512 |
|
513 |
static inline unsigned int __t4_pci_in(struct t4 *wc, const unsigned int addr) |
514 |
{ |
515 |
unsigned int res = readl(&wc->membase[addr]); |
516 |
return res; |
517 |
} |
518 |
|
519 |
static inline void __t4_pci_out(struct t4 *wc, const unsigned int addr, const unsigned int value) |
520 |
{ |
521 |
unsigned int tmp; |
522 |
writel(value, &wc->membase[addr]); |
523 |
if (pedanticpci) { |
524 |
tmp = __t4_pci_in(wc, WC_VERSION); |
525 |
if ((tmp & 0xffff0000) != 0xc01a0000) |
526 |
dev_notice(&wc->dev->dev, |
527 |
"Version Synchronization Error!\n"); |
528 |
} |
529 |
#if 0 |
530 |
tmp = __t4_pci_in(wc, addr); |
531 |
if ((value != tmp) && (addr != WC_LEDS) && (addr != WC_LDATA) && |
532 |
(addr != WC_GPIO) && (addr != WC_INTR)) |
533 |
dev_info(&wc->dev->dev, "Tried to load %08x into %08x, " |
534 |
"but got %08x instead\n", value, addr, tmp); |
535 |
#endif |
536 |
} |
537 |
|
538 |
static inline void __t4_gpio_set(struct t4 *wc, unsigned bits, unsigned int val) |
539 |
{ |
540 |
unsigned int newgpio; |
541 |
newgpio = wc->gpio & (~bits); |
542 |
newgpio |= val; |
543 |
if (newgpio != wc->gpio) { |
544 |
wc->gpio = newgpio; |
545 |
__t4_pci_out(wc, WC_GPIO, wc->gpio); |
546 |
} |
547 |
} |
548 |
|
549 |
static inline void __t4_gpio_setdir(struct t4 *wc, unsigned int bits, unsigned int val) |
550 |
{ |
551 |
unsigned int newgpioctl; |
552 |
newgpioctl = wc->gpioctl & (~bits); |
553 |
newgpioctl |= val; |
554 |
if (newgpioctl != wc->gpioctl) { |
555 |
wc->gpioctl = newgpioctl; |
556 |
__t4_pci_out(wc, WC_GPIOCTL, wc->gpioctl); |
557 |
} |
558 |
} |
559 |
|
560 |
static inline void t4_gpio_setdir(struct t4 *wc, unsigned int bits, unsigned int val) |
561 |
{ |
562 |
unsigned long flags; |
563 |
spin_lock_irqsave(&wc->reglock, flags); |
564 |
__t4_gpio_setdir(wc, bits, val); |
565 |
spin_unlock_irqrestore(&wc->reglock, flags); |
566 |
} |
567 |
|
568 |
static inline void t4_gpio_set(struct t4 *wc, unsigned int bits, unsigned int val) |
569 |
{ |
570 |
unsigned long flags; |
571 |
spin_lock_irqsave(&wc->reglock, flags); |
572 |
__t4_gpio_set(wc, bits, val); |
573 |
spin_unlock_irqrestore(&wc->reglock, flags); |
574 |
} |
575 |
|
576 |
static inline void t4_pci_out(struct t4 *wc, const unsigned int addr, const unsigned int value) |
577 |
{ |
578 |
unsigned long flags; |
579 |
spin_lock_irqsave(&wc->reglock, flags); |
580 |
__t4_pci_out(wc, addr, value); |
581 |
spin_unlock_irqrestore(&wc->reglock, flags); |
582 |
} |
583 |
|
584 |
static inline void __t4_set_led(struct t4 *wc, int span, int color) |
585 |
{ |
586 |
int oldreg = wc->ledreg; |
587 |
wc->ledreg &= ~(0x3 << (span << 1)); |
588 |
wc->ledreg |= (color << (span << 1)); |
589 |
if (oldreg != wc->ledreg) |
590 |
__t4_pci_out(wc, WC_LEDS, wc->ledreg); |
591 |
} |
592 |
|
593 |
static inline void t4_activate(struct t4 *wc) |
594 |
{ |
595 |
wc->ledreg |= WC_ACTIVATE; |
596 |
t4_pci_out(wc, WC_LEDS, wc->ledreg); |
597 |
} |
598 |
|
599 |
static inline unsigned int t4_pci_in(struct t4 *wc, const unsigned int addr) |
600 |
{ |
601 |
unsigned int ret; |
602 |
unsigned long flags; |
603 |
|
604 |
spin_lock_irqsave(&wc->reglock, flags); |
605 |
ret = __t4_pci_in(wc, addr); |
606 |
spin_unlock_irqrestore(&wc->reglock, flags); |
607 |
return ret; |
608 |
} |
609 |
|
610 |
static inline unsigned int __t4_framer_in(struct t4 *wc, int unit, const unsigned int addr) |
611 |
{ |
612 |
unsigned int ret; |
613 |
unit &= 0x3; |
614 |
__t4_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff)); |
615 |
if (!pedanticpci) |
616 |
__t4_pci_in(wc, WC_VERSION); |
617 |
__t4_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff) | WC_LFRMR_CS | WC_LREAD); |
618 |
if (!pedanticpci) { |
619 |
__t4_pci_in(wc, WC_VERSION); |
620 |
} else { |
621 |
__t4_pci_out(wc, WC_VERSION, 0); |
622 |
} |
623 |
ret = __t4_pci_in(wc, WC_LDATA); |
624 |
__t4_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff)); |
625 |
|
626 |
if (unlikely(debug & DEBUG_REGS)) |
627 |
dev_info(&wc->dev->dev, "Reading unit %d address %02x is " |
628 |
"%02x\n", unit, addr, ret & 0xff); |
629 |
|
630 |
if (!pedanticpci) |
631 |
__t4_pci_in(wc, WC_VERSION); |
632 |
|
633 |
return ret & 0xff; |
634 |
} |
635 |
|
636 |
static inline unsigned int t4_framer_in(struct t4 *wc, int unit, const unsigned int addr) |
637 |
{ |
638 |
unsigned long flags; |
639 |
unsigned int ret; |
640 |
spin_lock_irqsave(&wc->reglock, flags); |
641 |
ret = __t4_framer_in(wc, unit, addr); |
642 |
spin_unlock_irqrestore(&wc->reglock, flags); |
643 |
return ret; |
644 |
|
645 |
} |
646 |
|
647 |
static inline void __t4_framer_out(struct t4 *wc, int unit, const unsigned int addr, const unsigned int value) |
648 |
{ |
649 |
unit &= 0x3; |
650 |
if (unlikely(debug & DEBUG_REGS)) |
651 |
dev_info(&wc->dev->dev, "Writing %02x to address %02x of " |
652 |
"unit %d\n", value, addr, unit); |
653 |
__t4_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff)); |
654 |
__t4_pci_out(wc, WC_LDATA, value); |
655 |
if (!pedanticpci) |
656 |
__t4_pci_in(wc, WC_VERSION); |
657 |
__t4_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff) | WC_LFRMR_CS | WC_LWRITE); |
658 |
if (!pedanticpci) |
659 |
__t4_pci_in(wc, WC_VERSION); |
660 |
__t4_pci_out(wc, WC_LADDR, (unit << 8) | (addr & 0xff)); |
661 |
if (!pedanticpci) |
662 |
__t4_pci_in(wc, WC_VERSION); |
663 |
if (unlikely(debug & DEBUG_REGS)) |
664 |
dev_info(&wc->dev->dev, "Write complete\n"); |
665 |
#if 0 |
666 |
if ((addr != FRMR_TXFIFO) && (addr != FRMR_CMDR) && (addr != 0xbc)) |
667 |
{ unsigned int tmp; |
668 |
tmp = __t4_framer_in(wc, unit, addr); |
669 |
if (tmp != value) { |
670 |
dev_notice(&wc->dev->dev, "Expected %d from unit %d " |
671 |
"register %d but got %d instead\n", |
672 |
value, unit, addr, tmp); |
673 |
} } |
674 |
#endif |
675 |
} |
676 |
|
677 |
static inline void t4_framer_out(struct t4 *wc, int unit, const unsigned int addr, const unsigned int value) |
678 |
{ |
679 |
unsigned long flags; |
680 |
spin_lock_irqsave(&wc->reglock, flags); |
681 |
__t4_framer_out(wc, unit, addr, value); |
682 |
spin_unlock_irqrestore(&wc->reglock, flags); |
683 |
} |
684 |
|
685 |
#ifdef VPM_SUPPORT |
686 |
|
687 |
static inline void wait_a_little(void) |
688 |
{ |
689 |
unsigned long newjiffies=jiffies+2; |
690 |
while(jiffies < newjiffies); |
691 |
} |
692 |
|
693 |
static inline unsigned int __t4_vpm_in(struct t4 *wc, int unit, const unsigned int addr) |
694 |
{ |
695 |
unsigned int ret; |
696 |
unit &= 0x7; |
697 |
__t4_pci_out(wc, WC_LADDR, (addr & 0x1ff) | ( unit << 12)); |
698 |
__t4_pci_out(wc, WC_LADDR, (addr & 0x1ff) | ( unit << 12) | (1 << 11) | WC_LREAD); |
699 |
ret = __t4_pci_in(wc, WC_LDATA); |
700 |
__t4_pci_out(wc, WC_LADDR, 0); |
701 |
return ret & 0xff; |
702 |
} |
703 |
|
704 |
static inline void __t4_raw_oct_out(struct t4 *wc, const unsigned int addr, const unsigned int value) |
705 |
{ |
706 |
int octopt = wc->tspans[0]->spanflags & FLAG_OCTOPT; |
707 |
if (!octopt) |
708 |
__t4_gpio_set(wc, 0xff, (addr >> 8)); |
709 |
__t4_pci_out(wc, WC_LDATA, 0x10000 | (addr & 0xffff)); |
710 |
if (!octopt) |
711 |
__t4_pci_out(wc, WC_LADDR, (WC_LWRITE)); |
712 |
__t4_pci_out(wc, WC_LADDR, (WC_LWRITE | WC_LALE)); |
713 |
if (!pedanticpci) |
714 |
__t4_pci_in(wc, WC_VERSION); |
715 |
if (!octopt) |
716 |
__t4_gpio_set(wc, 0xff, (value >> 8)); |
717 |
__t4_pci_out(wc, WC_LDATA, (value & 0xffff)); |
718 |
__t4_pci_out(wc, WC_LADDR, (WC_LWRITE | WC_LALE | WC_LCS)); |
719 |
if (!pedanticpci) |
720 |
__t4_pci_in(wc, WC_VERSION); |
721 |
__t4_pci_out(wc, WC_LADDR, (0)); |
722 |
if (!pedanticpci) |
723 |
__t4_pci_in(wc, WC_VERSION); |
724 |
} |
725 |
|
726 |
static inline unsigned int __t4_raw_oct_in(struct t4 *wc, const unsigned int addr) |
727 |
{ |
728 |
unsigned int ret; |
729 |
int octopt = wc->tspans[0]->spanflags & FLAG_OCTOPT; |
730 |
if (!octopt) |
731 |
__t4_gpio_set(wc, 0xff, (addr >> 8)); |
732 |
__t4_pci_out(wc, WC_LDATA, 0x10000 | (addr & 0xffff)); |
733 |
if (!octopt) |
734 |
__t4_pci_out(wc, WC_LADDR, (WC_LWRITE)); |
735 |
if (!pedanticpci) |
736 |
__t4_pci_in(wc, WC_VERSION); |
737 |
__t4_pci_out(wc, WC_LADDR, (WC_LWRITE | WC_LALE)); |
738 |
if (!pedanticpci) |
739 |
__t4_pci_in(wc, WC_VERSION); |
740 |
#ifdef PEDANTIC_OCTASIC_CHECKING |
741 |
__t4_pci_out(wc, WC_LADDR, (WC_LALE)); |
742 |
if (!pedanticpci) |
743 |
__t4_pci_in(wc, WC_VERSION); |
744 |
#endif |
745 |
if (!octopt) { |
746 |
__t4_gpio_setdir(wc, 0xff, 0x00); |
747 |
__t4_gpio_set(wc, 0xff, 0x00); |
748 |
} |
749 |
__t4_pci_out(wc, WC_LADDR, (WC_LREAD | WC_LALE | WC_LCS)); |
750 |
if (!pedanticpci) |
751 |
__t4_pci_in(wc, WC_VERSION); |
752 |
if (octopt) { |
753 |
ret = __t4_pci_in(wc, WC_LDATA) & 0xffff; |
754 |
} else { |
755 |
ret = __t4_pci_in(wc, WC_LDATA) & 0xff; |
756 |
ret |= (__t4_pci_in(wc, WC_GPIO) & 0xff) << 8; |
757 |
} |
758 |
__t4_pci_out(wc, WC_LADDR, (0)); |
759 |
if (!pedanticpci) |
760 |
__t4_pci_in(wc, WC_VERSION); |
761 |
if (!octopt) |
762 |
__t4_gpio_setdir(wc, 0xff, 0xff); |
763 |
return ret & 0xffff; |
764 |
} |
765 |
|
766 |
static inline unsigned int __t4_oct_in(struct t4 *wc, unsigned int addr) |
767 |
{ |
768 |
#ifdef PEDANTIC_OCTASIC_CHECKING |
769 |
int count = 1000; |
770 |
#endif |
771 |
__t4_raw_oct_out(wc, 0x0008, (addr >> 20)); |
772 |
__t4_raw_oct_out(wc, 0x000a, (addr >> 4) & ((1 << 16) - 1)); |
773 |
__t4_raw_oct_out(wc, 0x0000, (((addr >> 1) & 0x7) << 9) | (1 << 8) | (1)); |
774 |
#ifdef PEDANTIC_OCTASIC_CHECKING |
775 |
while((__t4_raw_oct_in(wc, 0x0000) & (1 << 8)) && --count); |
776 |
if (count != 1000) |
777 |
dev_notice(&wc->dev->dev, "Yah, read can be slow...\n"); |
778 |
if (!count) |
779 |
dev_notice(&wc->dev->dev, "Read timed out!\n"); |
780 |
#endif |
781 |
return __t4_raw_oct_in(wc, 0x0004); |
782 |
} |
783 |
|
784 |
static inline unsigned int t4_oct_in(struct t4 *wc, const unsigned int addr) |
785 |
{ |
786 |
unsigned long flags; |
787 |
unsigned int ret; |
788 |
|
789 |
spin_lock_irqsave(&wc->reglock, flags); |
790 |
ret = __t4_oct_in(wc, addr); |
791 |
spin_unlock_irqrestore(&wc->reglock, flags); |
792 |
return ret; |
793 |
} |
794 |
|
795 |
static inline unsigned int t4_vpm_in(struct t4 *wc, int unit, const unsigned int addr) |
796 |
{ |
797 |
unsigned long flags; |
798 |
unsigned int ret; |
799 |
spin_lock_irqsave(&wc->reglock, flags); |
800 |
ret = __t4_vpm_in(wc, unit, addr); |
801 |
spin_unlock_irqrestore(&wc->reglock, flags); |
802 |
return ret; |
803 |
} |
804 |
|
805 |
static inline void __t4_vpm_out(struct t4 *wc, int unit, const unsigned int addr, const unsigned int value) |
806 |
{ |
807 |
unit &= 0x7; |
808 |
if (debug & DEBUG_REGS) |
809 |
dev_notice(&wc->dev->dev, "Writing %02x to address %02x of " |
810 |
"ec unit %d\n", value, addr, unit); |
811 |
__t4_pci_out(wc, WC_LADDR, (addr & 0xff)); |
812 |
__t4_pci_out(wc, WC_LDATA, value); |
813 |
__t4_pci_out(wc, WC_LADDR, (unit << 12) | (addr & 0x1ff) | (1 << 11)); |
814 |
__t4_pci_out(wc, WC_LADDR, (unit << 12) | (addr & 0x1ff) | (1 << 11) | WC_LWRITE); |
815 |
__t4_pci_out(wc, WC_LADDR, (unit << 12) | (addr & 0x1ff) | (1 << 11)); |
816 |
__t4_pci_out(wc, WC_LADDR, (unit << 12) | (addr & 0x1ff)); |
817 |
__t4_pci_out(wc, WC_LADDR, 0); |
818 |
if (debug & DEBUG_REGS) |
819 |
dev_notice(&wc->dev->dev, "Write complete\n"); |
820 |
|
821 |
|
822 |
#if 0 |
823 |
{ unsigned int tmp; |
824 |
tmp = t4_vpm_in(wc, unit, addr); |
825 |
if (tmp != value) { |
826 |
dev_notice(&wc->dev->dev, "Expected %d from unit %d echo " |
827 |
"register %d but got %d instead\n", |
828 |
value, unit, addr, tmp); |
829 |
} } |
830 |
#endif |
831 |
} |
832 |
|
833 |
static inline void __t4_oct_out(struct t4 *wc, unsigned int addr, unsigned int value) |
834 |
{ |
835 |
#ifdef PEDANTIC_OCTASIC_CHECKING |
836 |
int count = 1000; |
837 |
#endif |
838 |
__t4_raw_oct_out(wc, 0x0008, (addr >> 20)); |
839 |
__t4_raw_oct_out(wc, 0x000a, (addr >> 4) & ((1 << 16) - 1)); |
840 |
__t4_raw_oct_out(wc, 0x0004, value); |
841 |
__t4_raw_oct_out(wc, 0x0000, (((addr >> 1) & 0x7) << 9) | (1 << 8) | (3 << 12) | 1); |
842 |
#ifdef PEDANTIC_OCTASIC_CHECKING |
843 |
while((__t4_raw_oct_in(wc, 0x0000) & (1 << 8)) && --count); |
844 |
if (count != 1000) |
845 |
dev_notice(&wc->dev->dev, "Yah, write can be slow\n"); |
846 |
if (!count) |
847 |
dev_notice(&wc->dev->dev, "Write timed out!\n"); |
848 |
#endif |
849 |
} |
850 |
|
851 |
static inline void t4_oct_out(struct t4 *wc, const unsigned int addr, const unsigned int value) |
852 |
{ |
853 |
unsigned long flags; |
854 |
|
855 |
spin_lock_irqsave(&wc->reglock, flags); |
856 |
__t4_oct_out(wc, addr, value); |
857 |
spin_unlock_irqrestore(&wc->reglock, flags); |
858 |
} |
859 |
|
860 |
static inline void t4_vpm_out(struct t4 *wc, int unit, const unsigned int addr, const unsigned int value) |
861 |
{ |
862 |
unsigned long flags; |
863 |
spin_lock_irqsave(&wc->reglock, flags); |
864 |
__t4_vpm_out(wc, unit, addr, value); |
865 |
spin_unlock_irqrestore(&wc->reglock, flags); |
866 |
} |
867 |
|
868 |
static const char vpm_digits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', '*', '#'}; |
869 |
|
870 |
static void t4_check_vpm450(struct t4 *wc) |
871 |
{ |
872 |
int channel, tone, start, span; |
873 |
|
874 |
if (vpm450m_checkirq(wc->vpm450m)) { |
875 |
while(vpm450m_getdtmf(wc->vpm450m, &channel, &tone, &start)) { |
876 |
span = channel & 0x3; |
877 |
channel >>= 2; |
878 |
if (!wc->t1e1) |
879 |
channel -= 5; |
880 |
else |
881 |
channel -= 1; |
882 |
if (unlikely(debug)) |
883 |
dev_info(&wc->dev->dev, "Got tone %s of '%c' " |
884 |
"on channel %d of span %d\n", |
885 |
(start ? "START" : "STOP"), |
886 |
tone, channel, span + 1); |
887 |
if (test_bit(channel, &wc->tspans[span]->dtmfmask) && (tone != 'u')) { |
888 |
if (start) { |
889 |
/* The octasic is supposed to mute us, but... Yah, you |
890 |
guessed it. */ |
891 |
if (test_bit(channel, &wc->tspans[span]->dtmfmutemask)) { |
892 |
unsigned long flags; |
893 |
struct dahdi_chan *chan = wc->tspans[span]->span.chans[channel]; |
894 |
int y; |
895 |
spin_lock_irqsave(&chan->lock, flags); |
896 |
for (y=0;y<chan->numbufs;y++) { |
897 |
if ((chan->inreadbuf > -1) && (chan->readidx[y])) |
898 |
memset(chan->readbuf[chan->inreadbuf], DAHDI_XLAW(0, chan), chan->readidx[y]); |
899 |
} |
900 |
spin_unlock_irqrestore(&chan->lock, flags); |
901 |
} |
902 |
set_bit(channel, &wc->tspans[span]->dtmfactive); |
903 |
dahdi_qevent_lock(wc->tspans[span]->span.chans[channel], (DAHDI_EVENT_DTMFDOWN | tone)); |
904 |
} else { |
905 |
clear_bit(channel, &wc->tspans[span]->dtmfactive); |
906 |
dahdi_qevent_lock(wc->tspans[span]->span.chans[channel], (DAHDI_EVENT_DTMFUP | tone)); |
907 |
} |
908 |
} |
909 |
} |
910 |
} |
911 |
} |
912 |
|
913 |
static void t4_check_vpm400(struct t4 *wc, unsigned int newio) |
914 |
{ |
915 |
unsigned int digit, regval = 0; |
916 |
unsigned int regbyte; |
917 |
int x, i; |
918 |
short energy=0; |
919 |
static unsigned int lastio = 0; |
920 |
struct t4_span *ts; |
921 |
|
922 |
if (debug && (newio != lastio)) |
923 |
dev_notice(&wc->dev->dev, "Last was %08x, new is %08x\n", |
924 |
lastio, newio); |
925 |
|
926 |
lastio = newio; |
927 |
|
928 |
for(x = 0; x < 8; x++) { |
929 |
if (newio & (1 << (7 - x))) |
930 |
continue; |
931 |
ts = wc->tspans[x%4]; |
932 |
/* Start of DTMF detection process */ |
933 |
regbyte = t4_vpm_in(wc, x, 0xb8); |
934 |
t4_vpm_out(wc, x, 0xb8, regbyte); /* Write 1 to clear */ |
935 |
regval = regbyte << 8; |
936 |
regbyte = t4_vpm_in(wc, x, 0xb9); |
937 |
t4_vpm_out(wc, x, 0xb9, regbyte); |
938 |
regval |= regbyte; |
939 |
|
940 |
for(i = 0; (i < MAX_DTMF_DET) && regval; i++) { |
941 |
if(regval & 0x0001) { |
942 |
int channel = (i << 1) + (x >> 2); |
943 |
int base = channel - 1; |
944 |
|
945 |
if (!wc->t1e1) |
946 |
base -= 4; |
947 |
regbyte = t4_vpm_in(wc, x, 0xa8 + i); |
948 |
digit = vpm_digits[regbyte]; |
949 |
if (!(wc->tspans[0]->spanflags & FLAG_VPM2GEN)) { |
950 |
energy = t4_vpm_in(wc, x, 0x58 + channel); |
951 |
energy = DAHDI_XLAW(energy, ts->chans[0]); |
952 |
ts->dtmfenergy[base] = energy; |
953 |
} |
954 |
set_bit(base, &ts->dtmfactive); |
955 |
if (ts->dtmfdigit[base]) { |
956 |
if (ts->dtmfmask & (1 << base)) |
957 |
dahdi_qevent_lock(ts->span.chans[base], (DAHDI_EVENT_DTMFUP | ts->dtmfdigit[base])); |
958 |
} |
959 |
ts->dtmfdigit[base] = digit; |
960 |
if (test_bit(base, &ts->dtmfmask)) |
961 |
dahdi_qevent_lock(ts->span.chans[base], (DAHDI_EVENT_DTMFDOWN | digit)); |
962 |
if (test_bit(base, &ts->dtmfmutemask)) { |
963 |
/* Mute active receive buffer*/ |
964 |
unsigned long flags; |
965 |
struct dahdi_chan *chan = ts->span.chans[base]; |
966 |
int y; |
967 |
spin_lock_irqsave(&chan->lock, flags); |
968 |
for (y=0;y<chan->numbufs;y++) { |
969 |
if ((chan->inreadbuf > -1) && (chan->readidx[y])) |
970 |
memset(chan->readbuf[chan->inreadbuf], DAHDI_XLAW(0, chan), chan->readidx[y]); |
971 |
} |
972 |
spin_unlock_irqrestore(&chan->lock, flags); |
973 |
} |
974 |
if (debug) |
975 |
dev_notice(&wc->dev->dev, "Digit " |
976 |
"Seen: %d, Span: %d, channel:" |
977 |
" %d, energy: %02x, 'channel " |
978 |
"%d' chip %d\n", digit, x % 4, |
979 |
base + 1, energy, channel, x); |
980 |
|
981 |
} |
982 |
regval = regval >> 1; |
983 |
} |
984 |
if (!(wc->tspans[0]->spanflags & FLAG_VPM2GEN)) |
985 |
continue; |
986 |
|
987 |
/* Start of DTMF off detection process */ |
988 |
regbyte = t4_vpm_in(wc, x, 0xbc); |
989 |
t4_vpm_out(wc, x, 0xbc, regbyte); /* Write 1 to clear */ |
990 |
regval = regbyte << 8; |
991 |
regbyte = t4_vpm_in(wc, x, 0xbd); |
992 |
t4_vpm_out(wc, x, 0xbd, regbyte); |
993 |
regval |= regbyte; |
994 |
|
995 |
for(i = 0; (i < MAX_DTMF_DET) && regval; i++) { |
996 |
if(regval & 0x0001) { |
997 |
int channel = (i << 1) + (x >> 2); |
998 |
int base = channel - 1; |
999 |
|
1000 |
if (!wc->t1e1) |
1001 |
base -= 4; |
1002 |
clear_bit(base, &ts->dtmfactive); |
1003 |
if (ts->dtmfdigit[base]) { |
1004 |
if (test_bit(base, &ts->dtmfmask)) |
1005 |
dahdi_qevent_lock(ts->span.chans[base], (DAHDI_EVENT_DTMFUP | ts->dtmfdigit[base])); |
1006 |
} |
1007 |
digit = ts->dtmfdigit[base]; |
1008 |
ts->dtmfdigit[base] = 0; |
1009 |
if (debug) |
1010 |
dev_notice(&wc->dev->dev, "Digit " |
1011 |
"Gone: %d, Span: %d, channel:" |
1012 |
" %d, energy: %02x, 'channel " |
1013 |
"%d' chip %d\n", digit, x % 4, |
1014 |
base + 1, energy, channel, x); |
1015 |
|
1016 |
} |
1017 |
regval = regval >> 1; |
1018 |
} |
1019 |
|
1020 |
} |
1021 |
} |
1022 |
#endif |
1023 |
|
1024 |
static void hdlc_stop(struct t4 *wc, unsigned int span) |
1025 |
{ |
1026 |
struct t4_span *t = wc->tspans[span]; |
1027 |
unsigned char imr0, imr1, mode; |
1028 |
int i = 0; |
1029 |
|
1030 |
if (debug & DEBUG_FRAMER) |
1031 |
dev_notice(&wc->dev->dev, "Stopping HDLC controller on span " |
1032 |
"%d\n", span+1); |
1033 |
|
1034 |
/* Clear receive and transmit timeslots */ |
1035 |
for (i = 0; i < 4; i++) { |
1036 |
t4_framer_out(wc, span, FRMR_RTR_BASE + i, 0x00); |
1037 |
t4_framer_out(wc, span, FRMR_TTR_BASE + i, 0x00); |
1038 |
} |
1039 |
|
1040 |
imr0 = t4_framer_in(wc, span, FRMR_IMR0); |
1041 |
imr1 = t4_framer_in(wc, span, FRMR_IMR1); |
1042 |
|
1043 |
/* Disable HDLC interrupts */ |
1044 |
imr0 |= HDLC_IMR0_MASK; |
1045 |
t4_framer_out(wc, span, FRMR_IMR0, imr0); |
1046 |
|
1047 |
imr1 |= HDLC_IMR1_MASK; |
1048 |
t4_framer_out(wc, span, FRMR_IMR1, imr1); |
1049 |
|
1050 |
mode = t4_framer_in(wc, span, FRMR_MODE); |
1051 |
mode &= ~FRMR_MODE_HRAC; |
1052 |
t4_framer_out(wc, span, FRMR_MODE, mode); |
1053 |
|
1054 |
t->sigactive = 0; |
1055 |
} |
1056 |
|
1057 |
static inline void __t4_framer_cmd(struct t4 *wc, unsigned int span, int cmd) |
1058 |
{ |
1059 |
__t4_framer_out(wc, span, FRMR_CMDR, cmd); |
1060 |
} |
1061 |
|
1062 |
static inline void t4_framer_cmd_wait(struct t4 *wc, unsigned int span, int cmd) |
1063 |
{ |
1064 |
int sis; |
1065 |
int loops = 0; |
1066 |
|
1067 |
/* XXX could be time consuming XXX */ |
1068 |
for (;;) { |
1069 |
sis = t4_framer_in(wc, span, FRMR_SIS); |
1070 |
if (!(sis & 0x04)) |
1071 |
break; |
1072 |
if (!loops++ && (debug & DEBUG_FRAMER)) { |
1073 |
dev_notice(&wc->dev->dev, "!!!SIS Waiting before cmd " |
1074 |
"%02x\n", cmd); |
1075 |
} |
1076 |
} |
1077 |
if (loops && (debug & DEBUG_FRAMER)) |
1078 |
dev_notice(&wc->dev->dev, "!!!SIS waited %d loops\n", loops); |
1079 |
|
1080 |
t4_framer_out(wc, span, FRMR_CMDR, cmd); |
1081 |
} |
1082 |
|
1083 |
static int hdlc_start(struct t4 *wc, unsigned int span, struct dahdi_chan *chan, unsigned char mode) |
1084 |
{ |
1085 |
struct t4_span *t = wc->tspans[span]; |
1086 |
unsigned char imr0, imr1; |
1087 |
int offset = chan->chanpos; |
1088 |
unsigned long flags; |
1089 |
|
1090 |
if (debug & DEBUG_FRAMER) |
1091 |
dev_info(&wc->dev->dev, "Starting HDLC controller for channel " |
1092 |
"%d span %d\n", offset, span+1); |
1093 |
|
1094 |
if (mode != FRMR_MODE_NO_ADDR_CMP) |
1095 |
return -1; |
1096 |
|
1097 |
mode |= FRMR_MODE_HRAC; |
1098 |
|
1099 |
/* Make sure we're in the right mode */ |
1100 |
t4_framer_out(wc, span, FRMR_MODE, mode); |
1101 |
t4_framer_out(wc, span, FRMR_TSEO, 0x00); |
1102 |
t4_framer_out(wc, span, FRMR_TSBS1, hardhdlcmode); |
1103 |
|
1104 |
/* Set the interframe gaps, etc */ |
1105 |
t4_framer_out(wc, span, FRMR_CCR1, FRMR_CCR1_ITF|FRMR_CCR1_EITS); |
1106 |
|
1107 |
t4_framer_out(wc, span, FRMR_CCR2, FRMR_CCR2_RCRC); |
1108 |
|
1109 |
/* Set up the time slot that we want to tx/rx on */ |
1110 |
t4_framer_out(wc, span, FRMR_TTR_BASE + (offset / 8), (0x80 >> (offset % 8))); |
1111 |
t4_framer_out(wc, span, FRMR_RTR_BASE + (offset / 8), (0x80 >> (offset % 8))); |
1112 |
|
1113 |
imr0 = t4_framer_in(wc, span, FRMR_IMR0); |
1114 |
imr1 = t4_framer_in(wc, span, FRMR_IMR1); |
1115 |
|
1116 |
/* Enable our interrupts again */ |
1117 |
imr0 &= ~HDLC_IMR0_MASK; |
1118 |
t4_framer_out(wc, span, FRMR_IMR0, imr0); |
1119 |
|
1120 |
imr1 &= ~HDLC_IMR1_MASK; |
1121 |
t4_framer_out(wc, span, FRMR_IMR1, imr1); |
1122 |
|
1123 |
/* Reset the signaling controller */ |
1124 |
t4_framer_cmd_wait(wc, span, FRMR_CMDR_SRES); |
1125 |
|
1126 |
spin_lock_irqsave(&wc->reglock, flags); |
1127 |
t->sigchan = chan; |
1128 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1129 |
|
1130 |
t->sigactive = 0; |
1131 |
|
1132 |
return 0; |
1133 |
} |
1134 |
|
1135 |
static void __set_clear(struct t4 *wc, int span) |
1136 |
{ |
1137 |
int i,j; |
1138 |
int oldnotclear; |
1139 |
unsigned short val=0; |
1140 |
struct t4_span *ts = wc->tspans[span]; |
1141 |
|
1142 |
oldnotclear = ts->notclear; |
1143 |
if ((ts->spantype == TYPE_T1) || (ts->spantype == TYPE_J1)) { |
1144 |
for (i=0;i<24;i++) { |
1145 |
j = (i/8); |
1146 |
if (ts->span.chans[i]->flags & DAHDI_FLAG_CLEAR) { |
1147 |
val |= 1 << (7 - (i % 8)); |
1148 |
ts->notclear &= ~(1 << i); |
1149 |
} else |
1150 |
ts->notclear |= (1 << i); |
1151 |
if ((i % 8)==7) { |
1152 |
if (debug) |
1153 |
dev_notice(&wc->dev->dev, "Putting %d " |
1154 |
"in register %02x on span %d" |
1155 |
"\n", val, 0x2f + j, span + 1); |
1156 |
__t4_framer_out(wc, span, 0x2f + j, val); |
1157 |
val = 0; |
1158 |
} |
1159 |
} |
1160 |
} else { |
1161 |
for (i=0;i<31;i++) { |
1162 |
if (ts->span.chans[i]->flags & DAHDI_FLAG_CLEAR) |
1163 |
ts->notclear &= ~(1 << i); |
1164 |
else |
1165 |
ts->notclear |= (1 << i); |
1166 |
} |
1167 |
} |
1168 |
if (ts->notclear != oldnotclear) { |
1169 |
unsigned char reg; |
1170 |
reg = __t4_framer_in(wc, span, FRMR_IMR0); |
1171 |
if (ts->notclear) |
1172 |
reg &= ~0x08; |
1173 |
else |
1174 |
reg |= 0x08; |
1175 |
__t4_framer_out(wc, span, FRMR_IMR0, reg); |
1176 |
} |
1177 |
} |
1178 |
|
1179 |
#if 0 |
1180 |
static void set_clear(struct t4 *wc, int span) |
1181 |
{ |
1182 |
unsigned long flags; |
1183 |
spin_lock_irqsave(&wc->reglock, flags); |
1184 |
__set_clear(wc, span); |
1185 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1186 |
} |
1187 |
#endif |
1188 |
|
1189 |
static int t4_dacs(struct dahdi_chan *dst, struct dahdi_chan *src) |
1190 |
{ |
1191 |
struct t4 *wc; |
1192 |
struct t4_span *ts; |
1193 |
wc = dst->pvt; |
1194 |
ts = wc->tspans[dst->span->offset]; |
1195 |
if (src && (src->pvt != dst->pvt)) { |
1196 |
if (ts->spanflags & FLAG_2NDGEN) |
1197 |
t4_tsi_unassign(wc, dst->span->offset, dst->chanpos); |
1198 |
wc = src->pvt; |
1199 |
if (ts->spanflags & FLAG_2NDGEN) |
1200 |
t4_tsi_unassign(wc, src->span->offset, src->chanpos); |
1201 |
if (debug) |
1202 |
dev_notice(&wc->dev->dev, "Unassigning %d/%d by " |
1203 |
"default and...\n", src->span->offset, |
1204 |
src->chanpos); |
1205 |
if (debug) |
1206 |
dev_notice(&wc->dev->dev, "Unassigning %d/%d by " |
1207 |
"default\n", dst->span->offset, dst->chanpos); |
1208 |
return -1; |
1209 |
} |
1210 |
if (src) { |
1211 |
t4_tsi_assign(wc, src->span->offset, src->chanpos, dst->span->offset, dst->chanpos); |
1212 |
if (debug) |
1213 |
dev_notice(&wc->dev->dev, "Assigning channel %d/%d -> " |
1214 |
"%d/%d!\n", src->span->offset, src->chanpos, |
1215 |
dst->span->offset, dst->chanpos); |
1216 |
} else { |
1217 |
t4_tsi_unassign(wc, dst->span->offset, dst->chanpos); |
1218 |
if (debug) |
1219 |
dev_notice(&wc->dev->dev, "Unassigning channel %d/%d!" |
1220 |
"\n", dst->span->offset, dst->chanpos); |
1221 |
} |
1222 |
return 0; |
1223 |
} |
1224 |
|
1225 |
#ifdef VPM_SUPPORT |
1226 |
|
1227 |
void oct_set_reg(void *data, unsigned int reg, unsigned int val) |
1228 |
{ |
1229 |
struct t4 *wc = data; |
1230 |
t4_oct_out(wc, reg, val); |
1231 |
} |
1232 |
|
1233 |
unsigned int oct_get_reg(void *data, unsigned int reg) |
1234 |
{ |
1235 |
struct t4 *wc = data; |
1236 |
unsigned int ret; |
1237 |
ret = t4_oct_in(wc, reg); |
1238 |
return ret; |
1239 |
} |
1240 |
|
1241 |
static int t4_vpm_unit(int span, int channel) |
1242 |
{ |
1243 |
int unit = 0; |
1244 |
switch(vpmspans) { |
1245 |
case 4: |
1246 |
unit = span; |
1247 |
unit += (channel & 1) << 2; |
1248 |
break; |
1249 |
case 2: |
1250 |
unit = span; |
1251 |
unit += (channel & 0x3) << 1; |
1252 |
break; |
1253 |
case 1: |
1254 |
unit = span; |
1255 |
unit += (channel & 0x7); |
1256 |
} |
1257 |
return unit; |
1258 |
} |
1259 |
|
1260 |
static inline struct t4_span *t4_from_span(struct dahdi_span *span) |
1261 |
{ |
1262 |
return container_of(span, struct t4_span, span); |
1263 |
} |
1264 |
|
1265 |
static int t4_echocan_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, |
1266 |
struct dahdi_echocanparam *p, struct dahdi_echocan_state **ec) |
1267 |
{ |
1268 |
struct t4 *wc = chan->pvt; |
1269 |
struct t4_span *tspan = container_of(chan->span, struct t4_span, span); |
1270 |
int channel; |
1271 |
const struct dahdi_echocan_ops *ops; |
1272 |
const struct dahdi_echocan_features *features; |
1273 |
|
1274 |
if (!vpmsupport || !wc->vpm) |
1275 |
return -ENODEV; |
1276 |
|
1277 |
if (chan->span->offset >= vpmspans) |
1278 |
return -ENODEV; |
1279 |
|
1280 |
if (wc->vpm450m) { |
1281 |
ops = &vpm450m_ec_ops; |
1282 |
features = &vpm450m_ec_features; |
1283 |
} else { |
1284 |
ops = &vpm400m_ec_ops; |
1285 |
features = &vpm400m_ec_features; |
1286 |
} |
1287 |
|
1288 |
if (ecp->param_count > 0) { |
1289 |
dev_warn(&wc->dev->dev, "echo canceller does not support " |
1290 |
"parameters; failing request\n"); |
1291 |
return -EINVAL; |
1292 |
} |
1293 |
|
1294 |
*ec = tspan->ec[chan->chanpos - 1]; |
1295 |
(*ec)->ops = ops; |
1296 |
(*ec)->features = *features; |
1297 |
|
1298 |
channel = wc->t1e1 ? chan->chanpos : chan->chanpos + 4; |
1299 |
|
1300 |
if (wc->vpm450m) { |
1301 |
channel = channel << 2; |
1302 |
channel |= chan->span->offset; |
1303 |
if (debug & DEBUG_ECHOCAN) |
1304 |
dev_notice(&wc->dev->dev, "echocan: Card is %d, " |
1305 |
"Channel is %d, Span is %d, offset is %d " |
1306 |
"length %d\n", wc->num, chan->chanpos, |
1307 |
chan->span->offset, channel, ecp->tap_length); |
1308 |
vpm450m_setec(wc->vpm450m, channel, ecp->tap_length); |
1309 |
} else { |
1310 |
int unit = t4_vpm_unit(chan->span->offset, channel); |
1311 |
|
1312 |
if (debug & DEBUG_ECHOCAN) |
1313 |
dev_notice(&wc->dev->dev, "echocan: Card is %d, " |
1314 |
"Channel is %d, Span is %d, unit is %d, " |
1315 |
"unit offset is %d length %d\n", wc->num, |
1316 |
chan->chanpos, chan->span->offset, unit, |
1317 |
channel, ecp->tap_length); |
1318 |
t4_vpm_out(wc, unit, channel, 0x3e); |
1319 |
} |
1320 |
|
1321 |
return 0; |
1322 |
} |
1323 |
|
1324 |
static void echocan_free(struct dahdi_chan *chan, struct dahdi_echocan_state *ec) |
1325 |
{ |
1326 |
struct t4 *wc = chan->pvt; |
1327 |
int channel; |
1328 |
|
1329 |
memset(ec, 0, sizeof(*ec)); |
1330 |
|
1331 |
channel = wc->t1e1 ? chan->chanpos : chan->chanpos + 4; |
1332 |
|
1333 |
if (wc->vpm450m) { |
1334 |
channel = channel << 2; |
1335 |
channel |= chan->span->offset; |
1336 |
if (debug & DEBUG_ECHOCAN) |
1337 |
dev_notice(&wc->dev->dev, "echocan: Card is %d, " |
1338 |
"Channel is %d, Span is %d, offset is %d " |
1339 |
"length 0\n", wc->num, chan->chanpos, |
1340 |
chan->span->offset, channel); |
1341 |
vpm450m_setec(wc->vpm450m, channel, 0); |
1342 |
} else { |
1343 |
int unit = t4_vpm_unit(chan->span->offset, channel); |
1344 |
|
1345 |
if (debug & DEBUG_ECHOCAN) |
1346 |
dev_notice(&wc->dev->dev, "echocan: Card is %d, " |
1347 |
"Channel is %d, Span is %d, unit is %d, " |
1348 |
"unit offset is %d length 0\n", wc->num, |
1349 |
chan->chanpos, chan->span->offset, unit, |
1350 |
channel); |
1351 |
t4_vpm_out(wc, unit, channel, 0x01); |
1352 |
} |
1353 |
} |
1354 |
#endif |
1355 |
|
1356 |
static int t4_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long data) |
1357 |
{ |
1358 |
struct t4_regs regs; |
1359 |
int x; |
1360 |
struct t4 *wc = chan->pvt; |
1361 |
#ifdef VPM_SUPPORT |
1362 |
int j; |
1363 |
int channel; |
1364 |
struct t4_span *ts = wc->tspans[chan->span->offset]; |
1365 |
#endif |
1366 |
|
1367 |
#ifdef VPM_SUPPORT |
1368 |
if (dtmfthreshold == 0) |
1369 |
dtmfthreshold = VPM_DEFAULT_DTMFTHRESHOLD; |
1370 |
if (lastdtmfthreshold != dtmfthreshold) { |
1371 |
lastdtmfthreshold = dtmfthreshold; |
1372 |
t4_vpm_set_dtmf_threshold(wc, dtmfthreshold); |
1373 |
} |
1374 |
#endif |
1375 |
|
1376 |
switch(cmd) { |
1377 |
case WCT4_GET_REGS: |
1378 |
for (x=0;x<NUM_PCI;x++) |
1379 |
regs.pci[x] = t4_pci_in(wc, x); |
1380 |
for (x=0;x<NUM_REGS;x++) |
1381 |
regs.regs[x] = t4_framer_in(wc, chan->span->offset, x); |
1382 |
if (copy_to_user((__user void *) data, ®s, sizeof(regs))) |
1383 |
return -EFAULT; |
1384 |
break; |
1385 |
#ifdef VPM_SUPPORT |
1386 |
case DAHDI_TONEDETECT: |
1387 |
if (get_user(j, (__user int *) data)) |
1388 |
return -EFAULT; |
1389 |
if (!wc->vpm) |
1390 |
return -ENOSYS; |
1391 |
if (j && (vpmdtmfsupport == 0)) |
1392 |
return -ENOSYS; |
1393 |
if (j & DAHDI_TONEDETECT_ON) |
1394 |
set_bit(chan->chanpos - 1, &ts->dtmfmask); |
1395 |
else |
1396 |
clear_bit(chan->chanpos - 1, &ts->dtmfmask); |
1397 |
if (j & DAHDI_TONEDETECT_MUTE) |
1398 |
set_bit(chan->chanpos - 1, &ts->dtmfmutemask); |
1399 |
else |
1400 |
clear_bit(chan->chanpos - 1, &ts->dtmfmutemask); |
1401 |
if (wc->vpm450m) { |
1402 |
channel = (chan->chanpos) << 2; |
1403 |
if (!wc->t1e1) |
1404 |
channel += (4 << 2); |
1405 |
channel |= chan->span->offset; |
1406 |
vpm450m_setdtmf(wc->vpm450m, channel, j & DAHDI_TONEDETECT_ON, j & DAHDI_TONEDETECT_MUTE); |
1407 |
} |
1408 |
return 0; |
1409 |
#endif |
1410 |
default: |
1411 |
return -ENOTTY; |
1412 |
} |
1413 |
return 0; |
1414 |
} |
1415 |
|
1416 |
static void inline t4_hdlc_xmit_fifo(struct t4 *wc, unsigned int span, struct t4_span *ts) |
1417 |
{ |
1418 |
int res, i; |
1419 |
unsigned int size = 32; |
1420 |
unsigned char buf[32]; |
1421 |
|
1422 |
res = dahdi_hdlc_getbuf(ts->sigchan, buf, &size); |
1423 |
if (debug & DEBUG_FRAMER) |
1424 |
dev_notice(&wc->dev->dev, "Got buffer sized %d and res %d " |
1425 |
"for %d\n", size, res, span); |
1426 |
if (size > 0) { |
1427 |
ts->sigactive = 1; |
1428 |
|
1429 |
if (debug & DEBUG_FRAMER) { |
1430 |
dev_notice(&wc->dev->dev, "TX("); |
1431 |
for (i = 0; i < size; i++) |
1432 |
dev_notice(&wc->dev->dev, "%s%02x", |
1433 |
(i ? " " : ""), buf[i]); |
1434 |
dev_notice(&wc->dev->dev, ")\n"); |
1435 |
} |
1436 |
|
1437 |
for (i = 0; i < size; i++) |
1438 |
t4_framer_out(wc, span, FRMR_TXFIFO, buf[i]); |
1439 |
|
1440 |
if (res) /* End of message */ { |
1441 |
if (debug & DEBUG_FRAMER) |
1442 |
dev_notice(&wc->dev->dev, |
1443 |
"transmiting XHF|XME\n"); |
1444 |
t4_framer_cmd_wait(wc, span, FRMR_CMDR_XHF | FRMR_CMDR_XME); |
1445 |
#if 0 |
1446 |
ts->sigactive = (__t4_framer_in(wc, span, FRMR_SIS) & FRMR_SIS_XFW) ? 0 : 1; |
1447 |
#endif |
1448 |
++ts->frames_out; |
1449 |
if ((debug & DEBUG_FRAMER) && !(ts->frames_out & 0x0f)) |
1450 |
dev_notice(&wc->dev->dev, "Transmitted %d " |
1451 |
"frames on span %d\n", ts->frames_out, |
1452 |
span); |
1453 |
} else { /* Still more to transmit */ |
1454 |
if (debug & DEBUG_FRAMER) |
1455 |
dev_notice(&wc->dev->dev, "transmiting XHF\n"); |
1456 |
t4_framer_cmd_wait(wc, span, FRMR_CMDR_XHF); |
1457 |
} |
1458 |
} |
1459 |
else if (res < 0) |
1460 |
ts->sigactive = 0; |
1461 |
} |
1462 |
|
1463 |
static void t4_hdlc_hard_xmit(struct dahdi_chan *chan) |
1464 |
{ |
1465 |
struct t4 *wc = chan->pvt; |
1466 |
int span = chan->span->offset; |
1467 |
struct t4_span *ts = wc->tspans[span]; |
1468 |
unsigned long flags; |
1469 |
|
1470 |
spin_lock_irqsave(&wc->reglock, flags); |
1471 |
if (!ts->sigchan) { |
1472 |
dev_notice(&wc->dev->dev, "t4_hdlc_hard_xmit: Invalid (NULL) " |
1473 |
"signalling channel\n"); |
1474 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1475 |
return; |
1476 |
} |
1477 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1478 |
|
1479 |
if (debug & DEBUG_FRAMER) |
1480 |
dev_notice(&wc->dev->dev, "t4_hdlc_hard_xmit on channel %s " |
1481 |
"(sigchan %s), sigactive=%d\n", chan->name, |
1482 |
ts->sigchan->name, ts->sigactive); |
1483 |
|
1484 |
if ((ts->sigchan == chan) && !ts->sigactive) |
1485 |
t4_hdlc_xmit_fifo(wc, span, ts); |
1486 |
} |
1487 |
|
1488 |
static int t4_maint(struct dahdi_span *span, int cmd) |
1489 |
{ |
1490 |
struct t4_span *ts = t4_from_span(span); |
1491 |
struct t4 *wc = ts->owner; |
1492 |
unsigned int reg; |
1493 |
#ifdef DAHDI_SPAN_OPS |
1494 |
unsigned long flags; |
1495 |
#endif |
1496 |
|
1497 |
if (ts->spantype == TYPE_E1) { |
1498 |
switch(cmd) { |
1499 |
case DAHDI_MAINT_NONE: |
1500 |
dev_info(&wc->dev->dev, "Clearing all maint modes\n"); |
1501 |
t4_clear_maint(span); |
1502 |
break; |
1503 |
case DAHDI_MAINT_LOCALLOOP: |
1504 |
dev_info(&wc->dev->dev, |
1505 |
"Turning on local loopback\n"); |
1506 |
t4_clear_maint(span); |
1507 |
reg = t4_framer_in(wc, span->offset, LIM0_T); |
1508 |
t4_framer_out(wc, span->offset, LIM0_T, (reg|LIM0_LL)); |
1509 |
break; |
1510 |
#ifdef DAHDI_SPAN_OPS |
1511 |
case DAHDI_MAINT_NETWORKLINELOOP: |
1512 |
dev_info(&wc->dev->dev, |
1513 |
"Turning on network line loopback\n"); |
1514 |
t4_clear_maint(span); |
1515 |
reg = t4_framer_in(wc, span->offset, LIM1_T); |
1516 |
t4_framer_out(wc, span->offset, LIM1_T, (reg|LIM1_RL)); |
1517 |
break; |
1518 |
case DAHDI_MAINT_NETWORKPAYLOADLOOP: |
1519 |
dev_info(&wc->dev->dev, |
1520 |
"Turning on network payload loopback\n"); |
1521 |
t4_clear_maint(span); |
1522 |
reg = t4_framer_in(wc, span->offset, FMR2_T); |
1523 |
t4_framer_out(wc, span->offset, FMR2_T, (reg|FMR2_PLB)); |
1524 |
break; |
1525 |
#endif |
1526 |
case DAHDI_MAINT_LOOPUP: |
1527 |
case DAHDI_MAINT_LOOPDOWN: |
1528 |
dev_info(&wc->dev->dev, |
1529 |
"Loopup & loopdown supported in E1 mode\n"); |
1530 |
return -ENOSYS; |
1531 |
#ifdef DAHDI_SPAN_OPS |
1532 |
case DAHDI_MAINT_FAS_DEFECT: |
1533 |
t4_framer_out(wc, span->offset, IERR_T, IFASE); |
1534 |
break; |
1535 |
case DAHDI_MAINT_MULTI_DEFECT: |
1536 |
t4_framer_out(wc, span->offset, IERR_T, IMFE); |
1537 |
break; |
1538 |
case DAHDI_MAINT_CRC_DEFECT: |
1539 |
t4_framer_out(wc, span->offset, IERR_T, ICRCE); |
1540 |
break; |
1541 |
case DAHDI_MAINT_CAS_DEFECT: |
1542 |
t4_framer_out(wc, span->offset, IERR_T, ICASE); |
1543 |
break; |
1544 |
case DAHDI_MAINT_PRBS_DEFECT: |
1545 |
t4_framer_out(wc, span->offset, IERR_T, IPE); |
1546 |
break; |
1547 |
case DAHDI_MAINT_BIPOLAR_DEFECT: |
1548 |
t4_framer_out(wc, span->offset, IERR_T, IBV); |
1549 |
break; |
1550 |
case DAHDI_RESET_COUNTERS: |
1551 |
t4_reset_counters(span); |
1552 |
break; |
1553 |
case DAHDI_MAINT_ALARM_SIM: |
1554 |
dev_info(&wc->dev->dev, "Invoking alarm state"); |
1555 |
reg = t4_framer_in(wc, span->offset, FMR0); |
1556 |
t4_framer_out(wc, span->offset, FMR0, (reg|FMR0_SIM)); |
1557 |
break; |
1558 |
#endif |
1559 |
default: |
1560 |
dev_info(&wc->dev->dev, |
1561 |
"Unknown E1 maint command: %d\n", cmd); |
1562 |
return -ENOSYS; |
1563 |
} |
1564 |
} else { |
1565 |
switch(cmd) { |
1566 |
case DAHDI_MAINT_NONE: |
1567 |
dev_info(&wc->dev->dev, "Clearing all maint modes\n"); |
1568 |
t4_clear_maint(span); |
1569 |
break; |
1570 |
case DAHDI_MAINT_LOCALLOOP: |
1571 |
dev_info(&wc->dev->dev, |
1572 |
"Turning on local loopback\n"); |
1573 |
t4_clear_maint(span); |
1574 |
reg = t4_framer_in(wc, span->offset, LIM0_T); |
1575 |
t4_framer_out(wc, span->offset, LIM0_T, (reg|LIM0_LL)); |
1576 |
break; |
1577 |
#if (defined(DAHDI_SPAN_OPS) || defined(DAHDI_SPAN_MODULE) ) |
1578 |
case DAHDI_MAINT_NETWORKLINELOOP: |
1579 |
dev_info(&wc->dev->dev, |
1580 |
"Turning on network line loopback\n"); |
1581 |
t4_clear_maint(span); |
1582 |
reg = t4_framer_in(wc, span->offset, LIM1_T); |
1583 |
t4_framer_out(wc, span->offset, LIM1_T, (reg|LIM1_RL)); |
1584 |
break; |
1585 |
case DAHDI_MAINT_NETWORKPAYLOADLOOP: |
1586 |
dev_info(&wc->dev->dev, |
1587 |
"Turning on network payload loopback\n"); |
1588 |
t4_clear_maint(span); |
1589 |
reg = t4_framer_in(wc, span->offset, FMR2_T); |
1590 |
t4_framer_out(wc, span->offset, FMR2_T, (reg|FMR2_PLB)); |
1591 |
break; |
1592 |
#endif |
1593 |
case DAHDI_MAINT_LOOPUP: |
1594 |
dev_info(&wc->dev->dev, "Transmitting loopup code\n"); |
1595 |
t4_clear_maint(span); |
1596 |
t4_framer_out(wc, span->offset, 0x21, 0x50); |
1597 |
break; |
1598 |
case DAHDI_MAINT_LOOPDOWN: |
1599 |
dev_info(&wc->dev->dev, "Transmitting loopdown code\n"); |
1600 |
t4_clear_maint(span); |
1601 |
t4_framer_out(wc, span->offset, 0x21, 0x60); |
1602 |
break; |
1603 |
#if (defined(DAHDI_SPAN_OPS) || defined(DAHDI_SPAN_MODULE) ) |
1604 |
case DAHDI_MAINT_FAS_DEFECT: |
1605 |
t4_framer_out(wc, span->offset, IERR_T, IFASE); |
1606 |
break; |
1607 |
case DAHDI_MAINT_MULTI_DEFECT: |
1608 |
t4_framer_out(wc, span->offset, IERR_T, IMFE); |
1609 |
break; |
1610 |
case DAHDI_MAINT_CRC_DEFECT: |
1611 |
t4_framer_out(wc, span->offset, IERR_T, ICRCE); |
1612 |
break; |
1613 |
case DAHDI_MAINT_CAS_DEFECT: |
1614 |
t4_framer_out(wc, span->offset, IERR_T, ICASE); |
1615 |
break; |
1616 |
case DAHDI_MAINT_PRBS_DEFECT: |
1617 |
t4_framer_out(wc, span->offset, IERR_T, IPE); |
1618 |
break; |
1619 |
case DAHDI_MAINT_BIPOLAR_DEFECT: |
1620 |
t4_framer_out(wc, span->offset, IERR_T, IBV); |
1621 |
break; |
1622 |
case DAHDI_MAINT_PRBS: |
1623 |
dev_info(&wc->dev->dev, "PRBS not supported\n"); |
1624 |
#if 0 |
1625 |
dev_notice(&wc->dev->dev, "Enabling PRBS!\n"); |
1626 |
span->mainttimer = 1; |
1627 |
/* Enable PRBS monitor */ |
1628 |
reg = t4_framer_in(wc, span->offset, LCR1_T); |
1629 |
reg |= EPRM; |
1630 |
|
1631 |
/* Setup PRBS xmit */ |
1632 |
t4_framer_out(wc, span->offset, TPC0_T, 0); |
1633 |
|
1634 |
/* Enable PRBS transmit */ |
1635 |
reg |= XPRBS; |
1636 |
reg &= ~LLBP; |
1637 |
reg &= ~FLLB; |
1638 |
t4_framer_out(wc, span->offset, LCR1_T, reg); |
1639 |
#endif |
1640 |
return -ENOSYS; |
1641 |
case DAHDI_RESET_COUNTERS: |
1642 |
t4_reset_counters(span); |
1643 |
break; |
1644 |
#endif |
1645 |
#ifdef DAHDI_SPAN_OPS |
1646 |
case DAHDI_MAINT_ALARM_SIM: |
1647 |
reg = t4_framer_in(wc, span->offset, FMR0); |
1648 |
|
1649 |
/* |
1650 |
* The alarm simulation state machine requires us to |
1651 |
* bring this bit up and down for at least 1 clock cycle |
1652 |
*/ |
1653 |
spin_lock_irqsave(&wc->reglock, flags); |
1654 |
__t4_framer_out(wc, span->offset, |
1655 |
FMR0, (reg | FMR0_SIM)); |
1656 |
udelay(1); |
1657 |
__t4_framer_out(wc, span->offset, |
1658 |
FMR0, (reg & ~FMR0_SIM)); |
1659 |
udelay(1); |
1660 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1661 |
|
1662 |
reg = t4_framer_in(wc, span->offset, 0x4e); |
1663 |
if (debug & DEBUG_MAIN) { |
1664 |
dev_info(&wc->dev->dev, |
1665 |
"FRS2(alarm state): %d\n", |
1666 |
((reg & 0xe0) >> 5)); |
1667 |
} |
1668 |
break; |
1669 |
#endif |
1670 |
default: |
1671 |
dev_info(&wc->dev->dev, "Unknown T1 maint command:%d\n", |
1672 |
cmd); |
1673 |
break; |
1674 |
} |
1675 |
} |
1676 |
return 0; |
1677 |
} |
1678 |
|
1679 |
static int t4_clear_maint(struct dahdi_span *span) |
1680 |
{ |
1681 |
struct t4_span *ts = t4_from_span(span); |
1682 |
struct t4 *wc = ts->owner; |
1683 |
unsigned int reg; |
1684 |
|
1685 |
/* Clear local loop */ |
1686 |
reg = t4_framer_in(wc, span->offset, LIM0_T); |
1687 |
t4_framer_out(wc, span->offset, LIM0_T, (reg & ~LIM0_LL)); |
1688 |
|
1689 |
/* Clear Remote Loop */ |
1690 |
reg = t4_framer_in(wc, span->offset, LIM1_T); |
1691 |
t4_framer_out(wc, span->offset, LIM1_T, (reg & ~LIM1_RL)); |
1692 |
|
1693 |
/* Clear Remote Payload Loop */ |
1694 |
reg = t4_framer_in(wc, span->offset, FMR2_T); |
1695 |
t4_framer_out(wc, span->offset, FMR2_T, (reg & ~FMR2_PLB)); |
1696 |
|
1697 |
/* Clear PRBS */ |
1698 |
reg = t4_framer_in(wc, span->offset, LCR1_T); |
1699 |
t4_framer_out(wc, span->offset, LCR1_T, (reg & ~(XPRBS | EPRM))); |
1700 |
|
1701 |
span->mainttimer = 0; |
1702 |
|
1703 |
return 0; |
1704 |
} |
1705 |
|
1706 |
#if (defined(DAHDI_SPAN_OPS) || defined(DAHDI_SPAN_MODULE) ) |
1707 |
static int t4_reset_counters(struct dahdi_span *span) |
1708 |
{ |
1709 |
struct t4_span *ts = t4_from_span(span); |
1710 |
memset(&ts->span.count, 0, sizeof(ts->span.count)); |
1711 |
return 0; |
1712 |
} |
1713 |
#endif |
1714 |
|
1715 |
static int t4_rbsbits(struct dahdi_chan *chan, int bits) |
1716 |
{ |
1717 |
u_char m,c; |
1718 |
int k,n,b; |
1719 |
struct t4 *wc = chan->pvt; |
1720 |
struct t4_span *ts = wc->tspans[chan->span->offset]; |
1721 |
unsigned long flags; |
1722 |
|
1723 |
if (debug & DEBUG_RBS) |
1724 |
dev_notice(&wc->dev->dev, "Setting bits to %d on channel %s\n", |
1725 |
bits, chan->name); |
1726 |
spin_lock_irqsave(&wc->reglock, flags); |
1727 |
k = chan->span->offset; |
1728 |
if (ts->spantype == TYPE_E1) { /* do it E1 way */ |
1729 |
if (chan->chanpos == 16) { |
1730 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1731 |
return 0; |
1732 |
} |
1733 |
n = chan->chanpos - 1; |
1734 |
if (chan->chanpos > 15) n--; |
1735 |
b = (n % 15); |
1736 |
c = ts->txsigs[b]; |
1737 |
m = (n / 15) << 2; /* nibble selector */ |
1738 |
c &= (0xf << m); /* keep the other nibble */ |
1739 |
c |= (bits & 0xf) << (4 - m); /* put our new nibble here */ |
1740 |
ts->txsigs[b] = c; |
1741 |
/* output them to the chip */ |
1742 |
__t4_framer_out(wc,k,0x71 + b,c); |
1743 |
} else if (ts->span.lineconfig & DAHDI_CONFIG_D4) { |
1744 |
n = chan->chanpos - 1; |
1745 |
b = (n/4); |
1746 |
c = ts->txsigs[b]; |
1747 |
m = ((3 - (n % 4)) << 1); /* nibble selector */ |
1748 |
c &= ~(0x3 << m); /* keep the other nibble */ |
1749 |
c |= ((bits >> 2) & 0x3) << m; /* put our new nibble here */ |
1750 |
ts->txsigs[b] = c; |
1751 |
/* output them to the chip */ |
1752 |
__t4_framer_out(wc,k,0x70 + b,c); |
1753 |
__t4_framer_out(wc,k,0x70 + b + 6,c); |
1754 |
} else if (ts->span.lineconfig & DAHDI_CONFIG_ESF) { |
1755 |
n = chan->chanpos - 1; |
1756 |
b = (n/2); |
1757 |
c = ts->txsigs[b]; |
1758 |
m = ((n % 2) << 2); /* nibble selector */ |
1759 |
c &= (0xf << m); /* keep the other nibble */ |
1760 |
c |= (bits & 0xf) << (4 - m); /* put our new nibble here */ |
1761 |
ts->txsigs[b] = c; |
1762 |
/* output them to the chip */ |
1763 |
__t4_framer_out(wc,k,0x70 + b,c); |
1764 |
} |
1765 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1766 |
if (debug & DEBUG_RBS) |
1767 |
dev_notice(&wc->dev->dev, "Finished setting RBS bits\n"); |
1768 |
return 0; |
1769 |
} |
1770 |
|
1771 |
static int t4_shutdown(struct dahdi_span *span) |
1772 |
{ |
1773 |
int tspan; |
1774 |
int wasrunning; |
1775 |
unsigned long flags; |
1776 |
struct t4_span *ts = t4_from_span(span); |
1777 |
struct t4 *wc = ts->owner; |
1778 |
|
1779 |
tspan = span->offset + 1; |
1780 |
if (tspan < 0) { |
1781 |
dev_notice(&wc->dev->dev, "opvxd115: Span '%d' isn't us?\n", |
1782 |
span->spanno); |
1783 |
return -1; |
1784 |
} |
1785 |
|
1786 |
if (debug & DEBUG_MAIN) |
1787 |
dev_notice(&wc->dev->dev, "Shutting down span %d (%s)\n", |
1788 |
span->spanno, span->name); |
1789 |
|
1790 |
/* Stop HDLC controller if runned */ |
1791 |
if (ts->sigchan) |
1792 |
hdlc_stop(wc, span->offset); |
1793 |
|
1794 |
spin_lock_irqsave(&wc->reglock, flags); |
1795 |
wasrunning = span->flags & DAHDI_FLAG_RUNNING; |
1796 |
|
1797 |
span->flags &= ~DAHDI_FLAG_RUNNING; |
1798 |
__t4_set_led(wc, span->offset, WC_OFF); |
1799 |
if ((wc->numspans == 1) && |
1800 |
(!(wc->tspans[0]->span.flags & DAHDI_FLAG_RUNNING))) { |
1801 |
/* No longer in use, disable interrupts */ |
1802 |
dev_info(&wc->dev->dev, "opvxd115: Disabling interrupts since " |
1803 |
"there are no active spans\n"); |
1804 |
set_bit(T4_STOP_DMA, &wc->checkflag); |
1805 |
} else |
1806 |
set_bit(T4_CHECK_TIMING, &wc->checkflag); |
1807 |
|
1808 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1809 |
|
1810 |
/* Wait for interrupt routine to shut itself down */ |
1811 |
msleep(10); |
1812 |
if (wasrunning) |
1813 |
wc->spansstarted--; |
1814 |
|
1815 |
if (debug & DEBUG_MAIN) |
1816 |
dev_notice(&wc->dev->dev, "Span %d (%s) shutdown\n", |
1817 |
span->spanno, span->name); |
1818 |
return 0; |
1819 |
} |
1820 |
|
1821 |
static void t4_chan_set_sigcap(struct dahdi_span *span, int x) |
1822 |
{ |
1823 |
struct t4_span *wc = container_of(span, struct t4_span, span); |
1824 |
struct dahdi_chan *chan = wc->chans[x]; |
1825 |
chan->sigcap = DAHDI_SIG_CLEAR; |
1826 |
/* E&M variant supported depends on span type */ |
1827 |
if (wc->spantype == TYPE_E1) { |
1828 |
/* E1 sigcap setup */ |
1829 |
if (span->lineconfig & DAHDI_CONFIG_CCS) { |
1830 |
/* CCS setup */ |
1831 |
chan->sigcap |= DAHDI_SIG_MTP2 | DAHDI_SIG_SF | |
1832 |
DAHDI_SIG_HARDHDLC; |
1833 |
return; |
1834 |
} |
1835 |
/* clear out sig and sigcap for channel 16 on E1 CAS |
1836 |
* lines, otherwise, set it correctly */ |
1837 |
if (x == 15) { |
1838 |
/* CAS signaling channel setup */ |
1839 |
wc->chans[15]->sigcap = 0; |
1840 |
wc->chans[15]->sig = 0; |
1841 |
return; |
1842 |
} |
1843 |
/* normal CAS setup */ |
1844 |
chan->sigcap |= DAHDI_SIG_EM_E1 | DAHDI_SIG_FXSLS | |
1845 |
DAHDI_SIG_FXSGS | DAHDI_SIG_FXSKS | DAHDI_SIG_SF | |
1846 |
DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS | DAHDI_SIG_FXOKS | |
1847 |
DAHDI_SIG_CAS | DAHDI_SIG_DACS_RBS; |
1848 |
} else { |
1849 |
/* T1 sigcap setup */ |
1850 |
chan->sigcap |= DAHDI_SIG_EM | DAHDI_SIG_FXSLS | |
1851 |
DAHDI_SIG_FXSGS | DAHDI_SIG_FXSKS | DAHDI_SIG_MTP2 | |
1852 |
DAHDI_SIG_SF | DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS | |
1853 |
DAHDI_SIG_FXOKS | DAHDI_SIG_CAS | DAHDI_SIG_DACS_RBS | |
1854 |
DAHDI_SIG_HARDHDLC; |
1855 |
} |
1856 |
} |
1857 |
|
1858 |
static int t4_spanconfig(struct file *file, struct dahdi_span *span, |
1859 |
struct dahdi_lineconfig *lc) |
1860 |
{ |
1861 |
int i; |
1862 |
struct t4_span *ts = t4_from_span(span); |
1863 |
struct t4 *wc = ts->owner; |
1864 |
|
1865 |
if (debug) |
1866 |
dev_info(&wc->dev->dev, "About to enter spanconfig!\n"); |
1867 |
if (debug & DEBUG_MAIN) |
1868 |
dev_notice(&wc->dev->dev, "opvxd115: Configuring span %d\n", |
1869 |
span->spanno); |
1870 |
|
1871 |
if (lc->sync < 0) |
1872 |
lc->sync = 0; |
1873 |
if (lc->sync > wc->numspans) |
1874 |
lc->sync = 0; |
1875 |
|
1876 |
/* remove this span number from the current sync sources, if there */ |
1877 |
for(i = 0; i < wc->numspans; i++) { |
1878 |
if (wc->tspans[i]->sync == span->spanno) { |
1879 |
wc->tspans[i]->sync = 0; |
1880 |
wc->tspans[i]->psync = 0; |
1881 |
} |
1882 |
} |
1883 |
wc->tspans[span->offset]->syncpos = lc->sync; |
1884 |
/* if a sync src, put it in proper place */ |
1885 |
if (lc->sync) { |
1886 |
wc->tspans[lc->sync - 1]->sync = span->spanno; |
1887 |
wc->tspans[lc->sync - 1]->psync = span->offset + 1; |
1888 |
} |
1889 |
set_bit(T4_CHECK_TIMING, &wc->checkflag); |
1890 |
|
1891 |
/* Make sure this is clear in case of multiple startup and shutdown |
1892 |
* iterations */ |
1893 |
clear_bit(T4_STOP_DMA, &wc->checkflag); |
1894 |
|
1895 |
/* make sure that sigcaps gets updated if necessary */ |
1896 |
for (i = 0; i < span->channels; i++) |
1897 |
t4_chan_set_sigcap(span, i); |
1898 |
|
1899 |
/* If we're already running, then go ahead and apply the changes */ |
1900 |
if (span->flags & DAHDI_FLAG_RUNNING) |
1901 |
return t4_startup(file, span); |
1902 |
|
1903 |
if (debug) |
1904 |
dev_info(&wc->dev->dev, "Done with spanconfig!\n"); |
1905 |
return 0; |
1906 |
} |
1907 |
|
1908 |
static int t4_chanconfig(struct file *file, struct dahdi_chan *chan, |
1909 |
int sigtype) |
1910 |
{ |
1911 |
int alreadyrunning; |
1912 |
unsigned long flags; |
1913 |
struct t4 *wc = chan->pvt; |
1914 |
struct t4_span *ts = wc->tspans[chan->span->offset]; |
1915 |
|
1916 |
alreadyrunning = ts->span.flags & DAHDI_FLAG_RUNNING; |
1917 |
if (debug & DEBUG_MAIN) { |
1918 |
if (alreadyrunning) |
1919 |
dev_notice(&wc->dev->dev, "opvxd115: Reconfigured " |
1920 |
"channel %d (%s) sigtype %d\n", |
1921 |
chan->channo, chan->name, sigtype); |
1922 |
else |
1923 |
dev_notice(&wc->dev->dev, "opvxd115: Configured channel" |
1924 |
" %d (%s) sigtype %d\n", |
1925 |
chan->channo, chan->name, sigtype); |
1926 |
} |
1927 |
|
1928 |
spin_lock_irqsave(&wc->reglock, flags); |
1929 |
|
1930 |
if (alreadyrunning) |
1931 |
__set_clear(wc, chan->span->offset); |
1932 |
|
1933 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1934 |
|
1935 |
/* (re)configure signalling channel */ |
1936 |
if ((sigtype == DAHDI_SIG_HARDHDLC) || (ts->sigchan == chan)) { |
1937 |
if (debug & DEBUG_FRAMER) |
1938 |
dev_notice(&wc->dev->dev, "%sonfiguring hardware HDLC " |
1939 |
"on %s\n", |
1940 |
((sigtype == DAHDI_SIG_HARDHDLC) ? "C" : "Unc"), |
1941 |
chan->name); |
1942 |
if (alreadyrunning) { |
1943 |
if (ts->sigchan) |
1944 |
hdlc_stop(wc, ts->sigchan->span->offset); |
1945 |
if (sigtype == DAHDI_SIG_HARDHDLC) { |
1946 |
if (hdlc_start(wc, chan->span->offset, chan, ts->sigmode)) { |
1947 |
dev_notice(&wc->dev->dev, "Error " |
1948 |
"initializing signalling " |
1949 |
"controller\n"); |
1950 |
return -1; |
1951 |
} |
1952 |
} else { |
1953 |
spin_lock_irqsave(&wc->reglock, flags); |
1954 |
ts->sigchan = NULL; |
1955 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1956 |
} |
1957 |
|
1958 |
} |
1959 |
else { |
1960 |
spin_lock_irqsave(&wc->reglock, flags); |
1961 |
ts->sigchan = (sigtype == DAHDI_SIG_HARDHDLC) ? chan : NULL; |
1962 |
spin_unlock_irqrestore(&wc->reglock, flags); |
1963 |
ts->sigactive = 0; |
1964 |
} |
1965 |
} |
1966 |
return 0; |
1967 |
} |
1968 |
|
1969 |
static int t4_open(struct dahdi_chan *chan) |
1970 |
{ |
1971 |
return 0; |
1972 |
} |
1973 |
|
1974 |
static int t4_close(struct dahdi_chan *chan) |
1975 |
{ |
1976 |
return 0; |
1977 |
} |
1978 |
|
1979 |
static void set_span_devicetype(struct t4 *wc) |
1980 |
{ |
1981 |
struct dahdi_device *ddev = wc->ddev; |
1982 |
const char *devicetype_old = ddev->devicetype; |
1983 |
char *extra_str = ""; |
1984 |
|
1985 |
if (wc->vpm == T4_VPM_PRESENT) |
1986 |
extra_str = (!wc->vpm450m) ? " (VPM400M)" : " (VPMOCT032)", |
1987 |
wc->ddev->devicetype = kasprintf(GFP_KERNEL, "%s%s", |
1988 |
wc->variety, extra_str); |
1989 |
|
1990 |
/* On the off chance that we were able to allocate it previously. */ |
1991 |
if (!wc->ddev->devicetype) |
1992 |
wc->ddev->devicetype = devicetype_old; |
1993 |
else |
1994 |
kfree(devicetype_old); |
1995 |
} |
1996 |
|
1997 |
/* The number of cards we have seen with each |
1998 |
possible 'order' switch setting. |
1999 |
*/ |
2000 |
static unsigned int order_index[16]; |
2001 |
|
2002 |
static void setup_chunks(struct t4 *wc, int which) |
2003 |
{ |
2004 |
struct t4_span *ts; |
2005 |
int offset = 1; |
2006 |
int x, y; |
2007 |
int gen2; |
2008 |
|
2009 |
if (!wc->t1e1) |
2010 |
offset += 4; |
2011 |
|
2012 |
gen2 = (wc->tspans[0]->spanflags & FLAG_2NDGEN); |
2013 |
|
2014 |
for (x = 0; x < wc->numspans; x++) { |
2015 |
ts = wc->tspans[x]; |
2016 |
ts->writechunk = (void *)(wc->writechunk + (x * 32 * 2) + (which * (1024 >> 2))); |
2017 |
ts->readchunk = (void *)(wc->readchunk + (x * 32 * 2) + (which * (1024 >> 2))); |
2018 |
for (y=0;y<wc->tspans[x]->span.channels;y++) { |
2019 |
struct dahdi_chan *mychans = ts->chans[y]; |
2020 |
if (gen2) { |
2021 |
mychans->writechunk = (void *)(wc->writechunk + ((x * 32 + y + offset) * 2) + (which * (1024 >> 2))); |
2022 |
mychans->readchunk = (void *)(wc->readchunk + ((x * 32 + y + offset) * 2) + (which * (1024 >> 2))); |
2023 |
} |
2024 |
} |
2025 |
} |
2026 |
} |
2027 |
|
2028 |
#ifdef DAHDI_SPAN_OPS |
2029 |
static const struct dahdi_span_ops t4_gen1_span_ops = { |
2030 |
.owner = THIS_MODULE, |
2031 |
.spanconfig = t4_spanconfig, |
2032 |
.chanconfig = t4_chanconfig, |
2033 |
.startup = t4_startup, |
2034 |
.shutdown = t4_shutdown, |
2035 |
.rbsbits = t4_rbsbits, |
2036 |
.maint = t4_maint, |
2037 |
.open = t4_open, |
2038 |
.close = t4_close, |
2039 |
.ioctl = t4_ioctl, |
2040 |
.hdlc_hard_xmit = t4_hdlc_hard_xmit, |
2041 |
}; |
2042 |
|
2043 |
static const struct dahdi_span_ops t4_gen2_span_ops = { |
2044 |
.owner = THIS_MODULE, |
2045 |
.spanconfig = t4_spanconfig, |
2046 |
.chanconfig = t4_chanconfig, |
2047 |
.startup = t4_startup, |
2048 |
.shutdown = t4_shutdown, |
2049 |
.rbsbits = t4_rbsbits, |
2050 |
.maint = t4_maint, |
2051 |
.open = t4_open, |
2052 |
.close = t4_close, |
2053 |
.ioctl = t4_ioctl, |
2054 |
.hdlc_hard_xmit = t4_hdlc_hard_xmit, |
2055 |
.dacs = t4_dacs, |
2056 |
#ifdef VPM_SUPPORT |
2057 |
.echocan_create = t4_echocan_create, |
2058 |
#endif |
2059 |
}; |
2060 |
#endif |
2061 |
|
2062 |
static void init_spans(struct t4 *wc) |
2063 |
{ |
2064 |
int x,y; |
2065 |
int gen2; |
2066 |
struct t4_span *ts; |
2067 |
unsigned int reg; |
2068 |
|
2069 |
wc->ddev->manufacturer = "OpenVox"; |
2070 |
if (order_index[wc->order] == 1) |
2071 |
wc->ddev->location = kasprintf(GFP_KERNEL, |
2072 |
"Board ID Switch %d", wc->order); |
2073 |
else |
2074 |
wc->ddev->location = kasprintf(GFP_KERNEL, |
2075 |
"PCI%s Bus %02d Slot %02d", |
2076 |
(ts->spanflags & FLAG_EXPRESS) ? |
2077 |
" Express" : " ", |
2078 |
wc->dev->bus->number, |
2079 |
PCI_SLOT(wc->dev->devfn) + 1); |
2080 |
if (!wc->ddev->location) |
2081 |
return; /* FIXME: Error handling */ |
2082 |
|
2083 |
gen2 = (wc->tspans[0]->spanflags & FLAG_2NDGEN); |
2084 |
for (x = 0; x < wc->numspans; x++) { |
2085 |
ts = wc->tspans[x]; |
2086 |
sprintf(ts->span.name, "D115/D130/%d/%d", wc->num, x + 1); |
2087 |
snprintf(ts->span.desc, sizeof(ts->span.desc) - 1, |
2088 |
"D115/D130 (E1|T1) Card %d Span %d", wc->num, x+1); |
2089 |
switch (ts->spantype) { |
2090 |
case TYPE_T1: |
2091 |
ts->span.spantype = "T1"; |
2092 |
break; |
2093 |
case TYPE_E1: |
2094 |
ts->span.spantype = "E1"; |
2095 |
break; |
2096 |
case TYPE_J1: |
2097 |
ts->span.spantype = "J1"; |
2098 |
break; |
2099 |
} |
2100 |
#ifdef DAHDI_SPAN_MODULE |
2101 |
ts->span.owner = THIS_MODULE; |
2102 |
#endif |
2103 |
#ifdef DAHDI_SPAN_OPS |
2104 |
if (gen2) { |
2105 |
ts->span.ops = &t4_gen2_span_ops; |
2106 |
} else { |
2107 |
ts->span.ops = &t4_gen1_span_ops; |
2108 |
} |
2109 |
#else |
2110 |
ts->span.spanconfig = t4_spanconfig; |
2111 |
ts->span.chanconfig = t4_chanconfig; |
2112 |
ts->span.startup = t4_startup; |
2113 |
ts->span.shutdown = t4_shutdown; |
2114 |
ts->span.rbsbits = t4_rbsbits; |
2115 |
ts->span.maint = t4_maint; |
2116 |
ts->span.open = t4_open; |
2117 |
ts->span.close = t4_close; |
2118 |
ts->span.ioctl = t4_ioctl; |
2119 |
ts->span.hdlc_hard_xmit = t4_hdlc_hard_xmit; |
2120 |
if (gen2) { |
2121 |
#ifdef VPM_SUPPORT |
2122 |
if (vpmsupport) |
2123 |
ts->span.echocan_create = t4_echocan_create; |
2124 |
#endif |
2125 |
ts->span.dacs = t4_dacs; |
2126 |
} |
2127 |
ts->span.pvt = ts; |
2128 |
#endif |
2129 |
|
2130 |
/* HDLC Specific init */ |
2131 |
ts->sigchan = NULL; |
2132 |
ts->sigmode = sigmode; |
2133 |
ts->sigactive = 0; |
2134 |
|
2135 |
if (ts->spantype == TYPE_T1 || ts->spantype == TYPE_J1) { |
2136 |
ts->span.channels = 24; |
2137 |
ts->span.deflaw = DAHDI_LAW_MULAW; |
2138 |
ts->span.linecompat = DAHDI_CONFIG_AMI | |
2139 |
DAHDI_CONFIG_B8ZS | DAHDI_CONFIG_D4 | |
2140 |
DAHDI_CONFIG_ESF; |
2141 |
} else { |
2142 |
ts->span.channels = 31; |
2143 |
ts->span.deflaw = DAHDI_LAW_ALAW; |
2144 |
ts->span.linecompat = DAHDI_CONFIG_AMI | |
2145 |
DAHDI_CONFIG_HDB3 | DAHDI_CONFIG_CCS | |
2146 |
DAHDI_CONFIG_CRC4; |
2147 |
} |
2148 |
ts->span.chans = ts->chans; |
2149 |
ts->span.flags = DAHDI_FLAG_RBS; |
2150 |
|
2151 |
ts->owner = wc; |
2152 |
ts->span.offset = x; |
2153 |
ts->writechunk = (void *)(wc->writechunk + x * 32 * 2); |
2154 |
ts->readchunk = (void *)(wc->readchunk + x * 32 * 2); |
2155 |
|
2156 |
for (y=0;y<wc->tspans[x]->span.channels;y++) { |
2157 |
struct dahdi_chan *mychans = ts->chans[y]; |
2158 |
sprintf(mychans->name, "D115/D130/%d/%d/%d", wc->num, x + 1, y + 1); |
2159 |
t4_chan_set_sigcap(&ts->span, x); |
2160 |
mychans->pvt = wc; |
2161 |
mychans->chanpos = y + 1; |
2162 |
} |
2163 |
|
2164 |
/* Enable 1sec timer interrupt */ |
2165 |
reg = t4_framer_in(wc, x, FMR1_T); |
2166 |
t4_framer_out(wc, x, FMR1_T, (reg | FMR1_ECM)); |
2167 |
|
2168 |
/* Enable Errored Second interrupt */ |
2169 |
t4_framer_out(wc, x, ESM, 0); |
2170 |
|
2171 |
#if (defined(DAHDI_SPAN_OPS) || defined(DAHDI_SPAN_MODULE) ) |
2172 |
t4_reset_counters(&ts->span); |
2173 |
#endif |
2174 |
} |
2175 |
|
2176 |
set_span_devicetype(wc); |
2177 |
setup_chunks(wc, 0); |
2178 |
wc->lastindex = 0; |
2179 |
} |
2180 |
|
2181 |
static void t4_serial_setup(struct t4 *wc, int unit) |
2182 |
{ |
2183 |
if (!wc->globalconfig) { |
2184 |
wc->globalconfig = 1; |
2185 |
if (debug) |
2186 |
dev_info(&wc->dev->dev, "opvxd115: Setting up global " |
2187 |
"serial parameters\n"); |
2188 |
t4_framer_out(wc, 0, 0x85, 0xe0); /* GPC1: Multiplex mode enabled, FSC is output, active low, RCLK from channel 0 */ |
2189 |
t4_framer_out(wc, 0, 0x08, 0x01); /* IPC: Interrupt push/pull active low */ |
2190 |
|
2191 |
/* Global clocks (8.192 Mhz CLK) */ |
2192 |
t4_framer_out(wc, 0, 0x92, 0x00); |
2193 |
t4_framer_out(wc, 0, 0x93, 0x18); |
2194 |
t4_framer_out(wc, 0, 0x94, 0xfb); |
2195 |
t4_framer_out(wc, 0, 0x95, 0x0b); |
2196 |
t4_framer_out(wc, 0, 0x96, 0x00); |
2197 |
t4_framer_out(wc, 0, 0x97, 0x0b); |
2198 |
t4_framer_out(wc, 0, 0x98, 0xdb); |
2199 |
t4_framer_out(wc, 0, 0x99, 0xdf); |
2200 |
} |
2201 |
|
2202 |
/* Configure interrupts */ |
2203 |
t4_framer_out(wc, unit, FRMR_GCR, 0x00); /* GCR: Interrupt on Activation/Deactivation of each */ |
2204 |
|
2205 |
/* Configure system interface */ |
2206 |
t4_framer_out(wc, unit, FRMR_SIC1, 0xc2); /* SIC1: 8.192 Mhz clock/bus, double buffer receive / transmit, byte interleaved */ |
2207 |
t4_framer_out(wc, unit, FRMR_SIC2, 0x20 | (unit << 1)); /* SIC2: No FFS, no center receive eliastic buffer, phase */ |
2208 |
t4_framer_out(wc, unit, FRMR_SIC3, 0x04); /* SIC3: Edges for capture */ |
2209 |
t4_framer_out(wc, unit, FRMR_CMR2, 0x00); /* CMR2: We provide sync and clock for tx and rx. */ |
2210 |
if (!wc->t1e1) { /* T1 mode */ |
2211 |
t4_framer_out(wc, unit, FRMR_XC0, 0x03); /* XC0: Normal operation of Sa-bits */ |
2212 |
t4_framer_out(wc, unit, FRMR_XC1, 0x84); /* XC1: 0 offset */ |
2213 |
if (wc->tspans[unit]->spantype == TYPE_J1) |
2214 |
t4_framer_out(wc, unit, FRMR_RC0, 0x83); /* RC0: Just shy of 1023 */ |
2215 |
else |
2216 |
t4_framer_out(wc, unit, FRMR_RC0, 0x03); /* RC0: Just shy of 1023 */ |
2217 |
t4_framer_out(wc, unit, FRMR_RC1, 0x84); /* RC1: The rest of RC0 */ |
2218 |
} else { /* E1 mode */ |
2219 |
t4_framer_out(wc, unit, FRMR_XC0, 0x00); /* XC0: Normal operation of Sa-bits */ |
2220 |
t4_framer_out(wc, unit, FRMR_XC1, 0x04); /* XC1: 0 offset */ |
2221 |
t4_framer_out(wc, unit, FRMR_RC0, 0x04); /* RC0: Just shy of 1023 */ |
2222 |
t4_framer_out(wc, unit, FRMR_RC1, 0x04); /* RC1: The rest of RC0 */ |
2223 |
} |
2224 |
|
2225 |
/* Configure ports */ |
2226 |
t4_framer_out(wc, unit, 0x80, 0x00); /* PC1: SPYR/SPYX input on RPA/XPA */ |
2227 |
if (wc->falc31) { |
2228 |
t4_framer_out(wc, unit, 0x81, 0xBB); /* PC2: RMFB/XSIG output/input on RPB/XPB */ |
2229 |
t4_framer_out(wc, unit, 0x82, 0xBB); /* PC3: Some unused stuff */ |
2230 |
t4_framer_out(wc, unit, 0x83, 0xBB); /* PC4: Some more unused stuff */ |
2231 |
} else { |
2232 |
t4_framer_out(wc, unit, 0x81, 0x22); /* PC2: RMFB/XSIG output/input on RPB/XPB */ |
2233 |
t4_framer_out(wc, unit, 0x82, 0x65); /* PC3: Some unused stuff */ |
2234 |
t4_framer_out(wc, unit, 0x83, 0x35); /* PC4: Some more unused stuff */ |
2235 |
} |
2236 |
t4_framer_out(wc, unit, 0x84, 0x01); /* PC5: XMFS active low, SCLKR is input, RCLK is output */ |
2237 |
if (debug & DEBUG_MAIN) |
2238 |
dev_notice(&wc->dev->dev, "Successfully initialized serial " |
2239 |
"bus for unit %d\n", unit); |
2240 |
} |
2241 |
|
2242 |
static int syncsrc = 0; |
2243 |
static int syncnum = 0 /* -1 */; |
2244 |
static int syncspan = 0; |
2245 |
#ifdef DEFINE_SPINLOCK |
2246 |
static DEFINE_SPINLOCK(synclock); |
2247 |
#else |
2248 |
static spinlock_t synclock = SPIN_LOCK_UNLOCKED; |
2249 |
#endif |
2250 |
|
2251 |
static void __t4_set_rclk_src(struct t4 *wc, int span) |
2252 |
{ |
2253 |
int cmr1 = 0x38; /* Clock Mode: RCLK sourced by DCO-R1 |
2254 |
by default, Disable Clock-Switching */ |
2255 |
|
2256 |
cmr1 |= (span << 6); |
2257 |
__t4_framer_out(wc, 0, 0x44, cmr1); |
2258 |
|
2259 |
dev_info(&wc->dev->dev, "RCLK source set to span %d\n", span+1); |
2260 |
} |
2261 |
|
2262 |
static void __t4_set_sclk_src(struct t4 *wc, int mode, int master, int slave) |
2263 |
{ |
2264 |
if (slave) { |
2265 |
wc->dmactrl |= (1 << 25); |
2266 |
dev_info(&wc->dev->dev, "SCLK is slaved to timing cable\n"); |
2267 |
} else { |
2268 |
wc->dmactrl &= ~(1 << 25); |
2269 |
} |
2270 |
|
2271 |
if (master) { |
2272 |
wc->dmactrl |= (1 << 24); |
2273 |
dev_info(&wc->dev->dev, "SCLK is master to timing cable\n"); |
2274 |
} else { |
2275 |
wc->dmactrl &= ~(1 << 24); |
2276 |
} |
2277 |
|
2278 |
if (mode == WC_RECOVER) |
2279 |
wc->dmactrl |= (1 << 29); /* Recover timing from RCLK */ |
2280 |
|
2281 |
if (mode == WC_SELF) |
2282 |
wc->dmactrl &= ~(1 << 29);/* Provide timing from MCLK */ |
2283 |
|
2284 |
__t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
2285 |
} |
2286 |
|
2287 |
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)) |
2288 |
static ssize_t t4_timing_master_show(struct device *dev, |
2289 |
struct device_attribute *attr, |
2290 |
char *buf) |
2291 |
{ |
2292 |
struct t4 *wc = dev_get_drvdata(dev); |
2293 |
if (wc->dmactrl & (1 << 29)) |
2294 |
return sprintf(buf, "%d\n", wc->syncsrc); |
2295 |
else |
2296 |
return sprintf(buf, "%d\n", -1); |
2297 |
} |
2298 |
|
2299 |
static DEVICE_ATTR(timing_master, 0400, t4_timing_master_show, NULL); |
2300 |
|
2301 |
static void create_sysfs_files(struct t4 *wc) |
2302 |
{ |
2303 |
int ret; |
2304 |
ret = device_create_file(&wc->dev->dev, |
2305 |
&dev_attr_timing_master); |
2306 |
if (ret) { |
2307 |
dev_info(&wc->dev->dev, |
2308 |
"Failed to create device attributes.\n"); |
2309 |
} |
2310 |
} |
2311 |
|
2312 |
static void remove_sysfs_files(struct t4 *wc) |
2313 |
{ |
2314 |
device_remove_file(&wc->dev->dev, |
2315 |
&dev_attr_timing_master); |
2316 |
} |
2317 |
|
2318 |
#else |
2319 |
|
2320 |
static inline void create_sysfs_files(struct t4 *wc) { return; } |
2321 |
static inline void remove_sysfs_files(struct t4 *wc) { return; } |
2322 |
|
2323 |
#endif /* LINUX_KERNEL > 2.6.18 */ |
2324 |
|
2325 |
static inline void __t4_update_timing(struct t4 *wc) |
2326 |
{ |
2327 |
int i; |
2328 |
/* update sync src info */ |
2329 |
if (wc->syncsrc != syncsrc) { |
2330 |
dev_info(&wc->dev->dev, "Swapping card %d from %d to %d\n", |
2331 |
wc->num, wc->syncsrc, syncsrc); |
2332 |
wc->syncsrc = syncsrc; |
2333 |
/* Update sync sources */ |
2334 |
for (i = 0; i < wc->numspans; i++) { |
2335 |
wc->tspans[i]->span.syncsrc = wc->syncsrc; |
2336 |
} |
2337 |
if (syncnum == wc->num) { |
2338 |
__t4_set_rclk_src(wc, syncspan-1); |
2339 |
__t4_set_sclk_src(wc, WC_RECOVER, 1, 0); |
2340 |
if (debug) |
2341 |
dev_notice(&wc->dev->dev, "Card %d, using sync " |
2342 |
"span %d, master\n", wc->num, syncspan); |
2343 |
} else { |
2344 |
__t4_set_sclk_src(wc, WC_RECOVER, 0, 1); |
2345 |
if (debug) |
2346 |
dev_notice(&wc->dev->dev, "Card %d, using " |
2347 |
"Timing Bus, NOT master\n", wc->num); |
2348 |
} |
2349 |
} |
2350 |
} |
2351 |
|
2352 |
static int __t4_findsync(struct t4 *wc) |
2353 |
{ |
2354 |
int i; |
2355 |
int x; |
2356 |
unsigned long flags; |
2357 |
int p; |
2358 |
int nonzero; |
2359 |
int newsyncsrc = 0; /* DAHDI span number */ |
2360 |
int newsyncnum = 0; /* opvxd115 card number */ |
2361 |
int newsyncspan = 0; /* span on given opvxd115 card */ |
2362 |
spin_lock_irqsave(&synclock, flags); |
2363 |
#if 1 |
2364 |
if (!wc->num) { |
2365 |
/* If we're the first card, go through all the motions, up to 8 levels |
2366 |
of sync source */ |
2367 |
p = 1; |
2368 |
while (p < 8) { |
2369 |
nonzero = 0; |
2370 |
for (x=0;cards[x];x++) { |
2371 |
for (i = 0; i < wc->numspans; i++) { |
2372 |
if (cards[x]->tspans[i]->syncpos) { |
2373 |
nonzero = 1; |
2374 |
if ((cards[x]->tspans[i]->syncpos == p) && |
2375 |
!(cards[x]->tspans[i]->span.alarms & (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE | DAHDI_ALARM_LOOPBACK)) && |
2376 |
(cards[x]->tspans[i]->span.flags & DAHDI_FLAG_RUNNING)) { |
2377 |
/* This makes a good sync source */ |
2378 |
newsyncsrc = cards[x]->tspans[i]->span.spanno; |
2379 |
newsyncnum = x; |
2380 |
newsyncspan = i + 1; |
2381 |
/* Jump out */ |
2382 |
goto found; |
2383 |
} |
2384 |
} |
2385 |
} |
2386 |
} |
2387 |
if (nonzero) |
2388 |
p++; |
2389 |
else |
2390 |
break; |
2391 |
} |
2392 |
found: |
2393 |
if ((syncnum != newsyncnum) || (syncsrc != newsyncsrc) || (newsyncspan != syncspan)) { |
2394 |
if (debug) |
2395 |
dev_notice(&wc->dev->dev, "New syncnum: %d " |
2396 |
"(was %d), syncsrc: %d (was %d), " |
2397 |
"syncspan: %d (was %d)\n", newsyncnum, |
2398 |
syncnum, newsyncsrc, syncsrc, |
2399 |
newsyncspan, syncspan); |
2400 |
syncnum = newsyncnum; |
2401 |
syncsrc = newsyncsrc; |
2402 |
syncspan = newsyncspan; |
2403 |
for (x=0;cards[x];x++) { |
2404 |
__t4_update_timing(cards[x]); |
2405 |
} |
2406 |
} |
2407 |
} |
2408 |
__t4_update_timing(wc); |
2409 |
#endif |
2410 |
spin_unlock_irqrestore(&synclock, flags); |
2411 |
return 0; |
2412 |
} |
2413 |
|
2414 |
static void __t4_set_timing_source_auto(struct t4 *wc) |
2415 |
{ |
2416 |
int x; |
2417 |
int firstprio, secondprio; |
2418 |
firstprio = secondprio = 4; |
2419 |
|
2420 |
if (debug) |
2421 |
dev_info(&wc->dev->dev, "timing source auto\n"); |
2422 |
clear_bit(T4_CHECK_TIMING, &wc->checkflag); |
2423 |
if (timingcable) { |
2424 |
__t4_findsync(wc); |
2425 |
} else { |
2426 |
if (debug) |
2427 |
dev_info(&wc->dev->dev, "Evaluating spans for timing " |
2428 |
"source\n"); |
2429 |
for (x=0;x<wc->numspans;x++) { |
2430 |
if ((wc->tspans[x]->span.flags & DAHDI_FLAG_RUNNING) && |
2431 |
!(wc->tspans[x]->span.alarms & (DAHDI_ALARM_RED | |
2432 |
DAHDI_ALARM_BLUE))) { |
2433 |
if (debug) |
2434 |
dev_info(&wc->dev->dev, "span %d is " |
2435 |
"green : syncpos %d\n", x+1, |
2436 |
wc->tspans[x]->syncpos); |
2437 |
if (wc->tspans[x]->syncpos) { |
2438 |
/* Valid rsync source in recovered |
2439 |
timing mode */ |
2440 |
if (firstprio == 4) |
2441 |
firstprio = x; |
2442 |
else if (wc->tspans[x]->syncpos < |
2443 |
wc->tspans[firstprio]->syncpos) |
2444 |
firstprio = x; |
2445 |
} else { |
2446 |
/* Valid rsync source in system timing |
2447 |
mode */ |
2448 |
if (secondprio == 4) |
2449 |
secondprio = x; |
2450 |
} |
2451 |
} |
2452 |
} |
2453 |
if (firstprio != 4) { |
2454 |
wc->syncsrc = firstprio; |
2455 |
__t4_set_rclk_src(wc, firstprio); |
2456 |
__t4_set_sclk_src(wc, WC_RECOVER, 0, 0); |
2457 |
dev_info(&wc->dev->dev, "Recovered timing mode, "\ |
2458 |
"RCLK set to span %d\n", |
2459 |
firstprio+1); |
2460 |
} else if (secondprio != 4) { |
2461 |
wc->syncsrc = -1; |
2462 |
__t4_set_rclk_src(wc, secondprio); |
2463 |
__t4_set_sclk_src(wc, WC_SELF, 0, 0); |
2464 |
dev_info(&wc->dev->dev, "System timing mode, "\ |
2465 |
"RCLK set to span %d\n", |
2466 |
secondprio+1); |
2467 |
} else { |
2468 |
wc->syncsrc = -1; |
2469 |
dev_info(&wc->dev->dev, "All spans in alarm : No valid"\ |
2470 |
"span to source RCLK from\n"); |
2471 |
/* Default rclk to lock with span 1 */ |
2472 |
__t4_set_rclk_src(wc, 0); |
2473 |
__t4_set_sclk_src(wc, WC_SELF, 0, 0); |
2474 |
} |
2475 |
} |
2476 |
} |
2477 |
|
2478 |
static void __t4_configure_t1(struct t4 *wc, int unit, int lineconfig, int txlevel) |
2479 |
{ |
2480 |
unsigned int fmr4, fmr2, fmr1, fmr0, lim2; |
2481 |
char *framing, *line; |
2482 |
int mytxlevel; |
2483 |
if ((txlevel > 7) || (txlevel < 4)) |
2484 |
mytxlevel = 0; |
2485 |
else |
2486 |
mytxlevel = txlevel - 4; |
2487 |
fmr1 = 0x9c; /* FMR1: Mode 1, T1 mode, CRC on for ESF, 8.192 Mhz system data rate, no XAIS */ |
2488 |
fmr2 = 0x20; /* FMR2: no payload loopback, don't auto yellow */ |
2489 |
fmr4 = 0x0c; /* FMR4: Lose sync on 2 out of 5 framing bits, auto resync */ |
2490 |
lim2 = 0x21; /* LIM2: 50% peak is a "1", Advanced Loss recovery */ |
2491 |
lim2 |= (mytxlevel << 6); /* LIM2: Add line buildout */ |
2492 |
__t4_framer_out(wc, unit, 0x1d, fmr1); |
2493 |
__t4_framer_out(wc, unit, 0x1e, fmr2); |
2494 |
|
2495 |
/* Configure line interface */ |
2496 |
if (lineconfig & DAHDI_CONFIG_AMI) { |
2497 |
line = "AMI"; |
2498 |
/* workaround for errata #2 in ES v3 09-10-16 */ |
2499 |
fmr0 = (wc->falc31) ? 0xb0 : 0xa0; |
2500 |
} else { |
2501 |
line = "B8ZS"; |
2502 |
fmr0 = 0xf0; |
2503 |
} |
2504 |
if (lineconfig & DAHDI_CONFIG_D4) { |
2505 |
framing = "D4"; |
2506 |
} else { |
2507 |
framing = "ESF"; |
2508 |
fmr4 |= 0x2; |
2509 |
fmr2 |= 0xc0; |
2510 |
} |
2511 |
__t4_framer_out(wc, unit, 0x1c, fmr0); |
2512 |
__t4_framer_out(wc, unit, 0x20, fmr4); |
2513 |
__t4_framer_out(wc, unit, 0x21, 0x40); /* FMR5: Enable RBS mode */ |
2514 |
|
2515 |
__t4_framer_out(wc, unit, 0x37, 0xf0 ); /* LIM1: Clear data in case of LOS, Set receiver threshold (0.5V), No remote loop, no DRS */ |
2516 |
__t4_framer_out(wc, unit, 0x36, 0x08); /* LIM0: Enable auto long haul mode, no local loop (must be after LIM1) */ |
2517 |
|
2518 |
__t4_framer_out(wc, unit, 0x02, 0x50); /* CMDR: Reset the receiver and transmitter line interface */ |
2519 |
__t4_framer_out(wc, unit, 0x02, 0x00); /* CMDR: Reset the receiver and transmitter line interface */ |
2520 |
|
2521 |
if (wc->falc31) { |
2522 |
if (debug) |
2523 |
dev_info(&wc->dev->dev, "card %d span %d: setting Rtx " |
2524 |
"to 0ohm for T1\n", wc->num, unit); |
2525 |
__t4_framer_out(wc, unit, 0x86, 0x00); /* PC6: set Rtx to 0ohm for T1 */ |
2526 |
|
2527 |
// Hitting the bugfix register to fix errata #3 |
2528 |
__t4_framer_out(wc, unit, 0xbd, 0x05); |
2529 |
} |
2530 |
|
2531 |
__t4_framer_out(wc, unit, 0x3a, lim2); /* LIM2: 50% peak amplitude is a "1" */ |
2532 |
__t4_framer_out(wc, unit, 0x38, 0x0a); /* PCD: LOS after 176 consecutive "zeros" */ |
2533 |
__t4_framer_out(wc, unit, 0x39, 0x15); /* PCR: 22 "ones" clear LOS */ |
2534 |
|
2535 |
/* Generate pulse mask for T1 */ |
2536 |
switch(mytxlevel) { |
2537 |
case 3: |
2538 |
__t4_framer_out(wc, unit, 0x26, 0x07); /* XPM0 */ |
2539 |
__t4_framer_out(wc, unit, 0x27, 0x01); /* XPM1 */ |
2540 |
__t4_framer_out(wc, unit, 0x28, 0x00); /* XPM2 */ |
2541 |
break; |
2542 |
case 2: |
2543 |
__t4_framer_out(wc, unit, 0x26, 0x8c); /* XPM0 */ |
2544 |
__t4_framer_out(wc, unit, 0x27, 0x11); /* XPM1 */ |
2545 |
__t4_framer_out(wc, unit, 0x28, 0x01); /* XPM2 */ |
2546 |
break; |
2547 |
case 1: |
2548 |
__t4_framer_out(wc, unit, 0x26, 0x8c); /* XPM0 */ |
2549 |
__t4_framer_out(wc, unit, 0x27, 0x01); /* XPM1 */ |
2550 |
__t4_framer_out(wc, unit, 0x28, 0x00); /* XPM2 */ |
2551 |
break; |
2552 |
case 0: |
2553 |
default: |
2554 |
__t4_framer_out(wc, unit, 0x26, 0xd7); /* XPM0 */ |
2555 |
__t4_framer_out(wc, unit, 0x27, 0x22); /* XPM1 */ |
2556 |
__t4_framer_out(wc, unit, 0x28, 0x01); /* XPM2 */ |
2557 |
break; |
2558 |
} |
2559 |
|
2560 |
/* Don't mask framer interrupts if hardware HDLC is in use */ |
2561 |
__t4_framer_out(wc, unit, FRMR_IMR0, 0xff & ~((wc->tspans[unit]->sigchan) ? HDLC_IMR0_MASK : 0)); /* IMR0: We care about CAS changes, etc */ |
2562 |
__t4_framer_out(wc, unit, FRMR_IMR1, 0xff & ~((wc->tspans[unit]->sigchan) ? HDLC_IMR1_MASK : 0)); /* IMR1: We care about nothing */ |
2563 |
__t4_framer_out(wc, unit, 0x16, 0x00); /* IMR2: All the alarm stuff! */ |
2564 |
__t4_framer_out(wc, unit, 0x17, 0x34); /* IMR3: AIS and friends */ |
2565 |
__t4_framer_out(wc, unit, 0x18, 0x3f); /* IMR4: Slips on transmit */ |
2566 |
|
2567 |
dev_info(&wc->dev->dev, "Span %d configured for %s/%s\n", unit + 1, |
2568 |
framing, line); |
2569 |
} |
2570 |
|
2571 |
static void __t4_configure_e1(struct t4 *wc, int unit, int lineconfig) |
2572 |
{ |
2573 |
unsigned int fmr2, fmr1, fmr0; |
2574 |
unsigned int cas = 0; |
2575 |
unsigned int imr3extra=0; |
2576 |
char *crc4 = ""; |
2577 |
char *framing, *line; |
2578 |
fmr1 = 0x44; /* FMR1: E1 mode, Automatic force resync, PCM30 mode, 8.192 Mhz backplane, no XAIS */ |
2579 |
fmr2 = 0x03; /* FMR2: Auto transmit remote alarm, auto loss of multiframe recovery, no payload loopback */ |
2580 |
if (lineconfig & DAHDI_CONFIG_CRC4) { |
2581 |
fmr1 |= 0x08; /* CRC4 transmit */ |
2582 |
fmr2 |= 0xc0; /* CRC4 receive */ |
2583 |
crc4 = "/CRC4"; |
2584 |
} |
2585 |
__t4_framer_out(wc, unit, 0x1d, fmr1); |
2586 |
__t4_framer_out(wc, unit, 0x1e, fmr2); |
2587 |
|
2588 |
/* Configure line interface */ |
2589 |
if (lineconfig & DAHDI_CONFIG_AMI) { |
2590 |
line = "AMI"; |
2591 |
/* workaround for errata #2 in ES v3 09-10-16 */ |
2592 |
fmr0 = (wc->falc31) ? 0xb0 : 0xa0; |
2593 |
} else { |
2594 |
line = "HDB3"; |
2595 |
fmr0 = 0xf0; |
2596 |
} |
2597 |
if (lineconfig & DAHDI_CONFIG_CCS) { |
2598 |
framing = "CCS"; |
2599 |
imr3extra = 0x28; |
2600 |
} else { |
2601 |
framing = "CAS"; |
2602 |
cas = 0x40; |
2603 |
} |
2604 |
__t4_framer_out(wc, unit, 0x1c, fmr0); |
2605 |
|
2606 |
__t4_framer_out(wc, unit, 0x37, 0xf0 /*| 0x6 */ ); /* LIM1: Clear data in case of LOS, Set receiver threshold (0.5V), No remote loop, no DRS */ |
2607 |
__t4_framer_out(wc, unit, 0x36, 0x08); /* LIM0: Enable auto long haul mode, no local loop (must be after LIM1) */ |
2608 |
|
2609 |
__t4_framer_out(wc, unit, 0x02, 0x50); /* CMDR: Reset the receiver and transmitter line interface */ |
2610 |
__t4_framer_out(wc, unit, 0x02, 0x00); /* CMDR: Reset the receiver and transmitter line interface */ |
2611 |
|
2612 |
if (wc->falc31) { |
2613 |
if (debug) |
2614 |
dev_info(&wc->dev->dev, |
2615 |
"setting Rtx to 7.5ohm for E1\n"); |
2616 |
__t4_framer_out(wc, unit, 0x86, 0x40); /* PC6: turn on 7.5ohm Rtx for E1 */ |
2617 |
} |
2618 |
|
2619 |
/* Condition receive line interface for E1 after reset */ |
2620 |
__t4_framer_out(wc, unit, 0xbb, 0x17); |
2621 |
__t4_framer_out(wc, unit, 0xbc, 0x55); |
2622 |
__t4_framer_out(wc, unit, 0xbb, 0x97); |
2623 |
__t4_framer_out(wc, unit, 0xbb, 0x11); |
2624 |
__t4_framer_out(wc, unit, 0xbc, 0xaa); |
2625 |
__t4_framer_out(wc, unit, 0xbb, 0x91); |
2626 |
__t4_framer_out(wc, unit, 0xbb, 0x12); |
2627 |
__t4_framer_out(wc, unit, 0xbc, 0x55); |
2628 |
__t4_framer_out(wc, unit, 0xbb, 0x92); |
2629 |
__t4_framer_out(wc, unit, 0xbb, 0x0c); |
2630 |
__t4_framer_out(wc, unit, 0xbb, 0x00); |
2631 |
__t4_framer_out(wc, unit, 0xbb, 0x8c); |
2632 |
|
2633 |
__t4_framer_out(wc, unit, 0x3a, 0x20); /* LIM2: 50% peak amplitude is a "1" */ |
2634 |
__t4_framer_out(wc, unit, 0x38, 0x0a); /* PCD: LOS after 176 consecutive "zeros" */ |
2635 |
__t4_framer_out(wc, unit, 0x39, 0x15); /* PCR: 22 "ones" clear LOS */ |
2636 |
|
2637 |
__t4_framer_out(wc, unit, 0x20, 0x9f); /* XSW: Spare bits all to 1 */ |
2638 |
__t4_framer_out(wc, unit, 0x21, 0x1c|cas); /* XSP: E-bit set when async. AXS auto, XSIF to 1 */ |
2639 |
|
2640 |
|
2641 |
/* Generate pulse mask for E1 */ |
2642 |
__t4_framer_out(wc, unit, 0x26, 0x54); /* XPM0 */ |
2643 |
__t4_framer_out(wc, unit, 0x27, 0x02); /* XPM1 */ |
2644 |
__t4_framer_out(wc, unit, 0x28, 0x00); /* XPM2 */ |
2645 |
|
2646 |
/* Don't mask framer interrupts if hardware HDLC is in use */ |
2647 |
__t4_framer_out(wc, unit, FRMR_IMR0, 0xff & ~((wc->tspans[unit]->sigchan) ? HDLC_IMR0_MASK : 0)); /* IMR0: We care about CRC errors, CAS changes, etc */ |
2648 |
__t4_framer_out(wc, unit, FRMR_IMR1, 0x3f & ~((wc->tspans[unit]->sigchan) ? HDLC_IMR1_MASK : 0)); /* IMR1: We care about loopup / loopdown */ |
2649 |
__t4_framer_out(wc, unit, 0x16, 0x00); /* IMR2: We care about all the alarm stuff! */ |
2650 |
__t4_framer_out(wc, unit, 0x17, 0x04 | imr3extra); /* IMR3: AIS */ |
2651 |
__t4_framer_out(wc, unit, 0x18, 0x3f); /* IMR4: We care about slips on transmit */ |
2652 |
|
2653 |
dev_info(&wc->dev->dev, "opvxd115: Span %d configured for %s/%s%s\n", |
2654 |
unit + 1, framing, line, crc4); |
2655 |
} |
2656 |
|
2657 |
static int t4_startup(struct file *file, struct dahdi_span *span) |
2658 |
{ |
2659 |
#ifdef SUPPORT_GEN1 |
2660 |
int i; |
2661 |
#endif |
2662 |
int tspan; |
2663 |
unsigned long flags; |
2664 |
int alreadyrunning; |
2665 |
struct t4_span *ts = t4_from_span(span); |
2666 |
struct t4 *wc = ts->owner; |
2667 |
|
2668 |
set_bit(T4_IGNORE_LATENCY, &wc->checkflag); |
2669 |
if (debug) |
2670 |
dev_info(&wc->dev->dev, "About to enter startup!\n"); |
2671 |
tspan = span->offset + 1; |
2672 |
if (tspan < 0) { |
2673 |
dev_info(&wc->dev->dev, "opvxd115: Span '%d' isn't us?\n", |
2674 |
span->spanno); |
2675 |
return -1; |
2676 |
} |
2677 |
|
2678 |
spin_lock_irqsave(&wc->reglock, flags); |
2679 |
|
2680 |
alreadyrunning = span->flags & DAHDI_FLAG_RUNNING; |
2681 |
|
2682 |
#ifdef SUPPORT_GEN1 |
2683 |
/* initialize the start value for the entire chunk of last ec buffer */ |
2684 |
for(i = 0; i < span->channels; i++) |
2685 |
{ |
2686 |
memset(ts->ec_chunk1[i], |
2687 |
DAHDI_LIN2X(0,span->chans[i]),DAHDI_CHUNKSIZE); |
2688 |
memset(ts->ec_chunk2[i], |
2689 |
DAHDI_LIN2X(0,span->chans[i]),DAHDI_CHUNKSIZE); |
2690 |
} |
2691 |
#endif |
2692 |
/* Force re-evaluation of timing source */ |
2693 |
wc->syncsrc = -1; |
2694 |
set_bit(T4_CHECK_TIMING, &wc->checkflag); |
2695 |
|
2696 |
if (ts->spantype == TYPE_E1) { /* if this is an E1 card */ |
2697 |
__t4_configure_e1(wc, span->offset, span->lineconfig); |
2698 |
} else { /* is a T1 card */ |
2699 |
__t4_configure_t1(wc, span->offset, span->lineconfig, span->txlevel); |
2700 |
} |
2701 |
|
2702 |
/* Note clear channel status */ |
2703 |
wc->tspans[span->offset]->notclear = 0; |
2704 |
__set_clear(wc, span->offset); |
2705 |
|
2706 |
if (!alreadyrunning) { |
2707 |
span->flags |= DAHDI_FLAG_RUNNING; |
2708 |
wc->spansstarted++; |
2709 |
|
2710 |
if (wc->flags & FLAG_5THGEN) |
2711 |
__t4_pci_out(wc, 5, (ms_per_irq << 16) | wc->numbufs); |
2712 |
/* enable interrupts */ |
2713 |
/* Start DMA, enabling DMA interrupts on read only */ |
2714 |
#if 0 |
2715 |
/* Enable framer only interrupts */ |
2716 |
wc->dmactrl |= 1 << 27; |
2717 |
#endif |
2718 |
wc->dmactrl |= (ts->spanflags & FLAG_2NDGEN) ? 0xc0000000 : 0xc0000003; |
2719 |
#ifdef VPM_SUPPORT |
2720 |
wc->dmactrl |= wc->vpm; |
2721 |
#endif |
2722 |
/* Seed interrupt register */ |
2723 |
__t4_pci_out(wc, WC_INTR, 0x0c); |
2724 |
if (noburst || !(ts->spanflags & FLAG_BURST)) |
2725 |
wc->dmactrl |= (1 << 26); |
2726 |
__t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
2727 |
|
2728 |
/* Startup HDLC controller too */ |
2729 |
} |
2730 |
|
2731 |
if (ts->sigchan) { |
2732 |
struct dahdi_chan *sigchan = ts->sigchan; |
2733 |
|
2734 |
spin_unlock_irqrestore(&wc->reglock, flags); |
2735 |
if (hdlc_start(wc, span->offset, sigchan, ts->sigmode)) { |
2736 |
dev_notice(&wc->dev->dev, "Error initializing " |
2737 |
"signalling controller\n"); |
2738 |
return -1; |
2739 |
} |
2740 |
spin_lock_irqsave(&wc->reglock, flags); |
2741 |
} |
2742 |
|
2743 |
spin_unlock_irqrestore(&wc->reglock, flags); |
2744 |
|
2745 |
t4_check_alarms(wc, span->offset); |
2746 |
t4_check_sigbits(wc, span->offset); |
2747 |
|
2748 |
if (wc->tspans[0]->sync == span->spanno) |
2749 |
dev_info(&wc->dev->dev, "SPAN %d: Primary Sync Source\n", |
2750 |
span->spanno); |
2751 |
#ifdef VPM_SUPPORT |
2752 |
if (!alreadyrunning && !wc->vpm) { |
2753 |
wait_a_little(); |
2754 |
t4_vpm400_init(wc); |
2755 |
if (!wc->vpm) |
2756 |
t4_vpm450_init(wc); |
2757 |
wc->dmactrl |= wc->vpm; |
2758 |
t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
2759 |
if (wc->vpm) |
2760 |
set_span_devicetype(wc); |
2761 |
} |
2762 |
#endif |
2763 |
if (debug) |
2764 |
dev_info(&wc->dev->dev, "Completed startup!\n"); |
2765 |
clear_bit(T4_IGNORE_LATENCY, &wc->checkflag); |
2766 |
return 0; |
2767 |
} |
2768 |
|
2769 |
#ifdef SUPPORT_GEN1 |
2770 |
static inline void e1_check(struct t4 *wc, int span, int val) |
2771 |
{ |
2772 |
struct t4_span *ts = wc->tspans[span]; |
2773 |
if ((ts->span.channels > 24) && |
2774 |
(ts->span.flags & DAHDI_FLAG_RUNNING) && |
2775 |
!(ts->span.alarms) && |
2776 |
(!wc->e1recover)) { |
2777 |
if (val != 0x1b) { |
2778 |
ts->e1check++; |
2779 |
} else |
2780 |
ts->e1check = 0; |
2781 |
if (ts->e1check > 100) { |
2782 |
/* Wait 1000 ms */ |
2783 |
wc->e1recover = 1000 * 8; |
2784 |
wc->tspans[0]->e1check = 0; |
2785 |
if (debug & DEBUG_MAIN) |
2786 |
dev_notice(&wc->dev->dev, "Detected loss of " |
2787 |
"E1 alignment on span %d!\n", span); |
2788 |
t4_reset_dma(wc); |
2789 |
} |
2790 |
} |
2791 |
} |
2792 |
|
2793 |
static void t4_receiveprep(struct t4 *wc, int irq) |
2794 |
{ |
2795 |
volatile unsigned int *readchunk; |
2796 |
int dbl = 0; |
2797 |
int x,y,z; |
2798 |
unsigned int tmp; |
2799 |
int offset=0; |
2800 |
if (!wc->t1e1) |
2801 |
offset = 4; |
2802 |
if (irq & 1) { |
2803 |
/* First part */ |
2804 |
readchunk = wc->readchunk; |
2805 |
if (!wc->last0) |
2806 |
dbl = 1; |
2807 |
wc->last0 = 0; |
2808 |
} else { |
2809 |
readchunk = wc->readchunk + DAHDI_CHUNKSIZE * 32; |
2810 |
if (wc->last0) |
2811 |
dbl = 1; |
2812 |
wc->last0 = 1; |
2813 |
} |
2814 |
if (dbl) { |
2815 |
for (x=0;x<wc->numspans;x++) |
2816 |
wc->ddev->irqmisses++; |
2817 |
if (debug & DEBUG_MAIN) |
2818 |
dev_notice(&wc->dev->dev, "opvxd115: Double/missed " |
2819 |
"interrupt detected\n"); |
2820 |
} |
2821 |
for (x=0;x<DAHDI_CHUNKSIZE;x++) { |
2822 |
for (z=0;z<24;z++) { |
2823 |
/* All T1/E1 channels */ |
2824 |
tmp = readchunk[z+1+offset]; |
2825 |
wc->tspans[0]->span.chans[z]->readchunk[x] = tmp >> 24; |
2826 |
} |
2827 |
if (wc->t1e1) { |
2828 |
if (wc->e1recover > 0) |
2829 |
wc->e1recover--; |
2830 |
tmp = readchunk[0]; |
2831 |
e1_check(wc, 0, (tmp & 0x7f000000) >> 24); |
2832 |
for (z=24;z<31;z++) { |
2833 |
/* Only E1 channels now */ |
2834 |
tmp = readchunk[z+1]; |
2835 |
if (wc->tspans[0]->span.channels > 24) |
2836 |
wc->tspans[0]->span.chans[z]->readchunk[x] = tmp >> 24; |
2837 |
} |
2838 |
} |
2839 |
/* Advance pointer by 4 TDM frame lengths */ |
2840 |
readchunk += 32; |
2841 |
} |
2842 |
for (x=0;x<wc->numspans;x++) { |
2843 |
if (wc->tspans[x]->span.flags & DAHDI_FLAG_RUNNING) { |
2844 |
for (y=0;y<wc->tspans[x]->span.channels;y++) { |
2845 |
/* Echo cancel double buffered data */ |
2846 |
dahdi_ec_chunk(wc->tspans[x]->span.chans[y], |
2847 |
wc->tspans[x]->span.chans[y]->readchunk, |
2848 |
wc->tspans[x]->ec_chunk2[y]); |
2849 |
memcpy(wc->tspans[x]->ec_chunk2[y],wc->tspans[x]->ec_chunk1[y], |
2850 |
DAHDI_CHUNKSIZE); |
2851 |
memcpy(wc->tspans[x]->ec_chunk1[y], |
2852 |
wc->tspans[x]->span.chans[y]->writechunk, |
2853 |
DAHDI_CHUNKSIZE); |
2854 |
} |
2855 |
dahdi_receive(&wc->tspans[x]->span); |
2856 |
} |
2857 |
} |
2858 |
} |
2859 |
#endif |
2860 |
|
2861 |
#if (DAHDI_CHUNKSIZE != 8) |
2862 |
#error Sorry, nextgen does not support chunksize != 8 |
2863 |
#endif |
2864 |
|
2865 |
static inline void __receive_span(struct t4_span *ts) |
2866 |
{ |
2867 |
#ifdef VPM_SUPPORT |
2868 |
int y; |
2869 |
unsigned long merged; |
2870 |
merged = ts->dtmfactive & ts->dtmfmutemask; |
2871 |
if (merged) { |
2872 |
for (y=0;y<ts->span.channels;y++) { |
2873 |
/* Mute any DTMFs which are supposed to be muted */ |
2874 |
if (test_bit(y, &merged)) { |
2875 |
memset(ts->span.chans[y]->readchunk, DAHDI_XLAW(0, ts->span.chans[y]), DAHDI_CHUNKSIZE); |
2876 |
} |
2877 |
} |
2878 |
} |
2879 |
#endif |
2880 |
|
2881 |
#ifdef ENABLE_PREFETCH |
2882 |
prefetch((void *)(ts->readchunk)); |
2883 |
prefetch((void *)(ts->writechunk)); |
2884 |
prefetch((void *)(ts->readchunk + 8)); |
2885 |
prefetch((void *)(ts->writechunk + 8)); |
2886 |
prefetch((void *)(ts->readchunk + 16)); |
2887 |
prefetch((void *)(ts->writechunk + 16)); |
2888 |
prefetch((void *)(ts->readchunk + 24)); |
2889 |
prefetch((void *)(ts->writechunk + 24)); |
2890 |
prefetch((void *)(ts->readchunk + 32)); |
2891 |
prefetch((void *)(ts->writechunk + 32)); |
2892 |
prefetch((void *)(ts->readchunk + 40)); |
2893 |
prefetch((void *)(ts->writechunk + 40)); |
2894 |
prefetch((void *)(ts->readchunk + 48)); |
2895 |
prefetch((void *)(ts->writechunk + 48)); |
2896 |
prefetch((void *)(ts->readchunk + 56)); |
2897 |
prefetch((void *)(ts->writechunk + 56)); |
2898 |
#endif |
2899 |
|
2900 |
dahdi_ec_span(&ts->span); |
2901 |
dahdi_receive(&ts->span); |
2902 |
} |
2903 |
|
2904 |
static inline void __transmit_span(struct t4_span *ts) |
2905 |
{ |
2906 |
dahdi_transmit(&ts->span); |
2907 |
} |
2908 |
|
2909 |
#ifdef ENABLE_WORKQUEUES |
2910 |
static void workq_handlespan(void *data) |
2911 |
{ |
2912 |
struct t4_span *ts = data; |
2913 |
struct t4 *wc = ts->owner; |
2914 |
|
2915 |
__receive_span(ts); |
2916 |
__transmit_span(ts); |
2917 |
atomic_dec(&wc->worklist); |
2918 |
if (!atomic_read(&wc->worklist)) |
2919 |
t4_pci_out(wc, WC_INTR, 0); |
2920 |
} |
2921 |
#else |
2922 |
static void t4_prep_gen2(struct t4 *wc) |
2923 |
{ |
2924 |
int x; |
2925 |
for (x=0;x<wc->numspans;x++) { |
2926 |
if (wc->tspans[x]->span.flags & DAHDI_FLAG_RUNNING) { |
2927 |
__receive_span(wc->tspans[x]); |
2928 |
__transmit_span(wc->tspans[x]); |
2929 |
} |
2930 |
} |
2931 |
} |
2932 |
|
2933 |
#endif |
2934 |
#ifdef SUPPORT_GEN1 |
2935 |
static void t4_transmitprep(struct t4 *wc, int irq) |
2936 |
{ |
2937 |
volatile unsigned int *writechunk; |
2938 |
int x,y,z; |
2939 |
unsigned int tmp; |
2940 |
int offset=0; |
2941 |
if (!wc->t1e1) |
2942 |
offset = 4; |
2943 |
if (irq & 1) { |
2944 |
/* First part */ |
2945 |
writechunk = wc->writechunk + 1; |
2946 |
} else { |
2947 |
writechunk = wc->writechunk + DAHDI_CHUNKSIZE * 32 + 1; |
2948 |
} |
2949 |
for (y=0;y<wc->numspans;y++) { |
2950 |
if (wc->tspans[y]->span.flags & DAHDI_FLAG_RUNNING) |
2951 |
dahdi_transmit(&wc->tspans[y]->span); |
2952 |
} |
2953 |
|
2954 |
for (x=0;x<DAHDI_CHUNKSIZE;x++) { |
2955 |
/* Once per chunk */ |
2956 |
for (z=0;z<24;z++) { |
2957 |
/* All T1/E1 channels */ |
2958 |
tmp = (wc->tspans[0]->span.chans[z]->writechunk[x] << 24); |
2959 |
writechunk[z+offset] = tmp; |
2960 |
} |
2961 |
if (wc->t1e1) { |
2962 |
for (z=24;z<31;z++) { |
2963 |
/* Only E1 channels now */ |
2964 |
tmp = 0; |
2965 |
if (wc->tspans[0]->span.channels > 24) |
2966 |
tmp |= (wc->tspans[0]->span.chans[z]->writechunk[x] << 24); |
2967 |
writechunk[z] = tmp; |
2968 |
} |
2969 |
} |
2970 |
/* Advance pointer by 4 TDM frame lengths */ |
2971 |
writechunk += 32; |
2972 |
} |
2973 |
|
2974 |
} |
2975 |
#endif |
2976 |
|
2977 |
static void t4_check_sigbits(struct t4 *wc, int span) |
2978 |
{ |
2979 |
int a,i,rxs; |
2980 |
struct t4_span *ts = wc->tspans[span]; |
2981 |
|
2982 |
if (debug & DEBUG_RBS) |
2983 |
dev_notice(&wc->dev->dev, "Checking sigbits on span %d\n", |
2984 |
span + 1); |
2985 |
|
2986 |
if (!(ts->span.flags & DAHDI_FLAG_RUNNING)) |
2987 |
return; |
2988 |
if (ts->spantype == TYPE_E1) { |
2989 |
for (i = 0; i < 15; i++) { |
2990 |
a = t4_framer_in(wc, span, 0x71 + i); |
2991 |
/* Get high channel in low bits */ |
2992 |
rxs = (a & 0xf); |
2993 |
if (!(ts->span.chans[i+16]->sig & DAHDI_SIG_CLEAR)) { |
2994 |
if (ts->span.chans[i+16]->rxsig != rxs) |
2995 |
dahdi_rbsbits(ts->span.chans[i+16], rxs); |
2996 |
} |
2997 |
rxs = (a >> 4) & 0xf; |
2998 |
if (!(ts->span.chans[i]->sig & DAHDI_SIG_CLEAR)) { |
2999 |
if (ts->span.chans[i]->rxsig != rxs) |
3000 |
dahdi_rbsbits(ts->span.chans[i], rxs); |
3001 |
} |
3002 |
} |
3003 |
} else if (ts->span.lineconfig & DAHDI_CONFIG_D4) { |
3004 |
for (i = 0; i < 24; i+=4) { |
3005 |
a = t4_framer_in(wc, span, 0x70 + (i>>2)); |
3006 |
/* Get high channel in low bits */ |
3007 |
rxs = (a & 0x3) << 2; |
3008 |
if (!(ts->span.chans[i+3]->sig & DAHDI_SIG_CLEAR)) { |
3009 |
if (ts->span.chans[i+3]->rxsig != rxs) |
3010 |
dahdi_rbsbits(ts->span.chans[i+3], rxs); |
3011 |
} |
3012 |
rxs = (a & 0xc); |
3013 |
if (!(ts->span.chans[i+2]->sig & DAHDI_SIG_CLEAR)) { |
3014 |
if (ts->span.chans[i+2]->rxsig != rxs) |
3015 |
dahdi_rbsbits(ts->span.chans[i+2], rxs); |
3016 |
} |
3017 |
rxs = (a >> 2) & 0xc; |
3018 |
if (!(ts->span.chans[i+1]->sig & DAHDI_SIG_CLEAR)) { |
3019 |
if (ts->span.chans[i+1]->rxsig != rxs) |
3020 |
dahdi_rbsbits(ts->span.chans[i+1], rxs); |
3021 |
} |
3022 |
rxs = (a >> 4) & 0xc; |
3023 |
if (!(ts->span.chans[i]->sig & DAHDI_SIG_CLEAR)) { |
3024 |
if (ts->span.chans[i]->rxsig != rxs) |
3025 |
dahdi_rbsbits(ts->span.chans[i], rxs); |
3026 |
} |
3027 |
} |
3028 |
} else { |
3029 |
for (i = 0; i < 24; i+=2) { |
3030 |
a = t4_framer_in(wc, span, 0x70 + (i>>1)); |
3031 |
/* Get high channel in low bits */ |
3032 |
rxs = (a & 0xf); |
3033 |
if (!(ts->span.chans[i+1]->sig & DAHDI_SIG_CLEAR)) { |
3034 |
/* XXX Not really reset on every trans! XXX */ |
3035 |
if (ts->span.chans[i+1]->rxsig != rxs) { |
3036 |
dahdi_rbsbits(ts->span.chans[i+1], rxs); |
3037 |
} |
3038 |
} |
3039 |
rxs = (a >> 4) & 0xf; |
3040 |
if (!(ts->span.chans[i]->sig & DAHDI_SIG_CLEAR)) { |
3041 |
/* XXX Not really reset on every trans! XXX */ |
3042 |
if (ts->span.chans[i]->rxsig != rxs) { |
3043 |
dahdi_rbsbits(ts->span.chans[i], rxs); |
3044 |
} |
3045 |
} |
3046 |
} |
3047 |
} |
3048 |
} |
3049 |
|
3050 |
static void t4_check_alarms(struct t4 *wc, int span) |
3051 |
{ |
3052 |
unsigned char c, d, e; |
3053 |
int alarms; |
3054 |
int x,j; |
3055 |
struct t4_span *ts = wc->tspans[span]; |
3056 |
unsigned long flags; |
3057 |
|
3058 |
if (!(ts->span.flags & DAHDI_FLAG_RUNNING)) |
3059 |
return; |
3060 |
|
3061 |
spin_lock_irqsave(&wc->reglock, flags); |
3062 |
|
3063 |
c = __t4_framer_in(wc, span, 0x4c); |
3064 |
d = __t4_framer_in(wc, span, 0x4d); |
3065 |
|
3066 |
/* Assume no alarms */ |
3067 |
alarms = 0; |
3068 |
|
3069 |
/* And consider only carrier alarms */ |
3070 |
ts->span.alarms &= (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE | DAHDI_ALARM_NOTOPEN); |
3071 |
|
3072 |
if (ts->spantype == TYPE_E1) { |
3073 |
if (c & 0x04) { |
3074 |
/* No multiframe found, force RAI high after 400ms only if |
3075 |
we haven't found a multiframe since last loss |
3076 |
of frame */ |
3077 |
if (!(ts->spanflags & FLAG_NMF)) { |
3078 |
__t4_framer_out(wc, span, 0x20, 0x9f | 0x20); /* LIM0: Force RAI High */ |
3079 |
ts->spanflags |= FLAG_NMF; |
3080 |
dev_notice(&wc->dev->dev, |
3081 |
"NMF workaround on!\n"); |
3082 |
} |
3083 |
__t4_framer_out(wc, span, 0x1e, 0xc3); /* Reset to CRC4 mode */ |
3084 |
__t4_framer_out(wc, span, 0x1c, 0xf2); /* Force Resync */ |
3085 |
__t4_framer_out(wc, span, 0x1c, 0xf0); /* Force Resync */ |
3086 |
} else if (!(c & 0x02)) { |
3087 |
if ((ts->spanflags & FLAG_NMF)) { |
3088 |
__t4_framer_out(wc, span, 0x20, 0x9f); /* LIM0: Clear forced RAI */ |
3089 |
ts->spanflags &= ~FLAG_NMF; |
3090 |
dev_notice(&wc->dev->dev, |
3091 |
"NMF workaround off!\n"); |
3092 |
} |
3093 |
} |
3094 |
} else { |
3095 |
/* Detect loopup code if we're not sending one */ |
3096 |
if ((!ts->span.mainttimer) && (d & 0x08)) { |
3097 |
/* Loop-up code detected */ |
3098 |
if ((ts->loopupcnt++ > 80) && (ts->span.maintstat != DAHDI_MAINT_REMOTELOOP)) { |
3099 |
__t4_framer_out(wc, span, 0x36, 0x08); /* LIM0: Disable any local loop */ |
3100 |
__t4_framer_out(wc, span, 0x37, 0xf6 ); /* LIM1: Enable remote loop */ |
3101 |
ts->span.maintstat = DAHDI_MAINT_REMOTELOOP; |
3102 |
} |
3103 |
} else |
3104 |
ts->loopupcnt = 0; |
3105 |
/* Same for loopdown code */ |
3106 |
if ((!ts->span.mainttimer) && (d & 0x10)) { |
3107 |
/* Loop-down code detected */ |
3108 |
if ((ts->loopdowncnt++ > 80) && (ts->span.maintstat == DAHDI_MAINT_REMOTELOOP)) { |
3109 |
__t4_framer_out(wc, span, 0x36, 0x08); /* LIM0: Disable any local loop */ |
3110 |
__t4_framer_out(wc, span, 0x37, 0xf0 ); /* LIM1: Disable remote loop */ |
3111 |
ts->span.maintstat = DAHDI_MAINT_NONE; |
3112 |
} |
3113 |
} else |
3114 |
ts->loopdowncnt = 0; |
3115 |
} |
3116 |
|
3117 |
if (ts->span.lineconfig & DAHDI_CONFIG_NOTOPEN) { |
3118 |
for (x=0,j=0;x < ts->span.channels;x++) |
3119 |
if ((ts->span.chans[x]->flags & DAHDI_FLAG_OPEN) |
3120 |
#ifdef CONFIG_DAHDI_NET |
3121 |
|| |
3122 |
(ts->span.chans[x]->flags & DAHDI_FLAG_NETDEV) |
3123 |
#endif |
3124 |
) |
3125 |
j++; |
3126 |
if (!j) |
3127 |
alarms |= DAHDI_ALARM_NOTOPEN; |
3128 |
} |
3129 |
|
3130 |
/* Loss of Frame Alignment */ |
3131 |
if (c & 0x20) { |
3132 |
if (ts->alarmcount >= alarmdebounce) { |
3133 |
|
3134 |
/* Disable Slip Interrupts */ |
3135 |
e = __t4_framer_in(wc, span, 0x17); |
3136 |
__t4_framer_out(wc, span, 0x17, (e|0x03)); |
3137 |
|
3138 |
alarms |= DAHDI_ALARM_RED; |
3139 |
} else { |
3140 |
if (unlikely(debug && !ts->alarmcount)) { |
3141 |
/* starting to debounce LOF/LFA */ |
3142 |
dev_info(&wc->dev->dev, "opvxd115: LOF/LFA " |
3143 |
"detected on span %d but debouncing " |
3144 |
"for %d ms\n", span + 1, |
3145 |
alarmdebounce); |
3146 |
} |
3147 |
ts->alarmcount++; |
3148 |
} |
3149 |
} else |
3150 |
ts->alarmcount = 0; |
3151 |
|
3152 |
/* Loss of Signal */ |
3153 |
if (c & 0x80) { |
3154 |
if (ts->losalarmcount >= losalarmdebounce) { |
3155 |
/* Disable Slip Interrupts */ |
3156 |
e = __t4_framer_in(wc, span, 0x17); |
3157 |
__t4_framer_out(wc, span, 0x17, (e|0x03)); |
3158 |
|
3159 |
alarms |= DAHDI_ALARM_RED; |
3160 |
} else { |
3161 |
if (unlikely(debug && !ts->losalarmcount)) { |
3162 |
/* starting to debounce LOS */ |
3163 |
dev_info(&wc->dev->dev, "opvxd115: LOS " |
3164 |
"detected on span %d but debouncing " |
3165 |
"for %d ms\n", |
3166 |
span + 1, losalarmdebounce); |
3167 |
} |
3168 |
ts->losalarmcount++; |
3169 |
} |
3170 |
} else |
3171 |
ts->losalarmcount = 0; |
3172 |
|
3173 |
/* Alarm Indication Signal */ |
3174 |
if (c & 0x40) { |
3175 |
if (ts->aisalarmcount >= aisalarmdebounce) |
3176 |
alarms |= DAHDI_ALARM_BLUE; |
3177 |
else { |
3178 |
if (unlikely(debug && !ts->aisalarmcount)) { |
3179 |
/* starting to debounce AIS */ |
3180 |
dev_info(&wc->dev->dev, "opvxd115: AIS " |
3181 |
"detected on span %d but debouncing " |
3182 |
"for %d ms\n", |
3183 |
span + 1, aisalarmdebounce); |
3184 |
} |
3185 |
ts->aisalarmcount++; |
3186 |
} |
3187 |
} else |
3188 |
ts->aisalarmcount = 0; |
3189 |
|
3190 |
#ifdef DAHDI_SPAN_OPS |
3191 |
/* Add detailed alarm status information to a red alarm state */ |
3192 |
if (alarms & DAHDI_ALARM_RED) { |
3193 |
if (c & FRS0_LOS) |
3194 |
alarms |= DAHDI_ALARM_LOS; |
3195 |
if (c & FRS0_LFA) |
3196 |
alarms |= DAHDI_ALARM_LFA; |
3197 |
if (c & FRS0_LMFA) |
3198 |
alarms |= DAHDI_ALARM_LMFA; |
3199 |
} |
3200 |
|
3201 |
if (unlikely(debug)) { |
3202 |
/* Check to ensure the xmit line isn't shorted */ |
3203 |
if (unlikely(d & FRS1_XLS)) { |
3204 |
dev_info(&wc->dev->dev, |
3205 |
"Detected a possible hardware malfunction"\ |
3206 |
" this card may need servicing\n"); |
3207 |
} |
3208 |
} |
3209 |
#endif |
3210 |
|
3211 |
if (((!ts->span.alarms) && alarms) || |
3212 |
(ts->span.alarms && (!alarms))) |
3213 |
set_bit(T4_CHECK_TIMING, &wc->checkflag); |
3214 |
|
3215 |
/* Keep track of recovering */ |
3216 |
if ((!alarms) && ts->span.alarms) |
3217 |
ts->alarmtimer = DAHDI_ALARMSETTLE_TIME; |
3218 |
if (ts->alarmtimer) |
3219 |
alarms |= DAHDI_ALARM_RECOVER; |
3220 |
|
3221 |
/* If receiving alarms, go into Yellow alarm state */ |
3222 |
if (alarms && !(ts->spanflags & FLAG_SENDINGYELLOW)) { |
3223 |
/* We manually do yellow alarm to handle RECOVER and NOTOPEN, otherwise it's auto anyway */ |
3224 |
unsigned char fmr4; |
3225 |
fmr4 = __t4_framer_in(wc, span, 0x20); |
3226 |
__t4_framer_out(wc, span, 0x20, fmr4 | 0x20); |
3227 |
dev_info(&wc->dev->dev, "Setting yellow alarm span %d\n", |
3228 |
span+1); |
3229 |
ts->spanflags |= FLAG_SENDINGYELLOW; |
3230 |
} else if ((!alarms) && (ts->spanflags & FLAG_SENDINGYELLOW)) { |
3231 |
unsigned char fmr4; |
3232 |
/* We manually do yellow alarm to handle RECOVER */ |
3233 |
fmr4 = __t4_framer_in(wc, span, 0x20); |
3234 |
__t4_framer_out(wc, span, 0x20, fmr4 & ~0x20); |
3235 |
dev_info(&wc->dev->dev, "Clearing yellow alarm span %d\n", |
3236 |
span+1); |
3237 |
|
3238 |
/* Re-enable timing slip interrupts */ |
3239 |
e = __t4_framer_in(wc, span, 0x17); |
3240 |
|
3241 |
__t4_framer_out(wc, span, 0x17, (e & ~(0x03))); |
3242 |
|
3243 |
ts->spanflags &= ~FLAG_SENDINGYELLOW; |
3244 |
} |
3245 |
|
3246 |
/* Re-check the timing source when we enter/leave alarm, not withstanding |
3247 |
yellow alarm */ |
3248 |
if (c & 0x10) { /* receiving yellow (RAI) */ |
3249 |
if (ts->yelalarmcount >= yelalarmdebounce) |
3250 |
alarms |= DAHDI_ALARM_YELLOW; |
3251 |
else { |
3252 |
if (unlikely(debug && !ts->yelalarmcount)) { |
3253 |
/* starting to debounce AIS */ |
3254 |
dev_info(&wc->dev->dev, "wct%dxxp: yellow " |
3255 |
"(RAI) detected on span %d but " |
3256 |
"debouncing for %d ms\n", |
3257 |
wc->numspans, span + 1, |
3258 |
yelalarmdebounce); |
3259 |
} |
3260 |
ts->yelalarmcount++; |
3261 |
} |
3262 |
} else |
3263 |
ts->yelalarmcount = 0; |
3264 |
|
3265 |
if (ts->span.mainttimer || ts->span.maintstat) |
3266 |
alarms |= DAHDI_ALARM_LOOPBACK; |
3267 |
ts->span.alarms = alarms; |
3268 |
spin_unlock_irqrestore(&wc->reglock, flags); |
3269 |
dahdi_alarm_notify(&ts->span); |
3270 |
} |
3271 |
|
3272 |
static void t4_do_counters(struct t4 *wc) |
3273 |
{ |
3274 |
int span; |
3275 |
for (span=0;span<wc->numspans;span++) { |
3276 |
struct t4_span *ts = wc->tspans[span]; |
3277 |
int docheck=0; |
3278 |
|
3279 |
spin_lock(&wc->reglock); |
3280 |
if (ts->loopupcnt || ts->loopdowncnt || ts->alarmcount |
3281 |
|| ts->losalarmcount || ts->aisalarmcount |
3282 |
|| ts->yelalarmcount) |
3283 |
docheck++; |
3284 |
|
3285 |
if (ts->alarmtimer) { |
3286 |
if (!--ts->alarmtimer) { |
3287 |
docheck++; |
3288 |
ts->span.alarms &= ~(DAHDI_ALARM_RECOVER); |
3289 |
} |
3290 |
} |
3291 |
spin_unlock(&wc->reglock); |
3292 |
if (docheck) { |
3293 |
t4_check_alarms(wc, span); |
3294 |
dahdi_alarm_notify(&ts->span); |
3295 |
} |
3296 |
} |
3297 |
} |
3298 |
|
3299 |
static inline void __handle_leds(struct t4 *wc) |
3300 |
{ |
3301 |
int x; |
3302 |
|
3303 |
wc->blinktimer++; |
3304 |
for (x=0;x<wc->numspans;x++) { |
3305 |
struct t4_span *ts = wc->tspans[x]; |
3306 |
if (ts->span.flags & DAHDI_FLAG_RUNNING) { |
3307 |
if ((ts->span.alarms & (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE)) || ts->losalarmcount) { |
3308 |
#ifdef FANCY_ALARM |
3309 |
if (wc->blinktimer == (altab[wc->alarmpos] >> 1)) { |
3310 |
__t4_set_led(wc, x, WC_RED); |
3311 |
} |
3312 |
if (wc->blinktimer == 0xf) { |
3313 |
__t4_set_led(wc, x, WC_OFF); |
3314 |
} |
3315 |
#else |
3316 |
if (wc->blinktimer == 160) { |
3317 |
__t4_set_led(wc, x, WC_RED); |
3318 |
} else if (wc->blinktimer == 480) { |
3319 |
__t4_set_led(wc, x, WC_OFF); |
3320 |
} |
3321 |
#endif |
3322 |
} else if (ts->span.alarms & DAHDI_ALARM_YELLOW) { |
3323 |
/* Yellow Alarm */ |
3324 |
__t4_set_led(wc, x, WC_YELLOW); |
3325 |
} else if (ts->span.mainttimer || ts->span.maintstat) { |
3326 |
#ifdef FANCY_ALARM |
3327 |
if (wc->blinktimer == (altab[wc->alarmpos] >> 1)) { |
3328 |
__t4_set_led(wc, x, WC_GREEN); |
3329 |
} |
3330 |
if (wc->blinktimer == 0xf) { |
3331 |
__t4_set_led(wc, x, WC_OFF); |
3332 |
} |
3333 |
#else |
3334 |
if (wc->blinktimer == 160) { |
3335 |
__t4_set_led(wc, x, WC_GREEN); |
3336 |
} else if (wc->blinktimer == 480) { |
3337 |
__t4_set_led(wc, x, WC_OFF); |
3338 |
} |
3339 |
#endif |
3340 |
} else { |
3341 |
/* No Alarm */ |
3342 |
__t4_set_led(wc, x, WC_GREEN); |
3343 |
} |
3344 |
} else |
3345 |
__t4_set_led(wc, x, WC_OFF); |
3346 |
|
3347 |
} |
3348 |
#ifdef FANCY_ALARM |
3349 |
if (wc->blinktimer == 0xf) { |
3350 |
wc->blinktimer = -1; |
3351 |
wc->alarmpos++; |
3352 |
if (wc->alarmpos >= (sizeof(altab) / sizeof(altab[0]))) |
3353 |
wc->alarmpos = 0; |
3354 |
} |
3355 |
#else |
3356 |
if (wc->blinktimer == 480) |
3357 |
wc->blinktimer = 0; |
3358 |
#endif |
3359 |
} |
3360 |
|
3361 |
static inline void t4_framer_interrupt(struct t4 *wc, int span) |
3362 |
{ |
3363 |
unsigned char gis, isr0, isr1, isr2, isr3, isr4; |
3364 |
#if (defined(DAHDI_SPAN_OPS) || defined(DAHDI_SPAN_MODULE) ) |
3365 |
/* Check interrupts for a given span */ |
3366 |
unsigned char reg; |
3367 |
#endif |
3368 |
int readsize = -1; |
3369 |
struct t4_span *ts = wc->tspans[span]; |
3370 |
struct dahdi_chan *sigchan; |
3371 |
unsigned long flags; |
3372 |
|
3373 |
|
3374 |
/* 1st gen cards isn't used interrupts */ |
3375 |
gis = t4_framer_in(wc, span, FRMR_GIS); |
3376 |
isr0 = (gis & FRMR_GIS_ISR0) ? t4_framer_in(wc, span, FRMR_ISR0) : 0; |
3377 |
isr1 = (gis & FRMR_GIS_ISR1) ? t4_framer_in(wc, span, FRMR_ISR1) : 0; |
3378 |
isr2 = (gis & FRMR_GIS_ISR2) ? t4_framer_in(wc, span, FRMR_ISR2) : 0; |
3379 |
isr3 = (gis & FRMR_GIS_ISR3) ? t4_framer_in(wc, span, FRMR_ISR3) : 0; |
3380 |
isr4 = (gis & FRMR_GIS_ISR4) ? t4_framer_in(wc, span, FRMR_ISR4) : 0; |
3381 |
|
3382 |
if ((debug & DEBUG_FRAMER) && !(isr3 & ISR3_SEC)) { |
3383 |
dev_info(&wc->dev->dev, "gis: %02x, isr0: %02x, isr1: %02x, "\ |
3384 |
"isr2: %02x, isr3: %08x, isr4: %02x, intcount=%u\n", |
3385 |
gis, isr0, isr1, isr2, isr3, isr4, wc->intcount); |
3386 |
} |
3387 |
|
3388 |
#if (defined(DAHDI_SPAN_OPS) || defined(DAHDI_SPAN_MODULE) ) |
3389 |
/* Collect performance counters once per second */ |
3390 |
if (isr3 & ISR3_SEC) { |
3391 |
ts->span.count.fe += t4_framer_in(wc, span, FECL_T); |
3392 |
ts->span.count.crc4 += t4_framer_in(wc, span, CEC1L_T); |
3393 |
ts->span.count.cv += t4_framer_in(wc, span, CVCL_T); |
3394 |
ts->span.count.ebit += t4_framer_in(wc, span, EBCL_T); |
3395 |
ts->span.count.be += t4_framer_in(wc, span, BECL_T); |
3396 |
ts->span.count.prbs = t4_framer_in(wc, span, FRS1_T); |
3397 |
} |
3398 |
|
3399 |
/* Collect errored second counter once per second */ |
3400 |
if (isr3 & ISR3_ES) { |
3401 |
ts->span.count.errsec += 1; |
3402 |
} |
3403 |
|
3404 |
if (isr3 & 0x08) { |
3405 |
reg = t4_framer_in(wc, span, FRS1_T); |
3406 |
dev_info(&wc->dev->dev, "FRS1: %d\n", reg); |
3407 |
if (reg & LLBDD) { |
3408 |
dev_info(&wc->dev->dev, "Line loop-back activation "\ |
3409 |
"signal detected with status: %01d "\ |
3410 |
"for span %d\n", reg & LLBAD, span+1); |
3411 |
} |
3412 |
} |
3413 |
#endif |
3414 |
|
3415 |
if (isr0) |
3416 |
t4_check_sigbits(wc, span); |
3417 |
|
3418 |
if (ts->spantype == TYPE_E1) { |
3419 |
/* E1 checks */ |
3420 |
if ((isr3 & 0x38) || isr2 || isr1) |
3421 |
t4_check_alarms(wc, span); |
3422 |
} else { |
3423 |
/* T1 checks */ |
3424 |
if (isr2 || (isr3 & 0x08)) |
3425 |
t4_check_alarms(wc, span); |
3426 |
} |
3427 |
if (!ts->span.alarms) { |
3428 |
if ((isr3 & 0x3) || (isr4 & 0xc0)) |
3429 |
ts->span.timingslips++; |
3430 |
|
3431 |
if (debug & DEBUG_MAIN) { |
3432 |
if (isr3 & 0x02) |
3433 |
dev_notice(&wc->dev->dev, "opvxd115: RECEIVE " |
3434 |
"slip NEGATIVE on span %d\n", |
3435 |
span + 1); |
3436 |
if (isr3 & 0x01) |
3437 |
dev_notice(&wc->dev->dev, "opvxd115: RECEIVE " |
3438 |
"slip POSITIVE on span %d\n", |
3439 |
span + 1); |
3440 |
if (isr4 & 0x80) |
3441 |
dev_notice(&wc->dev->dev, "opvxd115: TRANSMIT " |
3442 |
"slip POSITIVE on span %d\n", |
3443 |
span + 1); |
3444 |
if (isr4 & 0x40) |
3445 |
dev_notice(&wc->dev->dev, "opvxd115: TRANSMIT " |
3446 |
"slip NEGATIVE on span %d\n", |
3447 |
span + 1); |
3448 |
} |
3449 |
} else |
3450 |
ts->span.timingslips = 0; |
3451 |
|
3452 |
spin_lock_irqsave(&wc->reglock, flags); |
3453 |
/* HDLC controller checks - receive side */ |
3454 |
if (!ts->sigchan) { |
3455 |
spin_unlock_irqrestore(&wc->reglock, flags); |
3456 |
return; |
3457 |
} |
3458 |
|
3459 |
sigchan = ts->sigchan; |
3460 |
spin_unlock_irqrestore(&wc->reglock, flags); |
3461 |
|
3462 |
if (isr0 & FRMR_ISR0_RME) { |
3463 |
readsize = (t4_framer_in(wc, span, FRMR_RBCH) << 8) | t4_framer_in(wc, span, FRMR_RBCL); |
3464 |
if (debug & DEBUG_FRAMER) |
3465 |
dev_notice(&wc->dev->dev, "Received data length is %d " |
3466 |
"(%d)\n", readsize, |
3467 |
readsize & FRMR_RBCL_MAX_SIZE); |
3468 |
/* RPF isn't set on last part of frame */ |
3469 |
if ((readsize > 0) && ((readsize &= FRMR_RBCL_MAX_SIZE) == 0)) |
3470 |
readsize = FRMR_RBCL_MAX_SIZE + 1; |
3471 |
} else if (isr0 & FRMR_ISR0_RPF) |
3472 |
readsize = FRMR_RBCL_MAX_SIZE + 1; |
3473 |
|
3474 |
if (readsize > 0) { |
3475 |
int i; |
3476 |
unsigned char readbuf[FRMR_RBCL_MAX_SIZE + 1]; |
3477 |
|
3478 |
if (debug & DEBUG_FRAMER) |
3479 |
dev_notice(&wc->dev->dev, "Framer %d: Got RPF/RME! " |
3480 |
"readsize is %d\n", sigchan->span->offset, |
3481 |
readsize); |
3482 |
|
3483 |
for (i = 0; i < readsize; i++) |
3484 |
readbuf[i] = t4_framer_in(wc, span, FRMR_RXFIFO); |
3485 |
|
3486 |
/* Tell the framer to clear the RFIFO */ |
3487 |
t4_framer_cmd_wait(wc, span, FRMR_CMDR_RMC); |
3488 |
|
3489 |
if (debug & DEBUG_FRAMER) { |
3490 |
dev_notice(&wc->dev->dev, "RX("); |
3491 |
for (i = 0; i < readsize; i++) |
3492 |
dev_notice(&wc->dev->dev, "%s%02x", |
3493 |
(i ? " " : ""), readbuf[i]); |
3494 |
dev_notice(&wc->dev->dev, ")\n"); |
3495 |
} |
3496 |
|
3497 |
if (isr0 & FRMR_ISR0_RME) { |
3498 |
/* Do checks for HDLC problems */ |
3499 |
unsigned char rsis = readbuf[readsize-1]; |
3500 |
#if 0 |
3501 |
unsigned int olddebug = debug; |
3502 |
#endif |
3503 |
unsigned char rsis_reg = t4_framer_in(wc, span, FRMR_RSIS); |
3504 |
|
3505 |
#if 0 |
3506 |
if ((rsis != 0xA2) || (rsis != rsis_reg)) |
3507 |
debug |= DEBUG_FRAMER; |
3508 |
#endif |
3509 |
|
3510 |
++ts->frames_in; |
3511 |
if ((debug & DEBUG_FRAMER) && !(ts->frames_in & 0x0f)) |
3512 |
dev_notice(&wc->dev->dev, "Received %d frames " |
3513 |
"on span %d\n", ts->frames_in, span); |
3514 |
if (debug & DEBUG_FRAMER) |
3515 |
dev_notice(&wc->dev->dev, "Received HDLC frame" |
3516 |
" %d. RSIS = 0x%x (%x)\n", |
3517 |
ts->frames_in, rsis, rsis_reg); |
3518 |
if (!(rsis & FRMR_RSIS_CRC16)) { |
3519 |
if (debug & DEBUG_FRAMER) |
3520 |
dev_notice(&wc->dev->dev, "CRC check " |
3521 |
"failed %d\n", span); |
3522 |
dahdi_hdlc_abort(sigchan, DAHDI_EVENT_BADFCS); |
3523 |
} else if (rsis & FRMR_RSIS_RAB) { |
3524 |
if (debug & DEBUG_FRAMER) |
3525 |
dev_notice(&wc->dev->dev, "ABORT of " |
3526 |
"current frame due to " |
3527 |
"overflow %d\n", span); |
3528 |
dahdi_hdlc_abort(sigchan, DAHDI_EVENT_ABORT); |
3529 |
} else if (rsis & FRMR_RSIS_RDO) { |
3530 |
if (debug & DEBUG_FRAMER) |
3531 |
dev_notice(&wc->dev->dev, "HDLC " |
3532 |
"overflow occured %d\n", |
3533 |
span); |
3534 |
dahdi_hdlc_abort(sigchan, DAHDI_EVENT_OVERRUN); |
3535 |
} else if (!(rsis & FRMR_RSIS_VFR)) { |
3536 |
if (debug & DEBUG_FRAMER) |
3537 |
dev_notice(&wc->dev->dev, "Valid Frame" |
3538 |
" check failed on span %d\n", |
3539 |
span); |
3540 |
dahdi_hdlc_abort(sigchan, DAHDI_EVENT_ABORT); |
3541 |
} else { |
3542 |
dahdi_hdlc_putbuf(sigchan, readbuf, readsize - 1); |
3543 |
dahdi_hdlc_finish(sigchan); |
3544 |
if (debug & DEBUG_FRAMER) |
3545 |
dev_notice(&wc->dev->dev, "Received " |
3546 |
"valid HDLC frame on span %d" |
3547 |
"\n", span); |
3548 |
} |
3549 |
#if 0 |
3550 |
debug = olddebug; |
3551 |
#endif |
3552 |
} else if (isr0 & FRMR_ISR0_RPF) |
3553 |
dahdi_hdlc_putbuf(sigchan, readbuf, readsize); |
3554 |
} |
3555 |
|
3556 |
/* Transmit side */ |
3557 |
if (isr1 & FRMR_ISR1_XDU) { |
3558 |
if (debug & DEBUG_FRAMER) |
3559 |
dev_notice(&wc->dev->dev, "XDU: Resetting signal " |
3560 |
"controller!\n"); |
3561 |
t4_framer_cmd_wait(wc, span, FRMR_CMDR_SRES); |
3562 |
} else if (isr1 & FRMR_ISR1_XPR) { |
3563 |
if (debug & DEBUG_FRAMER) |
3564 |
dev_notice(&wc->dev->dev, "Sigchan %d is %p\n", |
3565 |
sigchan->chanpos, sigchan); |
3566 |
|
3567 |
if (debug & DEBUG_FRAMER) |
3568 |
dev_notice(&wc->dev->dev, "Framer %d: Got XPR!\n", |
3569 |
sigchan->span->offset); |
3570 |
t4_hdlc_xmit_fifo(wc, span, ts); |
3571 |
} |
3572 |
|
3573 |
if (isr1 & FRMR_ISR1_ALLS) { |
3574 |
if (debug & DEBUG_FRAMER) |
3575 |
dev_notice(&wc->dev->dev, "ALLS received\n"); |
3576 |
} |
3577 |
} |
3578 |
|
3579 |
#ifdef SUPPORT_GEN1 |
3580 |
DAHDI_IRQ_HANDLER(t4_interrupt) |
3581 |
{ |
3582 |
struct t4 *wc = dev_id; |
3583 |
unsigned long flags; |
3584 |
int x; |
3585 |
|
3586 |
unsigned int status; |
3587 |
unsigned int status2; |
3588 |
|
3589 |
#if 0 |
3590 |
if (wc->intcount < 20) |
3591 |
dev_notice(&wc->dev->dev, "Pre-interrupt\n"); |
3592 |
#endif |
3593 |
|
3594 |
/* Make sure it's really for us */ |
3595 |
status = __t4_pci_in(wc, WC_INTR); |
3596 |
|
3597 |
/* Process framer interrupts */ |
3598 |
status2 = t4_framer_in(wc, 0, FRMR_CIS); |
3599 |
if (status2 & 0x0f) { |
3600 |
for (x = 0; x < wc->numspans; ++x) { |
3601 |
if (status2 & (1 << x)) |
3602 |
t4_framer_interrupt(wc, x); |
3603 |
} |
3604 |
} |
3605 |
|
3606 |
/* Ignore if it's not for us */ |
3607 |
if (!status) |
3608 |
return IRQ_NONE; |
3609 |
|
3610 |
__t4_pci_out(wc, WC_INTR, 0); |
3611 |
|
3612 |
if (!wc->spansstarted) { |
3613 |
dev_notice(&wc->dev->dev, "Not prepped yet!\n"); |
3614 |
return IRQ_NONE; |
3615 |
} |
3616 |
|
3617 |
wc->intcount++; |
3618 |
#if 0 |
3619 |
if (wc->intcount < 20) |
3620 |
dev_notice(&wc->dev->dev, "Got interrupt, status = %08x\n", |
3621 |
status); |
3622 |
#endif |
3623 |
|
3624 |
if (status & 0x3) { |
3625 |
t4_receiveprep(wc, status); |
3626 |
t4_transmitprep(wc, status); |
3627 |
} |
3628 |
|
3629 |
#if 0 |
3630 |
if ((wc->intcount < 10) || !(wc->intcount % 1000)) { |
3631 |
status2 = t4_framer_in(wc, 0, FRMR_CIS); |
3632 |
dev_notice(&wc->dev->dev, "Status2: %04x\n", status2); |
3633 |
for (x = 0;x<wc->numspans;x++) { |
3634 |
status2 = t4_framer_in(wc, x, FRMR_FRS0); |
3635 |
dev_notice(&wc->dev->dev, "FRS0/%d: %04x\n", x, |
3636 |
status2); |
3637 |
} |
3638 |
} |
3639 |
#endif |
3640 |
t4_do_counters(wc); |
3641 |
|
3642 |
x = wc->intcount & 15 /* 63 */; |
3643 |
switch(x) { |
3644 |
case 0: |
3645 |
case 1: |
3646 |
case 2: |
3647 |
case 3: |
3648 |
t4_check_sigbits(wc, x); |
3649 |
break; |
3650 |
case 4: |
3651 |
case 5: |
3652 |
case 6: |
3653 |
case 7: |
3654 |
t4_check_alarms(wc, x - 4); |
3655 |
break; |
3656 |
} |
3657 |
|
3658 |
spin_lock_irqsave(&wc->reglock, flags); |
3659 |
|
3660 |
__handle_leds(wc); |
3661 |
|
3662 |
if (test_bit(T4_CHECK_TIMING, &wc->checkflag)) |
3663 |
__t4_set_timing_source_auto(wc); |
3664 |
|
3665 |
spin_unlock_irqrestore(&wc->reglock, flags); |
3666 |
|
3667 |
return IRQ_RETVAL(1); |
3668 |
} |
3669 |
#endif |
3670 |
|
3671 |
static int t4_allocate_buffers(struct t4 *wc, int numbufs, volatile unsigned int **oldalloc, dma_addr_t *oldwritedma) |
3672 |
{ |
3673 |
volatile unsigned int *alloc; |
3674 |
dma_addr_t writedma; |
3675 |
|
3676 |
alloc = |
3677 |
/* 32 channels, Double-buffer, Read/Write, 4 spans */ |
3678 |
(unsigned int *)pci_alloc_consistent(wc->dev, numbufs * T4_BASE_SIZE * 2, &writedma); |
3679 |
|
3680 |
if (!alloc) { |
3681 |
dev_notice(&wc->dev->dev, "wct%dxxp: Unable to allocate " |
3682 |
"DMA-able memory\n", wc->numspans); |
3683 |
return -ENOMEM; |
3684 |
} |
3685 |
|
3686 |
if (oldwritedma) |
3687 |
*oldwritedma = wc->writedma; |
3688 |
if (oldalloc) |
3689 |
*oldalloc = wc->writechunk; |
3690 |
|
3691 |
wc->writechunk = alloc; |
3692 |
wc->writedma = writedma; |
3693 |
|
3694 |
/* Read is after the whole write piece (in words) */ |
3695 |
wc->readchunk = wc->writechunk + (T4_BASE_SIZE * numbufs) / 4; |
3696 |
|
3697 |
/* Same thing but in bytes... */ |
3698 |
wc->readdma = wc->writedma + (T4_BASE_SIZE * numbufs); |
3699 |
|
3700 |
wc->numbufs = numbufs; |
3701 |
|
3702 |
/* Initialize Write/Buffers to all blank data */ |
3703 |
memset((void *)wc->writechunk,0x00, T4_BASE_SIZE * numbufs); |
3704 |
memset((void *)wc->readchunk,0xff, T4_BASE_SIZE * numbufs); |
3705 |
|
3706 |
dev_notice(&wc->dev->dev, "DMA memory base of size %d at %p. Read: " |
3707 |
"%p and Write %p\n", numbufs * T4_BASE_SIZE * 2, |
3708 |
wc->writechunk, wc->readchunk, wc->writechunk); |
3709 |
|
3710 |
return 0; |
3711 |
} |
3712 |
|
3713 |
static void t4_increase_latency(struct t4 *wc, int newlatency) |
3714 |
{ |
3715 |
unsigned long flags; |
3716 |
volatile unsigned int *oldalloc; |
3717 |
dma_addr_t oldaddr; |
3718 |
int oldbufs; |
3719 |
|
3720 |
spin_lock_irqsave(&wc->reglock, flags); |
3721 |
|
3722 |
__t4_pci_out(wc, WC_DMACTRL, 0x00000000); |
3723 |
/* Acknowledge any pending interrupts */ |
3724 |
__t4_pci_out(wc, WC_INTR, 0x00000000); |
3725 |
|
3726 |
__t4_pci_in(wc, WC_VERSION); |
3727 |
|
3728 |
oldbufs = wc->numbufs; |
3729 |
|
3730 |
if (t4_allocate_buffers(wc, newlatency, &oldalloc, &oldaddr)) { |
3731 |
dev_info(&wc->dev->dev, "Error allocating latency buffers for " |
3732 |
"latency of %d\n", newlatency); |
3733 |
__t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
3734 |
spin_unlock_irqrestore(&wc->reglock, flags); |
3735 |
return; |
3736 |
} |
3737 |
|
3738 |
__t4_pci_out(wc, WC_RDADDR, wc->readdma); |
3739 |
__t4_pci_out(wc, WC_WRADDR, wc->writedma); |
3740 |
|
3741 |
__t4_pci_in(wc, WC_VERSION); |
3742 |
|
3743 |
__t4_pci_out(wc, 5, (ms_per_irq << 16) | newlatency); |
3744 |
__t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
3745 |
|
3746 |
__t4_pci_in(wc, WC_VERSION); |
3747 |
|
3748 |
wc->rxident = 0; |
3749 |
wc->lastindex = 0; |
3750 |
|
3751 |
spin_unlock_irqrestore(&wc->reglock, flags); |
3752 |
|
3753 |
pci_free_consistent(wc->dev, T4_BASE_SIZE * oldbufs * 2, (void *)oldalloc, oldaddr); |
3754 |
|
3755 |
dev_info(&wc->dev->dev, "Increased latency to %d\n", newlatency); |
3756 |
|
3757 |
} |
3758 |
|
3759 |
static void t4_isr_bh(unsigned long data) |
3760 |
{ |
3761 |
struct t4 *wc = (struct t4 *)data; |
3762 |
|
3763 |
if (test_bit(T4_CHANGE_LATENCY, &wc->checkflag)) { |
3764 |
if (wc->needed_latency != wc->numbufs) { |
3765 |
t4_increase_latency(wc, wc->needed_latency); |
3766 |
clear_bit(T4_CHANGE_LATENCY, &wc->checkflag); |
3767 |
} |
3768 |
} |
3769 |
#ifdef VPM_SUPPORT |
3770 |
if (wc->vpm) { |
3771 |
if (test_and_clear_bit(T4_CHECK_VPM, &wc->checkflag)) { |
3772 |
if (wc->vpm450m) { |
3773 |
/* How stupid is it that the octasic can't generate an |
3774 |
interrupt when there's a tone, in spite of what their |
3775 |
documentation says? */ |
3776 |
t4_check_vpm450(wc); |
3777 |
} else |
3778 |
t4_check_vpm400(wc, wc->vpm400checkstatus); |
3779 |
} |
3780 |
} |
3781 |
#endif |
3782 |
} |
3783 |
|
3784 |
DAHDI_IRQ_HANDLER(t4_interrupt_gen2) |
3785 |
{ |
3786 |
struct t4 *wc = dev_id; |
3787 |
unsigned int status; |
3788 |
unsigned char rxident, expected; |
3789 |
|
3790 |
/* Check this first in case we get a spurious interrupt */ |
3791 |
if (unlikely(test_bit(T4_STOP_DMA, &wc->checkflag))) { |
3792 |
/* Stop DMA cleanly if requested */ |
3793 |
wc->dmactrl = 0x0; |
3794 |
t4_pci_out(wc, WC_DMACTRL, 0x00000000); |
3795 |
/* Acknowledge any pending interrupts */ |
3796 |
t4_pci_out(wc, WC_INTR, 0x00000000); |
3797 |
spin_lock(&wc->reglock); |
3798 |
__t4_set_sclk_src(wc, WC_SELF, 0, 0); |
3799 |
spin_unlock(&wc->reglock); |
3800 |
return IRQ_RETVAL(1); |
3801 |
} |
3802 |
|
3803 |
/* Make sure it's really for us */ |
3804 |
status = __t4_pci_in(wc, WC_INTR); |
3805 |
|
3806 |
/* Ignore if it's not for us */ |
3807 |
if (!(status & 0x7)) { |
3808 |
return IRQ_NONE; |
3809 |
} |
3810 |
|
3811 |
#ifdef ENABLE_WORKQUEUES |
3812 |
__t4_pci_out(wc, WC_INTR, status & 0x00000008); |
3813 |
#endif |
3814 |
|
3815 |
if (unlikely(!wc->spansstarted)) { |
3816 |
dev_info(&wc->dev->dev, "Not prepped yet!\n"); |
3817 |
return IRQ_NONE; |
3818 |
} |
3819 |
|
3820 |
wc->intcount++; |
3821 |
|
3822 |
if ((wc->flags & FLAG_5THGEN) && (status & 0x2)) { |
3823 |
rxident = (status >> 16) & 0x7f; |
3824 |
expected = (wc->rxident + ms_per_irq) % 128; |
3825 |
|
3826 |
if ((rxident != expected) && !test_bit(T4_IGNORE_LATENCY, &wc->checkflag)) { |
3827 |
int needed_latency; |
3828 |
int smallest_max; |
3829 |
|
3830 |
if (debug & DEBUG_MAIN) |
3831 |
dev_warn(&wc->dev->dev, "Missed interrupt. " |
3832 |
"Expected ident of %d and got ident " |
3833 |
"of %d\n", expected, rxident); |
3834 |
|
3835 |
if (test_bit(T4_IGNORE_LATENCY, &wc->checkflag)) { |
3836 |
dev_info(&wc->dev->dev, |
3837 |
"Should have ignored latency\n"); |
3838 |
} |
3839 |
if (rxident > wc->rxident) { |
3840 |
needed_latency = rxident - wc->rxident; |
3841 |
} else { |
3842 |
needed_latency = (128 - wc->rxident) + rxident; |
3843 |
} |
3844 |
|
3845 |
needed_latency += 1; |
3846 |
|
3847 |
smallest_max = (max_latency >= GEN5_MAX_LATENCY) ? GEN5_MAX_LATENCY : max_latency; |
3848 |
|
3849 |
if (needed_latency > smallest_max) { |
3850 |
dev_info(&wc->dev->dev, "Truncating latency " |
3851 |
"request to %d instead of %d\n", |
3852 |
smallest_max, needed_latency); |
3853 |
needed_latency = smallest_max; |
3854 |
} |
3855 |
|
3856 |
if (needed_latency > wc->numbufs) { |
3857 |
int x; |
3858 |
|
3859 |
dev_info(&wc->dev->dev, "Need to increase " |
3860 |
"latency. Estimated latency should " |
3861 |
"be %d\n", needed_latency); |
3862 |
for (x = 0; x < wc->numspans; x++) |
3863 |
wc->ddev->irqmisses++; |
3864 |
wc->needed_latency = needed_latency; |
3865 |
__t4_pci_out(wc, WC_DMACTRL, 0x00000000); |
3866 |
set_bit(T4_CHANGE_LATENCY, &wc->checkflag); |
3867 |
goto out; |
3868 |
} |
3869 |
} |
3870 |
|
3871 |
wc->rxident = rxident; |
3872 |
} |
3873 |
|
3874 |
if (unlikely((wc->intcount < 20))) |
3875 |
|
3876 |
dev_info(&wc->dev->dev, "2G: Got interrupt, status = %08x, " |
3877 |
"CIS = %04x\n", status, t4_framer_in(wc, 0, FRMR_CIS)); |
3878 |
|
3879 |
if (likely(status & 0x2)) { |
3880 |
#ifdef ENABLE_WORKQUEUES |
3881 |
int cpus = num_online_cpus(); |
3882 |
atomic_set(&wc->worklist, wc->numspans); |
3883 |
if (wc->tspans[0]->span.flags & DAHDI_FLAG_RUNNING) |
3884 |
t4_queue_work(wc->workq, &wc->tspans[0]->swork, 0); |
3885 |
else |
3886 |
atomic_dec(&wc->worklist); |
3887 |
#else |
3888 |
#if 1 |
3889 |
unsigned int reg5 = __t4_pci_in(wc, 5); |
3890 |
if (wc->intcount < 20) { |
3891 |
|
3892 |
dev_info(&wc->dev->dev, "Reg 5 is %08x\n", reg5); |
3893 |
} |
3894 |
#endif |
3895 |
|
3896 |
if (wc->flags & FLAG_5THGEN) { |
3897 |
unsigned int current_index = (reg5 >> 8) & 0x7f; |
3898 |
|
3899 |
while (((wc->lastindex + 1) % wc->numbufs) != current_index) { |
3900 |
wc->lastindex = (wc->lastindex + 1) % wc->numbufs; |
3901 |
setup_chunks(wc, wc->lastindex); |
3902 |
t4_prep_gen2(wc); |
3903 |
} |
3904 |
} else { |
3905 |
t4_prep_gen2(wc); |
3906 |
} |
3907 |
|
3908 |
#endif |
3909 |
t4_do_counters(wc); |
3910 |
spin_lock(&wc->reglock); |
3911 |
__handle_leds(wc); |
3912 |
spin_unlock(&wc->reglock); |
3913 |
|
3914 |
} |
3915 |
|
3916 |
if (unlikely(status & 0x1)) { |
3917 |
unsigned char cis; |
3918 |
|
3919 |
cis = t4_framer_in(wc, 0, FRMR_CIS); |
3920 |
if (cis & FRMR_CIS_GIS1) |
3921 |
t4_framer_interrupt(wc, 0); |
3922 |
if (cis & FRMR_CIS_GIS2) |
3923 |
t4_framer_interrupt(wc, 1); |
3924 |
if (cis & FRMR_CIS_GIS3) |
3925 |
t4_framer_interrupt(wc, 2); |
3926 |
if (cis & FRMR_CIS_GIS4) |
3927 |
t4_framer_interrupt(wc, 3); |
3928 |
} |
3929 |
|
3930 |
if (wc->vpm && vpmdtmfsupport) { |
3931 |
if (wc->vpm450m) { |
3932 |
/* How stupid is it that the octasic can't generate an |
3933 |
interrupt when there's a tone, in spite of what their |
3934 |
documentation says? */ |
3935 |
if (!(wc->intcount & 0xf)) { |
3936 |
set_bit(T4_CHECK_VPM, &wc->checkflag); |
3937 |
} |
3938 |
} else if ((status & 0xff00) != 0xff00) { |
3939 |
wc->vpm400checkstatus = (status & 0xff00) >> 8; |
3940 |
set_bit(T4_CHECK_VPM, &wc->checkflag); |
3941 |
} |
3942 |
} |
3943 |
|
3944 |
spin_lock(&wc->reglock); |
3945 |
|
3946 |
if (unlikely(test_bit(T4_CHECK_TIMING, &wc->checkflag))) { |
3947 |
__t4_set_timing_source_auto(wc); |
3948 |
} |
3949 |
|
3950 |
spin_unlock(&wc->reglock); |
3951 |
|
3952 |
out: |
3953 |
if (unlikely(test_bit(T4_CHANGE_LATENCY, &wc->checkflag) || test_bit(T4_CHECK_VPM, &wc->checkflag))) |
3954 |
tasklet_schedule(&wc->t4_tlet); |
3955 |
|
3956 |
#ifndef ENABLE_WORKQUEUES |
3957 |
__t4_pci_out(wc, WC_INTR, 0); |
3958 |
#endif |
3959 |
|
3960 |
return IRQ_RETVAL(1); |
3961 |
} |
3962 |
|
3963 |
#ifdef SUPPORT_GEN1 |
3964 |
static int t4_reset_dma(struct t4 *wc) |
3965 |
{ |
3966 |
/* Turn off DMA and such */ |
3967 |
wc->dmactrl = 0x0; |
3968 |
t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
3969 |
t4_pci_out(wc, WC_COUNT, 0); |
3970 |
t4_pci_out(wc, WC_RDADDR, 0); |
3971 |
t4_pci_out(wc, WC_WRADDR, 0); |
3972 |
t4_pci_out(wc, WC_INTR, 0); |
3973 |
/* Turn it all back on */ |
3974 |
t4_pci_out(wc, WC_RDADDR, wc->readdma); |
3975 |
t4_pci_out(wc, WC_WRADDR, wc->writedma); |
3976 |
t4_pci_out(wc, WC_COUNT, ((DAHDI_MAX_CHUNKSIZE * 2 * 32 - 1) << 18) | ((DAHDI_MAX_CHUNKSIZE * 2 * 32 - 1) << 2)); |
3977 |
t4_pci_out(wc, WC_INTR, 0); |
3978 |
#ifdef VPM_SUPPORT |
3979 |
wc->dmactrl = 0xc0000000 | (1 << 29) | wc->vpm; |
3980 |
#else |
3981 |
wc->dmactrl = 0xc0000000 | (1 << 29); |
3982 |
#endif |
3983 |
if (noburst) |
3984 |
wc->dmactrl |= (1 << 26); |
3985 |
t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
3986 |
return 0; |
3987 |
} |
3988 |
#endif |
3989 |
|
3990 |
#ifdef VPM_SUPPORT |
3991 |
static void t4_vpm_set_dtmf_threshold(struct t4 *wc, unsigned int threshold) |
3992 |
{ |
3993 |
unsigned int x; |
3994 |
|
3995 |
for (x = 0; x < 8; x++) { |
3996 |
t4_vpm_out(wc, x, 0xC4, (threshold >> 8) & 0xFF); |
3997 |
t4_vpm_out(wc, x, 0xC5, (threshold & 0xFF)); |
3998 |
} |
3999 |
dev_info(&wc->dev->dev, "VPM: DTMF threshold set to %d\n", threshold); |
4000 |
} |
4001 |
|
4002 |
static unsigned int t4_vpm_mask(int chip) |
4003 |
{ |
4004 |
unsigned int mask=0; |
4005 |
switch(vpmspans) { |
4006 |
case 4: |
4007 |
mask = 0x55555555 << (chip >> 2); |
4008 |
break; |
4009 |
case 2: |
4010 |
mask = 0x11111111 << (chip >> 1); |
4011 |
break; |
4012 |
case 1: |
4013 |
mask = 0x01010101 << chip; |
4014 |
break; |
4015 |
} |
4016 |
return mask; |
4017 |
} |
4018 |
|
4019 |
static int t4_vpm_spanno(int chip) |
4020 |
{ |
4021 |
int spanno = 0; |
4022 |
switch(vpmspans) { |
4023 |
case 4: |
4024 |
spanno = chip & 0x3; |
4025 |
break; |
4026 |
case 2: |
4027 |
spanno = chip & 0x1; |
4028 |
break; |
4029 |
/* Case 1 is implicit */ |
4030 |
} |
4031 |
return spanno; |
4032 |
} |
4033 |
|
4034 |
static int t4_vpm_echotail(void) |
4035 |
{ |
4036 |
int echotail = 0x01ff; |
4037 |
switch(vpmspans) { |
4038 |
case 4: |
4039 |
echotail = 0x007f; |
4040 |
break; |
4041 |
case 2: |
4042 |
echotail = 0x00ff; |
4043 |
break; |
4044 |
/* Case 1 is implicit */ |
4045 |
} |
4046 |
return echotail; |
4047 |
} |
4048 |
|
4049 |
static void t4_vpm450_init(struct t4 *wc) |
4050 |
{ |
4051 |
unsigned int check1, check2; |
4052 |
int laws[1] = { 0, }; |
4053 |
int x; |
4054 |
unsigned int vpm_capacity; |
4055 |
struct firmware embedded_firmware; |
4056 |
const struct firmware *firmware = &embedded_firmware; |
4057 |
#if !defined(HOTPLUG_FIRMWARE) |
4058 |
extern void _binary_dahdi_fw_oct6114_032_bin_size; |
4059 |
extern void _binary_dahdi_fw_oct6114_064_bin_size; |
4060 |
extern void _binary_dahdi_fw_oct6114_128_bin_size; |
4061 |
extern u8 _binary_dahdi_fw_oct6114_032_bin_start[]; |
4062 |
extern u8 _binary_dahdi_fw_oct6114_064_bin_start[]; |
4063 |
extern u8 _binary_dahdi_fw_oct6114_128_bin_start[]; |
4064 |
#else |
4065 |
static const char oct032_firmware[] = "dahdi-fw-oct6114-032.bin"; |
4066 |
static const char oct064_firmware[] = "dahdi-fw-oct6114-064.bin"; |
4067 |
static const char oct128_firmware[] = "dahdi-fw-oct6114-128.bin"; |
4068 |
#endif |
4069 |
|
4070 |
if (!vpmsupport) { |
4071 |
dev_info(&wc->dev->dev, "VPM450: Support Disabled\n"); |
4072 |
return; |
4073 |
} |
4074 |
|
4075 |
/* Turn on GPIO/DATA mux if supported */ |
4076 |
t4_gpio_setdir(wc, (1 << 24), (1 << 24)); |
4077 |
__t4_raw_oct_out(wc, 0x000a, 0x5678); |
4078 |
__t4_raw_oct_out(wc, 0x0004, 0x1234); |
4079 |
check1 = __t4_raw_oct_in(wc, 0x0004); |
4080 |
check2 = __t4_raw_oct_in(wc, 0x000a); |
4081 |
if (debug) |
4082 |
dev_notice(&wc->dev->dev, "OCT Result: %04x/%04x\n", |
4083 |
__t4_raw_oct_in(wc, 0x0004), |
4084 |
__t4_raw_oct_in(wc, 0x000a)); |
4085 |
if (__t4_raw_oct_in(wc, 0x0004) != 0x1234) { |
4086 |
dev_notice(&wc->dev->dev, "VPM450: Not Present\n"); |
4087 |
return; |
4088 |
} |
4089 |
|
4090 |
/* Setup alaw vs ulaw rules */ |
4091 |
for (x = 0;x < wc->numspans; x++) { |
4092 |
if (wc->tspans[x]->span.channels > 24) |
4093 |
laws[x] = 1; |
4094 |
} |
4095 |
|
4096 |
switch ((vpm_capacity = get_vpm450m_capacity(wc))) { |
4097 |
case 32: |
4098 |
#if defined(HOTPLUG_FIRMWARE) |
4099 |
if ((request_firmware(&firmware, oct032_firmware, &wc->dev->dev) != 0) || |
4100 |
!firmware) { |
4101 |
dev_notice(&wc->dev->dev, "VPM450: firmware %s not " |
4102 |
"available from userspace\n", oct032_firmware); |
4103 |
return; |
4104 |
} |
4105 |
#else |
4106 |
embedded_firmware.data = _binary_dahdi_fw_oct6114_032_bin_start; |
4107 |
/* Yes... this is weird. objcopy gives us a symbol containing |
4108 |
the size of the firmware, not a pointer a variable containing |
4109 |
the size. The only way we can get the value of the symbol |
4110 |
is to take its address, so we define it as a pointer and |
4111 |
then cast that value to the proper type. |
4112 |
*/ |
4113 |
embedded_firmware.size = (size_t) &_binary_dahdi_fw_oct6114_032_bin_size; |
4114 |
#endif |
4115 |
break; |
4116 |
case 64: |
4117 |
#if defined(HOTPLUG_FIRMWARE) |
4118 |
if ((request_firmware(&firmware, oct064_firmware, &wc->dev->dev) != 0) || |
4119 |
!firmware) { |
4120 |
dev_notice(&wc->dev->dev, "VPM450: firmware %s not " |
4121 |
"available from userspace\n", oct064_firmware); |
4122 |
return; |
4123 |
} |
4124 |
#else |
4125 |
embedded_firmware.data = _binary_dahdi_fw_oct6114_064_bin_start; |
4126 |
/* Yes... this is weird. objcopy gives us a symbol containing |
4127 |
the size of the firmware, not a pointer a variable containing |
4128 |
the size. The only way we can get the value of the symbol |
4129 |
is to take its address, so we define it as a pointer and |
4130 |
then cast that value to the proper type. |
4131 |
*/ |
4132 |
embedded_firmware.size = (size_t) &_binary_dahdi_fw_oct6114_064_bin_size; |
4133 |
#endif |
4134 |
break; |
4135 |
case 128: |
4136 |
#if defined(HOTPLUG_FIRMWARE) |
4137 |
if ((request_firmware(&firmware, oct128_firmware, &wc->dev->dev) != 0) || |
4138 |
!firmware) { |
4139 |
dev_notice(&wc->dev->dev, "VPM450: firmware %s not " |
4140 |
"available from userspace\n", oct128_firmware); |
4141 |
return; |
4142 |
} |
4143 |
#else |
4144 |
embedded_firmware.data = _binary_dahdi_fw_oct6114_128_bin_start; |
4145 |
/* Yes... this is weird. objcopy gives us a symbol containing |
4146 |
the size of the firmware, not a pointer a variable containing |
4147 |
the size. The only way we can get the value of the symbol |
4148 |
is to take its address, so we define it as a pointer and |
4149 |
then cast that value to the proper type. |
4150 |
*/ |
4151 |
embedded_firmware.size = (size_t) &_binary_dahdi_fw_oct6114_128_bin_size; |
4152 |
#endif |
4153 |
break; |
4154 |
default: |
4155 |
dev_notice(&wc->dev->dev, "Unsupported channel capacity found " |
4156 |
"on VPM module (%d).\n", vpm_capacity); |
4157 |
return; |
4158 |
} |
4159 |
|
4160 |
if (!(wc->vpm450m = init_vpm450m(wc, laws, wc->numspans, firmware))) { |
4161 |
dev_notice(&wc->dev->dev, "VPM450: Failed to initialize\n"); |
4162 |
if (firmware != &embedded_firmware) |
4163 |
release_firmware(firmware); |
4164 |
return; |
4165 |
} |
4166 |
|
4167 |
if (firmware != &embedded_firmware) |
4168 |
release_firmware(firmware); |
4169 |
|
4170 |
if (vpmdtmfsupport == -1) { |
4171 |
dev_notice(&wc->dev->dev, "VPM450: hardware DTMF disabled.\n"); |
4172 |
vpmdtmfsupport = 0; |
4173 |
} |
4174 |
|
4175 |
wc->vpm = T4_VPM_PRESENT; |
4176 |
dev_info(&wc->dev->dev, "VPM450: Present and operational servicing %d " |
4177 |
"span(s)\n", wc->numspans); |
4178 |
|
4179 |
} |
4180 |
|
4181 |
static void t4_vpm400_init(struct t4 *wc) |
4182 |
{ |
4183 |
unsigned char reg; |
4184 |
unsigned int mask; |
4185 |
unsigned int ver; |
4186 |
unsigned int i, x, y, gen2vpm=0; |
4187 |
|
4188 |
if (!vpmsupport) { |
4189 |
dev_info(&wc->dev->dev, "VPM400: Support Disabled\n"); |
4190 |
return; |
4191 |
} |
4192 |
|
4193 |
switch(vpmspans) { |
4194 |
case 4: |
4195 |
case 2: |
4196 |
case 1: |
4197 |
break; |
4198 |
default: |
4199 |
dev_notice(&wc->dev->dev, "VPM400: %d is not a valid vpmspans " |
4200 |
"value, using 4\n", vpmspans); |
4201 |
vpmspans = 1; |
4202 |
} |
4203 |
|
4204 |
for (x=0;x<8;x++) { |
4205 |
int spanno = t4_vpm_spanno(x); |
4206 |
struct t4_span *ts = wc->tspans[spanno]; |
4207 |
int echotail = t4_vpm_echotail(); |
4208 |
|
4209 |
ver = t4_vpm_in(wc, x, 0x1a0); /* revision */ |
4210 |
if ((ver != 0x26) && (ver != 0x33)) { |
4211 |
if (x) |
4212 |
dev_notice(&wc->dev->dev, |
4213 |
"VPM400: Inoperable\n"); |
4214 |
return; |
4215 |
} |
4216 |
if (ver == 0x33) { |
4217 |
if (x && !gen2vpm) { |
4218 |
dev_notice(&wc->dev->dev, |
4219 |
"VPM400: Inconsistent\n"); |
4220 |
return; |
4221 |
} |
4222 |
ts->spanflags |= FLAG_VPM2GEN; |
4223 |
gen2vpm++; |
4224 |
} else if (gen2vpm) { |
4225 |
dev_notice(&wc->dev->dev, |
4226 |
"VPM400: Inconsistent\n"); |
4227 |
return; |
4228 |
} |
4229 |
|
4230 |
|
4231 |
/* Setup GPIO's */ |
4232 |
for (y=0;y<4;y++) { |
4233 |
t4_vpm_out(wc, x, 0x1a8 + y, 0x00); /* GPIO out */ |
4234 |
t4_vpm_out(wc, x, 0x1ac + y, 0x00); /* GPIO dir */ |
4235 |
t4_vpm_out(wc, x, 0x1b0 + y, 0x00); /* GPIO sel */ |
4236 |
} |
4237 |
|
4238 |
/* Setup TDM path - sets fsync and tdm_clk as inputs */ |
4239 |
reg = t4_vpm_in(wc, x, 0x1a3); /* misc_con */ |
4240 |
t4_vpm_out(wc, x, 0x1a3, reg & ~2); |
4241 |
|
4242 |
/* Setup timeslots */ |
4243 |
t4_vpm_out(wc, x, 0x02f, 0x20 | (spanno << 3)); |
4244 |
|
4245 |
/* Setup Echo length (128 taps) */ |
4246 |
t4_vpm_out(wc, x, 0x022, (echotail >> 8)); |
4247 |
t4_vpm_out(wc, x, 0x023, (echotail & 0xff)); |
4248 |
|
4249 |
/* Setup the tdm channel masks for all chips*/ |
4250 |
mask = t4_vpm_mask(x); |
4251 |
for (i = 0; i < 4; i++) |
4252 |
t4_vpm_out(wc, x, 0x30 + i, (mask >> (i << 3)) & 0xff); |
4253 |
|
4254 |
/* Setup convergence rate */ |
4255 |
reg = t4_vpm_in(wc,x,0x20); |
4256 |
reg &= 0xE0; |
4257 |
if (ts->spantype == TYPE_E1) { |
4258 |
if (x < vpmspans) |
4259 |
dev_info(&wc->dev->dev, "VPM400: Span %d " |
4260 |
"A-law mode\n", spanno); |
4261 |
reg |= 0x01; |
4262 |
} else { |
4263 |
if (x < vpmspans) |
4264 |
dev_info(&wc->dev->dev, "VPM400: Span %d " |
4265 |
"U-law mode\n", spanno); |
4266 |
reg &= ~0x01; |
4267 |
} |
4268 |
t4_vpm_out(wc,x,0x20,(reg | 0x20)); |
4269 |
|
4270 |
/* Initialize echo cans */ |
4271 |
for (i = 0 ; i < MAX_TDM_CHAN; i++) { |
4272 |
if (mask & (0x00000001 << i)) |
4273 |
t4_vpm_out(wc,x,i,0x00); |
4274 |
} |
4275 |
|
4276 |
wait_a_little(); |
4277 |
|
4278 |
/* Put in bypass mode */ |
4279 |
for (i = 0 ; i < MAX_TDM_CHAN ; i++) { |
4280 |
if (mask & (0x00000001 << i)) { |
4281 |
t4_vpm_out(wc,x,i,0x01); |
4282 |
} |
4283 |
} |
4284 |
|
4285 |
/* Enable bypass */ |
4286 |
for (i = 0 ; i < MAX_TDM_CHAN ; i++) { |
4287 |
if (mask & (0x00000001 << i)) |
4288 |
t4_vpm_out(wc,x,0x78 + i,0x01); |
4289 |
} |
4290 |
|
4291 |
/* set DTMF detection threshold */ |
4292 |
t4_vpm_set_dtmf_threshold(wc, dtmfthreshold); |
4293 |
|
4294 |
/* Enable DTMF detectors (always DTMF detect all spans) */ |
4295 |
for (i = 0; i < MAX_DTMF_DET; i++) { |
4296 |
t4_vpm_out(wc, x, 0x98 + i, 0x40 | (i * 2) | ((x < 4) ? 0 : 1)); |
4297 |
} |
4298 |
for (i = 0x34; i < 0x38; i++) |
4299 |
t4_vpm_out(wc, x, i, 0x00); |
4300 |
for (i = 0x3C; i < 0x40; i++) |
4301 |
t4_vpm_out(wc, x, i, 0x00); |
4302 |
|
4303 |
for (i = 0x48; i < 0x4B; i++) |
4304 |
t4_vpm_out(wc, x, i, 0x00); |
4305 |
for (i = 0x50; i < 0x53; i++) |
4306 |
t4_vpm_out(wc, x, i, 0x00); |
4307 |
for (i = 0xB8; i < 0xBE; i++) |
4308 |
t4_vpm_out(wc, x, i, 0xFF); |
4309 |
if (gen2vpm) { |
4310 |
for (i = 0xBE; i < 0xC0; i++) |
4311 |
t4_vpm_out(wc, x, i, 0xFF); |
4312 |
} else { |
4313 |
for (i = 0xBE; i < 0xC0; i++) |
4314 |
t4_vpm_out(wc, x, i, 0x00); |
4315 |
} |
4316 |
for (i = 0xC0; i < 0xC4; i++) |
4317 |
t4_vpm_out(wc, x, i, (x < 4) ? 0x55 : 0xAA); |
4318 |
|
4319 |
} |
4320 |
if (vpmdtmfsupport == -1) { |
4321 |
dev_info(&wc->dev->dev, "VPM400: hardware DTMF enabled.\n"); |
4322 |
vpmdtmfsupport = 0; |
4323 |
} |
4324 |
dev_info(&wc->dev->dev, "VPM400%s: Present and operational servicing " |
4325 |
"%d span(s)\n", (gen2vpm ? " (2nd Gen)" : ""), wc->numspans); |
4326 |
wc->vpm = T4_VPM_PRESENT; |
4327 |
} |
4328 |
|
4329 |
#endif |
4330 |
|
4331 |
static void t4_tsi_reset(struct t4 *wc) |
4332 |
{ |
4333 |
int x; |
4334 |
for (x=0;x<128;x++) { |
4335 |
wc->dmactrl &= ~0x00007fff; |
4336 |
wc->dmactrl |= (0x00004000 | (x << 7)); |
4337 |
t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
4338 |
} |
4339 |
wc->dmactrl &= ~0x00007fff; |
4340 |
t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
4341 |
} |
4342 |
|
4343 |
/* Note that channels here start from 1 */ |
4344 |
static void t4_tsi_assign(struct t4 *wc, int fromspan, int fromchan, int tospan, int tochan) |
4345 |
{ |
4346 |
unsigned long flags; |
4347 |
int fromts, tots; |
4348 |
|
4349 |
fromts = (fromspan << 5) |(fromchan); |
4350 |
tots = (tospan << 5) | (tochan); |
4351 |
|
4352 |
if (!wc->t1e1) { |
4353 |
fromts += 4; |
4354 |
tots += 4; |
4355 |
} |
4356 |
spin_lock_irqsave(&wc->reglock, flags); |
4357 |
wc->dmactrl &= ~0x00007fff; |
4358 |
wc->dmactrl |= (0x00004000 | (tots << 7) | (fromts)); |
4359 |
__t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
4360 |
wc->dmactrl &= ~0x00007fff; |
4361 |
__t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
4362 |
spin_unlock_irqrestore(&wc->reglock, flags); |
4363 |
} |
4364 |
|
4365 |
static void t4_tsi_unassign(struct t4 *wc, int tospan, int tochan) |
4366 |
{ |
4367 |
unsigned long flags; |
4368 |
int tots; |
4369 |
|
4370 |
tots = (tospan << 5) | (tochan); |
4371 |
|
4372 |
if (!wc->t1e1) |
4373 |
tots += 4; |
4374 |
spin_lock_irqsave(&wc->reglock, flags); |
4375 |
wc->dmactrl &= ~0x00007fff; |
4376 |
wc->dmactrl |= (0x00004000 | (tots << 7)); |
4377 |
__t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
4378 |
if (debug & DEBUG_TSI) |
4379 |
dev_notice(&wc->dev->dev, "Sending '%08x\n", wc->dmactrl); |
4380 |
wc->dmactrl &= ~0x00007fff; |
4381 |
__t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
4382 |
spin_unlock_irqrestore(&wc->reglock, flags); |
4383 |
} |
4384 |
#ifdef CONFIG_EXTENDED_RESET |
4385 |
static void t4_extended_reset(struct t4 *wc) |
4386 |
{ |
4387 |
unsigned int oldreg = t4_pci_in(wc, 0x4); |
4388 |
|
4389 |
udelay(1000); |
4390 |
|
4391 |
t4_pci_out(wc, 0x4, 0x42000000); |
4392 |
t4_pci_out(wc, 0xa, 0x42000000); |
4393 |
t4_pci_out(wc, 0xa, 0x00080000); |
4394 |
t4_pci_out(wc, 0xa, 0x00080000); |
4395 |
t4_pci_out(wc, 0xa, 0x00080000); |
4396 |
t4_pci_out(wc, 0xa, 0x00180000); |
4397 |
t4_pci_out(wc, 0xa, 0x00080000); |
4398 |
t4_pci_out(wc, 0xa, 0x00180000); |
4399 |
t4_pci_out(wc, 0xa, 0x00080000); |
4400 |
t4_pci_out(wc, 0xa, 0x00180000); |
4401 |
t4_pci_out(wc, 0xa, 0x00080000); |
4402 |
t4_pci_out(wc, 0xa, 0x00180000); |
4403 |
t4_pci_out(wc, 0xa, 0x00080000); |
4404 |
t4_pci_out(wc, 0xa, 0x00180000); |
4405 |
t4_pci_out(wc, 0xa, 0x00080000); |
4406 |
t4_pci_out(wc, 0xa, 0x00180000); |
4407 |
t4_pci_out(wc, 0x4, oldreg); |
4408 |
|
4409 |
udelay(1000); |
4410 |
} |
4411 |
#endif |
4412 |
|
4413 |
static int t4_hardware_init_1(struct t4 *wc, unsigned int cardflags) |
4414 |
{ |
4415 |
unsigned int version; |
4416 |
|
4417 |
version = t4_pci_in(wc, WC_VERSION); |
4418 |
dev_info(&wc->dev->dev, "Firmware Version: %08x\n", version); |
4419 |
dev_info(&wc->dev->dev, "Burst Mode: %s\n", |
4420 |
(!(cardflags & FLAG_BURST) && noburst) ? "Off" : "On"); |
4421 |
#ifdef ENABLE_WORKQUEUES |
4422 |
dev_info(&wc->dev->dev, "Work Queues: Enabled\n"); |
4423 |
#endif |
4424 |
|
4425 |
#ifdef CONFIG_EXTENDED_RESET |
4426 |
t4_extended_reset(wc); |
4427 |
#endif |
4428 |
|
4429 |
/* Make sure DMA engine is not running and interrupts are acknowledged */ |
4430 |
wc->dmactrl = 0x0; |
4431 |
t4_pci_out(wc, WC_DMACTRL, wc->dmactrl); |
4432 |
/* Reset Framer and friends */ |
4433 |
t4_pci_out(wc, WC_LEDS, 0x00000000); |
4434 |
|
4435 |
/* Set DMA addresses */ |
4436 |
t4_pci_out(wc, WC_RDADDR, wc->readdma); |
4437 |
t4_pci_out(wc, WC_WRADDR, wc->writedma); |
4438 |
|
4439 |
/* Setup counters, interrupt flags (ignored in Gen2) */ |
4440 |
if (cardflags & FLAG_2NDGEN) { |
4441 |
t4_tsi_reset(wc); |
4442 |
} else { |
4443 |
t4_pci_out(wc, WC_COUNT, ((DAHDI_MAX_CHUNKSIZE * 2 * 32 - 1) << 18) | ((DAHDI_MAX_CHUNKSIZE * 2 * 32 - 1) << 2)); |
4444 |
} |
4445 |
|
4446 |
/* Reset pending interrupts */ |
4447 |
t4_pci_out(wc, WC_INTR, 0x00000000); |
4448 |
|
4449 |
/* Read T1/E1 status */ |
4450 |
if (t1e1override > -1) |
4451 |
wc->t1e1 = t1e1override; |
4452 |
else |
4453 |
wc->t1e1 = ((t4_pci_in(wc, WC_LEDS)) & 0x0f00) >> 8; |
4454 |
wc->order = ((t4_pci_in(wc, WC_LEDS)) & 0xf0000000) >> 28; |
4455 |
order_index[wc->order]++; |
4456 |
return 0; |
4457 |
} |
4458 |
|
4459 |
static int t4_hardware_init_2(struct t4 *wc) |
4460 |
{ |
4461 |
int x; |
4462 |
unsigned int regval; |
4463 |
|
4464 |
if (t4_pci_in(wc, WC_VERSION) >= 0xc01a0165) { |
4465 |
wc->tspans[0]->spanflags |= FLAG_OCTOPT; |
4466 |
dev_info(&wc->dev->dev, "Octasic Optimizations: Enabled\n"); |
4467 |
} |
4468 |
/* Setup LEDS, take out of reset */ |
4469 |
t4_pci_out(wc, WC_LEDS, 0x000000ff); |
4470 |
t4_activate(wc); |
4471 |
|
4472 |
/* |
4473 |
* In order to find out the QFALC framer version, we have to temporarily term off compat |
4474 |
* mode and take a peak at VSTR. We turn compat back on when we are done. |
4475 |
*/ |
4476 |
if (t4_framer_in(wc, 0, 0x4a) != 0x05) |
4477 |
dev_info(&wc->dev->dev, "WARNING: FALC framer not intialized " |
4478 |
"in compatibility mode.\n"); |
4479 |
regval = t4_framer_in(wc, 0 ,0xd6); |
4480 |
regval |= (1 << 5); /* set COMP_DIS*/ |
4481 |
t4_framer_out(wc, 0, 0xd6, regval); |
4482 |
regval = t4_framer_in(wc, 0, 0x4a); |
4483 |
if (regval == 0x05) |
4484 |
dev_info(&wc->dev->dev, "FALC Framer Version: 2.1 or " |
4485 |
"earlier\n"); |
4486 |
else if (regval == 0x20) { |
4487 |
dev_info(&wc->dev->dev, "FALC Framer Version: 3.1\n"); |
4488 |
wc->falc31 = 1; |
4489 |
} else |
4490 |
dev_info(&wc->dev->dev, "FALC Framer Version: Unknown " |
4491 |
"(VSTR = 0x%02x)\n", regval); |
4492 |
regval = t4_framer_in(wc, 0 ,0xd6); |
4493 |
regval &= ~(1 << 5); /* clear COMP_DIS*/ |
4494 |
t4_framer_out(wc, 0, 0xd6, regval); |
4495 |
|
4496 |
t4_framer_out(wc, 0, 0x4a, 0xaa); |
4497 |
dev_info(&wc->dev->dev, "Board ID: %02x\n", wc->order); |
4498 |
|
4499 |
for (x=0;x< 11;x++) |
4500 |
dev_info(&wc->dev->dev, "Reg %d: 0x%08x\n", x, |
4501 |
t4_pci_in(wc, x)); |
4502 |
return 0; |
4503 |
} |
4504 |
|
4505 |
static int __devinit t4_launch(struct t4 *wc) |
4506 |
{ |
4507 |
int x; |
4508 |
unsigned long flags; |
4509 |
if (test_bit(DAHDI_FLAGBIT_REGISTERED, &wc->tspans[0]->span.flags)) |
4510 |
return 0; |
4511 |
dev_info(&wc->dev->dev, "opvxd115: Launching card: %d\n", |
4512 |
wc->order); |
4513 |
|
4514 |
/* Setup serial parameters and system interface */ |
4515 |
for (x=0;x<PORTS_PER_FRAMER;x++) |
4516 |
t4_serial_setup(wc, x); |
4517 |
|
4518 |
for (x = 0; x < wc->numspans; ++x) { |
4519 |
list_add_tail(&wc->tspans[x]->span.device_node, |
4520 |
&wc->ddev->spans); |
4521 |
} |
4522 |
if (dahdi_register_device(wc->ddev, &wc->dev->dev)) { |
4523 |
dev_err(&wc->dev->dev, "Unable to register span %s\n", |
4524 |
wc->tspans[0]->span.name); |
4525 |
return -1; |
4526 |
} |
4527 |
set_bit(T4_CHECK_TIMING, &wc->checkflag); |
4528 |
spin_lock_irqsave(&wc->reglock, flags); |
4529 |
__t4_set_sclk_src(wc, WC_SELF, 0, 0); |
4530 |
spin_unlock_irqrestore(&wc->reglock, flags); |
4531 |
tasklet_init(&wc->t4_tlet, t4_isr_bh, (unsigned long)wc); |
4532 |
return 0; |
4533 |
} |
4534 |
|
4535 |
static void free_wc(struct t4 *wc) |
4536 |
{ |
4537 |
unsigned int x, y; |
4538 |
|
4539 |
for (x = 0; x < sizeof(wc->tspans)/sizeof(wc->tspans[0]); x++) { |
4540 |
if (!wc->tspans[x]) { |
4541 |
continue; |
4542 |
} |
4543 |
|
4544 |
for (y = 0; y < sizeof(wc->tspans[x]->chans)/sizeof(wc->tspans[x]->chans[0]); y++) { |
4545 |
if (wc->tspans[x]->chans[y]) { |
4546 |
kfree(wc->tspans[x]->chans[y]); |
4547 |
} |
4548 |
if (wc->tspans[x]->ec[y]) |
4549 |
kfree(wc->tspans[x]->ec[y]); |
4550 |
} |
4551 |
kfree(wc->tspans[x]); |
4552 |
} |
4553 |
kfree(wc); |
4554 |
} |
4555 |
|
4556 |
static int __devinit t4_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
4557 |
{ |
4558 |
struct t4 *wc; |
4559 |
struct devtype *dt; |
4560 |
unsigned int x, f; |
4561 |
int init_latency; |
4562 |
|
4563 |
if (pci_enable_device(pdev)) { |
4564 |
return -EIO; |
4565 |
} |
4566 |
|
4567 |
if (!(wc = kmalloc(sizeof(*wc), GFP_KERNEL))) { |
4568 |
return -ENOMEM; |
4569 |
} |
4570 |
|
4571 |
memset(wc, 0x0, sizeof(*wc)); |
4572 |
spin_lock_init(&wc->reglock); |
4573 |
dt = (struct devtype *) (ent->driver_data); |
4574 |
|
4575 |
wc->flags = dt->flags; |
4576 |
|
4577 |
wc->numspans = 1; |
4578 |
|
4579 |
wc->variety = dt->desc; |
4580 |
|
4581 |
wc->memaddr = pci_resource_start(pdev, 0); |
4582 |
wc->memlen = pci_resource_len(pdev, 0); |
4583 |
wc->membase = ioremap(wc->memaddr, wc->memlen); |
4584 |
/* This rids of the Double missed interrupt message after loading */ |
4585 |
wc->last0 = 1; |
4586 |
#if 0 |
4587 |
if (!request_mem_region(wc->memaddr, wc->memlen, wc->variety)) |
4588 |
dev_info(&wc->dev->dev, "opvxd115: Unable to request memory " |
4589 |
"region :(, using anyway...\n"); |
4590 |
#endif |
4591 |
if (pci_request_regions(pdev, wc->variety)) |
4592 |
dev_info(&pdev->dev, "opvxd115: Unable to request regions\n"); |
4593 |
|
4594 |
dev_info(&pdev->dev, "Found opvxd115 at base address %08lx, remapped " |
4595 |
"to %p\n", wc->memaddr, wc->membase); |
4596 |
|
4597 |
wc->dev = pdev; |
4598 |
|
4599 |
/* Enable bus mastering */ |
4600 |
pci_set_master(pdev); |
4601 |
|
4602 |
/* Keep track of which device we are */ |
4603 |
pci_set_drvdata(pdev, wc); |
4604 |
|
4605 |
if (wc->flags & FLAG_5THGEN) { |
4606 |
if ((ms_per_irq > 1) && (latency <= ((ms_per_irq) << 1))) { |
4607 |
init_latency = ms_per_irq << 1; |
4608 |
} else { |
4609 |
if (latency > 2) |
4610 |
init_latency = latency; |
4611 |
else |
4612 |
init_latency = 2; |
4613 |
} |
4614 |
dev_info(&wc->dev->dev, "5th gen card with initial latency of " |
4615 |
"%d and %d ms per IRQ\n", init_latency, ms_per_irq); |
4616 |
} else { |
4617 |
if (wc->flags & FLAG_2NDGEN) |
4618 |
init_latency = 1; |
4619 |
else |
4620 |
init_latency = 2; |
4621 |
} |
4622 |
|
4623 |
if (max_latency < init_latency) { |
4624 |
printk(KERN_INFO "maxlatency must be set to something greater than %d ms, increasing it to %d\n", init_latency, init_latency); |
4625 |
max_latency = init_latency; |
4626 |
} |
4627 |
|
4628 |
if (t4_allocate_buffers(wc, init_latency, NULL, NULL)) { |
4629 |
return -ENOMEM; |
4630 |
} |
4631 |
|
4632 |
/* Initialize hardware */ |
4633 |
t4_hardware_init_1(wc, wc->flags); |
4634 |
|
4635 |
for(x = 0; x < MAX_T4_CARDS; x++) { |
4636 |
if (!cards[x]) |
4637 |
break; |
4638 |
} |
4639 |
|
4640 |
if (x >= MAX_T4_CARDS) { |
4641 |
dev_notice(&wc->dev->dev, "No cards[] slot available!!\n"); |
4642 |
kfree(wc); |
4643 |
return -ENOMEM; |
4644 |
} |
4645 |
|
4646 |
wc->num = x; |
4647 |
cards[x] = wc; |
4648 |
|
4649 |
#ifdef ENABLE_WORKQUEUES |
4650 |
if (wc->flags & FLAG_2NDGEN) { |
4651 |
char tmp[20]; |
4652 |
|
4653 |
sprintf(tmp, "opvxd115"); |
4654 |
wc->workq = create_workqueue(tmp); |
4655 |
} |
4656 |
#endif |
4657 |
|
4658 |
/* Allocate pieces we need here */ |
4659 |
for (x = 0; x < PORTS_PER_FRAMER; x++) { |
4660 |
if (!(wc->tspans[x] = kmalloc(sizeof(*wc->tspans[x]), GFP_KERNEL))) { |
4661 |
free_wc(wc); |
4662 |
return -ENOMEM; |
4663 |
} |
4664 |
|
4665 |
memset(wc->tspans[x], 0, sizeof(*wc->tspans[x])); |
4666 |
|
4667 |
if (wc->t1e1 & (1 << x)) { |
4668 |
wc->tspans[x]->spantype = TYPE_E1; |
4669 |
} else { |
4670 |
if (j1mode) |
4671 |
wc->tspans[x]->spantype = TYPE_J1; |
4672 |
else |
4673 |
wc->tspans[x]->spantype = TYPE_T1; |
4674 |
} |
4675 |
|
4676 |
for (f = 0; f < (wc->tspans[x]->spantype == TYPE_E1 ? 31 : 24); f++) { |
4677 |
if (!(wc->tspans[x]->chans[f] = kmalloc(sizeof(*wc->tspans[x]->chans[f]), GFP_KERNEL))) { |
4678 |
free_wc(wc); |
4679 |
return -ENOMEM; |
4680 |
} |
4681 |
memset(wc->tspans[x]->chans[f], 0, sizeof(*wc->tspans[x]->chans[f])); |
4682 |
if (!(wc->tspans[x]->ec[f] = kmalloc(sizeof(*wc->tspans[x]->ec[f]), GFP_KERNEL))) { |
4683 |
free_wc(wc); |
4684 |
return -ENOMEM; |
4685 |
} |
4686 |
memset(wc->tspans[x]->ec[f], 0, sizeof(*wc->tspans[x]->ec[f])); |
4687 |
} |
4688 |
|
4689 |
#ifdef ENABLE_WORKQUEUES |
4690 |
INIT_WORK(&wc->tspans[x]->swork, workq_handlespan, wc->tspans[x]); |
4691 |
#endif |
4692 |
wc->tspans[x]->spanflags |= wc->flags; |
4693 |
} |
4694 |
|
4695 |
/* Continue hardware intiialization */ |
4696 |
t4_hardware_init_2(wc); |
4697 |
|
4698 |
#ifdef SUPPORT_GEN1 |
4699 |
if (request_irq(pdev->irq, (wc->flags & FLAG_2NDGEN) ? t4_interrupt_gen2 :t4_interrupt, DAHDI_IRQ_SHARED_DISABLED, "opvxd115", wc)) |
4700 |
#else |
4701 |
if (!(wc->tspans[0]->spanflags & FLAG_2NDGEN)) { |
4702 |
dev_notice(&wc->dev->dev, "This driver does not " |
4703 |
"support 1st gen modules\n"); |
4704 |
free_wc(wc); |
4705 |
return -ENODEV; |
4706 |
} |
4707 |
if (request_irq(pdev->irq, t4_interrupt_gen2, DAHDI_IRQ_SHARED_DISABLED, "opvxd115", wc)) |
4708 |
#endif |
4709 |
{ |
4710 |
dev_notice(&wc->dev->dev, "opvxd115: Unable to request IRQ %d\n", |
4711 |
pdev->irq); |
4712 |
free_wc(wc); |
4713 |
return -EIO; |
4714 |
} |
4715 |
|
4716 |
init_spans(wc); |
4717 |
/* get the current number of probed cards and run a slice of a tail |
4718 |
* insertion sort */ |
4719 |
for (x = 0; x < MAX_T4_CARDS; x++) { |
4720 |
if (!cards[x+1]) |
4721 |
break; |
4722 |
} |
4723 |
for ( ; x > 0; x--) { |
4724 |
if (cards[x]->order < cards[x-1]->order) { |
4725 |
struct t4 *tmp = cards[x]; |
4726 |
cards[x] = cards[x-1]; |
4727 |
cards[x-1] = tmp; |
4728 |
} else { |
4729 |
/* if we're not moving it, we won't move any more |
4730 |
* since all cards are sorted on addition */ |
4731 |
break; |
4732 |
} |
4733 |
} |
4734 |
|
4735 |
dev_info(&wc->dev->dev, "Found an OpenVox Card: %s\n", wc->variety); |
4736 |
wc->gpio = 0x00000000; |
4737 |
t4_pci_out(wc, WC_GPIO, wc->gpio); |
4738 |
t4_gpio_setdir(wc, (1 << 17), (1 << 17)); |
4739 |
t4_gpio_setdir(wc, (0xff), (0xff)); |
4740 |
|
4741 |
create_sysfs_files(wc); |
4742 |
|
4743 |
#if 0 |
4744 |
for (x=0;x<0x10000;x++) { |
4745 |
__t4_raw_oct_out(wc, 0x0004, x); |
4746 |
__t4_raw_oct_out(wc, 0x000a, x ^ 0xffff); |
4747 |
if (__t4_raw_oct_in(wc, 0x0004) != x) |
4748 |
dev_notice(&wc->dev->dev, "Register 4 failed %04x\n", |
4749 |
x); |
4750 |
if (__t4_raw_oct_in(wc, 0x000a) != (x ^ 0xffff)) |
4751 |
dev_notice(&wc->dev->dev, "Register 10 failed %04x\n", |
4752 |
x); |
4753 |
} |
4754 |
#endif |
4755 |
|
4756 |
return 0; |
4757 |
} |
4758 |
|
4759 |
static int t4_hardware_stop(struct t4 *wc) |
4760 |
{ |
4761 |
|
4762 |
/* Turn off DMA, leave interrupts enabled */ |
4763 |
set_bit(T4_STOP_DMA, &wc->checkflag); |
4764 |
|
4765 |
/* Wait for interrupts to stop */ |
4766 |
msleep(25); |
4767 |
|
4768 |
/* Turn off counter, address, etc */ |
4769 |
if (wc->tspans[0]->spanflags & FLAG_2NDGEN) { |
4770 |
t4_tsi_reset(wc); |
4771 |
} else { |
4772 |
t4_pci_out(wc, WC_COUNT, 0x000000); |
4773 |
} |
4774 |
t4_pci_out(wc, WC_RDADDR, 0x0000000); |
4775 |
t4_pci_out(wc, WC_WRADDR, 0x0000000); |
4776 |
wc->gpio = 0x00000000; |
4777 |
t4_pci_out(wc, WC_GPIO, wc->gpio); |
4778 |
t4_pci_out(wc, WC_LEDS, 0x00000000); |
4779 |
|
4780 |
dev_notice(&wc->dev->dev, "\nStopped opvxd115, Turned off DMA\n"); |
4781 |
return 0; |
4782 |
} |
4783 |
|
4784 |
static void __devexit t4_remove_one(struct pci_dev *pdev) |
4785 |
{ |
4786 |
struct t4 *wc = pci_get_drvdata(pdev); |
4787 |
int basesize; |
4788 |
|
4789 |
if (!wc) { |
4790 |
return; |
4791 |
} |
4792 |
|
4793 |
remove_sysfs_files(wc); |
4794 |
|
4795 |
/* Stop hardware */ |
4796 |
t4_hardware_stop(wc); |
4797 |
|
4798 |
/* Release vpm450m */ |
4799 |
if (wc->vpm450m) |
4800 |
release_vpm450m(wc->vpm450m); |
4801 |
wc->vpm450m = NULL; |
4802 |
/* Unregister spans */ |
4803 |
|
4804 |
basesize = DAHDI_MAX_CHUNKSIZE * 32 * 4; |
4805 |
if (!(wc->tspans[0]->spanflags & FLAG_2NDGEN)) |
4806 |
basesize = basesize * 2; |
4807 |
|
4808 |
dahdi_unregister_device(wc->ddev); |
4809 |
kfree(wc->ddev->location); |
4810 |
kfree(wc->ddev->devicetype); |
4811 |
dahdi_free_device(wc->ddev); |
4812 |
#ifdef ENABLE_WORKQUEUES |
4813 |
if (wc->workq) { |
4814 |
flush_workqueue(wc->workq); |
4815 |
destroy_workqueue(wc->workq); |
4816 |
} |
4817 |
#endif |
4818 |
|
4819 |
free_irq(pdev->irq, wc); |
4820 |
|
4821 |
if (wc->membase) |
4822 |
iounmap(wc->membase); |
4823 |
|
4824 |
pci_release_regions(pdev); |
4825 |
|
4826 |
/* Immediately free resources */ |
4827 |
pci_free_consistent(pdev, T4_BASE_SIZE * wc->numbufs * 2, (void *)wc->writechunk, wc->writedma); |
4828 |
|
4829 |
order_index[wc->order]--; |
4830 |
|
4831 |
cards[wc->num] = NULL; |
4832 |
pci_set_drvdata(pdev, NULL); |
4833 |
free_wc(wc); |
4834 |
} |
4835 |
|
4836 |
|
4837 |
static struct pci_device_id t4_pci_tbl[] __devinitdata = |
4838 |
{ |
4839 |
{ 0x1b74, 0x0115, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long)&opvxd115 }, /* OpenVox D115P/D115E */ |
4840 |
{ 0x1b74, 0xd130, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (unsigned long)&opvxd130 }, /* OpenVox D130P/D130E */ |
4841 |
{ 0, } |
4842 |
}; |
4843 |
|
4844 |
static struct pci_driver t4_driver = { |
4845 |
.name = "opvxd115", |
4846 |
.probe = t4_init_one, |
4847 |
.remove = __devexit_p(t4_remove_one), |
4848 |
.id_table = t4_pci_tbl, |
4849 |
}; |
4850 |
|
4851 |
static int __init t4_init(void) |
4852 |
{ |
4853 |
int res; |
4854 |
res = dahdi_pci_module(&t4_driver); |
4855 |
if (res) |
4856 |
return -ENODEV; |
4857 |
/* initialize cards since we have all of them */ |
4858 |
/* warn for missing zero and duplicate numbers */ |
4859 |
if (cards[0] && cards[0]->order != 0) { |
4860 |
printk(KERN_NOTICE "opvxd115: Ident of first card is not zero (%d)\n", |
4861 |
cards[0]->order); |
4862 |
} |
4863 |
for (res = 0; cards[res]; res++) { |
4864 |
/* warn the user of duplicate ident values it is probably |
4865 |
* unintended */ |
4866 |
if (debug && res < 15 && cards[res+1] && |
4867 |
cards[res]->order == cards[res+1]->order) { |
4868 |
printk(KERN_NOTICE "opvxd115: Duplicate ident value found (%d)\n", |
4869 |
cards[res]->order); |
4870 |
} |
4871 |
t4_launch(cards[res]); |
4872 |
} |
4873 |
return 0; |
4874 |
} |
4875 |
|
4876 |
static void __exit t4_cleanup(void) |
4877 |
{ |
4878 |
pci_unregister_driver(&t4_driver); |
4879 |
} |
4880 |
|
4881 |
|
4882 |
MODULE_AUTHOR("mark.liu <mark.liu@openvox.cn>"); |
4883 |
MODULE_DESCRIPTION("Unified OpenVox Single T1/E1/J1 Card Driver"); |
4884 |
MODULE_ALIAS("opvxd115"); |
4885 |
MODULE_LICENSE("GPL v2"); |
4886 |
|
4887 |
module_param(pedanticpci, int, 0600); |
4888 |
module_param(debug, int, 0600); |
4889 |
module_param(noburst, int, 0600); |
4890 |
module_param(timingcable, int, 0600); |
4891 |
module_param(t1e1override, int, 0600); |
4892 |
module_param(alarmdebounce, int, 0600); |
4893 |
module_param(losalarmdebounce, int, 0600); |
4894 |
module_param(aisalarmdebounce, int, 0600); |
4895 |
module_param(yelalarmdebounce, int, 0600); |
4896 |
module_param(max_latency, int, 0600); |
4897 |
module_param(j1mode, int, 0600); |
4898 |
module_param(sigmode, int, 0600); |
4899 |
module_param(latency, int, 0600); |
4900 |
module_param(ms_per_irq, int, 0600); |
4901 |
#ifdef VPM_SUPPORT |
4902 |
module_param(vpmsupport, int, 0600); |
4903 |
module_param(vpmdtmfsupport, int, 0600); |
4904 |
module_param(vpmspans, int, 0600); |
4905 |
module_param(dtmfthreshold, int, 0600); |
4906 |
#endif |
4907 |
|
4908 |
MODULE_DEVICE_TABLE(pci, t4_pci_tbl); |
4909 |
|
4910 |
module_init(t4_init); |
4911 |
module_exit(t4_cleanup); |