aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/intel
diff options
context:
space:
mode:
authorAlexander Duyck <alexander.h.duyck@intel.com>2012-09-24 20:30:52 -0400
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>2012-10-19 07:27:30 -0400
commit1a1c225b9463038ac68b369ef05e4ee7fd9c82a5 (patch)
treedc79d408e1e8bdc756315b3ded1d2097e298015e /drivers/net/ethernet/intel
parentb534550a17cda69a1d62acc18fff33370b5eee5b (diff)
igb: Do not use header split, instead receive all frames into a single buffer
This change makes it so that we no longer use header split. The idea is to reduce partial cache line writes by hardware when handling frames larger then header size. We can compensate for the extra overhead of having to memcpy the header buffer by avoiding the cache misses seen by leaving an full skb allocated and sitting on the ring. Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com> Tested-by: Aaron Brown <aaron.f.brown@intel.com> Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet/intel')
-rw-r--r--drivers/net/ethernet/intel/igb/igb.h13
-rw-r--r--drivers/net/ethernet/intel/igb/igb_ethtool.c31
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c420
3 files changed, 312 insertions, 152 deletions
diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
index f6a1cd9d72a6..72ab9ac34a30 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -174,11 +174,9 @@ struct igb_tx_buffer {
174}; 174};
175 175
176struct igb_rx_buffer { 176struct igb_rx_buffer {
177 struct sk_buff *skb;
178 dma_addr_t dma; 177 dma_addr_t dma;
179 struct page *page; 178 struct page *page;
180 dma_addr_t page_dma; 179 unsigned int page_offset;
181 u32 page_offset;
182}; 180};
183 181
184struct igb_tx_queue_stats { 182struct igb_tx_queue_stats {
@@ -251,6 +249,7 @@ struct igb_ring {
251 }; 249 };
252 /* RX */ 250 /* RX */
253 struct { 251 struct {
252 struct sk_buff *skb;
254 struct igb_rx_queue_stats rx_stats; 253 struct igb_rx_queue_stats rx_stats;
255 struct u64_stats_sync rx_syncp; 254 struct u64_stats_sync rx_syncp;
256 }; 255 };
@@ -451,13 +450,11 @@ static inline void igb_ptp_rx_hwtstamp(struct igb_q_vector *q_vector,
451 union e1000_adv_rx_desc *rx_desc, 450 union e1000_adv_rx_desc *rx_desc,
452 struct sk_buff *skb) 451 struct sk_buff *skb)
453{ 452{
454 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) { 453 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TS) &&
455 igb_ptp_rx_pktstamp(q_vector, skb->data, skb); 454 !igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))
456 skb_pull(skb, IGB_TS_HDR_LEN);
457 } else if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TS)) {
458 igb_ptp_rx_rgtstamp(q_vector, skb); 455 igb_ptp_rx_rgtstamp(q_vector, skb);
459 }
460} 456}
457
461extern int igb_ptp_hwtstamp_ioctl(struct net_device *netdev, 458extern int igb_ptp_hwtstamp_ioctl(struct net_device *netdev,
462 struct ifreq *ifr, int cmd); 459 struct ifreq *ifr, int cmd);
463#endif /* CONFIG_IGB_PTP */ 460#endif /* CONFIG_IGB_PTP */
diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index 2ea012849825..0faac423bd5b 100644
--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -37,6 +37,7 @@
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/pm_runtime.h> 39#include <linux/pm_runtime.h>
40#include <linux/highmem.h>
40 41
41#include "igb.h" 42#include "igb.h"
42 43
@@ -1685,16 +1686,24 @@ static void igb_create_lbtest_frame(struct sk_buff *skb,
1685 memset(&skb->data[frame_size + 12], 0xAF, 1); 1686 memset(&skb->data[frame_size + 12], 0xAF, 1);
1686} 1687}
1687 1688
1688static int igb_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size) 1689static int igb_check_lbtest_frame(struct igb_rx_buffer *rx_buffer,
1690 unsigned int frame_size)
1689{ 1691{
1690 frame_size /= 2; 1692 unsigned char *data;
1691 if (*(skb->data + 3) == 0xFF) { 1693 bool match = true;
1692 if ((*(skb->data + frame_size + 10) == 0xBE) && 1694
1693 (*(skb->data + frame_size + 12) == 0xAF)) { 1695 frame_size >>= 1;
1694 return 0; 1696
1695 } 1697 data = kmap(rx_buffer->page) + rx_buffer->page_offset;
1696 } 1698
1697 return 13; 1699 if (data[3] != 0xFF ||
1700 data[frame_size + 10] != 0xBE ||
1701 data[frame_size + 12] != 0xAF)
1702 match = false;
1703
1704 kunmap(rx_buffer->page);
1705
1706 return match;
1698} 1707}
1699 1708
1700static int igb_clean_test_rings(struct igb_ring *rx_ring, 1709static int igb_clean_test_rings(struct igb_ring *rx_ring,
@@ -1720,12 +1729,12 @@ static int igb_clean_test_rings(struct igb_ring *rx_ring,
1720 /* unmap rx buffer, will be remapped by alloc_rx_buffers */ 1729 /* unmap rx buffer, will be remapped by alloc_rx_buffers */
1721 dma_unmap_single(rx_ring->dev, 1730 dma_unmap_single(rx_ring->dev,
1722 rx_buffer_info->dma, 1731 rx_buffer_info->dma,
1723 IGB_RX_HDR_LEN, 1732 PAGE_SIZE / 2,
1724 DMA_FROM_DEVICE); 1733 DMA_FROM_DEVICE);
1725 rx_buffer_info->dma = 0; 1734 rx_buffer_info->dma = 0;
1726 1735
1727 /* verify contents of skb */ 1736 /* verify contents of skb */
1728 if (!igb_check_lbtest_frame(rx_buffer_info->skb, size)) 1737 if (igb_check_lbtest_frame(rx_buffer_info, size))
1729 count++; 1738 count++;
1730 1739
1731 /* unmap buffer on tx side */ 1740 /* unmap buffer on tx side */
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index c611cffa788f..665eafa401d4 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -534,25 +534,21 @@ rx_ring_summary:
534 534
535 if (staterr & E1000_RXD_STAT_DD) { 535 if (staterr & E1000_RXD_STAT_DD) {
536 /* Descriptor Done */ 536 /* Descriptor Done */
537 pr_info("%s[0x%03X] %016llX %016llX -------" 537 pr_info("%s[0x%03X] %016llX %016llX ---------------- %s\n",
538 "--------- %p%s\n", "RWB", i, 538 "RWB", i,
539 le64_to_cpu(u0->a), 539 le64_to_cpu(u0->a),
540 le64_to_cpu(u0->b), 540 le64_to_cpu(u0->b),
541 buffer_info->skb, next_desc); 541 next_desc);
542 } else { 542 } else {
543 pr_info("%s[0x%03X] %016llX %016llX %016llX" 543 pr_info("%s[0x%03X] %016llX %016llX %016llX %s\n",
544 " %p%s\n", "R ", i, 544 "R ", i,
545 le64_to_cpu(u0->a), 545 le64_to_cpu(u0->a),
546 le64_to_cpu(u0->b), 546 le64_to_cpu(u0->b),
547 (u64)buffer_info->dma, 547 (u64)buffer_info->dma,
548 buffer_info->skb, next_desc); 548 next_desc);
549 549
550 if (netif_msg_pktdata(adapter) && 550 if (netif_msg_pktdata(adapter) &&
551 buffer_info->dma && buffer_info->skb) { 551 buffer_info->dma && buffer_info->page) {
552 print_hex_dump(KERN_INFO, "",
553 DUMP_PREFIX_ADDRESS,
554 16, 1, buffer_info->skb->data,
555 IGB_RX_HDR_LEN, true);
556 print_hex_dump(KERN_INFO, "", 552 print_hex_dump(KERN_INFO, "",
557 DUMP_PREFIX_ADDRESS, 553 DUMP_PREFIX_ADDRESS,
558 16, 1, 554 16, 1,
@@ -3111,7 +3107,7 @@ void igb_configure_rx_ring(struct igb_adapter *adapter,
3111#else 3107#else
3112 srrctl |= (PAGE_SIZE / 2) >> E1000_SRRCTL_BSIZEPKT_SHIFT; 3108 srrctl |= (PAGE_SIZE / 2) >> E1000_SRRCTL_BSIZEPKT_SHIFT;
3113#endif 3109#endif
3114 srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; 3110 srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
3115#ifdef CONFIG_IGB_PTP 3111#ifdef CONFIG_IGB_PTP
3116 if (hw->mac.type >= e1000_82580) 3112 if (hw->mac.type >= e1000_82580)
3117 srrctl |= E1000_SRRCTL_TIMESTAMP; 3113 srrctl |= E1000_SRRCTL_TIMESTAMP;
@@ -3305,36 +3301,27 @@ static void igb_clean_rx_ring(struct igb_ring *rx_ring)
3305 unsigned long size; 3301 unsigned long size;
3306 u16 i; 3302 u16 i;
3307 3303
3304 if (rx_ring->skb)
3305 dev_kfree_skb(rx_ring->skb);
3306 rx_ring->skb = NULL;
3307
3308 if (!rx_ring->rx_buffer_info) 3308 if (!rx_ring->rx_buffer_info)
3309 return; 3309 return;
3310 3310
3311 /* Free all the Rx ring sk_buffs */ 3311 /* Free all the Rx ring sk_buffs */
3312 for (i = 0; i < rx_ring->count; i++) { 3312 for (i = 0; i < rx_ring->count; i++) {
3313 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i]; 3313 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
3314 if (buffer_info->dma) {
3315 dma_unmap_single(rx_ring->dev,
3316 buffer_info->dma,
3317 IGB_RX_HDR_LEN,
3318 DMA_FROM_DEVICE);
3319 buffer_info->dma = 0;
3320 }
3321 3314
3322 if (buffer_info->skb) { 3315 if (buffer_info->dma)
3323 dev_kfree_skb(buffer_info->skb);
3324 buffer_info->skb = NULL;
3325 }
3326 if (buffer_info->page_dma) {
3327 dma_unmap_page(rx_ring->dev, 3316 dma_unmap_page(rx_ring->dev,
3328 buffer_info->page_dma, 3317 buffer_info->dma,
3329 PAGE_SIZE / 2, 3318 PAGE_SIZE / 2,
3330 DMA_FROM_DEVICE); 3319 DMA_FROM_DEVICE);
3331 buffer_info->page_dma = 0; 3320 buffer_info->dma = 0;
3332 } 3321 if (buffer_info->page)
3333 if (buffer_info->page) { 3322 __free_page(buffer_info->page);
3334 put_page(buffer_info->page); 3323 buffer_info->page = NULL;
3335 buffer_info->page = NULL; 3324 buffer_info->page_offset = 0;
3336 buffer_info->page_offset = 0;
3337 }
3338 } 3325 }
3339 3326
3340 size = sizeof(struct igb_rx_buffer) * rx_ring->count; 3327 size = sizeof(struct igb_rx_buffer) * rx_ring->count;
@@ -5906,23 +5893,219 @@ static void igb_rx_vlan(struct igb_ring *ring,
5906 } 5893 }
5907} 5894}
5908 5895
5909static inline u16 igb_get_hlen(union e1000_adv_rx_desc *rx_desc) 5896/**
5897 * igb_get_headlen - determine size of header for LRO/GRO
5898 * @data: pointer to the start of the headers
5899 * @max_len: total length of section to find headers in
5900 *
5901 * This function is meant to determine the length of headers that will
5902 * be recognized by hardware for LRO, and GRO offloads. The main
5903 * motivation of doing this is to only perform one pull for IPv4 TCP
5904 * packets so that we can do basic things like calculating the gso_size
5905 * based on the average data per packet.
5906 **/
5907static unsigned int igb_get_headlen(unsigned char *data,
5908 unsigned int max_len)
5909{
5910 union {
5911 unsigned char *network;
5912 /* l2 headers */
5913 struct ethhdr *eth;
5914 struct vlan_hdr *vlan;
5915 /* l3 headers */
5916 struct iphdr *ipv4;
5917 struct ipv6hdr *ipv6;
5918 } hdr;
5919 __be16 protocol;
5920 u8 nexthdr = 0; /* default to not TCP */
5921 u8 hlen;
5922
5923 /* this should never happen, but better safe than sorry */
5924 if (max_len < ETH_HLEN)
5925 return max_len;
5926
5927 /* initialize network frame pointer */
5928 hdr.network = data;
5929
5930 /* set first protocol and move network header forward */
5931 protocol = hdr.eth->h_proto;
5932 hdr.network += ETH_HLEN;
5933
5934 /* handle any vlan tag if present */
5935 if (protocol == __constant_htons(ETH_P_8021Q)) {
5936 if ((hdr.network - data) > (max_len - VLAN_HLEN))
5937 return max_len;
5938
5939 protocol = hdr.vlan->h_vlan_encapsulated_proto;
5940 hdr.network += VLAN_HLEN;
5941 }
5942
5943 /* handle L3 protocols */
5944 if (protocol == __constant_htons(ETH_P_IP)) {
5945 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
5946 return max_len;
5947
5948 /* access ihl as a u8 to avoid unaligned access on ia64 */
5949 hlen = (hdr.network[0] & 0x0F) << 2;
5950
5951 /* verify hlen meets minimum size requirements */
5952 if (hlen < sizeof(struct iphdr))
5953 return hdr.network - data;
5954
5955 /* record next protocol */
5956 nexthdr = hdr.ipv4->protocol;
5957 hdr.network += hlen;
5958 } else if (protocol == __constant_htons(ETH_P_IPV6)) {
5959 if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
5960 return max_len;
5961
5962 /* record next protocol */
5963 nexthdr = hdr.ipv6->nexthdr;
5964 hdr.network += sizeof(struct ipv6hdr);
5965 } else {
5966 return hdr.network - data;
5967 }
5968
5969 /* finally sort out TCP */
5970 if (nexthdr == IPPROTO_TCP) {
5971 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
5972 return max_len;
5973
5974 /* access doff as a u8 to avoid unaligned access on ia64 */
5975 hlen = (hdr.network[12] & 0xF0) >> 2;
5976
5977 /* verify hlen meets minimum size requirements */
5978 if (hlen < sizeof(struct tcphdr))
5979 return hdr.network - data;
5980
5981 hdr.network += hlen;
5982 } else if (nexthdr == IPPROTO_UDP) {
5983 if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
5984 return max_len;
5985
5986 hdr.network += sizeof(struct udphdr);
5987 }
5988
5989 /*
5990 * If everything has gone correctly hdr.network should be the
5991 * data section of the packet and will be the end of the header.
5992 * If not then it probably represents the end of the last recognized
5993 * header.
5994 */
5995 if ((hdr.network - data) < max_len)
5996 return hdr.network - data;
5997 else
5998 return max_len;
5999}
6000
6001/**
6002 * igb_pull_tail - igb specific version of skb_pull_tail
6003 * @rx_ring: rx descriptor ring packet is being transacted on
6004 * @skb: pointer to current skb being adjusted
6005 *
6006 * This function is an igb specific version of __pskb_pull_tail. The
6007 * main difference between this version and the original function is that
6008 * this function can make several assumptions about the state of things
6009 * that allow for significant optimizations versus the standard function.
6010 * As a result we can do things like drop a frag and maintain an accurate
6011 * truesize for the skb.
6012 */
6013static void igb_pull_tail(struct igb_ring *rx_ring,
6014 union e1000_adv_rx_desc *rx_desc,
6015 struct sk_buff *skb)
5910{ 6016{
5911 /* HW will not DMA in data larger than the given buffer, even if it 6017 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
5912 * parses the (NFS, of course) header to be larger. In that case, it 6018 unsigned char *va;
5913 * fills the header buffer and spills the rest into the page. 6019 unsigned int pull_len;
6020
6021 /*
6022 * it is valid to use page_address instead of kmap since we are
6023 * working with pages allocated out of the lomem pool per
6024 * alloc_page(GFP_ATOMIC)
5914 */ 6025 */
5915 u16 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) & 6026 va = skb_frag_address(frag);
5916 E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT; 6027
5917 if (hlen > IGB_RX_HDR_LEN) 6028#ifdef CONFIG_IGB_PTP
5918 hlen = IGB_RX_HDR_LEN; 6029 if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
5919 return hlen; 6030 /* retrieve timestamp from buffer */
6031 igb_ptp_rx_pktstamp(rx_ring->q_vector, va, skb);
6032
6033 /* update pointers to remove timestamp header */
6034 skb_frag_size_sub(frag, IGB_TS_HDR_LEN);
6035 frag->page_offset += IGB_TS_HDR_LEN;
6036 skb->data_len -= IGB_TS_HDR_LEN;
6037 skb->len -= IGB_TS_HDR_LEN;
6038
6039 /* move va to start of packet data */
6040 va += IGB_TS_HDR_LEN;
6041 }
6042
6043#endif
6044 /*
6045 * we need the header to contain the greater of either ETH_HLEN or
6046 * 60 bytes if the skb->len is less than 60 for skb_pad.
6047 */
6048 pull_len = igb_get_headlen(va, IGB_RX_HDR_LEN);
6049
6050 /* align pull length to size of long to optimize memcpy performance */
6051 skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
6052
6053 /* update all of the pointers */
6054 skb_frag_size_sub(frag, pull_len);
6055 frag->page_offset += pull_len;
6056 skb->data_len -= pull_len;
6057 skb->tail += pull_len;
6058}
6059
6060/**
6061 * igb_cleanup_headers - Correct corrupted or empty headers
6062 * @rx_ring: rx descriptor ring packet is being transacted on
6063 * @rx_desc: pointer to the EOP Rx descriptor
6064 * @skb: pointer to current skb being fixed
6065 *
6066 * Address the case where we are pulling data in on pages only
6067 * and as such no data is present in the skb header.
6068 *
6069 * In addition if skb is not at least 60 bytes we need to pad it so that
6070 * it is large enough to qualify as a valid Ethernet frame.
6071 *
6072 * Returns true if an error was encountered and skb was freed.
6073 **/
6074static bool igb_cleanup_headers(struct igb_ring *rx_ring,
6075 union e1000_adv_rx_desc *rx_desc,
6076 struct sk_buff *skb)
6077{
6078
6079 if (unlikely((igb_test_staterr(rx_desc,
6080 E1000_RXDEXT_ERR_FRAME_ERR_MASK)))) {
6081 struct net_device *netdev = rx_ring->netdev;
6082 if (!(netdev->features & NETIF_F_RXALL)) {
6083 dev_kfree_skb_any(skb);
6084 return true;
6085 }
6086 }
6087
6088 /* place header in linear portion of buffer */
6089 if (skb_is_nonlinear(skb))
6090 igb_pull_tail(rx_ring, rx_desc, skb);
6091
6092 /* if skb_pad returns an error the skb was freed */
6093 if (unlikely(skb->len < 60)) {
6094 int pad_len = 60 - skb->len;
6095
6096 if (skb_pad(skb, pad_len))
6097 return true;
6098 __skb_put(skb, pad_len);
6099 }
6100
6101 return false;
5920} 6102}
5921 6103
5922static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget) 6104static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
5923{ 6105{
5924 struct igb_ring *rx_ring = q_vector->rx.ring; 6106 struct igb_ring *rx_ring = q_vector->rx.ring;
5925 union e1000_adv_rx_desc *rx_desc; 6107 union e1000_adv_rx_desc *rx_desc;
6108 struct sk_buff *skb = rx_ring->skb;
5926 const int current_node = numa_node_id(); 6109 const int current_node = numa_node_id();
5927 unsigned int total_bytes = 0, total_packets = 0; 6110 unsigned int total_bytes = 0, total_packets = 0;
5928 u16 cleaned_count = igb_desc_unused(rx_ring); 6111 u16 cleaned_count = igb_desc_unused(rx_ring);
@@ -5932,12 +6115,9 @@ static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
5932 6115
5933 while (igb_test_staterr(rx_desc, E1000_RXD_STAT_DD)) { 6116 while (igb_test_staterr(rx_desc, E1000_RXD_STAT_DD)) {
5934 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i]; 6117 struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];
5935 struct sk_buff *skb = buffer_info->skb; 6118 struct page *page;
5936 union e1000_adv_rx_desc *next_rxd; 6119 union e1000_adv_rx_desc *next_rxd;
5937 6120
5938 buffer_info->skb = NULL;
5939 prefetch(skb->data);
5940
5941 i++; 6121 i++;
5942 if (i == rx_ring->count) 6122 if (i == rx_ring->count)
5943 i = 0; 6123 i = 0;
@@ -5952,52 +6132,57 @@ static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
5952 */ 6132 */
5953 rmb(); 6133 rmb();
5954 6134
5955 if (!skb_is_nonlinear(skb)) { 6135 page = buffer_info->page;
5956 __skb_put(skb, igb_get_hlen(rx_desc)); 6136 prefetchw(page);
5957 dma_unmap_single(rx_ring->dev, buffer_info->dma,
5958 IGB_RX_HDR_LEN,
5959 DMA_FROM_DEVICE);
5960 buffer_info->dma = 0;
5961 }
5962
5963 if (rx_desc->wb.upper.length) {
5964 u16 length = le16_to_cpu(rx_desc->wb.upper.length);
5965 6137
5966 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, 6138 if (likely(!skb)) {
5967 buffer_info->page, 6139 void *page_addr = page_address(page) +
5968 buffer_info->page_offset, 6140 buffer_info->page_offset;
5969 length);
5970 6141
5971 skb->len += length; 6142 /* prefetch first cache line of first page */
5972 skb->data_len += length; 6143 prefetch(page_addr);
5973 skb->truesize += PAGE_SIZE / 2; 6144#if L1_CACHE_BYTES < 128
6145 prefetch(page_addr + L1_CACHE_BYTES);
6146#endif
5974 6147
5975 if ((page_count(buffer_info->page) != 1) || 6148 /* allocate a skb to store the frags */
5976 (page_to_nid(buffer_info->page) != current_node)) 6149 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
5977 buffer_info->page = NULL; 6150 IGB_RX_HDR_LEN);
5978 else 6151 if (unlikely(!skb)) {
5979 get_page(buffer_info->page); 6152 rx_ring->rx_stats.alloc_failed++;
6153 break;
6154 }
5980 6155
5981 dma_unmap_page(rx_ring->dev, buffer_info->page_dma, 6156 /*
5982 PAGE_SIZE / 2, DMA_FROM_DEVICE); 6157 * we will be copying header into skb->data in
5983 buffer_info->page_dma = 0; 6158 * pskb_may_pull so it is in our interest to prefetch
6159 * it now to avoid a possible cache miss
6160 */
6161 prefetchw(skb->data);
5984 } 6162 }
5985 6163
5986 if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP)) { 6164 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
5987 struct igb_rx_buffer *next_buffer; 6165 buffer_info->page_offset,
5988 next_buffer = &rx_ring->rx_buffer_info[i]; 6166 le16_to_cpu(rx_desc->wb.upper.length),
5989 buffer_info->skb = next_buffer->skb; 6167 PAGE_SIZE / 2);
5990 buffer_info->dma = next_buffer->dma;
5991 next_buffer->skb = skb;
5992 next_buffer->dma = 0;
5993 goto next_desc;
5994 }
5995 6168
5996 if (unlikely((igb_test_staterr(rx_desc, 6169 if ((page_count(buffer_info->page) != 1) ||
5997 E1000_RXDEXT_ERR_FRAME_ERR_MASK)) 6170 (page_to_nid(buffer_info->page) != current_node))
5998 && !(rx_ring->netdev->features & NETIF_F_RXALL))) { 6171 buffer_info->page = NULL;
5999 dev_kfree_skb_any(skb); 6172 else
6173 get_page(buffer_info->page);
6174
6175 dma_unmap_page(rx_ring->dev, buffer_info->dma,
6176 PAGE_SIZE / 2, DMA_FROM_DEVICE);
6177 buffer_info->dma = 0;
6178
6179 if (!igb_test_staterr(rx_desc, E1000_RXD_STAT_EOP))
6000 goto next_desc; 6180 goto next_desc;
6181
6182 /* verify the packet layout is correct */
6183 if (igb_cleanup_headers(rx_ring, rx_desc, skb)) {
6184 skb = NULL;
6185 continue;
6001 } 6186 }
6002 6187
6003#ifdef CONFIG_IGB_PTP 6188#ifdef CONFIG_IGB_PTP
@@ -6010,10 +6195,14 @@ static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)
6010 total_bytes += skb->len; 6195 total_bytes += skb->len;
6011 total_packets++; 6196 total_packets++;
6012 6197
6198 skb_record_rx_queue(skb, rx_ring->queue_index);
6013 skb->protocol = eth_type_trans(skb, rx_ring->netdev); 6199 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
6014 6200
6015 napi_gro_receive(&q_vector->napi, skb); 6201 napi_gro_receive(&q_vector->napi, skb);
6016 6202
6203 /* reset skb pointer */
6204 skb = NULL;
6205
6017 budget--; 6206 budget--;
6018next_desc: 6207next_desc:
6019 if (!budget) 6208 if (!budget)
@@ -6030,6 +6219,9 @@ next_desc:
6030 rx_desc = next_rxd; 6219 rx_desc = next_rxd;
6031 } 6220 }
6032 6221
6222 /* place incomplete frames back on ring for completion */
6223 rx_ring->skb = skb;
6224
6033 rx_ring->next_to_clean = i; 6225 rx_ring->next_to_clean = i;
6034 u64_stats_update_begin(&rx_ring->rx_syncp); 6226 u64_stats_update_begin(&rx_ring->rx_syncp);
6035 rx_ring->rx_stats.packets += total_packets; 6227 rx_ring->rx_stats.packets += total_packets;
@@ -6044,70 +6236,37 @@ next_desc:
6044 return !!budget; 6236 return !!budget;
6045} 6237}
6046 6238
6047static bool igb_alloc_mapped_skb(struct igb_ring *rx_ring,
6048 struct igb_rx_buffer *bi)
6049{
6050 struct sk_buff *skb = bi->skb;
6051 dma_addr_t dma = bi->dma;
6052
6053 if (dma)
6054 return true;
6055
6056 if (likely(!skb)) {
6057 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
6058 IGB_RX_HDR_LEN);
6059 bi->skb = skb;
6060 if (!skb) {
6061 rx_ring->rx_stats.alloc_failed++;
6062 return false;
6063 }
6064
6065 /* initialize skb for ring */
6066 skb_record_rx_queue(skb, rx_ring->queue_index);
6067 }
6068
6069 dma = dma_map_single(rx_ring->dev, skb->data,
6070 IGB_RX_HDR_LEN, DMA_FROM_DEVICE);
6071
6072 if (dma_mapping_error(rx_ring->dev, dma)) {
6073 rx_ring->rx_stats.alloc_failed++;
6074 return false;
6075 }
6076
6077 bi->dma = dma;
6078 return true;
6079}
6080
6081static bool igb_alloc_mapped_page(struct igb_ring *rx_ring, 6239static bool igb_alloc_mapped_page(struct igb_ring *rx_ring,
6082 struct igb_rx_buffer *bi) 6240 struct igb_rx_buffer *bi)
6083{ 6241{
6084 struct page *page = bi->page; 6242 struct page *page = bi->page;
6085 dma_addr_t page_dma = bi->page_dma; 6243 dma_addr_t dma = bi->dma;
6086 unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2); 6244 unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2);
6087 6245
6088 if (page_dma) 6246 if (dma)
6089 return true; 6247 return true;
6090 6248
6091 if (!page) { 6249 if (!page) {
6092 page = __skb_alloc_page(GFP_ATOMIC, bi->skb); 6250 page = __skb_alloc_page(GFP_ATOMIC | __GFP_COLD, NULL);
6093 bi->page = page;
6094 if (unlikely(!page)) { 6251 if (unlikely(!page)) {
6095 rx_ring->rx_stats.alloc_failed++; 6252 rx_ring->rx_stats.alloc_failed++;
6096 return false; 6253 return false;
6097 } 6254 }
6255 bi->page = page;
6098 } 6256 }
6099 6257
6100 page_dma = dma_map_page(rx_ring->dev, page, 6258 dma = dma_map_page(rx_ring->dev, page,
6101 page_offset, PAGE_SIZE / 2, 6259 page_offset, PAGE_SIZE / 2,
6102 DMA_FROM_DEVICE); 6260 DMA_FROM_DEVICE);
6103 6261
6104 if (dma_mapping_error(rx_ring->dev, page_dma)) { 6262 if (dma_mapping_error(rx_ring->dev, dma)) {
6105 rx_ring->rx_stats.alloc_failed++; 6263 rx_ring->rx_stats.alloc_failed++;
6106 return false; 6264 return false;
6107 } 6265 }
6108 6266
6109 bi->page_dma = page_dma; 6267 bi->dma = dma;
6110 bi->page_offset = page_offset; 6268 bi->page_offset = page_offset;
6269
6111 return true; 6270 return true;
6112} 6271}
6113 6272
@@ -6126,17 +6285,12 @@ void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)
6126 i -= rx_ring->count; 6285 i -= rx_ring->count;
6127 6286
6128 while (cleaned_count--) { 6287 while (cleaned_count--) {
6129 if (!igb_alloc_mapped_skb(rx_ring, bi)) 6288 if (!igb_alloc_mapped_page(rx_ring, bi))
6130 break; 6289 break;
6131 6290
6132 /* Refresh the desc even if buffer_addrs didn't change 6291 /* Refresh the desc even if buffer_addrs didn't change
6133 * because each write-back erases this info. */ 6292 * because each write-back erases this info. */
6134 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); 6293 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
6135
6136 if (!igb_alloc_mapped_page(rx_ring, bi))
6137 break;
6138
6139 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
6140 6294
6141 rx_desc++; 6295 rx_desc++;
6142 bi++; 6296 bi++;