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