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