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