hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/net/ethernet/intel/igb/igb_main.c
....@@ -30,6 +30,8 @@
3030 #include <linux/if_ether.h>
3131 #include <linux/aer.h>
3232 #include <linux/prefetch.h>
33
+#include <linux/bpf.h>
34
+#include <linux/bpf_trace.h>
3335 #include <linux/pm_runtime.h>
3436 #include <linux/etherdevice.h>
3537 #ifdef CONFIG_IGB_DCA
....@@ -37,12 +39,6 @@
3739 #endif
3840 #include <linux/i2c.h>
3941 #include "igb.h"
40
-
41
-#define MAJ 5
42
-#define MIN 4
43
-#define BUILD 0
44
-#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
45
-__stringify(BUILD) "-k"
4642
4743 enum queue_mode {
4844 QUEUE_MODE_STRICT_PRIORITY,
....@@ -55,7 +51,6 @@
5551 };
5652
5753 char igb_driver_name[] = "igb";
58
-char igb_driver_version[] = DRV_VERSION;
5954 static const char igb_driver_string[] =
6055 "Intel(R) Gigabit Ethernet Network Driver";
6156 static const char igb_copyright[] =
....@@ -146,7 +141,7 @@
146141 static bool igb_clean_tx_irq(struct igb_q_vector *, int);
147142 static int igb_clean_rx_irq(struct igb_q_vector *, int);
148143 static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
149
-static void igb_tx_timeout(struct net_device *);
144
+static void igb_tx_timeout(struct net_device *, unsigned int txqueue);
150145 static void igb_reset_task(struct work_struct *);
151146 static void igb_vlan_mode(struct net_device *netdev,
152147 netdev_features_t features);
....@@ -239,8 +234,7 @@
239234
240235 MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
241236 MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
242
-MODULE_LICENSE("GPL");
243
-MODULE_VERSION(DRV_VERSION);
237
+MODULE_LICENSE("GPL v2");
244238
245239 #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
246240 static int debug = -1;
....@@ -557,8 +551,7 @@
557551
558552 /**
559553 * igb_get_i2c_data - Reads the I2C SDA data bit
560
- * @hw: pointer to hardware structure
561
- * @i2cctl: Current value of I2CCTL register
554
+ * @data: opaque pointer to adapter struct
562555 *
563556 * Returns the I2C data bit value
564557 **/
....@@ -666,8 +659,7 @@
666659 {
667660 int ret;
668661
669
- pr_info("%s - version %s\n",
670
- igb_driver_string, igb_driver_version);
662
+ pr_info("%s\n", igb_driver_string);
671663 pr_info("%s\n", igb_copyright);
672664
673665 #ifdef CONFIG_IGB_DCA
....@@ -720,14 +712,13 @@
720712 adapter->rx_ring[i]->reg_idx = rbase_offset +
721713 Q_IDX_82576(i);
722714 }
723
- /* Fall through */
715
+ fallthrough;
724716 case e1000_82575:
725717 case e1000_82580:
726718 case e1000_i350:
727719 case e1000_i354:
728720 case e1000_i210:
729721 case e1000_i211:
730
- /* Fall through */
731722 default:
732723 for (; i < adapter->num_rx_queues; i++)
733724 adapter->rx_ring[i]->reg_idx = rbase_offset + i;
....@@ -753,6 +744,8 @@
753744 struct net_device *netdev = igb->netdev;
754745 hw->hw_addr = NULL;
755746 netdev_err(netdev, "PCIe link lost\n");
747
+ WARN(pci_device_is_present(igb->pdev),
748
+ "igb: Failed to read reg 0x%x!\n", reg);
756749 }
757750
758751 return value;
....@@ -1196,23 +1189,27 @@
11961189 {
11971190 struct igb_q_vector *q_vector;
11981191 struct igb_ring *ring;
1199
- int ring_count, size;
1192
+ int ring_count;
1193
+ size_t size;
12001194
12011195 /* igb only supports 1 Tx and/or 1 Rx queue per vector */
12021196 if (txr_count > 1 || rxr_count > 1)
12031197 return -ENOMEM;
12041198
12051199 ring_count = txr_count + rxr_count;
1206
- size = sizeof(struct igb_q_vector) +
1207
- (sizeof(struct igb_ring) * ring_count);
1200
+ size = struct_size(q_vector, ring, ring_count);
12081201
12091202 /* allocate q_vector and rings */
12101203 q_vector = adapter->q_vector[v_idx];
12111204 if (!q_vector) {
12121205 q_vector = kzalloc(size, GFP_KERNEL);
12131206 } else if (size > ksize(q_vector)) {
1214
- kfree_rcu(q_vector, rcu);
1215
- q_vector = kzalloc(size, GFP_KERNEL);
1207
+ struct igb_q_vector *new_q_vector;
1208
+
1209
+ new_q_vector = kzalloc(size, GFP_KERNEL);
1210
+ if (new_q_vector)
1211
+ kfree_rcu(q_vector, rcu);
1212
+ q_vector = new_q_vector;
12161213 } else {
12171214 memset(q_vector, 0, size);
12181215 }
....@@ -1858,13 +1855,12 @@
18581855 * configuration' in respect to these parameters.
18591856 */
18601857
1861
- netdev_dbg(netdev, "Qav Tx mode: cbs %s, launchtime %s, queue %d \
1862
- idleslope %d sendslope %d hiCredit %d \
1863
- locredit %d\n",
1864
- (ring->cbs_enable) ? "enabled" : "disabled",
1865
- (ring->launchtime_enable) ? "enabled" : "disabled", queue,
1866
- ring->idleslope, ring->sendslope, ring->hicredit,
1867
- ring->locredit);
1858
+ netdev_dbg(netdev, "Qav Tx mode: cbs %s, launchtime %s, queue %d idleslope %d sendslope %d hiCredit %d locredit %d\n",
1859
+ ring->cbs_enable ? "enabled" : "disabled",
1860
+ ring->launchtime_enable ? "enabled" : "disabled",
1861
+ queue,
1862
+ ring->idleslope, ring->sendslope,
1863
+ ring->hicredit, ring->locredit);
18681864 }
18691865
18701866 static int igb_save_txtime_params(struct igb_adapter *adapter, int queue,
....@@ -1943,7 +1939,7 @@
19431939
19441940 val = rd32(E1000_RXPBS);
19451941 val &= ~I210_RXPBSIZE_MASK;
1946
- val |= I210_RXPBSIZE_PB_32KB;
1942
+ val |= I210_RXPBSIZE_PB_30KB;
19471943 wr32(E1000_RXPBS, val);
19481944
19491945 /* Section 8.12.9 states that MAX_TPKT_SIZE from DTXMXPKTSZ
....@@ -2237,7 +2233,6 @@
22372233
22382234 void igb_reinit_locked(struct igb_adapter *adapter)
22392235 {
2240
- WARN_ON(in_interrupt());
22412236 while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
22422237 usleep_range(1000, 2000);
22432238 igb_down(adapter);
....@@ -2379,7 +2374,7 @@
23792374 adapter->ei.get_invariants(hw);
23802375 adapter->flags &= ~IGB_FLAG_MEDIA_RESET;
23812376 }
2382
- if ((mac->type == e1000_82575) &&
2377
+ if ((mac->type == e1000_82575 || mac->type == e1000_i350) &&
23832378 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
23842379 igb_enable_mas(adapter);
23852380 }
....@@ -2490,13 +2485,14 @@
24902485 else
24912486 igb_reset(adapter);
24922487
2493
- return 0;
2488
+ return 1;
24942489 }
24952490
24962491 static int igb_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
24972492 struct net_device *dev,
24982493 const unsigned char *addr, u16 vid,
2499
- u16 flags)
2494
+ u16 flags,
2495
+ struct netlink_ext_ack *extack)
25002496 {
25012497 /* guarantee we can provide a unique filter for the unicast address */
25022498 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
....@@ -2524,6 +2520,7 @@
25242520 if (unlikely(mac_hdr_len > IGB_MAX_MAC_HDR_LEN))
25252521 return features & ~(NETIF_F_HW_CSUM |
25262522 NETIF_F_SCTP_CRC |
2523
+ NETIF_F_GSO_UDP_L4 |
25272524 NETIF_F_HW_VLAN_CTAG_TX |
25282525 NETIF_F_TSO |
25292526 NETIF_F_TSO6);
....@@ -2532,6 +2529,7 @@
25322529 if (unlikely(network_hdr_len > IGB_MAX_NETWORK_HDR_LEN))
25332530 return features & ~(NETIF_F_HW_CSUM |
25342531 NETIF_F_SCTP_CRC |
2532
+ NETIF_F_GSO_UDP_L4 |
25352533 NETIF_F_TSO |
25362534 NETIF_F_TSO6);
25372535
....@@ -2586,13 +2584,15 @@
25862584 #define VLAN_PRIO_FULL_MASK (0x07)
25872585
25882586 static int igb_parse_cls_flower(struct igb_adapter *adapter,
2589
- struct tc_cls_flower_offload *f,
2587
+ struct flow_cls_offload *f,
25902588 int traffic_class,
25912589 struct igb_nfc_filter *input)
25922590 {
2591
+ struct flow_rule *rule = flow_cls_offload_flow_rule(f);
2592
+ struct flow_dissector *dissector = rule->match.dissector;
25932593 struct netlink_ext_ack *extack = f->common.extack;
25942594
2595
- if (f->dissector->used_keys &
2595
+ if (dissector->used_keys &
25962596 ~(BIT(FLOW_DISSECTOR_KEY_BASIC) |
25972597 BIT(FLOW_DISSECTOR_KEY_CONTROL) |
25982598 BIT(FLOW_DISSECTOR_KEY_ETH_ADDRS) |
....@@ -2602,78 +2602,61 @@
26022602 return -EOPNOTSUPP;
26032603 }
26042604
2605
- if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
2606
- struct flow_dissector_key_eth_addrs *key, *mask;
2605
+ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
2606
+ struct flow_match_eth_addrs match;
26072607
2608
- key = skb_flow_dissector_target(f->dissector,
2609
- FLOW_DISSECTOR_KEY_ETH_ADDRS,
2610
- f->key);
2611
- mask = skb_flow_dissector_target(f->dissector,
2612
- FLOW_DISSECTOR_KEY_ETH_ADDRS,
2613
- f->mask);
2614
-
2615
- if (!is_zero_ether_addr(mask->dst)) {
2616
- if (!is_broadcast_ether_addr(mask->dst)) {
2608
+ flow_rule_match_eth_addrs(rule, &match);
2609
+ if (!is_zero_ether_addr(match.mask->dst)) {
2610
+ if (!is_broadcast_ether_addr(match.mask->dst)) {
26172611 NL_SET_ERR_MSG_MOD(extack, "Only full masks are supported for destination MAC address");
26182612 return -EINVAL;
26192613 }
26202614
26212615 input->filter.match_flags |=
26222616 IGB_FILTER_FLAG_DST_MAC_ADDR;
2623
- ether_addr_copy(input->filter.dst_addr, key->dst);
2617
+ ether_addr_copy(input->filter.dst_addr, match.key->dst);
26242618 }
26252619
2626
- if (!is_zero_ether_addr(mask->src)) {
2627
- if (!is_broadcast_ether_addr(mask->src)) {
2620
+ if (!is_zero_ether_addr(match.mask->src)) {
2621
+ if (!is_broadcast_ether_addr(match.mask->src)) {
26282622 NL_SET_ERR_MSG_MOD(extack, "Only full masks are supported for source MAC address");
26292623 return -EINVAL;
26302624 }
26312625
26322626 input->filter.match_flags |=
26332627 IGB_FILTER_FLAG_SRC_MAC_ADDR;
2634
- ether_addr_copy(input->filter.src_addr, key->src);
2628
+ ether_addr_copy(input->filter.src_addr, match.key->src);
26352629 }
26362630 }
26372631
2638
- if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_BASIC)) {
2639
- struct flow_dissector_key_basic *key, *mask;
2632
+ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
2633
+ struct flow_match_basic match;
26402634
2641
- key = skb_flow_dissector_target(f->dissector,
2642
- FLOW_DISSECTOR_KEY_BASIC,
2643
- f->key);
2644
- mask = skb_flow_dissector_target(f->dissector,
2645
- FLOW_DISSECTOR_KEY_BASIC,
2646
- f->mask);
2647
-
2648
- if (mask->n_proto) {
2649
- if (mask->n_proto != ETHER_TYPE_FULL_MASK) {
2635
+ flow_rule_match_basic(rule, &match);
2636
+ if (match.mask->n_proto) {
2637
+ if (match.mask->n_proto != ETHER_TYPE_FULL_MASK) {
26502638 NL_SET_ERR_MSG_MOD(extack, "Only full mask is supported for EtherType filter");
26512639 return -EINVAL;
26522640 }
26532641
26542642 input->filter.match_flags |= IGB_FILTER_FLAG_ETHER_TYPE;
2655
- input->filter.etype = key->n_proto;
2643
+ input->filter.etype = match.key->n_proto;
26562644 }
26572645 }
26582646
2659
- if (dissector_uses_key(f->dissector, FLOW_DISSECTOR_KEY_VLAN)) {
2660
- struct flow_dissector_key_vlan *key, *mask;
2647
+ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
2648
+ struct flow_match_vlan match;
26612649
2662
- key = skb_flow_dissector_target(f->dissector,
2663
- FLOW_DISSECTOR_KEY_VLAN,
2664
- f->key);
2665
- mask = skb_flow_dissector_target(f->dissector,
2666
- FLOW_DISSECTOR_KEY_VLAN,
2667
- f->mask);
2668
-
2669
- if (mask->vlan_priority) {
2670
- if (mask->vlan_priority != VLAN_PRIO_FULL_MASK) {
2650
+ flow_rule_match_vlan(rule, &match);
2651
+ if (match.mask->vlan_priority) {
2652
+ if (match.mask->vlan_priority != VLAN_PRIO_FULL_MASK) {
26712653 NL_SET_ERR_MSG_MOD(extack, "Only full mask is supported for VLAN priority");
26722654 return -EINVAL;
26732655 }
26742656
26752657 input->filter.match_flags |= IGB_FILTER_FLAG_VLAN_TCI;
2676
- input->filter.vlan_tci = key->vlan_priority;
2658
+ input->filter.vlan_tci =
2659
+ (__force __be16)match.key->vlan_priority;
26772660 }
26782661 }
26792662
....@@ -2684,7 +2667,7 @@
26842667 }
26852668
26862669 static int igb_configure_clsflower(struct igb_adapter *adapter,
2687
- struct tc_cls_flower_offload *cls_flower)
2670
+ struct flow_cls_offload *cls_flower)
26882671 {
26892672 struct netlink_ext_ack *extack = cls_flower->common.extack;
26902673 struct igb_nfc_filter *filter, *f;
....@@ -2746,7 +2729,7 @@
27462729 }
27472730
27482731 static int igb_delete_clsflower(struct igb_adapter *adapter,
2749
- struct tc_cls_flower_offload *cls_flower)
2732
+ struct flow_cls_offload *cls_flower)
27502733 {
27512734 struct igb_nfc_filter *filter;
27522735 int err;
....@@ -2776,14 +2759,14 @@
27762759 }
27772760
27782761 static int igb_setup_tc_cls_flower(struct igb_adapter *adapter,
2779
- struct tc_cls_flower_offload *cls_flower)
2762
+ struct flow_cls_offload *cls_flower)
27802763 {
27812764 switch (cls_flower->command) {
2782
- case TC_CLSFLOWER_REPLACE:
2765
+ case FLOW_CLS_REPLACE:
27832766 return igb_configure_clsflower(adapter, cls_flower);
2784
- case TC_CLSFLOWER_DESTROY:
2767
+ case FLOW_CLS_DESTROY:
27852768 return igb_delete_clsflower(adapter, cls_flower);
2786
- case TC_CLSFLOWER_STATS:
2769
+ case FLOW_CLS_STATS:
27872770 return -EOPNOTSUPP;
27882771 default:
27892772 return -EOPNOTSUPP;
....@@ -2802,25 +2785,6 @@
28022785 case TC_SETUP_CLSFLOWER:
28032786 return igb_setup_tc_cls_flower(adapter, type_data);
28042787
2805
- default:
2806
- return -EOPNOTSUPP;
2807
- }
2808
-}
2809
-
2810
-static int igb_setup_tc_block(struct igb_adapter *adapter,
2811
- struct tc_block_offload *f)
2812
-{
2813
- if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
2814
- return -EOPNOTSUPP;
2815
-
2816
- switch (f->command) {
2817
- case TC_BLOCK_BIND:
2818
- return tcf_block_cb_register(f->block, igb_setup_tc_block_cb,
2819
- adapter, adapter, f->extack);
2820
- case TC_BLOCK_UNBIND:
2821
- tcf_block_cb_unregister(f->block, igb_setup_tc_block_cb,
2822
- adapter);
2823
- return 0;
28242788 default:
28252789 return -EOPNOTSUPP;
28262790 }
....@@ -2849,6 +2813,8 @@
28492813 return 0;
28502814 }
28512815
2816
+static LIST_HEAD(igb_block_cb_list);
2817
+
28522818 static int igb_setup_tc(struct net_device *dev, enum tc_setup_type type,
28532819 void *type_data)
28542820 {
....@@ -2858,13 +2824,168 @@
28582824 case TC_SETUP_QDISC_CBS:
28592825 return igb_offload_cbs(adapter, type_data);
28602826 case TC_SETUP_BLOCK:
2861
- return igb_setup_tc_block(adapter, type_data);
2827
+ return flow_block_cb_setup_simple(type_data,
2828
+ &igb_block_cb_list,
2829
+ igb_setup_tc_block_cb,
2830
+ adapter, adapter, true);
2831
+
28622832 case TC_SETUP_QDISC_ETF:
28632833 return igb_offload_txtime(adapter, type_data);
28642834
28652835 default:
28662836 return -EOPNOTSUPP;
28672837 }
2838
+}
2839
+
2840
+static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)
2841
+{
2842
+ int i, frame_size = dev->mtu + IGB_ETH_PKT_HDR_PAD;
2843
+ struct igb_adapter *adapter = netdev_priv(dev);
2844
+ struct bpf_prog *prog = bpf->prog, *old_prog;
2845
+ bool running = netif_running(dev);
2846
+ bool need_reset;
2847
+
2848
+ /* verify igb ring attributes are sufficient for XDP */
2849
+ for (i = 0; i < adapter->num_rx_queues; i++) {
2850
+ struct igb_ring *ring = adapter->rx_ring[i];
2851
+
2852
+ if (frame_size > igb_rx_bufsz(ring)) {
2853
+ NL_SET_ERR_MSG_MOD(bpf->extack,
2854
+ "The RX buffer size is too small for the frame size");
2855
+ netdev_warn(dev, "XDP RX buffer size %d is too small for the frame size %d\n",
2856
+ igb_rx_bufsz(ring), frame_size);
2857
+ return -EINVAL;
2858
+ }
2859
+ }
2860
+
2861
+ old_prog = xchg(&adapter->xdp_prog, prog);
2862
+ need_reset = (!!prog != !!old_prog);
2863
+
2864
+ /* device is up and bpf is added/removed, must setup the RX queues */
2865
+ if (need_reset && running) {
2866
+ igb_close(dev);
2867
+ } else {
2868
+ for (i = 0; i < adapter->num_rx_queues; i++)
2869
+ (void)xchg(&adapter->rx_ring[i]->xdp_prog,
2870
+ adapter->xdp_prog);
2871
+ }
2872
+
2873
+ if (old_prog)
2874
+ bpf_prog_put(old_prog);
2875
+
2876
+ /* bpf is just replaced, RXQ and MTU are already setup */
2877
+ if (!need_reset)
2878
+ return 0;
2879
+
2880
+ if (running)
2881
+ igb_open(dev);
2882
+
2883
+ return 0;
2884
+}
2885
+
2886
+static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp)
2887
+{
2888
+ switch (xdp->command) {
2889
+ case XDP_SETUP_PROG:
2890
+ return igb_xdp_setup(dev, xdp);
2891
+ default:
2892
+ return -EINVAL;
2893
+ }
2894
+}
2895
+
2896
+static void igb_xdp_ring_update_tail(struct igb_ring *ring)
2897
+{
2898
+ /* Force memory writes to complete before letting h/w know there
2899
+ * are new descriptors to fetch.
2900
+ */
2901
+ wmb();
2902
+ writel(ring->next_to_use, ring->tail);
2903
+}
2904
+
2905
+static struct igb_ring *igb_xdp_tx_queue_mapping(struct igb_adapter *adapter)
2906
+{
2907
+ unsigned int r_idx = smp_processor_id();
2908
+
2909
+ if (r_idx >= adapter->num_tx_queues)
2910
+ r_idx = r_idx % adapter->num_tx_queues;
2911
+
2912
+ return adapter->tx_ring[r_idx];
2913
+}
2914
+
2915
+static int igb_xdp_xmit_back(struct igb_adapter *adapter, struct xdp_buff *xdp)
2916
+{
2917
+ struct xdp_frame *xdpf = xdp_convert_buff_to_frame(xdp);
2918
+ int cpu = smp_processor_id();
2919
+ struct igb_ring *tx_ring;
2920
+ struct netdev_queue *nq;
2921
+ u32 ret;
2922
+
2923
+ if (unlikely(!xdpf))
2924
+ return IGB_XDP_CONSUMED;
2925
+
2926
+ /* During program transitions its possible adapter->xdp_prog is assigned
2927
+ * but ring has not been configured yet. In this case simply abort xmit.
2928
+ */
2929
+ tx_ring = adapter->xdp_prog ? igb_xdp_tx_queue_mapping(adapter) : NULL;
2930
+ if (unlikely(!tx_ring))
2931
+ return IGB_XDP_CONSUMED;
2932
+
2933
+ nq = txring_txq(tx_ring);
2934
+ __netif_tx_lock(nq, cpu);
2935
+ /* Avoid transmit queue timeout since we share it with the slow path */
2936
+ nq->trans_start = jiffies;
2937
+ ret = igb_xmit_xdp_ring(adapter, tx_ring, xdpf);
2938
+ __netif_tx_unlock(nq);
2939
+
2940
+ return ret;
2941
+}
2942
+
2943
+static int igb_xdp_xmit(struct net_device *dev, int n,
2944
+ struct xdp_frame **frames, u32 flags)
2945
+{
2946
+ struct igb_adapter *adapter = netdev_priv(dev);
2947
+ int cpu = smp_processor_id();
2948
+ struct igb_ring *tx_ring;
2949
+ struct netdev_queue *nq;
2950
+ int drops = 0;
2951
+ int i;
2952
+
2953
+ if (unlikely(test_bit(__IGB_DOWN, &adapter->state)))
2954
+ return -ENETDOWN;
2955
+
2956
+ if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
2957
+ return -EINVAL;
2958
+
2959
+ /* During program transitions its possible adapter->xdp_prog is assigned
2960
+ * but ring has not been configured yet. In this case simply abort xmit.
2961
+ */
2962
+ tx_ring = adapter->xdp_prog ? igb_xdp_tx_queue_mapping(adapter) : NULL;
2963
+ if (unlikely(!tx_ring))
2964
+ return -ENXIO;
2965
+
2966
+ nq = txring_txq(tx_ring);
2967
+ __netif_tx_lock(nq, cpu);
2968
+
2969
+ /* Avoid transmit queue timeout since we share it with the slow path */
2970
+ nq->trans_start = jiffies;
2971
+
2972
+ for (i = 0; i < n; i++) {
2973
+ struct xdp_frame *xdpf = frames[i];
2974
+ int err;
2975
+
2976
+ err = igb_xmit_xdp_ring(adapter, tx_ring, xdpf);
2977
+ if (err != IGB_XDP_TX) {
2978
+ xdp_return_frame_rx_napi(xdpf);
2979
+ drops++;
2980
+ }
2981
+ }
2982
+
2983
+ __netif_tx_unlock(nq);
2984
+
2985
+ if (unlikely(flags & XDP_XMIT_FLUSH))
2986
+ igb_xdp_ring_update_tail(tx_ring);
2987
+
2988
+ return n - drops;
28682989 }
28692990
28702991 static const struct net_device_ops igb_netdev_ops = {
....@@ -2891,6 +3012,8 @@
28913012 .ndo_fdb_add = igb_ndo_fdb_add,
28923013 .ndo_features_check = igb_features_check,
28933014 .ndo_setup_tc = igb_setup_tc,
3015
+ .ndo_bpf = igb_xdp,
3016
+ .ndo_xdp_xmit = igb_xdp_xmit,
28943017 };
28953018
28963019 /**
....@@ -2915,7 +3038,7 @@
29153038 fw.invm_img_type);
29163039 break;
29173040 }
2918
- /* fall through */
3041
+ fallthrough;
29193042 default:
29203043 /* if option is rom valid, display its version too */
29213044 if (fw.or_valid) {
....@@ -3157,7 +3280,7 @@
31573280 NETIF_F_HW_CSUM;
31583281
31593282 if (hw->mac.type >= e1000_82576)
3160
- netdev->features |= NETIF_F_SCTP_CRC;
3283
+ netdev->features |= NETIF_F_SCTP_CRC | NETIF_F_GSO_UDP_L4;
31613284
31623285 if (hw->mac.type >= e1000_i350)
31633286 netdev->features |= NETIF_F_HW_TC;
....@@ -3431,7 +3554,9 @@
34313554 "Width x1" : "unknown"), netdev->dev_addr);
34323555 }
34333556
3434
- if ((hw->mac.type >= e1000_i210 ||
3557
+ if ((hw->mac.type == e1000_82576 &&
3558
+ rd32(E1000_EECD) & E1000_EECD_PRES) ||
3559
+ (hw->mac.type >= e1000_i210 ||
34353560 igb_get_flash_presence_i210(hw))) {
34363561 ret_val = igb_read_part_string(hw, part_str,
34373562 E1000_PBANUM_LENGTH);
....@@ -3478,7 +3603,7 @@
34783603 }
34793604 }
34803605
3481
- dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NEVER_SKIP);
3606
+ dev_pm_set_driver_flags(&pdev->dev, DPM_FLAG_NO_DIRECT_COMPLETE);
34823607
34833608 pm_runtime_put_noidle(&pdev->dev);
34843609 return 0;
....@@ -3517,6 +3642,7 @@
35173642 struct net_device *netdev = pci_get_drvdata(pdev);
35183643 struct igb_adapter *adapter = netdev_priv(netdev);
35193644 struct e1000_hw *hw = &adapter->hw;
3645
+ unsigned long flags;
35203646
35213647 /* reclaim resources allocated to VFs */
35223648 if (adapter->vf_data) {
....@@ -3529,12 +3655,13 @@
35293655 pci_disable_sriov(pdev);
35303656 msleep(500);
35313657 }
3532
-
3658
+ spin_lock_irqsave(&adapter->vfs_lock, flags);
35333659 kfree(adapter->vf_mac_list);
35343660 adapter->vf_mac_list = NULL;
35353661 kfree(adapter->vf_data);
35363662 adapter->vf_data = NULL;
35373663 adapter->vfs_allocated_count = 0;
3664
+ spin_unlock_irqrestore(&adapter->vfs_lock, flags);
35383665 wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
35393666 wrfl();
35403667 msleep(100);
....@@ -3730,8 +3857,9 @@
37303857 struct pci_dev *pdev = adapter->pdev;
37313858 struct e1000_hw *hw = &adapter->hw;
37323859
3733
- /* Virtualization features not supported on i210 family. */
3734
- if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211))
3860
+ /* Virtualization features not supported on i210 and 82580 family. */
3861
+ if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211) ||
3862
+ (hw->mac.type == e1000_82580))
37353863 return;
37363864
37373865 /* Of the below we really only want the effect of getting
....@@ -3767,13 +3895,13 @@
37673895 max_rss_queues = 1;
37683896 break;
37693897 }
3770
- /* fall through */
3898
+ fallthrough;
37713899 case e1000_82576:
37723900 if (!!adapter->vfs_allocated_count) {
37733901 max_rss_queues = 2;
37743902 break;
37753903 }
3776
- /* fall through */
3904
+ fallthrough;
37773905 case e1000_82580:
37783906 case e1000_i354:
37793907 default:
....@@ -3849,12 +3977,14 @@
38493977 /* set default work limits */
38503978 adapter->tx_work_limit = IGB_DEFAULT_TX_WORK;
38513979
3852
- adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN +
3853
- VLAN_HLEN;
3980
+ adapter->max_frame_size = netdev->mtu + IGB_ETH_PKT_HDR_PAD;
38543981 adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
38553982
38563983 spin_lock_init(&adapter->nfc_lock);
38573984 spin_lock_init(&adapter->stats64_lock);
3985
+
3986
+ /* init spinlock to avoid concurrency of VF resources */
3987
+ spin_lock_init(&adapter->vfs_lock);
38583988 #ifdef CONFIG_PCI_IOV
38593989 switch (hw->mac.type) {
38603990 case e1000_82576:
....@@ -3912,6 +4042,7 @@
39124042 /**
39134043 * igb_open - Called when a network interface is made active
39144044 * @netdev: network interface device structure
4045
+ * @resuming: indicates whether we are in a resume call
39154046 *
39164047 * Returns 0 on success, negative value on failure
39174048 *
....@@ -4029,6 +4160,7 @@
40294160 /**
40304161 * igb_close - Disables a network interface
40314162 * @netdev: network interface device structure
4163
+ * @suspending: indicates we are in a suspend call
40324164 *
40334165 * Returns 0, this is not allowed to fail
40344166 *
....@@ -4222,6 +4354,7 @@
42224354 **/
42234355 int igb_setup_rx_resources(struct igb_ring *rx_ring)
42244356 {
4357
+ struct igb_adapter *adapter = netdev_priv(rx_ring->netdev);
42254358 struct device *dev = rx_ring->dev;
42264359 int size;
42274360
....@@ -4243,6 +4376,13 @@
42434376 rx_ring->next_to_alloc = 0;
42444377 rx_ring->next_to_clean = 0;
42454378 rx_ring->next_to_use = 0;
4379
+
4380
+ rx_ring->xdp_prog = adapter->xdp_prog;
4381
+
4382
+ /* XDP RX-queue info */
4383
+ if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, rx_ring->netdev,
4384
+ rx_ring->queue_index) < 0)
4385
+ goto err;
42464386
42474387 return 0;
42484388
....@@ -4362,8 +4502,7 @@
43624502 else
43634503 mrqc |= E1000_MRQC_ENABLE_VMDQ;
43644504 } else {
4365
- if (hw->mac.type != e1000_i211)
4366
- mrqc |= E1000_MRQC_ENABLE_RSS_MQ;
4505
+ mrqc |= E1000_MRQC_ENABLE_RSS_MQ;
43674506 }
43684507 igb_vmm_control(adapter);
43694508
....@@ -4502,6 +4641,37 @@
45024641 }
45034642
45044643 /**
4644
+ * igb_setup_srrctl - configure the split and replication receive control
4645
+ * registers
4646
+ * @adapter: Board private structure
4647
+ * @ring: receive ring to be configured
4648
+ **/
4649
+void igb_setup_srrctl(struct igb_adapter *adapter, struct igb_ring *ring)
4650
+{
4651
+ struct e1000_hw *hw = &adapter->hw;
4652
+ int reg_idx = ring->reg_idx;
4653
+ u32 srrctl = 0;
4654
+
4655
+ srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
4656
+ if (ring_uses_large_buffer(ring))
4657
+ srrctl |= IGB_RXBUFFER_3072 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
4658
+ else
4659
+ srrctl |= IGB_RXBUFFER_2048 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
4660
+ srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
4661
+ if (hw->mac.type >= e1000_82580)
4662
+ srrctl |= E1000_SRRCTL_TIMESTAMP;
4663
+ /* Only set Drop Enable if VFs allocated, or we are supporting multiple
4664
+ * queues and rx flow control is disabled
4665
+ */
4666
+ if (adapter->vfs_allocated_count ||
4667
+ (!(hw->fc.current_mode & e1000_fc_rx_pause) &&
4668
+ adapter->num_rx_queues > 1))
4669
+ srrctl |= E1000_SRRCTL_DROP_EN;
4670
+
4671
+ wr32(E1000_SRRCTL(reg_idx), srrctl);
4672
+}
4673
+
4674
+/**
45054675 * igb_configure_rx_ring - Configure a receive ring after Reset
45064676 * @adapter: board private structure
45074677 * @ring: receive ring to be configured
....@@ -4515,7 +4685,11 @@
45154685 union e1000_adv_rx_desc *rx_desc;
45164686 u64 rdba = ring->dma;
45174687 int reg_idx = ring->reg_idx;
4518
- u32 srrctl = 0, rxdctl = 0;
4688
+ u32 rxdctl = 0;
4689
+
4690
+ xdp_rxq_info_unreg_mem_model(&ring->xdp_rxq);
4691
+ WARN_ON(xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
4692
+ MEM_TYPE_PAGE_SHARED, NULL));
45194693
45204694 /* disable the queue */
45214695 wr32(E1000_RXDCTL(reg_idx), 0);
....@@ -4533,19 +4707,7 @@
45334707 writel(0, ring->tail);
45344708
45354709 /* set descriptor configuration */
4536
- srrctl = IGB_RX_HDR_LEN << E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
4537
- if (ring_uses_large_buffer(ring))
4538
- srrctl |= IGB_RXBUFFER_3072 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
4539
- else
4540
- srrctl |= IGB_RXBUFFER_2048 >> E1000_SRRCTL_BSIZEPKT_SHIFT;
4541
- srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
4542
- if (hw->mac.type >= e1000_82580)
4543
- srrctl |= E1000_SRRCTL_TIMESTAMP;
4544
- /* Only set Drop Enable if we are supporting multiple queues */
4545
- if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
4546
- srrctl |= E1000_SRRCTL_DROP_EN;
4547
-
4548
- wr32(E1000_SRRCTL(reg_idx), srrctl);
4710
+ igb_setup_srrctl(adapter, ring);
45494711
45504712 /* set filtering for VMDQ pools */
45514713 igb_set_vmolr(adapter, reg_idx & 0x7, true);
....@@ -4570,6 +4732,10 @@
45704732 static void igb_set_rx_buffer_len(struct igb_adapter *adapter,
45714733 struct igb_ring *rx_ring)
45724734 {
4735
+#if (PAGE_SIZE < 8192)
4736
+ struct e1000_hw *hw = &adapter->hw;
4737
+#endif
4738
+
45734739 /* set build_skb and buffer size flags */
45744740 clear_ring_build_skb_enabled(rx_ring);
45754741 clear_ring_uses_large_buffer(rx_ring);
....@@ -4580,10 +4746,9 @@
45804746 set_ring_build_skb_enabled(rx_ring);
45814747
45824748 #if (PAGE_SIZE < 8192)
4583
- if (adapter->max_frame_size <= IGB_MAX_FRAME_BUILD_SKB)
4584
- return;
4585
-
4586
- set_ring_uses_large_buffer(rx_ring);
4749
+ if (adapter->max_frame_size > IGB_MAX_FRAME_BUILD_SKB ||
4750
+ rd32(E1000_RCTL) & E1000_RCTL_SBP)
4751
+ set_ring_uses_large_buffer(rx_ring);
45874752 #endif
45884753 }
45894754
....@@ -4661,8 +4826,11 @@
46614826 while (i != tx_ring->next_to_use) {
46624827 union e1000_adv_tx_desc *eop_desc, *tx_desc;
46634828
4664
- /* Free all the Tx ring sk_buffs */
4665
- dev_kfree_skb_any(tx_buffer->skb);
4829
+ /* Free all the Tx ring sk_buffs or xdp frames */
4830
+ if (tx_buffer->type == IGB_TYPE_SKB)
4831
+ dev_kfree_skb_any(tx_buffer->skb);
4832
+ else
4833
+ xdp_return_frame(tx_buffer->xdpf);
46664834
46674835 /* unmap skb header data */
46684836 dma_unmap_single(tx_ring->dev,
....@@ -4735,6 +4903,8 @@
47354903 {
47364904 igb_clean_rx_ring(rx_ring);
47374905
4906
+ rx_ring->xdp_prog = NULL;
4907
+ xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
47384908 vfree(rx_ring->rx_buffer_info);
47394909 rx_ring->rx_buffer_info = NULL;
47404910
....@@ -4771,8 +4941,7 @@
47714941 {
47724942 u16 i = rx_ring->next_to_clean;
47734943
4774
- if (rx_ring->skb)
4775
- dev_kfree_skb(rx_ring->skb);
4944
+ dev_kfree_skb(rx_ring->skb);
47764945 rx_ring->skb = NULL;
47774946
47784947 /* Free all the Rx ring sk_buffs */
....@@ -4896,14 +5065,14 @@
48965065 /* VLAN filtering needed for VLAN prio filter */
48975066 if (adapter->netdev->features & NETIF_F_NTUPLE)
48985067 break;
4899
- /* fall through */
5068
+ fallthrough;
49005069 case e1000_82576:
49015070 case e1000_82580:
49025071 case e1000_i354:
49035072 /* VLAN filtering needed for pool filtering */
49045073 if (adapter->vfs_allocated_count)
49055074 break;
4906
- /* fall through */
5075
+ fallthrough;
49075076 default:
49085077 return 1;
49095078 }
....@@ -5183,7 +5352,7 @@
51835352 case e1000_media_type_copper:
51845353 if (!hw->mac.get_link_status)
51855354 return true;
5186
- /* fall through */
5355
+ fallthrough;
51875356 case e1000_media_type_internal_serdes:
51885357 hw->mac.ops.check_for_link(hw);
51895358 link_active = !hw->mac.get_link_status;
....@@ -5247,7 +5416,7 @@
52475416
52485417 /**
52495418 * igb_watchdog - Timer Call-back
5250
- * @data: pointer to adapter cast into an unsigned long
5419
+ * @t: pointer to timer_list containing our private info pointer
52515420 **/
52525421 static void igb_watchdog(struct timer_list *t)
52535422 {
....@@ -5346,7 +5515,8 @@
53465515 break;
53475516 }
53485517
5349
- if (adapter->link_speed != SPEED_1000)
5518
+ if (adapter->link_speed != SPEED_1000 ||
5519
+ !hw->phy.ops.read_reg)
53505520 goto no_wait;
53515521
53525522 /* wait for Remote receiver status OK */
....@@ -5714,8 +5884,8 @@
57145884 * should have been handled by the upper layers.
57155885 */
57165886 if (tx_ring->launchtime_enable) {
5717
- ts = ns_to_timespec64(first->skb->tstamp);
5718
- first->skb->tstamp = 0;
5887
+ ts = ktime_to_timespec64(first->skb->tstamp);
5888
+ skb_txtime_consumed(first->skb);
57195889 context_desc->seqnum_seed = cpu_to_le32(ts.tv_nsec / 32);
57205890 } else {
57215891 context_desc->seqnum_seed = 0;
....@@ -5735,6 +5905,7 @@
57355905 } ip;
57365906 union {
57375907 struct tcphdr *tcp;
5908
+ struct udphdr *udp;
57385909 unsigned char *hdr;
57395910 } l4;
57405911 u32 paylen, l4_offset;
....@@ -5754,7 +5925,8 @@
57545925 l4.hdr = skb_checksum_start(skb);
57555926
57565927 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
5757
- type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5928
+ type_tucmd = (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) ?
5929
+ E1000_ADVTXD_TUCMD_L4T_UDP : E1000_ADVTXD_TUCMD_L4T_TCP;
57585930
57595931 /* initialize outer IP header fields */
57605932 if (ip.v4->version == 4) {
....@@ -5782,12 +5954,19 @@
57825954 /* determine offset of inner transport header */
57835955 l4_offset = l4.hdr - skb->data;
57845956
5785
- /* compute length of segmentation header */
5786
- *hdr_len = (l4.tcp->doff * 4) + l4_offset;
5787
-
57885957 /* remove payload length from inner checksum */
57895958 paylen = skb->len - l4_offset;
5790
- csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
5959
+ if (type_tucmd & E1000_ADVTXD_TUCMD_L4T_TCP) {
5960
+ /* compute length of segmentation header */
5961
+ *hdr_len = (l4.tcp->doff * 4) + l4_offset;
5962
+ csum_replace_by_diff(&l4.tcp->check,
5963
+ (__force __wsum)htonl(paylen));
5964
+ } else {
5965
+ /* compute length of segmentation header */
5966
+ *hdr_len = sizeof(*l4.udp) + l4_offset;
5967
+ csum_replace_by_diff(&l4.udp->check,
5968
+ (__force __wsum)htonl(paylen));
5969
+ }
57915970
57925971 /* update gso size and bytecount with header size */
57935972 first->gso_segs = skb_shinfo(skb)->gso_segs;
....@@ -5834,7 +6013,7 @@
58346013 switch (skb->csum_offset) {
58356014 case offsetof(struct tcphdr, check):
58366015 type_tucmd = E1000_ADVTXD_TUCMD_L4T_TCP;
5837
- /* fall through */
6016
+ fallthrough;
58386017 case offsetof(struct udphdr, check):
58396018 break;
58406019 case offsetof(struct sctphdr, checksum):
....@@ -5846,7 +6025,7 @@
58466025 type_tucmd = E1000_ADVTXD_TUCMD_L4T_SCTP;
58476026 break;
58486027 }
5849
- /* fall through */
6028
+ fallthrough;
58506029 default:
58516030 skb_checksum_help(skb);
58526031 goto csum_failed;
....@@ -5958,7 +6137,7 @@
59586137 struct sk_buff *skb = first->skb;
59596138 struct igb_tx_buffer *tx_buffer;
59606139 union e1000_adv_tx_desc *tx_desc;
5961
- struct skb_frag_struct *frag;
6140
+ skb_frag_t *frag;
59626141 dma_addr_t dma;
59636142 unsigned int data_len, size;
59646143 u32 tx_flags = first->tx_flags;
....@@ -6035,6 +6214,8 @@
60356214 /* set the timestamp */
60366215 first->time_stamp = jiffies;
60376216
6217
+ skb_tx_timestamp(skb);
6218
+
60386219 /* Force memory writes to complete before letting h/w know there
60396220 * are new descriptors to fetch. (Only applicable for weak-ordered
60406221 * memory model archs, such as IA-64).
....@@ -6056,13 +6237,8 @@
60566237 /* Make sure there is space in the ring for the next send. */
60576238 igb_maybe_stop_tx(tx_ring, DESC_NEEDED);
60586239
6059
- if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
6240
+ if (netif_xmit_stopped(txring_txq(tx_ring)) || !netdev_xmit_more()) {
60606241 writel(i, tx_ring->tail);
6061
-
6062
- /* we need this if more than one processor can write to our tail
6063
- * at a time, it synchronizes IO on IA64/Altix systems
6064
- */
6065
- mmiowb();
60666242 }
60676243 return 0;
60686244
....@@ -6099,6 +6275,80 @@
60996275 return -1;
61006276 }
61016277
6278
+int igb_xmit_xdp_ring(struct igb_adapter *adapter,
6279
+ struct igb_ring *tx_ring,
6280
+ struct xdp_frame *xdpf)
6281
+{
6282
+ union e1000_adv_tx_desc *tx_desc;
6283
+ u32 len, cmd_type, olinfo_status;
6284
+ struct igb_tx_buffer *tx_buffer;
6285
+ dma_addr_t dma;
6286
+ u16 i;
6287
+
6288
+ len = xdpf->len;
6289
+
6290
+ if (unlikely(!igb_desc_unused(tx_ring)))
6291
+ return IGB_XDP_CONSUMED;
6292
+
6293
+ dma = dma_map_single(tx_ring->dev, xdpf->data, len, DMA_TO_DEVICE);
6294
+ if (dma_mapping_error(tx_ring->dev, dma))
6295
+ return IGB_XDP_CONSUMED;
6296
+
6297
+ /* record the location of the first descriptor for this packet */
6298
+ tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6299
+ tx_buffer->bytecount = len;
6300
+ tx_buffer->gso_segs = 1;
6301
+ tx_buffer->protocol = 0;
6302
+
6303
+ i = tx_ring->next_to_use;
6304
+ tx_desc = IGB_TX_DESC(tx_ring, i);
6305
+
6306
+ dma_unmap_len_set(tx_buffer, len, len);
6307
+ dma_unmap_addr_set(tx_buffer, dma, dma);
6308
+ tx_buffer->type = IGB_TYPE_XDP;
6309
+ tx_buffer->xdpf = xdpf;
6310
+
6311
+ tx_desc->read.buffer_addr = cpu_to_le64(dma);
6312
+
6313
+ /* put descriptor type bits */
6314
+ cmd_type = E1000_ADVTXD_DTYP_DATA |
6315
+ E1000_ADVTXD_DCMD_DEXT |
6316
+ E1000_ADVTXD_DCMD_IFCS;
6317
+ cmd_type |= len | IGB_TXD_DCMD;
6318
+ tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
6319
+
6320
+ olinfo_status = len << E1000_ADVTXD_PAYLEN_SHIFT;
6321
+ /* 82575 requires a unique index per ring */
6322
+ if (test_bit(IGB_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
6323
+ olinfo_status |= tx_ring->reg_idx << 4;
6324
+
6325
+ tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
6326
+
6327
+ netdev_tx_sent_queue(txring_txq(tx_ring), tx_buffer->bytecount);
6328
+
6329
+ /* set the timestamp */
6330
+ tx_buffer->time_stamp = jiffies;
6331
+
6332
+ /* Avoid any potential race with xdp_xmit and cleanup */
6333
+ smp_wmb();
6334
+
6335
+ /* set next_to_watch value indicating a packet is present */
6336
+ i++;
6337
+ if (i == tx_ring->count)
6338
+ i = 0;
6339
+
6340
+ tx_buffer->next_to_watch = tx_desc;
6341
+ tx_ring->next_to_use = i;
6342
+
6343
+ /* Make sure there is space in the ring for the next send. */
6344
+ igb_maybe_stop_tx(tx_ring, DESC_NEEDED);
6345
+
6346
+ if (netif_xmit_stopped(txring_txq(tx_ring)) || !netdev_xmit_more())
6347
+ writel(i, tx_ring->tail);
6348
+
6349
+ return IGB_XDP_TX;
6350
+}
6351
+
61026352 netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,
61036353 struct igb_ring *tx_ring)
61046354 {
....@@ -6117,7 +6367,8 @@
61176367 * otherwise try next time
61186368 */
61196369 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6120
- count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6370
+ count += TXD_USE_COUNT(skb_frag_size(
6371
+ &skb_shinfo(skb)->frags[f]));
61216372
61226373 if (igb_maybe_stop_tx(tx_ring, count + 3)) {
61236374 /* this is a hard error */
....@@ -6126,6 +6377,7 @@
61266377
61276378 /* record the location of the first descriptor for this packet */
61286379 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
6380
+ first->type = IGB_TYPE_SKB;
61296381 first->skb = skb;
61306382 first->bytecount = skb->len;
61316383 first->gso_segs = 1;
....@@ -6162,8 +6414,6 @@
61626414 goto out_drop;
61636415 else if (!tso)
61646416 igb_tx_csum(tx_ring, first);
6165
-
6166
- skb_tx_timestamp(skb);
61676417
61686418 if (igb_tx_map(tx_ring, first, hdr_len))
61696419 goto cleanup_tx_tstamp;
....@@ -6215,8 +6465,9 @@
62156465 /**
62166466 * igb_tx_timeout - Respond to a Tx Hang
62176467 * @netdev: network interface device structure
6468
+ * @txqueue: number of the Tx queue that hung (unused)
62186469 **/
6219
-static void igb_tx_timeout(struct net_device *netdev)
6470
+static void igb_tx_timeout(struct net_device *netdev, unsigned int __always_unused txqueue)
62206471 {
62216472 struct igb_adapter *adapter = netdev_priv(netdev);
62226473 struct e1000_hw *hw = &adapter->hw;
....@@ -6277,8 +6528,22 @@
62776528 static int igb_change_mtu(struct net_device *netdev, int new_mtu)
62786529 {
62796530 struct igb_adapter *adapter = netdev_priv(netdev);
6280
- struct pci_dev *pdev = adapter->pdev;
6281
- int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
6531
+ int max_frame = new_mtu + IGB_ETH_PKT_HDR_PAD;
6532
+
6533
+ if (adapter->xdp_prog) {
6534
+ int i;
6535
+
6536
+ for (i = 0; i < adapter->num_rx_queues; i++) {
6537
+ struct igb_ring *ring = adapter->rx_ring[i];
6538
+
6539
+ if (max_frame > igb_rx_bufsz(ring)) {
6540
+ netdev_warn(adapter->netdev,
6541
+ "Requested MTU size is not supported with XDP. Max frame size is %d\n",
6542
+ max_frame);
6543
+ return -EINVAL;
6544
+ }
6545
+ }
6546
+ }
62826547
62836548 /* adjust max frame to be at least the size of a standard frame */
62846549 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
....@@ -6293,8 +6558,8 @@
62936558 if (netif_running(netdev))
62946559 igb_down(adapter);
62956560
6296
- dev_info(&pdev->dev, "changing MTU from %d to %d\n",
6297
- netdev->mtu, new_mtu);
6561
+ netdev_dbg(netdev, "changing MTU from %d to %d\n",
6562
+ netdev->mtu, new_mtu);
62986563 netdev->mtu = new_mtu;
62996564
63006565 if (netif_running(netdev))
....@@ -6738,7 +7003,7 @@
67387003 igb_setup_dca(adapter);
67397004 break;
67407005 }
6741
- /* Fall Through since DCA is disabled. */
7006
+ fallthrough; /* since DCA is disabled. */
67427007 case DCA_PROVIDER_REMOVE:
67437008 if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
67447009 /* without this a class_device is left
....@@ -7157,7 +7422,7 @@
71577422 {
71587423 struct e1000_hw *hw = &adapter->hw;
71597424 unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
7160
- u32 reg, msgbuf[3];
7425
+ u32 reg, msgbuf[3] = {};
71617426 u8 *addr = (u8 *)(&msgbuf[1]);
71627427
71637428 /* process all the same items cleared in a function level reset */
....@@ -7191,7 +7456,7 @@
71917456
71927457 for (i = 0; i < hw->mac.rar_entry_count; i++) {
71937458 adapter->mac_table[i].state &= ~IGB_MAC_STATE_IN_USE;
7194
- memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
7459
+ eth_zero_addr(adapter->mac_table[i].addr);
71957460 adapter->mac_table[i].queue = 0;
71967461 igb_rar_set_index(adapter, i);
71977462 }
....@@ -7340,7 +7605,7 @@
73407605 } else {
73417606 adapter->mac_table[i].state = 0;
73427607 adapter->mac_table[i].queue = 0;
7343
- memset(adapter->mac_table[i].addr, 0, ETH_ALEN);
7608
+ eth_zero_addr(adapter->mac_table[i].addr);
73447609 }
73457610
73467611 igb_rar_set_index(adapter, i);
....@@ -7600,8 +7865,10 @@
76007865 static void igb_msg_task(struct igb_adapter *adapter)
76017866 {
76027867 struct e1000_hw *hw = &adapter->hw;
7868
+ unsigned long flags;
76037869 u32 vf;
76047870
7871
+ spin_lock_irqsave(&adapter->vfs_lock, flags);
76057872 for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
76067873 /* process any reset requests */
76077874 if (!igb_check_for_rst(hw, vf))
....@@ -7615,6 +7882,7 @@
76157882 if (!igb_check_for_ack(hw, vf))
76167883 igb_rcv_ack_from_vf(adapter, vf);
76177884 }
7885
+ spin_unlock_irqrestore(&adapter->vfs_lock, flags);
76187886 }
76197887
76207888 /**
....@@ -7778,11 +8046,13 @@
77788046 if (!clean_complete)
77798047 return budget;
77808048
7781
- /* If not enough Rx work done, exit the polling mode */
7782
- napi_complete_done(napi, work_done);
7783
- igb_ring_irq_enable(q_vector);
8049
+ /* Exit the polling mode, but don't re-enable interrupts if stack might
8050
+ * poll us due to busy-polling
8051
+ */
8052
+ if (likely(napi_complete_done(napi, work_done)))
8053
+ igb_ring_irq_enable(q_vector);
77848054
7785
- return 0;
8055
+ return work_done;
77868056 }
77878057
77888058 /**
....@@ -7831,7 +8101,10 @@
78318101 total_packets += tx_buffer->gso_segs;
78328102
78338103 /* free the skb */
7834
- napi_consume_skb(tx_buffer->skb, napi_budget);
8104
+ if (tx_buffer->type == IGB_TYPE_SKB)
8105
+ napi_consume_skb(tx_buffer->skb, napi_budget);
8106
+ else
8107
+ xdp_return_frame(tx_buffer->xdpf);
78358108
78368109 /* unmap skb header data */
78378110 dma_unmap_single(tx_ring->dev,
....@@ -7990,7 +8263,8 @@
79908263 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
79918264 }
79928265
7993
-static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer)
8266
+static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,
8267
+ int rx_buf_pgcnt)
79948268 {
79958269 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
79968270 struct page *page = rx_buffer->page;
....@@ -8001,7 +8275,7 @@
80018275
80028276 #if (PAGE_SIZE < 8192)
80038277 /* if we are only owner of page we can reuse it */
8004
- if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
8278
+ if (unlikely((rx_buf_pgcnt - pagecnt_bias) > 1))
80058279 return false;
80068280 #else
80078281 #define IGB_LAST_OFFSET \
....@@ -8015,8 +8289,8 @@
80158289 * the pagecnt_bias and page count so that we fully restock the
80168290 * number of references the driver holds.
80178291 */
8018
- if (unlikely(!pagecnt_bias)) {
8019
- page_ref_add(page, USHRT_MAX);
8292
+ if (unlikely(pagecnt_bias == 1)) {
8293
+ page_ref_add(page, USHRT_MAX - 1);
80208294 rx_buffer->pagecnt_bias = USHRT_MAX;
80218295 }
80228296
....@@ -8055,23 +8329,21 @@
80558329
80568330 static struct sk_buff *igb_construct_skb(struct igb_ring *rx_ring,
80578331 struct igb_rx_buffer *rx_buffer,
8058
- union e1000_adv_rx_desc *rx_desc,
8059
- unsigned int size)
8332
+ struct xdp_buff *xdp,
8333
+ union e1000_adv_rx_desc *rx_desc)
80608334 {
8061
- void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
80628335 #if (PAGE_SIZE < 8192)
80638336 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
80648337 #else
8065
- unsigned int truesize = SKB_DATA_ALIGN(size);
8338
+ unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end -
8339
+ xdp->data_hard_start);
80668340 #endif
8341
+ unsigned int size = xdp->data_end - xdp->data;
80678342 unsigned int headlen;
80688343 struct sk_buff *skb;
80698344
80708345 /* prefetch first cache line of first page */
8071
- prefetch(va);
8072
-#if L1_CACHE_BYTES < 128
8073
- prefetch(va + L1_CACHE_BYTES);
8074
-#endif
8346
+ net_prefetch(xdp->data);
80758347
80768348 /* allocate a skb to store the frags */
80778349 skb = napi_alloc_skb(&rx_ring->q_vector->napi, IGB_RX_HDR_LEN);
....@@ -8079,24 +8351,25 @@
80798351 return NULL;
80808352
80818353 if (unlikely(igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))) {
8082
- igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
8083
- va += IGB_TS_HDR_LEN;
8084
- size -= IGB_TS_HDR_LEN;
8354
+ if (!igb_ptp_rx_pktstamp(rx_ring->q_vector, xdp->data, skb)) {
8355
+ xdp->data += IGB_TS_HDR_LEN;
8356
+ size -= IGB_TS_HDR_LEN;
8357
+ }
80858358 }
80868359
80878360 /* Determine available headroom for copy */
80888361 headlen = size;
80898362 if (headlen > IGB_RX_HDR_LEN)
8090
- headlen = eth_get_headlen(va, IGB_RX_HDR_LEN);
8363
+ headlen = eth_get_headlen(skb->dev, xdp->data, IGB_RX_HDR_LEN);
80918364
80928365 /* align pull length to size of long to optimize memcpy performance */
8093
- memcpy(__skb_put(skb, headlen), va, ALIGN(headlen, sizeof(long)));
8366
+ memcpy(__skb_put(skb, headlen), xdp->data, ALIGN(headlen, sizeof(long)));
80948367
80958368 /* update all of the pointers */
80968369 size -= headlen;
80978370 if (size) {
80988371 skb_add_rx_frag(skb, 0, rx_buffer->page,
8099
- (va + headlen) - page_address(rx_buffer->page),
8372
+ (xdp->data + headlen) - page_address(rx_buffer->page),
81008373 size, truesize);
81018374 #if (PAGE_SIZE < 8192)
81028375 rx_buffer->page_offset ^= truesize;
....@@ -8112,37 +8385,38 @@
81128385
81138386 static struct sk_buff *igb_build_skb(struct igb_ring *rx_ring,
81148387 struct igb_rx_buffer *rx_buffer,
8115
- union e1000_adv_rx_desc *rx_desc,
8116
- unsigned int size)
8388
+ struct xdp_buff *xdp,
8389
+ union e1000_adv_rx_desc *rx_desc)
81178390 {
8118
- void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
81198391 #if (PAGE_SIZE < 8192)
81208392 unsigned int truesize = igb_rx_pg_size(rx_ring) / 2;
81218393 #else
81228394 unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
8123
- SKB_DATA_ALIGN(IGB_SKB_PAD + size);
8395
+ SKB_DATA_ALIGN(xdp->data_end -
8396
+ xdp->data_hard_start);
81248397 #endif
8398
+ unsigned int metasize = xdp->data - xdp->data_meta;
81258399 struct sk_buff *skb;
81268400
81278401 /* prefetch first cache line of first page */
8128
- prefetch(va);
8129
-#if L1_CACHE_BYTES < 128
8130
- prefetch(va + L1_CACHE_BYTES);
8131
-#endif
8402
+ net_prefetch(xdp->data_meta);
81328403
81338404 /* build an skb around the page buffer */
8134
- skb = build_skb(va - IGB_SKB_PAD, truesize);
8405
+ skb = build_skb(xdp->data_hard_start, truesize);
81358406 if (unlikely(!skb))
81368407 return NULL;
81378408
81388409 /* update pointers within the skb to store the data */
8139
- skb_reserve(skb, IGB_SKB_PAD);
8140
- __skb_put(skb, size);
8410
+ skb_reserve(skb, xdp->data - xdp->data_hard_start);
8411
+ __skb_put(skb, xdp->data_end - xdp->data);
8412
+
8413
+ if (metasize)
8414
+ skb_metadata_set(skb, metasize);
81418415
81428416 /* pull timestamp out of packet data */
81438417 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
8144
- igb_ptp_rx_pktstamp(rx_ring->q_vector, skb->data, skb);
8145
- __skb_pull(skb, IGB_TS_HDR_LEN);
8418
+ if (!igb_ptp_rx_pktstamp(rx_ring->q_vector, skb->data, skb))
8419
+ __skb_pull(skb, IGB_TS_HDR_LEN);
81468420 }
81478421
81488422 /* update buffer offset */
....@@ -8153,6 +8427,81 @@
81538427 #endif
81548428
81558429 return skb;
8430
+}
8431
+
8432
+static struct sk_buff *igb_run_xdp(struct igb_adapter *adapter,
8433
+ struct igb_ring *rx_ring,
8434
+ struct xdp_buff *xdp)
8435
+{
8436
+ int err, result = IGB_XDP_PASS;
8437
+ struct bpf_prog *xdp_prog;
8438
+ u32 act;
8439
+
8440
+ rcu_read_lock();
8441
+ xdp_prog = READ_ONCE(rx_ring->xdp_prog);
8442
+
8443
+ if (!xdp_prog)
8444
+ goto xdp_out;
8445
+
8446
+ prefetchw(xdp->data_hard_start); /* xdp_frame write */
8447
+
8448
+ act = bpf_prog_run_xdp(xdp_prog, xdp);
8449
+ switch (act) {
8450
+ case XDP_PASS:
8451
+ break;
8452
+ case XDP_TX:
8453
+ result = igb_xdp_xmit_back(adapter, xdp);
8454
+ if (result == IGB_XDP_CONSUMED)
8455
+ goto out_failure;
8456
+ break;
8457
+ case XDP_REDIRECT:
8458
+ err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog);
8459
+ if (err)
8460
+ goto out_failure;
8461
+ result = IGB_XDP_REDIR;
8462
+ break;
8463
+ default:
8464
+ bpf_warn_invalid_xdp_action(act);
8465
+ fallthrough;
8466
+ case XDP_ABORTED:
8467
+out_failure:
8468
+ trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
8469
+ fallthrough;
8470
+ case XDP_DROP:
8471
+ result = IGB_XDP_CONSUMED;
8472
+ break;
8473
+ }
8474
+xdp_out:
8475
+ rcu_read_unlock();
8476
+ return ERR_PTR(-result);
8477
+}
8478
+
8479
+static unsigned int igb_rx_frame_truesize(struct igb_ring *rx_ring,
8480
+ unsigned int size)
8481
+{
8482
+ unsigned int truesize;
8483
+
8484
+#if (PAGE_SIZE < 8192)
8485
+ truesize = igb_rx_pg_size(rx_ring) / 2; /* Must be power-of-2 */
8486
+#else
8487
+ truesize = ring_uses_build_skb(rx_ring) ?
8488
+ SKB_DATA_ALIGN(IGB_SKB_PAD + size) +
8489
+ SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) :
8490
+ SKB_DATA_ALIGN(size);
8491
+#endif
8492
+ return truesize;
8493
+}
8494
+
8495
+static void igb_rx_buffer_flip(struct igb_ring *rx_ring,
8496
+ struct igb_rx_buffer *rx_buffer,
8497
+ unsigned int size)
8498
+{
8499
+ unsigned int truesize = igb_rx_frame_truesize(rx_ring, size);
8500
+#if (PAGE_SIZE < 8192)
8501
+ rx_buffer->page_offset ^= truesize;
8502
+#else
8503
+ rx_buffer->page_offset += truesize;
8504
+#endif
81568505 }
81578506
81588507 static inline void igb_rx_checksum(struct igb_ring *ring,
....@@ -8209,7 +8558,6 @@
82098558 * igb_is_non_eop - process handling of non-EOP buffers
82108559 * @rx_ring: Rx ring being processed
82118560 * @rx_desc: Rx descriptor for current buffer
8212
- * @skb: current socket buffer containing buffer in progress
82138561 *
82148562 * This function updates next to clean. If the buffer is an EOP buffer
82158563 * this function exits returning false, otherwise it will place the
....@@ -8251,6 +8599,10 @@
82518599 union e1000_adv_rx_desc *rx_desc,
82528600 struct sk_buff *skb)
82538601 {
8602
+ /* XDP packets use error pointer so abort at this point */
8603
+ if (IS_ERR(skb))
8604
+ return true;
8605
+
82548606 if (unlikely((igb_test_staterr(rx_desc,
82558607 E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) {
82568608 struct net_device *netdev = rx_ring->netdev;
....@@ -8297,7 +8649,7 @@
82978649
82988650 if (igb_test_staterr(rx_desc, E1000_RXDEXT_STATERR_LB) &&
82998651 test_bit(IGB_RING_FLAG_RX_LB_VLAN_BSWAP, &rx_ring->flags))
8300
- vid = be16_to_cpu(rx_desc->wb.upper.vlan);
8652
+ vid = be16_to_cpu((__force __be16)rx_desc->wb.upper.vlan);
83018653 else
83028654 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
83038655
....@@ -8309,12 +8661,23 @@
83098661 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
83108662 }
83118663
8664
+static unsigned int igb_rx_offset(struct igb_ring *rx_ring)
8665
+{
8666
+ return ring_uses_build_skb(rx_ring) ? IGB_SKB_PAD : 0;
8667
+}
8668
+
83128669 static struct igb_rx_buffer *igb_get_rx_buffer(struct igb_ring *rx_ring,
8313
- const unsigned int size)
8670
+ const unsigned int size, int *rx_buf_pgcnt)
83148671 {
83158672 struct igb_rx_buffer *rx_buffer;
83168673
83178674 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
8675
+ *rx_buf_pgcnt =
8676
+#if (PAGE_SIZE < 8192)
8677
+ page_count(rx_buffer->page);
8678
+#else
8679
+ 0;
8680
+#endif
83188681 prefetchw(rx_buffer->page);
83198682
83208683 /* we are reusing so sync this buffer for CPU use */
....@@ -8330,9 +8693,9 @@
83308693 }
83318694
83328695 static void igb_put_rx_buffer(struct igb_ring *rx_ring,
8333
- struct igb_rx_buffer *rx_buffer)
8696
+ struct igb_rx_buffer *rx_buffer, int rx_buf_pgcnt)
83348697 {
8335
- if (igb_can_reuse_rx_page(rx_buffer)) {
8698
+ if (igb_can_reuse_rx_page(rx_buffer, rx_buf_pgcnt)) {
83368699 /* hand second half of page back to the ring */
83378700 igb_reuse_rx_page(rx_ring, rx_buffer);
83388701 } else {
....@@ -8352,10 +8715,21 @@
83528715
83538716 static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
83548717 {
8718
+ struct igb_adapter *adapter = q_vector->adapter;
83558719 struct igb_ring *rx_ring = q_vector->rx.ring;
83568720 struct sk_buff *skb = rx_ring->skb;
83578721 unsigned int total_bytes = 0, total_packets = 0;
83588722 u16 cleaned_count = igb_desc_unused(rx_ring);
8723
+ unsigned int xdp_xmit = 0;
8724
+ struct xdp_buff xdp;
8725
+ int rx_buf_pgcnt;
8726
+
8727
+ xdp.rxq = &rx_ring->xdp_rxq;
8728
+
8729
+ /* Frame size depend on rx_ring setup when PAGE_SIZE=4K */
8730
+#if (PAGE_SIZE < 8192)
8731
+ xdp.frame_sz = igb_rx_frame_truesize(rx_ring, 0);
8732
+#endif
83598733
83608734 while (likely(total_packets < budget)) {
83618735 union e1000_adv_rx_desc *rx_desc;
....@@ -8379,16 +8753,41 @@
83798753 */
83808754 dma_rmb();
83818755
8382
- rx_buffer = igb_get_rx_buffer(rx_ring, size);
8756
+ rx_buffer = igb_get_rx_buffer(rx_ring, size, &rx_buf_pgcnt);
83838757
83848758 /* retrieve a buffer from the ring */
8385
- if (skb)
8759
+ if (!skb) {
8760
+ xdp.data = page_address(rx_buffer->page) +
8761
+ rx_buffer->page_offset;
8762
+ xdp.data_meta = xdp.data;
8763
+ xdp.data_hard_start = xdp.data -
8764
+ igb_rx_offset(rx_ring);
8765
+ xdp.data_end = xdp.data + size;
8766
+#if (PAGE_SIZE > 4096)
8767
+ /* At larger PAGE_SIZE, frame_sz depend on len size */
8768
+ xdp.frame_sz = igb_rx_frame_truesize(rx_ring, size);
8769
+#endif
8770
+ skb = igb_run_xdp(adapter, rx_ring, &xdp);
8771
+ }
8772
+
8773
+ if (IS_ERR(skb)) {
8774
+ unsigned int xdp_res = -PTR_ERR(skb);
8775
+
8776
+ if (xdp_res & (IGB_XDP_TX | IGB_XDP_REDIR)) {
8777
+ xdp_xmit |= xdp_res;
8778
+ igb_rx_buffer_flip(rx_ring, rx_buffer, size);
8779
+ } else {
8780
+ rx_buffer->pagecnt_bias++;
8781
+ }
8782
+ total_packets++;
8783
+ total_bytes += size;
8784
+ } else if (skb)
83868785 igb_add_rx_frag(rx_ring, rx_buffer, skb, size);
83878786 else if (ring_uses_build_skb(rx_ring))
8388
- skb = igb_build_skb(rx_ring, rx_buffer, rx_desc, size);
8787
+ skb = igb_build_skb(rx_ring, rx_buffer, &xdp, rx_desc);
83898788 else
83908789 skb = igb_construct_skb(rx_ring, rx_buffer,
8391
- rx_desc, size);
8790
+ &xdp, rx_desc);
83928791
83938792 /* exit if we failed to retrieve a buffer */
83948793 if (!skb) {
....@@ -8397,7 +8796,7 @@
83978796 break;
83988797 }
83998798
8400
- igb_put_rx_buffer(rx_ring, rx_buffer);
8799
+ igb_put_rx_buffer(rx_ring, rx_buffer, rx_buf_pgcnt);
84018800 cleaned_count++;
84028801
84038802 /* fetch next buffer in frame if non-eop */
....@@ -8428,6 +8827,15 @@
84288827 /* place incomplete frames back on ring for completion */
84298828 rx_ring->skb = skb;
84308829
8830
+ if (xdp_xmit & IGB_XDP_REDIR)
8831
+ xdp_do_flush();
8832
+
8833
+ if (xdp_xmit & IGB_XDP_TX) {
8834
+ struct igb_ring *tx_ring = igb_xdp_tx_queue_mapping(adapter);
8835
+
8836
+ igb_xdp_ring_update_tail(tx_ring);
8837
+ }
8838
+
84318839 u64_stats_update_begin(&rx_ring->rx_syncp);
84328840 rx_ring->rx_stats.packets += total_packets;
84338841 rx_ring->rx_stats.bytes += total_bytes;
....@@ -8439,11 +8847,6 @@
84398847 igb_alloc_rx_buffers(rx_ring, cleaned_count);
84408848
84418849 return total_packets;
8442
-}
8443
-
8444
-static inline unsigned int igb_rx_offset(struct igb_ring *rx_ring)
8445
-{
8446
- return ring_uses_build_skb(rx_ring) ? IGB_SKB_PAD : 0;
84478850 }
84488851
84498852 static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
....@@ -8482,14 +8885,16 @@
84828885 bi->dma = dma;
84838886 bi->page = page;
84848887 bi->page_offset = igb_rx_offset(rx_ring);
8485
- bi->pagecnt_bias = 1;
8888
+ page_ref_add(page, USHRT_MAX - 1);
8889
+ bi->pagecnt_bias = USHRT_MAX;
84868890
84878891 return true;
84888892 }
84898893
84908894 /**
8491
- * igb_alloc_rx_buffers - Replace used receive buffers; packet split
8492
- * @adapter: address of board private structure
8895
+ * igb_alloc_rx_buffers - Replace used receive buffers
8896
+ * @rx_ring: rx descriptor ring to allocate new receive buffers
8897
+ * @cleaned_count: count of buffers to allocate
84938898 **/
84948899 void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
84958900 {
....@@ -8558,9 +8963,9 @@
85588963
85598964 /**
85608965 * igb_mii_ioctl -
8561
- * @netdev:
8562
- * @ifreq:
8563
- * @cmd:
8966
+ * @netdev: pointer to netdev struct
8967
+ * @ifr: interface structure
8968
+ * @cmd: ioctl command to execute
85648969 **/
85658970 static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
85668971 {
....@@ -8588,9 +8993,9 @@
85888993
85898994 /**
85908995 * igb_ioctl -
8591
- * @netdev:
8592
- * @ifreq:
8593
- * @cmd:
8996
+ * @netdev: pointer to netdev struct
8997
+ * @ifr: interface structure
8998
+ * @cmd: ioctl command to execute
85948999 **/
85959000 static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
85969001 {
....@@ -8875,7 +9280,7 @@
88759280 return __igb_shutdown(to_pci_dev(dev), NULL, 0);
88769281 }
88779282
8878
-static int __maybe_unused igb_resume(struct device *dev)
9283
+static int __maybe_unused __igb_resume(struct device *dev, bool rpm)
88799284 {
88809285 struct pci_dev *pdev = to_pci_dev(dev);
88819286 struct net_device *netdev = pci_get_drvdata(pdev);
....@@ -8918,21 +9323,27 @@
89189323
89199324 wr32(E1000_WUS, ~0);
89209325
8921
- rtnl_lock();
9326
+ if (!rpm)
9327
+ rtnl_lock();
89229328 if (!err && netif_running(netdev))
89239329 err = __igb_open(netdev, true);
89249330
89259331 if (!err)
89269332 netif_device_attach(netdev);
8927
- rtnl_unlock();
9333
+ if (!rpm)
9334
+ rtnl_unlock();
89289335
89299336 return err;
89309337 }
89319338
9339
+static int __maybe_unused igb_resume(struct device *dev)
9340
+{
9341
+ return __igb_resume(dev, false);
9342
+}
9343
+
89329344 static int __maybe_unused igb_runtime_idle(struct device *dev)
89339345 {
8934
- struct pci_dev *pdev = to_pci_dev(dev);
8935
- struct net_device *netdev = pci_get_drvdata(pdev);
9346
+ struct net_device *netdev = dev_get_drvdata(dev);
89369347 struct igb_adapter *adapter = netdev_priv(netdev);
89379348
89389349 if (!igb_has_link(adapter))
....@@ -8948,7 +9359,7 @@
89489359
89499360 static int __maybe_unused igb_runtime_resume(struct device *dev)
89509361 {
8951
- return igb_resume(dev);
9362
+ return __igb_resume(dev, true);
89529363 }
89539364
89549365 static void igb_shutdown(struct pci_dev *pdev)
....@@ -9046,6 +9457,11 @@
90469457 struct net_device *netdev = pci_get_drvdata(pdev);
90479458 struct igb_adapter *adapter = netdev_priv(netdev);
90489459
9460
+ if (state == pci_channel_io_normal) {
9461
+ dev_warn(&pdev->dev, "Non-correctable non-fatal error reported.\n");
9462
+ return PCI_ERS_RESULT_CAN_RECOVER;
9463
+ }
9464
+
90499465 netif_device_detach(netdev);
90509466
90519467 if (state == pci_channel_io_perm_failure)
....@@ -9064,7 +9480,7 @@
90649480 * @pdev: Pointer to PCI device
90659481 *
90669482 * Restart the card from scratch, as if from a cold-boot. Implementation
9067
- * resembles the first-half of the igb_resume routine.
9483
+ * resembles the first-half of the __igb_resume routine.
90689484 **/
90699485 static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
90709486 {
....@@ -9072,7 +9488,6 @@
90729488 struct igb_adapter *adapter = netdev_priv(netdev);
90739489 struct e1000_hw *hw = &adapter->hw;
90749490 pci_ers_result_t result;
9075
- int err;
90769491
90779492 if (pci_enable_device_mem(pdev)) {
90789493 dev_err(&pdev->dev,
....@@ -9096,14 +9511,6 @@
90969511 result = PCI_ERS_RESULT_RECOVERED;
90979512 }
90989513
9099
- err = pci_cleanup_aer_uncorrect_error_status(pdev);
9100
- if (err) {
9101
- dev_err(&pdev->dev,
9102
- "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
9103
- err);
9104
- /* non-fatal, continue */
9105
- }
9106
-
91079514 return result;
91089515 }
91099516
....@@ -9113,7 +9520,7 @@
91139520 *
91149521 * This callback is called when the error recovery driver tells us that
91159522 * its OK to resume normal operation. Implementation resembles the
9116
- * second-half of the igb_resume routine.
9523
+ * second-half of the __igb_resume routine.
91179524 */
91189525 static void igb_io_resume(struct pci_dev *pdev)
91199526 {
....@@ -9415,13 +9822,13 @@
94159822 reg = rd32(E1000_DTXCTL);
94169823 reg |= E1000_DTXCTL_VLAN_ADDED;
94179824 wr32(E1000_DTXCTL, reg);
9418
- /* Fall through */
9825
+ fallthrough;
94199826 case e1000_82580:
94209827 /* enable replication vlan tag stripping */
94219828 reg = rd32(E1000_RPLOLR);
94229829 reg |= E1000_RPLOLR_STRVLAN;
94239830 wr32(E1000_RPLOLR, reg);
9424
- /* Fall through */
9831
+ fallthrough;
94259832 case e1000_i350:
94269833 /* none of the above registers are supported by i350 */
94279834 break;
....@@ -9443,11 +9850,10 @@
94439850 struct e1000_hw *hw = &adapter->hw;
94449851 u32 dmac_thr;
94459852 u16 hwm;
9853
+ u32 reg;
94469854
94479855 if (hw->mac.type > e1000_82580) {
94489856 if (adapter->flags & IGB_FLAG_DMAC) {
9449
- u32 reg;
9450
-
94519857 /* force threshold to 0. */
94529858 wr32(E1000_DMCTXTH, 0);
94539859
....@@ -9480,7 +9886,6 @@
94809886 /* Disable BMC-to-OS Watchdog Enable */
94819887 if (hw->mac.type != e1000_i354)
94829888 reg &= ~E1000_DMACR_DC_BMC2OSW_EN;
9483
-
94849889 wr32(E1000_DMACR, reg);
94859890
94869891 /* no lower threshold to disable
....@@ -9497,12 +9902,12 @@
94979902 */
94989903 wr32(E1000_DMCTXTH, (IGB_MIN_TXPBSIZE -
94999904 (IGB_TX_BUF_4096 + adapter->max_frame_size)) >> 6);
9905
+ }
95009906
9501
- /* make low power state decision controlled
9502
- * by DMA coal
9503
- */
9907
+ if (hw->mac.type >= e1000_i210 ||
9908
+ (adapter->flags & IGB_FLAG_DMAC)) {
95049909 reg = rd32(E1000_PCIEMISC);
9505
- reg &= ~E1000_PCIEMISC_LX_DECISION;
9910
+ reg |= E1000_PCIEMISC_LX_DECISION;
95069911 wr32(E1000_PCIEMISC, reg);
95079912 } /* endif adapter->dmac is not disabled */
95089913 } else if (hw->mac.type == e1000_82580) {