net/core/tso.c

Source file repositories/reference/linux-study-clean/net/core/tso.c

File Facts

System
Linux kernel
Corpus path
net/core/tso.c
Extension
.c
Size
9554 bytes
Lines
359
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!is_last) {
			/* Clear all special flags for not last packet */
			tcph->psh = 0;
			tcph->fin = 0;
			tcph->rst = 0;
		}
	} else {
		struct udphdr *uh = (struct udphdr *)hdr;

		uh->len = htons(sizeof(*uh) + size);
	}
}
EXPORT_SYMBOL(tso_build_hdr);

void tso_build_data(const struct sk_buff *skb, struct tso_t *tso, int size)
{
	tso->tcp_seq += size; /* not worth avoiding this operation for UDP */
	tso->size -= size;
	tso->data += size;

	if ((tso->size == 0) &&
	    (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
		skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];

		/* Move to next segment */
		tso->size = skb_frag_size(frag);
		tso->data = skb_frag_address(frag);
		tso->next_frag_idx++;
	}
}
EXPORT_SYMBOL(tso_build_data);

int tso_start(struct sk_buff *skb, struct tso_t *tso)
{
	int tlen = skb_is_gso_tcp(skb) ? tcp_hdrlen(skb) : sizeof(struct udphdr);
	int hdr_len = skb_transport_offset(skb) + tlen;

	tso->tlen = tlen;
	tso->ip_id = ntohs(ip_hdr(skb)->id);
	tso->tcp_seq = (tlen != sizeof(struct udphdr)) ? ntohl(tcp_hdr(skb)->seq) : 0;
	tso->next_frag_idx = 0;
	tso->ipv6 = vlan_get_protocol(skb) == htons(ETH_P_IPV6);

	/* Build first data */
	tso->size = skb_headlen(skb) - hdr_len;
	tso->data = skb->data + hdr_len;
	if ((tso->size == 0) &&
	    (tso->next_frag_idx < skb_shinfo(skb)->nr_frags)) {
		skb_frag_t *frag = &skb_shinfo(skb)->frags[tso->next_frag_idx];

		/* Move to next segment */
		tso->size = skb_frag_size(frag);
		tso->data = skb_frag_address(frag);
		tso->next_frag_idx++;
	}
	return hdr_len;
}
EXPORT_SYMBOL(tso_start);

static int tso_dma_iova_try(struct device *dev, struct tso_dma_map *map,
			    phys_addr_t phys, size_t linear_len,
			    size_t total_len, size_t *offset)
{
	const struct sk_buff *skb;
	unsigned int nr_frags;
	int i;

	if (!dma_iova_try_alloc(dev, &map->iova_state, phys, total_len))
		return 1;

	skb = map->skb;
	nr_frags = skb_shinfo(skb)->nr_frags;

	if (linear_len) {
		if (dma_iova_link(dev, &map->iova_state,
				  phys, *offset, linear_len,
				  DMA_TO_DEVICE, 0))
			goto iova_fail;
		map->linear_len = linear_len;
		*offset += linear_len;
	}

	for (i = 0; i < nr_frags; i++) {
		skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
		unsigned int frag_len = skb_frag_size(frag);

		if (dma_iova_link(dev, &map->iova_state,
				  skb_frag_phys(frag), *offset,
				  frag_len, DMA_TO_DEVICE, 0)) {
			map->nr_frags = i;

Annotation

Implementation Notes