blob: e63983aa1d276996030158112987c3255aa2174d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 1996 SpellCaster Telecommunications Inc.
3 *
4 * This software may be used and distributed according to the terms
5 * of the GNU General Public License, incorporated herein by reference.
6 *
7 */
8
9#include "includes.h"
10#include "hardware.h"
11#include "message.h"
12#include "card.h"
13#include "scioc.h"
14
Adrian Bunke3ca5e72005-06-25 14:58:34 -070015static int GetStatus(int card, boardInfo *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17/*
18 * Process private IOCTL messages (typically from scctrl)
19 */
20int sc_ioctl(int card, scs_ioctl *data)
21{
22 int status;
23 RspMessage *rcvmsg;
24 char *spid;
25 char *dn;
26 char switchtype;
27 char speed;
28
29 rcvmsg = kmalloc(sizeof(RspMessage), GFP_KERNEL);
30 if (!rcvmsg)
31 return -ENOMEM;
32
Joe Perches475be4d2012-02-19 19:52:38 -080033 switch (data->command) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 case SCIOCRESET: /* Perform a hard reset of the adapter */
35 {
36 pr_debug("%s: SCIOCRESET: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -080037 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 sc_adapter[card]->StartOnReset = 0;
Jesper Juhld32af0f2006-03-31 02:30:57 -080039 kfree(rcvmsg);
40 return reset(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 }
42
43 case SCIOCLOAD:
44 {
45 char *srec;
46
47 srec = kmalloc(SCIOC_SRECSIZE, GFP_KERNEL);
48 if (!srec) {
49 kfree(rcvmsg);
50 return -ENOMEM;
51 }
52 pr_debug("%s: SCIOLOAD: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -080053 sc_adapter[card]->devicename);
54 if (sc_adapter[card]->EngineUp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 pr_debug("%s: SCIOCLOAD: command failed, LoadProc while engine running.\n",
Joe Perches475be4d2012-02-19 19:52:38 -080056 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 kfree(rcvmsg);
58 kfree(srec);
59 return -1;
60 }
61
62 /*
63 * Get the SRec from user space
64 */
Domen Puncerabffa7d2006-02-03 03:04:14 -080065 if (copy_from_user(srec, data->dataptr, SCIOC_SRECSIZE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 kfree(rcvmsg);
67 kfree(srec);
68 return -EFAULT;
69 }
70
71 status = send_and_receive(card, CMPID, cmReqType2, cmReqClass0, cmReqLoadProc,
Joe Perches475be4d2012-02-19 19:52:38 -080072 0, SCIOC_SRECSIZE, srec, rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 kfree(rcvmsg);
74 kfree(srec);
75
Joe Perches475be4d2012-02-19 19:52:38 -080076 if (status) {
77 pr_debug("%s: SCIOCLOAD: command failed, status = %d\n",
78 sc_adapter[card]->devicename, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 return -1;
80 }
81 else {
82 pr_debug("%s: SCIOCLOAD: command successful\n",
Joe Perches475be4d2012-02-19 19:52:38 -080083 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 return 0;
85 }
86 }
87
88 case SCIOCSTART:
89 {
Jesper Juhl94a67352006-06-23 02:05:27 -070090 kfree(rcvmsg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 pr_debug("%s: SCIOSTART: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -080092 sc_adapter[card]->devicename);
93 if (sc_adapter[card]->EngineUp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 pr_debug("%s: SCIOCSTART: command failed, engine already running.\n",
Joe Perches475be4d2012-02-19 19:52:38 -080095 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 return -1;
97 }
98
99 sc_adapter[card]->StartOnReset = 1;
100 startproc(card);
101 return 0;
102 }
103
104 case SCIOCSETSWITCH:
105 {
106 pr_debug("%s: SCIOSETSWITCH: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800107 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 /*
110 * Get the switch type from user space
111 */
112 if (copy_from_user(&switchtype, data->dataptr, sizeof(char))) {
113 kfree(rcvmsg);
114 return -EFAULT;
115 }
116
117 pr_debug("%s: SCIOCSETSWITCH: setting switch type to %d\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800118 sc_adapter[card]->devicename,
119 switchtype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 status = send_and_receive(card, CEPID, ceReqTypeCall, ceReqClass0, ceReqCallSetSwitchType,
Joe Perches475be4d2012-02-19 19:52:38 -0800121 0, sizeof(char), &switchtype, rcvmsg, SAR_TIMEOUT);
122 if (!status && !(rcvmsg->rsp_status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 pr_debug("%s: SCIOCSETSWITCH: command successful\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800124 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 kfree(rcvmsg);
126 return 0;
127 }
128 else {
129 pr_debug("%s: SCIOCSETSWITCH: command failed (status = %d)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800130 sc_adapter[card]->devicename, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 kfree(rcvmsg);
132 return status;
133 }
134 }
Joe Perches475be4d2012-02-19 19:52:38 -0800135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 case SCIOCGETSWITCH:
137 {
138 pr_debug("%s: SCIOGETSWITCH: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800139 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 /*
142 * Get the switch type from the board
143 */
Joe Perches475be4d2012-02-19 19:52:38 -0800144 status = send_and_receive(card, CEPID, ceReqTypeCall, ceReqClass0,
145 ceReqCallGetSwitchType, 0, 0, NULL, rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 if (!status && !(rcvmsg->rsp_status)) {
147 pr_debug("%s: SCIOCGETSWITCH: command successful\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800148 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 }
150 else {
151 pr_debug("%s: SCIOCGETSWITCH: command failed (status = %d)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800152 sc_adapter[card]->devicename, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 kfree(rcvmsg);
154 return status;
155 }
156
157 switchtype = rcvmsg->msg_data.byte_array[0];
158
159 /*
160 * Package the switch type and send to user space
161 */
162 if (copy_to_user(data->dataptr, &switchtype,
163 sizeof(char))) {
164 kfree(rcvmsg);
165 return -EFAULT;
166 }
167
168 kfree(rcvmsg);
169 return 0;
170 }
171
172 case SCIOCGETSPID:
173 {
174 pr_debug("%s: SCIOGETSPID: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800175 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Dan Carpenter4b030d42010-08-04 23:38:06 +0000177 spid = kzalloc(SCIOC_SPIDSIZE, GFP_KERNEL);
Jesper Juhld32af0f2006-03-31 02:30:57 -0800178 if (!spid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 kfree(rcvmsg);
180 return -ENOMEM;
181 }
182 /*
183 * Get the spid from the board
184 */
185 status = send_and_receive(card, CEPID, ceReqTypeCall, ceReqClass0, ceReqCallGetSPID,
Joe Perches475be4d2012-02-19 19:52:38 -0800186 data->channel, 0, NULL, rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 if (!status) {
188 pr_debug("%s: SCIOCGETSPID: command successful\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800189 sc_adapter[card]->devicename);
Jesper Juhld32af0f2006-03-31 02:30:57 -0800190 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 pr_debug("%s: SCIOCGETSPID: command failed (status = %d)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800192 sc_adapter[card]->devicename, status);
Jesper Juhld32af0f2006-03-31 02:30:57 -0800193 kfree(spid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 kfree(rcvmsg);
195 return status;
196 }
Dan Carpenter4b030d42010-08-04 23:38:06 +0000197 strlcpy(spid, rcvmsg->msg_data.byte_array, SCIOC_SPIDSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 /*
200 * Package the switch type and send to user space
201 */
202 if (copy_to_user(data->dataptr, spid, SCIOC_SPIDSIZE)) {
203 kfree(spid);
204 kfree(rcvmsg);
205 return -EFAULT;
206 }
207
208 kfree(spid);
209 kfree(rcvmsg);
210 return 0;
Joe Perches475be4d2012-02-19 19:52:38 -0800211 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 case SCIOCSETSPID:
214 {
215 pr_debug("%s: DCBIOSETSPID: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800216 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 /*
219 * Get the spid from user space
220 */
Julia Lawall024cb8a2010-05-21 22:26:42 +0000221 spid = memdup_user(data->dataptr, SCIOC_SPIDSIZE);
222 if (IS_ERR(spid)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 kfree(rcvmsg);
Julia Lawall024cb8a2010-05-21 22:26:42 +0000224 return PTR_ERR(spid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
226
Joe Perches475be4d2012-02-19 19:52:38 -0800227 pr_debug("%s: SCIOCSETSPID: setting channel %d spid to %s\n",
228 sc_adapter[card]->devicename, data->channel, spid);
229 status = send_and_receive(card, CEPID, ceReqTypeCall,
230 ceReqClass0, ceReqCallSetSPID, data->channel,
231 strlen(spid), spid, rcvmsg, SAR_TIMEOUT);
232 if (!status && !(rcvmsg->rsp_status)) {
233 pr_debug("%s: SCIOCSETSPID: command successful\n",
234 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 kfree(rcvmsg);
236 kfree(spid);
237 return 0;
238 }
239 else {
240 pr_debug("%s: SCIOCSETSPID: command failed (status = %d)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800241 sc_adapter[card]->devicename, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 kfree(rcvmsg);
243 kfree(spid);
244 return status;
245 }
246 }
247
248 case SCIOCGETDN:
249 {
250 pr_debug("%s: SCIOGETDN: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800251 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 /*
254 * Get the dn from the board
255 */
256 status = send_and_receive(card, CEPID, ceReqTypeCall, ceReqClass0, ceReqCallGetMyNumber,
Joe Perches475be4d2012-02-19 19:52:38 -0800257 data->channel, 0, NULL, rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (!status) {
259 pr_debug("%s: SCIOCGETDN: command successful\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800260 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
262 else {
263 pr_debug("%s: SCIOCGETDN: command failed (status = %d)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800264 sc_adapter[card]->devicename, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 kfree(rcvmsg);
266 return status;
267 }
268
Dan Carpenter4b030d42010-08-04 23:38:06 +0000269 dn = kzalloc(SCIOC_DNSIZE, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (!dn) {
271 kfree(rcvmsg);
272 return -ENOMEM;
273 }
Dan Carpenter4b030d42010-08-04 23:38:06 +0000274 strlcpy(dn, rcvmsg->msg_data.byte_array, SCIOC_DNSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 kfree(rcvmsg);
276
277 /*
278 * Package the dn and send to user space
279 */
280 if (copy_to_user(data->dataptr, dn, SCIOC_DNSIZE)) {
281 kfree(dn);
282 return -EFAULT;
283 }
284 kfree(dn);
285 return 0;
Joe Perches475be4d2012-02-19 19:52:38 -0800286 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 case SCIOCSETDN:
289 {
290 pr_debug("%s: SCIOSETDN: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800291 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 /*
294 * Get the spid from user space
295 */
Julia Lawall024cb8a2010-05-21 22:26:42 +0000296 dn = memdup_user(data->dataptr, SCIOC_DNSIZE);
297 if (IS_ERR(dn)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 kfree(rcvmsg);
Julia Lawall024cb8a2010-05-21 22:26:42 +0000299 return PTR_ERR(dn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301
Joe Perches475be4d2012-02-19 19:52:38 -0800302 pr_debug("%s: SCIOCSETDN: setting channel %d dn to %s\n",
303 sc_adapter[card]->devicename, data->channel, dn);
304 status = send_and_receive(card, CEPID, ceReqTypeCall,
305 ceReqClass0, ceReqCallSetMyNumber, data->channel,
306 strlen(dn), dn, rcvmsg, SAR_TIMEOUT);
307 if (!status && !(rcvmsg->rsp_status)) {
308 pr_debug("%s: SCIOCSETDN: command successful\n",
309 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 kfree(rcvmsg);
311 kfree(dn);
312 return 0;
313 }
314 else {
315 pr_debug("%s: SCIOCSETDN: command failed (status = %d)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800316 sc_adapter[card]->devicename, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 kfree(rcvmsg);
318 kfree(dn);
319 return status;
320 }
321 }
322
323 case SCIOCTRACE:
324
325 pr_debug("%s: SCIOTRACE: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800326 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327/* sc_adapter[card]->trace = !sc_adapter[card]->trace;
328 pr_debug("%s: SCIOCTRACE: tracing turned %s\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800329 sc_adapter[card]->devicename,
330 sc_adapter[card]->trace ? "ON" : "OFF"); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 break;
332
333 case SCIOCSTAT:
334 {
335 boardInfo *bi;
336
337 pr_debug("%s: SCIOSTAT: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800338 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Dan Carpenter4b030d42010-08-04 23:38:06 +0000340 bi = kzalloc(sizeof(boardInfo), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 if (!bi) {
342 kfree(rcvmsg);
343 return -ENOMEM;
344 }
345
346 kfree(rcvmsg);
347 GetStatus(card, bi);
348
349 if (copy_to_user(data->dataptr, bi, sizeof(boardInfo))) {
350 kfree(bi);
351 return -EFAULT;
352 }
353
354 kfree(bi);
355 return 0;
356 }
357
358 case SCIOCGETSPEED:
359 {
360 pr_debug("%s: SCIOGETSPEED: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800361 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363 /*
364 * Get the speed from the board
365 */
Joe Perches475be4d2012-02-19 19:52:38 -0800366 status = send_and_receive(card, CEPID, ceReqTypeCall, ceReqClass0,
367 ceReqCallGetCallType, data->channel, 0, NULL, rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 if (!status && !(rcvmsg->rsp_status)) {
369 pr_debug("%s: SCIOCGETSPEED: command successful\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800370 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 }
372 else {
373 pr_debug("%s: SCIOCGETSPEED: command failed (status = %d)\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800374 sc_adapter[card]->devicename, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 kfree(rcvmsg);
376 return status;
377 }
378
379 speed = rcvmsg->msg_data.byte_array[0];
380
381 kfree(rcvmsg);
382
383 /*
384 * Package the switch type and send to user space
385 */
386
387 if (copy_to_user(data->dataptr, &speed, sizeof(char)))
388 return -EFAULT;
389
390 return 0;
391 }
392
393 case SCIOCSETSPEED:
394 pr_debug("%s: SCIOCSETSPEED: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800395 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 break;
397
398 case SCIOCLOOPTST:
399 pr_debug("%s: SCIOCLOOPTST: ioctl received\n",
Joe Perches475be4d2012-02-19 19:52:38 -0800400 sc_adapter[card]->devicename);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 break;
402
403 default:
404 kfree(rcvmsg);
405 return -1;
406 }
407
408 kfree(rcvmsg);
409 return 0;
410}
411
Adrian Bunke3ca5e72005-06-25 14:58:34 -0700412static int GetStatus(int card, boardInfo *bi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413{
414 RspMessage rcvmsg;
415 int i, status;
416
417 /*
418 * Fill in some of the basic info about the board
419 */
420 bi->modelid = sc_adapter[card]->model;
421 strcpy(bi->serial_no, sc_adapter[card]->hwconfig.serial_no);
422 strcpy(bi->part_no, sc_adapter[card]->hwconfig.part_no);
423 bi->iobase = sc_adapter[card]->iobase;
424 bi->rambase = sc_adapter[card]->rambase;
425 bi->irq = sc_adapter[card]->interrupt;
426 bi->ramsize = sc_adapter[card]->hwconfig.ram_size;
427 bi->interface = sc_adapter[card]->hwconfig.st_u_sense;
428 strcpy(bi->load_ver, sc_adapter[card]->load_ver);
429 strcpy(bi->proc_ver, sc_adapter[card]->proc_ver);
430
431 /*
432 * Get the current PhyStats and LnkStats
433 */
434 status = send_and_receive(card, CEPID, ceReqTypePhy, ceReqClass2,
Joe Perches475be4d2012-02-19 19:52:38 -0800435 ceReqPhyStatus, 0, 0, NULL, &rcvmsg, SAR_TIMEOUT);
436 if (!status) {
437 if (sc_adapter[card]->model < PRI_BOARD) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 bi->l1_status = rcvmsg.msg_data.byte_array[2];
Joe Perches475be4d2012-02-19 19:52:38 -0800439 for (i = 0; i < BRI_CHANNELS; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 bi->status.bristats[i].phy_stat =
441 rcvmsg.msg_data.byte_array[i];
442 }
443 else {
444 bi->l1_status = rcvmsg.msg_data.byte_array[0];
445 bi->l2_status = rcvmsg.msg_data.byte_array[1];
Joe Perches475be4d2012-02-19 19:52:38 -0800446 for (i = 0; i < PRI_CHANNELS; i++)
447 bi->status.pristats[i].phy_stat =
448 rcvmsg.msg_data.byte_array[i + 2];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450 }
Joe Perches475be4d2012-02-19 19:52:38 -0800451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 /*
453 * Get the call types for each channel
454 */
Joe Perches475be4d2012-02-19 19:52:38 -0800455 for (i = 0; i < sc_adapter[card]->nChannels; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 status = send_and_receive(card, CEPID, ceReqTypeCall, ceReqClass0,
Joe Perches475be4d2012-02-19 19:52:38 -0800457 ceReqCallGetCallType, 0, 0, NULL, &rcvmsg, SAR_TIMEOUT);
458 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (sc_adapter[card]->model == PRI_BOARD) {
Joe Perches475be4d2012-02-19 19:52:38 -0800460 bi->status.pristats[i].call_type =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 rcvmsg.msg_data.byte_array[0];
462 }
463 else {
464 bi->status.bristats[i].call_type =
465 rcvmsg.msg_data.byte_array[0];
466 }
467 }
468 }
Joe Perches475be4d2012-02-19 19:52:38 -0800469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 /*
471 * If PRI, get the call states and service states for each channel
472 */
473 if (sc_adapter[card]->model == PRI_BOARD) {
474 /*
475 * Get the call states
476 */
477 status = send_and_receive(card, CEPID, ceReqTypeStat, ceReqClass2,
Joe Perches475be4d2012-02-19 19:52:38 -0800478 ceReqPhyChCallState, 0, 0, NULL, &rcvmsg, SAR_TIMEOUT);
479 if (!status) {
480 for (i = 0; i < PRI_CHANNELS; i++)
481 bi->status.pristats[i].call_state =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 rcvmsg.msg_data.byte_array[i];
483 }
484
485 /*
486 * Get the service states
487 */
488 status = send_and_receive(card, CEPID, ceReqTypeStat, ceReqClass2,
Joe Perches475be4d2012-02-19 19:52:38 -0800489 ceReqPhyChServState, 0, 0, NULL, &rcvmsg, SAR_TIMEOUT);
490 if (!status) {
491 for (i = 0; i < PRI_CHANNELS; i++)
492 bi->status.pristats[i].serv_state =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 rcvmsg.msg_data.byte_array[i];
494 }
495
496 /*
497 * Get the link stats for the channels
498 */
Joe Perches475be4d2012-02-19 19:52:38 -0800499 for (i = 1; i <= PRI_CHANNELS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 status = send_and_receive(card, CEPID, ceReqTypeLnk, ceReqClass0,
Joe Perches475be4d2012-02-19 19:52:38 -0800501 ceReqLnkGetStats, i, 0, NULL, &rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (!status) {
Joe Perches475be4d2012-02-19 19:52:38 -0800503 bi->status.pristats[i - 1].link_stats.tx_good =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 (unsigned long)rcvmsg.msg_data.byte_array[0];
Joe Perches475be4d2012-02-19 19:52:38 -0800505 bi->status.pristats[i - 1].link_stats.tx_bad =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 (unsigned long)rcvmsg.msg_data.byte_array[4];
Joe Perches475be4d2012-02-19 19:52:38 -0800507 bi->status.pristats[i - 1].link_stats.rx_good =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 (unsigned long)rcvmsg.msg_data.byte_array[8];
Joe Perches475be4d2012-02-19 19:52:38 -0800509 bi->status.pristats[i - 1].link_stats.rx_bad =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 (unsigned long)rcvmsg.msg_data.byte_array[12];
511 }
512 }
513
514 /*
515 * Link stats for the D channel
516 */
517 status = send_and_receive(card, CEPID, ceReqTypeLnk, ceReqClass0,
Joe Perches475be4d2012-02-19 19:52:38 -0800518 ceReqLnkGetStats, 0, 0, NULL, &rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (!status) {
520 bi->dch_stats.tx_good = (unsigned long)rcvmsg.msg_data.byte_array[0];
521 bi->dch_stats.tx_bad = (unsigned long)rcvmsg.msg_data.byte_array[4];
522 bi->dch_stats.rx_good = (unsigned long)rcvmsg.msg_data.byte_array[8];
523 bi->dch_stats.rx_bad = (unsigned long)rcvmsg.msg_data.byte_array[12];
524 }
525
526 return 0;
527 }
528
529 /*
530 * If BRI or POTS, Get SPID, DN and call types for each channel
531 */
532
533 /*
534 * Get the link stats for the channels
535 */
536 status = send_and_receive(card, CEPID, ceReqTypeLnk, ceReqClass0,
Joe Perches475be4d2012-02-19 19:52:38 -0800537 ceReqLnkGetStats, 0, 0, NULL, &rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (!status) {
539 bi->dch_stats.tx_good = (unsigned long)rcvmsg.msg_data.byte_array[0];
540 bi->dch_stats.tx_bad = (unsigned long)rcvmsg.msg_data.byte_array[4];
541 bi->dch_stats.rx_good = (unsigned long)rcvmsg.msg_data.byte_array[8];
542 bi->dch_stats.rx_bad = (unsigned long)rcvmsg.msg_data.byte_array[12];
Joe Perches475be4d2012-02-19 19:52:38 -0800543 bi->status.bristats[0].link_stats.tx_good =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 (unsigned long)rcvmsg.msg_data.byte_array[16];
Joe Perches475be4d2012-02-19 19:52:38 -0800545 bi->status.bristats[0].link_stats.tx_bad =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 (unsigned long)rcvmsg.msg_data.byte_array[20];
Joe Perches475be4d2012-02-19 19:52:38 -0800547 bi->status.bristats[0].link_stats.rx_good =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 (unsigned long)rcvmsg.msg_data.byte_array[24];
Joe Perches475be4d2012-02-19 19:52:38 -0800549 bi->status.bristats[0].link_stats.rx_bad =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 (unsigned long)rcvmsg.msg_data.byte_array[28];
Joe Perches475be4d2012-02-19 19:52:38 -0800551 bi->status.bristats[1].link_stats.tx_good =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 (unsigned long)rcvmsg.msg_data.byte_array[32];
Joe Perches475be4d2012-02-19 19:52:38 -0800553 bi->status.bristats[1].link_stats.tx_bad =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 (unsigned long)rcvmsg.msg_data.byte_array[36];
Joe Perches475be4d2012-02-19 19:52:38 -0800555 bi->status.bristats[1].link_stats.rx_good =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 (unsigned long)rcvmsg.msg_data.byte_array[40];
Joe Perches475be4d2012-02-19 19:52:38 -0800557 bi->status.bristats[1].link_stats.rx_bad =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 (unsigned long)rcvmsg.msg_data.byte_array[44];
559 }
560
561 /*
562 * Get the SPIDs
563 */
Joe Perches475be4d2012-02-19 19:52:38 -0800564 for (i = 0; i < BRI_CHANNELS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 status = send_and_receive(card, CEPID, ceReqTypeCall, ceReqClass0,
Joe Perches475be4d2012-02-19 19:52:38 -0800566 ceReqCallGetSPID, i + 1, 0, NULL, &rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 if (!status)
568 strcpy(bi->status.bristats[i].spid, rcvmsg.msg_data.byte_array);
569 }
Joe Perches475be4d2012-02-19 19:52:38 -0800570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 /*
572 * Get the DNs
573 */
Joe Perches475be4d2012-02-19 19:52:38 -0800574 for (i = 0; i < BRI_CHANNELS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 status = send_and_receive(card, CEPID, ceReqTypeCall, ceReqClass0,
Joe Perches475be4d2012-02-19 19:52:38 -0800576 ceReqCallGetMyNumber, i + 1, 0, NULL, &rcvmsg, SAR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 if (!status)
578 strcpy(bi->status.bristats[i].dn, rcvmsg.msg_data.byte_array);
579 }
Joe Perches475be4d2012-02-19 19:52:38 -0800580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 return 0;
582}