File: /usr/src/linux/drivers/isdn/hysdn/hycapi.c
1 /* $Id: hycapi.c,v 1.8.6.3 2001/05/26 15:19:58 kai Exp $
2 *
3 * Linux driver for HYSDN cards, CAPI2.0-Interface.
4 * written by Ulrich Albrecht (u.albrecht@hypercope.de) for Hypercope GmbH
5 *
6 * Copyright 2000 by Hypercope GmbH
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24 #define __NO_VERSION__
25 #include <linux/module.h>
26 #include <linux/version.h>
27 #include <linux/signal.h>
28 #include <linux/kernel.h>
29 #include <linux/skbuff.h>
30
31
32 #define VER_DRIVER 0
33 #define VER_CARDTYPE 1
34 #define VER_HWID 2
35 #define VER_SERIAL 3
36 #define VER_OPTION 4
37 #define VER_PROTO 5
38 #define VER_PROFILE 6
39 #define VER_CAPI 7
40
41 #include "hysdn_defs.h"
42 #include <linux/kernelcapi.h>
43
44 static char hycapi_revision[]="$Revision: 1.8.6.3 $";
45
46 unsigned int hycapi_enable = 0xffffffff;
47 MODULE_PARM(hycapi_enable, "i");
48
49 typedef struct _hycapi_appl {
50 unsigned int ctrl_mask;
51 capi_register_params rp;
52 struct sk_buff *listen_req[CAPI_MAXCONTR];
53 } hycapi_appl;
54
55 static hycapi_appl hycapi_applications[CAPI_MAXAPPL];
56
57 static inline int _hycapi_appCheck(int app_id, int ctrl_no)
58 {
59 if((ctrl_no <= 0) || (ctrl_no > CAPI_MAXCONTR) || (app_id <= 0) ||
60 (app_id > CAPI_MAXAPPL))
61 {
62 printk(KERN_ERR "HYCAPI: Invalid request app_id %d for controller %d", app_id, ctrl_no);
63 return -1;
64 }
65 return ((hycapi_applications[app_id-1].ctrl_mask & (1 << (ctrl_no-1))) != 0);
66 }
67
68 struct capi_driver_interface *hy_di = NULL;
69
70 /******************************
71 Kernel-Capi callback reset_ctr
72 ******************************/
73
74 void
75 hycapi_reset_ctr(struct capi_ctr *ctrl)
76 {
77 #ifdef HYCAPI_PRINTFNAMES
78 printk(KERN_NOTICE "HYCAPI hycapi_reset_ctr\n");
79 #endif
80 ctrl->reseted(ctrl);
81 }
82
83 /******************************
84 Kernel-Capi callback remove_ctr
85 ******************************/
86
87 void
88 hycapi_remove_ctr(struct capi_ctr *ctrl)
89 {
90 int i;
91 hycapictrl_info *cinfo = NULL;
92 hysdn_card *card = NULL;
93 #ifdef HYCAPI_PRINTFNAMES
94 printk(KERN_NOTICE "HYCAPI hycapi_remove_ctr\n");
95 #endif
96 if(!hy_di) {
97 printk(KERN_ERR "No capi_driver_interface set!");
98 return;
99 }
100 cinfo = (hycapictrl_info *)(ctrl->driverdata);
101 if(!cinfo) {
102 printk(KERN_ERR "No hycapictrl_info set!");
103 return;
104 }
105 card = cinfo->card;
106 ctrl->suspend_output(ctrl);
107 for(i=0; i<CAPI_MAXAPPL;i++) {
108 if(hycapi_applications[i].listen_req[ctrl->cnr-1]) {
109 kfree_skb(hycapi_applications[i].listen_req[ctrl->cnr-1]);
110 hycapi_applications[i].listen_req[ctrl->cnr-1] = NULL;
111 }
112 }
113 hy_di->detach_ctr(ctrl);
114 ctrl->driverdata = 0;
115 kfree(card->hyctrlinfo);
116
117
118 card->hyctrlinfo = NULL;
119 }
120
121 /***********************************************************
122
123 Queue a CAPI-message to the controller.
124
125 ***********************************************************/
126
127 static void
128 hycapi_sendmsg_internal(struct capi_ctr *ctrl, struct sk_buff *skb)
129 {
130 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
131 hysdn_card *card = cinfo->card;
132
133 spin_lock_irq(&cinfo->lock);
134 #ifdef HYCAPI_PRINTFNAMES
135 printk(KERN_NOTICE "hycapi_send_message\n");
136 #endif
137 cinfo->skbs[cinfo->in_idx++] = skb; /* add to buffer list */
138 if (cinfo->in_idx >= HYSDN_MAX_CAPI_SKB)
139 cinfo->in_idx = 0; /* wrap around */
140 cinfo->sk_count++; /* adjust counter */
141 if (cinfo->sk_count >= HYSDN_MAX_CAPI_SKB) {
142 /* inform upper layers we're full */
143 printk(KERN_ERR "HYSDN Card%d: CAPI-buffer overrun!\n",
144 card->myid);
145 ctrl->suspend_output(ctrl);
146 }
147 cinfo->tx_skb = skb;
148 spin_unlock_irq(&cinfo->lock);
149 queue_task(&card->irq_queue, &tq_immediate);
150 mark_bh(IMMEDIATE_BH);
151 }
152
153 /***********************************************************
154 hycapi_register_internal
155
156 Send down the CAPI_REGISTER-Command to the controller.
157 This functions will also be used if the adapter has been rebooted to
158 re-register any applications in the private list.
159
160 ************************************************************/
161
162 static void
163 hycapi_register_internal(struct capi_ctr *ctrl, __u16 appl,
164 capi_register_params *rp)
165 {
166 char ExtFeatureDefaults[] = "49 /0/0/0/0,*/1,*/2,*/3,*/4,*/5,*/6,*/7,*/8,*/9,*";
167 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
168 hysdn_card *card = cinfo->card;
169 struct sk_buff *skb;
170 __u16 len;
171 __u8 _command = 0xa0, _subcommand = 0x80;
172 __u16 MessageNumber = 0x0000;
173 __u16 MessageBufferSize = 0;
174 int slen = strlen(ExtFeatureDefaults);
175 #ifdef HYCAPI_PRINTFNAMES
176 printk(KERN_NOTICE "hycapi_register_appl\n");
177 #endif
178 MessageBufferSize = rp->level3cnt * rp->datablkcnt * rp->datablklen;
179
180 len = CAPI_MSG_BASELEN + 8 + slen + 1;
181 if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
182 printk(KERN_ERR "HYSDN card%d: memory squeeze in hycapi_register_appl\n",
183 card->myid);
184 return;
185 }
186 memcpy(skb_put(skb,sizeof(__u16)), &len, sizeof(__u16));
187 memcpy(skb_put(skb,sizeof(__u16)), &appl, sizeof(__u16));
188 memcpy(skb_put(skb,sizeof(__u8)), &_command, sizeof(_command));
189 memcpy(skb_put(skb,sizeof(__u8)), &_subcommand, sizeof(_subcommand));
190 memcpy(skb_put(skb,sizeof(__u16)), &MessageNumber, sizeof(__u16));
191 memcpy(skb_put(skb,sizeof(__u16)), &MessageBufferSize, sizeof(__u16));
192 memcpy(skb_put(skb,sizeof(__u16)), &(rp->level3cnt), sizeof(__u16));
193 memcpy(skb_put(skb,sizeof(__u16)), &(rp->datablkcnt), sizeof(__u16));
194 memcpy(skb_put(skb,sizeof(__u16)), &(rp->datablklen), sizeof(__u16));
195 memcpy(skb_put(skb,slen), ExtFeatureDefaults, slen);
196 hycapi_applications[appl-1].ctrl_mask |= (1 << (ctrl->cnr-1));
197 hycapi_send_message(ctrl, skb);
198 }
199
200 /************************************************************
201 hycapi_restart_internal
202
203 After an adapter has been rebootet, re-register all applications and
204 send a LISTEN_REQ (if there has been such a thing )
205
206 *************************************************************/
207
208 static void hycapi_restart_internal(struct capi_ctr *ctrl)
209 {
210 int i;
211 struct sk_buff *skb;
212 #ifdef HYCAPI_PRINTFNAMES
213 printk(KERN_WARNING "HYSDN: hycapi_restart_internal");
214 #endif
215 for(i=0; i<CAPI_MAXAPPL; i++) {
216 if(_hycapi_appCheck(i+1, ctrl->cnr) == 1) {
217 hycapi_register_internal(ctrl, i+1,
218 &hycapi_applications[i].rp);
219 if(hycapi_applications[i].listen_req[ctrl->cnr-1]) {
220 skb = skb_copy(hycapi_applications[i].listen_req[ctrl->cnr-1], GFP_ATOMIC);
221 hycapi_sendmsg_internal(ctrl, skb);
222 }
223 }
224 }
225 }
226
227 /*************************************************************
228 Register an application.
229 Error-checking is done for CAPI-compliance.
230
231 The application is recorded in the internal list.
232 *************************************************************/
233
234 void
235 hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl,
236 capi_register_params *rp)
237 {
238 int MaxLogicalConnections = 0, MaxBDataBlocks = 0, MaxBDataLen = 0;
239 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
240 hysdn_card *card = cinfo->card;
241 int chk = _hycapi_appCheck(appl, ctrl->cnr);
242 if(chk < 0) {
243 return;
244 }
245 if(chk == 1) {
246 printk(KERN_INFO "HYSDN: apl %d allready registered\n", appl);
247 return;
248 }
249 MaxBDataBlocks = rp->datablkcnt > CAPI_MAXDATAWINDOW ? CAPI_MAXDATAWINDOW : rp->datablkcnt;
250 rp->datablkcnt = MaxBDataBlocks;
251 MaxBDataLen = rp->datablklen < 1024 ? 1024 : rp->datablklen ;
252 rp->datablklen = MaxBDataLen;
253
254 MaxLogicalConnections = rp->level3cnt;
255 if (MaxLogicalConnections < 0) {
256 MaxLogicalConnections = card->bchans * -MaxLogicalConnections;
257 }
258 if (MaxLogicalConnections == 0) {
259 MaxLogicalConnections = card->bchans;
260 }
261
262 rp->level3cnt = MaxLogicalConnections;
263 memcpy(&hycapi_applications[appl-1].rp,
264 rp, sizeof(capi_register_params));
265
266 /* MOD_INC_USE_COUNT; */
267 ctrl->appl_registered(ctrl, appl);
268 }
269
270 /*********************************************************************
271
272 hycapi_release_internal
273
274 Send down a CAPI_RELEASE to the controller.
275 *********************************************************************/
276
277 static void hycapi_release_internal(struct capi_ctr *ctrl, __u16 appl)
278 {
279 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
280 hysdn_card *card = cinfo->card;
281 struct sk_buff *skb;
282 __u16 len;
283 __u8 _command = 0xa1, _subcommand = 0x80;
284 __u16 MessageNumber = 0x0000;
285 #ifdef HYCAPI_PRINTFNAMES
286 printk(KERN_NOTICE "hycapi_release_appl\n");
287 #endif
288 len = CAPI_MSG_BASELEN;
289 if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
290 printk(KERN_ERR "HYSDN card%d: memory squeeze in hycapi_register_appl\n",
291 card->myid);
292 return;
293 }
294 memcpy(skb_put(skb,sizeof(__u16)), &len, sizeof(__u16));
295 memcpy(skb_put(skb,sizeof(__u16)), &appl, sizeof(__u16));
296 memcpy(skb_put(skb,sizeof(__u8)), &_command, sizeof(_command));
297 memcpy(skb_put(skb,sizeof(__u8)), &_subcommand, sizeof(_subcommand));
298 memcpy(skb_put(skb,sizeof(__u16)), &MessageNumber, sizeof(__u16));
299 hycapi_send_message(ctrl, skb);
300 hycapi_applications[appl-1].ctrl_mask &= ~(1 << (ctrl->cnr-1));
301 }
302
303 /******************************************************************
304 hycapi_release_appl
305
306 Release the application from the internal list an remove it's
307 registration at controller-level
308 ******************************************************************/
309
310 void
311 hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl)
312 {
313 int chk;
314
315 chk = _hycapi_appCheck(appl, ctrl->cnr);
316 if(chk<0) {
317 printk(KERN_ERR "HYCAPI: Releasing invalid appl %d on controller %d\n", appl, ctrl->cnr);
318 return;
319 }
320 if(hycapi_applications[appl-1].listen_req[ctrl->cnr-1]) {
321 kfree_skb(hycapi_applications[appl-1].listen_req[ctrl->cnr-1]);
322 hycapi_applications[appl-1].listen_req[ctrl->cnr-1] = NULL;
323 }
324 if(chk == 1)
325 {
326 hycapi_release_internal(ctrl, appl);
327 }
328 ctrl->appl_released(ctrl, appl);
329 /* MOD_DEC_USE_COUNT; */
330 }
331
332
333 /**************************************************************
334 Kill a single controller.
335 **************************************************************/
336
337 int hycapi_capi_release(hysdn_card *card)
338 {
339 hycapictrl_info *cinfo = card->hyctrlinfo;
340 struct capi_ctr *ctrl;
341 #ifdef HYCAPI_PRINTFNAMES
342 printk(KERN_NOTICE "hycapi_capi_release\n");
343 #endif
344 if(cinfo) {
345 ctrl = cinfo->capi_ctrl;
346 hycapi_remove_ctr(ctrl);
347 }
348 return 0;
349 }
350
351 /**************************************************************
352 hycapi_capi_stop
353
354 Stop CAPI-Output on a card. (e.g. during reboot)
355 ***************************************************************/
356
357 int hycapi_capi_stop(hysdn_card *card)
358 {
359 hycapictrl_info *cinfo = card->hyctrlinfo;
360 struct capi_ctr *ctrl;
361 #ifdef HYCAPI_PRINTFNAMES
362 printk(KERN_NOTICE "hycapi_capi_stop\n");
363 #endif
364 if(cinfo) {
365 if(cinfo->capi_ctrl) {
366 ctrl = cinfo->capi_ctrl;
367 /* ctrl->suspend_output(ctrl); */
368 ctrl->reseted(ctrl);
369
370 } else {
371 printk(KERN_NOTICE "hycapi_capi_stop: cinfo but no capi_ctrl\n");
372 }
373 }
374 return 0;
375 }
376
377 /***************************************************************
378 hycapi_send_message
379
380 Send a message to the controller.
381
382 Messages are parsed for their Command/Subcommand-type, and appropriate
383 action's are performed.
384
385 Note that we have to muck around with a 64Bit-DATA_REQ as there are
386 firmware-releases that do not check the MsgLen-Indication!
387
388 ***************************************************************/
389
390 void hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
391 {
392 __u16 appl_id;
393 int _len, _len2;
394 __u8 msghead[64];
395
396 appl_id = CAPIMSG_APPID(skb->data);
397 switch(_hycapi_appCheck(appl_id, ctrl->cnr))
398 {
399 case 0:
400 /* printk(KERN_INFO "Need to register\n"); */
401 hycapi_register_internal(ctrl,
402 appl_id,
403 &(hycapi_applications[appl_id-1].rp));
404 break;
405 case 1:
406 break;
407 default:
408 printk(KERN_ERR "HYCAPI: Controller mixup!\n");
409 return;
410 }
411 switch(CAPIMSG_CMD(skb->data)) {
412 case CAPI_DISCONNECT_B3_RESP:
413 ctrl->free_ncci(ctrl, appl_id,
414 CAPIMSG_NCCI(skb->data));
415 break;
416 case CAPI_DATA_B3_REQ:
417 _len = CAPIMSG_LEN(skb->data);
418 if (_len > 22) {
419 _len2 = _len - 22;
420 memcpy(msghead, skb->data, 22);
421 memcpy(skb->data + _len2, msghead, 22);
422 skb_pull(skb, _len2);
423 CAPIMSG_SETLEN(skb->data, 22);
424 }
425 break;
426 case CAPI_LISTEN_REQ:
427 if(hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1])
428 {
429 kfree_skb(hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1]);
430 hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1] = NULL;
431 }
432 if (!(hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1] = skb_copy(skb, GFP_ATOMIC)))
433 {
434 printk(KERN_ERR "HYSDN: memory squeeze in private_listen\n");
435 }
436 break;
437 default:
438 break;
439 }
440 hycapi_sendmsg_internal(ctrl, skb);
441 }
442
443 /*********************************************************************
444 hycapi_read_proc
445
446 Informations provided in the /proc/capi-entries.
447
448 *********************************************************************/
449
450 int hycapi_read_proc(char *page, char **start, off_t off,
451 int count, int *eof, struct capi_ctr *ctrl)
452 {
453 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
454 hysdn_card *card = cinfo->card;
455 int len = 0;
456 char *s;
457 #ifdef HYCAPI_PRINTFNAMES
458 printk(KERN_NOTICE "hycapi_read_proc\n");
459 #endif
460 len += sprintf(page+len, "%-16s %s\n", "name", cinfo->cardname);
461 len += sprintf(page+len, "%-16s 0x%x\n", "io", card->iobase);
462 len += sprintf(page+len, "%-16s %d\n", "irq", card->irq);
463
464 switch (card->brdtype) {
465 case BD_PCCARD: s = "HYSDN Hycard"; break;
466 case BD_ERGO: s = "HYSDN Ergo2"; break;
467 case BD_METRO: s = "HYSDN Metro4"; break;
468 case BD_CHAMP2: s = "HYSDN Champ2"; break;
469 case BD_PLEXUS: s = "HYSDN Plexus30"; break;
470 default: s = "???"; break;
471 }
472 len += sprintf(page+len, "%-16s %s\n", "type", s);
473 if ((s = cinfo->version[VER_DRIVER]) != 0)
474 len += sprintf(page+len, "%-16s %s\n", "ver_driver", s);
475 if ((s = cinfo->version[VER_CARDTYPE]) != 0)
476 len += sprintf(page+len, "%-16s %s\n", "ver_cardtype", s);
477 if ((s = cinfo->version[VER_SERIAL]) != 0)
478 len += sprintf(page+len, "%-16s %s\n", "ver_serial", s);
479
480 len += sprintf(page+len, "%-16s %s\n", "cardname", cinfo->cardname);
481
482 if (off+count >= len)
483 *eof = 1;
484 if (len < off)
485 return 0;
486 *start = page + off;
487 return ((count < len-off) ? count : len-off);
488 }
489
490 /**************************************************************
491 hycapi_load_firmware
492
493 This does NOT load any firmware, but the callback somehow is needed
494 on capi-interface registration.
495
496 **************************************************************/
497
498 int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
499 {
500 #ifdef HYCAPI_PRINTFNAMES
501 printk(KERN_NOTICE "hycapi_load_firmware\n");
502 #endif
503 return 0;
504 }
505
506
507 char *hycapi_procinfo(struct capi_ctr *ctrl)
508 {
509 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
510 #ifdef HYCAPI_PRINTFNAMES
511 printk(KERN_NOTICE "hycapi_proc_info\n");
512 #endif
513 if (!cinfo)
514 return "";
515 sprintf(cinfo->infobuf, "%s %s 0x%x %d %s",
516 cinfo->cardname[0] ? cinfo->cardname : "-",
517 cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
518 cinfo->card ? cinfo->card->iobase : 0x0,
519 cinfo->card ? cinfo->card->irq : 0,
520 hycapi_revision
521 );
522 return cinfo->infobuf;
523 }
524
525 /******************************************************************
526 hycapi_rx_capipkt
527
528 Receive a capi-message.
529
530 All B3_DATA_IND are converted to 64K-extension compatible format.
531 New nccis are created if neccessary.
532 *******************************************************************/
533
534 void
535 hycapi_rx_capipkt(hysdn_card * card, uchar * buf, word len)
536 {
537 struct sk_buff *skb;
538 hycapictrl_info *cinfo = card->hyctrlinfo;
539 struct capi_ctr *ctrl;
540 __u16 ApplId;
541 __u16 MsgLen, info;
542 __u16 len2, CapiCmd;
543 __u32 CP64[2] = {0,0};
544 #ifdef HYCAPI_PRINTFNAMES
545 printk(KERN_NOTICE "hycapi_rx_capipkt\n");
546 #endif
547 if(!cinfo) {
548 return;
549 }
550 ctrl = cinfo->capi_ctrl;
551 if(!ctrl)
552 {
553 return;
554 }
555 if(len < CAPI_MSG_BASELEN) {
556 printk(KERN_ERR "HYSDN Card%d: invalid CAPI-message, lenght %d!\n",
557 card->myid, len);
558 return;
559 }
560 MsgLen = CAPIMSG_LEN(buf);
561 ApplId = CAPIMSG_APPID(buf);
562 CapiCmd = CAPIMSG_CMD(buf);
563
564 if((CapiCmd == CAPI_DATA_B3_IND) && (MsgLen < 30)) {
565 len2 = len + (30 - MsgLen);
566 if (!(skb = alloc_skb(len2, GFP_ATOMIC))) {
567 printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n",
568 card->myid);
569 return;
570 }
571 memcpy(skb_put(skb, MsgLen), buf, MsgLen);
572 memcpy(skb_put(skb, 2*sizeof(__u32)), CP64, 2* sizeof(__u32));
573 memcpy(skb_put(skb, len - MsgLen), buf + MsgLen,
574 len - MsgLen);
575 CAPIMSG_SETLEN(skb->data, 30);
576 } else {
577 if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
578 printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n",
579 card->myid);
580 return;
581 }
582 memcpy(skb_put(skb, len), buf, len);
583 }
584 switch(CAPIMSG_CMD(skb->data))
585 {
586 case CAPI_CONNECT_B3_CONF:
587 /* Check info-field for error-indication: */
588 info = CAPIMSG_U16(skb->data, 12);
589 switch(info)
590 {
591 case 0:
592 ctrl->new_ncci(ctrl, ApplId, CAPIMSG_NCCI(skb->data),
593 hycapi_applications[ApplId-1].rp.datablkcnt);
594
595 break;
596 case 0x0001:
597 printk(KERN_ERR "HYSDN Card%d: NCPI not supported by current "
598 "protocol. NCPI ignored.\n", card->myid);
599 break;
600 case 0x2001:
601 printk(KERN_ERR "HYSDN Card%d: Message not supported in"
602 " current state\n", card->myid);
603 break;
604 case 0x2002:
605 printk(KERN_ERR "HYSDN Card%d: illegal PLCI\n", card->myid);
606 break;
607 case 0x2004:
608 printk(KERN_ERR "HYSDN Card%d: out of NCCI\n", card->myid);
609 break;
610 case 0x3008:
611 printk(KERN_ERR "HYSDN Card%d: NCPI not supported\n",
612 card->myid);
613 break;
614 default:
615 printk(KERN_ERR "HYSDN Card%d: Info in CONNECT_B3_CONF: %d\n",
616 card->myid, info);
617 break;
618 }
619 break;
620 case CAPI_CONNECT_B3_IND:
621 ctrl->new_ncci(ctrl, ApplId,
622 CAPIMSG_NCCI(skb->data),
623 hycapi_applications[ApplId-1].rp.datablkcnt);
624 break;
625 default:
626 break;
627 }
628 ctrl->handle_capimsg(ctrl, ApplId, skb);
629 }
630
631 /******************************************************************
632 hycapi_tx_capiack
633
634 Internally acknowledge a msg sent. This will remove the msg from the
635 internal queue.
636
637 *******************************************************************/
638
639 void hycapi_tx_capiack(hysdn_card * card)
640 {
641 hycapictrl_info *cinfo = card->hyctrlinfo;
642 #ifdef HYCAPI_PRINTFNAMES
643 printk(KERN_NOTICE "hycapi_tx_capiack\n");
644 #endif
645 if(!cinfo) {
646 return;
647 }
648 spin_lock_irq(&cinfo->lock);
649 kfree_skb(cinfo->skbs[cinfo->out_idx]); /* free skb */
650 cinfo->skbs[cinfo->out_idx++] = NULL;
651 if (cinfo->out_idx >= HYSDN_MAX_CAPI_SKB)
652 cinfo->out_idx = 0; /* wrap around */
653
654 if (cinfo->sk_count-- == HYSDN_MAX_CAPI_SKB) /* dec usage count */
655 cinfo->capi_ctrl->resume_output(cinfo->capi_ctrl);
656 spin_unlock_irq(&cinfo->lock);
657 }
658
659 /***************************************************************
660 hycapi_tx_capiget(hysdn_card *card)
661
662 This is called when polling for messages to SEND.
663
664 ****************************************************************/
665
666 struct sk_buff *
667 hycapi_tx_capiget(hysdn_card *card)
668 {
669 hycapictrl_info *cinfo = card->hyctrlinfo;
670 if(!cinfo) {
671 return (struct sk_buff *)NULL;
672 }
673 if (!cinfo->sk_count)
674 return (struct sk_buff *)NULL; /* nothing available */
675
676 return (cinfo->skbs[cinfo->out_idx]); /* next packet to send */
677 }
678
679
680 static struct capi_driver hycapi_driver = {
681 "hysdn",
682 "0.0",
683 hycapi_load_firmware,
684 hycapi_reset_ctr,
685 hycapi_remove_ctr,
686 hycapi_register_appl,
687 hycapi_release_appl,
688 hycapi_send_message,
689 hycapi_procinfo,
690 hycapi_read_proc,
691 0, /* use standard driver_read_proc */
692 0, /* no add_card function */
693 };
694
695
696 /**********************************************************
697 int hycapi_init()
698
699 attach the capi-driver to the kernel-capi.
700
701 ***********************************************************/
702
703 int hycapi_init()
704 {
705 struct capi_driver *driver;
706 int i;
707 if(hy_di) {
708 printk(KERN_NOTICE "HyDI allready set\n");
709 return 0;
710 }
711 driver = &hycapi_driver;
712 printk(KERN_NOTICE "HYSDN: Attaching capi-driver\n");
713 hy_di = attach_capi_driver(driver);
714 if (!hy_di) {
715 printk(KERN_ERR "HYCAPI: failed to attach capi_driver\n");
716 return(-1);
717 }
718 for(i=0;i<CAPI_MAXAPPL;i++) {
719 memset(&(hycapi_applications[i]), 0, sizeof(hycapi_appl));
720 }
721 return(0);
722 }
723
724 /**************************************************************
725 hycapi_cleanup(void)
726
727 detach the capi-driver to the kernel-capi. Actually this should
728 free some more ressources. Do that later.
729 **************************************************************/
730
731 void
732 hycapi_cleanup(void)
733 {
734 struct capi_driver *driver;
735 driver = &hycapi_driver;
736 if (!hy_di) {
737 printk(KERN_ERR "HYSDN: no capi-driver to detach (?)\n");
738 return;
739 }
740 printk(KERN_NOTICE "HYSDN: Detaching capi-driver\n");
741 detach_capi_driver(driver);
742 hy_di = 0;
743 return;
744 }
745
746 /********************************************************************
747 hycapi_capi_create(hysdn_card *card)
748
749 Attach the card with it's capi-ctrl.
750 *********************************************************************/
751
752 static void hycapi_fill_profile(hysdn_card *card)
753 {
754 hycapictrl_info *cinfo = NULL;
755 struct capi_ctr *ctrl = NULL;
756 cinfo = card->hyctrlinfo;
757 if(!cinfo) return;
758 ctrl = cinfo->capi_ctrl;
759 if(!ctrl) return;
760 strcpy(ctrl->manu, "Hypercope");
761 ctrl->version.majorversion = 2;
762 ctrl->version.minorversion = 0;
763 ctrl->version.majormanuversion = 3;
764 ctrl->version.minormanuversion = 2;
765 ctrl->profile.ncontroller = card->myid;
766 ctrl->profile.nbchannel = card->bchans;
767 ctrl->profile.goptions = GLOBAL_OPTION_INTERNAL_CONTROLLER |
768 GLOBAL_OPTION_B_CHANNEL_OPERATION;
769 ctrl->profile.support1 = B1_PROT_64KBIT_HDLC |
770 (card->faxchans ? B1_PROT_T30 : 0) |
771 B1_PROT_64KBIT_TRANSPARENT;
772 ctrl->profile.support2 = B2_PROT_ISO7776 |
773 (card->faxchans ? B2_PROT_T30 : 0) |
774 B2_PROT_TRANSPARENT;
775 ctrl->profile.support3 = B3_PROT_TRANSPARENT |
776 B3_PROT_T90NL |
777 (card->faxchans ? B3_PROT_T30 : 0) |
778 (card->faxchans ? B3_PROT_T30EXT : 0) |
779 B3_PROT_ISO8208;
780 }
781
782 int
783 hycapi_capi_create(hysdn_card *card)
784 {
785 hycapictrl_info *cinfo = NULL;
786 struct capi_ctr *ctrl = NULL;
787 #ifdef HYCAPI_PRINTFNAMES
788 printk(KERN_NOTICE "hycapi_capi_create\n");
789 #endif
790 if((hycapi_enable & (1 << card->myid)) == 0) {
791 return 1;
792 }
793 if (!card->hyctrlinfo) {
794 cinfo = (hycapictrl_info *) kmalloc(sizeof(hycapictrl_info), GFP_ATOMIC);
795 if (!cinfo) {
796 printk(KERN_WARNING "HYSDN: no memory for capi-ctrl.\n");
797 return -ENOMEM;
798 }
799 memset(cinfo, 0, sizeof(hycapictrl_info));
800 card->hyctrlinfo = cinfo;
801 cinfo->card = card;
802 spin_lock_init(&cinfo->lock);
803
804 switch (card->brdtype) {
805 case BD_PCCARD: strcpy(cinfo->cardname,"HYSDN Hycard"); break;
806 case BD_ERGO: strcpy(cinfo->cardname,"HYSDN Ergo2"); break;
807 case BD_METRO: strcpy(cinfo->cardname,"HYSDN Metro4"); break;
808 case BD_CHAMP2: strcpy(cinfo->cardname,"HYSDN Champ2"); break;
809 case BD_PLEXUS: strcpy(cinfo->cardname,"HYSDN Plexus30"); break;
810 default: strcpy(cinfo->cardname,"HYSDN ???"); break;
811 }
812
813 cinfo->capi_ctrl = hy_di->attach_ctr(&hycapi_driver,
814 cinfo->cardname, cinfo);
815 ctrl = cinfo->capi_ctrl;
816 if (!ctrl) {
817 printk(KERN_ERR "%s: attach controller failed.\n",
818 hycapi_driver.name);
819 return -EBUSY;
820 }
821 /* fill in the blanks: */
822 hycapi_fill_profile(card);
823 ctrl->ready(ctrl);
824 } else {
825 /* resume output on stopped ctrl */
826 ctrl = card->hyctrlinfo->capi_ctrl;
827 if(ctrl) {
828 hycapi_fill_profile(card);
829 ctrl->ready(ctrl);
830 hycapi_restart_internal(ctrl);
831 /* ctrl->resume_output(ctrl); */
832 } else {
833 printk(KERN_WARNING "HYSDN: No ctrl???? How come?\n");
834 }
835 }
836 return 0;
837 }
838