From: Paul Burton <paul.burton@mips.com>
To: <netdev@vger.kernel.org>
Cc: Hassan Naveed <hassan.naveed@mips.com>,
Matt Redfearn <matt.redfearn@mips.com>,
"David S . Miller" <davem@davemloft.net>,
<linux-mips@linux-mips.org>, Paul Burton <paul.burton@mips.com>
Subject: [PATCH v5 07/14] net: pch_gbe: Fix handling of TX padding
Date: Sat, 17 Feb 2018 12:10:30 -0800 [thread overview]
Message-ID: <20180217201037.3006-8-paul.burton@mips.com> (raw)
In-Reply-To: <20180217201037.3006-1-paul.burton@mips.com>
The ethernet controller found in the Intel EG20T Platform Controller
Hub requires that we place 2 bytes of padding between the ethernet
header & the packet payload. Our pch_gbe driver handles this by copying
packets to be transmitted to a temporary struct skb with the padding
bytes inserted, however it sets the length of this temporary skb to
equal that of the original, without the 2 padding bytes, and then uses
this length as that of the memory to map for DMA.
This is problematic on systems that don't have cache-coherent DMA, since
if the length of the original buffer is either a multiple of the
system's cache line size or one less than such a multiple then the size
we provide to dma_map_single() will not cover the last byte or two of
the data when rounded up to a cache line boundary. This may result in us
transmitting corrupt data in the last one or two bytes of the packet,
depending upon its length.
Fix this by setting the length of tmp_skb to include the 2 padding
bytes, which is actually the length of the data it holds. This is then
assigned to buffer_info->length & provided to dma_map_single() which
will operate on all of the data as desired. The EG20T datasheet
specifies that the padding bytes should not be included in the length
stored in the TX descriptor, so we switch that to use the length of the
original skb.
Whilst modifying this code we switch to using PCH_GBE_DMA_PADDING rather
than the magic number 2 to specify the size of the padding, making it
clearer what the code is doing, and fix a typo in the comment indicating
that padding is inserted.
Signed-off-by: Paul Burton <paul.burton@mips.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: linux-mips@linux-mips.org
Cc: netdev@vger.kernel.org
---
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
index 77f7fbd98e8f..60e91c0fc98b 100644
--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
@@ -1223,13 +1223,12 @@ static void pch_gbe_tx_queue(struct pch_gbe_adapter *adapter,
buffer_info = &tx_ring->buffer_info[ring_num];
tmp_skb = buffer_info->skb;
- /* [Header:14][payload] ---> [Header:14][paddong:2][payload] */
+ /* [Header:14][payload] ---> [Header:14][padding:2][payload] */
memcpy(tmp_skb->data, skb->data, ETH_HLEN);
- tmp_skb->data[ETH_HLEN] = 0x00;
- tmp_skb->data[ETH_HLEN + 1] = 0x00;
- tmp_skb->len = skb->len;
- memcpy(&tmp_skb->data[ETH_HLEN + 2], &skb->data[ETH_HLEN],
- (skb->len - ETH_HLEN));
+ memset(&tmp_skb->data[ETH_HLEN], 0, PCH_GBE_DMA_PADDING);
+ memcpy(&tmp_skb->data[ETH_HLEN + PCH_GBE_DMA_PADDING],
+ &skb->data[ETH_HLEN], skb->len - ETH_HLEN);
+ tmp_skb->len = skb->len + PCH_GBE_DMA_PADDING;
/*-- Set Buffer information --*/
buffer_info->length = tmp_skb->len;
buffer_info->dma = dma_map_single(&adapter->pdev->dev, tmp_skb->data,
@@ -1248,8 +1247,8 @@ static void pch_gbe_tx_queue(struct pch_gbe_adapter *adapter,
/*-- Set Tx descriptor --*/
tx_desc = PCH_GBE_TX_DESC(*tx_ring, ring_num);
tx_desc->buffer_addr = (buffer_info->dma);
- tx_desc->length = (tmp_skb->len);
- tx_desc->tx_words_eob = ((tmp_skb->len + 3));
+ tx_desc->length = (skb->len);
+ tx_desc->tx_words_eob = ((skb->len + 3));
tx_desc->tx_frame_ctrl = (frame_ctrl);
tx_desc->gbec_status = (DSC_INIT16);
--
2.16.1
next prev parent reply other threads:[~2018-02-17 20:10 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-17 20:10 [PATCH v5 00/14] net: pch_gbe: Fixes & MIPS support Paul Burton
2018-02-17 20:10 ` [PATCH v5 01/14] net: pch_gbe: Mark Minnow PHY reset GPIO active low Paul Burton
2018-02-17 22:14 ` Andrew Lunn
2018-02-17 20:10 ` [PATCH v5 02/14] net: pch_gbe: Pull PHY GPIO handling out of Minnow code Paul Burton
2018-02-17 22:29 ` Andrew Lunn
2018-02-17 22:50 ` Paul Burton
2018-02-17 23:34 ` Andrew Lunn
2018-02-18 15:51 ` Paul Burton
2018-02-18 16:14 ` Andrew Lunn
2018-02-17 20:10 ` [PATCH v5 03/14] dt-bindings: net: Document Intel pch_gbe binding Paul Burton
[not found] ` <20180217201037.3006-4-paul.burton-8NJIiSa5LzA@public.gmane.org>
2018-02-17 22:32 ` Andrew Lunn
2018-02-17 20:10 ` [PATCH v5 04/14] net: pch_gbe: Add device tree support Paul Burton
2018-02-17 20:10 ` [PATCH v5 05/14] net: pch_gbe: Always reset PHY along with MAC Paul Burton
2018-02-17 20:10 ` [PATCH v5 06/14] net: pch_gbe: Allow longer for resets Paul Burton
2018-02-18 15:29 ` kbuild test robot
2018-02-17 20:10 ` Paul Burton [this message]
2018-02-19 14:01 ` [PATCH v5 07/14] net: pch_gbe: Fix handling of TX padding David Laight
2018-02-19 16:42 ` Paul Burton
2018-02-19 16:41 ` David Miller
2018-02-17 20:10 ` [PATCH v5 08/14] net: pch_gbe: Fold pch_gbe_setup_[rt]ctl into pch_gbe_configure_[rt]x Paul Burton
2018-02-17 20:10 ` [PATCH v5 09/14] net: pch_gbe: Use pch_gbe_disable_dma_rx() in pch_gbe_configure_rx() Paul Burton
2018-02-17 20:10 ` [PATCH v5 10/14] net: pch_gbe: Disable TX DMA whilst configuring descriptors Paul Burton
2018-02-17 20:10 ` [PATCH v5 11/14] net: pch_gbe: Ensure DMA is ordered with descriptor writes Paul Burton
2018-02-17 20:10 ` [PATCH v5 12/14] net: pch_gbe: Fix TX RX descriptor accesses for big endian systems Paul Burton
2018-02-18 16:01 ` kbuild test robot
2018-02-17 20:10 ` [PATCH v5 13/14] ptp: pch: Allow build on MIPS platforms Paul Burton
2018-02-17 20:10 ` [PATCH v5 14/14] net: pch_gbe: " Paul Burton
2018-02-18 15:31 ` [PATCH v5 00/14] net: pch_gbe: Fixes & MIPS support David Miller
2018-02-18 17:03 ` Paul Burton
2018-02-18 17:56 ` Andrew Lunn
2018-02-18 22:09 ` Paul Burton
2018-02-19 1:15 ` David Miller
2018-02-19 2:17 ` Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180217201037.3006-8-paul.burton@mips.com \
--to=paul.burton@mips.com \
--cc=davem@davemloft.net \
--cc=hassan.naveed@mips.com \
--cc=linux-mips@linux-mips.org \
--cc=matt.redfearn@mips.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).