mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hayes Wang <hayeswang@realtek.com>
To: <netdev@vger.kernel.org>
Cc: <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>,
	<linux-usb@vger.kernel.org>, Hayes Wang <hayeswang@realtek.com>
Subject: [PATCH net-next v2 2/3] net/usb/r8152: enable tx checksum
Date: Wed, 14 Aug 2013 20:54:39 +0800	[thread overview]
Message-ID: <1376484880-741-2-git-send-email-hayeswang@realtek.com> (raw)
In-Reply-To: <1376484880-741-1-git-send-email-hayeswang@realtek.com>

Enable tx checksum.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 64 +++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 59 insertions(+), 5 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index abb0b9f..4d938a7 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -20,6 +20,8 @@
 #include <linux/if_vlan.h>
 #include <linux/uaccess.h>
 #include <linux/list.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
 
 /* Version Information */
 #define DRIVER_VERSION "v1.01.0 (2013/08/12)"
@@ -314,8 +316,13 @@ struct tx_desc {
 	u32 opts1;
 #define TX_FS			(1 << 31) /* First segment of a packet */
 #define TX_LS			(1 << 30) /* Final segment of a packet */
-#define TX_LEN_MASK		0xffff
+#define TX_LEN_MASK		0x3ffff
+
 	u32 opts2;
+#define UDP_CS			(1 << 31) /* Calculate UDP/IP checksum */
+#define TCP_CS			(1 << 30) /* Calculate TCP/IP checksum */
+#define IPV4_CS			(1 << 29) /* Calculate IPv4 checksum */
+#define IPV6_CS			(1 << 28) /* Calculate IPv6 checksum */
 };
 
 struct rx_agg {
@@ -968,6 +975,52 @@ err1:
 	return -ENOMEM;
 }
 
+static void
+r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, struct sk_buff *skb)
+{
+	memset(desc, 0, sizeof(*desc));
+
+	desc->opts1 = cpu_to_le32((skb->len & TX_LEN_MASK) | TX_FS | TX_LS);
+
+	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		__be16 protocol;
+		u8 ip_protocol;
+		u32 opts2 = 0;
+
+		if (skb->protocol == htons(ETH_P_8021Q))
+			protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
+		else
+			protocol = skb->protocol;
+
+		switch (protocol) {
+		case htons(ETH_P_IP):
+			opts2 |= IPV4_CS;
+			ip_protocol = ip_hdr(skb)->protocol;
+			break;
+
+		case htons(ETH_P_IPV6):
+			opts2 |= IPV6_CS;
+			ip_protocol = ipv6_hdr(skb)->nexthdr;
+			break;
+
+		default:
+			ip_protocol = IPPROTO_RAW;
+			break;
+		}
+
+		if (ip_protocol == IPPROTO_TCP) {
+			opts2 |= TCP_CS;
+			opts2 |= (skb_transport_offset(skb) & 0x7fff) << 17;
+		} else if (ip_protocol == IPPROTO_UDP) {
+			opts2 |= UDP_CS;
+		} else {
+			WARN_ON_ONCE(1);
+		}
+
+		desc->opts2 = cpu_to_le32(opts2);
+	}
+}
+
 static void rx_bottom(struct r8152 *tp)
 {
 	struct net_device_stats *stats;
@@ -1097,8 +1150,7 @@ next_agg:
 		tx_desc = (struct tx_desc *)tx_data;
 		tx_data += sizeof(*tx_desc);
 
-		tx_desc->opts1 = cpu_to_le32((skb->len & TX_LEN_MASK) | TX_FS |
-					     TX_LS);
+		r8152_tx_csum(tp, tx_desc, skb);
 		memcpy(tx_data, skb->data, len);
 		agg->skb_num++;
 		agg->skb_len += len;
@@ -1256,7 +1308,7 @@ static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb,
 	agg->skb_num = agg->skb_len = 0;
 
 	len = skb->len;
-	tx_desc->opts1 = cpu_to_le32((skb->len & TX_LEN_MASK) | TX_FS | TX_LS);
+	r8152_tx_csum(tp, tx_desc, skb);
 	memcpy(tx_data, skb->data, len);
 	dev_kfree_skb_any(skb);
 	agg->skb_num++;
@@ -1977,7 +2029,9 @@ static int rtl8152_probe(struct usb_interface *intf,
 	tp->netdev = netdev;
 	netdev->netdev_ops = &rtl8152_netdev_ops;
 	netdev->watchdog_timeo = RTL8152_TX_TIMEOUT;
-	netdev->features &= ~NETIF_F_IP_CSUM;
+
+	netdev->features |= NETIF_F_IP_CSUM;
+	netdev->hw_features = NETIF_F_IP_CSUM;
 	SET_ETHTOOL_OPS(netdev, &ops);
 	tp->speed = 0;
 
-- 
1.8.3.1


  reply	other threads:[~2013-08-14 12:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-13  7:28 [PATCH net-next 1/3] net/usb/r8152: support aggregation Hayes Wang
2013-08-13  7:28 ` [PATCH net-next 2/3] net/usb/r8152: enable tx checksum Hayes Wang
2013-08-13 14:39   ` Sergei Shtylyov
2013-08-13  7:28 ` [PATCH net-next 3/3] net/usb/r8152: enable interrupt transfer Hayes Wang
2013-08-13  8:49 ` [PATCH net-next 1/3] net/usb/r8152: support aggregation Oliver Neukum
2013-08-13 12:32   ` hayeswang
2013-08-13 15:17     ` Oliver Neukum
2013-08-13 23:41       ` David Miller
2013-08-14  3:02         ` hayeswang
2013-08-14 12:54 ` [PATCH net-next v2 " Hayes Wang
2013-08-14 12:54   ` Hayes Wang [this message]
2013-08-15  8:34     ` [PATCH net-next v2 2/3] net/usb/r8152: enable tx checksum David Miller
2013-08-14 12:54   ` [PATCH net-next v2 3/3] net/usb/r8152: enable interrupt transfer Hayes Wang
2013-08-15  8:35     ` David Miller
2013-08-15  8:34   ` [PATCH net-next v2 1/3] net/usb/r8152: support aggregation David Miller
2013-08-15 12:26   ` Francois Romieu
2013-08-16  3:44     ` hayeswang
2013-08-16  5:54       ` Francois Romieu

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=1376484880-741-2-git-send-email-hayeswang@realtek.com \
    --to=hayeswang@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.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

Powered by JetHome