• Home
  • Raw
  • Download

Lines Matching full:vi

391 	/* Find end of list, sew whole thing into vi->rq.pages. */  in give_pages()
410 static void virtnet_rq_free_buf(struct virtnet_info *vi, in virtnet_rq_free_buf() argument
413 if (vi->mergeable_rx_bufs) in virtnet_rq_free_buf()
415 else if (vi->big_packets) in virtnet_rq_free_buf()
421 static void enable_delayed_refill(struct virtnet_info *vi) in enable_delayed_refill() argument
423 spin_lock_bh(&vi->refill_lock); in enable_delayed_refill()
424 vi->refill_enabled = true; in enable_delayed_refill()
425 spin_unlock_bh(&vi->refill_lock); in enable_delayed_refill()
428 static void disable_delayed_refill(struct virtnet_info *vi) in disable_delayed_refill() argument
430 spin_lock_bh(&vi->refill_lock); in disable_delayed_refill()
431 vi->refill_enabled = false; in disable_delayed_refill()
432 spin_unlock_bh(&vi->refill_lock); in disable_delayed_refill()
460 struct virtnet_info *vi = vq->vdev->priv; in skb_xmit_done() local
461 struct napi_struct *napi = &vi->sq[vq2txq(vq)].napi; in skb_xmit_done()
470 netif_wake_subqueue(vi->dev, vq2txq(vq)); in skb_xmit_done()
507 static struct sk_buff *page_to_skb(struct virtnet_info *vi, in page_to_skb() argument
523 hdr_len = vi->hdr_len; in page_to_skb()
524 if (vi->mergeable_rx_bufs) in page_to_skb()
566 if (vi->mergeable_rx_bufs) { in page_to_skb()
730 static void virtnet_rq_set_premapped(struct virtnet_info *vi) in virtnet_rq_set_premapped() argument
735 if (!vi->mergeable_rx_bufs && vi->big_packets) in virtnet_rq_set_premapped()
738 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_rq_set_premapped()
739 if (virtqueue_set_dma_premapped(vi->rq[i].vq)) in virtnet_rq_set_premapped()
742 vi->rq[i].do_dma = true; in virtnet_rq_set_premapped()
748 struct virtnet_info *vi = vq->vdev->priv; in virtnet_rq_unmap_free_buf() local
752 rq = &vi->rq[i]; in virtnet_rq_unmap_free_buf()
757 virtnet_rq_free_buf(vi, rq, buf); in virtnet_rq_unmap_free_buf()
796 static bool is_xdp_raw_buffer_queue(struct virtnet_info *vi, int q) in is_xdp_raw_buffer_queue() argument
798 if (q < (vi->curr_queue_pairs - vi->xdp_queue_pairs)) in is_xdp_raw_buffer_queue()
800 else if (q < vi->curr_queue_pairs) in is_xdp_raw_buffer_queue()
806 static void check_sq_full_and_disable(struct virtnet_info *vi, in check_sq_full_and_disable() argument
813 qnum = sq - vi->sq; in check_sq_full_and_disable()
841 static int __virtnet_xdp_xmit_one(struct virtnet_info *vi, in __virtnet_xdp_xmit_one() argument
850 if (unlikely(xdpf->headroom < vi->hdr_len)) in __virtnet_xdp_xmit_one()
865 xdpf->headroom -= vi->hdr_len; in __virtnet_xdp_xmit_one()
866 xdpf->data -= vi->hdr_len; in __virtnet_xdp_xmit_one()
869 memset(hdr, 0, vi->hdr_len); in __virtnet_xdp_xmit_one()
870 xdpf->len += vi->hdr_len; in __virtnet_xdp_xmit_one()
889 /* when vi->curr_queue_pairs > nr_cpu_ids, the txq/sq is only used for xdp tx on
897 #define virtnet_xdp_get_sq(vi) ({ \ argument
900 typeof(vi) v = (vi); \
916 #define virtnet_xdp_put_sq(vi, q) { \ argument
918 typeof(vi) v = (vi); \
930 struct virtnet_info *vi = netdev_priv(dev); in virtnet_xdp_xmit() local
931 struct receive_queue *rq = vi->rq; in virtnet_xdp_xmit()
950 sq = virtnet_xdp_get_sq(vi); in virtnet_xdp_xmit()
976 if (__virtnet_xdp_xmit_one(vi, sq, xdpf)) in virtnet_xdp_xmit()
982 if (!is_xdp_raw_buffer_queue(vi, sq - vi->sq)) in virtnet_xdp_xmit()
983 check_sq_full_and_disable(vi, dev, sq); in virtnet_xdp_xmit()
998 virtnet_xdp_put_sq(vi, sq); in virtnet_xdp_xmit()
1071 static unsigned int virtnet_get_headroom(struct virtnet_info *vi) in virtnet_get_headroom() argument
1073 return vi->xdp_enabled ? VIRTIO_XDP_HEADROOM : 0; in virtnet_get_headroom()
1144 static struct sk_buff *receive_small_build_skb(struct virtnet_info *vi, in receive_small_build_skb() argument
1155 headroom = vi->hdr_len + header_offset; in receive_small_build_skb()
1164 memcpy(skb_vnet_common_hdr(skb), buf, vi->hdr_len); in receive_small_build_skb()
1170 struct virtnet_info *vi, in receive_small_xdp() argument
1180 unsigned int headroom = vi->hdr_len + header_offset; in receive_small_xdp()
1196 if (unlikely(xdp_headroom < virtnet_get_headroom(vi))) { in receive_small_xdp()
1198 unsigned int tlen = len + vi->hdr_len; in receive_small_xdp()
1201 xdp_headroom = virtnet_get_headroom(vi); in receive_small_xdp()
1203 headroom = vi->hdr_len + header_offset; in receive_small_xdp()
1218 xdp_prepare_buff(&xdp, buf + VIRTNET_RX_PAD + vi->hdr_len, in receive_small_xdp()
1257 struct virtnet_info *vi, in receive_small() argument
1268 len -= vi->hdr_len; in receive_small()
1278 if (unlikely(vi->xdp_enabled)) { in receive_small()
1284 skb = receive_small_xdp(dev, vi, rq, xdp_prog, buf, in receive_small()
1293 skb = receive_small_build_skb(vi, xdp_headroom, buf, len); in receive_small()
1304 struct virtnet_info *vi, in receive_big() argument
1312 page_to_skb(vi, rq, page, 0, len, PAGE_SIZE, 0); in receive_big()
1314 u64_stats_add(&stats->bytes, len - vi->hdr_len); in receive_big()
1356 struct virtnet_info *vi, in build_skb_from_xdp_buff() argument
1399 struct virtnet_info *vi, in virtnet_build_xdp_buff_mrg() argument
1421 VIRTIO_XDP_HEADROOM + vi->hdr_len, len - vi->hdr_len, true); in virtnet_build_xdp_buff_mrg()
1447 virtio16_to_cpu(vi->vdev, hdr->num_buffers)); in virtnet_build_xdp_buff_mrg()
1487 static void *mergeable_xdp_get_buf(struct virtnet_info *vi, in mergeable_xdp_get_buf() argument
1517 if (likely(headroom >= virtnet_get_headroom(vi) && in mergeable_xdp_get_buf()
1562 struct virtnet_info *vi, in receive_mergeable_xdp() argument
1572 int num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers); in receive_mergeable_xdp()
1583 data = mergeable_xdp_get_buf(vi, rq, xdp_prog, ctx, &frame_sz, &num_buf, &page, in receive_mergeable_xdp()
1588 err = virtnet_build_xdp_buff_mrg(dev, vi, rq, &xdp, data, len, frame_sz, in receive_mergeable_xdp()
1597 head_skb = build_skb_from_xdp_buff(dev, vi, &xdp, xdp_frags_truesz); in receive_mergeable_xdp()
1622 struct virtnet_info *vi, in receive_mergeable() argument
1631 int num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers); in receive_mergeable()
1641 u64_stats_add(&stats->bytes, len - vi->hdr_len); in receive_mergeable()
1650 if (unlikely(vi->xdp_enabled)) { in receive_mergeable()
1656 head_skb = receive_mergeable_xdp(dev, vi, rq, xdp_prog, buf, ctx, in receive_mergeable()
1664 head_skb = page_to_skb(vi, rq, page, offset, len, truesize, headroom); in receive_mergeable()
1676 virtio16_to_cpu(vi->vdev, in receive_mergeable()
1768 static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, in receive_buf() argument
1773 struct net_device *dev = vi->dev; in receive_buf()
1777 if (unlikely(len < vi->hdr_len + ETH_HLEN)) { in receive_buf()
1780 virtnet_rq_free_buf(vi, rq, buf); in receive_buf()
1784 if (vi->mergeable_rx_bufs) in receive_buf()
1785 skb = receive_mergeable(dev, vi, rq, buf, ctx, len, xdp_xmit, in receive_buf()
1787 else if (vi->big_packets) in receive_buf()
1788 skb = receive_big(dev, vi, rq, buf, len, stats); in receive_buf()
1790 skb = receive_small(dev, vi, rq, buf, ctx, len, xdp_xmit, stats); in receive_buf()
1796 if (dev->features & NETIF_F_RXHASH && vi->has_rss_hash_report) in receive_buf()
1803 virtio_is_little_endian(vi->vdev))) { in receive_buf()
1828 static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq, in add_recvbuf_small() argument
1832 unsigned int xdp_headroom = virtnet_get_headroom(vi); in add_recvbuf_small()
1834 int len = vi->hdr_len + VIRTNET_RX_PAD + GOOD_PACKET_LEN + xdp_headroom; in add_recvbuf_small()
1845 vi->hdr_len + GOOD_PACKET_LEN); in add_recvbuf_small()
1857 static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq, in add_recvbuf_big() argument
1864 sg_init_table(rq->sg, vi->big_packets_num_skbfrags + 2); in add_recvbuf_big()
1866 /* page in rq->sg[vi->big_packets_num_skbfrags + 1] is list tail */ in add_recvbuf_big()
1867 for (i = vi->big_packets_num_skbfrags + 1; i > 1; --i) { in add_recvbuf_big()
1890 sg_set_buf(&rq->sg[0], p, vi->hdr_len); in add_recvbuf_big()
1898 err = virtqueue_add_inbuf(rq->vq, rq->sg, vi->big_packets_num_skbfrags + 2, in add_recvbuf_big()
1910 struct virtnet_info *vi = rq->vq->vdev->priv; in get_mergeable_buf_len() local
1911 const size_t hdr_len = vi->hdr_len; in get_mergeable_buf_len()
1923 static int add_recvbuf_mergeable(struct virtnet_info *vi, in add_recvbuf_mergeable() argument
1927 unsigned int headroom = virtnet_get_headroom(vi); in add_recvbuf_mergeable()
1979 static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq, in try_fill_recv() argument
1986 if (vi->mergeable_rx_bufs) in try_fill_recv()
1987 err = add_recvbuf_mergeable(vi, rq, gfp); in try_fill_recv()
1988 else if (vi->big_packets) in try_fill_recv()
1989 err = add_recvbuf_big(vi, rq, gfp); in try_fill_recv()
1991 err = add_recvbuf_small(vi, rq, gfp); in try_fill_recv()
2010 struct virtnet_info *vi = rvq->vdev->priv; in skb_recv_done() local
2011 struct receive_queue *rq = &vi->rq[vq2rxq(rvq)]; in skb_recv_done()
2029 static void virtnet_napi_tx_enable(struct virtnet_info *vi, in virtnet_napi_tx_enable() argument
2039 if (!vi->affinity_hint_set) { in virtnet_napi_tx_enable()
2055 struct virtnet_info *vi = in refill_work() local
2060 for (i = 0; i < vi->curr_queue_pairs; i++) { in refill_work()
2061 struct receive_queue *rq = &vi->rq[i]; in refill_work()
2064 still_empty = !try_fill_recv(vi, rq, GFP_KERNEL); in refill_work()
2071 schedule_delayed_work(&vi->refill, HZ/2); in refill_work()
2078 struct virtnet_info *vi = rq->vq->vdev->priv; in virtnet_receive() local
2085 if (!vi->big_packets || vi->mergeable_rx_bufs) { in virtnet_receive()
2090 receive_buf(vi, rq, buf, len, ctx, xdp_xmit, &stats); in virtnet_receive()
2096 receive_buf(vi, rq, buf, len, NULL, xdp_xmit, &stats); in virtnet_receive()
2102 if (!try_fill_recv(vi, rq, GFP_ATOMIC)) { in virtnet_receive()
2103 spin_lock(&vi->refill_lock); in virtnet_receive()
2104 if (vi->refill_enabled) in virtnet_receive()
2105 schedule_delayed_work(&vi->refill, 0); in virtnet_receive()
2106 spin_unlock(&vi->refill_lock); in virtnet_receive()
2127 struct virtnet_info *vi = rq->vq->vdev->priv; in virtnet_poll_cleantx() local
2129 struct send_queue *sq = &vi->sq[index]; in virtnet_poll_cleantx()
2130 struct netdev_queue *txq = netdev_get_tx_queue(vi->dev, index); in virtnet_poll_cleantx()
2132 if (!sq->napi.weight || is_xdp_raw_buffer_queue(vi, index)) in virtnet_poll_cleantx()
2157 struct virtnet_info *vi = rq->vq->vdev->priv; in virtnet_poll() local
2174 sq = virtnet_xdp_get_sq(vi); in virtnet_poll()
2180 virtnet_xdp_put_sq(vi, sq); in virtnet_poll()
2186 static void virtnet_disable_queue_pair(struct virtnet_info *vi, int qp_index) in virtnet_disable_queue_pair() argument
2188 virtnet_napi_tx_disable(&vi->sq[qp_index].napi); in virtnet_disable_queue_pair()
2189 napi_disable(&vi->rq[qp_index].napi); in virtnet_disable_queue_pair()
2190 xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); in virtnet_disable_queue_pair()
2193 static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) in virtnet_enable_queue_pair() argument
2195 struct net_device *dev = vi->dev; in virtnet_enable_queue_pair()
2198 err = xdp_rxq_info_reg(&vi->rq[qp_index].xdp_rxq, dev, qp_index, in virtnet_enable_queue_pair()
2199 vi->rq[qp_index].napi.napi_id); in virtnet_enable_queue_pair()
2203 err = xdp_rxq_info_reg_mem_model(&vi->rq[qp_index].xdp_rxq, in virtnet_enable_queue_pair()
2208 virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi); in virtnet_enable_queue_pair()
2209 virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi); in virtnet_enable_queue_pair()
2214 xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); in virtnet_enable_queue_pair()
2220 struct virtnet_info *vi = netdev_priv(dev); in virtnet_open() local
2223 enable_delayed_refill(vi); in virtnet_open()
2225 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_open()
2226 if (i < vi->curr_queue_pairs) in virtnet_open()
2228 if (!try_fill_recv(vi, &vi->rq[i], GFP_KERNEL)) in virtnet_open()
2229 schedule_delayed_work(&vi->refill, 0); in virtnet_open()
2231 err = virtnet_enable_queue_pair(vi, i); in virtnet_open()
2239 disable_delayed_refill(vi); in virtnet_open()
2240 cancel_delayed_work_sync(&vi->refill); in virtnet_open()
2243 virtnet_disable_queue_pair(vi, i); in virtnet_open()
2250 struct virtnet_info *vi = sq->vq->vdev->priv; in virtnet_poll_tx() local
2256 if (unlikely(is_xdp_raw_buffer_queue(vi, index))) { in virtnet_poll_tx()
2262 txq = netdev_get_tx_queue(vi->dev, index); in virtnet_poll_tx()
2297 struct virtnet_info *vi = sq->vq->vdev->priv; in xmit_skb() local
2299 unsigned hdr_len = vi->hdr_len; in xmit_skb()
2302 pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); in xmit_skb()
2304 can_push = vi->any_header_sg && in xmit_skb()
2315 virtio_is_little_endian(vi->vdev), false, in xmit_skb()
2319 if (vi->mergeable_rx_bufs) in xmit_skb()
2342 struct virtnet_info *vi = netdev_priv(dev); in start_xmit() local
2344 struct send_queue *sq = &vi->sq[qnum]; in start_xmit()
2384 check_sq_full_and_disable(vi, dev, sq); in start_xmit()
2397 static int virtnet_rx_resize(struct virtnet_info *vi, in virtnet_rx_resize() argument
2400 bool running = netif_running(vi->dev); in virtnet_rx_resize()
2403 qindex = rq - vi->rq; in virtnet_rx_resize()
2410 netdev_err(vi->dev, "resize rx fail: rx queue index: %d err: %d\n", qindex, err); in virtnet_rx_resize()
2412 if (!try_fill_recv(vi, rq, GFP_KERNEL)) in virtnet_rx_resize()
2413 schedule_delayed_work(&vi->refill, 0); in virtnet_rx_resize()
2420 static int virtnet_tx_resize(struct virtnet_info *vi, in virtnet_tx_resize() argument
2423 bool running = netif_running(vi->dev); in virtnet_tx_resize()
2427 qindex = sq - vi->sq; in virtnet_tx_resize()
2432 txq = netdev_get_tx_queue(vi->dev, qindex); in virtnet_tx_resize()
2443 netif_stop_subqueue(vi->dev, qindex); in virtnet_tx_resize()
2449 netdev_err(vi->dev, "resize tx fail: tx queue index: %d err: %d\n", qindex, err); in virtnet_tx_resize()
2457 virtnet_napi_tx_enable(vi, sq->vq, &sq->napi); in virtnet_tx_resize()
2466 static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd, in virtnet_send_command() argument
2474 BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)); in virtnet_send_command()
2476 vi->ctrl->status = ~0; in virtnet_send_command()
2477 vi->ctrl->hdr.class = class; in virtnet_send_command()
2478 vi->ctrl->hdr.cmd = cmd; in virtnet_send_command()
2480 sg_init_one(&hdr, &vi->ctrl->hdr, sizeof(vi->ctrl->hdr)); in virtnet_send_command()
2487 sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status)); in virtnet_send_command()
2491 ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC); in virtnet_send_command()
2493 dev_warn(&vi->vdev->dev, in virtnet_send_command()
2498 if (unlikely(!virtqueue_kick(vi->cvq))) in virtnet_send_command()
2499 return vi->ctrl->status == VIRTIO_NET_OK; in virtnet_send_command()
2504 while (!virtqueue_get_buf(vi->cvq, &tmp) && in virtnet_send_command()
2505 !virtqueue_is_broken(vi->cvq)) in virtnet_send_command()
2508 return vi->ctrl->status == VIRTIO_NET_OK; in virtnet_send_command()
2513 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_mac_address() local
2514 struct virtio_device *vdev = vi->vdev; in virtnet_set_mac_address()
2519 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STANDBY)) in virtnet_set_mac_address()
2532 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, in virtnet_set_mac_address()
2561 struct virtnet_info *vi = netdev_priv(dev); in virtnet_stats() local
2565 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_stats()
2567 struct receive_queue *rq = &vi->rq[i]; in virtnet_stats()
2568 struct send_queue *sq = &vi->sq[i]; in virtnet_stats()
2598 static void virtnet_ack_link_announce(struct virtnet_info *vi) in virtnet_ack_link_announce() argument
2601 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_ANNOUNCE, in virtnet_ack_link_announce()
2603 dev_warn(&vi->dev->dev, "Failed to ack link announce.\n"); in virtnet_ack_link_announce()
2607 static int _virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) in _virtnet_set_queues() argument
2610 struct net_device *dev = vi->dev; in _virtnet_set_queues()
2612 if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ)) in _virtnet_set_queues()
2615 vi->ctrl->mq.virtqueue_pairs = cpu_to_virtio16(vi->vdev, queue_pairs); in _virtnet_set_queues()
2616 sg_init_one(&sg, &vi->ctrl->mq, sizeof(vi->ctrl->mq)); in _virtnet_set_queues()
2618 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, in _virtnet_set_queues()
2624 vi->curr_queue_pairs = queue_pairs; in _virtnet_set_queues()
2627 schedule_delayed_work(&vi->refill, 0); in _virtnet_set_queues()
2633 static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) in virtnet_set_queues() argument
2638 err = _virtnet_set_queues(vi, queue_pairs); in virtnet_set_queues()
2645 struct virtnet_info *vi = netdev_priv(dev); in virtnet_close() local
2649 disable_delayed_refill(vi); in virtnet_close()
2651 cancel_delayed_work_sync(&vi->refill); in virtnet_close()
2653 for (i = 0; i < vi->max_queue_pairs; i++) in virtnet_close()
2654 virtnet_disable_queue_pair(vi, i); in virtnet_close()
2661 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_rx_mode() local
2671 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX)) in virtnet_set_rx_mode()
2674 vi->ctrl->promisc = ((dev->flags & IFF_PROMISC) != 0); in virtnet_set_rx_mode()
2675 vi->ctrl->allmulti = ((dev->flags & IFF_ALLMULTI) != 0); in virtnet_set_rx_mode()
2677 sg_init_one(sg, &vi->ctrl->promisc, sizeof(vi->ctrl->promisc)); in virtnet_set_rx_mode()
2679 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, in virtnet_set_rx_mode()
2682 vi->ctrl->promisc ? "en" : "dis"); in virtnet_set_rx_mode()
2684 sg_init_one(sg, &vi->ctrl->allmulti, sizeof(vi->ctrl->allmulti)); in virtnet_set_rx_mode()
2686 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, in virtnet_set_rx_mode()
2689 vi->ctrl->allmulti ? "en" : "dis"); in virtnet_set_rx_mode()
2703 mac_data->entries = cpu_to_virtio32(vi->vdev, uc_count); in virtnet_set_rx_mode()
2714 mac_data->entries = cpu_to_virtio32(vi->vdev, mc_count); in virtnet_set_rx_mode()
2722 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, in virtnet_set_rx_mode()
2732 struct virtnet_info *vi = netdev_priv(dev); in virtnet_vlan_rx_add_vid() local
2735 vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid); in virtnet_vlan_rx_add_vid()
2736 sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid)); in virtnet_vlan_rx_add_vid()
2738 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN, in virtnet_vlan_rx_add_vid()
2747 struct virtnet_info *vi = netdev_priv(dev); in virtnet_vlan_rx_kill_vid() local
2750 vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid); in virtnet_vlan_rx_kill_vid()
2751 sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid)); in virtnet_vlan_rx_kill_vid()
2753 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN, in virtnet_vlan_rx_kill_vid()
2759 static void virtnet_clean_affinity(struct virtnet_info *vi) in virtnet_clean_affinity() argument
2763 if (vi->affinity_hint_set) { in virtnet_clean_affinity()
2764 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_clean_affinity()
2765 virtqueue_set_affinity(vi->rq[i].vq, NULL); in virtnet_clean_affinity()
2766 virtqueue_set_affinity(vi->sq[i].vq, NULL); in virtnet_clean_affinity()
2769 vi->affinity_hint_set = false; in virtnet_clean_affinity()
2773 static void virtnet_set_affinity(struct virtnet_info *vi) in virtnet_set_affinity() argument
2783 virtnet_clean_affinity(vi); in virtnet_set_affinity()
2788 stride = max_t(int, num_cpu / vi->curr_queue_pairs, 1); in virtnet_set_affinity()
2789 stragglers = num_cpu >= vi->curr_queue_pairs ? in virtnet_set_affinity()
2790 num_cpu % vi->curr_queue_pairs : in virtnet_set_affinity()
2794 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_set_affinity()
2802 virtqueue_set_affinity(vi->rq[i].vq, mask); in virtnet_set_affinity()
2803 virtqueue_set_affinity(vi->sq[i].vq, mask); in virtnet_set_affinity()
2804 __netif_set_xps_queue(vi->dev, cpumask_bits(mask), i, XPS_CPUS); in virtnet_set_affinity()
2808 vi->affinity_hint_set = true; in virtnet_set_affinity()
2814 struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, in virtnet_cpu_online() local
2816 virtnet_set_affinity(vi); in virtnet_cpu_online()
2822 struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, in virtnet_cpu_dead() local
2824 virtnet_set_affinity(vi); in virtnet_cpu_dead()
2830 struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, in virtnet_cpu_down_prep() local
2833 virtnet_clean_affinity(vi); in virtnet_cpu_down_prep()
2839 static int virtnet_cpu_notif_add(struct virtnet_info *vi) in virtnet_cpu_notif_add() argument
2843 ret = cpuhp_state_add_instance_nocalls(virtionet_online, &vi->node); in virtnet_cpu_notif_add()
2847 &vi->node_dead); in virtnet_cpu_notif_add()
2850 cpuhp_state_remove_instance_nocalls(virtionet_online, &vi->node); in virtnet_cpu_notif_add()
2854 static void virtnet_cpu_notif_remove(struct virtnet_info *vi) in virtnet_cpu_notif_remove() argument
2856 cpuhp_state_remove_instance_nocalls(virtionet_online, &vi->node); in virtnet_cpu_notif_remove()
2858 &vi->node_dead); in virtnet_cpu_notif_remove()
2866 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_ringparam() local
2868 ring->rx_max_pending = vi->rq[0].vq->num_max; in virtnet_get_ringparam()
2869 ring->tx_max_pending = vi->sq[0].vq->num_max; in virtnet_get_ringparam()
2870 ring->rx_pending = virtqueue_get_vring_size(vi->rq[0].vq); in virtnet_get_ringparam()
2871 ring->tx_pending = virtqueue_get_vring_size(vi->sq[0].vq); in virtnet_get_ringparam()
2874 static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi,
2882 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_ringparam() local
2891 rx_pending = virtqueue_get_vring_size(vi->rq[0].vq); in virtnet_set_ringparam()
2892 tx_pending = virtqueue_get_vring_size(vi->sq[0].vq); in virtnet_set_ringparam()
2898 if (ring->rx_pending > vi->rq[0].vq->num_max) in virtnet_set_ringparam()
2901 if (ring->tx_pending > vi->sq[0].vq->num_max) in virtnet_set_ringparam()
2904 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_set_ringparam()
2905 rq = vi->rq + i; in virtnet_set_ringparam()
2906 sq = vi->sq + i; in virtnet_set_ringparam()
2909 err = virtnet_tx_resize(vi, sq, ring->tx_pending); in virtnet_set_ringparam()
2918 err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(i), in virtnet_set_ringparam()
2919 vi->intr_coal_tx.max_usecs, in virtnet_set_ringparam()
2920 vi->intr_coal_tx.max_packets); in virtnet_set_ringparam()
2924 vi->sq[i].intr_coal.max_usecs = vi->intr_coal_tx.max_usecs; in virtnet_set_ringparam()
2925 vi->sq[i].intr_coal.max_packets = vi->intr_coal_tx.max_packets; in virtnet_set_ringparam()
2929 err = virtnet_rx_resize(vi, rq, ring->rx_pending); in virtnet_set_ringparam()
2934 err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(i), in virtnet_set_ringparam()
2935 vi->intr_coal_rx.max_usecs, in virtnet_set_ringparam()
2936 vi->intr_coal_rx.max_packets); in virtnet_set_ringparam()
2940 vi->rq[i].intr_coal.max_usecs = vi->intr_coal_rx.max_usecs; in virtnet_set_ringparam()
2941 vi->rq[i].intr_coal.max_packets = vi->intr_coal_rx.max_packets; in virtnet_set_ringparam()
2948 static bool virtnet_commit_rss_command(struct virtnet_info *vi) in virtnet_commit_rss_command() argument
2950 struct net_device *dev = vi->dev; in virtnet_commit_rss_command()
2958 sg_set_buf(&sgs[0], &vi->ctrl->rss, sg_buf_size); in virtnet_commit_rss_command()
2960 sg_buf_size = sizeof(uint16_t) * (vi->ctrl->rss.indirection_table_mask + 1); in virtnet_commit_rss_command()
2961 sg_set_buf(&sgs[1], vi->ctrl->rss.indirection_table, sg_buf_size); in virtnet_commit_rss_command()
2965 sg_set_buf(&sgs[2], &vi->ctrl->rss.max_tx_vq, sg_buf_size); in virtnet_commit_rss_command()
2967 sg_buf_size = vi->rss_key_size; in virtnet_commit_rss_command()
2968 sg_set_buf(&sgs[3], vi->ctrl->rss.key, sg_buf_size); in virtnet_commit_rss_command()
2970 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, in virtnet_commit_rss_command()
2971 vi->has_rss ? VIRTIO_NET_CTRL_MQ_RSS_CONFIG in virtnet_commit_rss_command()
2979 static void virtnet_init_default_rss(struct virtnet_info *vi) in virtnet_init_default_rss() argument
2984 vi->ctrl->rss.hash_types = vi->rss_hash_types_supported; in virtnet_init_default_rss()
2985 vi->rss_hash_types_saved = vi->rss_hash_types_supported; in virtnet_init_default_rss()
2986 vi->ctrl->rss.indirection_table_mask = vi->rss_indir_table_size in virtnet_init_default_rss()
2987 ? vi->rss_indir_table_size - 1 : 0; in virtnet_init_default_rss()
2988 vi->ctrl->rss.unclassified_queue = 0; in virtnet_init_default_rss()
2990 for (; i < vi->rss_indir_table_size; ++i) { in virtnet_init_default_rss()
2991 indir_val = ethtool_rxfh_indir_default(i, vi->curr_queue_pairs); in virtnet_init_default_rss()
2992 vi->ctrl->rss.indirection_table[i] = indir_val; in virtnet_init_default_rss()
2995 vi->ctrl->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0; in virtnet_init_default_rss()
2996 vi->ctrl->rss.hash_key_length = vi->rss_key_size; in virtnet_init_default_rss()
2998 netdev_rss_key_fill(vi->ctrl->rss.key, vi->rss_key_size); in virtnet_init_default_rss()
3001 static void virtnet_get_hashflow(const struct virtnet_info *vi, struct ethtool_rxnfc *info) in virtnet_get_hashflow() argument
3006 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_TCPv4) { in virtnet_get_hashflow()
3009 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv4) { in virtnet_get_hashflow()
3014 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_TCPv6) { in virtnet_get_hashflow()
3017 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv6) { in virtnet_get_hashflow()
3022 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_UDPv4) { in virtnet_get_hashflow()
3025 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv4) { in virtnet_get_hashflow()
3030 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_UDPv6) { in virtnet_get_hashflow()
3033 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv6) { in virtnet_get_hashflow()
3038 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv4) in virtnet_get_hashflow()
3043 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv6) in virtnet_get_hashflow()
3053 static bool virtnet_set_hashflow(struct virtnet_info *vi, struct ethtool_rxnfc *info) in virtnet_set_hashflow() argument
3055 u32 new_hashtypes = vi->rss_hash_types_saved; in virtnet_set_hashflow()
3104 if (new_hashtypes != (new_hashtypes & vi->rss_hash_types_supported)) in virtnet_set_hashflow()
3107 if (new_hashtypes != vi->rss_hash_types_saved) { in virtnet_set_hashflow()
3108 vi->rss_hash_types_saved = new_hashtypes; in virtnet_set_hashflow()
3109 vi->ctrl->rss.hash_types = vi->rss_hash_types_saved; in virtnet_set_hashflow()
3110 if (vi->dev->features & NETIF_F_RXHASH) in virtnet_set_hashflow()
3111 return virtnet_commit_rss_command(vi); in virtnet_set_hashflow()
3120 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_drvinfo() local
3121 struct virtio_device *vdev = vi->vdev; in virtnet_get_drvinfo()
3133 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_channels() local
3143 if (queue_pairs > vi->max_queue_pairs || queue_pairs == 0) in virtnet_set_channels()
3150 if (vi->rq[0].xdp_prog) in virtnet_set_channels()
3154 err = _virtnet_set_queues(vi, queue_pairs); in virtnet_set_channels()
3159 virtnet_set_affinity(vi); in virtnet_set_channels()
3170 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_strings() local
3176 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_strings()
3182 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_strings()
3193 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_sset_count() local
3197 return vi->curr_queue_pairs * (VIRTNET_RQ_STATS_LEN + in virtnet_get_sset_count()
3207 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_ethtool_stats() local
3213 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_ethtool_stats()
3214 struct receive_queue *rq = &vi->rq[i]; in virtnet_get_ethtool_stats()
3228 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_ethtool_stats()
3229 struct send_queue *sq = &vi->sq[i]; in virtnet_get_ethtool_stats()
3247 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_channels() local
3249 channels->combined_count = vi->curr_queue_pairs; in virtnet_get_channels()
3250 channels->max_combined = vi->max_queue_pairs; in virtnet_get_channels()
3260 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_link_ksettings() local
3263 &vi->speed, &vi->duplex); in virtnet_set_link_ksettings()
3269 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_link_ksettings() local
3271 cmd->base.speed = vi->speed; in virtnet_get_link_ksettings()
3272 cmd->base.duplex = vi->duplex; in virtnet_get_link_ksettings()
3278 static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi, in virtnet_send_notf_coal_cmds() argument
3284 vi->ctrl->coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs); in virtnet_send_notf_coal_cmds()
3285 vi->ctrl->coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames); in virtnet_send_notf_coal_cmds()
3286 sg_init_one(&sgs_tx, &vi->ctrl->coal_tx, sizeof(vi->ctrl->coal_tx)); in virtnet_send_notf_coal_cmds()
3288 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, in virtnet_send_notf_coal_cmds()
3294 vi->intr_coal_tx.max_usecs = ec->tx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3295 vi->intr_coal_tx.max_packets = ec->tx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3296 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_send_notf_coal_cmds()
3297 vi->sq[i].intr_coal.max_usecs = ec->tx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3298 vi->sq[i].intr_coal.max_packets = ec->tx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3301 vi->ctrl->coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); in virtnet_send_notf_coal_cmds()
3302 vi->ctrl->coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); in virtnet_send_notf_coal_cmds()
3303 sg_init_one(&sgs_rx, &vi->ctrl->coal_rx, sizeof(vi->ctrl->coal_rx)); in virtnet_send_notf_coal_cmds()
3305 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, in virtnet_send_notf_coal_cmds()
3311 vi->intr_coal_rx.max_usecs = ec->rx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3312 vi->intr_coal_rx.max_packets = ec->rx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3313 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_send_notf_coal_cmds()
3314 vi->rq[i].intr_coal.max_usecs = ec->rx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3315 vi->rq[i].intr_coal.max_packets = ec->rx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3321 static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi, in virtnet_send_ctrl_coal_vq_cmd() argument
3326 vi->ctrl->coal_vq.vqn = cpu_to_le16(vqn); in virtnet_send_ctrl_coal_vq_cmd()
3327 vi->ctrl->coal_vq.coal.max_usecs = cpu_to_le32(max_usecs); in virtnet_send_ctrl_coal_vq_cmd()
3328 vi->ctrl->coal_vq.coal.max_packets = cpu_to_le32(max_packets); in virtnet_send_ctrl_coal_vq_cmd()
3329 sg_init_one(&sgs, &vi->ctrl->coal_vq, sizeof(vi->ctrl->coal_vq)); in virtnet_send_ctrl_coal_vq_cmd()
3331 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, in virtnet_send_ctrl_coal_vq_cmd()
3339 static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, in virtnet_send_notf_coal_vq_cmds() argument
3345 err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue), in virtnet_send_notf_coal_vq_cmds()
3351 vi->rq[queue].intr_coal.max_usecs = ec->rx_coalesce_usecs; in virtnet_send_notf_coal_vq_cmds()
3352 vi->rq[queue].intr_coal.max_packets = ec->rx_max_coalesced_frames; in virtnet_send_notf_coal_vq_cmds()
3354 err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue), in virtnet_send_notf_coal_vq_cmds()
3360 vi->sq[queue].intr_coal.max_usecs = ec->tx_coalesce_usecs; in virtnet_send_notf_coal_vq_cmds()
3361 vi->sq[queue].intr_coal.max_packets = ec->tx_max_coalesced_frames; in virtnet_send_notf_coal_vq_cmds()
3398 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_coalesce() local
3404 for (queue_number = 0; queue_number < vi->max_queue_pairs; queue_number++) { in virtnet_set_coalesce()
3406 vi->sq[queue_number].napi.weight, in virtnet_set_coalesce()
3412 /* All queues that belong to [queue_number, vi->max_queue_pairs] will be in virtnet_set_coalesce()
3419 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) in virtnet_set_coalesce()
3420 ret = virtnet_send_notf_coal_cmds(vi, ec); in virtnet_set_coalesce()
3428 for (; queue_number < vi->max_queue_pairs; queue_number++) in virtnet_set_coalesce()
3429 vi->sq[queue_number].napi.weight = napi_weight; in virtnet_set_coalesce()
3440 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_coalesce() local
3442 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { in virtnet_get_coalesce()
3443 ec->rx_coalesce_usecs = vi->intr_coal_rx.max_usecs; in virtnet_get_coalesce()
3444 ec->tx_coalesce_usecs = vi->intr_coal_tx.max_usecs; in virtnet_get_coalesce()
3445 ec->tx_max_coalesced_frames = vi->intr_coal_tx.max_packets; in virtnet_get_coalesce()
3446 ec->rx_max_coalesced_frames = vi->intr_coal_rx.max_packets; in virtnet_get_coalesce()
3450 if (vi->sq[0].napi.weight) in virtnet_get_coalesce()
3461 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_per_queue_coalesce() local
3465 if (queue >= vi->max_queue_pairs) in virtnet_set_per_queue_coalesce()
3471 vi->sq[queue].napi.weight, in virtnet_set_per_queue_coalesce()
3476 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) in virtnet_set_per_queue_coalesce()
3477 ret = virtnet_send_notf_coal_vq_cmds(vi, ec, queue); in virtnet_set_per_queue_coalesce()
3485 vi->sq[queue].napi.weight = napi_weight; in virtnet_set_per_queue_coalesce()
3494 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_per_queue_coalesce() local
3496 if (queue >= vi->max_queue_pairs) in virtnet_get_per_queue_coalesce()
3499 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) { in virtnet_get_per_queue_coalesce()
3500 ec->rx_coalesce_usecs = vi->rq[queue].intr_coal.max_usecs; in virtnet_get_per_queue_coalesce()
3501 ec->tx_coalesce_usecs = vi->sq[queue].intr_coal.max_usecs; in virtnet_get_per_queue_coalesce()
3502 ec->tx_max_coalesced_frames = vi->sq[queue].intr_coal.max_packets; in virtnet_get_per_queue_coalesce()
3503 ec->rx_max_coalesced_frames = vi->rq[queue].intr_coal.max_packets; in virtnet_get_per_queue_coalesce()
3507 if (vi->sq[queue].napi.weight) in virtnet_get_per_queue_coalesce()
3516 struct virtnet_info *vi = netdev_priv(dev); in virtnet_init_settings() local
3518 vi->speed = SPEED_UNKNOWN; in virtnet_init_settings()
3519 vi->duplex = DUPLEX_UNKNOWN; in virtnet_init_settings()
3522 static void virtnet_update_settings(struct virtnet_info *vi) in virtnet_update_settings() argument
3527 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_SPEED_DUPLEX)) in virtnet_update_settings()
3530 virtio_cread_le(vi->vdev, struct virtio_net_config, speed, &speed); in virtnet_update_settings()
3533 vi->speed = speed; in virtnet_update_settings()
3535 virtio_cread_le(vi->vdev, struct virtio_net_config, duplex, &duplex); in virtnet_update_settings()
3538 vi->duplex = duplex; in virtnet_update_settings()
3553 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_rxfh() local
3557 for (i = 0; i < vi->rss_indir_table_size; ++i) in virtnet_get_rxfh()
3558 indir[i] = vi->ctrl->rss.indirection_table[i]; in virtnet_get_rxfh()
3562 memcpy(key, vi->ctrl->rss.key, vi->rss_key_size); in virtnet_get_rxfh()
3572 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_rxfh() local
3579 for (i = 0; i < vi->rss_indir_table_size; ++i) in virtnet_set_rxfh()
3580 vi->ctrl->rss.indirection_table[i] = indir[i]; in virtnet_set_rxfh()
3583 memcpy(vi->ctrl->rss.key, key, vi->rss_key_size); in virtnet_set_rxfh()
3585 virtnet_commit_rss_command(vi); in virtnet_set_rxfh()
3592 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_rxnfc() local
3597 info->data = vi->curr_queue_pairs; in virtnet_get_rxnfc()
3600 virtnet_get_hashflow(vi, info); in virtnet_get_rxnfc()
3611 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_rxnfc() local
3616 if (!virtnet_set_hashflow(vi, info)) in virtnet_set_rxnfc()
3656 struct virtnet_info *vi = vdev->priv; in virtnet_freeze_down() local
3659 flush_work(&vi->config_work); in virtnet_freeze_down()
3661 netif_tx_lock_bh(vi->dev); in virtnet_freeze_down()
3662 netif_device_detach(vi->dev); in virtnet_freeze_down()
3663 netif_tx_unlock_bh(vi->dev); in virtnet_freeze_down()
3664 if (netif_running(vi->dev)) in virtnet_freeze_down()
3665 virtnet_close(vi->dev); in virtnet_freeze_down()
3668 static int init_vqs(struct virtnet_info *vi);
3672 struct virtnet_info *vi = vdev->priv; in virtnet_restore_up() local
3675 err = init_vqs(vi); in virtnet_restore_up()
3681 enable_delayed_refill(vi); in virtnet_restore_up()
3683 if (netif_running(vi->dev)) { in virtnet_restore_up()
3684 err = virtnet_open(vi->dev); in virtnet_restore_up()
3689 netif_tx_lock_bh(vi->dev); in virtnet_restore_up()
3690 netif_device_attach(vi->dev); in virtnet_restore_up()
3691 netif_tx_unlock_bh(vi->dev); in virtnet_restore_up()
3695 static int virtnet_set_guest_offloads(struct virtnet_info *vi, u64 offloads) in virtnet_set_guest_offloads() argument
3698 vi->ctrl->offloads = cpu_to_virtio64(vi->vdev, offloads); in virtnet_set_guest_offloads()
3700 sg_init_one(&sg, &vi->ctrl->offloads, sizeof(vi->ctrl->offloads)); in virtnet_set_guest_offloads()
3702 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_GUEST_OFFLOADS, in virtnet_set_guest_offloads()
3704 dev_warn(&vi->dev->dev, "Fail to set guest offload.\n"); in virtnet_set_guest_offloads()
3711 static int virtnet_clear_guest_offloads(struct virtnet_info *vi) in virtnet_clear_guest_offloads() argument
3715 if (!vi->guest_offloads) in virtnet_clear_guest_offloads()
3718 return virtnet_set_guest_offloads(vi, offloads); in virtnet_clear_guest_offloads()
3721 static int virtnet_restore_guest_offloads(struct virtnet_info *vi) in virtnet_restore_guest_offloads() argument
3723 u64 offloads = vi->guest_offloads; in virtnet_restore_guest_offloads()
3725 if (!vi->guest_offloads) in virtnet_restore_guest_offloads()
3728 return virtnet_set_guest_offloads(vi, offloads); in virtnet_restore_guest_offloads()
3737 struct virtnet_info *vi = netdev_priv(dev); in virtnet_xdp_set() local
3742 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) in virtnet_xdp_set()
3743 && (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO4) || in virtnet_xdp_set()
3744 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO6) || in virtnet_xdp_set()
3745 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_ECN) || in virtnet_xdp_set()
3746 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO) || in virtnet_xdp_set()
3747 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_CSUM) || in virtnet_xdp_set()
3748 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO4) || in virtnet_xdp_set()
3749 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO6))) { in virtnet_xdp_set()
3754 if (vi->mergeable_rx_bufs && !vi->any_header_sg) { in virtnet_xdp_set()
3765 curr_qp = vi->curr_queue_pairs - vi->xdp_queue_pairs; in virtnet_xdp_set()
3770 if (curr_qp + xdp_qp > vi->max_queue_pairs) { in virtnet_xdp_set()
3772 curr_qp + xdp_qp, vi->max_queue_pairs); in virtnet_xdp_set()
3776 old_prog = rtnl_dereference(vi->rq[0].xdp_prog); in virtnet_xdp_set()
3781 bpf_prog_add(prog, vi->max_queue_pairs - 1); in virtnet_xdp_set()
3785 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3786 napi_disable(&vi->rq[i].napi); in virtnet_xdp_set()
3787 virtnet_napi_tx_disable(&vi->sq[i].napi); in virtnet_xdp_set()
3792 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3793 rcu_assign_pointer(vi->rq[i].xdp_prog, prog); in virtnet_xdp_set()
3795 virtnet_restore_guest_offloads(vi); in virtnet_xdp_set()
3800 err = _virtnet_set_queues(vi, curr_qp + xdp_qp); in virtnet_xdp_set()
3804 vi->xdp_queue_pairs = xdp_qp; in virtnet_xdp_set()
3807 vi->xdp_enabled = true; in virtnet_xdp_set()
3808 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3809 rcu_assign_pointer(vi->rq[i].xdp_prog, prog); in virtnet_xdp_set()
3811 virtnet_clear_guest_offloads(vi); in virtnet_xdp_set()
3817 vi->xdp_enabled = false; in virtnet_xdp_set()
3820 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3824 virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); in virtnet_xdp_set()
3825 virtnet_napi_tx_enable(vi, vi->sq[i].vq, in virtnet_xdp_set()
3826 &vi->sq[i].napi); in virtnet_xdp_set()
3834 virtnet_clear_guest_offloads(vi); in virtnet_xdp_set()
3835 for (i = 0; i < vi->max_queue_pairs; i++) in virtnet_xdp_set()
3836 rcu_assign_pointer(vi->rq[i].xdp_prog, old_prog); in virtnet_xdp_set()
3840 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3841 virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); in virtnet_xdp_set()
3842 virtnet_napi_tx_enable(vi, vi->sq[i].vq, in virtnet_xdp_set()
3843 &vi->sq[i].napi); in virtnet_xdp_set()
3847 bpf_prog_sub(prog, vi->max_queue_pairs - 1); in virtnet_xdp_set()
3864 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_phys_port_name() local
3867 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_STANDBY)) in virtnet_get_phys_port_name()
3880 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_features() local
3885 if (vi->xdp_enabled) in virtnet_set_features()
3889 offloads = vi->guest_offloads_capable; in virtnet_set_features()
3891 offloads = vi->guest_offloads_capable & in virtnet_set_features()
3894 err = virtnet_set_guest_offloads(vi, offloads); in virtnet_set_features()
3897 vi->guest_offloads = offloads; in virtnet_set_features()
3902 vi->ctrl->rss.hash_types = vi->rss_hash_types_saved; in virtnet_set_features()
3904 vi->ctrl->rss.hash_types = VIRTIO_NET_HASH_REPORT_NONE; in virtnet_set_features()
3906 if (!virtnet_commit_rss_command(vi)) in virtnet_set_features()
3948 struct virtnet_info *vi = in virtnet_config_changed_work() local
3952 if (virtio_cread_feature(vi->vdev, VIRTIO_NET_F_STATUS, in virtnet_config_changed_work()
3957 netdev_notify_peers(vi->dev); in virtnet_config_changed_work()
3958 virtnet_ack_link_announce(vi); in virtnet_config_changed_work()
3964 if (vi->status == v) in virtnet_config_changed_work()
3967 vi->status = v; in virtnet_config_changed_work()
3969 if (vi->status & VIRTIO_NET_S_LINK_UP) { in virtnet_config_changed_work()
3970 virtnet_update_settings(vi); in virtnet_config_changed_work()
3971 netif_carrier_on(vi->dev); in virtnet_config_changed_work()
3972 netif_tx_wake_all_queues(vi->dev); in virtnet_config_changed_work()
3974 netif_carrier_off(vi->dev); in virtnet_config_changed_work()
3975 netif_tx_stop_all_queues(vi->dev); in virtnet_config_changed_work()
3981 struct virtnet_info *vi = vdev->priv; in virtnet_config_changed() local
3983 schedule_work(&vi->config_work); in virtnet_config_changed()
3986 static void virtnet_free_queues(struct virtnet_info *vi) in virtnet_free_queues() argument
3990 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_free_queues()
3991 __netif_napi_del(&vi->rq[i].napi); in virtnet_free_queues()
3992 __netif_napi_del(&vi->sq[i].napi); in virtnet_free_queues()
3996 * we need to respect an RCU grace period before freeing vi->rq in virtnet_free_queues()
4000 kfree(vi->rq); in virtnet_free_queues()
4001 kfree(vi->sq); in virtnet_free_queues()
4002 kfree(vi->ctrl); in virtnet_free_queues()
4005 static void _free_receive_bufs(struct virtnet_info *vi) in _free_receive_bufs() argument
4010 for (i = 0; i < vi->max_queue_pairs; i++) { in _free_receive_bufs()
4011 while (vi->rq[i].pages) in _free_receive_bufs()
4012 __free_pages(get_a_page(&vi->rq[i], GFP_KERNEL), 0); in _free_receive_bufs()
4014 old_prog = rtnl_dereference(vi->rq[i].xdp_prog); in _free_receive_bufs()
4015 RCU_INIT_POINTER(vi->rq[i].xdp_prog, NULL); in _free_receive_bufs()
4021 static void free_receive_bufs(struct virtnet_info *vi) in free_receive_bufs() argument
4024 _free_receive_bufs(vi); in free_receive_bufs()
4028 static void free_receive_page_frags(struct virtnet_info *vi) in free_receive_page_frags() argument
4031 for (i = 0; i < vi->max_queue_pairs; i++) in free_receive_page_frags()
4032 if (vi->rq[i].alloc_frag.page) { in free_receive_page_frags()
4033 if (vi->rq[i].do_dma && vi->rq[i].last_dma) in free_receive_page_frags()
4034 virtnet_rq_unmap(&vi->rq[i], vi->rq[i].last_dma, 0); in free_receive_page_frags()
4035 put_page(vi->rq[i].alloc_frag.page); in free_receive_page_frags()
4047 static void free_unused_bufs(struct virtnet_info *vi) in free_unused_bufs() argument
4052 for (i = 0; i < vi->max_queue_pairs; i++) { in free_unused_bufs()
4053 struct virtqueue *vq = vi->sq[i].vq; in free_unused_bufs()
4059 for (i = 0; i < vi->max_queue_pairs; i++) { in free_unused_bufs()
4060 struct virtqueue *vq = vi->rq[i].vq; in free_unused_bufs()
4068 static void virtnet_del_vqs(struct virtnet_info *vi) in virtnet_del_vqs() argument
4070 struct virtio_device *vdev = vi->vdev; in virtnet_del_vqs()
4072 virtnet_clean_affinity(vi); in virtnet_del_vqs()
4076 virtnet_free_queues(vi); in virtnet_del_vqs()
4083 static unsigned int mergeable_min_buf_len(struct virtnet_info *vi, struct virtqueue *vq) in mergeable_min_buf_len() argument
4085 const unsigned int hdr_len = vi->hdr_len; in mergeable_min_buf_len()
4087 unsigned int packet_len = vi->big_packets ? IP_MAX_MTU : vi->dev->max_mtu; in mergeable_min_buf_len()
4095 static int virtnet_find_vqs(struct virtnet_info *vi) in virtnet_find_vqs() argument
4109 total_vqs = vi->max_queue_pairs * 2 + in virtnet_find_vqs()
4110 virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ); in virtnet_find_vqs()
4122 if (!vi->big_packets || vi->mergeable_rx_bufs) { in virtnet_find_vqs()
4131 if (vi->has_cvq) { in virtnet_find_vqs()
4137 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_find_vqs()
4140 sprintf(vi->rq[i].name, "input.%u", i); in virtnet_find_vqs()
4141 sprintf(vi->sq[i].name, "output.%u", i); in virtnet_find_vqs()
4142 names[rxq2vq(i)] = vi->rq[i].name; in virtnet_find_vqs()
4143 names[txq2vq(i)] = vi->sq[i].name; in virtnet_find_vqs()
4148 ret = virtio_find_vqs_ctx(vi->vdev, total_vqs, vqs, callbacks, in virtnet_find_vqs()
4153 if (vi->has_cvq) { in virtnet_find_vqs()
4154 vi->cvq = vqs[total_vqs - 1]; in virtnet_find_vqs()
4155 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN)) in virtnet_find_vqs()
4156 vi->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; in virtnet_find_vqs()
4159 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_find_vqs()
4160 vi->rq[i].vq = vqs[rxq2vq(i)]; in virtnet_find_vqs()
4161 vi->rq[i].min_buf_len = mergeable_min_buf_len(vi, vi->rq[i].vq); in virtnet_find_vqs()
4162 vi->sq[i].vq = vqs[txq2vq(i)]; in virtnet_find_vqs()
4180 static int virtnet_alloc_queues(struct virtnet_info *vi) in virtnet_alloc_queues() argument
4184 if (vi->has_cvq) { in virtnet_alloc_queues()
4185 vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL); in virtnet_alloc_queues()
4186 if (!vi->ctrl) in virtnet_alloc_queues()
4189 vi->ctrl = NULL; in virtnet_alloc_queues()
4191 vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL); in virtnet_alloc_queues()
4192 if (!vi->sq) in virtnet_alloc_queues()
4194 vi->rq = kcalloc(vi->max_queue_pairs, sizeof(*vi->rq), GFP_KERNEL); in virtnet_alloc_queues()
4195 if (!vi->rq) in virtnet_alloc_queues()
4198 INIT_DELAYED_WORK(&vi->refill, refill_work); in virtnet_alloc_queues()
4199 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_alloc_queues()
4200 vi->rq[i].pages = NULL; in virtnet_alloc_queues()
4201 netif_napi_add_weight(vi->dev, &vi->rq[i].napi, virtnet_poll, in virtnet_alloc_queues()
4203 netif_napi_add_tx_weight(vi->dev, &vi->sq[i].napi, in virtnet_alloc_queues()
4207 sg_init_table(vi->rq[i].sg, ARRAY_SIZE(vi->rq[i].sg)); in virtnet_alloc_queues()
4208 ewma_pkt_len_init(&vi->rq[i].mrg_avg_pkt_len); in virtnet_alloc_queues()
4209 sg_init_table(vi->sq[i].sg, ARRAY_SIZE(vi->sq[i].sg)); in virtnet_alloc_queues()
4211 u64_stats_init(&vi->rq[i].stats.syncp); in virtnet_alloc_queues()
4212 u64_stats_init(&vi->sq[i].stats.syncp); in virtnet_alloc_queues()
4218 kfree(vi->sq); in virtnet_alloc_queues()
4220 kfree(vi->ctrl); in virtnet_alloc_queues()
4225 static int init_vqs(struct virtnet_info *vi) in init_vqs() argument
4230 ret = virtnet_alloc_queues(vi); in init_vqs()
4234 ret = virtnet_find_vqs(vi); in init_vqs()
4238 virtnet_rq_set_premapped(vi); in init_vqs()
4241 virtnet_set_affinity(vi); in init_vqs()
4247 virtnet_free_queues(vi); in init_vqs()
4256 struct virtnet_info *vi = netdev_priv(queue->dev); in mergeable_rx_buffer_size_show() local
4258 unsigned int headroom = virtnet_get_headroom(vi); in mergeable_rx_buffer_size_show()
4262 BUG_ON(queue_index >= vi->max_queue_pairs); in mergeable_rx_buffer_size_show()
4263 avg = &vi->rq[queue_index].mrg_avg_pkt_len; in mergeable_rx_buffer_size_show()
4265 get_mergeable_buf_len(&vi->rq[queue_index], avg, in mergeable_rx_buffer_size_show()
4356 static bool virtnet_check_guest_gso(const struct virtnet_info *vi) in virtnet_check_guest_gso() argument
4358 return virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO4) || in virtnet_check_guest_gso()
4359 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO6) || in virtnet_check_guest_gso()
4360 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_ECN) || in virtnet_check_guest_gso()
4361 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO) || in virtnet_check_guest_gso()
4362 (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO4) && in virtnet_check_guest_gso()
4363 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO6)); in virtnet_check_guest_gso()
4366 static void virtnet_set_big_packets(struct virtnet_info *vi, const int mtu) in virtnet_set_big_packets() argument
4368 bool guest_gso = virtnet_check_guest_gso(vi); in virtnet_set_big_packets()
4375 vi->big_packets = true; in virtnet_set_big_packets()
4376 vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS : DIV_ROUND_UP(mtu, PAGE_SIZE); in virtnet_set_big_packets()
4384 struct virtnet_info *vi; in virtnet_probe() local
4471 vi = netdev_priv(dev); in virtnet_probe()
4472 vi->dev = dev; in virtnet_probe()
4473 vi->vdev = vdev; in virtnet_probe()
4474 vdev->priv = vi; in virtnet_probe()
4476 INIT_WORK(&vi->config_work, virtnet_config_changed_work); in virtnet_probe()
4477 spin_lock_init(&vi->refill_lock); in virtnet_probe()
4480 vi->mergeable_rx_bufs = true; in virtnet_probe()
4484 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { in virtnet_probe()
4485 vi->intr_coal_rx.max_usecs = 0; in virtnet_probe()
4486 vi->intr_coal_tx.max_usecs = 0; in virtnet_probe()
4487 vi->intr_coal_tx.max_packets = 0; in virtnet_probe()
4488 vi->intr_coal_rx.max_packets = 0; in virtnet_probe()
4492 vi->has_rss_hash_report = true; in virtnet_probe()
4495 vi->has_rss = true; in virtnet_probe()
4497 if (vi->has_rss || vi->has_rss_hash_report) { in virtnet_probe()
4498 vi->rss_indir_table_size = in virtnet_probe()
4501 vi->rss_key_size = in virtnet_probe()
4504 vi->rss_hash_types_supported = in virtnet_probe()
4506 vi->rss_hash_types_supported &= in virtnet_probe()
4514 if (vi->has_rss_hash_report) in virtnet_probe()
4515 vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); in virtnet_probe()
4518 vi->hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf); in virtnet_probe()
4520 vi->hdr_len = sizeof(struct virtio_net_hdr); in virtnet_probe()
4524 vi->any_header_sg = true; in virtnet_probe()
4527 vi->has_cvq = true; in virtnet_probe()
4548 virtnet_set_big_packets(vi, mtu); in virtnet_probe()
4550 if (vi->any_header_sg) in virtnet_probe()
4551 dev->needed_headroom = vi->hdr_len; in virtnet_probe()
4555 vi->curr_queue_pairs = max_queue_pairs; in virtnet_probe()
4557 vi->curr_queue_pairs = num_online_cpus(); in virtnet_probe()
4558 vi->max_queue_pairs = max_queue_pairs; in virtnet_probe()
4561 err = init_vqs(vi); in virtnet_probe()
4566 if (vi->mergeable_rx_bufs) in virtnet_probe()
4569 netif_set_real_num_tx_queues(dev, vi->curr_queue_pairs); in virtnet_probe()
4570 netif_set_real_num_rx_queues(dev, vi->curr_queue_pairs); in virtnet_probe()
4575 vi->failover = net_failover_create(vi->dev); in virtnet_probe()
4576 if (IS_ERR(vi->failover)) { in virtnet_probe()
4577 err = PTR_ERR(vi->failover); in virtnet_probe()
4582 if (vi->has_rss || vi->has_rss_hash_report) in virtnet_probe()
4583 virtnet_init_default_rss(vi); in virtnet_probe()
4597 _virtnet_set_queues(vi, vi->curr_queue_pairs); in virtnet_probe()
4604 virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) { in virtnet_probe()
4608 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, in virtnet_probe()
4619 err = virtnet_cpu_notif_add(vi); in virtnet_probe()
4628 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) { in virtnet_probe()
4629 schedule_work(&vi->config_work); in virtnet_probe()
4631 vi->status = VIRTIO_NET_S_LINK_UP; in virtnet_probe()
4632 virtnet_update_settings(vi); in virtnet_probe()
4637 if (virtio_has_feature(vi->vdev, guest_offloads[i])) in virtnet_probe()
4638 set_bit(guest_offloads[i], &vi->guest_offloads); in virtnet_probe()
4639 vi->guest_offloads_capable = vi->guest_offloads; in virtnet_probe()
4649 net_failover_destroy(vi->failover); in virtnet_probe()
4652 cancel_delayed_work_sync(&vi->refill); in virtnet_probe()
4653 free_receive_page_frags(vi); in virtnet_probe()
4654 virtnet_del_vqs(vi); in virtnet_probe()
4660 static void remove_vq_common(struct virtnet_info *vi) in remove_vq_common() argument
4662 virtio_reset_device(vi->vdev); in remove_vq_common()
4665 free_unused_bufs(vi); in remove_vq_common()
4667 free_receive_bufs(vi); in remove_vq_common()
4669 free_receive_page_frags(vi); in remove_vq_common()
4671 virtnet_del_vqs(vi); in remove_vq_common()
4676 struct virtnet_info *vi = vdev->priv; in virtnet_remove() local
4678 virtnet_cpu_notif_remove(vi); in virtnet_remove()
4681 flush_work(&vi->config_work); in virtnet_remove()
4683 unregister_netdev(vi->dev); in virtnet_remove()
4685 net_failover_destroy(vi->failover); in virtnet_remove()
4687 remove_vq_common(vi); in virtnet_remove()
4689 free_netdev(vi->dev); in virtnet_remove()
4694 struct virtnet_info *vi = vdev->priv; in virtnet_freeze() local
4696 virtnet_cpu_notif_remove(vi); in virtnet_freeze()
4698 remove_vq_common(vi); in virtnet_freeze()
4705 struct virtnet_info *vi = vdev->priv; in virtnet_restore() local
4711 virtnet_set_queues(vi, vi->curr_queue_pairs); in virtnet_restore()
4713 err = virtnet_cpu_notif_add(vi); in virtnet_restore()
4716 remove_vq_common(vi); in virtnet_restore()