Lines Matching full:vi
392 /* Find end of list, sew whole thing into vi->rq.pages. */ in give_pages()
411 static void enable_delayed_refill(struct virtnet_info *vi) in enable_delayed_refill() argument
413 spin_lock_bh(&vi->refill_lock); in enable_delayed_refill()
414 vi->refill_enabled = true; in enable_delayed_refill()
415 spin_unlock_bh(&vi->refill_lock); in enable_delayed_refill()
418 static void disable_delayed_refill(struct virtnet_info *vi) in disable_delayed_refill() argument
420 spin_lock_bh(&vi->refill_lock); in disable_delayed_refill()
421 vi->refill_enabled = false; in disable_delayed_refill()
422 spin_unlock_bh(&vi->refill_lock); in disable_delayed_refill()
450 struct virtnet_info *vi = vq->vdev->priv; in skb_xmit_done() local
451 struct napi_struct *napi = &vi->sq[vq2txq(vq)].napi; in skb_xmit_done()
460 netif_wake_subqueue(vi->dev, vq2txq(vq)); in skb_xmit_done()
497 static struct sk_buff *page_to_skb(struct virtnet_info *vi, in page_to_skb() argument
513 hdr_len = vi->hdr_len; in page_to_skb()
514 if (vi->mergeable_rx_bufs) in page_to_skb()
556 if (vi->mergeable_rx_bufs) { in page_to_skb()
731 static void virtnet_rq_set_premapped(struct virtnet_info *vi) in virtnet_rq_set_premapped() argument
736 if (!vi->mergeable_rx_bufs && vi->big_packets) in virtnet_rq_set_premapped()
739 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_rq_set_premapped()
740 if (virtqueue_set_dma_premapped(vi->rq[i].vq)) in virtnet_rq_set_premapped()
743 vi->rq[i].do_dma = true; in virtnet_rq_set_premapped()
783 static bool is_xdp_raw_buffer_queue(struct virtnet_info *vi, int q) in is_xdp_raw_buffer_queue() argument
785 if (q < (vi->curr_queue_pairs - vi->xdp_queue_pairs)) in is_xdp_raw_buffer_queue()
787 else if (q < vi->curr_queue_pairs) in is_xdp_raw_buffer_queue()
793 static void check_sq_full_and_disable(struct virtnet_info *vi, in check_sq_full_and_disable() argument
800 qnum = sq - vi->sq; in check_sq_full_and_disable()
828 static int __virtnet_xdp_xmit_one(struct virtnet_info *vi, in __virtnet_xdp_xmit_one() argument
837 if (unlikely(xdpf->headroom < vi->hdr_len)) in __virtnet_xdp_xmit_one()
852 xdpf->headroom -= vi->hdr_len; in __virtnet_xdp_xmit_one()
853 xdpf->data -= vi->hdr_len; in __virtnet_xdp_xmit_one()
856 memset(hdr, 0, vi->hdr_len); in __virtnet_xdp_xmit_one()
857 xdpf->len += vi->hdr_len; in __virtnet_xdp_xmit_one()
876 /* when vi->curr_queue_pairs > nr_cpu_ids, the txq/sq is only used for xdp tx on
884 #define virtnet_xdp_get_sq(vi) ({ \ argument
887 typeof(vi) v = (vi); \
903 #define virtnet_xdp_put_sq(vi, q) { \ argument
905 typeof(vi) v = (vi); \
917 struct virtnet_info *vi = netdev_priv(dev); in virtnet_xdp_xmit() local
918 struct receive_queue *rq = vi->rq; in virtnet_xdp_xmit()
937 sq = virtnet_xdp_get_sq(vi); in virtnet_xdp_xmit()
963 if (__virtnet_xdp_xmit_one(vi, sq, xdpf)) in virtnet_xdp_xmit()
969 if (!is_xdp_raw_buffer_queue(vi, sq - vi->sq)) in virtnet_xdp_xmit()
970 check_sq_full_and_disable(vi, dev, sq); in virtnet_xdp_xmit()
985 virtnet_xdp_put_sq(vi, sq); in virtnet_xdp_xmit()
1058 static unsigned int virtnet_get_headroom(struct virtnet_info *vi) in virtnet_get_headroom() argument
1060 return vi->xdp_enabled ? VIRTIO_XDP_HEADROOM : 0; in virtnet_get_headroom()
1131 static struct sk_buff *receive_small_build_skb(struct virtnet_info *vi, in receive_small_build_skb() argument
1142 headroom = vi->hdr_len + header_offset; in receive_small_build_skb()
1151 memcpy(skb_vnet_common_hdr(skb), buf, vi->hdr_len); in receive_small_build_skb()
1157 struct virtnet_info *vi, in receive_small_xdp() argument
1167 unsigned int headroom = vi->hdr_len + header_offset; in receive_small_xdp()
1183 if (unlikely(xdp_headroom < virtnet_get_headroom(vi))) { in receive_small_xdp()
1185 unsigned int tlen = len + vi->hdr_len; in receive_small_xdp()
1188 xdp_headroom = virtnet_get_headroom(vi); in receive_small_xdp()
1190 headroom = vi->hdr_len + header_offset; in receive_small_xdp()
1205 xdp_prepare_buff(&xdp, buf + VIRTNET_RX_PAD + vi->hdr_len, in receive_small_xdp()
1244 struct virtnet_info *vi, in receive_small() argument
1255 len -= vi->hdr_len; in receive_small()
1265 if (unlikely(vi->xdp_enabled)) { in receive_small()
1271 skb = receive_small_xdp(dev, vi, rq, xdp_prog, buf, in receive_small()
1280 skb = receive_small_build_skb(vi, xdp_headroom, buf, len); in receive_small()
1291 struct virtnet_info *vi, in receive_big() argument
1299 page_to_skb(vi, rq, page, 0, len, PAGE_SIZE, 0); in receive_big()
1301 stats->bytes += len - vi->hdr_len; in receive_big()
1343 struct virtnet_info *vi, in build_skb_from_xdp_buff() argument
1386 struct virtnet_info *vi, in virtnet_build_xdp_buff_mrg() argument
1408 VIRTIO_XDP_HEADROOM + vi->hdr_len, len - vi->hdr_len, true); in virtnet_build_xdp_buff_mrg()
1434 virtio16_to_cpu(vi->vdev, hdr->num_buffers)); in virtnet_build_xdp_buff_mrg()
1474 static void *mergeable_xdp_get_buf(struct virtnet_info *vi, in mergeable_xdp_get_buf() argument
1504 if (likely(headroom >= virtnet_get_headroom(vi) && in mergeable_xdp_get_buf()
1549 struct virtnet_info *vi, in receive_mergeable_xdp() argument
1559 int num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers); in receive_mergeable_xdp()
1570 data = mergeable_xdp_get_buf(vi, rq, xdp_prog, ctx, &frame_sz, &num_buf, &page, in receive_mergeable_xdp()
1575 err = virtnet_build_xdp_buff_mrg(dev, vi, rq, &xdp, data, len, frame_sz, in receive_mergeable_xdp()
1584 head_skb = build_skb_from_xdp_buff(dev, vi, &xdp, xdp_frags_truesz); in receive_mergeable_xdp()
1609 struct virtnet_info *vi, in receive_mergeable() argument
1618 int num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers); in receive_mergeable()
1628 stats->bytes += len - vi->hdr_len; in receive_mergeable()
1637 if (unlikely(vi->xdp_enabled)) { in receive_mergeable()
1643 head_skb = receive_mergeable_xdp(dev, vi, rq, xdp_prog, buf, ctx, in receive_mergeable()
1651 head_skb = page_to_skb(vi, rq, page, offset, len, truesize, headroom); in receive_mergeable()
1663 virtio16_to_cpu(vi->vdev, in receive_mergeable()
1755 static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, in receive_buf() argument
1760 struct net_device *dev = vi->dev; in receive_buf()
1764 if (unlikely(len < vi->hdr_len + ETH_HLEN)) { in receive_buf()
1771 if (vi->mergeable_rx_bufs) in receive_buf()
1772 skb = receive_mergeable(dev, vi, rq, buf, ctx, len, xdp_xmit, in receive_buf()
1774 else if (vi->big_packets) in receive_buf()
1775 skb = receive_big(dev, vi, rq, buf, len, stats); in receive_buf()
1777 skb = receive_small(dev, vi, rq, buf, ctx, len, xdp_xmit, stats); in receive_buf()
1783 if (dev->features & NETIF_F_RXHASH && vi->has_rss_hash_report) in receive_buf()
1790 virtio_is_little_endian(vi->vdev))) { in receive_buf()
1815 static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq, in add_recvbuf_small() argument
1819 unsigned int xdp_headroom = virtnet_get_headroom(vi); in add_recvbuf_small()
1821 int len = vi->hdr_len + VIRTNET_RX_PAD + GOOD_PACKET_LEN + xdp_headroom; in add_recvbuf_small()
1832 vi->hdr_len + GOOD_PACKET_LEN); in add_recvbuf_small()
1844 static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq, in add_recvbuf_big() argument
1851 sg_init_table(rq->sg, vi->big_packets_num_skbfrags + 2); in add_recvbuf_big()
1853 /* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ in add_recvbuf_big()
1854 for (i = vi->big_packets_num_skbfrags + 1; i > 1; --i) { in add_recvbuf_big()
1877 sg_set_buf(&rq->sg[0], p, vi->hdr_len); in add_recvbuf_big()
1885 err = virtqueue_add_inbuf(rq->vq, rq->sg, vi->big_packets_num_skbfrags + 2, in add_recvbuf_big()
1897 struct virtnet_info *vi = rq->vq->vdev->priv; in get_mergeable_buf_len() local
1898 const size_t hdr_len = vi->hdr_len; in get_mergeable_buf_len()
1910 static int add_recvbuf_mergeable(struct virtnet_info *vi, in add_recvbuf_mergeable() argument
1914 unsigned int headroom = virtnet_get_headroom(vi); in add_recvbuf_mergeable()
1966 static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq, in try_fill_recv() argument
1973 if (vi->mergeable_rx_bufs) in try_fill_recv()
1974 err = add_recvbuf_mergeable(vi, rq, gfp); in try_fill_recv()
1975 else if (vi->big_packets) in try_fill_recv()
1976 err = add_recvbuf_big(vi, rq, gfp); in try_fill_recv()
1978 err = add_recvbuf_small(vi, rq, gfp); in try_fill_recv()
1997 struct virtnet_info *vi = rvq->vdev->priv; in skb_recv_done() local
1998 struct receive_queue *rq = &vi->rq[vq2rxq(rvq)]; in skb_recv_done()
2016 static void virtnet_napi_tx_enable(struct virtnet_info *vi, in virtnet_napi_tx_enable() argument
2026 if (!vi->affinity_hint_set) { in virtnet_napi_tx_enable()
2042 struct virtnet_info *vi = in refill_work() local
2047 for (i = 0; i < vi->curr_queue_pairs; i++) { in refill_work()
2048 struct receive_queue *rq = &vi->rq[i]; in refill_work()
2051 still_empty = !try_fill_recv(vi, rq, GFP_KERNEL); in refill_work()
2058 schedule_delayed_work(&vi->refill, HZ/2); in refill_work()
2065 struct virtnet_info *vi = rq->vq->vdev->priv; in virtnet_receive() local
2071 if (!vi->big_packets || vi->mergeable_rx_bufs) { in virtnet_receive()
2076 receive_buf(vi, rq, buf, len, ctx, xdp_xmit, &stats); in virtnet_receive()
2082 receive_buf(vi, rq, buf, len, NULL, xdp_xmit, &stats); in virtnet_receive()
2088 if (!try_fill_recv(vi, rq, GFP_ATOMIC)) { in virtnet_receive()
2089 spin_lock(&vi->refill_lock); in virtnet_receive()
2090 if (vi->refill_enabled) in virtnet_receive()
2091 schedule_delayed_work(&vi->refill, 0); in virtnet_receive()
2092 spin_unlock(&vi->refill_lock); in virtnet_receive()
2111 struct virtnet_info *vi = rq->vq->vdev->priv; in virtnet_poll_cleantx() local
2113 struct send_queue *sq = &vi->sq[index]; in virtnet_poll_cleantx()
2114 struct netdev_queue *txq = netdev_get_tx_queue(vi->dev, index); in virtnet_poll_cleantx()
2116 if (!sq->napi.weight || is_xdp_raw_buffer_queue(vi, index)) in virtnet_poll_cleantx()
2141 struct virtnet_info *vi = rq->vq->vdev->priv; in virtnet_poll() local
2158 sq = virtnet_xdp_get_sq(vi); in virtnet_poll()
2164 virtnet_xdp_put_sq(vi, sq); in virtnet_poll()
2170 static void virtnet_disable_queue_pair(struct virtnet_info *vi, int qp_index) in virtnet_disable_queue_pair() argument
2172 virtnet_napi_tx_disable(&vi->sq[qp_index].napi); in virtnet_disable_queue_pair()
2173 napi_disable(&vi->rq[qp_index].napi); in virtnet_disable_queue_pair()
2174 xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); in virtnet_disable_queue_pair()
2177 static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) in virtnet_enable_queue_pair() argument
2179 struct net_device *dev = vi->dev; in virtnet_enable_queue_pair()
2182 err = xdp_rxq_info_reg(&vi->rq[qp_index].xdp_rxq, dev, qp_index, in virtnet_enable_queue_pair()
2183 vi->rq[qp_index].napi.napi_id); in virtnet_enable_queue_pair()
2187 err = xdp_rxq_info_reg_mem_model(&vi->rq[qp_index].xdp_rxq, in virtnet_enable_queue_pair()
2192 virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi); in virtnet_enable_queue_pair()
2193 virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi); in virtnet_enable_queue_pair()
2198 xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); in virtnet_enable_queue_pair()
2204 struct virtnet_info *vi = netdev_priv(dev); in virtnet_open() local
2207 enable_delayed_refill(vi); in virtnet_open()
2209 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_open()
2210 if (i < vi->curr_queue_pairs) in virtnet_open()
2212 if (!try_fill_recv(vi, &vi->rq[i], GFP_KERNEL)) in virtnet_open()
2213 schedule_delayed_work(&vi->refill, 0); in virtnet_open()
2215 err = virtnet_enable_queue_pair(vi, i); in virtnet_open()
2223 disable_delayed_refill(vi); in virtnet_open()
2224 cancel_delayed_work_sync(&vi->refill); in virtnet_open()
2227 virtnet_disable_queue_pair(vi, i); in virtnet_open()
2234 struct virtnet_info *vi = sq->vq->vdev->priv; in virtnet_poll_tx() local
2240 if (unlikely(is_xdp_raw_buffer_queue(vi, index))) { in virtnet_poll_tx()
2246 txq = netdev_get_tx_queue(vi->dev, index); in virtnet_poll_tx()
2281 struct virtnet_info *vi = sq->vq->vdev->priv; in xmit_skb() local
2283 unsigned hdr_len = vi->hdr_len; in xmit_skb()
2286 pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); in xmit_skb()
2288 can_push = vi->any_header_sg && in xmit_skb()
2299 virtio_is_little_endian(vi->vdev), false, in xmit_skb()
2303 if (vi->mergeable_rx_bufs) in xmit_skb()
2326 struct virtnet_info *vi = netdev_priv(dev); in start_xmit() local
2328 struct send_queue *sq = &vi->sq[qnum]; in start_xmit()
2368 check_sq_full_and_disable(vi, dev, sq); in start_xmit()
2381 static int virtnet_rx_resize(struct virtnet_info *vi, in virtnet_rx_resize() argument
2384 bool running = netif_running(vi->dev); in virtnet_rx_resize()
2387 qindex = rq - vi->rq; in virtnet_rx_resize()
2394 netdev_err(vi->dev, "resize rx fail: rx queue index: %d err: %d\n", qindex, err); in virtnet_rx_resize()
2396 if (!try_fill_recv(vi, rq, GFP_KERNEL)) in virtnet_rx_resize()
2397 schedule_delayed_work(&vi->refill, 0); in virtnet_rx_resize()
2404 static int virtnet_tx_resize(struct virtnet_info *vi, in virtnet_tx_resize() argument
2407 bool running = netif_running(vi->dev); in virtnet_tx_resize()
2411 qindex = sq - vi->sq; in virtnet_tx_resize()
2416 txq = netdev_get_tx_queue(vi->dev, qindex); in virtnet_tx_resize()
2427 netif_stop_subqueue(vi->dev, qindex); in virtnet_tx_resize()
2433 netdev_err(vi->dev, "resize tx fail: tx queue index: %d err: %d\n", qindex, err); in virtnet_tx_resize()
2441 virtnet_napi_tx_enable(vi, sq->vq, &sq->napi); in virtnet_tx_resize()
2450 static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd, in virtnet_send_command() argument
2458 BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)); in virtnet_send_command()
2460 vi->ctrl->status = ~0; in virtnet_send_command()
2461 vi->ctrl->hdr.class = class; in virtnet_send_command()
2462 vi->ctrl->hdr.cmd = cmd; in virtnet_send_command()
2464 sg_init_one(&hdr, &vi->ctrl->hdr, sizeof(vi->ctrl->hdr)); in virtnet_send_command()
2471 sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status)); in virtnet_send_command()
2475 ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC); in virtnet_send_command()
2477 dev_warn(&vi->vdev->dev, in virtnet_send_command()
2482 if (unlikely(!virtqueue_kick(vi->cvq))) in virtnet_send_command()
2483 return vi->ctrl->status == VIRTIO_NET_OK; in virtnet_send_command()
2488 while (!virtqueue_get_buf(vi->cvq, &tmp) && in virtnet_send_command()
2489 !virtqueue_is_broken(vi->cvq)) in virtnet_send_command()
2492 return vi->ctrl->status == VIRTIO_NET_OK; in virtnet_send_command()
2497 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_mac_address() local
2498 struct virtio_device *vdev = vi->vdev; in virtnet_set_mac_address()
2503 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STANDBY)) in virtnet_set_mac_address()
2516 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, in virtnet_set_mac_address()
2545 struct virtnet_info *vi = netdev_priv(dev); in virtnet_stats() local
2549 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_stats()
2551 struct receive_queue *rq = &vi->rq[i]; in virtnet_stats()
2552 struct send_queue *sq = &vi->sq[i]; in virtnet_stats()
2582 static void virtnet_ack_link_announce(struct virtnet_info *vi) in virtnet_ack_link_announce() argument
2585 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_ANNOUNCE, in virtnet_ack_link_announce()
2587 dev_warn(&vi->dev->dev, "Failed to ack link announce.\n"); in virtnet_ack_link_announce()
2591 static int _virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) in _virtnet_set_queues() argument
2594 struct net_device *dev = vi->dev; in _virtnet_set_queues()
2596 if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ)) in _virtnet_set_queues()
2599 vi->ctrl->mq.virtqueue_pairs = cpu_to_virtio16(vi->vdev, queue_pairs); in _virtnet_set_queues()
2600 sg_init_one(&sg, &vi->ctrl->mq, sizeof(vi->ctrl->mq)); in _virtnet_set_queues()
2602 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, in _virtnet_set_queues()
2608 vi->curr_queue_pairs = queue_pairs; in _virtnet_set_queues()
2611 schedule_delayed_work(&vi->refill, 0); in _virtnet_set_queues()
2617 static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) in virtnet_set_queues() argument
2622 err = _virtnet_set_queues(vi, queue_pairs); in virtnet_set_queues()
2629 struct virtnet_info *vi = netdev_priv(dev); in virtnet_close() local
2633 disable_delayed_refill(vi); in virtnet_close()
2635 cancel_delayed_work_sync(&vi->refill); in virtnet_close()
2637 for (i = 0; i < vi->max_queue_pairs; i++) in virtnet_close()
2638 virtnet_disable_queue_pair(vi, i); in virtnet_close()
2645 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_rx_mode() local
2655 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX)) in virtnet_set_rx_mode()
2658 vi->ctrl->promisc = ((dev->flags & IFF_PROMISC) != 0); in virtnet_set_rx_mode()
2659 vi->ctrl->allmulti = ((dev->flags & IFF_ALLMULTI) != 0); in virtnet_set_rx_mode()
2661 sg_init_one(sg, &vi->ctrl->promisc, sizeof(vi->ctrl->promisc)); in virtnet_set_rx_mode()
2663 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, in virtnet_set_rx_mode()
2666 vi->ctrl->promisc ? "en" : "dis"); in virtnet_set_rx_mode()
2668 sg_init_one(sg, &vi->ctrl->allmulti, sizeof(vi->ctrl->allmulti)); in virtnet_set_rx_mode()
2670 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, in virtnet_set_rx_mode()
2673 vi->ctrl->allmulti ? "en" : "dis"); in virtnet_set_rx_mode()
2687 mac_data->entries = cpu_to_virtio32(vi->vdev, uc_count); in virtnet_set_rx_mode()
2698 mac_data->entries = cpu_to_virtio32(vi->vdev, mc_count); in virtnet_set_rx_mode()
2706 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, in virtnet_set_rx_mode()
2716 struct virtnet_info *vi = netdev_priv(dev); in virtnet_vlan_rx_add_vid() local
2719 vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid); in virtnet_vlan_rx_add_vid()
2720 sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid)); in virtnet_vlan_rx_add_vid()
2722 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN, in virtnet_vlan_rx_add_vid()
2731 struct virtnet_info *vi = netdev_priv(dev); in virtnet_vlan_rx_kill_vid() local
2734 vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid); in virtnet_vlan_rx_kill_vid()
2735 sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid)); in virtnet_vlan_rx_kill_vid()
2737 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN, in virtnet_vlan_rx_kill_vid()
2743 static void virtnet_clean_affinity(struct virtnet_info *vi) in virtnet_clean_affinity() argument
2747 if (vi->affinity_hint_set) { in virtnet_clean_affinity()
2748 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_clean_affinity()
2749 virtqueue_set_affinity(vi->rq[i].vq, NULL); in virtnet_clean_affinity()
2750 virtqueue_set_affinity(vi->sq[i].vq, NULL); in virtnet_clean_affinity()
2753 vi->affinity_hint_set = false; in virtnet_clean_affinity()
2757 static void virtnet_set_affinity(struct virtnet_info *vi) in virtnet_set_affinity() argument
2767 virtnet_clean_affinity(vi); in virtnet_set_affinity()
2772 stride = max_t(int, num_cpu / vi->curr_queue_pairs, 1); in virtnet_set_affinity()
2773 stragglers = num_cpu >= vi->curr_queue_pairs ? in virtnet_set_affinity()
2774 num_cpu % vi->curr_queue_pairs : in virtnet_set_affinity()
2778 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_set_affinity()
2786 virtqueue_set_affinity(vi->rq[i].vq, mask); in virtnet_set_affinity()
2787 virtqueue_set_affinity(vi->sq[i].vq, mask); in virtnet_set_affinity()
2788 __netif_set_xps_queue(vi->dev, cpumask_bits(mask), i, XPS_CPUS); in virtnet_set_affinity()
2792 vi->affinity_hint_set = true; in virtnet_set_affinity()
2798 struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, in virtnet_cpu_online() local
2800 virtnet_set_affinity(vi); in virtnet_cpu_online()
2806 struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, in virtnet_cpu_dead() local
2808 virtnet_set_affinity(vi); in virtnet_cpu_dead()
2814 struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, in virtnet_cpu_down_prep() local
2817 virtnet_clean_affinity(vi); in virtnet_cpu_down_prep()
2823 static int virtnet_cpu_notif_add(struct virtnet_info *vi) in virtnet_cpu_notif_add() argument
2827 ret = cpuhp_state_add_instance_nocalls(virtionet_online, &vi->node); in virtnet_cpu_notif_add()
2831 &vi->node_dead); in virtnet_cpu_notif_add()
2834 cpuhp_state_remove_instance_nocalls(virtionet_online, &vi->node); in virtnet_cpu_notif_add()
2838 static void virtnet_cpu_notif_remove(struct virtnet_info *vi) in virtnet_cpu_notif_remove() argument
2840 cpuhp_state_remove_instance_nocalls(virtionet_online, &vi->node); in virtnet_cpu_notif_remove()
2842 &vi->node_dead); in virtnet_cpu_notif_remove()
2850 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_ringparam() local
2852 ring->rx_max_pending = vi->rq[0].vq->num_max; in virtnet_get_ringparam()
2853 ring->tx_max_pending = vi->sq[0].vq->num_max; in virtnet_get_ringparam()
2854 ring->rx_pending = virtqueue_get_vring_size(vi->rq[0].vq); in virtnet_get_ringparam()
2855 ring->tx_pending = virtqueue_get_vring_size(vi->sq[0].vq); in virtnet_get_ringparam()
2863 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_ringparam() local
2872 rx_pending = virtqueue_get_vring_size(vi->rq[0].vq); in virtnet_set_ringparam()
2873 tx_pending = virtqueue_get_vring_size(vi->sq[0].vq); in virtnet_set_ringparam()
2879 if (ring->rx_pending > vi->rq[0].vq->num_max) in virtnet_set_ringparam()
2882 if (ring->tx_pending > vi->sq[0].vq->num_max) in virtnet_set_ringparam()
2885 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_set_ringparam()
2886 rq = vi->rq + i; in virtnet_set_ringparam()
2887 sq = vi->sq + i; in virtnet_set_ringparam()
2890 err = virtnet_tx_resize(vi, sq, ring->tx_pending); in virtnet_set_ringparam()
2896 err = virtnet_rx_resize(vi, rq, ring->rx_pending); in virtnet_set_ringparam()
2905 static bool virtnet_commit_rss_command(struct virtnet_info *vi) in virtnet_commit_rss_command() argument
2907 struct net_device *dev = vi->dev; in virtnet_commit_rss_command()
2915 sg_set_buf(&sgs[0], &vi->ctrl->rss, sg_buf_size); in virtnet_commit_rss_command()
2917 sg_buf_size = sizeof(uint16_t) * (vi->ctrl->rss.indirection_table_mask + 1); in virtnet_commit_rss_command()
2918 sg_set_buf(&sgs[1], vi->ctrl->rss.indirection_table, sg_buf_size); in virtnet_commit_rss_command()
2922 sg_set_buf(&sgs[2], &vi->ctrl->rss.max_tx_vq, sg_buf_size); in virtnet_commit_rss_command()
2924 sg_buf_size = vi->rss_key_size; in virtnet_commit_rss_command()
2925 sg_set_buf(&sgs[3], vi->ctrl->rss.key, sg_buf_size); in virtnet_commit_rss_command()
2927 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, in virtnet_commit_rss_command()
2928 vi->has_rss ? VIRTIO_NET_CTRL_MQ_RSS_CONFIG in virtnet_commit_rss_command()
2936 static void virtnet_init_default_rss(struct virtnet_info *vi) in virtnet_init_default_rss() argument
2941 vi->ctrl->rss.hash_types = vi->rss_hash_types_supported; in virtnet_init_default_rss()
2942 vi->rss_hash_types_saved = vi->rss_hash_types_supported; in virtnet_init_default_rss()
2943 vi->ctrl->rss.indirection_table_mask = vi->rss_indir_table_size in virtnet_init_default_rss()
2944 ? vi->rss_indir_table_size - 1 : 0; in virtnet_init_default_rss()
2945 vi->ctrl->rss.unclassified_queue = 0; in virtnet_init_default_rss()
2947 for (; i < vi->rss_indir_table_size; ++i) { in virtnet_init_default_rss()
2948 indir_val = ethtool_rxfh_indir_default(i, vi->curr_queue_pairs); in virtnet_init_default_rss()
2949 vi->ctrl->rss.indirection_table[i] = indir_val; in virtnet_init_default_rss()
2952 vi->ctrl->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0; in virtnet_init_default_rss()
2953 vi->ctrl->rss.hash_key_length = vi->rss_key_size; in virtnet_init_default_rss()
2955 netdev_rss_key_fill(vi->ctrl->rss.key, vi->rss_key_size); in virtnet_init_default_rss()
2958 static void virtnet_get_hashflow(const struct virtnet_info *vi, struct ethtool_rxnfc *info) in virtnet_get_hashflow() argument
2963 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_TCPv4) { in virtnet_get_hashflow()
2966 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv4) { in virtnet_get_hashflow()
2971 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_TCPv6) { in virtnet_get_hashflow()
2974 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv6) { in virtnet_get_hashflow()
2979 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_UDPv4) { in virtnet_get_hashflow()
2982 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv4) { in virtnet_get_hashflow()
2987 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_UDPv6) { in virtnet_get_hashflow()
2990 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv6) { in virtnet_get_hashflow()
2995 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv4) in virtnet_get_hashflow()
3000 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv6) in virtnet_get_hashflow()
3010 static bool virtnet_set_hashflow(struct virtnet_info *vi, struct ethtool_rxnfc *info) in virtnet_set_hashflow() argument
3012 u32 new_hashtypes = vi->rss_hash_types_saved; in virtnet_set_hashflow()
3061 if (new_hashtypes != (new_hashtypes & vi->rss_hash_types_supported)) in virtnet_set_hashflow()
3064 if (new_hashtypes != vi->rss_hash_types_saved) { in virtnet_set_hashflow()
3065 vi->rss_hash_types_saved = new_hashtypes; in virtnet_set_hashflow()
3066 vi->ctrl->rss.hash_types = vi->rss_hash_types_saved; in virtnet_set_hashflow()
3067 if (vi->dev->features & NETIF_F_RXHASH) in virtnet_set_hashflow()
3068 return virtnet_commit_rss_command(vi); in virtnet_set_hashflow()
3077 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_drvinfo() local
3078 struct virtio_device *vdev = vi->vdev; in virtnet_get_drvinfo()
3090 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_channels() local
3100 if (queue_pairs > vi->max_queue_pairs || queue_pairs == 0) in virtnet_set_channels()
3107 if (vi->rq[0].xdp_prog) in virtnet_set_channels()
3111 err = _virtnet_set_queues(vi, queue_pairs); in virtnet_set_channels()
3116 virtnet_set_affinity(vi); in virtnet_set_channels()
3127 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_strings() local
3133 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_strings()
3139 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_strings()
3150 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_sset_count() local
3154 return vi->curr_queue_pairs * (VIRTNET_RQ_STATS_LEN + in virtnet_get_sset_count()
3164 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_ethtool_stats() local
3169 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_ethtool_stats()
3170 struct receive_queue *rq = &vi->rq[i]; in virtnet_get_ethtool_stats()
3183 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_ethtool_stats()
3184 struct send_queue *sq = &vi->sq[i]; in virtnet_get_ethtool_stats()
3201 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_channels() local
3203 channels->combined_count = vi->curr_queue_pairs; in virtnet_get_channels()
3204 channels->max_combined = vi->max_queue_pairs; in virtnet_get_channels()
3214 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_link_ksettings() local
3217 &vi->speed, &vi->duplex); in virtnet_set_link_ksettings()
3223 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_link_ksettings() local
3225 cmd->base.speed = vi->speed; in virtnet_get_link_ksettings()
3226 cmd->base.duplex = vi->duplex; in virtnet_get_link_ksettings()
3232 static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi, in virtnet_send_notf_coal_cmds() argument
3237 vi->ctrl->coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs); in virtnet_send_notf_coal_cmds()
3238 vi->ctrl->coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames); in virtnet_send_notf_coal_cmds()
3239 sg_init_one(&sgs_tx, &vi->ctrl->coal_tx, sizeof(vi->ctrl->coal_tx)); in virtnet_send_notf_coal_cmds()
3241 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, in virtnet_send_notf_coal_cmds()
3247 vi->intr_coal_tx.max_usecs = ec->tx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3248 vi->intr_coal_tx.max_packets = ec->tx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3250 vi->ctrl->coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); in virtnet_send_notf_coal_cmds()
3251 vi->ctrl->coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); in virtnet_send_notf_coal_cmds()
3252 sg_init_one(&sgs_rx, &vi->ctrl->coal_rx, sizeof(vi->ctrl->coal_rx)); in virtnet_send_notf_coal_cmds()
3254 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, in virtnet_send_notf_coal_cmds()
3260 vi->intr_coal_rx.max_usecs = ec->rx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3261 vi->intr_coal_rx.max_packets = ec->rx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3266 static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi, in virtnet_send_ctrl_coal_vq_cmd() argument
3271 vi->ctrl->coal_vq.vqn = cpu_to_le16(vqn); in virtnet_send_ctrl_coal_vq_cmd()
3272 vi->ctrl->coal_vq.coal.max_usecs = cpu_to_le32(max_usecs); in virtnet_send_ctrl_coal_vq_cmd()
3273 vi->ctrl->coal_vq.coal.max_packets = cpu_to_le32(max_packets); in virtnet_send_ctrl_coal_vq_cmd()
3274 sg_init_one(&sgs, &vi->ctrl->coal_vq, sizeof(vi->ctrl->coal_vq)); in virtnet_send_ctrl_coal_vq_cmd()
3276 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, in virtnet_send_ctrl_coal_vq_cmd()
3284 static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, in virtnet_send_notf_coal_vq_cmds() argument
3291 err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue), in virtnet_send_notf_coal_vq_cmds()
3297 vi->rq[queue].intr_coal.max_usecs = ec->rx_coalesce_usecs; in virtnet_send_notf_coal_vq_cmds()
3298 vi->rq[queue].intr_coal.max_packets = ec->rx_max_coalesced_frames; in virtnet_send_notf_coal_vq_cmds()
3302 err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue), in virtnet_send_notf_coal_vq_cmds()
3308 vi->sq[queue].intr_coal.max_usecs = ec->tx_coalesce_usecs; in virtnet_send_notf_coal_vq_cmds()
3309 vi->sq[queue].intr_coal.max_packets = ec->tx_max_coalesced_frames; in virtnet_send_notf_coal_vq_cmds()
3347 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_coalesce() local
3353 for (queue_number = 0; queue_number < vi->max_queue_pairs; queue_number++) { in virtnet_set_coalesce()
3355 vi->sq[queue_number].napi.weight, in virtnet_set_coalesce()
3361 /* All queues that belong to [queue_number, vi->max_queue_pairs] will be in virtnet_set_coalesce()
3368 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) in virtnet_set_coalesce()
3369 ret = virtnet_send_notf_coal_cmds(vi, ec); in virtnet_set_coalesce()
3377 for (; queue_number < vi->max_queue_pairs; queue_number++) in virtnet_set_coalesce()
3378 vi->sq[queue_number].napi.weight = napi_weight; in virtnet_set_coalesce()
3389 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_coalesce() local
3391 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { in virtnet_get_coalesce()
3392 ec->rx_coalesce_usecs = vi->intr_coal_rx.max_usecs; in virtnet_get_coalesce()
3393 ec->tx_coalesce_usecs = vi->intr_coal_tx.max_usecs; in virtnet_get_coalesce()
3394 ec->tx_max_coalesced_frames = vi->intr_coal_tx.max_packets; in virtnet_get_coalesce()
3395 ec->rx_max_coalesced_frames = vi->intr_coal_rx.max_packets; in virtnet_get_coalesce()
3399 if (vi->sq[0].napi.weight) in virtnet_get_coalesce()
3410 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_per_queue_coalesce() local
3414 if (queue >= vi->max_queue_pairs) in virtnet_set_per_queue_coalesce()
3420 vi->sq[queue].napi.weight, in virtnet_set_per_queue_coalesce()
3425 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) in virtnet_set_per_queue_coalesce()
3426 ret = virtnet_send_notf_coal_vq_cmds(vi, ec, queue); in virtnet_set_per_queue_coalesce()
3434 vi->sq[queue].napi.weight = napi_weight; in virtnet_set_per_queue_coalesce()
3443 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_per_queue_coalesce() local
3445 if (queue >= vi->max_queue_pairs) in virtnet_get_per_queue_coalesce()
3448 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) { in virtnet_get_per_queue_coalesce()
3449 ec->rx_coalesce_usecs = vi->rq[queue].intr_coal.max_usecs; in virtnet_get_per_queue_coalesce()
3450 ec->tx_coalesce_usecs = vi->sq[queue].intr_coal.max_usecs; in virtnet_get_per_queue_coalesce()
3451 ec->tx_max_coalesced_frames = vi->sq[queue].intr_coal.max_packets; in virtnet_get_per_queue_coalesce()
3452 ec->rx_max_coalesced_frames = vi->rq[queue].intr_coal.max_packets; in virtnet_get_per_queue_coalesce()
3456 if (vi->sq[0].napi.weight) in virtnet_get_per_queue_coalesce()
3465 struct virtnet_info *vi = netdev_priv(dev); in virtnet_init_settings() local
3467 vi->speed = SPEED_UNKNOWN; in virtnet_init_settings()
3468 vi->duplex = DUPLEX_UNKNOWN; in virtnet_init_settings()
3471 static void virtnet_update_settings(struct virtnet_info *vi) in virtnet_update_settings() argument
3476 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_SPEED_DUPLEX)) in virtnet_update_settings()
3479 virtio_cread_le(vi->vdev, struct virtio_net_config, speed, &speed); in virtnet_update_settings()
3482 vi->speed = speed; in virtnet_update_settings()
3484 virtio_cread_le(vi->vdev, struct virtio_net_config, duplex, &duplex); in virtnet_update_settings()
3487 vi->duplex = duplex; in virtnet_update_settings()
3502 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_rxfh() local
3506 for (i = 0; i < vi->rss_indir_table_size; ++i) in virtnet_get_rxfh()
3507 indir[i] = vi->ctrl->rss.indirection_table[i]; in virtnet_get_rxfh()
3511 memcpy(key, vi->ctrl->rss.key, vi->rss_key_size); in virtnet_get_rxfh()
3521 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_rxfh() local
3528 for (i = 0; i < vi->rss_indir_table_size; ++i) in virtnet_set_rxfh()
3529 vi->ctrl->rss.indirection_table[i] = indir[i]; in virtnet_set_rxfh()
3532 memcpy(vi->ctrl->rss.key, key, vi->rss_key_size); in virtnet_set_rxfh()
3534 virtnet_commit_rss_command(vi); in virtnet_set_rxfh()
3541 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_rxnfc() local
3546 info->data = vi->curr_queue_pairs; in virtnet_get_rxnfc()
3549 virtnet_get_hashflow(vi, info); in virtnet_get_rxnfc()
3560 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_rxnfc() local
3565 if (!virtnet_set_hashflow(vi, info)) in virtnet_set_rxnfc()
3605 struct virtnet_info *vi = vdev->priv; in virtnet_freeze_down() local
3608 flush_work(&vi->config_work); in virtnet_freeze_down()
3610 netif_tx_lock_bh(vi->dev); in virtnet_freeze_down()
3611 netif_device_detach(vi->dev); in virtnet_freeze_down()
3612 netif_tx_unlock_bh(vi->dev); in virtnet_freeze_down()
3613 if (netif_running(vi->dev)) in virtnet_freeze_down()
3614 virtnet_close(vi->dev); in virtnet_freeze_down()
3617 static int init_vqs(struct virtnet_info *vi);
3621 struct virtnet_info *vi = vdev->priv; in virtnet_restore_up() local
3624 err = init_vqs(vi); in virtnet_restore_up()
3630 enable_delayed_refill(vi); in virtnet_restore_up()
3632 if (netif_running(vi->dev)) { in virtnet_restore_up()
3633 err = virtnet_open(vi->dev); in virtnet_restore_up()
3638 netif_tx_lock_bh(vi->dev); in virtnet_restore_up()
3639 netif_device_attach(vi->dev); in virtnet_restore_up()
3640 netif_tx_unlock_bh(vi->dev); in virtnet_restore_up()
3644 static int virtnet_set_guest_offloads(struct virtnet_info *vi, u64 offloads) in virtnet_set_guest_offloads() argument
3647 vi->ctrl->offloads = cpu_to_virtio64(vi->vdev, offloads); in virtnet_set_guest_offloads()
3649 sg_init_one(&sg, &vi->ctrl->offloads, sizeof(vi->ctrl->offloads)); in virtnet_set_guest_offloads()
3651 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_GUEST_OFFLOADS, in virtnet_set_guest_offloads()
3653 dev_warn(&vi->dev->dev, "Fail to set guest offload.\n"); in virtnet_set_guest_offloads()
3660 static int virtnet_clear_guest_offloads(struct virtnet_info *vi) in virtnet_clear_guest_offloads() argument
3664 if (!vi->guest_offloads) in virtnet_clear_guest_offloads()
3667 return virtnet_set_guest_offloads(vi, offloads); in virtnet_clear_guest_offloads()
3670 static int virtnet_restore_guest_offloads(struct virtnet_info *vi) in virtnet_restore_guest_offloads() argument
3672 u64 offloads = vi->guest_offloads; in virtnet_restore_guest_offloads()
3674 if (!vi->guest_offloads) in virtnet_restore_guest_offloads()
3677 return virtnet_set_guest_offloads(vi, offloads); in virtnet_restore_guest_offloads()
3686 struct virtnet_info *vi = netdev_priv(dev); in virtnet_xdp_set() local
3691 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) in virtnet_xdp_set()
3692 && (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO4) || in virtnet_xdp_set()
3693 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO6) || in virtnet_xdp_set()
3694 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_ECN) || in virtnet_xdp_set()
3695 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO) || in virtnet_xdp_set()
3696 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_CSUM) || in virtnet_xdp_set()
3697 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO4) || in virtnet_xdp_set()
3698 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO6))) { in virtnet_xdp_set()
3703 if (vi->mergeable_rx_bufs && !vi->any_header_sg) { in virtnet_xdp_set()
3714 curr_qp = vi->curr_queue_pairs - vi->xdp_queue_pairs; in virtnet_xdp_set()
3719 if (curr_qp + xdp_qp > vi->max_queue_pairs) { in virtnet_xdp_set()
3721 curr_qp + xdp_qp, vi->max_queue_pairs); in virtnet_xdp_set()
3725 old_prog = rtnl_dereference(vi->rq[0].xdp_prog); in virtnet_xdp_set()
3730 bpf_prog_add(prog, vi->max_queue_pairs - 1); in virtnet_xdp_set()
3734 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3735 napi_disable(&vi->rq[i].napi); in virtnet_xdp_set()
3736 virtnet_napi_tx_disable(&vi->sq[i].napi); in virtnet_xdp_set()
3741 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3742 rcu_assign_pointer(vi->rq[i].xdp_prog, prog); in virtnet_xdp_set()
3744 virtnet_restore_guest_offloads(vi); in virtnet_xdp_set()
3749 err = _virtnet_set_queues(vi, curr_qp + xdp_qp); in virtnet_xdp_set()
3753 vi->xdp_queue_pairs = xdp_qp; in virtnet_xdp_set()
3756 vi->xdp_enabled = true; in virtnet_xdp_set()
3757 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3758 rcu_assign_pointer(vi->rq[i].xdp_prog, prog); in virtnet_xdp_set()
3760 virtnet_clear_guest_offloads(vi); in virtnet_xdp_set()
3766 vi->xdp_enabled = false; in virtnet_xdp_set()
3769 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3773 virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); in virtnet_xdp_set()
3774 virtnet_napi_tx_enable(vi, vi->sq[i].vq, in virtnet_xdp_set()
3775 &vi->sq[i].napi); in virtnet_xdp_set()
3783 virtnet_clear_guest_offloads(vi); in virtnet_xdp_set()
3784 for (i = 0; i < vi->max_queue_pairs; i++) in virtnet_xdp_set()
3785 rcu_assign_pointer(vi->rq[i].xdp_prog, old_prog); in virtnet_xdp_set()
3789 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3790 virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); in virtnet_xdp_set()
3791 virtnet_napi_tx_enable(vi, vi->sq[i].vq, in virtnet_xdp_set()
3792 &vi->sq[i].napi); in virtnet_xdp_set()
3796 bpf_prog_sub(prog, vi->max_queue_pairs - 1); in virtnet_xdp_set()
3813 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_phys_port_name() local
3816 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_STANDBY)) in virtnet_get_phys_port_name()
3829 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_features() local
3834 if (vi->xdp_enabled) in virtnet_set_features()
3838 offloads = vi->guest_offloads_capable; in virtnet_set_features()
3840 offloads = vi->guest_offloads_capable & in virtnet_set_features()
3843 err = virtnet_set_guest_offloads(vi, offloads); in virtnet_set_features()
3846 vi->guest_offloads = offloads; in virtnet_set_features()
3851 vi->ctrl->rss.hash_types = vi->rss_hash_types_saved; in virtnet_set_features()
3853 vi->ctrl->rss.hash_types = VIRTIO_NET_HASH_REPORT_NONE; in virtnet_set_features()
3855 if (!virtnet_commit_rss_command(vi)) in virtnet_set_features()
3897 struct virtnet_info *vi = in virtnet_config_changed_work() local
3901 if (virtio_cread_feature(vi->vdev, VIRTIO_NET_F_STATUS, in virtnet_config_changed_work()
3906 netdev_notify_peers(vi->dev); in virtnet_config_changed_work()
3907 virtnet_ack_link_announce(vi); in virtnet_config_changed_work()
3913 if (vi->status == v) in virtnet_config_changed_work()
3916 vi->status = v; in virtnet_config_changed_work()
3918 if (vi->status & VIRTIO_NET_S_LINK_UP) { in virtnet_config_changed_work()
3919 virtnet_update_settings(vi); in virtnet_config_changed_work()
3920 netif_carrier_on(vi->dev); in virtnet_config_changed_work()
3921 netif_tx_wake_all_queues(vi->dev); in virtnet_config_changed_work()
3923 netif_carrier_off(vi->dev); in virtnet_config_changed_work()
3924 netif_tx_stop_all_queues(vi->dev); in virtnet_config_changed_work()
3930 struct virtnet_info *vi = vdev->priv; in virtnet_config_changed() local
3932 schedule_work(&vi->config_work); in virtnet_config_changed()
3935 static void virtnet_free_queues(struct virtnet_info *vi) in virtnet_free_queues() argument
3939 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_free_queues()
3940 __netif_napi_del(&vi->rq[i].napi); in virtnet_free_queues()
3941 __netif_napi_del(&vi->sq[i].napi); in virtnet_free_queues()
3945 * we need to respect an RCU grace period before freeing vi->rq in virtnet_free_queues()
3949 kfree(vi->rq); in virtnet_free_queues()
3950 kfree(vi->sq); in virtnet_free_queues()
3951 kfree(vi->ctrl); in virtnet_free_queues()
3954 static void _free_receive_bufs(struct virtnet_info *vi) in _free_receive_bufs() argument
3959 for (i = 0; i < vi->max_queue_pairs; i++) { in _free_receive_bufs()
3960 while (vi->rq[i].pages) in _free_receive_bufs()
3961 __free_pages(get_a_page(&vi->rq[i], GFP_KERNEL), 0); in _free_receive_bufs()
3963 old_prog = rtnl_dereference(vi->rq[i].xdp_prog); in _free_receive_bufs()
3964 RCU_INIT_POINTER(vi->rq[i].xdp_prog, NULL); in _free_receive_bufs()
3970 static void free_receive_bufs(struct virtnet_info *vi) in free_receive_bufs() argument
3973 _free_receive_bufs(vi); in free_receive_bufs()
3977 static void free_receive_page_frags(struct virtnet_info *vi) in free_receive_page_frags() argument
3980 for (i = 0; i < vi->max_queue_pairs; i++) in free_receive_page_frags()
3981 if (vi->rq[i].alloc_frag.page) { in free_receive_page_frags()
3982 if (vi->rq[i].do_dma && vi->rq[i].last_dma) in free_receive_page_frags()
3983 virtnet_rq_unmap(&vi->rq[i], vi->rq[i].last_dma, 0); in free_receive_page_frags()
3984 put_page(vi->rq[i].alloc_frag.page); in free_receive_page_frags()
3998 struct virtnet_info *vi = vq->vdev->priv; in virtnet_rq_free_unused_buf() local
4001 if (vi->mergeable_rx_bufs) in virtnet_rq_free_unused_buf()
4003 else if (vi->big_packets) in virtnet_rq_free_unused_buf()
4004 give_pages(&vi->rq[i], buf); in virtnet_rq_free_unused_buf()
4009 static void free_unused_bufs(struct virtnet_info *vi) in free_unused_bufs() argument
4014 for (i = 0; i < vi->max_queue_pairs; i++) { in free_unused_bufs()
4015 struct virtqueue *vq = vi->sq[i].vq; in free_unused_bufs()
4021 for (i = 0; i < vi->max_queue_pairs; i++) { in free_unused_bufs()
4022 struct receive_queue *rq = &vi->rq[i]; in free_unused_bufs()
4030 static void virtnet_del_vqs(struct virtnet_info *vi) in virtnet_del_vqs() argument
4032 struct virtio_device *vdev = vi->vdev; in virtnet_del_vqs()
4034 virtnet_clean_affinity(vi); in virtnet_del_vqs()
4038 virtnet_free_queues(vi); in virtnet_del_vqs()
4045 static unsigned int mergeable_min_buf_len(struct virtnet_info *vi, struct virtqueue *vq) in mergeable_min_buf_len() argument
4047 const unsigned int hdr_len = vi->hdr_len; in mergeable_min_buf_len()
4049 unsigned int packet_len = vi->big_packets ? IP_MAX_MTU : vi->dev->max_mtu; in mergeable_min_buf_len()
4057 static int virtnet_find_vqs(struct virtnet_info *vi) in virtnet_find_vqs() argument
4070 total_vqs = vi->max_queue_pairs * 2 + in virtnet_find_vqs()
4071 virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ); in virtnet_find_vqs()
4083 if (!vi->big_packets || vi->mergeable_rx_bufs) { in virtnet_find_vqs()
4092 if (vi->has_cvq) { in virtnet_find_vqs()
4098 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_find_vqs()
4101 sprintf(vi->rq[i].name, "input.%d", i); in virtnet_find_vqs()
4102 sprintf(vi->sq[i].name, "output.%d", i); in virtnet_find_vqs()
4103 names[rxq2vq(i)] = vi->rq[i].name; in virtnet_find_vqs()
4104 names[txq2vq(i)] = vi->sq[i].name; in virtnet_find_vqs()
4109 ret = virtio_find_vqs_ctx(vi->vdev, total_vqs, vqs, callbacks, in virtnet_find_vqs()
4114 if (vi->has_cvq) { in virtnet_find_vqs()
4115 vi->cvq = vqs[total_vqs - 1]; in virtnet_find_vqs()
4116 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN)) in virtnet_find_vqs()
4117 vi->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; in virtnet_find_vqs()
4120 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_find_vqs()
4121 vi->rq[i].vq = vqs[rxq2vq(i)]; in virtnet_find_vqs()
4122 vi->rq[i].min_buf_len = mergeable_min_buf_len(vi, vi->rq[i].vq); in virtnet_find_vqs()
4123 vi->sq[i].vq = vqs[txq2vq(i)]; in virtnet_find_vqs()
4141 static int virtnet_alloc_queues(struct virtnet_info *vi) in virtnet_alloc_queues() argument
4145 if (vi->has_cvq) { in virtnet_alloc_queues()
4146 vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL); in virtnet_alloc_queues()
4147 if (!vi->ctrl) in virtnet_alloc_queues()
4150 vi->ctrl = NULL; in virtnet_alloc_queues()
4152 vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL); in virtnet_alloc_queues()
4153 if (!vi->sq) in virtnet_alloc_queues()
4155 vi->rq = kcalloc(vi->max_queue_pairs, sizeof(*vi->rq), GFP_KERNEL); in virtnet_alloc_queues()
4156 if (!vi->rq) in virtnet_alloc_queues()
4159 INIT_DELAYED_WORK(&vi->refill, refill_work); in virtnet_alloc_queues()
4160 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_alloc_queues()
4161 vi->rq[i].pages = NULL; in virtnet_alloc_queues()
4162 netif_napi_add_weight(vi->dev, &vi->rq[i].napi, virtnet_poll, in virtnet_alloc_queues()
4164 netif_napi_add_tx_weight(vi->dev, &vi->sq[i].napi, in virtnet_alloc_queues()
4168 sg_init_table(vi->rq[i].sg, ARRAY_SIZE(vi->rq[i].sg)); in virtnet_alloc_queues()
4169 ewma_pkt_len_init(&vi->rq[i].mrg_avg_pkt_len); in virtnet_alloc_queues()
4170 sg_init_table(vi->sq[i].sg, ARRAY_SIZE(vi->sq[i].sg)); in virtnet_alloc_queues()
4172 u64_stats_init(&vi->rq[i].stats.syncp); in virtnet_alloc_queues()
4173 u64_stats_init(&vi->sq[i].stats.syncp); in virtnet_alloc_queues()
4179 kfree(vi->sq); in virtnet_alloc_queues()
4181 kfree(vi->ctrl); in virtnet_alloc_queues()
4186 static int init_vqs(struct virtnet_info *vi) in init_vqs() argument
4191 ret = virtnet_alloc_queues(vi); in init_vqs()
4195 ret = virtnet_find_vqs(vi); in init_vqs()
4199 virtnet_rq_set_premapped(vi); in init_vqs()
4202 virtnet_set_affinity(vi); in init_vqs()
4208 virtnet_free_queues(vi); in init_vqs()
4217 struct virtnet_info *vi = netdev_priv(queue->dev); in mergeable_rx_buffer_size_show() local
4219 unsigned int headroom = virtnet_get_headroom(vi); in mergeable_rx_buffer_size_show()
4223 BUG_ON(queue_index >= vi->max_queue_pairs); in mergeable_rx_buffer_size_show()
4224 avg = &vi->rq[queue_index].mrg_avg_pkt_len; in mergeable_rx_buffer_size_show()
4226 get_mergeable_buf_len(&vi->rq[queue_index], avg, in mergeable_rx_buffer_size_show()
4317 static bool virtnet_check_guest_gso(const struct virtnet_info *vi) in virtnet_check_guest_gso() argument
4319 return virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO4) || in virtnet_check_guest_gso()
4320 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO6) || in virtnet_check_guest_gso()
4321 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_ECN) || in virtnet_check_guest_gso()
4322 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO) || in virtnet_check_guest_gso()
4323 (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO4) && in virtnet_check_guest_gso()
4324 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO6)); in virtnet_check_guest_gso()
4327 static void virtnet_set_big_packets(struct virtnet_info *vi, const int mtu) in virtnet_set_big_packets() argument
4329 bool guest_gso = virtnet_check_guest_gso(vi); in virtnet_set_big_packets()
4336 vi->big_packets = true; in virtnet_set_big_packets()
4337 vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS : DIV_ROUND_UP(mtu, PAGE_SIZE); in virtnet_set_big_packets()
4345 struct virtnet_info *vi; in virtnet_probe() local
4432 vi = netdev_priv(dev); in virtnet_probe()
4433 vi->dev = dev; in virtnet_probe()
4434 vi->vdev = vdev; in virtnet_probe()
4435 vdev->priv = vi; in virtnet_probe()
4437 INIT_WORK(&vi->config_work, virtnet_config_changed_work); in virtnet_probe()
4438 spin_lock_init(&vi->refill_lock); in virtnet_probe()
4441 vi->mergeable_rx_bufs = true; in virtnet_probe()
4445 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { in virtnet_probe()
4446 vi->intr_coal_rx.max_usecs = 0; in virtnet_probe()
4447 vi->intr_coal_tx.max_usecs = 0; in virtnet_probe()
4448 vi->intr_coal_tx.max_packets = 0; in virtnet_probe()
4449 vi->intr_coal_rx.max_packets = 0; in virtnet_probe()
4453 vi->has_rss_hash_report = true; in virtnet_probe()
4456 vi->has_rss = true; in virtnet_probe()
4458 if (vi->has_rss || vi->has_rss_hash_report) { in virtnet_probe()
4459 vi->rss_indir_table_size = in virtnet_probe()
4462 vi->rss_key_size = in virtnet_probe()
4465 vi->rss_hash_types_supported = in virtnet_probe()
4467 vi->rss_hash_types_supported &= in virtnet_probe()
4475 if (vi->has_rss_hash_report) in virtnet_probe()
4476 vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); in virtnet_probe()
4479 vi->hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf); in virtnet_probe()
4481 vi->hdr_len = sizeof(struct virtio_net_hdr); in virtnet_probe()
4485 vi->any_header_sg = true; in virtnet_probe()
4488 vi->has_cvq = true; in virtnet_probe()
4509 virtnet_set_big_packets(vi, mtu); in virtnet_probe()
4511 if (vi->any_header_sg) in virtnet_probe()
4512 dev->needed_headroom = vi->hdr_len; in virtnet_probe()
4516 vi->curr_queue_pairs = max_queue_pairs; in virtnet_probe()
4518 vi->curr_queue_pairs = num_online_cpus(); in virtnet_probe()
4519 vi->max_queue_pairs = max_queue_pairs; in virtnet_probe()
4522 err = init_vqs(vi); in virtnet_probe()
4527 if (vi->mergeable_rx_bufs) in virtnet_probe()
4530 netif_set_real_num_tx_queues(dev, vi->curr_queue_pairs); in virtnet_probe()
4531 netif_set_real_num_rx_queues(dev, vi->curr_queue_pairs); in virtnet_probe()
4536 vi->failover = net_failover_create(vi->dev); in virtnet_probe()
4537 if (IS_ERR(vi->failover)) { in virtnet_probe()
4538 err = PTR_ERR(vi->failover); in virtnet_probe()
4543 if (vi->has_rss || vi->has_rss_hash_report) in virtnet_probe()
4544 virtnet_init_default_rss(vi); in virtnet_probe()
4558 _virtnet_set_queues(vi, vi->curr_queue_pairs); in virtnet_probe()
4565 virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) { in virtnet_probe()
4569 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, in virtnet_probe()
4580 err = virtnet_cpu_notif_add(vi); in virtnet_probe()
4589 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) { in virtnet_probe()
4590 schedule_work(&vi->config_work); in virtnet_probe()
4592 vi->status = VIRTIO_NET_S_LINK_UP; in virtnet_probe()
4593 virtnet_update_settings(vi); in virtnet_probe()
4598 if (virtio_has_feature(vi->vdev, guest_offloads[i])) in virtnet_probe()
4599 set_bit(guest_offloads[i], &vi->guest_offloads); in virtnet_probe()
4600 vi->guest_offloads_capable = vi->guest_offloads; in virtnet_probe()
4610 net_failover_destroy(vi->failover); in virtnet_probe()
4613 cancel_delayed_work_sync(&vi->refill); in virtnet_probe()
4614 free_receive_page_frags(vi); in virtnet_probe()
4615 virtnet_del_vqs(vi); in virtnet_probe()
4621 static void remove_vq_common(struct virtnet_info *vi) in remove_vq_common() argument
4623 virtio_reset_device(vi->vdev); in remove_vq_common()
4626 free_unused_bufs(vi); in remove_vq_common()
4628 free_receive_bufs(vi); in remove_vq_common()
4630 free_receive_page_frags(vi); in remove_vq_common()
4632 virtnet_del_vqs(vi); in remove_vq_common()
4637 struct virtnet_info *vi = vdev->priv; in virtnet_remove() local
4639 virtnet_cpu_notif_remove(vi); in virtnet_remove()
4642 flush_work(&vi->config_work); in virtnet_remove()
4644 unregister_netdev(vi->dev); in virtnet_remove()
4646 net_failover_destroy(vi->failover); in virtnet_remove()
4648 remove_vq_common(vi); in virtnet_remove()
4650 free_netdev(vi->dev); in virtnet_remove()
4655 struct virtnet_info *vi = vdev->priv; in virtnet_freeze() local
4657 virtnet_cpu_notif_remove(vi); in virtnet_freeze()
4659 remove_vq_common(vi); in virtnet_freeze()
4666 struct virtnet_info *vi = vdev->priv; in virtnet_restore() local
4672 virtnet_set_queues(vi, vi->curr_queue_pairs); in virtnet_restore()
4674 err = virtnet_cpu_notif_add(vi); in virtnet_restore()
4677 remove_vq_common(vi); in virtnet_restore()