| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 |
|
| 25 |
#include <linux/kernel.h> |
| 26 |
#include <linux/errno.h> |
| 27 |
#include <linux/module.h> |
| 28 |
#include <linux/init.h> |
| 29 |
#include <linux/pci.h> |
| 30 |
#include <linux/proc_fs.h> |
| 31 |
#include <linux/moduleparam.h> |
| 32 |
#include <linux/interrupt.h> |
| 33 |
#include <linux/workqueue.h> |
| 34 |
#include <linux/delay.h> |
| 35 |
#include <linux/sched.h> |
| 36 |
#include <linux/crc32.h> |
| 37 |
#include <linux/slab.h> |
| 38 |
|
| 39 |
#include <linux/vmalloc.h> |
| 40 |
#include <linux/string.h> |
| 41 |
#include <linux/time.h> |
| 42 |
#include <linux/version.h> |
| 43 |
#include <linux/firmware.h> |
| 44 |
#include <oct612x.h> |
| 45 |
|
| 46 |
#include <dahdi/kernel.h> |
| 47 |
|
| 48 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) |
| 49 |
#include <linux/sched/signal.h> |
| 50 |
#endif |
| 51 |
|
| 52 |
#include "wct4xxp/wct4xxp.h" |
| 53 |
#include "wcxb.h" |
| 54 |
#include "wcxb_spi.h" |
| 55 |
#include "wcxb_flash.h" |
| 56 |
|
| 57 |
static const char *TE435_FW_FILENAME = "dahdi-fw-te435.bin"; |
| 58 |
static const char *TE436_FW_FILENAME = "dahdi-fw-te436.bin"; |
| 59 |
static const u32 TE435_VERSION = 0x13001e; |
| 60 |
static const u32 TE436_VERSION = 0x10017; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
enum linemode { |
| 65 |
T1 = 1, |
| 66 |
E1, |
| 67 |
J1, |
| 68 |
}; |
| 69 |
|
| 70 |
#define STATUS_LED_GREEN (1 << 9) |
| 71 |
#define STATUS_LED_RED (1 << 10) |
| 72 |
#define STATUS_LED_YELLOW (STATUS_LED_RED | STATUS_LED_GREEN) |
| 73 |
#define LED_MASK 0x7f8 |
| 74 |
#define FALC_CPU_RESET (1 << 11) |
| 75 |
|
| 76 |
|
| 77 |
#define FALC_INT (1<<3) |
| 78 |
#define SPI_INT (1<<4) |
| 79 |
#define DMA_STOPPED (1<<5) |
| 80 |
|
| 81 |
struct t43x; |
| 82 |
|
| 83 |
struct t43x_span { |
| 84 |
struct t43x *owner; |
| 85 |
struct dahdi_span span; |
| 86 |
#define NMF_FLAGBIT 1 |
| 87 |
#define SENDINGYELLOW_FLAGBIT 2 |
| 88 |
#define HAVE_OPEN_CHANNELS_FLAGBIT 3 |
| 89 |
unsigned long bit_flags; |
| 90 |
unsigned char txsigs[16]; |
| 91 |
unsigned long lofalarmtimer; |
| 92 |
unsigned long losalarmtimer; |
| 93 |
unsigned long aisalarmtimer; |
| 94 |
unsigned long yelalarmtimer; |
| 95 |
unsigned long recoverytimer; |
| 96 |
unsigned long loopuptimer; |
| 97 |
unsigned long loopdntimer; |
| 98 |
|
| 99 |
struct dahdi_chan *chans[32]; |
| 100 |
struct dahdi_echocan_state *ec[32]; |
| 101 |
|
| 102 |
bool debounce; |
| 103 |
int syncpos; |
| 104 |
int sync; |
| 105 |
u32 lineconfig_fingerprint; |
| 106 |
}; |
| 107 |
|
| 108 |
struct t43x_clksrc_work { |
| 109 |
struct delayed_work work; |
| 110 |
spinlock_t lock; |
| 111 |
enum wcxb_clock_sources clksrc; |
| 112 |
bool is_timing_master; |
| 113 |
}; |
| 114 |
|
| 115 |
|
| 116 |
struct t43x { |
| 117 |
spinlock_t reglock; |
| 118 |
|
| 119 |
const struct t43x_desc *devtype; |
| 120 |
unsigned long blinktimer; |
| 121 |
bool blink; |
| 122 |
struct dahdi_device *ddev; |
| 123 |
struct t43x_span *tspans[4]; |
| 124 |
int numspans; |
| 125 |
int spansstarted; |
| 126 |
|
| 127 |
|
| 128 |
struct timer_list timer; |
| 129 |
struct work_struct timer_work; |
| 130 |
struct workqueue_struct *wq; |
| 131 |
struct t43x_clksrc_work clksrc_work; |
| 132 |
unsigned int not_ready; |
| 133 |
struct vpm450m *vpm; |
| 134 |
char *vpm_name; |
| 135 |
struct mutex lock; |
| 136 |
bool latency_locked; |
| 137 |
int syncsrc; |
| 138 |
int num; |
| 139 |
int intr_span; |
| 140 |
|
| 141 |
struct wcxb xb; |
| 142 |
struct list_head card_node; |
| 143 |
}; |
| 144 |
|
| 145 |
static void t43x_handle_transmit(struct wcxb *xb, void *vfp); |
| 146 |
static void t43x_handle_receive(struct wcxb *xb, void *vfp); |
| 147 |
static void t43x_handle_interrupt(struct wcxb *xb, u32 pending); |
| 148 |
|
| 149 |
static void t43x_handle_error(struct wcxb *xb) |
| 150 |
{ |
| 151 |
struct t43x *wc = container_of(xb, struct t43x, xb); |
| 152 |
wc->ddev->irqmisses++; |
| 153 |
} |
| 154 |
|
| 155 |
static struct wcxb_operations xb_ops = { |
| 156 |
.handle_receive = t43x_handle_receive, |
| 157 |
.handle_transmit = t43x_handle_transmit, |
| 158 |
.handle_interrupt = t43x_handle_interrupt, |
| 159 |
.handle_error = t43x_handle_error, |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
#define LIM0 0x36 |
| 164 |
#define LIM0_LL (1<<1) |
| 165 |
#define LIM1 0x37 |
| 166 |
#define LIM1_RL (1<<1) |
| 167 |
#define LIM1_JATT (1<<2) |
| 168 |
|
| 169 |
|
| 170 |
#define CCB1 0x2f |
| 171 |
#define CCB2 0x30 |
| 172 |
#define CCB3 0x31 |
| 173 |
|
| 174 |
#define FECL_T 0x50 |
| 175 |
#define FECH_T 0x51 |
| 176 |
#define CVCL_T 0x52 |
| 177 |
#define CVCH_T 0x53 |
| 178 |
#define CEC1L_T 0x54 |
| 179 |
#define CEC1H_T 0x55 |
| 180 |
#define EBCL_T 0x56 |
| 181 |
#define EBCH_T 0x57 |
| 182 |
#define BECL_T 0x58 |
| 183 |
#define BECH_T 0x59 |
| 184 |
#define COEC_T 0x5A |
| 185 |
#define PRBSSTA_T 0xDA |
| 186 |
#define FRS1_T 0x4D |
| 187 |
|
| 188 |
#define ISR3_SEC (1 << 6) |
| 189 |
#define ISR3_ES (1 << 7) |
| 190 |
|
| 191 |
#define IMR0 0x14 |
| 192 |
|
| 193 |
|
| 194 |
#define DMA1 0x00 |
| 195 |
#define DMA2 0x04 |
| 196 |
#define DMA3 0x08 |
| 197 |
#define CNTL 0x0C |
| 198 |
#define INT_MASK 0x10 |
| 199 |
#define INT_STAT 0x14 |
| 200 |
#define FRAMER_BASE 0x00000800 |
| 201 |
|
| 202 |
#define NOSYNC_ALARMS (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE | \ |
| 203 |
DAHDI_ALARM_LOOPBACK) |
| 204 |
|
| 205 |
static int debug; |
| 206 |
static int timingcable; |
| 207 |
static int force_firmware; |
| 208 |
static int alarmdebounce = 2500; |
| 209 |
static int losalarmdebounce = 2500; |
| 210 |
static int aisalarmdebounce = 2500; |
| 211 |
static int yelalarmdebounce = 500; |
| 212 |
static char *default_linemode = "t1"; |
| 213 |
static int latency = WCXB_DEFAULT_LATENCY; |
| 214 |
static int max_latency = WCXB_DEFAULT_MAXLATENCY; |
| 215 |
|
| 216 |
struct t43x_firm_header { |
| 217 |
u8 header[6]; |
| 218 |
__le32 chksum; |
| 219 |
u8 pad[18]; |
| 220 |
__le32 version; |
| 221 |
} __packed; |
| 222 |
|
| 223 |
static int t43x_check_for_interrupts(struct t43x *wc); |
| 224 |
static void t43x_check_alarms(struct t43x *wc, int span_idx); |
| 225 |
static void t43x_check_sigbits(struct t43x *wc, int span_idx); |
| 226 |
static const struct dahdi_span_ops t43x_span_ops; |
| 227 |
static void __t43x_set_timing_source_auto(struct t43x *wc); |
| 228 |
|
| 229 |
static int vpmsupport = 1; |
| 230 |
|
| 231 |
#include "oct6100api/oct6100_api.h" |
| 232 |
|
| 233 |
#define ECHOCAN_NUM_CHANS 128 |
| 234 |
|
| 235 |
#define FLAGBIT_DTMF 1 |
| 236 |
#define FLAGBIT_MUTE 2 |
| 237 |
#define FLAGBIT_ECHO 3 |
| 238 |
#define FLAGBIT_ALAW 4 |
| 239 |
|
| 240 |
#define OCT_CHIP_ID 0 |
| 241 |
#define OCT_MAX_TDM_STREAMS 4 |
| 242 |
#define OCT_TONEEVENT_BUFFER_SIZE 128 |
| 243 |
#define SOUT_STREAM 1 |
| 244 |
#define RIN_STREAM 0 |
| 245 |
#define SIN_STREAM 2 |
| 246 |
|
| 247 |
static void t43x_vpm_init(struct t43x *wc); |
| 248 |
static void echocan_free(struct dahdi_chan *chan, |
| 249 |
struct dahdi_echocan_state *ec); |
| 250 |
static const struct dahdi_echocan_features vpm_ec_features = { |
| 251 |
.NLP_automatic = 1, |
| 252 |
.CED_tx_detect = 1, |
| 253 |
.CED_rx_detect = 1, |
| 254 |
}; |
| 255 |
static const struct dahdi_echocan_ops vpm_ec_ops = { |
| 256 |
.echocan_free = echocan_free, |
| 257 |
}; |
| 258 |
|
| 259 |
struct vpm450m { |
| 260 |
tPOCT6100_INSTANCE_API pApiInstance; |
| 261 |
struct oct612x_context context; |
| 262 |
UINT32 aulEchoChanHndl[ECHOCAN_NUM_CHANS]; |
| 263 |
int ecmode[ECHOCAN_NUM_CHANS]; |
| 264 |
unsigned long chanflags[ECHOCAN_NUM_CHANS]; |
| 265 |
}; |
| 266 |
|
| 267 |
static int t43x_oct612x_write(struct oct612x_context *context, |
| 268 |
u32 address, u16 value) |
| 269 |
{ |
| 270 |
struct t43x *wc = dev_get_drvdata(context->dev); |
| 271 |
wcxb_set_echocan_reg(&wc->xb, address, value); |
| 272 |
return 0; |
| 273 |
} |
| 274 |
|
| 275 |
static int t43x_oct612x_read(struct oct612x_context *context, u32 address, |
| 276 |
u16 *value) |
| 277 |
{ |
| 278 |
struct t43x *wc = dev_get_drvdata(context->dev); |
| 279 |
*value = wcxb_get_echocan_reg(&wc->xb, address); |
| 280 |
return 0; |
| 281 |
} |
| 282 |
|
| 283 |
static int t43x_oct612x_write_smear(struct oct612x_context *context, |
| 284 |
u32 address, u16 value, size_t count) |
| 285 |
{ |
| 286 |
unsigned int i; |
| 287 |
struct t43x *wc = dev_get_drvdata(context->dev); |
| 288 |
for (i = 0; i < count; ++i) |
| 289 |
wcxb_set_echocan_reg(&wc->xb, address + (i << 1), value); |
| 290 |
return 0; |
| 291 |
} |
| 292 |
|
| 293 |
static int t43x_oct612x_write_burst(struct oct612x_context *context, |
| 294 |
u32 address, const u16 *buffer, |
| 295 |
size_t count) |
| 296 |
{ |
| 297 |
unsigned int i; |
| 298 |
struct t43x *wc = dev_get_drvdata(context->dev); |
| 299 |
for (i = 0; i < count; ++i) |
| 300 |
wcxb_set_echocan_reg(&wc->xb, address + (i << 1), buffer[i]); |
| 301 |
return 0; |
| 302 |
} |
| 303 |
|
| 304 |
static int t43x_oct612x_read_burst(struct oct612x_context *context, |
| 305 |
u32 address, u16 *buffer, size_t count) |
| 306 |
{ |
| 307 |
unsigned int i; |
| 308 |
struct t43x *wc = dev_get_drvdata(context->dev); |
| 309 |
for (i = 0; i < count; ++i) |
| 310 |
buffer[i] = wcxb_get_echocan_reg(&wc->xb, address + (i << 1)); |
| 311 |
return 0; |
| 312 |
} |
| 313 |
|
| 314 |
static const struct oct612x_ops t43x_oct612x_ops = { |
| 315 |
.write = t43x_oct612x_write, |
| 316 |
.read = t43x_oct612x_read, |
| 317 |
.write_smear = t43x_oct612x_write_smear, |
| 318 |
.write_burst = t43x_oct612x_write_burst, |
| 319 |
.read_burst = t43x_oct612x_read_burst, |
| 320 |
}; |
| 321 |
|
| 322 |
static void vpm450m_setecmode(struct vpm450m *vpm450m, int channel, int mode) |
| 323 |
{ |
| 324 |
tOCT6100_CHANNEL_MODIFY *modify; |
| 325 |
UINT32 ulResult; |
| 326 |
|
| 327 |
if (vpm450m->ecmode[channel] == mode) |
| 328 |
return; |
| 329 |
modify = kzalloc(sizeof(tOCT6100_CHANNEL_MODIFY), GFP_ATOMIC); |
| 330 |
if (!modify) { |
| 331 |
pr_notice("Unable to allocate memory for setec!\n"); |
| 332 |
return; |
| 333 |
} |
| 334 |
Oct6100ChannelModifyDef(modify); |
| 335 |
modify->ulEchoOperationMode = mode; |
| 336 |
modify->ulChannelHndl = vpm450m->aulEchoChanHndl[channel]; |
| 337 |
ulResult = Oct6100ChannelModify(vpm450m->pApiInstance, modify); |
| 338 |
if (ulResult != GENERIC_OK) { |
| 339 |
pr_notice("Failed to apply echo can changes on channel %d %d %08x!\n", |
| 340 |
vpm450m->aulEchoChanHndl[channel], channel, ulResult); |
| 341 |
} else { |
| 342 |
#ifdef OCTASIC_DEBUG |
| 343 |
pr_debug("Echo can on channel %d set to %d\n", channel, mode); |
| 344 |
#endif |
| 345 |
vpm450m->ecmode[channel] = mode; |
| 346 |
} |
| 347 |
kfree(modify); |
| 348 |
} |
| 349 |
|
| 350 |
static void vpm450m_set_alaw_companding(struct vpm450m *vpm450m, int channel, |
| 351 |
bool alaw) |
| 352 |
{ |
| 353 |
tOCT6100_CHANNEL_MODIFY *modify; |
| 354 |
UINT32 ulResult; |
| 355 |
UINT32 law_to_use = (alaw) ? cOCT6100_PCM_A_LAW : |
| 356 |
cOCT6100_PCM_U_LAW; |
| 357 |
|
| 358 |
|
| 359 |
if (alaw == (test_bit(FLAGBIT_ALAW, &vpm450m->chanflags[channel]) > 0)) |
| 360 |
return; |
| 361 |
|
| 362 |
modify = kzalloc(sizeof(tOCT6100_CHANNEL_MODIFY), GFP_ATOMIC); |
| 363 |
if (!modify) { |
| 364 |
pr_notice("Unable to allocate memory for setec!\n"); |
| 365 |
return; |
| 366 |
} |
| 367 |
|
| 368 |
Oct6100ChannelModifyDef(modify); |
| 369 |
modify->ulChannelHndl = vpm450m->aulEchoChanHndl[channel]; |
| 370 |
modify->fTdmConfigModified = TRUE; |
| 371 |
modify->TdmConfig.ulSinPcmLaw = law_to_use; |
| 372 |
modify->TdmConfig.ulRinPcmLaw = law_to_use; |
| 373 |
modify->TdmConfig.ulSoutPcmLaw = law_to_use; |
| 374 |
modify->TdmConfig.ulRoutPcmLaw = law_to_use; |
| 375 |
ulResult = Oct6100ChannelModify(vpm450m->pApiInstance, modify); |
| 376 |
if (ulResult != GENERIC_OK) { |
| 377 |
pr_notice("Failed to apply echo can changes on channel %d %d %08x!\n", |
| 378 |
vpm450m->aulEchoChanHndl[channel], channel, ulResult); |
| 379 |
} else { |
| 380 |
if (debug) { |
| 381 |
pr_info("Changed companding on channel %d to %s.\n", |
| 382 |
channel, (alaw) ? "alaw" : "ulaw"); |
| 383 |
} |
| 384 |
if (alaw) |
| 385 |
set_bit(FLAGBIT_ALAW, &vpm450m->chanflags[channel]); |
| 386 |
else |
| 387 |
clear_bit(FLAGBIT_ALAW, &vpm450m->chanflags[channel]); |
| 388 |
} |
| 389 |
kfree(modify); |
| 390 |
} |
| 391 |
|
| 392 |
static void vpm450m_setec(struct vpm450m *vpm450m, int channel, int eclen) |
| 393 |
{ |
| 394 |
if (eclen) { |
| 395 |
set_bit(FLAGBIT_ECHO, &vpm450m->chanflags[channel]); |
| 396 |
vpm450m_setecmode(vpm450m, channel, |
| 397 |
cOCT6100_ECHO_OP_MODE_NORMAL); |
| 398 |
} else { |
| 399 |
unsigned long *flags = &vpm450m->chanflags[channel]; |
| 400 |
clear_bit(FLAGBIT_ECHO, &vpm450m->chanflags[channel]); |
| 401 |
if (test_bit(FLAGBIT_DTMF, flags) || |
| 402 |
test_bit(FLAGBIT_MUTE, flags)) { |
| 403 |
vpm450m_setecmode(vpm450m, channel, |
| 404 |
cOCT6100_ECHO_OP_MODE_HT_RESET); |
| 405 |
} else { |
| 406 |
vpm450m_setecmode(vpm450m, channel, |
| 407 |
cOCT6100_ECHO_OP_MODE_POWER_DOWN); |
| 408 |
} |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
static UINT32 tdmmode_chan_to_slot_map(int channel) |
| 413 |
{ |
| 414 |
|
| 415 |
|
| 416 |
return 1 + ((channel % 32) * 4) + (channel / 32); |
| 417 |
} |
| 418 |
|
| 419 |
static int echocan_initialize_channel( |
| 420 |
struct vpm450m *vpm, int channel, int mode) |
| 421 |
{ |
| 422 |
tOCT6100_CHANNEL_OPEN ChannelOpen; |
| 423 |
UINT32 law_to_use = (mode) ? cOCT6100_PCM_A_LAW : |
| 424 |
cOCT6100_PCM_U_LAW; |
| 425 |
UINT32 tdmslot_setting; |
| 426 |
UINT32 ulResult; |
| 427 |
|
| 428 |
tdmslot_setting = tdmmode_chan_to_slot_map(channel); |
| 429 |
|
| 430 |
|
| 431 |
Oct6100ChannelOpenDef(&ChannelOpen); |
| 432 |
|
| 433 |
|
| 434 |
ChannelOpen.pulChannelHndl = &vpm->aulEchoChanHndl[channel]; |
| 435 |
ChannelOpen.ulUserChanId = channel; |
| 436 |
|
| 437 |
ChannelOpen.fEnableToneDisabler = TRUE; |
| 438 |
|
| 439 |
|
| 440 |
ChannelOpen.ulEchoOperationMode = cOCT6100_ECHO_OP_MODE_POWER_DOWN; |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
ChannelOpen.TdmConfig.ulSinStream = SIN_STREAM; |
| 445 |
ChannelOpen.TdmConfig.ulSinTimeslot = tdmslot_setting; |
| 446 |
ChannelOpen.TdmConfig.ulSinPcmLaw = law_to_use; |
| 447 |
|
| 448 |
|
| 449 |
ChannelOpen.TdmConfig.ulRinStream = RIN_STREAM; |
| 450 |
ChannelOpen.TdmConfig.ulRinTimeslot = tdmslot_setting; |
| 451 |
ChannelOpen.TdmConfig.ulRinPcmLaw = law_to_use; |
| 452 |
|
| 453 |
|
| 454 |
ChannelOpen.TdmConfig.ulSoutStream = SOUT_STREAM; |
| 455 |
ChannelOpen.TdmConfig.ulSoutTimeslot = tdmslot_setting; |
| 456 |
ChannelOpen.TdmConfig.ulSoutPcmLaw = law_to_use; |
| 457 |
|
| 458 |
|
| 459 |
ChannelOpen.TdmConfig.ulRoutStream = cOCT6100_UNASSIGNED; |
| 460 |
ChannelOpen.TdmConfig.ulRoutTimeslot = cOCT6100_UNASSIGNED; |
| 461 |
ChannelOpen.TdmConfig.ulRoutPcmLaw = law_to_use; |
| 462 |
|
| 463 |
|
| 464 |
ChannelOpen.VqeConfig.fEnableNlp = TRUE; |
| 465 |
ChannelOpen.VqeConfig.fRinDcOffsetRemoval = TRUE; |
| 466 |
ChannelOpen.VqeConfig.fSinDcOffsetRemoval = TRUE; |
| 467 |
ChannelOpen.VqeConfig.ulComfortNoiseMode = |
| 468 |
cOCT6100_COMFORT_NOISE_NORMAL; |
| 469 |
|
| 470 |
|
| 471 |
ulResult = Oct6100ChannelOpen(vpm->pApiInstance, &ChannelOpen); |
| 472 |
|
| 473 |
return ulResult; |
| 474 |
} |
| 475 |
|
| 476 |
static struct vpm450m *init_vpm450m(struct t43x *wc, int *laws, int numspans, |
| 477 |
const struct firmware *firmware) |
| 478 |
{ |
| 479 |
tOCT6100_CHIP_OPEN *ChipOpen; |
| 480 |
tOCT6100_GET_INSTANCE_SIZE InstanceSize; |
| 481 |
tOCT6100_CHANNEL_OPEN *ChannelOpen; |
| 482 |
UINT32 ulResult; |
| 483 |
struct vpm450m *vpm450m; |
| 484 |
int x, i; |
| 485 |
|
| 486 |
vpm450m = kzalloc(sizeof(struct vpm450m), GFP_KERNEL); |
| 487 |
if (!vpm450m) { |
| 488 |
dev_info(&wc->xb.pdev->dev, |
| 489 |
"Unable to allocate vpm450m struct\n"); |
| 490 |
return NULL; |
| 491 |
} |
| 492 |
|
| 493 |
vpm450m->context.dev = &wc->xb.pdev->dev; |
| 494 |
vpm450m->context.ops = &t43x_oct612x_ops; |
| 495 |
|
| 496 |
ChipOpen = kzalloc(sizeof(tOCT6100_CHIP_OPEN), GFP_KERNEL); |
| 497 |
if (!ChipOpen) { |
| 498 |
dev_info(&wc->xb.pdev->dev, "Unable to allocate ChipOpen\n"); |
| 499 |
kfree(vpm450m); |
| 500 |
return NULL; |
| 501 |
} |
| 502 |
|
| 503 |
ChannelOpen = kzalloc(sizeof(tOCT6100_CHANNEL_OPEN), GFP_KERNEL); |
| 504 |
if (!ChannelOpen) { |
| 505 |
dev_info(&wc->xb.pdev->dev, "Unable to allocate ChannelOpen\n"); |
| 506 |
kfree(vpm450m); |
| 507 |
kfree(ChipOpen); |
| 508 |
return NULL; |
| 509 |
} |
| 510 |
|
| 511 |
for (x = 0; x < ARRAY_SIZE(vpm450m->ecmode); x++) |
| 512 |
vpm450m->ecmode[x] = -1; |
| 513 |
|
| 514 |
dev_info(&wc->xb.pdev->dev, "Echo cancellation for %d channels\n", |
| 515 |
wc->numspans * 32); |
| 516 |
|
| 517 |
Oct6100ChipOpenDef(ChipOpen); |
| 518 |
ChipOpen->pProcessContext = &vpm450m->context; |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
ChipOpen->ulUpclkFreq = cOCT6100_UPCLK_FREQ_33_33_MHZ; |
| 523 |
|
| 524 |
|
| 525 |
ChipOpen->fEnableMemClkOut = TRUE; |
| 526 |
ChipOpen->ulMemClkFreq = cOCT6100_MCLK_FREQ_133_MHZ; |
| 527 |
|
| 528 |
|
| 529 |
ChipOpen->ulUserChipId = OCT_CHIP_ID; |
| 530 |
|
| 531 |
|
| 532 |
ChipOpen->ulMaxChannels = wc->numspans * 32; |
| 533 |
ChipOpen->ulMaxTdmStreams = OCT_MAX_TDM_STREAMS; |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
ChipOpen->ulMemoryType = cOCT6100_MEM_TYPE_DDR; |
| 538 |
ChipOpen->ulNumMemoryChips = 1; |
| 539 |
ChipOpen->ulMemoryChipSize = cOCT6100_MEMORY_CHIP_SIZE_32MB; |
| 540 |
|
| 541 |
ChipOpen->pbyImageFile = (PUINT8) firmware->data; |
| 542 |
ChipOpen->ulImageSize = firmware->size; |
| 543 |
|
| 544 |
|
| 545 |
for (i = 0; i < ChipOpen->ulMaxTdmStreams; i++) |
| 546 |
ChipOpen->aulTdmStreamFreqs[i] = cOCT6100_TDM_STREAM_FREQ_8MHZ; |
| 547 |
|
| 548 |
|
| 549 |
ChipOpen->ulTdmSampling = cOCT6100_TDM_SAMPLE_AT_FALLING_EDGE; |
| 550 |
|
| 551 |
ChipOpen->fEnableChannelRecording = false; |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
ChipOpen->InterruptConfig.ulErrorH100Config = |
| 556 |
cOCT6100_INTERRUPT_DISABLE; |
| 557 |
ChipOpen->InterruptConfig.ulErrorMemoryConfig = |
| 558 |
cOCT6100_INTERRUPT_DISABLE; |
| 559 |
ChipOpen->InterruptConfig.ulFatalGeneralConfig = |
| 560 |
cOCT6100_INTERRUPT_DISABLE; |
| 561 |
ChipOpen->InterruptConfig.ulFatalMemoryConfig = |
| 562 |
cOCT6100_INTERRUPT_DISABLE; |
| 563 |
|
| 564 |
ChipOpen->ulSoftToneEventsBufSize = OCT_TONEEVENT_BUFFER_SIZE; |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
Oct6100GetInstanceSizeDef(&InstanceSize); |
| 569 |
|
| 570 |
|
| 571 |
wcxb_reset_echocan(&wc->xb); |
| 572 |
|
| 573 |
|
| 574 |
ulResult = Oct6100GetInstanceSize(ChipOpen, &InstanceSize); |
| 575 |
if (ulResult != cOCT6100_ERR_OK) { |
| 576 |
dev_info(&wc->xb.pdev->dev, "Unable to get instance size: %x\n", |
| 577 |
ulResult); |
| 578 |
return NULL; |
| 579 |
} |
| 580 |
|
| 581 |
vpm450m->pApiInstance = vmalloc(InstanceSize.ulApiInstanceSize); |
| 582 |
if (!vpm450m->pApiInstance) { |
| 583 |
dev_info(&wc->xb.pdev->dev, |
| 584 |
"Out of memory (can't allocate %d bytes)!\n", |
| 585 |
InstanceSize.ulApiInstanceSize); |
| 586 |
return NULL; |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
wcxb_enable_echocan_dram(&wc->xb); |
| 591 |
ulResult = Oct6100ChipOpen(vpm450m->pApiInstance, ChipOpen); |
| 592 |
if (ulResult != cOCT6100_ERR_OK) { |
| 593 |
dev_info(&wc->xb.pdev->dev, "Unable to Oct6100ChipOpen: %x\n", |
| 594 |
ulResult); |
| 595 |
return NULL; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
for (x = 0; x < numspans; x++) { |
| 601 |
for (i = 0; i < 31; i++) { |
| 602 |
ulResult = echocan_initialize_channel(vpm450m, |
| 603 |
(x*32)+i, |
| 604 |
laws[x]); |
| 605 |
if (0 != ulResult) { |
| 606 |
dev_info(&wc->xb.pdev->dev, |
| 607 |
"Unable to echocan_initialize_channel: %d %x\n", |
| 608 |
(x*32)+i, ulResult); |
| 609 |
return NULL; |
| 610 |
} else if (laws[x]) { |
| 611 |
set_bit(FLAGBIT_ALAW, |
| 612 |
&vpm450m->chanflags[(x*32)+i]); |
| 613 |
} |
| 614 |
} |
| 615 |
} |
| 616 |
|
| 617 |
if (vpmsupport != 0) |
| 618 |
wcxb_enable_echocan(&wc->xb); |
| 619 |
|
| 620 |
kfree(ChipOpen); |
| 621 |
kfree(ChannelOpen); |
| 622 |
return vpm450m; |
| 623 |
} |
| 624 |
|
| 625 |
static void release_vpm450m(struct vpm450m *vpm450m) |
| 626 |
{ |
| 627 |
UINT32 ulResult; |
| 628 |
tOCT6100_CHIP_CLOSE ChipClose; |
| 629 |
|
| 630 |
Oct6100ChipCloseDef(&ChipClose); |
| 631 |
ulResult = Oct6100ChipClose(vpm450m->pApiInstance, &ChipClose); |
| 632 |
if (ulResult != cOCT6100_ERR_OK) |
| 633 |
pr_notice("Failed to close chip, code %08x!\n", ulResult); |
| 634 |
vfree(vpm450m->pApiInstance); |
| 635 |
kfree(vpm450m); |
| 636 |
} |
| 637 |
|
| 638 |
static const char *__t43x_echocan_name(struct t43x *wc) |
| 639 |
{ |
| 640 |
if (wc->vpm) |
| 641 |
return wc->vpm_name; |
| 642 |
else |
| 643 |
return NULL; |
| 644 |
} |
| 645 |
|
| 646 |
static const char *t43x_echocan_name(const struct dahdi_chan *chan) |
| 647 |
{ |
| 648 |
struct t43x *wc = chan->pvt; |
| 649 |
return __t43x_echocan_name(wc); |
| 650 |
} |
| 651 |
|
| 652 |
static int t43x_echocan_create(struct dahdi_chan *chan, |
| 653 |
struct dahdi_echocanparams *ecp, |
| 654 |
struct dahdi_echocanparam *p, |
| 655 |
struct dahdi_echocan_state **ec) |
| 656 |
{ |
| 657 |
struct t43x *wc = chan->pvt; |
| 658 |
struct t43x_span *ts = container_of(chan->span, struct t43x_span, span); |
| 659 |
int channel = chan->chanpos - 1; |
| 660 |
const bool alaw = (chan->span->deflaw == 2); |
| 661 |
|
| 662 |
if (!vpmsupport || !wc->vpm) |
| 663 |
return -ENODEV; |
| 664 |
|
| 665 |
if (ecp->param_count > 0) { |
| 666 |
dev_warn(&wc->xb.pdev->dev, |
| 667 |
"%s echo canceller does not support parameters; failing request\n", |
| 668 |
chan->ec_factory->get_name(chan)); |
| 669 |
return -EINVAL; |
| 670 |
} |
| 671 |
|
| 672 |
*ec = ts->ec[channel]; |
| 673 |
(*ec)->ops = &vpm_ec_ops; |
| 674 |
(*ec)->features = vpm_ec_features; |
| 675 |
|
| 676 |
channel += (32*chan->span->offset); |
| 677 |
vpm450m_set_alaw_companding(wc->vpm, channel, alaw); |
| 678 |
vpm450m_setec(wc->vpm, channel, ecp->tap_length); |
| 679 |
return 0; |
| 680 |
} |
| 681 |
|
| 682 |
static void echocan_free(struct dahdi_chan *chan, |
| 683 |
struct dahdi_echocan_state *ec) |
| 684 |
{ |
| 685 |
struct t43x *wc = chan->pvt; |
| 686 |
int channel = chan->chanpos - 1; |
| 687 |
if (!wc->vpm) |
| 688 |
return; |
| 689 |
memset(ec, 0, sizeof(*ec)); |
| 690 |
channel += (32*chan->span->offset); |
| 691 |
vpm450m_setec(wc->vpm, channel, 0); |
| 692 |
} |
| 693 |
|
| 694 |
static void t43x_vpm_init(struct t43x *wc) |
| 695 |
{ |
| 696 |
int laws[8] = {0, }; |
| 697 |
int x; |
| 698 |
|
| 699 |
struct firmware embedded_firmware; |
| 700 |
const struct firmware *firmware = &embedded_firmware; |
| 701 |
#if !defined(HOTPLUG_FIRMWARE) |
| 702 |
extern void _binary_dahdi_fw_oct6114_064_bin_size; |
| 703 |
extern u8 _binary_dahdi_fw_oct6114_064_bin_start[]; |
| 704 |
extern void _binary_dahdi_fw_oct6114_128_bin_size; |
| 705 |
extern u8 _binary_dahdi_fw_oct6114_128_bin_start[]; |
| 706 |
#else |
| 707 |
static const char oct064_firmware[] = "dahdi-fw-oct6114-064.bin"; |
| 708 |
static const char oct128_firmware[] = "dahdi-fw-oct6114-128.bin"; |
| 709 |
const char *oct_firmware; |
| 710 |
#endif |
| 711 |
|
| 712 |
if (!vpmsupport) { |
| 713 |
dev_info(&wc->xb.pdev->dev, "VPM450: Support Disabled\n"); |
| 714 |
return; |
| 715 |
} |
| 716 |
|
| 717 |
#if defined(HOTPLUG_FIRMWARE) |
| 718 |
if (wc->numspans == 2) { |
| 719 |
wc->vpm_name = "VPMOCT064"; |
| 720 |
oct_firmware = oct064_firmware; |
| 721 |
} else { |
| 722 |
wc->vpm_name = "VPMOCT128"; |
| 723 |
oct_firmware = oct128_firmware; |
| 724 |
} |
| 725 |
if ((request_firmware(&firmware, oct_firmware, &wc->xb.pdev->dev) != 0) |
| 726 |
|| !firmware) { |
| 727 |
dev_notice(&wc->xb.pdev->dev, |
| 728 |
"VPM450: firmware %s not available from userspace\n", |
| 729 |
oct_firmware); |
| 730 |
return; |
| 731 |
} |
| 732 |
#else |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
if (wc->numspans == 2) { |
| 740 |
embedded_firmware.data = _binary_dahdi_fw_oct6114_064_bin_start; |
| 741 |
embedded_firmware.size = |
| 742 |
(size_t)&_binary_dahdi_fw_oct6114_064_bin_size; |
| 743 |
} else { |
| 744 |
embedded_firmware.size = |
| 745 |
(size_t)&_binary_dahdi_fw_oct6114_128_bin_size; |
| 746 |
embedded_firmware.data = _binary_dahdi_fw_oct6114_128_bin_start; |
| 747 |
} |
| 748 |
#endif |
| 749 |
|
| 750 |
|
| 751 |
for (x = 0; x < wc->numspans; x++) { |
| 752 |
if (wc->tspans[x]->span.channels > 24) |
| 753 |
laws[x] = 1; |
| 754 |
} |
| 755 |
|
| 756 |
wc->vpm = init_vpm450m(wc, laws, wc->numspans, firmware); |
| 757 |
|
| 758 |
if (!wc->vpm) { |
| 759 |
dev_notice(&wc->xb.pdev->dev, "VPM450: Failed to initialize\n"); |
| 760 |
if (firmware != &embedded_firmware) |
| 761 |
release_firmware(firmware); |
| 762 |
return; |
| 763 |
} |
| 764 |
|
| 765 |
if (firmware != &embedded_firmware) |
| 766 |
release_firmware(firmware); |
| 767 |
|
| 768 |
dev_info(&wc->xb.pdev->dev, |
| 769 |
"VPM450: Present and operational servicing %d span(s)\n", |
| 770 |
wc->numspans); |
| 771 |
|
| 772 |
} |
| 773 |
|
| 774 |
static int t43x_clear_maint(struct dahdi_span *span); |
| 775 |
|
| 776 |
static DEFINE_MUTEX(card_list_lock); |
| 777 |
static LIST_HEAD(card_list); |
| 778 |
|
| 779 |
struct t43x_desc { |
| 780 |
const char *name; |
| 781 |
}; |
| 782 |
|
| 783 |
static const struct t43x_desc te435 = {"Wildcard TE435"}; |
| 784 |
static const struct t43x_desc te235 = {"Wildcard TE235"}; |
| 785 |
static const struct t43x_desc te436 = {"Wildcard TE436"}; |
| 786 |
static const struct t43x_desc te236 = {"Wildcard TE236"}; |
| 787 |
|
| 788 |
static int __t43x_pci_get(struct t43x *wc, unsigned int addr) |
| 789 |
{ |
| 790 |
unsigned int res = ioread8(wc->xb.membase + addr); |
| 791 |
return res; |
| 792 |
} |
| 793 |
|
| 794 |
static inline int __t43x_pci_set(struct t43x *wc, unsigned int addr, int val) |
| 795 |
{ |
| 796 |
iowrite8(val, wc->xb.membase + addr); |
| 797 |
__t43x_pci_get(wc, 0); |
| 798 |
return 0; |
| 799 |
} |
| 800 |
|
| 801 |
static inline int t43x_pci_get(struct t43x *wc, int addr) |
| 802 |
{ |
| 803 |
unsigned int ret; |
| 804 |
unsigned long flags; |
| 805 |
|
| 806 |
spin_lock_irqsave(&wc->reglock, flags); |
| 807 |
ret = __t43x_pci_get(wc, addr); |
| 808 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 809 |
return ret; |
| 810 |
} |
| 811 |
|
| 812 |
static inline int t43x_pci_set(struct t43x *wc, int addr, int val) |
| 813 |
{ |
| 814 |
unsigned long flags; |
| 815 |
unsigned int ret; |
| 816 |
spin_lock_irqsave(&wc->reglock, flags); |
| 817 |
ret = __t43x_pci_set(wc, addr, val); |
| 818 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 819 |
return ret; |
| 820 |
} |
| 821 |
|
| 822 |
static inline int |
| 823 |
__t43x_framer_set(struct t43x *wc, int unit, int addr, int val) |
| 824 |
{ |
| 825 |
return __t43x_pci_set(wc, FRAMER_BASE + (unit << 8) + addr, val); |
| 826 |
} |
| 827 |
|
| 828 |
static inline int t43x_framer_set(struct t43x *wc, int unit, int addr, int val) |
| 829 |
{ |
| 830 |
return t43x_pci_set(wc, FRAMER_BASE + (unit << 8) + addr, val); |
| 831 |
} |
| 832 |
|
| 833 |
static inline int __t43x_framer_get(struct t43x *wc, int unit, int addr) |
| 834 |
{ |
| 835 |
return __t43x_pci_get(wc, FRAMER_BASE + (unit << 8) + addr); |
| 836 |
} |
| 837 |
|
| 838 |
static inline int t43x_framer_get(struct t43x *wc, int unit, int addr) |
| 839 |
{ |
| 840 |
return t43x_pci_get(wc, FRAMER_BASE + (unit << 8) + addr); |
| 841 |
} |
| 842 |
|
| 843 |
static void t43x_framer_reset(struct t43x *wc) |
| 844 |
{ |
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
wcxb_stop_dma(&wc->xb); |
| 852 |
wcxb_wait_for_stop(&wc->xb, 50); |
| 853 |
wcxb_set_clksrc(&wc->xb, WCXB_CLOCK_SELF); |
| 854 |
wcxb_gpio_clear(&wc->xb, FALC_CPU_RESET); |
| 855 |
msleep_interruptible(100); |
| 856 |
wcxb_gpio_set(&wc->xb, FALC_CPU_RESET); |
| 857 |
} |
| 858 |
|
| 859 |
static void t43x_setleds(struct t43x *wc, u32 leds) |
| 860 |
{ |
| 861 |
wcxb_gpio_set(&wc->xb, leds & LED_MASK); |
| 862 |
wcxb_gpio_clear(&wc->xb, ~leds & LED_MASK); |
| 863 |
} |
| 864 |
|
| 865 |
static void t43x_set_cas_mode(struct t43x *wc, int span_idx) |
| 866 |
{ |
| 867 |
struct t43x_span *ts = wc->tspans[span_idx]; |
| 868 |
int fidx = (wc->numspans == 2) ? span_idx+1 : span_idx; |
| 869 |
int i, offset; |
| 870 |
int reg; |
| 871 |
unsigned long flags; |
| 872 |
bool span_has_cas_channel = false; |
| 873 |
|
| 874 |
if (debug) |
| 875 |
dev_info(&wc->xb.pdev->dev, "%s span: %d\n", __func__, |
| 876 |
span_idx); |
| 877 |
|
| 878 |
if (dahdi_is_e1_span(&ts->span)) { |
| 879 |
span_has_cas_channel = !(ts->span.lineconfig&DAHDI_CONFIG_CCS); |
| 880 |
} else { |
| 881 |
unsigned char ccb[3] = {0, 0, 0}; |
| 882 |
|
| 883 |
for (i = 0; i < ts->span.channels; i++) { |
| 884 |
offset = i/8; |
| 885 |
if (offset >= ARRAY_SIZE(ccb)) { |
| 886 |
WARN_ON(1); |
| 887 |
break; |
| 888 |
} |
| 889 |
if (ts->span.chans[i]->flags & DAHDI_FLAG_CLEAR) |
| 890 |
ccb[offset] |= 1 << (7 - (i % 8)); |
| 891 |
else |
| 892 |
ccb[offset] &= ~(1 << (7 - (i % 8))); |
| 893 |
} |
| 894 |
|
| 895 |
spin_lock_irqsave(&wc->reglock, flags); |
| 896 |
__t43x_framer_set(wc, fidx, CCB1, ccb[0]); |
| 897 |
__t43x_framer_set(wc, fidx, CCB2, ccb[1]); |
| 898 |
__t43x_framer_set(wc, fidx, CCB3, ccb[2]); |
| 899 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 900 |
|
| 901 |
if ((~ccb[0]) | (~ccb[1]) | (~ccb[2])) |
| 902 |
span_has_cas_channel = true; |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
spin_lock_irqsave(&wc->reglock, flags); |
| 908 |
reg = __t43x_framer_get(wc, fidx, IMR0); |
| 909 |
if (span_has_cas_channel) |
| 910 |
__t43x_framer_set(wc, fidx, IMR0, reg & ~0x08); |
| 911 |
else |
| 912 |
__t43x_framer_set(wc, fidx, IMR0, reg | 0x08); |
| 913 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
static void _t43x_free_channels(struct t43x *wc) |
| 923 |
{ |
| 924 |
unsigned int x, y; |
| 925 |
|
| 926 |
for (x = 0; x < ARRAY_SIZE(wc->tspans); x++) { |
| 927 |
if (!wc->tspans[x]) |
| 928 |
continue; |
| 929 |
for (y = 0; y < ARRAY_SIZE(wc->tspans[x]->chans); y++) { |
| 930 |
kfree(wc->tspans[x]->chans[y]); |
| 931 |
kfree(wc->tspans[x]->ec[y]); |
| 932 |
} |
| 933 |
kfree(wc->tspans[x]); |
| 934 |
} |
| 935 |
} |
| 936 |
|
| 937 |
static void free_wc(struct t43x *wc) |
| 938 |
{ |
| 939 |
unsigned long flags; |
| 940 |
LIST_HEAD(list); |
| 941 |
|
| 942 |
mutex_lock(&card_list_lock); |
| 943 |
list_del(&wc->card_node); |
| 944 |
mutex_unlock(&card_list_lock); |
| 945 |
|
| 946 |
spin_lock_irqsave(&wc->reglock, flags); |
| 947 |
_t43x_free_channels(wc); |
| 948 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 949 |
|
| 950 |
if (wc->wq) |
| 951 |
destroy_workqueue(wc->wq); |
| 952 |
kfree(wc->ddev->location); |
| 953 |
kfree(wc->ddev->devicetype); |
| 954 |
kfree(wc->ddev->hardware_id); |
| 955 |
if (wc->ddev) |
| 956 |
dahdi_free_device(wc->ddev); |
| 957 |
kfree(wc); |
| 958 |
} |
| 959 |
|
| 960 |
static void t43x_serial_setup(struct t43x *wc) |
| 961 |
{ |
| 962 |
unsigned long flags; |
| 963 |
int slot, fidx; |
| 964 |
|
| 965 |
dev_info(&wc->xb.pdev->dev, |
| 966 |
"Setting up global serial parameters for card %d\n", wc->num); |
| 967 |
|
| 968 |
t43x_framer_reset(wc); |
| 969 |
|
| 970 |
spin_lock_irqsave(&wc->reglock, flags); |
| 971 |
|
| 972 |
|
| 973 |
__t43x_framer_set(wc, 0, 0x85, 0xe0); |
| 974 |
|
| 975 |
__t43x_framer_set(wc, 0, 0xd3, 0xa1); |
| 976 |
|
| 977 |
__t43x_framer_set(wc, 0, 0xd4, 0x83); |
| 978 |
|
| 979 |
__t43x_framer_set(wc, 0, 0xd5, 0xe5); |
| 980 |
|
| 981 |
__t43x_framer_set(wc, 0, 0xd6, 0x87); |
| 982 |
|
| 983 |
__t43x_framer_set(wc, 0, 0x08, 0x05); |
| 984 |
|
| 985 |
|
| 986 |
__t43x_framer_set(wc, 0, 0x92, 0x00); |
| 987 |
__t43x_framer_set(wc, 0, 0x93, 0x18); |
| 988 |
__t43x_framer_set(wc, 0, 0x94, 0xfb); |
| 989 |
__t43x_framer_set(wc, 0, 0x95, 0x0b); |
| 990 |
__t43x_framer_set(wc, 0, 0x96, 0x00); |
| 991 |
__t43x_framer_set(wc, 0, 0x97, 0x0b); |
| 992 |
__t43x_framer_set(wc, 0, 0x98, 0xdb); |
| 993 |
__t43x_framer_set(wc, 0, 0x99, 0xdf); |
| 994 |
|
| 995 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 996 |
|
| 997 |
for (fidx = 0; fidx < 4; fidx++) { |
| 998 |
|
| 999 |
|
| 1000 |
if (wc->numspans == 2) |
| 1001 |
slot = (fidx - 1) & 3; |
| 1002 |
else |
| 1003 |
slot = fidx; |
| 1004 |
spin_lock_irqsave(&wc->reglock, flags); |
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
__t43x_framer_set(wc, fidx, 0x46, 0xc0); |
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
__t43x_framer_set(wc, fidx, 0x3e, 0xc2); |
| 1016 |
|
| 1017 |
__t43x_framer_set(wc, fidx, 0x3f, (slot << 1)); |
| 1018 |
|
| 1019 |
|
| 1020 |
__t43x_framer_set(wc, fidx, 0x40, 0x04); |
| 1021 |
|
| 1022 |
__t43x_framer_set(wc, fidx, 0x2a, 0x06); |
| 1023 |
|
| 1024 |
#ifndef RPC_RCLK |
| 1025 |
|
| 1026 |
__t43x_framer_set(wc, fidx, 0x44, 0x30); |
| 1027 |
#else |
| 1028 |
|
| 1029 |
|
| 1030 |
__t43x_framer_set(wc, fidx, 0x44, 0x38 | (fidx << 6)); |
| 1031 |
#endif |
| 1032 |
|
| 1033 |
|
| 1034 |
__t43x_framer_set(wc, fidx, 0x45, 0x00); |
| 1035 |
|
| 1036 |
|
| 1037 |
__t43x_framer_set(wc, fidx, 0x22, 0x07); |
| 1038 |
__t43x_framer_set(wc, fidx, 0x23, 0xfa); |
| 1039 |
|
| 1040 |
__t43x_framer_set(wc, fidx, 0x24, 0x07); |
| 1041 |
__t43x_framer_set(wc, fidx, 0x25, 0xfa); |
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
__t43x_framer_set(wc, fidx, 0x80, 0x00); |
| 1046 |
|
| 1047 |
__t43x_framer_set(wc, fidx, 0x81, 0xBB); |
| 1048 |
#ifndef RPC_RCLK |
| 1049 |
|
| 1050 |
__t43x_framer_set(wc, fidx, 0x82, 0xBB); |
| 1051 |
#else |
| 1052 |
|
| 1053 |
__t43x_framer_set(wc, fidx, 0x82, 0xFB); |
| 1054 |
#endif |
| 1055 |
|
| 1056 |
__t43x_framer_set(wc, fidx, 0x83, 0xBB); |
| 1057 |
|
| 1058 |
__t43x_framer_set(wc, fidx, 0x84, 0x01); |
| 1059 |
__t43x_framer_set(wc, fidx, 0x3b, 0x00); |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
__t43x_framer_set(wc, fidx, 0x1c, 0xf0); |
| 1066 |
__t43x_framer_set(wc, fidx, 0x1d, 0x9c); |
| 1067 |
__t43x_framer_set(wc, fidx, 0x1e, 0x20); |
| 1068 |
__t43x_framer_set(wc, fidx, 0x20, 0x0c); |
| 1069 |
|
| 1070 |
__t43x_framer_set(wc, fidx, 0x21, 0x40); |
| 1071 |
|
| 1072 |
__t43x_framer_set(wc, fidx, 0x36, 0x08); |
| 1073 |
__t43x_framer_set(wc, fidx, 0x37, 0xf0); |
| 1074 |
__t43x_framer_set(wc, fidx, 0x3a, 0x21); |
| 1075 |
|
| 1076 |
__t43x_framer_set(wc, fidx, 0x02, 0x50); |
| 1077 |
__t43x_framer_set(wc, fidx, 0x02, 0x00); |
| 1078 |
|
| 1079 |
__t43x_framer_set(wc, fidx, 0x38, 0x0a); |
| 1080 |
__t43x_framer_set(wc, fidx, 0x39, 0x15); |
| 1081 |
|
| 1082 |
__t43x_framer_set(wc, fidx, 0x28, 0x40); |
| 1083 |
|
| 1084 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 1085 |
} |
| 1086 |
} |
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
static void t43x_span_assigned(struct dahdi_span *span) |
| 1101 |
{ |
| 1102 |
struct t43x_span *tspan = container_of(span, struct t43x_span, span); |
| 1103 |
struct t43x *wc = tspan->owner; |
| 1104 |
struct dahdi_span *pos; |
| 1105 |
unsigned int unassigned_spans = 0; |
| 1106 |
|
| 1107 |
if (debug) |
| 1108 |
dev_info(&wc->xb.pdev->dev, "%s\n", __func__); |
| 1109 |
|
| 1110 |
span->alarms = DAHDI_ALARM_NONE; |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
list_for_each_entry(pos, &wc->ddev->spans, device_node) { |
| 1115 |
if (!test_bit(DAHDI_FLAGBIT_REGISTERED, &pos->flags)) |
| 1116 |
++unassigned_spans; |
| 1117 |
} |
| 1118 |
|
| 1119 |
if (0 == unassigned_spans) { |
| 1120 |
|
| 1121 |
|
| 1122 |
t43x_serial_setup(wc); |
| 1123 |
} |
| 1124 |
} |
| 1125 |
|
| 1126 |
static int syncsrc; |
| 1127 |
static int syncnum; |
| 1128 |
static int syncspan; |
| 1129 |
static DEFINE_SPINLOCK(synclock); |
| 1130 |
|
| 1131 |
static void __t43x_set_rclk_src(struct t43x *wc, int span) |
| 1132 |
{ |
| 1133 |
#ifndef RPC_RCLK |
| 1134 |
int cmr1 = 0x38; |
| 1135 |
|
| 1136 |
int fidx; |
| 1137 |
|
| 1138 |
if (2 == wc->numspans) { |
| 1139 |
u8 reg; |
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
fidx = span+1; |
| 1149 |
|
| 1150 |
reg = __t43x_framer_get(wc, fidx, 0x1d); |
| 1151 |
__t43x_framer_set(wc, 0, 0x1d, reg); |
| 1152 |
|
| 1153 |
reg = __t43x_framer_get(wc, fidx, 0x1e); |
| 1154 |
__t43x_framer_set(wc, 0, 0x1e, reg); |
| 1155 |
|
| 1156 |
} else { |
| 1157 |
fidx = span; |
| 1158 |
} |
| 1159 |
|
| 1160 |
cmr1 |= (fidx) << 6; |
| 1161 |
__t43x_framer_set(wc, 0, 0x44, cmr1); |
| 1162 |
#else |
| 1163 |
int fidx = (2 == wc->numspans) ? span+1 : span; |
| 1164 |
int gpc1 = __t43x_framer_get(wc, 0, 0x85); |
| 1165 |
|
| 1166 |
gpc1 &= ~3; |
| 1167 |
gpc1 |= fidx & 3; |
| 1168 |
|
| 1169 |
t43x_framer_set(wc, 0, 0x85, gpc1); |
| 1170 |
#endif |
| 1171 |
dev_info(&wc->xb.pdev->dev, "RCLK source set to span %d\n", span+1); |
| 1172 |
} |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
static void t43x_clksrc_work_fn(struct work_struct *data) |
| 1177 |
{ |
| 1178 |
struct t43x_clksrc_work *work = container_of(data, |
| 1179 |
struct t43x_clksrc_work, work.work); |
| 1180 |
struct t43x *wc = container_of(work, struct t43x, clksrc_work); |
| 1181 |
|
| 1182 |
if (debug) { |
| 1183 |
dev_info(&wc->xb.pdev->dev, |
| 1184 |
"t43x_clksrc_work() called from queue\n"); |
| 1185 |
} |
| 1186 |
|
| 1187 |
if (wcxb_is_stopped(&wc->xb)) { |
| 1188 |
|
| 1189 |
|
| 1190 |
if (work->is_timing_master) |
| 1191 |
wcxb_enable_timing_header_driver(&wc->xb); |
| 1192 |
else |
| 1193 |
wcxb_disable_timing_header_driver(&wc->xb); |
| 1194 |
wcxb_set_clksrc(&wc->xb, work->clksrc); |
| 1195 |
|
| 1196 |
|
| 1197 |
wcxb_start(&wc->xb); |
| 1198 |
} else { |
| 1199 |
|
| 1200 |
wcxb_stop_dma(&wc->xb); |
| 1201 |
queue_delayed_work(wc->wq, &work->work, msecs_to_jiffies(10)); |
| 1202 |
} |
| 1203 |
} |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
static void |
| 1217 |
__t43x_set_sclk_src(struct t43x *wc, enum wcxb_clock_sources mode, bool master) |
| 1218 |
{ |
| 1219 |
struct t43x_clksrc_work *const work = &wc->clksrc_work; |
| 1220 |
unsigned long flags; |
| 1221 |
bool changed = false; |
| 1222 |
|
| 1223 |
|
| 1224 |
WARN_ON(master && (mode == WCXB_CLOCK_SLAVE)); |
| 1225 |
|
| 1226 |
spin_lock_irqsave(&work->lock, flags); |
| 1227 |
if (!delayed_work_pending(&work->work)) { |
| 1228 |
|
| 1229 |
changed = (wcxb_get_clksrc(&wc->xb) != mode) || |
| 1230 |
(wcxb_is_timing_header_driver_enabled(&wc->xb) != master); |
| 1231 |
} else { |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
changed = (work->clksrc != mode) || |
| 1236 |
(work->is_timing_master != master); |
| 1237 |
} |
| 1238 |
if (changed) { |
| 1239 |
work->clksrc = mode; |
| 1240 |
work->is_timing_master = master; |
| 1241 |
} |
| 1242 |
spin_unlock_irqrestore(&work->lock, flags); |
| 1243 |
|
| 1244 |
if (!changed) { |
| 1245 |
if (debug) |
| 1246 |
dev_info(&wc->xb.pdev->dev, "Clock source is unchanged\n"); |
| 1247 |
return; |
| 1248 |
} |
| 1249 |
|
| 1250 |
wcxb_stop_dma(&wc->xb); |
| 1251 |
|
| 1252 |
dev_dbg(&wc->xb.pdev->dev, |
| 1253 |
"Queueing delayed work for clock source change\n"); |
| 1254 |
|
| 1255 |
queue_delayed_work(wc->wq, &work->work, msecs_to_jiffies(10)); |
| 1256 |
} |
| 1257 |
|
| 1258 |
static ssize_t t43x_timing_master_show(struct device *dev, |
| 1259 |
struct device_attribute *attr, |
| 1260 |
char *buf) |
| 1261 |
{ |
| 1262 |
struct t43x *wc = dev_get_drvdata(dev); |
| 1263 |
|
| 1264 |
if (wcxb_is_timing_header_driver_enabled(&wc->xb)) |
| 1265 |
return sprintf(buf, "%d\n", wc->syncsrc); |
| 1266 |
else |
| 1267 |
return sprintf(buf, "%d\n", -1); |
| 1268 |
} |
| 1269 |
|
| 1270 |
static DEVICE_ATTR(timing_master, 0400, t43x_timing_master_show, NULL); |
| 1271 |
|
| 1272 |
static void create_sysfs_files(struct t43x *wc) |
| 1273 |
{ |
| 1274 |
int ret; |
| 1275 |
ret = device_create_file(&wc->xb.pdev->dev, |
| 1276 |
&dev_attr_timing_master); |
| 1277 |
if (ret) { |
| 1278 |
dev_info(&wc->xb.pdev->dev, |
| 1279 |
"Failed to create device attributes.\n"); |
| 1280 |
} |
| 1281 |
} |
| 1282 |
|
| 1283 |
static void remove_sysfs_files(struct t43x *wc) |
| 1284 |
{ |
| 1285 |
device_remove_file(&wc->xb.pdev->dev, &dev_attr_timing_master); |
| 1286 |
} |
| 1287 |
|
| 1288 |
static inline void __t43x_update_timing(struct t43x *wc) |
| 1289 |
{ |
| 1290 |
int i; |
| 1291 |
|
| 1292 |
|
| 1293 |
if (wc->syncsrc != syncsrc) { |
| 1294 |
dev_info(&wc->xb.pdev->dev, "Swapping card %d from %d to %d\n", |
| 1295 |
wc->num, wc->syncsrc, syncsrc); |
| 1296 |
wc->syncsrc = syncsrc; |
| 1297 |
|
| 1298 |
for (i = 0; i < wc->numspans; i++) |
| 1299 |
wc->tspans[i]->span.syncsrc = wc->syncsrc; |
| 1300 |
if (syncnum == wc->num) { |
| 1301 |
__t43x_set_rclk_src(wc, syncspan-1); |
| 1302 |
__t43x_set_sclk_src(wc, WCXB_CLOCK_RECOVER, 1); |
| 1303 |
if (debug) { |
| 1304 |
dev_notice(&wc->xb.pdev->dev, |
| 1305 |
"Card %d, using sync span %d, master\n", |
| 1306 |
wc->num, syncspan); |
| 1307 |
} |
| 1308 |
} else { |
| 1309 |
__t43x_set_sclk_src(wc, WCXB_CLOCK_SLAVE, 0); |
| 1310 |
if (debug) { |
| 1311 |
dev_notice(&wc->xb.pdev->dev, |
| 1312 |
"Card %d, using Timing Bus, NOT master\n", |
| 1313 |
wc->num); |
| 1314 |
} |
| 1315 |
} |
| 1316 |
} |
| 1317 |
} |
| 1318 |
|
| 1319 |
static int __t43x_findsync(struct t43x *wc) |
| 1320 |
{ |
| 1321 |
int i; |
| 1322 |
unsigned long flags; |
| 1323 |
int p; |
| 1324 |
int nonzero; |
| 1325 |
int newsyncsrc = 0; |
| 1326 |
int newsyncnum = 0; |
| 1327 |
int newsyncspan = 0; |
| 1328 |
struct t43x *cur; |
| 1329 |
|
| 1330 |
spin_lock_irqsave(&synclock, flags); |
| 1331 |
if (!wc->num) { |
| 1332 |
|
| 1333 |
|
| 1334 |
p = 1; |
| 1335 |
while (p < 8) { |
| 1336 |
nonzero = 0; |
| 1337 |
list_for_each_entry(cur, &card_list, card_node) { |
| 1338 |
for (i = 0; i < cur->numspans; i++) { |
| 1339 |
struct t43x_span *const ts = |
| 1340 |
cur->tspans[i]; |
| 1341 |
struct dahdi_span *const s = |
| 1342 |
&cur->tspans[i]->span; |
| 1343 |
if (!ts->syncpos) |
| 1344 |
continue; |
| 1345 |
nonzero = 1; |
| 1346 |
if ((ts->syncpos == p) && |
| 1347 |
!(s->alarms & NOSYNC_ALARMS) && |
| 1348 |
(s->flags & DAHDI_FLAG_RUNNING)) { |
| 1349 |
|
| 1350 |
|
| 1351 |
newsyncsrc = s->spanno; |
| 1352 |
newsyncnum = cur->num; |
| 1353 |
newsyncspan = i + 1; |
| 1354 |
|
| 1355 |
goto found; |
| 1356 |
} |
| 1357 |
} |
| 1358 |
} |
| 1359 |
if (nonzero) |
| 1360 |
p++; |
| 1361 |
else |
| 1362 |
break; |
| 1363 |
} |
| 1364 |
found: |
| 1365 |
if ((syncnum != newsyncnum) || |
| 1366 |
(syncsrc != newsyncsrc) || |
| 1367 |
(newsyncspan != syncspan)) { |
| 1368 |
if (debug) { |
| 1369 |
dev_notice(&wc->xb.pdev->dev, |
| 1370 |
"New syncnum: %d (was %d), syncsrc: %d (was %d), syncspan: %d (was %d)\n", |
| 1371 |
newsyncnum, syncnum, newsyncsrc, |
| 1372 |
syncsrc, newsyncspan, syncspan); |
| 1373 |
} |
| 1374 |
syncnum = newsyncnum; |
| 1375 |
syncsrc = newsyncsrc; |
| 1376 |
syncspan = newsyncspan; |
| 1377 |
nonzero = 0; |
| 1378 |
list_for_each_entry(cur, &card_list, card_node) |
| 1379 |
__t43x_update_timing(cur); |
| 1380 |
} |
| 1381 |
} |
| 1382 |
__t43x_update_timing(wc); |
| 1383 |
spin_unlock_irqrestore(&synclock, flags); |
| 1384 |
return 0; |
| 1385 |
} |
| 1386 |
|
| 1387 |
static void __t43x_set_timing_source_auto(struct t43x *wc) |
| 1388 |
{ |
| 1389 |
int x, i; |
| 1390 |
int firstprio, secondprio; |
| 1391 |
firstprio = secondprio = 4; |
| 1392 |
|
| 1393 |
if (debug) |
| 1394 |
dev_info(&wc->xb.pdev->dev, "timing source auto\n"); |
| 1395 |
|
| 1396 |
if (timingcable) { |
| 1397 |
__t43x_findsync(wc); |
| 1398 |
} else { |
| 1399 |
if (debug) |
| 1400 |
dev_info(&wc->xb.pdev->dev, |
| 1401 |
"Evaluating spans for timing source\n"); |
| 1402 |
for (x = 0; x < wc->numspans; x++) { |
| 1403 |
if ((wc->tspans[x]->span.flags & DAHDI_FLAG_RUNNING) && |
| 1404 |
!(wc->tspans[x]->span.alarms & (DAHDI_ALARM_RED | |
| 1405 |
DAHDI_ALARM_BLUE))) { |
| 1406 |
if (debug) { |
| 1407 |
dev_info(&wc->xb.pdev->dev, |
| 1408 |
"span %d is green : syncpos %d\n", |
| 1409 |
x+1, wc->tspans[x]->syncpos); |
| 1410 |
} |
| 1411 |
if (wc->tspans[x]->syncpos) { |
| 1412 |
|
| 1413 |
|
| 1414 |
if (firstprio == 4) |
| 1415 |
firstprio = x; |
| 1416 |
else if (wc->tspans[x]->syncpos < |
| 1417 |
wc->tspans[firstprio]->syncpos) |
| 1418 |
firstprio = x; |
| 1419 |
} else { |
| 1420 |
|
| 1421 |
|
| 1422 |
if (secondprio == 4) |
| 1423 |
secondprio = x; |
| 1424 |
} |
| 1425 |
} |
| 1426 |
} |
| 1427 |
if (firstprio != 4) { |
| 1428 |
wc->syncsrc = firstprio; |
| 1429 |
__t43x_set_rclk_src(wc, firstprio); |
| 1430 |
__t43x_set_sclk_src(wc, WCXB_CLOCK_RECOVER, 0); |
| 1431 |
dev_info(&wc->xb.pdev->dev, |
| 1432 |
"Recovered timing mode, RCLK set to span %d\n", |
| 1433 |
firstprio+1); |
| 1434 |
} else if (secondprio != 4) { |
| 1435 |
wc->syncsrc = -1; |
| 1436 |
__t43x_set_rclk_src(wc, secondprio); |
| 1437 |
__t43x_set_sclk_src(wc, WCXB_CLOCK_SELF, 0); |
| 1438 |
dev_info(&wc->xb.pdev->dev, |
| 1439 |
"System timing mode, RCLK set to span %d\n", |
| 1440 |
secondprio+1); |
| 1441 |
} else { |
| 1442 |
wc->syncsrc = -1; |
| 1443 |
dev_info(&wc->xb.pdev->dev, |
| 1444 |
"All spans in alarm : No valid span to source RCLK from\n"); |
| 1445 |
|
| 1446 |
__t43x_set_rclk_src(wc, 0); |
| 1447 |
__t43x_set_sclk_src(wc, WCXB_CLOCK_SELF, 0); |
| 1448 |
} |
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
for (i = 0; i < wc->numspans; i++) |
| 1454 |
wc->tspans[i]->span.syncsrc = wc->syncsrc + 1; |
| 1455 |
} |
| 1456 |
} |
| 1457 |
|
| 1458 |
static void |
| 1459 |
t43x_configure_t1(struct t43x *wc, int span_idx, int lineconfig, int txlevel) |
| 1460 |
{ |
| 1461 |
struct t43x_span *ts = wc->tspans[span_idx]; |
| 1462 |
int fidx = (wc->numspans == 2) ? span_idx+1 : span_idx; |
| 1463 |
unsigned int fmr4, fmr2, fmr1, fmr0, lim2; |
| 1464 |
char *framing, *line; |
| 1465 |
int mytxlevel, reg; |
| 1466 |
unsigned long flags; |
| 1467 |
|
| 1468 |
if ((txlevel > 7) || (txlevel < 4)) |
| 1469 |
mytxlevel = 0; |
| 1470 |
else |
| 1471 |
mytxlevel = txlevel - 4; |
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
fmr1 = 0x9c; |
| 1476 |
|
| 1477 |
fmr2 = 0x20; |
| 1478 |
|
| 1479 |
if (SPANTYPE_DIGITAL_J1 == ts->span.spantype) { |
| 1480 |
fmr4 = 0x1c; |
| 1481 |
} else { |
| 1482 |
|
| 1483 |
fmr4 = 0x0c; |
| 1484 |
} |
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
lim2 = 0x23; |
| 1489 |
|
| 1490 |
lim2 |= (mytxlevel << 6); |
| 1491 |
|
| 1492 |
spin_lock_irqsave(&wc->reglock, flags); |
| 1493 |
|
| 1494 |
__t43x_framer_set(wc, fidx, 0x1d, fmr1); |
| 1495 |
__t43x_framer_set(wc, fidx, 0x1e, fmr2); |
| 1496 |
|
| 1497 |
|
| 1498 |
if (lineconfig & DAHDI_CONFIG_AMI) { |
| 1499 |
line = "AMI"; |
| 1500 |
|
| 1501 |
|
| 1502 |
fmr0 = 0xb0; |
| 1503 |
} else { |
| 1504 |
line = "B8ZS"; |
| 1505 |
fmr0 = 0xf0; |
| 1506 |
} |
| 1507 |
if (lineconfig & DAHDI_CONFIG_D4) { |
| 1508 |
framing = "D4"; |
| 1509 |
} else { |
| 1510 |
framing = "ESF"; |
| 1511 |
fmr4 |= 0x2; |
| 1512 |
fmr2 |= 0xc0; |
| 1513 |
} |
| 1514 |
|
| 1515 |
|
| 1516 |
__t43x_framer_set(wc, fidx, 0x09, 0x80); |
| 1517 |
__t43x_framer_set(wc, fidx, 0x1c, fmr0); |
| 1518 |
|
| 1519 |
__t43x_framer_set(wc, fidx, 0x20, fmr4); |
| 1520 |
|
| 1521 |
__t43x_framer_set(wc, fidx, 0x21, 0x40); |
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
__t43x_framer_set(wc, fidx, 0x37, 0xf0); |
| 1526 |
|
| 1527 |
__t43x_framer_set(wc, fidx, 0x36, 0x08); |
| 1528 |
|
| 1529 |
|
| 1530 |
__t43x_framer_set(wc, fidx, 0x02, 0x50); |
| 1531 |
|
| 1532 |
__t43x_framer_set(wc, fidx, 0x02, 0x00); |
| 1533 |
if (debug) { |
| 1534 |
dev_info(&wc->xb.pdev->dev, |
| 1535 |
"card %d span %d: setting Rtx to 0ohm for T1\n", |
| 1536 |
wc->num, span_idx); |
| 1537 |
} |
| 1538 |
|
| 1539 |
__t43x_framer_set(wc, fidx, 0x86, 0x00); |
| 1540 |
|
| 1541 |
|
| 1542 |
__t43x_framer_set(wc, fidx, 0xbd, 0x05); |
| 1543 |
|
| 1544 |
|
| 1545 |
__t43x_framer_set(wc, fidx, 0x3a, lim2); |
| 1546 |
|
| 1547 |
__t43x_framer_set(wc, fidx, 0x38, 0x0a); |
| 1548 |
|
| 1549 |
__t43x_framer_set(wc, fidx, 0x39, 0x15); |
| 1550 |
|
| 1551 |
reg = __t43x_framer_get(wc, fidx, 0x24); |
| 1552 |
if (SPANTYPE_DIGITAL_J1 == ts->span.spantype) { |
| 1553 |
|
| 1554 |
__t43x_framer_set(wc, fidx, 0x24, reg | 0x80); |
| 1555 |
} else { |
| 1556 |
|
| 1557 |
__t43x_framer_set(wc, fidx, 0x24, reg & ~0x80); |
| 1558 |
} |
| 1559 |
|
| 1560 |
|
| 1561 |
switch (mytxlevel) { |
| 1562 |
case 3: |
| 1563 |
__t43x_framer_set(wc, fidx, 0x26, 0x07); |
| 1564 |
__t43x_framer_set(wc, fidx, 0x27, 0x01); |
| 1565 |
__t43x_framer_set(wc, fidx, 0x28, 0x00); |
| 1566 |
break; |
| 1567 |
case 2: |
| 1568 |
__t43x_framer_set(wc, fidx, 0x26, 0x8c); |
| 1569 |
__t43x_framer_set(wc, fidx, 0x27, 0x11); |
| 1570 |
__t43x_framer_set(wc, fidx, 0x28, 0x01); |
| 1571 |
break; |
| 1572 |
case 1: |
| 1573 |
__t43x_framer_set(wc, fidx, 0x26, 0x8c); |
| 1574 |
__t43x_framer_set(wc, fidx, 0x27, 0x01); |
| 1575 |
__t43x_framer_set(wc, fidx, 0x28, 0x00); |
| 1576 |
break; |
| 1577 |
case 0: |
| 1578 |
default: |
| 1579 |
__t43x_framer_set(wc, fidx, 0x26, 0x1a); |
| 1580 |
__t43x_framer_set(wc, fidx, 0x27, 0x27); |
| 1581 |
__t43x_framer_set(wc, fidx, 0x28, 0x01); |
| 1582 |
break; |
| 1583 |
} |
| 1584 |
|
| 1585 |
__t43x_framer_set(wc, fidx, 0x14, 0xff); |
| 1586 |
__t43x_framer_set(wc, fidx, 0x15, 0xff); |
| 1587 |
|
| 1588 |
|
| 1589 |
__t43x_framer_set(wc, fidx, 0x16, 0x00); |
| 1590 |
|
| 1591 |
__t43x_framer_set(wc, fidx, 0x17, 0x34); |
| 1592 |
|
| 1593 |
__t43x_framer_set(wc, fidx, 0x18, 0x3f); |
| 1594 |
|
| 1595 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 1596 |
dev_info(&wc->xb.pdev->dev, "Span %d configured for %s/%s\n", |
| 1597 |
span_idx, framing, line); |
| 1598 |
} |
| 1599 |
|
| 1600 |
static void t43x_configure_e1(struct t43x *wc, int span_idx, int lineconfig) |
| 1601 |
{ |
| 1602 |
int fidx = (wc->numspans == 2) ? span_idx+1 : span_idx; |
| 1603 |
unsigned int fmr2, fmr1, fmr0; |
| 1604 |
unsigned int cas = 0; |
| 1605 |
unsigned int imr3extra = 0; |
| 1606 |
char *crc4 = ""; |
| 1607 |
char *framing, *line; |
| 1608 |
unsigned long flags; |
| 1609 |
|
| 1610 |
fmr1 = 0x44; |
| 1611 |
|
| 1612 |
fmr2 = 0x03; |
| 1613 |
|
| 1614 |
|
| 1615 |
if (lineconfig & DAHDI_CONFIG_CRC4) { |
| 1616 |
fmr1 |= 0x08; |
| 1617 |
fmr2 |= 0xc0; |
| 1618 |
crc4 = "/CRC4"; |
| 1619 |
} |
| 1620 |
|
| 1621 |
spin_lock_irqsave(&wc->reglock, flags); |
| 1622 |
|
| 1623 |
__t43x_framer_set(wc, fidx, 0x1d, fmr1); |
| 1624 |
__t43x_framer_set(wc, fidx, 0x1e, fmr2); |
| 1625 |
|
| 1626 |
|
| 1627 |
if (lineconfig & DAHDI_CONFIG_AMI) { |
| 1628 |
line = "AMI"; |
| 1629 |
|
| 1630 |
fmr0 = 0xb0; |
| 1631 |
} else { |
| 1632 |
line = "HDB3"; |
| 1633 |
fmr0 = 0xf0; |
| 1634 |
} |
| 1635 |
|
| 1636 |
if (lineconfig & DAHDI_CONFIG_CCS) { |
| 1637 |
framing = "CCS"; |
| 1638 |
imr3extra = 0x28; |
| 1639 |
} else { |
| 1640 |
framing = "CAS"; |
| 1641 |
cas = 0x40; |
| 1642 |
} |
| 1643 |
|
| 1644 |
__t43x_framer_set(wc, fidx, 0x1c, fmr0); |
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
__t43x_framer_set(wc, fidx, 0x37, 0xf0); |
| 1649 |
|
| 1650 |
|
| 1651 |
__t43x_framer_set(wc, fidx, 0x36, 0x08); |
| 1652 |
|
| 1653 |
|
| 1654 |
__t43x_framer_set(wc, fidx, 0x02, 0x50); |
| 1655 |
|
| 1656 |
__t43x_framer_set(wc, fidx, 0x02, 0x00); |
| 1657 |
if (debug) |
| 1658 |
dev_info(&wc->xb.pdev->dev, |
| 1659 |
"setting Rtx to 7.5ohm for E1\n"); |
| 1660 |
|
| 1661 |
__t43x_framer_set(wc, fidx, 0x86, 0x40); |
| 1662 |
|
| 1663 |
|
| 1664 |
__t43x_framer_set(wc, fidx, 0xbb, 0x17); |
| 1665 |
__t43x_framer_set(wc, fidx, 0xbc, 0x55); |
| 1666 |
__t43x_framer_set(wc, fidx, 0xbb, 0x97); |
| 1667 |
__t43x_framer_set(wc, fidx, 0xbb, 0x11); |
| 1668 |
__t43x_framer_set(wc, fidx, 0xbc, 0xaa); |
| 1669 |
__t43x_framer_set(wc, fidx, 0xbb, 0x91); |
| 1670 |
__t43x_framer_set(wc, fidx, 0xbb, 0x12); |
| 1671 |
__t43x_framer_set(wc, fidx, 0xbc, 0x55); |
| 1672 |
__t43x_framer_set(wc, fidx, 0xbb, 0x92); |
| 1673 |
__t43x_framer_set(wc, fidx, 0xbb, 0x0c); |
| 1674 |
__t43x_framer_set(wc, fidx, 0xbb, 0x00); |
| 1675 |
__t43x_framer_set(wc, fidx, 0xbb, 0x8c); |
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
__t43x_framer_set(wc, fidx, 0x3a, 0x22); |
| 1680 |
|
| 1681 |
|
| 1682 |
__t43x_framer_set(wc, fidx, 0x38, 0x0a); |
| 1683 |
|
| 1684 |
__t43x_framer_set(wc, fidx, 0x39, 0x15); |
| 1685 |
|
| 1686 |
|
| 1687 |
__t43x_framer_set(wc, fidx, 0x20, 0x9f); |
| 1688 |
|
| 1689 |
__t43x_framer_set(wc, fidx, 0x21, 0x1c|cas); |
| 1690 |
|
| 1691 |
|
| 1692 |
__t43x_framer_set(wc, fidx, 0x26, 0xb5); |
| 1693 |
__t43x_framer_set(wc, fidx, 0x27, 0x02); |
| 1694 |
__t43x_framer_set(wc, fidx, 0x28, 0x00); |
| 1695 |
|
| 1696 |
__t43x_framer_set(wc, fidx, 0x14, 0xff); |
| 1697 |
__t43x_framer_set(wc, fidx, 0x15, 0xff); |
| 1698 |
|
| 1699 |
__t43x_framer_set(wc, fidx, 0x16, 0x00); |
| 1700 |
__t43x_framer_set(wc, fidx, 0x17, 0x04 | imr3extra); |
| 1701 |
__t43x_framer_set(wc, fidx, 0x18, 0x3f); |
| 1702 |
|
| 1703 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 1704 |
dev_info(&wc->xb.pdev->dev, "Span configured for %s/%s%s\n", |
| 1705 |
framing, line, crc4); |
| 1706 |
} |
| 1707 |
|
| 1708 |
static bool have_open_channels(const struct t43x_span *ts) |
| 1709 |
{ |
| 1710 |
int x, j; |
| 1711 |
for (x = 0, j = 0; x < ts->span.channels; x++) { |
| 1712 |
const struct dahdi_chan *chan = ts->span.chans[x]; |
| 1713 |
if (test_bit(DAHDI_FLAGBIT_OPEN, &chan->flags) || |
| 1714 |
dahdi_have_netdev(chan)) |
| 1715 |
return true; |
| 1716 |
} |
| 1717 |
return false; |
| 1718 |
} |
| 1719 |
|
| 1720 |
static void t43x_framer_start(struct t43x *wc) |
| 1721 |
{ |
| 1722 |
int unit; |
| 1723 |
unsigned long flags; |
| 1724 |
int res; |
| 1725 |
|
| 1726 |
if (debug) |
| 1727 |
dev_info(&wc->xb.pdev->dev, "%s\n", __func__); |
| 1728 |
|
| 1729 |
|
| 1730 |
wcxb_disable_interrupts(&wc->xb); |
| 1731 |
|
| 1732 |
|
| 1733 |
wcxb_stop_dma(&wc->xb); |
| 1734 |
res = wcxb_wait_for_stop(&wc->xb, 50); |
| 1735 |
if (res) |
| 1736 |
dev_warn(&wc->xb.pdev->dev, "DMA engine did not stop.\n"); |
| 1737 |
|
| 1738 |
for (unit = 0; unit < wc->numspans; unit++) { |
| 1739 |
struct t43x_span *ts = wc->tspans[unit]; |
| 1740 |
if (dahdi_is_e1_span(&ts->span)) { |
| 1741 |
t43x_configure_e1(wc, unit, ts->span.lineconfig); |
| 1742 |
} else { |
| 1743 |
t43x_configure_t1(wc, unit, ts->span.lineconfig, |
| 1744 |
ts->span.txlevel); |
| 1745 |
} |
| 1746 |
t43x_set_cas_mode(wc, unit); |
| 1747 |
|
| 1748 |
set_bit(DAHDI_FLAGBIT_RUNNING, &ts->span.flags); |
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
ts->span.alarms |= DAHDI_ALARM_RED; |
| 1753 |
} |
| 1754 |
|
| 1755 |
for (unit = 0; unit < wc->numspans; unit++) { |
| 1756 |
|
| 1757 |
struct t43x_span *ts = wc->tspans[unit]; |
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
if (have_open_channels(ts)) |
| 1762 |
clear_bit(HAVE_OPEN_CHANNELS_FLAGBIT, &ts->bit_flags); |
| 1763 |
else |
| 1764 |
set_bit(HAVE_OPEN_CHANNELS_FLAGBIT, &ts->bit_flags); |
| 1765 |
|
| 1766 |
local_irq_save(flags); |
| 1767 |
t43x_check_alarms(wc, unit); |
| 1768 |
t43x_check_sigbits(wc, unit); |
| 1769 |
local_irq_restore(flags); |
| 1770 |
} |
| 1771 |
|
| 1772 |
dev_info(&wc->xb.pdev->dev, "Enabling DMA controller and interrupts\n"); |
| 1773 |
|
| 1774 |
|
| 1775 |
wcxb_start(&wc->xb); |
| 1776 |
|
| 1777 |
t43x_check_for_interrupts(wc); |
| 1778 |
|
| 1779 |
|
| 1780 |
wc->syncsrc = -1; |
| 1781 |
spin_lock_irqsave(&wc->reglock, flags); |
| 1782 |
__t43x_set_timing_source_auto(wc); |
| 1783 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 1784 |
|
| 1785 |
|
| 1786 |
for (unit = 0; unit < wc->numspans; unit++) { |
| 1787 |
struct t43x_span *ts = wc->tspans[unit]; |
| 1788 |
memset(&ts->span.count, 0, sizeof(ts->span.count)); |
| 1789 |
} |
| 1790 |
|
| 1791 |
|
| 1792 |
mod_timer(&wc->timer, jiffies); |
| 1793 |
} |
| 1794 |
|
| 1795 |
#ifndef RPC_RCLK |
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
static int t43x_check_spanconfig(const struct t43x *wc) |
| 1806 |
{ |
| 1807 |
unsigned int i; |
| 1808 |
bool span_1_is_e1; |
| 1809 |
|
| 1810 |
if (&te435 != wc->devtype) |
| 1811 |
return 0; |
| 1812 |
|
| 1813 |
span_1_is_e1 = dahdi_is_e1_span(&wc->tspans[0]->span); |
| 1814 |
|
| 1815 |
for (i = 1; i < wc->numspans; ++i) { |
| 1816 |
struct t43x_span *ts = wc->tspans[i]; |
| 1817 |
|
| 1818 |
|
| 1819 |
if (!ts->syncpos) |
| 1820 |
continue; |
| 1821 |
|
| 1822 |
if ((bool)dahdi_is_e1_span(&ts->span) == span_1_is_e1) |
| 1823 |
continue; |
| 1824 |
|
| 1825 |
dev_warn(&wc->xb.pdev->dev, |
| 1826 |
"Local span %d is configured as a sync source but the line mode does not match local span 1.\n", |
| 1827 |
ts->span.offset + 1); |
| 1828 |
dev_warn(&wc->xb.pdev->dev, |
| 1829 |
"Please configure local span 1 as a sync src and ensure all other local sync sources match the line config of span 1.\n"); |
| 1830 |
|
| 1831 |
return -EINVAL; |
| 1832 |
} |
| 1833 |
|
| 1834 |
return 0; |
| 1835 |
} |
| 1836 |
#endif |
| 1837 |
|
| 1838 |
static int t43x_startup(struct file *file, struct dahdi_span *span) |
| 1839 |
{ |
| 1840 |
struct t43x_span *ts = container_of(span, struct t43x_span, span); |
| 1841 |
struct t43x *wc = ts->owner; |
| 1842 |
|
| 1843 |
if (debug) |
| 1844 |
dev_info(&wc->xb.pdev->dev, "%s\n", __func__); |
| 1845 |
|
| 1846 |
#ifndef RPC_RCLK |
| 1847 |
if (t43x_check_spanconfig(wc)) |
| 1848 |
return -EINVAL; |
| 1849 |
#endif |
| 1850 |
|
| 1851 |
|
| 1852 |
dev_info(&wc->xb.pdev->dev, |
| 1853 |
"Calling startup (flags is %lu)\n", span->flags); |
| 1854 |
t43x_framer_start(wc); |
| 1855 |
|
| 1856 |
return 0; |
| 1857 |
} |
| 1858 |
|
| 1859 |
static inline bool is_initialized(struct t43x *wc) |
| 1860 |
{ |
| 1861 |
WARN_ON(wc->not_ready < 0); |
| 1862 |
return (wc->not_ready == 0); |
| 1863 |
} |
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
static int t43x_wait_for_ready(struct t43x *wc) |
| 1872 |
{ |
| 1873 |
while (!is_initialized(wc)) { |
| 1874 |
if (fatal_signal_pending(current)) |
| 1875 |
return -EIO; |
| 1876 |
msleep_interruptible(250); |
| 1877 |
} |
| 1878 |
return 0; |
| 1879 |
} |
| 1880 |
|
| 1881 |
static int t43x_chanconfig(struct file *file, |
| 1882 |
struct dahdi_chan *chan, int sigtype) |
| 1883 |
{ |
| 1884 |
struct t43x *wc = chan->pvt; |
| 1885 |
|
| 1886 |
if (file->f_flags & O_NONBLOCK && !is_initialized(wc)) |
| 1887 |
return -EAGAIN; |
| 1888 |
else |
| 1889 |
t43x_wait_for_ready(wc); |
| 1890 |
|
| 1891 |
if (test_bit(DAHDI_FLAGBIT_RUNNING, &chan->span->flags)) |
| 1892 |
t43x_set_cas_mode(wc, chan->span->offset); |
| 1893 |
return 0; |
| 1894 |
} |
| 1895 |
|
| 1896 |
static int t43x_rbsbits(struct dahdi_chan *chan, int bits) |
| 1897 |
{ |
| 1898 |
u_char m, c; |
| 1899 |
int n, b; |
| 1900 |
struct t43x *wc = chan->pvt; |
| 1901 |
struct t43x_span *ts = container_of(chan->span, struct t43x_span, span); |
| 1902 |
int fidx = (2 == wc->numspans) ? |
| 1903 |
chan->span->offset+1 : chan->span->offset; |
| 1904 |
unsigned long flags; |
| 1905 |
|
| 1906 |
if (dahdi_is_e1_span(&ts->span)) { |
| 1907 |
if (chan->chanpos == 16) |
| 1908 |
return 0; |
| 1909 |
|
| 1910 |
n = chan->chanpos - 1; |
| 1911 |
if (chan->chanpos > 15) |
| 1912 |
n--; |
| 1913 |
b = (n % 15); |
| 1914 |
spin_lock_irqsave(&wc->reglock, flags); |
| 1915 |
c = ts->txsigs[b]; |
| 1916 |
m = (n / 15) << 2; |
| 1917 |
c &= (0xf << m); |
| 1918 |
c |= (bits & 0xf) << (4 - m); |
| 1919 |
ts->txsigs[b] = c; |
| 1920 |
|
| 1921 |
__t43x_framer_set(wc, fidx, 0x71 + b, c); |
| 1922 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 1923 |
} else if (ts->span.lineconfig & DAHDI_CONFIG_D4) { |
| 1924 |
n = chan->chanpos - 1; |
| 1925 |
b = (n / 4); |
| 1926 |
spin_lock_irqsave(&wc->reglock, flags); |
| 1927 |
c = ts->txsigs[b]; |
| 1928 |
m = ((3 - (n % 4)) << 1); |
| 1929 |
c &= ~(0x3 << m); |
| 1930 |
c |= ((bits >> 2) & 0x3) << m; |
| 1931 |
ts->txsigs[b] = c; |
| 1932 |
|
| 1933 |
__t43x_framer_set(wc, fidx, 0x70 + b, c); |
| 1934 |
__t43x_framer_set(wc, fidx, 0x70 + b + 6, c); |
| 1935 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 1936 |
} else if (ts->span.lineconfig & DAHDI_CONFIG_ESF) { |
| 1937 |
n = chan->chanpos - 1; |
| 1938 |
b = (n / 2); |
| 1939 |
spin_lock_irqsave(&wc->reglock, flags); |
| 1940 |
c = ts->txsigs[b]; |
| 1941 |
m = ((n % 2) << 2); |
| 1942 |
c &= (0xf << m); |
| 1943 |
c |= (bits & 0xf) << (4 - m); |
| 1944 |
ts->txsigs[b] = c; |
| 1945 |
|
| 1946 |
__t43x_framer_set(wc, fidx, 0x70 + b, c); |
| 1947 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 1948 |
} |
| 1949 |
|
| 1950 |
return 0; |
| 1951 |
} |
| 1952 |
|
| 1953 |
static inline void t43x_dahdi_rbsbits(struct dahdi_chan *c, const int rxs) |
| 1954 |
{ |
| 1955 |
if (!(c->sig & DAHDI_SIG_CLEAR) && (c->rxsig != rxs)) |
| 1956 |
dahdi_rbsbits(c, rxs); |
| 1957 |
} |
| 1958 |
|
| 1959 |
static void t43x_check_sigbits(struct t43x *wc, int span_idx) |
| 1960 |
{ |
| 1961 |
int a, i, rxs; |
| 1962 |
struct t43x_span *ts = wc->tspans[span_idx]; |
| 1963 |
int fidx = (wc->numspans == 2) ? span_idx+1 : span_idx; |
| 1964 |
|
| 1965 |
if (dahdi_is_e1_span(&ts->span)) { |
| 1966 |
for (i = 0; i < 15; i++) { |
| 1967 |
a = t43x_framer_get(wc, fidx, 0x71 + i); |
| 1968 |
rxs = (a & 0xf); |
| 1969 |
t43x_dahdi_rbsbits(ts->span.chans[i+16], rxs); |
| 1970 |
|
| 1971 |
rxs = (a >> 4) & 0xf; |
| 1972 |
t43x_dahdi_rbsbits(ts->span.chans[i], rxs); |
| 1973 |
} |
| 1974 |
} else if (ts->span.lineconfig & DAHDI_CONFIG_D4) { |
| 1975 |
for (i = 0; i < 24; i += 4) { |
| 1976 |
a = t43x_framer_get(wc, fidx, 0x70 + (i>>2)); |
| 1977 |
rxs = (a & 0x3) << 2; |
| 1978 |
t43x_dahdi_rbsbits(ts->span.chans[i+3], rxs); |
| 1979 |
|
| 1980 |
rxs = (a & 0xc); |
| 1981 |
t43x_dahdi_rbsbits(ts->span.chans[i+2], rxs); |
| 1982 |
|
| 1983 |
rxs = (a >> 2) & 0xc; |
| 1984 |
t43x_dahdi_rbsbits(ts->span.chans[i+1], rxs); |
| 1985 |
|
| 1986 |
rxs = (a >> 4) & 0xc; |
| 1987 |
t43x_dahdi_rbsbits(ts->span.chans[i], rxs); |
| 1988 |
} |
| 1989 |
} else { |
| 1990 |
for (i = 0; i < 24; i += 2) { |
| 1991 |
a = t43x_framer_get(wc, fidx, 0x70 + (i>>1)); |
| 1992 |
rxs = (a & 0xf); |
| 1993 |
t43x_dahdi_rbsbits(ts->span.chans[i+1], rxs); |
| 1994 |
|
| 1995 |
rxs = (a >> 4) & 0xf; |
| 1996 |
t43x_dahdi_rbsbits(ts->span.chans[i], rxs); |
| 1997 |
} |
| 1998 |
} |
| 1999 |
} |
| 2000 |
|
| 2001 |
struct maint_work_struct { |
| 2002 |
struct work_struct work; |
| 2003 |
struct t43x *wc; |
| 2004 |
int cmd; |
| 2005 |
struct dahdi_span *span; |
| 2006 |
}; |
| 2007 |
|
| 2008 |
static void t43x_maint_work(struct work_struct *work) |
| 2009 |
{ |
| 2010 |
struct maint_work_struct *w = container_of(work, |
| 2011 |
struct maint_work_struct, work); |
| 2012 |
|
| 2013 |
struct t43x *wc = w->wc; |
| 2014 |
struct dahdi_span *span = w->span; |
| 2015 |
int reg = 0; |
| 2016 |
int cmd = w->cmd; |
| 2017 |
unsigned long flags; |
| 2018 |
int fidx = (wc->numspans == 2) ? span->offset+1 : span->offset; |
| 2019 |
|
| 2020 |
if (dahdi_is_e1_span(span)) { |
| 2021 |
switch (cmd) { |
| 2022 |
case DAHDI_MAINT_NONE: |
| 2023 |
dev_info(&wc->xb.pdev->dev, |
| 2024 |
"Clearing all maint modes\n"); |
| 2025 |
t43x_clear_maint(span); |
| 2026 |
break; |
| 2027 |
case DAHDI_MAINT_LOCALLOOP: |
| 2028 |
dev_info(&wc->xb.pdev->dev, |
| 2029 |
"Turning on local loopback\n"); |
| 2030 |
t43x_clear_maint(span); |
| 2031 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2032 |
reg = __t43x_framer_get(wc, fidx, LIM0); |
| 2033 |
if (reg < 0) { |
| 2034 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2035 |
goto cleanup; |
| 2036 |
} |
| 2037 |
__t43x_framer_set(wc, fidx, LIM0, reg | LIM0_LL); |
| 2038 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2039 |
break; |
| 2040 |
case DAHDI_MAINT_NETWORKLINELOOP: |
| 2041 |
dev_info(&wc->xb.pdev->dev, |
| 2042 |
"Turning on network line loopback\n"); |
| 2043 |
t43x_clear_maint(span); |
| 2044 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2045 |
reg = __t43x_framer_get(wc, fidx, LIM1); |
| 2046 |
if (reg < 0) { |
| 2047 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2048 |
goto cleanup; |
| 2049 |
} |
| 2050 |
__t43x_framer_set(wc, fidx, LIM1, reg | LIM1_RL); |
| 2051 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2052 |
break; |
| 2053 |
case DAHDI_MAINT_NETWORKPAYLOADLOOP: |
| 2054 |
dev_info(&wc->xb.pdev->dev, |
| 2055 |
"Turning on network payload loopback\n"); |
| 2056 |
t43x_clear_maint(span); |
| 2057 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2058 |
reg = __t43x_framer_get(wc, fidx, LIM1); |
| 2059 |
if (reg < 0) { |
| 2060 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2061 |
goto cleanup; |
| 2062 |
} |
| 2063 |
__t43x_framer_set(wc, fidx, LIM1, |
| 2064 |
reg | (LIM1_RL | LIM1_JATT)); |
| 2065 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2066 |
break; |
| 2067 |
case DAHDI_MAINT_FAS_DEFECT: |
| 2068 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 5)); |
| 2069 |
break; |
| 2070 |
case DAHDI_MAINT_MULTI_DEFECT: |
| 2071 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 4)); |
| 2072 |
break; |
| 2073 |
case DAHDI_MAINT_CRC_DEFECT: |
| 2074 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 3)); |
| 2075 |
break; |
| 2076 |
case DAHDI_MAINT_CAS_DEFECT: |
| 2077 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 2)); |
| 2078 |
break; |
| 2079 |
case DAHDI_MAINT_PRBS_DEFECT: |
| 2080 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 1)); |
| 2081 |
break; |
| 2082 |
case DAHDI_MAINT_BIPOLAR_DEFECT: |
| 2083 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 0)); |
| 2084 |
break; |
| 2085 |
default: |
| 2086 |
dev_info(&wc->xb.pdev->dev, |
| 2087 |
"Unknown E1 maint command: %d\n", cmd); |
| 2088 |
goto cleanup; |
| 2089 |
} |
| 2090 |
} else { |
| 2091 |
switch (cmd) { |
| 2092 |
case DAHDI_MAINT_NONE: |
| 2093 |
dev_info(&wc->xb.pdev->dev, |
| 2094 |
"Clearing all maint modes\n"); |
| 2095 |
t43x_clear_maint(span); |
| 2096 |
break; |
| 2097 |
case DAHDI_MAINT_LOCALLOOP: |
| 2098 |
dev_info(&wc->xb.pdev->dev, |
| 2099 |
"Turning on local loopback\n"); |
| 2100 |
t43x_clear_maint(span); |
| 2101 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2102 |
reg = __t43x_framer_get(wc, fidx, LIM0); |
| 2103 |
if (reg < 0) { |
| 2104 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2105 |
goto cleanup; |
| 2106 |
} |
| 2107 |
__t43x_framer_set(wc, fidx, LIM0, reg | LIM0_LL); |
| 2108 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2109 |
break; |
| 2110 |
case DAHDI_MAINT_NETWORKLINELOOP: |
| 2111 |
dev_info(&wc->xb.pdev->dev, |
| 2112 |
"Turning on network line loopback\n"); |
| 2113 |
t43x_clear_maint(span); |
| 2114 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2115 |
reg = __t43x_framer_get(wc, fidx, LIM1); |
| 2116 |
if (reg < 0) { |
| 2117 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2118 |
goto cleanup; |
| 2119 |
} |
| 2120 |
__t43x_framer_set(wc, fidx, LIM1, reg | LIM1_RL); |
| 2121 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2122 |
break; |
| 2123 |
case DAHDI_MAINT_NETWORKPAYLOADLOOP: |
| 2124 |
dev_info(&wc->xb.pdev->dev, |
| 2125 |
"Turning on network payload loopback\n"); |
| 2126 |
t43x_clear_maint(span); |
| 2127 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2128 |
reg = __t43x_framer_get(wc, fidx, LIM1); |
| 2129 |
if (reg < 0) { |
| 2130 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2131 |
goto cleanup; |
| 2132 |
} |
| 2133 |
__t43x_framer_set(wc, fidx, LIM1, |
| 2134 |
reg | (LIM1_RL | LIM1_JATT)); |
| 2135 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2136 |
break; |
| 2137 |
case DAHDI_MAINT_LOOPUP: |
| 2138 |
dev_info(&wc->xb.pdev->dev, |
| 2139 |
"Transmitting loopup code\n"); |
| 2140 |
t43x_clear_maint(span); |
| 2141 |
t43x_framer_set(wc, fidx, 0x21, 0x50); |
| 2142 |
break; |
| 2143 |
case DAHDI_MAINT_LOOPDOWN: |
| 2144 |
dev_info(&wc->xb.pdev->dev, |
| 2145 |
"Transmitting loopdown code\n"); |
| 2146 |
t43x_clear_maint(span); |
| 2147 |
t43x_framer_set(wc, fidx, 0x21, 0x60); |
| 2148 |
break; |
| 2149 |
case DAHDI_MAINT_FAS_DEFECT: |
| 2150 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 5)); |
| 2151 |
break; |
| 2152 |
case DAHDI_MAINT_MULTI_DEFECT: |
| 2153 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 4)); |
| 2154 |
break; |
| 2155 |
case DAHDI_MAINT_CRC_DEFECT: |
| 2156 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 3)); |
| 2157 |
break; |
| 2158 |
case DAHDI_MAINT_CAS_DEFECT: |
| 2159 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 2)); |
| 2160 |
break; |
| 2161 |
case DAHDI_MAINT_PRBS_DEFECT: |
| 2162 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 1)); |
| 2163 |
break; |
| 2164 |
case DAHDI_MAINT_BIPOLAR_DEFECT: |
| 2165 |
t43x_framer_set(wc, fidx, 0x1b, (1 << 0)); |
| 2166 |
break; |
| 2167 |
default: |
| 2168 |
dev_info(&wc->xb.pdev->dev, |
| 2169 |
"Unknown T1 maint command: %d\n", cmd); |
| 2170 |
return; |
| 2171 |
} |
| 2172 |
} |
| 2173 |
|
| 2174 |
|
| 2175 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2176 |
if (!span->maintstat) |
| 2177 |
span->alarms &= ~DAHDI_ALARM_LOOPBACK; |
| 2178 |
dahdi_alarm_notify(span); |
| 2179 |
__t43x_set_timing_source_auto(wc); |
| 2180 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2181 |
|
| 2182 |
cleanup: |
| 2183 |
kfree(w); |
| 2184 |
return; |
| 2185 |
} |
| 2186 |
|
| 2187 |
static int t43x_reset_counters(struct dahdi_span *span) |
| 2188 |
{ |
| 2189 |
struct t43x_span *ts = container_of(span, struct t43x_span, span); |
| 2190 |
memset(&ts->span.count, 0, sizeof(ts->span.count)); |
| 2191 |
return 0; |
| 2192 |
} |
| 2193 |
|
| 2194 |
static int t43x_maint(struct dahdi_span *span, int cmd) |
| 2195 |
{ |
| 2196 |
struct maint_work_struct *work; |
| 2197 |
struct t43x_span *ts = container_of(span, struct t43x_span, span); |
| 2198 |
struct t43x *wc = ts->owner; |
| 2199 |
|
| 2200 |
if (dahdi_is_e1_span(span)) { |
| 2201 |
switch (cmd) { |
| 2202 |
case DAHDI_MAINT_NONE: |
| 2203 |
case DAHDI_MAINT_LOCALLOOP: |
| 2204 |
case DAHDI_MAINT_NETWORKLINELOOP: |
| 2205 |
case DAHDI_MAINT_NETWORKPAYLOADLOOP: |
| 2206 |
case DAHDI_MAINT_FAS_DEFECT: |
| 2207 |
case DAHDI_MAINT_MULTI_DEFECT: |
| 2208 |
case DAHDI_MAINT_CRC_DEFECT: |
| 2209 |
case DAHDI_MAINT_CAS_DEFECT: |
| 2210 |
case DAHDI_MAINT_PRBS_DEFECT: |
| 2211 |
case DAHDI_MAINT_BIPOLAR_DEFECT: |
| 2212 |
break; |
| 2213 |
case DAHDI_MAINT_LOOPUP: |
| 2214 |
case DAHDI_MAINT_LOOPDOWN: |
| 2215 |
dev_info(&wc->xb.pdev->dev, |
| 2216 |
"Only local loop supported in E1 mode\n"); |
| 2217 |
return -ENOSYS; |
| 2218 |
case DAHDI_RESET_COUNTERS: |
| 2219 |
t43x_reset_counters(span); |
| 2220 |
return 0; |
| 2221 |
default: |
| 2222 |
dev_info(&wc->xb.pdev->dev, |
| 2223 |
"Unknown E1 maint command: %d\n", cmd); |
| 2224 |
return -ENOSYS; |
| 2225 |
} |
| 2226 |
} else { |
| 2227 |
switch (cmd) { |
| 2228 |
case DAHDI_MAINT_NONE: |
| 2229 |
case DAHDI_MAINT_LOCALLOOP: |
| 2230 |
case DAHDI_MAINT_NETWORKLINELOOP: |
| 2231 |
case DAHDI_MAINT_NETWORKPAYLOADLOOP: |
| 2232 |
case DAHDI_MAINT_LOOPUP: |
| 2233 |
case DAHDI_MAINT_LOOPDOWN: |
| 2234 |
case DAHDI_MAINT_FAS_DEFECT: |
| 2235 |
case DAHDI_MAINT_MULTI_DEFECT: |
| 2236 |
case DAHDI_MAINT_CRC_DEFECT: |
| 2237 |
case DAHDI_MAINT_CAS_DEFECT: |
| 2238 |
case DAHDI_MAINT_PRBS_DEFECT: |
| 2239 |
case DAHDI_MAINT_BIPOLAR_DEFECT: |
| 2240 |
break; |
| 2241 |
case DAHDI_RESET_COUNTERS: |
| 2242 |
t43x_reset_counters(span); |
| 2243 |
return 0; |
| 2244 |
default: |
| 2245 |
dev_info(&wc->xb.pdev->dev, |
| 2246 |
"Unknown T1 maint command: %d\n", cmd); |
| 2247 |
return -ENOSYS; |
| 2248 |
} |
| 2249 |
} |
| 2250 |
|
| 2251 |
work = kzalloc(sizeof(*work), GFP_ATOMIC); |
| 2252 |
if (!work) { |
| 2253 |
dev_info(&wc->xb.pdev->dev, |
| 2254 |
"Failed to allocate memory for workqueue\n"); |
| 2255 |
return -ENOMEM; |
| 2256 |
} |
| 2257 |
|
| 2258 |
work->span = span; |
| 2259 |
work->wc = wc; |
| 2260 |
work->cmd = cmd; |
| 2261 |
|
| 2262 |
INIT_WORK(&work->work, t43x_maint_work); |
| 2263 |
queue_work(wc->wq, &work->work); |
| 2264 |
return 0; |
| 2265 |
} |
| 2266 |
|
| 2267 |
static int t43x_clear_maint(struct dahdi_span *span) |
| 2268 |
{ |
| 2269 |
struct t43x_span *ts = container_of(span, struct t43x_span, span); |
| 2270 |
struct t43x *wc = ts->owner; |
| 2271 |
int reg = 0; |
| 2272 |
unsigned long flags; |
| 2273 |
int fidx = (wc->numspans == 2) ? span->offset+1 : span->offset; |
| 2274 |
|
| 2275 |
|
| 2276 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2277 |
reg = __t43x_framer_get(wc, fidx, LIM0); |
| 2278 |
if (reg < 0) { |
| 2279 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2280 |
return -EIO; |
| 2281 |
} |
| 2282 |
__t43x_framer_set(wc, fidx, LIM0, reg & ~LIM0_LL); |
| 2283 |
|
| 2284 |
|
| 2285 |
reg = __t43x_framer_get(wc, fidx, LIM1); |
| 2286 |
if (reg < 0) { |
| 2287 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2288 |
return -EIO; |
| 2289 |
} |
| 2290 |
__t43x_framer_set(wc, fidx, LIM1, reg & ~(LIM1_RL | LIM1_JATT)); |
| 2291 |
|
| 2292 |
|
| 2293 |
__t43x_framer_set(wc, fidx, 0x21, 0x40); |
| 2294 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2295 |
return 0; |
| 2296 |
} |
| 2297 |
|
| 2298 |
static int t43x_ioctl(struct dahdi_chan *chan, unsigned int cmd, |
| 2299 |
unsigned long data) |
| 2300 |
{ |
| 2301 |
struct t4_regs regs; |
| 2302 |
unsigned int x; |
| 2303 |
struct t43x *wc; |
| 2304 |
int fidx; |
| 2305 |
|
| 2306 |
switch (cmd) { |
| 2307 |
case WCT4_GET_REGS: |
| 2308 |
wc = chan->pvt; |
| 2309 |
fidx = (wc->numspans == 2) ? chan->span->offset+1 : |
| 2310 |
chan->span->offset; |
| 2311 |
for (x = 0; x < sizeof(regs.regs) / sizeof(regs.regs[0]); x++) |
| 2312 |
regs.regs[x] = t43x_framer_get(wc, fidx, x); |
| 2313 |
|
| 2314 |
if (copy_to_user((void __user *) data, ®s, sizeof(regs))) |
| 2315 |
return -EFAULT; |
| 2316 |
break; |
| 2317 |
default: |
| 2318 |
return -ENOTTY; |
| 2319 |
} |
| 2320 |
return 0; |
| 2321 |
} |
| 2322 |
|
| 2323 |
static void t43x_chan_set_sigcap(struct dahdi_span *span, int x) |
| 2324 |
{ |
| 2325 |
struct t43x_span *ts = container_of(span, struct t43x_span, span); |
| 2326 |
struct dahdi_chan *chan = ts->chans[x]; |
| 2327 |
|
| 2328 |
chan->sigcap = DAHDI_SIG_CLEAR; |
| 2329 |
|
| 2330 |
if (dahdi_is_e1_span(span)) { |
| 2331 |
|
| 2332 |
if (span->lineconfig & DAHDI_CONFIG_CCS) { |
| 2333 |
|
| 2334 |
chan->sigcap |= DAHDI_SIG_MTP2 | DAHDI_SIG_SF; |
| 2335 |
return; |
| 2336 |
} |
| 2337 |
|
| 2338 |
|
| 2339 |
if (x == 15) { |
| 2340 |
|
| 2341 |
ts->chans[15]->sigcap = 0; |
| 2342 |
ts->chans[15]->sig = 0; |
| 2343 |
return; |
| 2344 |
} |
| 2345 |
|
| 2346 |
chan->sigcap |= DAHDI_SIG_EM_E1 | DAHDI_SIG_FXSLS | |
| 2347 |
DAHDI_SIG_FXSGS | DAHDI_SIG_FXSKS | DAHDI_SIG_SF | |
| 2348 |
DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS | DAHDI_SIG_FXOKS | |
| 2349 |
DAHDI_SIG_CAS | DAHDI_SIG_DACS_RBS; |
| 2350 |
} else { |
| 2351 |
|
| 2352 |
chan->sigcap |= DAHDI_SIG_EM | DAHDI_SIG_FXSLS | |
| 2353 |
DAHDI_SIG_FXSGS | DAHDI_SIG_FXSKS | DAHDI_SIG_MTP2 | |
| 2354 |
DAHDI_SIG_SF | DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS | |
| 2355 |
DAHDI_SIG_FXOKS | DAHDI_SIG_CAS | DAHDI_SIG_DACS_RBS; |
| 2356 |
} |
| 2357 |
} |
| 2358 |
|
| 2359 |
static bool t43x_lineconfig_changed(struct t43x_span *ts, |
| 2360 |
const struct dahdi_lineconfig *lc) |
| 2361 |
{ |
| 2362 |
unsigned long flags; |
| 2363 |
bool result; |
| 2364 |
u32 crc = crc32(~0, lc, sizeof(*lc)); |
| 2365 |
|
| 2366 |
spin_lock_irqsave(&ts->owner->reglock, flags); |
| 2367 |
result = (crc != ts->lineconfig_fingerprint); |
| 2368 |
spin_unlock_irqrestore(&ts->owner->reglock, flags); |
| 2369 |
return result; |
| 2370 |
} |
| 2371 |
|
| 2372 |
static void t43x_save_lineconfig(struct t43x_span *ts, |
| 2373 |
const struct dahdi_lineconfig *lc) |
| 2374 |
{ |
| 2375 |
unsigned long flags; |
| 2376 |
u32 crc = crc32(~0, lc, sizeof(*lc)); |
| 2377 |
|
| 2378 |
spin_lock_irqsave(&ts->owner->reglock, flags); |
| 2379 |
ts->lineconfig_fingerprint = crc; |
| 2380 |
spin_unlock_irqrestore(&ts->owner->reglock, flags); |
| 2381 |
} |
| 2382 |
|
| 2383 |
static int |
| 2384 |
t43x_spanconfig(struct file *file, struct dahdi_span *span, |
| 2385 |
struct dahdi_lineconfig *lc) |
| 2386 |
{ |
| 2387 |
struct t43x_span *ts = container_of(span, struct t43x_span, span); |
| 2388 |
struct t43x *wc = ts->owner; |
| 2389 |
int i; |
| 2390 |
int res = 0; |
| 2391 |
|
| 2392 |
if (debug) |
| 2393 |
dev_info(&wc->xb.pdev->dev, "%s\n", __func__); |
| 2394 |
|
| 2395 |
if (file->f_flags & O_NONBLOCK) { |
| 2396 |
if (!is_initialized(wc)) |
| 2397 |
return -EAGAIN; |
| 2398 |
} else { |
| 2399 |
t43x_wait_for_ready(wc); |
| 2400 |
} |
| 2401 |
|
| 2402 |
if (lc->sync < 0) |
| 2403 |
lc->sync = 0; |
| 2404 |
if (lc->sync > wc->numspans) { |
| 2405 |
dev_warn(&wc->xb.pdev->dev, |
| 2406 |
"WARNING: Cannot set priority on span %d to %d. Please set to a number between 1 and %d\n", |
| 2407 |
span->spanno, lc->sync, wc->numspans); |
| 2408 |
lc->sync = 0; |
| 2409 |
} |
| 2410 |
|
| 2411 |
|
| 2412 |
for (i = 0; i < wc->numspans; i++) { |
| 2413 |
if (wc->tspans[i]->sync == span->spanno) |
| 2414 |
wc->tspans[i]->sync = 0; |
| 2415 |
} |
| 2416 |
|
| 2417 |
wc->tspans[span->offset]->syncpos = lc->sync; |
| 2418 |
|
| 2419 |
if (lc->sync) |
| 2420 |
wc->tspans[lc->sync - 1]->sync = span->spanno; |
| 2421 |
|
| 2422 |
|
| 2423 |
for (i = 0; i < span->channels; i++) |
| 2424 |
t43x_chan_set_sigcap(span, i); |
| 2425 |
|
| 2426 |
|
| 2427 |
if (test_bit(DAHDI_FLAGBIT_RUNNING, &span->flags) && |
| 2428 |
t43x_lineconfig_changed(ts, lc)) { |
| 2429 |
res = t43x_startup(file, span); |
| 2430 |
if (!res) |
| 2431 |
t43x_save_lineconfig(ts, lc); |
| 2432 |
} |
| 2433 |
return res; |
| 2434 |
} |
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
static int |
| 2441 |
t43x_init_one_span(struct t43x *wc, struct t43x_span *ts, enum linemode type) |
| 2442 |
{ |
| 2443 |
int x; |
| 2444 |
struct dahdi_chan *chans[32] = {NULL,}; |
| 2445 |
struct dahdi_echocan_state *ec[32] = {NULL,}; |
| 2446 |
unsigned long flags; |
| 2447 |
int res = 0; |
| 2448 |
|
| 2449 |
if (debug) |
| 2450 |
dev_info(&wc->xb.pdev->dev, "%s\n", __func__); |
| 2451 |
|
| 2452 |
for (x = 0; x < ((E1 == type) ? 31 : 24); x++) { |
| 2453 |
chans[x] = kzalloc(sizeof(*chans[x]), GFP_KERNEL); |
| 2454 |
ec[x] = kzalloc(sizeof(*ec[x]), GFP_KERNEL); |
| 2455 |
if (!chans[x] || !ec[x]) |
| 2456 |
goto error_exit; |
| 2457 |
} |
| 2458 |
|
| 2459 |
|
| 2460 |
disable_irq(wc->xb.pdev->irq); |
| 2461 |
|
| 2462 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2463 |
for (x = 0; x < ARRAY_SIZE(ts->chans); x++) { |
| 2464 |
kfree(ts->chans[x]); |
| 2465 |
kfree(ts->ec[x]); |
| 2466 |
ts->chans[x] = NULL; |
| 2467 |
ts->ec[x] = NULL; |
| 2468 |
} |
| 2469 |
memcpy(ts->chans, chans, sizeof(ts->chans)); |
| 2470 |
memcpy(ts->ec, ec, sizeof(ts->ec)); |
| 2471 |
|
| 2472 |
switch (type) { |
| 2473 |
case E1: |
| 2474 |
ts->span.channels = 31; |
| 2475 |
ts->span.spantype = SPANTYPE_DIGITAL_E1; |
| 2476 |
ts->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_HDB3 | |
| 2477 |
DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4; |
| 2478 |
ts->span.deflaw = DAHDI_LAW_ALAW; |
| 2479 |
break; |
| 2480 |
case T1: |
| 2481 |
ts->span.channels = 24; |
| 2482 |
ts->span.spantype = SPANTYPE_DIGITAL_T1; |
| 2483 |
ts->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS | |
| 2484 |
DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF; |
| 2485 |
ts->span.deflaw = DAHDI_LAW_MULAW; |
| 2486 |
break; |
| 2487 |
case J1: |
| 2488 |
ts->span.channels = 24; |
| 2489 |
ts->span.spantype = SPANTYPE_DIGITAL_J1; |
| 2490 |
ts->span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS | |
| 2491 |
DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF; |
| 2492 |
ts->span.deflaw = DAHDI_LAW_MULAW; |
| 2493 |
break; |
| 2494 |
default: |
| 2495 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2496 |
res = -EINVAL; |
| 2497 |
enable_irq(wc->xb.pdev->irq); |
| 2498 |
goto error_exit; |
| 2499 |
} |
| 2500 |
|
| 2501 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2502 |
|
| 2503 |
set_bit(DAHDI_FLAGBIT_RBS, &ts->span.flags); |
| 2504 |
for (x = 0; x < ts->span.channels; x++) { |
| 2505 |
snprintf(ts->chans[x]->name, sizeof(ts->chans[x]->name), |
| 2506 |
"%s/%d", ts->span.name, x + 1); |
| 2507 |
t43x_chan_set_sigcap(&ts->span, x); |
| 2508 |
ts->chans[x]->pvt = wc; |
| 2509 |
ts->chans[x]->chanpos = x + 1; |
| 2510 |
} |
| 2511 |
|
| 2512 |
t43x_reset_counters(&ts->span); |
| 2513 |
|
| 2514 |
|
| 2515 |
ts->span.alarms = DAHDI_ALARM_NONE; |
| 2516 |
|
| 2517 |
enable_irq(wc->xb.pdev->irq); |
| 2518 |
return 0; |
| 2519 |
|
| 2520 |
error_exit: |
| 2521 |
|
| 2522 |
for (x = 0; x < ARRAY_SIZE(chans); ++x) { |
| 2523 |
kfree(chans[x]); |
| 2524 |
kfree(ec[x]); |
| 2525 |
} |
| 2526 |
return res; |
| 2527 |
} |
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
static void t43x_init_spans(struct t43x *wc, enum linemode type) |
| 2534 |
{ |
| 2535 |
struct t43x_span *ts; |
| 2536 |
int x; |
| 2537 |
|
| 2538 |
if (debug) |
| 2539 |
dev_info(&wc->xb.pdev->dev, "%s\n", __func__); |
| 2540 |
|
| 2541 |
for (x = 0; x < wc->numspans; x++) { |
| 2542 |
ts = wc->tspans[x]; |
| 2543 |
sprintf(ts->span.name, |
| 2544 |
"WCTE%d/%d/%d", wc->numspans, wc->num, x + 1); |
| 2545 |
snprintf(ts->span.desc, sizeof(ts->span.desc) - 1, |
| 2546 |
"WCTE%d3X (PCI) Card %d Span %d", |
| 2547 |
wc->numspans, wc->num, x + 1); |
| 2548 |
|
| 2549 |
ts->span.chans = ts->chans; |
| 2550 |
ts->span.flags = DAHDI_FLAG_RBS; |
| 2551 |
ts->span.ops = &t43x_span_ops; |
| 2552 |
ts->span.offset = x; |
| 2553 |
|
| 2554 |
ts->owner = wc; |
| 2555 |
|
| 2556 |
t43x_init_one_span(wc, ts, type); |
| 2557 |
|
| 2558 |
list_add_tail(&ts->span.device_node, &wc->ddev->spans); |
| 2559 |
} |
| 2560 |
} |
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
static int t43x_set_linemode(struct dahdi_span *span, enum spantypes linemode) |
| 2573 |
{ |
| 2574 |
int res; |
| 2575 |
struct t43x_span *ts = container_of(span, struct t43x_span, span); |
| 2576 |
struct t43x *wc = ts->owner; |
| 2577 |
|
| 2578 |
if (debug) |
| 2579 |
dev_info(&wc->xb.pdev->dev, "%s\n", __func__); |
| 2580 |
|
| 2581 |
|
| 2582 |
if (span->spantype == linemode) { |
| 2583 |
ts->span.alarms = DAHDI_ALARM_NONE; |
| 2584 |
return 0; |
| 2585 |
} |
| 2586 |
|
| 2587 |
res = t43x_wait_for_ready(wc); |
| 2588 |
if (res) |
| 2589 |
return res; |
| 2590 |
|
| 2591 |
mutex_lock(&wc->lock); |
| 2592 |
|
| 2593 |
switch (linemode) { |
| 2594 |
case SPANTYPE_DIGITAL_T1: |
| 2595 |
dev_info(&wc->xb.pdev->dev, |
| 2596 |
"Changing from %s to T1 line mode.\n", |
| 2597 |
dahdi_spantype2str(span->spantype)); |
| 2598 |
res = t43x_init_one_span(wc, ts, T1); |
| 2599 |
break; |
| 2600 |
case SPANTYPE_DIGITAL_E1: |
| 2601 |
dev_info(&wc->xb.pdev->dev, |
| 2602 |
"Changing from %s to E1 line mode.\n", |
| 2603 |
dahdi_spantype2str(span->spantype)); |
| 2604 |
res = t43x_init_one_span(wc, ts, E1); |
| 2605 |
break; |
| 2606 |
case SPANTYPE_DIGITAL_J1: |
| 2607 |
dev_info(&wc->xb.pdev->dev, |
| 2608 |
"Changing from %s to J1 line mode.\n", |
| 2609 |
dahdi_spantype2str(span->spantype)); |
| 2610 |
res = t43x_init_one_span(wc, ts, J1); |
| 2611 |
break; |
| 2612 |
default: |
| 2613 |
dev_err(&wc->xb.pdev->dev, |
| 2614 |
"Got invalid linemode '%s' from dahdi\n", |
| 2615 |
dahdi_spantype2str(linemode)); |
| 2616 |
res = -EINVAL; |
| 2617 |
} |
| 2618 |
|
| 2619 |
|
| 2620 |
|
| 2621 |
if (!res) |
| 2622 |
dahdi_init_span(span); |
| 2623 |
|
| 2624 |
mutex_unlock(&wc->lock); |
| 2625 |
return res; |
| 2626 |
} |
| 2627 |
|
| 2628 |
static int t43x_hardware_post_init(struct t43x *wc, enum linemode *type) |
| 2629 |
{ |
| 2630 |
int reg; |
| 2631 |
int x; |
| 2632 |
|
| 2633 |
if (!strcasecmp(default_linemode, "e1")) { |
| 2634 |
*type = E1; |
| 2635 |
} else if (!strcasecmp(default_linemode, "t1")) { |
| 2636 |
*type = T1; |
| 2637 |
} else if (!strcasecmp(default_linemode, "j1")) { |
| 2638 |
*type = J1; |
| 2639 |
} else { |
| 2640 |
dev_warn(&wc->xb.pdev->dev, |
| 2641 |
"'%s' is an unknown linemode. Defaulting to 't1'\n", |
| 2642 |
default_linemode); |
| 2643 |
*type = T1; |
| 2644 |
} |
| 2645 |
|
| 2646 |
if (debug) { |
| 2647 |
dev_info(&wc->xb.pdev->dev, "linemode: %s\n", |
| 2648 |
(*type == T1) ? "T1" : ((J1 == *type) ? "J1" : "E1")); |
| 2649 |
} |
| 2650 |
|
| 2651 |
|
| 2652 |
wcxb_gpio_set(&wc->xb, FALC_CPU_RESET); |
| 2653 |
reg = t43x_framer_get(wc, 0, 0x4a); |
| 2654 |
if (reg < 0) { |
| 2655 |
dev_info(&wc->xb.pdev->dev, |
| 2656 |
"Failed to read FALC version (%x)\n", reg); |
| 2657 |
return -EIO; |
| 2658 |
} |
| 2659 |
dev_info(&wc->xb.pdev->dev, "FALC version: %1x\n", reg); |
| 2660 |
|
| 2661 |
|
| 2662 |
for (x = 0; x < 256; x++) { |
| 2663 |
t43x_framer_set(wc, 0, 0x14, x); |
| 2664 |
reg = t43x_framer_get(wc, 0, 0x14); |
| 2665 |
if (reg < 0) { |
| 2666 |
dev_info(&wc->xb.pdev->dev, |
| 2667 |
"Failed register read (%d)\n", reg); |
| 2668 |
return -EIO; |
| 2669 |
} |
| 2670 |
if (reg != x) { |
| 2671 |
dev_info(&wc->xb.pdev->dev, |
| 2672 |
"Register test failed. Wrote '%x' but read '%x'\n", |
| 2673 |
x, reg); |
| 2674 |
return -EIO; |
| 2675 |
} |
| 2676 |
} |
| 2677 |
|
| 2678 |
|
| 2679 |
t43x_setleds(wc, -1); |
| 2680 |
|
| 2681 |
return 0; |
| 2682 |
} |
| 2683 |
|
| 2684 |
static void t43x_check_alarms(struct t43x *wc, int span_idx) |
| 2685 |
{ |
| 2686 |
struct t43x_span *ts = wc->tspans[span_idx]; |
| 2687 |
unsigned char c, d; |
| 2688 |
int alarms; |
| 2689 |
int fidx = (wc->numspans == 2) ? span_idx+1 : span_idx; |
| 2690 |
|
| 2691 |
if (!(test_bit(DAHDI_FLAGBIT_RUNNING, &ts->span.flags))) |
| 2692 |
return; |
| 2693 |
|
| 2694 |
spin_lock(&wc->reglock); |
| 2695 |
|
| 2696 |
c = __t43x_framer_get(wc, fidx, 0x4c); |
| 2697 |
d = __t43x_framer_get(wc, fidx, 0x4d); |
| 2698 |
|
| 2699 |
|
| 2700 |
alarms = ts->span.alarms; |
| 2701 |
|
| 2702 |
if (dahdi_is_e1_span(&ts->span)) { |
| 2703 |
if (c & 0x04) { |
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
if (!test_and_set_bit(NMF_FLAGBIT, &ts->bit_flags)) { |
| 2708 |
|
| 2709 |
__t43x_framer_set(wc, fidx, 0x20, 0x9f | 0x20); |
| 2710 |
dev_info(&wc->xb.pdev->dev, |
| 2711 |
"NMF workaround on!\n"); |
| 2712 |
} |
| 2713 |
|
| 2714 |
__t43x_framer_set(wc, fidx, 0x1e, 0xc3); |
| 2715 |
|
| 2716 |
__t43x_framer_set(wc, fidx, 0x1c, 0xf2); |
| 2717 |
|
| 2718 |
__t43x_framer_set(wc, fidx, 0x1c, 0xf0); |
| 2719 |
} else if (!(c & 0x02)) { |
| 2720 |
if (test_and_clear_bit(NMF_FLAGBIT, &ts->bit_flags)) { |
| 2721 |
|
| 2722 |
__t43x_framer_set(wc, fidx, 0x20, 0x9f); |
| 2723 |
dev_info(&wc->xb.pdev->dev, |
| 2724 |
"NMF workaround off!\n"); |
| 2725 |
} |
| 2726 |
} |
| 2727 |
} |
| 2728 |
|
| 2729 |
if (ts->span.lineconfig & DAHDI_CONFIG_NOTOPEN) { |
| 2730 |
if (!test_bit(HAVE_OPEN_CHANNELS_FLAGBIT, &ts->bit_flags)) |
| 2731 |
alarms |= DAHDI_ALARM_NOTOPEN; |
| 2732 |
else |
| 2733 |
alarms &= ~DAHDI_ALARM_NOTOPEN; |
| 2734 |
} |
| 2735 |
|
| 2736 |
if (c & 0x20) { |
| 2737 |
if (!(alarms & DAHDI_ALARM_RED) && (0 == ts->lofalarmtimer)) { |
| 2738 |
ts->lofalarmtimer = (jiffies + |
| 2739 |
msecs_to_jiffies(alarmdebounce)) ?: 1; |
| 2740 |
} |
| 2741 |
} else { |
| 2742 |
ts->lofalarmtimer = 0; |
| 2743 |
} |
| 2744 |
|
| 2745 |
if (c & 0x80) { |
| 2746 |
if (!(alarms & DAHDI_ALARM_RED) && (0 == ts->losalarmtimer)) { |
| 2747 |
ts->losalarmtimer = (jiffies + |
| 2748 |
msecs_to_jiffies(losalarmdebounce)) ?: 1; |
| 2749 |
} |
| 2750 |
} else { |
| 2751 |
ts->losalarmtimer = 0; |
| 2752 |
} |
| 2753 |
|
| 2754 |
if (!(c & (0x80|0x20))) |
| 2755 |
alarms &= ~DAHDI_ALARM_RED; |
| 2756 |
|
| 2757 |
if (c & 0x40) { |
| 2758 |
if (!(alarms & DAHDI_ALARM_BLUE) && (0 == ts->aisalarmtimer)) |
| 2759 |
ts->aisalarmtimer = (jiffies + |
| 2760 |
msecs_to_jiffies(aisalarmdebounce)) ?: 1; |
| 2761 |
} else { |
| 2762 |
ts->aisalarmtimer = 0; |
| 2763 |
alarms &= ~DAHDI_ALARM_BLUE; |
| 2764 |
} |
| 2765 |
|
| 2766 |
|
| 2767 |
if (alarms & (DAHDI_ALARM_RED|DAHDI_ALARM_BLUE|DAHDI_ALARM_NOTOPEN)) { |
| 2768 |
ts->recoverytimer = 0; |
| 2769 |
alarms &= ~DAHDI_ALARM_RECOVER; |
| 2770 |
} else if (ts->span.alarms & (DAHDI_ALARM_RED|DAHDI_ALARM_BLUE)) { |
| 2771 |
if (0 == ts->recoverytimer) { |
| 2772 |
ts->recoverytimer = (jiffies + 5*HZ) ?: 1; |
| 2773 |
alarms |= DAHDI_ALARM_RECOVER; |
| 2774 |
} |
| 2775 |
} |
| 2776 |
|
| 2777 |
if (c & 0x10) { |
| 2778 |
if (!(alarms & DAHDI_ALARM_YELLOW) && !ts->yelalarmtimer) { |
| 2779 |
ts->yelalarmtimer = (jiffies + |
| 2780 |
msecs_to_jiffies(yelalarmdebounce)) ?: 1; |
| 2781 |
} |
| 2782 |
} else { |
| 2783 |
ts->yelalarmtimer = 0; |
| 2784 |
alarms &= ~DAHDI_ALARM_YELLOW; |
| 2785 |
} |
| 2786 |
|
| 2787 |
if (ts->span.alarms != alarms) { |
| 2788 |
|
| 2789 |
if ((alarms ^ ts->span.alarms) & NOSYNC_ALARMS) { |
| 2790 |
ts->span.alarms = alarms; |
| 2791 |
__t43x_set_timing_source_auto(wc); |
| 2792 |
} else { |
| 2793 |
ts->span.alarms = alarms; |
| 2794 |
} |
| 2795 |
|
| 2796 |
spin_unlock(&wc->reglock); |
| 2797 |
|
| 2798 |
dahdi_alarm_notify(&ts->span); |
| 2799 |
} else { |
| 2800 |
spin_unlock(&wc->reglock); |
| 2801 |
} |
| 2802 |
} |
| 2803 |
|
| 2804 |
static void t43x_check_loopcodes(struct t43x *wc, int span_idx) |
| 2805 |
{ |
| 2806 |
struct t43x_span *ts = wc->tspans[span_idx]; |
| 2807 |
unsigned char frs1; |
| 2808 |
int fidx = (wc->numspans == 2) ? span_idx+1 : span_idx; |
| 2809 |
|
| 2810 |
frs1 = t43x_framer_get(wc, fidx, 0x4d); |
| 2811 |
|
| 2812 |
|
| 2813 |
if ((ts->span.maintstat != DAHDI_MAINT_LOOPUP) && (frs1 & 0x08)) { |
| 2814 |
|
| 2815 |
if ((ts->span.maintstat != DAHDI_MAINT_REMOTELOOP) && |
| 2816 |
(0 == ts->loopuptimer)) |
| 2817 |
ts->loopuptimer = (jiffies + msecs_to_jiffies(800)) | 1; |
| 2818 |
} else { |
| 2819 |
ts->loopuptimer = 0; |
| 2820 |
} |
| 2821 |
|
| 2822 |
|
| 2823 |
if ((ts->span.maintstat != DAHDI_MAINT_LOOPDOWN) && (frs1 & 0x10)) { |
| 2824 |
|
| 2825 |
if ((ts->span.maintstat == DAHDI_MAINT_REMOTELOOP) && |
| 2826 |
(0 == ts->loopdntimer)) |
| 2827 |
ts->loopdntimer = (jiffies + msecs_to_jiffies(800)) | 1; |
| 2828 |
} else { |
| 2829 |
ts->loopdntimer = 0; |
| 2830 |
} |
| 2831 |
} |
| 2832 |
|
| 2833 |
static void t43x_debounce_alarms(struct t43x *wc, int span_idx) |
| 2834 |
{ |
| 2835 |
struct t43x_span *ts = wc->tspans[span_idx]; |
| 2836 |
int alarms; |
| 2837 |
unsigned long flags; |
| 2838 |
unsigned int fmr4; |
| 2839 |
int fidx = (wc->numspans == 2) ? span_idx+1 : span_idx; |
| 2840 |
|
| 2841 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2842 |
alarms = ts->span.alarms; |
| 2843 |
|
| 2844 |
if (ts->lofalarmtimer && time_after(jiffies, ts->lofalarmtimer)) { |
| 2845 |
alarms |= DAHDI_ALARM_RED; |
| 2846 |
ts->lofalarmtimer = 0; |
| 2847 |
dev_info(&wc->xb.pdev->dev, "LOF alarm detected\n"); |
| 2848 |
} |
| 2849 |
|
| 2850 |
if (ts->losalarmtimer && time_after(jiffies, ts->losalarmtimer)) { |
| 2851 |
alarms |= DAHDI_ALARM_RED; |
| 2852 |
ts->losalarmtimer = 0; |
| 2853 |
dev_info(&wc->xb.pdev->dev, "LOS alarm detected\n"); |
| 2854 |
} |
| 2855 |
|
| 2856 |
if (ts->aisalarmtimer && time_after(jiffies, ts->aisalarmtimer)) { |
| 2857 |
alarms |= DAHDI_ALARM_BLUE; |
| 2858 |
ts->aisalarmtimer = 0; |
| 2859 |
dev_info(&wc->xb.pdev->dev, "AIS alarm detected\n"); |
| 2860 |
} |
| 2861 |
|
| 2862 |
if (ts->yelalarmtimer && time_after(jiffies, ts->yelalarmtimer)) { |
| 2863 |
alarms |= DAHDI_ALARM_YELLOW; |
| 2864 |
ts->yelalarmtimer = 0; |
| 2865 |
dev_info(&wc->xb.pdev->dev, "YEL alarm detected\n"); |
| 2866 |
} |
| 2867 |
|
| 2868 |
if (ts->recoverytimer && time_after(jiffies, ts->recoverytimer)) { |
| 2869 |
alarms &= ~(DAHDI_ALARM_RECOVER); |
| 2870 |
ts->recoverytimer = 0; |
| 2871 |
memset(&ts->span.count, 0, sizeof(ts->span.count)); |
| 2872 |
dev_info(&wc->xb.pdev->dev, "Alarms cleared\n"); |
| 2873 |
} |
| 2874 |
|
| 2875 |
if (alarms != ts->span.alarms) { |
| 2876 |
|
| 2877 |
if ((alarms ^ ts->span.alarms) & NOSYNC_ALARMS) { |
| 2878 |
ts->span.alarms = alarms; |
| 2879 |
__t43x_set_timing_source_auto(wc); |
| 2880 |
} else { |
| 2881 |
ts->span.alarms = alarms; |
| 2882 |
} |
| 2883 |
|
| 2884 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2885 |
dahdi_alarm_notify(&ts->span); |
| 2886 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2887 |
} |
| 2888 |
|
| 2889 |
|
| 2890 |
if (alarms & (DAHDI_ALARM_RED|DAHDI_ALARM_BLUE| |
| 2891 |
DAHDI_ALARM_NOTOPEN|DAHDI_ALARM_RECOVER)) { |
| 2892 |
if (!test_and_set_bit(SENDINGYELLOW_FLAGBIT, &ts->bit_flags)) { |
| 2893 |
dev_info(&wc->xb.pdev->dev, "Setting yellow alarm\n"); |
| 2894 |
|
| 2895 |
|
| 2896 |
fmr4 = __t43x_framer_get(wc, fidx, 0x20); |
| 2897 |
__t43x_framer_set(wc, fidx, 0x20, fmr4 | 0x20); |
| 2898 |
} |
| 2899 |
} else { |
| 2900 |
if (test_and_clear_bit(SENDINGYELLOW_FLAGBIT, &ts->bit_flags)) { |
| 2901 |
dev_info(&wc->xb.pdev->dev, "Clearing yellow alarm\n"); |
| 2902 |
|
| 2903 |
fmr4 = __t43x_framer_get(wc, fidx, 0x20); |
| 2904 |
__t43x_framer_set(wc, fidx, 0x20, fmr4 & ~0x20); |
| 2905 |
} |
| 2906 |
} |
| 2907 |
|
| 2908 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2909 |
} |
| 2910 |
|
| 2911 |
static void t43x_debounce_loopcodes(struct t43x *wc, int span_idx) |
| 2912 |
{ |
| 2913 |
struct t43x_span *ts = wc->tspans[span_idx]; |
| 2914 |
unsigned long flags; |
| 2915 |
int fidx = (wc->numspans == 2) ? span_idx+1 : span_idx; |
| 2916 |
|
| 2917 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2918 |
if (ts->loopuptimer && time_after(jiffies, ts->loopuptimer)) { |
| 2919 |
|
| 2920 |
dev_info(&wc->xb.pdev->dev, "Loopup detected, enabling remote loop\n"); |
| 2921 |
__t43x_framer_set(wc, fidx, 0x36, 0x08); |
| 2922 |
|
| 2923 |
__t43x_framer_set(wc, fidx, 0x37, 0xf6); |
| 2924 |
|
| 2925 |
ts->span.maintstat = DAHDI_MAINT_REMOTELOOP; |
| 2926 |
ts->loopuptimer = 0; |
| 2927 |
dahdi_alarm_notify(&ts->span); |
| 2928 |
__t43x_set_timing_source_auto(wc); |
| 2929 |
} |
| 2930 |
|
| 2931 |
if (ts->loopdntimer && time_after(jiffies, ts->loopdntimer)) { |
| 2932 |
|
| 2933 |
dev_info(&wc->xb.pdev->dev, "Loopdown detected, disabling remote loop\n"); |
| 2934 |
__t43x_framer_set(wc, fidx, 0x36, 0x08); |
| 2935 |
|
| 2936 |
__t43x_framer_set(wc, fidx, 0x37, 0xf0); |
| 2937 |
|
| 2938 |
ts->span.maintstat = DAHDI_MAINT_NONE; |
| 2939 |
ts->loopdntimer = 0; |
| 2940 |
dahdi_alarm_notify(&ts->span); |
| 2941 |
__t43x_set_timing_source_auto(wc); |
| 2942 |
} |
| 2943 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2944 |
} |
| 2945 |
|
| 2946 |
static void handle_leds(struct t43x *wc) |
| 2947 |
{ |
| 2948 |
u32 led = 0; |
| 2949 |
struct t43x_span *ts; |
| 2950 |
int span_idx; |
| 2951 |
|
| 2952 |
if (time_after(jiffies, wc->blinktimer)) { |
| 2953 |
wc->blink = !wc->blink; |
| 2954 |
wc->blinktimer = jiffies + HZ/2; |
| 2955 |
} |
| 2956 |
|
| 2957 |
for (span_idx = wc->numspans-1; span_idx >= 0; span_idx--) { |
| 2958 |
led >>= 2; |
| 2959 |
ts = wc->tspans[span_idx]; |
| 2960 |
if ((ts->span.alarms & (DAHDI_ALARM_RED | DAHDI_ALARM_BLUE)) || |
| 2961 |
ts->losalarmtimer) { |
| 2962 |
|
| 2963 |
|
| 2964 |
if (wc->blink) |
| 2965 |
led |= STATUS_LED_RED; |
| 2966 |
} else if (ts->span.alarms & DAHDI_ALARM_YELLOW) { |
| 2967 |
led |= STATUS_LED_YELLOW; |
| 2968 |
} else { |
| 2969 |
if (test_bit(DAHDI_FLAGBIT_RUNNING, &ts->span.flags)) |
| 2970 |
led |= STATUS_LED_GREEN; |
| 2971 |
} |
| 2972 |
} |
| 2973 |
|
| 2974 |
if (wc->numspans == 2) |
| 2975 |
led >>= 2; |
| 2976 |
|
| 2977 |
if (led != (ioread32be(wc->xb.membase) & LED_MASK)) |
| 2978 |
t43x_setleds(wc, led); |
| 2979 |
} |
| 2980 |
|
| 2981 |
static void t43x_handle_receive(struct wcxb *xb, void *vfp) |
| 2982 |
{ |
| 2983 |
int i, j, s; |
| 2984 |
u_char *frame = (u_char *) vfp; |
| 2985 |
struct t43x *wc = container_of(xb, struct t43x, xb); |
| 2986 |
struct t43x_span *ts; |
| 2987 |
|
| 2988 |
for (s = 0; s < wc->numspans; s++) { |
| 2989 |
ts = wc->tspans[s]; |
| 2990 |
if (!test_bit(DAHDI_FLAGBIT_REGISTERED, &ts->span.flags)) |
| 2991 |
continue; |
| 2992 |
|
| 2993 |
for (j = 0; j < DAHDI_CHUNKSIZE; j++) { |
| 2994 |
for (i = 0; i < ts->span.channels; i++) { |
| 2995 |
ts->chans[i]->readchunk[j] = |
| 2996 |
frame[j*WCXB_DMA_CHAN_SIZE+(s+1+i*4)]; |
| 2997 |
} |
| 2998 |
} |
| 2999 |
|
| 3000 |
if (0 == vpmsupport) { |
| 3001 |
for (i = 0; i < ts->span.channels; i++) { |
| 3002 |
struct dahdi_chan *const c = ts->span.chans[i]; |
| 3003 |
__dahdi_ec_chunk(c, c->readchunk, c->readchunk, |
| 3004 |
c->writechunk); |
| 3005 |
} |
| 3006 |
} |
| 3007 |
|
| 3008 |
_dahdi_receive(&ts->span); |
| 3009 |
} |
| 3010 |
} |
| 3011 |
|
| 3012 |
static void t43x_handle_transmit(struct wcxb *xb, void *vfp) |
| 3013 |
{ |
| 3014 |
int i, j, s; |
| 3015 |
u_char *frame = (u_char *) vfp; |
| 3016 |
struct t43x *wc = container_of(xb, struct t43x, xb); |
| 3017 |
struct t43x_span *ts; |
| 3018 |
|
| 3019 |
for (s = 0; s < wc->numspans; s++) { |
| 3020 |
ts = wc->tspans[s]; |
| 3021 |
if (!test_bit(DAHDI_FLAGBIT_REGISTERED, |
| 3022 |
&ts->span.flags)) { |
| 3023 |
continue; |
| 3024 |
} |
| 3025 |
|
| 3026 |
_dahdi_transmit(&ts->span); |
| 3027 |
|
| 3028 |
for (j = 0; j < DAHDI_CHUNKSIZE; j++) |
| 3029 |
for (i = 0; i < ts->span.channels; i++) |
| 3030 |
frame[j*WCXB_DMA_CHAN_SIZE+(s+1+i*4)] = |
| 3031 |
ts->chans[i]->writechunk[j]; |
| 3032 |
} |
| 3033 |
} |
| 3034 |
|
| 3035 |
#define SPAN_DEBOUNCE \ |
| 3036 |
(ts->lofalarmtimer || ts->losalarmtimer || \ |
| 3037 |
ts->aisalarmtimer || ts->yelalarmtimer || \ |
| 3038 |
ts->recoverytimer || \ |
| 3039 |
ts->loopuptimer || ts->loopdntimer) |
| 3040 |
|
| 3041 |
#define SPAN_ALARMS \ |
| 3042 |
(ts->span.alarms & ~DAHDI_ALARM_NOTOPEN) |
| 3043 |
|
| 3044 |
static void timer_work_func(struct work_struct *work) |
| 3045 |
{ |
| 3046 |
struct t43x *wc = container_of(work, struct t43x, timer_work); |
| 3047 |
struct t43x_span *ts; |
| 3048 |
int x; |
| 3049 |
bool start_timer = false; |
| 3050 |
|
| 3051 |
for (x = 0; x < wc->numspans; x++) { |
| 3052 |
ts = wc->tspans[x]; |
| 3053 |
if (ts->debounce) { |
| 3054 |
|
| 3055 |
|
| 3056 |
ts->debounce = false; |
| 3057 |
t43x_debounce_alarms(wc, x); |
| 3058 |
if (!dahdi_is_e1_span(&ts->span)) |
| 3059 |
t43x_debounce_loopcodes(wc, x); |
| 3060 |
if (SPAN_DEBOUNCE || SPAN_ALARMS) |
| 3061 |
ts->debounce = true; |
| 3062 |
if (ts->debounce) |
| 3063 |
start_timer = true; |
| 3064 |
} |
| 3065 |
} |
| 3066 |
|
| 3067 |
handle_leds(wc); |
| 3068 |
if (start_timer) |
| 3069 |
mod_timer(&wc->timer, jiffies + HZ/10); |
| 3070 |
} |
| 3071 |
|
| 3072 |
static void handle_falc_int(struct t43x *wc, int unit) |
| 3073 |
{ |
| 3074 |
struct t43x_span *ts = wc->tspans[unit]; |
| 3075 |
unsigned char gis, isr0, isr1, isr2, isr3, isr4; |
| 3076 |
static int intcount; |
| 3077 |
bool start_timer; |
| 3078 |
bool recheck_sigbits = false; |
| 3079 |
int fidx = (wc->numspans == 2) ? unit+1 : unit; |
| 3080 |
|
| 3081 |
intcount++; |
| 3082 |
start_timer = false; |
| 3083 |
|
| 3084 |
spin_lock(&wc->reglock); |
| 3085 |
gis = __t43x_framer_get(wc, fidx, FRMR_GIS); |
| 3086 |
isr0 = (gis&FRMR_GIS_ISR0) ? __t43x_framer_get(wc, fidx, FRMR_ISR0) : 0; |
| 3087 |
isr1 = (gis&FRMR_GIS_ISR1) ? __t43x_framer_get(wc, fidx, FRMR_ISR1) : 0; |
| 3088 |
isr2 = (gis&FRMR_GIS_ISR2) ? __t43x_framer_get(wc, fidx, FRMR_ISR2) : 0; |
| 3089 |
isr3 = (gis&FRMR_GIS_ISR3) ? __t43x_framer_get(wc, fidx, FRMR_ISR3) : 0; |
| 3090 |
isr4 = (gis&FRMR_GIS_ISR4) ? __t43x_framer_get(wc, fidx, FRMR_ISR4) : 0; |
| 3091 |
|
| 3092 |
if ((debug) && !(isr3 & ISR3_SEC)) { |
| 3093 |
dev_info(&wc->xb.pdev->dev, |
| 3094 |
"span: %d gis: %02x, isr0: %02x, isr1: %02x, isr2: %02x, isr3: %02x, isr4: %02x, intcount=%u\n", |
| 3095 |
unit, gis, isr0, isr1, isr2, isr3, isr4, intcount); |
| 3096 |
} |
| 3097 |
|
| 3098 |
|
| 3099 |
if (isr3 & ISR3_SEC) { |
| 3100 |
ts->span.count.fe += __t43x_framer_get(wc, fidx, FECL_T); |
| 3101 |
ts->span.count.crc4 += __t43x_framer_get(wc, fidx, CEC1L_T); |
| 3102 |
ts->span.count.cv += __t43x_framer_get(wc, fidx, CVCL_T); |
| 3103 |
ts->span.count.ebit += __t43x_framer_get(wc, fidx, EBCL_T); |
| 3104 |
ts->span.count.be += __t43x_framer_get(wc, fidx, BECL_T); |
| 3105 |
ts->span.count.prbs = __t43x_framer_get(wc, fidx, FRS1_T); |
| 3106 |
|
| 3107 |
if (DAHDI_RXSIG_INITIAL == ts->span.chans[0]->rxhooksig) |
| 3108 |
recheck_sigbits = true; |
| 3109 |
} |
| 3110 |
spin_unlock(&wc->reglock); |
| 3111 |
|
| 3112 |
|
| 3113 |
if (isr3 & ISR3_ES) |
| 3114 |
ts->span.count.errsec += 1; |
| 3115 |
|
| 3116 |
|
| 3117 |
|
| 3118 |
if (isr0 & 0x08 || recheck_sigbits) |
| 3119 |
t43x_check_sigbits(wc, unit); |
| 3120 |
|
| 3121 |
if (dahdi_is_e1_span(&ts->span)) { |
| 3122 |
|
| 3123 |
if ((isr3 & 0x68) || isr2 || (isr1 & 0x7f)) { |
| 3124 |
t43x_check_alarms(wc, unit); |
| 3125 |
start_timer = true; |
| 3126 |
} |
| 3127 |
} else { |
| 3128 |
|
| 3129 |
if (isr2) { |
| 3130 |
t43x_check_alarms(wc, unit); |
| 3131 |
start_timer = true; |
| 3132 |
} |
| 3133 |
if (isr3 & 0x08) { |
| 3134 |
t43x_check_loopcodes(wc, unit); |
| 3135 |
start_timer = true; |
| 3136 |
} |
| 3137 |
} |
| 3138 |
|
| 3139 |
if (!ts->span.alarms) { |
| 3140 |
if ((isr3 & 0x3) || (isr4 & 0xc0)) |
| 3141 |
ts->span.count.timingslips++; |
| 3142 |
} |
| 3143 |
|
| 3144 |
if (start_timer) { |
| 3145 |
ts->debounce = true; |
| 3146 |
if (!timer_pending(&wc->timer)) |
| 3147 |
mod_timer(&wc->timer, jiffies + HZ/10); |
| 3148 |
} |
| 3149 |
} |
| 3150 |
|
| 3151 |
static void t43x_handle_interrupt(struct wcxb *xb, u32 pending) |
| 3152 |
{ |
| 3153 |
u32 status; |
| 3154 |
struct t43x *wc = container_of(xb, struct t43x, xb); |
| 3155 |
|
| 3156 |
if (!(pending & FALC_INT)) |
| 3157 |
return; |
| 3158 |
|
| 3159 |
|
| 3160 |
status = t43x_framer_get(wc, 0, FRMR_CIS); |
| 3161 |
if (status & (1 << (wc->intr_span + ((wc->numspans == 2) ? 1 : 0)))) |
| 3162 |
handle_falc_int(wc, wc->intr_span); |
| 3163 |
if (++wc->intr_span >= wc->numspans) |
| 3164 |
wc->intr_span = 0; |
| 3165 |
} |
| 3166 |
|
| 3167 |
static void t43x_timer(TIMER_DATA_TYPE timer) |
| 3168 |
{ |
| •3169 |
struct t43x *wc = timer_container_of(wc, timer, timer); |
| 3170 |
|
| 3171 |
if (!is_initialized(wc)) |
| 3172 |
return; |
| 3173 |
|
| 3174 |
queue_work(wc->wq, &wc->timer_work); |
| 3175 |
return; |
| 3176 |
} |
| 3177 |
|
| 3178 |
static int t43x_open(struct dahdi_chan *chan) |
| 3179 |
{ |
| 3180 |
struct t43x *wc = chan->pvt; |
| 3181 |
struct t43x_span *ts = container_of(chan->span, struct t43x_span, span); |
| 3182 |
unsigned long flags; |
| 3183 |
|
| 3184 |
if (!(ts->span.lineconfig & DAHDI_CONFIG_NOTOPEN)) |
| 3185 |
return 0; |
| 3186 |
|
| 3187 |
if (!test_and_set_bit(HAVE_OPEN_CHANNELS_FLAGBIT, &ts->bit_flags)) { |
| 3188 |
local_irq_save(flags); |
| 3189 |
t43x_check_alarms(wc, ts->span.offset); |
| 3190 |
local_irq_restore(flags); |
| 3191 |
} |
| 3192 |
|
| 3193 |
return 0; |
| 3194 |
} |
| 3195 |
|
| 3196 |
static int t43x_close(struct dahdi_chan *chan) |
| 3197 |
{ |
| 3198 |
struct t43x *wc = chan->pvt; |
| 3199 |
struct t43x_span *ts = container_of(chan->span, struct t43x_span, span); |
| 3200 |
unsigned long flags; |
| 3201 |
|
| 3202 |
if (!(ts->span.lineconfig & DAHDI_CONFIG_NOTOPEN)) |
| 3203 |
return 0; |
| 3204 |
|
| 3205 |
if (have_open_channels(ts)) |
| 3206 |
return 0; |
| 3207 |
|
| 3208 |
if (!test_and_set_bit(HAVE_OPEN_CHANNELS_FLAGBIT, &ts->bit_flags)) { |
| 3209 |
local_irq_save(flags); |
| 3210 |
t43x_check_alarms(wc, ts->span.offset); |
| 3211 |
local_irq_restore(flags); |
| 3212 |
} |
| 3213 |
|
| 3214 |
return 0; |
| 3215 |
} |
| 3216 |
|
| 3217 |
static const struct dahdi_span_ops t43x_span_ops = { |
| 3218 |
.owner = THIS_MODULE, |
| 3219 |
.spanconfig = t43x_spanconfig, |
| 3220 |
.chanconfig = t43x_chanconfig, |
| 3221 |
.startup = t43x_startup, |
| 3222 |
.rbsbits = t43x_rbsbits, |
| 3223 |
.maint = t43x_maint, |
| 3224 |
.ioctl = t43x_ioctl, |
| 3225 |
.assigned = t43x_span_assigned, |
| 3226 |
.set_spantype = t43x_set_linemode, |
| 3227 |
.echocan_create = t43x_echocan_create, |
| 3228 |
.echocan_name = t43x_echocan_name, |
| 3229 |
.open = t43x_open, |
| 3230 |
.close = t43x_close, |
| 3231 |
}; |
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
|
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
|
| 3241 |
static int t43x_check_for_interrupts(struct t43x *wc) |
| 3242 |
{ |
| 3243 |
unsigned int starting_framecount = wc->xb.framecount; |
| 3244 |
unsigned long stop_time = jiffies + HZ*2; |
| 3245 |
unsigned long flags; |
| 3246 |
int x; |
| 3247 |
|
| 3248 |
msleep(20); |
| 3249 |
spin_lock_irqsave(&wc->reglock, flags); |
| 3250 |
while (starting_framecount == wc->xb.framecount) { |
| 3251 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 3252 |
if (time_after(jiffies, stop_time)) { |
| 3253 |
for (x = 0; x < wc->numspans; x++) |
| 3254 |
wc->tspans[x]->span.alarms = DAHDI_ALARM_RED; |
| 3255 |
dev_err(&wc->xb.pdev->dev, "Interrupts not detected.\n"); |
| 3256 |
return -EIO; |
| 3257 |
} |
| 3258 |
msleep(100); |
| 3259 |
spin_lock_irqsave(&wc->reglock, flags); |
| 3260 |
} |
| 3261 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 3262 |
|
| 3263 |
return 0; |
| 3264 |
} |
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
|
| 3273 |
|
| 3274 |
|
| 3275 |
|
| 3276 |
static char *t43x_read_serial(struct t43x *wc) |
| 3277 |
{ |
| 3278 |
int i; |
| 3279 |
static const int MAX_SERIAL = 20*5; |
| 3280 |
const unsigned int SERIAL_ADDRESS = 0x1f0000; |
| 3281 |
unsigned char *serial = kzalloc(MAX_SERIAL + 1, GFP_KERNEL); |
| 3282 |
struct wcxb const *xb = &wc->xb; |
| 3283 |
struct wcxb_spi_master *flash_spi_master = NULL; |
| 3284 |
struct wcxb_spi_device *flash_spi_device = NULL; |
| 3285 |
const unsigned int FLASH_SPI_BASE = 0x200; |
| 3286 |
|
| 3287 |
if (!serial) |
| 3288 |
return NULL; |
| 3289 |
|
| 3290 |
flash_spi_master = wcxb_spi_master_create(&xb->pdev->dev, |
| 3291 |
xb->membase + FLASH_SPI_BASE, |
| 3292 |
false); |
| 3293 |
if (!flash_spi_master) |
| 3294 |
return NULL; |
| 3295 |
|
| 3296 |
flash_spi_device = wcxb_spi_device_create(flash_spi_master, 0); |
| 3297 |
if (!flash_spi_device) |
| 3298 |
goto error_exit; |
| 3299 |
|
| 3300 |
wcxb_flash_read(flash_spi_device, SERIAL_ADDRESS, |
| 3301 |
serial, MAX_SERIAL); |
| 3302 |
|
| 3303 |
for (i = 0; i < MAX_SERIAL; ++i) { |
| 3304 |
if ((serial[i] < 0x20) || (serial[i] > 0x7e)) { |
| 3305 |
serial[i] = '\0'; |
| 3306 |
break; |
| 3307 |
} |
| 3308 |
} |
| 3309 |
|
| 3310 |
if (!i) { |
| 3311 |
kfree(serial); |
| 3312 |
serial = NULL; |
| 3313 |
} else { |
| 3314 |
|
| 3315 |
|
| 3316 |
unsigned char *new_serial; |
| 3317 |
new_serial = kasprintf(GFP_KERNEL, "%s", serial); |
| 3318 |
kfree(serial); |
| 3319 |
serial = new_serial; |
| 3320 |
} |
| 3321 |
|
| 3322 |
error_exit: |
| 3323 |
wcxb_spi_device_destroy(flash_spi_device); |
| 3324 |
wcxb_spi_master_destroy(flash_spi_master); |
| 3325 |
return serial; |
| 3326 |
} |
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
static void t43x_assign_num(struct t43x *wc) |
| 3334 |
{ |
| 3335 |
mutex_lock(&card_list_lock); |
| 3336 |
if (list_empty(&card_list)) { |
| 3337 |
wc->num = 0; |
| 3338 |
list_add(&wc->card_node, &card_list); |
| 3339 |
} else { |
| 3340 |
struct t43x *cur; |
| 3341 |
struct list_head *insert_pos; |
| 3342 |
int new_num = 0; |
| 3343 |
|
| 3344 |
insert_pos = &card_list; |
| 3345 |
list_for_each_entry(cur, &card_list, card_node) { |
| 3346 |
if (new_num != cur->num) |
| 3347 |
break; |
| 3348 |
new_num++; |
| 3349 |
insert_pos = &cur->card_node; |
| 3350 |
} |
| 3351 |
|
| 3352 |
wc->num = new_num; |
| 3353 |
list_add_tail(&wc->card_node, insert_pos); |
| 3354 |
} |
| 3355 |
mutex_unlock(&card_list_lock); |
| 3356 |
} |
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
static int __devinit t43x_init_one(struct pci_dev *pdev, |
| 3363 |
const struct pci_device_id *ent) |
| 3364 |
{ |
| 3365 |
struct t43x *wc; |
| 3366 |
struct t43x_span *ts; |
| 3367 |
unsigned int x; |
| 3368 |
int res; |
| 3369 |
enum linemode type; |
| 3370 |
|
| 3371 |
wc = kzalloc(sizeof(*wc), GFP_KERNEL); |
| 3372 |
if (!wc) { |
| 3373 |
pci_disable_device(pdev); |
| 3374 |
return -ENOMEM; |
| 3375 |
} |
| 3376 |
|
| 3377 |
t43x_assign_num(wc); |
| 3378 |
|
| 3379 |
wc->blinktimer = jiffies; |
| 3380 |
dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
| 3381 |
wc->not_ready = 1; |
| 3382 |
|
| 3383 |
spin_lock_init(&wc->reglock); |
| 3384 |
|
| 3385 |
pci_set_drvdata(pdev, wc); |
| 3386 |
wc->xb.pdev = pdev; |
| 3387 |
wc->xb.ops = &xb_ops; |
| 3388 |
wc->xb.debug = &debug; |
| 3389 |
|
| 3390 |
res = wcxb_init(&wc->xb, KBUILD_MODNAME, 0); |
| 3391 |
if (res) |
| 3392 |
goto fail_exit; |
| 3393 |
|
| 3394 |
mutex_init(&wc->lock); |
| 3395 |
timer_setup(&wc->timer, t43x_timer, 0); |
| 3396 |
|
| 3397 |
INIT_WORK(&wc->timer_work, timer_work_func); |
| 3398 |
INIT_DELAYED_WORK(&wc->clksrc_work.work, t43x_clksrc_work_fn); |
| 3399 |
spin_lock_init(&wc->clksrc_work.lock); |
| 3400 |
|
| 3401 |
wc->ddev = dahdi_create_device(); |
| 3402 |
if (!wc->ddev) { |
| 3403 |
res = -ENOMEM; |
| 3404 |
goto fail_exit; |
| 3405 |
} |
| 3406 |
wc->ddev->manufacturer = "Digium"; |
| 3407 |
wc->ddev->location = kasprintf(GFP_KERNEL, "PCI Bus %02d Slot %02d", |
| 3408 |
pdev->bus->number, |
| 3409 |
PCI_SLOT(pdev->devfn) + 1); |
| 3410 |
if (!wc->ddev->location) { |
| 3411 |
res = -ENOMEM; |
| 3412 |
goto fail_exit; |
| 3413 |
} |
| 3414 |
|
| 3415 |
wc->ddev->hardware_id = t43x_read_serial(wc); |
| 3416 |
|
| 3417 |
if (wc->ddev->hardware_id == NULL) { |
| 3418 |
dev_info(&wc->xb.pdev->dev, "Unable to read valid serial number\n"); |
| 3419 |
res = -EIO; |
| 3420 |
goto fail_exit; |
| 3421 |
} |
| 3422 |
|
| 3423 |
if (strncmp(wc->ddev->hardware_id, "1TE435F", 7) == 0) { |
| 3424 |
|
| 3425 |
wc->numspans = 4; |
| 3426 |
wc->devtype = &te435; |
| 3427 |
} else if (strncmp(wc->ddev->hardware_id, "1TE235F", 7) == 0) { |
| 3428 |
|
| 3429 |
wc->numspans = 2; |
| 3430 |
wc->devtype = &te235; |
| 3431 |
} else if (strncmp(wc->ddev->hardware_id, "1TE436F", 7) == 0) { |
| 3432 |
|
| 3433 |
wc->numspans = 4; |
| 3434 |
wc->devtype = &te436; |
| 3435 |
} else if (strncmp(wc->ddev->hardware_id, "1TE236F", 7) == 0) { |
| 3436 |
|
| 3437 |
wc->numspans = 2; |
| 3438 |
wc->devtype = &te236; |
| 3439 |
} else { |
| 3440 |
dev_info(&wc->xb.pdev->dev, |
| 3441 |
"Unable to identify board type from serial number %s\n", |
| 3442 |
wc->ddev->hardware_id); |
| 3443 |
res = -EIO; |
| 3444 |
goto fail_exit; |
| 3445 |
} |
| 3446 |
|
| 3447 |
|
| 3448 |
if ((wc->devtype == &te435) || (wc->devtype == &te235)) { |
| 3449 |
res = wcxb_check_firmware(&wc->xb, TE435_VERSION, |
| 3450 |
TE435_FW_FILENAME, force_firmware, WCXB_RESET_NOW); |
| 3451 |
} else if ((wc->devtype == &te436) || (wc->devtype == &te236)) { |
| 3452 |
res = wcxb_check_firmware(&wc->xb, TE436_VERSION, |
| 3453 |
TE436_FW_FILENAME, force_firmware, WCXB_RESET_NOW); |
| 3454 |
} else { |
| 3455 |
res = -EIO; |
| 3456 |
} |
| 3457 |
|
| 3458 |
if (res) |
| 3459 |
goto fail_exit; |
| 3460 |
|
| 3461 |
for (x = 0; x < wc->numspans; x++) { |
| 3462 |
ts = kzalloc(sizeof(*wc->tspans[x]), GFP_KERNEL); |
| 3463 |
if (!ts) { |
| 3464 |
res = -ENOMEM; |
| 3465 |
goto fail_exit; |
| 3466 |
} |
| 3467 |
wc->tspans[x] = ts; |
| 3468 |
} |
| 3469 |
|
| 3470 |
wc->wq = create_singlethread_workqueue(KBUILD_MODNAME); |
| 3471 |
if (!wc->wq) { |
| 3472 |
res = -ENOMEM; |
| 3473 |
goto fail_exit; |
| 3474 |
} |
| 3475 |
|
| 3476 |
wcxb_set_minlatency(&wc->xb, latency); |
| 3477 |
wcxb_set_maxlatency(&wc->xb, max_latency); |
| 3478 |
|
| 3479 |
create_sysfs_files(wc); |
| 3480 |
|
| 3481 |
res = t43x_hardware_post_init(wc, &type); |
| 3482 |
if (res) |
| 3483 |
goto fail_exit; |
| 3484 |
|
| 3485 |
t43x_init_spans(wc, type); |
| 3486 |
|
| 3487 |
if (!wc->vpm) |
| 3488 |
t43x_vpm_init(wc); |
| 3489 |
|
| 3490 |
if (wc->vpm) { |
| 3491 |
wc->ddev->devicetype = kasprintf(GFP_KERNEL, |
| 3492 |
"%s (%s)", wc->devtype->name, |
| 3493 |
wc->vpm_name); |
| 3494 |
} else { |
| 3495 |
wc->ddev->devicetype = kasprintf(GFP_KERNEL, |
| 3496 |
"%s", wc->devtype->name); |
| 3497 |
} |
| 3498 |
|
| 3499 |
res = dahdi_register_device(wc->ddev, &wc->xb.pdev->dev); |
| 3500 |
if (res) { |
| 3501 |
dev_info(&wc->xb.pdev->dev, "Unable to register with DAHDI\n"); |
| 3502 |
goto fail_exit; |
| 3503 |
} |
| 3504 |
|
| 3505 |
if (wc->ddev->hardware_id) { |
| 3506 |
dev_info(&wc->xb.pdev->dev, "Found a %s (SN: %s)\n", |
| 3507 |
wc->devtype->name, wc->ddev->hardware_id); |
| 3508 |
} else { |
| 3509 |
dev_info(&wc->xb.pdev->dev, "Found a %s\n", |
| 3510 |
wc->devtype->name); |
| 3511 |
} |
| 3512 |
|
| 3513 |
wc->not_ready = 0; |
| 3514 |
return 0; |
| 3515 |
|
| 3516 |
fail_exit: |
| 3517 |
wcxb_release(&wc->xb); |
| 3518 |
|
| 3519 |
if (debug) |
| 3520 |
dev_info(&wc->xb.pdev->dev, "***At fail_exit in init_one***\n"); |
| 3521 |
|
| 3522 |
for (x = 0; x < wc->numspans; x++) |
| 3523 |
kfree(wc->tspans[x]); |
| 3524 |
|
| 3525 |
free_wc(wc); |
| 3526 |
return res; |
| 3527 |
} |
| 3528 |
|
| 3529 |
static void __devexit t43x_remove_one(struct pci_dev *pdev) |
| 3530 |
{ |
| 3531 |
struct t43x *wc = pci_get_drvdata(pdev); |
| 3532 |
dev_info(&wc->xb.pdev->dev, "Removing a Wildcard TE43x.\n"); |
| 3533 |
|
| 3534 |
if (!wc) |
| 3535 |
return; |
| 3536 |
|
| 3537 |
wc->not_ready = 1; |
| 3538 |
smp_mb__after_atomic(); |
| 3539 |
|
| 3540 |
|
| 3541 |
wcxb_stop(&wc->xb); |
| 3542 |
|
| 3543 |
|
| 3544 |
wcxb_gpio_clear(&wc->xb, FALC_CPU_RESET); |
| 3545 |
|
| 3546 |
|
| 3547 |
t43x_setleds(wc, 0); |
| 3548 |
|
| 3549 |
if (wc->vpm) |
| 3550 |
release_vpm450m(wc->vpm); |
| 3551 |
wc->vpm = NULL; |
| 3552 |
|
| 3553 |
cancel_delayed_work_sync(&wc->clksrc_work.work); |
| 3554 |
|
| •3555 |
timer_delete_sync(&wc->timer); |
| 3556 |
flush_workqueue(wc->wq); |
| •3557 |
timer_delete_sync(&wc->timer); |
| 3558 |
|
| 3559 |
dahdi_unregister_device(wc->ddev); |
| 3560 |
|
| 3561 |
remove_sysfs_files(wc); |
| 3562 |
|
| 3563 |
wcxb_release(&wc->xb); |
| 3564 |
free_wc(wc); |
| 3565 |
} |
| 3566 |
|
| 3567 |
static DEFINE_PCI_DEVICE_TABLE(t43x_pci_tbl) = { |
| 3568 |
{ 0xd161, 0x800e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 3569 |
{ 0xd161, 0x8013, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, |
| 3570 |
{ 0 } |
| 3571 |
}; |
| 3572 |
|
| 3573 |
static void t43x_shutdown(struct pci_dev *pdev) |
| 3574 |
{ |
| 3575 |
struct t43x *wc = pci_get_drvdata(pdev); |
| 3576 |
dev_info(&wc->xb.pdev->dev, "Quiescing a Wildcard TE43x.\n"); |
| 3577 |
if (!wc) |
| 3578 |
return; |
| 3579 |
|
| 3580 |
|
| 3581 |
wcxb_stop(&wc->xb); |
| 3582 |
|
| 3583 |
} |
| 3584 |
|
| 3585 |
static int t43x_suspend(struct pci_dev *pdev, pm_message_t state) |
| 3586 |
{ |
| 3587 |
return -ENOSYS; |
| 3588 |
} |
| 3589 |
|
| 3590 |
MODULE_DEVICE_TABLE(pci, t43x_pci_tbl); |
| 3591 |
|
| 3592 |
static struct pci_driver t43x_driver = { |
| 3593 |
.name = "wcte43x", |
| 3594 |
.probe = t43x_init_one, |
| 3595 |
.remove = __devexit_p(t43x_remove_one), |
| 3596 |
.shutdown = t43x_shutdown, |
| 3597 |
.suspend = t43x_suspend, |
| 3598 |
.id_table = t43x_pci_tbl, |
| 3599 |
}; |
| 3600 |
|
| 3601 |
static int __init t43x_init(void) |
| 3602 |
{ |
| 3603 |
int res; |
| 3604 |
|
| 3605 |
if (strcasecmp(default_linemode, "t1") && |
| 3606 |
strcasecmp(default_linemode, "j1") && |
| 3607 |
strcasecmp(default_linemode, "e1")) { |
| 3608 |
pr_err("'%s' is an unknown span type.\n", default_linemode); |
| 3609 |
default_linemode = "t1"; |
| 3610 |
return -EINVAL; |
| 3611 |
} |
| 3612 |
|
| 3613 |
res = pci_register_driver(&t43x_driver); |
| 3614 |
if (res) |
| 3615 |
return -ENODEV; |
| 3616 |
|
| 3617 |
return 0; |
| 3618 |
} |
| 3619 |
|
| 3620 |
|
| 3621 |
static void __exit t43x_cleanup(void) |
| 3622 |
{ |
| 3623 |
pci_unregister_driver(&t43x_driver); |
| 3624 |
} |
| 3625 |
|
| 3626 |
module_param(debug, int, S_IRUGO | S_IWUSR); |
| 3627 |
module_param(timingcable, int, 0600); |
| 3628 |
module_param(default_linemode, charp, S_IRUGO); |
| 3629 |
MODULE_PARM_DESC(default_linemode, "\"t1\"(default), \"e1\", or \"j1\"."); |
| 3630 |
module_param(alarmdebounce, int, S_IRUGO | S_IWUSR); |
| 3631 |
module_param(losalarmdebounce, int, S_IRUGO | S_IWUSR); |
| 3632 |
module_param(aisalarmdebounce, int, S_IRUGO | S_IWUSR); |
| 3633 |
module_param(yelalarmdebounce, int, S_IRUGO | S_IWUSR); |
| 3634 |
module_param(vpmsupport, int, 0600); |
| 3635 |
module_param(force_firmware, int, S_IRUGO); |
| 3636 |
module_param(latency, int, S_IRUGO); |
| 3637 |
MODULE_PARM_DESC(latency, "How many milliseconds of audio to buffer between card and host (3ms default). This number will increase during runtime, dynamically, if dahdi detects that it is too small. This is commonly refered to as a \"latency bump\""); |
| 3638 |
module_param(max_latency, int, 0600); |
| 3639 |
MODULE_PARM_DESC(max_latency, "The maximum amount of latency that the driver will permit."); |
| 3640 |
|
| 3641 |
MODULE_DESCRIPTION("Wildcard Digital Card Driver"); |
| 3642 |
MODULE_AUTHOR("Digium Incorporated <[email protected]>"); |
| 3643 |
MODULE_LICENSE("GPL v2"); |
| 3644 |
|
| 3645 |
module_init(t43x_init); |
| 3646 |
module_exit(t43x_cleanup); |