]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
IB/ipoib: CSUM support in connected mode
authorYuval Shaia <yuval.shaia@oracle.com>
Tue, 16 Jun 2015 07:32:36 +0000 (00:32 -0700)
committerMukesh Kacker <mukesh.kacker@oracle.com>
Wed, 8 Jul 2015 01:11:03 +0000 (18:11 -0700)
This enhancement suggest the usage of IB CRC instead of CSUM in IPoIB CM.
IPoIB CM uses RC (Reliable Connection) which guarantees the corruption free
delivery of the packet.

InfiniBand uses 32b CRC which provides stronger data integrity protection
compare to 16b IP Checksum. So, there is no added value that IP/TCP Checksum
provides in the IB world.

The proposal is to tell network stack that IPoIB-CM supports IP Checksum
offload. This enables the kernel to save the time of checksum calculation
of IPoIB CM packets. Network sends the IP packet without adding the IP
Checksum to the header. On the receive side, IPoIB driver again tells the
network stack that IP Checksum is good for the incoming packets and network
stack avoids the IP Checksum calculations.

During connection establishment the driver determine if peer supports
IB CRC as checksum. This is done so driver will be able to calculate
checksum before transmiting the packet in case the peer does not support
this feature.

Orabug: 20559068

Tested-Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Reviewed-by: Mukesh Kacker <mukesh.kacker@oracle.com>
Reviewed-by: Ajaykumar Hotchandani <ajaykumar.hotchandani@oracle.com>
Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
drivers/infiniband/ulp/ipoib/ipoib.h
drivers/infiniband/ulp/ipoib/ipoib_cm.c
drivers/infiniband/ulp/ipoib/ipoib_main.c

index a4de6a825f58eb0cd00dd09d45214caa6a5b12da..693b9da6a2637800e766a221a0278045595e49cd 100644 (file)
@@ -92,6 +92,7 @@ enum {
        IPOIB_FLAG_UMCAST         = 10,
        IPOIB_STOP_NEIGH_GC       = 11,
        IPOIB_NEIGH_TBL_FLUSH     = 12,
+       IPOIB_FLAG_CSUM           = 15,
 
        IPOIB_MAX_BACKOFF_SECONDS = 16,
 
@@ -185,9 +186,20 @@ struct ipoib_pmtu_update {
 
 struct ib_cm_id;
 
+/* Signature so driver can make sure ipoib_cm_data.caps is valid */
+#define IPOIB_CM_PROTO_SIG     0x2211
+/* Current driver ipoib_cm_data version */
+#define IPOIB_CM_PROTO_VER     (1UL << 12)
+
+enum ipoib_cm_data_caps {
+       IPOIB_CM_CAPS_IBCRC_AS_CSUM     = 1UL << 0,
+};
+
 struct ipoib_cm_data {
        __be32 qpn; /* High byte MUST be ignored on receive */
        __be32 mtu;
+       __be16 sig; /* must be IPOIB_CM_PROTO_SIG */
+       __be16 caps; /* 4 bits proto ver and 12 bits capabilities */
 };
 
 /*
@@ -232,6 +244,7 @@ struct ipoib_cm_rx {
        unsigned long           jiffies;
        enum ipoib_cm_state     state;
        int                     recv_count;
+       u16                     caps;
 };
 
 struct ipoib_cm_tx {
@@ -246,6 +259,7 @@ struct ipoib_cm_tx {
        unsigned             tx_tail;
        unsigned long        flags;
        u32                  mtu;
+       u16                  caps;
 };
 
 struct ipoib_cm_rx_buf {
@@ -454,8 +468,20 @@ void ipoib_del_neighs_by_gid(struct net_device *dev, u8 *gid);
 
 extern struct workqueue_struct *ipoib_workqueue;
 
+extern int cm_ibcrc_as_csum;
+
 /* functions */
 
+static inline int ipoib_cm_check_proto_sig(u16 proto_sig)
+{
+       return (proto_sig == IPOIB_CM_PROTO_SIG);
+}
+
+static inline int ipoib_cm_check_proto_ver(u16 caps)
+{
+       return ((caps & 0xF000) == IPOIB_CM_PROTO_VER);
+}
+
 int ipoib_poll(struct napi_struct *napi, int budget);
 void ipoib_ib_completion(struct ib_cq *cq, void *dev_ptr);
 void ipoib_send_comp_handler(struct ib_cq *cq, void *dev_ptr);
index 7452cbe3079af2c9b286b2b93166cb414ea497ae..d84531d49722b9137d05ddf833b3839cd55965f1 100644 (file)
@@ -448,9 +448,16 @@ static int ipoib_cm_send_rep(struct net_device *dev, struct ib_cm_id *cm_id,
        struct ipoib_dev_priv *priv = netdev_priv(dev);
        struct ipoib_cm_data data = {};
        struct ib_cm_rep_param rep = {};
+       u16 caps = 0;
+
+       caps |= IPOIB_CM_PROTO_VER;
+       if (cm_ibcrc_as_csum && test_bit(IPOIB_FLAG_CSUM, &priv->flags))
+               caps |= IPOIB_CM_CAPS_IBCRC_AS_CSUM;
 
        data.qpn = cpu_to_be32(priv->qp->qp_num);
        data.mtu = cpu_to_be32(IPOIB_CM_BUF_SIZE);
+       data.sig = cpu_to_be16(IPOIB_CM_PROTO_SIG);
+       data.caps = cpu_to_be16(caps);
 
        rep.private_data = &data;
        rep.private_data_len = sizeof data;
@@ -469,6 +476,7 @@ static int ipoib_cm_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *even
        struct ipoib_cm_rx *p;
        unsigned psn;
        int ret;
+       struct ipoib_cm_data *cm_data;
 
        ipoib_dbg(priv, "REQ arrived\n");
        p = kzalloc(sizeof *p, GFP_KERNEL);
@@ -487,6 +495,13 @@ static int ipoib_cm_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *even
                goto err_qp;
        }
 
+       cm_data = (struct ipoib_cm_data *)event->private_data;
+       ipoib_dbg(priv, "Otherend sig=0x%x\n", be16_to_cpu(cm_data->sig));
+       if (ipoib_cm_check_proto_sig(be16_to_cpu(cm_data->sig)) &&
+           ipoib_cm_check_proto_ver(be16_to_cpu(cm_data->caps)))
+               p->caps = be16_to_cpu(cm_data->caps);
+       ipoib_dbg(priv, "Otherend caps=0x%x\n", p->caps);
+
        psn = prandom_u32() & 0xffffff;
        ret = ipoib_cm_modify_rx_qp(dev, cm_id, p->qp, psn);
        if (ret)
@@ -697,6 +712,10 @@ copied:
        skb->dev = dev;
        /* XXX get correct PACKET_ type here */
        skb->pkt_type = PACKET_HOST;
+
+       if (cm_ibcrc_as_csum && test_bit(IPOIB_FLAG_CSUM, &priv->flags))
+               skb->ip_summed = CHECKSUM_UNNECESSARY;
+
        netif_receive_skb(skb);
 
 repost:
@@ -789,6 +808,18 @@ void ipoib_cm_send(struct net_device *dev, struct sk_buff *skb, struct ipoib_cm_
        tx_req = &tx->tx_ring[tx->tx_head & (ipoib_sendq_size - 1)];
        tx_req->skb = skb;
 
+       /* Calculate checksum if we support ibcrc_as_csum but peer is not */
+       if ((skb->ip_summed == CHECKSUM_PARTIAL) && cm_ibcrc_as_csum &&
+           test_bit(IPOIB_FLAG_CSUM, &priv->flags) &&
+           !(tx->caps & IPOIB_CM_CAPS_IBCRC_AS_CSUM)) {
+               if (skb_checksum_help(skb)) {
+                       ipoib_warn(priv, "Fail to csum skb\n");
+                       ++dev->stats.tx_errors;
+                       dev_kfree_skb_any(skb);
+                       return;
+               }
+       }
+
        if (skb_shinfo(skb)->nr_frags) {
                if (unlikely(ipoib_dma_map_tx(priv->ca, tx_req))) {
                        ++dev->stats.tx_errors;
@@ -1032,6 +1063,7 @@ static int ipoib_cm_rep_handler(struct ib_cm_id *cm_id, struct ib_cm_event *even
        struct ib_qp_attr qp_attr;
        int qp_attr_mask, ret;
        struct sk_buff *skb;
+       struct ipoib_cm_data *cm_data;
 
        p->mtu = be32_to_cpu(data->mtu);
 
@@ -1041,6 +1073,13 @@ static int ipoib_cm_rep_handler(struct ib_cm_id *cm_id, struct ib_cm_event *even
                return -EINVAL;
        }
 
+       cm_data = (struct ipoib_cm_data *)event->private_data;
+       ipoib_dbg(priv, "Otherend sig=0x%x\n", be16_to_cpu(cm_data->sig));
+       if (ipoib_cm_check_proto_sig(be16_to_cpu(cm_data->sig)) &&
+           ipoib_cm_check_proto_ver(be16_to_cpu(cm_data->caps)))
+               p->caps = be16_to_cpu(cm_data->caps);
+       ipoib_dbg(priv, "Otherend caps=0x%x\n", p->caps);
+
        qp_attr.qp_state = IB_QPS_RTR;
        ret = ib_cm_init_qp_attr(cm_id, &qp_attr, &qp_attr_mask);
        if (ret) {
@@ -1133,9 +1172,16 @@ static int ipoib_cm_send_req(struct net_device *dev,
        struct ipoib_dev_priv *priv = netdev_priv(dev);
        struct ipoib_cm_data data = {};
        struct ib_cm_req_param req = {};
+       u16 caps = 0;
+
+       caps |= IPOIB_CM_PROTO_VER;
+       if (cm_ibcrc_as_csum && test_bit(IPOIB_FLAG_CSUM, &priv->flags))
+               caps |= IPOIB_CM_CAPS_IBCRC_AS_CSUM;
 
        data.qpn = cpu_to_be32(priv->qp->qp_num);
        data.mtu = cpu_to_be32(IPOIB_CM_BUF_SIZE);
+       data.sig = cpu_to_be16(IPOIB_CM_PROTO_SIG);
+       data.caps = cpu_to_be16(caps);
 
        req.primary_path                = pathrec;
        req.alternate_path              = NULL;
index 8f60a15e7469326e40cc9bb061ed740400b2550b..e5b627fe9e4335ed2e4588341b095afbe0651691 100644 (file)
@@ -74,6 +74,11 @@ module_param_named(debug_level, ipoib_debug_level, int, 0644);
 MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
 #endif
 
+int cm_ibcrc_as_csum = 1;
+module_param_named(cm_ibcrc_as_csum, cm_ibcrc_as_csum, int, 0444);
+MODULE_PARM_DESC(cm_ibcrc_as_csum,
+                "Indicates whether to utilize IB-CRC as CSUM in connected mode,(default: 1)");
+
 struct ipoib_path_iter {
        struct net_device *dev;
        struct ipoib_path  path;
@@ -197,8 +202,12 @@ static netdev_features_t ipoib_fix_features(struct net_device *dev, netdev_featu
 {
        struct ipoib_dev_priv *priv = netdev_priv(dev);
 
-       if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags))
-               features &= ~(NETIF_F_IP_CSUM | NETIF_F_TSO);
+       if (test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags)) {
+               features &= ~NETIF_F_TSO;
+               if (!(cm_ibcrc_as_csum && (test_bit(IPOIB_FLAG_CSUM,
+                                          &priv->flags))))
+                       features &= ~(NETIF_F_IP_CSUM | NETIF_F_TSO);
+       }
 
        return features;
 }
@@ -254,7 +263,11 @@ int ipoib_set_mode(struct net_device *dev, const char *buf)
                           "will cause multicast packet drops\n");
                netdev_update_features(dev);
                rtnl_unlock();
-               priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM;
+               if (cm_ibcrc_as_csum && (test_bit(IPOIB_FLAG_CSUM,
+                                                 &priv->flags)))
+                       priv->tx_wr.send_flags |= IB_SEND_IP_CSUM;
+               else
+                       priv->tx_wr.send_flags &= ~IB_SEND_IP_CSUM;
 
                ipoib_flush_paths(dev);
 
@@ -1738,6 +1751,7 @@ int ipoib_set_dev_features(struct ipoib_dev_priv *priv, struct ib_device *hca)
        kfree(device_attr);
 
        if (priv->hca_caps & IB_DEVICE_UD_IP_CSUM) {
+               set_bit(IPOIB_FLAG_CSUM, &priv->flags);
                priv->dev->hw_features = NETIF_F_SG |
                        NETIF_F_IP_CSUM | NETIF_F_RXCSUM;