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