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