tso.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include <linux/export.h>
  2. #include <net/ip.h>
  3. #include <net/tso.h>
  4. #include <asm/unaligned.h>
  5. /* Calculate expected number of TX descriptors */
  6. int tso_count_descs(struct sk_buff *skb)
  7. {
  8. /* The Marvell Way */
  9. return skb_shinfo(skb)->gso_segs * 2 + skb_shinfo(skb)->nr_frags;
  10. }
  11. EXPORT_SYMBOL(tso_count_descs);
  12. void tso_build_hdr(struct sk_buff *skb, char *hdr, struct tso_t *tso,
  13. int size, bool is_last)
  14. {
  15. struct iphdr *iph;
  16. struct tcphdr *tcph;
  17. int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  18. int mac_hdr_len = skb_network_offset(skb);
  19. memcpy(hdr, skb->data, hdr_len);
  20. iph = (struct iphdr *)(hdr + mac_hdr_len);
  21. iph->id = htons(tso->ip_id);
  22. iph->tot_len = htons(size + hdr_len - mac_hdr_len);
  23. tcph = (struct tcphdr *)(hdr + skb_transport_offset(skb));
  24. put_unaligned_be32(tso->tcp_seq, &tcph->seq);
  25. tso->ip_id++;
  26. if (!is_last) {
  27. /* Clear all special flags for not last packet */
  28. tcph->psh = 0;
  29. tcph->fin = 0;
  30. tcph->rst = 0;
  31. }
  32. }
  33. EXPORT_SYMBOL(tso_build_hdr);
  34. void tso_build_data(struct sk_buff *skb, struct tso_t *tso, int size)
  35. {
  36. tso->tcp_seq += size;
  37. tso->size -= size;
  38. tso->data += size;
  39. if ((tso->size == 0) &&
  40. (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
  41. skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
  42. /* Move to next segment */
  43. tso->size = frag->size;
  44. tso->data = page_address(frag->page.p) + frag->page_offset;
  45. tso->next_frag_idx++;
  46. }
  47. }
  48. EXPORT_SYMBOL(tso_build_data);
  49. void tso_start(struct sk_buff *skb, struct tso_t *tso)
  50. {
  51. int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  52. tso->ip_id = ntohs(ip_hdr(skb)->id);
  53. tso->tcp_seq = ntohl(tcp_hdr(skb)->seq);
  54. tso->next_frag_idx = 0;
  55. /* Build first data */
  56. tso->size = skb_headlen(skb) - hdr_len;
  57. tso->data = skb->data + hdr_len;
  58. if ((tso->size == 0) &&
  59. (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
  60. skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
  61. /* Move to next segment */
  62. tso->size = frag->size;
  63. tso->data = page_address(frag->page.p) + frag->page_offset;
  64. tso->next_frag_idx++;
  65. }
  66. }
  67. EXPORT_SYMBOL(tso_start);