* [PATCH net-next] net/mlx4_en: Fix IPv6 csum calculation
@ 2015-08-28 19:28 clsoto
2015-08-28 19:46 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: clsoto @ 2015-08-28 19:28 UTC (permalink / raw)
To: davem; +Cc: netdev, ogerlitz, brking, amirv, Carol L Soto, Muhammad Mahajna
From: Carol L Soto <clsoto@linux.vnet.ibm.com>
Seeing this message with mlx4_eni with IPv6: hw csum failure
Changing IPv6 csum calculation to be based on OFED 2.4 code.
When calculate IPv6 csum based also on source and destination
addresses.
Signed-off-by: Muhammad Mahajna <muhammadm@mellanox.com>
Signed-off-by: Carol L Soto <clsoto@linux.vnet.ibm.com>
---
drivers/net/ethernet/mellanox/mlx4/en_rx.c | 46 +++++++++++++++++++++---------
1 file changed, 33 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
index 4402a1e..d43c512 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_rx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
@@ -693,26 +693,46 @@ static void get_fixed_ipv4_csum(__wsum hw_checksum, struct sk_buff *skb,
}
#if IS_ENABLED(CONFIG_IPV6)
-/* In IPv6 packets, besides subtracting the pseudo header checksum,
- * we also compute/add the IP header checksum which
- * is not added by the HW.
- */
+static __wsum csum_ipv6_magic_nofold(const struct in6_addr *saddr,
+ const struct in6_addr *daddr,
+ __u32 len, unsigned short proto)
+{
+ __wsum res = 0;
+
+ res = csum_add(res, saddr->in6_u.u6_addr32[0]);
+ res = csum_add(res, saddr->in6_u.u6_addr32[1]);
+ res = csum_add(res, saddr->in6_u.u6_addr32[2]);
+ res = csum_add(res, saddr->in6_u.u6_addr32[3]);
+ res = csum_add(res, daddr->in6_u.u6_addr32[0]);
+ res = csum_add(res, daddr->in6_u.u6_addr32[1]);
+ res = csum_add(res, daddr->in6_u.u6_addr32[2]);
+ res = csum_add(res, daddr->in6_u.u6_addr32[3]);
+ res = csum_add(res, len);
+ res = csum_add(res, htonl(proto));
+
+ return res;
+}
+
static int get_fixed_ipv6_csum(__wsum hw_checksum, struct sk_buff *skb,
struct ipv6hdr *ipv6h)
{
- __wsum csum_pseudo_hdr = 0;
+ __wsum csum_pseudo_header = 0;
- if (ipv6h->nexthdr == IPPROTO_FRAGMENT || ipv6h->nexthdr == IPPROTO_HOPOPTS)
+ if (ipv6h->nexthdr == IPPROTO_FRAGMENT ||
+ ipv6h->nexthdr == IPPROTO_HOPOPTS)
return -1;
- hw_checksum = csum_add(hw_checksum, (__force __wsum)(ipv6h->nexthdr << 8));
- csum_pseudo_hdr = csum_partial(&ipv6h->saddr,
- sizeof(ipv6h->saddr) + sizeof(ipv6h->daddr), 0);
- csum_pseudo_hdr = csum_add(csum_pseudo_hdr, (__force __wsum)ipv6h->payload_len);
- csum_pseudo_hdr = csum_add(csum_pseudo_hdr, (__force __wsum)ntohs(ipv6h->nexthdr));
+ hw_checksum = csum_add(hw_checksum, cpu_to_be16(ipv6h->nexthdr));
+ csum_pseudo_header = csum_ipv6_magic_nofold(&ipv6h->saddr,
+ &ipv6h->daddr,
+ ipv6h->payload_len,
+ ipv6h->nexthdr);
+ hw_checksum = csum_sub(hw_checksum, csum_pseudo_header);
+ hw_checksum = csum_partial(ipv6h, sizeof(struct ipv6hdr), hw_checksum);
+ if (!hw_checksum)
+ return -1;
- skb->csum = csum_sub(hw_checksum, csum_pseudo_hdr);
- skb->csum = csum_add(skb->csum, csum_partial(ipv6h, sizeof(struct ipv6hdr), 0));
+ skb->csum = hw_checksum;
return 0;
}
#endif
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net/mlx4_en: Fix IPv6 csum calculation
2015-08-28 19:28 [PATCH net-next] net/mlx4_en: Fix IPv6 csum calculation clsoto
@ 2015-08-28 19:46 ` Joe Perches
2015-08-30 6:18 ` Or Gerlitz
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2015-08-28 19:46 UTC (permalink / raw)
To: clsoto; +Cc: davem, netdev, ogerlitz, brking, amirv, Muhammad Mahajna
On Fri, 2015-08-28 at 14:28 -0500, clsoto@linux.vnet.ibm.com wrote:
> From: Carol L Soto <clsoto@linux.vnet.ibm.com>
>
> Seeing this message with mlx4_eni with IPv6: hw csum failure
>
> Changing IPv6 csum calculation to be based on OFED 2.4 code.
> When calculate IPv6 csum based also on source and destination
> addresses.
[]
> diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
[]
> +static __wsum csum_ipv6_magic_nofold(const struct in6_addr *saddr,
> + const struct in6_addr *daddr,
> + __u32 len, unsigned short proto)
> +{
> + __wsum res = 0;
> +
> + res = csum_add(res, saddr->in6_u.u6_addr32[0]);
> + res = csum_add(res, saddr->in6_u.u6_addr32[1]);
> + res = csum_add(res, saddr->in6_u.u6_addr32[2]);
> + res = csum_add(res, saddr->in6_u.u6_addr32[3]);
> + res = csum_add(res, daddr->in6_u.u6_addr32[0]);
> + res = csum_add(res, daddr->in6_u.u6_addr32[1]);
> + res = csum_add(res, daddr->in6_u.u6_addr32[2]);
> + res = csum_add(res, daddr->in6_u.u6_addr32[3]);
> + res = csum_add(res, len);
> + res = csum_add(res, htonl(proto));
You should try running sparse on this code.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net/mlx4_en: Fix IPv6 csum calculation
2015-08-28 19:46 ` Joe Perches
@ 2015-08-30 6:18 ` Or Gerlitz
0 siblings, 0 replies; 3+ messages in thread
From: Or Gerlitz @ 2015-08-30 6:18 UTC (permalink / raw)
To: Joe Perches
Cc: clsoto, David Miller, Linux Netdev List, Or Gerlitz, brking,
Amir Vadai, Muhammad Mahajna
On Fri, Aug 28, 2015 at 12:46 PM, Joe Perches <joe@perches.com> wrote:
> On Fri, 2015-08-28 at 14:28 -0500, clsoto@linux.vnet.ibm.com wrote:
>> From: Carol L Soto <clsoto@linux.vnet.ibm.com>
>>
>> Seeing this message with mlx4_eni with IPv6: hw csum failure
>>
>> Changing IPv6 csum calculation to be based on OFED 2.4 code.
>> When calculate IPv6 csum based also on source and destination
>> addresses.
> []
>> diff --git a/drivers/net/ethernet/mellanox/mlx4/en_rx.c b/drivers/net/ethernet/mellanox/mlx4/en_rx.c
> []
>> +static __wsum csum_ipv6_magic_nofold(const struct in6_addr *saddr,
>> + const struct in6_addr *daddr,
>> + __u32 len, unsigned short proto)
>> +{
>> + __wsum res = 0;
>> +
>> + res = csum_add(res, saddr->in6_u.u6_addr32[0]);
>> + res = csum_add(res, saddr->in6_u.u6_addr32[1]);
>> + res = csum_add(res, saddr->in6_u.u6_addr32[2]);
>> + res = csum_add(res, saddr->in6_u.u6_addr32[3]);
>> + res = csum_add(res, daddr->in6_u.u6_addr32[0]);
>> + res = csum_add(res, daddr->in6_u.u6_addr32[1]);
>> + res = csum_add(res, daddr->in6_u.u6_addr32[2]);
>> + res = csum_add(res, daddr->in6_u.u6_addr32[3]);
>> + res = csum_add(res, len);
>> + res = csum_add(res, htonl(proto));
>
> You should try running sparse on this code.
Yep, if I remember correct, the patch is still under internal review
with making sparse/smatch happy on it being a pending comment.
Or.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-30 6:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-28 19:28 [PATCH net-next] net/mlx4_en: Fix IPv6 csum calculation clsoto
2015-08-28 19:46 ` Joe Perches
2015-08-30 6:18 ` Or Gerlitz
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).