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()
388 struct vhost_virtqueue *vq = ubufs->vq; in vhost_zerocopy_callback() local
394 vq->heads[ubuf->desc].len = success ? in vhost_zerocopy_callback()
406 vhost_poll_queue(&vq->poll); in vhost_zerocopy_callback()
423 struct vhost_virtqueue *vq) in vhost_net_disable_vq() argument
426 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_disable_vq()
428 if (!vhost_vq_get_backend(vq)) in vhost_net_disable_vq()
434 struct vhost_virtqueue *vq) in vhost_net_enable_vq() argument
437 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_enable_vq()
441 sock = vhost_vq_get_backend(vq); in vhost_net_enable_vq()
450 struct vhost_virtqueue *vq = &nvq->vq; in vhost_net_signal_used() local
451 struct vhost_dev *dev = vq->dev; in vhost_net_signal_used()
456 vhost_add_used_and_signal_n(dev, vq, vq->heads, nvq->done_idx); in vhost_net_signal_used()
478 vq_err(&nvq->vq, "Fail to batch sending packets\n"); in vhost_tx_batch()
508 struct vhost_virtqueue *vq) in vhost_net_busy_poll_try_queue() argument
510 if (!vhost_vq_avail_empty(&net->dev, vq)) { in vhost_net_busy_poll_try_queue()
511 vhost_poll_queue(&vq->poll); in vhost_net_busy_poll_try_queue()
512 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in vhost_net_busy_poll_try_queue()
513 vhost_disable_notify(&net->dev, vq); in vhost_net_busy_poll_try_queue()
514 vhost_poll_queue(&vq->poll); in vhost_net_busy_poll_try_queue()
527 struct vhost_virtqueue *vq = poll_rx ? tvq : rvq; in vhost_net_busy_poll() local
533 if (!mutex_trylock(&vq->mutex)) in vhost_net_busy_poll()
536 vhost_disable_notify(&net->dev, vq); in vhost_net_busy_poll()
562 vhost_net_busy_poll_try_queue(net, vq); in vhost_net_busy_poll()
566 mutex_unlock(&vq->mutex); in vhost_net_busy_poll()
575 struct vhost_virtqueue *rvq = &rnvq->vq; in vhost_net_tx_get_vq_desc()
576 struct vhost_virtqueue *tvq = &tnvq->vq; in vhost_net_tx_get_vq_desc()
600 struct vhost_virtqueue *vq = &nvq->vq; in vhost_exceeds_maxpend() local
603 min_t(unsigned int, VHOST_MAX_PEND, vq->num >> 2); in vhost_exceeds_maxpend()
606 static size_t init_iov_iter(struct vhost_virtqueue *vq, struct iov_iter *iter, in init_iov_iter() argument
610 size_t len = iov_length(vq->iov, out); in init_iov_iter()
612 iov_iter_init(iter, WRITE, vq->iov, out, len); in init_iov_iter()
624 struct vhost_virtqueue *vq = &nvq->vq; in get_tx_bufs() local
629 if (ret < 0 || ret == vq->num) in get_tx_bufs()
633 vq_err(vq, "Unexpected descriptor format for TX: out %d, int %d\n", in get_tx_bufs()
639 *len = init_iov_iter(vq, &msg->msg_iter, nvq->vhost_hlen, *out); in get_tx_bufs()
641 vq_err(vq, "Unexpected header len for TX: %zd expected %zd\n", in get_tx_bufs()
649 static bool tx_can_batch(struct vhost_virtqueue *vq, size_t total_len) in tx_can_batch() argument
652 !vhost_vq_avail_empty(vq->dev, vq); in tx_can_batch()
695 struct vhost_virtqueue *vq = &nvq->vq; in vhost_net_build_xdp() local
696 struct vhost_net *net = container_of(vq->dev, struct vhost_net, in vhost_net_build_xdp()
698 struct socket *sock = vhost_vq_get_backend(vq); in vhost_net_build_xdp()
736 vhost16_to_cpu(vq, gso->csum_start) + in vhost_net_build_xdp()
737 vhost16_to_cpu(vq, gso->csum_offset) + 2 > in vhost_net_build_xdp()
738 vhost16_to_cpu(vq, gso->hdr_len)) { in vhost_net_build_xdp()
739 gso->hdr_len = cpu_to_vhost16(vq, in vhost_net_build_xdp()
740 vhost16_to_cpu(vq, gso->csum_start) + in vhost_net_build_xdp()
741 vhost16_to_cpu(vq, gso->csum_offset) + 2); in vhost_net_build_xdp()
743 if (vhost16_to_cpu(vq, gso->hdr_len) > len) in vhost_net_build_xdp()
769 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx_copy() local
796 if (head == vq->num) { in handle_tx_copy()
798 vhost_poll_queue(&vq->poll); in handle_tx_copy()
800 vq))) { in handle_tx_copy()
801 vhost_disable_notify(&net->dev, vq); in handle_tx_copy()
818 vhost_discard_vq_desc(vq, 1); in handle_tx_copy()
819 vhost_net_enable_vq(net, vq); in handle_tx_copy()
830 if (tx_can_batch(vq, total_len)) in handle_tx_copy()
839 vhost_discard_vq_desc(vq, 1); in handle_tx_copy()
840 vhost_net_enable_vq(net, vq); in handle_tx_copy()
848 vq->heads[nvq->done_idx].id = cpu_to_vhost32(vq, head); in handle_tx_copy()
849 vq->heads[nvq->done_idx].len = 0; in handle_tx_copy()
851 } while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len))); in handle_tx_copy()
859 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx_zerocopy() local
881 vhost_zerocopy_signal_used(net, vq); in handle_tx_zerocopy()
890 if (head == vq->num) { in handle_tx_zerocopy()
892 vhost_poll_queue(&vq->poll); in handle_tx_zerocopy()
893 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in handle_tx_zerocopy()
894 vhost_disable_notify(&net->dev, vq); in handle_tx_zerocopy()
907 vq->heads[nvq->upend_idx].id = cpu_to_vhost32(vq, head); in handle_tx_zerocopy()
908 vq->heads[nvq->upend_idx].len = VHOST_DMA_IN_PROGRESS; in handle_tx_zerocopy()
926 if (tx_can_batch(vq, total_len) && in handle_tx_zerocopy()
936 if (vq->heads[ubuf->desc].len == VHOST_DMA_IN_PROGRESS) in handle_tx_zerocopy()
942 vhost_discard_vq_desc(vq, 1); in handle_tx_zerocopy()
943 vhost_net_enable_vq(net, vq); in handle_tx_zerocopy()
951 vhost_add_used_and_signal(&net->dev, vq, head, 0); in handle_tx_zerocopy()
953 vhost_zerocopy_signal_used(net, vq); in handle_tx_zerocopy()
955 } while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len))); in handle_tx_zerocopy()
963 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx() local
966 mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_TX); in handle_tx()
967 sock = vhost_vq_get_backend(vq); in handle_tx()
971 if (!vq_meta_prefetch(vq)) in handle_tx()
974 vhost_disable_notify(&net->dev, vq); in handle_tx()
975 vhost_net_disable_vq(net, vq); in handle_tx()
983 mutex_unlock(&vq->mutex); in handle_tx()
1012 struct vhost_virtqueue *rvq = &rnvq->vq; in vhost_net_rx_peek_head_len()
1013 struct vhost_virtqueue *tvq = &tnvq->vq; in vhost_net_rx_peek_head_len()
1038 static int get_rx_bufs(struct vhost_virtqueue *vq, in get_rx_bufs() argument
1061 r = vhost_get_vq_desc(vq, vq->iov + seg, in get_rx_bufs()
1062 ARRAY_SIZE(vq->iov) - seg, &out, in get_rx_bufs()
1068 if (d == vq->num) { in get_rx_bufs()
1073 vq_err(vq, "unexpected descriptor format for RX: " in get_rx_bufs()
1082 heads[headcount].id = cpu_to_vhost32(vq, d); in get_rx_bufs()
1083 len = iov_length(vq->iov + seg, in); in get_rx_bufs()
1084 heads[headcount].len = cpu_to_vhost32(vq, len); in get_rx_bufs()
1089 heads[headcount - 1].len = cpu_to_vhost32(vq, len + datalen); in get_rx_bufs()
1101 vhost_discard_vq_desc(vq, headcount); in get_rx_bufs()
1110 struct vhost_virtqueue *vq = &nvq->vq; in handle_rx() local
1135 mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_RX); in handle_rx()
1136 sock = vhost_vq_get_backend(vq); in handle_rx()
1140 if (!vq_meta_prefetch(vq)) in handle_rx()
1143 vhost_disable_notify(&net->dev, vq); in handle_rx()
1144 vhost_net_disable_vq(net, vq); in handle_rx()
1149 vq_log = unlikely(vhost_has_feature(vq, VHOST_F_LOG_ALL)) ? in handle_rx()
1150 vq->log : NULL; in handle_rx()
1151 mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF); in handle_rx()
1160 headcount = get_rx_bufs(vq, vq->heads + nvq->done_idx, in handle_rx()
1169 vhost_poll_queue(&vq->poll); in handle_rx()
1170 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in handle_rx()
1173 vhost_disable_notify(&net->dev, vq); in handle_rx()
1185 iov_iter_init(&msg.msg_iter, READ, vq->iov, 1, 1); in handle_rx()
1192 iov_iter_init(&msg.msg_iter, READ, vq->iov, in, vhost_len); in handle_rx()
1208 vhost_discard_vq_desc(vq, headcount); in handle_rx()
1215 vq_err(vq, "Unable to write vnet_hdr " in handle_rx()
1216 "at addr %p\n", vq->iov->iov_base); in handle_rx()
1227 num_buffers = cpu_to_vhost16(vq, headcount); in handle_rx()
1231 vq_err(vq, "Failed num_buffers write"); in handle_rx()
1232 vhost_discard_vq_desc(vq, headcount); in handle_rx()
1239 vhost_log_write(vq, vq_log, log, vhost_len, in handle_rx()
1240 vq->iov, in); in handle_rx()
1242 } while (likely(!vhost_exceeds_weight(vq, ++recv_pkts, total_len))); in handle_rx()
1245 vhost_poll_queue(&vq->poll); in handle_rx()
1247 vhost_net_enable_vq(net, vq); in handle_rx()
1250 mutex_unlock(&vq->mutex); in handle_rx()
1255 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue, in handle_tx_kick() local
1257 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev); in handle_tx_kick()
1264 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue, in handle_rx_kick() local
1266 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev); in handle_rx_kick()
1322 vqs[VHOST_NET_VQ_TX] = &n->vqs[VHOST_NET_VQ_TX].vq; in vhost_net_open()
1323 vqs[VHOST_NET_VQ_RX] = &n->vqs[VHOST_NET_VQ_RX].vq; in vhost_net_open()
1324 n->vqs[VHOST_NET_VQ_TX].vq.handle_kick = handle_tx_kick; in vhost_net_open()
1325 n->vqs[VHOST_NET_VQ_RX].vq.handle_kick = handle_rx_kick; in vhost_net_open()
1353 struct vhost_virtqueue *vq) in vhost_net_stop_vq() argument
1357 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_stop_vq()
1359 mutex_lock(&vq->mutex); in vhost_net_stop_vq()
1360 sock = vhost_vq_get_backend(vq); in vhost_net_stop_vq()
1361 vhost_net_disable_vq(n, vq); in vhost_net_stop_vq()
1362 vhost_vq_set_backend(vq, NULL); in vhost_net_stop_vq()
1365 mutex_unlock(&vq->mutex); in vhost_net_stop_vq()
1372 *tx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_TX].vq); in vhost_net_stop()
1373 *rx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_RX].vq); in vhost_net_stop()
1379 vhost_poll_flush(&n->vqs[index].vq.poll); in vhost_net_flush_vq()
1387 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1389 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1392 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1395 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1506 struct vhost_virtqueue *vq; in vhost_net_set_backend() local
1520 vq = &n->vqs[index].vq; in vhost_net_set_backend()
1522 mutex_lock(&vq->mutex); in vhost_net_set_backend()
1525 if (!vhost_vq_access_ok(vq)) { in vhost_net_set_backend()
1536 oldsock = vhost_vq_get_backend(vq); in vhost_net_set_backend()
1538 ubufs = vhost_net_ubuf_alloc(vq, in vhost_net_set_backend()
1545 vhost_net_disable_vq(n, vq); in vhost_net_set_backend()
1546 vhost_vq_set_backend(vq, sock); in vhost_net_set_backend()
1548 r = vhost_vq_init_access(vq); in vhost_net_set_backend()
1551 r = vhost_net_enable_vq(n, vq); in vhost_net_set_backend()
1565 mutex_unlock(&vq->mutex); in vhost_net_set_backend()
1569 mutex_lock(&vq->mutex); in vhost_net_set_backend()
1570 vhost_zerocopy_signal_used(n, vq); in vhost_net_set_backend()
1571 mutex_unlock(&vq->mutex); in vhost_net_set_backend()
1583 vhost_vq_set_backend(vq, oldsock); in vhost_net_set_backend()
1584 vhost_net_enable_vq(n, vq); in vhost_net_set_backend()
1591 mutex_unlock(&vq->mutex); in vhost_net_set_backend()
1656 mutex_lock(&n->vqs[i].vq.mutex); in vhost_net_set_features()
1657 n->vqs[i].vq.acked_features = features; in vhost_net_set_features()
1660 mutex_unlock(&n->vqs[i].vq.mutex); in vhost_net_set_features()