netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2 1/2] sfc: use 64-bit writes for PIO.
       [not found] <cover.1401268725.git.sshah@solarflare.com>
@ 2014-05-28  9:27 ` Shradha Shah
  2014-05-28  9:32   ` Shradha Shah
  2014-05-28 14:48   ` Sergei Shtylyov
  2014-05-28  9:28 ` [PATCH net v2 2/2] sfc: Restrict PIO to 64-bit architectures Shradha Shah
  1 sibling, 2 replies; 6+ messages in thread
From: Shradha Shah @ 2014-05-28  9:27 UTC (permalink / raw)
  To: netdev; +Cc: linux-net-drivers

From: Jon Cooper <jcooper@solarflare.com>

Patch to open-code the memory copy routines.
32bit writes over the PCI bus causes data corruption.

Fixes:ee45fd92c739db5b7950163d91dfe5f016af6d24

orig-hg-hash: 853f313def1e5e9c733f980f2b4e6330a7d063ef
Signed-off-by: Shradha Shah <sshah@solarflare.com>
---
 drivers/net/ethernet/sfc/tx.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/sfc/tx.c b/drivers/net/ethernet/sfc/tx.c
index fa94753..bd6a4b8 100644
--- a/drivers/net/ethernet/sfc/tx.c
+++ b/drivers/net/ethernet/sfc/tx.c
@@ -189,6 +189,20 @@ struct efx_short_copy_buffer {
 	u8 buf[L1_CACHE_BYTES];
 };
 
+/* Copy in explicit 64-bit writes. */
+static void efx_memcpy_64(void *dest, void *src, size_t len)
+{
+	uint64_t *src64 = src, *dest64 = dest;
+	size_t i, l64 = len / 8;
+
+	WARN_ON_ONCE(len % 8 != 0);
+	WARN_ON_ONCE(((u8 *)dest - (u8 *) 0) % 8 != 0);
+	BUILD_BUG_ON(sizeof(uint64_t) != 8);
+
+	for(i = 0; i < l64; ++i)
+		dest64[i] = src64[i];
+}
+
 /* Copy to PIO, respecting that writes to PIO buffers must be dword aligned.
  * Advances piobuf pointer. Leaves additional data in the copy buffer.
  */
@@ -198,7 +212,7 @@ static void efx_memcpy_toio_aligned(struct efx_nic *efx, u8 __iomem **piobuf,
 {
 	int block_len = len & ~(sizeof(copy_buf->buf) - 1);
 
-	memcpy_toio(*piobuf, data, block_len);
+	efx_memcpy_64(*piobuf, data, block_len);
 	*piobuf += block_len;
 	len -= block_len;
 
@@ -230,7 +244,7 @@ static void efx_memcpy_toio_aligned_cb(struct efx_nic *efx, u8 __iomem **piobuf,
 		if (copy_buf->used < sizeof(copy_buf->buf))
 			return;
 
-		memcpy_toio(*piobuf, copy_buf->buf, sizeof(copy_buf->buf));
+		efx_memcpy_64(*piobuf, copy_buf->buf, sizeof(copy_buf->buf));
 		*piobuf += sizeof(copy_buf->buf);
 		data += copy_to_buf;
 		len -= copy_to_buf;
@@ -245,7 +259,7 @@ static void efx_flush_copy_buffer(struct efx_nic *efx, u8 __iomem *piobuf,
 {
 	/* if there's anything in it, write the whole buffer, including junk */
 	if (copy_buf->used)
-		memcpy_toio(piobuf, copy_buf->buf, sizeof(copy_buf->buf));
+		efx_memcpy_64(piobuf, copy_buf->buf, sizeof(copy_buf->buf));
 }
 
 /* Traverse skb structure and copy fragments in to PIO buffer.
@@ -304,8 +318,8 @@ efx_enqueue_skb_pio(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
 		 */
 		BUILD_BUG_ON(L1_CACHE_BYTES >
 			     SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
-		memcpy_toio(tx_queue->piobuf, skb->data,
-			    ALIGN(skb->len, L1_CACHE_BYTES));
+		efx_memcpy_64(tx_queue->piobuf, skb->data,
+			      ALIGN(skb->len, L1_CACHE_BYTES));
 	}
 
 	EFX_POPULATE_QWORD_5(buffer->option,

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net v2 1/2] sfc: use 64-bit writes for PIO.
  2014-05-28  9:23 [PATCH net v2 0/2] sfc: Restrict PIO for 64bit arch in order to avoid data corruption Shradha Shah
@ 2014-05-28  9:28 ` Shradha Shah
  0 siblings, 0 replies; 6+ messages in thread
From: Shradha Shah @ 2014-05-28  9:28 UTC (permalink / raw)
  Cc: netdev, linux-net-drivers

From: Jon Cooper <jcooper@solarflare.com>

Patch to open-code the memory copy routines.
32bit writes over the PCI bus causes data corruption.

Fixes:ee45fd92c739db5b7950163d91dfe5f016af6d24

orig-hg-hash: 853f313def1e5e9c733f980f2b4e6330a7d063ef
Signed-off-by: Shradha Shah <sshah@solarflare.com>
---
 drivers/net/ethernet/sfc/tx.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/sfc/tx.c b/drivers/net/ethernet/sfc/tx.c
index fa94753..bd6a4b8 100644
--- a/drivers/net/ethernet/sfc/tx.c
+++ b/drivers/net/ethernet/sfc/tx.c
@@ -189,6 +189,20 @@ struct efx_short_copy_buffer {
 	u8 buf[L1_CACHE_BYTES];
 };
 
+/* Copy in explicit 64-bit writes. */
+static void efx_memcpy_64(void *dest, void *src, size_t len)
+{
+	uint64_t *src64 = src, *dest64 = dest;
+	size_t i, l64 = len / 8;
+
+	WARN_ON_ONCE(len % 8 != 0);
+	WARN_ON_ONCE(((u8 *)dest - (u8 *) 0) % 8 != 0);
+	BUILD_BUG_ON(sizeof(uint64_t) != 8);
+
+	for(i = 0; i < l64; ++i)
+		dest64[i] = src64[i];
+}
+
 /* Copy to PIO, respecting that writes to PIO buffers must be dword aligned.
  * Advances piobuf pointer. Leaves additional data in the copy buffer.
  */
@@ -198,7 +212,7 @@ static void efx_memcpy_toio_aligned(struct efx_nic *efx, u8 __iomem **piobuf,
 {
 	int block_len = len & ~(sizeof(copy_buf->buf) - 1);
 
-	memcpy_toio(*piobuf, data, block_len);
+	efx_memcpy_64(*piobuf, data, block_len);
 	*piobuf += block_len;
 	len -= block_len;
 
@@ -230,7 +244,7 @@ static void efx_memcpy_toio_aligned_cb(struct efx_nic *efx, u8 __iomem **piobuf,
 		if (copy_buf->used < sizeof(copy_buf->buf))
 			return;
 
-		memcpy_toio(*piobuf, copy_buf->buf, sizeof(copy_buf->buf));
+		efx_memcpy_64(*piobuf, copy_buf->buf, sizeof(copy_buf->buf));
 		*piobuf += sizeof(copy_buf->buf);
 		data += copy_to_buf;
 		len -= copy_to_buf;
@@ -245,7 +259,7 @@ static void efx_flush_copy_buffer(struct efx_nic *efx, u8 __iomem *piobuf,
 {
 	/* if there's anything in it, write the whole buffer, including junk */
 	if (copy_buf->used)
-		memcpy_toio(piobuf, copy_buf->buf, sizeof(copy_buf->buf));
+		efx_memcpy_64(piobuf, copy_buf->buf, sizeof(copy_buf->buf));
 }
 
 /* Traverse skb structure and copy fragments in to PIO buffer.
@@ -304,8 +318,8 @@ efx_enqueue_skb_pio(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
 		 */
 		BUILD_BUG_ON(L1_CACHE_BYTES >
 			     SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
-		memcpy_toio(tx_queue->piobuf, skb->data,
-			    ALIGN(skb->len, L1_CACHE_BYTES));
+		efx_memcpy_64(tx_queue->piobuf, skb->data,
+			      ALIGN(skb->len, L1_CACHE_BYTES));
 	}
 
 	EFX_POPULATE_QWORD_5(buffer->option,

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net v2 2/2] sfc: Restrict PIO to 64-bit architectures
       [not found] <cover.1401268725.git.sshah@solarflare.com>
  2014-05-28  9:27 ` [PATCH net v2 1/2] sfc: use 64-bit writes for PIO Shradha Shah
@ 2014-05-28  9:28 ` Shradha Shah
  2014-05-28 14:45   ` Sergei Shtylyov
  1 sibling, 1 reply; 6+ messages in thread
From: Shradha Shah @ 2014-05-28  9:28 UTC (permalink / raw)
  To: netdev; +Cc: linux-net-drivers

From: Jon Cooper <jcooper@solarflare.com>

Enable PIO for x86_64 architecture only.
Not tested on platforms other than x86_64.

Fixes:ee45fd92c739db5b7950163d91dfe5f016af6d24

orig-hg-hash: 53dc43553d9bbe1c5a64c49e580ca571ddc470ae
Signed-off-by: Shradha Shah <sshah@solarflare.com>
---
 drivers/net/ethernet/sfc/io.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/sfc/io.h b/drivers/net/ethernet/sfc/io.h
index 4d3f119..adadcf0 100644
--- a/drivers/net/ethernet/sfc/io.h
+++ b/drivers/net/ethernet/sfc/io.h
@@ -66,10 +66,18 @@
 #define EFX_USE_QWORD_IO 1
 #endif
 
+/* PIO only works on 64-bit architectures */
+#if BITS_PER_LONG == 64
+/* not strictly necessary to restrict to x86 arch, but done for safety
+ * since unusual write combining behaviour can break PIO.
+ */
+#ifdef CONFIG_X86_64
 /* PIO is a win only if write-combining is possible */
 #ifdef ARCH_HAS_IOREMAP_WC
 #define EFX_USE_PIO 1
 #endif
+#endif
+#endif
 
 #ifdef EFX_USE_QWORD_IO
 static inline void _efx_writeq(struct efx_nic *efx, __le64 value,

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net v2 1/2] sfc: use 64-bit writes for PIO.
  2014-05-28  9:27 ` [PATCH net v2 1/2] sfc: use 64-bit writes for PIO Shradha Shah
@ 2014-05-28  9:32   ` Shradha Shah
  2014-05-28 14:48   ` Sergei Shtylyov
  1 sibling, 0 replies; 6+ messages in thread
From: Shradha Shah @ 2014-05-28  9:32 UTC (permalink / raw)
  To: netdev; +Cc: linux-net-drivers

Please ignore this patch.

I have sent out the correct patch with a cover letter.

My Apologies for duplication

Regards,
Shradha

On 28/05/14 10:27, Shradha Shah wrote:
> From: Jon Cooper <jcooper@solarflare.com>
> 
> Patch to open-code the memory copy routines.
> 32bit writes over the PCI bus causes data corruption.
> 
> Fixes:ee45fd92c739db5b7950163d91dfe5f016af6d24
> 
> orig-hg-hash: 853f313def1e5e9c733f980f2b4e6330a7d063ef
> Signed-off-by: Shradha Shah <sshah@solarflare.com>
> ---
>  drivers/net/ethernet/sfc/tx.c | 24 +++++++++++++++++++-----
>  1 file changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/sfc/tx.c b/drivers/net/ethernet/sfc/tx.c
> index fa94753..bd6a4b8 100644
> --- a/drivers/net/ethernet/sfc/tx.c
> +++ b/drivers/net/ethernet/sfc/tx.c
> @@ -189,6 +189,20 @@ struct efx_short_copy_buffer {
>  	u8 buf[L1_CACHE_BYTES];
>  };
>  
> +/* Copy in explicit 64-bit writes. */
> +static void efx_memcpy_64(void *dest, void *src, size_t len)
> +{
> +	uint64_t *src64 = src, *dest64 = dest;
> +	size_t i, l64 = len / 8;
> +
> +	WARN_ON_ONCE(len % 8 != 0);
> +	WARN_ON_ONCE(((u8 *)dest - (u8 *) 0) % 8 != 0);
> +	BUILD_BUG_ON(sizeof(uint64_t) != 8);
> +
> +	for(i = 0; i < l64; ++i)
> +		dest64[i] = src64[i];
> +}
> +
>  /* Copy to PIO, respecting that writes to PIO buffers must be dword aligned.
>   * Advances piobuf pointer. Leaves additional data in the copy buffer.
>   */
> @@ -198,7 +212,7 @@ static void efx_memcpy_toio_aligned(struct efx_nic *efx, u8 __iomem **piobuf,
>  {
>  	int block_len = len & ~(sizeof(copy_buf->buf) - 1);
>  
> -	memcpy_toio(*piobuf, data, block_len);
> +	efx_memcpy_64(*piobuf, data, block_len);
>  	*piobuf += block_len;
>  	len -= block_len;
>  
> @@ -230,7 +244,7 @@ static void efx_memcpy_toio_aligned_cb(struct efx_nic *efx, u8 __iomem **piobuf,
>  		if (copy_buf->used < sizeof(copy_buf->buf))
>  			return;
>  
> -		memcpy_toio(*piobuf, copy_buf->buf, sizeof(copy_buf->buf));
> +		efx_memcpy_64(*piobuf, copy_buf->buf, sizeof(copy_buf->buf));
>  		*piobuf += sizeof(copy_buf->buf);
>  		data += copy_to_buf;
>  		len -= copy_to_buf;
> @@ -245,7 +259,7 @@ static void efx_flush_copy_buffer(struct efx_nic *efx, u8 __iomem *piobuf,
>  {
>  	/* if there's anything in it, write the whole buffer, including junk */
>  	if (copy_buf->used)
> -		memcpy_toio(piobuf, copy_buf->buf, sizeof(copy_buf->buf));
> +		efx_memcpy_64(piobuf, copy_buf->buf, sizeof(copy_buf->buf));
>  }
>  
>  /* Traverse skb structure and copy fragments in to PIO buffer.
> @@ -304,8 +318,8 @@ efx_enqueue_skb_pio(struct efx_tx_queue *tx_queue, struct sk_buff *skb)
>  		 */
>  		BUILD_BUG_ON(L1_CACHE_BYTES >
>  			     SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
> -		memcpy_toio(tx_queue->piobuf, skb->data,
> -			    ALIGN(skb->len, L1_CACHE_BYTES));
> +		efx_memcpy_64(tx_queue->piobuf, skb->data,
> +			      ALIGN(skb->len, L1_CACHE_BYTES));
>  	}
>  
>  	EFX_POPULATE_QWORD_5(buffer->option,
> 

-- 
Many Thanks,
Regards,
Shradha Shah

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net v2 2/2] sfc: Restrict PIO to 64-bit architectures
  2014-05-28  9:28 ` [PATCH net v2 2/2] sfc: Restrict PIO to 64-bit architectures Shradha Shah
@ 2014-05-28 14:45   ` Sergei Shtylyov
  0 siblings, 0 replies; 6+ messages in thread
From: Sergei Shtylyov @ 2014-05-28 14:45 UTC (permalink / raw)
  To: Shradha Shah, netdev; +Cc: linux-net-drivers

Hello.

On 05/28/2014 01:28 PM, Shradha Shah wrote:

> From: Jon Cooper <jcooper@solarflare.com>

> Enable PIO for x86_64 architecture only.
> Not tested on platforms other than x86_64.

> Fixes:ee45fd92c739db5b7950163d91dfe5f016af6d24

    12 digits is enough. And please specify that commit's summary enclosed in 
parens and quotes.

> orig-hg-hash: 53dc43553d9bbe1c5a64c49e580ca571ddc470ae
> Signed-off-by: Shradha Shah <sshah@solarflare.com>
> ---
>   drivers/net/ethernet/sfc/io.h | 8 ++++++++
>   1 file changed, 8 insertions(+)

WBR, Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net v2 1/2] sfc: use 64-bit writes for PIO.
  2014-05-28  9:27 ` [PATCH net v2 1/2] sfc: use 64-bit writes for PIO Shradha Shah
  2014-05-28  9:32   ` Shradha Shah
@ 2014-05-28 14:48   ` Sergei Shtylyov
  1 sibling, 0 replies; 6+ messages in thread
From: Sergei Shtylyov @ 2014-05-28 14:48 UTC (permalink / raw)
  To: Shradha Shah, netdev; +Cc: linux-net-drivers

On 05/28/2014 01:27 PM, Shradha Shah wrote:

> From: Jon Cooper <jcooper@solarflare.com>

> Patch to open-code the memory copy routines.
> 32bit writes over the PCI bus causes data corruption.

> Fixes:ee45fd92c739db5b7950163d91dfe5f016af6d24

    Same comment as in the patch #2

> orig-hg-hash: 853f313def1e5e9c733f980f2b4e6330a7d063ef

    What's this?

> Signed-off-by: Shradha Shah <sshah@solarflare.com>
> ---
>   drivers/net/ethernet/sfc/tx.c | 24 +++++++++++++++++++-----
>   1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethernet/sfc/tx.c b/drivers/net/ethernet/sfc/tx.c
> index fa94753..bd6a4b8 100644
> --- a/drivers/net/ethernet/sfc/tx.c
> +++ b/drivers/net/ethernet/sfc/tx.c
> @@ -189,6 +189,20 @@ struct efx_short_copy_buffer {
>   	u8 buf[L1_CACHE_BYTES];
>   };
>
> +/* Copy in explicit 64-bit writes. */
> +static void efx_memcpy_64(void *dest, void *src, size_t len)
> +{
> +	uint64_t *src64 = src, *dest64 = dest;
> +	size_t i, l64 = len / 8;
> +
> +	WARN_ON_ONCE(len % 8 != 0);
> +	WARN_ON_ONCE(((u8 *)dest - (u8 *) 0) % 8 != 0);

    Be consistent with spaces after a typecast, please.

> +	BUILD_BUG_ON(sizeof(uint64_t) != 8);
> +
> +	for(i = 0; i < l64; ++i)
> +		dest64[i] = src64[i];
> +}
> +
>   /* Copy to PIO, respecting that writes to PIO buffers must be dword aligned.
>    * Advances piobuf pointer. Leaves additional data in the copy buffer.
>    */
[...]

WBR, Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-05-28 14:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1401268725.git.sshah@solarflare.com>
2014-05-28  9:27 ` [PATCH net v2 1/2] sfc: use 64-bit writes for PIO Shradha Shah
2014-05-28  9:32   ` Shradha Shah
2014-05-28 14:48   ` Sergei Shtylyov
2014-05-28  9:28 ` [PATCH net v2 2/2] sfc: Restrict PIO to 64-bit architectures Shradha Shah
2014-05-28 14:45   ` Sergei Shtylyov
2014-05-28  9:23 [PATCH net v2 0/2] sfc: Restrict PIO for 64bit arch in order to avoid data corruption Shradha Shah
2014-05-28  9:28 ` [PATCH net v2 1/2] sfc: use 64-bit writes for PIO Shradha Shah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).