Merge ../torvalds-2.6/
[linux-2.6] / drivers / s390 / net / qeth_tso.h
1 /*
2  * linux/drivers/s390/net/qeth_tso.h ($Revision: 1.8 $)
3  *
4  * Header file for qeth TCP Segmentation Offload support.
5  *
6  * Copyright 2004 IBM Corporation
7  *
8  *    Author(s): Frank Pavlic <fpavlic@de.ibm.com>
9  *
10  *    $Revision: 1.8 $   $Date: 2005/05/04 20:19:18 $
11  *
12  */
13 #ifndef __QETH_TSO_H__
14 #define __QETH_TSO_H__
15
16 #include <linux/skbuff.h>
17 #include <linux/tcp.h>
18 #include <linux/ip.h>
19 #include <linux/ipv6.h>
20 #include <net/ip6_checksum.h>
21 #include "qeth.h"
22 #include "qeth_mpc.h"
23
24
25 static inline struct qeth_hdr_tso *
26 qeth_tso_prepare_skb(struct qeth_card *card, struct sk_buff **skb)
27 {
28         QETH_DBF_TEXT(trace, 5, "tsoprsk");
29         return qeth_push_skb(card, skb, sizeof(struct qeth_hdr_tso));
30 }
31
32 /**
33  * fill header for a TSO packet
34  */
35 static inline void
36 qeth_tso_fill_header(struct qeth_card *card, struct sk_buff *skb)
37 {
38         struct qeth_hdr_tso *hdr;
39         struct tcphdr *tcph;
40         struct iphdr *iph;
41
42         QETH_DBF_TEXT(trace, 5, "tsofhdr");
43
44         hdr  = (struct qeth_hdr_tso *) skb->data;
45         iph  = skb->nh.iph;
46         tcph = skb->h.th;
47         /*fix header to TSO values ...*/
48         hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
49         /*set values which are fix for the first approach ...*/
50         hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
51         hdr->ext.imb_hdr_no  = 1;
52         hdr->ext.hdr_type    = 1;
53         hdr->ext.hdr_version = 1;
54         hdr->ext.hdr_len     = 28;
55         /*insert non-fix values */
56         hdr->ext.mss = skb_shinfo(skb)->tso_size;
57         hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
58         hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
59                                        sizeof(struct qeth_hdr_tso));
60 }
61
62 /**
63  * change some header values as requested by hardware
64  */
65 static inline void
66 qeth_tso_set_tcpip_header(struct qeth_card *card, struct sk_buff *skb)
67 {
68         struct iphdr *iph;
69         struct ipv6hdr *ip6h;
70         struct tcphdr *tcph;
71
72         iph  = skb->nh.iph;
73         ip6h = skb->nh.ipv6h;
74         tcph = skb->h.th;
75
76         tcph->check = 0;
77         if (skb->protocol == ETH_P_IPV6) {
78                 ip6h->payload_len = 0;
79                 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
80                                                0, IPPROTO_TCP, 0);
81                 return;
82         }
83         /*OSA want us to set these values ...*/
84         tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
85                                          0, IPPROTO_TCP, 0);
86         iph->tot_len = 0;
87         iph->check = 0;
88 }
89
90 static inline int
91 qeth_tso_prepare_packet(struct qeth_card *card, struct sk_buff *skb,
92                         int ipv, int cast_type)
93 {
94         struct qeth_hdr_tso *hdr;
95
96         QETH_DBF_TEXT(trace, 5, "tsoprep");
97
98         hdr = (struct qeth_hdr_tso *) qeth_tso_prepare_skb(card, &skb);
99         if (hdr == NULL) {
100                 QETH_DBF_TEXT(trace, 4, "tsoperr");
101                 return -ENOMEM;
102         }
103         memset(hdr, 0, sizeof(struct qeth_hdr_tso));
104         /*fill first 32 bytes of  qdio header as used
105          *FIXME: TSO has two struct members
106          * with different names but same size
107          * */
108         qeth_fill_header(card, &hdr->hdr, skb, ipv, cast_type);
109         qeth_tso_fill_header(card, skb);
110         qeth_tso_set_tcpip_header(card, skb);
111         return 0;
112 }
113
114 static inline void
115 __qeth_fill_buffer_frag(struct sk_buff *skb, struct qdio_buffer *buffer,
116                         int is_tso, int *next_element_to_fill)
117 {
118         struct skb_frag_struct *frag;
119         int fragno;
120         unsigned long addr;
121         int element, cnt, dlen;
122         
123         fragno = skb_shinfo(skb)->nr_frags;
124         element = *next_element_to_fill;
125         dlen = 0;
126         
127         if (is_tso)
128                 buffer->element[element].flags =
129                         SBAL_FLAGS_MIDDLE_FRAG;
130         else
131                 buffer->element[element].flags =
132                         SBAL_FLAGS_FIRST_FRAG;
133         if ( (dlen = (skb->len - skb->data_len)) ) {
134                 buffer->element[element].addr = skb->data;
135                 buffer->element[element].length = dlen;
136                 element++;
137         }
138         for (cnt = 0; cnt < fragno; cnt++) {
139                 frag = &skb_shinfo(skb)->frags[cnt];
140                 addr = (page_to_pfn(frag->page) << PAGE_SHIFT) +
141                         frag->page_offset;
142                 buffer->element[element].addr = (char *)addr;
143                 buffer->element[element].length = frag->size;
144                 if (cnt < (fragno - 1))
145                         buffer->element[element].flags =
146                                 SBAL_FLAGS_MIDDLE_FRAG;
147                 else
148                         buffer->element[element].flags =
149                                 SBAL_FLAGS_LAST_FRAG;
150                 element++;
151         }
152         *next_element_to_fill = element;
153 }
154 #endif /* __QETH_TSO_H__ */