[ofa-general] [PATCH 11 of 17] ipoib: add LSO support

Eli Cohen eli at mellanox.co.il
Tue Sep 11 08:54:47 PDT 2007


Index: ofa_1_3_dev_kernel/drivers/infiniband/ulp/ipoib/ipoib.h
===================================================================
--- ofa_1_3_dev_kernel.orig/drivers/infiniband/ulp/ipoib/ipoib.h	2007-09-11 21:15:26.000000000 +0300
+++ ofa_1_3_dev_kernel/drivers/infiniband/ulp/ipoib/ipoib.h	2007-09-11 21:15:28.000000000 +0300
@@ -133,28 +133,38 @@ static inline int ipoib_dma_map_tx(struc
 {
 	struct sk_buff *skb = tx_req->skb;
 	u64 *mapping = tx_req->mapping;
-	int i, frags;
+	int i, frags, off;
 
-	mapping[0] = ib_dma_map_single(ca, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
-	if (unlikely(ib_dma_mapping_error(ca, mapping[0])))
-		return -EIO;
+	if (!skb_is_gso(skb)) {
+		mapping[0] = ib_dma_map_single(ca, skb->data, skb_headlen(skb), DMA_TO_DEVICE);
+		if (unlikely(ib_dma_mapping_error(ca, mapping[0])))
+			return -EIO;
+		off = 1;
+	}
+	else
+		off = 0;
 
 	frags = skb_shinfo(skb)->nr_frags;
 	for (i = 0; i < frags; ++i) {
 		skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
-		mapping[i + 1] = ib_dma_map_page(ca, frag->page, frag->page_offset,
-						 frag->size, DMA_TO_DEVICE);
-		if (unlikely(ib_dma_mapping_error(ca, mapping[i + 1])))
+		mapping[i + off] = ib_dma_map_page(ca, frag->page, frag->page_offset,
+						   frag->size, DMA_TO_DEVICE);
+		if (unlikely(ib_dma_mapping_error(ca, mapping[i + off])))
 			goto partial_error;
 	}
 	return 0;
 
 partial_error:
-	ib_dma_unmap_single(ca, mapping[0], skb_headlen(skb), DMA_TO_DEVICE);
+	if (!skb_is_gso(skb)) {
+		ib_dma_unmap_single(ca, mapping[0], skb_headlen(skb), DMA_TO_DEVICE);
+		off = 0;
+	}
+	else
+		off = 1;
 
 	for (; i > 0; --i) {
 		skb_frag_t *frag = &skb_shinfo(skb)->frags[i - 1];
-		ib_dma_unmap_page(ca, mapping[i], frag->size, DMA_TO_DEVICE);
+		ib_dma_unmap_page(ca, mapping[i - off], frag->size, DMA_TO_DEVICE);
 	}
 	return -EIO;
 }
@@ -163,14 +173,19 @@ static inline void ipoib_dma_unmap_tx(st
 {
 	struct sk_buff *skb = tx_req->skb;
 	u64 *mapping = tx_req->mapping;
-	int i, frags;
+	int i, frags, off;
 
-	ib_dma_unmap_single(ca, mapping[0], skb_headlen(skb), DMA_TO_DEVICE);
+	if (!skb_is_gso(skb)) {
+		ib_dma_unmap_single(ca, mapping[0], skb_headlen(skb), DMA_TO_DEVICE);
+		off = 1;
+	}
+	else
+		off = 0;
 
 	frags = skb_shinfo(skb)->nr_frags;
 	for (i = 0; i < frags; ++i) {
 		skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
-		ib_dma_unmap_page(ca, mapping[i + 1], frag->size, DMA_TO_DEVICE);
+		ib_dma_unmap_page(ca, mapping[i + off], frag->size, DMA_TO_DEVICE);
 	}
 }
 
Index: ofa_1_3_dev_kernel/drivers/infiniband/ulp/ipoib/ipoib_ib.c
===================================================================
--- ofa_1_3_dev_kernel.orig/drivers/infiniband/ulp/ipoib/ipoib_ib.c	2007-09-11 21:15:26.000000000 +0300
+++ ofa_1_3_dev_kernel/drivers/infiniband/ulp/ipoib/ipoib_ib.c	2007-09-11 21:15:28.000000000 +0300
@@ -38,6 +38,7 @@
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/ip.h>
+#include <linux/tcp.h>
 
 #include <rdma/ib_cache.h>
 
@@ -354,22 +355,36 @@ static inline int post_send(struct ipoib
 			    struct ib_ah *address, u32 qpn,
 			    u64 *mapping, int headlen,
 			    skb_frag_t *frags,
-			    int nr_frags)
+			    int nr_frags, void *lso_header)
 {
 	struct ib_send_wr *bad_wr;
-	int i;
+	int i, off;
+
+	if (!lso_header) {
+		priv->tx_sge[0].addr         = mapping[0];
+		priv->tx_sge[0].length       = headlen;
+		off = 1;
+	}
+	else
+		off = 0;
 
-	priv->tx_sge[0].addr         = mapping[0];
-	priv->tx_sge[0].length       = headlen;
 	for (i = 0; i < nr_frags; ++i) {
-		priv->tx_sge[i + 1].addr = mapping[i + 1];
-		priv->tx_sge[i + 1].length = frags[i].size;
+		priv->tx_sge[i + off].addr = mapping[i + off];
+		priv->tx_sge[i + off].length = frags[i].size;
 	}
-	priv->tx_wr.num_sge          = nr_frags + 1;
+	priv->tx_wr.num_sge          = nr_frags + off;
 	priv->tx_wr.wr_id 	     = wr_id;
 	priv->tx_wr.wr.ud.remote_qpn = qpn;
 	priv->tx_wr.wr.ud.ah 	     = address;
 
+	if (lso_header) {
+		priv->tx_wr.wr.ud.mss = priv->dev->mtu;
+		priv->tx_wr.wr.ud.header = lso_header;
+		priv->tx_wr.wr.ud.hlen = headlen;
+		priv->tx_wr.opcode      = IB_WR_LSO;
+	} else
+		priv->tx_wr.opcode      = IB_WR_SEND;
+
 	return ib_post_send(priv->qp, &priv->tx_wr, &bad_wr);
 }
 
@@ -379,13 +394,26 @@ void ipoib_send(struct net_device *dev, 
 	struct ipoib_dev_priv *priv = netdev_priv(dev);
 	struct ipoib_tx_buf *tx_req;
 
-	if (unlikely(skb->len > priv->mcast_mtu + IPOIB_ENCAP_LEN)) {
-		ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
-			   skb->len, priv->mcast_mtu + IPOIB_ENCAP_LEN);
-		++priv->stats.tx_dropped;
-		++priv->stats.tx_errors;
-		ipoib_cm_skb_too_long(dev, skb, priv->mcast_mtu);
-		return;
+	if (!skb_is_gso(skb)) {
+		if (unlikely(skb->len > priv->mcast_mtu + IPOIB_ENCAP_LEN)) {
+			ipoib_warn(priv, "packet len %d (> %d) too long to send, dropping\n",
+				   skb->len, priv->mcast_mtu + IPOIB_ENCAP_LEN);
+			++priv->stats.tx_dropped;
+			++priv->stats.tx_errors;
+			ipoib_cm_skb_too_long(dev, skb, priv->mcast_mtu);
+			return;
+		}
+	} else {
+		if (unlikely((skb_headlen(skb) - IPOIB_ENCAP_LEN) !=
+			     ((ip_hdr(skb)->ihl + tcp_hdr(skb)->doff) << 2))) {
+			ipoib_warn(priv, "headlen (%d) does not match ip (%d)and "
+				   "tcp headers(%d), dropping skb\n",
+				   skb_headlen(skb) - IPOIB_ENCAP_LEN,
+				   ip_hdr(skb)->ihl << 2, tcp_hdr(skb)->doff << 2);
+			++priv->stats.tx_errors;
+			dev_kfree_skb_any(skb);
+			return;
+		}
 	}
 
 	ipoib_dbg_data(priv, "sending packet, length=%d address=%p qpn=0x%06x\n",
@@ -419,7 +447,9 @@ void ipoib_send(struct net_device *dev, 
 	if (unlikely(post_send(priv, priv->tx_head & (ipoib_sendq_size - 1),
 			       address->ah, qpn,
 			       tx_req->mapping, skb_headlen(skb),
-			       skb_shinfo(skb)->frags, skb_shinfo(skb)->nr_frags))) {
+			       skb_shinfo(skb)->frags,
+			       skb_shinfo(skb)->nr_frags,
+			       skb_is_gso(skb) ? skb->data : NULL))) {
 		ipoib_warn(priv, "post_send failed\n");
 		++priv->stats.tx_errors;
 		ipoib_dma_unmap_tx(priv->ca, tx_req);
Index: ofa_1_3_dev_kernel/drivers/infiniband/ulp/ipoib/ipoib_main.c
===================================================================
--- ofa_1_3_dev_kernel.orig/drivers/infiniband/ulp/ipoib/ipoib_main.c	2007-09-11 21:15:26.000000000 +0300
+++ ofa_1_3_dev_kernel/drivers/infiniband/ulp/ipoib/ipoib_main.c	2007-09-11 21:15:28.000000000 +0300
@@ -733,7 +733,9 @@ static int ipoib_start_xmit(struct sk_bu
 				goto out;
 			}
 
-			ipoib_send(dev, skb, neigh->ah, IPOIB_QPN(skb->dst->neighbour->ha));
+			ipoib_send(dev, skb, neigh->ah,
+				   IPOIB_QPN(skb->dst->neighbour->ha));
+
 			goto out;
 		}
 
@@ -1203,6 +1205,11 @@ static struct net_device *ipoib_add_port
 	set_tx_csum(priv->dev);
 	set_rx_csum(priv->dev);
 
+	if (!ipoib_hw_csum && priv->dev->features & NETIF_F_SG &&
+	    priv->ca->flags & IB_DEVICE_TCP_GSO)
+		priv->dev->features |= NETIF_F_TSO;
+
+
 	result = register_netdev(priv->dev);
 	if (result) {
 		printk(KERN_WARNING "%s: couldn't register ipoib port %d; error %d\n",
Index: ofa_1_3_dev_kernel/drivers/infiniband/ulp/ipoib/ipoib_cm.c
===================================================================
--- ofa_1_3_dev_kernel.orig/drivers/infiniband/ulp/ipoib/ipoib_cm.c	2007-09-11 21:15:26.000000000 +0300
+++ ofa_1_3_dev_kernel/drivers/infiniband/ulp/ipoib/ipoib_cm.c	2007-09-11 21:15:28.000000000 +0300
@@ -1264,7 +1264,7 @@ static ssize_t set_mode(struct device *d
 			   "will cause multicast packet drops\n");
 
 		/* clear ipv6 flag too */
-		dev->features &= ~NETIF_F_IP_CSUM;
+		dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_TSO);
 
 		priv->tx_wr.send_flags &=
 			~(IB_SEND_UDP_TCP_CSUM | IB_SEND_IP_CSUM);
@@ -1282,6 +1282,12 @@ static ssize_t set_mode(struct device *d
 		    !test_bit(IPOIB_FLAG_HW_CSUM, &priv->flags))
 			dev->features |= NETIF_F_IP_CSUM; /* ipv6 too */
 
+
+		if (!test_bit(IPOIB_FLAG_HW_CSUM, &priv->flags) &&
+		    priv->dev->features & NETIF_F_SG &&
+		    priv->ca->flags & IB_DEVICE_TCP_GSO)
+			priv->dev->features |= NETIF_F_TSO;
+
 		return count;
 	}
 




More information about the general mailing list