Lines Matching refs:sk

48 	struct sock sk; /* must be first member */  member
87 static void caif_read_lock(struct sock *sk) in caif_read_lock() argument
90 cf_sk = container_of(sk, struct caifsock, sk); in caif_read_lock()
94 static void caif_read_unlock(struct sock *sk) in caif_read_unlock() argument
97 cf_sk = container_of(sk, struct caifsock, sk); in caif_read_unlock()
104 return cf_sk->sk.sk_rcvbuf / 4; in sk_rcvbuf_lowwater()
107 static void caif_flow_ctrl(struct sock *sk, int mode) in caif_flow_ctrl() argument
110 cf_sk = container_of(sk, struct caifsock, sk); in caif_flow_ctrl()
119 static void caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) in caif_queue_rcv_skb() argument
123 struct sk_buff_head *list = &sk->sk_receive_queue; in caif_queue_rcv_skb()
124 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); in caif_queue_rcv_skb()
127 if (atomic_read(&sk->sk_rmem_alloc) + skb->truesize >= in caif_queue_rcv_skb()
128 (unsigned int)sk->sk_rcvbuf && rx_flow_is_on(cf_sk)) { in caif_queue_rcv_skb()
130 atomic_read(&cf_sk->sk.sk_rmem_alloc), in caif_queue_rcv_skb()
133 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ); in caif_queue_rcv_skb()
136 err = sk_filter(sk, skb); in caif_queue_rcv_skb()
140 if (!sk_rmem_schedule(sk, skb, skb->truesize) && rx_flow_is_on(cf_sk)) { in caif_queue_rcv_skb()
143 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ); in caif_queue_rcv_skb()
146 skb_set_owner_r(skb, sk); in caif_queue_rcv_skb()
148 queued = !sock_flag(sk, SOCK_DEAD); in caif_queue_rcv_skb()
154 sk->sk_data_ready(sk); in caif_queue_rcv_skb()
168 if (unlikely(cf_sk->sk.sk_state != CAIF_CONNECTED)) { in caif_sktrecv_cb()
172 caif_queue_rcv_skb(&cf_sk->sk, skb); in caif_sktrecv_cb()
179 sock_hold(&cf_sk->sk); in cfsk_hold()
185 sock_put(&cf_sk->sk); in cfsk_put()
198 cf_sk->sk.sk_state_change(&cf_sk->sk); in caif_ctrl_cb()
204 cf_sk->sk.sk_state_change(&cf_sk->sk); in caif_ctrl_cb()
211 cf_sk->sk.sk_state = CAIF_CONNECTED; in caif_ctrl_cb()
213 cf_sk->sk.sk_shutdown = 0; in caif_ctrl_cb()
214 cf_sk->sk.sk_state_change(&cf_sk->sk); in caif_ctrl_cb()
219 cf_sk->sk.sk_state = CAIF_DISCONNECTED; in caif_ctrl_cb()
220 cf_sk->sk.sk_state_change(&cf_sk->sk); in caif_ctrl_cb()
225 cf_sk->sk.sk_err = ECONNREFUSED; in caif_ctrl_cb()
226 cf_sk->sk.sk_state = CAIF_DISCONNECTED; in caif_ctrl_cb()
227 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK; in caif_ctrl_cb()
233 cf_sk->sk.sk_state_change(&cf_sk->sk); in caif_ctrl_cb()
238 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK; in caif_ctrl_cb()
239 cf_sk->sk.sk_err = ECONNRESET; in caif_ctrl_cb()
241 sk_error_report(&cf_sk->sk); in caif_ctrl_cb()
249 static void caif_check_flow_release(struct sock *sk) in caif_check_flow_release() argument
251 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); in caif_check_flow_release()
256 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) { in caif_check_flow_release()
258 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ); in caif_check_flow_release()
270 struct sock *sk = sock->sk; in caif_seqpkt_recvmsg() local
279 skb = skb_recv_datagram(sk, flags, &ret); in caif_seqpkt_recvmsg()
294 skb_free_datagram(sk, skb); in caif_seqpkt_recvmsg()
295 caif_check_flow_release(sk); in caif_seqpkt_recvmsg()
304 static long caif_stream_data_wait(struct sock *sk, long timeo) in caif_stream_data_wait() argument
307 lock_sock(sk); in caif_stream_data_wait()
310 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); in caif_stream_data_wait()
312 if (!skb_queue_empty(&sk->sk_receive_queue) || in caif_stream_data_wait()
313 sk->sk_err || in caif_stream_data_wait()
314 sk->sk_state != CAIF_CONNECTED || in caif_stream_data_wait()
315 sock_flag(sk, SOCK_DEAD) || in caif_stream_data_wait()
316 (sk->sk_shutdown & RCV_SHUTDOWN) || in caif_stream_data_wait()
321 sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); in caif_stream_data_wait()
322 release_sock(sk); in caif_stream_data_wait()
324 lock_sock(sk); in caif_stream_data_wait()
326 if (sock_flag(sk, SOCK_DEAD)) in caif_stream_data_wait()
329 sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); in caif_stream_data_wait()
332 finish_wait(sk_sleep(sk), &wait); in caif_stream_data_wait()
333 release_sock(sk); in caif_stream_data_wait()
345 struct sock *sk = sock->sk; in caif_stream_recvmsg() local
360 if (sk->sk_state == CAIF_CONNECTING) in caif_stream_recvmsg()
363 caif_read_lock(sk); in caif_stream_recvmsg()
364 target = sock_rcvlowat(sk, flags&MSG_WAITALL, size); in caif_stream_recvmsg()
365 timeo = sock_rcvtimeo(sk, flags&MSG_DONTWAIT); in caif_stream_recvmsg()
371 lock_sock(sk); in caif_stream_recvmsg()
372 if (sock_flag(sk, SOCK_DEAD)) { in caif_stream_recvmsg()
376 skb = skb_dequeue(&sk->sk_receive_queue); in caif_stream_recvmsg()
377 caif_check_flow_release(sk); in caif_stream_recvmsg()
385 err = sock_error(sk); in caif_stream_recvmsg()
389 if (sk->sk_shutdown & RCV_SHUTDOWN) in caif_stream_recvmsg()
393 if (sk->sk_state != CAIF_CONNECTED) in caif_stream_recvmsg()
395 if (sock_flag(sk, SOCK_DEAD)) in caif_stream_recvmsg()
398 release_sock(sk); in caif_stream_recvmsg()
404 caif_read_unlock(sk); in caif_stream_recvmsg()
406 timeo = caif_stream_data_wait(sk, timeo); in caif_stream_recvmsg()
412 caif_read_lock(sk); in caif_stream_recvmsg()
415 release_sock(sk); in caif_stream_recvmsg()
418 release_sock(sk); in caif_stream_recvmsg()
421 skb_queue_head(&sk->sk_receive_queue, skb); in caif_stream_recvmsg()
435 skb_queue_head(&sk->sk_receive_queue, skb); in caif_stream_recvmsg()
445 skb_queue_head(&sk->sk_receive_queue, skb); in caif_stream_recvmsg()
449 caif_read_unlock(sk); in caif_stream_recvmsg()
462 struct sock *sk = &cf_sk->sk; in caif_wait_for_flow_on() local
467 (!wait_writeable || sock_writeable(&cf_sk->sk))) in caif_wait_for_flow_on()
475 prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); in caif_wait_for_flow_on()
477 if (sk->sk_shutdown & SHUTDOWN_MASK) in caif_wait_for_flow_on()
479 *err = -sk->sk_err; in caif_wait_for_flow_on()
480 if (sk->sk_err) in caif_wait_for_flow_on()
483 if (cf_sk->sk.sk_state != CAIF_CONNECTED) in caif_wait_for_flow_on()
487 finish_wait(sk_sleep(sk), &wait); in caif_wait_for_flow_on()
502 cfpkt_set_prio(pkt, cf_sk->sk.sk_priority); in transmit_skb()
516 struct sock *sk = sock->sk; in caif_seqpkt_sendmsg() local
517 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); in caif_seqpkt_sendmsg()
524 ret = sock_error(sk); in caif_seqpkt_sendmsg()
542 timeo = sock_sndtimeo(sk, noblock); in caif_seqpkt_sendmsg()
543 timeo = caif_wait_for_flow_on(container_of(sk, struct caifsock, sk), in caif_seqpkt_sendmsg()
549 if (cf_sk->sk.sk_state != CAIF_CONNECTED || in caif_seqpkt_sendmsg()
550 sock_flag(sk, SOCK_DEAD) || in caif_seqpkt_sendmsg()
551 (sk->sk_shutdown & RCV_SHUTDOWN)) in caif_seqpkt_sendmsg()
556 if (len > cf_sk->maxframe && cf_sk->sk.sk_protocol != CAIFPROTO_RFM) in caif_seqpkt_sendmsg()
562 skb = sock_alloc_send_skb(sk, buffer_size, noblock, &ret); in caif_seqpkt_sendmsg()
592 struct sock *sk = sock->sk; in caif_stream_sendmsg() local
593 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); in caif_stream_sendmsg()
606 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); in caif_stream_sendmsg()
609 if (unlikely(sk->sk_shutdown & SEND_SHUTDOWN)) in caif_stream_sendmsg()
620 if (size > ((sk->sk_sndbuf >> 1) - 64)) in caif_stream_sendmsg()
621 size = (sk->sk_sndbuf >> 1) - 64; in caif_stream_sendmsg()
626 skb = sock_alloc_send_skb(sk, in caif_stream_sendmsg()
671 struct sock *sk = sock->sk; in setsockopt() local
672 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); in setsockopt()
675 if (cf_sk->sk.sk_socket->state != SS_UNCONNECTED) in setsockopt()
686 lock_sock(&(cf_sk->sk)); in setsockopt()
688 release_sock(&cf_sk->sk); in setsockopt()
694 if (cf_sk->sk.sk_protocol != CAIFPROTO_UTIL) in setsockopt()
696 lock_sock(&(cf_sk->sk)); in setsockopt()
699 release_sock(&cf_sk->sk); in setsockopt()
703 release_sock(&cf_sk->sk); in setsockopt()
743 struct sock *sk = sock->sk; in caif_connect() local
744 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); in caif_connect()
751 lock_sock(sk); in caif_connect()
764 caif_assert(sk->sk_state == CAIF_DISCONNECTED); in caif_connect()
767 switch (sk->sk_state) { in caif_connect()
783 caif_assert(sk->sk_state == CAIF_CONNECTED || in caif_connect()
784 sk->sk_state == CAIF_DISCONNECTED); in caif_connect()
785 if (sk->sk_shutdown & SHUTDOWN_MASK) { in caif_connect()
787 caif_disconnect_client(sock_net(sk), &cf_sk->layer); in caif_connect()
799 sk->sk_state = CAIF_DISCONNECTED; in caif_connect()
801 sk_stream_kill_queues(&cf_sk->sk); in caif_connect()
812 sk->sk_state = CAIF_CONNECTING; in caif_connect()
816 if (cf_sk->sk.sk_priority > CAIF_PRIO_MAX) in caif_connect()
818 else if (cf_sk->sk.sk_priority < CAIF_PRIO_MIN) in caif_connect()
821 cf_sk->conn_req.priority = cf_sk->sk.sk_priority; in caif_connect()
824 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if; in caif_connect()
828 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req, in caif_connect()
832 cf_sk->sk.sk_socket->state = SS_UNCONNECTED; in caif_connect()
833 cf_sk->sk.sk_state = CAIF_DISCONNECTED; in caif_connect()
839 dev = dev_get_by_index_rcu(sock_net(sk), ifindex); in caif_connect()
859 if (sk->sk_state != CAIF_CONNECTED && (flags & O_NONBLOCK)) in caif_connect()
862 timeo = sock_sndtimeo(sk, flags & O_NONBLOCK); in caif_connect()
864 release_sock(sk); in caif_connect()
866 timeo = wait_event_interruptible_timeout(*sk_sleep(sk), in caif_connect()
867 sk->sk_state != CAIF_CONNECTING, in caif_connect()
869 lock_sock(sk); in caif_connect()
874 if (timeo == 0 && sk->sk_state != CAIF_CONNECTED) in caif_connect()
876 if (sk->sk_state != CAIF_CONNECTED) { in caif_connect()
878 err = sock_error(sk); in caif_connect()
886 release_sock(sk); in caif_connect()
896 struct sock *sk = sock->sk; in caif_release() local
897 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); in caif_release()
899 if (!sk) in caif_release()
909 spin_lock_bh(&sk->sk_receive_queue.lock); in caif_release()
910 sock_set_flag(sk, SOCK_DEAD); in caif_release()
911 spin_unlock_bh(&sk->sk_receive_queue.lock); in caif_release()
912 sock->sk = NULL; in caif_release()
917 lock_sock(&(cf_sk->sk)); in caif_release()
918 sk->sk_state = CAIF_DISCONNECTED; in caif_release()
919 sk->sk_shutdown = SHUTDOWN_MASK; in caif_release()
921 caif_disconnect_client(sock_net(sk), &cf_sk->layer); in caif_release()
922 cf_sk->sk.sk_socket->state = SS_DISCONNECTING; in caif_release()
923 wake_up_interruptible_poll(sk_sleep(sk), EPOLLERR|EPOLLHUP); in caif_release()
925 sock_orphan(sk); in caif_release()
926 sk_stream_kill_queues(&cf_sk->sk); in caif_release()
927 release_sock(sk); in caif_release()
928 sock_put(sk); in caif_release()
936 struct sock *sk = sock->sk; in caif_poll() local
938 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); in caif_poll()
944 if (sk->sk_err) in caif_poll()
946 if (sk->sk_shutdown == SHUTDOWN_MASK) in caif_poll()
948 if (sk->sk_shutdown & RCV_SHUTDOWN) in caif_poll()
952 if (!skb_queue_empty_lockless(&sk->sk_receive_queue) || in caif_poll()
953 (sk->sk_shutdown & RCV_SHUTDOWN)) in caif_poll()
960 if (sock_writeable(sk) && tx_flow_is_on(cf_sk)) in caif_poll()
1007 static void caif_sock_destructor(struct sock *sk) in caif_sock_destructor() argument
1009 struct caifsock *cf_sk = container_of(sk, struct caifsock, sk); in caif_sock_destructor()
1010 caif_assert(!refcount_read(&sk->sk_wmem_alloc)); in caif_sock_destructor()
1011 caif_assert(sk_unhashed(sk)); in caif_sock_destructor()
1012 caif_assert(!sk->sk_socket); in caif_sock_destructor()
1013 if (!sock_flag(sk, SOCK_DEAD)) { in caif_sock_destructor()
1014 pr_debug("Attempt to release alive CAIF socket: %p\n", sk); in caif_sock_destructor()
1017 sk_stream_kill_queues(&cf_sk->sk); in caif_sock_destructor()
1024 struct sock *sk = NULL; in caif_create() local
1055 sk = sk_alloc(net, PF_CAIF, GFP_KERNEL, &prot, kern); in caif_create()
1056 if (!sk) in caif_create()
1059 cf_sk = container_of(sk, struct caifsock, sk); in caif_create()
1062 sk->sk_protocol = (unsigned char) protocol; in caif_create()
1067 sk->sk_priority = TC_PRIO_CONTROL; in caif_create()
1070 sk->sk_priority = TC_PRIO_INTERACTIVE_BULK; in caif_create()
1073 sk->sk_priority = TC_PRIO_BESTEFFORT; in caif_create()
1080 lock_sock(&(cf_sk->sk)); in caif_create()
1083 sock_init_data(sock, sk); in caif_create()
1084 sk->sk_destruct = caif_sock_destructor; in caif_create()
1088 cf_sk->sk.sk_socket->state = SS_UNCONNECTED; in caif_create()
1089 cf_sk->sk.sk_state = CAIF_DISCONNECTED; in caif_create()
1097 release_sock(&cf_sk->sk); in caif_create()