Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0
 2#include <linux/export.h>
 3#include <linux/if_vlan.h>
 4#include <net/ip.h>
 5#include <net/tso.h>
 6#include <linux/unaligned.h>
 7
 8void tso_build_hdr(const struct sk_buff *skb, char *hdr, struct tso_t *tso,
 
 
 
 
 
 
 
 
 9		   int size, bool is_last)
10{
11	int hdr_len = skb_transport_offset(skb) + tso->tlen;
 
12	int mac_hdr_len = skb_network_offset(skb);
13
14	memcpy(hdr, skb->data, hdr_len);
15	if (!tso->ipv6) {
16		struct iphdr *iph = (void *)(hdr + mac_hdr_len);
17
18		iph->id = htons(tso->ip_id);
19		iph->tot_len = htons(size + hdr_len - mac_hdr_len);
20		tso->ip_id++;
21	} else {
22		struct ipv6hdr *iph = (void *)(hdr + mac_hdr_len);
23
24		iph->payload_len = htons(size + tso->tlen);
25	}
26	hdr += skb_transport_offset(skb);
27	if (tso->tlen != sizeof(struct udphdr)) {
28		struct tcphdr *tcph = (struct tcphdr *)hdr;
29
30		put_unaligned_be32(tso->tcp_seq, &tcph->seq);
31
32		if (!is_last) {
33			/* Clear all special flags for not last packet */
34			tcph->psh = 0;
35			tcph->fin = 0;
36			tcph->rst = 0;
37		}
38	} else {
39		struct udphdr *uh = (struct udphdr *)hdr;
40
41		uh->len = htons(sizeof(*uh) + size);
 
 
 
 
42	}
43}
44EXPORT_SYMBOL(tso_build_hdr);
45
46void tso_build_data(const struct sk_buff *skb, struct tso_t *tso, int size)
47{
48	tso->tcp_seq += size; /* not worth avoiding this operation for UDP */
49	tso->size -= size;
50	tso->data += size;
51
52	if ((tso->size == 0) &&
53	    (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
54		skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
55
56		/* Move to next segment */
57		tso->size = skb_frag_size(frag);
58		tso->data = skb_frag_address(frag);
59		tso->next_frag_idx++;
60	}
61}
62EXPORT_SYMBOL(tso_build_data);
63
64int tso_start(struct sk_buff *skb, struct tso_t *tso)
65{
66	int tlen = skb_is_gso_tcp(skb) ? tcp_hdrlen(skb) : sizeof(struct udphdr);
67	int hdr_len = skb_transport_offset(skb) + tlen;
68
69	tso->tlen = tlen;
70	tso->ip_id = ntohs(ip_hdr(skb)->id);
71	tso->tcp_seq = (tlen != sizeof(struct udphdr)) ? ntohl(tcp_hdr(skb)->seq) : 0;
72	tso->next_frag_idx = 0;
73	tso->ipv6 = vlan_get_protocol(skb) == htons(ETH_P_IPV6);
74
75	/* Build first data */
76	tso->size = skb_headlen(skb) - hdr_len;
77	tso->data = skb->data + hdr_len;
78	if ((tso->size == 0) &&
79	    (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
80		skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
81
82		/* Move to next segment */
83		tso->size = skb_frag_size(frag);
84		tso->data = skb_frag_address(frag);
85		tso->next_frag_idx++;
86	}
87	return hdr_len;
88}
89EXPORT_SYMBOL(tso_start);
v5.4
 1// SPDX-License-Identifier: GPL-2.0
 2#include <linux/export.h>
 3#include <linux/if_vlan.h>
 4#include <net/ip.h>
 5#include <net/tso.h>
 6#include <asm/unaligned.h>
 7
 8/* Calculate expected number of TX descriptors */
 9int tso_count_descs(struct sk_buff *skb)
10{
11	/* The Marvell Way */
12	return skb_shinfo(skb)->gso_segs * 2 + skb_shinfo(skb)->nr_frags;
13}
14EXPORT_SYMBOL(tso_count_descs);
15
16void tso_build_hdr(struct sk_buff *skb, char *hdr, struct tso_t *tso,
17		   int size, bool is_last)
18{
19	struct tcphdr *tcph;
20	int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
21	int mac_hdr_len = skb_network_offset(skb);
22
23	memcpy(hdr, skb->data, hdr_len);
24	if (!tso->ipv6) {
25		struct iphdr *iph = (void *)(hdr + mac_hdr_len);
26
27		iph->id = htons(tso->ip_id);
28		iph->tot_len = htons(size + hdr_len - mac_hdr_len);
29		tso->ip_id++;
30	} else {
31		struct ipv6hdr *iph = (void *)(hdr + mac_hdr_len);
32
33		iph->payload_len = htons(size + tcp_hdrlen(skb));
34	}
35	tcph = (struct tcphdr *)(hdr + skb_transport_offset(skb));
36	put_unaligned_be32(tso->tcp_seq, &tcph->seq);
 
 
 
 
 
 
 
 
 
 
 
 
37
38	if (!is_last) {
39		/* Clear all special flags for not last packet */
40		tcph->psh = 0;
41		tcph->fin = 0;
42		tcph->rst = 0;
43	}
44}
45EXPORT_SYMBOL(tso_build_hdr);
46
47void tso_build_data(struct sk_buff *skb, struct tso_t *tso, int size)
48{
49	tso->tcp_seq += size;
50	tso->size -= size;
51	tso->data += size;
52
53	if ((tso->size == 0) &&
54	    (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
55		skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
56
57		/* Move to next segment */
58		tso->size = skb_frag_size(frag);
59		tso->data = skb_frag_address(frag);
60		tso->next_frag_idx++;
61	}
62}
63EXPORT_SYMBOL(tso_build_data);
64
65void tso_start(struct sk_buff *skb, struct tso_t *tso)
66{
67	int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
 
68
 
69	tso->ip_id = ntohs(ip_hdr(skb)->id);
70	tso->tcp_seq = ntohl(tcp_hdr(skb)->seq);
71	tso->next_frag_idx = 0;
72	tso->ipv6 = vlan_get_protocol(skb) == htons(ETH_P_IPV6);
73
74	/* Build first data */
75	tso->size = skb_headlen(skb) - hdr_len;
76	tso->data = skb->data + hdr_len;
77	if ((tso->size == 0) &&
78	    (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
79		skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];
80
81		/* Move to next segment */
82		tso->size = skb_frag_size(frag);
83		tso->data = skb_frag_address(frag);
84		tso->next_frag_idx++;
85	}
 
86}
87EXPORT_SYMBOL(tso_start);