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