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