[ofa-general] [PATCH 4/16 v2] IB/ipoib: Add checksum offload support for ipoib
Eli Cohen
eli at mellanox.co.il
Thu Jan 24 08:57:11 PST 2008
Add checksum offload support for ipoib
Signed-off-by: Eli Cohen <eli at mellanox.co.il>
---
changes:
remove ipv6 support
add call to skb_reset_network_header()
drivers/infiniband/ulp/ipoib/ipoib.h | 1 +
drivers/infiniband/ulp/ipoib/ipoib_cm.c | 9 +++++++++
drivers/infiniband/ulp/ipoib/ipoib_ib.c | 20 ++++++++++++++++++++
drivers/infiniband/ulp/ipoib/ipoib_main.c | 15 +++++++++++++++
4 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 6729c14..f0876dc 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -86,6 +86,7 @@ enum {
IPOIB_MCAST_STARTED = 8,
IPOIB_FLAG_ADMIN_CM = 9,
IPOIB_FLAG_UMCAST = 10,
+ IPOIB_FLAG_CSUM = 11,
IPOIB_MAX_BACKOFF_SECONDS = 16,
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 8485fde..1c1e446 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -1234,6 +1234,11 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
set_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
ipoib_warn(priv, "enabling connected mode "
"will cause multicast packet drops\n");
+
+ dev->features &= ~NETIF_F_IP_CSUM;
+
+ priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM;
+
ipoib_flush_paths(dev);
return count;
}
@@ -1242,6 +1247,10 @@ static ssize_t set_mode(struct device *d, struct device_attribute *attr,
clear_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
dev->mtu = min(priv->mcast_mtu, dev->mtu);
ipoib_flush_paths(dev);
+
+ if (priv->ca->flags & IB_DEVICE_IP_CSUM)
+ dev->features |= NETIF_F_IP_CSUM;
+
return count;
}
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index 680c27f..875eba0 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -37,6 +37,7 @@
#include <linux/delay.h>
#include <linux/dma-mapping.h>
+#include <linux/ip.h>
#include <rdma/ib_cache.h>
@@ -231,6 +232,19 @@ static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
skb->dev = dev;
/* XXX get correct PACKET_ type here */
skb->pkt_type = PACKET_HOST;
+
+ /* check rx csum */
+ if (test_bit(IPOIB_FLAG_CSUM, &priv->flags) && likely(wc->csum_ok)) {
+ /*
+ * Note: this is a specific requirement for Mellanox
+ * HW but since it is the only HW currently supporting
+ * checksum offload I put it here
+ */
+ skb_reset_network_header(skb);
+ if (ip_hdr(skb)->ihl == 5)
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+ }
+
netif_receive_skb(skb);
repost:
@@ -394,6 +408,12 @@ void ipoib_send(struct net_device *dev, struct sk_buff *skb,
return;
}
+ if (dev->flags & NETIF_F_IP_CSUM &&
+ skb->ip_summed == CHECKSUM_PARTIAL)
+ priv->tx_wr.send_flags |= IB_SEND_IP_CSUM;
+ else
+ priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM;
+
if (unlikely(post_send(priv, priv->tx_head & (ipoib_sendq_size - 1),
address->ah, qpn,
tx_req->mapping, skb_headlen(skb),
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index b40e0f7..c0e6c01 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -1106,6 +1106,20 @@ int ipoib_add_pkey_attr(struct net_device *dev)
return device_create_file(&dev->dev, &dev_attr_pkey);
}
+static void set_csum(struct net_device *dev, struct ib_device *hca)
+{
+ struct ipoib_dev_priv *priv = netdev_priv(dev);
+
+ if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags))
+ return;
+
+ if (!(hca->flags & IB_DEVICE_IP_CSUM))
+ return;
+
+ dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
+ set_bit(IPOIB_FLAG_CSUM, &priv->flags);
+}
+
static struct net_device *ipoib_add_port(const char *format,
struct ib_device *hca, u8 port)
{
@@ -1144,6 +1158,7 @@ static struct net_device *ipoib_add_port(const char *format,
} else
memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid));
+ set_csum(priv->dev, hca);
result = ipoib_dev_init(priv->dev, hca, port);
if (result < 0) {
--
1.5.3.8
More information about the general
mailing list