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 (!vhost_vq_get_backend(vq)) 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 = vhost_vq_get_backend(vq); 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()
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()
697 struct vhost_virtqueue *vq = &nvq->vq; in vhost_net_build_xdp() local
698 struct vhost_net *net = container_of(vq->dev, struct vhost_net, in vhost_net_build_xdp()
700 struct socket *sock = vhost_vq_get_backend(vq); in vhost_net_build_xdp()
738 vhost16_to_cpu(vq, gso->csum_start) + in vhost_net_build_xdp()
739 vhost16_to_cpu(vq, gso->csum_offset) + 2 > in vhost_net_build_xdp()
740 vhost16_to_cpu(vq, gso->hdr_len)) { in vhost_net_build_xdp()
741 gso->hdr_len = cpu_to_vhost16(vq, in vhost_net_build_xdp()
742 vhost16_to_cpu(vq, gso->csum_start) + in vhost_net_build_xdp()
743 vhost16_to_cpu(vq, gso->csum_offset) + 2); in vhost_net_build_xdp()
745 if (vhost16_to_cpu(vq, gso->hdr_len) > len) in vhost_net_build_xdp()
773 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx_copy() local
800 if (head == vq->num) { in handle_tx_copy()
802 vhost_poll_queue(&vq->poll); in handle_tx_copy()
804 vq))) { in handle_tx_copy()
805 vhost_disable_notify(&net->dev, vq); in handle_tx_copy()
822 vhost_discard_vq_desc(vq, 1); in handle_tx_copy()
823 vhost_net_enable_vq(net, vq); in handle_tx_copy()
834 if (tx_can_batch(vq, total_len)) in handle_tx_copy()
843 vhost_discard_vq_desc(vq, 1); in handle_tx_copy()
844 vhost_net_enable_vq(net, vq); in handle_tx_copy()
851 vq->heads[nvq->done_idx].id = cpu_to_vhost32(vq, head); in handle_tx_copy()
852 vq->heads[nvq->done_idx].len = 0; in handle_tx_copy()
854 } while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len))); in handle_tx_copy()
862 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx_zerocopy() local
884 vhost_zerocopy_signal_used(net, vq); in handle_tx_zerocopy()
893 if (head == vq->num) { in handle_tx_zerocopy()
895 vhost_poll_queue(&vq->poll); in handle_tx_zerocopy()
896 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in handle_tx_zerocopy()
897 vhost_disable_notify(&net->dev, vq); in handle_tx_zerocopy()
910 vq->heads[nvq->upend_idx].id = cpu_to_vhost32(vq, head); in handle_tx_zerocopy()
911 vq->heads[nvq->upend_idx].len = VHOST_DMA_IN_PROGRESS; in handle_tx_zerocopy()
928 if (tx_can_batch(vq, total_len) && in handle_tx_zerocopy()
939 if (vq->heads[ubuf->desc].len == VHOST_DMA_IN_PROGRESS) in handle_tx_zerocopy()
944 vhost_discard_vq_desc(vq, 1); in handle_tx_zerocopy()
945 vhost_net_enable_vq(net, vq); in handle_tx_zerocopy()
952 vhost_add_used_and_signal(&net->dev, vq, head, 0); in handle_tx_zerocopy()
954 vhost_zerocopy_signal_used(net, vq); in handle_tx_zerocopy()
956 } while (likely(!vhost_exceeds_weight(vq, ++sent_pkts, total_len))); in handle_tx_zerocopy()
964 struct vhost_virtqueue *vq = &nvq->vq; in handle_tx() local
967 mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_TX); in handle_tx()
968 sock = vhost_vq_get_backend(vq); in handle_tx()
972 if (!vq_meta_prefetch(vq)) in handle_tx()
975 vhost_disable_notify(&net->dev, vq); in handle_tx()
976 vhost_net_disable_vq(net, vq); in handle_tx()
984 mutex_unlock(&vq->mutex); in handle_tx()
1013 struct vhost_virtqueue *rvq = &rnvq->vq; in vhost_net_rx_peek_head_len()
1014 struct vhost_virtqueue *tvq = &tnvq->vq; in vhost_net_rx_peek_head_len()
1039 static int get_rx_bufs(struct vhost_virtqueue *vq, in get_rx_bufs() argument
1062 r = vhost_get_vq_desc(vq, vq->iov + seg, in get_rx_bufs()
1063 ARRAY_SIZE(vq->iov) - seg, &out, in get_rx_bufs()
1069 if (d == vq->num) { in get_rx_bufs()
1074 vq_err(vq, "unexpected descriptor format for RX: " in get_rx_bufs()
1083 heads[headcount].id = cpu_to_vhost32(vq, d); in get_rx_bufs()
1084 len = iov_length(vq->iov + seg, in); in get_rx_bufs()
1085 heads[headcount].len = cpu_to_vhost32(vq, len); in get_rx_bufs()
1090 heads[headcount - 1].len = cpu_to_vhost32(vq, len + datalen); in get_rx_bufs()
1102 vhost_discard_vq_desc(vq, headcount); in get_rx_bufs()
1111 struct vhost_virtqueue *vq = &nvq->vq; in handle_rx() local
1136 mutex_lock_nested(&vq->mutex, VHOST_NET_VQ_RX); in handle_rx()
1137 sock = vhost_vq_get_backend(vq); in handle_rx()
1141 if (!vq_meta_prefetch(vq)) in handle_rx()
1144 vhost_disable_notify(&net->dev, vq); in handle_rx()
1145 vhost_net_disable_vq(net, vq); in handle_rx()
1150 vq_log = unlikely(vhost_has_feature(vq, VHOST_F_LOG_ALL)) ? in handle_rx()
1151 vq->log : NULL; in handle_rx()
1152 mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF); in handle_rx()
1161 headcount = get_rx_bufs(vq, vq->heads + nvq->done_idx, in handle_rx()
1170 vhost_poll_queue(&vq->poll); in handle_rx()
1171 } else if (unlikely(vhost_enable_notify(&net->dev, vq))) { in handle_rx()
1174 vhost_disable_notify(&net->dev, vq); in handle_rx()
1186 iov_iter_init(&msg.msg_iter, READ, vq->iov, 1, 1); in handle_rx()
1193 iov_iter_init(&msg.msg_iter, READ, vq->iov, in, vhost_len); in handle_rx()
1209 vhost_discard_vq_desc(vq, headcount); in handle_rx()
1216 vq_err(vq, "Unable to write vnet_hdr " in handle_rx()
1217 "at addr %p\n", vq->iov->iov_base); in handle_rx()
1228 num_buffers = cpu_to_vhost16(vq, headcount); in handle_rx()
1232 vq_err(vq, "Failed num_buffers write"); in handle_rx()
1233 vhost_discard_vq_desc(vq, headcount); in handle_rx()
1240 vhost_log_write(vq, vq_log, log, vhost_len, in handle_rx()
1241 vq->iov, in); in handle_rx()
1243 } while (likely(!vhost_exceeds_weight(vq, ++recv_pkts, total_len))); in handle_rx()
1246 vhost_poll_queue(&vq->poll); in handle_rx()
1248 vhost_net_enable_vq(net, vq); in handle_rx()
1251 mutex_unlock(&vq->mutex); in handle_rx()
1256 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue, in handle_tx_kick() local
1258 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev); in handle_tx_kick()
1265 struct vhost_virtqueue *vq = container_of(work, struct vhost_virtqueue, in handle_rx_kick() local
1267 struct vhost_net *net = container_of(vq->dev, struct vhost_net, dev); in handle_rx_kick()
1323 vqs[VHOST_NET_VQ_TX] = &n->vqs[VHOST_NET_VQ_TX].vq; in vhost_net_open()
1324 vqs[VHOST_NET_VQ_RX] = &n->vqs[VHOST_NET_VQ_RX].vq; in vhost_net_open()
1325 n->vqs[VHOST_NET_VQ_TX].vq.handle_kick = handle_tx_kick; in vhost_net_open()
1326 n->vqs[VHOST_NET_VQ_RX].vq.handle_kick = handle_rx_kick; in vhost_net_open()
1354 struct vhost_virtqueue *vq) in vhost_net_stop_vq() argument
1358 container_of(vq, struct vhost_net_virtqueue, vq); in vhost_net_stop_vq()
1360 mutex_lock(&vq->mutex); in vhost_net_stop_vq()
1361 sock = vhost_vq_get_backend(vq); in vhost_net_stop_vq()
1362 vhost_net_disable_vq(n, vq); in vhost_net_stop_vq()
1363 vhost_vq_set_backend(vq, NULL); in vhost_net_stop_vq()
1366 mutex_unlock(&vq->mutex); in vhost_net_stop_vq()
1373 *tx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_TX].vq); in vhost_net_stop()
1374 *rx_sock = vhost_net_stop_vq(n, &n->vqs[VHOST_NET_VQ_RX].vq); in vhost_net_stop()
1380 vhost_poll_flush(&n->vqs[index].vq.poll); in vhost_net_flush_vq()
1388 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1390 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1393 mutex_lock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1396 mutex_unlock(&n->vqs[VHOST_NET_VQ_TX].vq.mutex); in vhost_net_flush()
1502 struct vhost_virtqueue *vq; in vhost_net_set_backend() local
1516 vq = &n->vqs[index].vq; in vhost_net_set_backend()
1518 mutex_lock(&vq->mutex); in vhost_net_set_backend()
1521 if (!vhost_vq_access_ok(vq)) { in vhost_net_set_backend()
1532 oldsock = vhost_vq_get_backend(vq); in vhost_net_set_backend()
1534 ubufs = vhost_net_ubuf_alloc(vq, in vhost_net_set_backend()
1541 vhost_net_disable_vq(n, vq); in vhost_net_set_backend()
1542 vhost_vq_set_backend(vq, sock); in vhost_net_set_backend()
1544 r = vhost_vq_init_access(vq); in vhost_net_set_backend()
1547 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()