From: David Woodhouse <dwmw2@infradead.org>
To: Francois Romieu <romieu@fr.zoreil.com>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH 4/7] 8139cp: Fix TSO/scatter-gather descriptor setup
Date: Mon, 21 Sep 2015 22:47:47 +0100 [thread overview]
Message-ID: <1442872067.7367.86.camel@infradead.org> (raw)
In-Reply-To: <20150921210139.GB4559@electric-eye.fr.zoreil.com>
[-- Attachment #1: Type: text/plain, Size: 4443 bytes --]
On Mon, 2015-09-21 at 23:01 +0200, Francois Romieu wrote:
>
> Can you pile a patch to replace BUG with WARN_ON_ONCE(1) ?
Let's avoid having three copies of the same damn code, while we're at
it... http://git.infradead.org/users/dwmw2/linux-8139cp.git has this
and the appropriate minor fixes to subsequent patches in the series.
What do you think of finally enabling hw csum and TSO by default, btw?
Subject: [PATCH 4½/7] 8139cp: Reduce duplicate csum/tso code in cp_start_xmit()
We calculate the value of the opts1 descriptor field in three different
places. With two different behaviours when given an invalid packet to
be checksummed — none of them correct. Sort that out.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
---
drivers/net/ethernet/realtek/8139cp.c | 61 ++++++++++++-----------------------
1 file changed, 20 insertions(+), 41 deletions(-)
diff --git a/drivers/net/ethernet/realtek/8139cp.c b/drivers/net/ethernet/realtek/8139cp.c
index 3b219aa..a2c471d 100644
--- a/drivers/net/ethernet/realtek/8139cp.c
+++ b/drivers/net/ethernet/realtek/8139cp.c
@@ -740,7 +740,7 @@ static netdev_tx_t cp_start_xmit (struct sk_buff *skb,
{
struct cp_private *cp = netdev_priv(dev);
unsigned entry;
- u32 eor, flags;
+ u32 eor, opts1;
unsigned long intr_flags;
__le32 opts2;
int mss = 0;
@@ -760,6 +760,21 @@ static netdev_tx_t cp_start_xmit (struct sk_buff *skb,
mss = skb_shinfo(skb)->gso_size;
opts2 = cpu_to_le32(cp_tx_vlan_tag(skb));
+ opts1 = DescOwn;
+ if (mss)
+ opts1 |= LargeSend | ((mss & MSSMask) << MSSShift);
+ else if (skb->ip_summed == CHECKSUM_PARTIAL) {
+ const struct iphdr *ip = ip_hdr(skb);
+ if (ip->protocol == IPPROTO_TCP)
+ opts1 |= IPCS | TCPCS;
+ else if (ip->protocol == IPPROTO_UDP)
+ opts1 |= IPCS | UDPCS;
+ else {
+ WARN_ONCE(1,
+ "Net bug: asked to checksum invalid Legacy IP packet\n");
+ goto out_dma_error;
+ }
+ }
if (skb_shinfo(skb)->nr_frags == 0) {
struct cp_desc *txd = &cp->tx_ring[entry];
@@ -775,21 +790,9 @@ static netdev_tx_t cp_start_xmit (struct sk_buff *skb,
txd->addr = cpu_to_le64(mapping);
wmb();
- flags = eor | len | DescOwn | FirstFrag | LastFrag;
-
- if (mss)
- flags |= LargeSend | ((mss & MSSMask) << MSSShift);
- else if (skb->ip_summed == CHECKSUM_PARTIAL) {
- const struct iphdr *ip = ip_hdr(skb);
- if (ip->protocol == IPPROTO_TCP)
- flags |= IPCS | TCPCS;
- else if (ip->protocol == IPPROTO_UDP)
- flags |= IPCS | UDPCS;
- else
- WARN_ON(1); /* we need a WARN() */
- }
+ opts1 |= eor | len | FirstFrag | LastFrag;
- txd->opts1 = cpu_to_le32(flags);
+ txd->opts1 = cpu_to_le32(opts1);
wmb();
cp->tx_skb[entry] = skb;
@@ -800,7 +803,6 @@ static netdev_tx_t cp_start_xmit (struct sk_buff *skb,
u32 first_len, first_eor, ctrl;
dma_addr_t first_mapping;
int frag, first_entry = entry;
- const struct iphdr *ip = ip_hdr(skb);
/* We must give this initial chunk to the device last.
* Otherwise we could race with the device.
@@ -832,19 +834,7 @@ static netdev_tx_t cp_start_xmit (struct sk_buff *skb,
eor = (entry == (CP_TX_RING_SIZE - 1)) ? RingEnd : 0;
- ctrl = eor | len | DescOwn;
-
- if (mss)
- ctrl |= LargeSend |
- ((mss & MSSMask) << MSSShift);
- else if (skb->ip_summed == CHECKSUM_PARTIAL) {
- if (ip->protocol == IPPROTO_TCP)
- ctrl |= IPCS | TCPCS;
- else if (ip->protocol == IPPROTO_UDP)
- ctrl |= IPCS | UDPCS;
- else
- BUG();
- }
+ ctrl = opts1 | eor | len;
if (frag == skb_shinfo(skb)->nr_frags - 1)
ctrl |= LastFrag;
@@ -864,18 +854,7 @@ static netdev_tx_t cp_start_xmit (struct sk_buff *skb,
txd->addr = cpu_to_le64(first_mapping);
wmb();
- ctrl = first_eor | first_len | FirstFrag | DescOwn;
- if (mss)
- ctrl |= LargeSend | (mss & MSSMask) << MSSShift);
- else if (skb->ip_summed == CHECKSUM_PARTIAL) {
- if (ip->protocol == IPPROTO_TCP)
- ctrl |= IPCS | TCPCS;
- else if (ip->protocol == IPPROTO_UDP)
- ctrl |= IPCS | UDPCS;
- else
- BUG();
- }
-
+ ctrl = opts1 | first_eor | first_len | FirstFrag;
txd->opts1 = cpu_to_le32(ctrl);
wmb();
--
2.4.3
--
David Woodhouse Open Source Technology Centre
David.Woodhouse@intel.com Intel Corporation
[-- Attachment #2: smime.p7s --]
[-- Type: application/x-pkcs7-signature, Size: 5691 bytes --]
next prev parent reply other threads:[~2015-09-21 21:47 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-17 23:19 [PATCH 1/2] 8139cp: Use dev_kfree_skb_any() instead of dev_kfree_skb() in cp_clean_rings() David Woodhouse
2015-09-17 23:21 ` [PATCH 2/2] 8139cp: Call __cp_set_rx_mode() from cp_tx_timeout() David Woodhouse
2015-09-18 11:37 ` [PATCH 3/2] 8139cp: Improve accuracy of cp_interrupt() return, to survive IRQ storms David Woodhouse
2015-09-18 12:17 ` [PATCH 4/2] 8139cp: Do not re-enable RX interrupts in cp_tx_timeout() David Woodhouse
2015-09-21 5:24 ` [PATCH 2/2] 8139cp: Call __cp_set_rx_mode() from cp_tx_timeout() David Miller
2015-09-21 13:59 ` David Woodhouse
2015-09-21 14:01 ` [PATCH 1/7] 8139cp: Improve accuracy of cp_interrupt() return, to survive IRQ storms David Woodhouse
2015-09-21 20:25 ` Francois Romieu
2015-09-21 20:52 ` David Woodhouse
2015-09-22 23:45 ` David Miller
2015-09-23 8:14 ` David Woodhouse
2015-09-23 8:43 ` [PATCH 1/7] 8139cp: Do not re-enable RX interrupts in cp_tx_timeout() David Woodhouse
2015-09-23 8:44 ` [PATCH 2/7] 8139cp: Fix tx_queued debug message to print correct slot numbers David Woodhouse
2015-09-23 8:44 ` [PATCH 3/7] 8139cp: Fix TSO/scatter-gather descriptor setup David Woodhouse
2015-09-23 8:44 ` [PATCH 4/7] 8139cp: Reduce duplicate csum/tso code in cp_start_xmit() David Woodhouse
2015-09-23 8:45 ` [PATCH 5/7] 8139cp: Fix DMA unmapping of transmitted buffers David Woodhouse
2015-09-23 8:45 ` [PATCH 6/7] 8139cp: Dump contents of descriptor ring on TX timeout David Woodhouse
2015-09-23 8:46 ` [PATCH 7/7] 8139cp: Enable offload features by default David Woodhouse
2015-09-23 17:58 ` [PATCH 1/7] 8139cp: Improve accuracy of cp_interrupt() return, to survive IRQ storms David Miller
2015-09-23 19:45 ` David Woodhouse
2015-09-23 21:48 ` David Miller
2015-09-23 22:00 ` David Woodhouse
2015-09-23 23:29 ` Francois Romieu
2015-09-24 8:58 ` [PATCH WTF] 8139cp: Fix GSO MSS handling David Woodhouse
2015-09-24 10:38 ` [PATCH v2 RFC] " David Woodhouse
2015-09-24 12:05 ` Eric Dumazet
2015-09-24 12:31 ` David Woodhouse
2015-09-28 5:37 ` Tom Herbert
2015-09-28 7:21 ` David Woodhouse
2015-09-27 5:38 ` David Miller
2015-09-23 22:02 ` [PATCH] 8139cp: Set GSO max size and enforce it David Woodhouse
2015-09-23 22:44 ` [PATCH 1/7] 8139cp: Improve accuracy of cp_interrupt() return, to survive IRQ storms Francois Romieu
2015-09-23 23:09 ` David Woodhouse
2015-10-28 8:47 ` David Woodhouse
2015-09-23 22:44 ` Francois Romieu
2015-09-23 23:18 ` David Woodhouse
2015-09-21 14:02 ` [PATCH 2/7] 8139cp: Do not re-enable RX interrupts in cp_tx_timeout() David Woodhouse
2015-09-22 23:46 ` David Miller
2015-09-21 14:02 ` [PATCH 3/7] 8139cp: Fix tx_queued debug message to print correct slot numbers David Woodhouse
2015-09-21 14:02 ` [PATCH 4/7] 8139cp: Fix TSO/scatter-gather descriptor setup David Woodhouse
2015-09-21 21:01 ` Francois Romieu
2015-09-21 21:06 ` David Woodhouse
2015-09-21 21:47 ` David Woodhouse [this message]
2015-09-22 21:59 ` Francois Romieu
2015-09-21 14:03 ` [PATCH 5/7] 8139cp: Fix DMA unmapping of transmitted buffers David Woodhouse
2015-09-21 14:03 ` [PATCH 6/7] 8139cp: Dump contents of descriptor ring on TX timeout David Woodhouse
2015-09-21 14:05 ` [PATCH 7/7] 8139cp: Avoid gratuitous writes to TxPoll register when already running David Woodhouse
2015-09-21 20:54 ` Francois Romieu
2015-09-21 21:10 ` David Woodhouse
2015-09-21 14:11 ` [PATCH 2/2] 8139cp: Call __cp_set_rx_mode() from cp_tx_timeout() David Woodhouse
2015-09-21 5:24 ` [PATCH 1/2] 8139cp: Use dev_kfree_skb_any() instead of dev_kfree_skb() in cp_clean_rings() David Miller
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=1442872067.7367.86.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=netdev@vger.kernel.org \
--cc=romieu@fr.zoreil.com \
/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).