blob: f59112944c917e845c919b90449098aa7a3a1a7e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* net/atm/common.c - ATM sockets (common part for PVC and SVC) */
2
3/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4
Joe Perches99824462010-01-26 11:40:00 +00005#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/module.h>
8#include <linux/kmod.h>
9#include <linux/net.h> /* struct socket, struct proto_ops */
10#include <linux/atm.h> /* ATM stuff */
11#include <linux/atmdev.h>
12#include <linux/socket.h> /* SOL_SOCKET */
13#include <linux/errno.h> /* error codes */
14#include <linux/capability.h>
Jesper Juhle49332b2005-05-01 08:59:08 -070015#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/sched.h>
17#include <linux/time.h> /* struct timeval */
18#include <linux/skbuff.h>
19#include <linux/bitops.h>
20#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <net/sock.h> /* struct sock */
Joe Perchesa8147d72010-01-26 11:40:06 +000023#include <linux/uaccess.h>
24#include <linux/poll.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Arun Sharma600634972011-07-26 16:09:06 -070026#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28#include "resources.h" /* atm_find_dev */
29#include "common.h" /* prototypes */
30#include "protocols.h" /* atm_init_<transport> */
31#include "addr.h" /* address registry */
32#include "signaling.h" /* for WAITING and sigd_attach */
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
Joe Perchesa8147d72010-01-26 11:40:06 +000035EXPORT_SYMBOL(vcc_hash);
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037DEFINE_RWLOCK(vcc_sklist_lock);
Joe Perchesa8147d72010-01-26 11:40:06 +000038EXPORT_SYMBOL(vcc_sklist_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Karl Hiramoto7313bb82010-07-08 20:55:30 +000040static ATOMIC_NOTIFIER_HEAD(atm_dev_notify_chain);
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static void __vcc_insert_socket(struct sock *sk)
43{
44 struct atm_vcc *vcc = atm_sk(sk);
Joe Perchesa8147d72010-01-26 11:40:06 +000045 struct hlist_head *head = &vcc_hash[vcc->vci & (VCC_HTABLE_SIZE - 1)];
Eric Dumazet81c3d542005-10-03 14:13:38 -070046 sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 sk_add_node(sk, head);
48}
49
50void vcc_insert_socket(struct sock *sk)
51{
52 write_lock_irq(&vcc_sklist_lock);
53 __vcc_insert_socket(sk);
54 write_unlock_irq(&vcc_sklist_lock);
55}
Joe Perchesa8147d72010-01-26 11:40:06 +000056EXPORT_SYMBOL(vcc_insert_socket);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58static void vcc_remove_socket(struct sock *sk)
59{
60 write_lock_irq(&vcc_sklist_lock);
61 sk_del_node_init(sk);
62 write_unlock_irq(&vcc_sklist_lock);
63}
64
Joe Perchesa8147d72010-01-26 11:40:06 +000065static struct sk_buff *alloc_tx(struct atm_vcc *vcc, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 struct sk_buff *skb;
68 struct sock *sk = sk_atm(vcc);
69
Eric Dumazet81e2a3d2009-06-17 19:06:12 -070070 if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) {
Stephen Hemminger52240062007-08-28 15:22:09 -070071 pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
Joe Perches99824462010-01-26 11:40:00 +000072 sk_wmem_alloc_get(sk), size, sk->sk_sndbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return NULL;
74 }
Eric Dumazet81e2a3d2009-06-17 19:06:12 -070075 while (!(skb = alloc_skb(size, GFP_KERNEL)))
76 schedule();
Joe Perchesa8147d72010-01-26 11:40:06 +000077 pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 atomic_add(skb->truesize, &sk->sk_wmem_alloc);
79 return skb;
80}
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static void vcc_sock_destruct(struct sock *sk)
83{
84 if (atomic_read(&sk->sk_rmem_alloc))
Joe Perchesa8147d72010-01-26 11:40:06 +000085 printk(KERN_DEBUG "%s: rmem leakage (%d bytes) detected.\n",
86 __func__, atomic_read(&sk->sk_rmem_alloc));
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 if (atomic_read(&sk->sk_wmem_alloc))
Joe Perchesa8147d72010-01-26 11:40:06 +000089 printk(KERN_DEBUG "%s: wmem leakage (%d bytes) detected.\n",
90 __func__, atomic_read(&sk->sk_wmem_alloc));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
93static void vcc_def_wakeup(struct sock *sk)
94{
Eric Dumazet43815482010-04-29 11:01:49 +000095 struct socket_wq *wq;
96
97 rcu_read_lock();
98 wq = rcu_dereference(sk->sk_wq);
99 if (wq_has_sleeper(wq))
100 wake_up(&wq->wait);
101 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
104static inline int vcc_writable(struct sock *sk)
105{
106 struct atm_vcc *vcc = atm_sk(sk);
107
108 return (vcc->qos.txtp.max_sdu +
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900109 atomic_read(&sk->sk_wmem_alloc)) <= sk->sk_sndbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
112static void vcc_write_space(struct sock *sk)
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900113{
Eric Dumazet43815482010-04-29 11:01:49 +0000114 struct socket_wq *wq;
115
116 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 if (vcc_writable(sk)) {
Eric Dumazet43815482010-04-29 11:01:49 +0000119 wq = rcu_dereference(sk->sk_wq);
120 if (wq_has_sleeper(wq))
121 wake_up_interruptible(&wq->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Pavel Emelyanov8d8ad9d2007-11-26 20:10:50 +0800123 sk_wake_async(sk, SOCK_WAKE_SPACE, POLL_OUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125
Eric Dumazet43815482010-04-29 11:01:49 +0000126 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
David Woodhousec971f082012-11-28 00:03:11 +0000129static void vcc_release_cb(struct sock *sk)
130{
131 struct atm_vcc *vcc = atm_sk(sk);
132
133 if (vcc->release_cb)
134 vcc->release_cb(vcc);
135}
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137static struct proto vcc_proto = {
138 .name = "VCC",
139 .owner = THIS_MODULE,
140 .obj_size = sizeof(struct atm_vcc),
David Woodhousec971f082012-11-28 00:03:11 +0000141 .release_cb = vcc_release_cb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142};
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900143
Eric W. Biederman1b8d7ae2007-10-08 23:24:22 -0700144int vcc_create(struct net *net, struct socket *sock, int protocol, int family)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 struct sock *sk;
147 struct atm_vcc *vcc;
148
149 sock->sk = NULL;
150 if (sock->type == SOCK_STREAM)
151 return -EINVAL;
Pavel Emelyanov6257ff22007-11-01 00:39:31 -0700152 sk = sk_alloc(net, family, GFP_KERNEL, &vcc_proto);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 if (!sk)
154 return -ENOMEM;
155 sock_init_data(sock, sk);
156 sk->sk_state_change = vcc_def_wakeup;
157 sk->sk_write_space = vcc_write_space;
158
159 vcc = atm_sk(sk);
160 vcc->dev = NULL;
Joe Perchesa8147d72010-01-26 11:40:06 +0000161 memset(&vcc->local, 0, sizeof(struct sockaddr_atmsvc));
162 memset(&vcc->remote, 0, sizeof(struct sockaddr_atmsvc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
Eric Dumazet81e2a3d2009-06-17 19:06:12 -0700164 atomic_set(&sk->sk_wmem_alloc, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 atomic_set(&sk->sk_rmem_alloc, 0);
166 vcc->push = NULL;
167 vcc->pop = NULL;
Krzysztof Mazurec809bd2012-11-06 23:16:57 +0100168 vcc->owner = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 vcc->push_oam = NULL;
David Woodhousec971f082012-11-28 00:03:11 +0000170 vcc->release_cb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 vcc->vpi = vcc->vci = 0; /* no VCI/VPI yet */
172 vcc->atm_options = vcc->aal_options = 0;
173 sk->sk_destruct = vcc_sock_destruct;
174 return 0;
175}
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177static void vcc_destroy_socket(struct sock *sk)
178{
179 struct atm_vcc *vcc = atm_sk(sk);
180 struct sk_buff *skb;
181
182 set_bit(ATM_VF_CLOSE, &vcc->flags);
183 clear_bit(ATM_VF_READY, &vcc->flags);
184 if (vcc->dev) {
185 if (vcc->dev->ops->close)
186 vcc->dev->ops->close(vcc);
187 if (vcc->push)
188 vcc->push(vcc, NULL); /* atmarpd has no push */
Krzysztof Mazurec809bd2012-11-06 23:16:57 +0100189 module_put(vcc->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000192 atm_return(vcc, skb->truesize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 kfree_skb(skb);
194 }
195
196 module_put(vcc->dev->ops->owner);
197 atm_dev_put(vcc->dev);
198 }
Chas Williams9301e322005-09-28 16:35:01 -0700199
200 vcc_remove_socket(sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203int vcc_release(struct socket *sock)
204{
205 struct sock *sk = sock->sk;
206
207 if (sk) {
208 lock_sock(sk);
209 vcc_destroy_socket(sock->sk);
210 release_sock(sk);
211 sock_put(sk);
212 }
213
214 return 0;
215}
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217void vcc_release_async(struct atm_vcc *vcc, int reply)
218{
219 struct sock *sk = sk_atm(vcc);
220
221 set_bit(ATM_VF_CLOSE, &vcc->flags);
222 sk->sk_shutdown |= RCV_SHUTDOWN;
223 sk->sk_err = -reply;
224 clear_bit(ATM_VF_WAITING, &vcc->flags);
225 sk->sk_state_change(sk);
226}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227EXPORT_SYMBOL(vcc_release_async);
228
Jorge Boncompte [DTI2]4e55f572011-11-21 10:25:57 +0000229void vcc_process_recv_queue(struct atm_vcc *vcc)
230{
231 struct sk_buff_head queue, *rq;
232 struct sk_buff *skb, *tmp;
233 unsigned long flags;
234
235 __skb_queue_head_init(&queue);
236 rq = &sk_atm(vcc)->sk_receive_queue;
237
238 spin_lock_irqsave(&rq->lock, flags);
239 skb_queue_splice_init(rq, &queue);
240 spin_unlock_irqrestore(&rq->lock, flags);
241
242 skb_queue_walk_safe(&queue, skb, tmp) {
243 __skb_unlink(skb, &queue);
244 vcc->push(vcc, skb);
245 }
246}
247EXPORT_SYMBOL(vcc_process_recv_queue);
248
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000249void atm_dev_signal_change(struct atm_dev *dev, char signal)
250{
251 pr_debug("%s signal=%d dev=%p number=%d dev->signal=%d\n",
252 __func__, signal, dev, dev->number, dev->signal);
253
254 /* atm driver sending invalid signal */
255 WARN_ON(signal < ATM_PHY_SIG_LOST || signal > ATM_PHY_SIG_FOUND);
256
257 if (dev->signal == signal)
258 return; /* no change */
259
260 dev->signal = signal;
261
262 atomic_notifier_call_chain(&atm_dev_notify_chain, signal, dev);
263}
264EXPORT_SYMBOL(atm_dev_signal_change);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800266void atm_dev_release_vccs(struct atm_dev *dev)
267{
268 int i;
269
270 write_lock_irq(&vcc_sklist_lock);
271 for (i = 0; i < VCC_HTABLE_SIZE; i++) {
272 struct hlist_head *head = &vcc_hash[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800273 struct hlist_node *tmp;
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800274 struct sock *s;
275 struct atm_vcc *vcc;
276
Sasha Levinb67bfe02013-02-27 17:06:00 -0800277 sk_for_each_safe(s, tmp, head) {
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800278 vcc = atm_sk(s);
279 if (vcc->dev == dev) {
280 vcc_release_async(vcc, -EPIPE);
281 sk_del_node_init(s);
282 }
283 }
284 }
285 write_unlock_irq(&vcc_sklist_lock);
286}
Philip A. Prindevillec0312352011-03-30 13:17:04 +0000287EXPORT_SYMBOL(atm_dev_release_vccs);
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800288
Joe Perchesa8147d72010-01-26 11:40:06 +0000289static int adjust_tp(struct atm_trafprm *tp, unsigned char aal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 int max_sdu;
292
Joe Perchesa8147d72010-01-26 11:40:06 +0000293 if (!tp->traffic_class)
294 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 switch (aal) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000296 case ATM_AAL0:
297 max_sdu = ATM_CELL_SIZE-1;
298 break;
299 case ATM_AAL34:
300 max_sdu = ATM_MAX_AAL34_PDU;
301 break;
302 default:
Joe Perchesef423a42014-09-09 21:17:28 -0700303 pr_warn("AAL problems ... (%d)\n", aal);
Joe Perchesa8147d72010-01-26 11:40:06 +0000304 /* fall through */
305 case ATM_AAL5:
306 max_sdu = ATM_MAX_AAL5_PDU;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000308 if (!tp->max_sdu)
309 tp->max_sdu = max_sdu;
310 else if (tp->max_sdu > max_sdu)
311 return -EINVAL;
312 if (!tp->max_cdv)
313 tp->max_cdv = ATM_MAX_CDV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 return 0;
315}
316
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700317static int check_ci(const struct atm_vcc *vcc, short vpi, int vci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
Joe Perchesa8147d72010-01-26 11:40:06 +0000319 struct hlist_head *head = &vcc_hash[vci & (VCC_HTABLE_SIZE - 1)];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 struct sock *s;
321 struct atm_vcc *walk;
322
Sasha Levinb67bfe02013-02-27 17:06:00 -0800323 sk_for_each(s, head) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 walk = atm_sk(s);
325 if (walk->dev != vcc->dev)
326 continue;
327 if (test_bit(ATM_VF_ADDR, &walk->flags) && walk->vpi == vpi &&
328 walk->vci == vci && ((walk->qos.txtp.traffic_class !=
329 ATM_NONE && vcc->qos.txtp.traffic_class != ATM_NONE) ||
330 (walk->qos.rxtp.traffic_class != ATM_NONE &&
331 vcc->qos.rxtp.traffic_class != ATM_NONE)))
332 return -EADDRINUSE;
333 }
334
335 /* allow VCCs with same VPI/VCI iff they don't collide on
336 TX/RX (but we may refuse such sharing for other reasons,
337 e.g. if protocol requires to have both channels) */
338
339 return 0;
340}
341
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700342static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
344 static short p; /* poor man's per-device cache */
345 static int c;
346 short old_p;
347 int old_c;
348 int err;
349
350 if (*vpi != ATM_VPI_ANY && *vci != ATM_VCI_ANY) {
351 err = check_ci(vcc, *vpi, *vci);
352 return err;
353 }
354 /* last scan may have left values out of bounds for current device */
355 if (*vpi != ATM_VPI_ANY)
356 p = *vpi;
357 else if (p >= 1 << vcc->dev->ci_range.vpi_bits)
358 p = 0;
359 if (*vci != ATM_VCI_ANY)
360 c = *vci;
361 else if (c < ATM_NOT_RSV_VCI || c >= 1 << vcc->dev->ci_range.vci_bits)
362 c = ATM_NOT_RSV_VCI;
363 old_p = p;
364 old_c = c;
365 do {
366 if (!check_ci(vcc, p, c)) {
367 *vpi = p;
368 *vci = c;
369 return 0;
370 }
371 if (*vci == ATM_VCI_ANY) {
372 c++;
373 if (c >= 1 << vcc->dev->ci_range.vci_bits)
374 c = ATM_NOT_RSV_VCI;
375 }
376 if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) &&
377 *vpi == ATM_VPI_ANY) {
378 p++;
Joe Perchesa8147d72010-01-26 11:40:06 +0000379 if (p >= 1 << vcc->dev->ci_range.vpi_bits)
380 p = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000382 } while (old_p != p || old_c != c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 return -EADDRINUSE;
384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
387 int vci)
388{
389 struct sock *sk = sk_atm(vcc);
390 int error;
391
392 if ((vpi != ATM_VPI_UNSPEC && vpi != ATM_VPI_ANY &&
393 vpi >> dev->ci_range.vpi_bits) || (vci != ATM_VCI_UNSPEC &&
394 vci != ATM_VCI_ANY && vci >> dev->ci_range.vci_bits))
395 return -EINVAL;
396 if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
397 return -EPERM;
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800398 error = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (!try_module_get(dev->ops->owner))
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800400 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 vcc->dev = dev;
402 write_lock_irq(&vcc_sklist_lock);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900403 if (test_bit(ATM_DF_REMOVED, &dev->flags) ||
Stanislaw Gruszka64bf69d2005-11-29 16:16:41 -0800404 (error = find_ci(vcc, &vpi, &vci))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 write_unlock_irq(&vcc_sklist_lock);
406 goto fail_module_put;
407 }
408 vcc->vpi = vpi;
409 vcc->vci = vci;
410 __vcc_insert_socket(sk);
411 write_unlock_irq(&vcc_sklist_lock);
412 switch (vcc->qos.aal) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000413 case ATM_AAL0:
414 error = atm_init_aal0(vcc);
415 vcc->stats = &dev->stats.aal0;
416 break;
417 case ATM_AAL34:
418 error = atm_init_aal34(vcc);
419 vcc->stats = &dev->stats.aal34;
420 break;
421 case ATM_NO_AAL:
422 /* ATM_AAL5 is also used in the "0 for default" case */
423 vcc->qos.aal = ATM_AAL5;
424 /* fall through */
425 case ATM_AAL5:
426 error = atm_init_aal5(vcc);
427 vcc->stats = &dev->stats.aal5;
428 break;
429 default:
430 error = -EPROTOTYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000432 if (!error)
433 error = adjust_tp(&vcc->qos.txtp, vcc->qos.aal);
434 if (!error)
435 error = adjust_tp(&vcc->qos.rxtp, vcc->qos.aal);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 if (error)
437 goto fail;
Joe Perches99824462010-01-26 11:40:00 +0000438 pr_debug("VCC %d.%d, AAL %d\n", vpi, vci, vcc->qos.aal);
439 pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",
440 vcc->qos.txtp.traffic_class,
441 vcc->qos.txtp.min_pcr,
442 vcc->qos.txtp.max_pcr,
443 vcc->qos.txtp.max_sdu);
444 pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",
445 vcc->qos.rxtp.traffic_class,
446 vcc->qos.rxtp.min_pcr,
447 vcc->qos.rxtp.max_pcr,
448 vcc->qos.rxtp.max_sdu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 if (dev->ops->open) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000451 error = dev->ops->open(vcc);
452 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 goto fail;
454 }
455 return 0;
456
457fail:
458 vcc_remove_socket(sk);
459fail_module_put:
460 module_put(dev->ops->owner);
461 /* ensure we get dev module ref count correct */
462 vcc->dev = NULL;
463 return error;
464}
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
467{
468 struct atm_dev *dev;
469 struct atm_vcc *vcc = ATM_SD(sock);
470 int error;
471
Joe Perches99824462010-01-26 11:40:00 +0000472 pr_debug("(vpi %d, vci %d)\n", vpi, vci);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 if (sock->state == SS_CONNECTED)
474 return -EISCONN;
475 if (sock->state != SS_UNCONNECTED)
476 return -EINVAL;
477 if (!(vpi || vci))
478 return -EINVAL;
479
480 if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC)
Joe Perchesa8147d72010-01-26 11:40:06 +0000481 clear_bit(ATM_VF_PARTIAL, &vcc->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 else
Joe Perchesa8147d72010-01-26 11:40:06 +0000483 if (test_bit(ATM_VF_PARTIAL, &vcc->flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 return -EINVAL;
Joe Perches99824462010-01-26 11:40:00 +0000485 pr_debug("(TX: cl %d,bw %d-%d,sdu %d; "
486 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
487 vcc->qos.txtp.traffic_class, vcc->qos.txtp.min_pcr,
488 vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_sdu,
489 vcc->qos.rxtp.traffic_class, vcc->qos.rxtp.min_pcr,
Joe Perchesa8147d72010-01-26 11:40:06 +0000490 vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_sdu,
Joe Perches99824462010-01-26 11:40:00 +0000491 vcc->qos.aal == ATM_AAL5 ? "" :
492 vcc->qos.aal == ATM_AAL0 ? "" : " ??? code ",
493 vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
495 return -EBADFD;
496 if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
497 vcc->qos.rxtp.traffic_class == ATM_ANYCLASS)
498 return -EINVAL;
Mitchell Blank Jrc9933d02005-11-29 16:13:32 -0800499 if (likely(itf != ATM_ITF_ANY)) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000500 dev = try_then_request_module(atm_dev_lookup(itf),
501 "atm-device-%d", itf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 dev = NULL;
Ingo Molnar57b47a52006-03-20 22:35:41 -0800504 mutex_lock(&atm_dev_mutex);
Mitchell Blank Jrc9933d02005-11-29 16:13:32 -0800505 if (!list_empty(&atm_devs)) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000506 dev = list_entry(atm_devs.next,
507 struct atm_dev, dev_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 atm_dev_hold(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
Ingo Molnar57b47a52006-03-20 22:35:41 -0800510 mutex_unlock(&atm_dev_mutex);
Mitchell Blank Jrc9933d02005-11-29 16:13:32 -0800511 }
512 if (!dev)
513 return -ENODEV;
514 error = __vcc_connect(vcc, dev, vpi, vci);
515 if (error) {
516 atm_dev_put(dev);
517 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
519 if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
Joe Perchesa8147d72010-01-26 11:40:06 +0000520 set_bit(ATM_VF_PARTIAL, &vcc->flags);
521 if (test_bit(ATM_VF_READY, &ATM_SD(sock)->flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 sock->state = SS_CONNECTED;
523 return 0;
524}
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
527 size_t size, int flags)
528{
529 struct sock *sk = sock->sk;
530 struct atm_vcc *vcc;
531 struct sk_buff *skb;
532 int copied, error = -EINVAL;
533
534 if (sock->state != SS_CONNECTED)
535 return -ENOTCONN;
Jorge Boncompte [DTI2]40ba8492011-11-21 10:25:58 +0000536
537 /* only handle MSG_DONTWAIT and MSG_PEEK */
538 if (flags & ~(MSG_DONTWAIT | MSG_PEEK))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 return -EOPNOTSUPP;
Jorge Boncompte [DTI2]40ba8492011-11-21 10:25:58 +0000540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 vcc = ATM_SD(sock);
Joe Perchesa8147d72010-01-26 11:40:06 +0000542 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
543 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 !test_bit(ATM_VF_READY, &vcc->flags))
545 return 0;
546
547 skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &error);
548 if (!skb)
549 return error;
550
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900551 copied = skb->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (copied > size) {
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900553 copied = size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 msg->msg_flags |= MSG_TRUNC;
555 }
556
David S. Miller51f3d022014-11-05 16:46:40 -0500557 error = skb_copy_datagram_msg(skb, 0, msg, copied);
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900558 if (error)
559 return error;
Neil Horman3b885782009-10-12 13:26:31 -0700560 sock_recv_ts_and_drops(msg, sk, skb);
Jorge Boncompte [DTI2]40ba8492011-11-21 10:25:58 +0000561
562 if (!(flags & MSG_PEEK)) {
563 pr_debug("%d -= %d\n", atomic_read(&sk->sk_rmem_alloc),
564 skb->truesize);
565 atm_return(vcc, skb->truesize);
566 }
567
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900568 skb_free_datagram(sk, skb);
569 return copied;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570}
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m,
Al Viro7424ce62014-11-20 07:01:29 -0500573 size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
575 struct sock *sk = sock->sk;
576 DEFINE_WAIT(wait);
577 struct atm_vcc *vcc;
578 struct sk_buff *skb;
Joe Perchesa8147d72010-01-26 11:40:06 +0000579 int eff, error;
Al Viro7424ce62014-11-20 07:01:29 -0500580 struct iov_iter from;
581
582 iov_iter_init(&from, WRITE, m->msg_iov, m->msg_iovlen, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 lock_sock(sk);
585 if (sock->state != SS_CONNECTED) {
586 error = -ENOTCONN;
587 goto out;
588 }
589 if (m->msg_name) {
590 error = -EISCONN;
591 goto out;
592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 vcc = ATM_SD(sock);
594 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
595 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
596 !test_bit(ATM_VF_READY, &vcc->flags)) {
597 error = -EPIPE;
598 send_sig(SIGPIPE, current, 0);
599 goto out;
600 }
601 if (!size) {
602 error = 0;
603 goto out;
604 }
Al Viro7424ce62014-11-20 07:01:29 -0500605 if (size > vcc->qos.txtp.max_sdu) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 error = -EMSGSIZE;
607 goto out;
608 }
Jesper Juhle49332b2005-05-01 08:59:08 -0700609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 eff = (size+3) & ~3; /* align to word boundary */
Eric Dumazetaa395142010-04-20 13:03:51 +0000611 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 error = 0;
Joe Perchesa8147d72010-01-26 11:40:06 +0000613 while (!(skb = alloc_tx(vcc, eff))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 if (m->msg_flags & MSG_DONTWAIT) {
615 error = -EAGAIN;
616 break;
617 }
618 schedule();
619 if (signal_pending(current)) {
620 error = -ERESTARTSYS;
621 break;
622 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000623 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
624 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
625 !test_bit(ATM_VF_READY, &vcc->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 error = -EPIPE;
627 send_sig(SIGPIPE, current, 0);
628 break;
629 }
Eric Dumazetaa395142010-04-20 13:03:51 +0000630 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
Eric Dumazetaa395142010-04-20 13:03:51 +0000632 finish_wait(sk_sleep(sk), &wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 if (error)
634 goto out;
635 skb->dev = NULL; /* for paths shared with net_device interfaces */
636 ATM_SKB(skb)->atm_options = vcc->atm_options;
Al Viro7424ce62014-11-20 07:01:29 -0500637 if (copy_from_iter(skb_put(skb, size), size, &from) != size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 kfree_skb(skb);
639 error = -EFAULT;
640 goto out;
641 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000642 if (eff != size)
643 memset(skb->data + size, 0, eff-size);
644 error = vcc->dev->ops->send(vcc, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 error = error ? error : size;
646out:
647 release_sock(sk);
648 return error;
649}
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait)
652{
653 struct sock *sk = sock->sk;
654 struct atm_vcc *vcc;
655 unsigned int mask;
656
Eric Dumazetaa395142010-04-20 13:03:51 +0000657 sock_poll_wait(file, sk_sleep(sk), wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 mask = 0;
659
660 vcc = ATM_SD(sock);
661
662 /* exceptional events */
663 if (sk->sk_err)
664 mask = POLLERR;
665
666 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
667 test_bit(ATM_VF_CLOSE, &vcc->flags))
668 mask |= POLLHUP;
669
670 /* readable? */
671 if (!skb_queue_empty(&sk->sk_receive_queue))
672 mask |= POLLIN | POLLRDNORM;
673
674 /* writable? */
675 if (sock->state == SS_CONNECTING &&
676 test_bit(ATM_VF_WAITING, &vcc->flags))
677 return mask;
678
679 if (vcc->qos.txtp.traffic_class != ATM_NONE &&
680 vcc_writable(sk))
681 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
682
683 return mask;
684}
685
Joe Perchesa8147d72010-01-26 11:40:06 +0000686static int atm_change_qos(struct atm_vcc *vcc, struct atm_qos *qos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 int error;
689
690 /*
691 * Don't let the QoS change the already connected AAL type nor the
692 * traffic class.
693 */
694 if (qos->aal != vcc->qos.aal ||
695 qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class ||
696 qos->txtp.traffic_class != vcc->qos.txtp.traffic_class)
697 return -EINVAL;
Joe Perchesa8147d72010-01-26 11:40:06 +0000698 error = adjust_tp(&qos->txtp, qos->aal);
699 if (!error)
700 error = adjust_tp(&qos->rxtp, qos->aal);
701 if (error)
702 return error;
703 if (!vcc->dev->ops->change_qos)
704 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 if (sk_atm(vcc)->sk_family == AF_ATMPVC)
Joe Perchesa8147d72010-01-26 11:40:06 +0000706 return vcc->dev->ops->change_qos(vcc, qos, ATM_MF_SET);
707 return svc_change_qos(vcc, qos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
709
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700710static int check_tp(const struct atm_trafprm *tp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
712 /* @@@ Should be merged with adjust_tp */
Joe Perchesa8147d72010-01-26 11:40:06 +0000713 if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS)
714 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
Joe Perchesa8147d72010-01-26 11:40:06 +0000716 !tp->max_pcr)
717 return -EINVAL;
718 if (tp->min_pcr == ATM_MAX_PCR)
719 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR &&
Joe Perchesa8147d72010-01-26 11:40:06 +0000721 tp->min_pcr > tp->max_pcr)
722 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 /*
724 * We allow pcr to be outside [min_pcr,max_pcr], because later
725 * adjustment may still push it in the valid range.
726 */
727 return 0;
728}
729
Mitchell Blank Jr61c33e02008-06-17 16:20:06 -0700730static int check_qos(const struct atm_qos *qos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
732 int error;
733
734 if (!qos->txtp.traffic_class && !qos->rxtp.traffic_class)
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +0900735 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
737 qos->txtp.traffic_class && qos->rxtp.traffic_class &&
738 qos->txtp.traffic_class != ATM_ANYCLASS &&
Joe Perchesa8147d72010-01-26 11:40:06 +0000739 qos->rxtp.traffic_class != ATM_ANYCLASS)
740 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 error = check_tp(&qos->txtp);
Joe Perchesa8147d72010-01-26 11:40:06 +0000742 if (error)
743 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 return check_tp(&qos->rxtp);
745}
746
747int vcc_setsockopt(struct socket *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -0700748 char __user *optval, unsigned int optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
750 struct atm_vcc *vcc;
751 unsigned long value;
752 int error;
753
754 if (__SO_LEVEL_MATCH(optname, level) && optlen != __SO_SIZE(optname))
755 return -EINVAL;
756
757 vcc = ATM_SD(sock);
758 switch (optname) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000759 case SO_ATMQOS:
760 {
761 struct atm_qos qos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Joe Perchesa8147d72010-01-26 11:40:06 +0000763 if (copy_from_user(&qos, optval, sizeof(qos)))
764 return -EFAULT;
765 error = check_qos(&qos);
766 if (error)
767 return error;
768 if (sock->state == SS_CONNECTED)
769 return atm_change_qos(vcc, &qos);
770 if (sock->state != SS_UNCONNECTED)
771 return -EBADFD;
772 vcc->qos = qos;
773 set_bit(ATM_VF_HASQOS, &vcc->flags);
774 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000776 case SO_SETCLP:
777 if (get_user(value, (unsigned long __user *)optval))
778 return -EFAULT;
779 if (value)
780 vcc->atm_options |= ATM_ATMOPT_CLP;
781 else
782 vcc->atm_options &= ~ATM_ATMOPT_CLP;
783 return 0;
784 default:
785 if (level == SOL_SOCKET)
786 return -EINVAL;
787 break;
788 }
789 if (!vcc->dev || !vcc->dev->ops->setsockopt)
790 return -EINVAL;
791 return vcc->dev->ops->setsockopt(vcc, level, optname, optval, optlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794int vcc_getsockopt(struct socket *sock, int level, int optname,
795 char __user *optval, int __user *optlen)
796{
797 struct atm_vcc *vcc;
798 int len;
799
800 if (get_user(len, optlen))
801 return -EFAULT;
802 if (__SO_LEVEL_MATCH(optname, level) && len != __SO_SIZE(optname))
803 return -EINVAL;
804
805 vcc = ATM_SD(sock);
806 switch (optname) {
Joe Perchesa8147d72010-01-26 11:40:06 +0000807 case SO_ATMQOS:
808 if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
809 return -EINVAL;
810 return copy_to_user(optval, &vcc->qos, sizeof(vcc->qos))
811 ? -EFAULT : 0;
812 case SO_SETCLP:
813 return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : 0,
814 (unsigned long __user *)optval) ? -EFAULT : 0;
815 case SO_ATMPVC:
816 {
817 struct sockaddr_atmpvc pvc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
Joe Perchesa8147d72010-01-26 11:40:06 +0000819 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
820 return -ENOTCONN;
Mathias Krausee862f1a2012-08-15 11:31:44 +0000821 memset(&pvc, 0, sizeof(pvc));
Joe Perchesa8147d72010-01-26 11:40:06 +0000822 pvc.sap_family = AF_ATMPVC;
823 pvc.sap_addr.itf = vcc->dev->number;
824 pvc.sap_addr.vpi = vcc->vpi;
825 pvc.sap_addr.vci = vcc->vci;
826 return copy_to_user(optval, &pvc, sizeof(pvc)) ? -EFAULT : 0;
827 }
828 default:
829 if (level == SOL_SOCKET)
830 return -EINVAL;
Julia Lawall510a05e2010-08-05 10:19:00 +0000831 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000833 if (!vcc->dev || !vcc->dev->ops->getsockopt)
834 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len);
836}
837
Karl Hiramoto7313bb82010-07-08 20:55:30 +0000838int register_atmdevice_notifier(struct notifier_block *nb)
839{
840 return atomic_notifier_chain_register(&atm_dev_notify_chain, nb);
841}
842EXPORT_SYMBOL_GPL(register_atmdevice_notifier);
843
844void unregister_atmdevice_notifier(struct notifier_block *nb)
845{
846 atomic_notifier_chain_unregister(&atm_dev_notify_chain, nb);
847}
848EXPORT_SYMBOL_GPL(unregister_atmdevice_notifier);
849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850static int __init atm_init(void)
851{
852 int error;
853
Joe Perchesa8147d72010-01-26 11:40:06 +0000854 error = proto_register(&vcc_proto, 0);
855 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 goto out;
Joe Perchesa8147d72010-01-26 11:40:06 +0000857 error = atmpvc_init();
858 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000859 pr_err("atmpvc_init() failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 goto out_unregister_vcc_proto;
861 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000862 error = atmsvc_init();
863 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000864 pr_err("atmsvc_init() failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 goto out_atmpvc_exit;
866 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000867 error = atm_proc_init();
868 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000869 pr_err("atm_proc_init() failed with %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 goto out_atmsvc_exit;
871 }
Joe Perchesa8147d72010-01-26 11:40:06 +0000872 error = atm_sysfs_init();
873 if (error < 0) {
Joe Perches99824462010-01-26 11:40:00 +0000874 pr_err("atm_sysfs_init() failed with %d\n", error);
Roman Kagan656d98b2006-06-29 12:36:34 -0700875 goto out_atmproc_exit;
876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877out:
878 return error;
Roman Kagan656d98b2006-06-29 12:36:34 -0700879out_atmproc_exit:
880 atm_proc_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881out_atmsvc_exit:
882 atmsvc_exit();
883out_atmpvc_exit:
884 atmsvc_exit();
885out_unregister_vcc_proto:
886 proto_unregister(&vcc_proto);
887 goto out;
888}
889
890static void __exit atm_exit(void)
891{
892 atm_proc_exit();
Roman Kagan656d98b2006-06-29 12:36:34 -0700893 atm_sysfs_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 atmsvc_exit();
895 atmpvc_exit();
896 proto_unregister(&vcc_proto);
897}
898
Daniel Walker84ff6022007-02-05 18:04:06 -0800899subsys_initcall(atm_init);
900
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901module_exit(atm_exit);
902
903MODULE_LICENSE("GPL");
904MODULE_ALIAS_NETPROTO(PF_ATMPVC);
905MODULE_ALIAS_NETPROTO(PF_ATMSVC);