Linux 4.19.133
[linux/fpc-iii.git] / drivers / isdn / hysdn / hycapi.c
bloba2c15cd7bf6777f49efeaf481bf60786c9940ce5
1 /* $Id: hycapi.c,v 1.8.6.4 2001/09/23 22:24:54 kai Exp $
3 * Linux driver for HYSDN cards, CAPI2.0-Interface.
5 * Author Ulrich Albrecht <u.albrecht@hypercope.de> for Hypercope GmbH
6 * Copyright 2000 by Hypercope GmbH
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
13 #include <linux/module.h>
14 #include <linux/proc_fs.h>
15 #include <linux/seq_file.h>
16 #include <linux/signal.h>
17 #include <linux/kernel.h>
18 #include <linux/skbuff.h>
19 #include <linux/netdevice.h>
20 #include <linux/slab.h>
22 #define VER_DRIVER 0
23 #define VER_CARDTYPE 1
24 #define VER_HWID 2
25 #define VER_SERIAL 3
26 #define VER_OPTION 4
27 #define VER_PROTO 5
28 #define VER_PROFILE 6
29 #define VER_CAPI 7
31 #include "hysdn_defs.h"
32 #include <linux/kernelcapi.h>
34 static char hycapi_revision[] = "$Revision: 1.8.6.4 $";
36 unsigned int hycapi_enable = 0xffffffff;
37 module_param(hycapi_enable, uint, 0);
39 typedef struct _hycapi_appl {
40 unsigned int ctrl_mask;
41 capi_register_params rp;
42 struct sk_buff *listen_req[CAPI_MAXCONTR];
43 } hycapi_appl;
45 static hycapi_appl hycapi_applications[CAPI_MAXAPPL];
47 static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb);
49 static inline int _hycapi_appCheck(int app_id, int ctrl_no)
51 if ((ctrl_no <= 0) || (ctrl_no > CAPI_MAXCONTR) || (app_id <= 0) ||
52 (app_id > CAPI_MAXAPPL))
54 printk(KERN_ERR "HYCAPI: Invalid request app_id %d for controller %d", app_id, ctrl_no);
55 return -1;
57 return ((hycapi_applications[app_id - 1].ctrl_mask & (1 << (ctrl_no-1))) != 0);
60 /******************************
61 Kernel-Capi callback reset_ctr
62 ******************************/
64 static void
65 hycapi_reset_ctr(struct capi_ctr *ctrl)
67 hycapictrl_info *cinfo = ctrl->driverdata;
69 #ifdef HYCAPI_PRINTFNAMES
70 printk(KERN_NOTICE "HYCAPI hycapi_reset_ctr\n");
71 #endif
72 capilib_release(&cinfo->ncci_head);
73 capi_ctr_down(ctrl);
76 /******************************
77 Kernel-Capi callback remove_ctr
78 ******************************/
80 static void
81 hycapi_remove_ctr(struct capi_ctr *ctrl)
83 int i;
84 hycapictrl_info *cinfo = NULL;
85 hysdn_card *card = NULL;
86 #ifdef HYCAPI_PRINTFNAMES
87 printk(KERN_NOTICE "HYCAPI hycapi_remove_ctr\n");
88 #endif
89 cinfo = (hycapictrl_info *)(ctrl->driverdata);
90 if (!cinfo) {
91 printk(KERN_ERR "No hycapictrl_info set!");
92 return;
94 card = cinfo->card;
95 capi_ctr_suspend_output(ctrl);
96 for (i = 0; i < CAPI_MAXAPPL; i++) {
97 if (hycapi_applications[i].listen_req[ctrl->cnr - 1]) {
98 kfree_skb(hycapi_applications[i].listen_req[ctrl->cnr - 1]);
99 hycapi_applications[i].listen_req[ctrl->cnr - 1] = NULL;
102 detach_capi_ctr(ctrl);
103 ctrl->driverdata = NULL;
104 kfree(card->hyctrlinfo);
107 card->hyctrlinfo = NULL;
110 /***********************************************************
112 Queue a CAPI-message to the controller.
114 ***********************************************************/
116 static void
117 hycapi_sendmsg_internal(struct capi_ctr *ctrl, struct sk_buff *skb)
119 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
120 hysdn_card *card = cinfo->card;
122 spin_lock_irq(&cinfo->lock);
123 #ifdef HYCAPI_PRINTFNAMES
124 printk(KERN_NOTICE "hycapi_send_message\n");
125 #endif
126 cinfo->skbs[cinfo->in_idx++] = skb; /* add to buffer list */
127 if (cinfo->in_idx >= HYSDN_MAX_CAPI_SKB)
128 cinfo->in_idx = 0; /* wrap around */
129 cinfo->sk_count++; /* adjust counter */
130 if (cinfo->sk_count >= HYSDN_MAX_CAPI_SKB) {
131 /* inform upper layers we're full */
132 printk(KERN_ERR "HYSDN Card%d: CAPI-buffer overrun!\n",
133 card->myid);
134 capi_ctr_suspend_output(ctrl);
136 cinfo->tx_skb = skb;
137 spin_unlock_irq(&cinfo->lock);
138 schedule_work(&card->irq_queue);
141 /***********************************************************
142 hycapi_register_internal
144 Send down the CAPI_REGISTER-Command to the controller.
145 This functions will also be used if the adapter has been rebooted to
146 re-register any applications in the private list.
148 ************************************************************/
150 static void
151 hycapi_register_internal(struct capi_ctr *ctrl, __u16 appl,
152 capi_register_params *rp)
154 char ExtFeatureDefaults[] = "49 /0/0/0/0,*/1,*/2,*/3,*/4,*/5,*/6,*/7,*/8,*/9,*";
155 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
156 hysdn_card *card = cinfo->card;
157 struct sk_buff *skb;
158 __u16 len;
159 __u8 _command = 0xa0, _subcommand = 0x80;
160 __u16 MessageNumber = 0x0000;
161 __u16 MessageBufferSize = 0;
162 int slen = strlen(ExtFeatureDefaults);
163 #ifdef HYCAPI_PRINTFNAMES
164 printk(KERN_NOTICE "hycapi_register_appl\n");
165 #endif
166 MessageBufferSize = rp->level3cnt * rp->datablkcnt * rp->datablklen;
168 len = CAPI_MSG_BASELEN + 8 + slen + 1;
169 if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
170 printk(KERN_ERR "HYSDN card%d: memory squeeze in hycapi_register_appl\n",
171 card->myid);
172 return;
174 skb_put_data(skb, &len, sizeof(__u16));
175 skb_put_data(skb, &appl, sizeof(__u16));
176 skb_put_data(skb, &_command, sizeof(__u8));
177 skb_put_data(skb, &_subcommand, sizeof(__u8));
178 skb_put_data(skb, &MessageNumber, sizeof(__u16));
179 skb_put_data(skb, &MessageBufferSize, sizeof(__u16));
180 skb_put_data(skb, &(rp->level3cnt), sizeof(__u16));
181 skb_put_data(skb, &(rp->datablkcnt), sizeof(__u16));
182 skb_put_data(skb, &(rp->datablklen), sizeof(__u16));
183 skb_put_data(skb, ExtFeatureDefaults, slen);
184 hycapi_applications[appl - 1].ctrl_mask |= (1 << (ctrl->cnr - 1));
185 hycapi_send_message(ctrl, skb);
188 /************************************************************
189 hycapi_restart_internal
191 After an adapter has been rebootet, re-register all applications and
192 send a LISTEN_REQ (if there has been such a thing )
194 *************************************************************/
196 static void hycapi_restart_internal(struct capi_ctr *ctrl)
198 int i;
199 struct sk_buff *skb;
200 #ifdef HYCAPI_PRINTFNAMES
201 printk(KERN_WARNING "HYSDN: hycapi_restart_internal");
202 #endif
203 for (i = 0; i < CAPI_MAXAPPL; i++) {
204 if (_hycapi_appCheck(i + 1, ctrl->cnr) == 1) {
205 hycapi_register_internal(ctrl, i + 1,
206 &hycapi_applications[i].rp);
207 if (hycapi_applications[i].listen_req[ctrl->cnr - 1]) {
208 skb = skb_copy(hycapi_applications[i].listen_req[ctrl->cnr - 1], GFP_ATOMIC);
209 hycapi_sendmsg_internal(ctrl, skb);
215 /*************************************************************
216 Register an application.
217 Error-checking is done for CAPI-compliance.
219 The application is recorded in the internal list.
220 *************************************************************/
222 static void
223 hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl,
224 capi_register_params *rp)
226 int MaxLogicalConnections = 0, MaxBDataBlocks = 0, MaxBDataLen = 0;
227 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
228 hysdn_card *card = cinfo->card;
229 int chk = _hycapi_appCheck(appl, ctrl->cnr);
230 if (chk < 0) {
231 return;
233 if (chk == 1) {
234 printk(KERN_INFO "HYSDN: apl %d already registered\n", appl);
235 return;
237 MaxBDataBlocks = rp->datablkcnt > CAPI_MAXDATAWINDOW ? CAPI_MAXDATAWINDOW : rp->datablkcnt;
238 rp->datablkcnt = MaxBDataBlocks;
239 MaxBDataLen = rp->datablklen < 1024 ? 1024 : rp->datablklen;
240 rp->datablklen = MaxBDataLen;
242 MaxLogicalConnections = rp->level3cnt;
243 if (MaxLogicalConnections < 0) {
244 MaxLogicalConnections = card->bchans * -MaxLogicalConnections;
246 if (MaxLogicalConnections == 0) {
247 MaxLogicalConnections = card->bchans;
250 rp->level3cnt = MaxLogicalConnections;
251 memcpy(&hycapi_applications[appl - 1].rp,
252 rp, sizeof(capi_register_params));
255 /*********************************************************************
257 hycapi_release_internal
259 Send down a CAPI_RELEASE to the controller.
260 *********************************************************************/
262 static void hycapi_release_internal(struct capi_ctr *ctrl, __u16 appl)
264 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
265 hysdn_card *card = cinfo->card;
266 struct sk_buff *skb;
267 __u16 len;
268 __u8 _command = 0xa1, _subcommand = 0x80;
269 __u16 MessageNumber = 0x0000;
271 capilib_release_appl(&cinfo->ncci_head, appl);
273 #ifdef HYCAPI_PRINTFNAMES
274 printk(KERN_NOTICE "hycapi_release_appl\n");
275 #endif
276 len = CAPI_MSG_BASELEN;
277 if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
278 printk(KERN_ERR "HYSDN card%d: memory squeeze in hycapi_register_appl\n",
279 card->myid);
280 return;
282 skb_put_data(skb, &len, sizeof(__u16));
283 skb_put_data(skb, &appl, sizeof(__u16));
284 skb_put_data(skb, &_command, sizeof(__u8));
285 skb_put_data(skb, &_subcommand, sizeof(__u8));
286 skb_put_data(skb, &MessageNumber, sizeof(__u16));
287 hycapi_send_message(ctrl, skb);
288 hycapi_applications[appl - 1].ctrl_mask &= ~(1 << (ctrl->cnr - 1));
291 /******************************************************************
292 hycapi_release_appl
294 Release the application from the internal list an remove it's
295 registration at controller-level
296 ******************************************************************/
298 static void
299 hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl)
301 int chk;
303 chk = _hycapi_appCheck(appl, ctrl->cnr);
304 if (chk < 0) {
305 printk(KERN_ERR "HYCAPI: Releasing invalid appl %d on controller %d\n", appl, ctrl->cnr);
306 return;
308 if (hycapi_applications[appl - 1].listen_req[ctrl->cnr - 1]) {
309 kfree_skb(hycapi_applications[appl - 1].listen_req[ctrl->cnr - 1]);
310 hycapi_applications[appl - 1].listen_req[ctrl->cnr - 1] = NULL;
312 if (chk == 1)
314 hycapi_release_internal(ctrl, appl);
319 /**************************************************************
320 Kill a single controller.
321 **************************************************************/
323 int hycapi_capi_release(hysdn_card *card)
325 hycapictrl_info *cinfo = card->hyctrlinfo;
326 struct capi_ctr *ctrl;
327 #ifdef HYCAPI_PRINTFNAMES
328 printk(KERN_NOTICE "hycapi_capi_release\n");
329 #endif
330 if (cinfo) {
331 ctrl = &cinfo->capi_ctrl;
332 hycapi_remove_ctr(ctrl);
334 return 0;
337 /**************************************************************
338 hycapi_capi_stop
340 Stop CAPI-Output on a card. (e.g. during reboot)
341 ***************************************************************/
343 int hycapi_capi_stop(hysdn_card *card)
345 hycapictrl_info *cinfo = card->hyctrlinfo;
346 struct capi_ctr *ctrl;
347 #ifdef HYCAPI_PRINTFNAMES
348 printk(KERN_NOTICE "hycapi_capi_stop\n");
349 #endif
350 if (cinfo) {
351 ctrl = &cinfo->capi_ctrl;
352 /* ctrl->suspend_output(ctrl); */
353 capi_ctr_down(ctrl);
355 return 0;
358 /***************************************************************
359 hycapi_send_message
361 Send a message to the controller.
363 Messages are parsed for their Command/Subcommand-type, and appropriate
364 action's are performed.
366 Note that we have to muck around with a 64Bit-DATA_REQ as there are
367 firmware-releases that do not check the MsgLen-Indication!
369 ***************************************************************/
371 static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
373 __u16 appl_id;
374 int _len, _len2;
375 __u8 msghead[64];
376 hycapictrl_info *cinfo = ctrl->driverdata;
377 u16 retval = CAPI_NOERROR;
379 appl_id = CAPIMSG_APPID(skb->data);
380 switch (_hycapi_appCheck(appl_id, ctrl->cnr))
382 case 0:
383 /* printk(KERN_INFO "Need to register\n"); */
384 hycapi_register_internal(ctrl,
385 appl_id,
386 &(hycapi_applications[appl_id - 1].rp));
387 break;
388 case 1:
389 break;
390 default:
391 printk(KERN_ERR "HYCAPI: Controller mixup!\n");
392 retval = CAPI_ILLAPPNR;
393 goto out;
395 switch (CAPIMSG_CMD(skb->data)) {
396 case CAPI_DISCONNECT_B3_RESP:
397 capilib_free_ncci(&cinfo->ncci_head, appl_id,
398 CAPIMSG_NCCI(skb->data));
399 break;
400 case CAPI_DATA_B3_REQ:
401 _len = CAPIMSG_LEN(skb->data);
402 if (_len > 22) {
403 _len2 = _len - 22;
404 skb_copy_from_linear_data(skb, msghead, 22);
405 skb_copy_to_linear_data_offset(skb, _len2,
406 msghead, 22);
407 skb_pull(skb, _len2);
408 CAPIMSG_SETLEN(skb->data, 22);
409 retval = capilib_data_b3_req(&cinfo->ncci_head,
410 CAPIMSG_APPID(skb->data),
411 CAPIMSG_NCCI(skb->data),
412 CAPIMSG_MSGID(skb->data));
414 break;
415 case CAPI_LISTEN_REQ:
416 if (hycapi_applications[appl_id - 1].listen_req[ctrl->cnr - 1])
418 kfree_skb(hycapi_applications[appl_id - 1].listen_req[ctrl->cnr - 1]);
419 hycapi_applications[appl_id - 1].listen_req[ctrl->cnr - 1] = NULL;
421 if (!(hycapi_applications[appl_id -1].listen_req[ctrl->cnr - 1] = skb_copy(skb, GFP_ATOMIC)))
423 printk(KERN_ERR "HYSDN: memory squeeze in private_listen\n");
425 break;
426 default:
427 break;
429 out:
430 if (retval == CAPI_NOERROR)
431 hycapi_sendmsg_internal(ctrl, skb);
432 else
433 dev_kfree_skb_any(skb);
435 return retval;
438 static int hycapi_proc_show(struct seq_file *m, void *v)
440 struct capi_ctr *ctrl = m->private;
441 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
442 hysdn_card *card = cinfo->card;
443 char *s;
445 seq_printf(m, "%-16s %s\n", "name", cinfo->cardname);
446 seq_printf(m, "%-16s 0x%x\n", "io", card->iobase);
447 seq_printf(m, "%-16s %d\n", "irq", card->irq);
449 switch (card->brdtype) {
450 case BD_PCCARD: s = "HYSDN Hycard"; break;
451 case BD_ERGO: s = "HYSDN Ergo2"; break;
452 case BD_METRO: s = "HYSDN Metro4"; break;
453 case BD_CHAMP2: s = "HYSDN Champ2"; break;
454 case BD_PLEXUS: s = "HYSDN Plexus30"; break;
455 default: s = "???"; break;
457 seq_printf(m, "%-16s %s\n", "type", s);
458 if ((s = cinfo->version[VER_DRIVER]) != NULL)
459 seq_printf(m, "%-16s %s\n", "ver_driver", s);
460 if ((s = cinfo->version[VER_CARDTYPE]) != NULL)
461 seq_printf(m, "%-16s %s\n", "ver_cardtype", s);
462 if ((s = cinfo->version[VER_SERIAL]) != NULL)
463 seq_printf(m, "%-16s %s\n", "ver_serial", s);
465 seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname);
467 return 0;
470 /**************************************************************
471 hycapi_load_firmware
473 This does NOT load any firmware, but the callback somehow is needed
474 on capi-interface registration.
476 **************************************************************/
478 static int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
480 #ifdef HYCAPI_PRINTFNAMES
481 printk(KERN_NOTICE "hycapi_load_firmware\n");
482 #endif
483 return 0;
487 static char *hycapi_procinfo(struct capi_ctr *ctrl)
489 hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
490 #ifdef HYCAPI_PRINTFNAMES
491 printk(KERN_NOTICE "%s\n", __func__);
492 #endif
493 if (!cinfo)
494 return "";
495 sprintf(cinfo->infobuf, "%s %s 0x%x %d %s",
496 cinfo->cardname[0] ? cinfo->cardname : "-",
497 cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
498 cinfo->card ? cinfo->card->iobase : 0x0,
499 cinfo->card ? cinfo->card->irq : 0,
500 hycapi_revision
502 return cinfo->infobuf;
505 /******************************************************************
506 hycapi_rx_capipkt
508 Receive a capi-message.
510 All B3_DATA_IND are converted to 64K-extension compatible format.
511 New nccis are created if necessary.
512 *******************************************************************/
514 void
515 hycapi_rx_capipkt(hysdn_card *card, unsigned char *buf, unsigned short len)
517 struct sk_buff *skb;
518 hycapictrl_info *cinfo = card->hyctrlinfo;
519 struct capi_ctr *ctrl;
520 __u16 ApplId;
521 __u16 MsgLen, info;
522 __u16 len2, CapiCmd;
523 __u32 CP64[2] = {0, 0};
524 #ifdef HYCAPI_PRINTFNAMES
525 printk(KERN_NOTICE "hycapi_rx_capipkt\n");
526 #endif
527 if (!cinfo) {
528 return;
530 ctrl = &cinfo->capi_ctrl;
531 if (len < CAPI_MSG_BASELEN) {
532 printk(KERN_ERR "HYSDN Card%d: invalid CAPI-message, length %d!\n",
533 card->myid, len);
534 return;
536 MsgLen = CAPIMSG_LEN(buf);
537 ApplId = CAPIMSG_APPID(buf);
538 CapiCmd = CAPIMSG_CMD(buf);
540 if ((CapiCmd == CAPI_DATA_B3_IND) && (MsgLen < 30)) {
541 len2 = len + (30 - MsgLen);
542 if (!(skb = alloc_skb(len2, GFP_ATOMIC))) {
543 printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n",
544 card->myid);
545 return;
547 skb_put_data(skb, buf, MsgLen);
548 skb_put_data(skb, CP64, 2 * sizeof(__u32));
549 skb_put_data(skb, buf + MsgLen, len - MsgLen);
550 CAPIMSG_SETLEN(skb->data, 30);
551 } else {
552 if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
553 printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n",
554 card->myid);
555 return;
557 skb_put_data(skb, buf, len);
559 switch (CAPIMSG_CMD(skb->data))
561 case CAPI_CONNECT_B3_CONF:
562 /* Check info-field for error-indication: */
563 info = CAPIMSG_U16(skb->data, 12);
564 switch (info)
566 case 0:
567 capilib_new_ncci(&cinfo->ncci_head, ApplId, CAPIMSG_NCCI(skb->data),
568 hycapi_applications[ApplId - 1].rp.datablkcnt);
570 break;
571 case 0x0001:
572 printk(KERN_ERR "HYSDN Card%d: NCPI not supported by current "
573 "protocol. NCPI ignored.\n", card->myid);
574 break;
575 case 0x2001:
576 printk(KERN_ERR "HYSDN Card%d: Message not supported in"
577 " current state\n", card->myid);
578 break;
579 case 0x2002:
580 printk(KERN_ERR "HYSDN Card%d: invalid PLCI\n", card->myid);
581 break;
582 case 0x2004:
583 printk(KERN_ERR "HYSDN Card%d: out of NCCI\n", card->myid);
584 break;
585 case 0x3008:
586 printk(KERN_ERR "HYSDN Card%d: NCPI not supported\n",
587 card->myid);
588 break;
589 default:
590 printk(KERN_ERR "HYSDN Card%d: Info in CONNECT_B3_CONF: %d\n",
591 card->myid, info);
592 break;
594 break;
595 case CAPI_CONNECT_B3_IND:
596 capilib_new_ncci(&cinfo->ncci_head, ApplId,
597 CAPIMSG_NCCI(skb->data),
598 hycapi_applications[ApplId - 1].rp.datablkcnt);
599 break;
600 case CAPI_DATA_B3_CONF:
601 capilib_data_b3_conf(&cinfo->ncci_head, ApplId,
602 CAPIMSG_NCCI(skb->data),
603 CAPIMSG_MSGID(skb->data));
604 break;
605 default:
606 break;
608 capi_ctr_handle_message(ctrl, ApplId, skb);
611 /******************************************************************
612 hycapi_tx_capiack
614 Internally acknowledge a msg sent. This will remove the msg from the
615 internal queue.
617 *******************************************************************/
619 void hycapi_tx_capiack(hysdn_card *card)
621 hycapictrl_info *cinfo = card->hyctrlinfo;
622 #ifdef HYCAPI_PRINTFNAMES
623 printk(KERN_NOTICE "hycapi_tx_capiack\n");
624 #endif
625 if (!cinfo) {
626 return;
628 spin_lock_irq(&cinfo->lock);
629 kfree_skb(cinfo->skbs[cinfo->out_idx]); /* free skb */
630 cinfo->skbs[cinfo->out_idx++] = NULL;
631 if (cinfo->out_idx >= HYSDN_MAX_CAPI_SKB)
632 cinfo->out_idx = 0; /* wrap around */
634 if (cinfo->sk_count-- == HYSDN_MAX_CAPI_SKB) /* dec usage count */
635 capi_ctr_resume_output(&cinfo->capi_ctrl);
636 spin_unlock_irq(&cinfo->lock);
639 /***************************************************************
640 hycapi_tx_capiget(hysdn_card *card)
642 This is called when polling for messages to SEND.
644 ****************************************************************/
646 struct sk_buff *
647 hycapi_tx_capiget(hysdn_card *card)
649 hycapictrl_info *cinfo = card->hyctrlinfo;
650 if (!cinfo) {
651 return (struct sk_buff *)NULL;
653 if (!cinfo->sk_count)
654 return (struct sk_buff *)NULL; /* nothing available */
656 return (cinfo->skbs[cinfo->out_idx]); /* next packet to send */
660 /**********************************************************
661 int hycapi_init()
663 attach the capi-driver to the kernel-capi.
665 ***********************************************************/
667 int hycapi_init(void)
669 int i;
670 for (i = 0; i < CAPI_MAXAPPL; i++) {
671 memset(&(hycapi_applications[i]), 0, sizeof(hycapi_appl));
673 return (0);
676 /**************************************************************
677 hycapi_cleanup(void)
679 detach the capi-driver to the kernel-capi. Actually this should
680 free some more ressources. Do that later.
681 **************************************************************/
683 void
684 hycapi_cleanup(void)
688 /********************************************************************
689 hycapi_capi_create(hysdn_card *card)
691 Attach the card with its capi-ctrl.
692 *********************************************************************/
694 static void hycapi_fill_profile(hysdn_card *card)
696 hycapictrl_info *cinfo = NULL;
697 struct capi_ctr *ctrl = NULL;
698 cinfo = card->hyctrlinfo;
699 if (!cinfo) return;
700 ctrl = &cinfo->capi_ctrl;
701 strcpy(ctrl->manu, "Hypercope");
702 ctrl->version.majorversion = 2;
703 ctrl->version.minorversion = 0;
704 ctrl->version.majormanuversion = 3;
705 ctrl->version.minormanuversion = 2;
706 ctrl->profile.ncontroller = card->myid;
707 ctrl->profile.nbchannel = card->bchans;
708 ctrl->profile.goptions = GLOBAL_OPTION_INTERNAL_CONTROLLER |
709 GLOBAL_OPTION_B_CHANNEL_OPERATION;
710 ctrl->profile.support1 = B1_PROT_64KBIT_HDLC |
711 (card->faxchans ? B1_PROT_T30 : 0) |
712 B1_PROT_64KBIT_TRANSPARENT;
713 ctrl->profile.support2 = B2_PROT_ISO7776 |
714 (card->faxchans ? B2_PROT_T30 : 0) |
715 B2_PROT_TRANSPARENT;
716 ctrl->profile.support3 = B3_PROT_TRANSPARENT |
717 B3_PROT_T90NL |
718 (card->faxchans ? B3_PROT_T30 : 0) |
719 (card->faxchans ? B3_PROT_T30EXT : 0) |
720 B3_PROT_ISO8208;
724 hycapi_capi_create(hysdn_card *card)
726 hycapictrl_info *cinfo = NULL;
727 struct capi_ctr *ctrl = NULL;
728 int retval;
729 #ifdef HYCAPI_PRINTFNAMES
730 printk(KERN_NOTICE "hycapi_capi_create\n");
731 #endif
732 if ((hycapi_enable & (1 << card->myid)) == 0) {
733 return 1;
735 if (!card->hyctrlinfo) {
736 cinfo = kzalloc(sizeof(hycapictrl_info), GFP_ATOMIC);
737 if (!cinfo) {
738 printk(KERN_WARNING "HYSDN: no memory for capi-ctrl.\n");
739 return -ENOMEM;
741 card->hyctrlinfo = cinfo;
742 cinfo->card = card;
743 spin_lock_init(&cinfo->lock);
744 INIT_LIST_HEAD(&cinfo->ncci_head);
746 switch (card->brdtype) {
747 case BD_PCCARD: strcpy(cinfo->cardname, "HYSDN Hycard"); break;
748 case BD_ERGO: strcpy(cinfo->cardname, "HYSDN Ergo2"); break;
749 case BD_METRO: strcpy(cinfo->cardname, "HYSDN Metro4"); break;
750 case BD_CHAMP2: strcpy(cinfo->cardname, "HYSDN Champ2"); break;
751 case BD_PLEXUS: strcpy(cinfo->cardname, "HYSDN Plexus30"); break;
752 default: strcpy(cinfo->cardname, "HYSDN ???"); break;
755 ctrl = &cinfo->capi_ctrl;
756 ctrl->driver_name = "hycapi";
757 ctrl->driverdata = cinfo;
758 ctrl->register_appl = hycapi_register_appl;
759 ctrl->release_appl = hycapi_release_appl;
760 ctrl->send_message = hycapi_send_message;
761 ctrl->load_firmware = hycapi_load_firmware;
762 ctrl->reset_ctr = hycapi_reset_ctr;
763 ctrl->procinfo = hycapi_procinfo;
764 ctrl->proc_show = hycapi_proc_show;
765 strcpy(ctrl->name, cinfo->cardname);
766 ctrl->owner = THIS_MODULE;
768 retval = attach_capi_ctr(ctrl);
769 if (retval) {
770 printk(KERN_ERR "hycapi: attach controller failed.\n");
771 return -EBUSY;
773 /* fill in the blanks: */
774 hycapi_fill_profile(card);
775 capi_ctr_ready(ctrl);
776 } else {
777 /* resume output on stopped ctrl */
778 ctrl = &card->hyctrlinfo->capi_ctrl;
779 hycapi_fill_profile(card);
780 capi_ctr_ready(ctrl);
781 hycapi_restart_internal(ctrl);
782 /* ctrl->resume_output(ctrl); */
784 return 0;