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