Lines Matching refs:vq
97 struct vhost_virtqueue *vq; member
108 struct vhost_virtqueue vq; member
228 static void vhost_net_enable_zcopy(int vq) in vhost_net_enable_zcopy() argument
230 vhost_net_zcopy_mask |= 0x1 << vq; in vhost_net_enable_zcopy()
234 vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool zcopy) in vhost_net_ubuf_alloc() argument
245 ubufs->vq = vq; in vhost_net_ubuf_alloc()
359 struct vhost_virtqueue *vq) in vhost_zerocopy_signal_used() argument
362 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_zerocopy_signal_used()
367 if (vq->heads[i].len == VHOST_DMA_FAILED_LEN) in vhost_zerocopy_signal_used()
369 if (VHOST_DMA_IS_DONE(vq->heads[i].len)) { in vhost_zerocopy_signal_used()
370 vq->heads[i].len = VHOST_DMA_CLEAR_LEN; in vhost_zerocopy_signal_used()
377 vhost_add_used_and_signal_n(vq->dev, vq, in vhost_zerocopy_signal_used()
378 &vq->heads[nvq->done_idx], add); in vhost_zerocopy_signal_used()
387 struct vhost_virtqueue *vq = ubufs->vq; in vhost_zerocopy_callback() local
393 vq->heads[ubuf->desc].len = success ? in vhost_zerocopy_callback()
405 vhost_poll_queue(&vq->poll); in vhost_zerocopy_callback()
422 struct vhost_virtqueue *vq) in vhost_net_disable_vq() argument
425 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_disable_vq()
427 if (!vq->private_data) in vhost_net_disable_vq()
433 struct vhost_virtqueue *vq) in vhost_net_enable_vq() argument
436 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_enable_vq()
440 sock = vq->private_data; in vhost_net_enable_vq()
449 struct vhost_virtqueue *vq = &nvq->vq; in vhost_net_signal_used() local
450 struct vhost_dev *dev = vq->dev; in vhost_net_signal_used()
455 vhost_add_used_and_signal_n(dev, vq, vq->heads, nvq->done_idx); in vhost_net_signal_used()
477 vq_err(&nvq->vq, "Fail to batch sending packets\n"); in vhost_tx_batch()
498 struct vhost_virtqueue *vq) in vhost_net_busy_poll_try_queue() argument
500 if (!vhost_vq_avail_empty(&net->dev, vq)) { in vhost_net_busy_poll_try_queue()
501 vhost_poll_queue(&vq->poll); in vhost_net_busy_poll_try_queue()
502 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in vhost_net_busy_poll_try_queue()
503 vhost_disable_notify(&net->dev, vq); in vhost_net_busy_poll_try_queue()
504 vhost_poll_queue(&vq->poll); in vhost_net_busy_poll_try_queue()
517 struct vhost_virtqueue *vq = poll_rx ? tvq : rvq; in vhost_net_busy_poll() local
523 if (!mutex_trylock(&vq->mutex)) in vhost_net_busy_poll()
526 vhost_disable_notify(&net->dev, vq); in vhost_net_busy_poll()
552 vhost_net_busy_poll_try_queue(net, vq); in vhost_net_busy_poll()
556 mutex_unlock(&vq->mutex); in vhost_net_busy_poll()
565 struct vhost_virtqueue *rvq = &rnvq->vq; in vhost_net_tx_get_vq_desc()
566 struct vhost_virtqueue *tvq = &tnvq->vq; in vhost_net_tx_get_vq_desc()
588 struct vhost_virtqueue *vq = &nvq->vq; in vhost_exceeds_maxpend() local
591 min_t(unsigned int, VHOST_MAX_PEND, vq->num >> 2); in vhost_exceeds_maxpend()
594 static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter, in init_iov_iter() argument
598 size_t len = iov_length(vq->iov, out); in init_iov_iter()
600 iov_iter_init(iter, WRITE, vq->iov, out, len); in init_iov_iter()
612 struct vhost_virtqueue *vq = &nvq->vq; in get_tx_bufs() local
617 if (ret < 0 || ret == vq->num) in get_tx_bufs()
621 vq_err(vq, "Unexpected descriptor format for TX: out %d, int %d\n", in get_tx_bufs()
627 *len = init_iov_iter(vq, &msg->msg_iter, nvq->vhost_hlen, *out); in get_tx_bufs()
629 vq_err(vq, "Unexpected header len for TX: %zd expected %zd\n", in get_tx_bufs()
637 static bool tx_can_batch(struct vhost_virtqueue *vq, size_t total_len) in tx_can_batch() argument
640 !vhost_vq_avail_empty(vq->dev, vq); in tx_can_batch()
685 struct vhost_virtqueue *vq = &nvq->vq; in vhost_net_build_xdp() local
686 struct vhost_net *net = container_of(vq->dev, struct vhost_net, in vhost_net_build_xdp()
688 struct socket *sock = vq->private_data; in vhost_net_build_xdp()
726 vhost16_to_cpu(vq, gso->csum_start) + in vhost_net_build_xdp()
727 vhost16_to_cpu(vq, gso->csum_offset) + 2 > in vhost_net_build_xdp()
728 vhost16_to_cpu(vq, gso->hdr_len)) { in vhost_net_build_xdp()
729 gso->hdr_len = cpu_to_vhost16(vq, in vhost_net_build_xdp()
730 vhost16_to_cpu(vq, gso->csum_start) + in vhost_net_build_xdp()
731 vhost16_to_cpu(vq, gso->csum_offset) + 2); in vhost_net_build_xdp()
733 if (vhost16_to_cpu(vq, gso->hdr_len) > len) in vhost_net_build_xdp()
760 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx_copy() local
787 if (head == vq->num) { in handle_tx_copy()
789 vhost_poll_queue(&vq->poll); in handle_tx_copy()
791 vq))) { in handle_tx_copy()
792 vhost_disable_notify(&net->dev, vq); in handle_tx_copy()
809 vhost_discard_vq_desc(vq, 1); in handle_tx_copy()
810 vhost_net_enable_vq(net, vq); in handle_tx_copy()
821 if (tx_can_batch(vq, total_len)) in handle_tx_copy()
830 vhost_discard_vq_desc(vq, 1); in handle_tx_copy()
831 vhost_net_enable_vq(net, vq); in handle_tx_copy()
838 vq->heads[nvq->done_idx].id = cpu_to_vhost32(vq, head); in handle_tx_copy()
839 vq->heads[nvq->done_idx].len = 0; in handle_tx_copy()
841 } while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len))); in handle_tx_copy()
849 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx_zerocopy() local
870 vhost_zerocopy_signal_used(net, vq); in handle_tx_zerocopy()
879 if (head == vq->num) { in handle_tx_zerocopy()
881 vhost_poll_queue(&vq->poll); in handle_tx_zerocopy()
882 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in handle_tx_zerocopy()
883 vhost_disable_notify(&net->dev, vq); in handle_tx_zerocopy()
898 vq->heads[nvq->upend_idx].id = cpu_to_vhost32(vq, head); in handle_tx_zerocopy()
899 vq->heads[nvq->upend_idx].len = VHOST_DMA_IN_PROGRESS; in handle_tx_zerocopy()
916 if (tx_can_batch(vq, total_len) && in handle_tx_zerocopy()
931 vhost_discard_vq_desc(vq, 1); in handle_tx_zerocopy()
932 vhost_net_enable_vq(net, vq); in handle_tx_zerocopy()
939 vhost_add_used_and_signal(&net->dev, vq, head, 0); in handle_tx_zerocopy()
941 vhost_zerocopy_signal_used(net, vq); in handle_tx_zerocopy()
943 } while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len))); in handle_tx_zerocopy()
951 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx() local
954 mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_TX); in handle_tx()
955 sock = vq->private_data; in handle_tx()
959 if (!vq_meta_prefetch(vq)) in handle_tx()
962 vhost_disable_notify(&net->dev, vq); in handle_tx()
963 vhost_net_disable_vq(net, vq); in handle_tx()
971 mutex_unlock(&vq->mutex); in handle_tx()
1000 struct vhost_virtqueue *rvq = &rnvq->vq; in vhost_net_rx_peek_head_len()
1001 struct vhost_virtqueue *tvq = &tnvq->vq; in vhost_net_rx_peek_head_len()
1026 static int get_rx_bufs(struct vhost_virtqueue *vq, in get_rx_bufs() argument
1049 r = vhost_get_vq_desc(vq, vq->iov + seg, in get_rx_bufs()
1050 ARRAY_SIZE(vq->iov) - seg, &out, in get_rx_bufs()
1056 if (d == vq->num) { in get_rx_bufs()
1061 vq_err(vq, "unexpected descriptor format for RX: " in get_rx_bufs()
1070 heads[headcount].id = cpu_to_vhost32(vq, d); in get_rx_bufs()
1071 len = iov_length(vq->iov + seg, in); in get_rx_bufs()
1072 heads[headcount].len = cpu_to_vhost32(vq, len); in get_rx_bufs()
1077 heads[headcount - 1].len = cpu_to_vhost32(vq, len + datalen); in get_rx_bufs()
1089 vhost_discard_vq_desc(vq, headcount); in get_rx_bufs()
1098 struct vhost_virtqueue *vq = &nvq->vq; in handle_rx() local
1123 mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_RX); in handle_rx()
1124 sock = vq->private_data; in handle_rx()
1128 if (!vq_meta_prefetch(vq)) in handle_rx()
1131 vhost_disable_notify(&net->dev, vq); in handle_rx()
1132 vhost_net_disable_vq(net, vq); in handle_rx()
1137 vq_log = unlikely(vhost_has_feature(vq, VHOST_F_LOG_ALL)) ? in handle_rx()
1138 vq->log : NULL; in handle_rx()
1139 mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF); in handle_rx()
1148 headcount = get_rx_bufs(vq, vq->heads + nvq->done_idx, in handle_rx()
1157 vhost_poll_queue(&vq->poll); in handle_rx()
1158 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in handle_rx()
1161 vhost_disable_notify(&net->dev, vq); in handle_rx()
1173 iov_iter_init(&msg.msg_iter, READ, vq->iov, 1, 1); in handle_rx()
1180 iov_iter_init(&msg.msg_iter, READ, vq->iov, in, vhost_len); in handle_rx()
1196 vhost_discard_vq_desc(vq, headcount); in handle_rx()
1203 vq_err(vq, "Unable to write vnet_hdr " in handle_rx()
1204 "at addr %p\n", vq->iov->iov_base); in handle_rx()
1215 num_buffers = cpu_to_vhost16(vq, headcount); in handle_rx()
1219 vq_err(vq, "Failed num_buffers write"); in handle_rx()
1220 vhost_discard_vq_desc(vq, headcount); in handle_rx()
1227 vhost_log_write(vq, vq_log, log, vhost_len, in handle_rx()
1228 vq->iov, in); in handle_rx()
1230 } while (likely(!vhost_exceeds_weight(vq, ++recv_pkts, total_len))); in handle_rx()
1233 vhost_poll_queue(&vq->poll); in handle_rx()
1235 vhost_net_enable_vq(net, vq); in handle_rx()
1238 mutex_unlock(&vq->mutex); in handle_rx()
1243 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue, in handle_tx_kick() local
1245 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev); in handle_tx_kick()
1252 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue, in handle_rx_kick() local
1254 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev); in handle_rx_kick()
1310 vqs[VHOST_NET_VQ_TX] = &n->vqs[VHOST_NET_VQ_TX].vq; in vhost_net_open()
1311 vqs[VHOST_NET_VQ_RX] = &n->vqs[VHOST_NET_VQ_RX].vq; in vhost_net_open()
1312 n->vqs[VHOST_NET_VQ_TX].vq.handle_kick = handle_tx_kick; in vhost_net_open()
1313 n->vqs[VHOST_NET_VQ_RX].vq.handle_kick = handle_rx_kick; in vhost_net_open()
1340 struct vhost_virtqueue *vq) in vhost_net_stop_vq() argument
1344 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_stop_vq()
1346 mutex_lock(&vq->mutex); in vhost_net_stop_vq()
1347 sock = vq->private_data; in vhost_net_stop_vq()
1348 vhost_net_disable_vq(n, vq); in vhost_net_stop_vq()
1349 vq->private_data = NULL; in vhost_net_stop_vq()
1352 mutex_unlock(&vq->mutex); in vhost_net_stop_vq()
1359 *tx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_TX].vq); in vhost_net_stop()
1360 *rx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_RX].vq); in vhost_net_stop()
1366 vhost_poll_flush(&n->vqs[index].vq.poll); in vhost_net_flush_vq()
1374 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1376 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1379 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1382 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1501 struct vhost_virtqueue *vq; in vhost_net_set_backend() local
1515 vq = &n->vqs[index].vq; in vhost_net_set_backend()
1517 mutex_lock(&vq->mutex); in vhost_net_set_backend()
1520 if (!vhost_vq_access_ok(vq)) { in vhost_net_set_backend()
1531 oldsock = vq->private_data; in vhost_net_set_backend()
1533 ubufs = vhost_net_ubuf_alloc(vq, in vhost_net_set_backend()
1540 vhost_net_disable_vq(n, vq); in vhost_net_set_backend()
1541 vq->private_data = sock; in vhost_net_set_backend()
1543 r = vhost_vq_init_access(vq); in vhost_net_set_backend()
1546 r = vhost_net_enable_vq(n, vq); in vhost_net_set_backend()
1560 mutex_unlock(&vq->mutex); in vhost_net_set_backend()
1564 mutex_lock(&vq->mutex); in vhost_net_set_backend()
1565 vhost_zerocopy_signal_used(n, vq); in vhost_net_set_backend()
1566 mutex_unlock(&vq->mutex); in vhost_net_set_backend()
1578 vq->private_data = oldsock; in vhost_net_set_backend()
1579 vhost_net_enable_vq(n, vq); in vhost_net_set_backend()
1586 mutex_unlock(&vq->mutex); in vhost_net_set_backend()
1628 mutex_lock(&n->vqs[i].vq.mutex); in vhost_net_set_backend_features()
1629 n->vqs[i].vq.acked_backend_features = features; in vhost_net_set_backend_features()
1630 mutex_unlock(&n->vqs[i].vq.mutex); in vhost_net_set_backend_features()
1666 mutex_lock(&n->vqs[i].vq.mutex); in vhost_net_set_features()
1667 n->vqs[i].vq.acked_features = features; in vhost_net_set_features()
1670 mutex_unlock(&n->vqs[i].vq.mutex); in vhost_net_set_features()