[PATCH] pch_gbe: Fix the issue that the receiving data is not normal.

Subsystems: networking drivers, the rest

STALE5744d

3 messages, 2 authors, 2011-01-27 · open the first message on its own page

[PATCH] pch_gbe: Fix the issue that the receiving data is not normal.

From: Toshiharu Okada <hidden>
Date: 2011-01-24 04:41:26

This PCH_GBE driver had an issue that the receiving data is not normal.
This driver had not removed correctly the padding data 
which the DMA include in receiving data. 

This patch fixed this issue.

Signed-off-by: Toshiharu Okada <redacted>
---
 drivers/net/pch_gbe/pch_gbe_main.c |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/drivers/net/pch_gbe/pch_gbe_main.c b/drivers/net/pch_gbe/pch_gbe_main.c
index 03a1d28..1bf2626 100644
--- a/drivers/net/pch_gbe/pch_gbe_main.c
+++ b/drivers/net/pch_gbe/pch_gbe_main.c
@@ -29,6 +29,7 @@ const char pch_driver_version[] = DRV_VERSION;
 #define PCH_GBE_SHORT_PKT		64
 #define DSC_INIT16			0xC000
 #define PCH_GBE_DMA_ALIGN		0
+#define PCH_GBE_DMA_PADDING		2
 #define PCH_GBE_WATCHDOG_PERIOD		(1 * HZ)	/* watchdog time */
 #define PCH_GBE_COPYBREAK_DEFAULT	256
 #define PCH_GBE_PCI_BAR			1
@@ -1422,8 +1423,8 @@ pch_gbe_clean_rx(struct pch_gbe_adapter *adapter,
 			pr_err("Receive CRC Error\n");
 		} else {
 			/* get receive length */
-			/* length convert[-3], padding[-2] */
-			length = (rx_desc->rx_words_eob) - 3 - 2;
+			/* length convert[-3] */
+			length = (rx_desc->rx_words_eob) - 3;
 
 			/* Decide the data conversion method */
 			if (!adapter->rx_csum) {
@@ -1443,12 +1444,11 @@ pch_gbe_clean_rx(struct pch_gbe_adapter *adapter,
 			if (skb_copy_flag) {	/* recycle  skb */
 				struct sk_buff *new_skb;
 				new_skb =
-				    netdev_alloc_skb(netdev,
-						     length + NET_IP_ALIGN);
+				    netdev_alloc_skb(netdev, length);
 				if (new_skb) {
 					if (!skb_padding_flag) {
 						skb_reserve(new_skb,
-								NET_IP_ALIGN);
+							PCH_GBE_DMA_PADDING);
 					}
 					memcpy(new_skb->data, skb->data,
 						length);
@@ -1465,12 +1465,15 @@ pch_gbe_clean_rx(struct pch_gbe_adapter *adapter,
 			}
 			if (skb_padding_flag) {
 				memcpy(&tmp_packet[0], &skb->data[0], ETH_HLEN);
-				memcpy(&skb->data[NET_IP_ALIGN], &tmp_packet[0],
-					ETH_HLEN);
-				skb_reserve(skb, NET_IP_ALIGN);
-
+				memcpy(&skb->data[PCH_GBE_DMA_PADDING],
+				       &tmp_packet[0], ETH_HLEN);
+				skb_reserve(skb, PCH_GBE_DMA_PADDING);
+				/* The length includes padding length */
+				length = length - PCH_GBE_DMA_PADDING;
 			}
 
+			/* The length includes FCS length */
+			length = length - ETH_FCS_LEN;
 			/* update status of driver */
 			adapter->stats.rx_bytes += length;
 			adapter->stats.rx_packets++;
-- 
1.6.2.5

Re: [PATCH] pch_gbe: Fix the issue that the receiving data is not normal.

From: David Miller <davem@davemloft.net>
Date: 2011-01-25 21:32:08

From: Toshiharu Okada <redacted>
Date: Mon, 24 Jan 2011 13:43:31 +0900
This PCH_GBE driver had an issue that the receiving data is not normal.
This driver had not removed correctly the padding data 
which the DMA include in receiving data. 

This patch fixed this issue.

Signed-off-by: Toshiharu Okada <redacted>
There are bugs in these changes:
quoted hunk
 			if (skb_copy_flag) {	/* recycle  skb */
 				struct sk_buff *new_skb;
 				new_skb =
-				    netdev_alloc_skb(netdev,
-						     length + NET_IP_ALIGN);
+				    netdev_alloc_skb(netdev, length);
 				if (new_skb) {
 					if (!skb_padding_flag) {
 						skb_reserve(new_skb,
-								NET_IP_ALIGN);
+							PCH_GBE_DMA_PADDING);
 					}
 					memcpy(new_skb->data, skb->data,
 						length);
If "!skb_padding_flag" then you will write past the end of the SKB
data in that memcpy.

You cannot allocate only "length" then proceed to reserve PCH_GBE_DMA_PADDING
and then add "length" worth of data on top of that.  In such a cause you
must allocate at least "length + PCH_GBE_DMA_PADDING".

Furthermore you _MUST_ respect NET_IP_ALIGN.  Some platforms set this value
to "0", because otherwise performance suffers greatly.

There are two seperate issues, removing the padding bytes provided by
the device, and aligning the IP headers as wanted by the cpu
architecutre.  Therefore they should be handled seperately, and we
therefore should still see references to NET_IP_ALIGN in your patch.

Re: [PATCH] pch_gbe: Fix the issue that the receiving data is not normal.

From: Toshiharu Okada <hidden>
Date: 2011-01-27 08:45:42

Hi David

Thank you for your comment.
I will confirm them  and will submit the patch modified.

Best regards
Toshiharu Okada(OKI semiconductor)
----- Original Message ----- 
From: "David Miller" <davem@davemloft.net>
To: <redacted>
Cc: <redacted>; <redacted>; 
[off-list ref]; [off-list ref]; 
[off-list ref]; [off-list ref]; 
[off-list ref]
Sent: Wednesday, January 26, 2011 6:32 AM
Subject: Re: [PATCH] pch_gbe: Fix the issue that the receiving data is not 
normal.


From: Toshiharu Okada <redacted>
Date: Mon, 24 Jan 2011 13:43:31 +0900
This PCH_GBE driver had an issue that the receiving data is not normal.
This driver had not removed correctly the padding data
which the DMA include in receiving data.

This patch fixed this issue.

Signed-off-by: Toshiharu Okada <redacted>
There are bugs in these changes:
quoted hunk
 if (skb_copy_flag) { /* recycle  skb */
 struct sk_buff *new_skb;
 new_skb =
-     netdev_alloc_skb(netdev,
-      length + NET_IP_ALIGN);
+     netdev_alloc_skb(netdev, length);
 if (new_skb) {
 if (!skb_padding_flag) {
 skb_reserve(new_skb,
- NET_IP_ALIGN);
+ PCH_GBE_DMA_PADDING);
 }
 memcpy(new_skb->data, skb->data,
 length);
If "!skb_padding_flag" then you will write past the end of the SKB
data in that memcpy.

You cannot allocate only "length" then proceed to reserve 
PCH_GBE_DMA_PADDING
and then add "length" worth of data on top of that.  In such a cause you
must allocate at least "length + PCH_GBE_DMA_PADDING".

Furthermore you _MUST_ respect NET_IP_ALIGN.  Some platforms set this value
to "0", because otherwise performance suffers greatly.

There are two seperate issues, removing the padding bytes provided by
the device, and aligning the IP headers as wanted by the cpu
architecutre.  Therefore they should be handled seperately, and we
therefore should still see references to NET_IP_ALIGN in your patch.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help