1 #include <linux/export.h> 2 #include <net/ip.h> 3 #include <net/tso.h> 4 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 13 void tso_build_hdr(struct sk_buff *skb, char *hdr, struct tso_t *tso, 14 int size, bool is_last) 15 { 16 struct iphdr *iph; 17 struct tcphdr *tcph; 18 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); 19 int mac_hdr_len = skb_network_offset(skb); 20 21 memcpy(hdr, skb->data, hdr_len); 22 iph = (struct iphdr *)(hdr + mac_hdr_len); 23 iph->id = htons(tso->ip_id); 24 iph->tot_len = htons(size + hdr_len - mac_hdr_len); 25 tcph = (struct tcphdr *)(hdr + skb_transport_offset(skb)); 26 tcph->seq = htonl(tso->tcp_seq); 27 tso->ip_id++; 28 29 if (!is_last) { 30 /* Clear all special flags for not last packet */ 31 tcph->psh = 0; 32 tcph->fin = 0; 33 tcph->rst = 0; 34 } 35 } 36 EXPORT_SYMBOL(tso_build_hdr); 37 38 void tso_build_data(struct sk_buff *skb, struct tso_t *tso, int size) 39 { 40 tso->tcp_seq += size; 41 tso->size -= size; 42 tso->data += size; 43 44 if ((tso->size == 0) && 45 (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) { 46 skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx]; 47 48 /* Move to next segment */ 49 tso->size = frag->size; 50 tso->data = page_address(frag->page.p) + frag->page_offset; 51 tso->next_frag_idx++; 52 } 53 } 54 EXPORT_SYMBOL(tso_build_data); 55 56 void tso_start(struct sk_buff *skb, struct tso_t *tso) 57 { 58 int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); 59 60 tso->ip_id = ntohs(ip_hdr(skb)->id); 61 tso->tcp_seq = ntohl(tcp_hdr(skb)->seq); 62 tso->next_frag_idx = 0; 63 64 /* Build first data */ 65 tso->size = skb_headlen(skb) - hdr_len; 66 tso->data = skb->data + hdr_len; 67 if ((tso->size == 0) && 68 (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) { 69 skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx]; 70 71 /* Move to next segment */ 72 tso->size = frag->size; 73 tso->data = page_address(frag->page.p) + frag->page_offset; 74 tso->next_frag_idx++; 75 } 76 } 77 EXPORT_SYMBOL(tso_start); 78