i40e/i40evf: Add support for mapping pages with DMA attributes
authorAlexander Duyck <alexander.h.duyck@intel.com>
Mon, 30 Jan 2017 20:29:35 +0000 (12:29 -0800)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Wed, 15 Mar 2017 09:00:14 +0000 (02:00 -0700)
This patch adds support for DMA_ATTR_SKIP_CPU_SYNC and
DMA_ATTR_WEAK_ORDERING. By enabling both of these for the Rx path we
are able to see performance improvements on architectures that implement
either one due to the fact that page mapping and unmapping only has to
sync what is actually being used instead of the entire buffer. In addition
by enabling the weak ordering attribute enables a performance improvement
for architectures that can associate a memory ordering with a DMA buffer
such as Sparc.

Change-ID: If176824e8231c5b24b8a5d55b339a6026738fc75
Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/i40e/i40e_txrx.c
drivers/net/ethernet/intel/i40e/i40e_txrx.h
drivers/net/ethernet/intel/i40evf/i40e_txrx.c
drivers/net/ethernet/intel/i40evf/i40e_txrx.h

index 97d46058d71d3c118dfa8f5408b888a63fd1a933..86e4991a03a7fd428a3777769f8bcbc74f4896be 100644 (file)
@@ -1010,7 +1010,6 @@ err:
  **/
 void i40e_clean_rx_ring(struct i40e_ring *rx_ring)
 {
-       struct device *dev = rx_ring->dev;
        unsigned long bi_size;
        u16 i;
 
@@ -1030,7 +1029,20 @@ void i40e_clean_rx_ring(struct i40e_ring *rx_ring)
                if (!rx_bi->page)
                        continue;
 
-               dma_unmap_page(dev, rx_bi->dma, PAGE_SIZE, DMA_FROM_DEVICE);
+               /* Invalidate cache lines that may have been written to by
+                * device so that we avoid corrupting memory.
+                */
+               dma_sync_single_range_for_cpu(rx_ring->dev,
+                                             rx_bi->dma,
+                                             rx_bi->page_offset,
+                                             I40E_RXBUFFER_2048,
+                                             DMA_FROM_DEVICE);
+
+               /* free resources associated with mapping */
+               dma_unmap_page_attrs(rx_ring->dev, rx_bi->dma,
+                                    PAGE_SIZE,
+                                    DMA_FROM_DEVICE,
+                                    I40E_RX_DMA_ATTR);
                __free_pages(rx_bi->page, 0);
 
                rx_bi->page = NULL;
@@ -1159,7 +1171,10 @@ static bool i40e_alloc_mapped_page(struct i40e_ring *rx_ring,
        }
 
        /* map page for use */
-       dma = dma_map_page(rx_ring->dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE);
+       dma = dma_map_page_attrs(rx_ring->dev, page, 0,
+                                PAGE_SIZE,
+                                DMA_FROM_DEVICE,
+                                I40E_RX_DMA_ATTR);
 
        /* if mapping failed free memory back to system since
         * there isn't much point in holding memory we can't use
@@ -1219,6 +1234,12 @@ bool i40e_alloc_rx_buffers(struct i40e_ring *rx_ring, u16 cleaned_count)
                if (!i40e_alloc_mapped_page(rx_ring, bi))
                        goto no_buffers;
 
+               /* sync the buffer for use by the device */
+               dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
+                                                bi->page_offset,
+                                                I40E_RXBUFFER_2048,
+                                                DMA_FROM_DEVICE);
+
                /* Refresh the desc even if buffer_addrs didn't change
                 * because each write-back erases this info.
                 */
@@ -1685,8 +1706,8 @@ struct sk_buff *i40e_fetch_rx_buffer(struct i40e_ring *rx_ring,
                rx_ring->rx_stats.page_reuse_count++;
        } else {
                /* we are not reusing the buffer so unmap it */
-               dma_unmap_page(rx_ring->dev, rx_buffer->dma, PAGE_SIZE,
-                              DMA_FROM_DEVICE);
+               dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, PAGE_SIZE,
+                                    DMA_FROM_DEVICE, I40E_RX_DMA_ATTR);
        }
 
        /* clear contents of buffer_info */
index f80979025c0131a07e7b956826f17877b8b7081a..49c7b2089d8e5f99ced01616113fa62154731eb5 100644 (file)
@@ -133,6 +133,9 @@ enum i40e_dyn_idx_t {
 #define I40E_RX_HDR_SIZE I40E_RXBUFFER_256
 #define i40e_rx_desc i40e_32byte_rx_desc
 
+#define I40E_RX_DMA_ATTR \
+       (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
+
 /**
  * i40e_test_staterr - tests bits in Rx descriptor status and error fields
  * @rx_desc: pointer to receive descriptor (in le64 format)
index c91fcf43ccbc5eb7bfe95a9a3eec9c559519fcd0..d7790c08e523b9579741d0dc8d6e42ae84b916c6 100644 (file)
@@ -493,7 +493,6 @@ err:
  **/
 void i40evf_clean_rx_ring(struct i40e_ring *rx_ring)
 {
-       struct device *dev = rx_ring->dev;
        unsigned long bi_size;
        u16 i;
 
@@ -513,7 +512,20 @@ void i40evf_clean_rx_ring(struct i40e_ring *rx_ring)
                if (!rx_bi->page)
                        continue;
 
-               dma_unmap_page(dev, rx_bi->dma, PAGE_SIZE, DMA_FROM_DEVICE);
+               /* Invalidate cache lines that may have been written to by
+                * device so that we avoid corrupting memory.
+                */
+               dma_sync_single_range_for_cpu(rx_ring->dev,
+                                             rx_bi->dma,
+                                             rx_bi->page_offset,
+                                             I40E_RXBUFFER_2048,
+                                             DMA_FROM_DEVICE);
+
+               /* free resources associated with mapping */
+               dma_unmap_page_attrs(rx_ring->dev, rx_bi->dma,
+                                    PAGE_SIZE,
+                                    DMA_FROM_DEVICE,
+                                    I40E_RX_DMA_ATTR);
                __free_pages(rx_bi->page, 0);
 
                rx_bi->page = NULL;
@@ -642,7 +654,10 @@ static bool i40e_alloc_mapped_page(struct i40e_ring *rx_ring,
        }
 
        /* map page for use */
-       dma = dma_map_page(rx_ring->dev, page, 0, PAGE_SIZE, DMA_FROM_DEVICE);
+       dma = dma_map_page_attrs(rx_ring->dev, page, 0,
+                                PAGE_SIZE,
+                                DMA_FROM_DEVICE,
+                                I40E_RX_DMA_ATTR);
 
        /* if mapping failed free memory back to system since
         * there isn't much point in holding memory we can't use
@@ -702,6 +717,12 @@ bool i40evf_alloc_rx_buffers(struct i40e_ring *rx_ring, u16 cleaned_count)
                if (!i40e_alloc_mapped_page(rx_ring, bi))
                        goto no_buffers;
 
+               /* sync the buffer for use by the device */
+               dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
+                                                bi->page_offset,
+                                                I40E_RXBUFFER_2048,
+                                                DMA_FROM_DEVICE);
+
                /* Refresh the desc even if buffer_addrs didn't change
                 * because each write-back erases this info.
                 */
@@ -1158,8 +1179,8 @@ struct sk_buff *i40evf_fetch_rx_buffer(struct i40e_ring *rx_ring,
                rx_ring->rx_stats.page_reuse_count++;
        } else {
                /* we are not reusing the buffer so unmap it */
-               dma_unmap_page(rx_ring->dev, rx_buffer->dma, PAGE_SIZE,
-                              DMA_FROM_DEVICE);
+               dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, PAGE_SIZE,
+                                    DMA_FROM_DEVICE, I40E_RX_DMA_ATTR);
        }
 
        /* clear contents of buffer_info */
index 8274ba68bd32a6583538f7af6fd80417dc25e6ec..013512124e6a947949bc28aad53af03dcd30534f 100644 (file)
@@ -120,6 +120,9 @@ enum i40e_dyn_idx_t {
 #define I40E_RX_HDR_SIZE I40E_RXBUFFER_256
 #define i40e_rx_desc i40e_32byte_rx_desc
 
+#define I40E_RX_DMA_ATTR \
+       (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING)
+
 /**
  * i40e_test_staterr - tests bits in Rx descriptor status and error fields
  * @rx_desc: pointer to receive descriptor (in le64 format)