2002-02-22 22:57:51

by harish.vasudeva

[permalink] [raw]
Subject: Need some help with IP/TCP Checksum Offload

Hi All,

I am trying to offload checksum calculation to my hardware. What i am doing in my driver (kernel 2.4.6) is :

dev->features = NETIF_F_IP_CHECKSUM;

Then, in my start_xmit( ) routine, i am parsing for the right headers & when i get the IP/TCP header, i print out the checksum & it is already the right checksum. When does the OS/Protocol offload this task? Am i missing something here?

thanx for your help
HARISH V
Enterprise Connectivity Solutions, AMD
(408) 749-3324 (Work)
* Knowledge becomes wisdom only after it has been put to practical use. *



2002-02-22 23:52:50

by Benjamin LaHaise

[permalink] [raw]
Subject: Re: Need some help with IP/TCP Checksum Offload

On Fri, Feb 22, 2002 at 02:57:22PM -0800, [email protected] wrote:
>
> Then, in my start_xmit( ) routine, i am parsing for the right
> headers & when i get the IP/TCP header, i print out the checksum
> & it is already the right checksum. When does the OS/Protocol
> offload this task? Am i missing something here?

The network stack generates checksums for packets while copying,
so the checksum offload feature is only used for packets that are
not copied. The easiest way to generate packets of this nature
is to use the sendfile() syscall to transmit data from the page
cache directly onto the wire. If you need a couple of test
programs I can forward a few to you offline. Cheers,

-ben

2002-02-23 00:01:21

by Ion Badulescu

[permalink] [raw]
Subject: Re: Need some help with IP/TCP Checksum Offload

On Fri, 22 Feb 2002 14:57:22 -0800, [email protected] wrote:
>
> I am trying to offload checksum calculation to my hardware. What i am doing in my driver (kernel 2.4.6) is :
>
> dev->features = NETIF_F_IP_CHECKSUM;
>
> Then, in my start_xmit( ) routine, i am parsing for the right headers & when i get the IP/TCP header, i print out the checksum & it is already the right checksum. When does the OS/Protocol offload this task? Am i missing something here?

I haven't looked at this in a long time, but at the time the checksum
offloading support was introduced, the IP stack needed both NETIF_F_SG
and NETIF_F_IP_CSUM in dev->features before it would start offloading.

The idea was that cksum support without scatter-gather support is useless,
because the csum gets calculated essentially for free while copying the data
to linearize the skbuf.

Ion

--
It is better to keep your mouth shut and be thought a fool,
than to open it and remove all doubt.

2002-02-23 00:57:18

by harish.vasudeva

[permalink] [raw]
Subject: RE: Need some help with IP/TCP Checksum Offload

i tried setting the NETIF_F_SG flag, but the stack still gives the right checksum.

Now, i have this 1 more question. If @ all the stack does offload chksum to the hardware, how will the driver come to know about this? Is there a per packet indication from the stack asking the driver TO-DO/OR-NOT-TO-DO chksum offloading?

thanx again
HV

-----Original Message-----
From: Ion Badulescu [mailto:[email protected]]
Sent: Friday, February 22, 2002 4:01 PM
To: Vasudeva, Harish
Cc: [email protected]
Subject: Re: Need some help with IP/TCP Checksum Offload


On Fri, 22 Feb 2002 14:57:22 -0800, [email protected] wrote:
>
> I am trying to offload checksum calculation to my hardware. What i am doing in my driver (kernel 2.4.6) is :
>
> dev->features = NETIF_F_IP_CHECKSUM;
>
> Then, in my start_xmit( ) routine, i am parsing for the right headers & when i get the IP/TCP header, i print out the checksum & it is already the right checksum. When does the OS/Protocol offload this task? Am i missing something here?

I haven't looked at this in a long time, but at the time the checksum
offloading support was introduced, the IP stack needed both NETIF_F_SG
and NETIF_F_IP_CSUM in dev->features before it would start offloading.

The idea was that cksum support without scatter-gather support is useless,
because the csum gets calculated essentially for free while copying the data
to linearize the skbuf.

Ion

--
It is better to keep your mouth shut and be thought a fool,
than to open it and remove all doubt.

2002-02-23 07:34:33

by Andi Kleen

[permalink] [raw]
Subject: Re: Need some help with IP/TCP Checksum Offload

On Fri, Feb 22, 2002 at 02:57:22PM -0800, [email protected] wrote:
> Hi All,
>
> I am trying to offload checksum calculation to my hardware. What i am doing in my driver (kernel 2.4.6) is :
>
> dev->features = NETIF_F_IP_CHECKSUM;
>
> Then, in my start_xmit( ) routine, i am parsing for the right headers & when i get the IP/TCP header, i print out the checksum & it is already the right checksum. When does the OS/Protocol offload this task? Am i missing something here?

For TX the checksum is only offloaded when you set and support NETIF_F_SG
as well. Otherwise the stack has to copy anyways and can compute the
checksum during the copy operation. Then with NETIF_F_SG the TX checksumming
will only be used with sendfile(), because that is the only way to do zero
copy for now.

For RX you should set skb->ip_summed and skb->csum. The hardware checksum
is more useful in this case.

-Andi

2002-02-24 17:49:06

by Marek Zawadzki

[permalink] [raw]
Subject: Re: Need some help with IP/TCP Checksum Offload

On Fri, 22 Feb 2002 [email protected] wrote:

[...]
When does the OS/Protocol offload this task?

I can help with transport layer only -- checkumming of the transport
protocol packet is done by transport protocol -- for instance see udp.c :
udp_getfrag (for sending). So you must came up with a nice design to do it
in hardware instead (ie. without messing with the transport layer too
much). Hope this helps, although there is obviously more to do on other
layers.

-marek

P.S. Please break your lines when you post.

2002-02-25 16:23:11

by Ion Badulescu

[permalink] [raw]
Subject: RE: Need some help with IP/TCP Checksum Offload

On Fri, 22 Feb 2002 [email protected] wrote:

> i tried setting the NETIF_F_SG flag, but the stack still gives the right checksum.

Correct, not all packets will use the zerocopy framework. Using sendfile
is one way of generating them; I believe NFS will also do zerocopy but
I haven't checked it.

> Now, i have this 1 more question. If @ all the stack does offload chksum
> to the hardware, how will the driver come to know about this? Is there a
> per packet indication from the stack asking the driver
> TO-DO/OR-NOT-TO-DO chksum offloading?

Yes: skb->ip_summed == CHECKSUM_HW says the hardware is expected to
generate the checksum.

Ion

--
It is better to keep your mouth shut and be thought a fool,
than to open it and remove all doubt.