This provides an example of a driver calling the skb_csum_offload_check.

Signed-off-by: Tom Herbert <t...@herbertland.com>
---
 drivers/net/ethernet/mellanox/mlx4/en_netdev.c |  6 +++---
 drivers/net/ethernet/mellanox/mlx4/en_tx.c     | 20 +++++++++++++++-----
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c 
b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index 4726122..f2ed8d0 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -2360,7 +2360,7 @@ out:
        }
 
        /* set offloads */
-       priv->dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
+       priv->dev->hw_enc_features |= NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
                                      NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL;
        priv->dev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
        priv->dev->features    |= NETIF_F_GSO_UDP_TUNNEL;
@@ -2372,7 +2372,7 @@ static void mlx4_en_del_vxlan_offloads(struct work_struct 
*work)
        struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
                                                 vxlan_del_task);
        /* unset offloads */
-       priv->dev->hw_enc_features &= ~(NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
+       priv->dev->hw_enc_features &= ~(NETIF_F_HW_CSUM | NETIF_F_RXCSUM |
                                      NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL);
        priv->dev->hw_features &= ~NETIF_F_GSO_UDP_TUNNEL;
        priv->dev->features    &= ~NETIF_F_GSO_UDP_TUNNEL;
@@ -2943,7 +2943,7 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int 
port,
        /*
         * Set driver features
         */
-       dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
+       dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM;
        if (mdev->LSO_support)
                dev->hw_features |= NETIF_F_TSO | NETIF_F_TSO6;
 
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c 
b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index 494e776..f364ffd 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -702,6 +702,14 @@ static void mlx4_bf_copy(void __iomem *dst, const void 
*src,
        __iowrite64_copy(dst, src, bytecnt / 8);
 }
 
+static const struct skb_csum_offl_spec csum_offl_spec = {
+       .ipv4_okay = 1,
+       .ipv6_okay = 1,
+       .encap_okay = 1,
+       .tcp_okay = 1,
+       .udp_okay = 1,
+};
+
 netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct skb_shared_info *shinfo = skb_shinfo(skb);
@@ -727,6 +735,7 @@ netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct 
net_device *dev)
        bool stop_queue;
        bool inline_ok;
        u32 ring_cons;
+       struct skb_csum_offl_params offl_params;
 
        if (!priv->port_up)
                goto tx_drop;
@@ -853,8 +862,9 @@ netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct 
net_device *dev)
        /* Prepare ctrl segement apart opcode+ownership, which depends on
         * whether LSO is used */
        tx_desc->ctrl.srcrb_flags = priv->ctrl_flags;
-       if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
-               if (!skb->encapsulation)
+       if (skb_csum_offload_chk(skb, &csum_offl_spec,
+                                &offl_params, true)) {
+               if (!offl_params.encapped_csum)
                        tx_desc->ctrl.srcrb_flags |= 
cpu_to_be32(MLX4_WQE_CTRL_IP_CSUM |
                                                                 
MLX4_WQE_CTRL_TCP_UDP_CSUM);
                else
@@ -912,9 +922,9 @@ netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct 
net_device *dev)
                build_inline_wqe(tx_desc, skb, shinfo, real_size, &vlan_tag,
                                 tx_ind, fragptr);
 
-       if (skb->encapsulation) {
-               struct iphdr *ipv4 = (struct iphdr 
*)skb_inner_network_header(skb);
-               if (ipv4->protocol == IPPROTO_TCP || ipv4->protocol == 
IPPROTO_UDP)
+       if (!offl_params.encapped_csum) {
+               if (offl_params.ip_proto == IPPROTO_TCP ||
+                   offl_params.ip_proto == IPPROTO_UDP)
                        op_own |= cpu_to_be32(MLX4_WQE_CTRL_IIP | 
MLX4_WQE_CTRL_ILP);
                else
                        op_own |= cpu_to_be32(MLX4_WQE_CTRL_IIP);
-- 
2.4.6

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to