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