qeth_tso.h 3.8 KB

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