Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: kcapi.c,v 1.1.2.8 2004/03/26 19:57:20 armin Exp $ |
| 2 | * |
| 3 | * Kernel CAPI 2.0 Module |
| 4 | * |
| 5 | * Copyright 1999 by Carsten Paeth <calle@calle.de> |
| 6 | * Copyright 2002 by Kai Germaschewski <kai@germaschewski.name> |
| 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 | |
Robert P. J. Day | 37772ac | 2008-04-28 02:14:42 -0700 | [diff] [blame] | 13 | #define AVMB1_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include "kcapi.h" |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/mm.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/ioport.h> |
| 20 | #include <linux/proc_fs.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 21 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/seq_file.h> |
| 23 | #include <linux/skbuff.h> |
| 24 | #include <linux/workqueue.h> |
| 25 | #include <linux/capi.h> |
| 26 | #include <linux/kernelcapi.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/moduleparam.h> |
| 29 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/uaccess.h> |
| 32 | #include <linux/isdn/capicmd.h> |
| 33 | #include <linux/isdn/capiutil.h> |
Robert P. J. Day | 37772ac | 2008-04-28 02:14:42 -0700 | [diff] [blame] | 34 | #ifdef AVMB1_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/b1lli.h> |
| 36 | #endif |
Arjan van de Ven | 9cdf182 | 2006-03-23 03:00:21 -0800 | [diff] [blame] | 37 | #include <linux/mutex.h> |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 38 | #include <linux/rcupdate.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static int showcapimsgs = 0; |
| 41 | |
| 42 | MODULE_DESCRIPTION("CAPI4Linux: kernel CAPI layer"); |
| 43 | MODULE_AUTHOR("Carsten Paeth"); |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | module_param(showcapimsgs, uint, 0); |
| 46 | |
| 47 | /* ------------------------------------------------------------- */ |
| 48 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 49 | struct capictr_event { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | struct work_struct work; |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 51 | unsigned int type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | u32 controller; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | /* ------------------------------------------------------------- */ |
| 56 | |
| 57 | static struct capi_version driver_version = {2, 0, 1, 1<<4}; |
| 58 | static char driver_serial[CAPI_SERIAL_LEN] = "0004711"; |
| 59 | static char capi_manufakturer[64] = "AVM Berlin"; |
| 60 | |
| 61 | #define NCCI2CTRL(ncci) (((ncci) >> 24) & 0x7f) |
| 62 | |
| 63 | LIST_HEAD(capi_drivers); |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 64 | DEFINE_MUTEX(capi_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 66 | struct capi_ctr *capi_controller[CAPI_MAXCONTR]; |
| 67 | DEFINE_MUTEX(capi_controller_lock); |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | struct capi20_appl *capi_applications[CAPI_MAXAPPL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 71 | static int ncontrollers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 73 | static BLOCKING_NOTIFIER_HEAD(ctr_notifier_list); |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | /* -------- controller ref counting -------------------------------------- */ |
| 76 | |
| 77 | static inline struct capi_ctr * |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 78 | capi_ctr_get(struct capi_ctr *ctr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 80 | if (!try_module_get(ctr->owner)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | return NULL; |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 82 | return ctr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static inline void |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 86 | capi_ctr_put(struct capi_ctr *ctr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 88 | module_put(ctr->owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* ------------------------------------------------------------- */ |
| 92 | |
| 93 | static inline struct capi_ctr *get_capi_ctr_by_nr(u16 contr) |
| 94 | { |
| 95 | if (contr - 1 >= CAPI_MAXCONTR) |
| 96 | return NULL; |
| 97 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 98 | return capi_controller[contr - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static inline struct capi20_appl *get_capi_appl_by_nr(u16 applid) |
| 102 | { |
| 103 | if (applid - 1 >= CAPI_MAXAPPL) |
| 104 | return NULL; |
| 105 | |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 106 | return rcu_dereference(capi_applications[applid - 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* -------- util functions ------------------------------------ */ |
| 110 | |
| 111 | static inline int capi_cmd_valid(u8 cmd) |
| 112 | { |
| 113 | switch (cmd) { |
| 114 | case CAPI_ALERT: |
| 115 | case CAPI_CONNECT: |
| 116 | case CAPI_CONNECT_ACTIVE: |
| 117 | case CAPI_CONNECT_B3_ACTIVE: |
| 118 | case CAPI_CONNECT_B3: |
| 119 | case CAPI_CONNECT_B3_T90_ACTIVE: |
| 120 | case CAPI_DATA_B3: |
| 121 | case CAPI_DISCONNECT_B3: |
| 122 | case CAPI_DISCONNECT: |
| 123 | case CAPI_FACILITY: |
| 124 | case CAPI_INFO: |
| 125 | case CAPI_LISTEN: |
| 126 | case CAPI_MANUFACTURER: |
| 127 | case CAPI_RESET_B3: |
| 128 | case CAPI_SELECT_B_PROTOCOL: |
| 129 | return 1; |
| 130 | } |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | static inline int capi_subcmd_valid(u8 subcmd) |
| 135 | { |
| 136 | switch (subcmd) { |
| 137 | case CAPI_REQ: |
| 138 | case CAPI_CONF: |
| 139 | case CAPI_IND: |
| 140 | case CAPI_RESP: |
| 141 | return 1; |
| 142 | } |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | /* ------------------------------------------------------------ */ |
| 147 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 148 | static void |
| 149 | register_appl(struct capi_ctr *ctr, u16 applid, capi_register_params *rparam) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 151 | ctr = capi_ctr_get(ctr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 153 | if (ctr) |
| 154 | ctr->register_appl(ctr, applid, rparam); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | else |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 156 | printk(KERN_WARNING "%s: cannot get controller resources\n", |
| 157 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 161 | static void release_appl(struct capi_ctr *ctr, u16 applid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
| 163 | DBG("applid %#x", applid); |
| 164 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 165 | ctr->release_appl(ctr, applid); |
| 166 | capi_ctr_put(ctr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | static void notify_up(u32 contr) |
| 170 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | struct capi20_appl *ap; |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 172 | struct capi_ctr *ctr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | u16 applid; |
| 174 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 175 | mutex_lock(&capi_controller_lock); |
| 176 | |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 177 | if (showcapimsgs & 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | printk(KERN_DEBUG "kcapi: notify up contr %d\n", contr); |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 179 | |
| 180 | ctr = get_capi_ctr_by_nr(contr); |
| 181 | if (ctr) { |
| 182 | if (ctr->state == CAPI_CTR_RUNNING) |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 183 | goto unlock_out; |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 184 | |
| 185 | ctr->state = CAPI_CTR_RUNNING; |
| 186 | |
| 187 | for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { |
| 188 | ap = get_capi_appl_by_nr(applid); |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 189 | if (!ap) |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 190 | continue; |
| 191 | register_appl(ctr, applid, &ap->rparam); |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 192 | } |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 193 | |
| 194 | wake_up_interruptible_all(&ctr->state_wait_queue); |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 195 | } else |
Harvey Harrison | 156f1ed | 2008-04-28 02:14:40 -0700 | [diff] [blame] | 196 | printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 197 | |
| 198 | unlock_out: |
| 199 | mutex_unlock(&capi_controller_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 202 | static void ctr_down(struct capi_ctr *ctr, int new_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
| 204 | struct capi20_appl *ap; |
| 205 | u16 applid; |
| 206 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 207 | if (ctr->state == CAPI_CTR_DETECTED || ctr->state == CAPI_CTR_DETACHED) |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 208 | return; |
| 209 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 210 | ctr->state = new_state; |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 211 | |
| 212 | memset(ctr->manu, 0, sizeof(ctr->manu)); |
| 213 | memset(&ctr->version, 0, sizeof(ctr->version)); |
| 214 | memset(&ctr->profile, 0, sizeof(ctr->profile)); |
| 215 | memset(ctr->serial, 0, sizeof(ctr->serial)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { |
| 218 | ap = get_capi_appl_by_nr(applid); |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 219 | if (ap) |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 220 | capi_ctr_put(ctr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 222 | |
| 223 | wake_up_interruptible_all(&ctr->state_wait_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 226 | static void notify_down(u32 contr) |
| 227 | { |
| 228 | struct capi_ctr *ctr; |
| 229 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 230 | mutex_lock(&capi_controller_lock); |
| 231 | |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 232 | if (showcapimsgs & 1) |
| 233 | printk(KERN_DEBUG "kcapi: notify down contr %d\n", contr); |
| 234 | |
| 235 | ctr = get_capi_ctr_by_nr(contr); |
| 236 | if (ctr) |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 237 | ctr_down(ctr, CAPI_CTR_DETECTED); |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 238 | else |
| 239 | printk(KERN_WARNING "%s: invalid contr %d\n", __func__, contr); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 240 | |
| 241 | mutex_unlock(&capi_controller_lock); |
Jan Kiszka | 3efecf7 | 2010-02-08 10:12:12 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 244 | static int |
| 245 | notify_handler(struct notifier_block *nb, unsigned long val, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 247 | u32 contr = (long)v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 249 | switch (val) { |
| 250 | case CAPICTR_UP: |
| 251 | notify_up(contr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | break; |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 253 | case CAPICTR_DOWN: |
| 254 | notify_down(contr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | break; |
| 256 | } |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 257 | return NOTIFY_OK; |
| 258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 260 | static void do_notify_work(struct work_struct *work) |
| 261 | { |
| 262 | struct capictr_event *event = |
| 263 | container_of(work, struct capictr_event, work); |
| 264 | |
| 265 | blocking_notifier_call_chain(&ctr_notifier_list, event->type, |
| 266 | (void *)(long)event->controller); |
| 267 | kfree(event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /* |
| 271 | * The notifier will result in adding/deleteing of devices. Devices can |
| 272 | * only removed in user process, not in bh. |
| 273 | */ |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 274 | static int notify_push(unsigned int event_type, u32 controller) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | { |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 276 | struct capictr_event *event = kmalloc(sizeof(*event), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 278 | if (!event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | return -ENOMEM; |
| 280 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 281 | INIT_WORK(&event->work, do_notify_work); |
| 282 | event->type = event_type; |
| 283 | event->controller = controller; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 285 | schedule_work(&event->work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | return 0; |
| 287 | } |
| 288 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 289 | int register_capictr_notifier(struct notifier_block *nb) |
| 290 | { |
| 291 | return blocking_notifier_chain_register(&ctr_notifier_list, nb); |
| 292 | } |
| 293 | EXPORT_SYMBOL_GPL(register_capictr_notifier); |
| 294 | |
| 295 | int unregister_capictr_notifier(struct notifier_block *nb) |
| 296 | { |
| 297 | return blocking_notifier_chain_unregister(&ctr_notifier_list, nb); |
| 298 | } |
| 299 | EXPORT_SYMBOL_GPL(unregister_capictr_notifier); |
| 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /* -------- Receiver ------------------------------------------ */ |
| 302 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 303 | static void recv_handler(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
| 305 | struct sk_buff *skb; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 306 | struct capi20_appl *ap = |
| 307 | container_of(work, struct capi20_appl, recv_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | if ((!ap) || (ap->release_in_progress)) |
| 310 | return; |
| 311 | |
Matthias Kaehlcke | 67837f2 | 2007-07-17 04:04:16 -0700 | [diff] [blame] | 312 | mutex_lock(&ap->recv_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | while ((skb = skb_dequeue(&ap->recv_queue))) { |
| 314 | if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_IND) |
| 315 | ap->nrecvdatapkt++; |
| 316 | else |
| 317 | ap->nrecvctlpkt++; |
| 318 | |
| 319 | ap->recv_message(ap, skb); |
| 320 | } |
Matthias Kaehlcke | 67837f2 | 2007-07-17 04:04:16 -0700 | [diff] [blame] | 321 | mutex_unlock(&ap->recv_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 324 | /** |
| 325 | * capi_ctr_handle_message() - handle incoming CAPI message |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 326 | * @ctr: controller descriptor structure. |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 327 | * @appl: application ID. |
| 328 | * @skb: message. |
| 329 | * |
| 330 | * Called by hardware driver to pass a CAPI message to the application. |
| 331 | */ |
| 332 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 333 | void capi_ctr_handle_message(struct capi_ctr *ctr, u16 appl, |
| 334 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
| 336 | struct capi20_appl *ap; |
| 337 | int showctl = 0; |
| 338 | u8 cmd, subcmd; |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 339 | _cdebbuf *cdb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 341 | if (ctr->state != CAPI_CTR_RUNNING) { |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 342 | cdb = capi_message2str(skb->data); |
| 343 | if (cdb) { |
| 344 | printk(KERN_INFO "kcapi: controller [%03d] not active, got: %s", |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 345 | ctr->cnr, cdb->buf); |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 346 | cdebbuf_free(cdb); |
| 347 | } else |
| 348 | printk(KERN_INFO "kcapi: controller [%03d] not active, cannot trace\n", |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 349 | ctr->cnr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | goto error; |
| 351 | } |
| 352 | |
| 353 | cmd = CAPIMSG_COMMAND(skb->data); |
| 354 | subcmd = CAPIMSG_SUBCOMMAND(skb->data); |
| 355 | if (cmd == CAPI_DATA_B3 && subcmd == CAPI_IND) { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 356 | ctr->nrecvdatapkt++; |
| 357 | if (ctr->traceflag > 2) |
| 358 | showctl |= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } else { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 360 | ctr->nrecvctlpkt++; |
| 361 | if (ctr->traceflag) |
| 362 | showctl |= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 364 | showctl |= (ctr->traceflag & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if (showctl & 2) { |
| 366 | if (showctl & 1) { |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 367 | printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u\n", |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 368 | ctr->cnr, CAPIMSG_APPID(skb->data), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | capi_cmd2str(cmd, subcmd), |
| 370 | CAPIMSG_LEN(skb->data)); |
| 371 | } else { |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 372 | cdb = capi_message2str(skb->data); |
| 373 | if (cdb) { |
| 374 | printk(KERN_DEBUG "kcapi: got [%03d] %s\n", |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 375 | ctr->cnr, cdb->buf); |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 376 | cdebbuf_free(cdb); |
| 377 | } else |
| 378 | printk(KERN_DEBUG "kcapi: got [%03d] id#%d %s len=%u, cannot trace\n", |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 379 | ctr->cnr, CAPIMSG_APPID(skb->data), |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 380 | capi_cmd2str(cmd, subcmd), |
| 381 | CAPIMSG_LEN(skb->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | } |
| 385 | |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 386 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | ap = get_capi_appl_by_nr(CAPIMSG_APPID(skb->data)); |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 388 | if (!ap) { |
| 389 | rcu_read_unlock(); |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 390 | cdb = capi_message2str(skb->data); |
| 391 | if (cdb) { |
| 392 | printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s)\n", |
| 393 | CAPIMSG_APPID(skb->data), cdb->buf); |
| 394 | cdebbuf_free(cdb); |
| 395 | } else |
| 396 | printk(KERN_ERR "kcapi: handle_message: applid %d state released (%s) cannot trace\n", |
| 397 | CAPIMSG_APPID(skb->data), |
| 398 | capi_cmd2str(cmd, subcmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | goto error; |
| 400 | } |
| 401 | skb_queue_tail(&ap->recv_queue, skb); |
| 402 | schedule_work(&ap->recv_work); |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 403 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | return; |
| 406 | |
| 407 | error: |
| 408 | kfree_skb(skb); |
| 409 | } |
| 410 | |
| 411 | EXPORT_SYMBOL(capi_ctr_handle_message); |
| 412 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 413 | /** |
| 414 | * capi_ctr_ready() - signal CAPI controller ready |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 415 | * @ctr: controller descriptor structure. |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 416 | * |
| 417 | * Called by hardware driver to signal that the controller is up and running. |
| 418 | */ |
| 419 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 420 | void capi_ctr_ready(struct capi_ctr *ctr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 422 | printk(KERN_NOTICE "kcapi: controller [%03d] \"%s\" ready.\n", |
| 423 | ctr->cnr, ctr->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 425 | notify_push(CAPICTR_UP, ctr->cnr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | EXPORT_SYMBOL(capi_ctr_ready); |
| 429 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 430 | /** |
Tilman Schmidt | 4e32997 | 2009-06-07 09:09:23 +0000 | [diff] [blame] | 431 | * capi_ctr_down() - signal CAPI controller not ready |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 432 | * @ctr: controller descriptor structure. |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 433 | * |
| 434 | * Called by hardware driver to signal that the controller is down and |
| 435 | * unavailable for use. |
| 436 | */ |
| 437 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 438 | void capi_ctr_down(struct capi_ctr *ctr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 440 | printk(KERN_NOTICE "kcapi: controller [%03d] down.\n", ctr->cnr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 442 | notify_push(CAPICTR_DOWN, ctr->cnr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Tilman Schmidt | 4e32997 | 2009-06-07 09:09:23 +0000 | [diff] [blame] | 445 | EXPORT_SYMBOL(capi_ctr_down); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 447 | /** |
| 448 | * capi_ctr_suspend_output() - suspend controller |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 449 | * @ctr: controller descriptor structure. |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 450 | * |
| 451 | * Called by hardware driver to stop data flow. |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 452 | * |
| 453 | * Note: The caller is responsible for synchronizing concurrent state changes |
| 454 | * as well as invocations of capi_ctr_handle_message. |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 455 | */ |
| 456 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 457 | void capi_ctr_suspend_output(struct capi_ctr *ctr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 459 | if (!ctr->blocked) { |
| 460 | printk(KERN_DEBUG "kcapi: controller [%03d] suspend\n", |
| 461 | ctr->cnr); |
| 462 | ctr->blocked = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
| 466 | EXPORT_SYMBOL(capi_ctr_suspend_output); |
| 467 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 468 | /** |
| 469 | * capi_ctr_resume_output() - resume controller |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 470 | * @ctr: controller descriptor structure. |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 471 | * |
| 472 | * Called by hardware driver to resume data flow. |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 473 | * |
| 474 | * Note: The caller is responsible for synchronizing concurrent state changes |
| 475 | * as well as invocations of capi_ctr_handle_message. |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 476 | */ |
| 477 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 478 | void capi_ctr_resume_output(struct capi_ctr *ctr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 480 | if (ctr->blocked) { |
| 481 | printk(KERN_DEBUG "kcapi: controller [%03d] resumed\n", |
| 482 | ctr->cnr); |
| 483 | ctr->blocked = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
| 487 | EXPORT_SYMBOL(capi_ctr_resume_output); |
| 488 | |
| 489 | /* ------------------------------------------------------------- */ |
| 490 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 491 | /** |
| 492 | * attach_capi_ctr() - register CAPI controller |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 493 | * @ctr: controller descriptor structure. |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 494 | * |
| 495 | * Called by hardware driver to register a controller with the CAPI subsystem. |
| 496 | * Return value: 0 on success, error code < 0 on error |
| 497 | */ |
| 498 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 499 | int attach_capi_ctr(struct capi_ctr *ctr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
| 501 | int i; |
| 502 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 503 | mutex_lock(&capi_controller_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
| 505 | for (i = 0; i < CAPI_MAXCONTR; i++) { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 506 | if (!capi_controller[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | break; |
| 508 | } |
| 509 | if (i == CAPI_MAXCONTR) { |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 510 | mutex_unlock(&capi_controller_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | printk(KERN_ERR "kcapi: out of controller slots\n"); |
| 512 | return -EBUSY; |
| 513 | } |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 514 | capi_controller[i] = ctr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 516 | ctr->nrecvctlpkt = 0; |
| 517 | ctr->nrecvdatapkt = 0; |
| 518 | ctr->nsentctlpkt = 0; |
| 519 | ctr->nsentdatapkt = 0; |
| 520 | ctr->cnr = i + 1; |
| 521 | ctr->state = CAPI_CTR_DETECTED; |
| 522 | ctr->blocked = 0; |
| 523 | ctr->traceflag = showcapimsgs; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 524 | init_waitqueue_head(&ctr->state_wait_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 526 | sprintf(ctr->procfn, "capi/controllers/%d", ctr->cnr); |
| 527 | ctr->procent = proc_create_data(ctr->procfn, 0, NULL, ctr->proc_fops, ctr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 529 | ncontrollers++; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 530 | |
| 531 | mutex_unlock(&capi_controller_lock); |
| 532 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 533 | printk(KERN_NOTICE "kcapi: controller [%03d]: %s attached\n", |
| 534 | ctr->cnr, ctr->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | EXPORT_SYMBOL(attach_capi_ctr); |
| 539 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 540 | /** |
| 541 | * detach_capi_ctr() - unregister CAPI controller |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 542 | * @ctr: controller descriptor structure. |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 543 | * |
| 544 | * Called by hardware driver to remove the registration of a controller |
| 545 | * with the CAPI subsystem. |
| 546 | * Return value: 0 on success, error code < 0 on error |
| 547 | */ |
| 548 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 549 | int detach_capi_ctr(struct capi_ctr *ctr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 551 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 553 | mutex_lock(&capi_controller_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 555 | ctr_down(ctr, CAPI_CTR_DETACHED); |
| 556 | |
| 557 | if (capi_controller[ctr->cnr - 1] != ctr) { |
| 558 | err = -EINVAL; |
| 559 | goto unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | } |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 561 | capi_controller[ctr->cnr - 1] = NULL; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 562 | ncontrollers--; |
| 563 | |
| 564 | if (ctr->procent) |
| 565 | remove_proc_entry(ctr->procfn, NULL); |
| 566 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 567 | printk(KERN_NOTICE "kcapi: controller [%03d]: %s unregistered\n", |
| 568 | ctr->cnr, ctr->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 570 | unlock_out: |
| 571 | mutex_unlock(&capi_controller_lock); |
| 572 | |
| 573 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | EXPORT_SYMBOL(detach_capi_ctr); |
| 577 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 578 | /** |
| 579 | * register_capi_driver() - register CAPI driver |
| 580 | * @driver: driver descriptor structure. |
| 581 | * |
| 582 | * Called by hardware driver to register itself with the CAPI subsystem. |
| 583 | */ |
| 584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | void register_capi_driver(struct capi_driver *driver) |
| 586 | { |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 587 | mutex_lock(&capi_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | list_add_tail(&driver->list, &capi_drivers); |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 589 | mutex_unlock(&capi_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | EXPORT_SYMBOL(register_capi_driver); |
| 593 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 594 | /** |
| 595 | * unregister_capi_driver() - unregister CAPI driver |
| 596 | * @driver: driver descriptor structure. |
| 597 | * |
| 598 | * Called by hardware driver to unregister itself from the CAPI subsystem. |
| 599 | */ |
| 600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | void unregister_capi_driver(struct capi_driver *driver) |
| 602 | { |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 603 | mutex_lock(&capi_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | list_del(&driver->list); |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 605 | mutex_unlock(&capi_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | EXPORT_SYMBOL(unregister_capi_driver); |
| 609 | |
| 610 | /* ------------------------------------------------------------- */ |
| 611 | /* -------- CAPI2.0 Interface ---------------------------------- */ |
| 612 | /* ------------------------------------------------------------- */ |
| 613 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 614 | /** |
| 615 | * capi20_isinstalled() - CAPI 2.0 operation CAPI_INSTALLED |
| 616 | * |
| 617 | * Return value: CAPI result code (CAPI_NOERROR if at least one ISDN controller |
| 618 | * is ready for use, CAPI_REGNOTINSTALLED otherwise) |
| 619 | */ |
| 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | u16 capi20_isinstalled(void) |
| 622 | { |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 623 | u16 ret = CAPI_REGNOTINSTALLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | int i; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 625 | |
| 626 | mutex_lock(&capi_controller_lock); |
| 627 | |
| 628 | for (i = 0; i < CAPI_MAXCONTR; i++) |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 629 | if (capi_controller[i] && |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 630 | capi_controller[i]->state == CAPI_CTR_RUNNING) { |
| 631 | ret = CAPI_NOERROR; |
| 632 | break; |
| 633 | } |
| 634 | |
| 635 | mutex_unlock(&capi_controller_lock); |
| 636 | |
| 637 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | EXPORT_SYMBOL(capi20_isinstalled); |
| 641 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 642 | /** |
| 643 | * capi20_register() - CAPI 2.0 operation CAPI_REGISTER |
| 644 | * @ap: CAPI application descriptor structure. |
| 645 | * |
| 646 | * Register an application's presence with CAPI. |
| 647 | * A unique application ID is assigned and stored in @ap->applid. |
| 648 | * After this function returns successfully, the message receive |
| 649 | * callback function @ap->recv_message() may be called at any time |
| 650 | * until capi20_release() has been called for the same @ap. |
| 651 | * Return value: CAPI result code |
| 652 | */ |
| 653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | u16 capi20_register(struct capi20_appl *ap) |
| 655 | { |
| 656 | int i; |
| 657 | u16 applid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
| 659 | DBG(""); |
| 660 | |
| 661 | if (ap->rparam.datablklen < 128) |
| 662 | return CAPI_LOGBLKSIZETOSMALL; |
| 663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | ap->nrecvctlpkt = 0; |
| 665 | ap->nrecvdatapkt = 0; |
| 666 | ap->nsentctlpkt = 0; |
| 667 | ap->nsentdatapkt = 0; |
Matthias Kaehlcke | 67837f2 | 2007-07-17 04:04:16 -0700 | [diff] [blame] | 668 | mutex_init(&ap->recv_mtx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | skb_queue_head_init(&ap->recv_queue); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 670 | INIT_WORK(&ap->recv_work, recv_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | ap->release_in_progress = 0; |
| 672 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 673 | mutex_lock(&capi_controller_lock); |
| 674 | |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 675 | for (applid = 1; applid <= CAPI_MAXAPPL; applid++) { |
| 676 | if (capi_applications[applid - 1] == NULL) |
| 677 | break; |
| 678 | } |
| 679 | if (applid > CAPI_MAXAPPL) { |
| 680 | mutex_unlock(&capi_controller_lock); |
| 681 | return CAPI_TOOMANYAPPLS; |
| 682 | } |
| 683 | |
| 684 | ap->applid = applid; |
| 685 | capi_applications[applid - 1] = ap; |
| 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | for (i = 0; i < CAPI_MAXCONTR; i++) { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 688 | if (!capi_controller[i] || |
| 689 | capi_controller[i]->state != CAPI_CTR_RUNNING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | continue; |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 691 | register_appl(capi_controller[i], applid, &ap->rparam); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 693 | |
| 694 | mutex_unlock(&capi_controller_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
| 696 | if (showcapimsgs & 1) { |
| 697 | printk(KERN_DEBUG "kcapi: appl %d up\n", applid); |
| 698 | } |
| 699 | |
| 700 | return CAPI_NOERROR; |
| 701 | } |
| 702 | |
| 703 | EXPORT_SYMBOL(capi20_register); |
| 704 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 705 | /** |
| 706 | * capi20_release() - CAPI 2.0 operation CAPI_RELEASE |
| 707 | * @ap: CAPI application descriptor structure. |
| 708 | * |
| 709 | * Terminate an application's registration with CAPI. |
| 710 | * After this function returns successfully, the message receive |
| 711 | * callback function @ap->recv_message() will no longer be called. |
| 712 | * Return value: CAPI result code |
| 713 | */ |
| 714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | u16 capi20_release(struct capi20_appl *ap) |
| 716 | { |
| 717 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
| 719 | DBG("applid %#x", ap->applid); |
| 720 | |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 721 | mutex_lock(&capi_controller_lock); |
| 722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | ap->release_in_progress = 1; |
| 724 | capi_applications[ap->applid - 1] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
Jan Kiszka | 88c896e | 2010-02-08 10:12:15 +0000 | [diff] [blame] | 726 | synchronize_rcu(); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | for (i = 0; i < CAPI_MAXCONTR; i++) { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 729 | if (!capi_controller[i] || |
| 730 | capi_controller[i]->state != CAPI_CTR_RUNNING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | continue; |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 732 | release_appl(capi_controller[i], ap->applid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 734 | |
| 735 | mutex_unlock(&capi_controller_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
| 737 | flush_scheduled_work(); |
| 738 | skb_queue_purge(&ap->recv_queue); |
| 739 | |
| 740 | if (showcapimsgs & 1) { |
| 741 | printk(KERN_DEBUG "kcapi: appl %d down\n", ap->applid); |
| 742 | } |
| 743 | |
| 744 | return CAPI_NOERROR; |
| 745 | } |
| 746 | |
| 747 | EXPORT_SYMBOL(capi20_release); |
| 748 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 749 | /** |
| 750 | * capi20_put_message() - CAPI 2.0 operation CAPI_PUT_MESSAGE |
| 751 | * @ap: CAPI application descriptor structure. |
| 752 | * @skb: CAPI message. |
| 753 | * |
| 754 | * Transfer a single message to CAPI. |
| 755 | * Return value: CAPI result code |
| 756 | */ |
| 757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | u16 capi20_put_message(struct capi20_appl *ap, struct sk_buff *skb) |
| 759 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 760 | struct capi_ctr *ctr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | int showctl = 0; |
| 762 | u8 cmd, subcmd; |
| 763 | |
| 764 | DBG("applid %#x", ap->applid); |
| 765 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 766 | if (ncontrollers == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | return CAPI_REGNOTINSTALLED; |
| 768 | if ((ap->applid == 0) || ap->release_in_progress) |
| 769 | return CAPI_ILLAPPNR; |
| 770 | if (skb->len < 12 |
| 771 | || !capi_cmd_valid(CAPIMSG_COMMAND(skb->data)) |
| 772 | || !capi_subcmd_valid(CAPIMSG_SUBCOMMAND(skb->data))) |
| 773 | return CAPI_ILLCMDORSUBCMDORMSGTOSMALL; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 774 | |
| 775 | /* |
| 776 | * The controller reference is protected by the existence of the |
| 777 | * application passed to us. We assume that the caller properly |
| 778 | * synchronizes this service with capi20_release. |
| 779 | */ |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 780 | ctr = get_capi_ctr_by_nr(CAPIMSG_CONTROLLER(skb->data)); |
Jan Kiszka | c6af043 | 2010-02-08 10:12:43 +0000 | [diff] [blame] | 781 | if (!ctr || ctr->state != CAPI_CTR_RUNNING) |
| 782 | return CAPI_REGNOTINSTALLED; |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 783 | if (ctr->blocked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | return CAPI_SENDQUEUEFULL; |
| 785 | |
| 786 | cmd = CAPIMSG_COMMAND(skb->data); |
| 787 | subcmd = CAPIMSG_SUBCOMMAND(skb->data); |
| 788 | |
| 789 | if (cmd == CAPI_DATA_B3 && subcmd== CAPI_REQ) { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 790 | ctr->nsentdatapkt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | ap->nsentdatapkt++; |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 792 | if (ctr->traceflag > 2) |
| 793 | showctl |= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } else { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 795 | ctr->nsentctlpkt++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | ap->nsentctlpkt++; |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 797 | if (ctr->traceflag) |
| 798 | showctl |= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | } |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 800 | showctl |= (ctr->traceflag & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | if (showctl & 2) { |
| 802 | if (showctl & 1) { |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 803 | printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | CAPIMSG_CONTROLLER(skb->data), |
| 805 | CAPIMSG_APPID(skb->data), |
| 806 | capi_cmd2str(cmd, subcmd), |
| 807 | CAPIMSG_LEN(skb->data)); |
| 808 | } else { |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 809 | _cdebbuf *cdb = capi_message2str(skb->data); |
| 810 | if (cdb) { |
| 811 | printk(KERN_DEBUG "kcapi: put [%03d] %s\n", |
| 812 | CAPIMSG_CONTROLLER(skb->data), |
| 813 | cdb->buf); |
| 814 | cdebbuf_free(cdb); |
| 815 | } else |
| 816 | printk(KERN_DEBUG "kcapi: put [%03d] id#%d %s len=%u cannot trace\n", |
| 817 | CAPIMSG_CONTROLLER(skb->data), |
| 818 | CAPIMSG_APPID(skb->data), |
| 819 | capi_cmd2str(cmd, subcmd), |
| 820 | CAPIMSG_LEN(skb->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 823 | return ctr->send_message(ctr, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | EXPORT_SYMBOL(capi20_put_message); |
| 827 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 828 | /** |
| 829 | * capi20_get_manufacturer() - CAPI 2.0 operation CAPI_GET_MANUFACTURER |
| 830 | * @contr: controller number. |
| 831 | * @buf: result buffer (64 bytes). |
| 832 | * |
| 833 | * Retrieve information about the manufacturer of the specified ISDN controller |
| 834 | * or (for @contr == 0) the driver itself. |
| 835 | * Return value: CAPI result code |
| 836 | */ |
| 837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | u16 capi20_get_manufacturer(u32 contr, u8 *buf) |
| 839 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 840 | struct capi_ctr *ctr; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 841 | u16 ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
| 843 | if (contr == 0) { |
| 844 | strlcpy(buf, capi_manufakturer, CAPI_MANUFACTURER_LEN); |
| 845 | return CAPI_NOERROR; |
| 846 | } |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 847 | |
| 848 | mutex_lock(&capi_controller_lock); |
| 849 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 850 | ctr = get_capi_ctr_by_nr(contr); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 851 | if (ctr && ctr->state == CAPI_CTR_RUNNING) { |
| 852 | strlcpy(buf, ctr->manu, CAPI_MANUFACTURER_LEN); |
| 853 | ret = CAPI_NOERROR; |
| 854 | } else |
| 855 | ret = CAPI_REGNOTINSTALLED; |
| 856 | |
| 857 | mutex_unlock(&capi_controller_lock); |
| 858 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | EXPORT_SYMBOL(capi20_get_manufacturer); |
| 862 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 863 | /** |
| 864 | * capi20_get_version() - CAPI 2.0 operation CAPI_GET_VERSION |
| 865 | * @contr: controller number. |
| 866 | * @verp: result structure. |
| 867 | * |
| 868 | * Retrieve version information for the specified ISDN controller |
| 869 | * or (for @contr == 0) the driver itself. |
| 870 | * Return value: CAPI result code |
| 871 | */ |
| 872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | u16 capi20_get_version(u32 contr, struct capi_version *verp) |
| 874 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 875 | struct capi_ctr *ctr; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 876 | u16 ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | if (contr == 0) { |
| 879 | *verp = driver_version; |
| 880 | return CAPI_NOERROR; |
| 881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 883 | mutex_lock(&capi_controller_lock); |
| 884 | |
| 885 | ctr = get_capi_ctr_by_nr(contr); |
| 886 | if (ctr && ctr->state == CAPI_CTR_RUNNING) { |
| 887 | memcpy(verp, &ctr->version, sizeof(capi_version)); |
| 888 | ret = CAPI_NOERROR; |
| 889 | } else |
| 890 | ret = CAPI_REGNOTINSTALLED; |
| 891 | |
| 892 | mutex_unlock(&capi_controller_lock); |
| 893 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | EXPORT_SYMBOL(capi20_get_version); |
| 897 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 898 | /** |
| 899 | * capi20_get_serial() - CAPI 2.0 operation CAPI_GET_SERIAL_NUMBER |
| 900 | * @contr: controller number. |
| 901 | * @serial: result buffer (8 bytes). |
| 902 | * |
| 903 | * Retrieve the serial number of the specified ISDN controller |
| 904 | * or (for @contr == 0) the driver itself. |
| 905 | * Return value: CAPI result code |
| 906 | */ |
| 907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | u16 capi20_get_serial(u32 contr, u8 *serial) |
| 909 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 910 | struct capi_ctr *ctr; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 911 | u16 ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | |
| 913 | if (contr == 0) { |
| 914 | strlcpy(serial, driver_serial, CAPI_SERIAL_LEN); |
| 915 | return CAPI_NOERROR; |
| 916 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 918 | mutex_lock(&capi_controller_lock); |
| 919 | |
| 920 | ctr = get_capi_ctr_by_nr(contr); |
| 921 | if (ctr && ctr->state == CAPI_CTR_RUNNING) { |
| 922 | strlcpy(serial, ctr->serial, CAPI_SERIAL_LEN); |
| 923 | ret = CAPI_NOERROR; |
| 924 | } else |
| 925 | ret = CAPI_REGNOTINSTALLED; |
| 926 | |
| 927 | mutex_unlock(&capi_controller_lock); |
| 928 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | EXPORT_SYMBOL(capi20_get_serial); |
| 932 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 933 | /** |
| 934 | * capi20_get_profile() - CAPI 2.0 operation CAPI_GET_PROFILE |
| 935 | * @contr: controller number. |
| 936 | * @profp: result structure. |
| 937 | * |
| 938 | * Retrieve capability information for the specified ISDN controller |
| 939 | * or (for @contr == 0) the number of installed controllers. |
| 940 | * Return value: CAPI result code |
| 941 | */ |
| 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | u16 capi20_get_profile(u32 contr, struct capi_profile *profp) |
| 944 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 945 | struct capi_ctr *ctr; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 946 | u16 ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
| 948 | if (contr == 0) { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 949 | profp->ncontroller = ncontrollers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | return CAPI_NOERROR; |
| 951 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 953 | mutex_lock(&capi_controller_lock); |
| 954 | |
| 955 | ctr = get_capi_ctr_by_nr(contr); |
| 956 | if (ctr && ctr->state == CAPI_CTR_RUNNING) { |
| 957 | memcpy(profp, &ctr->profile, sizeof(struct capi_profile)); |
| 958 | ret = CAPI_NOERROR; |
| 959 | } else |
| 960 | ret = CAPI_REGNOTINSTALLED; |
| 961 | |
| 962 | mutex_unlock(&capi_controller_lock); |
| 963 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | EXPORT_SYMBOL(capi20_get_profile); |
| 967 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 968 | /* Must be called with capi_controller_lock held. */ |
| 969 | static int wait_on_ctr_state(struct capi_ctr *ctr, unsigned int state) |
| 970 | { |
| 971 | DEFINE_WAIT(wait); |
| 972 | int retval = 0; |
| 973 | |
| 974 | ctr = capi_ctr_get(ctr); |
| 975 | if (!ctr) |
| 976 | return -ESRCH; |
| 977 | |
| 978 | for (;;) { |
| 979 | prepare_to_wait(&ctr->state_wait_queue, &wait, |
| 980 | TASK_INTERRUPTIBLE); |
| 981 | |
| 982 | if (ctr->state == state) |
| 983 | break; |
| 984 | if (ctr->state == CAPI_CTR_DETACHED) { |
| 985 | retval = -ESRCH; |
| 986 | break; |
| 987 | } |
| 988 | if (signal_pending(current)) { |
| 989 | retval = -EINTR; |
| 990 | break; |
| 991 | } |
| 992 | |
| 993 | mutex_unlock(&capi_controller_lock); |
| 994 | schedule(); |
| 995 | mutex_lock(&capi_controller_lock); |
| 996 | } |
| 997 | finish_wait(&ctr->state_wait_queue, &wait); |
| 998 | |
| 999 | capi_ctr_put(ctr); |
| 1000 | |
| 1001 | return retval; |
| 1002 | } |
| 1003 | |
Robert P. J. Day | 37772ac | 2008-04-28 02:14:42 -0700 | [diff] [blame] | 1004 | #ifdef AVMB1_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | static int old_capi_manufacturer(unsigned int cmd, void __user *data) |
| 1006 | { |
| 1007 | avmb1_loadandconfigdef ldef; |
| 1008 | avmb1_extcarddef cdef; |
| 1009 | avmb1_resetdef rdef; |
| 1010 | capicardparams cparams; |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1011 | struct capi_ctr *ctr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | struct capi_driver *driver = NULL; |
| 1013 | capiloaddata ldata; |
| 1014 | struct list_head *l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | int retval; |
| 1016 | |
| 1017 | switch (cmd) { |
| 1018 | case AVMB1_ADDCARD: |
| 1019 | case AVMB1_ADDCARD_WITH_TYPE: |
| 1020 | if (cmd == AVMB1_ADDCARD) { |
| 1021 | if ((retval = copy_from_user(&cdef, data, |
| 1022 | sizeof(avmb1_carddef)))) |
| 1023 | return retval; |
| 1024 | cdef.cardtype = AVM_CARDTYPE_B1; |
| 1025 | } else { |
| 1026 | if ((retval = copy_from_user(&cdef, data, |
| 1027 | sizeof(avmb1_extcarddef)))) |
| 1028 | return retval; |
| 1029 | } |
| 1030 | cparams.port = cdef.port; |
| 1031 | cparams.irq = cdef.irq; |
| 1032 | cparams.cardnr = cdef.cardnr; |
| 1033 | |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 1034 | mutex_lock(&capi_drivers_lock); |
| 1035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | switch (cdef.cardtype) { |
| 1037 | case AVM_CARDTYPE_B1: |
| 1038 | list_for_each(l, &capi_drivers) { |
| 1039 | driver = list_entry(l, struct capi_driver, list); |
| 1040 | if (strcmp(driver->name, "b1isa") == 0) |
| 1041 | break; |
| 1042 | } |
| 1043 | break; |
| 1044 | case AVM_CARDTYPE_T1: |
| 1045 | list_for_each(l, &capi_drivers) { |
| 1046 | driver = list_entry(l, struct capi_driver, list); |
| 1047 | if (strcmp(driver->name, "t1isa") == 0) |
| 1048 | break; |
| 1049 | } |
| 1050 | break; |
| 1051 | default: |
| 1052 | driver = NULL; |
| 1053 | break; |
| 1054 | } |
| 1055 | if (!driver) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | printk(KERN_ERR "kcapi: driver not loaded.\n"); |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 1057 | retval = -EIO; |
| 1058 | } else if (!driver->add_card) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | printk(KERN_ERR "kcapi: driver has no add card function.\n"); |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 1060 | retval = -EIO; |
| 1061 | } else |
| 1062 | retval = driver->add_card(driver, &cparams); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 1064 | mutex_unlock(&capi_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | return retval; |
| 1066 | |
| 1067 | case AVMB1_LOAD: |
| 1068 | case AVMB1_LOAD_AND_CONFIG: |
| 1069 | |
| 1070 | if (cmd == AVMB1_LOAD) { |
| 1071 | if (copy_from_user(&ldef, data, |
| 1072 | sizeof(avmb1_loaddef))) |
| 1073 | return -EFAULT; |
| 1074 | ldef.t4config.len = 0; |
| 1075 | ldef.t4config.data = NULL; |
| 1076 | } else { |
| 1077 | if (copy_from_user(&ldef, data, |
| 1078 | sizeof(avmb1_loadandconfigdef))) |
| 1079 | return -EFAULT; |
| 1080 | } |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1081 | |
| 1082 | mutex_lock(&capi_controller_lock); |
| 1083 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1084 | ctr = get_capi_ctr_by_nr(ldef.contr); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1085 | if (!ctr) { |
| 1086 | retval = -EINVAL; |
| 1087 | goto load_unlock_out; |
| 1088 | } |
| 1089 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1090 | if (ctr->load_firmware == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | printk(KERN_DEBUG "kcapi: load: no load function\n"); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1092 | retval = -ESRCH; |
| 1093 | goto load_unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | if (ldef.t4file.len <= 0) { |
| 1097 | printk(KERN_DEBUG "kcapi: load: invalid parameter: length of t4file is %d ?\n", ldef.t4file.len); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1098 | retval = -EINVAL; |
| 1099 | goto load_unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | } |
Harvey Harrison | 2f9e9b6 | 2008-04-28 02:14:37 -0700 | [diff] [blame] | 1101 | if (ldef.t4file.data == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | printk(KERN_DEBUG "kcapi: load: invalid parameter: dataptr is 0\n"); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1103 | retval = -EINVAL; |
| 1104 | goto load_unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | ldata.firmware.user = 1; |
| 1108 | ldata.firmware.data = ldef.t4file.data; |
| 1109 | ldata.firmware.len = ldef.t4file.len; |
| 1110 | ldata.configuration.user = 1; |
| 1111 | ldata.configuration.data = ldef.t4config.data; |
| 1112 | ldata.configuration.len = ldef.t4config.len; |
| 1113 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1114 | if (ctr->state != CAPI_CTR_DETECTED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | printk(KERN_INFO "kcapi: load: contr=%d not in detect state\n", ldef.contr); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1116 | retval = -EBUSY; |
| 1117 | goto load_unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | } |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1119 | ctr->state = CAPI_CTR_LOADING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1121 | retval = ctr->load_firmware(ctr, &ldata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | if (retval) { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1123 | ctr->state = CAPI_CTR_DETECTED; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1124 | goto load_unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1127 | retval = wait_on_ctr_state(ctr, CAPI_CTR_RUNNING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1129 | load_unlock_out: |
| 1130 | mutex_unlock(&capi_controller_lock); |
| 1131 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
| 1133 | case AVMB1_RESETCARD: |
| 1134 | if (copy_from_user(&rdef, data, sizeof(avmb1_resetdef))) |
| 1135 | return -EFAULT; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1136 | |
| 1137 | retval = 0; |
| 1138 | |
| 1139 | mutex_lock(&capi_controller_lock); |
| 1140 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1141 | ctr = get_capi_ctr_by_nr(rdef.contr); |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1142 | if (!ctr) { |
| 1143 | retval = -ESRCH; |
| 1144 | goto reset_unlock_out; |
| 1145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1147 | if (ctr->state == CAPI_CTR_DETECTED) |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1148 | goto reset_unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
Tilman Schmidt | 85a8356 | 2010-05-23 01:02:08 +0000 | [diff] [blame^] | 1150 | if (ctr->reset_ctr == NULL) { |
| 1151 | printk(KERN_DEBUG "kcapi: reset: no reset function\n"); |
| 1152 | retval = -ESRCH; |
| 1153 | goto reset_unlock_out; |
| 1154 | } |
| 1155 | |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1156 | ctr->reset_ctr(ctr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1158 | retval = wait_on_ctr_state(ctr, CAPI_CTR_DETECTED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1160 | reset_unlock_out: |
| 1161 | mutex_unlock(&capi_controller_lock); |
| 1162 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | } |
| 1164 | return -EINVAL; |
| 1165 | } |
| 1166 | #endif |
| 1167 | |
Tilman Schmidt | 554f200 | 2009-04-23 02:24:21 +0000 | [diff] [blame] | 1168 | /** |
| 1169 | * capi20_manufacturer() - CAPI 2.0 operation CAPI_MANUFACTURER |
| 1170 | * @cmd: command. |
| 1171 | * @data: parameter. |
| 1172 | * |
| 1173 | * Perform manufacturer specific command. |
| 1174 | * Return value: CAPI result code |
| 1175 | */ |
| 1176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | int capi20_manufacturer(unsigned int cmd, void __user *data) |
| 1178 | { |
Jan Kiszka | 5225303 | 2010-02-08 10:12:10 +0000 | [diff] [blame] | 1179 | struct capi_ctr *ctr; |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1180 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | |
| 1182 | switch (cmd) { |
Robert P. J. Day | 37772ac | 2008-04-28 02:14:42 -0700 | [diff] [blame] | 1183 | #ifdef AVMB1_COMPAT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | case AVMB1_LOAD: |
| 1185 | case AVMB1_LOAD_AND_CONFIG: |
| 1186 | case AVMB1_RESETCARD: |
| 1187 | case AVMB1_GET_CARDINFO: |
| 1188 | case AVMB1_REMOVECARD: |
| 1189 | return old_capi_manufacturer(cmd, data); |
| 1190 | #endif |
| 1191 | case KCAPI_CMD_TRACE: |
| 1192 | { |
| 1193 | kcapi_flagdef fdef; |
| 1194 | |
| 1195 | if (copy_from_user(&fdef, data, sizeof(kcapi_flagdef))) |
| 1196 | return -EFAULT; |
| 1197 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1198 | mutex_lock(&capi_controller_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | |
Jan Kiszka | 0ca3a01 | 2010-02-08 10:12:14 +0000 | [diff] [blame] | 1200 | ctr = get_capi_ctr_by_nr(fdef.contr); |
| 1201 | if (ctr) { |
| 1202 | ctr->traceflag = fdef.flag; |
| 1203 | printk(KERN_INFO "kcapi: contr [%03d] set trace=%d\n", |
| 1204 | ctr->cnr, ctr->traceflag); |
| 1205 | retval = 0; |
| 1206 | } else |
| 1207 | retval = -ESRCH; |
| 1208 | |
| 1209 | mutex_unlock(&capi_controller_lock); |
| 1210 | |
| 1211 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | } |
| 1213 | case KCAPI_CMD_ADDCARD: |
| 1214 | { |
| 1215 | struct list_head *l; |
| 1216 | struct capi_driver *driver = NULL; |
| 1217 | capicardparams cparams; |
| 1218 | kcapi_carddef cdef; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
| 1220 | if ((retval = copy_from_user(&cdef, data, sizeof(cdef)))) |
| 1221 | return retval; |
| 1222 | |
| 1223 | cparams.port = cdef.port; |
| 1224 | cparams.irq = cdef.irq; |
| 1225 | cparams.membase = cdef.membase; |
| 1226 | cparams.cardnr = cdef.cardnr; |
| 1227 | cparams.cardtype = 0; |
| 1228 | cdef.driver[sizeof(cdef.driver)-1] = 0; |
| 1229 | |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 1230 | mutex_lock(&capi_drivers_lock); |
| 1231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | list_for_each(l, &capi_drivers) { |
| 1233 | driver = list_entry(l, struct capi_driver, list); |
| 1234 | if (strcmp(driver->name, cdef.driver) == 0) |
| 1235 | break; |
| 1236 | } |
Harvey Harrison | 2f9e9b6 | 2008-04-28 02:14:37 -0700 | [diff] [blame] | 1237 | if (driver == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | printk(KERN_ERR "kcapi: driver \"%s\" not loaded.\n", |
| 1239 | cdef.driver); |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 1240 | retval = -ESRCH; |
| 1241 | } else if (!driver->add_card) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | printk(KERN_ERR "kcapi: driver \"%s\" has no add card function.\n", cdef.driver); |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 1243 | retval = -EIO; |
| 1244 | } else |
| 1245 | retval = driver->add_card(driver, &cparams); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Jan Kiszka | 9717fb8 | 2010-02-08 10:12:11 +0000 | [diff] [blame] | 1247 | mutex_unlock(&capi_drivers_lock); |
| 1248 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | default: |
| 1252 | printk(KERN_ERR "kcapi: manufacturer command %d unknown.\n", |
| 1253 | cmd); |
| 1254 | break; |
| 1255 | |
| 1256 | } |
| 1257 | return -EINVAL; |
| 1258 | } |
| 1259 | |
| 1260 | EXPORT_SYMBOL(capi20_manufacturer); |
| 1261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | /* ------------------------------------------------------------- */ |
| 1263 | /* -------- Init & Cleanup ------------------------------------- */ |
| 1264 | /* ------------------------------------------------------------- */ |
| 1265 | |
| 1266 | /* |
| 1267 | * init / exit functions |
| 1268 | */ |
| 1269 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 1270 | static struct notifier_block capictr_nb = { |
| 1271 | .notifier_call = notify_handler, |
| 1272 | .priority = INT_MAX, |
| 1273 | }; |
| 1274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | static int __init kcapi_init(void) |
| 1276 | { |
Jan Kiszka | 88549d6 | 2010-02-08 10:12:09 +0000 | [diff] [blame] | 1277 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
Jan Kiszka | ef69bb2 | 2010-02-08 10:12:13 +0000 | [diff] [blame] | 1279 | register_capictr_notifier(&capictr_nb); |
| 1280 | |
Jan Kiszka | 88549d6 | 2010-02-08 10:12:09 +0000 | [diff] [blame] | 1281 | err = cdebug_init(); |
| 1282 | if (!err) |
| 1283 | kcapi_proc_init(); |
| 1284 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | static void __exit kcapi_exit(void) |
| 1288 | { |
| 1289 | kcapi_proc_exit(); |
| 1290 | |
| 1291 | /* make sure all notifiers are finished */ |
| 1292 | flush_scheduled_work(); |
Karsten Keil | 17f0cd2 | 2007-02-28 20:13:50 -0800 | [diff] [blame] | 1293 | cdebug_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | module_init(kcapi_init); |
| 1297 | module_exit(kcapi_exit); |