Lines Matching +full:data +full:- +full:active

1 // SPDX-License-Identifier: GPL-2.0-or-later
18 #include "pvcalls-front.h"
66 struct pvcalls_data data; member
71 } active; member
74 * Socket status, needs to be 64-bit aligned due to the
82 * Internal state-machine flags.
85 * flags needs to be 64-bit aligned due to the test_and_*
104 dev_get_drvdata(&pvcalls_front_dev->dev) == NULL) in pvcalls_enter_sock()
105 return ERR_PTR(-ENOTCONN); in pvcalls_enter_sock()
107 map = (struct sock_mapping *)sock->sk->sk_send_head; in pvcalls_enter_sock()
109 return ERR_PTR(-ENOTSOCK); in pvcalls_enter_sock()
112 atomic_inc(&map->refcount); in pvcalls_enter_sock()
120 map = (struct sock_mapping *)sock->sk->sk_send_head; in pvcalls_exit_sock()
121 atomic_dec(&map->refcount); in pvcalls_exit_sock()
127 *req_id = bedata->ring.req_prod_pvt & (RING_SIZE(&bedata->ring) - 1); in get_request()
128 if (RING_FULL(&bedata->ring) || in get_request()
129 bedata->rsp[*req_id].req_id != PVCALLS_INVALID_ID) in get_request()
130 return -EAGAIN; in get_request()
136 struct pvcalls_data_intf *intf = map->active.ring; in pvcalls_front_write_todo()
140 error = intf->out_error; in pvcalls_front_write_todo()
141 if (error == -ENOTCONN) in pvcalls_front_write_todo()
146 cons = intf->out_cons; in pvcalls_front_write_todo()
147 prod = intf->out_prod; in pvcalls_front_write_todo()
148 return !!(size - pvcalls_queued(prod, cons, size)); in pvcalls_front_write_todo()
153 struct pvcalls_data_intf *intf = map->active.ring; in pvcalls_front_read_todo()
157 cons = intf->in_cons; in pvcalls_front_read_todo()
158 prod = intf->in_prod; in pvcalls_front_read_todo()
159 error = intf->in_error; in pvcalls_front_read_todo()
177 bedata = dev_get_drvdata(&dev->dev); in pvcalls_front_event_handler()
184 while (RING_HAS_UNCONSUMED_RESPONSES(&bedata->ring)) { in pvcalls_front_event_handler()
185 rsp = RING_GET_RESPONSE(&bedata->ring, bedata->ring.rsp_cons); in pvcalls_front_event_handler()
187 req_id = rsp->req_id; in pvcalls_front_event_handler()
188 if (rsp->cmd == PVCALLS_POLL) { in pvcalls_front_event_handler()
190 rsp->u.poll.id; in pvcalls_front_event_handler()
193 (void *)&map->passive.flags); in pvcalls_front_event_handler()
201 (void *)&map->passive.flags); in pvcalls_front_event_handler()
203 dst = (uint8_t *)&bedata->rsp[req_id] + in pvcalls_front_event_handler()
204 sizeof(rsp->req_id); in pvcalls_front_event_handler()
205 src = (uint8_t *)rsp + sizeof(rsp->req_id); in pvcalls_front_event_handler()
206 memcpy(dst, src, sizeof(*rsp) - sizeof(rsp->req_id)); in pvcalls_front_event_handler()
208 * First copy the rest of the data, then req_id. It is in pvcalls_front_event_handler()
209 * paired with the barrier when accessing bedata->rsp. in pvcalls_front_event_handler()
212 bedata->rsp[req_id].req_id = req_id; in pvcalls_front_event_handler()
216 bedata->ring.rsp_cons++; in pvcalls_front_event_handler()
219 RING_FINAL_CHECK_FOR_RESPONSES(&bedata->ring, more); in pvcalls_front_event_handler()
223 wake_up(&bedata->inflight_req); in pvcalls_front_event_handler()
235 unbind_from_irqhandler(map->active.irq, map); in pvcalls_front_destroy_active()
238 spin_lock(&bedata->socket_lock); in pvcalls_front_destroy_active()
239 if (!list_empty(&map->list)) in pvcalls_front_destroy_active()
240 list_del_init(&map->list); in pvcalls_front_destroy_active()
241 spin_unlock(&bedata->socket_lock); in pvcalls_front_destroy_active()
245 gnttab_end_foreign_access(map->active.ring->ref[i], NULL); in pvcalls_front_destroy_active()
246 gnttab_end_foreign_access(map->active.ref, NULL); in pvcalls_front_destroy_active()
265 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_conn_handler()
284 if (sock->type != SOCK_STREAM) in pvcalls_front_socket()
285 return -EOPNOTSUPP; in pvcalls_front_socket()
290 return -EACCES; in pvcalls_front_socket()
292 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_socket()
297 return -ENOMEM; in pvcalls_front_socket()
300 spin_lock(&bedata->socket_lock); in pvcalls_front_socket()
305 spin_unlock(&bedata->socket_lock); in pvcalls_front_socket()
311 * sock->sk->sk_send_head is not used for ip sockets: reuse the in pvcalls_front_socket()
316 sock->sk->sk_send_head = (void *)map; in pvcalls_front_socket()
317 list_add_tail(&map->list, &bedata->socket_mappings); in pvcalls_front_socket()
319 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_socket()
320 req->req_id = req_id; in pvcalls_front_socket()
321 req->cmd = PVCALLS_SOCKET; in pvcalls_front_socket()
322 req->u.socket.id = (uintptr_t) map; in pvcalls_front_socket()
323 req->u.socket.domain = AF_INET; in pvcalls_front_socket()
324 req->u.socket.type = SOCK_STREAM; in pvcalls_front_socket()
325 req->u.socket.protocol = IPPROTO_IP; in pvcalls_front_socket()
327 bedata->ring.req_prod_pvt++; in pvcalls_front_socket()
328 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_socket()
329 spin_unlock(&bedata->socket_lock); in pvcalls_front_socket()
331 notify_remote_via_irq(bedata->irq); in pvcalls_front_socket()
333 wait_event(bedata->inflight_req, in pvcalls_front_socket()
334 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_socket()
338 ret = bedata->rsp[req_id].ret; in pvcalls_front_socket()
339 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_socket()
348 if (!map->active.ring) in free_active_ring()
351 free_pages_exact(map->active.data.in, in free_active_ring()
352 PAGE_SIZE << map->active.ring->ring_order); in free_active_ring()
353 free_page((unsigned long)map->active.ring); in free_active_ring()
360 map->active.ring = (struct pvcalls_data_intf *) in alloc_active_ring()
362 if (!map->active.ring) in alloc_active_ring()
365 map->active.ring->ring_order = PVCALLS_RING_ORDER; in alloc_active_ring()
371 map->active.data.in = bytes; in alloc_active_ring()
372 map->active.data.out = bytes + in alloc_active_ring()
379 return -ENOMEM; in alloc_active_ring()
385 int ret, irq = -1, i; in create_active()
388 init_waitqueue_head(&map->active.inflight_conn_req); in create_active()
390 bytes = map->active.data.in; in create_active()
392 map->active.ring->ref[i] = gnttab_grant_foreign_access( in create_active()
393 pvcalls_front_dev->otherend_id, in create_active()
396 map->active.ref = gnttab_grant_foreign_access( in create_active()
397 pvcalls_front_dev->otherend_id, in create_active()
398 pfn_to_gfn(virt_to_pfn((void *)map->active.ring)), 0); in create_active()
404 0, "pvcalls-frontend", map); in create_active()
410 map->active.irq = irq; in create_active()
411 map->active_socket = true; in create_active()
412 mutex_init(&map->active.in_mutex); in create_active()
413 mutex_init(&map->active.out_mutex); in create_active()
432 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) in pvcalls_front_connect()
433 return -EOPNOTSUPP; in pvcalls_front_connect()
439 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_connect()
452 spin_lock(&bedata->socket_lock); in pvcalls_front_connect()
455 spin_unlock(&bedata->socket_lock); in pvcalls_front_connect()
461 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_connect()
462 req->req_id = req_id; in pvcalls_front_connect()
463 req->cmd = PVCALLS_CONNECT; in pvcalls_front_connect()
464 req->u.connect.id = (uintptr_t)map; in pvcalls_front_connect()
465 req->u.connect.len = addr_len; in pvcalls_front_connect()
466 req->u.connect.flags = flags; in pvcalls_front_connect()
467 req->u.connect.ref = map->active.ref; in pvcalls_front_connect()
468 req->u.connect.evtchn = evtchn; in pvcalls_front_connect()
469 memcpy(req->u.connect.addr, addr, sizeof(*addr)); in pvcalls_front_connect()
471 map->sock = sock; in pvcalls_front_connect()
473 bedata->ring.req_prod_pvt++; in pvcalls_front_connect()
474 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_connect()
475 spin_unlock(&bedata->socket_lock); in pvcalls_front_connect()
478 notify_remote_via_irq(bedata->irq); in pvcalls_front_connect()
480 wait_event(bedata->inflight_req, in pvcalls_front_connect()
481 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_connect()
485 ret = bedata->rsp[req_id].ret; in pvcalls_front_connect()
486 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_connect()
493 struct pvcalls_data *data, in __write_ring() argument
501 error = intf->out_error; in __write_ring()
504 cons = intf->out_cons; in __write_ring()
505 prod = intf->out_prod; in __write_ring()
511 return -EINVAL; in __write_ring()
514 if (len > array_size - size) in __write_ring()
515 len = array_size - size; in __write_ring()
521 len = copy_from_iter(data->out + masked_prod, len, msg_iter); in __write_ring()
523 if (len > array_size - masked_prod) { in __write_ring()
524 int ret = copy_from_iter(data->out + masked_prod, in __write_ring()
525 array_size - masked_prod, msg_iter); in __write_ring()
526 if (ret != array_size - masked_prod) { in __write_ring()
530 len = ret + copy_from_iter(data->out, len - ret, msg_iter); in __write_ring()
532 len = copy_from_iter(data->out + masked_prod, len, msg_iter); in __write_ring()
538 intf->out_prod += len; in __write_ring()
550 flags = msg->msg_flags; in pvcalls_front_sendmsg()
552 return -EOPNOTSUPP; in pvcalls_front_sendmsg()
558 mutex_lock(&map->active.out_mutex); in pvcalls_front_sendmsg()
560 mutex_unlock(&map->active.out_mutex); in pvcalls_front_sendmsg()
562 return -EAGAIN; in pvcalls_front_sendmsg()
569 sent = __write_ring(map->active.ring, in pvcalls_front_sendmsg()
570 &map->active.data, &msg->msg_iter, in pvcalls_front_sendmsg()
573 len -= sent; in pvcalls_front_sendmsg()
575 notify_remote_via_irq(map->active.irq); in pvcalls_front_sendmsg()
582 mutex_unlock(&map->active.out_mutex); in pvcalls_front_sendmsg()
589 struct pvcalls_data *data, in __read_ring() argument
597 cons = intf->in_cons; in __read_ring()
598 prod = intf->in_prod; in __read_ring()
599 error = intf->in_error; in __read_ring()
614 len = copy_to_iter(data->in + masked_cons, len, msg_iter); in __read_ring()
616 if (len > (array_size - masked_cons)) { in __read_ring()
617 int ret = copy_to_iter(data->in + masked_cons, in __read_ring()
618 array_size - masked_cons, msg_iter); in __read_ring()
619 if (ret != array_size - masked_cons) { in __read_ring()
623 len = ret + copy_to_iter(data->in, len - ret, msg_iter); in __read_ring()
625 len = copy_to_iter(data->in + masked_cons, len, msg_iter); in __read_ring()
629 /* read data from the ring before increasing the index */ in __read_ring()
632 intf->in_cons += len; in __read_ring()
644 return -EOPNOTSUPP; in pvcalls_front_recvmsg()
650 mutex_lock(&map->active.in_mutex); in pvcalls_front_recvmsg()
655 wait_event_interruptible(map->active.inflight_conn_req, in pvcalls_front_recvmsg()
658 ret = __read_ring(map->active.ring, &map->active.data, in pvcalls_front_recvmsg()
659 &msg->msg_iter, len, flags); in pvcalls_front_recvmsg()
662 notify_remote_via_irq(map->active.irq); in pvcalls_front_recvmsg()
664 ret = (flags & MSG_DONTWAIT) ? -EAGAIN : 0; in pvcalls_front_recvmsg()
665 if (ret == -ENOTCONN) in pvcalls_front_recvmsg()
668 mutex_unlock(&map->active.in_mutex); in pvcalls_front_recvmsg()
681 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) in pvcalls_front_bind()
682 return -EOPNOTSUPP; in pvcalls_front_bind()
687 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_bind()
689 spin_lock(&bedata->socket_lock); in pvcalls_front_bind()
692 spin_unlock(&bedata->socket_lock); in pvcalls_front_bind()
696 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_bind()
697 req->req_id = req_id; in pvcalls_front_bind()
698 map->sock = sock; in pvcalls_front_bind()
699 req->cmd = PVCALLS_BIND; in pvcalls_front_bind()
700 req->u.bind.id = (uintptr_t)map; in pvcalls_front_bind()
701 memcpy(req->u.bind.addr, addr, sizeof(*addr)); in pvcalls_front_bind()
702 req->u.bind.len = addr_len; in pvcalls_front_bind()
704 init_waitqueue_head(&map->passive.inflight_accept_req); in pvcalls_front_bind()
706 map->active_socket = false; in pvcalls_front_bind()
708 bedata->ring.req_prod_pvt++; in pvcalls_front_bind()
709 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_bind()
710 spin_unlock(&bedata->socket_lock); in pvcalls_front_bind()
712 notify_remote_via_irq(bedata->irq); in pvcalls_front_bind()
714 wait_event(bedata->inflight_req, in pvcalls_front_bind()
715 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_bind()
719 ret = bedata->rsp[req_id].ret; in pvcalls_front_bind()
720 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_bind()
722 map->passive.status = PVCALLS_STATUS_BIND; in pvcalls_front_bind()
738 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_listen()
740 if (map->passive.status != PVCALLS_STATUS_BIND) { in pvcalls_front_listen()
742 return -EOPNOTSUPP; in pvcalls_front_listen()
745 spin_lock(&bedata->socket_lock); in pvcalls_front_listen()
748 spin_unlock(&bedata->socket_lock); in pvcalls_front_listen()
752 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_listen()
753 req->req_id = req_id; in pvcalls_front_listen()
754 req->cmd = PVCALLS_LISTEN; in pvcalls_front_listen()
755 req->u.listen.id = (uintptr_t) map; in pvcalls_front_listen()
756 req->u.listen.backlog = backlog; in pvcalls_front_listen()
758 bedata->ring.req_prod_pvt++; in pvcalls_front_listen()
759 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_listen()
760 spin_unlock(&bedata->socket_lock); in pvcalls_front_listen()
762 notify_remote_via_irq(bedata->irq); in pvcalls_front_listen()
764 wait_event(bedata->inflight_req, in pvcalls_front_listen()
765 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_listen()
769 ret = bedata->rsp[req_id].ret; in pvcalls_front_listen()
770 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_listen()
772 map->passive.status = PVCALLS_STATUS_LISTEN; in pvcalls_front_listen()
791 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_accept()
793 if (map->passive.status != PVCALLS_STATUS_LISTEN) { in pvcalls_front_accept()
795 return -EINVAL; in pvcalls_front_accept()
798 nonblock = arg->flags & SOCK_NONBLOCK; in pvcalls_front_accept()
804 (void *)&map->passive.flags)) { in pvcalls_front_accept()
805 req_id = READ_ONCE(map->passive.inflight_req_id); in pvcalls_front_accept()
807 READ_ONCE(bedata->rsp[req_id].req_id) == req_id) { in pvcalls_front_accept()
808 map2 = map->passive.accept_map; in pvcalls_front_accept()
813 return -EAGAIN; in pvcalls_front_accept()
815 if (wait_event_interruptible(map->passive.inflight_accept_req, in pvcalls_front_accept()
817 (void *)&map->passive.flags))) { in pvcalls_front_accept()
819 return -EINTR; in pvcalls_front_accept()
826 (void *)&map->passive.flags); in pvcalls_front_accept()
828 return -ENOMEM; in pvcalls_front_accept()
833 (void *)&map->passive.flags); in pvcalls_front_accept()
843 (void *)&map->passive.flags); in pvcalls_front_accept()
848 spin_lock(&bedata->socket_lock); in pvcalls_front_accept()
852 (void *)&map->passive.flags); in pvcalls_front_accept()
853 spin_unlock(&bedata->socket_lock); in pvcalls_front_accept()
859 list_add_tail(&map2->list, &bedata->socket_mappings); in pvcalls_front_accept()
861 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_accept()
862 req->req_id = req_id; in pvcalls_front_accept()
863 req->cmd = PVCALLS_ACCEPT; in pvcalls_front_accept()
864 req->u.accept.id = (uintptr_t) map; in pvcalls_front_accept()
865 req->u.accept.ref = map2->active.ref; in pvcalls_front_accept()
866 req->u.accept.id_new = (uintptr_t) map2; in pvcalls_front_accept()
867 req->u.accept.evtchn = evtchn; in pvcalls_front_accept()
868 map->passive.accept_map = map2; in pvcalls_front_accept()
870 bedata->ring.req_prod_pvt++; in pvcalls_front_accept()
871 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_accept()
872 spin_unlock(&bedata->socket_lock); in pvcalls_front_accept()
874 notify_remote_via_irq(bedata->irq); in pvcalls_front_accept()
877 WRITE_ONCE(map->passive.inflight_req_id, req_id); in pvcalls_front_accept()
879 return -EAGAIN; in pvcalls_front_accept()
882 if (wait_event_interruptible(bedata->inflight_req, in pvcalls_front_accept()
883 READ_ONCE(bedata->rsp[req_id].req_id) == req_id)) { in pvcalls_front_accept()
885 return -EINTR; in pvcalls_front_accept()
891 map2->sock = newsock; in pvcalls_front_accept()
892 newsock->sk = sk_alloc(sock_net(sock->sk), PF_INET, GFP_KERNEL, &pvcalls_proto, false); in pvcalls_front_accept()
893 if (!newsock->sk) { in pvcalls_front_accept()
894 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
895 map->passive.inflight_req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
897 (void *)&map->passive.flags); in pvcalls_front_accept()
900 return -ENOMEM; in pvcalls_front_accept()
902 newsock->sk->sk_send_head = (void *)map2; in pvcalls_front_accept()
904 ret = bedata->rsp[req_id].ret; in pvcalls_front_accept()
905 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
906 map->passive.inflight_req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
908 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, (void *)&map->passive.flags); in pvcalls_front_accept()
909 wake_up(&map->passive.inflight_accept_req); in pvcalls_front_accept()
925 (void *)&map->passive.flags)) { in pvcalls_front_poll_passive()
926 uint32_t req_id = READ_ONCE(map->passive.inflight_req_id); in pvcalls_front_poll_passive()
929 READ_ONCE(bedata->rsp[req_id].req_id) == req_id) in pvcalls_front_poll_passive()
932 poll_wait(file, &map->passive.inflight_accept_req, wait); in pvcalls_front_poll_passive()
937 (void *)&map->passive.flags)) in pvcalls_front_poll_passive()
947 (void *)&map->passive.flags)) { in pvcalls_front_poll_passive()
948 poll_wait(file, &bedata->inflight_req, wait); in pvcalls_front_poll_passive()
952 spin_lock(&bedata->socket_lock); in pvcalls_front_poll_passive()
955 spin_unlock(&bedata->socket_lock); in pvcalls_front_poll_passive()
958 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_poll_passive()
959 req->req_id = req_id; in pvcalls_front_poll_passive()
960 req->cmd = PVCALLS_POLL; in pvcalls_front_poll_passive()
961 req->u.poll.id = (uintptr_t) map; in pvcalls_front_poll_passive()
963 bedata->ring.req_prod_pvt++; in pvcalls_front_poll_passive()
964 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_poll_passive()
965 spin_unlock(&bedata->socket_lock); in pvcalls_front_poll_passive()
967 notify_remote_via_irq(bedata->irq); in pvcalls_front_poll_passive()
969 poll_wait(file, &bedata->inflight_req, wait); in pvcalls_front_poll_passive()
980 struct pvcalls_data_intf *intf = map->active.ring; in pvcalls_front_poll_active()
982 out_error = intf->out_error; in pvcalls_front_poll_active()
983 in_error = intf->in_error; in pvcalls_front_poll_active()
985 poll_wait(file, &map->active.inflight_conn_req, wait); in pvcalls_front_poll_active()
1006 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_poll()
1008 if (map->active_socket) in pvcalls_front_poll()
1024 if (sock->sk == NULL) in pvcalls_front_release()
1029 if (PTR_ERR(map) == -ENOTCONN) in pvcalls_front_release()
1030 return -EIO; in pvcalls_front_release()
1034 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_release()
1036 spin_lock(&bedata->socket_lock); in pvcalls_front_release()
1039 spin_unlock(&bedata->socket_lock); in pvcalls_front_release()
1043 sock->sk->sk_send_head = NULL; in pvcalls_front_release()
1045 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_release()
1046 req->req_id = req_id; in pvcalls_front_release()
1047 req->cmd = PVCALLS_RELEASE; in pvcalls_front_release()
1048 req->u.release.id = (uintptr_t)map; in pvcalls_front_release()
1050 bedata->ring.req_prod_pvt++; in pvcalls_front_release()
1051 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_release()
1052 spin_unlock(&bedata->socket_lock); in pvcalls_front_release()
1054 notify_remote_via_irq(bedata->irq); in pvcalls_front_release()
1056 wait_event(bedata->inflight_req, in pvcalls_front_release()
1057 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_release()
1059 if (map->active_socket) { in pvcalls_front_release()
1064 map->active.ring->in_error = -EBADF; in pvcalls_front_release()
1065 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_release()
1073 while (atomic_read(&map->refcount) > 1) in pvcalls_front_release()
1078 wake_up(&bedata->inflight_req); in pvcalls_front_release()
1079 wake_up(&map->passive.inflight_accept_req); in pvcalls_front_release()
1081 while (atomic_read(&map->refcount) > 1) in pvcalls_front_release()
1084 spin_lock(&bedata->socket_lock); in pvcalls_front_release()
1085 list_del(&map->list); in pvcalls_front_release()
1086 spin_unlock(&bedata->socket_lock); in pvcalls_front_release()
1087 if (READ_ONCE(map->passive.inflight_req_id) != PVCALLS_INVALID_ID && in pvcalls_front_release()
1088 READ_ONCE(map->passive.inflight_req_id) != 0) { in pvcalls_front_release()
1090 map->passive.accept_map); in pvcalls_front_release()
1094 WRITE_ONCE(bedata->rsp[req_id].req_id, PVCALLS_INVALID_ID); in pvcalls_front_release()
1111 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_remove()
1112 dev_set_drvdata(&dev->dev, NULL); in pvcalls_front_remove()
1114 if (bedata->irq >= 0) in pvcalls_front_remove()
1115 unbind_from_irqhandler(bedata->irq, dev); in pvcalls_front_remove()
1117 list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) { in pvcalls_front_remove()
1118 map->sock->sk->sk_send_head = NULL; in pvcalls_front_remove()
1119 if (map->active_socket) { in pvcalls_front_remove()
1120 map->active.ring->in_error = -EBADF; in pvcalls_front_remove()
1121 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_remove()
1128 list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) { in pvcalls_front_remove()
1129 if (map->active_socket) { in pvcalls_front_remove()
1133 list_del(&map->list); in pvcalls_front_remove()
1137 if (bedata->ref != -1) in pvcalls_front_remove()
1138 gnttab_end_foreign_access(bedata->ref, NULL); in pvcalls_front_remove()
1139 kfree(bedata->ring.sring); in pvcalls_front_remove()
1147 int ret = -ENOMEM, i; in pvcalls_front_probe()
1157 dev_err(&dev->dev, "only one PV Calls connection supported\n"); in pvcalls_front_probe()
1158 return -EINVAL; in pvcalls_front_probe()
1161 versions = xenbus_read(XBT_NIL, dev->otherend, "versions", &len); in pvcalls_front_probe()
1165 return -EINVAL; in pvcalls_front_probe()
1168 return -EINVAL; in pvcalls_front_probe()
1171 max_page_order = xenbus_read_unsigned(dev->otherend, in pvcalls_front_probe()
1172 "max-page-order", 0); in pvcalls_front_probe()
1174 return -ENODEV; in pvcalls_front_probe()
1175 function_calls = xenbus_read_unsigned(dev->otherend, in pvcalls_front_probe()
1176 "function-calls", 0); in pvcalls_front_probe()
1179 return -ENODEV; in pvcalls_front_probe()
1180 pr_info("%s max-page-order is %u\n", __func__, max_page_order); in pvcalls_front_probe()
1184 return -ENOMEM; in pvcalls_front_probe()
1186 dev_set_drvdata(&dev->dev, bedata); in pvcalls_front_probe()
1188 init_waitqueue_head(&bedata->inflight_req); in pvcalls_front_probe()
1189 INIT_LIST_HEAD(&bedata->socket_mappings); in pvcalls_front_probe()
1190 spin_lock_init(&bedata->socket_lock); in pvcalls_front_probe()
1191 bedata->irq = -1; in pvcalls_front_probe()
1192 bedata->ref = -1; in pvcalls_front_probe()
1195 bedata->rsp[i].req_id = PVCALLS_INVALID_ID; in pvcalls_front_probe()
1202 FRONT_RING_INIT(&bedata->ring, sring, XEN_PAGE_SIZE); in pvcalls_front_probe()
1208 bedata->irq = bind_evtchn_to_irqhandler(evtchn, in pvcalls_front_probe()
1210 0, "pvcalls-frontend", dev); in pvcalls_front_probe()
1211 if (bedata->irq < 0) { in pvcalls_front_probe()
1212 ret = bedata->irq; in pvcalls_front_probe()
1222 bedata->ref = ret; in pvcalls_front_probe()
1223 gnttab_grant_foreign_access_ref(bedata->ref, dev->otherend_id, in pvcalls_front_probe()
1232 ret = xenbus_printf(xbt, dev->nodename, "version", "%u", 1); in pvcalls_front_probe()
1235 ret = xenbus_printf(xbt, dev->nodename, "ring-ref", "%d", bedata->ref); in pvcalls_front_probe()
1238 ret = xenbus_printf(xbt, dev->nodename, "port", "%u", in pvcalls_front_probe()
1244 if (ret == -EAGAIN) in pvcalls_front_probe()
1280 if (dev->state == XenbusStateClosed) in pvcalls_front_changed()
1301 return -ENODEV; in pvcalls_frontend_init()