5 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
7 #include <linux/module.h>
10 #include <linux/atm.h>
11 #include <linux/atmdev.h>
12 #include <linux/socket.h>
13 #include <linux/errno.h>
14 #include <linux/capability.h>
16 #include <linux/sched.h>
17 #include <linux/time.h>
19 #include <linux/bitops.h>
21 #include <linux/slab.h>
24 #include <linux/poll.h>
42 static void __vcc_insert_socket(
struct sock *
sk)
47 sk_add_node(sk, head);
53 __vcc_insert_socket(sk);
58 static void vcc_remove_socket(
struct sock *
sk)
68 struct sock *
sk = sk_atm(vcc);
70 if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) {
71 pr_debug(
"Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
72 sk_wmem_alloc_get(sk), size, sk->
sk_sndbuf);
82 static void vcc_sock_destruct(
struct sock *sk)
93 static void vcc_def_wakeup(
struct sock *sk)
99 if (wq_has_sleeper(wq))
104 static inline int vcc_writable(
struct sock *sk)
106 struct atm_vcc *vcc = atm_sk(sk);
108 return (vcc->
qos.txtp.max_sdu +
112 static void vcc_write_space(
struct sock *sk)
118 if (vcc_writable(sk)) {
120 if (wq_has_sleeper(wq))
129 static struct proto vcc_proto = {
132 .obj_size =
sizeof(
struct atm_vcc),
154 vcc->
qos.txtp.max_sdu = 1 << 16;
166 static void vcc_destroy_socket(
struct sock *sk)
168 struct atm_vcc *vcc = atm_sk(sk);
174 if (vcc->
dev->ops->close)
175 vcc->
dev->ops->close(vcc);
184 module_put(vcc->
dev->ops->owner);
185 atm_dev_put(vcc->
dev);
188 vcc_remove_socket(sk);
193 struct sock *sk = sock->
sk;
197 vcc_destroy_socket(sock->
sk);
207 struct sock *sk = sk_atm(vcc);
223 __skb_queue_head_init(&queue);
224 rq = &sk_atm(vcc)->sk_receive_queue;
227 skb_queue_splice_init(rq, &queue);
228 spin_unlock_irqrestore(&rq->
lock, flags);
230 skb_queue_walk_safe(&queue, skb, tmp) {
231 __skb_unlink(skb, &queue);
239 pr_debug(
"%s signal=%d dev=%p number=%d dev->signal=%d\n",
245 if (dev->
signal == signal)
267 if (vcc->
dev == dev) {
277 static int adjust_tp(
struct atm_trafprm *tp,
unsigned char aal)
298 else if (tp->
max_sdu > max_sdu)
305 static int check_ci(
const struct atm_vcc *vcc,
short vpi,
int vci)
314 if (walk->
dev != vcc->
dev)
317 walk->
vci == vci && ((walk->
qos.txtp.traffic_class !=
331 static int find_ci(
const struct atm_vcc *vcc,
short *vpi,
int *vci)
340 err = check_ci(vcc, *vpi, *vci);
346 else if (p >= 1 << vcc->
dev->ci_range.vpi_bits)
350 else if (c < ATM_NOT_RSV_VCI || c >= 1 << vcc->
dev->ci_range.vci_bits)
355 if (!check_ci(vcc, p, c)) {
362 if (c >= 1 << vcc->
dev->ci_range.vci_bits)
368 if (p >= 1 << vcc->
dev->ci_range.vpi_bits)
371 }
while (old_p != p || old_c != c);
378 struct sock *sk = sk_atm(vcc);
388 if (!try_module_get(dev->
ops->owner))
393 (error = find_ci(vcc, &vpi, &vci))) {
395 goto fail_module_put;
399 __vcc_insert_socket(sk);
401 switch (vcc->
qos.aal) {
422 error = adjust_tp(&vcc->
qos.txtp, vcc->
qos.aal);
424 error = adjust_tp(&vcc->
qos.rxtp, vcc->
qos.aal);
427 pr_debug(
"VCC %d.%d, AAL %d\n", vpi, vci, vcc->
qos.aal);
428 pr_debug(
" TX: %d, PCR %d..%d, SDU %d\n",
429 vcc->
qos.txtp.traffic_class,
430 vcc->
qos.txtp.min_pcr,
431 vcc->
qos.txtp.max_pcr,
432 vcc->
qos.txtp.max_sdu);
433 pr_debug(
" RX: %d, PCR %d..%d, SDU %d\n",
434 vcc->
qos.rxtp.traffic_class,
435 vcc->
qos.rxtp.min_pcr,
436 vcc->
qos.rxtp.max_pcr,
437 vcc->
qos.rxtp.max_sdu);
439 if (dev->
ops->open) {
440 error = dev->
ops->open(vcc);
447 vcc_remove_socket(sk);
449 module_put(dev->
ops->owner);
458 struct atm_vcc *vcc = ATM_SD(sock);
461 pr_debug(
"(vpi %d, vci %d)\n", vpi, vci);
474 pr_debug(
"(TX: cl %d,bw %d-%d,sdu %d; "
475 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
476 vcc->
qos.txtp.traffic_class, vcc->
qos.txtp.min_pcr,
477 vcc->
qos.txtp.max_pcr, vcc->
qos.txtp.max_sdu,
478 vcc->
qos.rxtp.traffic_class, vcc->
qos.rxtp.min_pcr,
479 vcc->
qos.rxtp.max_pcr, vcc->
qos.rxtp.max_sdu,
490 "atm-device-%d", itf);
503 error = __vcc_connect(vcc, dev, vpi, vci);
516 size_t size,
int flags)
518 struct sock *sk = sock->
sk;
521 int copied, error = -
EINVAL;
549 sock_recv_ts_and_drops(msg, sk, skb);
564 struct sock *sk = sock->
sk;
599 if (size < 0 || size > vcc->
qos.txtp.max_sdu) {
607 while (!(skb = alloc_tx(vcc, eff))) {
638 error = vcc->
dev->ops->send(vcc, skb);
639 error = error ? error :
size;
647 struct sock *sk = sock->
sk;
651 sock_poll_wait(file, sk_sleep(sk), wait);
688 if (qos->aal != vcc->
qos.aal ||
689 qos->rxtp.traffic_class != vcc->
qos.rxtp.traffic_class ||
690 qos->
txtp.traffic_class != vcc->
qos.txtp.traffic_class)
692 error = adjust_tp(&qos->
txtp, qos->aal);
694 error = adjust_tp(&qos->rxtp, qos->aal);
697 if (!vcc->
dev->ops->change_qos)
724 static int check_qos(
const struct atm_qos *qos)
728 if (!qos->
txtp.traffic_class && !qos->rxtp.traffic_class)
730 if (qos->
txtp.traffic_class != qos->rxtp.traffic_class &&
731 qos->
txtp.traffic_class && qos->rxtp.traffic_class &&
735 error = check_tp(&qos->
txtp);
738 return check_tp(&qos->rxtp);
742 char __user *optval,
unsigned int optlen)
759 error = check_qos(&qos);
763 return atm_change_qos(vcc, &qos);
783 if (!vcc->
dev || !vcc->
dev->ops->setsockopt)
785 return vcc->
dev->ops->setsockopt(vcc, level, optname, optval, optlen);
789 char __user *optval,
int __user *optlen)
815 memset(&pvc, 0,
sizeof(pvc));
817 pvc.sap_addr.
itf = vcc->
dev->number;
818 pvc.sap_addr.
vpi = vcc->
vpi;
819 pvc.sap_addr.
vci = vcc->
vci;
827 if (!vcc->
dev || !vcc->
dev->ops->getsockopt)
829 return vcc->
dev->ops->getsockopt(vcc, level, optname, optval, len);
844 static int __init atm_init(
void)
853 pr_err(
"atmpvc_init() failed with %d\n", error);
854 goto out_unregister_vcc_proto;
858 pr_err(
"atmsvc_init() failed with %d\n", error);
859 goto out_atmpvc_exit;
863 pr_err(
"atm_proc_init() failed with %d\n", error);
864 goto out_atmsvc_exit;
868 pr_err(
"atm_sysfs_init() failed with %d\n", error);
869 goto out_atmproc_exit;
879 out_unregister_vcc_proto:
884 static void __exit atm_exit(
void)