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