Debian Codegraph @

drivers/dahdi/wct4xxp/wct4xxp-diag.c

raw symbols SCIP
1 /*
2 * See http://www.asterisk.org for more information about
3 * the Asterisk project. Please do not directly contact
4 * any of the maintainers of this project for assistance;
5 * the project provides a web site, mailing lists and IRC
6 * channels for your use.
7 *
8 * This program is free software, distributed under the terms of
9 * the GNU General Public License Version 2 as published by the
10 * Free Software Foundation. See the LICENSE file included with
11 * this program for more details.
12 */
13
14 #include <fcntl.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <sys/ioctl.h>
19 #include <errno.h>
20 #include <string.h>
21 #include <dahdi/user.h>
22 #include "wct4xxp.h"
23
24 struct t4_reg_def {
25 int reg;
26 char *name;
27 int global;
28 };
29 static struct t4_reg_def xreginfo[] = {
30 { 0x00, "RDADDR" },
31 { 0x01, "WRADDR" },
32 { 0x02, "COUNT" },
33 { 0x03, "DMACTRL" },
34 { 0x04, "WCINTR" },
35 { 0x06, "VERSION" },
36 { 0x07, "LEDS" },
37 { 0x08, "GPIOCTL" },
38 { 0x09, "GPIO" },
39 { 0x0A, "LADDR" },
40 { 0x0b, "LDATA" },
41 };
42
43 static struct t4_reg_def reginfo[] = {
44 { 0x00, "XFIFO" },
45 { 0x01, "XFIFO" },
46 { 0x02, "CMDR" },
47 { 0x03, "MODE" },
48 { 0x04, "RAH1" },
49 { 0x05, "RAH2" },
50 { 0x06, "RAL1" },
51 { 0x07, "RAL2" },
52 { 0x08, "IPC", 1 },
53 { 0x09, "CCR1" },
54 { 0x0a, "CCR2" },
55 { 0x0c, "RTR1" },
56 { 0x0d, "RTR2" },
57 { 0x0e, "RTR3" },
58 { 0x0f, "RTR4" },
59 { 0x10, "TTR1" },
60 { 0x11, "TTR2" },
61 { 0x12, "TTR3" },
62 { 0x13, "TTR4" },
63 { 0x14, "IMR0" },
64 { 0x15, "IMR1" },
65 { 0x16, "IMR2" },
66 { 0x17, "IMR3" },
67 { 0x18, "IMR4" },
68 { 0x1b, "IERR" },
69 { 0x1c, "FMR0" },
70 { 0x1d, "FMR1" },
71 { 0x1e, "FMR2" },
72 { 0x1f, "LOOP" },
73 { 0x20, "XSW" },
74 { 0x21, "XSP" },
75 { 0x22, "XC0" },
76 { 0x23, "XC1" },
77 { 0x24, "RC0" },
78 { 0x25, "RC1" },
79 { 0x26, "XPM0" },
80 { 0x27, "XPM1" },
81 { 0x28, "XPM2" },
82 { 0x29, "TSWM" },
83 { 0x2b, "IDLE" },
84 { 0x2c, "XSA4" },
85 { 0x2d, "XSA5" },
86 { 0x2e, "XSA6" },
87 { 0x2f, "XSA7" },
88 { 0x30, "XSA8" },
89 { 0x31, "FMR3" },
90 { 0x32, "ICB1" },
91 { 0x33, "ICB2" },
92 { 0x34, "ICB3" },
93 { 0x35, "ICB4" },
94 { 0x36, "LIM0" },
95 { 0x37, "LIM1" },
96 { 0x38, "PCD" },
97 { 0x39, "PCR" },
98 { 0x3a, "LIM2" },
99 { 0x3b, "LCR1" },
100 { 0x3c, "LCR2" },
101 { 0x3d, "LCR3" },
102 { 0x3e, "SIC1" },
103 { 0x3f, "SIC2" },
104 { 0x40, "SIC3" },
105 { 0x44, "CMR1" },
106 { 0x45, "CMR2" },
107 { 0x46, "GCR" },
108 { 0x47, "ESM" },
109 { 0x60, "DEC" },
110 { 0x70, "XS1" },
111 { 0x71, "XS2" },
112 { 0x72, "XS3" },
113 { 0x73, "XS4" },
114 { 0x74, "XS5" },
115 { 0x75, "XS6" },
116 { 0x76, "XS7" },
117 { 0x77, "XS8" },
118 { 0x78, "XS9" },
119 { 0x79, "XS10" },
120 { 0x7a, "XS11" },
121 { 0x7b, "XS12" },
122 { 0x7c, "XS13" },
123 { 0x7d, "XS14" },
124 { 0x7e, "XS15" },
125 { 0x7f, "XS16" },
126 { 0x80, "PC1" },
127 { 0x81, "PC2" },
128 { 0x82, "PC3" },
129 { 0x83, "PC4" },
130 { 0x84, "PC5" },
131 { 0x85, "GPC1", 1 },
132 { 0x87, "CMDR2" },
133 { 0x8d, "CCR5" },
134 { 0x92, "GCM1", 1 },
135 { 0x93, "GCM2", 1 },
136 { 0x94, "GCM3", 1 },
137 { 0x95, "GCM4", 1 },
138 { 0x96, "GCM5", 1 },
139 { 0x97, "GCM6", 1 },
140 { 0x98, "GCM7", 1 },
141 { 0x99, "GCM8", 1 },
142 { 0xa0, "TSEO" },
143 { 0xa1, "TSBS1" },
144 { 0xa8, "TPC0" },
145 };
146
147 static struct t4_reg_def t1_reginfo[] = {
148 { 0x00, "XFIFO" },
149 { 0x01, "XFIFO" },
150 { 0x02, "CMDR" },
151 { 0x03, "MODE" },
152 { 0x04, "RAH1" },
153 { 0x05, "RAH2" },
154 { 0x06, "RAL1" },
155 { 0x07, "RAL2" },
156 { 0x08, "IPC", 1 },
157 { 0x09, "CCR1" },
158 { 0x0a, "CCR2" },
159 { 0x0c, "RTR1" },
160 { 0x0d, "RTR2" },
161 { 0x0e, "RTR3" },
162 { 0x0f, "RTR4" },
163 { 0x10, "TTR1" },
164 { 0x11, "TTR2" },
165 { 0x12, "TTR3" },
166 { 0x13, "TTR4" },
167 { 0x14, "IMR0" },
168 { 0x15, "IMR1" },
169 { 0x16, "IMR2" },
170 { 0x17, "IMR3" },
171 { 0x18, "IMR4" },
172 { 0x1b, "IERR" },
173 { 0x1c, "FMR0" },
174 { 0x1d, "FMR1" },
175 { 0x1e, "FMR2" },
176 { 0x1f, "LOOP" },
177 { 0x20, "FMR4" },
178 { 0x21, "FMR5" },
179 { 0x22, "XC0" },
180 { 0x23, "XC1" },
181 { 0x24, "RC0" },
182 { 0x25, "RC1" },
183 { 0x26, "XPM0" },
184 { 0x27, "XPM1" },
185 { 0x28, "XPM2" },
186 { 0x2b, "IDLE" },
187 { 0x2c, "XDL1" },
188 { 0x2d, "XDL2" },
189 { 0x2e, "XDL3" },
190 { 0x2f, "CCB1" },
191 { 0x30, "CCB2" },
192 { 0x31, "CCB3" },
193 { 0x32, "ICB1" },
194 { 0x33, "ICB2" },
195 { 0x34, "ICB3" },
196 { 0x36, "LIM0" },
197 { 0x37, "LIM1" },
198 { 0x38, "PCD" },
199 { 0x39, "PCR" },
200 { 0x3a, "LIM2" },
201 { 0x3b, "LCR1" },
202 { 0x3c, "LCR2" },
203 { 0x3d, "LCR3" },
204 { 0x3e, "SIC1" },
205 { 0x3f, "SIC2" },
206 { 0x40, "SIC3" },
207 { 0x44, "CMR1" },
208 { 0x45, "CMR2" },
209 { 0x46, "GCR" },
210 { 0x47, "ESM" },
211 { 0x60, "DEC" },
212 { 0x70, "XS1" },
213 { 0x71, "XS2" },
214 { 0x72, "XS3" },
215 { 0x73, "XS4" },
216 { 0x74, "XS5" },
217 { 0x75, "XS6" },
218 { 0x76, "XS7" },
219 { 0x77, "XS8" },
220 { 0x78, "XS9" },
221 { 0x79, "XS10" },
222 { 0x7a, "XS11" },
223 { 0x7b, "XS12" },
224 { 0x80, "PC1" },
225 { 0x81, "PC2" },
226 { 0x82, "PC3" },
227 { 0x83, "PC4" },
228 { 0x84, "PC5" },
229 { 0x85, "GPC1", 1 },
230 { 0x87, "CMDR2" },
231 { 0x8d, "CCR5" },
232 { 0x92, "GCM1", 1 },
233 { 0x93, "GCM2", 1 },
234 { 0x94, "GCM3", 1 },
235 { 0x95, "GCM4", 1 },
236 { 0x96, "GCM5", 1 },
237 { 0x97, "GCM6", 1 },
238 { 0x98, "GCM7", 1 },
239 { 0x99, "GCM8", 1 },
240 { 0xa0, "TSEO" },
241 { 0xa1, "TSBS1" },
242 { 0xa8, "TPC0" },
243 };
244
245 static struct t4_reg_def t1_sreginfo[] = {
246 { 0x00, "RFIFO" },
247 { 0x01, "RFIFO" },
248 { 0x49, "RBD" },
249 { 0x4a, "VSTR", 1 },
250 { 0x4b, "RES" },
251 { 0x4c, "FRS0" },
252 { 0x4d, "FRS1" },
253 { 0x4e, "FRS2" },
254 { 0x4f, "Old FRS1" },
255 { 0x50, "FECL" },
256 { 0x51, "FECH" },
257 { 0x52, "CVCL" },
258 { 0x53, "CVCH" },
259 { 0x54, "CECL" },
260 { 0x55, "CECH" },
261 { 0x56, "EBCL" },
262 { 0x57, "EBCH" },
263 { 0x58, "BECL" },
264 { 0x59, "BECH" },
265 { 0x5a, "COEC" },
266 { 0x5c, "RDL1" },
267 { 0x5d, "RDL2" },
268 { 0x5e, "RDL3" },
269 { 0x62, "RSP1" },
270 { 0x63, "RSP2" },
271 { 0x64, "SIS" },
272 { 0x65, "RSIS" },
273 { 0x66, "RBCL" },
274 { 0x67, "RBCH" },
275 { 0x68, "ISR0" },
276 { 0x69, "ISR1" },
277 { 0x6a, "ISR2" },
278 { 0x6b, "ISR3" },
279 { 0x6c, "ISR4" },
280 { 0x6e, "GIS" },
281 { 0x6f, "CIS", 1 },
282 { 0x70, "RS1" },
283 { 0x71, "RS2" },
284 { 0x72, "RS3" },
285 { 0x73, "RS4" },
286 { 0x74, "RS5" },
287 { 0x75, "RS6" },
288 { 0x76, "RS7" },
289 { 0x77, "RS8" },
290 { 0x78, "RS9" },
291 { 0x79, "RS10" },
292 { 0x7a, "RS11" },
293 { 0x7b, "RS12" },
294 };
295
296 static struct t4_reg_def sreginfo[] = {
297 { 0x00, "RFIFO" },
298 { 0x01, "RFIFO" },
299 { 0x49, "RBD" },
300 { 0x4a, "VSTR", 1 },
301 { 0x4b, "RES" },
302 { 0x4c, "FRS0" },
303 { 0x4d, "FRS1" },
304 { 0x4e, "RSW" },
305 { 0x4f, "RSP" },
306 { 0x50, "FECL" },
307 { 0x51, "FECH" },
308 { 0x52, "CVCL" },
309 { 0x53, "CVCH" },
310 { 0x54, "CEC1L" },
311 { 0x55, "CEC1H" },
312 { 0x56, "EBCL" },
313 { 0x57, "EBCH" },
314 { 0x58, "CEC2L" },
315 { 0x59, "CEC2H" },
316 { 0x5a, "CEC3L" },
317 { 0x5b, "CEC3H" },
318 { 0x5c, "RSA4" },
319 { 0x5d, "RSA5" },
320 { 0x5e, "RSA6" },
321 { 0x5f, "RSA7" },
322 { 0x60, "RSA8" },
323 { 0x61, "RSA6S" },
324 { 0x62, "RSP1" },
325 { 0x63, "RSP2" },
326 { 0x64, "SIS" },
327 { 0x65, "RSIS" },
328 { 0x66, "RBCL" },
329 { 0x67, "RBCH" },
330 { 0x68, "ISR0" },
331 { 0x69, "ISR1" },
332 { 0x6a, "ISR2" },
333 { 0x6b, "ISR3" },
334 { 0x6c, "ISR4" },
335 { 0x6e, "GIS" },
336 { 0x6f, "CIS", 1 },
337 { 0x70, "RS1" },
338 { 0x71, "RS2" },
339 { 0x72, "RS3" },
340 { 0x73, "RS4" },
341 { 0x74, "RS5" },
342 { 0x75, "RS6" },
343 { 0x76, "RS7" },
344 { 0x77, "RS8" },
345 { 0x78, "RS9" },
346 { 0x79, "RS10" },
347 { 0x7a, "RS11" },
348 { 0x7b, "RS12" },
349 { 0x7c, "RS13" },
350 { 0x7d, "RS14" },
351 { 0x7e, "RS15" },
352 { 0x7f, "RS16" },
353 };
354
355 static char *tobin(int x)
356 {
357 static char s[9] = "";
358 int y,z=0;
359 for (y=7;y>=0;y--) {
360 if (x & (1 << y))
361 s[z++] = '1';
362 else
363 s[z++] = '0';
364 }
365 s[z] = '\0';
366 return s;
367 }
368
369 static char *tobin32(unsigned int x)
370 {
371 static char s[33] = "";
372 int y,z=0;
373 for (y=31;y>=0;y--) {
374 if (x & (1 << y))
375 s[z++] = '1';
376 else
377 s[z++] = '0';
378 }
379 s[z] = '\0';
380 return s;
381 }
382
383 int main(int argc, char *argv[])
384 {
385 int fd;
386 int x;
387 char fn[256];
388 struct t4_regs regs;
389 if ((argc < 2) || ((*(argv[1]) != '/') && !atoi(argv[1]))) {
390 fprintf(stderr, "Usage: wct4xxp-diag <channel>\n");
391 exit(1);
392 }
393 if (*(argv[1]) == '/')
394 dahdi_copy_string(fn, argv[1], sizeof(fn));
395 else
396 snprintf(fn, sizeof(fn), "/dev/dahdi/%d", atoi(argv[1]));
397 fd = open(fn, O_RDWR);
398 if (fd <0) {
399 fprintf(stderr, "Unable to open '%s': %s\n", fn, strerror(errno));
400 exit(1);
401 }
402 if (ioctl(fd, WCT4_GET_REGS, &regs)) {
403 fprintf(stderr, "Unable to get registers: %s\n", strerror(errno));
404 exit(1);
405 }
406 printf("PCI Registers:\n");
407 for (x=0;x<sizeof(xreginfo) / sizeof(xreginfo[0]);x++) {
408 fprintf(stdout, "%s (%02x): %08x (%s)\n", xreginfo[x].name, xreginfo[x].reg, regs.pci[xreginfo[x].reg], tobin32(regs.pci[xreginfo[x].reg]));
409 }
410 printf("\nE1 Control Registers:\n");
411 for (x=0;x<sizeof(reginfo) / sizeof(reginfo[0]);x++) {
412 fprintf(stdout, "%s (%02x): %02x (%s)\n", reginfo[x].name, reginfo[x].reg, regs.regs[reginfo[x].reg], tobin(regs.regs[reginfo[x].reg]));
413 }
414 printf("\nE1 Status Registers:\n");
415 for (x=0;x<sizeof(sreginfo) / sizeof(sreginfo[0]);x++) {
416 fprintf(stdout, "%s (%02x): %02x (%s)\n", sreginfo[x].name, sreginfo[x].reg, regs.regs[sreginfo[x].reg], tobin(regs.regs[sreginfo[x].reg]));
417 }
418 printf("\nT1 Control Registers:\n");
419 for (x=0;x<sizeof(t1_reginfo) / sizeof(t1_reginfo[0]);x++) {
420 fprintf(stdout, "%s (%02x): %02x (%s)\n", t1_reginfo[x].name, t1_reginfo[x].reg, regs.regs[t1_reginfo[x].reg], tobin(regs.regs[t1_reginfo[x].reg]));
421 }
422 printf("\nT1 Status Registers:\n");
423 for (x=0;x<sizeof(t1_sreginfo) / sizeof(t1_sreginfo[0]);x++) {
424 fprintf(stdout, "%s (%02x): %02x (%s)\n", t1_sreginfo[x].name, t1_sreginfo[x].reg, regs.regs[t1_sreginfo[x].reg], tobin(regs.regs[t1_sreginfo[x].reg]));
425 }
426 exit(0);
427 }