Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Heiko Carstens | e018ba1 | 2006-02-01 03:06:31 -0800 | [diff] [blame] | 2 | * linux/drivers/s390/net/qeth_tso.h |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Header file for qeth TCP Segmentation Offload support. |
| 5 | * |
| 6 | * Copyright 2004 IBM Corporation |
| 7 | * |
Frank Pavlic | 1387780f | 2005-11-10 13:51:42 +0100 | [diff] [blame] | 8 | * Author(s): Frank Pavlic <fpavlic@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | #ifndef __QETH_TSO_H__ |
| 12 | #define __QETH_TSO_H__ |
| 13 | |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 14 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 23 | static inline struct qeth_hdr_tso * |
| 24 | qeth_tso_prepare_skb(struct qeth_card *card, struct sk_buff **skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 26 | QETH_DBF_TEXT(trace, 5, "tsoprsk"); |
| 27 | return qeth_push_skb(card, skb, sizeof(struct qeth_hdr_tso)); |
| 28 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 30 | /** |
| 31 | * fill header for a TSO packet |
| 32 | */ |
| 33 | static inline void |
| 34 | qeth_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; |
| 43 | iph = skb->nh.iph; |
| 44 | tcph = skb->h.th; |
| 45 | /*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 */ |
| 54 | hdr->ext.mss = skb_shinfo(skb)->tso_size; |
| 55 | 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 | */ |
| 63 | static inline void |
| 64 | qeth_tso_set_tcpip_header(struct qeth_card *card, struct sk_buff *skb) |
| 65 | { |
| 66 | struct iphdr *iph; |
| 67 | struct ipv6hdr *ip6h; |
| 68 | struct tcphdr *tcph; |
| 69 | |
| 70 | iph = skb->nh.iph; |
| 71 | ip6h = skb->nh.ipv6h; |
| 72 | tcph = skb->h.th; |
| 73 | |
| 74 | tcph->check = 0; |
| 75 | if (skb->protocol == ETH_P_IPV6) { |
| 76 | ip6h->payload_len = 0; |
| 77 | tcph->check = ~csum_ipv6_magic(&ip6h->saddr, &ip6h->daddr, |
| 78 | 0, IPPROTO_TCP, 0); |
| 79 | return; |
| 80 | } |
| 81 | /*OSA want us to set these values ...*/ |
| 82 | tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, |
| 83 | 0, IPPROTO_TCP, 0); |
| 84 | iph->tot_len = 0; |
| 85 | iph->check = 0; |
| 86 | } |
| 87 | |
| 88 | static inline int |
| 89 | qeth_tso_prepare_packet(struct qeth_card *card, struct sk_buff *skb, |
| 90 | int ipv, int cast_type) |
| 91 | { |
| 92 | struct qeth_hdr_tso *hdr; |
| 93 | |
| 94 | QETH_DBF_TEXT(trace, 5, "tsoprep"); |
| 95 | |
| 96 | hdr = (struct qeth_hdr_tso *) qeth_tso_prepare_skb(card, &skb); |
| 97 | if (hdr == NULL) { |
| 98 | QETH_DBF_TEXT(trace, 4, "tsoperr"); |
| 99 | return -ENOMEM; |
| 100 | } |
| 101 | memset(hdr, 0, sizeof(struct qeth_hdr_tso)); |
| 102 | /*fill first 32 bytes of qdio header as used |
| 103 | *FIXME: TSO has two struct members |
| 104 | * with different names but same size |
| 105 | * */ |
| 106 | qeth_fill_header(card, &hdr->hdr, skb, ipv, cast_type); |
| 107 | qeth_tso_fill_header(card, skb); |
| 108 | qeth_tso_set_tcpip_header(card, skb); |
| 109 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
Frank Pavlic | d801145 | 2005-05-12 20:37:53 +0200 | [diff] [blame] | 111 | |
| 112 | static inline void |
| 113 | __qeth_fill_buffer_frag(struct sk_buff *skb, struct qdio_buffer *buffer, |
| 114 | int is_tso, int *next_element_to_fill) |
| 115 | { |
Frank Pavlic | d801145 | 2005-05-12 20:37:53 +0200 | [diff] [blame] | 116 | struct skb_frag_struct *frag; |
| 117 | int fragno; |
| 118 | unsigned long addr; |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 119 | int element, cnt, dlen; |
| 120 | |
| 121 | fragno = skb_shinfo(skb)->nr_frags; |
| 122 | element = *next_element_to_fill; |
| 123 | dlen = 0; |
| 124 | |
| 125 | if (is_tso) |
| 126 | buffer->element[element].flags = |
| 127 | SBAL_FLAGS_MIDDLE_FRAG; |
| 128 | else |
| 129 | buffer->element[element].flags = |
| 130 | SBAL_FLAGS_FIRST_FRAG; |
| 131 | if ( (dlen = (skb->len - skb->data_len)) ) { |
| 132 | buffer->element[element].addr = skb->data; |
| 133 | buffer->element[element].length = dlen; |
| 134 | element++; |
Frank Pavlic | d801145 | 2005-05-12 20:37:53 +0200 | [diff] [blame] | 135 | } |
Frank Pavlic | 05e08a2 | 2005-05-12 20:39:09 +0200 | [diff] [blame] | 136 | for (cnt = 0; cnt < fragno; cnt++) { |
| 137 | frag = &skb_shinfo(skb)->frags[cnt]; |
| 138 | addr = (page_to_pfn(frag->page) << PAGE_SHIFT) + |
| 139 | frag->page_offset; |
| 140 | buffer->element[element].addr = (char *)addr; |
| 141 | buffer->element[element].length = frag->size; |
| 142 | if (cnt < (fragno - 1)) |
| 143 | buffer->element[element].flags = |
| 144 | SBAL_FLAGS_MIDDLE_FRAG; |
| 145 | else |
| 146 | buffer->element[element].flags = |
| 147 | SBAL_FLAGS_LAST_FRAG; |
| 148 | element++; |
| 149 | } |
| 150 | *next_element_to_fill = element; |
Frank Pavlic | d801145 | 2005-05-12 20:37:53 +0200 | [diff] [blame] | 151 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | #endif /* __QETH_TSO_H__ */ |