| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2009, Microsoft Corporation. |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 5 | | - * under the terms and conditions of the GNU General Public License, |
|---|
| 6 | | - * version 2, as published by the Free Software Foundation. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
|---|
| 9 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 10 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 11 | | - * more details. |
|---|
| 12 | | - * |
|---|
| 13 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 14 | | - * this program; if not, see <http://www.gnu.org/licenses/>. |
|---|
| 15 | 4 | * |
|---|
| 16 | 5 | * Authors: |
|---|
| 17 | 6 | * Haiyang Zhang <haiyangz@microsoft.com> |
|---|
| .. | .. |
|---|
| 36 | 25 | #include <linux/slab.h> |
|---|
| 37 | 26 | #include <linux/rtnetlink.h> |
|---|
| 38 | 27 | #include <linux/netpoll.h> |
|---|
| 28 | +#include <linux/bpf.h> |
|---|
| 39 | 29 | |
|---|
| 40 | 30 | #include <net/arp.h> |
|---|
| 41 | 31 | #include <net/route.h> |
|---|
| .. | .. |
|---|
| 146 | 136 | * slave as up. If open fails, then slave will be |
|---|
| 147 | 137 | * still be offline (and not used). |
|---|
| 148 | 138 | */ |
|---|
| 149 | | - ret = dev_open(vf_netdev); |
|---|
| 139 | + ret = dev_open(vf_netdev, NULL); |
|---|
| 150 | 140 | if (ret) |
|---|
| 151 | 141 | netdev_warn(net, |
|---|
| 152 | 142 | "unable to open slave: %s: %d\n", |
|---|
| .. | .. |
|---|
| 246 | 236 | |
|---|
| 247 | 237 | ppi->size = ppi_size; |
|---|
| 248 | 238 | ppi->type = pkt_type; |
|---|
| 239 | + ppi->internal = 0; |
|---|
| 249 | 240 | ppi->ppi_offset = sizeof(struct rndis_per_packet_info); |
|---|
| 250 | 241 | |
|---|
| 251 | 242 | rndis_pkt->per_pkt_info_len += ppi_size; |
|---|
| .. | .. |
|---|
| 327 | 318 | * If a valid queue has already been assigned, then use that. |
|---|
| 328 | 319 | * Otherwise compute tx queue based on hash and the send table. |
|---|
| 329 | 320 | * |
|---|
| 330 | | - * This is basically similar to default (__netdev_pick_tx) with the added step |
|---|
| 321 | + * This is basically similar to default (netdev_pick_tx) with the added step |
|---|
| 331 | 322 | * of using the host send_table when no other queue has been assigned. |
|---|
| 332 | 323 | * |
|---|
| 333 | 324 | * TODO support XPS - but get_xps_queue not exported |
|---|
| .. | .. |
|---|
| 350 | 341 | } |
|---|
| 351 | 342 | |
|---|
| 352 | 343 | static u16 netvsc_select_queue(struct net_device *ndev, struct sk_buff *skb, |
|---|
| 353 | | - struct net_device *sb_dev, |
|---|
| 354 | | - select_queue_fallback_t fallback) |
|---|
| 344 | + struct net_device *sb_dev) |
|---|
| 355 | 345 | { |
|---|
| 356 | 346 | struct net_device_context *ndc = netdev_priv(ndev); |
|---|
| 357 | 347 | struct net_device *vf_netdev; |
|---|
| .. | .. |
|---|
| 363 | 353 | const struct net_device_ops *vf_ops = vf_netdev->netdev_ops; |
|---|
| 364 | 354 | |
|---|
| 365 | 355 | if (vf_ops->ndo_select_queue) |
|---|
| 366 | | - txq = vf_ops->ndo_select_queue(vf_netdev, skb, |
|---|
| 367 | | - sb_dev, fallback); |
|---|
| 356 | + txq = vf_ops->ndo_select_queue(vf_netdev, skb, sb_dev); |
|---|
| 368 | 357 | else |
|---|
| 369 | | - txq = fallback(vf_netdev, skb, NULL); |
|---|
| 358 | + txq = netdev_pick_tx(vf_netdev, skb, NULL); |
|---|
| 370 | 359 | |
|---|
| 371 | 360 | /* Record the queue selected by VF so that it can be |
|---|
| 372 | 361 | * used for common case where VF has more queues than |
|---|
| .. | .. |
|---|
| 384 | 373 | return txq; |
|---|
| 385 | 374 | } |
|---|
| 386 | 375 | |
|---|
| 387 | | -static u32 fill_pg_buf(struct page *page, u32 offset, u32 len, |
|---|
| 376 | +static u32 fill_pg_buf(unsigned long hvpfn, u32 offset, u32 len, |
|---|
| 388 | 377 | struct hv_page_buffer *pb) |
|---|
| 389 | 378 | { |
|---|
| 390 | 379 | int j = 0; |
|---|
| 391 | 380 | |
|---|
| 392 | | - /* Deal with compund pages by ignoring unused part |
|---|
| 393 | | - * of the page. |
|---|
| 394 | | - */ |
|---|
| 395 | | - page += (offset >> PAGE_SHIFT); |
|---|
| 396 | | - offset &= ~PAGE_MASK; |
|---|
| 381 | + hvpfn += offset >> HV_HYP_PAGE_SHIFT; |
|---|
| 382 | + offset = offset & ~HV_HYP_PAGE_MASK; |
|---|
| 397 | 383 | |
|---|
| 398 | 384 | while (len > 0) { |
|---|
| 399 | 385 | unsigned long bytes; |
|---|
| 400 | 386 | |
|---|
| 401 | | - bytes = PAGE_SIZE - offset; |
|---|
| 387 | + bytes = HV_HYP_PAGE_SIZE - offset; |
|---|
| 402 | 388 | if (bytes > len) |
|---|
| 403 | 389 | bytes = len; |
|---|
| 404 | | - pb[j].pfn = page_to_pfn(page); |
|---|
| 390 | + pb[j].pfn = hvpfn; |
|---|
| 405 | 391 | pb[j].offset = offset; |
|---|
| 406 | 392 | pb[j].len = bytes; |
|---|
| 407 | 393 | |
|---|
| 408 | 394 | offset += bytes; |
|---|
| 409 | 395 | len -= bytes; |
|---|
| 410 | 396 | |
|---|
| 411 | | - if (offset == PAGE_SIZE && len) { |
|---|
| 412 | | - page++; |
|---|
| 397 | + if (offset == HV_HYP_PAGE_SIZE && len) { |
|---|
| 398 | + hvpfn++; |
|---|
| 413 | 399 | offset = 0; |
|---|
| 414 | 400 | j++; |
|---|
| 415 | 401 | } |
|---|
| .. | .. |
|---|
| 432 | 418 | * 2. skb linear data |
|---|
| 433 | 419 | * 3. skb fragment data |
|---|
| 434 | 420 | */ |
|---|
| 435 | | - slots_used += fill_pg_buf(virt_to_page(hdr), |
|---|
| 436 | | - offset_in_page(hdr), |
|---|
| 437 | | - len, &pb[slots_used]); |
|---|
| 421 | + slots_used += fill_pg_buf(virt_to_hvpfn(hdr), |
|---|
| 422 | + offset_in_hvpage(hdr), |
|---|
| 423 | + len, |
|---|
| 424 | + &pb[slots_used]); |
|---|
| 438 | 425 | |
|---|
| 439 | 426 | packet->rmsg_size = len; |
|---|
| 440 | 427 | packet->rmsg_pgcnt = slots_used; |
|---|
| 441 | 428 | |
|---|
| 442 | | - slots_used += fill_pg_buf(virt_to_page(data), |
|---|
| 443 | | - offset_in_page(data), |
|---|
| 444 | | - skb_headlen(skb), &pb[slots_used]); |
|---|
| 429 | + slots_used += fill_pg_buf(virt_to_hvpfn(data), |
|---|
| 430 | + offset_in_hvpage(data), |
|---|
| 431 | + skb_headlen(skb), |
|---|
| 432 | + &pb[slots_used]); |
|---|
| 445 | 433 | |
|---|
| 446 | 434 | for (i = 0; i < frags; i++) { |
|---|
| 447 | 435 | skb_frag_t *frag = skb_shinfo(skb)->frags + i; |
|---|
| 448 | 436 | |
|---|
| 449 | | - slots_used += fill_pg_buf(skb_frag_page(frag), |
|---|
| 450 | | - frag->page_offset, |
|---|
| 451 | | - skb_frag_size(frag), &pb[slots_used]); |
|---|
| 437 | + slots_used += fill_pg_buf(page_to_hvpfn(skb_frag_page(frag)), |
|---|
| 438 | + skb_frag_off(frag), |
|---|
| 439 | + skb_frag_size(frag), |
|---|
| 440 | + &pb[slots_used]); |
|---|
| 452 | 441 | } |
|---|
| 453 | 442 | return slots_used; |
|---|
| 454 | 443 | } |
|---|
| .. | .. |
|---|
| 461 | 450 | for (i = 0; i < frags; i++) { |
|---|
| 462 | 451 | skb_frag_t *frag = skb_shinfo(skb)->frags + i; |
|---|
| 463 | 452 | unsigned long size = skb_frag_size(frag); |
|---|
| 464 | | - unsigned long offset = frag->page_offset; |
|---|
| 453 | + unsigned long offset = skb_frag_off(frag); |
|---|
| 465 | 454 | |
|---|
| 466 | 455 | /* Skip unused frames from start of page */ |
|---|
| 467 | | - offset &= ~PAGE_MASK; |
|---|
| 468 | | - pages += PFN_UP(offset + size); |
|---|
| 456 | + offset &= ~HV_HYP_PAGE_MASK; |
|---|
| 457 | + pages += HVPFN_UP(offset + size); |
|---|
| 469 | 458 | } |
|---|
| 470 | 459 | return pages; |
|---|
| 471 | 460 | } |
|---|
| .. | .. |
|---|
| 473 | 462 | static int netvsc_get_slots(struct sk_buff *skb) |
|---|
| 474 | 463 | { |
|---|
| 475 | 464 | char *data = skb->data; |
|---|
| 476 | | - unsigned int offset = offset_in_page(data); |
|---|
| 465 | + unsigned int offset = offset_in_hvpage(data); |
|---|
| 477 | 466 | unsigned int len = skb_headlen(skb); |
|---|
| 478 | 467 | int slots; |
|---|
| 479 | 468 | int frag_slots; |
|---|
| 480 | 469 | |
|---|
| 481 | | - slots = DIV_ROUND_UP(offset + len, PAGE_SIZE); |
|---|
| 470 | + slots = DIV_ROUND_UP(offset + len, HV_HYP_PAGE_SIZE); |
|---|
| 482 | 471 | frag_slots = count_skb_frag_slots(skb); |
|---|
| 483 | 472 | return slots + frag_slots; |
|---|
| 484 | 473 | } |
|---|
| .. | .. |
|---|
| 531 | 520 | return rc; |
|---|
| 532 | 521 | } |
|---|
| 533 | 522 | |
|---|
| 534 | | -static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) |
|---|
| 523 | +static int netvsc_xmit(struct sk_buff *skb, struct net_device *net, bool xdp_tx) |
|---|
| 535 | 524 | { |
|---|
| 536 | 525 | struct net_device_context *net_device_ctx = netdev_priv(net); |
|---|
| 537 | 526 | struct hv_netvsc_packet *packet = NULL; |
|---|
| .. | .. |
|---|
| 584 | 573 | |
|---|
| 585 | 574 | /* Use the skb control buffer for building up the packet */ |
|---|
| 586 | 575 | BUILD_BUG_ON(sizeof(struct hv_netvsc_packet) > |
|---|
| 587 | | - FIELD_SIZEOF(struct sk_buff, cb)); |
|---|
| 576 | + sizeof_field(struct sk_buff, cb)); |
|---|
| 588 | 577 | packet = (struct hv_netvsc_packet *)skb->cb; |
|---|
| 589 | 578 | |
|---|
| 590 | 579 | packet->q_idx = skb_get_queue_mapping(skb); |
|---|
| .. | .. |
|---|
| 617 | 606 | *hash_info = hash; |
|---|
| 618 | 607 | } |
|---|
| 619 | 608 | |
|---|
| 609 | + /* When using AF_PACKET we need to drop VLAN header from |
|---|
| 610 | + * the frame and update the SKB to allow the HOST OS |
|---|
| 611 | + * to transmit the 802.1Q packet |
|---|
| 612 | + */ |
|---|
| 613 | + if (skb->protocol == htons(ETH_P_8021Q)) { |
|---|
| 614 | + u16 vlan_tci; |
|---|
| 615 | + |
|---|
| 616 | + skb_reset_mac_header(skb); |
|---|
| 617 | + if (eth_type_vlan(eth_hdr(skb)->h_proto)) { |
|---|
| 618 | + if (unlikely(__skb_vlan_pop(skb, &vlan_tci) != 0)) { |
|---|
| 619 | + ++net_device_ctx->eth_stats.vlan_error; |
|---|
| 620 | + goto drop; |
|---|
| 621 | + } |
|---|
| 622 | + |
|---|
| 623 | + __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tci); |
|---|
| 624 | + /* Update the NDIS header pkt lengths */ |
|---|
| 625 | + packet->total_data_buflen -= VLAN_HLEN; |
|---|
| 626 | + packet->total_bytes -= VLAN_HLEN; |
|---|
| 627 | + rndis_msg->msg_len = packet->total_data_buflen; |
|---|
| 628 | + rndis_msg->msg.pkt.data_len = packet->total_data_buflen; |
|---|
| 629 | + } |
|---|
| 630 | + } |
|---|
| 631 | + |
|---|
| 620 | 632 | if (skb_vlan_tag_present(skb)) { |
|---|
| 621 | 633 | struct ndis_pkt_8021q_info *vlan; |
|---|
| 622 | 634 | |
|---|
| .. | .. |
|---|
| 625 | 637 | IEEE_8021Q_INFO); |
|---|
| 626 | 638 | |
|---|
| 627 | 639 | vlan->value = 0; |
|---|
| 628 | | - vlan->vlanid = skb->vlan_tci & VLAN_VID_MASK; |
|---|
| 629 | | - vlan->pri = (skb->vlan_tci & VLAN_PRIO_MASK) >> |
|---|
| 630 | | - VLAN_PRIO_SHIFT; |
|---|
| 640 | + vlan->vlanid = skb_vlan_tag_get_id(skb); |
|---|
| 641 | + vlan->cfi = skb_vlan_tag_get_cfi(skb); |
|---|
| 642 | + vlan->pri = skb_vlan_tag_get_prio(skb); |
|---|
| 631 | 643 | } |
|---|
| 632 | 644 | |
|---|
| 633 | 645 | if (skb_is_gso(skb)) { |
|---|
| .. | .. |
|---|
| 650 | 662 | } else { |
|---|
| 651 | 663 | lso_info->lso_v2_transmit.ip_version = |
|---|
| 652 | 664 | NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6; |
|---|
| 653 | | - ipv6_hdr(skb)->payload_len = 0; |
|---|
| 654 | | - tcp_hdr(skb)->check = |
|---|
| 655 | | - ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
|---|
| 656 | | - &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0); |
|---|
| 665 | + tcp_v6_gso_csum_prep(skb); |
|---|
| 657 | 666 | } |
|---|
| 658 | 667 | lso_info->lso_v2_transmit.tcp_header_offset = skb_transport_offset(skb); |
|---|
| 659 | 668 | lso_info->lso_v2_transmit.mss = skb_shinfo(skb)->gso_size; |
|---|
| .. | .. |
|---|
| 699 | 708 | /* timestamp packet in software */ |
|---|
| 700 | 709 | skb_tx_timestamp(skb); |
|---|
| 701 | 710 | |
|---|
| 702 | | - ret = netvsc_send(net, packet, rndis_msg, pb, skb); |
|---|
| 711 | + ret = netvsc_send(net, packet, rndis_msg, pb, skb, xdp_tx); |
|---|
| 703 | 712 | if (likely(ret == 0)) |
|---|
| 704 | 713 | return NETDEV_TX_OK; |
|---|
| 705 | 714 | |
|---|
| .. | .. |
|---|
| 722 | 731 | goto drop; |
|---|
| 723 | 732 | } |
|---|
| 724 | 733 | |
|---|
| 734 | +static netdev_tx_t netvsc_start_xmit(struct sk_buff *skb, |
|---|
| 735 | + struct net_device *ndev) |
|---|
| 736 | +{ |
|---|
| 737 | + return netvsc_xmit(skb, ndev, false); |
|---|
| 738 | +} |
|---|
| 739 | + |
|---|
| 725 | 740 | /* |
|---|
| 726 | 741 | * netvsc_linkstatus_callback - Link up/down notification |
|---|
| 727 | 742 | */ |
|---|
| .. | .. |
|---|
| 732 | 747 | struct net_device_context *ndev_ctx = netdev_priv(net); |
|---|
| 733 | 748 | struct netvsc_reconfig *event; |
|---|
| 734 | 749 | unsigned long flags; |
|---|
| 750 | + |
|---|
| 751 | + /* Ensure the packet is big enough to access its fields */ |
|---|
| 752 | + if (resp->msg_len - RNDIS_HEADER_SIZE < sizeof(struct rndis_indicate_status)) { |
|---|
| 753 | + netdev_err(net, "invalid rndis_indicate_status packet, len: %u\n", |
|---|
| 754 | + resp->msg_len); |
|---|
| 755 | + return; |
|---|
| 756 | + } |
|---|
| 735 | 757 | |
|---|
| 736 | 758 | /* Update the physical link speed when changing to another vSwitch */ |
|---|
| 737 | 759 | if (indicate->status == RNDIS_STATUS_LINK_SPEED_CHANGE) { |
|---|
| .. | .. |
|---|
| 764 | 786 | schedule_delayed_work(&ndev_ctx->dwork, 0); |
|---|
| 765 | 787 | } |
|---|
| 766 | 788 | |
|---|
| 789 | +static void netvsc_xdp_xmit(struct sk_buff *skb, struct net_device *ndev) |
|---|
| 790 | +{ |
|---|
| 791 | + int rc; |
|---|
| 792 | + |
|---|
| 793 | + skb->queue_mapping = skb_get_rx_queue(skb); |
|---|
| 794 | + __skb_push(skb, ETH_HLEN); |
|---|
| 795 | + |
|---|
| 796 | + rc = netvsc_xmit(skb, ndev, true); |
|---|
| 797 | + |
|---|
| 798 | + if (dev_xmit_complete(rc)) |
|---|
| 799 | + return; |
|---|
| 800 | + |
|---|
| 801 | + dev_kfree_skb_any(skb); |
|---|
| 802 | + ndev->stats.tx_dropped++; |
|---|
| 803 | +} |
|---|
| 804 | + |
|---|
| 767 | 805 | static void netvsc_comp_ipcsum(struct sk_buff *skb) |
|---|
| 768 | 806 | { |
|---|
| 769 | 807 | struct iphdr *iph = (struct iphdr *)skb->data; |
|---|
| .. | .. |
|---|
| 773 | 811 | } |
|---|
| 774 | 812 | |
|---|
| 775 | 813 | static struct sk_buff *netvsc_alloc_recv_skb(struct net_device *net, |
|---|
| 776 | | - struct napi_struct *napi, |
|---|
| 777 | | - const struct ndis_tcp_ip_checksum_info *csum_info, |
|---|
| 778 | | - const struct ndis_pkt_8021q_info *vlan, |
|---|
| 779 | | - void *data, u32 buflen) |
|---|
| 814 | + struct netvsc_channel *nvchan, |
|---|
| 815 | + struct xdp_buff *xdp) |
|---|
| 780 | 816 | { |
|---|
| 817 | + struct napi_struct *napi = &nvchan->napi; |
|---|
| 818 | + const struct ndis_pkt_8021q_info *vlan = nvchan->rsc.vlan; |
|---|
| 819 | + const struct ndis_tcp_ip_checksum_info *csum_info = |
|---|
| 820 | + nvchan->rsc.csum_info; |
|---|
| 821 | + const u32 *hash_info = nvchan->rsc.hash_info; |
|---|
| 781 | 822 | struct sk_buff *skb; |
|---|
| 823 | + void *xbuf = xdp->data_hard_start; |
|---|
| 824 | + int i; |
|---|
| 782 | 825 | |
|---|
| 783 | | - skb = napi_alloc_skb(napi, buflen); |
|---|
| 784 | | - if (!skb) |
|---|
| 785 | | - return skb; |
|---|
| 826 | + if (xbuf) { |
|---|
| 827 | + unsigned int hdroom = xdp->data - xdp->data_hard_start; |
|---|
| 828 | + unsigned int xlen = xdp->data_end - xdp->data; |
|---|
| 829 | + unsigned int frag_size = xdp->frame_sz; |
|---|
| 786 | 830 | |
|---|
| 787 | | - /* |
|---|
| 788 | | - * Copy to skb. This copy is needed here since the memory pointed by |
|---|
| 789 | | - * hv_netvsc_packet cannot be deallocated |
|---|
| 790 | | - */ |
|---|
| 791 | | - skb_put_data(skb, data, buflen); |
|---|
| 831 | + skb = build_skb(xbuf, frag_size); |
|---|
| 832 | + |
|---|
| 833 | + if (!skb) { |
|---|
| 834 | + __free_page(virt_to_page(xbuf)); |
|---|
| 835 | + return NULL; |
|---|
| 836 | + } |
|---|
| 837 | + |
|---|
| 838 | + skb_reserve(skb, hdroom); |
|---|
| 839 | + skb_put(skb, xlen); |
|---|
| 840 | + skb->dev = napi->dev; |
|---|
| 841 | + } else { |
|---|
| 842 | + skb = napi_alloc_skb(napi, nvchan->rsc.pktlen); |
|---|
| 843 | + |
|---|
| 844 | + if (!skb) |
|---|
| 845 | + return NULL; |
|---|
| 846 | + |
|---|
| 847 | + /* Copy to skb. This copy is needed here since the memory |
|---|
| 848 | + * pointed by hv_netvsc_packet cannot be deallocated. |
|---|
| 849 | + */ |
|---|
| 850 | + for (i = 0; i < nvchan->rsc.cnt; i++) |
|---|
| 851 | + skb_put_data(skb, nvchan->rsc.data[i], |
|---|
| 852 | + nvchan->rsc.len[i]); |
|---|
| 853 | + } |
|---|
| 792 | 854 | |
|---|
| 793 | 855 | skb->protocol = eth_type_trans(skb, net); |
|---|
| 794 | 856 | |
|---|
| .. | .. |
|---|
| 812 | 874 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
|---|
| 813 | 875 | } |
|---|
| 814 | 876 | |
|---|
| 877 | + if (hash_info && (net->features & NETIF_F_RXHASH)) |
|---|
| 878 | + skb_set_hash(skb, *hash_info, PKT_HASH_TYPE_L4); |
|---|
| 879 | + |
|---|
| 815 | 880 | if (vlan) { |
|---|
| 816 | | - u16 vlan_tci = vlan->vlanid | (vlan->pri << VLAN_PRIO_SHIFT); |
|---|
| 881 | + u16 vlan_tci = vlan->vlanid | (vlan->pri << VLAN_PRIO_SHIFT) | |
|---|
| 882 | + (vlan->cfi ? VLAN_CFI_MASK : 0); |
|---|
| 817 | 883 | |
|---|
| 818 | 884 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
|---|
| 819 | 885 | vlan_tci); |
|---|
| .. | .. |
|---|
| 828 | 894 | */ |
|---|
| 829 | 895 | int netvsc_recv_callback(struct net_device *net, |
|---|
| 830 | 896 | struct netvsc_device *net_device, |
|---|
| 831 | | - struct vmbus_channel *channel, |
|---|
| 832 | | - void *data, u32 len, |
|---|
| 833 | | - const struct ndis_tcp_ip_checksum_info *csum_info, |
|---|
| 834 | | - const struct ndis_pkt_8021q_info *vlan) |
|---|
| 897 | + struct netvsc_channel *nvchan) |
|---|
| 835 | 898 | { |
|---|
| 836 | 899 | struct net_device_context *net_device_ctx = netdev_priv(net); |
|---|
| 900 | + struct vmbus_channel *channel = nvchan->channel; |
|---|
| 837 | 901 | u16 q_idx = channel->offermsg.offer.sub_channel_index; |
|---|
| 838 | | - struct netvsc_channel *nvchan = &net_device->chan_table[q_idx]; |
|---|
| 839 | 902 | struct sk_buff *skb; |
|---|
| 840 | | - struct netvsc_stats *rx_stats; |
|---|
| 903 | + struct netvsc_stats *rx_stats = &nvchan->rx_stats; |
|---|
| 904 | + struct xdp_buff xdp; |
|---|
| 905 | + u32 act; |
|---|
| 841 | 906 | |
|---|
| 842 | 907 | if (net->reg_state != NETREG_REGISTERED) |
|---|
| 843 | 908 | return NVSP_STAT_FAIL; |
|---|
| 844 | 909 | |
|---|
| 910 | + act = netvsc_run_xdp(net, nvchan, &xdp); |
|---|
| 911 | + |
|---|
| 912 | + if (act != XDP_PASS && act != XDP_TX) { |
|---|
| 913 | + u64_stats_update_begin(&rx_stats->syncp); |
|---|
| 914 | + rx_stats->xdp_drop++; |
|---|
| 915 | + u64_stats_update_end(&rx_stats->syncp); |
|---|
| 916 | + |
|---|
| 917 | + return NVSP_STAT_SUCCESS; /* consumed by XDP */ |
|---|
| 918 | + } |
|---|
| 919 | + |
|---|
| 845 | 920 | /* Allocate a skb - TODO direct I/O to pages? */ |
|---|
| 846 | | - skb = netvsc_alloc_recv_skb(net, &nvchan->napi, |
|---|
| 847 | | - csum_info, vlan, data, len); |
|---|
| 921 | + skb = netvsc_alloc_recv_skb(net, nvchan, &xdp); |
|---|
| 922 | + |
|---|
| 848 | 923 | if (unlikely(!skb)) { |
|---|
| 849 | 924 | ++net_device_ctx->eth_stats.rx_no_memory; |
|---|
| 850 | 925 | return NVSP_STAT_FAIL; |
|---|
| .. | .. |
|---|
| 857 | 932 | * on the synthetic device because modifying the VF device |
|---|
| 858 | 933 | * statistics will not work correctly. |
|---|
| 859 | 934 | */ |
|---|
| 860 | | - rx_stats = &nvchan->rx_stats; |
|---|
| 861 | 935 | u64_stats_update_begin(&rx_stats->syncp); |
|---|
| 862 | 936 | rx_stats->packets++; |
|---|
| 863 | | - rx_stats->bytes += len; |
|---|
| 937 | + rx_stats->bytes += nvchan->rsc.pktlen; |
|---|
| 864 | 938 | |
|---|
| 865 | 939 | if (skb->pkt_type == PACKET_BROADCAST) |
|---|
| 866 | 940 | ++rx_stats->broadcast; |
|---|
| 867 | 941 | else if (skb->pkt_type == PACKET_MULTICAST) |
|---|
| 868 | 942 | ++rx_stats->multicast; |
|---|
| 869 | 943 | u64_stats_update_end(&rx_stats->syncp); |
|---|
| 944 | + |
|---|
| 945 | + if (act == XDP_TX) { |
|---|
| 946 | + netvsc_xdp_xmit(skb, net); |
|---|
| 947 | + return NVSP_STAT_SUCCESS; |
|---|
| 948 | + } |
|---|
| 870 | 949 | |
|---|
| 871 | 950 | napi_gro_receive(&nvchan->napi, skb); |
|---|
| 872 | 951 | return NVSP_STAT_SUCCESS; |
|---|
| .. | .. |
|---|
| 894 | 973 | /* Alloc struct netvsc_device_info, and initialize it from either existing |
|---|
| 895 | 974 | * struct netvsc_device, or from default values. |
|---|
| 896 | 975 | */ |
|---|
| 897 | | -static struct netvsc_device_info *netvsc_devinfo_get |
|---|
| 898 | | - (struct netvsc_device *nvdev) |
|---|
| 976 | +static |
|---|
| 977 | +struct netvsc_device_info *netvsc_devinfo_get(struct netvsc_device *nvdev) |
|---|
| 899 | 978 | { |
|---|
| 900 | 979 | struct netvsc_device_info *dev_info; |
|---|
| 980 | + struct bpf_prog *prog; |
|---|
| 901 | 981 | |
|---|
| 902 | 982 | dev_info = kzalloc(sizeof(*dev_info), GFP_ATOMIC); |
|---|
| 903 | 983 | |
|---|
| .. | .. |
|---|
| 905 | 985 | return NULL; |
|---|
| 906 | 986 | |
|---|
| 907 | 987 | if (nvdev) { |
|---|
| 988 | + ASSERT_RTNL(); |
|---|
| 989 | + |
|---|
| 908 | 990 | dev_info->num_chn = nvdev->num_chn; |
|---|
| 909 | 991 | dev_info->send_sections = nvdev->send_section_cnt; |
|---|
| 910 | 992 | dev_info->send_section_size = nvdev->send_section_size; |
|---|
| .. | .. |
|---|
| 913 | 995 | |
|---|
| 914 | 996 | memcpy(dev_info->rss_key, nvdev->extension->rss_key, |
|---|
| 915 | 997 | NETVSC_HASH_KEYLEN); |
|---|
| 998 | + |
|---|
| 999 | + prog = netvsc_xdp_get(nvdev); |
|---|
| 1000 | + if (prog) { |
|---|
| 1001 | + bpf_prog_inc(prog); |
|---|
| 1002 | + dev_info->bprog = prog; |
|---|
| 1003 | + } |
|---|
| 916 | 1004 | } else { |
|---|
| 917 | 1005 | dev_info->num_chn = VRSS_CHANNEL_DEFAULT; |
|---|
| 918 | 1006 | dev_info->send_sections = NETVSC_DEFAULT_TX; |
|---|
| .. | .. |
|---|
| 922 | 1010 | } |
|---|
| 923 | 1011 | |
|---|
| 924 | 1012 | return dev_info; |
|---|
| 1013 | +} |
|---|
| 1014 | + |
|---|
| 1015 | +/* Free struct netvsc_device_info */ |
|---|
| 1016 | +static void netvsc_devinfo_put(struct netvsc_device_info *dev_info) |
|---|
| 1017 | +{ |
|---|
| 1018 | + if (dev_info->bprog) { |
|---|
| 1019 | + ASSERT_RTNL(); |
|---|
| 1020 | + bpf_prog_put(dev_info->bprog); |
|---|
| 1021 | + } |
|---|
| 1022 | + |
|---|
| 1023 | + kfree(dev_info); |
|---|
| 925 | 1024 | } |
|---|
| 926 | 1025 | |
|---|
| 927 | 1026 | static int netvsc_detach(struct net_device *ndev, |
|---|
| .. | .. |
|---|
| 934 | 1033 | /* Don't try continuing to try and setup sub channels */ |
|---|
| 935 | 1034 | if (cancel_work_sync(&nvdev->subchan_work)) |
|---|
| 936 | 1035 | nvdev->num_chn = 1; |
|---|
| 1036 | + |
|---|
| 1037 | + netvsc_xdp_set(ndev, NULL, NULL, nvdev); |
|---|
| 937 | 1038 | |
|---|
| 938 | 1039 | /* If device was up (receiving) then shutdown */ |
|---|
| 939 | 1040 | if (netif_running(ndev)) { |
|---|
| .. | .. |
|---|
| 968 | 1069 | struct hv_device *hdev = ndev_ctx->device_ctx; |
|---|
| 969 | 1070 | struct netvsc_device *nvdev; |
|---|
| 970 | 1071 | struct rndis_device *rdev; |
|---|
| 971 | | - int ret; |
|---|
| 1072 | + struct bpf_prog *prog; |
|---|
| 1073 | + int ret = 0; |
|---|
| 972 | 1074 | |
|---|
| 973 | 1075 | nvdev = rndis_filter_device_add(hdev, dev_info); |
|---|
| 974 | 1076 | if (IS_ERR(nvdev)) |
|---|
| .. | .. |
|---|
| 984 | 1086 | } |
|---|
| 985 | 1087 | } |
|---|
| 986 | 1088 | |
|---|
| 1089 | + prog = dev_info->bprog; |
|---|
| 1090 | + if (prog) { |
|---|
| 1091 | + bpf_prog_inc(prog); |
|---|
| 1092 | + ret = netvsc_xdp_set(ndev, prog, NULL, nvdev); |
|---|
| 1093 | + if (ret) { |
|---|
| 1094 | + bpf_prog_put(prog); |
|---|
| 1095 | + goto err1; |
|---|
| 1096 | + } |
|---|
| 1097 | + } |
|---|
| 1098 | + |
|---|
| 987 | 1099 | /* In any case device is now ready */ |
|---|
| 988 | 1100 | nvdev->tx_disable = false; |
|---|
| 989 | 1101 | netif_device_attach(ndev); |
|---|
| .. | .. |
|---|
| 994 | 1106 | if (netif_running(ndev)) { |
|---|
| 995 | 1107 | ret = rndis_filter_open(nvdev); |
|---|
| 996 | 1108 | if (ret) |
|---|
| 997 | | - goto err; |
|---|
| 1109 | + goto err2; |
|---|
| 998 | 1110 | |
|---|
| 999 | 1111 | rdev = nvdev->extension; |
|---|
| 1000 | 1112 | if (!rdev->link_state) |
|---|
| .. | .. |
|---|
| 1003 | 1115 | |
|---|
| 1004 | 1116 | return 0; |
|---|
| 1005 | 1117 | |
|---|
| 1006 | | -err: |
|---|
| 1118 | +err2: |
|---|
| 1007 | 1119 | netif_device_detach(ndev); |
|---|
| 1008 | 1120 | |
|---|
| 1121 | +err1: |
|---|
| 1009 | 1122 | rndis_filter_device_remove(hdev, nvdev); |
|---|
| 1010 | 1123 | |
|---|
| 1011 | 1124 | return ret; |
|---|
| .. | .. |
|---|
| 1055 | 1168 | } |
|---|
| 1056 | 1169 | |
|---|
| 1057 | 1170 | out: |
|---|
| 1058 | | - kfree(device_info); |
|---|
| 1171 | + netvsc_devinfo_put(device_info); |
|---|
| 1059 | 1172 | return ret; |
|---|
| 1060 | | -} |
|---|
| 1061 | | - |
|---|
| 1062 | | -static bool |
|---|
| 1063 | | -netvsc_validate_ethtool_ss_cmd(const struct ethtool_link_ksettings *cmd) |
|---|
| 1064 | | -{ |
|---|
| 1065 | | - struct ethtool_link_ksettings diff1 = *cmd; |
|---|
| 1066 | | - struct ethtool_link_ksettings diff2 = {}; |
|---|
| 1067 | | - |
|---|
| 1068 | | - diff1.base.speed = 0; |
|---|
| 1069 | | - diff1.base.duplex = 0; |
|---|
| 1070 | | - /* advertising and cmd are usually set */ |
|---|
| 1071 | | - ethtool_link_ksettings_zero_link_mode(&diff1, advertising); |
|---|
| 1072 | | - diff1.base.cmd = 0; |
|---|
| 1073 | | - /* We set port to PORT_OTHER */ |
|---|
| 1074 | | - diff2.base.port = PORT_OTHER; |
|---|
| 1075 | | - |
|---|
| 1076 | | - return !memcmp(&diff1, &diff2, sizeof(diff1)); |
|---|
| 1077 | 1173 | } |
|---|
| 1078 | 1174 | |
|---|
| 1079 | 1175 | static void netvsc_init_settings(struct net_device *dev) |
|---|
| .. | .. |
|---|
| 1084 | 1180 | |
|---|
| 1085 | 1181 | ndc->speed = SPEED_UNKNOWN; |
|---|
| 1086 | 1182 | ndc->duplex = DUPLEX_FULL; |
|---|
| 1183 | + |
|---|
| 1184 | + dev->features = NETIF_F_LRO; |
|---|
| 1087 | 1185 | } |
|---|
| 1088 | 1186 | |
|---|
| 1089 | 1187 | static int netvsc_get_link_ksettings(struct net_device *dev, |
|---|
| 1090 | 1188 | struct ethtool_link_ksettings *cmd) |
|---|
| 1091 | 1189 | { |
|---|
| 1092 | 1190 | struct net_device_context *ndc = netdev_priv(dev); |
|---|
| 1191 | + struct net_device *vf_netdev; |
|---|
| 1192 | + |
|---|
| 1193 | + vf_netdev = rtnl_dereference(ndc->vf_netdev); |
|---|
| 1194 | + |
|---|
| 1195 | + if (vf_netdev) |
|---|
| 1196 | + return __ethtool_get_link_ksettings(vf_netdev, cmd); |
|---|
| 1093 | 1197 | |
|---|
| 1094 | 1198 | cmd->base.speed = ndc->speed; |
|---|
| 1095 | 1199 | cmd->base.duplex = ndc->duplex; |
|---|
| .. | .. |
|---|
| 1102 | 1206 | const struct ethtool_link_ksettings *cmd) |
|---|
| 1103 | 1207 | { |
|---|
| 1104 | 1208 | struct net_device_context *ndc = netdev_priv(dev); |
|---|
| 1105 | | - u32 speed; |
|---|
| 1209 | + struct net_device *vf_netdev = rtnl_dereference(ndc->vf_netdev); |
|---|
| 1106 | 1210 | |
|---|
| 1107 | | - speed = cmd->base.speed; |
|---|
| 1108 | | - if (!ethtool_validate_speed(speed) || |
|---|
| 1109 | | - !ethtool_validate_duplex(cmd->base.duplex) || |
|---|
| 1110 | | - !netvsc_validate_ethtool_ss_cmd(cmd)) |
|---|
| 1111 | | - return -EINVAL; |
|---|
| 1211 | + if (vf_netdev) { |
|---|
| 1212 | + if (!vf_netdev->ethtool_ops->set_link_ksettings) |
|---|
| 1213 | + return -EOPNOTSUPP; |
|---|
| 1112 | 1214 | |
|---|
| 1113 | | - ndc->speed = speed; |
|---|
| 1114 | | - ndc->duplex = cmd->base.duplex; |
|---|
| 1215 | + return vf_netdev->ethtool_ops->set_link_ksettings(vf_netdev, |
|---|
| 1216 | + cmd); |
|---|
| 1217 | + } |
|---|
| 1115 | 1218 | |
|---|
| 1116 | | - return 0; |
|---|
| 1219 | + return ethtool_virtdev_set_link_ksettings(dev, cmd, |
|---|
| 1220 | + &ndc->speed, &ndc->duplex); |
|---|
| 1117 | 1221 | } |
|---|
| 1118 | 1222 | |
|---|
| 1119 | 1223 | static int netvsc_change_mtu(struct net_device *ndev, int mtu) |
|---|
| .. | .. |
|---|
| 1160 | 1264 | dev_set_mtu(vf_netdev, orig_mtu); |
|---|
| 1161 | 1265 | |
|---|
| 1162 | 1266 | out: |
|---|
| 1163 | | - kfree(device_info); |
|---|
| 1267 | + netvsc_devinfo_put(device_info); |
|---|
| 1164 | 1268 | return ret; |
|---|
| 1165 | 1269 | } |
|---|
| 1166 | 1270 | |
|---|
| .. | .. |
|---|
| 1323 | 1427 | return -ENODEV; |
|---|
| 1324 | 1428 | |
|---|
| 1325 | 1429 | if (vf_netdev) { |
|---|
| 1326 | | - err = dev_set_mac_address(vf_netdev, addr); |
|---|
| 1430 | + err = dev_set_mac_address(vf_netdev, addr, NULL); |
|---|
| 1327 | 1431 | if (err) |
|---|
| 1328 | 1432 | return err; |
|---|
| 1329 | 1433 | } |
|---|
| .. | .. |
|---|
| 1334 | 1438 | } else if (vf_netdev) { |
|---|
| 1335 | 1439 | /* rollback change on VF */ |
|---|
| 1336 | 1440 | memcpy(addr->sa_data, ndev->dev_addr, ETH_ALEN); |
|---|
| 1337 | | - dev_set_mac_address(vf_netdev, addr); |
|---|
| 1441 | + dev_set_mac_address(vf_netdev, addr, NULL); |
|---|
| 1338 | 1442 | } |
|---|
| 1339 | 1443 | |
|---|
| 1340 | 1444 | return err; |
|---|
| .. | .. |
|---|
| 1354 | 1458 | { "rx_no_memory", offsetof(struct netvsc_ethtool_stats, rx_no_memory) }, |
|---|
| 1355 | 1459 | { "stop_queue", offsetof(struct netvsc_ethtool_stats, stop_queue) }, |
|---|
| 1356 | 1460 | { "wake_queue", offsetof(struct netvsc_ethtool_stats, wake_queue) }, |
|---|
| 1461 | + { "vlan_error", offsetof(struct netvsc_ethtool_stats, vlan_error) }, |
|---|
| 1357 | 1462 | }, pcpu_stats[] = { |
|---|
| 1358 | 1463 | { "cpu%u_rx_packets", |
|---|
| 1359 | 1464 | offsetof(struct netvsc_ethtool_pcpu_stats, rx_packets) }, |
|---|
| .. | .. |
|---|
| 1385 | 1490 | /* statistics per queue (rx/tx packets/bytes) */ |
|---|
| 1386 | 1491 | #define NETVSC_PCPU_STATS_LEN (num_present_cpus() * ARRAY_SIZE(pcpu_stats)) |
|---|
| 1387 | 1492 | |
|---|
| 1388 | | -/* 4 statistics per queue (rx/tx packets/bytes) */ |
|---|
| 1389 | | -#define NETVSC_QUEUE_STATS_LEN(dev) ((dev)->num_chn * 4) |
|---|
| 1493 | +/* 5 statistics per queue (rx/tx packets/bytes, rx xdp_drop) */ |
|---|
| 1494 | +#define NETVSC_QUEUE_STATS_LEN(dev) ((dev)->num_chn * 5) |
|---|
| 1390 | 1495 | |
|---|
| 1391 | 1496 | static int netvsc_get_sset_count(struct net_device *dev, int string_set) |
|---|
| 1392 | 1497 | { |
|---|
| .. | .. |
|---|
| 1418 | 1523 | struct netvsc_ethtool_pcpu_stats *pcpu_sum; |
|---|
| 1419 | 1524 | unsigned int start; |
|---|
| 1420 | 1525 | u64 packets, bytes; |
|---|
| 1526 | + u64 xdp_drop; |
|---|
| 1421 | 1527 | int i, j, cpu; |
|---|
| 1422 | 1528 | |
|---|
| 1423 | 1529 | if (!nvdev) |
|---|
| .. | .. |
|---|
| 1446 | 1552 | start = u64_stats_fetch_begin_irq(&qstats->syncp); |
|---|
| 1447 | 1553 | packets = qstats->packets; |
|---|
| 1448 | 1554 | bytes = qstats->bytes; |
|---|
| 1555 | + xdp_drop = qstats->xdp_drop; |
|---|
| 1449 | 1556 | } while (u64_stats_fetch_retry_irq(&qstats->syncp, start)); |
|---|
| 1450 | 1557 | data[i++] = packets; |
|---|
| 1451 | 1558 | data[i++] = bytes; |
|---|
| 1559 | + data[i++] = xdp_drop; |
|---|
| 1452 | 1560 | } |
|---|
| 1453 | 1561 | |
|---|
| 1454 | 1562 | pcpu_sum = kvmalloc_array(num_possible_cpus(), |
|---|
| 1455 | 1563 | sizeof(struct netvsc_ethtool_pcpu_stats), |
|---|
| 1456 | 1564 | GFP_KERNEL); |
|---|
| 1565 | + if (!pcpu_sum) |
|---|
| 1566 | + return; |
|---|
| 1567 | + |
|---|
| 1457 | 1568 | netvsc_get_pcpu_stats(dev, pcpu_sum); |
|---|
| 1458 | 1569 | for_each_present_cpu(cpu) { |
|---|
| 1459 | 1570 | struct netvsc_ethtool_pcpu_stats *this_sum = &pcpu_sum[cpu]; |
|---|
| .. | .. |
|---|
| 1495 | 1606 | sprintf(p, "rx_queue_%u_packets", i); |
|---|
| 1496 | 1607 | p += ETH_GSTRING_LEN; |
|---|
| 1497 | 1608 | sprintf(p, "rx_queue_%u_bytes", i); |
|---|
| 1609 | + p += ETH_GSTRING_LEN; |
|---|
| 1610 | + sprintf(p, "rx_queue_%u_xdp_drop", i); |
|---|
| 1498 | 1611 | p += ETH_GSTRING_LEN; |
|---|
| 1499 | 1612 | } |
|---|
| 1500 | 1613 | |
|---|
| .. | .. |
|---|
| 1641 | 1754 | |
|---|
| 1642 | 1755 | return -EOPNOTSUPP; |
|---|
| 1643 | 1756 | } |
|---|
| 1644 | | - |
|---|
| 1645 | | -#ifdef CONFIG_NET_POLL_CONTROLLER |
|---|
| 1646 | | -static void netvsc_poll_controller(struct net_device *dev) |
|---|
| 1647 | | -{ |
|---|
| 1648 | | - struct net_device_context *ndc = netdev_priv(dev); |
|---|
| 1649 | | - struct netvsc_device *ndev; |
|---|
| 1650 | | - int i; |
|---|
| 1651 | | - |
|---|
| 1652 | | - rcu_read_lock(); |
|---|
| 1653 | | - ndev = rcu_dereference(ndc->nvdev); |
|---|
| 1654 | | - if (ndev) { |
|---|
| 1655 | | - for (i = 0; i < ndev->num_chn; i++) { |
|---|
| 1656 | | - struct netvsc_channel *nvchan = &ndev->chan_table[i]; |
|---|
| 1657 | | - |
|---|
| 1658 | | - napi_schedule(&nvchan->napi); |
|---|
| 1659 | | - } |
|---|
| 1660 | | - } |
|---|
| 1661 | | - rcu_read_unlock(); |
|---|
| 1662 | | -} |
|---|
| 1663 | | -#endif |
|---|
| 1664 | 1757 | |
|---|
| 1665 | 1758 | static u32 netvsc_get_rxfh_key_size(struct net_device *dev) |
|---|
| 1666 | 1759 | { |
|---|
| .. | .. |
|---|
| 1812 | 1905 | } |
|---|
| 1813 | 1906 | |
|---|
| 1814 | 1907 | out: |
|---|
| 1815 | | - kfree(device_info); |
|---|
| 1908 | + netvsc_devinfo_put(device_info); |
|---|
| 1816 | 1909 | return ret; |
|---|
| 1910 | +} |
|---|
| 1911 | + |
|---|
| 1912 | +static netdev_features_t netvsc_fix_features(struct net_device *ndev, |
|---|
| 1913 | + netdev_features_t features) |
|---|
| 1914 | +{ |
|---|
| 1915 | + struct net_device_context *ndevctx = netdev_priv(ndev); |
|---|
| 1916 | + struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev); |
|---|
| 1917 | + |
|---|
| 1918 | + if (!nvdev || nvdev->destroy) |
|---|
| 1919 | + return features; |
|---|
| 1920 | + |
|---|
| 1921 | + if ((features & NETIF_F_LRO) && netvsc_xdp_get(nvdev)) { |
|---|
| 1922 | + features ^= NETIF_F_LRO; |
|---|
| 1923 | + netdev_info(ndev, "Skip LRO - unsupported with XDP\n"); |
|---|
| 1924 | + } |
|---|
| 1925 | + |
|---|
| 1926 | + return features; |
|---|
| 1927 | +} |
|---|
| 1928 | + |
|---|
| 1929 | +static int netvsc_set_features(struct net_device *ndev, |
|---|
| 1930 | + netdev_features_t features) |
|---|
| 1931 | +{ |
|---|
| 1932 | + netdev_features_t change = features ^ ndev->features; |
|---|
| 1933 | + struct net_device_context *ndevctx = netdev_priv(ndev); |
|---|
| 1934 | + struct netvsc_device *nvdev = rtnl_dereference(ndevctx->nvdev); |
|---|
| 1935 | + struct net_device *vf_netdev = rtnl_dereference(ndevctx->vf_netdev); |
|---|
| 1936 | + struct ndis_offload_params offloads; |
|---|
| 1937 | + int ret = 0; |
|---|
| 1938 | + |
|---|
| 1939 | + if (!nvdev || nvdev->destroy) |
|---|
| 1940 | + return -ENODEV; |
|---|
| 1941 | + |
|---|
| 1942 | + if (!(change & NETIF_F_LRO)) |
|---|
| 1943 | + goto syncvf; |
|---|
| 1944 | + |
|---|
| 1945 | + memset(&offloads, 0, sizeof(struct ndis_offload_params)); |
|---|
| 1946 | + |
|---|
| 1947 | + if (features & NETIF_F_LRO) { |
|---|
| 1948 | + offloads.rsc_ip_v4 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED; |
|---|
| 1949 | + offloads.rsc_ip_v6 = NDIS_OFFLOAD_PARAMETERS_RSC_ENABLED; |
|---|
| 1950 | + } else { |
|---|
| 1951 | + offloads.rsc_ip_v4 = NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED; |
|---|
| 1952 | + offloads.rsc_ip_v6 = NDIS_OFFLOAD_PARAMETERS_RSC_DISABLED; |
|---|
| 1953 | + } |
|---|
| 1954 | + |
|---|
| 1955 | + ret = rndis_filter_set_offload_params(ndev, nvdev, &offloads); |
|---|
| 1956 | + |
|---|
| 1957 | + if (ret) { |
|---|
| 1958 | + features ^= NETIF_F_LRO; |
|---|
| 1959 | + ndev->features = features; |
|---|
| 1960 | + } |
|---|
| 1961 | + |
|---|
| 1962 | +syncvf: |
|---|
| 1963 | + if (!vf_netdev) |
|---|
| 1964 | + return ret; |
|---|
| 1965 | + |
|---|
| 1966 | + vf_netdev->wanted_features = features; |
|---|
| 1967 | + netdev_update_features(vf_netdev); |
|---|
| 1968 | + |
|---|
| 1969 | + return ret; |
|---|
| 1970 | +} |
|---|
| 1971 | + |
|---|
| 1972 | +static int netvsc_get_regs_len(struct net_device *netdev) |
|---|
| 1973 | +{ |
|---|
| 1974 | + return VRSS_SEND_TAB_SIZE * sizeof(u32); |
|---|
| 1975 | +} |
|---|
| 1976 | + |
|---|
| 1977 | +static void netvsc_get_regs(struct net_device *netdev, |
|---|
| 1978 | + struct ethtool_regs *regs, void *p) |
|---|
| 1979 | +{ |
|---|
| 1980 | + struct net_device_context *ndc = netdev_priv(netdev); |
|---|
| 1981 | + u32 *regs_buff = p; |
|---|
| 1982 | + |
|---|
| 1983 | + /* increase the version, if buffer format is changed. */ |
|---|
| 1984 | + regs->version = 1; |
|---|
| 1985 | + |
|---|
| 1986 | + memcpy(regs_buff, ndc->tx_table, VRSS_SEND_TAB_SIZE * sizeof(u32)); |
|---|
| 1817 | 1987 | } |
|---|
| 1818 | 1988 | |
|---|
| 1819 | 1989 | static u32 netvsc_get_msglevel(struct net_device *ndev) |
|---|
| .. | .. |
|---|
| 1832 | 2002 | |
|---|
| 1833 | 2003 | static const struct ethtool_ops ethtool_ops = { |
|---|
| 1834 | 2004 | .get_drvinfo = netvsc_get_drvinfo, |
|---|
| 2005 | + .get_regs_len = netvsc_get_regs_len, |
|---|
| 2006 | + .get_regs = netvsc_get_regs, |
|---|
| 1835 | 2007 | .get_msglevel = netvsc_get_msglevel, |
|---|
| 1836 | 2008 | .set_msglevel = netvsc_set_msglevel, |
|---|
| 1837 | 2009 | .get_link = ethtool_op_get_link, |
|---|
| .. | .. |
|---|
| 1859 | 2031 | .ndo_start_xmit = netvsc_start_xmit, |
|---|
| 1860 | 2032 | .ndo_change_rx_flags = netvsc_change_rx_flags, |
|---|
| 1861 | 2033 | .ndo_set_rx_mode = netvsc_set_rx_mode, |
|---|
| 2034 | + .ndo_fix_features = netvsc_fix_features, |
|---|
| 2035 | + .ndo_set_features = netvsc_set_features, |
|---|
| 1862 | 2036 | .ndo_change_mtu = netvsc_change_mtu, |
|---|
| 1863 | 2037 | .ndo_validate_addr = eth_validate_addr, |
|---|
| 1864 | 2038 | .ndo_set_mac_address = netvsc_set_mac_addr, |
|---|
| 1865 | 2039 | .ndo_select_queue = netvsc_select_queue, |
|---|
| 1866 | 2040 | .ndo_get_stats64 = netvsc_get_stats64, |
|---|
| 1867 | | -#ifdef CONFIG_NET_POLL_CONTROLLER |
|---|
| 1868 | | - .ndo_poll_controller = netvsc_poll_controller, |
|---|
| 1869 | | -#endif |
|---|
| 2041 | + .ndo_bpf = netvsc_bpf, |
|---|
| 1870 | 2042 | }; |
|---|
| 1871 | 2043 | |
|---|
| 1872 | 2044 | /* |
|---|
| .. | .. |
|---|
| 2073 | 2245 | "unable to change mtu to %u\n", ndev->mtu); |
|---|
| 2074 | 2246 | |
|---|
| 2075 | 2247 | /* set multicast etc flags on VF */ |
|---|
| 2076 | | - dev_change_flags(vf_netdev, ndev->flags | IFF_SLAVE); |
|---|
| 2248 | + dev_change_flags(vf_netdev, ndev->flags | IFF_SLAVE, NULL); |
|---|
| 2077 | 2249 | |
|---|
| 2078 | 2250 | /* sync address list from ndev to VF */ |
|---|
| 2079 | 2251 | netif_addr_lock_bh(ndev); |
|---|
| .. | .. |
|---|
| 2082 | 2254 | netif_addr_unlock_bh(ndev); |
|---|
| 2083 | 2255 | |
|---|
| 2084 | 2256 | if (netif_running(ndev)) { |
|---|
| 2085 | | - ret = dev_open(vf_netdev); |
|---|
| 2257 | + ret = dev_open(vf_netdev, NULL); |
|---|
| 2086 | 2258 | if (ret) |
|---|
| 2087 | 2259 | netdev_warn(vf_netdev, |
|---|
| 2088 | 2260 | "unable to open: %d\n", ret); |
|---|
| .. | .. |
|---|
| 2118 | 2290 | { |
|---|
| 2119 | 2291 | struct device *parent = vf_netdev->dev.parent; |
|---|
| 2120 | 2292 | struct net_device_context *ndev_ctx; |
|---|
| 2293 | + struct net_device *ndev; |
|---|
| 2121 | 2294 | struct pci_dev *pdev; |
|---|
| 2122 | 2295 | u32 serial; |
|---|
| 2123 | 2296 | |
|---|
| .. | .. |
|---|
| 2144 | 2317 | return hv_get_drvdata(ndev_ctx->device_ctx); |
|---|
| 2145 | 2318 | } |
|---|
| 2146 | 2319 | |
|---|
| 2320 | + /* Fallback path to check synthetic vf with |
|---|
| 2321 | + * help of mac addr |
|---|
| 2322 | + */ |
|---|
| 2323 | + list_for_each_entry(ndev_ctx, &netvsc_dev_list, list) { |
|---|
| 2324 | + ndev = hv_get_drvdata(ndev_ctx->device_ctx); |
|---|
| 2325 | + if (ether_addr_equal(vf_netdev->perm_addr, ndev->perm_addr)) { |
|---|
| 2326 | + netdev_notice(vf_netdev, |
|---|
| 2327 | + "falling back to mac addr based matching\n"); |
|---|
| 2328 | + return ndev; |
|---|
| 2329 | + } |
|---|
| 2330 | + } |
|---|
| 2331 | + |
|---|
| 2147 | 2332 | netdev_notice(vf_netdev, |
|---|
| 2148 | 2333 | "no netdev found for vf serial:%u\n", serial); |
|---|
| 2149 | 2334 | return NULL; |
|---|
| .. | .. |
|---|
| 2153 | 2338 | { |
|---|
| 2154 | 2339 | struct net_device_context *net_device_ctx; |
|---|
| 2155 | 2340 | struct netvsc_device *netvsc_dev; |
|---|
| 2341 | + struct bpf_prog *prog; |
|---|
| 2156 | 2342 | struct net_device *ndev; |
|---|
| 2157 | 2343 | int ret; |
|---|
| 2158 | 2344 | |
|---|
| .. | .. |
|---|
| 2168 | 2354 | if (!netvsc_dev || rtnl_dereference(net_device_ctx->vf_netdev)) |
|---|
| 2169 | 2355 | return NOTIFY_DONE; |
|---|
| 2170 | 2356 | |
|---|
| 2171 | | - /* if syntihetic interface is a different namespace, |
|---|
| 2357 | + /* if synthetic interface is a different namespace, |
|---|
| 2172 | 2358 | * then move the VF to that namespace; join will be |
|---|
| 2173 | 2359 | * done again in that context. |
|---|
| 2174 | 2360 | */ |
|---|
| .. | .. |
|---|
| 2193 | 2379 | |
|---|
| 2194 | 2380 | dev_hold(vf_netdev); |
|---|
| 2195 | 2381 | rcu_assign_pointer(net_device_ctx->vf_netdev, vf_netdev); |
|---|
| 2382 | + |
|---|
| 2383 | + vf_netdev->wanted_features = ndev->features; |
|---|
| 2384 | + netdev_update_features(vf_netdev); |
|---|
| 2385 | + |
|---|
| 2386 | + prog = netvsc_xdp_get(netvsc_dev); |
|---|
| 2387 | + netvsc_vf_setxdp(vf_netdev, prog); |
|---|
| 2388 | + |
|---|
| 2196 | 2389 | return NOTIFY_OK; |
|---|
| 2197 | 2390 | } |
|---|
| 2198 | 2391 | |
|---|
| 2199 | | -/* VF up/down change detected, schedule to change data path */ |
|---|
| 2392 | +/* Change the data path when VF UP/DOWN/CHANGE are detected. |
|---|
| 2393 | + * |
|---|
| 2394 | + * Typically a UP or DOWN event is followed by a CHANGE event, so |
|---|
| 2395 | + * net_device_ctx->data_path_is_vf is used to cache the current data path |
|---|
| 2396 | + * to avoid the duplicate call of netvsc_switch_datapath() and the duplicate |
|---|
| 2397 | + * message. |
|---|
| 2398 | + * |
|---|
| 2399 | + * During hibernation, if a VF NIC driver (e.g. mlx5) preserves the network |
|---|
| 2400 | + * interface, there is only the CHANGE event and no UP or DOWN event. |
|---|
| 2401 | + */ |
|---|
| 2200 | 2402 | static int netvsc_vf_changed(struct net_device *vf_netdev) |
|---|
| 2201 | 2403 | { |
|---|
| 2202 | 2404 | struct net_device_context *net_device_ctx; |
|---|
| .. | .. |
|---|
| 2212 | 2414 | netvsc_dev = rtnl_dereference(net_device_ctx->nvdev); |
|---|
| 2213 | 2415 | if (!netvsc_dev) |
|---|
| 2214 | 2416 | return NOTIFY_DONE; |
|---|
| 2417 | + |
|---|
| 2418 | + if (net_device_ctx->data_path_is_vf == vf_is_up) |
|---|
| 2419 | + return NOTIFY_OK; |
|---|
| 2420 | + net_device_ctx->data_path_is_vf = vf_is_up; |
|---|
| 2421 | + |
|---|
| 2422 | + if (vf_is_up && !net_device_ctx->vf_alloc) { |
|---|
| 2423 | + netdev_info(ndev, "Waiting for the VF association from host\n"); |
|---|
| 2424 | + wait_for_completion(&net_device_ctx->vf_add); |
|---|
| 2425 | + } |
|---|
| 2215 | 2426 | |
|---|
| 2216 | 2427 | netvsc_switch_datapath(ndev, vf_is_up); |
|---|
| 2217 | 2428 | netdev_info(ndev, "Data path switched %s VF: %s\n", |
|---|
| .. | .. |
|---|
| 2234 | 2445 | |
|---|
| 2235 | 2446 | netdev_info(ndev, "VF unregistering: %s\n", vf_netdev->name); |
|---|
| 2236 | 2447 | |
|---|
| 2448 | + netvsc_vf_setxdp(vf_netdev, NULL); |
|---|
| 2449 | + |
|---|
| 2450 | + reinit_completion(&net_device_ctx->vf_add); |
|---|
| 2237 | 2451 | netdev_rx_handler_unregister(vf_netdev); |
|---|
| 2238 | 2452 | netdev_upper_dev_unlink(vf_netdev, ndev); |
|---|
| 2239 | 2453 | RCU_INIT_POINTER(net_device_ctx->vf_netdev, NULL); |
|---|
| .. | .. |
|---|
| 2271 | 2485 | |
|---|
| 2272 | 2486 | INIT_DELAYED_WORK(&net_device_ctx->dwork, netvsc_link_change); |
|---|
| 2273 | 2487 | |
|---|
| 2488 | + init_completion(&net_device_ctx->vf_add); |
|---|
| 2274 | 2489 | spin_lock_init(&net_device_ctx->lock); |
|---|
| 2275 | 2490 | INIT_LIST_HEAD(&net_device_ctx->reconfig_events); |
|---|
| 2276 | 2491 | INIT_DELAYED_WORK(&net_device_ctx->vf_takeover, netvsc_vf_setup); |
|---|
| .. | .. |
|---|
| 2316 | 2531 | * netvsc_probe() can't get rtnl lock and as a result vmbus_onoffer() |
|---|
| 2317 | 2532 | * -> ... -> device_add() -> ... -> __device_attach() can't get |
|---|
| 2318 | 2533 | * the device lock, so all the subchannels can't be processed -- |
|---|
| 2319 | | - * finally netvsc_subchan_work() hangs for ever. |
|---|
| 2534 | + * finally netvsc_subchan_work() hangs forever. |
|---|
| 2320 | 2535 | */ |
|---|
| 2321 | 2536 | rtnl_lock(); |
|---|
| 2322 | 2537 | |
|---|
| .. | .. |
|---|
| 2325 | 2540 | |
|---|
| 2326 | 2541 | /* hw_features computed in rndis_netdev_set_hwcaps() */ |
|---|
| 2327 | 2542 | net->features = net->hw_features | |
|---|
| 2328 | | - NETIF_F_HIGHDMA | NETIF_F_SG | |
|---|
| 2329 | | - NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
|---|
| 2543 | + NETIF_F_HIGHDMA | NETIF_F_HW_VLAN_CTAG_TX | |
|---|
| 2544 | + NETIF_F_HW_VLAN_CTAG_RX; |
|---|
| 2330 | 2545 | net->vlan_features = net->features; |
|---|
| 2331 | 2546 | |
|---|
| 2332 | 2547 | netdev_lockdep_set_classes(net); |
|---|
| .. | .. |
|---|
| 2349 | 2564 | list_add(&net_device_ctx->list, &netvsc_dev_list); |
|---|
| 2350 | 2565 | rtnl_unlock(); |
|---|
| 2351 | 2566 | |
|---|
| 2352 | | - kfree(device_info); |
|---|
| 2567 | + netvsc_devinfo_put(device_info); |
|---|
| 2353 | 2568 | return 0; |
|---|
| 2354 | 2569 | |
|---|
| 2355 | 2570 | register_failed: |
|---|
| 2356 | 2571 | rtnl_unlock(); |
|---|
| 2357 | 2572 | rndis_filter_device_remove(dev, nvdev); |
|---|
| 2358 | 2573 | rndis_failed: |
|---|
| 2359 | | - kfree(device_info); |
|---|
| 2574 | + netvsc_devinfo_put(device_info); |
|---|
| 2360 | 2575 | devinfo_failed: |
|---|
| 2361 | 2576 | free_percpu(net_device_ctx->vf_stats); |
|---|
| 2362 | 2577 | no_stats: |
|---|
| .. | .. |
|---|
| 2384 | 2599 | |
|---|
| 2385 | 2600 | rtnl_lock(); |
|---|
| 2386 | 2601 | nvdev = rtnl_dereference(ndev_ctx->nvdev); |
|---|
| 2387 | | - if (nvdev) |
|---|
| 2602 | + if (nvdev) { |
|---|
| 2388 | 2603 | cancel_work_sync(&nvdev->subchan_work); |
|---|
| 2604 | + netvsc_xdp_set(net, NULL, NULL, nvdev); |
|---|
| 2605 | + } |
|---|
| 2389 | 2606 | |
|---|
| 2390 | 2607 | /* |
|---|
| 2391 | 2608 | * Call to the vsc driver to let it know that the device is being |
|---|
| .. | .. |
|---|
| 2410 | 2627 | return 0; |
|---|
| 2411 | 2628 | } |
|---|
| 2412 | 2629 | |
|---|
| 2630 | +static int netvsc_suspend(struct hv_device *dev) |
|---|
| 2631 | +{ |
|---|
| 2632 | + struct net_device_context *ndev_ctx; |
|---|
| 2633 | + struct netvsc_device *nvdev; |
|---|
| 2634 | + struct net_device *net; |
|---|
| 2635 | + int ret; |
|---|
| 2636 | + |
|---|
| 2637 | + net = hv_get_drvdata(dev); |
|---|
| 2638 | + |
|---|
| 2639 | + ndev_ctx = netdev_priv(net); |
|---|
| 2640 | + cancel_delayed_work_sync(&ndev_ctx->dwork); |
|---|
| 2641 | + |
|---|
| 2642 | + rtnl_lock(); |
|---|
| 2643 | + |
|---|
| 2644 | + nvdev = rtnl_dereference(ndev_ctx->nvdev); |
|---|
| 2645 | + if (nvdev == NULL) { |
|---|
| 2646 | + ret = -ENODEV; |
|---|
| 2647 | + goto out; |
|---|
| 2648 | + } |
|---|
| 2649 | + |
|---|
| 2650 | + /* Save the current config info */ |
|---|
| 2651 | + ndev_ctx->saved_netvsc_dev_info = netvsc_devinfo_get(nvdev); |
|---|
| 2652 | + if (!ndev_ctx->saved_netvsc_dev_info) { |
|---|
| 2653 | + ret = -ENOMEM; |
|---|
| 2654 | + goto out; |
|---|
| 2655 | + } |
|---|
| 2656 | + ret = netvsc_detach(net, nvdev); |
|---|
| 2657 | +out: |
|---|
| 2658 | + rtnl_unlock(); |
|---|
| 2659 | + |
|---|
| 2660 | + return ret; |
|---|
| 2661 | +} |
|---|
| 2662 | + |
|---|
| 2663 | +static int netvsc_resume(struct hv_device *dev) |
|---|
| 2664 | +{ |
|---|
| 2665 | + struct net_device *net = hv_get_drvdata(dev); |
|---|
| 2666 | + struct net_device_context *net_device_ctx; |
|---|
| 2667 | + struct netvsc_device_info *device_info; |
|---|
| 2668 | + int ret; |
|---|
| 2669 | + |
|---|
| 2670 | + rtnl_lock(); |
|---|
| 2671 | + |
|---|
| 2672 | + net_device_ctx = netdev_priv(net); |
|---|
| 2673 | + |
|---|
| 2674 | + /* Reset the data path to the netvsc NIC before re-opening the vmbus |
|---|
| 2675 | + * channel. Later netvsc_netdev_event() will switch the data path to |
|---|
| 2676 | + * the VF upon the UP or CHANGE event. |
|---|
| 2677 | + */ |
|---|
| 2678 | + net_device_ctx->data_path_is_vf = false; |
|---|
| 2679 | + device_info = net_device_ctx->saved_netvsc_dev_info; |
|---|
| 2680 | + |
|---|
| 2681 | + ret = netvsc_attach(net, device_info); |
|---|
| 2682 | + |
|---|
| 2683 | + netvsc_devinfo_put(device_info); |
|---|
| 2684 | + net_device_ctx->saved_netvsc_dev_info = NULL; |
|---|
| 2685 | + |
|---|
| 2686 | + rtnl_unlock(); |
|---|
| 2687 | + |
|---|
| 2688 | + return ret; |
|---|
| 2689 | +} |
|---|
| 2413 | 2690 | static const struct hv_vmbus_device_id id_table[] = { |
|---|
| 2414 | 2691 | /* Network guid */ |
|---|
| 2415 | 2692 | { HV_NIC_GUID, }, |
|---|
| .. | .. |
|---|
| 2424 | 2701 | .id_table = id_table, |
|---|
| 2425 | 2702 | .probe = netvsc_probe, |
|---|
| 2426 | 2703 | .remove = netvsc_remove, |
|---|
| 2704 | + .suspend = netvsc_suspend, |
|---|
| 2705 | + .resume = netvsc_resume, |
|---|
| 2427 | 2706 | .driver = { |
|---|
| 2428 | 2707 | .probe_type = PROBE_FORCE_SYNCHRONOUS, |
|---|
| 2429 | 2708 | }, |
|---|
| .. | .. |
|---|
| 2464 | 2743 | return netvsc_unregister_vf(event_dev); |
|---|
| 2465 | 2744 | case NETDEV_UP: |
|---|
| 2466 | 2745 | case NETDEV_DOWN: |
|---|
| 2746 | + case NETDEV_CHANGE: |
|---|
| 2467 | 2747 | return netvsc_vf_changed(event_dev); |
|---|
| 2468 | 2748 | default: |
|---|
| 2469 | 2749 | return NOTIFY_DONE; |
|---|