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()
233 unbind_from_irqhandler(map->active.irq, map); in pvcalls_front_free_map()
235 spin_lock(&bedata->socket_lock); in pvcalls_front_free_map()
236 if (!list_empty(&map->list)) in pvcalls_front_free_map()
237 list_del_init(&map->list); in pvcalls_front_free_map()
238 spin_unlock(&bedata->socket_lock); in pvcalls_front_free_map()
241 gnttab_end_foreign_access(map->active.ring->ref[i], 0, 0); in pvcalls_front_free_map()
242 gnttab_end_foreign_access(map->active.ref, 0, 0); in pvcalls_front_free_map()
243 free_page((unsigned long)map->active.ring); in pvcalls_front_free_map()
255 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_conn_handler()
274 if (sock->type != SOCK_STREAM) in pvcalls_front_socket()
275 return -EOPNOTSUPP; in pvcalls_front_socket()
280 return -EACCES; in pvcalls_front_socket()
282 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_socket()
287 return -ENOMEM; in pvcalls_front_socket()
290 spin_lock(&bedata->socket_lock); in pvcalls_front_socket()
295 spin_unlock(&bedata->socket_lock); in pvcalls_front_socket()
301 * sock->sk->sk_send_head is not used for ip sockets: reuse the in pvcalls_front_socket()
306 sock->sk->sk_send_head = (void *)map; in pvcalls_front_socket()
307 list_add_tail(&map->list, &bedata->socket_mappings); in pvcalls_front_socket()
309 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_socket()
310 req->req_id = req_id; in pvcalls_front_socket()
311 req->cmd = PVCALLS_SOCKET; in pvcalls_front_socket()
312 req->u.socket.id = (uintptr_t) map; in pvcalls_front_socket()
313 req->u.socket.domain = AF_INET; in pvcalls_front_socket()
314 req->u.socket.type = SOCK_STREAM; in pvcalls_front_socket()
315 req->u.socket.protocol = IPPROTO_IP; in pvcalls_front_socket()
317 bedata->ring.req_prod_pvt++; in pvcalls_front_socket()
318 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_socket()
319 spin_unlock(&bedata->socket_lock); in pvcalls_front_socket()
321 notify_remote_via_irq(bedata->irq); in pvcalls_front_socket()
323 wait_event(bedata->inflight_req, in pvcalls_front_socket()
324 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_socket()
328 ret = bedata->rsp[req_id].ret; in pvcalls_front_socket()
329 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_socket()
337 if (!map->active.ring) in free_active_ring()
340 free_pages((unsigned long)map->active.data.in, in free_active_ring()
341 map->active.ring->ring_order); in free_active_ring()
342 free_page((unsigned long)map->active.ring); in free_active_ring()
349 map->active.ring = (struct pvcalls_data_intf *) in alloc_active_ring()
351 if (!map->active.ring) in alloc_active_ring()
354 map->active.ring->ring_order = PVCALLS_RING_ORDER; in alloc_active_ring()
360 map->active.data.in = bytes; in alloc_active_ring()
361 map->active.data.out = bytes + in alloc_active_ring()
368 return -ENOMEM; in alloc_active_ring()
374 int ret, irq = -1, i; in create_active()
377 init_waitqueue_head(&map->active.inflight_conn_req); in create_active()
379 bytes = map->active.data.in; in create_active()
381 map->active.ring->ref[i] = gnttab_grant_foreign_access( in create_active()
382 pvcalls_front_dev->otherend_id, in create_active()
385 map->active.ref = gnttab_grant_foreign_access( in create_active()
386 pvcalls_front_dev->otherend_id, in create_active()
387 pfn_to_gfn(virt_to_pfn((void *)map->active.ring)), 0); in create_active()
393 0, "pvcalls-frontend", map); in create_active()
399 map->active.irq = irq; in create_active()
400 map->active_socket = true; in create_active()
401 mutex_init(&map->active.in_mutex); in create_active()
402 mutex_init(&map->active.out_mutex); in create_active()
421 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) in pvcalls_front_connect()
422 return -EOPNOTSUPP; in pvcalls_front_connect()
428 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_connect()
435 spin_lock(&bedata->socket_lock); in pvcalls_front_connect()
438 spin_unlock(&bedata->socket_lock); in pvcalls_front_connect()
445 spin_unlock(&bedata->socket_lock); in pvcalls_front_connect()
451 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_connect()
452 req->req_id = req_id; in pvcalls_front_connect()
453 req->cmd = PVCALLS_CONNECT; in pvcalls_front_connect()
454 req->u.connect.id = (uintptr_t)map; in pvcalls_front_connect()
455 req->u.connect.len = addr_len; in pvcalls_front_connect()
456 req->u.connect.flags = flags; in pvcalls_front_connect()
457 req->u.connect.ref = map->active.ref; in pvcalls_front_connect()
458 req->u.connect.evtchn = evtchn; in pvcalls_front_connect()
459 memcpy(req->u.connect.addr, addr, sizeof(*addr)); in pvcalls_front_connect()
461 map->sock = sock; in pvcalls_front_connect()
463 bedata->ring.req_prod_pvt++; in pvcalls_front_connect()
464 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_connect()
465 spin_unlock(&bedata->socket_lock); in pvcalls_front_connect()
468 notify_remote_via_irq(bedata->irq); in pvcalls_front_connect()
470 wait_event(bedata->inflight_req, in pvcalls_front_connect()
471 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_connect()
475 ret = bedata->rsp[req_id].ret; in pvcalls_front_connect()
476 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_connect()
482 struct pvcalls_data *data, in __write_ring() argument
490 error = intf->out_error; in __write_ring()
493 cons = intf->out_cons; in __write_ring()
494 prod = intf->out_prod; in __write_ring()
500 return -EINVAL; in __write_ring()
503 if (len > array_size - size) in __write_ring()
504 len = array_size - size; in __write_ring()
510 len = copy_from_iter(data->out + masked_prod, len, msg_iter); in __write_ring()
512 if (len > array_size - masked_prod) { in __write_ring()
513 int ret = copy_from_iter(data->out + masked_prod, in __write_ring()
514 array_size - masked_prod, msg_iter); in __write_ring()
515 if (ret != array_size - masked_prod) { in __write_ring()
519 len = ret + copy_from_iter(data->out, len - ret, msg_iter); in __write_ring()
521 len = copy_from_iter(data->out + masked_prod, len, msg_iter); in __write_ring()
527 intf->out_prod += len; in __write_ring()
539 flags = msg->msg_flags; in pvcalls_front_sendmsg()
541 return -EOPNOTSUPP; in pvcalls_front_sendmsg()
547 mutex_lock(&map->active.out_mutex); in pvcalls_front_sendmsg()
549 mutex_unlock(&map->active.out_mutex); in pvcalls_front_sendmsg()
551 return -EAGAIN; in pvcalls_front_sendmsg()
558 sent = __write_ring(map->active.ring, in pvcalls_front_sendmsg()
559 &map->active.data, &msg->msg_iter, in pvcalls_front_sendmsg()
562 len -= sent; in pvcalls_front_sendmsg()
564 notify_remote_via_irq(map->active.irq); in pvcalls_front_sendmsg()
571 mutex_unlock(&map->active.out_mutex); in pvcalls_front_sendmsg()
577 struct pvcalls_data *data, in __read_ring() argument
585 cons = intf->in_cons; in __read_ring()
586 prod = intf->in_prod; in __read_ring()
587 error = intf->in_error; in __read_ring()
602 len = copy_to_iter(data->in + masked_cons, len, msg_iter); in __read_ring()
604 if (len > (array_size - masked_cons)) { in __read_ring()
605 int ret = copy_to_iter(data->in + masked_cons, in __read_ring()
606 array_size - masked_cons, msg_iter); in __read_ring()
607 if (ret != array_size - masked_cons) { in __read_ring()
611 len = ret + copy_to_iter(data->in, len - ret, msg_iter); in __read_ring()
613 len = copy_to_iter(data->in + masked_cons, len, msg_iter); in __read_ring()
617 /* read data from the ring before increasing the index */ in __read_ring()
620 intf->in_cons += len; in __read_ring()
632 return -EOPNOTSUPP; in pvcalls_front_recvmsg()
638 mutex_lock(&map->active.in_mutex); in pvcalls_front_recvmsg()
643 wait_event_interruptible(map->active.inflight_conn_req, in pvcalls_front_recvmsg()
646 ret = __read_ring(map->active.ring, &map->active.data, in pvcalls_front_recvmsg()
647 &msg->msg_iter, len, flags); in pvcalls_front_recvmsg()
650 notify_remote_via_irq(map->active.irq); in pvcalls_front_recvmsg()
652 ret = (flags & MSG_DONTWAIT) ? -EAGAIN : 0; in pvcalls_front_recvmsg()
653 if (ret == -ENOTCONN) in pvcalls_front_recvmsg()
656 mutex_unlock(&map->active.in_mutex); in pvcalls_front_recvmsg()
668 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) in pvcalls_front_bind()
669 return -EOPNOTSUPP; in pvcalls_front_bind()
674 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_bind()
676 spin_lock(&bedata->socket_lock); in pvcalls_front_bind()
679 spin_unlock(&bedata->socket_lock); in pvcalls_front_bind()
683 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_bind()
684 req->req_id = req_id; in pvcalls_front_bind()
685 map->sock = sock; in pvcalls_front_bind()
686 req->cmd = PVCALLS_BIND; in pvcalls_front_bind()
687 req->u.bind.id = (uintptr_t)map; in pvcalls_front_bind()
688 memcpy(req->u.bind.addr, addr, sizeof(*addr)); in pvcalls_front_bind()
689 req->u.bind.len = addr_len; in pvcalls_front_bind()
691 init_waitqueue_head(&map->passive.inflight_accept_req); in pvcalls_front_bind()
693 map->active_socket = false; in pvcalls_front_bind()
695 bedata->ring.req_prod_pvt++; in pvcalls_front_bind()
696 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_bind()
697 spin_unlock(&bedata->socket_lock); in pvcalls_front_bind()
699 notify_remote_via_irq(bedata->irq); in pvcalls_front_bind()
701 wait_event(bedata->inflight_req, in pvcalls_front_bind()
702 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_bind()
706 ret = bedata->rsp[req_id].ret; in pvcalls_front_bind()
707 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_bind()
709 map->passive.status = PVCALLS_STATUS_BIND; in pvcalls_front_bind()
724 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_listen()
726 if (map->passive.status != PVCALLS_STATUS_BIND) { in pvcalls_front_listen()
728 return -EOPNOTSUPP; in pvcalls_front_listen()
731 spin_lock(&bedata->socket_lock); in pvcalls_front_listen()
734 spin_unlock(&bedata->socket_lock); in pvcalls_front_listen()
738 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_listen()
739 req->req_id = req_id; in pvcalls_front_listen()
740 req->cmd = PVCALLS_LISTEN; in pvcalls_front_listen()
741 req->u.listen.id = (uintptr_t) map; in pvcalls_front_listen()
742 req->u.listen.backlog = backlog; in pvcalls_front_listen()
744 bedata->ring.req_prod_pvt++; in pvcalls_front_listen()
745 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_listen()
746 spin_unlock(&bedata->socket_lock); in pvcalls_front_listen()
748 notify_remote_via_irq(bedata->irq); in pvcalls_front_listen()
750 wait_event(bedata->inflight_req, in pvcalls_front_listen()
751 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_listen()
755 ret = bedata->rsp[req_id].ret; in pvcalls_front_listen()
756 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_listen()
758 map->passive.status = PVCALLS_STATUS_LISTEN; in pvcalls_front_listen()
775 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_accept()
777 if (map->passive.status != PVCALLS_STATUS_LISTEN) { in pvcalls_front_accept()
779 return -EINVAL; in pvcalls_front_accept()
788 (void *)&map->passive.flags)) { in pvcalls_front_accept()
789 req_id = READ_ONCE(map->passive.inflight_req_id); in pvcalls_front_accept()
791 READ_ONCE(bedata->rsp[req_id].req_id) == req_id) { in pvcalls_front_accept()
792 map2 = map->passive.accept_map; in pvcalls_front_accept()
797 return -EAGAIN; in pvcalls_front_accept()
799 if (wait_event_interruptible(map->passive.inflight_accept_req, in pvcalls_front_accept()
801 (void *)&map->passive.flags))) { in pvcalls_front_accept()
803 return -EINTR; in pvcalls_front_accept()
810 (void *)&map->passive.flags); in pvcalls_front_accept()
812 return -ENOMEM; in pvcalls_front_accept()
817 (void *)&map->passive.flags); in pvcalls_front_accept()
822 spin_lock(&bedata->socket_lock); in pvcalls_front_accept()
826 (void *)&map->passive.flags); in pvcalls_front_accept()
827 spin_unlock(&bedata->socket_lock); in pvcalls_front_accept()
839 (void *)&map->passive.flags); in pvcalls_front_accept()
840 spin_unlock(&bedata->socket_lock); in pvcalls_front_accept()
844 list_add_tail(&map2->list, &bedata->socket_mappings); in pvcalls_front_accept()
846 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_accept()
847 req->req_id = req_id; in pvcalls_front_accept()
848 req->cmd = PVCALLS_ACCEPT; in pvcalls_front_accept()
849 req->u.accept.id = (uintptr_t) map; in pvcalls_front_accept()
850 req->u.accept.ref = map2->active.ref; in pvcalls_front_accept()
851 req->u.accept.id_new = (uintptr_t) map2; in pvcalls_front_accept()
852 req->u.accept.evtchn = evtchn; in pvcalls_front_accept()
853 map->passive.accept_map = map2; in pvcalls_front_accept()
855 bedata->ring.req_prod_pvt++; in pvcalls_front_accept()
856 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_accept()
857 spin_unlock(&bedata->socket_lock); in pvcalls_front_accept()
859 notify_remote_via_irq(bedata->irq); in pvcalls_front_accept()
862 WRITE_ONCE(map->passive.inflight_req_id, req_id); in pvcalls_front_accept()
864 return -EAGAIN; in pvcalls_front_accept()
867 if (wait_event_interruptible(bedata->inflight_req, in pvcalls_front_accept()
868 READ_ONCE(bedata->rsp[req_id].req_id) == req_id)) { in pvcalls_front_accept()
870 return -EINTR; in pvcalls_front_accept()
876 map2->sock = newsock; in pvcalls_front_accept()
877 newsock->sk = sk_alloc(sock_net(sock->sk), PF_INET, GFP_KERNEL, &pvcalls_proto, false); in pvcalls_front_accept()
878 if (!newsock->sk) { in pvcalls_front_accept()
879 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
880 map->passive.inflight_req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
882 (void *)&map->passive.flags); in pvcalls_front_accept()
885 return -ENOMEM; in pvcalls_front_accept()
887 newsock->sk->sk_send_head = (void *)map2; in pvcalls_front_accept()
889 ret = bedata->rsp[req_id].ret; in pvcalls_front_accept()
890 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
891 map->passive.inflight_req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
893 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, (void *)&map->passive.flags); in pvcalls_front_accept()
894 wake_up(&map->passive.inflight_accept_req); in pvcalls_front_accept()
909 (void *)&map->passive.flags)) { in pvcalls_front_poll_passive()
910 uint32_t req_id = READ_ONCE(map->passive.inflight_req_id); in pvcalls_front_poll_passive()
913 READ_ONCE(bedata->rsp[req_id].req_id) == req_id) in pvcalls_front_poll_passive()
916 poll_wait(file, &map->passive.inflight_accept_req, wait); in pvcalls_front_poll_passive()
921 (void *)&map->passive.flags)) in pvcalls_front_poll_passive()
931 (void *)&map->passive.flags)) { in pvcalls_front_poll_passive()
932 poll_wait(file, &bedata->inflight_req, wait); in pvcalls_front_poll_passive()
936 spin_lock(&bedata->socket_lock); in pvcalls_front_poll_passive()
939 spin_unlock(&bedata->socket_lock); in pvcalls_front_poll_passive()
942 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_poll_passive()
943 req->req_id = req_id; in pvcalls_front_poll_passive()
944 req->cmd = PVCALLS_POLL; in pvcalls_front_poll_passive()
945 req->u.poll.id = (uintptr_t) map; in pvcalls_front_poll_passive()
947 bedata->ring.req_prod_pvt++; in pvcalls_front_poll_passive()
948 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_poll_passive()
949 spin_unlock(&bedata->socket_lock); in pvcalls_front_poll_passive()
951 notify_remote_via_irq(bedata->irq); in pvcalls_front_poll_passive()
953 poll_wait(file, &bedata->inflight_req, wait); in pvcalls_front_poll_passive()
964 struct pvcalls_data_intf *intf = map->active.ring; in pvcalls_front_poll_active()
966 out_error = intf->out_error; in pvcalls_front_poll_active()
967 in_error = intf->in_error; in pvcalls_front_poll_active()
969 poll_wait(file, &map->active.inflight_conn_req, wait); in pvcalls_front_poll_active()
990 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_poll()
992 if (map->active_socket) in pvcalls_front_poll()
1007 if (sock->sk == NULL) in pvcalls_front_release()
1012 if (PTR_ERR(map) == -ENOTCONN) in pvcalls_front_release()
1013 return -EIO; in pvcalls_front_release()
1017 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_release()
1019 spin_lock(&bedata->socket_lock); in pvcalls_front_release()
1022 spin_unlock(&bedata->socket_lock); in pvcalls_front_release()
1026 sock->sk->sk_send_head = NULL; in pvcalls_front_release()
1028 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_release()
1029 req->req_id = req_id; in pvcalls_front_release()
1030 req->cmd = PVCALLS_RELEASE; in pvcalls_front_release()
1031 req->u.release.id = (uintptr_t)map; in pvcalls_front_release()
1033 bedata->ring.req_prod_pvt++; in pvcalls_front_release()
1034 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_release()
1035 spin_unlock(&bedata->socket_lock); in pvcalls_front_release()
1037 notify_remote_via_irq(bedata->irq); in pvcalls_front_release()
1039 wait_event(bedata->inflight_req, in pvcalls_front_release()
1040 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_release()
1042 if (map->active_socket) { in pvcalls_front_release()
1047 map->active.ring->in_error = -EBADF; in pvcalls_front_release()
1048 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_release()
1056 while (atomic_read(&map->refcount) > 1) in pvcalls_front_release()
1061 wake_up(&bedata->inflight_req); in pvcalls_front_release()
1062 wake_up(&map->passive.inflight_accept_req); in pvcalls_front_release()
1064 while (atomic_read(&map->refcount) > 1) in pvcalls_front_release()
1067 spin_lock(&bedata->socket_lock); in pvcalls_front_release()
1068 list_del(&map->list); in pvcalls_front_release()
1069 spin_unlock(&bedata->socket_lock); in pvcalls_front_release()
1070 if (READ_ONCE(map->passive.inflight_req_id) != PVCALLS_INVALID_ID && in pvcalls_front_release()
1071 READ_ONCE(map->passive.inflight_req_id) != 0) { in pvcalls_front_release()
1073 map->passive.accept_map); in pvcalls_front_release()
1077 WRITE_ONCE(bedata->rsp[req_id].req_id, PVCALLS_INVALID_ID); in pvcalls_front_release()
1093 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_remove()
1094 dev_set_drvdata(&dev->dev, NULL); in pvcalls_front_remove()
1096 if (bedata->irq >= 0) in pvcalls_front_remove()
1097 unbind_from_irqhandler(bedata->irq, dev); in pvcalls_front_remove()
1099 list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) { in pvcalls_front_remove()
1100 map->sock->sk->sk_send_head = NULL; in pvcalls_front_remove()
1101 if (map->active_socket) { in pvcalls_front_remove()
1102 map->active.ring->in_error = -EBADF; in pvcalls_front_remove()
1103 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_remove()
1110 list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) { in pvcalls_front_remove()
1111 if (map->active_socket) { in pvcalls_front_remove()
1115 list_del(&map->list); in pvcalls_front_remove()
1119 if (bedata->ref != -1) in pvcalls_front_remove()
1120 gnttab_end_foreign_access(bedata->ref, 0, 0); in pvcalls_front_remove()
1121 kfree(bedata->ring.sring); in pvcalls_front_remove()
1130 int ret = -ENOMEM, i; in pvcalls_front_probe()
1140 dev_err(&dev->dev, "only one PV Calls connection supported\n"); in pvcalls_front_probe()
1141 return -EINVAL; in pvcalls_front_probe()
1144 versions = xenbus_read(XBT_NIL, dev->otherend, "versions", &len); in pvcalls_front_probe()
1148 return -EINVAL; in pvcalls_front_probe()
1151 return -EINVAL; in pvcalls_front_probe()
1154 max_page_order = xenbus_read_unsigned(dev->otherend, in pvcalls_front_probe()
1155 "max-page-order", 0); in pvcalls_front_probe()
1157 return -ENODEV; in pvcalls_front_probe()
1158 function_calls = xenbus_read_unsigned(dev->otherend, in pvcalls_front_probe()
1159 "function-calls", 0); in pvcalls_front_probe()
1162 return -ENODEV; in pvcalls_front_probe()
1163 pr_info("%s max-page-order is %u\n", __func__, max_page_order); in pvcalls_front_probe()
1167 return -ENOMEM; in pvcalls_front_probe()
1169 dev_set_drvdata(&dev->dev, bedata); in pvcalls_front_probe()
1171 init_waitqueue_head(&bedata->inflight_req); in pvcalls_front_probe()
1172 INIT_LIST_HEAD(&bedata->socket_mappings); in pvcalls_front_probe()
1173 spin_lock_init(&bedata->socket_lock); in pvcalls_front_probe()
1174 bedata->irq = -1; in pvcalls_front_probe()
1175 bedata->ref = -1; in pvcalls_front_probe()
1178 bedata->rsp[i].req_id = PVCALLS_INVALID_ID; in pvcalls_front_probe()
1185 FRONT_RING_INIT(&bedata->ring, sring, XEN_PAGE_SIZE); in pvcalls_front_probe()
1191 bedata->irq = bind_evtchn_to_irqhandler(evtchn, in pvcalls_front_probe()
1193 0, "pvcalls-frontend", dev); in pvcalls_front_probe()
1194 if (bedata->irq < 0) { in pvcalls_front_probe()
1195 ret = bedata->irq; in pvcalls_front_probe()
1205 bedata->ref = ret; in pvcalls_front_probe()
1206 gnttab_grant_foreign_access_ref(bedata->ref, dev->otherend_id, in pvcalls_front_probe()
1215 ret = xenbus_printf(xbt, dev->nodename, "version", "%u", 1); in pvcalls_front_probe()
1218 ret = xenbus_printf(xbt, dev->nodename, "ring-ref", "%d", bedata->ref); in pvcalls_front_probe()
1221 ret = xenbus_printf(xbt, dev->nodename, "port", "%u", in pvcalls_front_probe()
1227 if (ret == -EAGAIN) in pvcalls_front_probe()
1263 if (dev->state == XenbusStateClosed) in pvcalls_front_changed()
1283 return -ENODEV; in pvcalls_frontend_init()