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()
347 if (!map->active.ring) in free_active_ring()
350 free_pages_exact(map->active.data.in, in free_active_ring()
351 PAGE_SIZE << map->active.ring->ring_order); in free_active_ring()
352 free_page((unsigned long)map->active.ring); in free_active_ring()
359 map->active.ring = (struct pvcalls_data_intf *) in alloc_active_ring()
361 if (!map->active.ring) in alloc_active_ring()
364 map->active.ring->ring_order = PVCALLS_RING_ORDER; in alloc_active_ring()
370 map->active.data.in = bytes; in alloc_active_ring()
371 map->active.data.out = bytes + in alloc_active_ring()
378 return -ENOMEM; in alloc_active_ring()
384 int ret, irq = -1, i; in create_active()
387 init_waitqueue_head(&map->active.inflight_conn_req); in create_active()
389 bytes = map->active.data.in; in create_active()
391 map->active.ring->ref[i] = gnttab_grant_foreign_access( in create_active()
392 pvcalls_front_dev->otherend_id, in create_active()
395 map->active.ref = gnttab_grant_foreign_access( in create_active()
396 pvcalls_front_dev->otherend_id, in create_active()
397 pfn_to_gfn(virt_to_pfn((void *)map->active.ring)), 0); in create_active()
403 0, "pvcalls-frontend", map); in create_active()
409 map->active.irq = irq; in create_active()
410 map->active_socket = true; in create_active()
411 mutex_init(&map->active.in_mutex); in create_active()
412 mutex_init(&map->active.out_mutex); in create_active()
431 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) in pvcalls_front_connect()
432 return -EOPNOTSUPP; in pvcalls_front_connect()
438 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_connect()
451 spin_lock(&bedata->socket_lock); in pvcalls_front_connect()
454 spin_unlock(&bedata->socket_lock); in pvcalls_front_connect()
460 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_connect()
461 req->req_id = req_id; in pvcalls_front_connect()
462 req->cmd = PVCALLS_CONNECT; in pvcalls_front_connect()
463 req->u.connect.id = (uintptr_t)map; in pvcalls_front_connect()
464 req->u.connect.len = addr_len; in pvcalls_front_connect()
465 req->u.connect.flags = flags; in pvcalls_front_connect()
466 req->u.connect.ref = map->active.ref; in pvcalls_front_connect()
467 req->u.connect.evtchn = evtchn; in pvcalls_front_connect()
468 memcpy(req->u.connect.addr, addr, sizeof(*addr)); in pvcalls_front_connect()
470 map->sock = sock; in pvcalls_front_connect()
472 bedata->ring.req_prod_pvt++; in pvcalls_front_connect()
473 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_connect()
474 spin_unlock(&bedata->socket_lock); in pvcalls_front_connect()
477 notify_remote_via_irq(bedata->irq); in pvcalls_front_connect()
479 wait_event(bedata->inflight_req, in pvcalls_front_connect()
480 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_connect()
484 ret = bedata->rsp[req_id].ret; in pvcalls_front_connect()
485 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_connect()
491 struct pvcalls_data *data, in __write_ring() argument
499 error = intf->out_error; in __write_ring()
502 cons = intf->out_cons; in __write_ring()
503 prod = intf->out_prod; in __write_ring()
509 return -EINVAL; in __write_ring()
512 if (len > array_size - size) in __write_ring()
513 len = array_size - size; in __write_ring()
519 len = copy_from_iter(data->out + masked_prod, len, msg_iter); in __write_ring()
521 if (len > array_size - masked_prod) { in __write_ring()
522 int ret = copy_from_iter(data->out + masked_prod, in __write_ring()
523 array_size - masked_prod, msg_iter); in __write_ring()
524 if (ret != array_size - masked_prod) { in __write_ring()
528 len = ret + copy_from_iter(data->out, len - ret, msg_iter); in __write_ring()
530 len = copy_from_iter(data->out + masked_prod, len, msg_iter); in __write_ring()
536 intf->out_prod += len; in __write_ring()
548 flags = msg->msg_flags; in pvcalls_front_sendmsg()
550 return -EOPNOTSUPP; in pvcalls_front_sendmsg()
556 mutex_lock(&map->active.out_mutex); in pvcalls_front_sendmsg()
558 mutex_unlock(&map->active.out_mutex); in pvcalls_front_sendmsg()
560 return -EAGAIN; in pvcalls_front_sendmsg()
567 sent = __write_ring(map->active.ring, in pvcalls_front_sendmsg()
568 &map->active.data, &msg->msg_iter, in pvcalls_front_sendmsg()
571 len -= sent; in pvcalls_front_sendmsg()
573 notify_remote_via_irq(map->active.irq); in pvcalls_front_sendmsg()
580 mutex_unlock(&map->active.out_mutex); in pvcalls_front_sendmsg()
586 struct pvcalls_data *data, in __read_ring() argument
594 cons = intf->in_cons; in __read_ring()
595 prod = intf->in_prod; in __read_ring()
596 error = intf->in_error; in __read_ring()
611 len = copy_to_iter(data->in + masked_cons, len, msg_iter); in __read_ring()
613 if (len > (array_size - masked_cons)) { in __read_ring()
614 int ret = copy_to_iter(data->in + masked_cons, in __read_ring()
615 array_size - masked_cons, msg_iter); in __read_ring()
616 if (ret != array_size - masked_cons) { in __read_ring()
620 len = ret + copy_to_iter(data->in, len - ret, msg_iter); in __read_ring()
622 len = copy_to_iter(data->in + masked_cons, len, msg_iter); in __read_ring()
626 /* read data from the ring before increasing the index */ in __read_ring()
629 intf->in_cons += len; in __read_ring()
641 return -EOPNOTSUPP; in pvcalls_front_recvmsg()
647 mutex_lock(&map->active.in_mutex); in pvcalls_front_recvmsg()
652 wait_event_interruptible(map->active.inflight_conn_req, in pvcalls_front_recvmsg()
655 ret = __read_ring(map->active.ring, &map->active.data, in pvcalls_front_recvmsg()
656 &msg->msg_iter, len, flags); in pvcalls_front_recvmsg()
659 notify_remote_via_irq(map->active.irq); in pvcalls_front_recvmsg()
661 ret = (flags & MSG_DONTWAIT) ? -EAGAIN : 0; in pvcalls_front_recvmsg()
662 if (ret == -ENOTCONN) in pvcalls_front_recvmsg()
665 mutex_unlock(&map->active.in_mutex); in pvcalls_front_recvmsg()
677 if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) in pvcalls_front_bind()
678 return -EOPNOTSUPP; in pvcalls_front_bind()
683 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_bind()
685 spin_lock(&bedata->socket_lock); in pvcalls_front_bind()
688 spin_unlock(&bedata->socket_lock); in pvcalls_front_bind()
692 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_bind()
693 req->req_id = req_id; in pvcalls_front_bind()
694 map->sock = sock; in pvcalls_front_bind()
695 req->cmd = PVCALLS_BIND; in pvcalls_front_bind()
696 req->u.bind.id = (uintptr_t)map; in pvcalls_front_bind()
697 memcpy(req->u.bind.addr, addr, sizeof(*addr)); in pvcalls_front_bind()
698 req->u.bind.len = addr_len; in pvcalls_front_bind()
700 init_waitqueue_head(&map->passive.inflight_accept_req); in pvcalls_front_bind()
702 map->active_socket = false; in pvcalls_front_bind()
704 bedata->ring.req_prod_pvt++; in pvcalls_front_bind()
705 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_bind()
706 spin_unlock(&bedata->socket_lock); in pvcalls_front_bind()
708 notify_remote_via_irq(bedata->irq); in pvcalls_front_bind()
710 wait_event(bedata->inflight_req, in pvcalls_front_bind()
711 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_bind()
715 ret = bedata->rsp[req_id].ret; in pvcalls_front_bind()
716 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_bind()
718 map->passive.status = PVCALLS_STATUS_BIND; in pvcalls_front_bind()
733 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_listen()
735 if (map->passive.status != PVCALLS_STATUS_BIND) { in pvcalls_front_listen()
737 return -EOPNOTSUPP; in pvcalls_front_listen()
740 spin_lock(&bedata->socket_lock); in pvcalls_front_listen()
743 spin_unlock(&bedata->socket_lock); in pvcalls_front_listen()
747 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_listen()
748 req->req_id = req_id; in pvcalls_front_listen()
749 req->cmd = PVCALLS_LISTEN; in pvcalls_front_listen()
750 req->u.listen.id = (uintptr_t) map; in pvcalls_front_listen()
751 req->u.listen.backlog = backlog; in pvcalls_front_listen()
753 bedata->ring.req_prod_pvt++; in pvcalls_front_listen()
754 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_listen()
755 spin_unlock(&bedata->socket_lock); in pvcalls_front_listen()
757 notify_remote_via_irq(bedata->irq); in pvcalls_front_listen()
759 wait_event(bedata->inflight_req, in pvcalls_front_listen()
760 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_listen()
764 ret = bedata->rsp[req_id].ret; in pvcalls_front_listen()
765 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_listen()
767 map->passive.status = PVCALLS_STATUS_LISTEN; in pvcalls_front_listen()
784 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_accept()
786 if (map->passive.status != PVCALLS_STATUS_LISTEN) { in pvcalls_front_accept()
788 return -EINVAL; in pvcalls_front_accept()
797 (void *)&map->passive.flags)) { in pvcalls_front_accept()
798 req_id = READ_ONCE(map->passive.inflight_req_id); in pvcalls_front_accept()
800 READ_ONCE(bedata->rsp[req_id].req_id) == req_id) { in pvcalls_front_accept()
801 map2 = map->passive.accept_map; in pvcalls_front_accept()
806 return -EAGAIN; in pvcalls_front_accept()
808 if (wait_event_interruptible(map->passive.inflight_accept_req, in pvcalls_front_accept()
810 (void *)&map->passive.flags))) { in pvcalls_front_accept()
812 return -EINTR; in pvcalls_front_accept()
819 (void *)&map->passive.flags); in pvcalls_front_accept()
821 return -ENOMEM; in pvcalls_front_accept()
826 (void *)&map->passive.flags); in pvcalls_front_accept()
836 (void *)&map->passive.flags); in pvcalls_front_accept()
841 spin_lock(&bedata->socket_lock); in pvcalls_front_accept()
845 (void *)&map->passive.flags); in pvcalls_front_accept()
846 spin_unlock(&bedata->socket_lock); in pvcalls_front_accept()
852 list_add_tail(&map2->list, &bedata->socket_mappings); in pvcalls_front_accept()
854 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_accept()
855 req->req_id = req_id; in pvcalls_front_accept()
856 req->cmd = PVCALLS_ACCEPT; in pvcalls_front_accept()
857 req->u.accept.id = (uintptr_t) map; in pvcalls_front_accept()
858 req->u.accept.ref = map2->active.ref; in pvcalls_front_accept()
859 req->u.accept.id_new = (uintptr_t) map2; in pvcalls_front_accept()
860 req->u.accept.evtchn = evtchn; in pvcalls_front_accept()
861 map->passive.accept_map = map2; in pvcalls_front_accept()
863 bedata->ring.req_prod_pvt++; in pvcalls_front_accept()
864 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_accept()
865 spin_unlock(&bedata->socket_lock); in pvcalls_front_accept()
867 notify_remote_via_irq(bedata->irq); in pvcalls_front_accept()
870 WRITE_ONCE(map->passive.inflight_req_id, req_id); in pvcalls_front_accept()
872 return -EAGAIN; in pvcalls_front_accept()
875 if (wait_event_interruptible(bedata->inflight_req, in pvcalls_front_accept()
876 READ_ONCE(bedata->rsp[req_id].req_id) == req_id)) { in pvcalls_front_accept()
878 return -EINTR; in pvcalls_front_accept()
884 map2->sock = newsock; in pvcalls_front_accept()
885 newsock->sk = sk_alloc(sock_net(sock->sk), PF_INET, GFP_KERNEL, &pvcalls_proto, false); in pvcalls_front_accept()
886 if (!newsock->sk) { in pvcalls_front_accept()
887 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
888 map->passive.inflight_req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
890 (void *)&map->passive.flags); in pvcalls_front_accept()
893 return -ENOMEM; in pvcalls_front_accept()
895 newsock->sk->sk_send_head = (void *)map2; in pvcalls_front_accept()
897 ret = bedata->rsp[req_id].ret; in pvcalls_front_accept()
898 bedata->rsp[req_id].req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
899 map->passive.inflight_req_id = PVCALLS_INVALID_ID; in pvcalls_front_accept()
901 clear_bit(PVCALLS_FLAG_ACCEPT_INFLIGHT, (void *)&map->passive.flags); in pvcalls_front_accept()
902 wake_up(&map->passive.inflight_accept_req); in pvcalls_front_accept()
917 (void *)&map->passive.flags)) { in pvcalls_front_poll_passive()
918 uint32_t req_id = READ_ONCE(map->passive.inflight_req_id); in pvcalls_front_poll_passive()
921 READ_ONCE(bedata->rsp[req_id].req_id) == req_id) in pvcalls_front_poll_passive()
924 poll_wait(file, &map->passive.inflight_accept_req, wait); in pvcalls_front_poll_passive()
929 (void *)&map->passive.flags)) in pvcalls_front_poll_passive()
939 (void *)&map->passive.flags)) { in pvcalls_front_poll_passive()
940 poll_wait(file, &bedata->inflight_req, wait); in pvcalls_front_poll_passive()
944 spin_lock(&bedata->socket_lock); in pvcalls_front_poll_passive()
947 spin_unlock(&bedata->socket_lock); in pvcalls_front_poll_passive()
950 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_poll_passive()
951 req->req_id = req_id; in pvcalls_front_poll_passive()
952 req->cmd = PVCALLS_POLL; in pvcalls_front_poll_passive()
953 req->u.poll.id = (uintptr_t) map; in pvcalls_front_poll_passive()
955 bedata->ring.req_prod_pvt++; in pvcalls_front_poll_passive()
956 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_poll_passive()
957 spin_unlock(&bedata->socket_lock); in pvcalls_front_poll_passive()
959 notify_remote_via_irq(bedata->irq); in pvcalls_front_poll_passive()
961 poll_wait(file, &bedata->inflight_req, wait); in pvcalls_front_poll_passive()
972 struct pvcalls_data_intf *intf = map->active.ring; in pvcalls_front_poll_active()
974 out_error = intf->out_error; in pvcalls_front_poll_active()
975 in_error = intf->in_error; in pvcalls_front_poll_active()
977 poll_wait(file, &map->active.inflight_conn_req, wait); in pvcalls_front_poll_active()
998 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_poll()
1000 if (map->active_socket) in pvcalls_front_poll()
1015 if (sock->sk == NULL) in pvcalls_front_release()
1020 if (PTR_ERR(map) == -ENOTCONN) in pvcalls_front_release()
1021 return -EIO; in pvcalls_front_release()
1025 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_release()
1027 spin_lock(&bedata->socket_lock); in pvcalls_front_release()
1030 spin_unlock(&bedata->socket_lock); in pvcalls_front_release()
1034 sock->sk->sk_send_head = NULL; in pvcalls_front_release()
1036 req = RING_GET_REQUEST(&bedata->ring, req_id); in pvcalls_front_release()
1037 req->req_id = req_id; in pvcalls_front_release()
1038 req->cmd = PVCALLS_RELEASE; in pvcalls_front_release()
1039 req->u.release.id = (uintptr_t)map; in pvcalls_front_release()
1041 bedata->ring.req_prod_pvt++; in pvcalls_front_release()
1042 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&bedata->ring, notify); in pvcalls_front_release()
1043 spin_unlock(&bedata->socket_lock); in pvcalls_front_release()
1045 notify_remote_via_irq(bedata->irq); in pvcalls_front_release()
1047 wait_event(bedata->inflight_req, in pvcalls_front_release()
1048 READ_ONCE(bedata->rsp[req_id].req_id) == req_id); in pvcalls_front_release()
1050 if (map->active_socket) { in pvcalls_front_release()
1055 map->active.ring->in_error = -EBADF; in pvcalls_front_release()
1056 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_release()
1064 while (atomic_read(&map->refcount) > 1) in pvcalls_front_release()
1069 wake_up(&bedata->inflight_req); in pvcalls_front_release()
1070 wake_up(&map->passive.inflight_accept_req); in pvcalls_front_release()
1072 while (atomic_read(&map->refcount) > 1) in pvcalls_front_release()
1075 spin_lock(&bedata->socket_lock); in pvcalls_front_release()
1076 list_del(&map->list); in pvcalls_front_release()
1077 spin_unlock(&bedata->socket_lock); in pvcalls_front_release()
1078 if (READ_ONCE(map->passive.inflight_req_id) != PVCALLS_INVALID_ID && in pvcalls_front_release()
1079 READ_ONCE(map->passive.inflight_req_id) != 0) { in pvcalls_front_release()
1081 map->passive.accept_map); in pvcalls_front_release()
1085 WRITE_ONCE(bedata->rsp[req_id].req_id, PVCALLS_INVALID_ID); in pvcalls_front_release()
1101 bedata = dev_get_drvdata(&pvcalls_front_dev->dev); in pvcalls_front_remove()
1102 dev_set_drvdata(&dev->dev, NULL); in pvcalls_front_remove()
1104 if (bedata->irq >= 0) in pvcalls_front_remove()
1105 unbind_from_irqhandler(bedata->irq, dev); in pvcalls_front_remove()
1107 list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) { in pvcalls_front_remove()
1108 map->sock->sk->sk_send_head = NULL; in pvcalls_front_remove()
1109 if (map->active_socket) { in pvcalls_front_remove()
1110 map->active.ring->in_error = -EBADF; in pvcalls_front_remove()
1111 wake_up_interruptible(&map->active.inflight_conn_req); in pvcalls_front_remove()
1118 list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) { in pvcalls_front_remove()
1119 if (map->active_socket) { in pvcalls_front_remove()
1123 list_del(&map->list); in pvcalls_front_remove()
1127 if (bedata->ref != -1) in pvcalls_front_remove()
1128 gnttab_end_foreign_access(bedata->ref, NULL); in pvcalls_front_remove()
1129 kfree(bedata->ring.sring); in pvcalls_front_remove()
1137 int ret = -ENOMEM, i; in pvcalls_front_probe()
1147 dev_err(&dev->dev, "only one PV Calls connection supported\n"); in pvcalls_front_probe()
1148 return -EINVAL; in pvcalls_front_probe()
1151 versions = xenbus_read(XBT_NIL, dev->otherend, "versions", &len); in pvcalls_front_probe()
1155 return -EINVAL; in pvcalls_front_probe()
1158 return -EINVAL; in pvcalls_front_probe()
1161 max_page_order = xenbus_read_unsigned(dev->otherend, in pvcalls_front_probe()
1162 "max-page-order", 0); in pvcalls_front_probe()
1164 return -ENODEV; in pvcalls_front_probe()
1165 function_calls = xenbus_read_unsigned(dev->otherend, in pvcalls_front_probe()
1166 "function-calls", 0); in pvcalls_front_probe()
1169 return -ENODEV; in pvcalls_front_probe()
1170 pr_info("%s max-page-order is %u\n", __func__, max_page_order); in pvcalls_front_probe()
1174 return -ENOMEM; in pvcalls_front_probe()
1176 dev_set_drvdata(&dev->dev, bedata); in pvcalls_front_probe()
1178 init_waitqueue_head(&bedata->inflight_req); in pvcalls_front_probe()
1179 INIT_LIST_HEAD(&bedata->socket_mappings); in pvcalls_front_probe()
1180 spin_lock_init(&bedata->socket_lock); in pvcalls_front_probe()
1181 bedata->irq = -1; in pvcalls_front_probe()
1182 bedata->ref = -1; in pvcalls_front_probe()
1185 bedata->rsp[i].req_id = PVCALLS_INVALID_ID; in pvcalls_front_probe()
1192 FRONT_RING_INIT(&bedata->ring, sring, XEN_PAGE_SIZE); in pvcalls_front_probe()
1198 bedata->irq = bind_evtchn_to_irqhandler(evtchn, in pvcalls_front_probe()
1200 0, "pvcalls-frontend", dev); in pvcalls_front_probe()
1201 if (bedata->irq < 0) { in pvcalls_front_probe()
1202 ret = bedata->irq; in pvcalls_front_probe()
1212 bedata->ref = ret; in pvcalls_front_probe()
1213 gnttab_grant_foreign_access_ref(bedata->ref, dev->otherend_id, in pvcalls_front_probe()
1222 ret = xenbus_printf(xbt, dev->nodename, "version", "%u", 1); in pvcalls_front_probe()
1225 ret = xenbus_printf(xbt, dev->nodename, "ring-ref", "%d", bedata->ref); in pvcalls_front_probe()
1228 ret = xenbus_printf(xbt, dev->nodename, "port", "%u", in pvcalls_front_probe()
1234 if (ret == -EAGAIN) in pvcalls_front_probe()
1270 if (dev->state == XenbusStateClosed) in pvcalls_front_changed()
1291 return -ENODEV; in pvcalls_frontend_init()