| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include <linux/kernel.h> |
| 24 |
#include <linux/pci.h> |
| 25 |
#include <linux/ppp_defs.h> |
| 26 |
#include <linux/delay.h> |
| 27 |
#include <linux/sched.h> |
| 28 |
#include <linux/slab.h> |
| 29 |
|
| 30 |
#define FAST_HDLC_NEED_TABLES |
| 31 |
#include <dahdi/kernel.h> |
| 32 |
#include <dahdi/fasthdlc.h> |
| 33 |
|
| 34 |
#include "wctdm24xxp.h" |
| 35 |
#include "xhfc.h" |
| 36 |
|
| 37 |
#define HFC_NR_FIFOS 16 |
| 38 |
#define HFC_ZMIN 0x00 |
| 39 |
#define HFC_ZMAX 0x7f |
| 40 |
#define HFC_FMIN 0x00 |
| 41 |
#define HFC_FMAX 0x07 |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
#define R_CIRM 0x00 |
| 52 |
#define R_CTRL 0x01 |
| 53 |
#define R_CLK_CFG 0x02 |
| 54 |
#define A_Z1 0x04 |
| 55 |
#define A_Z2 0x06 |
| 56 |
#define R_RAM_ADDR 0x08 |
| 57 |
#define R_RAM_CTRL 0x09 |
| 58 |
#define R_FIRST_FIFO 0x0b |
| 59 |
#define R_FIFO_THRES 0x0c |
| 60 |
#define A_F1 0x0c |
| 61 |
#define R_FIFO_MD 0x0d |
| 62 |
#define A_F2 0x0d |
| 63 |
#define A_INC_RES_FIFO 0x0e |
| 64 |
#define A_FIFO_STA 0x0e |
| 65 |
#define R_FSM_IDX 0x0f |
| 66 |
#define R_FIFO 0x0f |
| 67 |
|
| 68 |
#define R_SLOT 0x10 |
| 69 |
#define R_IRQ_OVIEW 0x10 |
| 70 |
#define R_MISC_IRQMSK 0x11 |
| 71 |
#define R_MISC_IRQ 0x11 |
| 72 |
#define R_SU_IRQMSK 0x12 |
| 73 |
#define R_SU_IRQ 0x12 |
| 74 |
#define R_IRQ_CTRL 0x13 |
| 75 |
#define R_AF0_OVIEW 0x13 |
| 76 |
#define R_PCM_MD0 0x14 |
| 77 |
#define A_USAGE 0x14 |
| 78 |
#define R_MSS0 0x15 |
| 79 |
#define R_MSS1 0x15 |
| 80 |
#define R_PCM_MD1 0x15 |
| 81 |
#define R_PCM_MD2 0x15 |
| 82 |
#define R_SH0H 0x15 |
| 83 |
#define R_SH1H 0x15 |
| 84 |
#define R_SH0L 0x15 |
| 85 |
#define R_SH1L 0x15 |
| 86 |
#define R_SL_SEL0 0x15 |
| 87 |
#define R_SL_SEL1 0x15 |
| 88 |
#define R_SL_SEL7 0x15 |
| 89 |
#define R_RAM_USE 0x15 |
| 90 |
#define R_SU_SEL 0x16 |
| 91 |
#define R_CHIP_ID 0x16 |
| 92 |
#define R_SU_SYNC 0x17 |
| 93 |
#define R_BERT_STA 0x17 |
| 94 |
#define R_F0_CNTL 0x18 |
| 95 |
#define R_F0_CNTH 0x19 |
| 96 |
#define R_TI_WD 0x1a |
| 97 |
#define R_BERT_ECL 0x1a |
| 98 |
#define R_BERT_WD_MD 0x1b |
| 99 |
#define R_BERT_ECH 0x1b |
| 100 |
#define R_STATUS 0x1c |
| 101 |
#define R_SL_MAX 0x1d |
| 102 |
#define R_PWM_CFG 0x1e |
| 103 |
#define R_CHIP_RV 0x1f |
| 104 |
|
| 105 |
#define R_FIFO_BL0_IRQ 0x20 |
| 106 |
#define R_FIFO_BL1_IRQ 0x21 |
| 107 |
#define R_FIFO_BL2_IRQ 0x22 |
| 108 |
#define R_FIFO_BL3_IRQ 0x23 |
| 109 |
#define R_FILL_BL0 0x24 |
| 110 |
#define R_FILL_BL1 0x25 |
| 111 |
#define R_FILL_BL2 0x26 |
| 112 |
#define R_FILL_BL3 0x27 |
| 113 |
#define R_CI_TX 0x28 |
| 114 |
#define R_CI_RX 0x28 |
| 115 |
#define R_CGI_CFG0 0x29 |
| 116 |
#define R_CGI_STA 0x29 |
| 117 |
#define R_CGI_CFG1 0x2a |
| 118 |
#define R_MON_RX 0x2a |
| 119 |
#define R_MON_TX 0x2b |
| 120 |
|
| 121 |
#define A_SU_WR_STA 0x30 |
| 122 |
#define A_SU_RD_STA 0x30 |
| 123 |
#define A_SU_CTRL0 0x31 |
| 124 |
#define A_SU_DLYL 0x31 |
| 125 |
#define A_SU_CTRL1 0x32 |
| 126 |
#define A_SU_DLYH 0x32 |
| 127 |
#define A_SU_CTRL2 0x33 |
| 128 |
#define A_MS_TX 0x34 |
| 129 |
#define A_MS_RX 0x34 |
| 130 |
#define A_ST_CTRL3 0x35 |
| 131 |
#define A_UP_CTRL3 0x35 |
| 132 |
#define A_SU_STA 0x35 |
| 133 |
#define A_MS_DF 0x36 |
| 134 |
#define A_SU_CLK_DLY 0x37 |
| 135 |
#define R_PWM0 0x38 |
| 136 |
#define R_PWM1 0x39 |
| 137 |
#define A_B1_TX 0x3c |
| 138 |
#define A_B1_RX 0x3c |
| 139 |
#define A_B2_TX 0x3d |
| 140 |
#define A_B2_RX 0x3d |
| 141 |
#define A_D_TX 0x3e |
| 142 |
#define A_D_RX 0x3e |
| 143 |
#define A_BAC_S_TX 0x3f |
| 144 |
#define A_E_RX 0x3f |
| 145 |
|
| 146 |
#define R_GPIO_OUT1 0x40 |
| 147 |
#define R_GPIO_IN1 0x40 |
| 148 |
#define R_GPIO_OUT3 0x41 |
| 149 |
#define R_GPIO_IN3 0x41 |
| 150 |
#define R_GPIO_EN1 0x42 |
| 151 |
#define R_GPIO_EN3 0x43 |
| 152 |
#define R_GPIO_SEL_BL 0x44 |
| 153 |
#define R_GPIO_OUT2 0x45 |
| 154 |
#define R_GPIO_IN2 0x45 |
| 155 |
#define R_PWM_MD 0x46 |
| 156 |
#define R_GPIO_EN2 0x47 |
| 157 |
#define R_GPIO_OUT0 0x48 |
| 158 |
#define R_GPIO_IN0 0x48 |
| 159 |
#define R_GPIO_EN0 0x4a |
| 160 |
#define R_GPIO_SEL 0x4c |
| 161 |
|
| 162 |
#define R_PLL_CTRL 0x50 |
| 163 |
#define R_PLL_STA 0x50 |
| 164 |
#define R_PLL_P 0x51 |
| 165 |
#define R_PLL_N 0x52 |
| 166 |
#define R_PLL_S 0x53 |
| 167 |
|
| 168 |
#define A_FIFO_DATA 0x80 |
| 169 |
#define A_FIFO_DATA_NOINC 0x84 |
| 170 |
|
| 171 |
#define R_INT_DATA 0x88 |
| 172 |
|
| 173 |
#define R_RAM_DATA 0xc0 |
| 174 |
|
| 175 |
#define A_SL_CFG 0xd0 |
| 176 |
#define A_CH_MSK 0xf4 |
| 177 |
#define A_CON_HDLC 0xfa |
| 178 |
#define A_SUBCH_CFG 0xfb |
| 179 |
#define A_CHANNEL 0xfc |
| 180 |
#define A_FIFO_SEQ 0xfd |
| 181 |
#define A_FIFO_CTRL 0xff |
| 182 |
|
| 183 |
|
| 184 |
#define V_CLK_OFF (1 << 0) |
| 185 |
#define V_WAIT_PROC (1 << 1) |
| 186 |
#define V_WAIT_REG (1 << 2) |
| 187 |
#define V_SRES (1 << 3) |
| 188 |
#define V_HFC_RES (1 << 4) |
| 189 |
#define V_PCM_RES (1 << 5) |
| 190 |
#define V_SU_RES (1 << 6) |
| 191 |
#define XHFC_FULL_RESET (V_SRES | V_HFC_RES | V_PCM_RES | V_SU_RES) |
| 192 |
|
| 193 |
|
| 194 |
#define V_BUSY (1 << 0) |
| 195 |
#define V_PROC (1 << 1) |
| 196 |
#define V_LOST_STA (1 << 3) |
| 197 |
#define V_PCM_INIT (1 << 4) |
| 198 |
#define V_WAK_STA (1 << 5) |
| 199 |
#define V_MISC_IRQSTA (1 << 6) |
| 200 |
#define V_FR_IRQSTA (1 << 7) |
| 201 |
#define XHFC_INTS (V_MISC_IRQSTA | V_FR_IRQSTA) |
| 202 |
|
| 203 |
|
| 204 |
#define V_FIFOx_TX_IRQ (1 << 0) |
| 205 |
#define V_FIFOx_RX_IRQ (1 << 1) |
| 206 |
#define FIFOx_TXRX_IRQ (V_FIFOx_TX_IRQ | V_FIFOx_RX_IRQ) |
| 207 |
|
| 208 |
|
| 209 |
#define V_FILL_FIFOx_TX (1 << 0) |
| 210 |
#define V_FILL_FIFOx_RX (1 << 1) |
| 211 |
#define FILL_FIFOx_TXRX (V_FILL_FIFOx_TX | V_FILL_FIFOx_RX) |
| 212 |
|
| 213 |
|
| 214 |
#define V_SLP_IRQ (1 << 0) |
| 215 |
#define V_TI_IRQ (1 << 1) |
| 216 |
#define V_PROC_IRQ (1 << 2) |
| 217 |
#define V_CI_IRQ (1 << 4) |
| 218 |
#define V_WAK_IRQ (1 << 5) |
| 219 |
#define V_MON_TX_IRQ (1 << 6) |
| 220 |
#define V_MON_RX_IRQ (1 << 7) |
| 221 |
|
| 222 |
|
| 223 |
#define V_SU0_IRQ (1 << 0) |
| 224 |
#define V_SU1_IRQ (1 << 1) |
| 225 |
#define V_SU2_IRQ (1 << 2) |
| 226 |
#define V_SU3_IRQ (1 << 3) |
| 227 |
|
| 228 |
|
| 229 |
#define V_FIFO_IRQ_EN (1 << 0) |
| 230 |
#define V_GLOB_IRQ_EN (1 << 3) |
| 231 |
#define V_IRQ_POL (1 << 4) |
| 232 |
|
| 233 |
|
| 234 |
#define V_BERT_ERR (1 << 3) |
| 235 |
#define V_AUTO_WD_RES (1 << 5) |
| 236 |
#define V_WD_RES (1 << 7) |
| 237 |
|
| 238 |
|
| 239 |
#define V_EV_TS_SHIFT (0) |
| 240 |
#define V_EV_TS_MASK (0x0f) |
| 241 |
#define V_WD_TS_SHIFT (4) |
| 242 |
#define V_WD_TS_MASK (0xf0) |
| 243 |
|
| 244 |
|
| 245 |
#define V_FIFO_IRQMSK (1 << 0) |
| 246 |
#define V_BERT_EN (1 << 1) |
| 247 |
#define V_MIX_IRQ (1 << 2) |
| 248 |
#define V_FR_ABO (1 << 3) |
| 249 |
#define V_NO_CRC (1 << 4) |
| 250 |
#define V_NO_REP (1 << 5) |
| 251 |
|
| 252 |
|
| 253 |
#define V_CLK_PLL (1 << 0) |
| 254 |
#define V_CLKO_HI (1 << 1) |
| 255 |
#define V_CLKO_PLL (1 << 2) |
| 256 |
#define V_PCM_CLK (1 << 5) |
| 257 |
#define V_CLKO_OFF (1 << 6) |
| 258 |
#define V_CLK_F1 (1 << 7) |
| 259 |
|
| 260 |
|
| 261 |
#define V_PCM_MD (1 << 0) |
| 262 |
#define V_C4_POL (1 << 1) |
| 263 |
#define V_F0_NEG (1 << 2) |
| 264 |
#define V_F0_LEN (1 << 3) |
| 265 |
#define V_PCM_IDX_SEL0 (0x0 << 4) |
| 266 |
#define V_PCM_IDX_SEL1 (0x1 << 4) |
| 267 |
#define V_PCM_IDX_SEL7 (0x7 << 4) |
| 268 |
#define V_PCM_IDX_MSS0 (0x8 << 4) |
| 269 |
#define V_PCM_IDX_MD1 (0x9 << 4) |
| 270 |
#define V_PCM_IDX_MD2 (0xa << 4) |
| 271 |
#define V_PCM_IDX_MSS1 (0xb << 4) |
| 272 |
#define V_PCM_IDX_SH0L (0xc << 4) |
| 273 |
#define V_PCM_IDX_SH0H (0xd << 4) |
| 274 |
#define V_PCM_IDX_SH1L (0xe << 4) |
| 275 |
#define V_PCM_IDX_SH1H (0xf << 4) |
| 276 |
#define V_PCM_IDX_MASK (0xf0) |
| 277 |
|
| 278 |
|
| 279 |
#define V_PLL_ADJ_00 (0x0 << 2) |
| 280 |
#define V_PLL_ADJ_01 (0x1 << 2) |
| 281 |
#define V_PLL_ADJ_10 (0x2 << 2) |
| 282 |
#define V_PLL_ADJ_11 (0x3 << 2) |
| 283 |
#define V_PCM_DR_2048 (0x0 << 4) |
| 284 |
#define V_PCM_DR_4096 (0x1 << 4) |
| 285 |
#define V_PCM_DR_8192 (0x2 << 4) |
| 286 |
#define V_PCM_DR_075 (0x3 << 4) |
| 287 |
#define V_PCM_LOOP (1 << 6) |
| 288 |
#define V_PCM_SMPL (1 << 7) |
| 289 |
#define V_PLL_ADJ_MASK (0x3 << 2) |
| 290 |
#define V_PCM_DR_MASK (0x3 << 4) |
| 291 |
|
| 292 |
|
| 293 |
#define V_SYNC_OUT1 (1 << 1) |
| 294 |
#define V_SYNC_SRC (1 << 2) |
| 295 |
#define V_SYNC_OUT2 (1 << 3) |
| 296 |
#define V_C2O_EN (1 << 4) |
| 297 |
#define V_C2I_EN (1 << 5) |
| 298 |
#define V_PLL_ICR (1 << 6) |
| 299 |
#define V_PLL_MAN (1 << 7) |
| 300 |
|
| 301 |
|
| 302 |
#define V_CH_SDIR (1 << 0) |
| 303 |
#define V_ROUT_TX_DIS (0x0 << 6) |
| 304 |
#define V_ROUT_TX_LOOP (0x1 << 6) |
| 305 |
#define V_ROUT_TX_STIO1 (0x2 << 6) |
| 306 |
#define V_ROUT_TX_STIO2 (0x3 << 6) |
| 307 |
#define V_ROUT_RX_DIS (0x0 << 6) |
| 308 |
#define V_ROUT_RX_LOOP (0x1 << 6) |
| 309 |
#define V_ROUT_RX_STIO2 (0x2 << 6) |
| 310 |
#define V_ROUT_RX_STIO1 (0x3 << 6) |
| 311 |
#define V_CH_SNUM_SHIFT (1) |
| 312 |
#define V_CH_SNUM_MASK (31 << 1) |
| 313 |
|
| 314 |
|
| 315 |
#define V_IFF (1 << 0) |
| 316 |
#define V_HDLC_TRP (1 << 1) |
| 317 |
#define V_TRP_DISABLED (0x0 << 2) |
| 318 |
#define V_TRP_IRQ_64 (0x1 << 2) |
| 319 |
#define V_TRP_IRQ_128 (0x2 << 2) |
| 320 |
#define V_TRP_IRQ_256 (0x3 << 2) |
| 321 |
#define V_TRP_IRQ_512 (0x4 << 2) |
| 322 |
#define V_TRP_IRQ_1024 (0x5 << 2) |
| 323 |
#define V_TRP_NO_IRQ (0x7 << 2) |
| 324 |
#define V_HDLC_IRQ (0x3 << 2) |
| 325 |
#define V_DATA_FLOW_000 (0x0 << 5) |
| 326 |
#define V_DATA_FLOW_001 (0x1 << 5) |
| 327 |
#define V_DATA_FLOW_010 (0x2 << 5) |
| 328 |
#define V_DATA_FLOW_011 (0x3 << 5) |
| 329 |
#define V_DATA_FLOW_100 (0x4 << 5) |
| 330 |
#define V_DATA_FLOW_101 (0x5 << 5) |
| 331 |
#define V_DATA_FLOW_110 (0x6 << 5) |
| 332 |
#define V_DATA_FLOW_111 (0x7 << 5) |
| 333 |
|
| 334 |
|
| 335 |
#define V_FIFO_DIR (1 << 0) |
| 336 |
#define V_REV (1 << 7) |
| 337 |
#define V_FIFO_NUM_SHIFT (1) |
| 338 |
#define V_FIFO_NUM_MASK (0x3e) |
| 339 |
|
| 340 |
|
| 341 |
#define V_CH_FDIR (1 << 0) |
| 342 |
#define V_CH_FNUM_SHIFT (1) |
| 343 |
#define V_CH_FNUM_MASK (0x3e) |
| 344 |
|
| 345 |
|
| 346 |
#define V_SL_DIR (1 << 0) |
| 347 |
#define V_SL_NUM_SHIFT (1) |
| 348 |
#define V_SL_NUM_MASK (0xfe) |
| 349 |
|
| 350 |
|
| 351 |
#define V_INC_F (1 << 0) |
| 352 |
#define V_RES_FIFO (1 << 1) |
| 353 |
#define V_RES_LOST (1 << 2) |
| 354 |
#define V_RES_FIFO_ERR (1 << 3) |
| 355 |
|
| 356 |
|
| 357 |
#define V_FIFO_MD_00 (0x0 << 0) |
| 358 |
#define V_FIFO_MD_01 (0x1 << 0) |
| 359 |
#define V_FIFO_MD_10 (0x2 << 0) |
| 360 |
#define V_DF_MD_SM (0x0 << 2) |
| 361 |
#define V_DF_MD_CSM (0x1 << 2) |
| 362 |
#define V_DF_MD_FSM (0x3 << 2) |
| 363 |
#define V_UNIDIR_MD (1 << 4) |
| 364 |
#define V_UNIDIR_RX (1 << 5) |
| 365 |
|
| 366 |
|
| 367 |
#define V_BIT_CNT_8BIT (0) |
| 368 |
#define V_BIT_CNT_1BIT (1) |
| 369 |
#define V_BIT_CNT_2BIT (2) |
| 370 |
#define V_BIT_CNT_3BIT (3) |
| 371 |
#define V_BIT_CNT_4BIT (4) |
| 372 |
#define V_BIT_CNT_5BIT (5) |
| 373 |
#define V_BIT_CNT_6BIT (6) |
| 374 |
#define V_BIT_CNT_7BIT (7) |
| 375 |
#define V_LOOP_FIFO (1 << 6) |
| 376 |
#define V_INV_DATA (1 << 7) |
| 377 |
#define V_START_BIT_SHIFT (3) |
| 378 |
#define V_START_BIT_MASK (0x38) |
| 379 |
|
| 380 |
|
| 381 |
#define V_SYNC_SEL_PORT0 (0x0 << 0) |
| 382 |
#define V_SYNC_SEL_PORT1 (0x1 << 0) |
| 383 |
#define V_SYNC_SEL_PORT2 (0x2 << 0) |
| 384 |
#define V_SYNC_SEL_PORT3 (0x3 << 0) |
| 385 |
#define V_SYNC_SEL_SYNCI (0x4 << 0) |
| 386 |
#define V_MAN_SYNC (1 << 3) |
| 387 |
#define V_AUTO_SYNCI (1 << 4) |
| 388 |
#define V_D_MERGE_TX (1 << 5) |
| 389 |
#define V_E_MERGE_RX (1 << 6) |
| 390 |
#define V_D_MERGE_RX (1 << 7) |
| 391 |
#define V_SYNC_SEL_MASK (0x03) |
| 392 |
|
| 393 |
|
| 394 |
#define V_SU_SET_STA_MASK (0x0f) |
| 395 |
#define V_SU_LD_STA (1 << 4) |
| 396 |
#define V_SU_ACT_NOP (0x0 << 5) |
| 397 |
#define V_SU_ACT_DEACTIVATE (0x2 << 5) |
| 398 |
#define V_SU_ACT_ACTIVATE (0x3 << 5) |
| 399 |
#define V_SET_G2_G3 (1 << 7) |
| 400 |
|
| 401 |
|
| 402 |
#define V_SU_STA_MASK (0x0f) |
| 403 |
#define V_SU_FR_SYNC (1 << 4) |
| 404 |
#define V_SU_T2_EXP (1 << 5) |
| 405 |
#define V_SU_INFO0 (1 << 6) |
| 406 |
#define V_G2_G3 (1 << 7) |
| 407 |
|
| 408 |
|
| 409 |
#define V_SU_DLY_MASK (0x0f) |
| 410 |
#define V_SU_SMPL_MASK (0xf0) |
| 411 |
#define V_SU_SMPL_SHIFT (4) |
| 412 |
|
| 413 |
|
| 414 |
#define V_B1_TX_EN (1 << 0) |
| 415 |
#define V_B2_TX_EN (1 << 1) |
| 416 |
#define V_SU_MD (1 << 2) |
| 417 |
#define V_ST_D_LPRIO (1 << 3) |
| 418 |
#define V_ST_SQ_EN (1 << 4) |
| 419 |
#define V_SU_TST_SIG (1 << 5) |
| 420 |
#define V_ST_PU_CTRL (1 << 6) |
| 421 |
#define V_SU_STOP (1 << 7) |
| 422 |
|
| 423 |
|
| 424 |
#define V_G2_G3_EN (1 << 0) |
| 425 |
#define V_D_RES (1 << 2) |
| 426 |
#define V_ST_E_IGNO (1 << 3) |
| 427 |
#define V_ST_E_LO (1 << 4) |
| 428 |
#define V_BAC_D (1 << 6) |
| 429 |
#define V_B12_SWAP (1 << 7) |
| 430 |
|
| 431 |
|
| 432 |
#define V_B1_RX_EN (1 << 0) |
| 433 |
#define V_B2_RX_EN (1 << 1) |
| 434 |
#define V_MS_SSYNC2 (1 << 2) |
| 435 |
#define V_BAC_S_SEL (1 << 3) |
| 436 |
#define V_SU_SYNC_NT (1 << 4) |
| 437 |
#define V_SU_2KHZ (1 << 5) |
| 438 |
#define V_SU_TRI (1 << 6) |
| 439 |
#define V_SU_EXCHG (1 << 7) |
| 440 |
|
| 441 |
|
| 442 |
#define V_FIFO_BL0_IRQ (1 << 0) |
| 443 |
#define V_FIFO_BL1_IRQ (1 << 1) |
| 444 |
#define V_FIFO_BL2_IRQ (1 << 2) |
| 445 |
#define V_FIFO_BL3_IRQ (1 << 3) |
| 446 |
#define V_MISC_IRQ (1 << 4) |
| 447 |
#define V_STUP_IRQ (1 << 5) |
| 448 |
#define V_FIFO_BLx_IRQ (V_FIFO_BL0_IRQ | V_FIFO_BL1_IRQ | V_FIFO_BL2_IRQ | V_FIFO_BL3_IRQ) |
| 449 |
|
| 450 |
|
| 451 |
#define V_FIRST_FIFO_NUM_SHIFT (1) |
| 452 |
|
| 453 |
|
| 454 |
#define V_NEXT_FIFO_NUM_SHIFT (1) |
| 455 |
#define V_SEQ_END (1 << 6) |
| 456 |
|
| 457 |
#if (DAHDI_CHUNKSIZE != 8) |
| 458 |
#error Sorry, the b400m does not support chunksize != 8 |
| 459 |
#endif |
| 460 |
|
| 461 |
|
| 462 |
#define DEBUG_GENERAL (1 << 0) |
| 463 |
|
| 464 |
#define DEBUG_DTMF (1 << 1) |
| 465 |
|
| 466 |
#define DEBUG_REGS (1 << 2) |
| 467 |
|
| 468 |
#define DEBUG_FOPS (1 << 3) |
| 469 |
#define DEBUG_ECHOCAN (1 << 4) |
| 470 |
|
| 471 |
#define DEBUG_ST_STATE (1 << 5) |
| 472 |
|
| 473 |
#define DEBUG_HDLC (1 << 6) |
| 474 |
|
| 475 |
#define DEBUG_ALARM (1 << 7) |
| 476 |
|
| 477 |
#define DEBUG_TIMING (1 << 8) |
| 478 |
|
| 479 |
#define DBG (bri_debug & DEBUG_GENERAL) |
| 480 |
#define DBG_DTMF (bri_debug & DEBUG_DTMF) |
| 481 |
#define DBG_REGS (bri_debug & DEBUG_REGS) |
| 482 |
#define DBG_FOPS (bri_debug & DEBUG_FOPS) |
| 483 |
#define DBG_EC (bri_debug & DEBUG_ECHOCAN) |
| 484 |
#define DBG_ST (bri_debug & DEBUG_ST_STATE) |
| 485 |
#define DBG_HDLC (bri_debug & DEBUG_HDLC) |
| 486 |
#define DBG_ALARM (bri_debug & DEBUG_ALARM) |
| 487 |
#define DBG_TIMING (bri_debug & DEBUG_TIMING) |
| 488 |
|
| 489 |
#define DBG_SPANFILTER ((1 << bspan->port) & bri_spanfilter) |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
int bri_debug; |
| 496 |
int bri_spanfilter = 9; |
| 497 |
int bri_teignorered = 1; |
| 498 |
int bri_alarmdebounce; |
| 499 |
int bri_persistentlayer1; |
| 500 |
int timingcable; |
| 501 |
|
| 502 |
static int synccard = -1; |
| 503 |
static int syncspan = -1; |
| 504 |
|
| 505 |
static const int TIMER_3_MS = 30000; |
| 506 |
|
| 507 |
#define b4_info(b4, format, arg...) \ |
| 508 |
dev_info(&(b4)->wc->vb.pdev->dev , format , ## arg) |
| 509 |
|
| 510 |
|
| 511 |
#define SWAP_PORTS |
| 512 |
|
| 513 |
#define XHFC_T1 0 |
| 514 |
#define XHFC_T2 1 |
| 515 |
#define XHFC_T3 2 |
| 516 |
|
| 517 |
#define XHFC_T4 3 |
| 518 |
|
| 519 |
#define B400M_CHANNELS_PER_SPAN 3 |
| 520 |
#define B400M_HDLC_BUF_LEN 128 |
| 521 |
|
| 522 |
#define get_F(f1, f2, flen) { \ |
| 523 |
f1 = hfc_readcounter8(b4, A_F1); \ |
| 524 |
f2 = hfc_readcounter8(b4, A_F2); \ |
| 525 |
flen = f1 - f2; \ |
| 526 |
\ |
| 527 |
if (flen < 0) \ |
| 528 |
flen += (HFC_FMAX - HFC_FMIN) + 1; \ |
| 529 |
} |
| 530 |
|
| 531 |
#define get_Z(z1, z2, zlen) { \ |
| 532 |
z1 = hfc_readcounter8(b4, A_Z1); \ |
| 533 |
z2 = hfc_readcounter8(b4, A_Z2); \ |
| 534 |
zlen = z1 - z2; \ |
| 535 |
\ |
| 536 |
if (zlen < 0) \ |
| 537 |
zlen += (HFC_ZMAX - HFC_ZMIN) + 1; \ |
| 538 |
} |
| 539 |
|
| 540 |
struct b400m_span { |
| 541 |
struct b400m *parent; |
| 542 |
unsigned int port; |
| 543 |
|
| 544 |
int oldstate; |
| 545 |
int newalarm; |
| 546 |
unsigned long alarmtimer; |
| 547 |
|
| 548 |
unsigned int te_mode:1; |
| 549 |
unsigned int term_on:1; |
| 550 |
unsigned long hfc_timers[B400M_CHANNELS_PER_SPAN+1]; |
| 551 |
int hfc_timer_on[B400M_CHANNELS_PER_SPAN+1]; |
| 552 |
int fifos[B400M_CHANNELS_PER_SPAN]; |
| 553 |
|
| 554 |
|
| 555 |
struct wctdm_span *wspan; |
| 556 |
struct dahdi_chan *sigchan; |
| 557 |
int sigactive; |
| 558 |
atomic_t hdlc_pending; |
| 559 |
unsigned int frames_out; |
| 560 |
unsigned int frames_in; |
| 561 |
|
| 562 |
struct fasthdlc_state rxhdlc; |
| 563 |
int infcs; |
| 564 |
int f_sz; |
| 565 |
}; |
| 566 |
|
| 567 |
|
| 568 |
struct b400m { |
| 569 |
char name[10]; |
| 570 |
int position; |
| 571 |
int b400m_no; |
| 572 |
|
| 573 |
struct wctdm *wc; |
| 574 |
|
| 575 |
spinlock_t reglock; |
| 576 |
|
| 577 |
unsigned long ticks; |
| 578 |
|
| 579 |
unsigned long fifo_en_rxint; |
| 580 |
unsigned long fifo_en_txint; |
| 581 |
unsigned char fifo_irqstatus; |
| 582 |
|
| 583 |
int setsyncspan; |
| 584 |
int reportedsyncspan; |
| 585 |
|
| 586 |
unsigned int running:1; |
| 587 |
unsigned int shutdown:1; |
| 588 |
unsigned int inited:1; |
| 589 |
unsigned int misc_irq_mask:1; |
| 590 |
|
| 591 |
struct b400m_span spans[4]; |
| 592 |
|
| 593 |
struct workqueue_struct *xhfc_ws; |
| 594 |
struct work_struct xhfc_wq; |
| 595 |
|
| 596 |
unsigned char irq_oview; |
| 597 |
unsigned char fifo_fill; |
| 598 |
|
| 599 |
struct semaphore regsem; |
| 600 |
struct semaphore fifosem; |
| 601 |
|
| 602 |
unsigned char lastreg; |
| 603 |
}; |
| 604 |
|
| 605 |
static void hfc_start_st(struct b400m_span *s); |
| 606 |
static void hfc_stop_st(struct b400m_span *s); |
| 607 |
|
| 608 |
void b400m_set_dahdi_span(struct b400m *b4, int spanno, |
| 609 |
struct wctdm_span *wspan) |
| 610 |
{ |
| 611 |
b4->spans[spanno].wspan = wspan; |
| 612 |
wspan->bspan = &b4->spans[spanno]; |
| 613 |
} |
| 614 |
|
| 615 |
static inline void flush_hw(void) |
| 616 |
{ |
| 617 |
} |
| 618 |
|
| 619 |
static int xhfc_getreg(struct wctdm *wc, struct wctdm_module *const mod, |
| 620 |
int addr, u8 *lastreg) |
| 621 |
{ |
| 622 |
int x; |
| 623 |
|
| 624 |
if (*lastreg != (unsigned char)addr) { |
| 625 |
wctdm_setreg(wc, mod, 0x60, addr); |
| 626 |
*lastreg = (unsigned char)addr; |
| 627 |
} |
| 628 |
x = wctdm_getreg(wc, mod, 0x80); |
| 629 |
return x; |
| 630 |
} |
| 631 |
|
| 632 |
static int xhfc_setreg(struct wctdm *wc, struct wctdm_module *const mod, |
| 633 |
int addr, int val, u8 *lastreg) |
| 634 |
{ |
| 635 |
if (*lastreg != (unsigned char)addr) { |
| 636 |
wctdm_setreg(wc, mod, 0x60, addr); |
| 637 |
*lastreg = (unsigned char)addr; |
| 638 |
} |
| 639 |
return wctdm_setreg(wc, mod, 0x00, val); |
| 640 |
} |
| 641 |
|
| 642 |
static inline struct wctdm_module *get_mod(struct b400m *b4) |
| 643 |
{ |
| 644 |
return &b4->wc->mods[b4->position]; |
| 645 |
} |
| 646 |
|
| 647 |
static int b400m_getreg(struct b400m *b4, int addr) |
| 648 |
{ |
| 649 |
int x; |
| 650 |
|
| 651 |
if (down_trylock(&b4->regsem)) { |
| 652 |
if (down_interruptible(&b4->regsem)) { |
| 653 |
b4_info(b4, "b400m_getreg(0x%02x) interrupted\n", |
| 654 |
addr); |
| 655 |
return -1; |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
x = xhfc_getreg(b4->wc, get_mod(b4), addr, &b4->lastreg); |
| 660 |
up(&b4->regsem); |
| 661 |
|
| 662 |
return x; |
| 663 |
} |
| 664 |
|
| 665 |
static int b400m_setreg(struct b400m *b4, const int addr, const int val) |
| 666 |
{ |
| 667 |
int x; |
| 668 |
|
| 669 |
if (down_trylock(&b4->regsem)) { |
| 670 |
if (down_interruptible(&b4->regsem)) { |
| 671 |
b4_info(b4, "b400m_setreg(0x%02x -> 0x%02x) " |
| 672 |
"interrupted\n", val, addr); |
| 673 |
return -1; |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
x = xhfc_setreg(b4->wc, get_mod(b4), addr, val, &b4->lastreg); |
| 678 |
up(&b4->regsem); |
| 679 |
|
| 680 |
return x; |
| 681 |
} |
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
static void b400m_setreg_ra(struct b400m *b4, u8 r, u8 rd, u8 a, u8 ad) |
| 689 |
{ |
| 690 |
if (down_trylock(&b4->regsem)) { |
| 691 |
if (down_interruptible(&b4->regsem)) { |
| 692 |
b4_info(b4, "b400m_setreg_ra(0x%02x -> 0x%02x) " |
| 693 |
"interrupted\n", a, ad); |
| 694 |
return; |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
xhfc_setreg(b4->wc, get_mod(b4), r, rd, &b4->lastreg); |
| 699 |
xhfc_setreg(b4->wc, get_mod(b4), a, ad, &b4->lastreg); |
| 700 |
up(&b4->regsem); |
| 701 |
} |
| 702 |
|
| 703 |
static u8 b400m_getreg_ra(struct b400m *b4, u8 r, u8 rd, u8 a) |
| 704 |
{ |
| 705 |
unsigned char res; |
| 706 |
if (down_trylock(&b4->regsem)) { |
| 707 |
if (down_interruptible(&b4->regsem)) { |
| 708 |
b4_info(b4, "b400m_getreg_ra(0x%02x) interrupted\n", |
| 709 |
a); |
| 710 |
return -1; |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
xhfc_setreg(b4->wc, get_mod(b4), r, rd, &b4->lastreg); |
| 715 |
res = xhfc_getreg(b4->wc, get_mod(b4), a, &b4->lastreg); |
| 716 |
up(&b4->regsem); |
| 717 |
return res; |
| 718 |
} |
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
static void hfc_gpio_init(struct b400m *b4) |
| 732 |
{ |
| 733 |
|
| 734 |
b400m_setreg(b4, R_GPIO_SEL, 0x8f); |
| 735 |
|
| 736 |
b400m_setreg(b4, R_GPIO_OUT0, 0x00); |
| 737 |
|
| 738 |
b400m_setreg(b4, R_GPIO_EN0, 0xff); |
| 739 |
|
| 740 |
b400m_setreg(b4, R_GPIO_SEL_BL, 0x00); |
| 741 |
|
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
static void hfc_setreg_waitbusy(struct b400m *b4, const unsigned int reg, |
| 749 |
const unsigned int val) |
| 750 |
{ |
| 751 |
b400m_setreg(b4, reg, val); |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
static unsigned char hfc_readcounter8(struct b400m *b4, const unsigned int reg) |
| 759 |
{ |
| 760 |
unsigned char r1, r2; |
| 761 |
unsigned long maxwait = 1048576; |
| 762 |
|
| 763 |
do { |
| 764 |
r1 = b400m_getreg(b4, reg); |
| 765 |
r2 = b400m_getreg(b4, reg); |
| 766 |
} while ((r1 != r2) && maxwait--); |
| 767 |
|
| 768 |
if (!maxwait) { |
| 769 |
if (printk_ratelimit()) { |
| 770 |
dev_warn(&b4->wc->vb.pdev->dev, |
| 771 |
"hfc_readcounter8(reg 0x%02x) timed out " \ |
| 772 |
"waiting for data to settle!\n", reg); |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
return r1; |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
static void hfc_reset(struct b400m *b4) |
| 781 |
{ |
| 782 |
unsigned long start; |
| 783 |
int TIMEOUT = HZ; |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
b400m_setreg(b4, R_FIFO_MD, V_FIFO_MD_01 | V_DF_MD_FSM); |
| 789 |
|
| 790 |
msleep(1); |
| 791 |
|
| 792 |
b400m_setreg(b4, R_CIRM, V_SRES); |
| 793 |
flush_hw(); |
| 794 |
|
| 795 |
msleep(100); |
| 796 |
|
| 797 |
b400m_setreg(b4, R_CIRM, 0x00); |
| 798 |
flush_hw(); |
| 799 |
|
| 800 |
|
| 801 |
start = jiffies; |
| 802 |
while (b400m_getreg(b4, R_STATUS) & (V_BUSY | V_PCM_INIT)) { |
| 803 |
if (time_after(jiffies, start + TIMEOUT)) { |
| 804 |
b4_info(b4, "hfc_reset() Module won't come out of " |
| 805 |
"reset... continuing.\n"); |
| 806 |
break; |
| 807 |
} |
| 808 |
}; |
| 809 |
|
| 810 |
|
| 811 |
b400m_setreg(b4, R_CTRL, 0x00); |
| 812 |
} |
| 813 |
|
| 814 |
static void hfc_enable_fifo_irqs(struct b400m *b4) |
| 815 |
{ |
| 816 |
b400m_setreg(b4, R_IRQ_CTRL, V_FIFO_IRQ_EN | V_GLOB_IRQ_EN); |
| 817 |
flush_hw(); |
| 818 |
} |
| 819 |
|
| 820 |
static void hfc_enable_interrupts(struct b400m *b4) |
| 821 |
{ |
| 822 |
b4->running = 1; |
| 823 |
|
| 824 |
|
| 825 |
b4->misc_irq_mask = 0x01; |
| 826 |
b400m_setreg(b4, R_MISC_IRQMSK, b4->misc_irq_mask); |
| 827 |
|
| 828 |
|
| 829 |
b400m_getreg(b4, R_STATUS); |
| 830 |
b400m_getreg(b4, R_MISC_IRQ); |
| 831 |
b400m_getreg(b4, R_FIFO_BL0_IRQ); |
| 832 |
b400m_getreg(b4, R_FIFO_BL1_IRQ); |
| 833 |
b400m_getreg(b4, R_FIFO_BL2_IRQ); |
| 834 |
b400m_getreg(b4, R_FIFO_BL3_IRQ); |
| 835 |
|
| 836 |
hfc_enable_fifo_irqs(b4); |
| 837 |
} |
| 838 |
|
| 839 |
static inline void hfc_reset_fifo(struct b400m *b4) |
| 840 |
{ |
| 841 |
hfc_setreg_waitbusy(b4, A_INC_RES_FIFO, |
| 842 |
V_RES_FIFO | V_RES_LOST | V_RES_FIFO_ERR); |
| 843 |
} |
| 844 |
|
| 845 |
static void hfc_setup_fifo(struct b400m *b4, int fifo) |
| 846 |
{ |
| 847 |
if (fifo < 4) { |
| 848 |
|
| 849 |
hfc_setreg_waitbusy(b4, R_FIFO, (fifo << V_FIFO_NUM_SHIFT)); |
| 850 |
b400m_setreg(b4, A_CON_HDLC, |
| 851 |
V_HDLC_IRQ | V_DATA_FLOW_000 | V_IFF); |
| 852 |
hfc_reset_fifo(b4); |
| 853 |
|
| 854 |
|
| 855 |
hfc_setreg_waitbusy(b4, R_FIFO, |
| 856 |
(fifo << V_FIFO_NUM_SHIFT) | V_FIFO_DIR); |
| 857 |
b400m_setreg(b4, A_CON_HDLC, |
| 858 |
V_HDLC_IRQ | V_DATA_FLOW_000 | V_IFF); |
| 859 |
hfc_reset_fifo(b4); |
| 860 |
} else { |
| 861 |
|
| 862 |
hfc_setreg_waitbusy(b4, R_FIFO, (fifo << V_FIFO_NUM_SHIFT)); |
| 863 |
b400m_setreg(b4, A_CON_HDLC, |
| 864 |
V_HDLC_TRP | V_TRP_NO_IRQ | V_DATA_FLOW_110); |
| 865 |
hfc_reset_fifo(b4); |
| 866 |
|
| 867 |
|
| 868 |
hfc_setreg_waitbusy(b4, R_FIFO, |
| 869 |
(fifo << V_FIFO_NUM_SHIFT) | V_FIFO_DIR); |
| 870 |
b400m_setreg(b4, A_CON_HDLC, |
| 871 |
V_HDLC_TRP | V_TRP_NO_IRQ | V_DATA_FLOW_110); |
| 872 |
hfc_reset_fifo(b4); |
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
static void hfc_setup_pcm(struct b400m *b4, int port) |
| 877 |
{ |
| 878 |
int physport; |
| 879 |
int offset; |
| 880 |
int hfc_chan; |
| 881 |
int ts; |
| 882 |
#ifdef HARDHDLC_RX |
| 883 |
const int MAX_OFFSET = 2; |
| 884 |
#else |
| 885 |
const int MAX_OFFSET = 3; |
| 886 |
#endif |
| 887 |
|
| 888 |
#ifdef SWAP_PORTS |
| 889 |
|
| 890 |
physport = (1 == port) ? 2 : (2 == port) ? 1 : port; |
| 891 |
#else |
| 892 |
physport = port; |
| 893 |
#endif |
| 894 |
|
| 895 |
for (offset = 0; offset < MAX_OFFSET; offset++) { |
| 896 |
hfc_chan = (port * 4) + offset; |
| 897 |
ts = (physport * 3) + offset; |
| 898 |
ts += (b4->b400m_no * 12); |
| 899 |
b400m_setreg(b4, R_SLOT, (ts << V_SL_NUM_SHIFT)); |
| 900 |
b400m_setreg(b4, A_SL_CFG, |
| 901 |
(hfc_chan << V_CH_SNUM_SHIFT) | |
| 902 |
V_ROUT_TX_STIO2); |
| 903 |
|
| 904 |
if (offset < 2) { |
| 905 |
b400m_setreg(b4, R_SLOT, |
| 906 |
(ts << V_SL_NUM_SHIFT) | |
| 907 |
V_SL_DIR); |
| 908 |
b400m_setreg(b4, A_SL_CFG, |
| 909 |
(hfc_chan << V_CH_SNUM_SHIFT) | |
| 910 |
V_ROUT_RX_STIO1 | V_CH_SDIR); |
| 911 |
} |
| 912 |
} |
| 913 |
} |
| 914 |
|
| 915 |
#ifdef SWAP_PORTS |
| 916 |
#ifdef HARDHDLC_RX |
| 917 |
static const int fifos[24] = {0, 0, 2, 2, 1, 1, 3, 3, 4, 4, 4, 4, 6, 6, 6, 6, |
| 918 |
5, 5, 5, 5, 7, 7, 7, 7 }; |
| 919 |
#else |
| 920 |
static const int fifos[24] = {0, 4, 2, 6, 1, 5, 3, 7, 4, 4, 4, 4, 6, 6, 6, 6, |
| 921 |
5, 5, 5, 5, 7, 7, 7, 7 }; |
| 922 |
#endif |
| 923 |
static const int hfc_chans[12] = {2, 10, 6, 14, 0, 1, 8, 9, 4, 5, 12, 13 }; |
| 924 |
#else |
| 925 |
#ifdef HARDHDLC_RX |
| 926 |
static const int fifos[24] = {0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, |
| 927 |
6, 6, 6, 6, 7, 7, 7, 7 }; |
| 928 |
#else |
| 929 |
static const int fifos[24] = {0, 4, 1, 5, 2, 6, 3, 7, 4, 4, 4, 4, 5, 5, 5, 5, |
| 930 |
6, 6, 6, 6, 7, 7, 7, 7 }; |
| 931 |
#endif |
| 932 |
static const int hfc_chans[12] = { 2, 6, 10, 14, 0, 1, 4, 5, 8, 9, 12, 13 }; |
| 933 |
#endif |
| 934 |
|
| 935 |
static void hfc_setup_fifo_arrays(struct b400m *b4, int fifo) |
| 936 |
{ |
| 937 |
int val; |
| 938 |
if (!fifo) { |
| 939 |
val = (fifos[fifo] << V_FIRST_FIFO_NUM_SHIFT) | (fifo & 1); |
| 940 |
b400m_setreg(b4, R_FIRST_FIFO, val); |
| 941 |
} else { |
| 942 |
#ifdef HARDHDLC_RX |
| 943 |
val = (fifos[fifo] << V_NEXT_FIFO_NUM_SHIFT) | (fifo & 1); |
| 944 |
#else |
| 945 |
val = (fifo < 8) ? (fifos[fifo] << V_NEXT_FIFO_NUM_SHIFT) : |
| 946 |
(fifos[fifo] << V_NEXT_FIFO_NUM_SHIFT) | |
| 947 |
(fifo&1); |
| 948 |
#endif |
| 949 |
b400m_setreg(b4, A_FIFO_SEQ, val); |
| 950 |
} |
| 951 |
|
| 952 |
b400m_setreg(b4, R_FSM_IDX, fifo); |
| 953 |
val = (fifo < 8) ? (hfc_chans[fifo>>1] << V_CH_FNUM_SHIFT) : |
| 954 |
(hfc_chans[fifo>>1] << V_CH_FNUM_SHIFT) | |
| 955 |
(fifo & 1); |
| 956 |
|
| 957 |
b400m_setreg(b4, A_CHANNEL, val); |
| 958 |
b400m_setreg(b4, A_SUBCH_CFG, 0x02); |
| 959 |
} |
| 960 |
|
| 961 |
static void hfc_setup_fsm(struct b400m *b4) |
| 962 |
{ |
| 963 |
int chan, fifo, port, offset; |
| 964 |
#ifdef SWAP_PORTS |
| 965 |
const int chan_to_fifo[12] = { 4, 4, 0, 6, 6, 2, 5, 5, 1, 7, 7, 3 }; |
| 966 |
#else |
| 967 |
const int chan_to_fifo[12] = { 4, 4, 0, 5, 5, 1, 6, 6, 2, 7, 7, 3 }; |
| 968 |
#endif |
| 969 |
|
| 970 |
for (port = 0; port < 4; port++) { |
| 971 |
for (offset = 0; offset < 3; offset++) { |
| 972 |
b4->spans[port].fifos[offset] = |
| 973 |
chan_to_fifo[(port * 3) + offset]; |
| 974 |
} |
| 975 |
} |
| 976 |
|
| 977 |
for (chan = 0; chan < ARRAY_SIZE(fifos); chan++) |
| 978 |
hfc_setup_fifo_arrays(b4, chan); |
| 979 |
|
| 980 |
b400m_setreg(b4, A_FIFO_SEQ, V_SEQ_END); |
| 981 |
|
| 982 |
for (fifo = 0; fifo < 8; fifo++) |
| 983 |
hfc_setup_fifo(b4, fifo); |
| 984 |
|
| 985 |
for (port = 0; port < 4; port++) |
| 986 |
hfc_setup_pcm(b4, port); |
| 987 |
} |
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
static void hfc_reset_fifo_pair(struct b400m *b4, int fifo, |
| 992 |
int reset, int force_no_irq) |
| 993 |
{ |
| 994 |
unsigned char b; |
| 995 |
|
| 996 |
if (down_interruptible(&b4->fifosem)) { |
| 997 |
b4_info(b4, "Unable to retrieve fifo sem\n"); |
| 998 |
return; |
| 999 |
} |
| 1000 |
b = (!force_no_irq && b4->fifo_en_txint & (1 << fifo)) ? |
| 1001 |
V_FIFO_IRQMSK : 0; |
| 1002 |
hfc_setreg_waitbusy(b4, R_FIFO, (fifo << V_FIFO_NUM_SHIFT)); |
| 1003 |
|
| 1004 |
if (fifo < 4) |
| 1005 |
b |= V_MIX_IRQ; |
| 1006 |
|
| 1007 |
b400m_setreg(b4, A_FIFO_CTRL, b); |
| 1008 |
|
| 1009 |
if (reset) |
| 1010 |
hfc_reset_fifo(b4); |
| 1011 |
|
| 1012 |
b = (!force_no_irq && b4->fifo_en_rxint & (1 << fifo)) ? |
| 1013 |
V_FIFO_IRQMSK : 0; |
| 1014 |
hfc_setreg_waitbusy(b4, R_FIFO, |
| 1015 |
(fifo << V_FIFO_NUM_SHIFT) | V_FIFO_DIR); |
| 1016 |
|
| 1017 |
if (fifo < 4) |
| 1018 |
b |= V_MIX_IRQ; |
| 1019 |
|
| 1020 |
b400m_setreg(b4, A_FIFO_CTRL, b); |
| 1021 |
|
| 1022 |
if (reset) |
| 1023 |
hfc_reset_fifo(b4); |
| 1024 |
|
| 1025 |
up(&b4->fifosem); |
| 1026 |
} |
| 1027 |
|
| 1028 |
static void xhfc_set_sync_src(struct b400m *b4, int port) |
| 1029 |
{ |
| 1030 |
int b; |
| 1031 |
|
| 1032 |
|
| 1033 |
if (port == -2) |
| 1034 |
return; |
| 1035 |
|
| 1036 |
if (port == b4->setsyncspan) |
| 1037 |
return; |
| 1038 |
else |
| 1039 |
b4->setsyncspan = port; |
| 1040 |
|
| 1041 |
b4_info(b4, "xhfc_set_sync_src - modpos %d: setting sync to " |
| 1042 |
"be port %d\n", b4->position, port); |
| 1043 |
|
| 1044 |
if (port == -1) |
| 1045 |
b = 0; |
| 1046 |
else { |
| 1047 |
#ifdef SWAP_PORTS |
| 1048 |
port = (1 == port) ? 2 : (2 == port) ? 1 : port; |
| 1049 |
#endif |
| 1050 |
b = (port & V_SYNC_SEL_MASK) | V_MAN_SYNC; |
| 1051 |
} |
| 1052 |
|
| 1053 |
b400m_setreg(b4, R_SU_SYNC, b); |
| 1054 |
} |
| 1055 |
|
| 1056 |
static void wctdm_change_card_sync_src(struct wctdm *wc, int newsrc, int master) |
| 1057 |
{ |
| 1058 |
int newctlreg; |
| 1059 |
|
| 1060 |
newctlreg = wc->ctlreg; |
| 1061 |
|
| 1062 |
if (master) |
| 1063 |
newctlreg |= (1 << 5); |
| 1064 |
else |
| 1065 |
newctlreg &= ~(1 << 5); |
| 1066 |
|
| 1067 |
newctlreg &= 0xfc; |
| 1068 |
|
| 1069 |
newctlreg |= newsrc; |
| 1070 |
|
| 1071 |
if (DBG_TIMING) { |
| 1072 |
dev_info(&wc->vb.pdev->dev, |
| 1073 |
"Final ctlreg before swap: %02x\n", newctlreg); |
| 1074 |
} |
| 1075 |
|
| 1076 |
wc->ctlreg = newctlreg; |
| 1077 |
wc->oldsync = newsrc; |
| 1078 |
|
| 1079 |
msleep(10); |
| 1080 |
} |
| 1081 |
|
| 1082 |
static void wctdm_change_system_sync_src(int oldsync, int oldspan, |
| 1083 |
int newsync, int newspan) |
| 1084 |
{ |
| 1085 |
struct wctdm *wc; |
| 1086 |
struct wctdm *oldsyncwc = NULL, *newsyncwc = NULL; |
| 1087 |
int newspot; |
| 1088 |
int i; |
| 1089 |
int max_latency = 0; |
| 1090 |
|
| 1091 |
if (oldsync > -1) |
| 1092 |
oldsyncwc = ifaces[oldsync]; |
| 1093 |
|
| 1094 |
if (newsync > -1) |
| 1095 |
newsyncwc = ifaces[newsync]; |
| 1096 |
|
| 1097 |
if (newsync == -1) { |
| 1098 |
BUG_ON(!ifaces[0]); |
| 1099 |
|
| 1100 |
newsyncwc = ifaces[0]; |
| 1101 |
newsync = 0; |
| 1102 |
} |
| 1103 |
|
| 1104 |
newspot = (-1 == newspan) ? 0 : 2 | (newspan >> 2); |
| 1105 |
|
| 1106 |
if ((oldsync == newsync) && (oldspan == newspan)) { |
| 1107 |
dev_info(&newsyncwc->vb.pdev->dev, |
| 1108 |
"No need for timing change. All is same\n"); |
| 1109 |
return; |
| 1110 |
} |
| 1111 |
|
| 1112 |
|
| 1113 |
for (i = 0; i < WC_MAX_IFACES; i++) { |
| 1114 |
wc = ifaces[i]; |
| 1115 |
if ((wc != oldsyncwc) && wc) { |
| 1116 |
wctdm_change_card_sync_src(wc, 0, 0); |
| 1117 |
if (voicebus_current_latency(&wc->vb) > max_latency) |
| 1118 |
max_latency = voicebus_current_latency(&wc->vb); |
| 1119 |
} |
| 1120 |
} |
| 1121 |
msleep(max_latency << 1); |
| 1122 |
|
| 1123 |
|
| 1124 |
if (oldsyncwc) { |
| 1125 |
wctdm_change_card_sync_src(oldsyncwc, 0, 0); |
| 1126 |
msleep(voicebus_current_latency(&oldsyncwc->vb) << 1); |
| 1127 |
} |
| 1128 |
|
| 1129 |
dev_info(&newsyncwc->vb.pdev->dev, |
| 1130 |
"Setting new card %d now to be timing master\n", newsync); |
| 1131 |
|
| 1132 |
wctdm_change_card_sync_src(newsyncwc, newspot, 1); |
| 1133 |
msleep(voicebus_current_latency(&newsyncwc->vb) << 1); |
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
for (i = 0; (i < WC_MAX_IFACES) && ifaces[i]; i++) { |
| 1138 |
wc = ifaces[i]; |
| 1139 |
if (i == newsync) |
| 1140 |
continue; |
| 1141 |
|
| 1142 |
dev_info(&wc->vb.pdev->dev, |
| 1143 |
"Setting card %d to be timing slave\n", i); |
| 1144 |
wctdm_change_card_sync_src(wc, 1, 0); |
| 1145 |
} |
| 1146 |
msleep(max_latency << 1); |
| 1147 |
synccard = newsync; |
| 1148 |
syncspan = newspan; |
| 1149 |
} |
| 1150 |
|
| 1151 |
static int xhfc_find_sync_with_timingcable(struct b400m *b4) |
| 1152 |
{ |
| 1153 |
struct wctdm *wc = b4->wc; |
| 1154 |
int i, j, osrc, src = -1; |
| 1155 |
int lowestprio = 10000; |
| 1156 |
int lowestcard = -1; |
| 1157 |
|
| 1158 |
if (down_trylock(&ifacelock)) { |
| 1159 |
set_bit(WCTDM_CHECK_TIMING, &wc->checkflag); |
| 1160 |
return -2; |
| 1161 |
} |
| 1162 |
|
| 1163 |
for (j = 0; j < WC_MAX_IFACES && ifaces[j]; j++) { |
| 1164 |
if (is_initialized(ifaces[j])) { |
| 1165 |
set_bit(WCTDM_CHECK_TIMING, &wc->checkflag); |
| 1166 |
osrc = -2; |
| 1167 |
goto out; |
| 1168 |
} else { |
| 1169 |
for (i = 0; i < (MAX_SPANS - 1); i++) { |
| 1170 |
struct wctdm_span *wspan = ifaces[j]->spans[i]; |
| 1171 |
if (wspan && |
| 1172 |
wspan->timing_priority && |
| 1173 |
!wspan->span.alarms && |
| 1174 |
(wspan->timing_priority < |
| 1175 |
lowestprio)) { |
| 1176 |
src = i; |
| 1177 |
lowestprio = wspan->timing_priority; |
| 1178 |
lowestcard = j; |
| 1179 |
} |
| 1180 |
} |
| 1181 |
} |
| 1182 |
} |
| 1183 |
|
| 1184 |
if (lowestcard != synccard) { |
| 1185 |
b4_info(b4, "Found new timing master, card " |
| 1186 |
"%d. Old is card %d\n", lowestcard, synccard); |
| 1187 |
} else if (src != syncspan) { |
| 1188 |
b4_info(b4, "Timing change, but only from %d to %d on " |
| 1189 |
"card %d\n", syncspan, src, lowestcard); |
| 1190 |
} |
| 1191 |
|
| 1192 |
wctdm_change_system_sync_src(synccard, syncspan, |
| 1193 |
lowestcard, src); |
| 1194 |
|
| 1195 |
osrc = -1; |
| 1196 |
|
| 1197 |
if (wc == ifaces[lowestcard]) { |
| 1198 |
if (src < (b4->position + 4) && (src >= b4->position)) |
| 1199 |
osrc = src - b4->position; |
| 1200 |
} |
| 1201 |
|
| 1202 |
out: |
| 1203 |
up(&ifacelock); |
| 1204 |
|
| 1205 |
return osrc; |
| 1206 |
} |
| 1207 |
|
| 1208 |
static int xhfc_find_sync_without_timingcable(struct b400m *b4) |
| 1209 |
{ |
| 1210 |
struct wctdm *wc = b4->wc; |
| 1211 |
int i, osrc, src = -1; |
| 1212 |
int lowestprio = 10000; |
| 1213 |
int newctlregmux; |
| 1214 |
|
| 1215 |
if (down_trylock(&wc->syncsem)) { |
| 1216 |
set_bit(WCTDM_CHECK_TIMING, &wc->checkflag); |
| 1217 |
return -2; |
| 1218 |
} |
| 1219 |
|
| 1220 |
|
| 1221 |
for (i = 0; i < (MAX_SPANS - 1); i++) { |
| 1222 |
struct wctdm_span *const wspan = wc->spans[i]; |
| 1223 |
if (wspan && wspan->timing_priority && |
| 1224 |
!wspan->span.alarms && |
| 1225 |
(wspan->timing_priority < lowestprio)) { |
| 1226 |
src = i; |
| 1227 |
lowestprio = wspan->timing_priority; |
| 1228 |
} |
| 1229 |
} |
| 1230 |
|
| 1231 |
if (src < 0) { |
| 1232 |
if (DBG_TIMING) |
| 1233 |
b4_info(b4, "Picked analog span\n"); |
| 1234 |
osrc = src; |
| 1235 |
goto check_card_timing; |
| 1236 |
} else { |
| 1237 |
if (DBG_TIMING) { |
| 1238 |
b4_info(b4, "Picked span offset %d to be timing " |
| 1239 |
"source\n", src); |
| 1240 |
} |
| 1241 |
} |
| 1242 |
|
| 1243 |
osrc = ((src < (b4->position + 4)) && (src >= b4->position)) ? |
| 1244 |
src - b4->position : -1; |
| 1245 |
|
| 1246 |
if (DBG_TIMING) { |
| 1247 |
b4_info(b4, "For b4->position %d timing is %d\n", |
| 1248 |
b4->position, osrc); |
| 1249 |
} |
| 1250 |
|
| 1251 |
check_card_timing: |
| 1252 |
|
| 1253 |
if (src != -1) |
| 1254 |
newctlregmux = 2 | (src >> 2); |
| 1255 |
else |
| 1256 |
newctlregmux = 0; |
| 1257 |
|
| 1258 |
if ((newctlregmux & 3) != (wc->ctlreg & 3)) { |
| 1259 |
if (DBG_TIMING) { |
| 1260 |
b4_info(b4, "!!!Need to change timing " |
| 1261 |
"on baseboard to spot %d!!!\n", |
| 1262 |
src >> 2); |
| 1263 |
} |
| 1264 |
|
| 1265 |
wctdm_change_card_sync_src(wc, newctlregmux, 0); |
| 1266 |
} else { |
| 1267 |
if (DBG_TIMING) { |
| 1268 |
dev_info(&b4->wc->vb.pdev->dev, "!!!No need to change timing " \ |
| 1269 |
"on baseboard to spot %d, already there!!!\n", |
| 1270 |
src >> 2); |
| 1271 |
|
| 1272 |
} |
| 1273 |
} |
| 1274 |
|
| 1275 |
|
| 1276 |
up(&wc->syncsem); |
| 1277 |
|
| 1278 |
return osrc; |
| 1279 |
} |
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
static inline int xhfc_find_sync(struct b400m *b4) |
| 1287 |
{ |
| 1288 |
if (timingcable) |
| 1289 |
return xhfc_find_sync_with_timingcable(b4); |
| 1290 |
else |
| 1291 |
return xhfc_find_sync_without_timingcable(b4); |
| 1292 |
} |
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
static char *hfc_decode_st_state(struct b400m *b4, struct b400m_span *span, |
| 1302 |
unsigned char state, int full) |
| 1303 |
{ |
| 1304 |
int nt, sta; |
| 1305 |
char s[128], *str; |
| 1306 |
const char *ststr[2][16] = { |
| 1307 |
{ "RESET", "?", "SENSING", "DEACT.", |
| 1308 |
"AWAIT.SIG", "IDENT.INPUT", "SYNCD", "ACTIVATED", |
| 1309 |
"LOSTFRAMING", "?", "?", "?", |
| 1310 |
"?", "?", "?", "?" }, |
| 1311 |
{ "RESET", "DEACT.", "PEND.ACT", "ACTIVE", |
| 1312 |
"PEND.DEACT", "?", "?", "?", |
| 1313 |
"?", "?", "?", "?", |
| 1314 |
"?", "?", "?", "?" } |
| 1315 |
}; |
| 1316 |
|
| 1317 |
str = kmalloc(256, GFP_KERNEL); |
| 1318 |
if (!str) { |
| 1319 |
dev_warn(&b4->wc->vb.pdev->dev, |
| 1320 |
"could not allocate mem for ST state decode " \ |
| 1321 |
"string!\n"); |
| 1322 |
return NULL; |
| 1323 |
} |
| 1324 |
|
| 1325 |
nt = (span->te_mode == 0); |
| 1326 |
sta = (state & V_SU_STA_MASK); |
| 1327 |
|
| 1328 |
sprintf(str, "P%d: %s state %c%d (%s)", span->port + 1, |
| 1329 |
(nt ? "NT" : "TE"), (nt ? 'G' : 'F'), sta, |
| 1330 |
ststr[nt][sta]); |
| 1331 |
|
| 1332 |
if (full) { |
| 1333 |
sprintf(s, " SYNC: %s, RX INFO0: %s", |
| 1334 |
((state & V_SU_FR_SYNC) ? "yes" : "no"), |
| 1335 |
((state & V_SU_INFO0) ? "yes" : "no")); |
| 1336 |
strcat(str, s); |
| 1337 |
|
| 1338 |
if (nt) { |
| 1339 |
sprintf(s, ", T2 %s, auto G2->G3: %s", |
| 1340 |
((state & V_SU_T2_EXP) ? "expired" : "OK"), |
| 1341 |
((state & V_G2_G3) ? "yes" : "no")); |
| 1342 |
strcat(str, s); |
| 1343 |
} |
| 1344 |
} |
| 1345 |
|
| 1346 |
return str; |
| 1347 |
} |
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
static void hfc_handle_state(struct b400m_span *s); |
| 1354 |
static void hfc_force_st_state(struct b400m *b4, struct b400m_span *s, |
| 1355 |
int state, int resume_auto) |
| 1356 |
{ |
| 1357 |
b400m_setreg_ra(b4, R_SU_SEL, s->port, A_SU_WR_STA, |
| 1358 |
state | V_SU_LD_STA); |
| 1359 |
|
| 1360 |
if (resume_auto) |
| 1361 |
b400m_setreg_ra(b4, R_SU_SEL, s->port, A_SU_WR_STA, state); |
| 1362 |
|
| 1363 |
if (DBG_ST && ((1 << s->port) & bri_spanfilter)) { |
| 1364 |
char *x; |
| 1365 |
|
| 1366 |
x = hfc_decode_st_state(b4, s, state, 1); |
| 1367 |
b4_info(b4, "forced port %d to state %d (auto: %d), " |
| 1368 |
"new decode: %s\n", s->port + 1, state, |
| 1369 |
resume_auto, x); |
| 1370 |
kfree(x); |
| 1371 |
} |
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
hfc_handle_state(s); |
| 1376 |
} |
| 1377 |
|
| 1378 |
|
| 1379 |
static void hfc_timer_expire(struct b400m_span *s, int t_no) |
| 1380 |
{ |
| 1381 |
struct b400m *b4 = s->parent; |
| 1382 |
|
| 1383 |
if (DBG_ST && ((1 << s->port) & bri_spanfilter)) { |
| 1384 |
b4_info(b4, "%lu: hfc_timer_expire, Port %d T%d " |
| 1385 |
"expired (value=%lu ena=%d)\n", b4->ticks, |
| 1386 |
s->port + 1, t_no + 1, s->hfc_timers[t_no], |
| 1387 |
s->hfc_timer_on[t_no]); |
| 1388 |
} |
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
s->hfc_timer_on[t_no] = 0; |
| 1405 |
|
| 1406 |
switch (t_no) { |
| 1407 |
case XHFC_T1: |
| 1408 |
hfc_force_st_state(b4, s, 4, 1); |
| 1409 |
break; |
| 1410 |
case XHFC_T2: |
| 1411 |
hfc_force_st_state(b4, s, 1, 1); |
| 1412 |
break; |
| 1413 |
case XHFC_T3: |
| 1414 |
hfc_stop_st(s); |
| 1415 |
if (bri_persistentlayer1) |
| 1416 |
hfc_start_st(s); |
| 1417 |
break; |
| 1418 |
case XHFC_T4: |
| 1419 |
hfc_handle_state(s); |
| 1420 |
s->hfc_timers[XHFC_T4] = b4->ticks + 1000; |
| 1421 |
s->hfc_timer_on[XHFC_T4] = 1; |
| 1422 |
break; |
| 1423 |
default: |
| 1424 |
if (printk_ratelimit()) { |
| 1425 |
dev_warn(&b4->wc->vb.pdev->dev, |
| 1426 |
"hfc_timer_expire found an unknown expired " |
| 1427 |
"timer (%d)??\n", t_no); |
| 1428 |
} |
| 1429 |
} |
| 1430 |
} |
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
static void hfc_update_st_timers(struct b400m *b4) |
| 1437 |
{ |
| 1438 |
int i, j; |
| 1439 |
struct b400m_span *s; |
| 1440 |
|
| 1441 |
for (i = 0; i < 4; i++) { |
| 1442 |
s = &b4->spans[i]; |
| 1443 |
|
| 1444 |
for (j = XHFC_T1; j <= XHFC_T4; j++) { |
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
if (j == XHFC_T2) |
| 1449 |
continue; |
| 1450 |
|
| 1451 |
if (s->hfc_timer_on[j] && |
| 1452 |
time_after_eq(b4->ticks, s->hfc_timers[j])) |
| 1453 |
hfc_timer_expire(s, j); |
| 1454 |
} |
| 1455 |
|
| 1456 |
if (s->wspan && s->newalarm != s->wspan->span.alarms && |
| 1457 |
time_after_eq(b4->ticks, s->alarmtimer)) { |
| 1458 |
s->wspan->span.alarms = s->newalarm; |
| 1459 |
if ((!s->newalarm && bri_teignorered) || (!bri_teignorered)) |
| 1460 |
dahdi_alarm_notify(&s->wspan->span); |
| 1461 |
|
| 1462 |
if (DBG_ALARM) { |
| 1463 |
dev_info(&b4->wc->vb.pdev->dev, "span %d: alarm " \ |
| 1464 |
"%d debounced\n", i + 1, |
| 1465 |
s->newalarm); |
| 1466 |
} |
| 1467 |
set_bit(WCTDM_CHECK_TIMING, &b4->wc->checkflag); |
| 1468 |
} |
| 1469 |
} |
| 1470 |
|
| 1471 |
if (test_and_clear_bit(WCTDM_CHECK_TIMING, &b4->wc->checkflag)) |
| 1472 |
xhfc_set_sync_src(b4, xhfc_find_sync(b4)); |
| 1473 |
} |
| 1474 |
|
| 1475 |
|
| 1476 |
static void hfc_handle_state(struct b400m_span *s) |
| 1477 |
{ |
| 1478 |
struct b400m *b4; |
| 1479 |
unsigned char state, sta; |
| 1480 |
int nt, newsync, oldalarm; |
| 1481 |
unsigned long oldtimer; |
| 1482 |
|
| 1483 |
b4 = s->parent; |
| 1484 |
nt = !s->te_mode; |
| 1485 |
|
| 1486 |
state = b400m_getreg_ra(b4, R_SU_SEL, s->port, A_SU_RD_STA); |
| 1487 |
sta = (state & V_SU_STA_MASK); |
| 1488 |
|
| 1489 |
if (DBG_ST && ((1 << s->port) & bri_spanfilter)) { |
| 1490 |
char *x; |
| 1491 |
|
| 1492 |
x = hfc_decode_st_state(b4, s, state, 1); |
| 1493 |
b4_info(b4, "port %d A_SU_RD_STA old=0x%02x " |
| 1494 |
"now=0x%02x, decoded: %s\n", s->port + 1, |
| 1495 |
s->oldstate, state, x); |
| 1496 |
kfree(x); |
| 1497 |
} |
| 1498 |
|
| 1499 |
oldalarm = s->newalarm; |
| 1500 |
oldtimer = s->alarmtimer; |
| 1501 |
|
| 1502 |
if (nt) { |
| 1503 |
switch (sta) { |
| 1504 |
default: |
| 1505 |
case 0x0: |
| 1506 |
case 0x1: |
| 1507 |
case 0x4: |
| 1508 |
s->newalarm = DAHDI_ALARM_RED; |
| 1509 |
break; |
| 1510 |
case 0x2: |
| 1511 |
s->newalarm = DAHDI_ALARM_YELLOW; |
| 1512 |
break; |
| 1513 |
case 0x3: |
| 1514 |
s->hfc_timer_on[XHFC_T1] = 0; |
| 1515 |
s->newalarm = 0; |
| 1516 |
break; |
| 1517 |
} |
| 1518 |
} else { |
| 1519 |
switch (sta) { |
| 1520 |
default: |
| 1521 |
case 0x0: |
| 1522 |
case 0x2: |
| 1523 |
case 0x3: |
| 1524 |
case 0x4: |
| 1525 |
case 0x8: |
| 1526 |
s->newalarm = DAHDI_ALARM_RED; |
| 1527 |
break; |
| 1528 |
case 0x5: |
| 1529 |
case 0x6: |
| 1530 |
s->newalarm = DAHDI_ALARM_YELLOW; |
| 1531 |
break; |
| 1532 |
case 0x7: |
| 1533 |
s->hfc_timer_on[XHFC_T3] = 0; |
| 1534 |
s->hfc_timer_on[XHFC_T4] = 0; |
| 1535 |
s->newalarm = 0; |
| 1536 |
break; |
| 1537 |
} |
| 1538 |
} |
| 1539 |
|
| 1540 |
s->alarmtimer = b4->ticks + bri_alarmdebounce; |
| 1541 |
s->oldstate = state; |
| 1542 |
|
| 1543 |
if (DBG_ALARM) { |
| 1544 |
b4_info(b4, "span %d: old alarm %d expires %ld, " |
| 1545 |
"new alarm %d expires %ld\n", s->port + 1, oldalarm, |
| 1546 |
oldtimer, s->newalarm, s->alarmtimer); |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
if (nt && (sta == 4) && (state & V_SU_T2_EXP)) { |
| 1551 |
if (s->hfc_timer_on[XHFC_T2]) |
| 1552 |
hfc_timer_expire(s, XHFC_T2); |
| 1553 |
} |
| 1554 |
|
| 1555 |
|
| 1556 |
if (!nt && (sta == 3) && (state & V_SU_INFO0)) { |
| 1557 |
if (bri_persistentlayer1) { |
| 1558 |
s->hfc_timers[XHFC_T3] = b4->ticks + TIMER_3_MS; |
| 1559 |
s->hfc_timer_on[XHFC_T3] = 1; |
| 1560 |
if (DBG_ST) { |
| 1561 |
b4_info(b4, "port %d: receiving " |
| 1562 |
"INFO0 in state 3, setting T3 and " |
| 1563 |
"jumping to F4\n", s->port + 1); |
| 1564 |
} |
| 1565 |
hfc_start_st(s); |
| 1566 |
} |
| 1567 |
} |
| 1568 |
|
| 1569 |
|
| 1570 |
newsync = b400m_getreg(b4, R_BERT_STA) & 0x07; |
| 1571 |
if (newsync != b4->reportedsyncspan) { |
| 1572 |
if (DBG_TIMING) { |
| 1573 |
if (newsync == 5) { |
| 1574 |
b4_info(b4, "new card sync source: SYNC_I\n"); |
| 1575 |
} else { |
| 1576 |
b4_info(b4, "Card position %d: new " |
| 1577 |
"sync source: port %d\n", |
| 1578 |
b4->position, newsync); |
| 1579 |
} |
| 1580 |
} |
| 1581 |
|
| 1582 |
b4->reportedsyncspan = newsync; |
| 1583 |
} |
| 1584 |
} |
| 1585 |
|
| 1586 |
static void hfc_stop_all_timers(struct b400m_span *s) |
| 1587 |
{ |
| 1588 |
s->hfc_timer_on[XHFC_T4] = 0; |
| 1589 |
s->hfc_timer_on[XHFC_T3] = 0; |
| 1590 |
s->hfc_timer_on[XHFC_T2] = 0; |
| 1591 |
s->hfc_timer_on[XHFC_T1] = 0; |
| 1592 |
} |
| 1593 |
|
| 1594 |
static void hfc_stop_st(struct b400m_span *s) |
| 1595 |
{ |
| 1596 |
struct b400m *b4 = s->parent; |
| 1597 |
|
| 1598 |
hfc_stop_all_timers(s); |
| 1599 |
|
| 1600 |
b400m_setreg_ra(b4, R_SU_SEL, s->port, A_SU_WR_STA, V_SU_ACT_DEACTIVATE); |
| 1601 |
} |
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
static void hfc_reset_st(struct b400m_span *s) |
| 1607 |
{ |
| 1608 |
int b; |
| 1609 |
struct b400m *b4; |
| 1610 |
|
| 1611 |
b4 = s->parent; |
| 1612 |
|
| 1613 |
hfc_stop_st(s); |
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
b400m_setreg_ra(b4, R_SU_SEL, s->port, A_SU_WR_STA, V_SU_LD_STA); |
| 1618 |
flush_hw(); |
| 1619 |
|
| 1620 |
s->wspan->span.alarms = DAHDI_ALARM_RED; |
| 1621 |
s->newalarm = DAHDI_ALARM_RED; |
| 1622 |
dahdi_alarm_notify(&s->wspan->span); |
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
if (s->te_mode) |
| 1627 |
b = 0x0e; |
| 1628 |
else |
| 1629 |
b = 0x0c | (6 << V_SU_SMPL_SHIFT); |
| 1630 |
|
| 1631 |
b400m_setreg(b4, A_SU_CLK_DLY, b); |
| 1632 |
|
| 1633 |
|
| 1634 |
b400m_setreg(b4, A_SU_CTRL0, V_B1_TX_EN | V_B2_TX_EN | |
| 1635 |
(s->te_mode ? 0 : V_SU_MD) | V_ST_PU_CTRL); |
| 1636 |
b400m_setreg(b4, A_SU_CTRL1, V_G2_G3_EN); |
| 1637 |
b400m_setreg(b4, A_SU_CTRL2, V_B1_RX_EN | V_B2_RX_EN); |
| 1638 |
b400m_setreg(b4, A_ST_CTRL3, (0x7c << 1)); |
| 1639 |
|
| 1640 |
|
| 1641 |
b400m_setreg(b4, A_SU_WR_STA, 0x00); |
| 1642 |
flush_hw(); |
| 1643 |
} |
| 1644 |
|
| 1645 |
static void hfc_start_st(struct b400m_span *s) |
| 1646 |
{ |
| 1647 |
struct b400m *b4 = s->parent; |
| 1648 |
|
| 1649 |
b400m_setreg_ra(b4, R_SU_SEL, s->port, A_SU_WR_STA, V_SU_ACT_ACTIVATE); |
| 1650 |
|
| 1651 |
|
| 1652 |
if (s->te_mode) { |
| 1653 |
|
| 1654 |
s->hfc_timers[XHFC_T3] = b4->ticks + TIMER_3_MS; |
| 1655 |
s->hfc_timer_on[XHFC_T3] = 1; |
| 1656 |
s->hfc_timer_on[XHFC_T1] = 0; |
| 1657 |
|
| 1658 |
s->hfc_timers[XHFC_T4] = b4->ticks + 1000; |
| 1659 |
s->hfc_timer_on[XHFC_T4] = 1; |
| 1660 |
|
| 1661 |
if (DBG_ST) { |
| 1662 |
b4_info(b4, "setting port %d t3 timer to %lu\n", |
| 1663 |
s->port + 1, s->hfc_timers[XHFC_T3]); |
| 1664 |
} |
| 1665 |
} else { |
| 1666 |
static const int TIMER_1_MS = 2000; |
| 1667 |
s->hfc_timers[XHFC_T1] = b4->ticks + TIMER_1_MS; |
| 1668 |
s->hfc_timer_on[XHFC_T1] = 1; |
| 1669 |
s->hfc_timer_on[XHFC_T3] = 0; |
| 1670 |
if (DBG_ST) { |
| 1671 |
b4_info(b4, "setting port %d t1 timer to %lu\n", |
| 1672 |
s->port + 1, s->hfc_timers[XHFC_T1]); |
| 1673 |
} |
| 1674 |
} |
| 1675 |
} |
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
static int hdlc_start(struct b400m *b4, int fifo); |
| 1683 |
static void hfc_init_all_st(struct b400m *b4) |
| 1684 |
{ |
| 1685 |
int i; |
| 1686 |
struct b400m_span *s; |
| 1687 |
|
| 1688 |
for (i = 0; i < 4; i++) { |
| 1689 |
s = &b4->spans[i]; |
| 1690 |
s->parent = b4; |
| 1691 |
|
| 1692 |
#ifdef SWAP_PORTS |
| 1693 |
s->port = (1 == i) ? 2 : (2 == i) ? 1 : i; |
| 1694 |
#else |
| 1695 |
s->port = i; |
| 1696 |
#endif |
| 1697 |
s->te_mode = 1; |
| 1698 |
|
| 1699 |
hdlc_start(b4, s->fifos[2]); |
| 1700 |
} |
| 1701 |
|
| 1702 |
} |
| 1703 |
|
| 1704 |
|
| 1705 |
#define debug_fz(b4, fifo, prefix, buf) \ |
| 1706 |
do { \ |
| 1707 |
sprintf(buf, "%s: (fifo %d): f1/f2/flen=%d/%d/%d, " \ |
| 1708 |
"z1/z2/zlen=%d/%d/%d\n", prefix, fifo, f1, f2, flen, z1, \ |
| 1709 |
z2, zlen); \ |
| 1710 |
} while (0) |
| 1711 |
|
| 1712 |
|
| 1713 |
static int hdlc_start(struct b400m *b4, int fifo) |
| 1714 |
{ |
| 1715 |
b4->fifo_en_txint |= (1 << fifo); |
| 1716 |
b4->fifo_en_rxint |= (1 << fifo); |
| 1717 |
|
| 1718 |
hfc_reset_fifo_pair(b4, fifo, 1, 0); |
| 1719 |
return 0; |
| 1720 |
} |
| 1721 |
|
| 1722 |
#ifdef HARDHDLC_RX |
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
static void hdlc_signal_complete(struct b400m_span *bspan, u8 stat) |
| 1732 |
{ |
| 1733 |
struct b400m *b4 = bspan->parent; |
| 1734 |
|
| 1735 |
|
| 1736 |
if (stat != 0x00) { |
| 1737 |
if (DBG_HDLC && DBG_SPANFILTER) { |
| 1738 |
b4_info(b4, "(span %d) STAT=0x%02x indicates " \ |
| 1739 |
"frame problem: %s\n", bspan->port + 1, stat, |
| 1740 |
(0xff == stat) ? "HDLC Abort" : "Bad FCS"); |
| 1741 |
} |
| 1742 |
|
| 1743 |
dahdi_hdlc_abort(bspan->sigchan, (0xff == stat) ? |
| 1744 |
DAHDI_EVENT_ABORT : DAHDI_EVENT_BADFCS); |
| 1745 |
|
| 1746 |
} else { |
| 1747 |
if (DBG_HDLC && DBG_SPANFILTER) { |
| 1748 |
b4_info(b4, "(span %d) Frame %d is good!\n", |
| 1749 |
bspan->port + 1, bspan->frames_in); |
| 1750 |
} |
| 1751 |
dahdi_hdlc_finish(bspan->sigchan); |
| 1752 |
} |
| 1753 |
} |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
static int hdlc_rx_frame(struct b400m_span *bspan) |
| 1764 |
{ |
| 1765 |
int fifo, i, j, x, zleft; |
| 1766 |
int z1, z2, zlen, f1, f2, flen, new_flen; |
| 1767 |
unsigned char buf[B400M_HDLC_BUF_LEN]; |
| 1768 |
char debugbuf[256]; |
| 1769 |
struct b400m *b4 = bspan->parent; |
| 1770 |
|
| 1771 |
fifo = bspan->fifos[2]; |
| 1772 |
|
| 1773 |
if (DBG_HDLC && DBG_SPANFILTER) |
| 1774 |
b4_info(b4, "hdlc_rx_frame fifo %d: start\n", fifo); |
| 1775 |
|
| 1776 |
if (down_trylock(&b4->fifosem) && DBG_HDLC && DBG_SPANFILTER) { |
| 1777 |
b4_info(b4, "rx_frame: fifo %d 1: couldn't get lock\n", |
| 1778 |
fifo); |
| 1779 |
return -1; |
| 1780 |
} |
| 1781 |
|
| 1782 |
hfc_setreg_waitbusy(b4, R_FIFO, |
| 1783 |
(fifo << V_FIFO_NUM_SHIFT) | V_FIFO_DIR); |
| 1784 |
get_F(f1, f2, flen); |
| 1785 |
get_Z(z1, z2, zlen); |
| 1786 |
debug_fz(b4, fifo, "hdlc_rx_frame", debugbuf); |
| 1787 |
up(&b4->fifosem); |
| 1788 |
|
| 1789 |
if (DBG_HDLC && DBG_SPANFILTER) |
| 1790 |
pr_info("%s", debugbuf); |
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
zleft = zlen; |
| 1795 |
if (flen) |
| 1796 |
zleft++; |
| 1797 |
|
| 1798 |
do { |
| 1799 |
if (zleft > B400M_HDLC_BUF_LEN) |
| 1800 |
j = B400M_HDLC_BUF_LEN; |
| 1801 |
else |
| 1802 |
j = zleft; |
| 1803 |
|
| 1804 |
if (down_trylock(&b4->fifosem) && DBG_HDLC && DBG_SPANFILTER) { |
| 1805 |
b4_info(b4, |
| 1806 |
"rx_frame fifo %d 2: couldn't get lock\n", |
| 1807 |
fifo); |
| 1808 |
return -1; |
| 1809 |
} |
| 1810 |
hfc_setreg_waitbusy(b4, R_FIFO, |
| 1811 |
(fifo << V_FIFO_NUM_SHIFT) | V_FIFO_DIR); |
| 1812 |
for (i = 0; i < j; i++) |
| 1813 |
buf[i] = b400m_getreg(b4, A_FIFO_DATA); |
| 1814 |
up(&b4->fifosem); |
| 1815 |
|
| 1816 |
|
| 1817 |
x = j; |
| 1818 |
if (bspan->sigchan) { |
| 1819 |
if ((j != B400M_HDLC_BUF_LEN) && flen) |
| 1820 |
x--; |
| 1821 |
if (x) |
| 1822 |
dahdi_hdlc_putbuf(bspan->sigchan, buf, x); |
| 1823 |
} |
| 1824 |
|
| 1825 |
zleft -= j; |
| 1826 |
|
| 1827 |
if (DBG_HDLC && DBG_SPANFILTER) { |
| 1828 |
b4_info(b4, "transmitted %d bytes to dahdi, " \ |
| 1829 |
"zleft=%d\n", x, zleft); |
| 1830 |
} |
| 1831 |
|
| 1832 |
if (DBG_HDLC && DBG_SPANFILTER) { |
| 1833 |
|
| 1834 |
b4_info(b4, "hdlc_rx_frame(span %d): " \ |
| 1835 |
"z1/z2/zlen=%d/%d/%d, zleft=%d\n", |
| 1836 |
bspan->port + 1, z1, z2, zlen, zleft); |
| 1837 |
for (i = 0; i < j; i++) { |
| 1838 |
b4_info(b4, "%02x%c", buf[i], |
| 1839 |
(i < (j - 1)) ? ' ' : '\n'); |
| 1840 |
} |
| 1841 |
} |
| 1842 |
} while (zleft > 0); |
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
if (down_trylock(&b4->fifosem) && DBG_HDLC && DBG_SPANFILTER) { |
| 1847 |
b4_info(b4, "rx_frame fifo %d 3: couldn't get lock\n", |
| 1848 |
fifo); |
| 1849 |
return 0; |
| 1850 |
} |
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
if (flen) { |
| 1855 |
hfc_setreg_waitbusy(b4, A_INC_RES_FIFO, V_INC_F); |
| 1856 |
++bspan->frames_in; |
| 1857 |
get_F(f1, f2, new_flen); |
| 1858 |
} else |
| 1859 |
new_flen = flen; |
| 1860 |
|
| 1861 |
up(&b4->fifosem); |
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
if (!bspan->sigchan) { |
| 1866 |
if (DBG_HDLC && DBG_SPANFILTER) { |
| 1867 |
b4_info(b4, "hdlc_rx_frame fifo %d: " \ |
| 1868 |
"new_flen %d, early end.\n", fifo, new_flen); |
| 1869 |
} |
| 1870 |
return new_flen; |
| 1871 |
} |
| 1872 |
|
| 1873 |
if (flen) { |
| 1874 |
|
| 1875 |
if (0 && zlen < 3) { |
| 1876 |
if (DBG_HDLC && DBG_SPANFILTER) |
| 1877 |
b4_info(b4, "odd, zlen less then 3?\n"); |
| 1878 |
dahdi_hdlc_abort(bspan->sigchan, DAHDI_EVENT_ABORT); |
| 1879 |
} else { |
| 1880 |
hdlc_signal_complete(bspan, buf[i - 1]); |
| 1881 |
} |
| 1882 |
} |
| 1883 |
|
| 1884 |
if (DBG_HDLC && DBG_SPANFILTER) { |
| 1885 |
b4_info(b4, "hdlc_rx_frame fifo %d: new_flen=%d end.\n", |
| 1886 |
fifo, new_flen); |
| 1887 |
} |
| 1888 |
|
| 1889 |
return new_flen; |
| 1890 |
} |
| 1891 |
|
| 1892 |
#endif |
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
static int hdlc_tx_frame(struct b400m_span *bspan) |
| 1902 |
{ |
| 1903 |
struct b400m *b4 = bspan->parent; |
| 1904 |
int res, i, fifo; |
| 1905 |
int z1, z2, zlen; |
| 1906 |
int f1 = -1, f2 = -1, flen = -1; |
| 1907 |
unsigned char buf[B400M_HDLC_BUF_LEN]; |
| 1908 |
unsigned int size = ARRAY_SIZE(buf); |
| 1909 |
char debugbuf[256]; |
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
if (bspan->te_mode && (bspan->newalarm != 0)) { |
| 1914 |
hfc_start_st(bspan); |
| 1915 |
} |
| 1916 |
|
| 1917 |
fifo = bspan->fifos[2]; |
| 1918 |
res = dahdi_hdlc_getbuf(bspan->sigchan, buf, &size); |
| 1919 |
|
| 1920 |
if (down_interruptible(&b4->fifosem)) { |
| 1921 |
static int arg; |
| 1922 |
b4_info(b4, "b400m: arg (%d), grabbed data from DAHDI " \ |
| 1923 |
"but couldn't grab the lock!\n", ++arg); |
| 1924 |
|
| 1925 |
|
| 1926 |
dahdi_hdlc_abort(bspan->sigchan, DAHDI_EVENT_OVERRUN); |
| 1927 |
return 1; |
| 1928 |
} |
| 1929 |
hfc_setreg_waitbusy(b4, R_FIFO, (fifo << V_FIFO_NUM_SHIFT)); |
| 1930 |
|
| 1931 |
get_Z(z1, z2, zlen); |
| 1932 |
debug_fz(b4, fifo, __func__, debugbuf); |
| 1933 |
|
| 1934 |
|
| 1935 |
if ((HFC_ZMAX-zlen) < size) { |
| 1936 |
static int arg; |
| 1937 |
b4_info(b4, "b400m: arg (%d), zlen (%d) < what we " \ |
| 1938 |
"grabbed from DAHDI (%d)!\n", ++arg, zlen, size); |
| 1939 |
size = zlen; |
| 1940 |
dahdi_hdlc_abort(bspan->sigchan, DAHDI_EVENT_OVERRUN); |
| 1941 |
} |
| 1942 |
|
| 1943 |
if (size > 0) { |
| 1944 |
bspan->sigactive = 1; |
| 1945 |
|
| 1946 |
for (i = 0; i < size; i++) |
| 1947 |
b400m_setreg(b4, A_FIFO_DATA, buf[i]); |
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
if (res != 0) { |
| 1956 |
++bspan->frames_out; |
| 1957 |
bspan->sigactive = 0; |
| 1958 |
hfc_setreg_waitbusy(b4, A_INC_RES_FIFO, V_INC_F); |
| 1959 |
atomic_dec(&bspan->hdlc_pending); |
| 1960 |
} else { |
| 1961 |
hfc_setreg_waitbusy(b4, R_FIFO, |
| 1962 |
(fifo << V_FIFO_NUM_SHIFT)); |
| 1963 |
} |
| 1964 |
} |
| 1965 |
|
| 1966 |
up(&b4->fifosem); |
| 1967 |
|
| 1968 |
if (0 && DBG_HDLC && DBG_SPANFILTER) { |
| 1969 |
b4_info(b4, "%s", debugbuf); |
| 1970 |
|
| 1971 |
b4_info(b4, "hdlc_tx_frame(span %d): DAHDI gave %d " \ |
| 1972 |
"bytes for FIFO %d (res = %d)\n", |
| 1973 |
bspan->port + 1, size, fifo, res); |
| 1974 |
|
| 1975 |
for (i = 0; i < size; i++) |
| 1976 |
b4_info(b4, |
| 1977 |
"%02x%c\n", buf[i], |
| 1978 |
(i < (size - 1)) ? ' ' : '\n'); |
| 1979 |
|
| 1980 |
if (size && res != 0) { |
| 1981 |
pr_info("Transmitted frame %d on span %d\n", |
| 1982 |
bspan->frames_out - 1, bspan->port); |
| 1983 |
} |
| 1984 |
} |
| 1985 |
|
| 1986 |
return (res == 0); |
| 1987 |
} |
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
static void xhfc_init_stage1(struct b400m *b4) |
| 2000 |
{ |
| 2001 |
int i; |
| 2002 |
|
| 2003 |
hfc_reset(b4); |
| 2004 |
hfc_gpio_init(b4); |
| 2005 |
|
| 2006 |
|
| 2007 |
b400m_setreg(b4, R_IRQ_CTRL, 0x00); |
| 2008 |
|
| 2009 |
|
| 2010 |
flush_hw(); |
| 2011 |
|
| 2012 |
|
| 2013 |
for (i = 0; i < HFC_NR_FIFOS; i++) { |
| 2014 |
hfc_setreg_waitbusy(b4, R_FIFO, (i << V_FIFO_NUM_SHIFT)); |
| 2015 |
|
| 2016 |
b400m_setreg(b4, A_FIFO_CTRL, 0x00); |
| 2017 |
hfc_setreg_waitbusy(b4, R_FIFO, |
| 2018 |
(i << V_FIFO_NUM_SHIFT) | V_FIFO_DIR); |
| 2019 |
|
| 2020 |
b400m_setreg(b4, A_FIFO_CTRL, 0x00); |
| 2021 |
flush_hw(); |
| 2022 |
} |
| 2023 |
|
| 2024 |
|
| 2025 |
b400m_setreg(b4, R_FIFO_THRES, 0x11); |
| 2026 |
|
| 2027 |
|
| 2028 |
b400m_getreg(b4, R_FIFO_BL2_IRQ); |
| 2029 |
b400m_getreg(b4, R_FIFO_BL3_IRQ); |
| 2030 |
|
| 2031 |
b4->misc_irq_mask = 0x00; |
| 2032 |
b400m_setreg(b4, R_MISC_IRQMSK, b4->misc_irq_mask); |
| 2033 |
b400m_setreg(b4, R_IRQ_CTRL, 0); |
| 2034 |
} |
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
static void xhfc_init_stage2(struct b400m *b4) |
| 2043 |
{ |
| 2044 |
|
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
b400m_setreg(b4, R_PCM_MD0, V_PCM_IDX_MD1); |
| 2051 |
b400m_setreg(b4, R_PCM_MD1, V_PCM_DR_8192 | (0x3 << 2)); |
| 2052 |
b400m_setreg(b4, R_PCM_MD0, V_PCM_IDX_MD2); |
| 2053 |
b400m_setreg(b4, R_PCM_MD2, V_C2I_EN | V_SYNC_OUT1); |
| 2054 |
b400m_setreg(b4, R_SU_SYNC, V_SYNC_SEL_PORT0); |
| 2055 |
|
| 2056 |
|
| 2057 |
hfc_setup_fsm(b4); |
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
} |
| 2065 |
|
| 2066 |
static inline struct b400m_span *bspan_from_dspan(struct dahdi_span *span) |
| 2067 |
{ |
| 2068 |
return container_of(span, struct wctdm_span, span)->bspan; |
| 2069 |
} |
| 2070 |
|
| 2071 |
static int xhfc_startup(struct dahdi_span *span) |
| 2072 |
{ |
| 2073 |
struct b400m_span *bspan = bspan_from_dspan(span); |
| 2074 |
struct b400m *b4 = bspan->parent; |
| 2075 |
if (!b4->running) |
| 2076 |
hfc_enable_interrupts(bspan->parent); |
| 2077 |
|
| 2078 |
return 0; |
| 2079 |
} |
| 2080 |
|
| 2081 |
|
| 2082 |
static void xhfc_reset_span(struct b400m_span *bspan) |
| 2083 |
{ |
| 2084 |
int i; |
| 2085 |
struct b400m *b4 = bspan->parent; |
| 2086 |
|
| 2087 |
|
| 2088 |
for (i = 0; i < 3; i++) |
| 2089 |
hfc_reset_fifo_pair(b4, bspan->fifos[i], (i == 2) ? 1 : 0, 1); |
| 2090 |
} |
| 2091 |
|
| 2092 |
static void b400m_enable_workqueues(struct wctdm *wc) |
| 2093 |
{ |
| 2094 |
struct b400m *b4s[2]; |
| 2095 |
int i, numb4s = 0; |
| 2096 |
unsigned long flags; |
| 2097 |
|
| 2098 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2099 |
for (i = 0; i < wc->mods_per_board; i += 4) { |
| 2100 |
if (wc->mods[i].type == BRI) |
| 2101 |
b4s[numb4s++] = wc->mods[i].mod.bri; |
| 2102 |
} |
| 2103 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2104 |
|
| 2105 |
for (i = 0; i < numb4s; i++) { |
| 2106 |
if (b4s[i]) |
| 2107 |
b4s[i]->shutdown = 0; |
| 2108 |
} |
| 2109 |
|
| 2110 |
} |
| 2111 |
|
| 2112 |
static void b400m_disable_workqueues(struct wctdm *wc) |
| 2113 |
{ |
| 2114 |
struct b400m *b4s[2]; |
| 2115 |
int i, numb4s = 0; |
| 2116 |
unsigned long flags; |
| 2117 |
|
| 2118 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2119 |
for (i = 0; i < wc->mods_per_board; i += 4) { |
| 2120 |
if (wc->mods[i].type == BRI) |
| 2121 |
b4s[numb4s++] = wc->mods[i].mod.bri; |
| 2122 |
} |
| 2123 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2124 |
|
| 2125 |
for (i = 0; i < numb4s; i++) { |
| 2126 |
if (b4s[i]) { |
| 2127 |
down(&wc->syncsem); |
| 2128 |
b4s[i]->shutdown = 1; |
| 2129 |
up(&wc->syncsem); |
| 2130 |
flush_workqueue(b4s[i]->xhfc_ws); |
| 2131 |
} |
| 2132 |
} |
| 2133 |
} |
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
static int b400m_set_ntte(struct b400m_span *bspan, int te_mode, int term_on) |
| 2147 |
{ |
| 2148 |
struct b400m *b4 = bspan->parent; |
| 2149 |
unsigned char data; |
| 2150 |
unsigned char addr; |
| 2151 |
int all_modes = 0, all_terms = 0; |
| 2152 |
int i; |
| 2153 |
|
| 2154 |
bspan->wspan->span.spantype = (te_mode > 0) |
| 2155 |
? SPANTYPE_DIGITAL_BRI_TE |
| 2156 |
: SPANTYPE_DIGITAL_BRI_NT; |
| 2157 |
|
| 2158 |
bspan->te_mode = te_mode; |
| 2159 |
bspan->term_on = term_on; |
| 2160 |
|
| 2161 |
for (i = 0; i < 4; i++) { |
| 2162 |
if (!b4->spans[i].te_mode) |
| 2163 |
all_modes |= (1 << i); |
| 2164 |
if (b4->spans[i].term_on) |
| 2165 |
all_terms |= (1 << i); |
| 2166 |
} |
| 2167 |
|
| 2168 |
data = 0x10 | ((all_terms << 4) & 0xc0) | ((all_terms << 2) & 0x0c); |
| 2169 |
addr = 0x10 | all_modes; |
| 2170 |
|
| 2171 |
msleep(voicebus_current_latency(&b4->wc->vb) + 2); |
| 2172 |
wctdm_setreg(b4->wc, get_mod(b4), addr, data); |
| 2173 |
|
| 2174 |
b4->lastreg = 0xff; |
| 2175 |
msleep(voicebus_current_latency(&b4->wc->vb) + 2); |
| 2176 |
|
| 2177 |
hfc_reset_st(bspan); |
| 2178 |
|
| 2179 |
if (bri_persistentlayer1) |
| 2180 |
hfc_start_st(bspan); |
| 2181 |
|
| 2182 |
return 0; |
| 2183 |
} |
| 2184 |
|
| 2185 |
|
| 2186 |
int b400m_spanconfig(struct file *file, struct dahdi_span *span, |
| 2187 |
struct dahdi_lineconfig *lc) |
| 2188 |
{ |
| 2189 |
struct b400m_span *bspan; |
| 2190 |
struct b400m *b4; |
| 2191 |
struct wctdm *wc; |
| 2192 |
int te_mode, term; |
| 2193 |
int pos; |
| 2194 |
int res; |
| 2195 |
|
| 2196 |
bspan = bspan_from_dspan(span); |
| 2197 |
b4 = bspan->parent; |
| 2198 |
wc = b4->wc; |
| 2199 |
|
| 2200 |
if ((file->f_flags & O_NONBLOCK) && !is_initialized(wc)) |
| 2201 |
return -EAGAIN; |
| 2202 |
|
| 2203 |
res = wctdm_wait_for_ready(wc); |
| 2204 |
if (res) |
| 2205 |
return res; |
| 2206 |
|
| 2207 |
b400m_disable_workqueues(b4->wc); |
| 2208 |
|
| 2209 |
te_mode = (lc->lineconfig & DAHDI_CONFIG_NTTE) ? 0 : 1; |
| 2210 |
|
| 2211 |
term = (lc->lineconfig & DAHDI_CONFIG_TERM) ? 1 : 0; |
| 2212 |
|
| 2213 |
b4_info(b4, "xhfc: Configuring port %d span %d in %s " \ |
| 2214 |
"mode with termination resistance %s\n", bspan->port, |
| 2215 |
span->spanno, (te_mode) ? "TE" : "NT", |
| 2216 |
(term) ? "ENABLED" : "DISABLED"); |
| 2217 |
|
| 2218 |
b400m_set_ntte(bspan, te_mode, term); |
| 2219 |
if (lc->sync < 0) { |
| 2220 |
b4_info(b4, "Span %d has invalid sync priority (%d), " \ |
| 2221 |
"removing from sync source list\n", span->spanno, |
| 2222 |
lc->sync); |
| 2223 |
lc->sync = 0; |
| 2224 |
} |
| 2225 |
|
| 2226 |
if (span->offset >= 4) { |
| 2227 |
pos = span->offset; |
| 2228 |
} else { |
| 2229 |
|
| 2230 |
|
| 2231 |
pos = span->offset + b4->position; |
| 2232 |
} |
| 2233 |
|
| 2234 |
if (!te_mode && lc->sync) { |
| 2235 |
b4_info(b4, "NT Spans cannot be timing sources. " \ |
| 2236 |
"Span %d requested to be timing source of " \ |
| 2237 |
"priority %d. Changing priority to 0\n", pos, |
| 2238 |
lc->sync); |
| 2239 |
lc->sync = 0; |
| 2240 |
} |
| 2241 |
|
| 2242 |
wc->spans[pos]->timing_priority = lc->sync; |
| 2243 |
|
| 2244 |
bspan->wspan = container_of(span, struct wctdm_span, span); |
| 2245 |
xhfc_reset_span(bspan); |
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
xhfc_startup(span); |
| 2251 |
|
| 2252 |
span->flags |= DAHDI_FLAG_RUNNING; |
| 2253 |
|
| 2254 |
set_bit(WCTDM_CHECK_TIMING, &wc->checkflag); |
| 2255 |
|
| 2256 |
b400m_enable_workqueues(b4->wc); |
| 2257 |
|
| 2258 |
return 0; |
| 2259 |
} |
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
int b400m_chanconfig(struct file *file, struct dahdi_chan *chan, int sigtype) |
| 2271 |
{ |
| 2272 |
int alreadyrunning; |
| 2273 |
struct b400m_span *bspan = bspan_from_dspan(chan->span); |
| 2274 |
struct b400m *b4 = bspan->parent; |
| 2275 |
int res; |
| 2276 |
|
| 2277 |
if ((file->f_flags & O_NONBLOCK) && !is_initialized(b4->wc)) |
| 2278 |
return -EAGAIN; |
| 2279 |
|
| 2280 |
res = wctdm_wait_for_ready(b4->wc); |
| 2281 |
if (res) |
| 2282 |
return res; |
| 2283 |
|
| 2284 |
alreadyrunning = bspan->wspan->span.flags & DAHDI_FLAG_RUNNING; |
| 2285 |
|
| 2286 |
if (DBG_FOPS) { |
| 2287 |
b4_info(b4, "%s channel %d (%s) sigtype %08x\n", |
| 2288 |
alreadyrunning ? "Reconfigured" : "Configured", |
| 2289 |
chan->channo, chan->name, sigtype); |
| 2290 |
} |
| 2291 |
|
| 2292 |
switch (sigtype) { |
| 2293 |
case DAHDI_SIG_HARDHDLC: |
| 2294 |
if (DBG_FOPS) { |
| 2295 |
b4_info(b4, "%sonfiguring hardware HDLC on %s\n", |
| 2296 |
((sigtype == DAHDI_SIG_HARDHDLC) ? "C" : |
| 2297 |
"Unc"), chan->name); |
| 2298 |
} |
| 2299 |
bspan->sigchan = chan; |
| 2300 |
bspan->sigactive = 0; |
| 2301 |
atomic_set(&bspan->hdlc_pending, 0); |
| 2302 |
res = 0; |
| 2303 |
break; |
| 2304 |
case DAHDI_SIG_HDLCFCS: |
| 2305 |
case DAHDI_SIG_HDLCNET: |
| 2306 |
case DAHDI_SIG_HDLCRAW: |
| 2307 |
|
| 2308 |
|
| 2309 |
res = -EINVAL; |
| 2310 |
break; |
| 2311 |
default: |
| 2312 |
res = 0; |
| 2313 |
break; |
| 2314 |
}; |
| 2315 |
|
| 2316 |
return res; |
| 2317 |
} |
| 2318 |
|
| 2319 |
int b400m_dchan(struct dahdi_span *span) |
| 2320 |
{ |
| 2321 |
struct b400m_span *bspan; |
| 2322 |
struct b400m *b4; |
| 2323 |
unsigned char *rxb; |
| 2324 |
int res; |
| 2325 |
int i; |
| 2326 |
|
| 2327 |
bspan = bspan_from_dspan(span); |
| 2328 |
b4 = bspan->parent; |
| 2329 |
#ifdef HARDHDLC_RX |
| 2330 |
return 0; |
| 2331 |
#else |
| 2332 |
#endif |
| 2333 |
|
| 2334 |
if (!bspan->sigchan) |
| 2335 |
return 0; |
| 2336 |
|
| 2337 |
rxb = bspan->sigchan->readchunk; |
| 2338 |
|
| 2339 |
if (!rxb) { |
| 2340 |
b4_info(b4, "No RXB!\n"); |
| 2341 |
return 0; |
| 2342 |
} |
| 2343 |
|
| 2344 |
for (i = 0; i < DAHDI_CHUNKSIZE; i++) { |
| 2345 |
fasthdlc_rx_load_nocheck(&bspan->rxhdlc, *(rxb++)); |
| 2346 |
res = fasthdlc_rx_run(&bspan->rxhdlc); |
| 2347 |
|
| 2348 |
if (res & RETURN_EMPTY_FLAG) |
| 2349 |
continue; |
| 2350 |
else if (res & RETURN_COMPLETE_FLAG) { |
| 2351 |
|
| 2352 |
if (!bspan->f_sz) |
| 2353 |
continue; |
| 2354 |
|
| 2355 |
|
| 2356 |
if (bspan->infcs != PPP_GOODFCS) { |
| 2357 |
dahdi_hdlc_abort(bspan->sigchan, |
| 2358 |
DAHDI_EVENT_BADFCS); |
| 2359 |
} else { |
| 2360 |
dahdi_hdlc_finish(bspan->sigchan); |
| 2361 |
} |
| 2362 |
bspan->infcs = PPP_INITFCS; |
| 2363 |
bspan->f_sz = 0; |
| 2364 |
continue; |
| 2365 |
} else if (res & RETURN_DISCARD_FLAG) { |
| 2366 |
|
| 2367 |
if (!bspan->f_sz) |
| 2368 |
continue; |
| 2369 |
|
| 2370 |
dahdi_hdlc_abort(bspan->sigchan, DAHDI_EVENT_ABORT); |
| 2371 |
bspan->infcs = PPP_INITFCS; |
| 2372 |
bspan->f_sz = 0; |
| 2373 |
break; |
| 2374 |
} else { |
| 2375 |
unsigned char rxc = res; |
| 2376 |
bspan->infcs = PPP_FCS(bspan->infcs, rxc); |
| 2377 |
bspan->f_sz++; |
| 2378 |
dahdi_hdlc_putbuf(bspan->sigchan, &rxc, 1); |
| 2379 |
} |
| 2380 |
} |
| 2381 |
|
| 2382 |
return 0; |
| 2383 |
} |
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
static void xhfc_work(struct work_struct *work) |
| 2390 |
{ |
| 2391 |
struct b400m *b4 = container_of(work, struct b400m, xhfc_wq); |
| 2392 |
int i, j, k, fifo; |
| 2393 |
unsigned char b, b2; |
| 2394 |
|
| 2395 |
if (b4->shutdown || !is_initialized(b4->wc)) |
| 2396 |
return; |
| 2397 |
|
| 2398 |
b4->irq_oview = b400m_getreg(b4, R_IRQ_OVIEW); |
| 2399 |
b4->fifo_fill = b400m_getreg(b4, R_FILL_BL0); |
| 2400 |
|
| 2401 |
if (b4->irq_oview & V_FIFO_BL0_IRQ) { |
| 2402 |
b4->fifo_irqstatus |= b400m_getreg(b4, R_FIFO_BL0_IRQ); |
| 2403 |
b4->irq_oview &= ~V_FIFO_BL0_IRQ; |
| 2404 |
} |
| 2405 |
|
| 2406 |
|
| 2407 |
b = b2 = b4->fifo_irqstatus; |
| 2408 |
|
| 2409 |
for (j = 0; j < 4; j++) { |
| 2410 |
#ifdef SWAP_PORTS |
| 2411 |
fifo = (1 == j) ? 2 : (2 == j) ? 1 : j; |
| 2412 |
#else |
| 2413 |
fifo = j; |
| 2414 |
#endif |
| 2415 |
|
| 2416 |
#ifdef HARDHDLC_RX |
| 2417 |
if (b & V_FIFOx_RX_IRQ) { |
| 2418 |
if (fifo < 4) { |
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
do { |
| 2430 |
k = hdlc_rx_frame(&b4->spans[fifo]); |
| 2431 |
} while (k); |
| 2432 |
} |
| 2433 |
} |
| 2434 |
|
| 2435 |
#endif |
| 2436 |
b >>= 2; |
| 2437 |
} |
| 2438 |
|
| 2439 |
|
| 2440 |
b4->fifo_irqstatus &= ~b2; |
| 2441 |
b4->fifo_fill &= ~b2; |
| 2442 |
|
| 2443 |
|
| 2444 |
#if 1 |
| 2445 |
|
| 2446 |
b = b2 = b4->fifo_fill; |
| 2447 |
|
| 2448 |
for (j = 0; j < 4; j++) { |
| 2449 |
#ifdef SWAP_PORTS |
| 2450 |
fifo = (1 == j) ? 2 : (2 == j) ? 1 : j; |
| 2451 |
#else |
| 2452 |
fifo = j; |
| 2453 |
#endif |
| 2454 |
if (b4->spans[fifo].sigactive && (b & V_FIFOx_TX_IRQ)) |
| 2455 |
hdlc_tx_frame(&b4->spans[fifo]); |
| 2456 |
|
| 2457 |
#ifdef HARDHDLC_RX |
| 2458 |
if (b & V_FIFOx_RX_IRQ) |
| 2459 |
hdlc_rx_frame(&b4->spans[fifo]); |
| 2460 |
#endif |
| 2461 |
|
| 2462 |
b >>= 2; |
| 2463 |
} |
| 2464 |
#endif |
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
for (i = 0; i < ARRAY_SIZE(b4->spans); i++) { |
| 2475 |
struct b400m_span *bspan = &b4->spans[i]; |
| 2476 |
|
| 2477 |
if (atomic_read(&bspan->hdlc_pending)) { |
| 2478 |
do { |
| 2479 |
k = hdlc_tx_frame(bspan); |
| 2480 |
} while (k); |
| 2481 |
} |
| 2482 |
} |
| 2483 |
|
| 2484 |
b = b400m_getreg(b4, R_SU_IRQ); |
| 2485 |
|
| 2486 |
if (b) { |
| 2487 |
for (i = 0; i < ARRAY_SIZE(b4->spans); i++) { |
| 2488 |
int physport; |
| 2489 |
|
| 2490 |
#ifdef SWAP_PORTS |
| 2491 |
if (i == 1) |
| 2492 |
physport = 2; |
| 2493 |
else if (i == 2) |
| 2494 |
physport = 1; |
| 2495 |
else |
| 2496 |
physport = i; |
| 2497 |
#else |
| 2498 |
physport = i; |
| 2499 |
#endif |
| 2500 |
if (b & (1 << i)) |
| 2501 |
hfc_handle_state(&b4->spans[physport]); |
| 2502 |
} |
| 2503 |
} |
| 2504 |
|
| 2505 |
hfc_update_st_timers(b4); |
| 2506 |
} |
| 2507 |
|
| 2508 |
void wctdm_bri_checkisr(struct wctdm *wc, struct wctdm_module *const mod, |
| 2509 |
int offset) |
| 2510 |
{ |
| 2511 |
struct b400m *b4 = mod->mod.bri; |
| 2512 |
|
| 2513 |
|
| 2514 |
if (mod->card & 0x03) |
| 2515 |
return; |
| 2516 |
|
| 2517 |
|
| 2518 |
if (!is_initialized(wc) || !b4 || !b4->inited) |
| 2519 |
return; |
| 2520 |
|
| 2521 |
if (offset == 0) { |
| 2522 |
if (!b4->shutdown) |
| 2523 |
queue_work(b4->xhfc_ws, &b4->xhfc_wq); |
| 2524 |
b4->ticks++; |
| 2525 |
} |
| 2526 |
return; |
| 2527 |
} |
| 2528 |
|
| 2529 |
|
| 2530 |
void wctdm_hdlc_hard_xmit(struct dahdi_chan *chan) |
| 2531 |
{ |
| 2532 |
struct b400m *b4; |
| 2533 |
struct b400m_span *bspan; |
| 2534 |
struct dahdi_span *dspan; |
| 2535 |
int span; |
| 2536 |
|
| 2537 |
dspan = chan->span; |
| 2538 |
bspan = bspan_from_dspan(dspan); |
| 2539 |
b4 = bspan->parent; |
| 2540 |
span = bspan->port; |
| 2541 |
|
| 2542 |
if ((DBG_FOPS || DBG_HDLC) && DBG_SPANFILTER) { |
| 2543 |
b4_info(b4, "hdlc_hard_xmit on chan %s (%i/%i), " \ |
| 2544 |
"span=%i (sigchan=%p, chan=%p)\n", chan->name, |
| 2545 |
chan->channo, chan->chanpos, span + 1, |
| 2546 |
bspan->sigchan, chan); |
| 2547 |
} |
| 2548 |
|
| 2549 |
|
| 2550 |
|
| 2551 |
if (bspan->sigchan == chan) |
| 2552 |
atomic_inc(&bspan->hdlc_pending); |
| 2553 |
} |
| 2554 |
|
| 2555 |
static int b400m_probe(struct wctdm *wc, int modpos) |
| 2556 |
{ |
| 2557 |
unsigned char id, x; |
| 2558 |
struct b400m *b4; |
| 2559 |
unsigned long flags; |
| 2560 |
int chiprev; |
| 2561 |
|
| 2562 |
wctdm_setreg(wc, &wc->mods[modpos], 0x10, 0x10); |
| 2563 |
id = xhfc_getreg(wc, &wc->mods[modpos], R_CHIP_ID, &x); |
| 2564 |
|
| 2565 |
|
| 2566 |
if ((id & 0xfe) != 0x62) |
| 2567 |
return -2; |
| 2568 |
|
| 2569 |
b4 = kzalloc(sizeof(struct b400m), GFP_KERNEL); |
| 2570 |
if (!b4) { |
| 2571 |
dev_err(&wc->vb.pdev->dev, |
| 2572 |
"Couldn't allocate memory for b400m structure!\n"); |
| 2573 |
return -ENOMEM; |
| 2574 |
} |
| 2575 |
|
| 2576 |
|
| 2577 |
b4->wc = wc; |
| 2578 |
b4->position = modpos; |
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
for (x = 0; x < modpos; x += 4) { |
| 2583 |
if (wc->mods[x].type == BRI) |
| 2584 |
++b4->b400m_no; |
| 2585 |
} |
| 2586 |
|
| 2587 |
spin_lock_init(&b4->reglock); |
| 2588 |
sema_init(&b4->regsem, 1); |
| 2589 |
sema_init(&b4->fifosem, 1); |
| 2590 |
|
| 2591 |
for (x = 0; x < 4; x++) { |
| 2592 |
fasthdlc_init(&b4->spans[x].rxhdlc, FASTHDLC_MODE_16); |
| 2593 |
b4->spans[x].infcs = PPP_INITFCS; |
| 2594 |
} |
| 2595 |
|
| 2596 |
b4->lastreg = 0xff; |
| 2597 |
|
| 2598 |
chiprev = b400m_getreg(b4, R_CHIP_RV); |
| 2599 |
|
| 2600 |
b4->setsyncspan = -1; |
| 2601 |
b4->reportedsyncspan = -1; |
| 2602 |
|
| 2603 |
if (DBG) { |
| 2604 |
b4_info(b4, "Identified controller rev %d in module %d.\n", |
| 2605 |
chiprev, b4->position); |
| 2606 |
} |
| 2607 |
|
| 2608 |
xhfc_init_stage1(b4); |
| 2609 |
|
| 2610 |
xhfc_init_stage2(b4); |
| 2611 |
hfc_init_all_st(b4); |
| 2612 |
|
| 2613 |
hfc_enable_interrupts(b4); |
| 2614 |
|
| 2615 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2616 |
wc->mods[modpos].mod.bri = (void *)b4; |
| 2617 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2618 |
|
| 2619 |
return 0; |
| 2620 |
} |
| 2621 |
|
| 2622 |
void b400m_post_init(struct b400m *b4) |
| 2623 |
{ |
| 2624 |
snprintf(b4->name, sizeof(b4->name) - 1, "b400m-%d", |
| 2625 |
b4->b400m_no); |
| 2626 |
b4->xhfc_ws = create_singlethread_workqueue(b4->name); |
| 2627 |
INIT_WORK(&b4->xhfc_wq, xhfc_work); |
| 2628 |
b4->inited = 1; |
| 2629 |
} |
| 2630 |
|
| 2631 |
|
| 2632 |
int wctdm_init_b400m(struct wctdm *wc, int card) |
| 2633 |
{ |
| 2634 |
int ret = 0; |
| 2635 |
unsigned long flags; |
| 2636 |
|
| 2637 |
if (wc->mods[card & 0xfc].type == QRV) |
| 2638 |
return -2; |
| 2639 |
|
| 2640 |
if (!(card & 0x03)) { |
| 2641 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2642 |
wc->mods[card + 0].type = BRI; |
| 2643 |
wc->mods[card + 0].mod.bri = NULL; |
| 2644 |
wc->mods[card + 1].type = BRI; |
| 2645 |
wc->mods[card + 1].mod.bri = NULL; |
| 2646 |
wc->mods[card + 2].type = BRI; |
| 2647 |
wc->mods[card + 2].mod.bri = NULL; |
| 2648 |
wc->mods[card + 3].type = BRI; |
| 2649 |
wc->mods[card + 3].mod.bri = NULL; |
| 2650 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2651 |
|
| 2652 |
msleep(20); |
| 2653 |
|
| 2654 |
if (b400m_probe(wc, card) != 0) { |
| 2655 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2656 |
wc->mods[card + 0].type = NONE; |
| 2657 |
wc->mods[card + 1].type = NONE; |
| 2658 |
wc->mods[card + 2].type = NONE; |
| 2659 |
wc->mods[card + 3].type = NONE; |
| 2660 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2661 |
ret = -2; |
| 2662 |
} |
| 2663 |
} else { |
| 2664 |
if (wc->mods[card & 0xfc].type == BRI) { |
| 2665 |
spin_lock_irqsave(&wc->reglock, flags); |
| 2666 |
wc->mods[card].type = BRI; |
| 2667 |
wc->mods[card].mod.bri = wc->mods[card & 0xfc].mod.bri; |
| 2668 |
spin_unlock_irqrestore(&wc->reglock, flags); |
| 2669 |
} else { |
| 2670 |
ret = -2; |
| 2671 |
} |
| 2672 |
} |
| 2673 |
|
| 2674 |
return ret; |
| 2675 |
} |
| 2676 |
|
| 2677 |
void wctdm_unload_b400m(struct wctdm *wc, int card) |
| 2678 |
{ |
| 2679 |
struct b400m *b4 = wc->mods[card].mod.bri; |
| 2680 |
int i; |
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
static int shutdown_once; |
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
if (card & 0x03) |
| 2691 |
return; |
| 2692 |
|
| 2693 |
if (timingcable && !shutdown_once) { |
| 2694 |
b4_info(b4, "Disabling all workqueues for B400Ms\n"); |
| 2695 |
|
| 2696 |
for (i = 0; i < WC_MAX_IFACES; i++) { |
| 2697 |
if (ifaces[i]) |
| 2698 |
b400m_disable_workqueues(ifaces[i]); |
| 2699 |
} |
| 2700 |
b4_info(b4, "Forcing sync to card 0\n"); |
| 2701 |
|
| 2702 |
|
| 2703 |
wctdm_change_system_sync_src(synccard, syncspan, -1, -1); |
| 2704 |
|
| 2705 |
|
| 2706 |
b4_info(b4, "Setting all cards to return to self sync\n"); |
| 2707 |
for (i = 1; i < WC_MAX_IFACES; i++) { |
| 2708 |
if (ifaces[i]) |
| 2709 |
wctdm_change_card_sync_src(ifaces[i], 0, 0); |
| 2710 |
} |
| 2711 |
|
| 2712 |
b4_info(b4, |
| 2713 |
"Finished preparing timing linked cards for " |
| 2714 |
"shutdown\n"); |
| 2715 |
|
| 2716 |
shutdown_once = 1; |
| 2717 |
} |
| 2718 |
|
| 2719 |
if (b4) { |
| 2720 |
b4->inited = 0; |
| 2721 |
|
| 2722 |
msleep(100); |
| 2723 |
|
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
b400m_disable_workqueues(wc); |
| 2730 |
|
| 2731 |
for (i = 0; i < (MAX_SPANS - 1); i++) { |
| 2732 |
if (wc->spans[i]) |
| 2733 |
wc->spans[i]->timing_priority = 0; |
| 2734 |
} |
| 2735 |
|
| 2736 |
for (i = 0; i < ARRAY_SIZE(b4->spans); i++) |
| 2737 |
b4->spans[i].wspan->span.flags &= ~DAHDI_FLAG_RUNNING; |
| 2738 |
|
| 2739 |
wctdm_change_card_sync_src(b4->wc, 0, 0); |
| 2740 |
|
| 2741 |
xhfc_init_stage1(b4); |
| 2742 |
|
| 2743 |
destroy_workqueue(b4->xhfc_ws); |
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
wc->mods[card].type = NONE; |
| 2748 |
wc->mods[card + 1].type = NONE; |
| 2749 |
wc->mods[card + 2].type = NONE; |
| 2750 |
wc->mods[card + 3].type = NONE; |
| 2751 |
|
| 2752 |
wc->mods[card].mod.bri = NULL; |
| 2753 |
wc->mods[card + 1].mod.bri = NULL; |
| 2754 |
wc->mods[card + 2].mod.bri = NULL; |
| 2755 |
wc->mods[card + 3].mod.bri = NULL; |
| 2756 |
|
| 2757 |
msleep(voicebus_current_latency(&wc->vb) << 1); |
| 2758 |
b4_info(b4, "Driver unloaded.\n"); |
| 2759 |
kfree(b4); |
| 2760 |
} |
| 2761 |
|
| 2762 |
} |
| 2763 |
|
| 2764 |
void b400m_module_init(void) |
| 2765 |
{ |
| 2766 |
fasthdlc_precalc(); |
| 2767 |
} |
| 2768 |
|
| 2769 |
void b400m_module_cleanup(void) |
| 2770 |
{ |
| 2771 |
} |