netdev.vger.kernel.org archive mirror
 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 08/12] r8152: support TSO
Date: Tue, 4 Mar 2014 20:01:00 +0800	[thread overview]
Message-ID: <1393934464-23675-9-git-send-email-hayeswang@realtek.com> (raw)
In-Reply-To: <1393934464-23675-1-git-send-email-hayeswang@realtek.com>

Support scatter gather and TSO.

Adjust the tx checksum function and set the max gso size to fix the
size of the tx aggregation buffer.

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

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 5fdf0af..774a19a 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -23,7 +23,7 @@
 #include <linux/ipv6.h>
 
 /* Version Information */
-#define DRIVER_VERSION "v1.05.0 (2014/02/18)"
+#define DRIVER_VERSION "v1.06.0 (2014/03/03)"
 #define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>"
 #define DRIVER_DESC "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
 #define MODULENAME "r8152"
@@ -490,13 +490,18 @@ struct tx_desc {
 	__le32 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		0x3ffff
+#define GTSENDV4		(1 << 28)
+#define GTTCPHO_SHIFT		18
+#define TX_LEN_MAX		0x3ffffU
 
 	__le32 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 */
+#define MSS_SHIFT		17
+#define MSS_MAX			0x7ffU
+#define TCPHO_SHIFT		17
 };
 
 struct r8152;
@@ -563,12 +568,21 @@ enum rtl_version {
 	RTL_VER_MAX
 };
 
+enum tx_csum_stat {
+	TX_CSUM_SUCCESS = 0,
+	TX_CSUM_TSO,
+	TX_CSUM_NONE
+};
+
 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
  * The RTL chips use a 64 element hash table based on the Ethernet CRC.
  */
 static const int multicast_filter_limit = 32;
 static unsigned int rx_buf_sz = 16384;
 
+#define RTL_LIMITED_TSO_SIZE	(rx_buf_sz - sizeof(struct tx_desc) - \
+				 VLAN_ETH_HLEN - VLAN_HLEN)
+
 static
 int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
 {
@@ -1295,24 +1309,46 @@ static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp)
 	return agg;
 }
 
-static void
-r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, struct sk_buff *skb)
+static inline __be16 get_protocol(struct sk_buff *skb)
 {
-	memset(desc, 0, sizeof(*desc));
+	__be16 protocol;
 
-	desc->opts1 = cpu_to_le32((skb->len & TX_LEN_MASK) | TX_FS | TX_LS);
+	if (skb->protocol == htons(ETH_P_8021Q))
+		protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
+	else
+		protocol = skb->protocol;
 
-	if (skb->ip_summed == CHECKSUM_PARTIAL) {
-		__be16 protocol;
-		u8 ip_protocol;
-		u32 opts2 = 0;
+	return protocol;
+}
 
-		if (skb->protocol == htons(ETH_P_8021Q))
-			protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto;
-		else
-			protocol = skb->protocol;
+static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc,
+			 struct sk_buff *skb, u32 len, u32 transport_offset)
+{
+	u32 mss = skb_shinfo(skb)->gso_size;
+	u32 opts1, opts2 = 0;
+	int ret = TX_CSUM_SUCCESS;
+
+	WARN_ON_ONCE(len > TX_LEN_MAX);
+
+	opts1 = len | TX_FS | TX_LS;
+
+	if (mss) {
+		switch (get_protocol(skb)) {
+		case htons(ETH_P_IP):
+			opts1 |= GTSENDV4;
+			break;
 
-		switch (protocol) {
+		default:
+			WARN_ON_ONCE(1);
+			break;
+		}
+
+		opts1 |= transport_offset << GTTCPHO_SHIFT;
+		opts2 |= min(mss, MSS_MAX) << MSS_SHIFT;
+	} else if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		u8 ip_protocol;
+
+		switch (get_protocol(skb)) {
 		case htons(ETH_P_IP):
 			opts2 |= IPV4_CS;
 			ip_protocol = ip_hdr(skb)->protocol;
@@ -1328,17 +1364,44 @@ r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc, struct sk_buff *skb)
 			break;
 		}
 
-		if (ip_protocol == IPPROTO_TCP) {
+		if (ip_protocol == IPPROTO_TCP)
 			opts2 |= TCP_CS;
-			opts2 |= (skb_transport_offset(skb) & 0x7fff) << 17;
-		} else if (ip_protocol == IPPROTO_UDP) {
+		else if (ip_protocol == IPPROTO_UDP)
 			opts2 |= UDP_CS;
-		} else {
+		else
 			WARN_ON_ONCE(1);
-		}
 
-		desc->opts2 = cpu_to_le32(opts2);
+		opts2 |= transport_offset << TCPHO_SHIFT;
+	}
+
+	desc->opts2 = cpu_to_le32(opts2);
+	desc->opts1 = cpu_to_le32(opts1);
+
+	return ret;
+}
+
+static u32 r8152_xmit_frags(struct r8152 *tp, struct sk_buff *skb, u8 *data)
+{
+	struct skb_shared_info *info = skb_shinfo(skb);
+	unsigned int cur_frag;
+	u32 total = skb_headlen(skb);
+
+	memcpy(data, skb->data, total);
+	data += total;
+
+	for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) {
+		const skb_frag_t *frag = info->frags + cur_frag;
+		void *addr;
+		u32 len;
+
+		len = skb_frag_size(frag);
+		addr = skb_frag_address(frag);
+		memcpy(data, addr, len);
+		data += len;
+		total += len;
 	}
+
+	return total;
 }
 
 static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
@@ -1360,29 +1423,36 @@ static int r8152_tx_agg_fill(struct r8152 *tp, struct tx_agg *agg)
 		struct tx_desc *tx_desc;
 		struct sk_buff *skb;
 		unsigned int len;
+		u32 offset;
 
 		skb = __skb_dequeue(&skb_head);
 		if (!skb)
 			break;
 
-		remain -= sizeof(*tx_desc);
-		len = skb->len;
-		if (remain < len) {
+		len = skb->len + sizeof(*tx_desc);
+
+		if (len > remain) {
 			__skb_queue_head(&skb_head, skb);
 			break;
 		}
 
 		tx_data = tx_agg_align(tx_data);
 		tx_desc = (struct tx_desc *)tx_data;
+
+		offset = (u32)skb_transport_offset(skb);
+
+		r8152_tx_csum(tp, tx_desc, skb, skb->len, offset);
+
 		tx_data += sizeof(*tx_desc);
 
-		r8152_tx_csum(tp, tx_desc, skb);
-		memcpy(tx_data, skb->data, len);
-		agg->skb_num++;
+		len = r8152_xmit_frags(tp, skb, tx_data);
+
+		tx_data += len;
 		agg->skb_len += len;
+		agg->skb_num++;
+
 		dev_kfree_skb_any(skb);
 
-		tx_data += len;
 		remain = rx_buf_sz - (int)(tx_agg_align(tx_data) - agg->head);
 	}
 
@@ -3149,10 +3219,13 @@ static int rtl8152_probe(struct usb_interface *intf,
 	netdev->netdev_ops = &rtl8152_netdev_ops;
 	netdev->watchdog_timeo = RTL8152_TX_TIMEOUT;
 
-	netdev->features |= NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
-	netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
+	netdev->features |= NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG |
+			    NETIF_F_TSO;
+	netdev->hw_features = NETIF_F_RXCSUM | NETIF_F_IP_CSUM | NETIF_F_SG |
+			      NETIF_F_TSO;
 
 	SET_ETHTOOL_OPS(netdev, &ops);
+	netif_set_gso_max_size(netdev, RTL_LIMITED_TSO_SIZE);
 
 	tp->mii.dev = netdev;
 	tp->mii.mdio_read = read_mii_word;
-- 
1.8.4.2

  parent reply	other threads:[~2014-03-04 12:01 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-04 12:00 [PATCH net-next 00/12] r8152: new features Hayes Wang
2014-03-04 12:00 ` [PATCH net-next 01/12] r8152: deal with the empty line and space Hayes Wang
2014-03-04 12:00 ` [PATCH net-next 02/12] r8152: replace tp->netdev with netdev Hayes Wang
2014-03-04 12:00 ` [PATCH net-next 03/12] r8152: remove rtl8152_get_stats Hayes Wang
2014-03-04 12:00 ` [PATCH net-next 04/12] r8152: replace spin_lock_irqsave and spin_unlock_irqrestore Hayes Wang
2014-03-04 12:00 ` [PATCH net-next 05/12] r8152: check tx agg list before spin lock Hayes Wang
2014-03-04 12:00 ` [PATCH net-next 06/12] r8152: up the priority of the transmission Hayes Wang
2014-03-04 12:00 ` [PATCH net-next 07/12] r8152: support rx checksum Hayes Wang
2014-03-04 21:32   ` David Miller
2014-03-04 12:01 ` Hayes Wang [this message]
2014-03-04 12:11   ` [PATCH net-next 08/12] r8152: support TSO David Laight
2014-03-04 13:11     ` hayeswang
     [not found]       ` <CF9EF717568D49DB858D5363B1099FC0-Rasf1IRRPZGoECsaD+WFmw@public.gmane.org>
2014-03-04 14:35         ` David Laight
2014-03-04 15:02           ` Eric Dumazet
2014-03-04 15:14             ` David Laight
2014-03-04 16:11   ` Eric Dumazet
2014-03-04 16:52   ` Eric Dumazet
2014-03-04 12:01 ` [PATCH net-next 09/12] r8152: support IPv6 Hayes Wang
2014-03-04 16:58   ` Eric Dumazet
2014-03-04 12:01 ` [PATCH net-next 10/12] r8152: reduce the numbers of the bulks Hayes Wang
2014-03-04 12:01 ` [PATCH net-next 11/12] r8152: add additional parameter for non x86 platform Hayes Wang
2014-03-04 12:01 ` [PATCH net-next 12/12] r8152: modify the tx timeout funcfion Hayes Wang
     [not found]   ` <1393934464-23675-13-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2014-03-25 20:12     ` Grant Grundler
2014-03-26  9:54       ` hayeswang
2014-03-05  6:49 ` [PATCH net-next v2 00/13] r8152: new features Hayes Wang
     [not found]   ` <1394002168-3193-1-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2014-03-05  6:49     ` [PATCH net-next v2 01/13] r8152: deal with the empty line and space Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 02/13] r8152: replace tp->netdev with netdev Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 03/13] r8152: remove rtl8152_get_stats Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 04/13] r8152: replace spin_lock_irqsave and spin_unlock_irqrestore Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 05/13] r8152: check tx agg list before spin lock Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 06/13] r8152: up the priority of the transmission Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 07/13] r8152: calculate the dropped packets for rx Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 08/13] r8152: support rx checksum Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 09/13] r8152: support TSO Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 10/13] r8152: support IPv6 Hayes Wang
     [not found]     ` <1394002168-3193-11-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2014-03-09 19:47       ` Ben Hutchings
     [not found]         ` <1394394475.15968.25.camel-nDn/Rdv9kqW9Jme8/bJn5UCKIB8iOfG2tUK59QYPAWc@public.gmane.org>
2014-03-09 22:56           ` David Miller
2014-03-05  6:49   ` [PATCH net-next v2 11/13] r8152: reduce the numbers of the bulks Hayes Wang
2014-03-05  6:49   ` [PATCH net-next v2 12/13] r8152: add additional parameter for non x86 platform Hayes Wang
2014-03-06  5:05     ` David Miller
2014-03-05  6:49   ` [PATCH net-next v2 13/13] r8152: modify the tx timeout funcfion Hayes Wang
2014-03-07  3:04 ` [PATCH net-next 0/7] r8152: tx/rx improvement Hayes Wang
2014-03-07  3:04   ` [PATCH net-next 1/7] r8152: replace spin_lock_irqsave and spin_unlock_irqrestore Hayes Wang
     [not found]   ` <1394161480-2918-1-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2014-03-07  3:04     ` [PATCH net-next 2/7] r8152: check tx agg list before spin lock Hayes Wang
2014-03-07  3:04   ` [PATCH net-next 3/7] r8152: up the priority of the transmission Hayes Wang
2014-03-07  3:04   ` [PATCH net-next 4/7] r8152: calculate the dropped packets for rx Hayes Wang
2014-03-07  3:04   ` [PATCH net-next 5/7] r8152: support rx checksum Hayes Wang
2014-03-07  3:04   ` [PATCH net-next 6/7] r8152: support TSO Hayes Wang
2014-03-07  3:04   ` [PATCH net-next 7/7] r8152: support IPv6 Hayes Wang
2014-03-07 21:27   ` [PATCH net-next 0/7] r8152: tx/rx improvement David Miller
2014-03-10  3:45     ` hayeswang
     [not found] ` <1393934464-23675-1-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2014-03-06  7:07   ` [PATCH net-next 0/3] r8152: cleanups Hayes Wang
2014-03-06  7:07     ` [PATCH net-next 1/3] r8152: deal with the empty line and space Hayes Wang
2014-03-06  7:07     ` [PATCH net-next 2/3] r8152: replace tp->netdev with netdev Hayes Wang
2014-03-06  7:07     ` [PATCH net-next 3/3] r8152: remove rtl8152_get_stats Hayes Wang
2014-03-06 18:17     ` [PATCH net-next 0/3] r8152: cleanups David Miller
2014-03-10  6:22   ` [PATCH net-next] r8152: add skb_cow_head Hayes Wang
2014-03-10 20:31     ` David Miller
2014-03-11  2:20   ` [PATCH net-next v2] " Hayes Wang
2014-03-11  2:25     ` David Miller
2014-03-12 12:39 ` [PATCH net-next 0/2] parameter modification Hayes Wang
2014-03-12 12:39   ` [PATCH net-next 1/2] r8152: add CONFIG_RTL8152_EARLY_AGG_SUPER Hayes Wang
2014-03-12 13:40     ` Bjørn Mork
2014-03-12 12:39   ` [PATCH net-next 2/2] r8152: reduce the numbers of the bulks Hayes Wang
2014-03-13  3:34 ` [PATCH net-next v2 0/2] parameter modification Hayes Wang
2014-03-13  3:34   ` [PATCH net-next v2 1/2] r8152: add RTL8152_EARLY_AGG_TIMEOUT_SUPER Hayes Wang
2014-03-13  9:28     ` David Laight
2014-03-13  3:34   ` [PATCH net-next v2 2/2] r8152: reduce the numbers of the bulks Hayes Wang
2014-03-13 12:05 ` [PATCH net-next v3 0/2] parameter modification Hayes Wang
2014-03-13 12:05   ` [PATCH net-next v3 1/2] r8152: add RTL8152_EARLY_AGG_TIMEOUT_SUPER Hayes Wang
2014-03-13 13:12     ` David Laight
2014-03-13 17:22       ` David Miller
2014-03-14  2:37         ` [PATCH net-next v3 1/2] r8152: addRTL8152_EARLY_AGG_TIMEOUT_SUPER hayeswang
2014-03-14  4:07           ` David Miller
     [not found]             ` <20140314.000741.1829674011496195593.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2014-03-14  7:24               ` [PATCH net-next v3 1/2] r8152:addRTL8152_EARLY_AGG_TIMEOUT_SUPER hayeswang
2014-03-14 18:43                 ` David Miller
2014-03-17  6:01                   ` [PATCH net-next v3 1/2]r8152:addRTL8152_EARLY_AGG_TIMEOUT_SUPER hayeswang
2014-03-14 23:42                 ` [PATCH net-next v3 1/2] r8152:addRTL8152_EARLY_AGG_TIMEOUT_SUPER Francois Romieu
2014-03-17  6:03                   ` hayeswang
2014-03-13 12:05   ` [PATCH net-next v3 2/2] r8152: reduce the numbers of the bulks Hayes Wang

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=1393934464-23675-9-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;
as well as URLs for NNTP newsgroup(s).