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