Lines Matching refs:vi
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()
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()
1200 if (unlikely(xdp_headroom < virtnet_get_headroom(vi))) { in receive_small_xdp()
1202 unsigned int tlen = len + vi->hdr_len; in receive_small_xdp()
1205 xdp_headroom = virtnet_get_headroom(vi); in receive_small_xdp()
1207 headroom = vi->hdr_len + header_offset; in receive_small_xdp()
1222 xdp_prepare_buff(&xdp, buf + VIRTNET_RX_PAD + vi->hdr_len, in receive_small_xdp()
1261 struct virtnet_info *vi, in receive_small() argument
1272 len -= vi->hdr_len; in receive_small()
1282 if (unlikely(vi->xdp_enabled)) { in receive_small()
1288 skb = receive_small_xdp(dev, vi, rq, xdp_prog, buf, in receive_small()
1297 skb = receive_small_build_skb(vi, xdp_headroom, buf, len); in receive_small()
1308 struct virtnet_info *vi, in receive_big() argument
1316 page_to_skb(vi, rq, page, 0, len, PAGE_SIZE, 0); in receive_big()
1318 u64_stats_add(&stats->bytes, len - vi->hdr_len); in receive_big()
1360 struct virtnet_info *vi, in build_skb_from_xdp_buff() argument
1403 struct virtnet_info *vi, in virtnet_build_xdp_buff_mrg() argument
1425 VIRTIO_XDP_HEADROOM + vi->hdr_len, len - vi->hdr_len, true); in virtnet_build_xdp_buff_mrg()
1451 virtio16_to_cpu(vi->vdev, hdr->num_buffers)); in virtnet_build_xdp_buff_mrg()
1491 static void *mergeable_xdp_get_buf(struct virtnet_info *vi, in mergeable_xdp_get_buf() argument
1525 if (likely(headroom >= virtnet_get_headroom(vi) && in mergeable_xdp_get_buf()
1570 struct virtnet_info *vi, in receive_mergeable_xdp() argument
1580 int num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers); in receive_mergeable_xdp()
1591 data = mergeable_xdp_get_buf(vi, rq, xdp_prog, ctx, &frame_sz, &num_buf, &page, in receive_mergeable_xdp()
1596 err = virtnet_build_xdp_buff_mrg(dev, vi, rq, &xdp, data, len, frame_sz, in receive_mergeable_xdp()
1605 head_skb = build_skb_from_xdp_buff(dev, vi, &xdp, xdp_frags_truesz); in receive_mergeable_xdp()
1630 struct virtnet_info *vi, in receive_mergeable() argument
1639 int num_buf = virtio16_to_cpu(vi->vdev, hdr->num_buffers); in receive_mergeable()
1649 u64_stats_add(&stats->bytes, len - vi->hdr_len); in receive_mergeable()
1658 if (unlikely(vi->xdp_enabled)) { in receive_mergeable()
1664 head_skb = receive_mergeable_xdp(dev, vi, rq, xdp_prog, buf, ctx, in receive_mergeable()
1672 head_skb = page_to_skb(vi, rq, page, offset, len, truesize, headroom); in receive_mergeable()
1684 virtio16_to_cpu(vi->vdev, in receive_mergeable()
1776 static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, in receive_buf() argument
1781 struct net_device *dev = vi->dev; in receive_buf()
1786 if (unlikely(len < vi->hdr_len + ETH_HLEN)) { in receive_buf()
1789 virtnet_rq_free_buf(vi, rq, buf); in receive_buf()
1802 if (vi->mergeable_rx_bufs) in receive_buf()
1803 skb = receive_mergeable(dev, vi, rq, buf, ctx, len, xdp_xmit, in receive_buf()
1805 else if (vi->big_packets) in receive_buf()
1806 skb = receive_big(dev, vi, rq, buf, len, stats); in receive_buf()
1808 skb = receive_small(dev, vi, rq, buf, ctx, len, xdp_xmit, stats); in receive_buf()
1814 if (dev->features & NETIF_F_RXHASH && vi->has_rss_hash_report) in receive_buf()
1821 virtio_is_little_endian(vi->vdev))) { in receive_buf()
1846 static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq, in add_recvbuf_small() argument
1850 unsigned int xdp_headroom = virtnet_get_headroom(vi); in add_recvbuf_small()
1852 int len = vi->hdr_len + VIRTNET_RX_PAD + GOOD_PACKET_LEN + xdp_headroom; in add_recvbuf_small()
1863 vi->hdr_len + GOOD_PACKET_LEN); in add_recvbuf_small()
1875 static int add_recvbuf_big(struct virtnet_info *vi, struct receive_queue *rq, in add_recvbuf_big() argument
1882 sg_init_table(rq->sg, vi->big_packets_num_skbfrags + 2); in add_recvbuf_big()
1885 for (i = vi->big_packets_num_skbfrags + 1; i > 1; --i) { in add_recvbuf_big()
1908 sg_set_buf(&rq->sg[0], p, vi->hdr_len); in add_recvbuf_big()
1916 err = virtqueue_add_inbuf(rq->vq, rq->sg, vi->big_packets_num_skbfrags + 2, in add_recvbuf_big()
1928 struct virtnet_info *vi = rq->vq->vdev->priv; in get_mergeable_buf_len() local
1929 const size_t hdr_len = vi->hdr_len; in get_mergeable_buf_len()
1941 static int add_recvbuf_mergeable(struct virtnet_info *vi, in add_recvbuf_mergeable() argument
1945 unsigned int headroom = virtnet_get_headroom(vi); in add_recvbuf_mergeable()
1997 static bool try_fill_recv(struct virtnet_info *vi, struct receive_queue *rq, in try_fill_recv() argument
2004 if (vi->mergeable_rx_bufs) in try_fill_recv()
2005 err = add_recvbuf_mergeable(vi, rq, gfp); in try_fill_recv()
2006 else if (vi->big_packets) in try_fill_recv()
2007 err = add_recvbuf_big(vi, rq, gfp); in try_fill_recv()
2009 err = add_recvbuf_small(vi, rq, gfp); in try_fill_recv()
2028 struct virtnet_info *vi = rvq->vdev->priv; in skb_recv_done() local
2029 struct receive_queue *rq = &vi->rq[vq2rxq(rvq)]; in skb_recv_done()
2047 static void virtnet_napi_tx_enable(struct virtnet_info *vi, in virtnet_napi_tx_enable() argument
2057 if (!vi->affinity_hint_set) { in virtnet_napi_tx_enable()
2073 struct virtnet_info *vi = in refill_work() local
2078 for (i = 0; i < vi->curr_queue_pairs; i++) { in refill_work()
2079 struct receive_queue *rq = &vi->rq[i]; in refill_work()
2082 still_empty = !try_fill_recv(vi, rq, GFP_KERNEL); in refill_work()
2089 schedule_delayed_work(&vi->refill, HZ/2); in refill_work()
2096 struct virtnet_info *vi = rq->vq->vdev->priv; in virtnet_receive() local
2103 if (!vi->big_packets || vi->mergeable_rx_bufs) { in virtnet_receive()
2108 receive_buf(vi, rq, buf, len, ctx, xdp_xmit, &stats); in virtnet_receive()
2114 receive_buf(vi, rq, buf, len, NULL, xdp_xmit, &stats); in virtnet_receive()
2120 if (!try_fill_recv(vi, rq, GFP_ATOMIC)) { in virtnet_receive()
2121 spin_lock(&vi->refill_lock); in virtnet_receive()
2122 if (vi->refill_enabled) in virtnet_receive()
2123 schedule_delayed_work(&vi->refill, 0); in virtnet_receive()
2124 spin_unlock(&vi->refill_lock); in virtnet_receive()
2145 struct virtnet_info *vi = rq->vq->vdev->priv; in virtnet_poll_cleantx() local
2147 struct send_queue *sq = &vi->sq[index]; in virtnet_poll_cleantx()
2148 struct netdev_queue *txq = netdev_get_tx_queue(vi->dev, index); in virtnet_poll_cleantx()
2150 if (!sq->napi.weight || is_xdp_raw_buffer_queue(vi, index)) in virtnet_poll_cleantx()
2175 struct virtnet_info *vi = rq->vq->vdev->priv; in virtnet_poll() local
2192 sq = virtnet_xdp_get_sq(vi); in virtnet_poll()
2198 virtnet_xdp_put_sq(vi, sq); in virtnet_poll()
2204 static void virtnet_disable_queue_pair(struct virtnet_info *vi, int qp_index) in virtnet_disable_queue_pair() argument
2206 virtnet_napi_tx_disable(&vi->sq[qp_index].napi); in virtnet_disable_queue_pair()
2207 napi_disable(&vi->rq[qp_index].napi); in virtnet_disable_queue_pair()
2208 xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); in virtnet_disable_queue_pair()
2211 static int virtnet_enable_queue_pair(struct virtnet_info *vi, int qp_index) in virtnet_enable_queue_pair() argument
2213 struct net_device *dev = vi->dev; in virtnet_enable_queue_pair()
2216 err = xdp_rxq_info_reg(&vi->rq[qp_index].xdp_rxq, dev, qp_index, in virtnet_enable_queue_pair()
2217 vi->rq[qp_index].napi.napi_id); in virtnet_enable_queue_pair()
2221 err = xdp_rxq_info_reg_mem_model(&vi->rq[qp_index].xdp_rxq, in virtnet_enable_queue_pair()
2226 virtnet_napi_enable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi); in virtnet_enable_queue_pair()
2227 virtnet_napi_tx_enable(vi, vi->sq[qp_index].vq, &vi->sq[qp_index].napi); in virtnet_enable_queue_pair()
2232 xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); in virtnet_enable_queue_pair()
2238 struct virtnet_info *vi = netdev_priv(dev); in virtnet_open() local
2241 enable_delayed_refill(vi); in virtnet_open()
2243 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_open()
2244 if (i < vi->curr_queue_pairs) in virtnet_open()
2246 if (!try_fill_recv(vi, &vi->rq[i], GFP_KERNEL)) in virtnet_open()
2247 schedule_delayed_work(&vi->refill, 0); in virtnet_open()
2249 err = virtnet_enable_queue_pair(vi, i); in virtnet_open()
2257 disable_delayed_refill(vi); in virtnet_open()
2258 cancel_delayed_work_sync(&vi->refill); in virtnet_open()
2261 virtnet_disable_queue_pair(vi, i); in virtnet_open()
2268 struct virtnet_info *vi = sq->vq->vdev->priv; in virtnet_poll_tx() local
2274 if (unlikely(is_xdp_raw_buffer_queue(vi, index))) { in virtnet_poll_tx()
2280 txq = netdev_get_tx_queue(vi->dev, index); in virtnet_poll_tx()
2315 struct virtnet_info *vi = sq->vq->vdev->priv; in xmit_skb() local
2317 unsigned hdr_len = vi->hdr_len; in xmit_skb()
2320 pr_debug("%s: xmit %p %pM\n", vi->dev->name, skb, dest); in xmit_skb()
2322 can_push = vi->any_header_sg && in xmit_skb()
2333 virtio_is_little_endian(vi->vdev), false, in xmit_skb()
2337 if (vi->mergeable_rx_bufs) in xmit_skb()
2360 struct virtnet_info *vi = netdev_priv(dev); in start_xmit() local
2362 struct send_queue *sq = &vi->sq[qnum]; in start_xmit()
2402 check_sq_full_and_disable(vi, dev, sq); in start_xmit()
2415 static int virtnet_rx_resize(struct virtnet_info *vi, in virtnet_rx_resize() argument
2418 bool running = netif_running(vi->dev); in virtnet_rx_resize()
2421 qindex = rq - vi->rq; in virtnet_rx_resize()
2428 netdev_err(vi->dev, "resize rx fail: rx queue index: %d err: %d\n", qindex, err); in virtnet_rx_resize()
2430 if (!try_fill_recv(vi, rq, GFP_KERNEL)) in virtnet_rx_resize()
2431 schedule_delayed_work(&vi->refill, 0); in virtnet_rx_resize()
2438 static int virtnet_tx_resize(struct virtnet_info *vi, in virtnet_tx_resize() argument
2441 bool running = netif_running(vi->dev); in virtnet_tx_resize()
2445 qindex = sq - vi->sq; in virtnet_tx_resize()
2450 txq = netdev_get_tx_queue(vi->dev, qindex); in virtnet_tx_resize()
2461 netif_stop_subqueue(vi->dev, qindex); in virtnet_tx_resize()
2467 netdev_err(vi->dev, "resize tx fail: tx queue index: %d err: %d\n", qindex, err); in virtnet_tx_resize()
2475 virtnet_napi_tx_enable(vi, sq->vq, &sq->napi); in virtnet_tx_resize()
2484 static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd, in virtnet_send_command() argument
2492 BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)); in virtnet_send_command()
2494 vi->ctrl->status = ~0; in virtnet_send_command()
2495 vi->ctrl->hdr.class = class; in virtnet_send_command()
2496 vi->ctrl->hdr.cmd = cmd; in virtnet_send_command()
2498 sg_init_one(&hdr, &vi->ctrl->hdr, sizeof(vi->ctrl->hdr)); in virtnet_send_command()
2505 sg_init_one(&stat, &vi->ctrl->status, sizeof(vi->ctrl->status)); in virtnet_send_command()
2509 ret = virtqueue_add_sgs(vi->cvq, sgs, out_num, 1, vi, GFP_ATOMIC); in virtnet_send_command()
2511 dev_warn(&vi->vdev->dev, in virtnet_send_command()
2516 if (unlikely(!virtqueue_kick(vi->cvq))) in virtnet_send_command()
2517 return vi->ctrl->status == VIRTIO_NET_OK; in virtnet_send_command()
2522 while (!virtqueue_get_buf(vi->cvq, &tmp) && in virtnet_send_command()
2523 !virtqueue_is_broken(vi->cvq)) in virtnet_send_command()
2526 return vi->ctrl->status == VIRTIO_NET_OK; in virtnet_send_command()
2531 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_mac_address() local
2532 struct virtio_device *vdev = vi->vdev; in virtnet_set_mac_address()
2537 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STANDBY)) in virtnet_set_mac_address()
2550 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, in virtnet_set_mac_address()
2579 struct virtnet_info *vi = netdev_priv(dev); in virtnet_stats() local
2583 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_stats()
2585 struct receive_queue *rq = &vi->rq[i]; in virtnet_stats()
2586 struct send_queue *sq = &vi->sq[i]; in virtnet_stats()
2616 static void virtnet_ack_link_announce(struct virtnet_info *vi) in virtnet_ack_link_announce() argument
2619 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_ANNOUNCE, in virtnet_ack_link_announce()
2621 dev_warn(&vi->dev->dev, "Failed to ack link announce.\n"); in virtnet_ack_link_announce()
2625 static int _virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) in _virtnet_set_queues() argument
2628 struct net_device *dev = vi->dev; in _virtnet_set_queues()
2630 if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ)) in _virtnet_set_queues()
2633 vi->ctrl->mq.virtqueue_pairs = cpu_to_virtio16(vi->vdev, queue_pairs); in _virtnet_set_queues()
2634 sg_init_one(&sg, &vi->ctrl->mq, sizeof(vi->ctrl->mq)); in _virtnet_set_queues()
2636 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, in _virtnet_set_queues()
2642 vi->curr_queue_pairs = queue_pairs; in _virtnet_set_queues()
2645 schedule_delayed_work(&vi->refill, 0); in _virtnet_set_queues()
2651 static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs) in virtnet_set_queues() argument
2656 err = _virtnet_set_queues(vi, queue_pairs); in virtnet_set_queues()
2663 struct virtnet_info *vi = netdev_priv(dev); in virtnet_close() local
2667 disable_delayed_refill(vi); in virtnet_close()
2669 cancel_delayed_work_sync(&vi->refill); in virtnet_close()
2671 for (i = 0; i < vi->max_queue_pairs; i++) in virtnet_close()
2672 virtnet_disable_queue_pair(vi, i); in virtnet_close()
2679 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_rx_mode() local
2689 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX)) in virtnet_set_rx_mode()
2692 vi->ctrl->promisc = ((dev->flags & IFF_PROMISC) != 0); in virtnet_set_rx_mode()
2693 vi->ctrl->allmulti = ((dev->flags & IFF_ALLMULTI) != 0); in virtnet_set_rx_mode()
2695 sg_init_one(sg, &vi->ctrl->promisc, sizeof(vi->ctrl->promisc)); in virtnet_set_rx_mode()
2697 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, in virtnet_set_rx_mode()
2700 vi->ctrl->promisc ? "en" : "dis"); in virtnet_set_rx_mode()
2702 sg_init_one(sg, &vi->ctrl->allmulti, sizeof(vi->ctrl->allmulti)); in virtnet_set_rx_mode()
2704 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, in virtnet_set_rx_mode()
2707 vi->ctrl->allmulti ? "en" : "dis"); in virtnet_set_rx_mode()
2721 mac_data->entries = cpu_to_virtio32(vi->vdev, uc_count); in virtnet_set_rx_mode()
2732 mac_data->entries = cpu_to_virtio32(vi->vdev, mc_count); in virtnet_set_rx_mode()
2740 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, in virtnet_set_rx_mode()
2750 struct virtnet_info *vi = netdev_priv(dev); in virtnet_vlan_rx_add_vid() local
2753 vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid); in virtnet_vlan_rx_add_vid()
2754 sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid)); in virtnet_vlan_rx_add_vid()
2756 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN, in virtnet_vlan_rx_add_vid()
2765 struct virtnet_info *vi = netdev_priv(dev); in virtnet_vlan_rx_kill_vid() local
2768 vi->ctrl->vid = cpu_to_virtio16(vi->vdev, vid); in virtnet_vlan_rx_kill_vid()
2769 sg_init_one(&sg, &vi->ctrl->vid, sizeof(vi->ctrl->vid)); in virtnet_vlan_rx_kill_vid()
2771 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_VLAN, in virtnet_vlan_rx_kill_vid()
2777 static void virtnet_clean_affinity(struct virtnet_info *vi) in virtnet_clean_affinity() argument
2781 if (vi->affinity_hint_set) { in virtnet_clean_affinity()
2782 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_clean_affinity()
2783 virtqueue_set_affinity(vi->rq[i].vq, NULL); in virtnet_clean_affinity()
2784 virtqueue_set_affinity(vi->sq[i].vq, NULL); in virtnet_clean_affinity()
2787 vi->affinity_hint_set = false; in virtnet_clean_affinity()
2791 static void virtnet_set_affinity(struct virtnet_info *vi) in virtnet_set_affinity() argument
2801 virtnet_clean_affinity(vi); in virtnet_set_affinity()
2806 stride = max_t(int, num_cpu / vi->curr_queue_pairs, 1); in virtnet_set_affinity()
2807 stragglers = num_cpu >= vi->curr_queue_pairs ? in virtnet_set_affinity()
2808 num_cpu % vi->curr_queue_pairs : in virtnet_set_affinity()
2812 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_set_affinity()
2820 virtqueue_set_affinity(vi->rq[i].vq, mask); in virtnet_set_affinity()
2821 virtqueue_set_affinity(vi->sq[i].vq, mask); in virtnet_set_affinity()
2822 __netif_set_xps_queue(vi->dev, cpumask_bits(mask), i, XPS_CPUS); in virtnet_set_affinity()
2826 vi->affinity_hint_set = true; in virtnet_set_affinity()
2832 struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, in virtnet_cpu_online() local
2834 virtnet_set_affinity(vi); in virtnet_cpu_online()
2840 struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, in virtnet_cpu_dead() local
2842 virtnet_set_affinity(vi); in virtnet_cpu_dead()
2848 struct virtnet_info *vi = hlist_entry_safe(node, struct virtnet_info, in virtnet_cpu_down_prep() local
2851 virtnet_clean_affinity(vi); in virtnet_cpu_down_prep()
2857 static int virtnet_cpu_notif_add(struct virtnet_info *vi) in virtnet_cpu_notif_add() argument
2861 ret = cpuhp_state_add_instance_nocalls(virtionet_online, &vi->node); in virtnet_cpu_notif_add()
2865 &vi->node_dead); in virtnet_cpu_notif_add()
2868 cpuhp_state_remove_instance_nocalls(virtionet_online, &vi->node); in virtnet_cpu_notif_add()
2872 static void virtnet_cpu_notif_remove(struct virtnet_info *vi) in virtnet_cpu_notif_remove() argument
2874 cpuhp_state_remove_instance_nocalls(virtionet_online, &vi->node); in virtnet_cpu_notif_remove()
2876 &vi->node_dead); in virtnet_cpu_notif_remove()
2884 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_ringparam() local
2886 ring->rx_max_pending = vi->rq[0].vq->num_max; in virtnet_get_ringparam()
2887 ring->tx_max_pending = vi->sq[0].vq->num_max; in virtnet_get_ringparam()
2888 ring->rx_pending = virtqueue_get_vring_size(vi->rq[0].vq); in virtnet_get_ringparam()
2889 ring->tx_pending = virtqueue_get_vring_size(vi->sq[0].vq); in virtnet_get_ringparam()
2892 static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi,
2900 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_ringparam() local
2909 rx_pending = virtqueue_get_vring_size(vi->rq[0].vq); in virtnet_set_ringparam()
2910 tx_pending = virtqueue_get_vring_size(vi->sq[0].vq); in virtnet_set_ringparam()
2916 if (ring->rx_pending > vi->rq[0].vq->num_max) in virtnet_set_ringparam()
2919 if (ring->tx_pending > vi->sq[0].vq->num_max) in virtnet_set_ringparam()
2922 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_set_ringparam()
2923 rq = vi->rq + i; in virtnet_set_ringparam()
2924 sq = vi->sq + i; in virtnet_set_ringparam()
2927 err = virtnet_tx_resize(vi, sq, ring->tx_pending); in virtnet_set_ringparam()
2936 err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(i), in virtnet_set_ringparam()
2937 vi->intr_coal_tx.max_usecs, in virtnet_set_ringparam()
2938 vi->intr_coal_tx.max_packets); in virtnet_set_ringparam()
2942 vi->sq[i].intr_coal.max_usecs = vi->intr_coal_tx.max_usecs; in virtnet_set_ringparam()
2943 vi->sq[i].intr_coal.max_packets = vi->intr_coal_tx.max_packets; in virtnet_set_ringparam()
2947 err = virtnet_rx_resize(vi, rq, ring->rx_pending); in virtnet_set_ringparam()
2952 err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(i), in virtnet_set_ringparam()
2953 vi->intr_coal_rx.max_usecs, in virtnet_set_ringparam()
2954 vi->intr_coal_rx.max_packets); in virtnet_set_ringparam()
2958 vi->rq[i].intr_coal.max_usecs = vi->intr_coal_rx.max_usecs; in virtnet_set_ringparam()
2959 vi->rq[i].intr_coal.max_packets = vi->intr_coal_rx.max_packets; in virtnet_set_ringparam()
2966 static bool virtnet_commit_rss_command(struct virtnet_info *vi) in virtnet_commit_rss_command() argument
2968 struct net_device *dev = vi->dev; in virtnet_commit_rss_command()
2976 sg_set_buf(&sgs[0], &vi->ctrl->rss, sg_buf_size); in virtnet_commit_rss_command()
2978 sg_buf_size = sizeof(uint16_t) * (vi->ctrl->rss.indirection_table_mask + 1); in virtnet_commit_rss_command()
2979 sg_set_buf(&sgs[1], vi->ctrl->rss.indirection_table, sg_buf_size); in virtnet_commit_rss_command()
2983 sg_set_buf(&sgs[2], &vi->ctrl->rss.max_tx_vq, sg_buf_size); in virtnet_commit_rss_command()
2985 sg_buf_size = vi->rss_key_size; in virtnet_commit_rss_command()
2986 sg_set_buf(&sgs[3], vi->ctrl->rss.key, sg_buf_size); in virtnet_commit_rss_command()
2988 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MQ, in virtnet_commit_rss_command()
2989 vi->has_rss ? VIRTIO_NET_CTRL_MQ_RSS_CONFIG in virtnet_commit_rss_command()
2997 static void virtnet_init_default_rss(struct virtnet_info *vi) in virtnet_init_default_rss() argument
3002 vi->ctrl->rss.hash_types = vi->rss_hash_types_supported; in virtnet_init_default_rss()
3003 vi->rss_hash_types_saved = vi->rss_hash_types_supported; in virtnet_init_default_rss()
3004 vi->ctrl->rss.indirection_table_mask = vi->rss_indir_table_size in virtnet_init_default_rss()
3005 ? vi->rss_indir_table_size - 1 : 0; in virtnet_init_default_rss()
3006 vi->ctrl->rss.unclassified_queue = 0; in virtnet_init_default_rss()
3008 for (; i < vi->rss_indir_table_size; ++i) { in virtnet_init_default_rss()
3009 indir_val = ethtool_rxfh_indir_default(i, vi->curr_queue_pairs); in virtnet_init_default_rss()
3010 vi->ctrl->rss.indirection_table[i] = indir_val; in virtnet_init_default_rss()
3013 vi->ctrl->rss.max_tx_vq = vi->has_rss ? vi->curr_queue_pairs : 0; in virtnet_init_default_rss()
3014 vi->ctrl->rss.hash_key_length = vi->rss_key_size; in virtnet_init_default_rss()
3016 netdev_rss_key_fill(vi->ctrl->rss.key, vi->rss_key_size); in virtnet_init_default_rss()
3019 static void virtnet_get_hashflow(const struct virtnet_info *vi, struct ethtool_rxnfc *info) in virtnet_get_hashflow() argument
3024 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_TCPv4) { in virtnet_get_hashflow()
3027 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv4) { in virtnet_get_hashflow()
3032 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_TCPv6) { in virtnet_get_hashflow()
3035 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv6) { in virtnet_get_hashflow()
3040 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_UDPv4) { in virtnet_get_hashflow()
3043 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv4) { in virtnet_get_hashflow()
3048 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_UDPv6) { in virtnet_get_hashflow()
3051 } else if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv6) { in virtnet_get_hashflow()
3056 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv4) in virtnet_get_hashflow()
3061 if (vi->rss_hash_types_saved & VIRTIO_NET_RSS_HASH_TYPE_IPv6) in virtnet_get_hashflow()
3071 static bool virtnet_set_hashflow(struct virtnet_info *vi, struct ethtool_rxnfc *info) in virtnet_set_hashflow() argument
3073 u32 new_hashtypes = vi->rss_hash_types_saved; in virtnet_set_hashflow()
3122 if (new_hashtypes != (new_hashtypes & vi->rss_hash_types_supported)) in virtnet_set_hashflow()
3125 if (new_hashtypes != vi->rss_hash_types_saved) { in virtnet_set_hashflow()
3126 vi->rss_hash_types_saved = new_hashtypes; in virtnet_set_hashflow()
3127 vi->ctrl->rss.hash_types = vi->rss_hash_types_saved; in virtnet_set_hashflow()
3128 if (vi->dev->features & NETIF_F_RXHASH) in virtnet_set_hashflow()
3129 return virtnet_commit_rss_command(vi); in virtnet_set_hashflow()
3138 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_drvinfo() local
3139 struct virtio_device *vdev = vi->vdev; in virtnet_get_drvinfo()
3151 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_channels() local
3161 if (queue_pairs > vi->max_queue_pairs || queue_pairs == 0) in virtnet_set_channels()
3168 if (vi->rq[0].xdp_prog) in virtnet_set_channels()
3172 err = _virtnet_set_queues(vi, queue_pairs); in virtnet_set_channels()
3177 virtnet_set_affinity(vi); in virtnet_set_channels()
3188 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_strings() local
3194 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_strings()
3200 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_strings()
3211 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_sset_count() local
3215 return vi->curr_queue_pairs * (VIRTNET_RQ_STATS_LEN + in virtnet_get_sset_count()
3225 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_ethtool_stats() local
3231 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_ethtool_stats()
3232 struct receive_queue *rq = &vi->rq[i]; in virtnet_get_ethtool_stats()
3246 for (i = 0; i < vi->curr_queue_pairs; i++) { in virtnet_get_ethtool_stats()
3247 struct send_queue *sq = &vi->sq[i]; in virtnet_get_ethtool_stats()
3265 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_channels() local
3267 channels->combined_count = vi->curr_queue_pairs; in virtnet_get_channels()
3268 channels->max_combined = vi->max_queue_pairs; in virtnet_get_channels()
3278 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_link_ksettings() local
3281 &vi->speed, &vi->duplex); in virtnet_set_link_ksettings()
3287 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_link_ksettings() local
3289 cmd->base.speed = vi->speed; in virtnet_get_link_ksettings()
3290 cmd->base.duplex = vi->duplex; in virtnet_get_link_ksettings()
3296 static int virtnet_send_notf_coal_cmds(struct virtnet_info *vi, in virtnet_send_notf_coal_cmds() argument
3302 vi->ctrl->coal_tx.tx_usecs = cpu_to_le32(ec->tx_coalesce_usecs); in virtnet_send_notf_coal_cmds()
3303 vi->ctrl->coal_tx.tx_max_packets = cpu_to_le32(ec->tx_max_coalesced_frames); in virtnet_send_notf_coal_cmds()
3304 sg_init_one(&sgs_tx, &vi->ctrl->coal_tx, sizeof(vi->ctrl->coal_tx)); in virtnet_send_notf_coal_cmds()
3306 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, in virtnet_send_notf_coal_cmds()
3312 vi->intr_coal_tx.max_usecs = ec->tx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3313 vi->intr_coal_tx.max_packets = ec->tx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3314 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_send_notf_coal_cmds()
3315 vi->sq[i].intr_coal.max_usecs = ec->tx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3316 vi->sq[i].intr_coal.max_packets = ec->tx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3319 vi->ctrl->coal_rx.rx_usecs = cpu_to_le32(ec->rx_coalesce_usecs); in virtnet_send_notf_coal_cmds()
3320 vi->ctrl->coal_rx.rx_max_packets = cpu_to_le32(ec->rx_max_coalesced_frames); in virtnet_send_notf_coal_cmds()
3321 sg_init_one(&sgs_rx, &vi->ctrl->coal_rx, sizeof(vi->ctrl->coal_rx)); in virtnet_send_notf_coal_cmds()
3323 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, in virtnet_send_notf_coal_cmds()
3329 vi->intr_coal_rx.max_usecs = ec->rx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3330 vi->intr_coal_rx.max_packets = ec->rx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3331 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_send_notf_coal_cmds()
3332 vi->rq[i].intr_coal.max_usecs = ec->rx_coalesce_usecs; in virtnet_send_notf_coal_cmds()
3333 vi->rq[i].intr_coal.max_packets = ec->rx_max_coalesced_frames; in virtnet_send_notf_coal_cmds()
3339 static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi, in virtnet_send_ctrl_coal_vq_cmd() argument
3344 vi->ctrl->coal_vq.vqn = cpu_to_le16(vqn); in virtnet_send_ctrl_coal_vq_cmd()
3345 vi->ctrl->coal_vq.coal.max_usecs = cpu_to_le32(max_usecs); in virtnet_send_ctrl_coal_vq_cmd()
3346 vi->ctrl->coal_vq.coal.max_packets = cpu_to_le32(max_packets); in virtnet_send_ctrl_coal_vq_cmd()
3347 sg_init_one(&sgs, &vi->ctrl->coal_vq, sizeof(vi->ctrl->coal_vq)); in virtnet_send_ctrl_coal_vq_cmd()
3349 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, in virtnet_send_ctrl_coal_vq_cmd()
3357 static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, in virtnet_send_notf_coal_vq_cmds() argument
3363 err = virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue), in virtnet_send_notf_coal_vq_cmds()
3369 vi->rq[queue].intr_coal.max_usecs = ec->rx_coalesce_usecs; in virtnet_send_notf_coal_vq_cmds()
3370 vi->rq[queue].intr_coal.max_packets = ec->rx_max_coalesced_frames; in virtnet_send_notf_coal_vq_cmds()
3372 err = virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue), in virtnet_send_notf_coal_vq_cmds()
3378 vi->sq[queue].intr_coal.max_usecs = ec->tx_coalesce_usecs; in virtnet_send_notf_coal_vq_cmds()
3379 vi->sq[queue].intr_coal.max_packets = ec->tx_max_coalesced_frames; in virtnet_send_notf_coal_vq_cmds()
3416 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_coalesce() local
3422 for (queue_number = 0; queue_number < vi->max_queue_pairs; queue_number++) { in virtnet_set_coalesce()
3424 vi->sq[queue_number].napi.weight, in virtnet_set_coalesce()
3437 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) in virtnet_set_coalesce()
3438 ret = virtnet_send_notf_coal_cmds(vi, ec); in virtnet_set_coalesce()
3446 for (; queue_number < vi->max_queue_pairs; queue_number++) in virtnet_set_coalesce()
3447 vi->sq[queue_number].napi.weight = napi_weight; in virtnet_set_coalesce()
3458 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_coalesce() local
3460 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { in virtnet_get_coalesce()
3461 ec->rx_coalesce_usecs = vi->intr_coal_rx.max_usecs; in virtnet_get_coalesce()
3462 ec->tx_coalesce_usecs = vi->intr_coal_tx.max_usecs; in virtnet_get_coalesce()
3463 ec->tx_max_coalesced_frames = vi->intr_coal_tx.max_packets; in virtnet_get_coalesce()
3464 ec->rx_max_coalesced_frames = vi->intr_coal_rx.max_packets; in virtnet_get_coalesce()
3468 if (vi->sq[0].napi.weight) in virtnet_get_coalesce()
3479 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_per_queue_coalesce() local
3483 if (queue >= vi->max_queue_pairs) in virtnet_set_per_queue_coalesce()
3489 vi->sq[queue].napi.weight, in virtnet_set_per_queue_coalesce()
3494 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) in virtnet_set_per_queue_coalesce()
3495 ret = virtnet_send_notf_coal_vq_cmds(vi, ec, queue); in virtnet_set_per_queue_coalesce()
3503 vi->sq[queue].napi.weight = napi_weight; in virtnet_set_per_queue_coalesce()
3512 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_per_queue_coalesce() local
3514 if (queue >= vi->max_queue_pairs) in virtnet_get_per_queue_coalesce()
3517 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_COAL)) { in virtnet_get_per_queue_coalesce()
3518 ec->rx_coalesce_usecs = vi->rq[queue].intr_coal.max_usecs; in virtnet_get_per_queue_coalesce()
3519 ec->tx_coalesce_usecs = vi->sq[queue].intr_coal.max_usecs; in virtnet_get_per_queue_coalesce()
3520 ec->tx_max_coalesced_frames = vi->sq[queue].intr_coal.max_packets; in virtnet_get_per_queue_coalesce()
3521 ec->rx_max_coalesced_frames = vi->rq[queue].intr_coal.max_packets; in virtnet_get_per_queue_coalesce()
3525 if (vi->sq[queue].napi.weight) in virtnet_get_per_queue_coalesce()
3534 struct virtnet_info *vi = netdev_priv(dev); in virtnet_init_settings() local
3536 vi->speed = SPEED_UNKNOWN; in virtnet_init_settings()
3537 vi->duplex = DUPLEX_UNKNOWN; in virtnet_init_settings()
3540 static void virtnet_update_settings(struct virtnet_info *vi) in virtnet_update_settings() argument
3545 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_SPEED_DUPLEX)) in virtnet_update_settings()
3548 virtio_cread_le(vi->vdev, struct virtio_net_config, speed, &speed); in virtnet_update_settings()
3551 vi->speed = speed; in virtnet_update_settings()
3553 virtio_cread_le(vi->vdev, struct virtio_net_config, duplex, &duplex); in virtnet_update_settings()
3556 vi->duplex = duplex; in virtnet_update_settings()
3571 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_rxfh() local
3575 for (i = 0; i < vi->rss_indir_table_size; ++i) in virtnet_get_rxfh()
3576 indir[i] = vi->ctrl->rss.indirection_table[i]; in virtnet_get_rxfh()
3580 memcpy(key, vi->ctrl->rss.key, vi->rss_key_size); in virtnet_get_rxfh()
3590 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_rxfh() local
3598 if (!vi->has_rss) in virtnet_set_rxfh()
3601 for (i = 0; i < vi->rss_indir_table_size; ++i) in virtnet_set_rxfh()
3602 vi->ctrl->rss.indirection_table[i] = indir[i]; in virtnet_set_rxfh()
3610 if (!vi->has_rss && !vi->has_rss_hash_report) in virtnet_set_rxfh()
3613 memcpy(vi->ctrl->rss.key, key, vi->rss_key_size); in virtnet_set_rxfh()
3618 virtnet_commit_rss_command(vi); in virtnet_set_rxfh()
3625 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_rxnfc() local
3630 info->data = vi->curr_queue_pairs; in virtnet_get_rxnfc()
3633 virtnet_get_hashflow(vi, info); in virtnet_get_rxnfc()
3644 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_rxnfc() local
3649 if (!virtnet_set_hashflow(vi, info)) in virtnet_set_rxnfc()
3689 struct virtnet_info *vi = vdev->priv; in virtnet_freeze_down() local
3692 flush_work(&vi->config_work); in virtnet_freeze_down()
3694 netif_tx_lock_bh(vi->dev); in virtnet_freeze_down()
3695 netif_device_detach(vi->dev); in virtnet_freeze_down()
3696 netif_tx_unlock_bh(vi->dev); in virtnet_freeze_down()
3697 if (netif_running(vi->dev)) in virtnet_freeze_down()
3698 virtnet_close(vi->dev); in virtnet_freeze_down()
3701 static int init_vqs(struct virtnet_info *vi);
3705 struct virtnet_info *vi = vdev->priv; in virtnet_restore_up() local
3708 err = init_vqs(vi); in virtnet_restore_up()
3714 enable_delayed_refill(vi); in virtnet_restore_up()
3716 if (netif_running(vi->dev)) { in virtnet_restore_up()
3717 err = virtnet_open(vi->dev); in virtnet_restore_up()
3722 netif_tx_lock_bh(vi->dev); in virtnet_restore_up()
3723 netif_device_attach(vi->dev); in virtnet_restore_up()
3724 netif_tx_unlock_bh(vi->dev); in virtnet_restore_up()
3728 static int virtnet_set_guest_offloads(struct virtnet_info *vi, u64 offloads) in virtnet_set_guest_offloads() argument
3731 vi->ctrl->offloads = cpu_to_virtio64(vi->vdev, offloads); in virtnet_set_guest_offloads()
3733 sg_init_one(&sg, &vi->ctrl->offloads, sizeof(vi->ctrl->offloads)); in virtnet_set_guest_offloads()
3735 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_GUEST_OFFLOADS, in virtnet_set_guest_offloads()
3737 dev_warn(&vi->dev->dev, "Fail to set guest offload.\n"); in virtnet_set_guest_offloads()
3744 static int virtnet_clear_guest_offloads(struct virtnet_info *vi) in virtnet_clear_guest_offloads() argument
3748 if (!vi->guest_offloads) in virtnet_clear_guest_offloads()
3751 return virtnet_set_guest_offloads(vi, offloads); in virtnet_clear_guest_offloads()
3754 static int virtnet_restore_guest_offloads(struct virtnet_info *vi) in virtnet_restore_guest_offloads() argument
3756 u64 offloads = vi->guest_offloads; in virtnet_restore_guest_offloads()
3758 if (!vi->guest_offloads) in virtnet_restore_guest_offloads()
3761 return virtnet_set_guest_offloads(vi, offloads); in virtnet_restore_guest_offloads()
3770 struct virtnet_info *vi = netdev_priv(dev); in virtnet_xdp_set() local
3775 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) in virtnet_xdp_set()
3776 && (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO4) || in virtnet_xdp_set()
3777 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO6) || in virtnet_xdp_set()
3778 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_ECN) || in virtnet_xdp_set()
3779 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO) || in virtnet_xdp_set()
3780 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_CSUM) || in virtnet_xdp_set()
3781 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO4) || in virtnet_xdp_set()
3782 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO6))) { in virtnet_xdp_set()
3787 if (vi->mergeable_rx_bufs && !vi->any_header_sg) { in virtnet_xdp_set()
3798 curr_qp = vi->curr_queue_pairs - vi->xdp_queue_pairs; in virtnet_xdp_set()
3803 if (curr_qp + xdp_qp > vi->max_queue_pairs) { in virtnet_xdp_set()
3805 curr_qp + xdp_qp, vi->max_queue_pairs); in virtnet_xdp_set()
3809 old_prog = rtnl_dereference(vi->rq[0].xdp_prog); in virtnet_xdp_set()
3814 bpf_prog_add(prog, vi->max_queue_pairs - 1); in virtnet_xdp_set()
3818 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3819 napi_disable(&vi->rq[i].napi); in virtnet_xdp_set()
3820 virtnet_napi_tx_disable(&vi->sq[i].napi); in virtnet_xdp_set()
3825 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3826 rcu_assign_pointer(vi->rq[i].xdp_prog, prog); in virtnet_xdp_set()
3828 virtnet_restore_guest_offloads(vi); in virtnet_xdp_set()
3833 err = _virtnet_set_queues(vi, curr_qp + xdp_qp); in virtnet_xdp_set()
3837 vi->xdp_queue_pairs = xdp_qp; in virtnet_xdp_set()
3840 vi->xdp_enabled = true; in virtnet_xdp_set()
3841 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3842 rcu_assign_pointer(vi->rq[i].xdp_prog, prog); in virtnet_xdp_set()
3844 virtnet_clear_guest_offloads(vi); in virtnet_xdp_set()
3850 vi->xdp_enabled = false; in virtnet_xdp_set()
3853 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3857 virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); in virtnet_xdp_set()
3858 virtnet_napi_tx_enable(vi, vi->sq[i].vq, in virtnet_xdp_set()
3859 &vi->sq[i].napi); in virtnet_xdp_set()
3867 virtnet_clear_guest_offloads(vi); in virtnet_xdp_set()
3868 for (i = 0; i < vi->max_queue_pairs; i++) in virtnet_xdp_set()
3869 rcu_assign_pointer(vi->rq[i].xdp_prog, old_prog); in virtnet_xdp_set()
3873 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_xdp_set()
3874 virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi); in virtnet_xdp_set()
3875 virtnet_napi_tx_enable(vi, vi->sq[i].vq, in virtnet_xdp_set()
3876 &vi->sq[i].napi); in virtnet_xdp_set()
3880 bpf_prog_sub(prog, vi->max_queue_pairs - 1); in virtnet_xdp_set()
3897 struct virtnet_info *vi = netdev_priv(dev); in virtnet_get_phys_port_name() local
3900 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_STANDBY)) in virtnet_get_phys_port_name()
3913 struct virtnet_info *vi = netdev_priv(dev); in virtnet_set_features() local
3918 if (vi->xdp_enabled) in virtnet_set_features()
3922 offloads = vi->guest_offloads_capable; in virtnet_set_features()
3924 offloads = vi->guest_offloads_capable & in virtnet_set_features()
3927 err = virtnet_set_guest_offloads(vi, offloads); in virtnet_set_features()
3930 vi->guest_offloads = offloads; in virtnet_set_features()
3935 vi->ctrl->rss.hash_types = vi->rss_hash_types_saved; in virtnet_set_features()
3937 vi->ctrl->rss.hash_types = VIRTIO_NET_HASH_REPORT_NONE; in virtnet_set_features()
3939 if (!virtnet_commit_rss_command(vi)) in virtnet_set_features()
3981 struct virtnet_info *vi = in virtnet_config_changed_work() local
3985 if (virtio_cread_feature(vi->vdev, VIRTIO_NET_F_STATUS, in virtnet_config_changed_work()
3990 netdev_notify_peers(vi->dev); in virtnet_config_changed_work()
3991 virtnet_ack_link_announce(vi); in virtnet_config_changed_work()
3997 if (vi->status == v) in virtnet_config_changed_work()
4000 vi->status = v; in virtnet_config_changed_work()
4002 if (vi->status & VIRTIO_NET_S_LINK_UP) { in virtnet_config_changed_work()
4003 virtnet_update_settings(vi); in virtnet_config_changed_work()
4004 netif_carrier_on(vi->dev); in virtnet_config_changed_work()
4005 netif_tx_wake_all_queues(vi->dev); in virtnet_config_changed_work()
4007 netif_carrier_off(vi->dev); in virtnet_config_changed_work()
4008 netif_tx_stop_all_queues(vi->dev); in virtnet_config_changed_work()
4014 struct virtnet_info *vi = vdev->priv; in virtnet_config_changed() local
4016 schedule_work(&vi->config_work); in virtnet_config_changed()
4019 static void virtnet_free_queues(struct virtnet_info *vi) in virtnet_free_queues() argument
4023 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_free_queues()
4024 __netif_napi_del(&vi->rq[i].napi); in virtnet_free_queues()
4025 __netif_napi_del(&vi->sq[i].napi); in virtnet_free_queues()
4033 kfree(vi->rq); in virtnet_free_queues()
4034 kfree(vi->sq); in virtnet_free_queues()
4035 kfree(vi->ctrl); in virtnet_free_queues()
4038 static void _free_receive_bufs(struct virtnet_info *vi) in _free_receive_bufs() argument
4043 for (i = 0; i < vi->max_queue_pairs; i++) { in _free_receive_bufs()
4044 while (vi->rq[i].pages) in _free_receive_bufs()
4045 __free_pages(get_a_page(&vi->rq[i], GFP_KERNEL), 0); in _free_receive_bufs()
4047 old_prog = rtnl_dereference(vi->rq[i].xdp_prog); in _free_receive_bufs()
4048 RCU_INIT_POINTER(vi->rq[i].xdp_prog, NULL); in _free_receive_bufs()
4054 static void free_receive_bufs(struct virtnet_info *vi) in free_receive_bufs() argument
4057 _free_receive_bufs(vi); in free_receive_bufs()
4061 static void free_receive_page_frags(struct virtnet_info *vi) in free_receive_page_frags() argument
4064 for (i = 0; i < vi->max_queue_pairs; i++) in free_receive_page_frags()
4065 if (vi->rq[i].alloc_frag.page) { in free_receive_page_frags()
4066 if (vi->rq[i].do_dma && vi->rq[i].last_dma) in free_receive_page_frags()
4067 virtnet_rq_unmap(&vi->rq[i], vi->rq[i].last_dma, 0); in free_receive_page_frags()
4068 put_page(vi->rq[i].alloc_frag.page); in free_receive_page_frags()
4080 static void free_unused_bufs(struct virtnet_info *vi) in free_unused_bufs() argument
4085 for (i = 0; i < vi->max_queue_pairs; i++) { in free_unused_bufs()
4086 struct virtqueue *vq = vi->sq[i].vq; in free_unused_bufs()
4092 for (i = 0; i < vi->max_queue_pairs; i++) { in free_unused_bufs()
4093 struct virtqueue *vq = vi->rq[i].vq; in free_unused_bufs()
4101 static void virtnet_del_vqs(struct virtnet_info *vi) in virtnet_del_vqs() argument
4103 struct virtio_device *vdev = vi->vdev; in virtnet_del_vqs()
4105 virtnet_clean_affinity(vi); in virtnet_del_vqs()
4109 virtnet_free_queues(vi); in virtnet_del_vqs()
4116 static unsigned int mergeable_min_buf_len(struct virtnet_info *vi, struct virtqueue *vq) in mergeable_min_buf_len() argument
4118 const unsigned int hdr_len = vi->hdr_len; in mergeable_min_buf_len()
4120 unsigned int packet_len = vi->big_packets ? IP_MAX_MTU : vi->dev->max_mtu; in mergeable_min_buf_len()
4128 static int virtnet_find_vqs(struct virtnet_info *vi) in virtnet_find_vqs() argument
4142 total_vqs = vi->max_queue_pairs * 2 + in virtnet_find_vqs()
4143 virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ); in virtnet_find_vqs()
4155 if (!vi->big_packets || vi->mergeable_rx_bufs) { in virtnet_find_vqs()
4164 if (vi->has_cvq) { in virtnet_find_vqs()
4170 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_find_vqs()
4173 sprintf(vi->rq[i].name, "input.%u", i); in virtnet_find_vqs()
4174 sprintf(vi->sq[i].name, "output.%u", i); in virtnet_find_vqs()
4175 names[rxq2vq(i)] = vi->rq[i].name; in virtnet_find_vqs()
4176 names[txq2vq(i)] = vi->sq[i].name; in virtnet_find_vqs()
4181 ret = virtio_find_vqs_ctx(vi->vdev, total_vqs, vqs, callbacks, in virtnet_find_vqs()
4186 if (vi->has_cvq) { in virtnet_find_vqs()
4187 vi->cvq = vqs[total_vqs - 1]; in virtnet_find_vqs()
4188 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN)) in virtnet_find_vqs()
4189 vi->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; in virtnet_find_vqs()
4192 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_find_vqs()
4193 vi->rq[i].vq = vqs[rxq2vq(i)]; in virtnet_find_vqs()
4194 vi->rq[i].min_buf_len = mergeable_min_buf_len(vi, vi->rq[i].vq); in virtnet_find_vqs()
4195 vi->sq[i].vq = vqs[txq2vq(i)]; in virtnet_find_vqs()
4213 static int virtnet_alloc_queues(struct virtnet_info *vi) in virtnet_alloc_queues() argument
4217 if (vi->has_cvq) { in virtnet_alloc_queues()
4218 vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL); in virtnet_alloc_queues()
4219 if (!vi->ctrl) in virtnet_alloc_queues()
4222 vi->ctrl = NULL; in virtnet_alloc_queues()
4224 vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL); in virtnet_alloc_queues()
4225 if (!vi->sq) in virtnet_alloc_queues()
4227 vi->rq = kcalloc(vi->max_queue_pairs, sizeof(*vi->rq), GFP_KERNEL); in virtnet_alloc_queues()
4228 if (!vi->rq) in virtnet_alloc_queues()
4231 INIT_DELAYED_WORK(&vi->refill, refill_work); in virtnet_alloc_queues()
4232 for (i = 0; i < vi->max_queue_pairs; i++) { in virtnet_alloc_queues()
4233 vi->rq[i].pages = NULL; in virtnet_alloc_queues()
4234 netif_napi_add_weight(vi->dev, &vi->rq[i].napi, virtnet_poll, in virtnet_alloc_queues()
4236 netif_napi_add_tx_weight(vi->dev, &vi->sq[i].napi, in virtnet_alloc_queues()
4240 sg_init_table(vi->rq[i].sg, ARRAY_SIZE(vi->rq[i].sg)); in virtnet_alloc_queues()
4241 ewma_pkt_len_init(&vi->rq[i].mrg_avg_pkt_len); in virtnet_alloc_queues()
4242 sg_init_table(vi->sq[i].sg, ARRAY_SIZE(vi->sq[i].sg)); in virtnet_alloc_queues()
4244 u64_stats_init(&vi->rq[i].stats.syncp); in virtnet_alloc_queues()
4245 u64_stats_init(&vi->sq[i].stats.syncp); in virtnet_alloc_queues()
4251 kfree(vi->sq); in virtnet_alloc_queues()
4253 kfree(vi->ctrl); in virtnet_alloc_queues()
4258 static int init_vqs(struct virtnet_info *vi) in init_vqs() argument
4263 ret = virtnet_alloc_queues(vi); in init_vqs()
4267 ret = virtnet_find_vqs(vi); in init_vqs()
4271 virtnet_rq_set_premapped(vi); in init_vqs()
4274 virtnet_set_affinity(vi); in init_vqs()
4280 virtnet_free_queues(vi); in init_vqs()
4289 struct virtnet_info *vi = netdev_priv(queue->dev); in mergeable_rx_buffer_size_show() local
4291 unsigned int headroom = virtnet_get_headroom(vi); in mergeable_rx_buffer_size_show()
4295 BUG_ON(queue_index >= vi->max_queue_pairs); in mergeable_rx_buffer_size_show()
4296 avg = &vi->rq[queue_index].mrg_avg_pkt_len; in mergeable_rx_buffer_size_show()
4298 get_mergeable_buf_len(&vi->rq[queue_index], avg, in mergeable_rx_buffer_size_show()
4389 static bool virtnet_check_guest_gso(const struct virtnet_info *vi) in virtnet_check_guest_gso() argument
4391 return virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO4) || in virtnet_check_guest_gso()
4392 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO6) || in virtnet_check_guest_gso()
4393 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_ECN) || in virtnet_check_guest_gso()
4394 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO) || in virtnet_check_guest_gso()
4395 (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO4) && in virtnet_check_guest_gso()
4396 virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_USO6)); in virtnet_check_guest_gso()
4399 static void virtnet_set_big_packets(struct virtnet_info *vi, const int mtu) in virtnet_set_big_packets() argument
4401 bool guest_gso = virtnet_check_guest_gso(vi); in virtnet_set_big_packets()
4408 vi->big_packets = true; in virtnet_set_big_packets()
4409 vi->big_packets_num_skbfrags = guest_gso ? MAX_SKB_FRAGS : DIV_ROUND_UP(mtu, PAGE_SIZE); in virtnet_set_big_packets()
4417 struct virtnet_info *vi; in virtnet_probe() local
4512 vi = netdev_priv(dev); in virtnet_probe()
4513 vi->dev = dev; in virtnet_probe()
4514 vi->vdev = vdev; in virtnet_probe()
4515 vdev->priv = vi; in virtnet_probe()
4517 INIT_WORK(&vi->config_work, virtnet_config_changed_work); in virtnet_probe()
4518 spin_lock_init(&vi->refill_lock); in virtnet_probe()
4521 vi->mergeable_rx_bufs = true; in virtnet_probe()
4525 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { in virtnet_probe()
4526 vi->intr_coal_rx.max_usecs = 0; in virtnet_probe()
4527 vi->intr_coal_tx.max_usecs = 0; in virtnet_probe()
4528 vi->intr_coal_tx.max_packets = 0; in virtnet_probe()
4529 vi->intr_coal_rx.max_packets = 0; in virtnet_probe()
4533 vi->has_rss_hash_report = true; in virtnet_probe()
4536 vi->has_rss = true; in virtnet_probe()
4538 vi->rss_indir_table_size = in virtnet_probe()
4543 if (vi->has_rss || vi->has_rss_hash_report) { in virtnet_probe()
4544 vi->rss_key_size = in virtnet_probe()
4547 vi->rss_hash_types_supported = in virtnet_probe()
4549 vi->rss_hash_types_supported &= in virtnet_probe()
4557 if (vi->has_rss_hash_report) in virtnet_probe()
4558 vi->hdr_len = sizeof(struct virtio_net_hdr_v1_hash); in virtnet_probe()
4561 vi->hdr_len = sizeof(struct virtio_net_hdr_mrg_rxbuf); in virtnet_probe()
4563 vi->hdr_len = sizeof(struct virtio_net_hdr); in virtnet_probe()
4567 vi->any_header_sg = true; in virtnet_probe()
4570 vi->has_cvq = true; in virtnet_probe()
4591 virtnet_set_big_packets(vi, mtu); in virtnet_probe()
4593 if (vi->any_header_sg) in virtnet_probe()
4594 dev->needed_headroom = vi->hdr_len; in virtnet_probe()
4598 vi->curr_queue_pairs = max_queue_pairs; in virtnet_probe()
4600 vi->curr_queue_pairs = num_online_cpus(); in virtnet_probe()
4601 vi->max_queue_pairs = max_queue_pairs; in virtnet_probe()
4604 err = init_vqs(vi); in virtnet_probe()
4609 if (vi->mergeable_rx_bufs) in virtnet_probe()
4612 netif_set_real_num_tx_queues(dev, vi->curr_queue_pairs); in virtnet_probe()
4613 netif_set_real_num_rx_queues(dev, vi->curr_queue_pairs); in virtnet_probe()
4618 vi->failover = net_failover_create(vi->dev); in virtnet_probe()
4619 if (IS_ERR(vi->failover)) { in virtnet_probe()
4620 err = PTR_ERR(vi->failover); in virtnet_probe()
4625 if (vi->has_rss || vi->has_rss_hash_report) in virtnet_probe()
4626 virtnet_init_default_rss(vi); in virtnet_probe()
4640 _virtnet_set_queues(vi, vi->curr_queue_pairs); in virtnet_probe()
4647 virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_MAC_ADDR)) { in virtnet_probe()
4651 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_MAC, in virtnet_probe()
4662 err = virtnet_cpu_notif_add(vi); in virtnet_probe()
4671 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) { in virtnet_probe()
4672 schedule_work(&vi->config_work); in virtnet_probe()
4674 vi->status = VIRTIO_NET_S_LINK_UP; in virtnet_probe()
4675 virtnet_update_settings(vi); in virtnet_probe()
4680 if (virtio_has_feature(vi->vdev, guest_offloads[i])) in virtnet_probe()
4681 set_bit(guest_offloads[i], &vi->guest_offloads); in virtnet_probe()
4682 vi->guest_offloads_capable = vi->guest_offloads; in virtnet_probe()
4692 net_failover_destroy(vi->failover); in virtnet_probe()
4695 cancel_delayed_work_sync(&vi->refill); in virtnet_probe()
4696 free_receive_page_frags(vi); in virtnet_probe()
4697 virtnet_del_vqs(vi); in virtnet_probe()
4703 static void remove_vq_common(struct virtnet_info *vi) in remove_vq_common() argument
4705 virtio_reset_device(vi->vdev); in remove_vq_common()
4708 free_unused_bufs(vi); in remove_vq_common()
4710 free_receive_bufs(vi); in remove_vq_common()
4712 free_receive_page_frags(vi); in remove_vq_common()
4714 virtnet_del_vqs(vi); in remove_vq_common()
4719 struct virtnet_info *vi = vdev->priv; in virtnet_remove() local
4721 virtnet_cpu_notif_remove(vi); in virtnet_remove()
4724 flush_work(&vi->config_work); in virtnet_remove()
4726 unregister_netdev(vi->dev); in virtnet_remove()
4728 net_failover_destroy(vi->failover); in virtnet_remove()
4730 remove_vq_common(vi); in virtnet_remove()
4732 free_netdev(vi->dev); in virtnet_remove()
4737 struct virtnet_info *vi = vdev->priv; in virtnet_freeze() local
4739 virtnet_cpu_notif_remove(vi); in virtnet_freeze()
4741 remove_vq_common(vi); in virtnet_freeze()
4748 struct virtnet_info *vi = vdev->priv; in virtnet_restore() local
4754 virtnet_set_queues(vi, vi->curr_queue_pairs); in virtnet_restore()
4756 err = virtnet_cpu_notif_add(vi); in virtnet_restore()
4759 remove_vq_common(vi); in virtnet_restore()