Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: capi.c,v 1.1.2.7 2004/04/28 09:48:59 armin Exp $ |
| 2 | * |
| 3 | * CAPI 2.0 Interface for Linux |
| 4 | * |
| 5 | * Copyright 1996 by Carsten Paeth <calle@calle.de> |
| 6 | * |
| 7 | * This software may be used and distributed according to the terms |
| 8 | * of the GNU General Public License, incorporated herein by reference. |
| 9 | * |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/major.h> |
| 16 | #include <linux/sched.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/fcntl.h> |
| 19 | #include <linux/fs.h> |
| 20 | #include <linux/signal.h> |
Matthias Kaehlcke | 9ea6e5d | 2007-05-08 00:32:43 -0700 | [diff] [blame] | 21 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/timer.h> |
| 24 | #include <linux/wait.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/tty.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/netdevice.h> |
| 27 | #include <linux/ppp_defs.h> |
| 28 | #include <linux/if_ppp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/skbuff.h> |
| 30 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 31 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/poll.h> |
| 33 | #include <linux/capi.h> |
| 34 | #include <linux/kernelcapi.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/device.h> |
| 37 | #include <linux/moduleparam.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/isdn/capiutil.h> |
| 39 | #include <linux/isdn/capicmd.h> |
Jan Kiszka | 90926f0 | 2010-02-08 10:12:06 +0000 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include "capifs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | MODULE_DESCRIPTION("CAPI4Linux: Userspace /dev/capi20 interface"); |
| 44 | MODULE_AUTHOR("Carsten Paeth"); |
| 45 | MODULE_LICENSE("GPL"); |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #undef _DEBUG_TTYFUNCS /* call to tty_driver */ |
| 48 | #undef _DEBUG_DATAFLOW /* data flow */ |
| 49 | |
| 50 | /* -------- driver information -------------------------------------- */ |
| 51 | |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 52 | static DEFINE_MUTEX(capi_mutex); |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 53 | static struct class *capi_class; |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 54 | static int capi_major = 68; /* allocated */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | module_param_named(major, capi_major, uint, 0); |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 59 | #define CAPINC_NR_PORTS 32 |
| 60 | #define CAPINC_MAX_PORTS 256 |
| 61 | |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 62 | static int capi_ttyminors = CAPINC_NR_PORTS; |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | module_param_named(ttyminors, capi_ttyminors, uint, 0); |
| 65 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
| 66 | |
| 67 | /* -------- defines ------------------------------------------------- */ |
| 68 | |
| 69 | #define CAPINC_MAX_RECVQUEUE 10 |
| 70 | #define CAPINC_MAX_SENDQUEUE 10 |
| 71 | #define CAPI_MAX_BLKSIZE 2048 |
| 72 | |
| 73 | /* -------- data structures ----------------------------------------- */ |
| 74 | |
| 75 | struct capidev; |
| 76 | struct capincci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | struct capiminor; |
| 78 | |
Jan Kiszka | 42651b5 | 2010-02-08 10:12:37 +0000 | [diff] [blame] | 79 | struct ackqueue_entry { |
Michael Buesch | 6aa6547 | 2006-06-26 00:25:30 -0700 | [diff] [blame] | 80 | struct list_head list; |
| 81 | u16 datahandle; |
| 82 | }; |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | struct capiminor { |
Jan Kiszka | 0159d54 | 2010-02-08 10:12:27 +0000 | [diff] [blame] | 85 | struct kref kref; |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | unsigned int minor; |
Jan Kiszka | 90926f0 | 2010-02-08 10:12:06 +0000 | [diff] [blame] | 88 | struct dentry *capifs_dentry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Jan Kiszka | 4279271 | 2010-02-08 10:12:38 +0000 | [diff] [blame] | 90 | struct capi20_appl *ap; |
| 91 | u32 ncci; |
| 92 | atomic_t datahandle; |
| 93 | atomic_t msgid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 95 | struct tty_port port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | int ttyinstop; |
| 97 | int ttyoutstop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 99 | struct sk_buff_head inqueue; |
| 100 | |
| 101 | struct sk_buff_head outqueue; |
| 102 | int outbytes; |
| 103 | struct sk_buff *outskb; |
| 104 | spinlock_t outlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* transmit path */ |
Michael Buesch | 6aa6547 | 2006-06-26 00:25:30 -0700 | [diff] [blame] | 107 | struct list_head ackqueue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | int nack; |
Michael Buesch | 6aa6547 | 2006-06-26 00:25:30 -0700 | [diff] [blame] | 109 | spinlock_t ackqlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | struct capincci { |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 113 | struct list_head list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | u32 ncci; |
| 115 | struct capidev *cdev; |
| 116 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
| 117 | struct capiminor *minorp; |
| 118 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
| 119 | }; |
| 120 | |
| 121 | struct capidev { |
| 122 | struct list_head list; |
| 123 | struct capi20_appl ap; |
| 124 | u16 errcode; |
| 125 | unsigned userflags; |
| 126 | |
| 127 | struct sk_buff_head recvqueue; |
| 128 | wait_queue_head_t recvwait; |
| 129 | |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 130 | struct list_head nccis; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 132 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | /* -------- global variables ---------------------------------------- */ |
| 136 | |
Jan Kiszka | b8f433d | 2010-02-08 10:12:17 +0000 | [diff] [blame] | 137 | static DEFINE_MUTEX(capidev_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | static LIST_HEAD(capidev_list); |
| 139 | |
| 140 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 141 | |
Jan Kiszka | 3d5d30f | 2010-02-08 10:12:33 +0000 | [diff] [blame] | 142 | static DEFINE_SPINLOCK(capiminors_lock); |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 143 | static struct capiminor **capiminors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Jan Kiszka | 40fb2d0 | 2010-02-08 10:12:25 +0000 | [diff] [blame] | 145 | static struct tty_driver *capinc_tty_driver; |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | /* -------- datahandles --------------------------------------------- */ |
| 148 | |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 149 | static int capiminor_add_ack(struct capiminor *mp, u16 datahandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
Jan Kiszka | 42651b5 | 2010-02-08 10:12:37 +0000 | [diff] [blame] | 151 | struct ackqueue_entry *n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | n = kmalloc(sizeof(*n), GFP_ATOMIC); |
Michael Buesch | 6aa6547 | 2006-06-26 00:25:30 -0700 | [diff] [blame] | 154 | if (unlikely(!n)) { |
| 155 | printk(KERN_ERR "capi: alloc datahandle failed\n"); |
| 156 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | n->datahandle = datahandle; |
Michael Buesch | 6aa6547 | 2006-06-26 00:25:30 -0700 | [diff] [blame] | 159 | INIT_LIST_HEAD(&n->list); |
Jan Kiszka | 2b72b5b | 2010-02-08 10:12:41 +0000 | [diff] [blame] | 160 | spin_lock_bh(&mp->ackqlock); |
Michael Buesch | 6aa6547 | 2006-06-26 00:25:30 -0700 | [diff] [blame] | 161 | list_add_tail(&n->list, &mp->ackqueue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | mp->nack++; |
Jan Kiszka | 2b72b5b | 2010-02-08 10:12:41 +0000 | [diff] [blame] | 163 | spin_unlock_bh(&mp->ackqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int capiminor_del_ack(struct capiminor *mp, u16 datahandle) |
| 168 | { |
Jan Kiszka | 42651b5 | 2010-02-08 10:12:37 +0000 | [diff] [blame] | 169 | struct ackqueue_entry *p, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Jan Kiszka | 2b72b5b | 2010-02-08 10:12:41 +0000 | [diff] [blame] | 171 | spin_lock_bh(&mp->ackqlock); |
Michael Buesch | 6aa6547 | 2006-06-26 00:25:30 -0700 | [diff] [blame] | 172 | list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) { |
| 173 | if (p->datahandle == datahandle) { |
| 174 | list_del(&p->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | mp->nack--; |
Jan Kiszka | 2b72b5b | 2010-02-08 10:12:41 +0000 | [diff] [blame] | 176 | spin_unlock_bh(&mp->ackqlock); |
| 177 | kfree(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | return 0; |
| 179 | } |
| 180 | } |
Jan Kiszka | 2b72b5b | 2010-02-08 10:12:41 +0000 | [diff] [blame] | 181 | spin_unlock_bh(&mp->ackqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | static void capiminor_del_all_ack(struct capiminor *mp) |
| 186 | { |
Jan Kiszka | 42651b5 | 2010-02-08 10:12:37 +0000 | [diff] [blame] | 187 | struct ackqueue_entry *p, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Michael Buesch | 6aa6547 | 2006-06-26 00:25:30 -0700 | [diff] [blame] | 189 | list_for_each_entry_safe(p, tmp, &mp->ackqueue, list) { |
| 190 | list_del(&p->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | kfree(p); |
| 192 | mp->nack--; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | |
| 197 | /* -------- struct capiminor ---------------------------------------- */ |
| 198 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 199 | static const struct tty_port_operations capiminor_port_ops; /* we have none */ |
| 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci) |
| 202 | { |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 203 | struct capiminor *mp; |
Jan Kiszka | 40fb2d0 | 2010-02-08 10:12:25 +0000 | [diff] [blame] | 204 | struct device *dev; |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 205 | unsigned int minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Jan Kiszka | 54f0fad | 2010-02-08 10:12:20 +0000 | [diff] [blame] | 207 | mp = kzalloc(sizeof(*mp), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | if (!mp) { |
| 209 | printk(KERN_ERR "capi: can't alloc capiminor\n"); |
| 210 | return NULL; |
| 211 | } |
| 212 | |
Jan Kiszka | 0159d54 | 2010-02-08 10:12:27 +0000 | [diff] [blame] | 213 | kref_init(&mp->kref); |
| 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | mp->ap = ap; |
| 216 | mp->ncci = ncci; |
Michael Buesch | 6aa6547 | 2006-06-26 00:25:30 -0700 | [diff] [blame] | 217 | INIT_LIST_HEAD(&mp->ackqueue); |
| 218 | spin_lock_init(&mp->ackqlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | skb_queue_head_init(&mp->inqueue); |
| 221 | skb_queue_head_init(&mp->outqueue); |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 222 | spin_lock_init(&mp->outlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 224 | tty_port_init(&mp->port); |
| 225 | mp->port.ops = &capiminor_port_ops; |
| 226 | |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 227 | /* Allocate the least unused minor number. */ |
Jan Kiszka | 3d5d30f | 2010-02-08 10:12:33 +0000 | [diff] [blame] | 228 | spin_lock(&capiminors_lock); |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 229 | for (minor = 0; minor < capi_ttyminors; minor++) |
| 230 | if (!capiminors[minor]) { |
| 231 | capiminors[minor] = mp; |
| 232 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
Jan Kiszka | 3d5d30f | 2010-02-08 10:12:33 +0000 | [diff] [blame] | 234 | spin_unlock(&capiminors_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 236 | if (minor == capi_ttyminors) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | printk(KERN_NOTICE "capi: out of minors\n"); |
Jan Kiszka | 40fb2d0 | 2010-02-08 10:12:25 +0000 | [diff] [blame] | 238 | goto err_out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 241 | mp->minor = minor; |
| 242 | |
Jan Kiszka | 40fb2d0 | 2010-02-08 10:12:25 +0000 | [diff] [blame] | 243 | dev = tty_register_device(capinc_tty_driver, minor, NULL); |
| 244 | if (IS_ERR(dev)) |
| 245 | goto err_out2; |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return mp; |
Jan Kiszka | 40fb2d0 | 2010-02-08 10:12:25 +0000 | [diff] [blame] | 248 | |
| 249 | err_out2: |
Jan Kiszka | 3d5d30f | 2010-02-08 10:12:33 +0000 | [diff] [blame] | 250 | spin_lock(&capiminors_lock); |
Jan Kiszka | 40fb2d0 | 2010-02-08 10:12:25 +0000 | [diff] [blame] | 251 | capiminors[minor] = NULL; |
Jan Kiszka | 3d5d30f | 2010-02-08 10:12:33 +0000 | [diff] [blame] | 252 | spin_unlock(&capiminors_lock); |
Jan Kiszka | 40fb2d0 | 2010-02-08 10:12:25 +0000 | [diff] [blame] | 253 | |
| 254 | err_out1: |
| 255 | kfree(mp); |
| 256 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Jan Kiszka | 0159d54 | 2010-02-08 10:12:27 +0000 | [diff] [blame] | 259 | static void capiminor_destroy(struct kref *kref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
Jan Kiszka | 0159d54 | 2010-02-08 10:12:27 +0000 | [diff] [blame] | 261 | struct capiminor *mp = container_of(kref, struct capiminor, kref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 263 | kfree_skb(mp->outskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | skb_queue_purge(&mp->inqueue); |
| 265 | skb_queue_purge(&mp->outqueue); |
| 266 | capiminor_del_all_ack(mp); |
| 267 | kfree(mp); |
| 268 | } |
| 269 | |
Jan Kiszka | 40fb2d0 | 2010-02-08 10:12:25 +0000 | [diff] [blame] | 270 | static struct capiminor *capiminor_get(unsigned int minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 272 | struct capiminor *mp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Jan Kiszka | 3d5d30f | 2010-02-08 10:12:33 +0000 | [diff] [blame] | 274 | spin_lock(&capiminors_lock); |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 275 | mp = capiminors[minor]; |
Jan Kiszka | 0159d54 | 2010-02-08 10:12:27 +0000 | [diff] [blame] | 276 | if (mp) |
| 277 | kref_get(&mp->kref); |
Jan Kiszka | 3d5d30f | 2010-02-08 10:12:33 +0000 | [diff] [blame] | 278 | spin_unlock(&capiminors_lock); |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 279 | |
| 280 | return mp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Jan Kiszka | 0159d54 | 2010-02-08 10:12:27 +0000 | [diff] [blame] | 283 | static inline void capiminor_put(struct capiminor *mp) |
| 284 | { |
| 285 | kref_put(&mp->kref, capiminor_destroy); |
| 286 | } |
| 287 | |
| 288 | static void capiminor_free(struct capiminor *mp) |
| 289 | { |
Jan Kiszka | 0159d54 | 2010-02-08 10:12:27 +0000 | [diff] [blame] | 290 | tty_unregister_device(capinc_tty_driver, mp->minor); |
| 291 | |
Jan Kiszka | 3d5d30f | 2010-02-08 10:12:33 +0000 | [diff] [blame] | 292 | spin_lock(&capiminors_lock); |
Jan Kiszka | 0159d54 | 2010-02-08 10:12:27 +0000 | [diff] [blame] | 293 | capiminors[mp->minor] = NULL; |
Jan Kiszka | 3d5d30f | 2010-02-08 10:12:33 +0000 | [diff] [blame] | 294 | spin_unlock(&capiminors_lock); |
Jan Kiszka | 0159d54 | 2010-02-08 10:12:27 +0000 | [diff] [blame] | 295 | |
| 296 | capiminor_put(mp); |
| 297 | } |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | /* -------- struct capincci ----------------------------------------- */ |
| 300 | |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 301 | static void capincci_alloc_minor(struct capidev *cdev, struct capincci *np) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 303 | struct capiminor *mp; |
Jan Kiszka | e95ac14 | 2010-02-08 10:12:26 +0000 | [diff] [blame] | 304 | dev_t device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 306 | if (!(cdev->userflags & CAPIFLAG_HIGHJACKING)) |
| 307 | return; |
| 308 | |
| 309 | mp = np->minorp = capiminor_alloc(&cdev->ap, np->ncci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (mp) { |
Jan Kiszka | e95ac14 | 2010-02-08 10:12:26 +0000 | [diff] [blame] | 311 | device = MKDEV(capinc_tty_driver->major, mp->minor); |
| 312 | mp->capifs_dentry = capifs_new_ncci(mp->minor, device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | static void capincci_free_minor(struct capincci *np) |
| 317 | { |
| 318 | struct capiminor *mp = np->minorp; |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 319 | struct tty_struct *tty; |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 320 | |
| 321 | if (mp) { |
| 322 | capifs_free_ncci(mp->capifs_dentry); |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 323 | |
| 324 | tty = tty_port_tty_get(&mp->port); |
| 325 | if (tty) { |
Jan Kiszka | 30bced9 | 2010-02-08 10:12:31 +0000 | [diff] [blame] | 326 | tty_vhangup(tty); |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 327 | tty_kref_put(tty); |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 328 | } |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 329 | |
| 330 | capiminor_free(mp); |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
| 334 | static inline unsigned int capincci_minor_opencount(struct capincci *np) |
| 335 | { |
| 336 | struct capiminor *mp = np->minorp; |
Jan Kiszka | a84fdf4 | 2010-02-08 10:12:34 +0000 | [diff] [blame] | 337 | unsigned int count = 0; |
| 338 | struct tty_struct *tty; |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 339 | |
Jan Kiszka | a84fdf4 | 2010-02-08 10:12:34 +0000 | [diff] [blame] | 340 | if (mp) { |
| 341 | tty = tty_port_tty_get(&mp->port); |
| 342 | if (tty) { |
| 343 | count = tty->count; |
| 344 | tty_kref_put(tty); |
| 345 | } |
| 346 | } |
| 347 | return count; |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | #else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ |
| 351 | |
| 352 | static inline void |
| 353 | capincci_alloc_minor(struct capidev *cdev, struct capincci *np) { } |
| 354 | static inline void capincci_free_minor(struct capincci *np) { } |
| 355 | |
| 356 | static inline unsigned int capincci_minor_opencount(struct capincci *np) |
| 357 | { |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | #endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ |
| 362 | |
| 363 | static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci) |
| 364 | { |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 365 | struct capincci *np; |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 366 | |
Jan Kiszka | 54f0fad | 2010-02-08 10:12:20 +0000 | [diff] [blame] | 367 | np = kzalloc(sizeof(*np), GFP_KERNEL); |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 368 | if (!np) |
| 369 | return NULL; |
| 370 | np->ncci = ncci; |
| 371 | np->cdev = cdev; |
| 372 | |
| 373 | capincci_alloc_minor(cdev, np); |
| 374 | |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 375 | list_add_tail(&np->list, &cdev->nccis); |
| 376 | |
| 377 | return np; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static void capincci_free(struct capidev *cdev, u32 ncci) |
| 381 | { |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 382 | struct capincci *np, *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 384 | list_for_each_entry_safe(np, tmp, &cdev->nccis, list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | if (ncci == 0xffffffff || np->ncci == ncci) { |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 386 | capincci_free_minor(np); |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 387 | list_del(&np->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | kfree(np); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static struct capincci *capincci_find(struct capidev *cdev, u32 ncci) |
| 393 | { |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 394 | struct capincci *np; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 396 | list_for_each_entry(np, &cdev->nccis, list) |
| 397 | if (np->ncci == ncci) |
| 398 | return np; |
| 399 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
| 403 | /* -------- handle data queue --------------------------------------- */ |
| 404 | |
| 405 | static struct sk_buff * |
| 406 | gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb) |
| 407 | { |
| 408 | struct sk_buff *nskb; |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 409 | nskb = alloc_skb(CAPI_DATA_B3_RESP_LEN, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | if (nskb) { |
| 411 | u16 datahandle = CAPIMSG_U16(skb->data,CAPIMSG_BASELEN+4+4+2); |
| 412 | unsigned char *s = skb_put(nskb, CAPI_DATA_B3_RESP_LEN); |
| 413 | capimsg_setu16(s, 0, CAPI_DATA_B3_RESP_LEN); |
| 414 | capimsg_setu16(s, 2, mp->ap->applid); |
| 415 | capimsg_setu8 (s, 4, CAPI_DATA_B3); |
| 416 | capimsg_setu8 (s, 5, CAPI_RESP); |
Jan Kiszka | 4279271 | 2010-02-08 10:12:38 +0000 | [diff] [blame] | 417 | capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | capimsg_setu32(s, 8, mp->ncci); |
| 419 | capimsg_setu16(s, 12, datahandle); |
| 420 | } |
| 421 | return nskb; |
| 422 | } |
| 423 | |
| 424 | static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb) |
| 425 | { |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 426 | unsigned int datalen = skb->len - CAPIMSG_LEN(skb->data); |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 427 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | struct sk_buff *nskb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | u16 errcode, datahandle; |
| 430 | struct tty_ldisc *ld; |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 431 | int ret = -1; |
| 432 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 433 | tty = tty_port_tty_get(&mp->port); |
| 434 | if (!tty) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | #ifdef _DEBUG_DATAFLOW |
| 436 | printk(KERN_DEBUG "capi: currently no receiver\n"); |
| 437 | #endif |
| 438 | return -1; |
| 439 | } |
| 440 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 441 | ld = tty_ldisc_ref(tty); |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 442 | if (!ld) { |
| 443 | /* fatal error, do not requeue */ |
| 444 | ret = 0; |
| 445 | kfree_skb(skb); |
| 446 | goto deref_tty; |
| 447 | } |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 448 | |
Alan Cox | a352def | 2008-07-16 21:53:12 +0100 | [diff] [blame] | 449 | if (ld->ops->receive_buf == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) |
| 451 | printk(KERN_DEBUG "capi: ldisc has no receive_buf function\n"); |
| 452 | #endif |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 453 | /* fatal error, do not requeue */ |
| 454 | goto free_skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | if (mp->ttyinstop) { |
| 457 | #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) |
| 458 | printk(KERN_DEBUG "capi: recv tty throttled\n"); |
| 459 | #endif |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 460 | goto deref_ldisc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 462 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 463 | if (tty->receive_room < datalen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) |
| 465 | printk(KERN_DEBUG "capi: no room in tty\n"); |
| 466 | #endif |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 467 | goto deref_ldisc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | } |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 469 | |
| 470 | nskb = gen_data_b3_resp_for(mp, skb); |
| 471 | if (!nskb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | printk(KERN_ERR "capi: gen_data_b3_resp failed\n"); |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 473 | goto deref_ldisc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 475 | |
| 476 | datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN + 4); |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | errcode = capi20_put_message(mp->ap, nskb); |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 479 | |
| 480 | if (errcode == CAPI_NOERROR) { |
| 481 | skb_pull(skb, CAPIMSG_LEN(skb->data)); |
| 482 | #ifdef _DEBUG_DATAFLOW |
| 483 | printk(KERN_DEBUG "capi: DATA_B3_RESP %u len=%d => ldisc\n", |
| 484 | datahandle, skb->len); |
| 485 | #endif |
| 486 | ld->ops->receive_buf(tty, skb->data, NULL, skb->len); |
| 487 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | printk(KERN_ERR "capi: send DATA_B3_RESP failed=%x\n", |
| 489 | errcode); |
| 490 | kfree_skb(nskb); |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 491 | |
| 492 | if (errcode == CAPI_SENDQUEUEFULL) |
| 493 | goto deref_ldisc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 495 | |
| 496 | free_skb: |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 497 | ret = 0; |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 498 | kfree_skb(skb); |
| 499 | |
| 500 | deref_ldisc: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | tty_ldisc_deref(ld); |
Jan Kiszka | a11ef7b | 2010-02-08 10:12:36 +0000 | [diff] [blame] | 502 | |
| 503 | deref_tty: |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 504 | tty_kref_put(tty); |
| 505 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | static void handle_minor_recv(struct capiminor *mp) |
| 509 | { |
| 510 | struct sk_buff *skb; |
Jan Kiszka | 68d7347 | 2010-02-08 10:12:39 +0000 | [diff] [blame] | 511 | |
| 512 | while ((skb = skb_dequeue(&mp->inqueue)) != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (handle_recv_skb(mp, skb) < 0) { |
| 514 | skb_queue_head(&mp->inqueue, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | return; |
| 516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Jan Kiszka | eef0ced | 2010-02-08 10:12:42 +0000 | [diff] [blame] | 519 | static void handle_minor_send(struct capiminor *mp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 521 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | struct sk_buff *skb; |
| 523 | u16 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | u16 errcode; |
| 525 | u16 datahandle; |
| 526 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 527 | tty = tty_port_tty_get(&mp->port); |
| 528 | if (!tty) |
Jan Kiszka | eef0ced | 2010-02-08 10:12:42 +0000 | [diff] [blame] | 529 | return; |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 530 | |
| 531 | if (mp->ttyoutstop) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | #if defined(_DEBUG_DATAFLOW) || defined(_DEBUG_TTYFUNCS) |
| 533 | printk(KERN_DEBUG "capi: send: tty stopped\n"); |
| 534 | #endif |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 535 | tty_kref_put(tty); |
Jan Kiszka | eef0ced | 2010-02-08 10:12:42 +0000 | [diff] [blame] | 536 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 539 | while (1) { |
| 540 | spin_lock_bh(&mp->outlock); |
| 541 | skb = __skb_dequeue(&mp->outqueue); |
| 542 | if (!skb) { |
| 543 | spin_unlock_bh(&mp->outlock); |
| 544 | break; |
| 545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | len = (u16)skb->len; |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 547 | mp->outbytes -= len; |
| 548 | spin_unlock_bh(&mp->outlock); |
| 549 | |
| 550 | datahandle = atomic_inc_return(&mp->datahandle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | skb_push(skb, CAPI_DATA_B3_REQ_LEN); |
| 552 | memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN); |
| 553 | capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN); |
| 554 | capimsg_setu16(skb->data, 2, mp->ap->applid); |
| 555 | capimsg_setu8 (skb->data, 4, CAPI_DATA_B3); |
| 556 | capimsg_setu8 (skb->data, 5, CAPI_REQ); |
Jan Kiszka | 4279271 | 2010-02-08 10:12:38 +0000 | [diff] [blame] | 557 | capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */ |
Andrew Morton | 5e6c20a | 2007-07-17 04:04:22 -0700 | [diff] [blame] | 559 | capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | capimsg_setu16(skb->data, 16, len); /* Data length */ |
| 561 | capimsg_setu16(skb->data, 18, datahandle); |
| 562 | capimsg_setu16(skb->data, 20, 0); /* Flags */ |
| 563 | |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 564 | if (capiminor_add_ack(mp, datahandle) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | skb_pull(skb, CAPI_DATA_B3_REQ_LEN); |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 566 | |
| 567 | spin_lock_bh(&mp->outlock); |
| 568 | __skb_queue_head(&mp->outqueue, skb); |
| 569 | mp->outbytes += len; |
| 570 | spin_unlock_bh(&mp->outlock); |
| 571 | |
Jan Kiszka | eef0ced | 2010-02-08 10:12:42 +0000 | [diff] [blame] | 572 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
| 574 | errcode = capi20_put_message(mp->ap, skb); |
| 575 | if (errcode == CAPI_NOERROR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | #ifdef _DEBUG_DATAFLOW |
| 577 | printk(KERN_DEBUG "capi: DATA_B3_REQ %u len=%u\n", |
| 578 | datahandle, len); |
| 579 | #endif |
| 580 | continue; |
| 581 | } |
| 582 | capiminor_del_ack(mp, datahandle); |
| 583 | |
| 584 | if (errcode == CAPI_SENDQUEUEFULL) { |
| 585 | skb_pull(skb, CAPI_DATA_B3_REQ_LEN); |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 586 | |
| 587 | spin_lock_bh(&mp->outlock); |
| 588 | __skb_queue_head(&mp->outqueue, skb); |
| 589 | mp->outbytes += len; |
| 590 | spin_unlock_bh(&mp->outlock); |
| 591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | break; |
| 593 | } |
| 594 | |
| 595 | /* ups, drop packet */ |
| 596 | printk(KERN_ERR "capi: put_message = %x\n", errcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | kfree_skb(skb); |
| 598 | } |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 599 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
| 603 | /* -------- function called by lower level -------------------------- */ |
| 604 | |
| 605 | static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb) |
| 606 | { |
| 607 | struct capidev *cdev = ap->private; |
| 608 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 609 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | struct capiminor *mp; |
| 611 | u16 datahandle; |
| 612 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
| 613 | struct capincci *np; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 615 | mutex_lock(&cdev->lock); |
| 616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) { |
| 618 | u16 info = CAPIMSG_U16(skb->data, 12); // Info field |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 619 | if ((info & 0xff00) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 622 | if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) { |
| 626 | skb_queue_tail(&cdev->recvqueue, skb); |
| 627 | wake_up_interruptible(&cdev->recvwait); |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 628 | goto unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 630 | |
| 631 | np = capincci_find(cdev, CAPIMSG_CONTROL(skb->data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | if (!np) { |
| 633 | printk(KERN_ERR "BUG: capi_signal: ncci not found\n"); |
| 634 | skb_queue_tail(&cdev->recvqueue, skb); |
| 635 | wake_up_interruptible(&cdev->recvwait); |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 636 | goto unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | #ifndef CONFIG_ISDN_CAPI_MIDDLEWARE |
| 640 | skb_queue_tail(&cdev->recvqueue, skb); |
| 641 | wake_up_interruptible(&cdev->recvwait); |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | #else /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | mp = np->minorp; |
| 646 | if (!mp) { |
| 647 | skb_queue_tail(&cdev->recvqueue, skb); |
| 648 | wake_up_interruptible(&cdev->recvwait); |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 649 | goto unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_IND) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+4+2); |
| 653 | #ifdef _DEBUG_DATAFLOW |
| 654 | printk(KERN_DEBUG "capi_signal: DATA_B3_IND %u len=%d\n", |
| 655 | datahandle, skb->len-CAPIMSG_LEN(skb->data)); |
| 656 | #endif |
| 657 | skb_queue_tail(&mp->inqueue, skb); |
Jan Kiszka | 68d7347 | 2010-02-08 10:12:39 +0000 | [diff] [blame] | 658 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | handle_minor_recv(mp); |
| 660 | |
| 661 | } else if (CAPIMSG_SUBCOMMAND(skb->data) == CAPI_CONF) { |
| 662 | |
| 663 | datahandle = CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4); |
| 664 | #ifdef _DEBUG_DATAFLOW |
| 665 | printk(KERN_DEBUG "capi_signal: DATA_B3_CONF %u 0x%x\n", |
| 666 | datahandle, |
| 667 | CAPIMSG_U16(skb->data, CAPIMSG_BASELEN+4+2)); |
| 668 | #endif |
| 669 | kfree_skb(skb); |
Jan Kiszka | 2b72b5b | 2010-02-08 10:12:41 +0000 | [diff] [blame] | 670 | capiminor_del_ack(mp, datahandle); |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 671 | tty = tty_port_tty_get(&mp->port); |
| 672 | if (tty) { |
| 673 | tty_wakeup(tty); |
| 674 | tty_kref_put(tty); |
| 675 | } |
Jan Kiszka | eef0ced | 2010-02-08 10:12:42 +0000 | [diff] [blame] | 676 | handle_minor_send(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
| 678 | } else { |
| 679 | /* ups, let capi application handle it :-) */ |
| 680 | skb_queue_tail(&cdev->recvqueue, skb); |
| 681 | wake_up_interruptible(&cdev->recvwait); |
| 682 | } |
| 683 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 684 | |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 685 | unlock_out: |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 686 | mutex_unlock(&cdev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /* -------- file_operations for capidev ----------------------------- */ |
| 690 | |
| 691 | static ssize_t |
| 692 | capi_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) |
| 693 | { |
Joe Perches | 54cbb1c | 2010-07-12 10:50:02 +0000 | [diff] [blame^] | 694 | struct capidev *cdev = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | struct sk_buff *skb; |
| 696 | size_t copied; |
Jan Kiszka | 28a1dbb | 2010-02-08 10:12:21 +0000 | [diff] [blame] | 697 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
| 699 | if (!cdev->ap.applid) |
| 700 | return -ENODEV; |
| 701 | |
Jan Kiszka | 28a1dbb | 2010-02-08 10:12:21 +0000 | [diff] [blame] | 702 | skb = skb_dequeue(&cdev->recvqueue); |
| 703 | if (!skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | if (file->f_flags & O_NONBLOCK) |
| 705 | return -EAGAIN; |
Jan Kiszka | 28a1dbb | 2010-02-08 10:12:21 +0000 | [diff] [blame] | 706 | err = wait_event_interruptible(cdev->recvwait, |
| 707 | (skb = skb_dequeue(&cdev->recvqueue))); |
| 708 | if (err) |
| 709 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | } |
| 711 | if (skb->len > count) { |
| 712 | skb_queue_head(&cdev->recvqueue, skb); |
| 713 | return -EMSGSIZE; |
| 714 | } |
| 715 | if (copy_to_user(buf, skb->data, skb->len)) { |
| 716 | skb_queue_head(&cdev->recvqueue, skb); |
| 717 | return -EFAULT; |
| 718 | } |
| 719 | copied = skb->len; |
| 720 | |
| 721 | kfree_skb(skb); |
| 722 | |
| 723 | return copied; |
| 724 | } |
| 725 | |
| 726 | static ssize_t |
| 727 | capi_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) |
| 728 | { |
Joe Perches | 54cbb1c | 2010-07-12 10:50:02 +0000 | [diff] [blame^] | 729 | struct capidev *cdev = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | struct sk_buff *skb; |
| 731 | u16 mlen; |
| 732 | |
| 733 | if (!cdev->ap.applid) |
| 734 | return -ENODEV; |
| 735 | |
| 736 | skb = alloc_skb(count, GFP_USER); |
| 737 | if (!skb) |
| 738 | return -ENOMEM; |
| 739 | |
| 740 | if (copy_from_user(skb_put(skb, count), buf, count)) { |
| 741 | kfree_skb(skb); |
| 742 | return -EFAULT; |
| 743 | } |
| 744 | mlen = CAPIMSG_LEN(skb->data); |
| 745 | if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) { |
| 746 | if ((size_t)(mlen + CAPIMSG_DATALEN(skb->data)) != count) { |
| 747 | kfree_skb(skb); |
| 748 | return -EINVAL; |
| 749 | } |
| 750 | } else { |
| 751 | if (mlen != count) { |
| 752 | kfree_skb(skb); |
| 753 | return -EINVAL; |
| 754 | } |
| 755 | } |
| 756 | CAPIMSG_SETAPPID(skb->data, cdev->ap.applid); |
| 757 | |
| 758 | if (CAPIMSG_CMD(skb->data) == CAPI_DISCONNECT_B3_RESP) { |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 759 | mutex_lock(&cdev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | capincci_free(cdev, CAPIMSG_NCCI(skb->data)); |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 761 | mutex_unlock(&cdev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | cdev->errcode = capi20_put_message(&cdev->ap, skb); |
| 765 | |
| 766 | if (cdev->errcode) { |
| 767 | kfree_skb(skb); |
| 768 | return -EIO; |
| 769 | } |
| 770 | return count; |
| 771 | } |
| 772 | |
| 773 | static unsigned int |
| 774 | capi_poll(struct file *file, poll_table * wait) |
| 775 | { |
Joe Perches | 54cbb1c | 2010-07-12 10:50:02 +0000 | [diff] [blame^] | 776 | struct capidev *cdev = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | unsigned int mask = 0; |
| 778 | |
| 779 | if (!cdev->ap.applid) |
| 780 | return POLLERR; |
| 781 | |
| 782 | poll_wait(file, &(cdev->recvwait), wait); |
| 783 | mask = POLLOUT | POLLWRNORM; |
| 784 | if (!skb_queue_empty(&cdev->recvqueue)) |
| 785 | mask |= POLLIN | POLLRDNORM; |
| 786 | return mask; |
| 787 | } |
| 788 | |
| 789 | static int |
Arnd Bergmann | 703c631 | 2010-04-27 00:24:02 +0200 | [diff] [blame] | 790 | capi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | { |
| 792 | struct capidev *cdev = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | capi_ioctl_struct data; |
| 794 | int retval = -EINVAL; |
| 795 | void __user *argp = (void __user *)arg; |
| 796 | |
| 797 | switch (cmd) { |
| 798 | case CAPI_REGISTER: |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 799 | mutex_lock(&cdev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 801 | if (cdev->ap.applid) { |
| 802 | retval = -EEXIST; |
| 803 | goto register_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | } |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 805 | if (copy_from_user(&cdev->ap.rparam, argp, |
| 806 | sizeof(struct capi_register_params))) { |
| 807 | retval = -EFAULT; |
| 808 | goto register_out; |
| 809 | } |
| 810 | cdev->ap.private = cdev; |
| 811 | cdev->ap.recv_message = capi_recv_message; |
| 812 | cdev->errcode = capi20_register(&cdev->ap); |
| 813 | retval = (int)cdev->ap.applid; |
| 814 | if (cdev->errcode) { |
| 815 | cdev->ap.applid = 0; |
| 816 | retval = -EIO; |
| 817 | } |
| 818 | |
| 819 | register_out: |
| 820 | mutex_unlock(&cdev->lock); |
| 821 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
| 823 | case CAPI_GET_VERSION: |
| 824 | { |
| 825 | if (copy_from_user(&data.contr, argp, |
| 826 | sizeof(data.contr))) |
| 827 | return -EFAULT; |
| 828 | cdev->errcode = capi20_get_version(data.contr, &data.version); |
| 829 | if (cdev->errcode) |
| 830 | return -EIO; |
| 831 | if (copy_to_user(argp, &data.version, |
| 832 | sizeof(data.version))) |
| 833 | return -EFAULT; |
| 834 | } |
| 835 | return 0; |
| 836 | |
| 837 | case CAPI_GET_SERIAL: |
| 838 | { |
| 839 | if (copy_from_user(&data.contr, argp, |
| 840 | sizeof(data.contr))) |
| 841 | return -EFAULT; |
| 842 | cdev->errcode = capi20_get_serial (data.contr, data.serial); |
| 843 | if (cdev->errcode) |
| 844 | return -EIO; |
| 845 | if (copy_to_user(argp, data.serial, |
| 846 | sizeof(data.serial))) |
| 847 | return -EFAULT; |
| 848 | } |
| 849 | return 0; |
| 850 | case CAPI_GET_PROFILE: |
| 851 | { |
| 852 | if (copy_from_user(&data.contr, argp, |
| 853 | sizeof(data.contr))) |
| 854 | return -EFAULT; |
| 855 | |
| 856 | if (data.contr == 0) { |
| 857 | cdev->errcode = capi20_get_profile(data.contr, &data.profile); |
| 858 | if (cdev->errcode) |
| 859 | return -EIO; |
| 860 | |
| 861 | retval = copy_to_user(argp, |
| 862 | &data.profile.ncontroller, |
| 863 | sizeof(data.profile.ncontroller)); |
| 864 | |
| 865 | } else { |
| 866 | cdev->errcode = capi20_get_profile(data.contr, &data.profile); |
| 867 | if (cdev->errcode) |
| 868 | return -EIO; |
| 869 | |
| 870 | retval = copy_to_user(argp, &data.profile, |
| 871 | sizeof(data.profile)); |
| 872 | } |
| 873 | if (retval) |
| 874 | return -EFAULT; |
| 875 | } |
| 876 | return 0; |
| 877 | |
| 878 | case CAPI_GET_MANUFACTURER: |
| 879 | { |
| 880 | if (copy_from_user(&data.contr, argp, |
| 881 | sizeof(data.contr))) |
| 882 | return -EFAULT; |
| 883 | cdev->errcode = capi20_get_manufacturer(data.contr, data.manufacturer); |
| 884 | if (cdev->errcode) |
| 885 | return -EIO; |
| 886 | |
| 887 | if (copy_to_user(argp, data.manufacturer, |
| 888 | sizeof(data.manufacturer))) |
| 889 | return -EFAULT; |
| 890 | |
| 891 | } |
| 892 | return 0; |
| 893 | case CAPI_GET_ERRCODE: |
| 894 | data.errcode = cdev->errcode; |
| 895 | cdev->errcode = CAPI_NOERROR; |
| 896 | if (arg) { |
| 897 | if (copy_to_user(argp, &data.errcode, |
| 898 | sizeof(data.errcode))) |
| 899 | return -EFAULT; |
| 900 | } |
| 901 | return data.errcode; |
| 902 | |
| 903 | case CAPI_INSTALLED: |
| 904 | if (capi20_isinstalled() == CAPI_NOERROR) |
| 905 | return 0; |
| 906 | return -ENXIO; |
| 907 | |
| 908 | case CAPI_MANUFACTURER_CMD: |
| 909 | { |
| 910 | struct capi_manufacturer_cmd mcmd; |
| 911 | if (!capable(CAP_SYS_ADMIN)) |
| 912 | return -EPERM; |
| 913 | if (copy_from_user(&mcmd, argp, sizeof(mcmd))) |
| 914 | return -EFAULT; |
| 915 | return capi20_manufacturer(mcmd.cmd, mcmd.data); |
| 916 | } |
| 917 | return 0; |
| 918 | |
| 919 | case CAPI_SET_FLAGS: |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 920 | case CAPI_CLR_FLAGS: { |
| 921 | unsigned userflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 923 | if (copy_from_user(&userflags, argp, sizeof(userflags))) |
| 924 | return -EFAULT; |
| 925 | |
| 926 | mutex_lock(&cdev->lock); |
| 927 | if (cmd == CAPI_SET_FLAGS) |
| 928 | cdev->userflags |= userflags; |
| 929 | else |
| 930 | cdev->userflags &= ~userflags; |
| 931 | mutex_unlock(&cdev->lock); |
| 932 | return 0; |
| 933 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | case CAPI_GET_FLAGS: |
| 935 | if (copy_to_user(argp, &cdev->userflags, |
| 936 | sizeof(cdev->userflags))) |
| 937 | return -EFAULT; |
| 938 | return 0; |
| 939 | |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 940 | case CAPI_NCCI_OPENCOUNT: { |
| 941 | struct capincci *nccip; |
| 942 | unsigned ncci; |
| 943 | int count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 945 | if (copy_from_user(&ncci, argp, sizeof(ncci))) |
| 946 | return -EFAULT; |
| 947 | |
| 948 | mutex_lock(&cdev->lock); |
| 949 | nccip = capincci_find(cdev, (u32)ncci); |
| 950 | if (nccip) |
| 951 | count = capincci_minor_opencount(nccip); |
| 952 | mutex_unlock(&cdev->lock); |
| 953 | return count; |
| 954 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | |
| 956 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 957 | case CAPI_NCCI_GETUNIT: { |
| 958 | struct capincci *nccip; |
| 959 | struct capiminor *mp; |
| 960 | unsigned ncci; |
| 961 | int unit = -ESRCH; |
| 962 | |
| 963 | if (copy_from_user(&ncci, argp, sizeof(ncci))) |
| 964 | return -EFAULT; |
| 965 | |
| 966 | mutex_lock(&cdev->lock); |
| 967 | nccip = capincci_find(cdev, (u32)ncci); |
| 968 | if (nccip) { |
| 969 | mp = nccip->minorp; |
| 970 | if (mp) |
| 971 | unit = mp->minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | } |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 973 | mutex_unlock(&cdev->lock); |
| 974 | return unit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 976 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
| 977 | |
| 978 | default: |
| 979 | return -EINVAL; |
| 980 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | } |
| 982 | |
Arnd Bergmann | 703c631 | 2010-04-27 00:24:02 +0200 | [diff] [blame] | 983 | static long |
| 984 | capi_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 985 | { |
| 986 | int ret; |
| 987 | |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 988 | mutex_lock(&capi_mutex); |
Arnd Bergmann | 703c631 | 2010-04-27 00:24:02 +0200 | [diff] [blame] | 989 | ret = capi_ioctl(file, cmd, arg); |
Arnd Bergmann | 76a6492 | 2010-07-11 11:18:53 +0000 | [diff] [blame] | 990 | mutex_unlock(&capi_mutex); |
Arnd Bergmann | 703c631 | 2010-04-27 00:24:02 +0200 | [diff] [blame] | 991 | |
| 992 | return ret; |
| 993 | } |
| 994 | |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 995 | static int capi_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | { |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 997 | struct capidev *cdev; |
| 998 | |
| 999 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
| 1000 | if (!cdev) |
| 1001 | return -ENOMEM; |
| 1002 | |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 1003 | mutex_init(&cdev->lock); |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 1004 | skb_queue_head_init(&cdev->recvqueue); |
| 1005 | init_waitqueue_head(&cdev->recvwait); |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 1006 | INIT_LIST_HEAD(&cdev->nccis); |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 1007 | file->private_data = cdev; |
| 1008 | |
| 1009 | mutex_lock(&capidev_list_lock); |
| 1010 | list_add_tail(&cdev->list, &capidev_list); |
| 1011 | mutex_unlock(&capidev_list_lock); |
| 1012 | |
| 1013 | return nonseekable_open(inode, file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 1016 | static int capi_release(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | { |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 1018 | struct capidev *cdev = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 1020 | mutex_lock(&capidev_list_lock); |
| 1021 | list_del(&cdev->list); |
| 1022 | mutex_unlock(&capidev_list_lock); |
| 1023 | |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 1024 | if (cdev->ap.applid) |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 1025 | capi20_release(&cdev->ap); |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 1026 | skb_queue_purge(&cdev->recvqueue); |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 1027 | capincci_free(cdev, 0xffffffff); |
Jan Kiszka | eca39dd | 2010-02-08 10:12:18 +0000 | [diff] [blame] | 1028 | |
| 1029 | kfree(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | return 0; |
| 1031 | } |
| 1032 | |
Arjan van de Ven | 2b8693c | 2007-02-12 00:55:32 -0800 | [diff] [blame] | 1033 | static const struct file_operations capi_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | { |
| 1035 | .owner = THIS_MODULE, |
| 1036 | .llseek = no_llseek, |
| 1037 | .read = capi_read, |
| 1038 | .write = capi_write, |
| 1039 | .poll = capi_poll, |
Arnd Bergmann | 703c631 | 2010-04-27 00:24:02 +0200 | [diff] [blame] | 1040 | .unlocked_ioctl = capi_unlocked_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | .open = capi_open, |
| 1042 | .release = capi_release, |
| 1043 | }; |
| 1044 | |
| 1045 | #ifdef CONFIG_ISDN_CAPI_MIDDLEWARE |
| 1046 | /* -------- tty_operations for capincci ----------------------------- */ |
| 1047 | |
Jan Kiszka | 4632451 | 2010-02-08 10:12:28 +0000 | [diff] [blame] | 1048 | static int |
| 1049 | capinc_tty_install(struct tty_driver *driver, struct tty_struct *tty) |
| 1050 | { |
| 1051 | int idx = tty->index; |
| 1052 | struct capiminor *mp = capiminor_get(idx); |
| 1053 | int ret = tty_init_termios(tty); |
| 1054 | |
| 1055 | if (ret == 0) { |
| 1056 | tty_driver_kref_get(driver); |
| 1057 | tty->count++; |
| 1058 | tty->driver_data = mp; |
| 1059 | driver->ttys[idx] = tty; |
| 1060 | } else |
| 1061 | capiminor_put(mp); |
| 1062 | return ret; |
| 1063 | } |
| 1064 | |
| 1065 | static void capinc_tty_cleanup(struct tty_struct *tty) |
| 1066 | { |
| 1067 | struct capiminor *mp = tty->driver_data; |
| 1068 | tty->driver_data = NULL; |
| 1069 | capiminor_put(mp); |
| 1070 | } |
| 1071 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 1072 | static int capinc_tty_open(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | { |
Jan Kiszka | 4632451 | 2010-02-08 10:12:28 +0000 | [diff] [blame] | 1074 | struct capiminor *mp = tty->driver_data; |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 1075 | int err; |
| 1076 | |
| 1077 | err = tty_port_open(&mp->port, tty, filp); |
| 1078 | if (err) |
| 1079 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | handle_minor_recv(mp); |
| 1082 | return 0; |
| 1083 | } |
| 1084 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 1085 | static void capinc_tty_close(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | { |
Jan Kiszka | 4632451 | 2010-02-08 10:12:28 +0000 | [diff] [blame] | 1087 | struct capiminor *mp = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 1089 | tty_port_close(&mp->port, tty, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Jan Kiszka | 6576c28 | 2010-02-08 10:12:32 +0000 | [diff] [blame] | 1092 | static int capinc_tty_write(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | const unsigned char *buf, int count) |
| 1094 | { |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1095 | struct capiminor *mp = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | struct sk_buff *skb; |
| 1097 | |
| 1098 | #ifdef _DEBUG_TTYFUNCS |
| 1099 | printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count); |
| 1100 | #endif |
| 1101 | |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1102 | spin_lock_bh(&mp->outlock); |
| 1103 | skb = mp->outskb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | if (skb) { |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1105 | mp->outskb = NULL; |
| 1106 | __skb_queue_tail(&mp->outqueue, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | mp->outbytes += skb->len; |
| 1108 | } |
| 1109 | |
| 1110 | skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_ATOMIC); |
| 1111 | if (!skb) { |
| 1112 | printk(KERN_ERR "capinc_tty_write: alloc_skb failed\n"); |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1113 | spin_unlock_bh(&mp->outlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | return -ENOMEM; |
| 1115 | } |
| 1116 | |
| 1117 | skb_reserve(skb, CAPI_DATA_B3_REQ_LEN); |
| 1118 | memcpy(skb_put(skb, count), buf, count); |
| 1119 | |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1120 | __skb_queue_tail(&mp->outqueue, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | mp->outbytes += skb->len; |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1122 | spin_unlock_bh(&mp->outlock); |
| 1123 | |
Jan Kiszka | eef0ced | 2010-02-08 10:12:42 +0000 | [diff] [blame] | 1124 | handle_minor_send(mp); |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | return count; |
| 1127 | } |
| 1128 | |
Alan Cox | f2545a7 | 2008-04-30 00:54:09 -0700 | [diff] [blame] | 1129 | static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | { |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1131 | struct capiminor *mp = tty->driver_data; |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1132 | bool invoke_send = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | struct sk_buff *skb; |
Alan Cox | f2545a7 | 2008-04-30 00:54:09 -0700 | [diff] [blame] | 1134 | int ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
| 1136 | #ifdef _DEBUG_TTYFUNCS |
| 1137 | printk(KERN_DEBUG "capinc_put_char(%u)\n", ch); |
| 1138 | #endif |
| 1139 | |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1140 | spin_lock_bh(&mp->outlock); |
| 1141 | skb = mp->outskb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | if (skb) { |
| 1143 | if (skb_tailroom(skb) > 0) { |
| 1144 | *(skb_put(skb, 1)) = ch; |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1145 | goto unlock_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | } |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1147 | mp->outskb = NULL; |
| 1148 | __skb_queue_tail(&mp->outqueue, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | mp->outbytes += skb->len; |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1150 | invoke_send = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | } |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+CAPI_MAX_BLKSIZE, GFP_ATOMIC); |
| 1154 | if (skb) { |
| 1155 | skb_reserve(skb, CAPI_DATA_B3_REQ_LEN); |
| 1156 | *(skb_put(skb, 1)) = ch; |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1157 | mp->outskb = skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | } else { |
| 1159 | printk(KERN_ERR "capinc_put_char: char %u lost\n", ch); |
Alan Cox | f2545a7 | 2008-04-30 00:54:09 -0700 | [diff] [blame] | 1160 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | } |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1162 | |
| 1163 | unlock_out: |
| 1164 | spin_unlock_bh(&mp->outlock); |
| 1165 | |
| 1166 | if (invoke_send) |
Jan Kiszka | eef0ced | 2010-02-08 10:12:42 +0000 | [diff] [blame] | 1167 | handle_minor_send(mp); |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1168 | |
Alan Cox | f2545a7 | 2008-04-30 00:54:09 -0700 | [diff] [blame] | 1169 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | static void capinc_tty_flush_chars(struct tty_struct *tty) |
| 1173 | { |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1174 | struct capiminor *mp = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | struct sk_buff *skb; |
| 1176 | |
| 1177 | #ifdef _DEBUG_TTYFUNCS |
| 1178 | printk(KERN_DEBUG "capinc_tty_flush_chars\n"); |
| 1179 | #endif |
| 1180 | |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1181 | spin_lock_bh(&mp->outlock); |
| 1182 | skb = mp->outskb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | if (skb) { |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1184 | mp->outskb = NULL; |
| 1185 | __skb_queue_tail(&mp->outqueue, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | mp->outbytes += skb->len; |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1187 | spin_unlock_bh(&mp->outlock); |
| 1188 | |
Jan Kiszka | eef0ced | 2010-02-08 10:12:42 +0000 | [diff] [blame] | 1189 | handle_minor_send(mp); |
Jan Kiszka | dfbb84f | 2010-02-08 10:12:40 +0000 | [diff] [blame] | 1190 | } else |
| 1191 | spin_unlock_bh(&mp->outlock); |
| 1192 | |
| 1193 | handle_minor_recv(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | static int capinc_tty_write_room(struct tty_struct *tty) |
| 1197 | { |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1198 | struct capiminor *mp = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | int room; |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | room = CAPINC_MAX_SENDQUEUE-skb_queue_len(&mp->outqueue); |
| 1202 | room *= CAPI_MAX_BLKSIZE; |
| 1203 | #ifdef _DEBUG_TTYFUNCS |
| 1204 | printk(KERN_DEBUG "capinc_tty_write_room = %d\n", room); |
| 1205 | #endif |
| 1206 | return room; |
| 1207 | } |
| 1208 | |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 1209 | static int capinc_tty_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | { |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1211 | struct capiminor *mp = tty->driver_data; |
| 1212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | #ifdef _DEBUG_TTYFUNCS |
| 1214 | printk(KERN_DEBUG "capinc_tty_chars_in_buffer = %d nack=%d sq=%d rq=%d\n", |
| 1215 | mp->outbytes, mp->nack, |
| 1216 | skb_queue_len(&mp->outqueue), |
| 1217 | skb_queue_len(&mp->inqueue)); |
| 1218 | #endif |
| 1219 | return mp->outbytes; |
| 1220 | } |
| 1221 | |
| 1222 | static int capinc_tty_ioctl(struct tty_struct *tty, struct file * file, |
| 1223 | unsigned int cmd, unsigned long arg) |
| 1224 | { |
| 1225 | int error = 0; |
| 1226 | switch (cmd) { |
| 1227 | default: |
Stephen Rothwell | 53e8631 | 2008-10-13 10:44:33 +0100 | [diff] [blame] | 1228 | error = n_tty_ioctl_helper(tty, file, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | break; |
| 1230 | } |
| 1231 | return error; |
| 1232 | } |
| 1233 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 1234 | static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios * old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | { |
| 1236 | #ifdef _DEBUG_TTYFUNCS |
| 1237 | printk(KERN_DEBUG "capinc_tty_set_termios\n"); |
| 1238 | #endif |
| 1239 | } |
| 1240 | |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1241 | static void capinc_tty_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | { |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1243 | struct capiminor *mp = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | #ifdef _DEBUG_TTYFUNCS |
| 1245 | printk(KERN_DEBUG "capinc_tty_throttle\n"); |
| 1246 | #endif |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1247 | mp->ttyinstop = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1250 | static void capinc_tty_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | { |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1252 | struct capiminor *mp = tty->driver_data; |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | #ifdef _DEBUG_TTYFUNCS |
| 1255 | printk(KERN_DEBUG "capinc_tty_unthrottle\n"); |
| 1256 | #endif |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1257 | mp->ttyinstop = 0; |
| 1258 | handle_minor_recv(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | static void capinc_tty_stop(struct tty_struct *tty) |
| 1262 | { |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1263 | struct capiminor *mp = tty->driver_data; |
| 1264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | #ifdef _DEBUG_TTYFUNCS |
| 1266 | printk(KERN_DEBUG "capinc_tty_stop\n"); |
| 1267 | #endif |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1268 | mp->ttyoutstop = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | static void capinc_tty_start(struct tty_struct *tty) |
| 1272 | { |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1273 | struct capiminor *mp = tty->driver_data; |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | #ifdef _DEBUG_TTYFUNCS |
| 1276 | printk(KERN_DEBUG "capinc_tty_start\n"); |
| 1277 | #endif |
Jan Kiszka | 2c8df72 | 2010-02-08 10:12:30 +0000 | [diff] [blame] | 1278 | mp->ttyoutstop = 0; |
Jan Kiszka | eef0ced | 2010-02-08 10:12:42 +0000 | [diff] [blame] | 1279 | handle_minor_send(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static void capinc_tty_hangup(struct tty_struct *tty) |
| 1283 | { |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 1284 | struct capiminor *mp = tty->driver_data; |
| 1285 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | #ifdef _DEBUG_TTYFUNCS |
| 1287 | printk(KERN_DEBUG "capinc_tty_hangup\n"); |
| 1288 | #endif |
Jan Kiszka | fb4b488 | 2010-02-08 10:12:29 +0000 | [diff] [blame] | 1289 | tty_port_hangup(&mp->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Alan Cox | 9e98966c | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 1292 | static int capinc_tty_break_ctl(struct tty_struct *tty, int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | { |
| 1294 | #ifdef _DEBUG_TTYFUNCS |
| 1295 | printk(KERN_DEBUG "capinc_tty_break_ctl(%d)\n", state); |
| 1296 | #endif |
Alan Cox | 9e98966c | 2008-07-22 11:18:03 +0100 | [diff] [blame] | 1297 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | static void capinc_tty_flush_buffer(struct tty_struct *tty) |
| 1301 | { |
| 1302 | #ifdef _DEBUG_TTYFUNCS |
| 1303 | printk(KERN_DEBUG "capinc_tty_flush_buffer\n"); |
| 1304 | #endif |
| 1305 | } |
| 1306 | |
| 1307 | static void capinc_tty_set_ldisc(struct tty_struct *tty) |
| 1308 | { |
| 1309 | #ifdef _DEBUG_TTYFUNCS |
| 1310 | printk(KERN_DEBUG "capinc_tty_set_ldisc\n"); |
| 1311 | #endif |
| 1312 | } |
| 1313 | |
| 1314 | static void capinc_tty_send_xchar(struct tty_struct *tty, char ch) |
| 1315 | { |
| 1316 | #ifdef _DEBUG_TTYFUNCS |
| 1317 | printk(KERN_DEBUG "capinc_tty_send_xchar(%d)\n", ch); |
| 1318 | #endif |
| 1319 | } |
| 1320 | |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 1321 | static const struct tty_operations capinc_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | .open = capinc_tty_open, |
| 1323 | .close = capinc_tty_close, |
| 1324 | .write = capinc_tty_write, |
| 1325 | .put_char = capinc_tty_put_char, |
| 1326 | .flush_chars = capinc_tty_flush_chars, |
| 1327 | .write_room = capinc_tty_write_room, |
| 1328 | .chars_in_buffer = capinc_tty_chars_in_buffer, |
| 1329 | .ioctl = capinc_tty_ioctl, |
| 1330 | .set_termios = capinc_tty_set_termios, |
| 1331 | .throttle = capinc_tty_throttle, |
| 1332 | .unthrottle = capinc_tty_unthrottle, |
| 1333 | .stop = capinc_tty_stop, |
| 1334 | .start = capinc_tty_start, |
| 1335 | .hangup = capinc_tty_hangup, |
| 1336 | .break_ctl = capinc_tty_break_ctl, |
| 1337 | .flush_buffer = capinc_tty_flush_buffer, |
| 1338 | .set_ldisc = capinc_tty_set_ldisc, |
| 1339 | .send_xchar = capinc_tty_send_xchar, |
Jan Kiszka | 4632451 | 2010-02-08 10:12:28 +0000 | [diff] [blame] | 1340 | .install = capinc_tty_install, |
| 1341 | .cleanup = capinc_tty_cleanup, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | }; |
| 1343 | |
Jan Kiszka | e76b154 | 2010-02-08 10:12:24 +0000 | [diff] [blame] | 1344 | static int __init capinc_tty_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | { |
| 1346 | struct tty_driver *drv; |
Jan Kiszka | e76b154 | 2010-02-08 10:12:24 +0000 | [diff] [blame] | 1347 | int err; |
| 1348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | if (capi_ttyminors > CAPINC_MAX_PORTS) |
| 1350 | capi_ttyminors = CAPINC_MAX_PORTS; |
| 1351 | if (capi_ttyminors <= 0) |
| 1352 | capi_ttyminors = CAPINC_NR_PORTS; |
| 1353 | |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 1354 | capiminors = kzalloc(sizeof(struct capi_minor *) * capi_ttyminors, |
| 1355 | GFP_KERNEL); |
| 1356 | if (!capiminors) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | return -ENOMEM; |
| 1358 | |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 1359 | drv = alloc_tty_driver(capi_ttyminors); |
| 1360 | if (!drv) { |
| 1361 | kfree(capiminors); |
| 1362 | return -ENOMEM; |
| 1363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | drv->owner = THIS_MODULE; |
| 1365 | drv->driver_name = "capi_nc"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | drv->name = "capi"; |
Jan Kiszka | e95ac14 | 2010-02-08 10:12:26 +0000 | [diff] [blame] | 1367 | drv->major = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | drv->minor_start = 0; |
| 1369 | drv->type = TTY_DRIVER_TYPE_SERIAL; |
| 1370 | drv->subtype = SERIAL_TYPE_NORMAL; |
| 1371 | drv->init_termios = tty_std_termios; |
| 1372 | drv->init_termios.c_iflag = ICRNL; |
| 1373 | drv->init_termios.c_oflag = OPOST | ONLCR; |
| 1374 | drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; |
| 1375 | drv->init_termios.c_lflag = 0; |
Jan Kiszka | 40fb2d0 | 2010-02-08 10:12:25 +0000 | [diff] [blame] | 1376 | drv->flags = |
| 1377 | TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS | |
| 1378 | TTY_DRIVER_DYNAMIC_DEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | tty_set_operations(drv, &capinc_ops); |
Jan Kiszka | e76b154 | 2010-02-08 10:12:24 +0000 | [diff] [blame] | 1380 | |
| 1381 | err = tty_register_driver(drv); |
| 1382 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | put_tty_driver(drv); |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 1384 | kfree(capiminors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | printk(KERN_ERR "Couldn't register capi_nc driver\n"); |
Jan Kiszka | e76b154 | 2010-02-08 10:12:24 +0000 | [diff] [blame] | 1386 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | } |
| 1388 | capinc_tty_driver = drv; |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
Jan Kiszka | e76b154 | 2010-02-08 10:12:24 +0000 | [diff] [blame] | 1392 | static void __exit capinc_tty_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | { |
Jan Kiszka | e76b154 | 2010-02-08 10:12:24 +0000 | [diff] [blame] | 1394 | tty_unregister_driver(capinc_tty_driver); |
| 1395 | put_tty_driver(capinc_tty_driver); |
Jan Kiszka | 81d17fe | 2010-02-08 10:12:23 +0000 | [diff] [blame] | 1396 | kfree(capiminors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 1399 | #else /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ |
| 1400 | |
| 1401 | static inline int capinc_tty_init(void) |
| 1402 | { |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | static inline void capinc_tty_exit(void) { } |
| 1407 | |
| 1408 | #endif /* !CONFIG_ISDN_CAPI_MIDDLEWARE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | |
| 1410 | /* -------- /proc functions ----------------------------------------- */ |
| 1411 | |
| 1412 | /* |
| 1413 | * /proc/capi/capi20: |
| 1414 | * minor applid nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt |
| 1415 | */ |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 1416 | static int capi20_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | { |
| 1418 | struct capidev *cdev; |
| 1419 | struct list_head *l; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
Jan Kiszka | b8f433d | 2010-02-08 10:12:17 +0000 | [diff] [blame] | 1421 | mutex_lock(&capidev_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | list_for_each(l, &capidev_list) { |
| 1423 | cdev = list_entry(l, struct capidev, list); |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 1424 | seq_printf(m, "0 %d %lu %lu %lu %lu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | cdev->ap.applid, |
| 1426 | cdev->ap.nrecvctlpkt, |
| 1427 | cdev->ap.nrecvdatapkt, |
| 1428 | cdev->ap.nsentctlpkt, |
| 1429 | cdev->ap.nsentdatapkt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | } |
Jan Kiszka | b8f433d | 2010-02-08 10:12:17 +0000 | [diff] [blame] | 1431 | mutex_unlock(&capidev_list_lock); |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 1432 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 1435 | static int capi20_proc_open(struct inode *inode, struct file *file) |
| 1436 | { |
| 1437 | return single_open(file, capi20_proc_show, NULL); |
| 1438 | } |
| 1439 | |
| 1440 | static const struct file_operations capi20_proc_fops = { |
| 1441 | .owner = THIS_MODULE, |
| 1442 | .open = capi20_proc_open, |
| 1443 | .read = seq_read, |
| 1444 | .llseek = seq_lseek, |
| 1445 | .release = single_release, |
| 1446 | }; |
| 1447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | /* |
| 1449 | * /proc/capi/capi20ncci: |
| 1450 | * applid ncci |
| 1451 | */ |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 1452 | static int capi20ncci_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | { |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 1454 | struct capidev *cdev; |
| 1455 | struct capincci *np; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
Jan Kiszka | b8f433d | 2010-02-08 10:12:17 +0000 | [diff] [blame] | 1457 | mutex_lock(&capidev_list_lock); |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 1458 | list_for_each_entry(cdev, &capidev_list, list) { |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 1459 | mutex_lock(&cdev->lock); |
Jan Kiszka | 884f5c4 | 2010-02-08 10:12:22 +0000 | [diff] [blame] | 1460 | list_for_each_entry(np, &cdev->nccis, list) |
| 1461 | seq_printf(m, "%d 0x%x\n", cdev->ap.applid, np->ncci); |
Jan Kiszka | 05b4149 | 2010-02-08 10:12:19 +0000 | [diff] [blame] | 1462 | mutex_unlock(&cdev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | } |
Jan Kiszka | b8f433d | 2010-02-08 10:12:17 +0000 | [diff] [blame] | 1464 | mutex_unlock(&capidev_list_lock); |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 1465 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 1468 | static int capi20ncci_proc_open(struct inode *inode, struct file *file) |
| 1469 | { |
| 1470 | return single_open(file, capi20ncci_proc_show, NULL); |
| 1471 | } |
| 1472 | |
| 1473 | static const struct file_operations capi20ncci_proc_fops = { |
| 1474 | .owner = THIS_MODULE, |
| 1475 | .open = capi20ncci_proc_open, |
| 1476 | .read = seq_read, |
| 1477 | .llseek = seq_lseek, |
| 1478 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | }; |
| 1480 | |
| 1481 | static void __init proc_init(void) |
| 1482 | { |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 1483 | proc_create("capi/capi20", 0, NULL, &capi20_proc_fops); |
| 1484 | proc_create("capi/capi20ncci", 0, NULL, &capi20ncci_proc_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | static void __exit proc_exit(void) |
| 1488 | { |
Alexey Dobriyan | 9a58a80 | 2010-01-14 03:10:54 -0800 | [diff] [blame] | 1489 | remove_proc_entry("capi/capi20", NULL); |
| 1490 | remove_proc_entry("capi/capi20ncci", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | /* -------- init function and module interface ---------------------- */ |
| 1494 | |
| 1495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | static int __init capi_init(void) |
| 1497 | { |
Jan Kiszka | 88549d6 | 2010-02-08 10:12:09 +0000 | [diff] [blame] | 1498 | const char *compileinfo; |
Andrew Morton | 6d9eac3 | 2006-03-28 01:56:19 -0800 | [diff] [blame] | 1499 | int major_ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | |
Andrew Morton | 6d9eac3 | 2006-03-28 01:56:19 -0800 | [diff] [blame] | 1501 | major_ret = register_chrdev(capi_major, "capi20", &capi_fops); |
| 1502 | if (major_ret < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | printk(KERN_ERR "capi20: unable to get major %d\n", capi_major); |
Andrew Morton | 6d9eac3 | 2006-03-28 01:56:19 -0800 | [diff] [blame] | 1504 | return major_ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | } |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 1506 | capi_class = class_create(THIS_MODULE, "capi"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | if (IS_ERR(capi_class)) { |
| 1508 | unregister_chrdev(capi_major, "capi20"); |
| 1509 | return PTR_ERR(capi_class); |
| 1510 | } |
| 1511 | |
Greg Kroah-Hartman | a9b1261 | 2008-07-21 20:03:34 -0700 | [diff] [blame] | 1512 | device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | if (capinc_tty_init() < 0) { |
Tony Jones | d78b036 | 2007-09-25 02:03:03 +0200 | [diff] [blame] | 1515 | device_destroy(capi_class, MKDEV(capi_major, 0)); |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 1516 | class_destroy(capi_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | unregister_chrdev(capi_major, "capi20"); |
| 1518 | return -ENOMEM; |
| 1519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | |
| 1521 | proc_init(); |
| 1522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | #if defined(CONFIG_ISDN_CAPI_CAPIFS) || defined(CONFIG_ISDN_CAPI_CAPIFS_MODULE) |
| 1524 | compileinfo = " (middleware+capifs)"; |
Jan Kiszka | 501c87a | 2010-02-08 10:12:16 +0000 | [diff] [blame] | 1525 | #elif defined(CONFIG_ISDN_CAPI_MIDDLEWARE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | compileinfo = " (no capifs)"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | #else |
| 1528 | compileinfo = " (no middleware)"; |
| 1529 | #endif |
Jan Kiszka | 88549d6 | 2010-02-08 10:12:09 +0000 | [diff] [blame] | 1530 | printk(KERN_NOTICE "CAPI 2.0 started up with major %d%s\n", |
| 1531 | capi_major, compileinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
| 1533 | return 0; |
| 1534 | } |
| 1535 | |
| 1536 | static void __exit capi_exit(void) |
| 1537 | { |
| 1538 | proc_exit(); |
| 1539 | |
Tony Jones | d78b036 | 2007-09-25 02:03:03 +0200 | [diff] [blame] | 1540 | device_destroy(capi_class, MKDEV(capi_major, 0)); |
gregkh@suse.de | 56b2293 | 2005-03-23 10:01:41 -0800 | [diff] [blame] | 1541 | class_destroy(capi_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | unregister_chrdev(capi_major, "capi20"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | capinc_tty_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | module_init(capi_init); |
| 1548 | module_exit(capi_exit); |