blob: c20e923cf9ad0ff2ac7cd82d450350e43655e8aa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstense018ba12006-02-01 03:06:31 -08002 * linux/drivers/s390/net/qeth_tso.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Header file for qeth TCP Segmentation Offload support.
5 *
6 * Copyright 2004 IBM Corporation
7 *
Frank Pavlic13877802005-11-10 13:51:42 +01008 * Author(s): Frank Pavlic <fpavlic@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11#ifndef __QETH_TSO_H__
12#define __QETH_TSO_H__
13
Frank Pavlic05e08a22005-05-12 20:39:09 +020014#include <linux/skbuff.h>
15#include <linux/tcp.h>
16#include <linux/ip.h>
17#include <linux/ipv6.h>
18#include <net/ip6_checksum.h>
19#include "qeth.h"
20#include "qeth_mpc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Frank Pavlic05e08a22005-05-12 20:39:09 +020023static inline struct qeth_hdr_tso *
24qeth_tso_prepare_skb(struct qeth_card *card, struct sk_buff **skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
Frank Pavlic05e08a22005-05-12 20:39:09 +020026 QETH_DBF_TEXT(trace, 5, "tsoprsk");
Frank Pavlicf7b65d72006-09-15 16:26:19 +020027 return qeth_push_skb(card, *skb, sizeof(struct qeth_hdr_tso));
Frank Pavlic05e08a22005-05-12 20:39:09 +020028}
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Frank Pavlic05e08a22005-05-12 20:39:09 +020030/**
31 * fill header for a TSO packet
32 */
33static inline void
34qeth_tso_fill_header(struct qeth_card *card, struct sk_buff *skb)
35{
36 struct qeth_hdr_tso *hdr;
37 struct tcphdr *tcph;
38 struct iphdr *iph;
39
40 QETH_DBF_TEXT(trace, 5, "tsofhdr");
41
42 hdr = (struct qeth_hdr_tso *) skb->data;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -070043 iph = ip_hdr(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -070044 tcph = tcp_hdr(skb);
Frank Pavlic05e08a22005-05-12 20:39:09 +020045 /*fix header to TSO values ...*/
46 hdr->hdr.hdr.l3.id = QETH_HEADER_TYPE_TSO;
47 /*set values which are fix for the first approach ...*/
48 hdr->ext.hdr_tot_len = (__u16) sizeof(struct qeth_hdr_ext_tso);
49 hdr->ext.imb_hdr_no = 1;
50 hdr->ext.hdr_type = 1;
51 hdr->ext.hdr_version = 1;
52 hdr->ext.hdr_len = 28;
53 /*insert non-fix values */
Herbert Xu79671682006-06-22 02:40:14 -070054 hdr->ext.mss = skb_shinfo(skb)->gso_size;
Frank Pavlic05e08a22005-05-12 20:39:09 +020055 hdr->ext.dg_hdr_len = (__u16)(iph->ihl*4 + tcph->doff*4);
56 hdr->ext.payload_len = (__u16)(skb->len - hdr->ext.dg_hdr_len -
57 sizeof(struct qeth_hdr_tso));
58}
59
60/**
61 * change some header values as requested by hardware
62 */
63static inline void
64qeth_tso_set_tcpip_header(struct qeth_card *card, struct sk_buff *skb)
65{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -070066 struct iphdr *iph = ip_hdr(skb);
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -070067 struct ipv6hdr *ip6h = ipv6_hdr(skb);
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -070068 struct tcphdr *tcph = tcp_hdr(skb);
Frank Pavlic05e08a22005-05-12 20:39:09 +020069
70 tcph->check = 0;
71 if (skb->protocol == ETH_P_IPV6) {
72 ip6h->payload_len = 0;
73 tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr,
74 0, IPPROTO_TCP, 0);
75 return;
76 }
77 /*OSA want us to set these values ...*/
78 tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
79 0, IPPROTO_TCP, 0);
80 iph->tot_len = 0;
81 iph->check = 0;
82}
83
84static inline int
85qeth_tso_prepare_packet(struct qeth_card *card, struct sk_buff *skb,
86 int ipv, int cast_type)
87{
88 struct qeth_hdr_tso *hdr;
89
90 QETH_DBF_TEXT(trace, 5, "tsoprep");
91
92 hdr = (struct qeth_hdr_tso *) qeth_tso_prepare_skb(card, &skb);
93 if (hdr == NULL) {
94 QETH_DBF_TEXT(trace, 4, "tsoperr");
95 return -ENOMEM;
96 }
97 memset(hdr, 0, sizeof(struct qeth_hdr_tso));
98 /*fill first 32 bytes of qdio header as used
99 *FIXME: TSO has two struct members
100 * with different names but same size
101 * */
102 qeth_fill_header(card, &hdr->hdr, skb, ipv, cast_type);
103 qeth_tso_fill_header(card, skb);
104 qeth_tso_set_tcpip_header(card, skb);
105 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
Frank Pavlicd8011452005-05-12 20:37:53 +0200107
108static inline void
109__qeth_fill_buffer_frag(struct sk_buff *skb, struct qdio_buffer *buffer,
110 int is_tso, int *next_element_to_fill)
111{
Frank Pavlicd8011452005-05-12 20:37:53 +0200112 struct skb_frag_struct *frag;
113 int fragno;
114 unsigned long addr;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200115 int element, cnt, dlen;
Jeff Garzike82b0f22006-05-26 21:58:38 -0400116
Frank Pavlic05e08a22005-05-12 20:39:09 +0200117 fragno = skb_shinfo(skb)->nr_frags;
118 element = *next_element_to_fill;
119 dlen = 0;
Jeff Garzike82b0f22006-05-26 21:58:38 -0400120
Frank Pavlic05e08a22005-05-12 20:39:09 +0200121 if (is_tso)
122 buffer->element[element].flags =
123 SBAL_FLAGS_MIDDLE_FRAG;
124 else
125 buffer->element[element].flags =
126 SBAL_FLAGS_FIRST_FRAG;
127 if ( (dlen = (skb->len - skb->data_len)) ) {
128 buffer->element[element].addr = skb->data;
129 buffer->element[element].length = dlen;
130 element++;
Frank Pavlicd8011452005-05-12 20:37:53 +0200131 }
Frank Pavlic05e08a22005-05-12 20:39:09 +0200132 for (cnt = 0; cnt < fragno; cnt++) {
133 frag = &skb_shinfo(skb)->frags[cnt];
134 addr = (page_to_pfn(frag->page) << PAGE_SHIFT) +
135 frag->page_offset;
136 buffer->element[element].addr = (char *)addr;
137 buffer->element[element].length = frag->size;
138 if (cnt < (fragno - 1))
139 buffer->element[element].flags =
140 SBAL_FLAGS_MIDDLE_FRAG;
141 else
142 buffer->element[element].flags =
143 SBAL_FLAGS_LAST_FRAG;
144 element++;
145 }
146 *next_element_to_fill = element;
Frank Pavlicd8011452005-05-12 20:37:53 +0200147}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#endif /* __QETH_TSO_H__ */